From c52dbf5513ae7f106634967162da5cfb01dc5af3 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sat, 26 Jul 2025 01:47:32 +0100 Subject: feat: SOCL v1.0.2, changelog soon! Signed-off-by: Amlal El Mahrouss --- dev/examples/cgi/CMakeLists.txt | 12 ++++++ dev/examples/cgi/cgi.cc | 91 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 dev/examples/cgi/CMakeLists.txt create mode 100644 dev/examples/cgi/cgi.cc (limited to 'dev/examples/cgi') diff --git a/dev/examples/cgi/CMakeLists.txt b/dev/examples/cgi/CMakeLists.txt new file mode 100644 index 0000000..391899f --- /dev/null +++ b/dev/examples/cgi/CMakeLists.txt @@ -0,0 +1,12 @@ + +cmake_minimum_required(VERSION 3.15...3.31) + +project( + CGI + VERSION 1.0 + LANGUAGES CXX) + +add_executable(CGI cgi.cc) + +set_property(TARGET CGI PROPERTY CXX_STANDARD 20) +target_include_directories(CGI PUBLIC ../../) diff --git a/dev/examples/cgi/cgi.cc b/dev/examples/cgi/cgi.cc new file mode 100644 index 0000000..b4c0b34 --- /dev/null +++ b/dev/examples/cgi/cgi.cc @@ -0,0 +1,91 @@ +/* + cgi example + written by Amlal El Mahrouss. + licensed under the MIT license + */ + +#include +#include +#include +#include + +const std::string g_not_found = R"( + + + + + error | snu-lib + + + +

Uh Oh!

+
No index file was found in this directory.
+
+ + + + + + + + + +
Name

Refresh

+
snu's Common Gateway Server.
+ + +)"; + +/* finally test it */ +/* @brief this stub loads a 'index.html' or returns an error message if not found. */ +int main(int argc, char** argv) +{ + // ... let's assume we serve data. + + snu::cgi::cgi_writer writer; + std::stringstream ss_file; + + std::ifstream fp("index.html"); + + if (fp.good()) + ss_file << fp.rdbuf(); + else + ss_file << g_not_found; + + fp.close(); + + writer.eval_html(ss_file); + + return 0; +} -- cgit v1.2.3