summaryrefslogtreecommitdiff
path: root/src/CGIScript.cpp
diff options
context:
space:
mode:
authorcflip <cflip@cflip.net>2023-05-08 21:25:21 -0600
committercflip <cflip@cflip.net>2023-05-08 21:25:21 -0600
commit7f1d6bbc335288df1e24e7c8f305c32afe6b050a (patch)
tree3ca1784ab73315e44dd9e03b2f0e244a59158fbc /src/CGIScript.cpp
parent83fb0b96c94e7f596f81d5bc346150904457ed64 (diff)
Begin rewriting cfws in C
Diffstat (limited to 'src/CGIScript.cpp')
-rw-r--r--src/CGIScript.cpp69
1 files changed, 0 insertions, 69 deletions
diff --git a/src/CGIScript.cpp b/src/CGIScript.cpp
deleted file mode 100644
index 3ef1f3f..0000000
--- a/src/CGIScript.cpp
+++ /dev/null
@@ -1,69 +0,0 @@
-#include "CGIScript.h"
-
-#include <cstdlib>
-#include <filesystem>
-#include <iostream>
-#include <sstream>
-#include <string>
-#include <unistd.h>
-
-CGIScript::CGIScript(const std::string& script_path)
- : m_script_path(script_path)
-{
- set_environment("SCRIPT_NAME", script_path.c_str());
- set_environment("SCRIPT_FILENAME", script_path.c_str());
- set_environment("SERVER_PROTOCOL", "HTTP/1.1");
- set_environment("SERVER_SOFTWARE", "cfws");
-}
-
-CGIScript::~CGIScript()
-{
- pclose(m_pipe);
-
- for (const auto* key : m_environment_variables)
- unsetenv(key);
-}
-
-void CGIScript::set_environment(const char* key, const char* value)
-{
- m_environment_variables.push_back(key);
- setenv(key, value, 1);
-}
-
-bool CGIScript::open()
-{
- m_pipe = popen(m_script_path.c_str(), "r");
- if (m_pipe == nullptr) {
- perror("cfws: popen");
- return false;
- }
-
- m_is_open = true;
- return true;
-}
-
-std::string CGIScript::read_output()
-{
- std::stringstream sstream;
-
- char ch = 0;
- while ((ch = fgetc(m_pipe)) != EOF)
- sstream << ch;
-
- return sstream.str();
-}
-
-void CGIScript::validate_path(const std::string& script_path)
-{
- namespace fs = std::filesystem;
-
- if (!fs::exists(script_path)) {
- std::cerr << "cfws: Script not found: " << script_path << std::endl;
- exit(1);
- }
-
- if (access(script_path.c_str(), X_OK)) {
- std::cerr << "cfws: Script does not have execute permissions: " << script_path << std::endl;
- exit(1);
- }
-}