From 97cb8e1b8a4e1df3ed65ac5aa684c7babd1771dc Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sat, 22 Nov 2025 07:49:01 +0100 Subject: chore: small source code tweaks. Signed-off-by: Amlal El Mahrouss --- dev/lib/utility/cgi.hpp | 79 ++++++++++++++++++++++++++++++++++++++++++ dev/lib/utility/cgi_writer.hpp | 79 ------------------------------------------ 2 files changed, 79 insertions(+), 79 deletions(-) create mode 100644 dev/lib/utility/cgi.hpp delete mode 100644 dev/lib/utility/cgi_writer.hpp (limited to 'dev/lib/utility') diff --git a/dev/lib/utility/cgi.hpp b/dev/lib/utility/cgi.hpp new file mode 100644 index 0000000..fd00bbf --- /dev/null +++ b/dev/lib/utility/cgi.hpp @@ -0,0 +1,79 @@ +/* + * File: cgi.hpp + * Author: Amlal El Mahrouss, + * Copyright 2023-2025, Amlal El Mahrouss, Licensed under the Boost Software License. + */ + +#ifndef _OCL_CGI_HPP +#define _OCL_CGI_HPP + +#include +#include +#include +#include + +namespace ocl +{ + namespace cgi + { + /// @brief CGI Writer class, writes to stdout; as CGI expects. + template + class basic_writer + { + private: + basic_writer& eval_(const basic_chunk_string& mime, const basic_chunk_string& ss) noexcept + { + std::basic_stringstream ss_out; + + ss_out << std::format("Content-Type: {}\r\n", mime.str()); + ss_out << std::format("Server: {}\r\n", "OCL/1.0"); + ss_out << std::format("Content-Length: {}\r\n\r\n", ss.str().size()); + ss_out << ss.str(); + + io::print(ss_out.str()); + + return *this; + } + + public: + explicit basic_writer() = default; + virtual ~basic_writer() = default; + + basic_writer& operator=(const basic_writer&) = default; + basic_writer(const basic_writer&) = default; + + public: + friend void operator<<(basic_writer& self, const basic_chunk_string& ss_in) + { + self = self.eval_("text/plain", ss_in); + } + + basic_writer& binary(const basic_chunk_string& ss_in) + { + return this->eval_("application/octet-stream", ss_in); + } + + basic_writer& html(const basic_chunk_string& ss_in) + { + return this->eval_("text/html", ss_in); + } + + basic_writer& xml(const basic_chunk_string& ss_in) + { + return this->eval_("application/xml", ss_in); + } + + basic_writer& json(const basic_chunk_string& ss_in) + { + return this->eval_("application/json", ss_in); + } + + basic_writer& js(const basic_chunk_string& ss_in) + { + return this->eval_("text/javascript", ss_in); + } + }; + } // namespace cgi +} // namespace ocl + +#endif // ifndef _OCL_CGI_HPP diff --git a/dev/lib/utility/cgi_writer.hpp b/dev/lib/utility/cgi_writer.hpp deleted file mode 100644 index 7b95b2e..0000000 --- a/dev/lib/utility/cgi_writer.hpp +++ /dev/null @@ -1,79 +0,0 @@ -/* - * File: cgi_writer.hpp - * Author: Amlal El Mahrouss, - * Copyright 2023-2025, Amlal El Mahrouss, Licensed under the Boost Software License. - */ - -#ifndef _OCL_CGI_WRITER_HPP -#define _OCL_CGI_WRITER_HPP - -#include -#include -#include -#include - -namespace ocl -{ - namespace cgi - { - /// @brief CGI Writer class, writes to stdout; as CGI expects. - template - class basic_writer - { - private: - basic_writer& eval_(const basic_chunk_string& mime, const basic_chunk_string& ss) noexcept - { - std::basic_stringstream ss_out; - - ss_out << std::format("Content-Type: {}\r\n", mime.str()); - ss_out << std::format("Server: {}\r\n", "OCL-CGI/1.0"); - ss_out << std::format("Content-Length: {}\r\n\r\n", ss.str().size()); - ss_out << ss.str(); - - io::print(ss_out.str()); - - return *this; - } - - public: - explicit basic_writer() = default; - virtual ~basic_writer() = default; - - basic_writer& operator=(const basic_writer&) = default; - basic_writer(const basic_writer&) = default; - - public: - friend void operator<<(basic_writer& self, const basic_chunk_string& ss_in) - { - self = self.eval_("text/plain", ss_in); - } - - basic_writer& binary(const basic_chunk_string& ss_in) - { - return this->eval_("application/octet-stream", ss_in); - } - - basic_writer& html(const basic_chunk_string& ss_in) - { - return this->eval_("text/html", ss_in); - } - - basic_writer& xml(const basic_chunk_string& ss_in) - { - return this->eval_("application/xml", ss_in); - } - - basic_writer& json(const basic_chunk_string& ss_in) - { - return this->eval_("application/json", ss_in); - } - - basic_writer& js(const basic_chunk_string& ss_in) - { - return this->eval_("text/javascript", ss_in); - } - }; - } // namespace cgi -} // namespace ocl - -#endif // ifndef _OCL_CGI_WRITER_HPP -- cgit v1.2.3