- Don't mistake VC++'s _snprintf() for a snprintf() replacement.
[privoxy.git] / project.h
index a652b1b..d3cde77 100644 (file)
--- a/project.h
+++ b/project.h
@@ -1,7 +1,7 @@
 #ifndef PROJECT_H_INCLUDED
 #define PROJECT_H_INCLUDED
 /** Version string. */
-#define PROJECT_H_VERSION "$Id: project.h,v 1.82 2006/09/20 15:50:31 fabiankeil Exp $"
+#define PROJECT_H_VERSION "$Id: project.h,v 1.92 2007/03/17 15:20:05 fabiankeil Exp $"
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/project.h,v $
@@ -10,7 +10,7 @@
  *                project.  Does not define any variables or functions
  *                (though it does declare some macros).
  *
- * Copyright   :  Written by and Copyright (C) 2001 - 2004 the SourceForge
+ * Copyright   :  Written by and Copyright (C) 2001 - 2007 the SourceForge
  *                Privoxy team. http://www.privoxy.org/
  *
  *                Based on the Internet Junkbuster originally written
  *
  * Revisions   :
  *    $Log: project.h,v $
+ *    Revision 1.92  2007/03/17 15:20:05  fabiankeil
+ *    New config option: enforce-blocks.
+ *
+ *    Revision 1.91  2007/03/05 13:28:03  fabiankeil
+ *    Add some CSP_FLAGs for the header parsers.
+ *
+ *    Revision 1.90  2007/02/07 10:36:16  fabiankeil
+ *    Add new http_response member to save
+ *    the reason why the response was generated.
+ *
+ *    Revision 1.89  2007/01/27 13:09:16  fabiankeil
+ *    Add new config option "templdir" to
+ *    change the templates directory.
+ *
+ *    Revision 1.88  2007/01/25 13:36:59  fabiankeil
+ *    Add csp->error_message for failure reasons
+ *    that should be embedded into the CGI pages.
+ *
+ *    Revision 1.87  2007/01/01 19:36:37  fabiankeil
+ *    Integrate a modified version of Wil Mahan's
+ *    zlib patch (PR #895531).
+ *
+ *    Revision 1.86  2006/12/31 17:56:37  fabiankeil
+ *    Added config option accept-intercepted-requests
+ *    and disabled it by default.
+ *
+ *    Revision 1.85  2006/12/31 15:03:31  fabiankeil
+ *    Fix gcc43 compiler warnings and a comment.
+ *
+ *    Revision 1.84  2006/12/21 12:57:48  fabiankeil
+ *    Add config option "split-large-forms"
+ *    to work around the browser bug reported
+ *    in BR #1570678.
+ *
+ *    Revision 1.83  2006/12/06 19:26:29  fabiankeil
+ *    Moved HTTP snipplets into jcc.c. They aren't
+ *    used anywhere else.
+ *
  *    Revision 1.82  2006/09/20 15:50:31  fabiankeil
  *    Doubled size of HOSTENT_BUFFER_SIZE to mask
  *    problems with gethostbyname_r and some
@@ -621,7 +659,7 @@ typedef int jb_err;
 #define JB_ERR_PARSE      4 /**< Error parsing file                       */
 #define JB_ERR_MODIFIED   5 /**< File has been modified outside of the  
                                  CGI actions editor.                      */
-
+#define JB_ERR_COMPRESS   6 /**< Error on decompression                   */
 
 /**
  * This macro is used to free a pointer that may be NULL.
@@ -786,6 +824,21 @@ struct http_request
    int    dcount;  /**< How many parts to this domain? (length of dvec)   */
 };
 
+/**
+ * Reasons for generating a http_response instead of delivering
+ * the requested resource. Mostly ordered the way they are checked
+ * for in chat().
+ */
+#define RSP_REASON_UNSUPPORTED        1
+#define RSP_REASON_BLOCKED            2
+#define RSP_REASON_UNTRUSTED          3
+#define RSP_REASON_REDIRECTED         4
+#define RSP_REASON_CGI_CALL           5
+#define RSP_REASON_NO_SUCH_DOMAIN     6
+#define RSP_REASON_FORWARDING_FAILED  7
+#define RSP_REASON_CONNECT_FAILED     8
+#define RSP_REASON_OUT_OF_MEMORY      9
+#define RSP_REASON_INTERNAL_ERROR     10
 
 /**
  * Response generated by CGI, blocker, or error handler
@@ -800,6 +853,7 @@ struct http_response
   size_t content_length;  /**< Length of body, REQUIRED if binary body. */
   int    is_static;       /**< Nonzero if the content will never change and
                                should be cached by the browser (e.g. images). */
