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