Initial drop of dashboard instrumentation - enabled with
authorDavid Schmidt <david__schmidt@users.sourceforge.net>
Sat, 28 Dec 2002 03:58:19 +0000 (03:58 +0000)
committerDavid Schmidt <david__schmidt@users.sourceforge.net>
Sat, 28 Dec 2002 03:58:19 +0000 (03:58 +0000)
--enable-activity-console

src/cgisimple.c
src/filters.c
src/ipc.h [new file with mode: 0644]
src/jcc.c
src/loadcfg.c
src/parsers.c
src/project.h
src/stats.c [new file with mode: 0644]
src/stats.h [new file with mode: 0644]

index c1b50a8..c3de946 100644 (file)
@@ -1,4 +1,4 @@
-const char cgisimple_rcs[] = "$Id: cgisimple.c,v 2.0 2002/06/04 14:34:21 jongfoster Exp $";
+const char cgisimple_rcs[] = "$Id: cgisimple.c,v 2.1 2002/07/04 14:35:05 oes Exp $";
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/src/cgisimple.c,v $
@@ -36,6 +36,9 @@ const char cgisimple_rcs[] = "$Id: cgisimple.c,v 2.0 2002/06/04 14:34:21 jongfos
  *
  * Revisions   :
  *    $Log: cgisimple.c,v $
+ *    Revision 2.1  2002/07/04 14:35:05  oes
+ *    Added ability to send redirects to send-banner CGI, so that it can completely mimic the image blocking action if called with type=auto
+ *
  *    Revision 2.0  2002/06/04 14:34:21  jongfoster
  *    Moving source files to src/
  *
@@ -1410,6 +1413,9 @@ static char *show_rcs(void)
    SHOW_RCS(filters_rcs)
    SHOW_RCS(gateway_h_rcs)
    SHOW_RCS(gateway_rcs)
+#ifdef FEATURE_ACTIVITY_CONSOLE
+   SHOW_RCS(ipc_h_rcs)
+#endif /* def FEATURE_ACTIVITY_CONSOLE */
    SHOW_RCS(jbsockets_h_rcs)
    SHOW_RCS(jbsockets_rcs)
    SHOW_RCS(jcc_h_rcs)
@@ -1433,6 +1439,10 @@ static char *show_rcs(void)
    SHOW_RCS(project_h_rcs)
    SHOW_RCS(ssplit_h_rcs)
    SHOW_RCS(ssplit_rcs)
+#ifdef FEATURE_ACTIVITY_CONSOLE
+   SHOW_RCS(stats_h_rcs)
+   SHOW_RCS(stats_rcs)
+#endif /* def FEATURE_ACTIVITY_CONSOLE */
    SHOW_RCS(urlmatch_h_rcs)
    SHOW_RCS(urlmatch_rcs)
 #ifdef _WIN32
index 3c7265b..e761a7f 100644 (file)
@@ -1,7 +1,7 @@
-const char filters_rcs[] = "$Id: filters.c,v 2.1 2002/08/26 11:08:18 sarantis Exp $";
+const char filters_rcs[] = "$Id: filters.c,v 2.2 2002/09/04 15:38:24 oes Exp $";
 /*********************************************************************
  *
- * File        :  $Source: /cvsroot/ijbswa//current/src/filters.c,v $
+ * File        :  $Source: /cvsroot/ijbswa/current/src/filters.c,v $
  *
  * Purpose     :  Declares functions to parse/crunch headers and pages.
  *                Functions declared include:
@@ -38,6 +38,17 @@ const char filters_rcs[] = "$Id: filters.c,v 2.1 2002/08/26 11:08:18 sarantis Ex
  *
  * Revisions   :
  *    $Log: filters.c,v $
+ *    Revision 2.2  2002/09/04 15:38:24  oes
+ *    Synced with the stable branch:
+ *        Revision 1.58.2.2  2002/08/01 17:18:28  oes
+ *        Fixed BR 537651 / SR 579724 (MSIE image detect improper for IE/Mac)
+ *
+ *        Revision 1.58.2.1  2002/07/26 15:18:53  oes
+ *        - Bugfix: Executing a filters without jobs no longer results in
+ *          turing off *all* filters.
+ *        - Security fix: Malicious web servers can't cause a seg fault
+ *          through bogus chunk sizes anymore
+ *
  *    Revision 2.1  2002/08/26 11:08:18  sarantis
  *    Fix typo.
  *
@@ -440,7 +451,9 @@ const char filters_rcs[] = "$Id: filters.c,v 2.1 2002/08/26 11:08:18 sarantis Ex
 #include "list.h"
 #include "deanimate.h"
 #include "urlmatch.h"
-
+#ifdef FEATURE_ACTIVITY_CONSOLE
+#include "stats.h"
+#endif /* def FEATURE_ACTIVITY_CONSOLE */
 #ifdef _WIN32
 #include "win32.h"
 #endif
