summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--configure.ac6
-rw-r--r--lib/component_factory.cc2
-rw-r--r--lib/file_factory.cc2
-rw-r--r--src/sitecing-fastcgi.cc3
-rw-r--r--src/sitecing-plaincgi.cc3
5 files changed, 11 insertions, 5 deletions
diff --git a/configure.ac b/configure.ac
index b9e9b56..a8aa142 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,81 +1,81 @@
1AC_INIT([sitecing], [0.0.1], [sitecing-bugs@klever.net]) 1AC_INIT([sitecing], [0.0.1], [sitecing-bugs@klever.net])
2AC_CONFIG_SRCDIR([include/sitecing/sitecing_parser.h]) 2AC_CONFIG_SRCDIR([include/sitecing/sitecing_parser.h])
3AC_CONFIG_HEADER([config.h]) 3AC_CONFIG_HEADER([config.h])
4AM_INIT_AUTOMAKE([dist-bzip2]) 4AM_INIT_AUTOMAKE([dist-bzip2])
5 5
6AC_PROG_INSTALL 6AC_PROG_INSTALL
7AC_PROG_AWK 7AC_PROG_AWK
8AC_PROG_CXX 8AC_PROG_CXX
9AC_PROG_CC 9AC_PROG_CC
10AM_PROG_LEX 10AM_PROG_LEX
11AC_PROG_LIBTOOL 11AC_PROG_LIBTOOL
12 12
13AC_HEADER_STDC 13AC_HEADER_STDC
14AC_CHECK_HEADERS([stdlib.h unistd.h]) 14AC_CHECK_HEADERS([stdlib.h unistd.h])
15 15
16AC_C_CONST 16AC_C_CONST
17 17
18AC_FUNC_MALLOC 18AC_FUNC_MALLOC
19AC_FUNC_REALLOC 19AC_FUNC_REALLOC
20 20
21AC_WITH_PKGCONFIG 21AC_WITH_PKGCONFIG
22 22
23PKG_CHECK_MODULES([KINGATE],[kingate],,[ 23PKG_CHECK_MODULES([KINGATE],[kingate >= 0.0.1],,[
24 AC_MSG_ERROR([no kingate library found, get it at http://kin.klever.net/kingate/]) 24 AC_MSG_ERROR([no kingate library found, get it at http://kin.klever.net/kingate/])
25]) 25])
26HAVE_FCGI=false 26HAVE_FCGI=false
27HAVE_PLAINCGI=false 27HAVE_PLAINCGI=false
28PKG_CHECK_MODULES([KINGATE_FCGI],[kingate-fcgi],[ 28PKG_CHECK_MODULES([KINGATE_FCGI],[kingate-fcgi >= 0.0.1],[
29 HAVE_FCGI=true 29 HAVE_FCGI=true
30],[ 30],[
31 AC_MSG_NOTICE([no fastcgi support in kingate library]) 31 AC_MSG_NOTICE([no fastcgi support in kingate library])
32]) 32])
33PKG_CHECK_MODULES([KINGATE_PLAINCGI],[kingate-plaincgi],[ 33PKG_CHECK_MODULES([KINGATE_PLAINCGI],[kingate-plaincgi >= 0.0.1],[
34 HAVE_PLAINCGI=true 34 HAVE_PLAINCGI=true
35],[ 35],[
36 AC_MSG_NOTICE([no plaincgi support in kingate library]) 36 AC_MSG_NOTICE([no plaincgi support in kingate library])
37]) 37])
38if ! (${HAVE_FCGI} || ${HAVE_PLAINCGI}) ; then 38if ! (${HAVE_FCGI} || ${HAVE_PLAINCGI}) ; then
39 AC_MSG_ERROR([not a single CGI interface supported in kingate]) 39 AC_MSG_ERROR([not a single CGI interface supported in kingate])
40fi 40fi
41AM_CONDITIONAL([HAVE_FCGI],[${HAVE_FCGI}]) 41AM_CONDITIONAL([HAVE_FCGI],[${HAVE_FCGI}])
42AM_CONDITIONAL([HAVE_PLAINCGI],[${HAVE_PLAINCGI}]) 42AM_CONDITIONAL([HAVE_PLAINCGI],[${HAVE_PLAINCGI}])
43 43
44PKG_CHECK_MODULES([DOTCONF],[dotconf],,[ 44PKG_CHECK_MODULES([DOTCONF],[dotconf],,[
45 AC_MSG_ERROR([no dotconf library found]) 45 AC_MSG_ERROR([no dotconf library found])
46]) 46])
47 47
48AC_WITH_PCRE([ 48AC_WITH_PCRE([
49 AC_WITH_PCREPP(,[ 49 AC_WITH_PCREPP(,[
50 AC_MSG_ERROR([no pcre++ library found]) 50 AC_MSG_ERROR([no pcre++ library found])
51 ]) 51 ])
52],[ 52],[
53 AC_MSG_ERROR([no pcre library found]) 53 AC_MSG_ERROR([no pcre library found])
54]) 54])
55 55
56AC_CHECK_FUNC([dlopen],,[ 56AC_CHECK_FUNC([dlopen],,[
57 AC_CHECK_LIB([dl],[dlopen],,[ 57 AC_CHECK_LIB([dl],[dlopen],,[
58 AC_MSG_ERROR([no dlopen library found]) 58 AC_MSG_ERROR([no dlopen library found])
59 ]) 59 ])
60]) 60])
61 61
62AC_PATH_PROG([XSLTPROC],[xsltproc],[true]) 62AC_PATH_PROG([XSLTPROC],[xsltproc],[true])
63 63
64WANT_DOXYGEN="yes" 64WANT_DOXYGEN="yes"
65AC_ARG_ENABLE([doxygen], 65AC_ARG_ENABLE([doxygen],
66 AC_HELP_STRING([--disable-doxygen],[do not generate documentation]), 66 AC_HELP_STRING([--disable-doxygen],[do not generate documentation]),
67 [ 67 [
68 test "${enableval}" = "no" && WANT_DOXYGEN="no" 68 test "${enableval}" = "no" && WANT_DOXYGEN="no"
69 ] 69 ]
70) 70)
71if test "${WANT_DOXYGEN}" = "yes" ; then 71if test "${WANT_DOXYGEN}" = "yes" ; then
72 AC_WITH_DOXYGEN 72 AC_WITH_DOXYGEN
73 AC_WITH_DOT 73 AC_WITH_DOT
74else 74else
75 AM_CONDITIONAL([HAVE_DOXYGEN],[false]) 75 AM_CONDITIONAL([HAVE_DOXYGEN],[false])
76 AM_CONDITIONAL([HAVE_DOT],[false]) 76 AM_CONDITIONAL([HAVE_DOT],[false])
77fi 77fi
78 78
79AC_CONFIG_FILES([ 79AC_CONFIG_FILES([
80 Makefile 80 Makefile
81 Doxyfile 81 Doxyfile
diff --git a/lib/component_factory.cc b/lib/component_factory.cc
index b5e95af..d9692de 100644
--- a/lib/component_factory.cc
+++ b/lib/component_factory.cc
@@ -47,97 +47,97 @@ namespace sitecing {
47 for(list<string>::const_iterator i=co_so_deps->so_deps.begin();i!=co_so_deps->so_deps.end();++i) 47 for(list<string>::const_iterator i=co_so_deps->so_deps.begin();i!=co_so_deps->so_deps.end();++i)
48 deps.push_back(*i); 48 deps.push_back(*i);
49 } 49 }
50 return; 50 return;
51 }catch(utility_no_prefix& unp) { 51 }catch(utility_no_prefix& unp) {
52 throw konforka::exception(CODEPOINT,"component is outside of component root"); 52 throw konforka::exception(CODEPOINT,"component is outside of component root");
53 }catch(utility_no_suffix& uns) { } 53 }catch(utility_no_suffix& uns) { }
54 try { 54 try {
55 // preprocessor targets 55 // preprocessor targets
56 string noro = strip_prefix(dp,root_intermediate); 56 string noro = strip_prefix(dp,root_intermediate);
57 for(int ppt=0;ppt<sizeof(pp_targets)/sizeof(*pp_targets);ppt++) { 57 for(int ppt=0;ppt<sizeof(pp_targets)/sizeof(*pp_targets);ppt++) {
58 try { 58 try {
59 string nos = strip_suffix(noro,pp_targets[ppt]); 59 string nos = strip_suffix(noro,pp_targets[ppt]);
60 deps.push_back(root_source+nos); // depends on the source 60 deps.push_back(root_source+nos); // depends on the source
61 ifstream imports((root_intermediate+nos+".imports").c_str(),ios::in); 61 ifstream imports((root_intermediate+nos+".imports").c_str(),ios::in);
62 if(imports.good()) { 62 if(imports.good()) {
63 string str; 63 string str;
64 while(!imports.eof()) { 64 while(!imports.eof()) {
65 imports >> str; 65 imports >> str;
66 if(!str.empty()) 66 if(!str.empty())
67 deps.push_back(root_intermediate+str+".classname"); 67 deps.push_back(root_intermediate+str+".classname");
68 } 68 }
69 } 69 }
70 ifstream ancestors((root_intermediate+nos+".ancestors").c_str(),ios::in); 70 ifstream ancestors((root_intermediate+nos+".ancestors").c_str(),ios::in);
71 if(ancestors.good()) { 71 if(ancestors.good()) {
72 string str; 72 string str;
73 while(!ancestors.eof()) { 73 while(!ancestors.eof()) {
74 ancestors >> str; 74 ancestors >> str;
75 if(!str.empty()) 75 if(!str.empty())
76 deps.push_back(root_intermediate+str+".classname"); 76 deps.push_back(root_intermediate+str+".classname");
77 } 77 }
78 } 78 }
79 // XXX: intermediate_deps should be broken down 79 // XXX: intermediate_deps should be broken down
80 config_options *co_intermediate_deps = config.lookup_config(nos,config_options::flag_intermediate_deps); 80 config_options *co_intermediate_deps = config.lookup_config(nos,config_options::flag_intermediate_deps);
81 if(co_intermediate_deps) { 81 if(co_intermediate_deps) {
82 for(list<string>::const_iterator i=co_intermediate_deps->intermediate_deps.begin();i!=co_intermediate_deps->intermediate_deps.end();++i) 82 for(list<string>::const_iterator i=co_intermediate_deps->intermediate_deps.begin();i!=co_intermediate_deps->intermediate_deps.end();++i)
83 deps.push_back(*i); 83 deps.push_back(*i);
84 } 84 }
85 return; 85 return;
86 }catch(utility_no_suffix& uns) { } 86 }catch(utility_no_suffix& uns) { }
87 } 87 }
88 // compiler targets 88 // compiler targets
89 for(int cct=0;cct<sizeof(cc_targets)/sizeof(*cc_targets);cct++) { 89 for(int cct=0;cct<sizeof(cc_targets)/sizeof(*cc_targets);cct++) {
90 try { 90 try {
91 string nos = strip_suffix(noro,cc_targets[cct]); 91 string nos = strip_suffix(noro,cc_targets[cct]);
92 deps.push_back(root_intermediate+nos+".cc"); 92 deps.push_back(root_intermediate+nos+".cc");
93 config_options *co_cpp_deps = config.lookup_config(noro,config_options::flag_cpp_deps); 93 config_options *co_cpp_deps = config.lookup_config(noro,config_options::flag_cpp_deps);
94 if( (!co_cpp_deps) || co_cpp_deps->cpp_deps) { 94 if( (!co_cpp_deps) || co_cpp_deps->cpp_deps) {
95 ifstream df((root_intermediate+noro+".d").c_str(),ios::in); 95 ifstream df((root_intermediate+nos+".d").c_str(),ios::in);
96 if(df.good()) { 96 if(df.good()) {
97 string str; 97 string str;
98 while(!df.eof()) { 98 while(!df.eof()) {
99 df >> str; 99 df >> str;
100 if(str.find_first_of("\\:")==string::npos) 100 if(str.find_first_of("\\:")==string::npos)
101 deps.push_back(combine_path(config.root_source+nos,str)); 101 deps.push_back(combine_path(config.root_source+nos,str));
102 } 102 }
103 } 103 }
104 } 104 }
105 // XXX: intermediate_deps should be broken down 105 // XXX: intermediate_deps should be broken down
106 config_options *co_intermediate_deps = config.lookup_config(nos,config_options::flag_intermediate_deps); 106 config_options *co_intermediate_deps = config.lookup_config(nos,config_options::flag_intermediate_deps);
107 if(co_intermediate_deps) { 107 if(co_intermediate_deps) {
108 for(list<string>::const_iterator i=co_intermediate_deps->intermediate_deps.begin();i!=co_intermediate_deps->intermediate_deps.end();++i) 108 for(list<string>::const_iterator i=co_intermediate_deps->intermediate_deps.begin();i!=co_intermediate_deps->intermediate_deps.end();++i)
109 deps.push_back(*i); 109 deps.push_back(*i);
110 } 110 }
111 }catch(utility_no_suffix& uns) { } 111 }catch(utility_no_suffix& uns) { }
112 } 112 }
113 }catch(utility_no_prefix& unp) { } 113 }catch(utility_no_prefix& unp) { }
114 } 114 }
115 115
116 bool component_factory::is_uptodate(const string& dst,file_list_t *deps) { 116 bool component_factory::is_uptodate(const string& dst,file_list_t *deps) {
117 string dp = normalize_path(dst,strip_trailing_slash); 117 string dp = normalize_path(dst,strip_trailing_slash);
118 try { 118 try {
119 string noro = strip_prefix(dp,root_intermediate); 119 string noro = strip_prefix(dp,root_intermediate);
120 for(int ppt=0;(ppt+1)<sizeof(pp_targets)/sizeof(*pp_targets);ppt++) { 120 for(int ppt=0;(ppt+1)<sizeof(pp_targets)/sizeof(*pp_targets);ppt++) {
121 try { 121 try {
122 string nos = strip_suffix(noro,pp_targets[ppt]); 122 string nos = strip_suffix(noro,pp_targets[ppt]);
123 return file_factory::is_uptodate(root_intermediate+nos+".pp_stamp",deps); 123 return file_factory::is_uptodate(root_intermediate+nos+".pp_stamp",deps);
124 }catch(utility_no_suffix& uns) { } 124 }catch(utility_no_suffix& uns) { }
125 } 125 }
126 bool rv = file_factory::is_uptodate(dst,deps); 126 bool rv = file_factory::is_uptodate(dst,deps);
127 return rv; 127 return rv;
128 }catch(utility_no_prefix& unp) { } 128 }catch(utility_no_prefix& unp) { }
129 // XXX: or just compare it off, instead of throwing things around. 129 // XXX: or just compare it off, instead of throwing things around.
130 try { 130 try {
131 strip_prefix(dp,root_so); 131 strip_prefix(dp,root_so);
132 return file_factory::is_uptodate(dst,deps); 132 return file_factory::is_uptodate(dst,deps);
133 }catch(utility_no_prefix& unp) { } 133 }catch(utility_no_prefix& unp) { }
134 return true; 134 return true;
135 } 135 }
136 136
137 void component_factory::build(const string& dst) { 137 void component_factory::build(const string& dst) {
138 string dp = normalize_path(dst,strip_trailing_slash); 138 string dp = normalize_path(dst,strip_trailing_slash);
139 // sources 139 // sources
140 try { 140 try {
141 string noro = strip_prefix(dp,root_source); 141 string noro = strip_prefix(dp,root_source);
142 // building the sources is left up to developer 142 // building the sources is left up to developer
143 return; 143 return;
diff --git a/lib/file_factory.cc b/lib/file_factory.cc
index 7ca7b86..c22fac2 100644
--- a/lib/file_factory.cc
+++ b/lib/file_factory.cc
@@ -1,56 +1,56 @@
1#ifdef USE_PCH 1#ifdef USE_PCH
2 #include "pch.h" 2 #include "pch.h"
3#else 3#else
4 #include <sys/types.h> 4 #include <sys/types.h>
5 #include <sys/stat.h> 5 #include <sys/stat.h>
6 #include <unistd.h> 6 #include <unistd.h>
7 #include <konforka/exception.h> 7 #include <konforka/exception.h>
8 using namespace std; 8 using namespace std;
9 #include "sitecing/file_factory.h" 9 #include "sitecing/file_factory.h"
10#endif 10#endif
11 11
12namespace sitecing { 12namespace sitecing {
13 13
14 bool file_factory::is_uptodate(const string& dst,file_list_t* deps) { 14 bool file_factory::is_uptodate(const string& dst,file_list_t* deps) {
15 file_list_t deplist; 15 file_list_t deplist;
16 file_list_t *fl = deps?deps:&deplist; 16 file_list_t *fl = deps?deps:&deplist;
17 get_dependencies(dst,*fl); 17 get_dependencies(dst,*fl);
18 struct stat stdst; 18 struct stat stdst;
19 if(stat(dst.c_str(),&stdst)) 19 if(stat(dst.c_str(),&stdst))
20 return false; 20 return false;
21 for(file_list_t::const_iterator i=fl->begin();i!=fl->end();i++) { 21 for(file_list_t::const_iterator i=fl->begin();i!=fl->end();++i) {
22 struct stat stdep; 22 struct stat stdep;
23 if(stat(i->c_str(),&stdep)) 23 if(stat(i->c_str(),&stdep))
24 return false; 24 return false;
25 if(stdst.st_mtime<stdep.st_mtime) 25 if(stdst.st_mtime<stdep.st_mtime)
26 return false; 26 return false;
27 if(!is_uptodate(*i)) 27 if(!is_uptodate(*i))
28 return false; 28 return false;
29 } 29 }
30 return true; 30 return true;
31 } 31 }
32 32
33 void file_factory::make(const string& dst) { 33 void file_factory::make(const string& dst) {
34 try { 34 try {
35 depth++; 35 depth++;
36 if(depth>25) 36 if(depth>25)
37 throw konforka::exception(CODEPOINT,"recursed too deeply."); 37 throw konforka::exception(CODEPOINT,"recursed too deeply.");
38 file_list_t deps; 38 file_list_t deps;
39 if(!is_uptodate(dst,&deps)) { 39 if(!is_uptodate(dst,&deps)) {
40 for(file_list_t::const_iterator i=deps.begin();i!=deps.end();i++) 40 for(file_list_t::const_iterator i=deps.begin();i!=deps.end();i++)
41 make(*i); 41 make(*i);
42 if(!is_uptodate(dst,&deps)) 42 if(!is_uptodate(dst,&deps))
43 build(dst); 43 build(dst);
44 } 44 }
45 depth--; 45 depth--;
46 }catch(konforka::exception& ke) { 46 }catch(konforka::exception& ke) {
47 depth--; 47 depth--;
48 ke.see(CODEPOINT); 48 ke.see(CODEPOINT);
49 throw; 49 throw;
50 }catch(...) { 50 }catch(...) {
51 depth--; 51 depth--;
52 throw; 52 throw;
53 } 53 }
54 } 54 }
55 55
56} 56}
diff --git a/src/sitecing-fastcgi.cc b/src/sitecing-fastcgi.cc
index 9c0d7d1..756dcee 100644
--- a/src/sitecing-fastcgi.cc
+++ b/src/sitecing-fastcgi.cc
@@ -122,105 +122,108 @@ sitecing_fastcgi_pm::sitecing_fastcgi_pm(const string& config_file)
122 die_humbly=true; 122 die_humbly=true;
123 _exit(0); 123 _exit(0);
124 } 124 }
125 } 125 }
126 if(config.flags&configuration::flag_pid_file) { 126 if(config.flags&configuration::flag_pid_file) {
127 pidfile.set(config.pid_file); 127 pidfile.set(config.pid_file);
128 } 128 }
129 if(multi) 129 if(multi)
130 sem.init(); 130 sem.init();
131 } 131 }
132sitecing_fastcgi_pm::~sitecing_fastcgi_pm() { 132sitecing_fastcgi_pm::~sitecing_fastcgi_pm() {
133 if(fss) 133 if(fss)
134 delete fss; 134 delete fss;
135} 135}
136 136
137void sitecing_fastcgi_pm::process(int slot) { 137void sitecing_fastcgi_pm::process(int slot) {
138 signal(SIGINT,SIG_DFL); 138 signal(SIGINT,SIG_DFL);
139 signal(SIGABRT,SIG_DFL); 139 signal(SIGABRT,SIG_DFL);
140 signal(SIGTERM,SIG_DFL); 140 signal(SIGTERM,SIG_DFL);
141 give_up_privs(); 141 give_up_privs();
142 scoreboard_slot *sslot = sboard.get_slot(slot); 142 scoreboard_slot *sslot = sboard.get_slot(slot);
143 try { 143 try {
144 sitespace ss(config); 144 sitespace ss(config);
145 fcgi_socket& fs = *fss; 145 fcgi_socket& fs = *fss;
146 sitecing_interface_cgi scif(&ss); 146 sitecing_interface_cgi scif(&ss);
147 string component_path; 147 string component_path;
148 string action; 148 string action;
149 config_options::action_handler_t *action_handler; 149 config_options::action_handler_t *action_handler;
150 int rpc = 0; 150 int rpc = 0;
151 if(config.flags&configuration::flag_requests_per_child) 151 if(config.flags&configuration::flag_requests_per_child)
152 rpc = config.requests_per_child; 152 rpc = config.requests_per_child;
153 for(int req=0;(rpc<=0) || (req<rpc);rpc++) { 153 for(int req=0;(rpc<=0) || (req<rpc);rpc++) {
154 semaphore_lock sl; 154 semaphore_lock sl;
155 if(multi) { 155 if(multi) {
156 sslot->state = scoreboard_slot::state_idle; 156 sslot->state = scoreboard_slot::state_idle;
157 sl.sem = &sem; 157 sl.sem = &sem;
158 sl.lock(); 158 sl.lock();
159 } 159 }
160 sslot->state = scoreboard_slot::state_accept; 160 sslot->state = scoreboard_slot::state_accept;
161 fcgi_interface fi(fs); 161 fcgi_interface fi(fs);
162 sslot->state = scoreboard_slot::state_processing; 162 sslot->state = scoreboard_slot::state_processing;
163 if(multi) 163 if(multi)
164 sl.unlock(); 164 sl.unlock();
165 cgi_gateway gw(fi); 165 cgi_gateway gw(fi);
166 scif.prepare(&gw); 166 scif.prepare(&gw);
167 try { 167 try {
168 component_path = normalize_path(gw.path_info(),strip_leading_slash|strip_trailing_slash); 168 component_path = normalize_path(gw.path_info(),strip_leading_slash|strip_trailing_slash);
169 string full_component_path; 169 string full_component_path;
170 string sitecing_path_info;
170 while(true) { 171 while(true) {
171 full_component_path = config.root_source+'/'+component_path; 172 full_component_path = config.root_source+'/'+component_path;
172 if(!access(full_component_path.c_str(),F_OK)) 173 if(!access(full_component_path.c_str(),F_OK))
173 break; 174 break;
174 string::size_type sl = component_path.rfind('/'); 175 string::size_type sl = component_path.rfind('/');
175 if(sl==string::npos) 176 if(sl==string::npos)
176 throw konforka::exception(CODEPOINT,"can't find the target component"); 177 throw konforka::exception(CODEPOINT,"can't find the target component");
178 sitecing_path_info.insert(0,component_path,sl,string::npos);
177 component_path.erase(sl); 179 component_path.erase(sl);
178 } 180 }
181 fi.metavars["SITECING_PATH_INFO"]=sitecing_path_info;
179 action = component_path; 182 action = component_path;
180 action_handler = config.lookup_action_handler(component_path); 183 action_handler = config.lookup_action_handler(component_path);
181 if(action_handler) { 184 if(action_handler) {
182 action = action_handler->action; 185 action = action_handler->action;
183 } 186 }
184 string pwd = dir_name(full_component_path); 187 string pwd = dir_name(full_component_path);
185 if(chdir(pwd.c_str())) 188 if(chdir(pwd.c_str()))
186 throw konforka::exception(CODEPOINT,"failed to chdir() into document's directory"); 189 throw konforka::exception(CODEPOINT,"failed to chdir() into document's directory");
187 so_component soc = ss.fetch(action,&scif); 190 so_component soc = ss.fetch(action,&scif);
188 if(action_handler) { 191 if(action_handler) {
189 soc.ac->run(__magic_action, 192 soc.ac->run(__magic_action,
190 config.root_source.c_str(), config.root_intermediate.c_str(), config.root_so.c_str(), 193 config.root_source.c_str(), config.root_intermediate.c_str(), config.root_so.c_str(),
191 &(action_handler->args) 194 &(action_handler->args)
192 ); 195 );
193 }else{ 196 }else{
194 soc.ac->main(0,NULL); 197 soc.ac->main(0,NULL);
195 } 198 }
196 }catch(http_status& hs) { 199 }catch(http_status& hs) {
197 scif.headers["Status"] = hs.status+" "+hs.message; 200 scif.headers["Status"] = hs.status+" "+hs.message;
198 string hshp = config.lookup_http_status_handler(component_path,hs.status); 201 string hshp = config.lookup_http_status_handler(component_path,hs.status);
199 if(!hshp.empty()) { 202 if(!hshp.empty()) {
200 so_component hsh = ss.fetch(hshp,&scif); // TODO: handle error trying to handle status 203 so_component hsh = ss.fetch(hshp,&scif); // TODO: handle error trying to handle status
201 hsh.ac->run(__magic_http_status,config.root_source.c_str(),config.root_intermediate.c_str(), 204 hsh.ac->run(__magic_http_status,config.root_source.c_str(),config.root_intermediate.c_str(),
202 config.root_so.c_str(),action.c_str(),&hs); 205 config.root_so.c_str(),action.c_str(),&hs);
203 } 206 }
204 }catch(compile_error& ce) { 207 }catch(compile_error& ce) {
205 config_options *co_exception_handler = config.lookup_config(component_path,config_options::flag_exception_handler); 208 config_options *co_exception_handler = config.lookup_config(component_path,config_options::flag_exception_handler);
206 if(co_exception_handler) { 209 if(co_exception_handler) {
207 so_component eh = ss.fetch(co_exception_handler->exception_handler,&scif); // TODO: handle error trying to handle error. 210 so_component eh = ss.fetch(co_exception_handler->exception_handler,&scif); // TODO: handle error trying to handle error.
208 eh.ac->run(__magic_compile_error,ce.what(),config.root_source.c_str(),config.root_intermediate.c_str(),config.root_so.c_str(),ce.component_path.c_str()); 211 eh.ac->run(__magic_compile_error,ce.what(),config.root_source.c_str(),config.root_intermediate.c_str(),config.root_so.c_str(),ce.component_path.c_str());
209 }else{ 212 }else{
210 ce.see(CODEPOINT); 213 ce.see(CODEPOINT);
211 throw; 214 throw;
212 } 215 }
213 }catch(preprocessor_error& pe) { 216 }catch(preprocessor_error& pe) {
214 config_options *co_exception_handler = config.lookup_config(component_path,config_options::flag_exception_handler); 217 config_options *co_exception_handler = config.lookup_config(component_path,config_options::flag_exception_handler);
215 if(co_exception_handler) { 218 if(co_exception_handler) {
216 so_component eh = ss.fetch(co_exception_handler->exception_handler,&scif); // TODO: handle error trying to handle error. 219 so_component eh = ss.fetch(co_exception_handler->exception_handler,&scif); // TODO: handle error trying to handle error.
217 eh.ac->run(__magic_preprocess_error,pe.what(),config.root_source.c_str(),config.root_intermediate.c_str(),config.root_so.c_str(),pe.component_name.c_str(),pe.line_number); 220 eh.ac->run(__magic_preprocess_error,pe.what(),config.root_source.c_str(),config.root_intermediate.c_str(),config.root_so.c_str(),pe.component_name.c_str(),pe.line_number);
218 }else{ 221 }else{
219 pe.see(CODEPOINT); 222 pe.see(CODEPOINT);
220 throw; 223 throw;
221 } 224 }
222 }catch(exception& e) { 225 }catch(exception& e) {
223 config_options *co_exception_handler = config.lookup_config(component_path,config_options::flag_exception_handler); 226 config_options *co_exception_handler = config.lookup_config(component_path,config_options::flag_exception_handler);
224 if(co_exception_handler) { 227 if(co_exception_handler) {
225 so_component eh = ss.fetch(co_exception_handler->exception_handler,&scif); // TODO: handle error trying to handle error. 228 so_component eh = ss.fetch(co_exception_handler->exception_handler,&scif); // TODO: handle error trying to handle error.
226 eh.ac->run(__magic_generic_exception,e.what(),config.root_source.c_str(),config.root_intermediate.c_str(),config.root_so.c_str(),component_path.c_str(),&e); 229 eh.ac->run(__magic_generic_exception,e.what(),config.root_source.c_str(),config.root_intermediate.c_str(),config.root_so.c_str(),component_path.c_str(),&e);
diff --git a/src/sitecing-plaincgi.cc b/src/sitecing-plaincgi.cc
index 6e8a215..3bd291a 100644
--- a/src/sitecing-plaincgi.cc
+++ b/src/sitecing-plaincgi.cc
@@ -7,105 +7,108 @@
7#include <errno.h> 7#include <errno.h>
8#include <syslog.h> 8#include <syslog.h>
9#include <iostream> 9#include <iostream>
10#include <memory> 10#include <memory>
11#include <typeinfo> 11#include <typeinfo>
12using namespace std; 12using namespace std;
13#include "kingate/plaincgi.h" 13#include "kingate/plaincgi.h"
14#include "kingate/cgi_gateway.h" 14#include "kingate/cgi_gateway.h"
15using namespace kingate; 15using namespace kingate;
16#include "sitecing/sitecing_util.h" 16#include "sitecing/sitecing_util.h"
17#include "sitecing/util.h" 17#include "sitecing/util.h"
18#include "sitecing/sitespace.h" 18#include "sitecing/sitespace.h"
19#include "sitecing/sitecing_interface_cgi.h" 19#include "sitecing/sitecing_interface_cgi.h"
20#include "sitecing/cgi_component.h" 20#include "sitecing/cgi_component.h"
21#include "sitecing/configuration.h" 21#include "sitecing/configuration.h"
22#include "sitecing/magic.h" 22#include "sitecing/magic.h"
23#include "sitecing/sitecing_exception.h" 23#include "sitecing/sitecing_exception.h"
24#include "sitecing/exception.h" 24#include "sitecing/exception.h"
25using namespace sitecing; 25using namespace sitecing;
26 26
27#include "config.h" 27#include "config.h"
28#define PHEADER PACKAGE " Version " VERSION 28#define PHEADER PACKAGE " Version " VERSION
29#define PCOPY "Copyright (c) 2005 Klever Group" 29#define PCOPY "Copyright (c) 2005 Klever Group"
30 30
31class cdummyClass : public acomponent { 31class cdummyClass : public acomponent {
32 public: 32 public:
33 void main(int _magic,va_list _args) {} 33 void main(int _magic,va_list _args) {}
34 void *__the_most_derived_this() { return NULL; } 34 void *__the_most_derived_this() { return NULL; }
35} cdummyInstance; 35} cdummyInstance;
36class adummyClass : public cgi_component { 36class adummyClass : public cgi_component {
37 public: 37 public:
38 void main(int _magic,va_list _args) {} 38 void main(int _magic,va_list _args) {}
39 void *__the_most_derived_this() { return NULL; } 39 void *__the_most_derived_this() { return NULL; }
40} adummyInstance; 40} adummyInstance;
41 41
42void process_request(configuration& config) { 42void process_request(configuration& config) {
43 try { 43 try {
44 sitespace ss(config); 44 sitespace ss(config);
45 sitecing_interface_cgi scif(&ss); 45 sitecing_interface_cgi scif(&ss);
46 string component_path; 46 string component_path;
47 string action; 47 string action;
48 config_options::action_handler_t *action_handler; 48 config_options::action_handler_t *action_handler;
49 plaincgi_interface ci; 49 plaincgi_interface ci;
50 cgi_gateway gw(ci); 50 cgi_gateway gw(ci);
51 scif.prepare(&gw); 51 scif.prepare(&gw);
52 try { 52 try {
53 component_path = normalize_path(gw.path_info(),strip_leading_slash|strip_trailing_slash); 53 component_path = normalize_path(gw.path_info(),strip_leading_slash|strip_trailing_slash);
54 string full_component_path; 54 string full_component_path;
55 string sitecing_path_info;
55 while(true) { 56 while(true) {
56 full_component_path = config.root_source+'/'+component_path; 57 full_component_path = config.root_source+'/'+component_path;
57 if(!access(full_component_path.c_str(),F_OK)) 58 if(!access(full_component_path.c_str(),F_OK))
58 break; 59 break;
59 string::size_type sl = component_path.rfind('/'); 60 string::size_type sl = component_path.rfind('/');
60 if(sl==string::npos) 61 if(sl==string::npos)
61 throw konforka::exception(CODEPOINT,"can't find the target component"); 62 throw konforka::exception(CODEPOINT,"can't find the target component");
63 sitecing_path_info.insert(0,component_path,sl,string::npos);
62 component_path.erase(sl); 64 component_path.erase(sl);
63 } 65 }
66 ci.metavars["SITECING_PATH_INFO"]=sitecing_path_info;
64 action = component_path; 67 action = component_path;
65 action_handler = config.lookup_action_handler(component_path); 68 action_handler = config.lookup_action_handler(component_path);
66 if(action_handler) { 69 if(action_handler) {
67 action = action_handler->action; 70 action = action_handler->action;
68 } 71 }
69 string pwd = dir_name(full_component_path); 72 string pwd = dir_name(full_component_path);
70 if(chdir(pwd.c_str())) 73 if(chdir(pwd.c_str()))
71 throw konforka::exception(CODEPOINT,"failed to chdir() into document's directory"); 74 throw konforka::exception(CODEPOINT,"failed to chdir() into document's directory");
72 so_component soc = ss.fetch(action,&scif); 75 so_component soc = ss.fetch(action,&scif);
73 if(action_handler) { 76 if(action_handler) {
74 soc.ac->run(__magic_action, 77 soc.ac->run(__magic_action,
75 config.root_source.c_str(), config.root_intermediate.c_str(), config.root_so.c_str(), 78 config.root_source.c_str(), config.root_intermediate.c_str(), config.root_so.c_str(),
76 &(action_handler->args) 79 &(action_handler->args)
77 ); 80 );
78 }else{ 81 }else{
79 soc.ac->main(0,NULL); 82 soc.ac->main(0,NULL);
80 } 83 }
81 }catch(http_status& hs) { 84 }catch(http_status& hs) {
82 scif.headers["Status"] = hs.status+" "+hs.message; 85 scif.headers["Status"] = hs.status+" "+hs.message;
83 string hshp = config.lookup_http_status_handler(component_path,hs.status); 86 string hshp = config.lookup_http_status_handler(component_path,hs.status);
84 if(!hshp.empty()) { 87 if(!hshp.empty()) {
85 so_component hsh = ss.fetch(hshp,&scif); // TODO: handle error trying to handle status 88 so_component hsh = ss.fetch(hshp,&scif); // TODO: handle error trying to handle status
86 hsh.ac->run(__magic_http_status,config.root_source.c_str(),config.root_intermediate.c_str(), 89 hsh.ac->run(__magic_http_status,config.root_source.c_str(),config.root_intermediate.c_str(),
87 config.root_so.c_str(),action.c_str(),&hs); 90 config.root_so.c_str(),action.c_str(),&hs);
88 } 91 }
89 }catch(compile_error& ce) { 92 }catch(compile_error& ce) {
90 config_options *co_exception_handler = config.lookup_config(component_path,config_options::flag_exception_handler); 93 config_options *co_exception_handler = config.lookup_config(component_path,config_options::flag_exception_handler);
91 if(co_exception_handler) { 94 if(co_exception_handler) {
92 so_component eh = ss.fetch(co_exception_handler->exception_handler,&scif); // TODO: handle error trying to handle error. 95 so_component eh = ss.fetch(co_exception_handler->exception_handler,&scif); // TODO: handle error trying to handle error.
93 eh.ac->run(__magic_compile_error,ce.what(),config.root_source.c_str(),config.root_intermediate.c_str(),config.root_so.c_str(),ce.component_path.c_str()); 96 eh.ac->run(__magic_compile_error,ce.what(),config.root_source.c_str(),config.root_intermediate.c_str(),config.root_so.c_str(),ce.component_path.c_str());
94 }else{ 97 }else{
95 ce.see(CODEPOINT); 98 ce.see(CODEPOINT);
96 throw; 99 throw;
97 } 100 }
98 }catch(preprocessor_error& pe) { 101 }catch(preprocessor_error& pe) {
99 config_options *co_exception_handler = config.lookup_config(component_path,config_options::flag_exception_handler); 102 config_options *co_exception_handler = config.lookup_config(component_path,config_options::flag_exception_handler);
100 if(co_exception_handler) { 103 if(co_exception_handler) {
101 so_component eh = ss.fetch(co_exception_handler->exception_handler,&scif); // TODO: handle error trying to handle error. 104 so_component eh = ss.fetch(co_exception_handler->exception_handler,&scif); // TODO: handle error trying to handle error.
102 eh.ac->run(__magic_preprocess_error,pe.what(),config.root_source.c_str(),config.root_intermediate.c_str(),config.root_so.c_str(),pe.component_name.c_str(),pe.line_number); 105 eh.ac->run(__magic_preprocess_error,pe.what(),config.root_source.c_str(),config.root_intermediate.c_str(),config.root_so.c_str(),pe.component_name.c_str(),pe.line_number);
103 }else{ 106 }else{
104 pe.see(CODEPOINT); 107 pe.see(CODEPOINT);
105 throw; 108 throw;
106 } 109 }
107 }catch(exception& e) { 110 }catch(exception& e) {
108 config_options *co_exception_handler = config.lookup_config(component_path,config_options::flag_exception_handler); 111 config_options *co_exception_handler = config.lookup_config(component_path,config_options::flag_exception_handler);
109 if(co_exception_handler) { 112 if(co_exception_handler) {
110 so_component eh = ss.fetch(co_exception_handler->exception_handler,&scif); // TODO: handle error trying to handle error. 113 so_component eh = ss.fetch(co_exception_handler->exception_handler,&scif); // TODO: handle error trying to handle error.
111 eh.ac->run(__magic_generic_exception,e.what(),config.root_source.c_str(),config.root_intermediate.c_str(),config.root_so.c_str(),component_path.c_str(),&e); 114 eh.ac->run(__magic_generic_exception,e.what(),config.root_source.c_str(),config.root_intermediate.c_str(),config.root_so.c_str(),component_path.c_str(),&e);