-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathcgier.h
49 lines (41 loc) · 1.45 KB
/
cgier.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/**
* @file cgier.h
* @author Yukun J
* @expectation this header file should be compatible to compile in C++
* program on Linux
* @init_date Jan 13 2022
*
* This is a header file implementing the CGIer that fork another process
* to run the cgi program commanded by the client through http request in a
* RESTful style
*/
#ifndef SRC_INCLUDE_HTTP_CGIER_H_
#define SRC_INCLUDE_HTTP_CGIER_H_
#include <string>
#include <vector>
#include "core/utils.h"
namespace TURTLE_SERVER::HTTP {
/**
* This Cgier runs a client commanded program through traditional 'fork' +
* 'execve' All the cgi program should reside in a '/cgi-bin' folder in the root
* directory of the http serving directory parent and child process communicate
* through a file, where child writes the output to it and parent read it out
* afterwards
* */
class Cgier {
public:
static auto ParseCgier(const std::string &resource_url) noexcept -> Cgier;
static auto MakeInvalidCgier() noexcept -> Cgier;
explicit Cgier(const std::string &path, const std::vector<std::string> &arguments) noexcept;
auto Run() -> std::vector<unsigned char>;
auto IsValid() const noexcept -> bool;
auto GetPath() const noexcept -> std::string;
private:
auto BuildArgumentList() -> char **;
void FreeArgumentList(char **arg_list);
std::string cgi_program_path_;
std::vector<std::string> cgi_arguments_;
bool valid_{true};
};
} // namespace TURTLE_SERVER::HTTP
#endif // SRC_INCLUDE_HTTP_CGIER_H_