Google Images need img-reorder turned off.
[privoxy.git] / cgisimple.c
1 const char cgisimple_rcs[] = "$Id: cgisimple.c,v 1.35.2.7 2006/01/29 23:10:56 david__schmidt Exp $";
2 /*********************************************************************
3  *
4  * File        :  $Source: /cvsroot/ijbswa/current/Attic/cgisimple.c,v $
5  *
6  * Purpose     :  Simple CGIs to get information about Privoxy's
7  *                status.
8  *                
9  *                Functions declared include:
10  * 
11  *
12  * Copyright   :  Written by and Copyright (C) 2001 the SourceForge
13  *                Privoxy team. http://www.privoxy.org/
14  *
15  *                Based on the Internet Junkbuster originally written
16  *                by and Copyright (C) 1997 Anonymous Coders and 
17  *                Junkbusters Corporation.  http://www.junkbusters.com
18  *
19  *                This program is free software; you can redistribute it 
20  *                and/or modify it under the terms of the GNU General
21  *                Public License as published by the Free Software
22  *                Foundation; either version 2 of the License, or (at
23  *                your option) any later version.
24  *
25  *                This program is distributed in the hope that it will
26  *                be useful, but WITHOUT ANY WARRANTY; without even the
27  *                implied warranty of MERCHANTABILITY or FITNESS FOR A
28  *                PARTICULAR PURPOSE.  See the GNU General Public
29  *                License for more details.
30  *
31  *                The GNU General Public License should be included with
32  *                this file.  If not, you can view it at
33  *                http://www.gnu.org/copyleft/gpl.html
34  *                or write to the Free Software Foundation, Inc., 59
35  *                Temple Place - Suite 330, Boston, MA  02111-1307, USA.
36  *
37  * Revisions   :
38  *    $Log: cgisimple.c,v $
39  *    Revision 1.35.2.7  2006/01/29 23:10:56  david__schmidt
40  *    Multiple filter file support
41  *
42  *    Revision 1.35.2.6  2005/07/04 03:13:43  david__schmidt
43  *    Undo some damaging memory leak patches
44  *
45  *    Revision 1.35.2.5  2005/05/07 21:50:55  david__schmidt
46  *    A few memory leaks plugged (mostly on error paths)
47  *
48  *    Revision 1.35.2.4  2005/04/04 02:21:24  david__schmidt
49  *    Another instance of:
50  *    Don't show "Edit" buttons #ifndef FEATURE_CGI_EDIT_ACTIONS
51  *    Thanks to Magnus Holmgren for the patch
52  *
53  *    Revision 1.35.2.3  2003/12/17 16:34:15  oes
54  *     - Prevent line wrap beween "View/Edit" link buttons on status page
55  *     - Some (mostly irrelevant) fixes for Out-of-mem-case handling
56  *
57  *    Revision 1.35.2.2  2003/04/03 13:48:28  oes
58  *    Don't show "Edit" buttons #ifndef FEATURE_CGI_EDIT_ACTIONS
59  *
60  *    Revision 1.35.2.1  2002/07/04 15:02:38  oes
61  *    Added ability to send redirects to send-banner CGI, so that it can completely mimic the image blocking action if called with type=auto
62  *
63  *    Revision 1.35.2.1  2002/07/01 17:32:04  morcego
64  *    Applying patch from Andreas as provided by Hal on the list.
65  *    Message-ID: <20020701121218.V1606@feenix.burgiss.net>
66  *
67  *    Revision 1.35  2002/05/12 21:44:44  jongfoster
68  *    Adding amiga.[ch] revision information, if on an amiga.
69  *
70  *    Revision 1.34  2002/04/30 12:06:12  oes
71  *    Deleted unused code from default_cgi
72  *
73  *    Revision 1.33  2002/04/30 11:14:52  oes
74  *    Made csp the first parameter in *action_to_html
75  *
76  *    Revision 1.32  2002/04/26 18:29:13  jongfoster
77  *    Fixing this Visual C++ warning:
78  *    cgisimple.c(775) : warning C4018: '<' : signed/unsigned mismatch
79  *
80  *    Revision 1.31  2002/04/26 12:54:36  oes
81  *     - Kill obsolete REDIRECT_URL code
82  *     - Error handling fixes
83  *     - Style sheet related HTML snipplet changes
84  *     - cgi_show_url_info:
85  *       - Matches now in table, actions on single lines,
86  *         linked to help
87  *       - standard.action suppressed
88  *       - Buttons to View and Edit AFs
89  *
90  *    Revision 1.30  2002/04/24 02:18:08  oes
91  *     - show-status is now the starting point for editing
92  *       the actions files, generate list of all AFs with buttons
93  *       for viewing and editing, new look for file list (Jon:
94  *       buttons now aligned ;-P ), view mode now supports multiple
95  *       AFs, name changes, no view links for unspecified files,
96  *       no edit link for standard.action.
97  *
98  *     - Jon's multiple AF patch: cgi_show_url_info now uses all
99  *       AFs and marks the output accordingly
100  *
101  *    Revision 1.29  2002/04/10 13:38:35  oes
102  *    load_template signature changed
103  *
104  *    Revision 1.28  2002/04/07 15:42:12  jongfoster
105  *    Fixing send-banner?type=auto when the image-blocker is
106  *    a redirect to send-banner
107  *
108  *    Revision 1.27  2002/04/05 15:50:48  oes
109  *    added send-stylesheet CGI
110  *
111  *    Revision 1.26  2002/04/04 00:36:36  gliptak
112  *    always use pcre for matching
113  *
114  *    Revision 1.25  2002/04/03 22:28:03  gliptak
115  *    Removed references to gnu_regex
116  *
117  *    Revision 1.24  2002/04/02 16:12:47  oes
118  *    Fix: moving misplaced lines into #ifdef FEATURE_FORCE
119  *
120  *    Revision 1.23  2002/03/26 22:29:54  swa
121  *    we have a new homepage!
122  *
123  *    Revision 1.22  2002/03/24 16:18:15  jongfoster
124  *    Removing old logo
125  *
126  *    Revision 1.21  2002/03/24 15:23:33  jongfoster
127  *    Name changes
128  *
129  *    Revision 1.20  2002/03/24 13:25:43  swa
130  *    name change related issues
131  *
132  *    Revision 1.19  2002/03/16 23:54:06  jongfoster
133  *    Adding graceful termination feature, to help look for memory leaks.
134  *    If you enable this (which, by design, has to be done by hand
135  *    editing config.h) and then go to http://i.j.b/die, then the program
136  *    will exit cleanly after the *next* request.  It should free all the
137  *    memory that was used.
138  *
139  *    Revision 1.18  2002/03/12 01:44:49  oes
140  *    Changed default for "blocked" image from jb logo to checkboard pattern
141  *
142  *    Revision 1.17  2002/03/08 16:43:18  oes
143  *    Added choice beween GIF and PNG built-in images
144  *
145  *    Revision 1.16  2002/03/07 03:48:38  oes
146  *     - Changed built-in images from GIF to PNG
147  *       (with regard to Unisys patent issue)
148  *     - Added a 4x4 pattern PNG which is less intrusive
149  *       than the logo but also clearly marks the deleted banners
150  *
151  *    Revision 1.15  2002/03/06 22:54:35  jongfoster
152  *    Automated function-comment nitpicking.
153  *
154  *    Revision 1.14  2002/03/02 04:14:50  david__schmidt
155  *    Clean up a little CRLF unpleasantness that suddenly appeared
156  *
157  *    Revision 1.13  2002/02/21 00:10:37  jongfoster
158  *    Adding send-banner?type=auto option
159  *
160  *    Revision 1.12  2002/01/23 01:03:32  jongfoster
161  *    Fixing gcc [CygWin] compiler warnings
162  *
163  *    Revision 1.11  2002/01/23 00:01:04  jongfoster
164  *    Adding cgi_transparent_gif() for http://i.j.b/t
165  *    Adding missing html_encode() to many CGI functions.
166  *    Adding urlmatch.[ch] to http://i.j.b/show-version
167  *
168  *    Revision 1.10  2002/01/17 21:10:37  jongfoster
169  *    Changes to cgi_show_url_info to use new matching code from urlmatch.c.
170  *    Also fixing a problem in the same function with improperly quoted URLs
171  *    in output HTML, and adding code to handle https:// URLs correctly.
172  *
173  *    Revision 1.9  2001/11/30 23:09:15  jongfoster
174  *    Now reports on FEATURE_CGI_EDIT_ACTIONS
175  *    Removing FEATURE_DENY_GZIP from template
176  *
177  *    Revision 1.8  2001/11/13 00:14:07  jongfoster
178  *    Fixing stupid bug now I've figured out what || means.
179  *    (It always returns 0 or 1, not one of it's paramaters.)
180  *
181  *    Revision 1.7  2001/10/23 21:48:19  jongfoster
182  *    Cleaning up error handling in CGI functions - they now send back
183  *    a HTML error page and should never cause a FATAL error.  (Fixes one
184  *    potential source of "denial of service" attacks).
185  *
186  *    CGI actions file editor that works and is actually useful.
187  *
188  *    Ability to toggle JunkBuster remotely using a CGI call.
189  *
190  *    You can turn off both the above features in the main configuration
191  *    file, e.g. if you are running a multi-user proxy.
192  *
193  *    Revision 1.6  2001/10/14 22:00:32  jongfoster
194  *    Adding support for a 404 error when an invalid CGI page is requested.
195  *
196  *    Revision 1.5  2001/10/07 15:30:41  oes
197  *    Removed FEATURE_DENY_GZIP
198  *
199  *    Revision 1.4  2001/10/02 15:31:12  oes
200  *    Introduced show-request cgi
201  *
202  *    Revision 1.3  2001/09/22 16:34:44  jongfoster
203  *    Removing unneeded #includes
204  *
205  *    Revision 1.2  2001/09/19 18:01:11  oes
206  *    Fixed comments; cosmetics
207  *
208  *    Revision 1.1  2001/09/16 17:08:54  jongfoster
209  *    Moving simple CGI functions from cgi.c to new file cgisimple.c
210  *
211  *
212  **********************************************************************/
213 \f
214
215 #include "config.h"
216
217 #include <stdio.h>
218 #include <sys/types.h>
219 #include <stdlib.h>
220 #include <ctype.h>
221 #include <string.h>
222 #include <assert.h>
223
224 #ifdef _WIN32
225 #define snprintf _snprintf
226 #endif /* def _WIN32 */
227
228 #include "project.h"
229 #include "cgi.h"
230 #include "cgisimple.h"
231 #include "list.h"
232 #include "encode.h"
233 #include "jcc.h"
234 #include "filters.h"
235 #include "actions.h"
236 #include "miscutil.h"
237 #include "loadcfg.h"
238 #include "parsers.h"
239 #include "urlmatch.h"
240 #include "errlog.h"
241
242 const char cgisimple_h_rcs[] = CGISIMPLE_H_VERSION;
243
244
245 static char *show_rcs(void);
246 static jb_err show_defines(struct map *exports);
247
248
249 /*********************************************************************
250  *
251  * Function    :  cgi_default
252  *
253  * Description :  CGI function that is called for the CGI_SITE_1_HOST
254  *                and CGI_SITE_2_HOST/CGI_SITE_2_PATH base URLs.
255  *                Boring - only exports the default exports.
256  *               
257  * Parameters  :
258  *          1  :  csp = Current client state (buffers, headers, etc...)
259  *          2  :  rsp = http_response data structure for output
260  *          3  :  parameters = map of cgi parameters
261  *
262  * CGI Parameters : none
263  *
264  * Returns     :  JB_ERR_OK on success
265  *                JB_ERR_MEMORY on out-of-memory
266  *
267  *********************************************************************/
268 jb_err cgi_default(struct client_state *csp,
269                    struct http_response *rsp,
270                    const struct map *parameters)
271 {
272    struct map *exports;
273
274    assert(csp);
275    assert(rsp);
276
277    if (NULL == (exports = default_exports(csp, "")))
278    {
279       return JB_ERR_MEMORY;
280    }
281
282    return template_fill_for_cgi(csp, "default", exports, rsp);
283 }
284
285
286 /*********************************************************************
287  *
288  * Function    :  cgi_error_404
289  *
290  * Description :  CGI function that is called if an unknown action was
291  *                given.
292  *               
293  * Parameters  :
294  *          1  :  csp = Current client state (buffers, headers, etc...)
295  *          2  :  rsp = http_response data structure for output
296  *          3  :  parameters = map of cgi parameters
297  *
298  * CGI Parameters : none
299  *
300  * Returns     :  JB_ERR_OK on success
301  *                JB_ERR_MEMORY on out-of-memory error.  
302  *
303  *********************************************************************/
304 jb_err cgi_error_404(struct client_state *csp,
305                      struct http_response *rsp,
306                      const struct map *parameters)
307 {
308    struct map *exports;
309
310    assert(csp);
311    assert(rsp);
312    assert(parameters);
313
314    if (NULL == (exports = default_exports(csp, NULL)))
315    {
316       return JB_ERR_MEMORY;
317    }
318
319    rsp->status = strdup("404 Privoxy configuration page not found");
320    if (rsp->status == NULL)
321    {
322       free_map(exports);
323       return JB_ERR_MEMORY;
324    }
325
326    return template_fill_for_cgi(csp, "cgi-error-404", exports, rsp);
327 }
328
329
330 #ifdef FEATURE_GRACEFUL_TERMINATION
331 /*********************************************************************
332  *
333  * Function    :  cgi_die
334  *
335  * Description :  CGI function to shut down Privoxy.
336  *                NOTE: Turning this on in a production build
337  *                would be a BAD idea.  An EXTREMELY BAD idea.
338  *                In short, don't do it.
339  *               
340  * Parameters  :
341  *          1  :  csp = Current client state (buffers, headers, etc...)
342  *          2  :  rsp = http_response data structure for output
343  *          3  :  parameters = map of cgi parameters
344  *
345  * CGI Parameters : none
346  *
347  * Returns     :  JB_ERR_OK on success
348  *                JB_ERR_MEMORY on out-of-memory error.  
349  *
350  *********************************************************************/
351 jb_err cgi_die (struct client_state *csp,
352                 struct http_response *rsp,
353                 const struct map *parameters)
354 {
355    assert(csp);
356    assert(rsp);
357    assert(parameters);
358
359    /* quit */
360    g_terminate = 1;
361
362    /*
363     * I don't really care what gets sent back to the browser.
364     * Take the easy option - "out of memory" page.
365     */
366
367    return JB_ERR_MEMORY;
368 }
369 #endif /* def FEATURE_GRACEFUL_TERMINATION */
370
371
372 /*********************************************************************
373  *
374  * Function    :  cgi_show_request
375  *
376  * Description :  Show the client's request and what sed() would have
377  *                made of it.
378  *               
379  * Parameters  :
380  *          1  :  csp = Current client state (buffers, headers, etc...)
381  *          2  :  rsp = http_response data structure for output
382  *          3  :  parameters = map of cgi parameters
383  *
384  * CGI Parameters : none
385  *
386  * Returns     :  JB_ERR_OK on success
387  *                JB_ERR_MEMORY on out-of-memory error.  
388  *
389  *********************************************************************/
390 jb_err cgi_show_request(struct client_state *csp,
391                         struct http_response *rsp,
392                         const struct map *parameters)
393 {
394    char *p;
395    struct map *exports;
396
397    assert(csp);
398    assert(rsp);
399    assert(parameters);
400
401    if (NULL == (exports = default_exports(csp, "show-request")))
402    {
403       return JB_ERR_MEMORY;
404    }
405    
406    /*
407     * Repair the damage done to the IOB by get_header()
408     */
409    for (p = csp->iob->buf; p < csp->iob->eod; p++)
410    {
411       if (*p == '\0') *p = '\n';
412    }
413
414    /*
415     * Export the original client's request and the one we would
416     * be sending to the server if this wasn't a CGI call
417     */
418
419    if (map(exports, "client-request", 1, html_encode(csp->iob->buf), 0))
420    {
421       free_map(exports);
422       return JB_ERR_MEMORY;
423    }
424
425    if (map(exports, "processed-request", 1, html_encode_and_free_original(
426       sed(client_patterns, add_client_headers, csp)), 0))
427    {
428       free_map(exports);
429       return JB_ERR_MEMORY;
430    }
431
432    return template_fill_for_cgi(csp, "show-request", exports, rsp);
433 }
434
435
436 /*********************************************************************
437  *
438  * Function    :  cgi_send_banner
439  *
440  * Description :  CGI function that returns a banner. 
441  *
442  * Parameters  :
443  *          1  :  csp = Current client state (buffers, headers, etc...)
444  *          2  :  rsp = http_response data structure for output
445  *          3  :  parameters = map of cgi parameters
446  *
447  * CGI Parameters :
448  *           type : Selects the type of banner between "trans", "logo",
449  *                  and "auto". Defaults to "logo" if absent or invalid.
450  *                  "auto" means to select as if we were image-blocking.
451  *                  (Only the first character really counts; b and t are
452  *                  equivalent).
453  *
454  * Returns     :  JB_ERR_OK on success
455  *                JB_ERR_MEMORY on out-of-memory error.  
456  *
457  *********************************************************************/
458 jb_err cgi_send_banner(struct client_state *csp,
459                        struct http_response *rsp,
460                        const struct map *parameters)
461 {
462    char imagetype = lookup(parameters, "type")[0];
463
464    /*
465     * If type is auto, then determine the right thing
466     * to do from the set-image-blocker action
467     */
468    if (imagetype == 'a') 
469    {
470       /*
471        * Default to pattern
472        */
473       imagetype = 'p';
474
475 #ifdef FEATURE_IMAGE_BLOCKING
476       if ((csp->action->flags & ACTION_IMAGE_BLOCKER) != 0)
477       {
478          static const char prefix1[] = CGI_PREFIX "send-banner?type=";
479          static const char prefix2[] = "http://" CGI_SITE_1_HOST "/send-banner?type=";
480          const char *p = csp->action->string[ACTION_STRING_IMAGE_BLOCKER];
481
482          if (p == NULL)
483          {
484             /* Use default - nothing to do here. */
485          }
486          else if (0 == strcmpic(p, "blank"))
487          {
488             imagetype = 'b';
489          }
490          else if (0 == strcmpic(p, "pattern"))
491          {
492             imagetype = 'p';
493          }
494
495          /*
496           * If the action is to call this CGI, determine
497           * the argument:
498           */
499          else if (0 == strncmpic(p, prefix1, sizeof(prefix1) - 1))
500          {
501             imagetype = p[sizeof(prefix1) - 1];
502          }
503          else if (0 == strncmpic(p, prefix2, sizeof(prefix2) - 1))
504          {
505             imagetype = p[sizeof(prefix2) - 1];
506          }
507
508          /*
509           * Everything else must (should) be a URL to
510           * redirect to.
511           */
512          else
513          {
514             imagetype = 'r';
515          }
516       }
517 #endif /* def FEATURE_IMAGE_BLOCKING */
518    }
519       
520    /*
521     * Now imagetype is either the non-auto type we were called with,
522     * or it was auto and has since been determined. In any case, we
523     * can proceed to actually answering the request by sending a redirect
524     * or an image as appropriate:
525     */
526    if (imagetype == 'r') 
527    {
528       rsp->status = strdup("302 Local Redirect from Privoxy");
529       if (rsp->status == NULL)
530       {
531          return JB_ERR_MEMORY;
532       }
533       if (enlist_unique_header(rsp->headers, "Location",
534                                csp->action->string[ACTION_STRING_IMAGE_BLOCKER]))
535       {
536          return JB_ERR_MEMORY;
537       }
538    }
539    else
540    {
541       if ((imagetype == 'b') || (imagetype == 't')) 
542       {
543          rsp->body = bindup(image_blank_data, image_blank_length);
544          rsp->content_length = image_blank_length;
545       }
546       else
547       {
548          rsp->body = bindup(image_pattern_data, image_pattern_length);
549          rsp->content_length = image_pattern_length;
550       }
551
552       if (rsp->body == NULL)
553       {
554          return JB_ERR_MEMORY;
555       }
556       if (enlist(rsp->headers, "Content-Type: " BUILTIN_IMAGE_MIMETYPE))
557       {
558          return JB_ERR_MEMORY;
559       }
560
561       rsp->is_static = 1;
562    }
563
564    return JB_ERR_OK;
565
566 }
567
568
569 /*********************************************************************
570  *
571  * Function    :  cgi_transparent_image
572  *
573  * Description :  CGI function that sends a 1x1 transparent image.
574  *
575  * Parameters  :
576  *          1  :  csp = Current client state (buffers, headers, etc...)
577  *          2  :  rsp = http_response data structure for output
578  *          3  :  parameters = map of cgi parameters
579  *
580  * CGI Parameters : None
581  *
582  * Returns     :  JB_ERR_OK on success
583  *                JB_ERR_MEMORY on out-of-memory error.  
584  *
585  *********************************************************************/
586 jb_err cgi_transparent_image(struct client_state *csp,
587                              struct http_response *rsp,
588                              const struct map *parameters)
589 {
590    rsp->body = bindup(image_blank_data, image_blank_length);
591    rsp->content_length = image_blank_length;
592
593    if (rsp->body == NULL)
594    {
595       return JB_ERR_MEMORY;
596    }
597
598    if (enlist(rsp->headers, "Content-Type: " BUILTIN_IMAGE_MIMETYPE))
599    {
600       return JB_ERR_MEMORY;
601    }
602
603    rsp->is_static = 1;
604
605    return JB_ERR_OK;
606
607 }
608
609
610 /*********************************************************************
611  *
612  * Function    :  cgi_send_stylesheet
613  *
614  * Description :  CGI function that sends a css stylesheet found
615  *                in the cgi-style.css template
616  *
617  * Parameters  :
618  *          1  :  csp = Current client state (buffers, headers, etc...)
619  *          2  :  rsp = http_response data structure for output
620  *          3  :  parameters = map of cgi parameters
621  *
622  * CGI Parameters : None
623  *
624  * Returns     :  JB_ERR_OK on success
625  *                JB_ERR_MEMORY on out-of-memory error.  
626  *
627  *********************************************************************/
628 jb_err cgi_send_stylesheet(struct client_state *csp,
629                            struct http_response *rsp,
630                            const struct map *parameters)
631 {
632    jb_err err;
633    
634    assert(csp);
635    assert(rsp);
636
637    err = template_load(csp, &rsp->body, "cgi-style.css", 0);
638
639    if (err == JB_ERR_FILE)
640    {
641       /*
642        * No way to tell user; send empty stylesheet
643        */
644       log_error(LOG_LEVEL_ERROR, "Could not find cgi-style.css template");
645    }
646    else if (err)
647    {
648       return err; /* JB_ERR_MEMORY */
649    }
650
651    if (enlist(rsp->headers, "Content-Type: text/css"))
652    {
653       return JB_ERR_MEMORY;
654    }
655
656    return JB_ERR_OK;
657
658 }
659
660
661 /*********************************************************************
662  *
663  * Function    :  cgi_show_version
664  *
665  * Description :  CGI function that returns a a web page describing the
666  *                file versions of Privoxy.
667  *
668  * Parameters  :
669  *          1  :  csp = Current client state (buffers, headers, etc...)
670  *          2  :  rsp = http_response data structure for output
671  *          3  :  parameters = map of cgi parameters
672  *
673  * CGI Parameters : none
674  *
675  * Returns     :  JB_ERR_OK on success
676  *                JB_ERR_MEMORY on out-of-memory error.  
677  *
678  *********************************************************************/
679 jb_err cgi_show_version(struct client_state *csp,
680                         struct http_response *rsp,
681                         const struct map *parameters)
682 {
683    struct map *exports;
684
685    assert(csp);
686    assert(rsp);
687    assert(parameters);
688
689    if (NULL == (exports = default_exports(csp, "show-version")))
690    {
691       return JB_ERR_MEMORY;
692    }
693
694    if (map(exports, "sourceversions", 1, show_rcs(), 0))
695    {
696       free_map(exports);
697       return JB_ERR_MEMORY;
698    }
699
700    return template_fill_for_cgi(csp, "show-version", exports, rsp);
701 }
702
703  
704 /*********************************************************************
705  *
706  * Function    :  cgi_show_status
707  *
708  * Description :  CGI function that returns a a web page describing the
709  *                current status of Privoxy.
710  *
711  * Parameters  :
712  *          1  :  csp = Current client state (buffers, headers, etc...)
713  *          2  :  rsp = http_response data structure for output
714  *          3  :  parameters = map of cgi parameters
715  *
716  * CGI Parameters :
717  *        file :  Which file to show.  Only first letter is checked,
718  *                valid values are:
719  *                - "p"ermissions (actions) file
720  *                - "r"egex
721  *                - "t"rust
722  *                Default is to show menu and other information.
723  *
724  * Returns     :  JB_ERR_OK on success
725  *                JB_ERR_MEMORY on out-of-memory error.  
726  *
727  *********************************************************************/
728 jb_err cgi_show_status(struct client_state *csp,
729                        struct http_response *rsp,
730                        const struct map *parameters)
731 {
732    char *s = NULL;
733    unsigned i;
734    int j;
735
736    FILE * fp;
737    char buf[BUFFER_SIZE];
738    const char * filename = NULL;
739    char * file_description = NULL;
740 #ifdef FEATURE_STATISTICS
741    float perc_rej;   /* Percentage of http requests rejected */
742    int local_urls_read;
743    int local_urls_rejected;
744 #endif /* ndef FEATURE_STATISTICS */
745    struct file_list * fl;
746    struct url_actions * b;
747    jb_err err = JB_ERR_OK;
748
749    struct map *exports;
750
751    assert(csp);
752    assert(rsp);
753    assert(parameters);
754
755    if (NULL == (exports = default_exports(csp, "show-status")))
756    {
757       return JB_ERR_MEMORY;
758    }
759
760    switch (*(lookup(parameters, "file")))
761    {
762    case 'a':
763       if (!get_number_param(csp, parameters, "index", &i) && i < MAX_AF_FILES && csp->actions_list[i])
764       {
765          filename = csp->actions_list[i]->filename;
766          file_description = "Actions File";
767       }
768       break;
769
770    case 'f':
771       if (!get_number_param(csp, parameters, "index", &i) && i < MAX_AF_FILES && csp->rlist[i])
772       {
773          filename = csp->rlist[i]->filename;
774          file_description = "Filter File";
775       }
776       break;
777
778 #ifdef FEATURE_TRUST
779    case 't':
780       if (csp->tlist)
781       {
782          filename = csp->tlist->filename;
783          file_description = "Trust File";
784       }
785       break;
786 #endif /* def FEATURE_TRUST */
787    }
788
789    if (NULL != filename)
790    {
791       if ( map(exports, "file-description", 1, file_description, 1)
792         || map(exports, "filepath", 1, html_encode(filename), 0) )
793       {
794          free_map(exports);
795          return JB_ERR_MEMORY;
796       }
797
798       if ((fp = fopen(filename, "r")) == NULL)
799       {
800          if (map(exports, "content", 1, "<h1>ERROR OPENING FILE!</h1>", 1))
801          {
802             free_map(exports);
803             return JB_ERR_MEMORY;
804          }
805       }
806       else
807       {
808          s = strdup("");
809          while ((s != NULL) && fgets(buf, sizeof(buf), fp))
810          {
811             string_join  (&s, html_encode(buf));
812          }
813          fclose(fp);
814
815          if (map(exports, "contents", 1, s, 0))
816          {
817             free_map(exports);
818             return JB_ERR_MEMORY;
819          }
820       }
821
822       return template_fill_for_cgi(csp, "show-status-file", exports, rsp);
823    }
824
825    s = strdup("");
826    for (j = 0; (s != NULL) && (j < Argc); j++)
827    {
828       if (!err) err = string_join  (&s, html_encode(Argv[j]));
829       if (!err) err = string_append(&s, " ");
830    }
831    if (!err) err = map(exports, "invocation", 1, s, 0);
832
833    if (!err) err = map(exports, "options", 1, csp->config->proxy_args, 1);
834    if (!err) err = show_defines(exports);
835
836    if (err) 
837    {
838       free_map(exports);
839       return JB_ERR_MEMORY;
840    }
841
842 #ifdef FEATURE_STATISTICS
843    local_urls_read     = urls_read;
844    local_urls_rejected = urls_rejected;
845
846    /*
847     * Need to alter the stats not to include the fetch of this
848     * page.
849     *
850     * Can't do following thread safely! doh!
851     *
852     * urls_read--;
853     * urls_rejected--; * This will be incremented subsequently *
854     */
855
856    if (local_urls_read == 0)
857    {
858       if (!err) err = map_block_killer(exports, "have-stats");
859    }
860    else
861    {
862       if (!err) err = map_block_killer(exports, "have-no-stats");
863
864       perc_rej = (float)local_urls_rejected * 100.0F /
865             (float)local_urls_read;
866
867       sprintf(buf, "%d", local_urls_read);
868       if (!err) err = map(exports, "requests-received", 1, buf, 1);
869
870       sprintf(buf, "%d", local_urls_rejected);
871       if (!err) err = map(exports, "requests-blocked", 1, buf, 1);
872
873       sprintf(buf, "%6.2f", perc_rej);
874       if (!err) err = map(exports, "percent-blocked", 1, buf, 1);
875    }
876
877 #else /* ndef FEATURE_STATISTICS */
878    err = err || map_block_killer(exports, "statistics");
879 #endif /* ndef FEATURE_STATISTICS */
880    
881    /* 
882     * List all action files in use, together with view and edit links,
883     * except for standard.action, which should only be viewable. (Not
884     * enforced in the editor itself)
885     * FIXME: Shouldn't include hardwired HTML here, use line template instead!
886     */
887    s = strdup("");
888    for (i = 0; i < MAX_AF_FILES; i++)
889    {
890       if (((fl = csp->actions_list[i]) != NULL) && ((b = fl->f) != NULL))
891       {
892          if (!err) err = string_append(&s, "<tr><td>");
893          if (!err) err = string_join(&s, html_encode(csp->actions_list[i]->filename));
894          snprintf(buf, 100, "</td><td class=\"buttons\"><a href=\"/show-status?file=actions&index=%d\">View</a>", i);
895          if (!err) err = string_append(&s, buf);
896
897 #ifdef FEATURE_CGI_EDIT_ACTIONS
898          if (NULL == strstr(csp->actions_list[i]->filename, "standard.action") && NULL != csp->config->actions_file_short[i])
899          {
900             snprintf(buf, 100, "&nbsp;&nbsp;<a href=\"/edit-actions-list?f=%s\">Edit</a>", csp->config->actions_file_short[i]);
901             if (!err) err = string_append(&s, buf);
902          }
903 #endif
904
905          if (!err) err = string_append(&s, "</td></tr>\n");
906       }
907    }
908    if (*s != '\0')   
909    {
910       if (!err) err = map(exports, "actions-filenames", 1, s, 0);
911    }
912    else
913    {
914       if (!err) err = map(exports, "actions-filenames", 1, "<tr><td>None specified</td></tr>", 1);
915    }
916
917    /* 
918     * List all re_filterfiles in use, together with view options.
919     * FIXME: Shouldn't include hardwired HTML here, use line template instead!
920     */
921    s = strdup("");
922    for (i = 0; i < MAX_AF_FILES; i++)
923    {
924       if (((fl = csp->rlist[i]) != NULL) && ((b = fl->f) != NULL))
925       {
926          if (!err) err = string_append(&s, "<tr><td>");
927          if (!err) err = string_join(&s, html_encode(csp->rlist[i]->filename));
928          snprintf(buf, 100, "</td><td class=\"buttons\"><a href=\"/show-status?file=filter&index=%d\">View</a>", i);
929          if (!err) err = string_append(&s, buf);
930          if (!err) err = string_append(&s, "</td></tr>\n");
931       }
932    }
933    if (*s != '\0')   
934    {
935       if (!err) err = map(exports, "re-filter-filename", 1, s, 0);
936    }
937    else
938    {
939       if (!err) err = map(exports, "re-filter-filename", 1, "<tr><td>None specified</td></tr>", 1);
940       if (!err) err = map_block_killer(exports, "have-filterfile");
941    }
942
943 #ifdef FEATURE_TRUST
944    if (csp->tlist)
945    {
946       if (!err) err = map(exports, "trust-filename", 1, html_encode(csp->tlist->filename), 0);
947    }
948    else
949    {
950       if (!err) err = map(exports, "trust-filename", 1, "None specified", 1);
951       if (!err) err = map_block_killer(exports, "have-trustfile");
952    }
953 #else
954    if (!err) err = map_block_killer(exports, "trust-support");
955 #endif /* ndef FEATURE_TRUST */
956
957    if (err)
958    {
959       free_map(exports);
960       return JB_ERR_MEMORY;
961    }
962
963    return template_fill_for_cgi(csp, "show-status", exports, rsp);
964 }
965
966  
967 /*********************************************************************
968  *
969  * Function    :  cgi_show_url_info
970  *
971  * Description :  CGI function that determines and shows which actions
972  *                Privoxy will perform for a given url, and which
973  *                matches starting from the defaults have lead to that.
974  *
975  * Parameters  :
976  *          1  :  csp = Current client state (buffers, headers, etc...)
977  *          2  :  rsp = http_response data structure for output
978  *          3  :  parameters = map of cgi parameters
979  *
980  * CGI Parameters :
981  *            url : The url whose actions are to be determined.
982  *                  If url is unset, the url-given conditional will be
983  *                  set, so that all but the form can be suppressed in
984  *                  the template.
985  *
986  * Returns     :  JB_ERR_OK on success
987  *                JB_ERR_MEMORY on out-of-memory error.  
988  *
989  *********************************************************************/
990 jb_err cgi_show_url_info(struct client_state *csp,
991                          struct http_response *rsp,
992                          const struct map *parameters)
993 {
994    char *url_param;
995    struct map *exports;
996    char buf[150];
997
998    assert(csp);
999    assert(rsp);
1000    assert(parameters);
1001
1002    if (NULL == (exports = default_exports(csp, "show-url-info")))
1003    {
1004       return JB_ERR_MEMORY;
1005    }
1006
1007    /*
1008     * Get the url= parameter (if present) and remove any leading/trailing spaces.
1009     */
1010    url_param = strdup(lookup(parameters, "url"));
1011    if (url_param == NULL)
1012    {
1013       free_map(exports);
1014       return JB_ERR_MEMORY;
1015    }
1016    chomp(url_param);
1017
1018    /*
1019     * Handle prefixes.  4 possibilities:
1020     * 1) "http://" or "https://" prefix present and followed by URL - OK
1021     * 2) Only the "http://" or "https://" part is present, no URL - change
1022     *    to empty string so it will be detected later as "no URL".
1023     * 3) Parameter specified but doesn't contain "http(s?)://" - add a
1024     *    "http://" prefix.
1025     * 4) Parameter not specified or is empty string - let this fall through
1026     *    for now, next block of code will handle it.
1027     */
1028    if (0 == strncmp(url_param, "http://", 7))
1029    {
1030       if (url_param[7] == '\0')
1031       {
1032          /*
1033           * Empty URL (just prefix).
1034           * Make it totally empty so it's caught by the next if()
1035           */
1036          url_param[0] = '\0';
1037       }
1038    }
1039    else if (0 == strncmp(url_param, "https://", 8))
1040    {
1041       if (url_param[8] == '\0')
1042       {
1043          /*
1044           * Empty URL (just prefix).
1045           * Make it totally empty so it's caught by the next if()
1046           */
1047          url_param[0] = '\0';
1048       }
1049    }
1050    else if (url_param[0] != '\0')
1051    {
1052       /*
1053        * Unknown prefix - assume http://
1054        */
1055       char * url_param_prefixed = malloc(7 + 1 + strlen(url_param));
1056       if (NULL == url_param_prefixed)
1057       {
1058          free(url_param);
1059          free_map(exports);
1060          return JB_ERR_MEMORY;
1061       }
1062       strcpy(url_param_prefixed, "http://");
1063       strcpy(url_param_prefixed + 7, url_param);
1064       free(url_param);
1065       url_param = url_param_prefixed;
1066    }
1067
1068
1069    if (url_param[0] == '\0')
1070    {
1071       /* URL paramater not specified, display query form only. */
1072       free(url_param);
1073       if (map_block_killer(exports, "url-given")
1074         || map(exports, "url", 1, "", 1))
1075       {
1076          free_map(exports);
1077          return JB_ERR_MEMORY;
1078       }
1079    }
1080    else
1081    {
1082       /* Given a URL, so query it. */
1083       jb_err err;
1084       char *matches;
1085       char *s;
1086       int hits = 0;
1087       struct file_list *fl;
1088       struct url_actions *b;
1089       struct http_request url_to_query[1];
1090       struct current_action_spec action[1];
1091       int i;
1092       
1093       if (map(exports, "url", 1, html_encode(url_param), 0))
1094       {
1095          free(url_param);
1096          free_map(exports);
1097          return JB_ERR_MEMORY;
1098       }
1099
1100       init_current_action(action);
1101
1102       if (map(exports, "default", 1, current_action_to_html(csp, action), 0))
1103       {
1104          free_current_action(action);
1105          free(url_param);
1106          free_map(exports);
1107          return JB_ERR_MEMORY;
1108       }
1109
1110       err = parse_http_url(url_param, url_to_query, csp);
1111
1112       free(url_param);
1113
1114       if (err == JB_ERR_MEMORY)
1115       {
1116          free_http_request(url_to_query);
1117          free_current_action(action);
1118          free_map(exports);
1119          return JB_ERR_MEMORY;
1120       }
1121       else if (err)
1122       {
1123          /* Invalid URL */
1124
1125          err = map(exports, "matches", 1, "<b>[Invalid URL specified!]</b>" , 1);
1126          if (!err) err = map(exports, "final", 1, lookup(exports, "default"), 1);
1127
1128          free_current_action(action);
1129          free_http_request(url_to_query);
1130
1131          if (err)
1132          {
1133             free_map(exports);
1134             return JB_ERR_MEMORY;
1135          }
1136
1137          return template_fill_for_cgi(csp, "show-url-info", exports, rsp);
1138       }
1139
1140       /*
1141        * We have a warning about SSL paths.  Hide it for insecure sites.
1142        */
1143       if (!url_to_query->ssl)
1144       {
1145          if (map_block_killer(exports, "https"))
1146          {
1147             free_current_action(action);
1148             free_map(exports);
1149             free_http_request(url_to_query);
1150             return JB_ERR_MEMORY;
1151          }
1152       }
1153
1154       matches = strdup("<table class=\"transparent\">");
1155
1156       for (i = 0; i < MAX_AF_FILES; i++)
1157       {
1158          if (NULL == csp->config->actions_file_short[i]
1159              || !strcmp(csp->config->actions_file_short[i], "standard")) continue;
1160
1161          b = NULL;
1162          hits = 1;
1163          if ((fl = csp->actions_list[i]) != NULL)
1164          {
1165             if ((b = fl->f) != NULL)
1166             {
1167                /* FIXME: Hardcoded HTML! */
1168                string_append(&matches, "<tr><th>In file: ");
1169                string_join  (&matches, html_encode(csp->config->actions_file_short[i]));
1170                snprintf(buf, 150, ".action <a class=\"cmd\" href=\"/show-status?file=actions&index=%d\">", i);
1171                string_append(&matches, buf);
1172                string_append(&matches, "View</a>");
1173 #ifdef FEATURE_CGI_EDIT_ACTIONS
1174                string_append(&matches, " <a class=\"cmd\" href=\"/edit-actions-list?f=");
1175                string_join  (&matches, html_encode(csp->config->actions_file_short[i]));
1176                string_append(&matches, "\">Edit</a>");
1177 #endif
1178                string_append(&matches, "</th></tr>\n");
1179
1180                hits = 0;
1181                b = b->next;
1182             }
1183          }
1184
1185          for (; (b != NULL) && (matches != NULL); b = b->next)
1186          {
1187             if (url_match(b->url, url_to_query))
1188             {
1189                string_append(&matches, "<tr><td>{");
1190                string_join  (&matches, actions_to_html(csp, b->action));
1191                string_append(&matches, " }</b><br>\n<code>");
1192                string_join  (&matches, html_encode(b->url->spec));
1193                string_append(&matches, "</code></td></tr>\n");
1194
1195                if (merge_current_action(action, b->action))
1196                {
1197                   freez(matches);
1198                   free_http_request(url_to_query);
1199                   free_current_action(action);
1200                   free_map(exports);
1201                   return JB_ERR_MEMORY;
1202                }
1203                hits++;
1204             }
1205          }
1206
1207          if (!hits)
1208          {
1209             string_append(&matches, "<tr><td>(no matches in this file)</td></tr>\n");
1210          }
1211       }
1212       string_append(&matches, "</table>\n");
1213
1214       free_http_request(url_to_query);
1215
1216       if (matches == NULL)
1217       {
1218          free_current_action(action);
1219          free_map(exports);
1220          return JB_ERR_MEMORY;
1221       }
1222
1223       if (map(exports, "matches", 1, matches , 0))
1224       {
1225          free_current_action(action);
1226          free_map(exports);
1227          return JB_ERR_MEMORY;
1228       }
1229
1230       s = current_action_to_html(csp, action);
1231
1232       free_current_action(action);
1233
1234       if (map(exports, "final", 1, s, 0))
1235       {
1236          free_map(exports);
1237          return JB_ERR_MEMORY;
1238       }
1239    }
1240
1241    return template_fill_for_cgi(csp, "show-url-info", exports, rsp);
1242 }
1243
1244
1245 /*********************************************************************
1246  *
1247  * Function    :  cgi_robots_txt
1248  *
1249  * Description :  CGI function to return "/robots.txt".
1250  *
1251  * Parameters  :
1252  *          1  :  csp = Current client state (buffers, headers, etc...)
1253  *          2  :  rsp = http_response data structure for output
1254  *          3  :  parameters = map of cgi parameters
1255  *
1256  * CGI Parameters : None
1257  *
1258  * Returns     :  JB_ERR_OK on success
1259  *                JB_ERR_MEMORY on out-of-memory error.  
1260  *
1261  *********************************************************************/
1262 jb_err cgi_robots_txt(struct client_state *csp,
1263                       struct http_response *rsp,
1264                       const struct map *parameters)
1265 {
1266    char buf[100];
1267    jb_err err;
1268
1269    rsp->body = strdup(
1270       "# This is the Privoxy control interface.\n"
1271       "# It isn't very useful to index it, and you're likely to break stuff.\n"
1272       "# So go away!\n"
1273       "\n"
1274       "User-agent: *\n"
1275       "Disallow: /\n"
1276       "\n");
1277    if (rsp->body == NULL)
1278    {
1279       return JB_ERR_MEMORY;
1280    }
1281
1282    err = enlist_unique(rsp->headers, "Content-Type: text/plain", 13);
1283
1284    rsp->is_static = 1;
1285
1286    get_http_time(7 * 24 * 60 * 60, buf); /* 7 days into future */
1287    if (!err) err = enlist_unique_header(rsp->headers, "Expires", buf);
1288
1289    return (err ? JB_ERR_MEMORY : JB_ERR_OK);
1290 }
1291
1292
1293 /*********************************************************************
1294  *
1295  * Function    :  show_defines
1296  *
1297  * Description :  Add to a map the state od all conditional #defines
1298  *                used when building
1299  *
1300  * Parameters  :
1301  *          1  :  exports = map to extend
1302  *
1303  * Returns     :  JB_ERR_OK on success
1304  *                JB_ERR_MEMORY on out-of-memory error.  
1305  *
1306  *********************************************************************/
1307 static jb_err show_defines(struct map *exports)
1308 {
1309    jb_err err = JB_ERR_OK;
1310
1311 #ifdef FEATURE_ACL
1312    if (!err) err = map_conditional(exports, "FEATURE_ACL", 1);
1313 #else /* ifndef FEATURE_ACL */
1314    if (!err) err = map_conditional(exports, "FEATURE_ACL", 0);
1315 #endif /* ndef FEATURE_ACL */
1316
1317 #ifdef FEATURE_CGI_EDIT_ACTIONS
1318    if (!err) err = map_conditional(exports, "FEATURE_CGI_EDIT_ACTIONS", 1);
1319 #else /* ifndef FEATURE_COOKIE_JAR */
1320    if (!err) err = map_conditional(exports, "FEATURE_CGI_EDIT_ACTIONS", 0);
1321 #endif /* ndef FEATURE_COOKIE_JAR */
1322
1323 #ifdef FEATURE_COOKIE_JAR
1324    if (!err) err = map_conditional(exports, "FEATURE_COOKIE_JAR", 1);
1325 #else /* ifndef FEATURE_COOKIE_JAR */
1326    if (!err) err = map_conditional(exports, "FEATURE_COOKIE_JAR", 0);
1327 #endif /* ndef FEATURE_COOKIE_JAR */
1328
1329 #ifdef FEATURE_FAST_REDIRECTS
1330    if (!err) err = map_conditional(exports, "FEATURE_FAST_REDIRECTS", 1);
1331 #else /* ifndef FEATURE_FAST_REDIRECTS */
1332    if (!err) err = map_conditional(exports, "FEATURE_FAST_REDIRECTS", 0);
1333 #endif /* ndef FEATURE_FAST_REDIRECTS */
1334
1335 #ifdef FEATURE_FORCE_LOAD
1336    if (!err) err = map_conditional(exports, "FEATURE_FORCE_LOAD", 1);
1337    if (!err) err = map(exports, "FORCE_PREFIX", 1, FORCE_PREFIX, 1);
1338 #else /* ifndef FEATURE_FORCE_LOAD */
1339    if (!err) err = map_conditional(exports, "FEATURE_FORCE_LOAD", 0);
1340    if (!err) err = map(exports, "FORCE_PREFIX", 1, "(none - disabled)", 1);
1341 #endif /* ndef FEATURE_FORCE_LOAD */
1342
1343 #ifdef FEATURE_IMAGE_BLOCKING
1344    if (!err) err = map_conditional(exports, "FEATURE_IMAGE_BLOCKING", 1);
1345 #else /* ifndef FEATURE_IMAGE_BLOCKING */
1346    if (!err) err = map_conditional(exports, "FEATURE_IMAGE_BLOCKING", 0);
1347 #endif /* ndef FEATURE_IMAGE_BLOCKING */
1348
1349 #ifdef FEATURE_IMAGE_DETECT_MSIE
1350    if (!err) err = map_conditional(exports, "FEATURE_IMAGE_DETECT_MSIE", 1);
1351 #else /* ifndef FEATURE_IMAGE_DETECT_MSIE */
1352    if (!err) err = map_conditional(exports, "FEATURE_IMAGE_DETECT_MSIE", 0);
1353 #endif /* ndef FEATURE_IMAGE_DETECT_MSIE */
1354
1355 #ifdef FEATURE_KILL_POPUPS
1356    if (!err) err = map_conditional(exports, "FEATURE_KILL_POPUPS", 1);
1357 #else /* ifndef FEATURE_KILL_POPUPS */
1358    if (!err) err = map_conditional(exports, "FEATURE_KILL_POPUPS", 0);
1359 #endif /* ndef FEATURE_KILL_POPUPS */
1360
1361 #ifdef FEATURE_NO_GIFS
1362    if (!err) err = map_conditional(exports, "FEATURE_NO_GIFS", 1);
1363 #else /* ifndef FEATURE_NO_GIFS */
1364    if (!err) err = map_conditional(exports, "FEATURE_NO_GIFS", 0);
1365 #endif /* ndef FEATURE_NO_GIFS */
1366
1367 #ifdef FEATURE_PTHREAD
1368    if (!err) err = map_conditional(exports, "FEATURE_PTHREAD", 1);
1369 #else /* ifndef FEATURE_PTHREAD */
1370    if (!err) err = map_conditional(exports, "FEATURE_PTHREAD", 0);
1371 #endif /* ndef FEATURE_PTHREAD */
1372
1373 #ifdef FEATURE_STATISTICS
1374    if (!err) err = map_conditional(exports, "FEATURE_STATISTICS", 1);
1375 #else /* ifndef FEATURE_STATISTICS */
1376    if (!err) err = map_conditional(exports, "FEATURE_STATISTICS", 0);
1377 #endif /* ndef FEATURE_STATISTICS */
1378
1379 #ifdef FEATURE_TOGGLE
1380    if (!err) err = map_conditional(exports, "FEATURE_TOGGLE", 1);
1381 #else /* ifndef FEATURE_TOGGLE */
1382    if (!err) err = map_conditional(exports, "FEATURE_TOGGLE", 0);
1383 #endif /* ndef FEATURE_TOGGLE */
1384
1385 #ifdef FEATURE_TRUST
1386    if (!err) err = map_conditional(exports, "FEATURE_TRUST", 1);
1387 #else /* ifndef FEATURE_TRUST */
1388    if (!err) err = map_conditional(exports, "FEATURE_TRUST", 0);
1389 #endif /* ndef FEATURE_TRUST */
1390
1391 #ifdef STATIC_PCRE
1392    if (!err) err = map_conditional(exports, "STATIC_PCRE", 1);
1393 #else /* ifndef STATIC_PCRE */
1394    if (!err) err = map_conditional(exports, "STATIC_PCRE", 0);
1395 #endif /* ndef STATIC_PCRE */
1396
1397 #ifdef STATIC_PCRS
1398    if (!err) err = map_conditional(exports, "STATIC_PCRS", 1);
1399 #else /* ifndef STATIC_PCRS */
1400    if (!err) err = map_conditional(exports, "STATIC_PCRS", 0);
1401 #endif /* ndef STATIC_PCRS */
1402
1403    return err;
1404 }
1405
1406
1407 /*********************************************************************
1408  *
1409  * Function    :  show_rcs
1410  *
1411  * Description :  Create a string with the rcs info for all sourcefiles
1412  *
1413  * Parameters  :  None
1414  *
1415  * Returns     :  A string, or NULL on out-of-memory.
1416  *
1417  *********************************************************************/
1418 static char *show_rcs(void)
1419 {
1420    char *result = strdup("");
1421    char buf[BUFFER_SIZE];
1422
1423    /* Instead of including *all* dot h's in the project (thus creating a
1424     * tremendous amount of dependencies), I will concede to declaring them
1425     * as extern's.  This forces the developer to add to this list, but oh well.
1426     */
1427
1428 #define SHOW_RCS(__x)              \
1429    {                               \
1430       extern const char __x[];     \
1431       sprintf(buf, "%s\n", __x);   \
1432       string_append(&result, buf); \
1433    }
1434
1435    /* In alphabetical order */
1436    SHOW_RCS(actions_h_rcs)
1437    SHOW_RCS(actions_rcs)
1438 #ifdef AMIGA
1439    SHOW_RCS(amiga_h_rcs)
1440    SHOW_RCS(amiga_rcs)
1441 #endif /* def AMIGA */
1442    SHOW_RCS(cgi_h_rcs)
1443    SHOW_RCS(cgi_rcs)
1444 #ifdef FEATURE_CGI_EDIT_ACTIONS
1445    SHOW_RCS(cgiedit_h_rcs)
1446    SHOW_RCS(cgiedit_rcs)
1447 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1448    SHOW_RCS(cgisimple_h_rcs)
1449    SHOW_RCS(cgisimple_rcs)
1450 #ifdef __MINGW32__
1451    SHOW_RCS(cygwin_h_rcs)
1452 #endif
1453    SHOW_RCS(deanimate_h_rcs)
1454    SHOW_RCS(deanimate_rcs)
1455    SHOW_RCS(encode_h_rcs)
1456    SHOW_RCS(encode_rcs)
1457    SHOW_RCS(errlog_h_rcs)
1458    SHOW_RCS(errlog_rcs)
1459    SHOW_RCS(filters_h_rcs)
1460    SHOW_RCS(filters_rcs)
1461    SHOW_RCS(gateway_h_rcs)
1462    SHOW_RCS(gateway_rcs)
1463    SHOW_RCS(jbsockets_h_rcs)
1464    SHOW_RCS(jbsockets_rcs)
1465    SHOW_RCS(jcc_h_rcs)
1466    SHOW_RCS(jcc_rcs)
1467 #ifdef FEATURE_KILL_POPUPS
1468    SHOW_RCS(killpopup_h_rcs)
1469    SHOW_RCS(killpopup_rcs)
1470 #endif /* def FEATURE_KILL_POPUPS */
1471    SHOW_RCS(list_h_rcs)
1472    SHOW_RCS(list_rcs)
1473    SHOW_RCS(loadcfg_h_rcs)
1474    SHOW_RCS(loadcfg_rcs)
1475    SHOW_RCS(loaders_h_rcs)
1476    SHOW_RCS(loaders_rcs)
1477    SHOW_RCS(miscutil_h_rcs)
1478    SHOW_RCS(miscutil_rcs)
1479    SHOW_RCS(parsers_h_rcs)
1480    SHOW_RCS(parsers_rcs)
1481    SHOW_RCS(pcrs_rcs)
1482    SHOW_RCS(pcrs_h_rcs)
1483    SHOW_RCS(project_h_rcs)
1484    SHOW_RCS(ssplit_h_rcs)
1485    SHOW_RCS(ssplit_rcs)
1486    SHOW_RCS(urlmatch_h_rcs)
1487    SHOW_RCS(urlmatch_rcs)
1488 #ifdef _WIN32
1489 #ifndef _WIN_CONSOLE
1490    SHOW_RCS(w32log_h_rcs)
1491    SHOW_RCS(w32log_rcs)
1492    SHOW_RCS(w32res_h_rcs)
1493    SHOW_RCS(w32taskbar_h_rcs)
1494    SHOW_RCS(w32taskbar_rcs)
1495 #endif /* ndef _WIN_CONSOLE */
1496    SHOW_RCS(win32_h_rcs)
1497    SHOW_RCS(win32_rcs)
1498 #endif /* def _WIN32 */
1499
1500 #undef SHOW_RCS
1501
1502    return result;
1503
1504 }
1505
1506
1507 /*
1508   Local Variables:
1509   tab-width: 3
1510   end:
1511 */