- Use the shiny new CSS "pattern" class.
[privoxy.git] / filters.h
1 #ifndef FILTERS_H_INCLUDED
2 #define FILTERS_H_INCLUDED
3 #define FILTERS_H_VERSION "$Id: filters.h,v 1.30 2007/09/29 10:21:16 fabiankeil Exp $"
4 /*********************************************************************
5  *
6  * File        :  $Source: /cvsroot/ijbswa/current/filters.h,v $
7  *
8  * Purpose     :  Declares functions to parse/crunch headers and pages.
9  *                Functions declared include:
10  *                   `acl_addr', `add_stats', `block_acl', `block_imageurl',
11  *                   `block_url', `url_actions', `filter_popups', `forward_url'
12  *                   `ij_untrusted_url', `intercept_url', `re_process_buffer',
13  *                   `show_proxy_args', and `trust_url'
14  *
15  * Copyright   :  Written by and Copyright (C) 2001, 2004 the SourceForge
16  *                Privoxy team. http://www.privoxy.org/
17  *
18  *                Based on the Internet Junkbuster originally written
19  *                by and Copyright (C) 1997 Anonymous Coders and 
20  *                Junkbusters Corporation.  http://www.junkbusters.com
21  *
22  *                This program is free software; you can redistribute it 
23  *                and/or modify it under the terms of the GNU General
24  *                Public License as published by the Free Software
25  *                Foundation; either version 2 of the License, or (at
26  *                your option) any later version.
27  *
28  *                This program is distributed in the hope that it will
29  *                be useful, but WITHOUT ANY WARRANTY; without even the
30  *                implied warranty of MERCHANTABILITY or FITNESS FOR A
31  *                PARTICULAR PURPOSE.  See the GNU General Public
32  *                License for more details.
33  *
34  *                The GNU General Public License should be included with
35  *                this file.  If not, you can view it at
36  *                http://www.gnu.org/copyleft/gpl.html
37  *                or write to the Free Software Foundation, Inc., 59
38  *                Temple Place - Suite 330, Boston, MA  02111-1307, USA.
39  *
40  * Revisions   :
41  *    $Log: filters.h,v $
42  *    Revision 1.30  2007/09/29 10:21:16  fabiankeil
43  *    - Move get_filter_function() from jcc.c to filters.c
44  *      so the filter functions can be static.
45  *    - Don't bother filtering body-less responses.
46  *
47  *    Revision 1.29  2007/09/28 16:38:55  fabiankeil
48  *    - Execute content filters through execute_content_filter().
49  *    - Add prepare_for_filtering() so filter functions don't have to
50  *      care about de-chunking and decompression. As a side effect this enables
51  *      decompression for gif_deanimate_response() and jpeg_inspect_response().
52  *    - Change remove_chunked_transfer_coding()'s return type to jb_err.
53  *      Some clowns feel like chunking empty responses in which case
54  *      (size == 0) is valid but previously would be interpreted as error.
55  *
56  *    Revision 1.28  2007/09/02 15:31:20  fabiankeil
57  *    Move match_portlist() from filter.c to urlmatch.c.
58  *    It's used for url matching, not for filtering.
59  *
60  *    Revision 1.27  2007/04/30 15:02:18  fabiankeil
61  *    Introduce dynamic pcrs jobs that can resolve variables.
62  *
63  *    Revision 1.26  2007/03/13 11:28:43  fabiankeil
64  *    - Fix port handling in acl_addr() and use a temporary acl spec
65  *      copy so error messages don't contain a truncated version.
66  *    - Log size of iob before and after decompression.
67  *
68  *    Revision 1.25  2007/01/12 15:36:44  fabiankeil
69  *    Mark *csp as immutable for is_untrusted_url()
70  *    and is_imageurl(). Closes FR 1237736.
71  *
72  *    Revision 1.24  2006/12/29 18:30:46  fabiankeil
73  *    Fixed gcc43 conversion warnings,
74  *    changed sprintf calls to snprintf.
75  *
76  *    Revision 1.23  2006/11/28 15:19:43  fabiankeil
77  *    Implemented +redirect{s@foo@bar@} to generate
78  *    a redirect based on a rewritten version of the
79  *    original URL.
80  *
81  *    Revision 1.22  2006/07/18 14:48:46  david__schmidt
82  *    Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
83  *    with what was really the latest development (the v_3_0_branch branch)
84  *
85  *    Revision 1.20.2.2  2004/10/03 12:53:32  david__schmidt
86  *    Add the ability to check jpeg images for invalid
87  *    lengths of comment blocks.  Defensive strategy
88  *    against the exploit:
89  *       Microsoft Security Bulletin MS04-028
90  *       Buffer Overrun in JPEG Processing (GDI+) Could
91  *       Allow Code Execution (833987)
92  *    Enabled with +inspect-jpegs in actions files.
93  *
94  *    Revision 1.20.2.1  2002/09/25 14:51:51  oes
95  *    Added basic support for OPTIONS and TRACE HTTP methods:
96  *    New function direct_response which handles OPTIONS and
97  *    TRACE requests whose Max-Forwards header field is zero.
98  *
99  *    Revision 1.20  2002/04/02 14:56:16  oes
100  *    Bugfix: is_untrusted_url() and trust_url() now depend on FEATURE_TRUST, not FEATURE_COOKIE_JAR
101  *
102  *    Revision 1.19  2002/03/26 22:29:54  swa
103  *    we have a new homepage!
104  *
105  *    Revision 1.18  2002/03/25 22:12:45  oes
106  *    Added fix for undefined INADDR_NONE on Solaris by Bart Schelstraete
107  *
108  *    Revision 1.17  2002/03/24 13:25:43  swa
109  *    name change related issues
110  *
111  *    Revision 1.16  2002/01/17 21:01:02  jongfoster
112  *    Moving all our URL and URL pattern parsing code to urlmatch.c.
113  *
114  *    Revision 1.15  2001/10/10 16:44:16  oes
115  *    Added match_portlist function
116  *
117  *    Revision 1.14  2001/10/07 15:41:40  oes
118  *    Added prototype for remove_chunked_transfer_coding
119  *
120  *    Revision 1.13  2001/07/30 22:08:36  jongfoster
121  *    Tidying up #defines:
122  *    - All feature #defines are now of the form FEATURE_xxx
123  *    - Permanently turned off WIN_GUI_EDIT
124  *    - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
125  *
126  *    Revision 1.12  2001/07/29 19:01:11  jongfoster
127  *    Changed _FILENAME_H to FILENAME_H_INCLUDED.
128  *    Added forward declarations for needed structures.
129  *
130  *    Revision 1.11  2001/07/13 14:00:18  oes
131  *     - Introduced gif_deanimate_response
132  *     - Renamed re_process_buffer to pcrs_filter_response
133  *     - Removed all #ifdef PCRS
134  *
135  *    Revision 1.10  2001/06/29 13:29:01  oes
136  *    Cleaned up and updated to reflect the changesin
137  *    filters.c
138  *
139  *    Revision 1.9  2001/06/07 23:10:53  jongfoster
140  *    Replacing struct gateway with struct forward_spec
141  *
142  *    Revision 1.8  2001/06/03 19:12:00  oes
143  *    extracted-CGI relevant stuff
144  *
145  *    Revision 1.7  2001/05/31 21:21:30  jongfoster
146  *    Permissionsfile / actions file changes:
147  *    - Changed "permission" to "action" throughout
148  *    - changes to file format to allow string parameters
149  *    - Moved helper functions to actions.c
150  *
151  *    Revision 1.6  2001/05/29 09:50:24  jongfoster
152  *    Unified blocklist/imagelist/permissionslist.
153  *    File format is still under discussion, but the internal changes
154  *    are (mostly) done.
155  *
156  *    Also modified interceptor behaviour:
157  *    - We now intercept all URLs beginning with one of the following
158  *      prefixes (and *only* these prefixes):
159  *        * http://i.j.b/
160  *        * http://ijbswa.sf.net/config/
161  *        * http://ijbswa.sourceforge.net/config/
162  *    - New interceptors "home page" - go to http://i.j.b/ to see it.
163  *    - Internal changes so that intercepted and fast redirect pages
164  *      are not replaced with an image.
165  *    - Interceptors now have the option to send a binary page direct
166  *      to the client. (i.e. ijb-send-banner uses this)
167  *    - Implemented show-url-info interceptor.  (Which is why I needed
168  *      the above interceptors changes - a typical URL is
169  *      "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
170  *      The previous mechanism would not have intercepted that, and
171  *      if it had been intercepted then it then it would have replaced
172  *      it with an image.)
173  *
174  *    Revision 1.5  2001/05/27 22:17:04  oes
175  *
176  *    - re_process_buffer no longer writes the modified buffer
177  *      to the client, which was very ugly. It now returns the
178  *      buffer, which it is then written by chat.
179  *
180  *    - content_length now adjusts the Content-Length: header
181  *      for modified documents rather than crunch()ing it.
182  *      (Length info in csp->content_length, which is 0 for
183  *      unmodified documents)
184  *
185  *    - For this to work, sed() is called twice when filtering.
186  *
187  *    Revision 1.4  2001/05/26 15:26:15  jongfoster
188  *    ACL feature now provides more security by immediately dropping
189  *    connections from untrusted hosts.
190  *
191  *    Revision 1.3  2001/05/22 18:46:04  oes
192  *
193  *    - Enabled filtering banners by size rather than URL
194  *      by adding patterns that replace all standard banner
195  *      sizes with the "Junkbuster" gif to the re_filterfile
196  *
197  *    - Enabled filtering WebBugs by providing a pattern
198  *      which kills all 1x1 images
199  *
200  *    - Added support for PCRE_UNGREEDY behaviour to pcrs,
201  *      which is selected by the (nonstandard and therefore
202  *      capital) letter 'U' in the option string.
203  *      It causes the quantifiers to be ungreedy by default.
204  *      Appending a ? turns back to greedy (!).
205  *
206  *    - Added a new interceptor ijb-send-banner, which
207  *      sends back the "Junkbuster" gif. Without imagelist or
208  *      MSIE detection support, or if tinygif = 1, or the
209  *      URL isn't recognized as an imageurl, a lame HTML
210  *      explanation is sent instead.
211  *
212  *    - Added new feature, which permits blocking remote
213  *      script redirects and firing back a local redirect
214  *      to the browser.
215  *      The feature is conditionally compiled, i.e. it
216  *      can be disabled with --disable-fast-redirects,
217  *      plus it must be activated by a "fast-redirects"
218  *      line in the config file, has its own log level
219  *      and of course wants to be displayed by show-proxy-args
220  *      Note: Boy, all the #ifdefs in 1001 locations and
221  *      all the fumbling with configure.in and acconfig.h
222  *      were *way* more work than the feature itself :-(
223  *
224  *    - Because a generic redirect template was needed for
225  *      this, tinygif = 3 now uses the same.
226  *
227  *    - Moved GIFs, and other static HTTP response templates
228  *      to project.h
229  *
230  *    - Some minor fixes
231  *
232  *    - Removed some >400 CRs again (Jon, you really worked
233  *      a lot! ;-)
234  *
235  *    Revision 1.2  2001/05/20 01:21:20  jongfoster
236  *    Version 2.9.4 checkin.
237  *    - Merged popupfile and cookiefile, and added control over PCRS
238  *      filtering, in new "permissionsfile".
239  *    - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
240  *      file error you now get a message box (in the Win32 GUI) rather
241  *      than the program exiting with no explanation.
242  *    - Made killpopup use the PCRS MIME-type checking and HTTP-header
243  *      skipping.
244  *    - Removed tabs from "config"
245  *    - Moved duplicated url parsing code in "loaders.c" to a new funcition.
246  *    - Bumped up version number.
247  *
248  *    Revision 1.1.1.1  2001/05/15 13:58:52  oes
249  *    Initial import of version 2.9.3 source tree
250  *
251  *
252  *********************************************************************/
253 \f
254
255 #include "project.h"
256
257 #ifdef __cplusplus
258 extern "C" {
259 #endif
260
261
262 struct access_control_addr;
263 struct client_state;
264 struct http_request;
265 struct http_response;
266 struct current_action_spec;
267 struct url_actions;
268 struct url_spec;
269
270
271 /*
272  * ACL checking
273  */
274 #ifdef FEATURE_ACL
275 extern int block_acl(struct access_control_addr *dst, struct client_state *csp);
276 extern int acl_addr(const char *aspec, struct access_control_addr *aca);
277 #endif /* def FEATURE_ACL */
278
279 /*
280  * Interceptors
281  */
282 extern struct http_response *block_url(struct client_state *csp);
283 extern struct http_response *redirect_url(struct client_state *csp);
284 #ifdef FEATURE_TRUST
285 extern struct http_response *trust_url(struct client_state *csp);
286 #endif /* def FEATURE_TRUST */
287
288 /*
289  * Request inspectors
290  */
291 #ifdef FEATURE_TRUST
292 extern int is_untrusted_url(const struct client_state *csp);
293 #endif /* def FEATURE_TRUST */
294 #ifdef FEATURE_IMAGE_BLOCKING
295 extern int is_imageurl(const struct client_state *csp);
296 #endif /* def FEATURE_IMAGE_BLOCKING */
297
298 /*
299  * Determining applicable actions
300  */
301 extern void url_actions(struct http_request *http, 
302                         struct client_state *csp);
303 extern void apply_url_actions(struct current_action_spec *action, 
304                               struct http_request *http, 
305                               struct url_actions *b);
306 /*
307  * Determining parent proxies
308  */
309 extern const struct forward_spec *forward_url(struct http_request *http, struct client_state *csp);
310
311 /*
312  * Content modification
313  */
314
315 typedef char *(*filter_function_ptr)();
316 extern char *execute_content_filter(struct client_state *csp, filter_function_ptr content_filter);
317
318 extern filter_function_ptr get_filter_function(struct client_state *csp);
319 extern char *execute_single_pcrs_command(char *subject, const char *pcrs_command, int *hits);
320 extern char *rewrite_url(char *old_url, const char *pcrs_command);
321 extern char *get_last_url(char *subject, const char *redirect_mode);
322
323 extern pcrs_job *compile_dynamic_pcrs_job_list(const struct client_state *csp, const struct re_filterfile_spec *b);
324
325 extern inline int content_filters_enabled(const struct client_state *csp);
326
327 /*
328  * Handling Max-Forwards:
329  */
330 extern struct http_response *direct_response( struct client_state *csp);
331
332
333 /*
334  * Solaris fix:
335  */
336 #ifndef INADDR_NONE
337 #define INADDR_NONE -1
338 #endif     
339
340 /* 
341  * Revision control strings from this header and associated .c file
342  */
343 extern const char filters_rcs[];
344 extern const char filters_h_rcs[];
345
346 #ifdef __cplusplus
347 } /* extern "C" */
348 #endif
349
350 #endif /* ndef FILTERS_H_INCLUDED */
351
352 /*
353   Local Variables:
354   tab-width: 3
355   end:
356 */