20 #include <metaproxy/package.hpp>
21 #include <metaproxy/util.hpp>
33 namespace mp = metaproxy_1;
34 namespace yf = mp::filter;
36 namespace metaproxy_1 {
55 yf::CGI::CGI() : m_p(new Rep)
62 std::map<pid_t,pid_t>::const_iterator it;
63 boost::mutex::scoped_lock lock(m_mutex);
65 for (it = children.begin(); it != children.end(); it++)
66 kill(it->second, SIGTERM);
75 Z_GDU *zgdu_req = package.request().get();
81 if (zgdu_req->which != Z_GDU_HTTP_Request)
86 std::string path_info;
87 std::string query_string;
88 const char *path = zgdu_req->u.HTTP_Request->path;
89 yaz_log(YLOG_LOG,
"path=%s", path);
90 const char *p_cp = strchr(path,
'?');
93 path_info.assign(path, p_cp - path);
94 query_string.assign(p_cp+1);
97 path_info.assign(path);
99 std::list<CGI::Exec>::const_iterator it;
100 metaproxy_1::odr odr;
101 for (it =
m_p->exec_map.begin(); it !=
m_p->exec_map.end(); it++)
103 if (it->path.compare(path_info) == 0)
113 setenv(
"PATH_INFO", path_info.c_str(), 1);
114 setenv(
"QUERY_STRING", query_string.c_str(), 1);
115 r = execl(it->program.c_str(), it->program.c_str(), (
char *) 0);
121 zgdu_res = odr.create_HTTP_Response(
122 package.session(), zgdu_req->u.HTTP_Request, 400);
123 package.response() = zgdu_res;
128 boost::mutex::scoped_lock lock(
m_p->m_mutex);
129 m_p->children[pid] = pid;
131 waitpid(pid, &status, 0);
135 boost::mutex::scoped_lock lock(
m_p->m_mutex);
136 m_p->children.erase(pid);
138 zgdu_res = odr.create_HTTP_Response(
139 package.session(), zgdu_req->u.HTTP_Request, 200);
140 package.response() = zgdu_res;
151 for (ptr = ptr->children; ptr; ptr = ptr->next)
153 if (ptr->type != XML_ELEMENT_NODE)
155 if (!strcmp((
const char *) ptr->name,
"map"))
159 const struct _xmlAttr *attr;
160 for (attr = ptr->properties; attr; attr = attr->next)
162 if (!strcmp((
const char *) attr->name,
"path"))
163 exec.path = mp::xml::get_text(attr->children);
164 else if (!strcmp((
const char *) attr->name,
"exec"))
165 exec.program = mp::xml::get_text(attr->children);
167 throw mp::filter::FilterException
169 + std::string((
const char *) attr->name)
170 +
" in cgi section");
172 m_p->exec_map.push_back(exec);
176 throw mp::filter::FilterException(
"Bad element "
177 + std::string((
const char *)