Not needed - This URL can be started directly from the Help menu.
[privoxy.git] / showargs.c
1 const char showargs_rcs[] = "$Id: showargs.c,v 1.21 2001/07/30 22:08:36 jongfoster Exp $";
2 /*********************************************************************
3  *
4  * File        :  $Source: /cvsroot/ijbswa/current/showargs.c,v $
5  *
6  * Purpose     :  Contains various utility routines needed to 
7  *                generate the show-proxy-args page.
8  *                FIXME: Is this really stuff for a separate file?
9  *
10  * Copyright   :  Written by and Copyright (C) 2001 the SourceForge
11  *                IJBSWA team.  http://ijbswa.sourceforge.net
12  *
13  *                Based on the Internet Junkbuster originally written
14  *                by and Copyright (C) 1997 Anonymous Coders and 
15  *                Junkbusters Corporation.  http://www.junkbusters.com
16  *
17  *                This program is free software; you can redistribute it 
18  *                and/or modify it under the terms of the GNU General
19  *                Public License as published by the Free Software
20  *                Foundation; either version 2 of the License, or (at
21  *                your option) any later version.
22  *
23  *                This program is distributed in the hope that it will
24  *                be useful, but WITHOUT ANY WARRANTY; without even the
25  *                implied warranty of MERCHANTABILITY or FITNESS FOR A
26  *                PARTICULAR PURPOSE.  See the GNU General Public
27  *                License for more details.
28  *
29  *                The GNU General Public License should be included with
30  *                this file.  If not, you can view it at
31  *                http://www.gnu.org/copyleft/gpl.html
32  *                or write to the Free Software Foundation, Inc., 59
33  *                Temple Place - Suite 330, Boston, MA  02111-1307, USA.
34  *
35  * Revisions   :
36  *    $Log: showargs.c,v $
37  *    Revision 1.21  2001/07/30 22:08:36  jongfoster
38  *    Tidying up #defines:
39  *    - All feature #defines are now of the form FEATURE_xxx
40  *    - Permanently turned off WIN_GUI_EDIT
41  *    - Permanently turned on WEBDAV and SPLIT_PROXY_ARGS
42  *
43  *    Revision 1.20  2001/07/18 17:27:22  oes
44  *    Adapted to new #defines
45  *
46  *    Revision 1.19  2001/07/13 14:11:36  oes
47  *     - Included SHOW_RCS for deanimate.*
48  *     - Removed all #ifdef PCRS
49  *
50  *
51  *    Revision 1.18  2001/07/02 02:55:16  iwanttokeepanon
52  *    Apended " on some sites" to the HTML generating function `show_defines' (@ line
53  *    392); since "DENY_GZIP" is not *really* necessary for all PCRS functionallity.
54  *
55  *    Revision 1.17  2001/06/29 21:45:41  oes
56  *    Indentation, CRLF->LF, Tab-> Space
57  *
58  *    Revision 1.16  2001/06/29 13:35:07  oes
59  *    - Adapted
60  *    - Improved comments
61  *    - Removed init_proxy_args
62  *    - Renamed end_proxy_args(csp) to show_rcs(void)
63  *    - Removed logentry from cancelled commit
64  *    - Destroyed support for ndef SPLIT_PROXY_ARGS (Ooops)
65  *    - Separated the #define list into show_defines()
66  *
67  *    Revision 1.15  2001/06/09 10:55:28  jongfoster
68  *    Changing BUFSIZ ==> BUFFER_SIZE
69  *
70  *    Revision 1.14  2001/06/07 23:15:40  jongfoster
71  *    Removing config->proxy_args_gateways
72  *    Missing return statement added to end_proxy_args().
73  *
74  *    Revision 1.13  2001/06/06 09:37:59  sarantis
75  *    Fix misplaced comment start.
76  *
77  *    Revision 1.12  2001/06/04 10:41:52  swa
78  *    show version string of cgi.h and cgi.c
79  *
80  *    Revision 1.11  2001/06/03 11:03:48  oes
81  *    moved stuff to cgi.c
82  *
83  *    Revision 1.10  2001/05/31 21:36:07  jongfoster
84  *    Added RCS for actions.[ch] and list.[ch]
85  *
86  *    Revision 1.9  2001/05/29 23:11:38  oes
87  *
88  *     - Moved strsav() from showargs to miscutil
89  *
90  *    Revision 1.8  2001/05/29 09:50:24  jongfoster
91  *    Unified blocklist/imagelist/permissionslist.
92  *    File format is still under discussion, but the internal changes
93  *    are (mostly) done.
94  *
95  *    Also modified interceptor behaviour:
96  *    - We now intercept all URLs beginning with one of the following
97  *      prefixes (and *only* these prefixes):
98  *        * http://i.j.b/
99  *        * http://ijbswa.sf.net/config/
100  *        * http://ijbswa.sourceforge.net/config/
101  *    - New interceptors "home page" - go to http://i.j.b/ to see it.
102  *    - Internal changes so that intercepted and fast redirect pages
103  *      are not replaced with an image.
104  *    - Interceptors now have the option to send a binary page direct
105  *      to the client. (i.e. ijb-send-banner uses this)
106  *    - Implemented show-url-info interceptor.  (Which is why I needed
107  *      the above interceptors changes - a typical URL is
108  *      "http://i.j.b/show-url-info?url=www.somesite.com/banner.gif".
109  *      The previous mechanism would not have intercepted that, and
110  *      if it had been intercepted then it then it would have replaced
111  *      it with an image.)
112  *
113  *    Revision 1.7  2001/05/26 00:28:36  jongfoster
114  *    Automatic reloading of config file.
115  *    Removed obsolete SIGHUP support (Unix) and Reload menu option (Win32).
116  *    Most of the global variables have been moved to a new
117  *    struct configuration_spec, accessed through csp->config->globalname
118  *    Most of the globals remaining are used by the Win32 GUI.
119  *
120  *    Revision 1.6  2001/05/25 22:32:56  jongfoster
121  *    CRLF->LF
122  *
123  *    Revision 1.5  2001/05/22 18:54:49  oes
124  *
125  *    - Enabled filtering banners by size rather than URL
126  *      by adding patterns that replace all standard banner
127  *      sizes with the "Junkbuster" gif to the re_filterfile
128  *
129  *    - Enabled filtering WebBugs by providing a pattern
130  *      which kills all 1x1 images
131  *
132  *    - Added support for PCRE_UNGREEDY behaviour to pcrs,
133  *      which is selected by the (nonstandard and therefore
134  *      capital) letter 'U' in the option string.
135  *      It causes the quantifiers to be ungreedy by default.
136  *      Appending a ? turns back to greedy (!).
137  *
138  *    - Added a new interceptor ijb-send-banner, which
139  *      sends back the "Junkbuster" gif. Without imagelist or
140  *      MSIE detection support, or if tinygif = 1, or the
141  *      URL isn't recognized as an imageurl, a lame HTML
142  *      explanation is sent instead.
143  *
144  *    - Added new feature, which permits blocking remote
145  *      script redirects and firing back a local redirect
146  *      to the browser.
147  *      The feature is conditionally compiled, i.e. it
148  *      can be disabled with --disable-fast-redirects,
149  *      plus it must be activated by a "fast-redirects"
150  *      line in the config file, has its own log level
151  *      and of course wants to be displayed by show-proxy-args
152  *      Note: Boy, all the #ifdefs in 1001 locations and
153  *      all the fumbling with configure.in and acconfig.h
154  *      were *way* more work than the feature itself :-(
155  *
156  *    - Because a generic redirect template was needed for
157  *      this, tinygif = 3 now uses the same.
158  *
159  *    - Moved GIFs, and other static HTTP response templates
160  *      to project.h
161  *
162  *    - Some minor fixes
163  *
164  *    - Removed some >400 CRs again (Jon, you really worked
165  *      a lot! ;-)
166  *
167  *    Revision 1.4  2001/05/20 16:44:47  jongfoster
168  *    Removing last hardcoded JunkBusters.com URLs.
169  *
170  *    Revision 1.3  2001/05/20 01:21:20  jongfoster
171  *    Version 2.9.4 checkin.
172  *    - Merged popupfile and cookiefile, and added control over PCRS
173  *      filtering, in new "permissionsfile".
174  *    - Implemented LOG_LEVEL_FATAL, so that if there is a configuration
175  *      file error you now get a message box (in the Win32 GUI) rather
176  *      than the program exiting with no explanation.
177  *    - Made killpopup use the PCRS MIME-type checking and HTTP-header
178  *      skipping.
179  *    - Removed tabs from "config"
180  *    - Moved duplicated url parsing code in "loaders.c" to a new funcition.
181  *    - Bumped up version number.
182  *
183  *    Revision 1.2  2001/05/17 23:01:01  oes
184  *     - Cleaned CRLF's from the sources and related files
185  *
186  *    Revision 1.1.1.1  2001/05/15 13:59:03  oes
187  *    Initial import of version 2.9.3 source tree
188  *
189  *
190  *********************************************************************/
191 \f
192 #include "config.h"
193
194 #include <stdio.h>
195 #include <stdlib.h>
196 #include <sys/types.h>
197 #include <string.h>
198 #include <malloc.h>
199 #include <errno.h>
200
201 #include "project.h"
202 #include "showargs.h"
203 #include "jcc.h"
204 #include "encode.h"
205 #include "parsers.h"
206 #include "errlog.h"
207 #include "miscutil.h"
208 #include "gateway.h"
209 #include "cgi.h"
210 #include "list.h"
211
212 const char showargs_h_rcs[] = SHOWARGS_H_VERSION;
213
214
215 /*********************************************************************
216  *
217  * Function    :  savearg
218  *
219  * Description :  Called from `load_config'.  It saves each non-empty
220  *                and non-comment line from config into a list.  This
221  *                list is used to create the show-proxy-args page.
222  *
223  * Parameters  :
224  *          1  :  c = config setting that was found
225  *          2  :  o = the setting's argument (if any)
226  *
227  * Returns     :  N/A
228  *
229  *********************************************************************/
230 void savearg(char *c, char *o, struct configuration_spec * config)
231 {
232    char buf[BUFFER_SIZE];
233
234    *buf = '\0';
235
236    if ( ( NULL != c ) && ( '\0' != *c ) )
237    {
238       if ((c = html_encode(c)))
239       {
240          sprintf(buf, "<a href=\"" REDIRECT_URL "option#%s\">%s</a> ", c, c);
241       }
242       freez(c);
243    }
244    if ( ( NULL != o ) && ( '\0' != *o ) )
245    {
246       if ((o = html_encode(o)))
247       {
248          if (strncmpic(o, "http://", 7) == 0)
249          {
250             strcat(buf, "<a href=\"");
251             strcat(buf, o);
252             strcat(buf, "\">");
253             strcat(buf, o);
254             strcat(buf, "</a>");
255          }
256          else
257          {
258             strcat(buf, o);
259          }
260       }
261       freez(o);
262    }
263
264    strcat(buf, "<br>\n");
265
266    config->proxy_args = strsav(config->proxy_args, buf);
267
268 }
269
270
271 /*********************************************************************
272  *
273  * Function    :  show_rcs
274  *
275  * Description :  Create a string with the rcs info for all sourcefiles
276  *
277  * Parameters  :  None
278  *
279  * Returns     :  string 
280  *
281  *********************************************************************/
282 char *show_rcs(void)
283 {
284    char *b = NULL;
285    char buf[BUFFER_SIZE];
286
287    /* Instead of including *all* dot h's in the project (thus creating a
288     * tremendous amount of dependencies), I will concede to declaring them
289     * as extern's.  This forces the developer to add to this list, but oh well.
290     */
291
292 #define SHOW_RCS(__x)            \
293    {                             \
294       extern const char __x[];   \
295       sprintf(buf, "%s\n", __x); \
296       b = strsav(b, buf);        \
297    }
298
299    /* In alphabetical order */
300    SHOW_RCS(actions_h_rcs)
301    SHOW_RCS(actions_rcs)
302    SHOW_RCS(cgi_h_rcs)
303    SHOW_RCS(cgi_rcs)
304 #ifdef __MINGW32__
305    SHOW_RCS(cygwin_h_rcs)
306 #endif
307    SHOW_RCS(deanimate_h_rcs)
308    SHOW_RCS(deanimate_rcs)
309    SHOW_RCS(encode_h_rcs)
310    SHOW_RCS(encode_rcs)
311    SHOW_RCS(errlog_h_rcs)
312    SHOW_RCS(errlog_rcs)
313    SHOW_RCS(filters_h_rcs)
314    SHOW_RCS(filters_rcs)
315    SHOW_RCS(gateway_h_rcs)
316    SHOW_RCS(gateway_rcs)
317 #ifdef GNU_REGEX
318    SHOW_RCS(gnu_regex_h_rcs)
319    SHOW_RCS(gnu_regex_rcs)
320 #endif /* def GNU_REGEX */
321    SHOW_RCS(jbsockets_h_rcs)
322    SHOW_RCS(jbsockets_rcs)
323    SHOW_RCS(jcc_h_rcs)
324    SHOW_RCS(jcc_rcs)
325 #ifdef FEATURE_KILL_POPUPS
326    SHOW_RCS(killpopup_h_rcs)
327    SHOW_RCS(killpopup_rcs)
328 #endif /* def FEATURE_KILL_POPUPS */
329    SHOW_RCS(list_h_rcs)
330    SHOW_RCS(list_rcs)
331    SHOW_RCS(loadcfg_h_rcs)
332    SHOW_RCS(loadcfg_rcs)
333    SHOW_RCS(loaders_h_rcs)
334    SHOW_RCS(loaders_rcs)
335    SHOW_RCS(miscutil_h_rcs)
336    SHOW_RCS(miscutil_rcs)
337    SHOW_RCS(parsers_h_rcs)
338    SHOW_RCS(parsers_rcs)
339    SHOW_RCS(pcrs_rcs)
340    SHOW_RCS(pcrs_h_rcs)
341    SHOW_RCS(project_h_rcs)
342    SHOW_RCS(showargs_h_rcs)
343    SHOW_RCS(showargs_rcs)
344    SHOW_RCS(ssplit_h_rcs)
345    SHOW_RCS(ssplit_rcs)
346 #ifdef _WIN32
347 #ifndef _WIN_CONSOLE
348    SHOW_RCS(w32log_h_rcs)
349    SHOW_RCS(w32log_rcs)
350    SHOW_RCS(w32res_h_rcs)
351    SHOW_RCS(w32taskbar_h_rcs)
352    SHOW_RCS(w32taskbar_rcs)
353 #endif /* ndef _WIN_CONSOLE */
354    SHOW_RCS(win32_h_rcs)
355    SHOW_RCS(win32_rcs)
356 #endif /* def _WIN32 */
357
358 #undef SHOW_RCS
359
360    return(b);
361 }
362
363 /*********************************************************************
364  *
365  * Function    :  show_defines
366  *
367  * Description :  Create a string with all conditional #defines used
368  *                when building
369  *
370  * Parameters  :  None
371  *
372  * Returns     :  string 
373  *
374  *********************************************************************/
375 struct map * show_defines(struct map *exports)
376 {
377
378 #ifdef FEATURE_ACL
379    exports = map_conditional(exports, "FEATURE_ACL", 1);
380 #else /* ifndef FEATURE_ACL */
381    exports = map_conditional(exports, "FEATURE_ACL", 0);
382 #endif /* ndef FEATURE_ACL */
383
384 #ifdef FEATURE_COOKIE_JAR
385    exports = map_conditional(exports, "FEATURE_COOKIE_JAR", 1);
386 #else /* ifndef FEATURE_COOKIE_JAR */
387    exports = map_conditional(exports, "FEATURE_COOKIE_JAR", 0);
388 #endif /* ndef FEATURE_COOKIE_JAR */
389
390 #ifdef FEATURE_DENY_GZIP
391    exports = map_conditional(exports, "FEATURE_DENY_GZIP", 1);
392 #else /* ifndef FEATURE_DENY_GZIP */
393    exports = map_conditional(exports, "FEATURE_DENY_GZIP", 0);
394 #endif /* ndef FEATURE_DENY_GZIP */
395
396 #ifdef FEATURE_FAST_REDIRECTS
397    exports = map_conditional(exports, "FEATURE_FAST_REDIRECTS", 1);
398 #else /* ifndef FEATURE_FAST_REDIRECTS */
399    exports = map_conditional(exports, "FEATURE_FAST_REDIRECTS", 0);
400 #endif /* ndef FEATURE_FAST_REDIRECTS */
401
402 #ifdef FEATURE_FORCE_LOAD
403    exports = map_conditional(exports, "FEATURE_FORCE_LOAD", 1);
404 #else /* ifndef FEATURE_FORCE_LOAD */
405    exports = map_conditional(exports, "FEATURE_FORCE_LOAD", 0);
406 #endif /* ndef FEATURE_FORCE_LOAD */
407
408 #ifdef FEATURE_IMAGE_BLOCKING
409    exports = map_conditional(exports, "FEATURE_IMAGE_BLOCKING", 1);
410 #else /* ifndef FEATURE_IMAGE_BLOCKING */
411    exports = map_conditional(exports, "FEATURE_IMAGE_BLOCKING, 0);
412 #endif /* ndef FEATURE_IMAGE_BLOCKING */
413
414 #ifdef FEATURE_IMAGE_DETECT_MSIE
415    exports = map_conditional(exports, "FEATURE_IMAGE_DETECT_MSIE", 1);
416 #else /* ifndef FEATURE_IMAGE_DETECT_MSIE */
417    exports = map_conditional(exports, "FEATURE_IMAGE_DETECT_MSIE", 0);
418 #endif /* ndef FEATURE_IMAGE_DETECT_MSIE */
419
420 #ifdef FEATURE_KILL_POPUPS
421    exports = map_conditional(exports, "FEATURE_KILL_POPUPS", 1);
422 #else /* ifndef FEATURE_KILL_POPUPS */
423    exports = map_conditional(exports, "FEATURE_KILL_POPUPS", 0);
424 #endif /* ndef FEATURE_KILL_POPUPS */
425
426 #ifdef FEATURE_PTHREAD
427    exports = map_conditional(exports, "FEATURE_PTHREAD", 1);
428 #else /* ifndef FEATURE_PTHREAD */
429    exports = map_conditional(exports, "FEATURE_PTHREAD", 0);
430 #endif /* ndef FEATURE_PTHREAD */
431
432 #ifdef FEATURE_STATISTICS
433    exports = map_conditional(exports, "FEATURE_STATISTICS", 1);
434 #else /* ifndef FEATURE_STATISTICS */
435    exports = map_conditional(exports, "FEATURE_STATISTICS", 0);
436 #endif /* ndef FEATURE_STATISTICS */
437
438 #ifdef FEATURE_TOGGLE
439    exports = map_conditional(exports, "FEATURE_TOGGLE", 1);
440 #else /* ifndef FEATURE_TOGGLE */
441    exports = map_conditional(exports, "FEATURE_TOGGLE", 0);
442 #endif /* ndef FEATURE_TOGGLE */
443
444 #ifdef FEATURE_TRUST
445    exports = map_conditional(exports, "FEATURE_TRUST", 1);
446 #else /* ifndef FEATURE_TRUST */
447    exports = map_conditional(exports, "FEATURE_TRUST", 0);
448 #endif /* ndef FEATURE_TRUST */
449
450 #ifdef REGEX_GNU
451    exports = map_conditional(exports, "REGEX_GNU", 1);
452 #else /* ifndef REGEX_GNU */
453    exports = map_conditional(exports, "REGEX_GNU", 0);
454 #endif /* def REGEX_GNU */
455
456 #ifdef REGEX_PCRE
457    exports = map_conditional(exports, "REGEX_PCRE", 1);
458 #else /* ifndef REGEX_PCRE */
459    exports = map_conditional(exports, "REGEX_PCRE", 0);
460 #endif /* def REGEX_PCRE */
461
462 #ifdef STATIC_PCRE
463    exports = map_conditional(exports, "STATIC_PCRE", 1);
464 #else /* ifndef STATIC_PCRE */
465    exports = map_conditional(exports, "STATIC_PCRE", 0);
466 #endif /* ndef STATIC_PCRE */
467
468 #ifdef STATIC_PCRS
469    exports = map_conditional(exports, "STATIC_PCRS", 1);
470 #else /* ifndef STATIC_PCRS */
471    exports = map_conditional(exports, "STATIC_PCRS", 0);
472 #endif /* ndef STATIC_PCRS */
473
474    exports = map(exports, "FORCE_PREFIX", 1, FORCE_PREFIX, 1);
475
476    return exports;
477 }
478
479
480 /*
481   Local Variables:
482   tab-width: 3
483   end:
484 */