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