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