Fixed gcc43 conversion warnings,
[privoxy.git] / filters.h
1 #ifndef FILTERS_H_INCLUDED
2 #define FILTERS_H_INCLUDED
3 #define FILTERS_H_VERSION "$Id: filters.h,v 1.23 2006/11/28 15:19:43 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.23  2006/11/28 15:19:43  fabiankeil
43  *    Implemented +redirect{s@foo@bar@} to generate
44  *    a redirect based on a rewritten version of the
45  *    original URL.
46  *
47  *    Revision 1.22  2006/07/18 14:48:46  david__schmidt
48  *    Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
49  *    with what was really the latest development (the v_3_0_branch branch)
50  *
51  *    Revision 1.20.2.2  2004/10/03 12:53:32  david__schmidt
52  *    Add the ability to check jpeg images for invalid
53  *    lengths of comment blocks.  Defensive strategy
54  *    against the exploit:
55  *       Microsoft Security Bulletin MS04-028
56  *       Buffer Overrun in JPEG Processing (GDI+) Could
57  *       Allow Code Execution (833987)
58  *    Enabled with +inspect-jpegs in actions files.
59  *
60  *    Revision 1.20.2.1  2002/09/25 14:51:51  oes
61  *    Added basic support for OPTIONS and TRACE HTTP methods:
62  *    New function direct_response which handles OPTIONS and
63  *    TRACE requests whose Max-Forwards header field is zero.
64  *
65  *    Revision 1.20  2002/04/02 14:56:16  oes
66  *    Bugfix: is_untrusted_url() and trust_url() now depend on FEATURE_TRUST, not FEATURE_COOKIE_JAR
67  *
68  *    Revision 1.19  2002/03/26 22:29:54  swa
69  *    we have a new homepage!
70  *
71  *    Revision 1.18  2002/03/25 22:12:45  oes
72  *    Added fix for undefined INADDR_NONE on Solaris by Bart Schelstraete
73  *
74  *    Revision 1.17  2002/03/24 13:25:43  swa
75  *    name change related issues
76  *
77  *    Revision 1.16  2002/01/17 21:01:02  jongfoster
78  *    Moving all our URL and URL pattern parsing code to urlmatch.c.
79  *
80  *    Revision 1.15  2001/10/10 16:44:16  oes
81  *    Added match_portlist function
82  *
83  *    Revision 1.14  2001/10/07 15:41:40  oes
84  *    Added prototype for remove_chunked_transfer_coding
85  *
86  *    Revision 1.13  2001/07/30 22:08:36  jongfoster
87  *    Tidying up #defines:
88  *    - All feature #defines are now of the form FEATURE_xxx
89  *    - Permanently turned off WIN_GUI_EDIT
90  *    - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
91  *
92  *    Revision 1.12  2001/07/29 19:01:11  jongfoster
93  *    Changed _FILENAME_H to FILENAME_H_INCLUDED.
94  *    Added forward declarations for needed structures.
95  *
96  *    Revision 1.11  2001/07/13 14:00:18  oes
97  *     - Introduced gif_deanimate_response
98  *     - Renamed re_process_buffer to pcrs_filter_response
99  *     - Removed all #ifdef PCRS
100  *
101  *    Revision 1.10  2001/06/29 13:29:01  oes
102  *    Cleaned up and updated to reflect the changesin
103  *    filters.c
104  *
105  *    Revision 1.9  2001/06/07 23:10:53  jongfoster
106  *    Replacing struct gateway with struct forward_spec
107  *
108  *    Revision 1.8  2001/06/03 19:12:00  oes
109  *    extracted-CGI relevant stuff
110  *
111  *    Revision 1.7  2001/05/31 21:21:30  jongfoster
112  *    Permissionsfile / actions file changes:
113  *    - Changed "permission" to "action" throughout
114  *    - changes to file format to allow string parameters
115  *    - Moved helper functions to actions.c
116  *
117  *    Revision 1.6  2001/05/29 09:50:24  jongfoster
118  *    Unified blocklist/imagelist/permissionslist.
119  *    File format is still under discussion, but the internal changes
120  *    are (mostly) done.
121  *
122  *    Also modified interceptor behaviour:
123  *    - We now intercept all URLs beginning with one of the following
124  *      prefixes (and *only* these prefixes):
125  *        * http://i.j.b/
126  *        * http://ijbswa.sf.net/config/
127  *        * http://ijbswa.sourceforge.net/config/
128  *    - New interceptors "home page" - go to http://i.j.b/ to see it.
129  *    - Internal changes so that intercepted and fast redirect pages
130  *      are not replaced with an image.
131  *    - Interceptors now have the option to send a binary page direct
132  *      to the client. (i.e. ijb-send-banner uses this)
133  *    - Implemented show-url-info interceptor.  (Which is why I needed
134  *      the above interceptors changes - a typical URL is
135  *      "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
136  *      The previous mechanism would not have intercepted that, and
137  *      if it had been intercepted then it then it would have replaced
138  *      it with an image.)
139  *
140  *    Revision 1.5  2001/05/27 22:17:04  oes
141  *
142  *    - re_process_buffer no longer writes the modified buffer
143  *      to the client, which was very ugly. It now returns the
144  *      buffer, which it is then written by chat.
145  *
146  *    - content_length now adjusts the Content-Length: header
147  *      for modified documents rather than crunch()ing it.
148  *      (Length info in csp->content_length, which is 0 for
149  *      unmodified documents)
150  *
151  *    - For this to work, sed() is called twice when filtering.
152  *
153  *    Revision 1.4  2001/05/26 15:26:15  jongfoster
154  *    ACL feature now provides more security by immediately dropping
155  *    connections from untrusted hosts.
156  *
157  *    Revision 1.3  2001/05/22 18:46:04  oes
158  *
159  *    - Enabled filtering banners by size rather than URL
160  *      by adding patterns that replace all standard banner
161  *      sizes with the "Junkbuster" gif to the re_filterfile
162  *
163  *    - Enabled filtering WebBugs by providing a pattern
164  *      which kills all 1x1 images
165  *
166  *    - Added support for PCRE_UNGREEDY behaviour to pcrs,
167  *      which is selected by the (nonstandard and therefore
168  *      capital) letter 'U' in the option string.
169  *      It causes the quantifiers to be ungreedy by default.
170  *      Appending a ? turns back to greedy (!).
171  *
172  *    - Added a new interceptor ijb-send-banner, which
173  *      sends back the "Junkbuster" gif. Without imagelist or
174  *      MSIE detection support, or if tinygif = 1, or the
175  *      URL isn't recognized as an imageurl, a lame HTML
176  *      explanation is sent instead.
177  *
178  *    - Added new feature, which permits blocking remote
179  *      script redirects and firing back a local redirect
180  *      to the browser.
181  *      The feature is conditionally compiled, i.e. it
182  *      can be disabled with --disable-fast-redirects,
183  *      plus it must be activated by a "fast-redirects"
184  *      line in the config file, has its own log level
185  *      and of course wants to be displayed by show-proxy-args
186  *      Note: Boy, all the #ifdefs in 1001 locations and
187  *      all the fumbling with configure.in and acconfig.h
188  *      were *way* more work than the feature itself :-(
189  *
190  *    - Because a generic redirect template was needed for
191  *      this, tinygif = 3 now uses the same.
192  *
193  *    - Moved GIFs, and other static HTTP response templates
194  *      to project.h
195  *
196  *    - Some minor fixes
197  *
198  *    - Removed some >400 CRs again (Jon, you really worked
199  *      a lot! ;-)
200  *
201  *    Revision 1.2  2001/05/20 01:21:20  jongfoster
202  *    Version 2.9.4 checkin.
203  *    - Merged popupfile and cookiefile, and added control over PCRS
204  *      filtering, in new "permissionsfile".
205  *    - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
206  *      file error you now get a message box (in the Win32 GUI) rather
207  *      than the program exiting with no explanation.
208  *    - Made killpopup use the PCRS MIME-type checking and HTTP-header
209  *      skipping.
210  *    - Removed tabs from "config"
211  *    - Moved duplicated url parsing code in "loaders.c" to a new funcition.
212  *    - Bumped up version number.
213  *
214  *    Revision 1.1.1.1  2001/05/15 13:58:52  oes
215  *    Initial import of version 2.9.3 source tree
216  *
217  *
218  *********************************************************************/
219 \f
220
221 #include "project.h"
222
223 #ifdef __cplusplus
224 extern "C" {
225 #endif
226
227
228 struct access_control_addr;
229 struct client_state;
230 struct http_request;
231 struct http_response;
232 struct current_action_spec;
233 struct url_actions;
234 struct url_spec;
235
236
237 /*
238  * ACL checking
239  */
240 #ifdef FEATURE_ACL
241 extern int block_acl(struct access_control_addr *dst, struct client_state *csp);
242 extern int acl_addr(char *aspec, struct access_control_addr *aca);
243 #endif /* def FEATURE_ACL */
244 extern int match_portlist(const char *portlist, int port);
245
246 /*
247  * Interceptors
248  */
249 extern struct http_response *block_url(struct client_state *csp);
250 extern struct http_response *redirect_url(struct client_state *csp);
251 #ifdef FEATURE_TRUST
252 extern struct http_response *trust_url(struct client_state *csp);
253 #endif /* def FEATURE_TRUST */
254
255 /*
256  * Request inspectors
257  */
258 #ifdef FEATURE_TRUST
259 extern int is_untrusted_url(struct client_state *csp);
260 #endif /* def FEATURE_TRUST */
261 #ifdef FEATURE_IMAGE_BLOCKING
262 extern int is_imageurl(struct client_state *csp);
263 #endif /* def FEATURE_IMAGE_BLOCKING */
264
265 /*
266  * Determining applicable actions
267  */
268 extern void url_actions(struct http_request *http, 
269                         struct client_state *csp);
270 extern void apply_url_actions(struct current_action_spec *action, 
271                               struct http_request *http, 
272                               struct url_actions *b);
273 /*
274  * Determining parent proxies
275  */
276 extern const struct forward_spec *forward_url(struct http_request *http, struct client_state *csp);
277
278 /*
279  * Content modification
280  */
281 extern char *pcrs_filter_response(struct client_state *csp);
282 extern char *gif_deanimate_response(struct client_state *csp);
283 extern char *jpeg_inspect_response(struct client_state *csp);
284 extern size_t remove_chunked_transfer_coding(char *buffer, const size_t size);
285 extern char *execute_single_pcrs_command(char *subject, const char *pcrs_command, int *hits);
286 extern char *rewrite_url(char *old_url, const char *pcrs_command);
287 extern char *get_last_url(char *subject, const char *redirect_mode);
288
289 /*
290  * Handling Max-Forwards:
291  */
292 extern struct http_response *direct_response( struct client_state *csp);
293
294
295 /*
296  * Solaris fix:
297  */
298 #ifndef INADDR_NONE
299 #define INADDR_NONE -1
300 #endif     
301
302 /* 
303  * Revision control strings from this header and associated .c file
304  */
305 extern const char filters_rcs[];
306 extern const char filters_h_rcs[];
307
308 #ifdef __cplusplus
309 } /* extern "C" */
310 #endif
311
312 #endif /* ndef FILTERS_H_INCLUDED */
313
314 /*
315   Local Variables:
316   tab-width: 3
317   end:
318 */