aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2022-05-09 09:21:54 +0000
committerFuwn <[email protected]>2022-05-09 09:21:54 +0000
commitdc8ce1e38bd6dac964642af1c57b8457fdf7e007 (patch)
treeb51ca9a66ffade2630eedf2bca1633dd803362c8
parentdocs(readme): update instructions and description (diff)
downloadmaple-dc8ce1e38bd6dac964642af1c57b8457fdf7e007.tar.xz
maple-dc8ce1e38bd6dac964642af1c57b8457fdf7e007.zip
refactor: cleanup non-essential variables
-rw-r--r--maple/gemini.cc19
-rw-r--r--maple/maple.cc4
2 files changed, 7 insertions, 16 deletions
diff --git a/maple/gemini.cc b/maple/gemini.cc
index 2a8bc0d..af6d194 100644
--- a/maple/gemini.cc
+++ b/maple/gemini.cc
@@ -36,23 +36,12 @@ namespace maple::gemini {
".maple/gmi" + path
) != gemini_files.end()) {
// If the route is a file being served; get the file contents
-
- std::ifstream file(".maple/gmi" + path);
- std::stringstream buffer;
-
- buffer << file.rdbuf();
-
- file.close();
-
- response << "20 text/gemini\r\n" << buffer.str();
+ response << "20 text/gemini\r\n"
+ << std::ifstream(".maple/gmi" + path).rdbuf();
} else {
if (path.empty() || path.at(path.length() - 1) == '/') {
- std::ifstream file(".maple/gmi" + path + "index.gmi");
- std::stringstream buffer;
-
- buffer << file.rdbuf();
-
- response << "20 text/gemini\r\n" << buffer.str();
+ response << "20 text/gemini\r\n"
+ << std::ifstream(".maple/gmi" + path + "index.gmi").rdbuf();
} else {
response
<< "51 The server (Maple) could not find the specified file.\r\n";
diff --git a/maple/maple.cc b/maple/maple.cc
index d1d8175..259110f 100644
--- a/maple/maple.cc
+++ b/maple/maple.cc
@@ -190,7 +190,6 @@ auto main() -> int {
reinterpret_cast<sockaddr *>(&socket_address_),
&socket_address_length
);
- char request[1024];
if (client < 0) { maple::exit_with("unable to accept", false); }
@@ -204,6 +203,7 @@ auto main() -> int {
size_t index_of_junk;
int request_scheme; // Gemini = 1, Titan = 2, Error = 0
size_t bytes_read;
+ char request[1024];
SSL_read_ex(ssl, request, sizeof(request), &bytes_read);
@@ -291,7 +291,9 @@ auto main() -> int {
namespace maple {
auto exit_with[[noreturn]](const char *message, bool ssl) -> void {
perror(message);
+
if (ssl) { ERR_print_errors_fp(stderr); }
+
std::exit(EXIT_FAILURE);
}
}