+  int reason;             /**< Why the response was generated in the first place. */
 };
 
 /**
@@ -819,7 +873,7 @@ struct url_spec
    int   port;         /**< The port number, or 0 to match all ports.         */
 
    char *path;         /**< The source for the regex.                         */
-   int   pathlen;      /**< ==strlen(path).  Needed for prefix matching.  FIXME: Now obsolete?     */
+   size_t pathlen;     /**< ==strlen(path).  Needed for prefix matching.  FIXME: Now obsolete?     */
    regex_t *preg;      /**< Regex for matching path part                      */
 };
 
@@ -873,15 +927,18 @@ struct iob
  */
 #define IOB_RESET(CSP) if(CSP->iob->buf) free(CSP->iob->buf); memset(CSP->iob, '\0', sizeof(CSP->iob));
 
-/* Bits for csp->content_type */
-#define CT_TEXT   1 /**< csp->content_type bitmask:
-                         Suitable for pcrs filtering. */
-#define CT_GIF    2 /**< csp->content_type bitmask:
-                         Suitable for GIF filtering.  */
-#define CT_TABOO  4 /**< csp->content_type bitmask:
-                         DO NOT filter, irrespective of other flags. */
-#define CT_JPEG   8 /**< csp->content_type bitmask:
-                         Suitable for JPEG filtering.  */
+/* Bits for csp->content_type bitmask: */
+#define CT_TEXT    0x0001U /**< Suitable for pcrs filtering. */
+#define CT_GIF     0x0002U /**< Suitable for GIF filtering.  */
+#define CT_TABOO   0x0004U /**< DO NOT filter, irrespective of other flags. */
+#define CT_JPEG    0x0008U /**< Suitable for JPEG filtering.  */
+
+/* Although these are not, strictly speaking, content types
+ * (they are content encodings), it is simple to handle them
+ * as such.
+ */
+#define CT_GZIP    0x0010U /**< gzip-compressed data. */
+#define CT_DEFLATE 0x0020U /**< zlib-compressed data. */
 
 /**
  * The mask which includes all actions.
@@ -993,18 +1050,22 @@ struct iob
 #define ACTION_STRING_COUNT                15
 
 
-/*To make the ugly hack in sed easier to understand*/
+/* To make the ugly hack in sed easier to understand */
 #define CHECK_EVERY_HEADER_REMAINING 0
 
 
 /** Index into current_action_spec::multi[] for headers to add. */
-#define ACTION_MULTI_ADD_HEADER     0
+#define ACTION_MULTI_ADD_HEADER              0
 /** Index into current_action_spec::multi[] for headers to add. */
-#define ACTION_MULTI_WAFER          1
-/** Index into current_action_spec::multi[] for filters to apply. */
-#define ACTION_MULTI_FILTER         2
+#define ACTION_MULTI_WAFER                   1
+/** Index into current_action_spec::multi[] for content filters to apply. */
+#define ACTION_MULTI_FILTER                  2
+/** Index into current_action_spec::multi[] for server-header filters to apply. */
+#define ACTION_MULTI_SERVER_HEADER_FILTER    3
+/** Index into current_action_spec::multi[] for client-header filters to apply. */
+#define ACTION_MULTI_CLIENT_HEADER_FILTER    4
 /** Number of multi-string actions. */
-#define ACTION_MULTI_COUNT          3
+#define ACTION_MULTI_COUNT                   5
 
 
 /**
@@ -1111,6 +1172,30 @@ struct url_actions
  */
 #define CSP_FLAG_TOGGLED_ON 0x20
 
+/**
+ * Flag for csp->flags: Set if adding the 'Connection: close' header
+ * for the client isn't necessary.
+ */
+#define CSP_FLAG_CLIENT_CONNECTION_CLOSE_SET   0x00000040UL
+
+/**
+ * Flag for csp->flags: Set if adding the 'Connection: close' header
+ * for the server isn't necessary.
+ */
+#define CSP_FLAG_SERVER_CONNECTION_CLOSE_SET   0x00000080UL
+
+/**
+ * Flag for csp->flags: Signals header parsers whether they
+ * are parsing server or client headers.
+ */
+#define CSP_FLAG_CLIENT_HEADER_PARSING_DONE    0x00000100UL
+
+/**
+ * Flag for csp->flags: Set if adding the Host: header
+ * isn't necessary.
+ */
+#define CSP_FLAG_HOST_HEADER_IS_SET            0x00000200UL
+
 
 /*
  * Flags for use in return codes of child processes
@@ -1152,7 +1237,7 @@ struct client_state
    jb_socket sfd;
 
    /** Multi-purpose flag container, see CSP_FLAG_* above */
