silence lnog noise.
authorWilfried Goesgens <dothebart@citadel.org>
Sun, 11 Jan 2015 11:30:39 +0000 (12:30 +0100)
committerWilfried Goesgens <dothebart@citadel.org>
Sun, 11 Jan 2015 11:30:39 +0000 (12:30 +0100)
webcit/context_loop.c
webcit/webcit.c
webcit/webserver.c

index 6511572dbbf06b4e083846499c4bfec2f4652a0b..bf3ac7def2171edb0ee1a074978670aaa492ff9e 100644 (file)
@@ -32,6 +32,7 @@ extern HashList *HandlerHash;
 /* the following two values start at 1 because the initial parent thread counts as one. */
 int num_threads_existing = 1;          /* Number of worker threads which exist. */
 int num_threads_executing = 1;         /* Number of worker threads currently executing. */
+int verbose=0;
 
 extern void session_loop(void);
 void spawn_another_worker_thread(void);
@@ -177,7 +178,8 @@ wcsession *FindSession(wcsession **wclist, ParsedHttpHdrs *Hdr, pthread_mutex_t
                                && (!strcasecmp(ChrPtr(Hdr->c_password), ChrPtr(sptr->wc_password)))
                                && (sptr->killthis == 0)
                        ) {
-                               syslog(LOG_DEBUG, "Matched a session with the same http-auth");
+                               if (verbose)
+                                       syslog(LOG_DEBUG, "Matched a session with the same http-auth");
                                TheSession = sptr;
                        }
                        break;
