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