* finish migrating the hdr struct
[citadel.git] / webcit / context_loop.c
index 7bcf36702f7d44a6601b876058b1b1f87b8548c8..d930fd271fc8ae48bf44cc98869de79372362fd7 100644 (file)
@@ -276,17 +276,17 @@ int ReadHttpSubject(ParsedHttpHdrs *Hdr, StrBuf *Line, StrBuf *Buf)
                return 1;
        }
 
-       Hdr->this_page = NewStrBufDup(Hdr->HR.ReqLine);
+       StrBufAppendBuf(Hdr->this_page, Hdr->HR.ReqLine, 0);
        /* chop Filename / query arguments */
        Args = strchr(ChrPtr(Hdr->HR.ReqLine), '?');
        if (Args == NULL) /* whe're not that picky about params... TODO: this will spoil '&' in filenames.*/
                Args = strchr(ChrPtr(Hdr->HR.ReqLine), '&');
        if (Args != NULL) {
                Args ++; /* skip the ? */
-               Hdr->PlainArgs = NewStrBufPlain(
-                       Args, 
-                       StrLength(Hdr->HR.ReqLine) -
-                       (Args - ChrPtr(Hdr->HR.ReqLine)));
+               StrBufPlain(Hdr->PlainArgs, 
+                           Args, 
+                           StrLength(Hdr->HR.ReqLine) -
+                           (Args - ChrPtr(Hdr->HR.ReqLine)));
                StrBufCutAt(Hdr->HR.ReqLine, 0, Args - 1);
        } /* don't parse them yet, maybe we don't even care... */
        
@@ -358,7 +358,6 @@ int ReadHTTPRequset (ParsedHttpHdrs *Hdr)
        int isbogus = 0;
 
        HeaderName = NewStrBuf();
-       Hdr->ReadBuf = NewStrBuf();
        LastLine = NULL;
        do {
                nLine ++;
@@ -470,8 +469,13 @@ void context_loop(ParsedHttpHdrs *Hdr)
 
                do_404();
 
+               lprintf(9, "HTTP: 404 [%ld.%06ld] %s %s \n",
+                       ((tx_finish.tv_sec*1000000 + tx_finish.tv_usec) - (tx_start.tv_sec*1000000 + tx_start.tv_usec)) / 1000000,
+                       ((tx_finish.tv_sec*1000000 + tx_finish.tv_usec) - (tx_start.tv_sec*1000000 + tx_start.tv_usec)) % 1000000,
+                       ReqStrs[Hdr->HR.eReqType],
+                       ChrPtr(Hdr->this_page)
+                       );
                session_detach_modules(Bogus);
-               http_destroy_modules(Hdr);
                session_destroy_modules(&Bogus);
                return;
        }
@@ -487,14 +491,17 @@ void context_loop(ParsedHttpHdrs *Hdr)
                /* How long did this transaction take? */
                gettimeofday(&tx_finish, NULL);
                
-               lprintf(9, "SL: Transaction [%s] completed in %ld.%06ld seconds.\n",
-                       ChrPtr(Hdr->this_page),
-                       ((tx_finish.tv_sec*1000000 + tx_finish.tv_usec) - (tx_start.tv_sec*1000000 + tx_start.tv_usec)) / 1000000,
-                       ((tx_finish.tv_sec*1000000 + tx_finish.tv_usec) - (tx_start.tv_sec*1000000 + tx_start.tv_usec)) % 1000000
-                       );
-
+#ifdef TECH_PREVIEW
+               if ((Hdr->HR.Handler == NULL) ||
+                   ((Hdr->HR.Handler->Flags & LOGCHATTY) == 0))
+#endif
+                       lprintf(9, "HTTP: 200 [%ld.%06ld] %s %s \n",
+                               ((tx_finish.tv_sec*1000000 + tx_finish.tv_usec) - (tx_start.tv_sec*1000000 + tx_start.tv_usec)) / 1000000,
+                               ((tx_finish.tv_sec*1000000 + tx_finish.tv_usec) - (tx_start.tv_sec*1000000 + tx_start.tv_usec)) % 1000000,
+                               ReqStrs[Hdr->HR.eReqType],
+                               ChrPtr(Hdr->this_page)
+                               );
                session_detach_modules(Static);
