From: Viktor M. <mih...@us...> - 2005-07-01 16:06:49
|
Update of /cvsroot/sblim/sfcb In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23391 Modified Files: control.c httpAdapter.c httpComm.c Log Message: Bugs fixed: 1230295, 1231019. Enhanced error reporting for SSL failures. Added configureable keep-alive support for HTTP daemon. Index: control.c =================================================================== RCS file: /cvsroot/sblim/sfcb/control.c,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- control.c 13 Jun 2005 12:50:33 -0000 1.9 +++ control.c 1 Jul 2005 16:06:39 -0000 1.10 @@ -75,6 +75,8 @@ {"useChunking", 2, "false"}, {"chunkSize", 1, "50000"}, + + {"keepaliveTimeout", 1, "15"}, {"providerSampleInterval", 1, "30"}, {"providerTimeoutInterval", 1, "60"}, Index: httpComm.c =================================================================== RCS file: /cvsroot/sblim/sfcb/httpComm.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- httpComm.c 30 Jun 2005 11:36:08 -0000 1.4 +++ httpComm.c 1 Jul 2005 16:06:40 -0000 1.5 @@ -25,8 +25,7 @@ #if defined USE_SSL void handleSSLerror(const char *file, int lineno, const char *msg) { - fprintf(stderr, "** %s:%i %s\n", file, lineno, msg); - ERR_print_errors_fp(stderr); + mlogf(M_ERROR,M_SHOW,"\n*** %s:%i %s -- exiting\n", file, lineno, msg); exit(-1); } #endif Index: httpAdapter.c =================================================================== RCS file: /cvsroot/sblim/sfcb/httpAdapter.c,v retrieving revision 1.13 retrieving revision 1.14 diff -u -d -r1.13 -r1.14 --- httpAdapter.c 26 Jun 2005 21:52:08 -0000 1.13 +++ httpAdapter.c 1 Jul 2005 16:06:39 -0000 1.14 @@ -64,6 +64,7 @@ static int httpProcId; static int stopAccepting=0; static int running=0; +static long keepaliveTimeout=15; #if defined USE_SSL SSL_CTX *ctx; @@ -573,7 +574,7 @@ return 0; } -static void doHttpRequest(CommHndl conn_fd) +static int doHttpRequest(CommHndl conn_fd) { char *cp; Buffer inBuf = { NULL, NULL, 0, 0, 0, 0, 0 ,0}; @@ -597,7 +598,12 @@ int badReq = 0; getHdrs(conn_fd, &inBuf); - + if (inBuf.size == 0) { + /* no buffer data - end of file - quit */ + _SFCB_TRACE(1,("--- HTTP connection EOF, quit %d ", currentProc)); + _SFCB_RETURN(1); + } + inBuf.httpHdr = getNextHdr(&inBuf); for (badReq = 1;;) { if (inBuf.httpHdr == NULL) @@ -705,25 +711,20 @@ //commClose(conn_fd); -#if defined USE_SSL - if (sfcbSSLMode) { - if ((SSL_get_shutdown(conn_fd.ssl) & SSL_RECEIVED_SHUTDOWN)) - SSL_shutdown(conn_fd.ssl); - else SSL_clear(conn_fd.ssl); - SSL_free(conn_fd.ssl); - } -#endif freeBuffer(&inBuf); - _SFCB_EXIT(); + _SFCB_RETURN(0); } static void handleHttpRequest(int connFd) { int r; CommHndl conn_fd; + int isReady; + fd_set httpfds; struct sembuf procReleaseUnDo = {0,1,SEM_UNDO}; - + struct timeval httpTimeout; + _SFCB_ENTER(TRACE_HTTPDAEMON, "handleHttpRequest"); _SFCB_TRACE(1, ("--- Forking xml handler")); @@ -745,25 +746,6 @@ semReleaseUnDo(httpProcSem,httpProcId+1); semRelease(httpWorkSem,0); - if (sfcbSSLMode) { -#if defined USE_SSL - conn_fd.socket=-2; - conn_fd.bio=BIO_new(BIO_s_socket()); - BIO_set_fd(conn_fd.bio,connFd,BIO_CLOSE); - if (!(conn_fd.ssl = SSL_new(ctx))) - intSSLerror("Error creating SSL context"); - SSL_set_bio(conn_fd.ssl, conn_fd.bio, conn_fd.bio); - if (SSL_accept(conn_fd.ssl) <= 0) - intSSLerror("Error accepting SSL connection"); -#endif - } - else { - conn_fd.socket=connFd; -#if defined USE_SSL - conn_fd.bio=NULL; - conn_fd.ssl=NULL; -#endif - } } else if (r>0) { running++; @@ -791,14 +773,59 @@ fprintf(stderr,"-#- Pausing - pid: %d\n",currentProc); sleep(5); } - + conn_fd.socket=connFd; + if (sfcbSSLMode) { #if defined USE_SSL - conn_fd.bio=NULL; - conn_fd.ssl=NULL; + conn_fd.bio=BIO_new(BIO_s_socket()); + BIO_set_fd(conn_fd.bio,connFd,BIO_CLOSE); + if (!(conn_fd.ssl = SSL_new(ctx))) + intSSLerror("Error creating SSL object"); + SSL_set_bio(conn_fd.ssl, conn_fd.bio, conn_fd.bio); + if (SSL_accept(conn_fd.ssl) <= 0) + intSSLerror("Error accepting SSL connection"); +#endif + } else { +#if defined USE_SSL + conn_fd.bio=NULL; + conn_fd.ssl=NULL; #endif + } + + FD_ZERO(&httpfds); + FD_SET(conn_fd.socket,&httpfds); + do { + if (doHttpRequest(conn_fd)) { + /* eof reached - leave */ + break; + } + if (keepaliveTimeout==0) { + /* we don't support persistence - quit */ + break; + } + /* wait for next request or timeout */ + httpTimeout.tv_sec=keepaliveTimeout; + httpTimeout.tv_usec=keepaliveTimeout; + isReady = select(conn_fd.socket+1,&httpfds,NULL,NULL,&httpTimeout); + if (isReady == 0) { + _SFCB_TRACE(1,("--- HTTP connection timeout, quit %d ", currentProc)); + break; + } else if (isReady < 0) { + _SFCB_TRACE(1,("--- HTTP connection error, quit %d ", currentProc)); + break; + } + } while (1); - doHttpRequest(conn_fd); +#if defined USE_SSL + if (sfcbSSLMode) { + if ((SSL_get_shutdown(conn_fd.ssl) & SSL_RECEIVED_SHUTDOWN)) + SSL_shutdown(conn_fd.ssl); + else SSL_clear(conn_fd.ssl); + SSL_free(conn_fd.ssl); + } else { + close(conn_fd.socket); + } +#endif if (!doFork) return; @@ -848,6 +875,9 @@ if (getControlBool("doBasicAuth", &doBa)) doBa=0; + if (getControlNum("keepaliveTimeout", &keepaliveTimeout)) + keepaliveTimeout = 15; + i = 1; while (i < argc && argv[i][0] == '-') { if (strcmp(argv[i], "-D") == 0) @@ -889,6 +919,12 @@ if (doBa) mlogf(M_INFO,M_SHOW,"--- Using Basic Authentication\n"); + if (keepaliveTimeout == 0) { + mlogf(M_INFO,M_SHOW,"--- Keep-alive timeout disabled\n"); + } else { + mlogf(M_INFO,M_SHOW,"--- Keep-alive timeout %ld seconds\n",keepaliveTimeout); + } + listenFd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); sin_len = sizeof(sin); |