@@ -186,14 +188,16 @@ wcsession *FindSession(wcsession **wclist, ParsedHttpHdrs *Hdr, pthread_mutex_t
                        if (    (Hdr->HR.desired_session != 0)
                                && (sptr->wc_session == Hdr->HR.desired_session)
                        ) {
-                               syslog(LOG_DEBUG, "Matched a session with the same cookie");
+                               if (verbose)
+                                       syslog(LOG_DEBUG, "Matched a session with the same cookie");
                                TheSession = sptr;
                        }
                        break;                       
                case NO_AUTH:
                        /* Any unbound session is a candidate */
                        if ( (sptr->wc_session == 0) && (sptr->inuse == 0) ) {
-                               syslog(LOG_DEBUG, "Reusing an unbound session");
+                               if (verbose)
+                                       syslog(LOG_DEBUG, "Reusing an unbound session");
                                TheSession = sptr;
                        }
                        break;
@@ -345,7 +349,7 @@ int ReadHttpSubject(ParsedHttpHdrs *Hdr, StrBuf *Line, StrBuf *Buf)
                StrBuf *NewLine = NewStrBuf();
                Hdr->HR.DontNeedAuth = 1;
                StrBufAppendPrintf(NewLine, "GET /landing?go=%s?failvisibly=1 HTTP/1.0", ChrPtr(Buf));
-               syslog(LOG_DEBUG, "Replacing with: %s", ChrPtr(NewLine));
+               if (verbose) syslog(LOG_DEBUG, "Replacing with: %s", ChrPtr(NewLine));
                return_value = ReadHttpSubject(Hdr, NewLine, Buf);
                FreeStrBuf(&NewLine);
                return return_value;
@@ -405,7 +409,8 @@ int ReadHTTPRequest (ParsedHttpHdrs *Hdr)
                        memset(pHdr, 0, sizeof(OneHttpHeader));
                        pHdr->Val = Line;
                        Put(Hdr->HTTPHeaders, HKEY("GET /"), pHdr, DestroyHttpHeaderHandler);
-                       syslog(LOG_DEBUG, "%s", ChrPtr(Line));
+                       if (verbose || strstr(ChrPtr(Line), "sslg") == NULL)
+                               syslog(LOG_DEBUG, "%s", ChrPtr(Line));
                        isbogus = ReadHttpSubject(Hdr, Line, HeaderName);
                        if (isbogus) break;
                        continue;
@@ -537,11 +542,12 @@ void context_loop(ParsedHttpHdrs *Hdr)
                /* How long did this transaction take? */
                gettimeofday(&tx_finish, NULL);
                
-               syslog(LOG_DEBUG, "HTTP: 200 [%ld.%06ld] %s %s",
-                       ((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)
+               if (verbose)
+                       syslog(LOG_DEBUG, "HTTP: 200 [%ld.%06ld] %s %s",
+                              ((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);
                session_destroy_modules(&Static);
@@ -604,7 +610,8 @@ void context_loop(ParsedHttpHdrs *Hdr)
         * If a language was requested via a cookie, select that language now.
         */
        if (StrLength(Hdr->c_language) > 0) {
-               syslog(LOG_DEBUG, "Session cookie requests language '%s'", ChrPtr(Hdr->c_language));
+               if (verbose)
+                       syslog(LOG_DEBUG, "Session cookie requests language '%s'", ChrPtr(Hdr->c_language));
                set_selected_language(ChrPtr(Hdr->c_language));
                go_selected_language();
        }
@@ -618,13 +625,14 @@ void context_loop(ParsedHttpHdrs *Hdr)
        /* How long did this transaction take? */
        gettimeofday(&tx_finish, NULL);
 
-       syslog(LOG_INFO, "HTTP: 200 [%ld.%06ld] %s %s",
-               ((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)
-       );
-
+       if (verbose || strstr(ChrPtr(Hdr->this_page), "sslg") == NULL) {
+               syslog(LOG_INFO, "HTTP: 200 [%ld.%06ld] %s %s",
+                      ((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);
 
        /* If *this* very transaction did not explicitly specify a session cookie,
index 8a0ba58a98cb1d31dac5b5d3b397f312beccfda1..91fc47e26424c64bf0d85a0ec173554fed1cb5ec 100644 (file)
@@ -21,7 +21,7 @@ HashList *HandlerHash = NULL;
 
 void stuff_to_cookie(int unset_cookie);
 extern int GetConnected(void);
-
+extern int verbose;
 
 void PutRequestLocalMem(void *Data, DeleteHashDataFunc DeleteIt)
 {
@@ -237,7 +237,8 @@ void http_redirect(const char *whichpage) {
  */
 void http_transmit_thing(const char *content_type, int is_static)
 {
-       syslog(LOG_DEBUG, "http_transmit_thing(%s)%s", content_type, ((is_static > 0) ? " (static)" : ""));
+       if (verbose)
+               syslog(LOG_DEBUG, "http_transmit_thing(%s)%s", content_type, ((is_static > 0) ? " (static)" : ""));
        output_headers(0, 0, 0, 0, 0, is_static);
 
        hprintf("Content-type: %s\r\n"
@@ -252,7 +253,8 @@ void http_transmit_thing(const char *content_type, int is_static)
 void http_transmit_headers(const char *content_type, int is_static, long is_chunked, int is_gzip)
 {
        wcsession *WCC = WC;
-       syslog(LOG_DEBUG, "http_transmit_thing(%s)%s", content_type, ((is_static > 0) ? " (static)" : ""));
+       if (verbose)
+               syslog(LOG_DEBUG, "http_transmit_thing(%s)%s", content_type, ((is_static > 0) ? " (static)" : ""));
        output_headers(0, 0, 0, 0, 0, is_static);
 
        if (is_gzip)
@@ -403,7 +405,8 @@ void ajax_servcmd(void)
        char *junk;
        size_t len;
 
-       syslog(LOG_DEBUG, "ajax_servcmd() g_cmd=\"%s\"", bstr("g_cmd") );
+       if (verbose)
+               syslog(LOG_DEBUG, "ajax_servcmd() g_cmd=\"%s\"", bstr("g_cmd") );
        begin_ajax_response();
        Buf = NewStrBuf();
        serv_puts(bstr("g_cmd"));
@@ -500,7 +503,8 @@ void push_destination(void) {
 
        FreeStrBuf(&WCC->PushedDestination);
        WCC->PushedDestination = NewStrBufDup(SBSTR("url"));
-       syslog(LOG_DEBUG, "Push: %s", ChrPtr(WCC->PushedDestination));
+       if (verbose)
+               syslog(LOG_DEBUG, "Push: %s", ChrPtr(WCC->PushedDestination));
        wc_printf("OK");
 }
 
@@ -538,7 +542,8 @@ void pop_destination(void) {
        /*
         * All righty then!  We have a destination saved, so go there now.
         */
-       syslog(LOG_DEBUG, "Pop: %s", ChrPtr(WCC->PushedDestination));
+       if (verbose)
+               syslog(LOG_DEBUG, "Pop: %s", ChrPtr(WCC->PushedDestination));
        http_redirect(ChrPtr(WCC->PushedDestination));
 }
 
@@ -658,9 +663,10 @@ void session_loop(void)
 
        /* If the client sent a nonce that is incorrect, kill the request. */
        if (havebstr("nonce")) {
-               syslog(LOG_DEBUG, "Comparing supplied nonce %s to session nonce %d", 
-                       bstr("nonce"), WCC->nonce
-               );
+               if (verbose)
+                       syslog(LOG_DEBUG, "Comparing supplied nonce %s to session nonce %d", 
+                              bstr("nonce"), WCC->nonce
+                               );
                if (ibstr("nonce") != WCC->nonce) {
                        syslog(LOG_INFO, "Ignoring request with mismatched nonce.");
                        hprintf("HTTP/1.1 404 Security check failed\r\n");
@@ -738,15 +744,18 @@ void session_loop(void)
         */
        if (havebstr("go")) {
                int ret;
-               syslog(LOG_DEBUG, "Explicit room selection: %s", bstr("go"));
+               if (verbose)
+                       syslog(LOG_DEBUG, "Explicit room selection: %s", bstr("go"));
                ret = gotoroom(sbstr("go"));    /* do quietly to avoid session output! */
                if ((ret/100) != 2) {
-                       syslog(LOG_DEBUG, "Unable to change to [%s]; Reason: %d", bstr("go"), ret);
+                       if (verbose)
+                               syslog(LOG_DEBUG, "Unable to change to [%s]; Reason: %d", bstr("go"), ret);
                }
        }
        else if (havebstr("gotofirst")) {
                int ret;
-               syslog(LOG_DEBUG, "Explicit room selection: %s", bstr("gotofirst"));
+               if (verbose)
+                       syslog(LOG_DEBUG, "Explicit room selection: %s", bstr("gotofirst"));
                ret = gotoroom(sbstr("gotofirst"));     /* do quietly to avoid session output! */
                if ((ret/100) != 2) {
                        syslog(LOG_INFO, "Unable to change to [%s]; Reason: %d", bstr("gotofirst"), ret);
@@ -760,14 +769,16 @@ void session_loop(void)
        else if ( (StrLength(WCC->CurRoom.name) == 0) && ( (StrLength(WCC->Hdr->c_roomname) > 0) )) {
                int ret;
 
-               syslog(LOG_DEBUG, "We are in '%s' but cookie indicates '%s', going there...",
-                       ChrPtr(WCC->CurRoom.name),
-                       ChrPtr(WCC->Hdr->c_roomname)
+               if (verbose)
+                       syslog(LOG_DEBUG, "We are in '%s' but cookie indicates '%s', going there...",
+                              ChrPtr(WCC->CurRoom.name),
+                              ChrPtr(WCC->Hdr->c_roomname)
                );
                ret = gotoroom(WCC->Hdr->c_roomname);   /* do quietly to avoid session output! */
                if ((ret/100) != 2) {
-                       syslog(LOG_DEBUG, "COOKIEGOTO: Unable to change to [%s]; Reason: %d",
-                               ChrPtr(WCC->Hdr->c_roomname), ret);
+                       if (verbose)
+                               syslog(LOG_DEBUG, "COOKIEGOTO: Unable to change to [%s]; Reason: %d",
+                                      ChrPtr(WCC->Hdr->c_roomname), ret);
                }
        }
 
@@ -833,7 +844,8 @@ void display_default_landing_page(void) {
                /* default action */
 
                if (havebstr("go")) {
-                       syslog(LOG_DEBUG, "Explicit room selection: %s", bstr("go"));
+                       if (verbose)
+                               syslog(LOG_DEBUG, "Explicit room selection: %s", bstr("go"));
                        smart_goto(sbstr("go"));
                }
                else if (default_landing_page) {
index 0f299bfc77f521c1121a3c7dc1dd01cc4115c507..2f581356ab81eab1c29a8259971ec52b9419c46c 100644 (file)
@@ -49,6 +49,7 @@ extern HashList *HandlerHash;
 const char foobuf[32];
 const char *nix(void *vptr) {snprintf(foobuf, 32, "%0x", (long) vptr); return foobuf;}
 #endif 
+extern int verbose;
 extern int dbg_analyze_msg;
 extern int dbg_backtrace_template_errors;
 extern int DumpTemplateI18NStrings;
@@ -100,9 +101,9 @@ int main(int argc, char **argv)
 
        /* Parse command line */
 #ifdef HAVE_OPENSSL
-       while ((a = getopt(argc, argv, "u:h:i:p:t:T:B:x:g:dD:G:cfsS:Z")) != EOF)
+       while ((a = getopt(argc, argv, "u:h:i:p:t:T:B:x:g:dD:G:cfsS:Z:v:")) != EOF)
 #else
-       while ((a = getopt(argc, argv, "u:h:i:p:t:T:B:x:g:dD:G:cfZ")) != EOF)
+       while ((a = getopt(argc, argv, "u:h:i:p:t:T:B:x:g:dD:G:cfZ:v:")) != EOF)
 #endif
                switch (a) {
                case 'u':
@@ -189,6 +190,9 @@ int main(int argc, char **argv)
                        I18nDump = NewStrBufPlain(HKEY("int templatestrings(void)\n{\n"));
                        I18nDumpFile = optarg;
                        break;
+               case 'v':
+                       verbose=1;
+                       break;
                default:
                        fprintf(stderr, "usage: webcit "
                                "[-i ip_addr] [-p http_port] "