-rw-r--r-- | src/Makefile.am | 12 | ||||
-rw-r--r-- | src/fastcgi.cc | 1 | ||||
-rw-r--r-- | src/plaincgi.cc | 27 |
3 files changed, 38 insertions, 2 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 8a5447b..e5c6778 100644 --- a/src/Makefile.am +++ b/src/Makefile.am | |||
@@ -1,15 +1,25 @@ | |||
1 | lib_LTLIBRARIES = libkingate.la libkingate-fcgi.la | 1 | lib_LTLIBRARIES = libkingate.la libkingate-plaincgi.la |
2 | |||
3 | if HAVE_FCGI | ||
4 | lib_LTLIBRARIES += libkingate-fcgi.la | ||
5 | endif | ||
2 | 6 | ||
3 | INCLUDES = -I${top_srcdir}/include | 7 | INCLUDES = -I${top_srcdir}/include |
4 | AM_CXXFLAGS = ${KONFORKA_CFLAGS} | 8 | AM_CXXFLAGS = ${KONFORKA_CFLAGS} |
5 | LDADD = ${KONFORKA_LIBS} | 9 | LDADD = ${KONFORKA_LIBS} |
6 | 10 | ||
7 | libkingate_la_SOURCES = \ | 11 | libkingate_la_SOURCES = \ |
8 | cgi_gateway.cc \ | 12 | cgi_gateway.cc \ |
9 | cgi_interface.cc \ | 13 | cgi_interface.cc \ |
10 | util.cc | 14 | util.cc |
11 | libkingate_la_LDFLAGS = -version-info 1:0:0 | 15 | libkingate_la_LDFLAGS = -version-info 1:0:0 |
12 | 16 | ||
13 | libkingate_fcgi_la_SOURCES = \ | 17 | libkingate_fcgi_la_SOURCES = \ |
14 | fastcgi.cc | 18 | fastcgi.cc |
15 | libkingate_fcgi_la_LDFLAGS = -version-info 1:0:0 | 19 | libkingate_fcgi_la_LDFLAGS = -version-info 1:0:0 |
20 | |||
21 | libkingate_plaincgi_la_SOURCES = \ | ||
22 | plaincgi.cc | ||
23 | libkingate_plaincgi_la_LDFLAGS = -version-info 1:0:0 | ||
24 | |||
25 | EXTRA_DIST = ${libkingate_fcgi_la_SOURCES} | ||
diff --git a/src/fastcgi.cc b/src/fastcgi.cc index 7484449..6285370 100644 --- a/src/fastcgi.cc +++ b/src/fastcgi.cc | |||
@@ -24,44 +24,43 @@ namespace kingate { | |||
24 | throw exception(CODEPOINT,"failed to chmod()"); | 24 | throw exception(CODEPOINT,"failed to chmod()"); |
25 | } | 25 | } |
26 | fcgi_socket::fcgi_socket(int s) | 26 | fcgi_socket::fcgi_socket(int s) |
27 | : sock(0) { | 27 | : sock(0) { |
28 | if(!_initialized) { | 28 | if(!_initialized) { |
29 | if( FCGX_Init() ) | 29 | if( FCGX_Init() ) |
30 | throw exception(CODEPOINT,"failed to FCGX_Init()"); | 30 | throw exception(CODEPOINT,"failed to FCGX_Init()"); |
31 | _initialized = true; | 31 | _initialized = true; |
32 | } | 32 | } |
33 | } | 33 | } |
34 | fcgi_socket::~fcgi_socket() { | 34 | fcgi_socket::~fcgi_socket() { |
35 | if(sock>=0) | 35 | if(sock>=0) |
36 | close(sock); | 36 | close(sock); |
37 | } | 37 | } |
38 | 38 | ||
39 | fcgi_interface::fcgi_interface(fcgi_socket& s,int f) | 39 | fcgi_interface::fcgi_interface(fcgi_socket& s,int f) |
40 | : sin(&sbin), sout(&sbout), serr(&sberr) { | 40 | : sin(&sbin), sout(&sbout), serr(&sberr) { |
41 | if( FCGX_InitRequest(&request,s.sock,f) ) | 41 | if( FCGX_InitRequest(&request,s.sock,f) ) |
42 | throw exception(CODEPOINT,"failed to FCGX_InitRequest()"); | 42 | throw exception(CODEPOINT,"failed to FCGX_InitRequest()"); |
43 | if( FCGX_Accept_r(&request) ) | 43 | if( FCGX_Accept_r(&request) ) |
44 | throw exception(CODEPOINT,"failed to FCGX_Accept_r()"); | 44 | throw exception(CODEPOINT,"failed to FCGX_Accept_r()"); |
45 | sbin.attach(request.in); | 45 | sbin.attach(request.in); |
46 | sbout.attach(request.out); | 46 | sbout.attach(request.out); |
47 | sberr.attach(request.err); | 47 | sberr.attach(request.err); |
48 | metavars.clear(); // XXX: redundant. | ||
49 | for(char **p = request.envp; *p; p++) { | 48 | for(char **p = request.envp; *p; p++) { |
50 | const char *e = strchr(*p,'='); | 49 | const char *e = strchr(*p,'='); |
51 | if(!e){ | 50 | if(!e){ |
52 | // XXX: check if we have it already? | 51 | // XXX: check if we have it already? |
53 | metavars[*p] = string(0); | 52 | metavars[*p] = string(0); |
54 | }else{ | 53 | }else{ |
55 | int l = e-*p; e++; | 54 | int l = e-*p; e++; |
56 | // XXX: check if we have it already? | 55 | // XXX: check if we have it already? |
57 | metavars[string(*p,l)]=e; | 56 | metavars[string(*p,l)]=e; |
58 | } | 57 | } |
59 | } | 58 | } |
60 | } | 59 | } |
61 | fcgi_interface::~fcgi_interface() { | 60 | fcgi_interface::~fcgi_interface() { |
62 | sout.flush(); | 61 | sout.flush(); |
63 | serr.flush(); | 62 | serr.flush(); |
64 | FCGX_Finish_r(&request); | 63 | FCGX_Finish_r(&request); |
65 | } | 64 | } |
66 | 65 | ||
67 | } | 66 | } |
diff --git a/src/plaincgi.cc b/src/plaincgi.cc new file mode 100644 index 0000000..6934748 --- a/dev/null +++ b/src/plaincgi.cc | |||
@@ -0,0 +1,27 @@ | |||
1 | #include <unistd.h> | ||
2 | #include <sys/types.h> | ||
3 | #include <sys/stat.h> | ||
4 | #include "kingate/plaincgi.h" | ||
5 | #include "kingate/exception.h" | ||
6 | |||
7 | namespace kingate { | ||
8 | |||
9 | plaincgi_interface::plaincgi_interface() { | ||
10 | for(char **p = environ; *p; p++) { | ||
11 | const char *e = strchr(*p,'='); | ||
12 | if(!e){ | ||
13 | // XXX: check if we have it already? | ||
14 | metavars[*p] = string(0); | ||
15 | }else{ | ||
16 | int l = e-*p; e++; | ||
17 | // XXX: check if we have it already? | ||
18 | metavars[string(*p,l)]=e; | ||
19 | } | ||
20 | } | ||
21 | } | ||
22 | plaincgi_interface::~plaincgi_interface() { | ||
23 | cout.flush(); | ||
24 | cerr.flush(); | ||
25 | } | ||
26 | |||
27 | } | ||