summaryrefslogtreecommitdiffabout
path: root/src/fastcgi.cc
authorMichael Krelin <hacker@klever.net>2005-01-29 20:14:37 (UTC)
committer Michael Krelin <hacker@klever.net>2005-01-29 20:14:37 (UTC)
commitff4b919683537625f693eedf53006364d0f8444d (patch) (side-by-side diff)
tree4c19e38c0832b16b4ca98ae5af6542d932373eb1 /src/fastcgi.cc
parentf9a64a67c89a7566e63ed66c3a69c359abea4dfd (diff)
downloadkingate-0.0.zip
kingate-0.0.tar.gz
kingate-0.0.tar.bz2
initial commit into repository0.0
Diffstat (limited to 'src/fastcgi.cc') (more/less context) (ignore whitespace changes)
-rw-r--r--src/fastcgi.cc67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/fastcgi.cc b/src/fastcgi.cc
new file mode 100644
index 0000000..7484449
--- a/dev/null
+++ b/src/fastcgi.cc
@@ -0,0 +1,67 @@
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include "kingate/fastcgi.h"
+#include "kingate/exception.h"
+
+namespace kingate {
+
+ bool fcgi_socket::_initialized = false;
+
+ fcgi_socket::fcgi_socket(const char *s,int bl)
+ : sock(-1) {
+ if(!_initialized) {
+ if( FCGX_Init() )
+ throw exception(CODEPOINT,"failed to FCGX_Init()");
+ _initialized = true;
+ }
+ sock = FCGX_OpenSocket(s,bl);
+ if(sock<0)
+ throw exception(CODEPOINT,"failed to FCGX_OpenSocket(");
+ // TODO: check if there is a ':', not if it starts with ':'
+ if(*s != ':')
+ if(chmod(s,0777)) // XXX: configurable.
+ throw exception(CODEPOINT,"failed to chmod()");
+ }
+ fcgi_socket::fcgi_socket(int s)
+ : sock(0) {
+ if(!_initialized) {
+ if( FCGX_Init() )
+ throw exception(CODEPOINT,"failed to FCGX_Init()");
+ _initialized = true;
+ }
+ }
+ fcgi_socket::~fcgi_socket() {
+ if(sock>=0)
+ close(sock);
+ }
+
+ fcgi_interface::fcgi_interface(fcgi_socket& s,int f)
+ : sin(&sbin), sout(&sbout), serr(&sberr) {
+ if( FCGX_InitRequest(&request,s.sock,f) )
+ throw exception(CODEPOINT,"failed to FCGX_InitRequest()");
+ if( FCGX_Accept_r(&request) )
+ throw exception(CODEPOINT,"failed to FCGX_Accept_r()");
+ sbin.attach(request.in);
+ sbout.attach(request.out);
+ sberr.attach(request.err);
+ metavars.clear(); // XXX: redundant.
+ for(char **p = request.envp; *p; p++) {
+ const char *e = strchr(*p,'=');
+ if(!e){
+ // XXX: check if we have it already?
+ metavars[*p] = string(0);
+ }else{
+ int l = e-*p; e++;
+ // XXX: check if we have it already?
+ metavars[string(*p,l)]=e;
+ }
+ }
+ }
+ fcgi_interface::~fcgi_interface() {
+ sout.flush();
+ serr.flush();
+ FCGX_Finish_r(&request);
+ }
+
+}