-rw-r--r-- | src/fastcgi.cc | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/src/fastcgi.cc b/src/fastcgi.cc index 8b7668c..5a6c081 100644 --- a/src/fastcgi.cc +++ b/src/fastcgi.cc | |||
@@ -1,69 +1,70 @@ | |||
1 | #include <unistd.h> | 1 | #include <unistd.h> |
2 | #include <sys/types.h> | 2 | #include <sys/types.h> |
3 | #include <sys/stat.h> | 3 | #include <sys/stat.h> |
4 | #include <cstring> | ||
4 | #include "kingate/fastcgi.h" | 5 | #include "kingate/fastcgi.h" |
5 | #include "kingate/exception.h" | 6 | #include "kingate/exception.h" |
6 | 7 | ||
7 | namespace kingate { | 8 | namespace kingate { |
8 | 9 | ||
9 | bool fcgi_socket::_initialized = false; | 10 | bool fcgi_socket::_initialized = false; |
10 | 11 | ||
11 | fcgi_socket::fcgi_socket(const char *s,int bl) | 12 | fcgi_socket::fcgi_socket(const char *s,int bl) |
12 | : sock(-1) { | 13 | : sock(-1) { |
13 | if(!_initialized) { | 14 | if(!_initialized) { |
14 | if( FCGX_Init() ) | 15 | if( FCGX_Init() ) |
15 | throw exception(CODEPOINT,"failed to FCGX_Init()"); | 16 | throw exception(CODEPOINT,"failed to FCGX_Init()"); |
16 | _initialized = true; | 17 | _initialized = true; |
17 | } | 18 | } |
18 | sock = FCGX_OpenSocket(s,bl); | 19 | sock = FCGX_OpenSocket(s,bl); |
19 | if(sock<0) | 20 | if(sock<0) |
20 | throw exception(CODEPOINT,"failed to FCGX_OpenSocket("); | 21 | throw exception(CODEPOINT,"failed to FCGX_OpenSocket("); |
21 | // TODO: check if there is a ':', not if it starts with ':' | 22 | // TODO: check if there is a ':', not if it starts with ':' |
22 | if(*s != ':') | 23 | if(*s != ':') |
23 | if(chmod(s,0777)) // XXX: configurable. | 24 | if(chmod(s,0777)) // XXX: configurable. |
24 | throw exception(CODEPOINT,"failed to chmod()"); | 25 | throw exception(CODEPOINT,"failed to chmod()"); |
25 | } | 26 | } |
26 | fcgi_socket::fcgi_socket(int s) | 27 | fcgi_socket::fcgi_socket(int s) |
27 | : sock(0) { | 28 | : sock(0) { |
28 | if(!_initialized) { | 29 | if(!_initialized) { |
29 | if( FCGX_Init() ) | 30 | if( FCGX_Init() ) |
30 | throw exception(CODEPOINT,"failed to FCGX_Init()"); | 31 | throw exception(CODEPOINT,"failed to FCGX_Init()"); |
31 | _initialized = true; | 32 | _initialized = true; |
32 | } | 33 | } |
33 | } | 34 | } |
34 | fcgi_socket::~fcgi_socket() { | 35 | fcgi_socket::~fcgi_socket() { |
35 | if(sock>=0) | 36 | if(sock>=0) |
36 | close(sock); | 37 | close(sock); |
37 | } | 38 | } |
38 | 39 | ||
39 | fcgi_interface::fcgi_interface(fcgi_socket& s,int f) | 40 | fcgi_interface::fcgi_interface(fcgi_socket& s,int f) |
40 | : sbin(buf_sbin,sizeof(buf_sbin)), | 41 | : sbin(buf_sbin,sizeof(buf_sbin)), |
41 | sbout(buf_sbout,sizeof(buf_sbout)), | 42 | sbout(buf_sbout,sizeof(buf_sbout)), |
42 | sberr(buf_sberr,sizeof(buf_sberr)), | 43 | sberr(buf_sberr,sizeof(buf_sberr)), |
43 | sin(&sbin), sout(&sbout), serr(&sberr) { | 44 | sin(&sbin), sout(&sbout), serr(&sberr) { |
44 | if( FCGX_InitRequest(&request,s.sock,f) ) | 45 | if( FCGX_InitRequest(&request,s.sock,f) ) |
45 | throw exception(CODEPOINT,"failed to FCGX_InitRequest()"); | 46 | throw exception(CODEPOINT,"failed to FCGX_InitRequest()"); |
46 | if( FCGX_Accept_r(&request) ) | 47 | if( FCGX_Accept_r(&request) ) |
47 | throw exception(CODEPOINT,"failed to FCGX_Accept_r()"); | 48 | throw exception(CODEPOINT,"failed to FCGX_Accept_r()"); |
48 | sbin.attach(request.in); | 49 | sbin.attach(request.in); |
49 | sbout.attach(request.out); | 50 | sbout.attach(request.out); |
50 | sberr.attach(request.err); | 51 | sberr.attach(request.err); |
51 | for(char **p = request.envp; *p; p++) { | 52 | for(char **p = request.envp; *p; p++) { |
52 | const char *e = strchr(*p,'='); | 53 | const char *e = strchr(*p,'='); |
53 | if(!e){ | 54 | if(!e){ |
54 | // XXX: check if we have it already? | 55 | // XXX: check if we have it already? |
55 | metavars[*p] = string(0); | 56 | metavars[*p] = string(0); |
56 | }else{ | 57 | }else{ |
57 | int l = e-*p; e++; | 58 | int l = e-*p; e++; |
58 | // XXX: check if we have it already? | 59 | // XXX: check if we have it already? |
59 | metavars[string(*p,l)]=e; | 60 | metavars[string(*p,l)]=e; |
60 | } | 61 | } |
61 | } | 62 | } |
62 | } | 63 | } |
63 | fcgi_interface::~fcgi_interface() { | 64 | fcgi_interface::~fcgi_interface() { |
64 | sout.flush(); | 65 | sout.flush(); |
65 | serr.flush(); | 66 | serr.flush(); |
66 | FCGX_Finish_r(&request); | 67 | FCGX_Finish_r(&request); |
67 | } | 68 | } |
68 | 69 | ||
69 | } | 70 | } |