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