-               http_destroy_modules(Hdr);
                session_destroy_modules(&Static);
                return;
        }
@@ -508,22 +515,6 @@ TODO    HKEY("/static/nocookies.html?force_close_session=yes"));
 
 /*     dbg_PrintHash(HTTPHeaders, nix, NULL);  */
 
-
-       /* Begin parsing the request. * /
-#ifdef TECH_PREVIEW
-       if ((strncmp(ChrPtr(ReqLine), "/sslg", 5) != 0) &&
-           (strncmp(ChrPtr(ReqLine), "/static/", 8) != 0) &&
-           (strncmp(ChrPtr(ReqLine), "/tiny_mce/", 10) != 0) &&
-           (strncmp(ChrPtr(ReqLine), "/wholist_section", 16) != 0) &&
-           (strstr(ChrPtr(ReqLine), "wholist_section") == NULL)) {
-#endif
-               lprintf(5, "HTTP: %s %s\n", ReqStrs[Hdr.eReqType], ChrPtr(ReqLine));
-#ifdef TECH_PREVIEW
-       }
-#endif
-
-*/
-
        /**
         * See if there's an existing session open with the desired ID or user/pass
         */
@@ -567,18 +558,20 @@ TODO    HKEY("/static/nocookies.html?force_close_session=yes"));
        /* How long did this transaction take? */
        gettimeofday(&tx_finish, NULL);
        
-       lprintf(9, "Transaction [%s] completed in %ld.%06ld seconds.\n",
-               ChrPtr(Hdr->this_page),
-               ((tx_finish.tv_sec*1000000 + tx_finish.tv_usec) - (tx_start.tv_sec*1000000 + tx_start.tv_usec)) / 1000000,
-               ((tx_finish.tv_sec*1000000 + tx_finish.tv_usec) - (tx_start.tv_sec*1000000 + tx_start.tv_usec)) % 1000000
-       );
+
+       if ((Hdr->HR.Handler == NULL) ||
+           ((Hdr->HR.Handler->Flags & LOGCHATTY) == 0))
+               lprintf(9, "HTTP: 200 [%ld.%06ld] %s %s \n",
+                       ((tx_finish.tv_sec*1000000 + tx_finish.tv_usec) - (tx_start.tv_sec*1000000 + tx_start.tv_usec)) / 1000000,
+                       ((tx_finish.tv_sec*1000000 + tx_finish.tv_usec) - (tx_start.tv_sec*1000000 + tx_start.tv_usec)) % 1000000,
+                       ReqStrs[Hdr->HR.eReqType],
+                       ChrPtr(Hdr->this_page)
+                       );
 
        session_detach_modules(TheSession);
 
        TheSession->Hdr = NULL;
        pthread_mutex_unlock(&TheSession->SessionMutex);        /* unbind */
-
-       http_destroy_modules(Hdr);
 }
 
 void tmplput_nonce(StrBuf *Target, WCTemplputParams *TP)
@@ -769,14 +762,35 @@ InitModule_CONTEXT
 }
        
 
+void 
+HttpNewModule_CONTEXT
+(ParsedHttpHdrs *httpreq)
+{
+       httpreq->PlainArgs = NewStrBuf();
+       httpreq->this_page = NewStrBuf();
+}
+
+void 
+HttpDetachModule_CONTEXT
+(ParsedHttpHdrs *httpreq)
+{
+       FlushStrBuf(httpreq->ReadBuf);
+       FlushStrBuf(httpreq->PlainArgs);
+       FlushStrBuf(httpreq->this_page);
+       FlushStrBuf(httpreq->PlainArgs);
+       DeleteHash(&httpreq->HTTPHeaders);
+       memset(&httpreq->HR, 0, sizeof(HdrRefs));
+}
 
 void 
 HttpDestroyModule_CONTEXT
 (ParsedHttpHdrs *httpreq)
 {
+       FreeStrBuf(&httpreq->this_page);
        FreeStrBuf(&httpreq->ReadBuf);
        FreeStrBuf(&httpreq->PlainArgs);
        FreeStrBuf(&httpreq->this_page);
+       FreeStrBuf(&httpreq->PlainArgs);
        DeleteHash(&httpreq->HTTPHeaders);
 
 }