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