metaproxy  1.21.0
Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
metaproxy_1::filter::CGI::Rep Class Reference
Collaboration diagram for metaproxy_1::filter::CGI::Rep:
Collaboration graph

Public Member Functions

 ~Rep ()
 

Private Member Functions

void child (Z_HTTP_Request *, const CGI::Exec *)
 

Private Attributes

std::list< CGI::Execexec_map
 
std::map< std::string, std::string > env_map
 
std::map< pid_t, pid_t > children
 
boost::mutex m_mutex
 
std::string documentroot
 

Friends

class CGI
 

Detailed Description

Definition at line 46 of file filter_cgi.cpp.

Constructor & Destructor Documentation

◆ ~Rep()

mp::filter::CGI::Rep::~Rep ( )

Definition at line 65 of file filter_cgi.cpp.

66 {
67  std::map<pid_t,pid_t>::const_iterator it;
68  boost::mutex::scoped_lock lock(m_mutex);
69 
70  for (it = children.begin(); it != children.end(); it++)
71  kill(it->second, SIGTERM);
72 }
std::map< pid_t, pid_t > children
Definition: filter_cgi.cpp:50

Member Function Documentation

◆ child()

void mp::filter::CGI::Rep::child ( Z_HTTP_Request *  hreq,
const CGI::Exec it 
)
private

Definition at line 78 of file filter_cgi.cpp.

79 {
80  const char *path_cstr = hreq->path;
81  std::string path(path_cstr);
82  const char *program_cstr = it->program.c_str();
83  std::string script_name(path, 0, it->path.length());
84  std::string rest(path, it->path.length());
85  std::string query_string;
86  std::string path_info;
87  size_t qpos = rest.find('?');
88  if (qpos == std::string::npos)
89  path_info = rest;
90  else
91  {
92  query_string.assign(rest, qpos + 1, std::string::npos);
93  path_info.assign(rest, 0, qpos);
94  }
95  setenv("REQUEST_METHOD", hreq->method, 1);
96  setenv("REQUEST_URI", path_cstr, 1);
97  setenv("SCRIPT_NAME", script_name.c_str(), 1);
98  setenv("PATH_INFO", path_info.c_str(), 1);
99  setenv("QUERY_STRING", query_string.c_str(), 1);
100  const char *v;
101  v = z_HTTP_header_lookup(hreq->headers, "Cookie");
102  if (v)
103  setenv("HTTP_COOKIE", v, 1);
104  v = z_HTTP_header_lookup(hreq->headers, "User-Agent");
105  if (v)
106  setenv("HTTP_USER_AGENT", v, 1);
107  v = z_HTTP_header_lookup(hreq->headers, "Accept");
108  if (v)
109  setenv("HTTP_ACCEPT", v, 1);
110  v = z_HTTP_header_lookup(hreq->headers, "Accept-Encoding");
111  if (v)
112  setenv("HTTP_ACCEPT_ENCODING", v, 1);
113  setenv("DOCUMENT_ROOT", documentroot.c_str(), 1);
114  setenv("GATEWAY_INTERFACE", "CGI/1.1", 1);
115 
116  v = z_HTTP_header_lookup(hreq->headers, "Content-Type");
117  if (v)
118  {
119  char tmp[40];
120  sprintf(tmp, "%d", hreq->content_len);
121  setenv("CONTENT_LENGTH", tmp, 1);
122  setenv("CONTENT_TYPE", v, 1);
123  }
124  // apply user-defined environment
125  std::map<std::string,std::string>::const_iterator it_e;
126  for (it_e = env_map.begin();
127  it_e != env_map.end(); it_e++)
128  setenv(it_e->first.c_str(), it_e->second.c_str(), 1);
129  // change directory to configuration root
130  // then to CGI program directory (could be relative)
131  chdir(documentroot.c_str());
132  char *program = xstrdup(program_cstr);
133  char *cp = strrchr(program, '/');
134  if (cp)
135  {
136  *cp++ = '\0';
137  chdir(program);
138  }
139  else
140  cp = program;
141  int r = execl(cp, cp, (char *) 0);
142  if (r == -1)
143  exit(1);
144  exit(0);
145 }
std::map< std::string, std::string > env_map
Definition: filter_cgi.cpp:49

References metaproxy_1::filter::CGI::Exec::path, and metaproxy_1::filter::CGI::Exec::program.

Friends And Related Function Documentation

◆ CGI

friend class CGI
friend

Definition at line 47 of file filter_cgi.cpp.

Member Data Documentation

◆ children

std::map<pid_t,pid_t> metaproxy_1::filter::CGI::Rep::children
private

Definition at line 50 of file filter_cgi.cpp.

◆ documentroot

std::string metaproxy_1::filter::CGI::Rep::documentroot
private

Definition at line 52 of file filter_cgi.cpp.

◆ env_map

std::map<std::string,std::string> metaproxy_1::filter::CGI::Rep::env_map
private

Definition at line 49 of file filter_cgi.cpp.

◆ exec_map

std::list<CGI::Exec> metaproxy_1::filter::CGI::Rep::exec_map
private

Definition at line 48 of file filter_cgi.cpp.

◆ m_mutex

boost::mutex metaproxy_1::filter::CGI::Rep::m_mutex
private

Definition at line 51 of file filter_cgi.cpp.


The documentation for this class was generated from the following file: