From 9f1da374004be25348cfccb6608c32049d2b47d8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Wilfried=20G=C3=B6esgens?= Date: Sun, 31 May 2009 19:46:52 +0000 Subject: [PATCH] * start moving the hdr struct up, and add detach callback. Unfinished. --- webcit/auth.c | 10 ++++++++++ webcit/context_loop.c | 15 +++++++++++---- webcit/mk_module_init.sh | 31 +++++++++++++++++++++++++++++++ webcit/webserver.c | 12 ++++++++---- 4 files changed, 60 insertions(+), 8 deletions(-) diff --git a/webcit/auth.c b/webcit/auth.c index 22dbcfbf2..57f9b39a6 100644 --- a/webcit/auth.c +++ b/webcit/auth.c @@ -981,6 +981,16 @@ void Header_HandleCookie(StrBuf *Line, ParsedHttpHdrs *hdr) hdr->HR.got_auth = AUTH_COOKIE; } +void +HttpDetachModule_AUTH +(ParsedHttpHdrs *httpreq) +{ + FLUSHStrBuf(httpreq->c_username); + FLUSHStrBuf(httpreq->c_password); + FLUSHStrBuf(httpreq->c_roomname); + FLUSHStrBuf(httpreq->c_language); +} + void HttpDestroyModule_AUTH (ParsedHttpHdrs *httpreq) diff --git a/webcit/context_loop.c b/webcit/context_loop.c index 8dcd5d687..bce424d30 100644 --- a/webcit/context_loop.c +++ b/webcit/context_loop.c @@ -477,7 +477,6 @@ void context_loop(ParsedHttpHdrs *Hdr) ChrPtr(Hdr->this_page) ); session_detach_modules(Bogus); - http_destroy_modules(Hdr); session_destroy_modules(&Bogus); return; } @@ -504,7 +503,6 @@ void context_loop(ParsedHttpHdrs *Hdr) ChrPtr(Hdr->this_page) ); session_detach_modules(Static); - http_destroy_modules(Hdr); session_destroy_modules(&Static); return; } @@ -575,8 +573,6 @@ TODO HKEY("/static/nocookies.html?force_close_session=yes")); TheSession->Hdr = NULL; pthread_mutex_unlock(&TheSession->SessionMutex); /* unbind */ - - http_destroy_modules(Hdr); } void tmplput_nonce(StrBuf *Target, WCTemplputParams *TP) @@ -768,6 +764,17 @@ InitModule_CONTEXT +void +HttpDetachModule_CONTEXT +(ParsedHttpHdrs *httpreq) +{ + FlushStrBuf(httpreq->ReadBuf); + FlushStrBuf(httpreq->PlainArgs); + FlushStrBuf(httpreq->this_page); + DeleteHash(&httpreq->HTTPHeaders); + memset(&httpreq->HR, 0, sizeof(HdrRefs)); +} + void HttpDestroyModule_CONTEXT (ParsedHttpHdrs *httpreq) diff --git a/webcit/mk_module_init.sh b/webcit/mk_module_init.sh index 61fe9318a..17bf27298 100755 --- a/webcit/mk_module_init.sh +++ b/webcit/mk_module_init.sh @@ -43,6 +43,7 @@ SESS_ATTACH_FUNCS=`grep SessionAttachModule_ *.c |sed "s;.*:;;" |sort -u` SESS_DETACH_FUNCS=`grep SessionDetachModule_ *.c |sed "s;.*:;;" |sort -u` SESS_DESTROY_FUNCS=`grep SessionDestroyModule_ *.c |sed "s;.*:;;" |sort -u` +HTTP_DETACH_FUNCS=`grep HttpDetachModule_ *.c |sed "s;.*:;;" |sort -u` HTTP_DESTROY_FUNCS=`grep HttpDestroyModule_ *.c |sed "s;.*:;;" |sort -u` @@ -78,6 +79,7 @@ void session_attach_modules (wcsession *sess); void session_detach_modules (wcsession *sess); void session_destroy_modules (wcsession **sess); +void http_detach_modules (ParsedHttpHdrs *httpreq); void http_destroy_modules (ParsedHttpHdrs *httpreq); @@ -369,6 +371,35 @@ EOF +#******************************************************************************** +# DETACH-Httprequest module logic. +#******************************************************************************** +cat <> $C_FILE + +void http_detach_modules (ParsedHttpHdrs *httpreq) +{ +EOF + +for HOOK in $HTTP_DETACH_FUNCS; do +HOOKNAME=`echo $HOOK |sed "s;HttpDetachModule_;;"` +# Add this entry point to the .c file +cat <> $C_FILE +#ifdef DBG_PRINNT_HOOKS_AT_START + lprintf (CTDL_INFO, "Detaching $HOOKNAME\n"); +#endif + $HOOK(httpreq); +EOF +# Add this entry point to the .h file +cat <> $H_FILE +extern void $HOOK(ParsedHttpHdrs *httpreq); +EOF +done + +cat <>$C_FILE +} +EOF + + #******************************************************************************** # DESTROY-Httprequest module logic. #******************************************************************************** diff --git a/webcit/webserver.c b/webcit/webserver.c index 4479c0a5a..f72910f11 100644 --- a/webcit/webserver.c +++ b/webcit/webserver.c @@ -28,7 +28,7 @@ int follow_xff = 0; /* Follow X-Forwarded-For: header */ int home_specified = 0; /* did the user specify a homedir? */ int time_to_die = 0; /* Nonzero if server is shutting down */ int DisableGzip = 0; -extern void *context_loop(int*); +extern void *context_loop(ParsedHttpHdrs *Hdr); extern void *housekeeping_loop(void); extern pthread_mutex_t SessionListMutex; extern pthread_key_t MyConKey; @@ -623,6 +623,10 @@ void worker_entry(void) int ret; struct timeval tv; fd_set readset, tempset; + ParsedHttpHdrs Hdr; + + memset(&Hdr, 0, sizeof(ParsedHttpHdrs)); + Hdr.HR.eReqType = eGET; tv.tv_sec = 0; tv.tv_usec = 10000; @@ -722,9 +726,6 @@ void worker_entry(void) #endif if (fail_this_transaction == 0) { - ParsedHttpHdrs Hdr; - memset(&Hdr, 0, sizeof(ParsedHttpHdrs)); - Hdr.HR.eReqType = eGET; Hdr.http_sock = ssock; /* Perform an HTTP transaction... */ @@ -740,12 +741,15 @@ void worker_entry(void) /* ...and close the socket. */ if (Hdr.http_sock > 0) lingering_close(ssock); + http_detach_modules(&Hdr); + } } } while (!time_to_die); + http_destroy_modules(&Hdr); lprintf (1, "bye\n"); pthread_exit(NULL); } -- 2.30.2