- Cleaned CRLF's from the sources and related files
[privoxy.git] / showargs.c
1 const char showargs_rcs[] = "$Id: showargs.c,v 1.1.1.1 2001/05/15 13:59:03 oes 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  *
9  * Copyright   :  Written by and Copyright (C) 2001 the SourceForge
10  *                IJBSWA team.  http://ijbswa.sourceforge.net
11  *
12  *                Based on the Internet Junkbuster originally written
13  *                by and Copyright (C) 1997 Anonymous Coders and 
14  *                Junkbusters Corporation.  http://www.junkbusters.com
15  *
16  *                This program is free software; you can redistribute it 
17  *                and/or modify it under the terms of the GNU General
18  *                Public License as published by the Free Software
19  *                Foundation; either version 2 of the License, or (at
20  *                your option) any later version.
21  *
22  *                This program is distributed in the hope that it will
23  *                be useful, but WITHOUT ANY WARRANTY; without even the
24  *                implied warranty of MERCHANTABILITY or FITNESS FOR A
25  *                PARTICULAR PURPOSE.  See the GNU General Public
26  *                License for more details.
27  *
28  *                The GNU General Public License should be included with
29  *                this file.  If not, you can view it at
30  *                http://www.gnu.org/copyleft/gpl.html
31  *                or write to the Free Software Foundation, Inc., 59
32  *                Temple Place - Suite 330, Boston, MA  02111-1307, USA.
33  *
34  * Revisions   :
35  *    $Log: showargs.c,v $
36  *    Revision 1.1.1.1  2001/05/15 13:59:03  oes
37  *    Initial import of version 2.9.3 source tree
38  *
39  *
40  *********************************************************************/
41 \f
42 #include "config.h"
43
44 #include <stdio.h>
45 #include <stdlib.h>
46 #include <sys/types.h>
47 #include <string.h>
48 #include <malloc.h>
49 #include <errno.h>
50
51 #include "showargs.h"
52 #include "jcc.h"
53 #include "encode.h"
54 #include "parsers.h"
55 #include "errlog.h"
56 #include "miscutil.h"
57 #include "gateway.h"
58
59 const char showargs_h_rcs[] = SHOWARGS_H_VERSION;
60
61 /*********************************************************************
62  *
63  * Function    :  strsav
64  *
65  * Description :  Reallocate "old" and append text to it.  This makes
66  *                it easier to append to malloc'd strings.
67  *
68  * Parameters  :
69  *          1  :  old = Old text that is to be extended.  Will be
70  *                free()d by this routine.
71  *          2  :  text_to_append = Text to be appended to old.
72  *
73  * Returns     :  Pointer to newly malloc'ed appended string.
74  *                If there is no text to append, return old.  Caller
75  *                must free().
76  *
77  *********************************************************************/
78 char *strsav(char *old, const char *text_to_append)
79 {
80    int old_len, new_len;
81    char *p;
82
83    if (( text_to_append == NULL) || (*text_to_append == '\0'))
84    {
85       return(old);
86    }
87
88    if (NULL != old)
89    {
90       old_len = strlen(old);
91    }
92    else
93    {
94       old_len = 0;
95    }
96
97    new_len = old_len + strlen(text_to_append) + 1;
98
99    if (old)
100    {
101       if ((p = realloc(old, new_len)) == NULL)
102       {
103          log_error(LOG_LEVEL_ERROR, "realloc(%d) bytes for proxy_args failed!", new_len);
104          exit(1);
105       }
106    }
107    else
108    {
109       if ((p = (char *)malloc(new_len)) == NULL)
110       {
111          log_error(LOG_LEVEL_ERROR, "malloc(%d) bytes for proxy_args failed!", new_len);
112          exit(1);
113       }
114    }
115
116    strcpy(p + old_len, text_to_append);
117    return(p);
118
119 }
120
121
122 /*********************************************************************
123  *
124  * Function    :  savearg
125  *
126  * Description :  Called from `load_config'.  It saves each non-empty
127  *                and non-comment line from config into a list.  This
128  *                list is used to create the show-proxy-args page.
129  *
130  * Parameters  :
131  *          1  :  c = config setting that was found
132  *          2  :  o = the setting's argument (if any)
133  *
134  * Returns     :  N/A
135  *
136  *********************************************************************/
137 void savearg(char *c, char *o)
138 {
139    char buf[BUFSIZ];
140
141    *buf = '\0';
142
143    if ( ( NULL != c ) && ( '\0' != *c ) )
144    {
145       if ((c = html_encode(c)))
146       {
147          sprintf(buf, "<a href=\"" REDIRECT_URL "option#%s\">%s</a> ", c, c);
148       }
149       freez(c);
150    }
151    if ( ( NULL != o ) && ( '\0' != *o ) )
152    {
153       if ((o = html_encode(o)))
154       {
155          if (strncmpic(o, "http://", 7) == 0)
156          {
157             strcat(buf, "<a href=\"");
158             strcat(buf, o);
159             strcat(buf, "\">");
160             strcat(buf, o);
161             strcat(buf, "</a>");
162          }
163          else
164          {
165             strcat(buf, o);
166          }
167       }
168       freez(o);
169    }
170
171    strcat(buf, "<br>\n");
172
173    proxy_args->invocation = strsav(proxy_args->invocation, buf);
174
175 }
176
177
178 /*********************************************************************
179  *
180  * Function    :  init_proxy_args
181  *
182  * Description :  Create the "top" of the show-proxy-args page.
183  *
184  * Parameters  :
185  *          1  :  argc = argument count (same as in main)
186  *          2  :  argv[] = program arguments (same as in main)
187  *
188  * Returns     :  N/A
189  *
190  *********************************************************************/
191 void init_proxy_args(int argc, const char *argv[])
192 {
193    const struct gateway *g;
194    int i;
195
196    freez(proxy_args->header);
197    freez(proxy_args->invocation);
198    freez(proxy_args->gateways);
199    freez(proxy_args->trailer);
200    
201
202    proxy_args->header = strsav(proxy_args->header,
203       "HTTP/1.0 200 OK\n"
204       "Server: IJ/" VERSION "\n"
205       "Content-type: text/html\n\n"
206
207       "<html>"
208       "<head>"
209       "<title>Internet Junkbuster Proxy Status</title>"
210       "</head>\n"
211       "<body bgcolor=\"#f8f8f0\" link=\"#000078\" alink=\"#ff0022\" vlink=\"#787878\">\n"
212       "<center>\n"
213       "<h1>" BANNER "\n"
214       "<a href=\"" REDIRECT_URL "faq#show\">Proxy Status</a>\n"
215       "</h1></center>\n"
216       "<h2>You are using the " BANNER " <sup><small><small>TM</small></small></sup></h2>\n"
217       "Version: " VERSION "\n"
218       "<br>Home page: <a href=\"" HOME_PAGE_URL "\">" HOME_PAGE_URL "</a>\n"
219       "<p>\n"
220    );
221
222    proxy_args->header = strsav(proxy_args->header,
223       "<h2>The program was invoked as follows</h2>\n");
224
225    for (i=0; i < argc; i++)
226    {
227       proxy_args->header = strsav(proxy_args->header, argv[i]);
228       proxy_args->header = strsav(proxy_args->header, " ");
229    }
230    proxy_args->header = strsav(proxy_args->header, "<br>\n");
231
232
233    proxy_args->invocation = strsav(
234       proxy_args->invocation,
235       "<br>\n"
236       "and the following options were set in the configuration file"
237       "<br><br>\n"
238    );
239
240
241    proxy_args->gateways = strsav(proxy_args->gateways,
242       "<h2>It supports the following gateway protocols:</h2>\n");
243
244    for (g = gateways; g->name; g++)
245    {
246       proxy_args->gateways = strsav(proxy_args->gateways, g->name);
247       proxy_args->gateways = strsav(proxy_args->gateways, " ");
248    }
249    proxy_args->gateways = strsav(proxy_args->gateways, "<br>\n");
250
251 }
252
253
254 /*********************************************************************
255  *
256  * Function    :  end_proxy_args
257  *
258  * Description :  Create the "bottom" of the show-proxy-args page.
259  *
260  * Parameters  :  None
261  *
262  * Returns     :  N/A
263  *
264  *********************************************************************/
265 void end_proxy_args(void)
266 {
267    char *b = NULL;
268    char buf[BUFSIZ];
269
270    /* Instead of including *all* dot h's in the project (thus creating a
271     * tremendous amount of dependencies), I will concede to declaring them
272     * as extern's.  This forces the developer to add to this list, but oh well.
273     */
274
275 #ifndef SPLIT_PROXY_ARGS
276    if (suppress_blocklists && suppress_message!=NULL)
277    {
278       b = strsav(b, "<h2>File contents</h2>\n");
279       b = strsav(b, suppress_message);
280       b = strsav(b, "\n");
281    }
282 #endif /* ndef SPLIT_PROXY_ARGS */
283
284    b = strsav(b, "<h2>Source versions:</h2>\n");
285    b = strsav(b, "<pre>");
286
287 #define SHOW_RCS(__x)            \
288    {                             \
289       extern const char __x[];   \
290       sprintf(buf, "%s\n", __x); \
291       b = strsav(b, buf);        \
292    }
293
294    /* In alphabetical order */
295 #ifdef __MINGW32__
296    SHOW_RCS(cygwin_h_rcs)
297 #endif
298    SHOW_RCS(encode_h_rcs)
299    SHOW_RCS(encode_rcs)
300    SHOW_RCS(errlog_h_rcs)
301    SHOW_RCS(errlog_rcs)
302    SHOW_RCS(filters_h_rcs)
303    SHOW_RCS(filters_rcs)
304    SHOW_RCS(gateway_h_rcs)
305    SHOW_RCS(gateway_rcs)
306 #ifdef GNU_REGEX
307    SHOW_RCS(gnu_regex_h_rcs)
308    SHOW_RCS(gnu_regex_rcs)
309 #endif /* def GNU_REGEX */
310    SHOW_RCS(jbsockets_h_rcs)
311    SHOW_RCS(jbsockets_rcs)
312    SHOW_RCS(jcc_h_rcs)
313    SHOW_RCS(jcc_rcs)
314 #ifdef KILLPOPUPS
315    SHOW_RCS(killpopup_h_rcs)
316    SHOW_RCS(killpopup_rcs)
317 #endif /* def KILLPOPUPS */
318    SHOW_RCS(loadcfg_h_rcs)
319    SHOW_RCS(loadcfg_rcs)
320    SHOW_RCS(loaders_h_rcs)
321    SHOW_RCS(loaders_rcs)
322    SHOW_RCS(miscutil_h_rcs)
323    SHOW_RCS(miscutil_rcs)
324    SHOW_RCS(parsers_h_rcs)
325    SHOW_RCS(parsers_rcs)
326 #ifdef PCRS
327    SHOW_RCS(pcrs_rcs)
328    SHOW_RCS(pcrs_h_rcs)
329 #endif /* def PCRS */
330    SHOW_RCS(project_h_rcs)
331    SHOW_RCS(showargs_h_rcs)
332    SHOW_RCS(showargs_rcs)
333    SHOW_RCS(ssplit_h_rcs)
334    SHOW_RCS(ssplit_rcs)
335 #ifdef _WIN32
336    SHOW_RCS(w32log_h_rcs)
337    SHOW_RCS(w32log_rcs)
338    SHOW_RCS(w32res_h_rcs)
339    SHOW_RCS(w32rulesdlg_h_rcs)
340    SHOW_RCS(w32rulesdlg_rcs)
341    SHOW_RCS(w32taskbar_h_rcs)
342    SHOW_RCS(w32taskbar_rcs)
343    SHOW_RCS(win32_h_rcs)
344    SHOW_RCS(win32_rcs)
345 #endif /* def _WIN32 */
346
347 #undef SHOW_RCS
348
349    b = strsav(b, "</pre>\n");
350
351    b = strsav(b, "<h2>Conditional defines:</h2>\n<ul>");
352
353 #ifdef REGEX
354    b = strsav(b, "  <li><code>#define <b>REGEX</b></code> - Support for regular expressions in the path specs.</li>\n");
355 #else /* ifndef REGEX */
356    b = strsav(b, "  <li><code>#undef <b>REGEX</b></code> - No support for regular expressions in the path specs.</li>\n");
357 #endif /* ndef REGEX */
358
359 #ifdef PCRE
360    b = strsav(b, "  <li><code>#define <b>PCRE</b></code> - Use PCRE rather than old GNU regex library.</li>\n");
361 #else /* ifndef PCRE */
362    b = strsav(b, "  <li><code>#undef <b>PCRE</b></code> - Use old GNU regex library rather than PCRE.</li>\n");
363 #endif /* ndef PCRE */
364
365 #ifdef PCRS
366    b = strsav(b, "  <li><code>#define <b>PCRS</b></code> - Enables arbitrary content modification regexps.</li>\n");
367 #else /* ifndef PCRS */
368    b = strsav(b, "  <li><code>#undef <b>PCRS</b></code> - Disables arbitrary content modification regexps.</li>\n");
369 #endif /* ndef PCRS */
370
371 #ifdef TOGGLE
372    b = strsav(b, "  <li><code>#define <b>TOGGLE</b></code> - Allow JunkBuster to be \"disabled\" so it is just a normal non-blocking non-anonymizing proxy.</li>\n");
373 #else /* ifndef TOGGLE */
374    b = strsav(b, "  <li><code>#undef <b>TOGGLE</b></code> - Do not allow JunkBuster to be \"disabled\" so it is just a normal non-blocking non-anonymizing proxy.</li>\n");
375 #endif /* ndef TOGGLE */
376
377 #ifdef FORCE_LOAD
378    b = strsav(b, "  <li><code>#define <b>FORCE_LOAD</b></code> - Enables bypassing filtering for a single page using the prefix \"" FORCE_PREFIX "\".</li>\n");
379 #else /* ifndef FORCE_LOAD */
380    b = strsav(b, "  <li><code>#undef <b>FORCE_LOAD</b></code> - Disables bypassing filtering for a single page.</li>\n");
381 #endif /* ndef FORCE_LOAD */
382
383 #ifdef DENY_GZIP
384    b = strsav(b, "  <li><code>#define <b>DENY_GZIP</b></code> - Prevents requests from being compressed - required for PCRS.</li>\n");
385 #else /* ifndef DENY_GZIP */
386    b = strsav(b, "  <li><code>#undef <b>DENY_GZIP</b></code> - Allows requests to be compressed if the browser and server support it.</li>\n");
387 #endif /* ndef DENY_GZIP */
388
389 #ifdef STATISTICS
390    b = strsav(b, "  <li><code>#define <b>STATISTICS</b></code> - Enables statistics function.</li>\n");
391 #else /* ifndef STATISTICS */
392    b = strsav(b, "  <li><code>#undef <b>STATISTICS</b></code> - Disables statistics function.</li>\n");
393 #endif /* ndef STATISTICS */
394
395 #ifdef SPLIT_PROXY_ARGS
396    b = strsav(b, "  <li><code>#define <b>SPLIT_PROXY_ARGS</b></code> - Split this page up by placing the configuration files on separate pages.</li>\n");
397 #else /* ifndef SPLIT_PROXY_ARGS */
398    b = strsav(b, "  <li><code>#undef <b>SPLIT_PROXY_ARGS</b></code> - This page contains the text of the configuration files, they are not split onto separate pages.</li>\n");
399 #endif /* ndef SPLIT_PROXY_ARGS */
400
401 #ifdef KILLPOPUPS
402    b = strsav(b, "  <li><code>#define <b>KILLPOPUPS</b></code> - Enables killing JavaScript popups.</li>\n");
403 #else /* ifndef KILLPOPUPS */
404    b = strsav(b, "  <li><code>#undef <b>KILLPOPUPS</b></code> - Disables killing JavaScript popups.</li>\n");
405 #endif /* ndef KILLPOPUPS */
406
407 #ifdef WEBDAV
408    b = strsav(b, "  <li><code>#define <b>WEBDAV</b></code> - Enables support for webDAV - e.g. stops Microsoft Outlook from accessing HotMail e-mail.</li>\n");
409 #else /* ifndef WEBDAV */
410    b = strsav(b, "  <li><code>#undef <b>WEBDAV</b></code> - Disables support for webDAV - e.g. so Microsoft Outlook can access HotMail e-mail.</li>\n");
411 #endif /* ndef WEBDAV */
412
413 #ifdef DETECT_MSIE_IMAGES
414    b = strsav(b, "  <li><code>#define <b>DETECT_MSIE_IMAGES</b></code> - Enables detecting image requests automatically for MSIE.</li>\n");
415 #else /* ifndef DETECT_MSIE_IMAGES */
416    b = strsav(b, "  <li><code>#undef <b>DETECT_MSIE_IMAGES</b></code> - Disables detecting image requests automatically for MSIE.</li>\n");
417 #endif /* ndef DETECT_MSIE_IMAGES */
418
419 #ifdef USE_IMAGE_LIST
420    b = strsav(b, "  <li><code>#define <b>USE_IMAGE_LIST</b></code> - Enables using image list to detect images.</li>\n");
421 #else /* ifndef USE_IMAGE_LIST */
422    b = strsav(b, "  <li><code>#undef <b>USE_IMAGE_LIST</b></code> - Disables using image list to detect images.</li>\n");
423 #endif /* ndef USE_IMAGE_LIST */
424
425 #ifdef ACL_FILES
426    b = strsav(b, "  <li><code>#define <b>ACL_FILES</b></code> - Enables the use of ACL files to control access to the proxy by IP address.</li>\n");
427 #else /* ifndef ACL_FILES */
428    b = strsav(b, "  <li><code>#undef <b>ACL_FILES</b></code> - Disables the use of ACL files to control access to the proxy by IP address.</li>\n");
429 #endif /* ndef ACL_FILES */
430
431 #ifdef TRUST_FILES
432    b = strsav(b, "  <li><code>#define <b>TRUST_FILES</b></code> - Enables the use of trust files.</li>\n");
433 #else /* ifndef TRUST_FILES */
434    b = strsav(b, "  <li><code>#undef <b>TRUST_FILES</b></code> - Disables the use of trust files.</li>\n");
435 #endif /* ndef TRUST_FILES */
436
437 #ifdef JAR_FILES
438    b = strsav(b, "  <li><code>#define <b>JAR_FILES</b></code> - Enables the use of jar files to capture cookies.</li>\n");
439 #else /* ifndef JAR_FILES */
440    b = strsav(b, "  <li><code>#undef <b>JAR_FILES</b></code> - Disables the use of jar files to capture cookies.</li>\n");
441 #endif /* ndef JAR_FILES */
442
443    b = strsav(b, "</ul>\n<br>\n");
444
445    b = strsav(b,
446       "<small><small><p>\n"
447       "Code and documentation of the " BANNER " Proxy"
448       "<sup><small>TM</small></sup>\n"
449       "<a href=\"http://www.junkbusters.com/ht/en/legal.html#copy\">\n" "Copyright</a>&#169; 1997 Junkbusters Corporation\n"
450       "<a href=\"http://www.junkbusters.com/ht/en/legal.html#marks\"><sup><small>TM</small></sup></a><br>\n"
451       "Copying and distribution permitted under the"
452       "<a href=\"http://www.gnu.org/copyleft/gpl.html\">\n"
453       "<small>GNU</small></a> "
454       "General Public License.\n"
455       "</small>"
456       "<address><kbd>webmaster@junkbusters.com</kbd></address>"
457       "</small>"
458       "</body></html>\n"
459    );
460
461    proxy_args->trailer = b;
462
463 }
464
465
466 /*
467   Local Variables:
468   tab-width: 3
469   end:
470 */