@@ -506,6 +519,9 @@ int block_acl(struct access_control_addr *dst, struct client_state *csp)
             }
             else
             {
+#ifdef FEATURE_ACTIVITY_CONSOLE
+               accumulate_stats(STATS_ACL_RESTRICT, 1);
+#endif /* def FEATURE_ACTIVITY_CONSOLE */
                return(1);
             }
          }
@@ -724,6 +740,9 @@ struct http_response *block_url(struct client_state *csp)
       /* and handle accordingly: */
       if ((p == NULL) || (0 == strcmpic(p, "pattern")))
       {
+#ifdef FEATURE_ACTIVITY_CONSOLE
+         accumulate_stats(STATS_IMAGE_BLOCK, 1);
+#endif /* def FEATURE_ACTIVITY_CONSOLE */
          rsp->body = bindup(image_pattern_data, image_pattern_length);
          if (rsp->body == NULL)
          {
@@ -741,6 +760,9 @@ struct http_response *block_url(struct client_state *csp)
 
       else if (0 == strcmpic(p, "blank"))
       {
+#ifdef FEATURE_ACTIVITY_CONSOLE
+         accumulate_stats(STATS_IMAGE_BLOCK, 1);
+#endif /* def FEATURE_ACTIVITY_CONSOLE */
          rsp->body = bindup(image_blank_data, image_blank_length);
          if (rsp->body == NULL)
          {
@@ -1351,6 +1373,10 @@ char *pcrs_filter_response(struct client_state *csp)
       free(new);
       return(NULL);
    }
+#ifdef FEATURE_ACTIVITY_CONSOLE
+   else
+     accumulate_stats(STATS_FILTER, hits);
+#endif /* def FEATURE_ACTIVITY_CONSOLE */
 
    csp->flags |= CSP_FLAG_MODIFIED;
    csp->content_length = size;
@@ -1422,6 +1448,9 @@ char *gif_deanimate_response(struct client_state *csp)
       }
       else
       {
+#ifdef FEATURE_ACTIVITY_CONSOLE
+         accumulate_stats(STATS_GIF_DEANIMATE, 1);
+#endif /* def FEATURE_ACTIVITY_CONSOLE */
          log_error(LOG_LEVEL_DEANIMATE, "Success! GIF shrunk from %d bytes to %d.", size, out->offset);
       }
       csp->content_length = out->offset;
diff --git a/src/ipc.h b/src/ipc.h
new file mode 100644 (file)
index 0000000..e2cd5e3
--- /dev/null
+++ b/src/ipc.h
@@ -0,0 +1,90 @@
+#ifndef IPC_H_INCLUDED
+#define IPC_H_INCLUDED
+#define IPC_H_VERSION "$Id: ipc.h,v 2.0 2002/06/04 14:34:21 jongfoster Exp $"
+/*********************************************************************
+ *
+ * File        :  $Source: /cvsroot/ijbswa/current/src/ipc.h,v $
+ *
+ * Purpose     :  Functions to provide portable interprocess
+ *                communications: semaphores, sleeping, etc.
+ *
+ * Copyright   :  Written by and Copyright (C) 2002, 2003 the SourceForge
+ *                Privoxy team. http://www.privoxy.org/
+ *
+ *                Based on the Internet Junkbuster originally written
+ *                by and Copyright (C) 1997 Anonymous Coders and 
+ *                Junkbusters Corporation.  http://www.junkbusters.com
+ *
+ *                This program is free software; you can redistribute it 
+ *                and/or modify it under the terms of the GNU General
+ *                Public License as published by the Free Software
+ *                Foundation; either version 2 of the License, or (at
+ *                your option) any later version.
+ *
+ *                This program is distributed in the hope that it will
+ *                be useful, but WITHOUT ANY WARRANTY; without even the
+ *                implied warranty of MERCHANTABILITY or FITNESS FOR A
+ *                PARTICULAR PURPOSE.  See the GNU General Public
+ *                License for more details.
+ *
+ *                The GNU General Public License should be included with
+ *                this file.  If not, you can view it at
+ *                http://www.gnu.org/copyleft/gpl.html
+ *                or write to the Free Software Foundation, Inc., 59
+ *                Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ * Revisions   :
+ *    $Log: ipc.h,v $
+ *
+ *********************************************************************/
+\f
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Here, we define common ways of defining mutual exclusion variables
+ * and the manipulation thereof.  We define an alias for the type that
+ * particular OSes like to see, and we have a common model of locking
+ * and unlocking them.
+ */
+
+#ifdef _WIN32
+  #include <windows.h>
+  #define IPC_MUTEX_LOCK HANDLE
+  #define IPC_CREATE_MUTEX(lock) InitializeCriticalSection(&lock)
+  #define IPC_LOCK_MUTEX(lock) EnterCriticalSection(lock)
+  #define IPC_UNLOCK_MUTEX(lock) LeaveCriticalSection(lock)
+  #define IPC_SLEEP_SECONDS(seconds) Sleep(seconds * 1000)
+#elif __OS2__
+  #define INCL_DOSSEMAPHORES
+  #define INCL_DOSPROCESS
+  #include <os2.h>
+  #define IPC_MUTEX_LOCK HMTX
+  #define IPC_CREATE_MUTEX(lock) DosCreateMutexSem(NULL, &lock, 0, FALSE)
+  #define IPC_LOCK_MUTEX(lock) DosRequestMutexSem(lock,SEM_INDEFINITE_WAIT)
+  #define IPC_UNLOCK_MUTEX(lock) DosReleaseMutexSem(lock)
+  #define IPC_SLEEP_SECONDS(seconds) DosSleep(seconds * 1000)
+#else
+  /* Generic unix processing.  This will probably need tweaking for variants. */
+  #include <sys/signal.h>
+  #include <pthread.h>
+  #define IPC_MUTEX_LOCK pthread_mutex_t
+  #define IPC_CREATE_MUTEX(lock) pthread_mutex_init(&lock,0)
+  #define IPC_LOCK_MUTEX(lock) pthread_mutex_lock(&lock)
+  #define IPC_UNLOCK_MUTEX(lock) pthread_mutex_unlock(&lock)
+  #define IPC_SLEEP_SECONDS(seconds) sleep(seconds)
+#endif
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif /* ndef IPC_H_INCLUDED */
+
+/*
+  Local Variables:
+  tab-width: 3
+  end:
+*/
index 7a0d98a..24e8f74 100644 (file)
--- a/src/jcc.c
+++ b/src/jcc.c
@@ -1,4 +1,4 @@
-const char jcc_rcs[] = "$Id: jcc.c,v 2.2 2002/07/12 04:26:17 agotneja Exp $";
+const char jcc_rcs[] = "$Id: jcc.c,v 2.3 2002/07/18 22:06:12 jongfoster Exp $";
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/src/jcc.c,v $
@@ -33,6 +33,9 @@ const char jcc_rcs[] = "$Id: jcc.c,v 2.2 2002/07/12 04:26:17 agotneja Exp $";
  *
  * Revisions   :
  *    $Log: jcc.c,v $
+ *    Revision 2.3  2002/07/18 22:06:12  jongfoster
+ *    Trivial formatting changes
+ *
  *    Revision 2.2  2002/07/12 04:26:17  agotneja
  *    Re-factored 'chat()' to become understandable and maintainable as
  *    a first step in adding Transparent Proxy functionality.
@@ -615,6 +618,9 @@ const char jcc_rcs[] = "$Id: jcc.c,v 2.2 2002/07/12 04:26:17 agotneja Exp $";
 #include "cgi.h"
 #include "loadcfg.h"
 #include "urlmatch.h"
+#ifdef FEATURE_ACTIVITY_CONSOLE
+#include "stats.h"
+#endif /* def FEATURE_ACTIVITY_CONSOLE */
 
 const char jcc_h_rcs[] = JCC_H_VERSION;
 const char project_h_rcs[] = PROJECT_H_VERSION;
@@ -1347,6 +1353,10 @@ static void listen_loop(void)
 
    bfd = bind_port_helper(config);
 
+#ifdef FEATURE_ACTIVITY_CONSOLE
+   init_stats_config(config);
+#endif /* def FEATURE_ACTIVITY_CONSOLE */
+
 #ifdef FEATURE_GRACEFUL_TERMINATION
    while (!g_terminate)
 #else
@@ -1454,6 +1464,10 @@ static void listen_loop(void)
       }
 #endif /* def FEATURE_TOGGLE */
 
+#ifdef FEATURE_ACTIVITY_CONSOLE
+      update_stats_config(config);
+#endif /* def FEATURE_ACTIVITY_CONSOLE */
+
       if (run_loader(csp))
       {
          log_error(LOG_LEVEL_FATAL, "a loader failed - must exit");
@@ -2402,6 +2416,9 @@ static jb_err open_forwarding_connection(struct client_state *csp )
 {
    struct http_response *rsp;
    
+#ifdef FEATURE_ACTIVITY_CONSOLE
+   accumulate_stats(STATS_REQUEST, 1);
+#endif /* def FEATURE_ACTIVITY_CONSOLE */
    log_error(LOG_LEVEL_GPC, "%s%s", csp->http->hostport, csp->http->path);
 
    if (csp->http->fwd->forward_host)
index d4560c1..9772ef6 100644 (file)
@@ -1,4 +1,4 @@
-const char loadcfg_rcs[] = "$Id: loadcfg.c,v 2.2 2002/09/04 15:48:33 oes Exp $";
+const char loadcfg_rcs[] = "$Id: loadcfg.c,v 2.3 2002/09/19 03:48:29 iwanttokeepanon Exp $";
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/src/loadcfg.c,v $
@@ -35,6 +35,9 @@ const char loadcfg_rcs[] = "$Id: loadcfg.c,v 2.2 2002/09/04 15:48:33 oes Exp $";
  *
  * Revisions   :
  *    $Log: loadcfg.c,v $
+ *    Revision 2.3  2002/09/19 03:48:29  iwanttokeepanon
+ *    Just moved "int i" up 3 lines in function unload_configfile, out of the "ifdef FEATURE_ACL" clause.  I disable ACL and it was not compiling because "int i" was ifdef(d) out.  I noticed this in the past, but am just now in a spot where I can change/commit stuff ... long live broadband!
+ *
  *    Revision 2.2  2002/09/04 15:48:33  oes
  *    Synced with the stable branch:
  *        Revision 1.48.2.1  2002/08/21 17:58:05  oes
@@ -421,42 +424,43 @@ static struct file_list *current_configfile = NULL;
  * console and GUI specific options last).
  */
 
-#define hash_actions_file              1196306641ul /**< "actionsfile" */
-#define hash_admin_address             4112573064ul /**< "admin-address" */
-#define hash_buffer_limit              1881726070ul /**< "buffer-limit */
-#define hash_confdir                      1978389ul /**< "confdir" */
-#define hash_debug                          78263ul /**< "debug" */
-#define hash_deny_access               1227333715ul /**< "deny-access" */
-#define hash_enable_edit_actions       2517097536ul /**< "enable-edit-actions" */
-#define hash_enable_remote_toggle      2979744683ul /**< "enable-remote-toggle" */
-#define hash_filterfile                 250887266ul /**< "filterfile" */
-#define hash_forward                      2029845ul /**< "forward" */
-#define hash_forward_socks4            3963965521ul /**< "forward-socks4" */
-#define hash_forward_socks4a           2639958518ul /**< "forward-socks4a" */
-#define hash_jarfile                      2046641ul /**< "jarfile" */
-#define hash_listen_address            1255650842ul /**< "listen-address" */
-#define hash_logdir                        422889ul /**< "logdir" */
-#define hash_logfile                      2114766ul /**< "logfile" */
-#define hash_permit_access             3587953268ul /**< "permit-access" */
-#define hash_proxy_info_url            3903079059ul /**< "proxy-info-url" */
-#define hash_single_threaded           4250084780ul /**< "single-threaded" */
-#define hash_suppress_blocklists       1948693308ul /**< "suppress-blocklists" */
-#define hash_toggle                        447966ul /**< "toggle" */
-#define hash_trust_info_url             430331967ul /**< "trust-info-url" */
-#define hash_trustfile                   56494766ul /**< "trustfile" */
-#define hash_usermanual                1416668518ul /**< "user-manual" */
-
-#define hash_activity_animation        1817904738ul /**< "activity-animation" */
-#define hash_close_button_minimizes    3651284693ul /**< "close-button-minimizes" */
-#define hash_hide_console              2048809870ul /**< "hide-console" */
-#define hash_log_buffer_size           2918070425ul /**< "log-buffer-size" */
-#define hash_log_font_name             2866730124ul /**< "log-font-name" */
-#define hash_log_font_size             2866731014ul /**< "log-font-size" */
-#define hash_log_highlight_messages    4032101240ul /**< "log-highlight-messages" */
-#define hash_log_max_lines             2868344173ul /**< "log-max-lines" */
-#define hash_log_messages              2291744899ul /**< "log-messages" */
-#define hash_show_on_task_bar           215410365ul /**< "show-on-task-bar" */
-
+#define hash_actions_file                  1196306641ul /**< "actionsfile" */
+#define hash_activity_console_address        18904208ul /**< "activity-console-address" */
+#define hash_activity_console_update_freq  3442780376ul /**< "activity-console-update-freq" */
+#define hash_admin_address                 4112573064ul /**< "admin-address" */
+#define hash_buffer_limit                  1881726070ul /**< "buffer-limit */
+#define hash_confdir                          1978389ul /**< "confdir" */
+#define hash_debug                              78263ul /**< "debug" */
+#define hash_deny_access                   1227333715ul /**< "deny-access" */
+#define hash_enable_edit_actions           2517097536ul /**< "enable-edit-actions" */
+#define hash_enable_remote_toggle          2979744683ul /**< "enable-remote-toggle" */
+#define hash_filterfile                     250887266ul /**< "filterfile" */
+#define hash_forward                          2029845ul /**< "forward" */
+#define hash_forward_socks4                3963965521ul /**< "forward-socks4" */
+#define hash_forward_socks4a               2639958518ul /**< "forward-socks4a" */
+#define hash_jarfile                          2046641ul /**< "jarfile" */
+#define hash_listen_address                1255650842ul /**< "listen-address" */
+#define hash_logdir                            422889ul /**< "logdir" */
+#define hash_logfile                          2114766ul /**< "logfile" */
+#define hash_permit_access                 3587953268ul /**< "permit-access" */
+#define hash_proxy_info_url                3903079059ul /**< "proxy-info-url" */
+#define hash_single_threaded               4250084780ul /**< "single-threaded" */
+#define hash_suppress_blocklists           1948693308ul /**< "suppress-blocklists" */
+#define hash_toggle                            447966ul /**< "toggle" */
+#define hash_trust_info_url                 430331967ul /**< "trust-info-url" */
+#define hash_trustfile                       56494766ul /**< "trustfile" */
+#define hash_usermanual                    1416668518ul /**< "user-manual" */
+
+#define hash_activity_animation            1817904738ul /**< "activity-animation" */
+#define hash_close_button_minimizes        3651284693ul /**< "close-button-minimizes" */
+#define hash_hide_console                  2048809870ul /**< "hide-console" */
+#define hash_log_buffer_size               2918070425ul /**< "log-buffer-size" */
+#define hash_log_font_name                 2866730124ul /**< "log-font-name" */
+#define hash_log_font_size                 2866731014ul /**< "log-font-size" */
+#define hash_log_highlight_messages        4032101240ul /**< "log-highlight-messages" */
+#define hash_log_max_lines                 2868344173ul /**< "log-max-lines" */
+#define hash_log_messages                  2291744899ul /**< "log-messages" */
+#define hash_show_on_task_bar               215410365ul /**< "show-on-task-bar" */
 
 static void savearg(char *command, char *argument, struct configuration_spec * config);
 
@@ -627,6 +631,10 @@ struct configuration_spec * load_config(void)
    config->buffer_limit      = 4096 * 1024;
    config->usermanual        = strdup(USER_MANUAL_URL);
    config->proxy_args        = strdup("");
+#ifdef FEATURE_ACTIVITY_CONSOLE
+   config->activity_port     = ACTIVTY_ADDR_PORT;
+   config->activity_freq     = 5;
+#endif /* def FEATURE_ACTIVITY_CONSOLE */
 
    if ((configfp = fopen(configfile, "r")) == NULL)
    {
@@ -717,6 +725,27 @@ struct configuration_spec * load_config(void)
             free(p);
             continue;
 
+/* *************************************************************************
+ * activity-console-address [ip][:port]
+ * *************************************************************************/
+#ifdef FEATURE_ACTIVITY_CONSOLE
+         case hash_activity_console_address :
+            freez(config->activity_address);
+            config->activity_address = strdup(arg);
+            continue;
+#endif /* def FEATURE_ACTIVITY_CONSOLE */
+
+/* *************************************************************************
+ * activity-console-update-freq
+ * *************************************************************************/
+#ifdef FEATURE_ACTIVITY_CONSOLE
+         case hash_activity_console_update_freq :
+            config->activity_freq = atoi(arg);
+            if (config->activity_freq < 1)
+              config->activity_freq = 5;
+            continue;
+#endif /* def FEATURE_ACTIVITY_CONSOLE */
+
 /* *************************************************************************
  * admin-address email-address
  * *************************************************************************/
@@ -1436,6 +1465,36 @@ struct configuration_spec * load_config(void)
    }
 #endif /* def FEATURE_COOKIE_JAR */
 
+#ifdef FEATURE_ACTIVITY_CONSOLE
+   if ( NULL == config->activity_address )
+   {
+      config->activity_address = strdup( ACTIVTY_ADDR_DEFAULT );
+   }
+
+   if ( NULL != config->activity_address )
+   {
+      if (NULL != (p = strchr(config->activity_address, ':')))
+      {
+         *p++ = '\0';
+         if (*p)
+         {
+            config->activity_port = atoi(p);
+         }
+      }
+
+      if (config->activity_port <= 0)
+      {
+         *--p = ':';
+         log_error(LOG_LEVEL_ERROR, "invalid activity port spec %s", config->activity_address);
+      }
+      if (*config->activity_address == '\0')
+      {
+         config->activity_address = NULL;
+      }
+   }
+   log_error(LOG_LEVEL_INFO, "Sending statistics updates to %s, port %d.", config->activity_address, config->activity_port);
+#endif /* def FEATURE_ACTIVITY_CONSOLE */
+
    if ( NULL == config->haddr )
    {
       config->haddr = strdup( HADDR_DEFAULT );
index 2939425..c0302b1 100644 (file)
@@ -1,4 +1,4 @@
-const char parsers_rcs[] = "$Id: parsers.c,v 2.1 2002/09/11 11:23:59 oes Exp $";
+const char parsers_rcs[] = "$Id: parsers.c,v 2.2 2002/11/10 04:20:38 hal9 Exp $";
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/src/parsers.c,v $
@@ -40,6 +40,9 @@ const char parsers_rcs[] = "$Id: parsers.c,v 2.1 2002/09/11 11:23:59 oes Exp $";
  *
  * Revisions   :
  *    $Log: parsers.c,v $
+ *    Revision 2.2  2002/11/10 04:20:38  hal9
+ *    Fix typo: supressed -> suppressed
+ *
  *    Revision 2.1  2002/09/11 11:23:59  oes
  *    Fixed logging of cookies: Killed incoming cookies now logged; incoming/outgoing cookies now distinguished in log
  *
@@ -417,6 +420,9 @@ const char parsers_rcs[] = "$Id: parsers.c,v 2.1 2002/09/11 11:23:59 oes Exp $";
 #include "jbsockets.h"
 #include "miscutil.h"
 #include "list.h"
+#ifdef FEATURE_ACTIVITY_CONSOLE
+#include "stats.h"
+#endif /* def FEATURE_ACTIVITY_CONSOLE */
 
 const char parsers_h_rcs[] = PARSERS_H_VERSION;
 
@@ -1096,6 +1102,9 @@ jb_err client_referrer(struct client_state *csp, char **header)
       /*
        * Blocking referer
        */
+#ifdef FEATURE_ACTIVITY_CONSOLE
+      accumulate_stats(STATS_REFERER, 1);
+#endif /* def FEATURE_ACTIVITY_CONSOLE */
       log_error(LOG_LEVEL_HEADER, "crunch!");
       return JB_ERR_OK;
    }
@@ -1200,6 +1209,9 @@ jb_err client_ua(struct client_state *csp, char **header)
 {
    if ((csp->action->flags & ACTION_HIDE_USER_AGENT) != 0)
    {
+#ifdef FEATURE_ACTIVITY_CONSOLE
+      accumulate_stats(STATS_CLIENT_UA, 1);
+#endif /* def FEATURE_ACTIVITY_CONSOLE */
       log_error(LOG_LEVEL_HEADER, "crunch!");
       freez(*header);
    }
@@ -1244,6 +1256,9 @@ jb_err client_from(struct client_state *csp, char **header)
     */
    if ((newval == NULL) || (0 == strcmpic(newval, "block")) )
    {
+#ifdef FEATURE_ACTIVITY_CONSOLE
+      accumulate_stats(STATS_CLIENT_FROM, 1);
+#endif /* def FEATURE_ACTIVITY_CONSOLE */
       log_error(LOG_LEVEL_HEADER, "crunch!");
       return JB_ERR_OK;
    }
@@ -1335,6 +1350,9 @@ jb_err client_x_forwarded(struct client_state *csp, char **header)
    else
    {
       freez(*header);
+#ifdef FEATURE_ACTIVITY_CONSOLE
+      accumulate_stats(STATS_CLIENT_X_FORWARDED, 1);
+#endif /* def FEATURE_ACTIVITY_CONSOLE */
       log_error(LOG_LEVEL_HEADER, " crunch!");
    }
 
index 06412cd..43de24c 100644 (file)
@@ -1,10 +1,10 @@
 #ifndef PROJECT_H_INCLUDED
 #define PROJECT_H_INCLUDED
 /** Version string. */
-#define PROJECT_H_VERSION "$Id: project.h,v 2.2 2002/07/12 04:26:17 agotneja Exp $"
+#define PROJECT_H_VERSION "$Id: project.h,v 2.3 2002/09/05 08:00:23 oes Exp $"
 /*********************************************************************
  *
- * File        :  $Source: /cvsroot/ijbswa//current/src/project.h,v $
+ * File        :  $Source: /cvsroot/ijbswa/current/src/project.h,v $
  *
  * Purpose     :  Defines data structures which are widely used in the
  *                project.  Does not define any variables or functions
  *
  * Revisions   :
  *    $Log: project.h,v $
+ *    Revision 2.3  2002/09/05 08:00:23  oes
+ *    Synced with the stable branch:
+ *        Revision 1.72.2.1  2002/08/10 11:25:18  oes
+ *        - Include config.h for access to config data
+ *        - Include <pcre*.h> depending on where they are
+ *
  *    Revision 2.2  2002/07/12 04:26:17  agotneja
  *    Re-factored 'chat()' to become understandable and maintainable as
  *    a first step in adding Transparent Proxy functionality.
@@ -1353,6 +1359,31 @@ struct configuration_spec
    /** Size limit for IOB */
    size_t buffer_limit;
 
+#ifdef FEATURE_ACTIVITY_CONSOLE
+
+  /**
+   * Default IP address to send statistics to, as a string.
+   * Set to "127.0.0.1".
+   */
+  #define ACTIVTY_ADDR_DEFAULT   "127.0.0.1"
+
+  /**
+   * Default port to listen on, as a number.
+   * Set to 8119.
+   */
+  #define ACTIVTY_ADDR_PORT      8119
+
+   /** IP address to talk to for activity/statistics reporting. */
+   const char *activity_address;
+
+   /** Port to bind to.  Defaults to ACTIVTY_ADDR_PORT == 8119. */
+   int         activity_port;
+
+   /** Frequency, in seconds, of how often to update the stats console. */
+   int         activity_freq;
+
+#endif /* def FEATURE_ACTIVITY_CONSOLE */
+
 #ifdef FEATURE_TRUST
 
    /** The file name of the trust file. */
diff --git a/src/stats.c b/src/stats.c
new file mode 100644 (file)
index 0000000..b191df4
--- /dev/null
@@ -0,0 +1,224 @@
+const char stats_rcs[] = "$Id: stats.c,v 2.3 2002/07/18 22:06:12 jongfoster Exp $";
+/*********************************************************************
+ *
+ * File        :  $Source: /cvsroot/ijbswa/current/src/jcc.c,v $
+ *
+ * Purpose     :  
+ *                
+ *
+ * Copyright   :  Written by and Copyright (C) 2002, 2003 the SourceForge
+ *                Privoxy team. http://www.privoxy.org/
+ *
+ *                Based on the Internet Junkbuster originally written
+ *                by and Copyright (C) 1997 Anonymous Coders and
+ *                Junkbusters Corporation.  http://www.junkbusters.com
+ *
+ *                This program is free software; you can redistribute it
+ *                and/or modify it under the terms of the GNU General
+ *                Public License as published by the Free Software
+ *                Foundation; either version 2 of the License, or (at
+ *                your option) any later version.
+ *
+ *                This program is distributed in the hope that it will
+ *                be useful, but WITHOUT ANY WARRANTY; without even the
+ *                implied warranty of MERCHANTABILITY or FITNESS FOR A
+ *                PARTICULAR PURPOSE.  See the GNU General Public
+ *                License for more details.
+ *
+ *                The GNU General Public License should be included with
+ *                this file.  If not, you can view it at
+ *                http://www.gnu.org/copyleft/gpl.html
+ *                or write to the Free Software Foundation, Inc., 59
+ *                Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ *********************************************************************/
+\f
+
+#ifdef unix
+#include <sys/signal.h>
+#endif
+#include "project.h"
+#include "errlog.h"
+#include "stats.h"
+#include "ipc.h"
+
+const char stats_h_rcs[] = STATS_H_VERSION;
+const char ipc_h_rcs[] = IPC_H_VERSION;
+static IPC_MUTEX_LOCK stats_lock;
+
+struct configuration_spec *latest_config;
+int changed = 0,
+    stats_array[STATS_MAX_KEYS];
+
+/*********************************************************************
+ *
+ * Function    :  init_stats_config
+ *
+ * Description :  Initializes the statistics array and spawns a thread
+ *                to transmit statistics to the listening party.
+ *
+ * Parameters  :
+ *          1  :  config = Privoxy configuration.
+ *
+ * Returns     :  N/A
+ *
+ *********************************************************************/
+void init_stats_config(struct configuration_spec * config)
+{
+  int i;
+#if defined (_WIN32) || defined (__OS2__)
+  int child_id;
+#else
+  pthread_attr_t attr;
+  pthread_t thread;
+#endif /* def unix */
+
+  log_error(LOG_LEVEL_INFO, "init_stats_config hit.");
+  IPC_CREATE_MUTEX(stats_lock);
+  for (i=0; i < STATS_MAX_KEYS; i++)
+  {
+    stats_array[i] = 0;
+  }
+  latest_config = config;
+
+  /*
+   * Start the timing/sending thread - we'll need a lot of work here
+   * for each platform.  I imagine there is also a possibility of 
+   * doing this via fork() instead of threads.
+   */
+
+#ifdef _WIN32
+    child_id = _beginthread(
+            (void (*)(void *))forward_stats,
+            64 * 1024,
+            NULL);
+#elif __OS2__
+    child_id = _beginthread(
+            (void(* _Optlink)(void*))forward_stats,
+            NULL,
+            64 * 1024,
+            NULL);
+#else
+    /* Generic unix processing */
+    signal(SIGALRM, null_routine);  /* Ignore the SIGALRM signal */
+    pthread_attr_init(&attr);
+    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
+    pthread_create(&thread, &attr, forward_stats, NULL);
+#endif
+
+}
+
+/*********************************************************************
+ *
+ * Function    :  update_stats_config
+ *
+ * Description :  Updates the pointer to the most recent Privoxy
+ *                configuration changes.
+ *
+ * Parameters  :
+ *          1  :  config = Privoxy configuration.
+ *
+ * Returns     :  N/A
+ *
+ *********************************************************************/
+void update_stats_config(struct configuration_spec * config)
+{
+  latest_config = config;
+}
+
+/*********************************************************************
+ *
+ * Function    :  accumulate_stats
+ *
+ * Description :  Updates one element of the statistics array with a
+ *                single integer value.
+ *
+ * Parameters  :
+ *          1  :  key = the key into the stats array
+ *          2  :  value = the value to add to the current stats key
+ *
+ * Returns     :  N/A
+ *
+ *********************************************************************/
+void accumulate_stats(int key, int value)
+{
+  if (key < STATS_MAX_KEYS)
+  {
+    IPC_LOCK_MUTEX(stats_lock);
+    stats_array[key] += value;
+    changed = 1;
+    IPC_UNLOCK_MUTEX(stats_lock);
+  }
+  /* log_error(LOG_LEVEL_INFO, "Accumulate stats: key %d, value %d, total %d; send to: %s:%d", key, value, stats_array[key], latest_config->activity_address,latest_config->activity_port); */
+}
+
+/*********************************************************************
+ *
+ * Function    :  forward_stats
+ *
+ * Description :  Main routine for the statistics thread; loops and 
+ *                periodically checks if there's anything to send.  If
+ *                so, call send_stats() to do the work.
+ *
+ * Parameters  :  N/A
+ *
+ * Returns     :  N/A
+ *
+ *********************************************************************/
+void *forward_stats()
+{
+  int local_stats_array[STATS_MAX_KEYS];
+  
+  log_error(LOG_LEVEL_INFO, "forward_stats ready.");
+  for (;;)
+  {
+    IPC_SLEEP_SECONDS(latest_config->activity_freq);
+    if (changed == 1)
+    {
+      IPC_LOCK_MUTEX(stats_lock);
+      memcpy(local_stats_array,stats_array,sizeof(stats_array));
+      changed = 0;
+      IPC_UNLOCK_MUTEX(stats_lock);
+      send_stats(&local_stats_array);
+    }
+  }
+}
+
+/*********************************************************************
+ *
+ * Function    :  send_stats
+ *
+ * Description :  Attempt to send statistics to the listening console
+ *
+ * Parameters  :  N/A
+ *
+ * Returns     :  N/A
+ *
+ *********************************************************************/
+void send_stats(int *local_stats_array[])
+{
+  /* Here, we initiate the socket send to the console */
+  /*
+  log_error(LOG_LEVEL_INFO, "send_stats sending stats: %d %d %d %d %d %d %d %d %d %d",
+    local_stats_array[0],local_stats_array[1],local_stats_array[2],local_stats_array[3],local_stats_array[4],local_stats_array[5],local_stats_array[6],local_stats_array[7],local_stats_array[8],local_stats_array[9]);
+  */
+}
+
+/*********************************************************************
+ *
+ * Function    :  null_routine
+ *
+ * Description :  Called when hit by a signal in unix; do nothing.
+ *
+ * Parameters  :
+ *          1  :  sig - the integer signal
+ *
+ * Returns     :  N/A
+ *
+ *********************************************************************/
+#ifdef unix
+void null_routine(int sig)
+{
+  /* sigignore(sig); */
+}
+#endif /* def unix */
diff --git a/src/stats.h b/src/stats.h
new file mode 100644 (file)
index 0000000..3d099c1
--- /dev/null
@@ -0,0 +1,78 @@
+#ifndef STATS_H_INCLUDED
+#define STATS_H_INCLUDED
+#define STATS_H_VERSION "$Id: stats.h,v 2.0 2002/06/04 14:34:21 jongfoster Exp $"
+/*********************************************************************
+ *
+ * File        :  $Source: /cvsroot/ijbswa/current/src/stats.h,v $
+ *
+ * Purpose     :  Functions and definitions for accumulating and
+ *                sending statistics to an "external" stats console
+ *
+ * Copyright   :  Written by and Copyright (C) 2002, 2003 the SourceForge
+ *                Privoxy team. http://www.privoxy.org/
+ *
+ *                Based on the Internet Junkbuster originally written
+ *                by and Copyright (C) 1997 Anonymous Coders and 
+ *                Junkbusters Corporation.  http://www.junkbusters.com
+ *
+ *                This program is free software; you can redistribute it 
+ *                and/or modify it under the terms of the GNU General
+ *                Public License as published by the Free Software
+ *                Foundation; either version 2 of the License, or (at
+ *                your option) any later version.
+ *
+ *                This program is distributed in the hope that it will
+ *                be useful, but WITHOUT ANY WARRANTY; without even the
+ *                implied warranty of MERCHANTABILITY or FITNESS FOR A
+ *                PARTICULAR PURPOSE.  See the GNU General Public
+ *                License for more details.
+ *
+ *                The GNU General Public License should be included with
+ *                this file.  If not, you can view it at
+ *                http://www.gnu.org/copyleft/gpl.html
+ *                or write to the Free Software Foundation, Inc., 59
+ *                Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ * Revisions   :
+ *    $Log: stats.h,v $
+ *
+ *********************************************************************/
+\f
+
+/* Revision control strings from this header and associated .c file */
+extern const char stats_rcs[];
+extern const char stats_h_rcs[];
+
+/* Global variables */
+
+/* These are the different types of statistics we will be gathering. */
+#define STATS_REQUEST 0
+#define STATS_FILTER 1
+#define STATS_GIF_DEANIMATE 2
+#define STATS_ACL_RESTRICT 3
+#define STATS_IMAGE_BLOCK 4
+#define STATS_COOKIE 5
+#define STATS_REFERER 6
+#define STATS_CLIENT_UA 7
+#define STATS_CLIENT_FROM 8
+#define STATS_CLIENT_X_FORWARDED 9
+/** Define the maximum number of 'keys' we'll be sending.  Always keep this
+  * number one greater than the last actual key; it is used to define an 
+  * array (i.e. int stats[STATS_MAX_KEYS]. */
+#define STATS_MAX_KEYS 10
+
+/* Functions */
+
+void init_stats_config(struct configuration_spec * config);
+void update_stats_config(struct configuration_spec * config);
+void accumulate_stats(int key, int value);
+void *forward_stats();
+void send_stats(int *p_local_stats_array[]);
+
+#endif /* ndef STATS_H_INCLUDED */
+
+/*
+  Local Variables:
+  tab-width: 3
+  end:
+*/