-   unsigned short int flags;
+   unsigned int flags;
 
    /** Client PC's IP address, as reported by the accept() function.
        As a string. */
@@ -1182,7 +1267,7 @@ struct client_state
    struct list cookie_list[1];
 
    /** MIME-Type key, see CT_* above */
-   unsigned short int content_type;
+   unsigned int content_type;
 
    /** The "X-Forwarded-For:" header sent by the client */
    char   *x_forwarded;
@@ -1203,6 +1288,12 @@ struct client_state
 
 #endif /* def FEATURE_TRUST */
 
+   /**
+    * Failure reason to embedded in the CGI error page,
+    * or NULL. Currently only used for socks errors.
+    */
+   char *error_message;
+
    /** Next thread in linked list. Only read or modify from the main thread! */
    struct client_state *next;
 };
@@ -1315,8 +1406,7 @@ struct block_spec
 };
 
 /**
- * Arbitrary limit for the number of trusted referrers
- * Privoxy can print in its blocking message.
+ * Arbitrary limit for the number of trusted referrers.
  */
 #define MAX_TRUSTED_REFERRERS 512
 
@@ -1361,6 +1451,10 @@ struct forward_spec
  */
 #define FORWARD_SPEC_INITIALIZER { { URL_SPEC_INITIALIZER }, 0, NULL, 0, NULL, 0, NULL }
 
+/* Supported filter types */
+#define FT_CONTENT_FILTER       1
+#define FT_CLIENT_HEADER_FILTER 2
+#define FT_SERVER_HEADER_FILTER 3
 
 /**
  * This struct represents one filter (one block) from
@@ -1374,6 +1468,7 @@ struct re_filterfile_spec
    char *description;               /**< Description from FILTER: statement in re_filterfile. */
    struct list patterns[1];         /**< The patterns from the re_filterfile. */
    pcrs_job *joblist;               /**< The resulting compiled pcrs_jobs. */
+   int type;                        /**< Filter type (content, client-header, server-header). */
    struct re_filterfile_spec *next; /**< The pointer for chaining. */
 };
 
@@ -1415,13 +1510,23 @@ struct access_control_list
 
 
 /** configuration_spec::feature_flags: CGI actions editor. */
-#define RUNTIME_FEATURE_CGI_EDIT_ACTIONS  1
+#define RUNTIME_FEATURE_CGI_EDIT_ACTIONS             1
 
 /** configuration_spec::feature_flags: Web-based toggle. */
-#define RUNTIME_FEATURE_CGI_TOGGLE        2
+#define RUNTIME_FEATURE_CGI_TOGGLE                   2
 
 /** configuration_spec::feature_flags: HTTP-header-based toggle. */
-#define RUNTIME_FEATURE_HTTP_TOGGLE       4
+#define RUNTIME_FEATURE_HTTP_TOGGLE                  4
+
+/** configuration_spec::feature_flags: Split large forms to limit the number of GET arguments. */
+#define RUNTIME_FEATURE_SPLIT_LARGE_FORMS            8
+
+/** configuration_spec::feature_flags: Check the host header for requests with host-less request lines. */
+#define RUNTIME_FEATURE_ACCEPT_INTERCEPTED_REQUESTS 16
+
+/** configuration_spec::feature_flags: Don't allow to circumvent blocks with the force prefix. */
+#define RUNTIME_FEATURE_ENFORCE_BLOCKS              32
+
 
 /**
  * Data loaded from the configuration file.
@@ -1443,6 +1548,7 @@ struct configuration_spec
     * - RUNTIME_FEATURE_CGI_EDIT_ACTIONS
     * - RUNTIME_FEATURE_CGI_TOGGLE
     * - RUNTIME_FEATURE_HTTP_TOGGLE
+    * - RUNTIME_FEATURE_SPLIT_LARGE_FORMS
     */
    unsigned feature_flags;
 
@@ -1452,6 +1558,9 @@ struct configuration_spec
    /** The config file directory. */
    const char *confdir;
 
+   /** The directory for customized CGI templates. */
+   const char *templdir;
+
    /** The log file directory. */
    const char *logdir;