aboutsummaryrefslogtreecommitdiff
path: root/maple/gemini.cc
diff options
context:
space:
mode:
authorFuwn <[email protected]>2022-05-09 08:53:36 +0000
committerFuwn <[email protected]>2022-05-09 08:53:36 +0000
commit56fbf0ae1ef77ae69c7d2484d67bb664a4dee744 (patch)
tree14cdccb13cd594b2f18210ce352847e7b85170ad /maple/gemini.cc
parentrefactor: explicit auto (diff)
downloadarchived-maple-56fbf0ae1ef77ae69c7d2484d67bb664a4dee744.tar.xz
archived-maple-56fbf0ae1ef77ae69c7d2484d67bb664a4dee744.zip
feat: titan support
This commit is huge... For the most part, this commit just adds Titan support. However, this commit also refactors the `maple/` directory so that every complex block lives in it's own namespace.
Diffstat (limited to 'maple/gemini.cc')
-rw-r--r--maple/gemini.cc64
1 files changed, 64 insertions, 0 deletions
diff --git a/maple/gemini.cc b/maple/gemini.cc
new file mode 100644
index 0000000..2a8bc0d
--- /dev/null
+++ b/maple/gemini.cc
@@ -0,0 +1,64 @@
+/*
+ * This file is part of Maple <https://github.com/gemrest/maple>.
+ * Copyright (C) 2022-2022 Fuwn <[email protected]>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Copyright (C) 2022-2022 Fuwn <[email protected]>
+ * SPDX-License-Identifier: GPL-3.0-only
+ */
+
+#include <fstream>
+#include <iostream>
+
+#include "gemini.hh"
+
+namespace maple::gemini {
+ auto handle_client(
+ std::vector<std::string> gemini_files,
+ std::string path,
+ std::stringstream &response
+ ) -> void {
+ // Check if the route is a file being served
+ if (std::find(
+ gemini_files.begin(),
+ gemini_files.end(),
+ ".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();
+ } 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();
+ } else {
+ response
+ << "51 The server (Maple) could not find the specified file.\r\n";
+ }
+ }
+
+ std::cout << "requested " << path << std::endl;
+ }
+}