OS/2 native needed a snprintf() routine. Added one to miscutil, brackedted
[privoxy.git] / cgisimple.c
1 const char cgisimple_rcs[] = "$Id: cgisimple.c,v 1.6 2001/10/14 22:00:32 jongfoster Exp $";
2 /*********************************************************************
3  *
4  * File        :  $Source: /cvsroot/ijbswa/current/cgisimple.c,v $
5  *
6  * Purpose     :  Simple CGIs to get information about JunkBuster's
7  *                status.
8  *                
9  *                Functions declared include:
10  * 
11  *
12  * Copyright   :  Written by and Copyright (C) 2001 the SourceForge
13  *                IJBSWA team.  http://ijbswa.sourceforge.net
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.6  2001/10/14 22:00:32  jongfoster
40  *    Adding support for a 404 error when an invalid CGI page is requested.
41  *
42  *    Revision 1.5  2001/10/07 15:30:41  oes
43  *    Removed FEATURE_DENY_GZIP
44  *
45  *    Revision 1.4  2001/10/02 15:31:12  oes
46  *    Introduced show-request cgi
47  *
48  *    Revision 1.3  2001/09/22 16:34:44  jongfoster
49  *    Removing unneeded #includes
50  *
51  *    Revision 1.2  2001/09/19 18:01:11  oes
52  *    Fixed comments; cosmetics
53  *
54  *    Revision 1.1  2001/09/16 17:08:54  jongfoster
55  *    Moving simple CGI functions from cgi.c to new file cgisimple.c
56  *
57  *
58  **********************************************************************/
59 \f
60
61 #include "config.h"
62
63 #include <stdio.h>
64 #include <sys/types.h>
65 #include <stdlib.h>
66 #include <ctype.h>
67 #include <string.h>
68 #include <assert.h>
69
70 #ifdef _WIN32
71 #define snprintf _snprintf
72 #endif /* def _WIN32 */
73
74 #include "project.h"
75 #include "cgi.h"
76 #include "cgisimple.h"
77 #include "list.h"
78 #include "encode.h"
79 #include "jcc.h"
80 #include "filters.h"
81 #include "actions.h"
82 #include "miscutil.h"
83 #include "loadcfg.h"
84 #include "parsers.h"
85
86 const char cgisimple_h_rcs[] = CGISIMPLE_H_VERSION;
87
88
89 static char *show_rcs(void);
90 static jb_err show_defines(struct map *exports);
91
92
93 /*********************************************************************
94  *
95  * Function    :  cgi_default
96  *
97  * Description :  CGI function that is called if no action was given.
98  *                Lists menu of available unhidden CGIs.
99  *               
100  * Parameters  :
101  *           1 :  csp = Current client state (buffers, headers, etc...)
102  *           2 :  rsp = http_response data structure for output
103  *           3 :  parameters = map of cgi parameters
104  *
105  * CGI Parameters : none
106  *
107  * Returns     :  JB_ERR_OK on success
108  *                JB_ERR_MEMORY on out-of-memory
109  *                (Problems other than out-of-memory should be
110  *                handled by this routine - it should set the
111  *                rsp appropriately and return "success")
112  *
113  *********************************************************************/
114 jb_err cgi_default(struct client_state *csp,
115                    struct http_response *rsp,
116                    const struct map *parameters)
117 {
118    char *p;
119    char *tmp;
120    struct map *exports;
121
122    assert(csp);
123    assert(rsp);
124    assert(parameters);
125
126    if (NULL == (exports = default_exports(csp, "")))
127    {
128       return JB_ERR_MEMORY;
129    }
130
131    /* If there were other parameters, export a dump as "cgi-parameters" */
132    if (parameters->first)
133    {
134       if (NULL == (p = dump_map(parameters)))
135       {
136          free_map(exports);
137          return JB_ERR_MEMORY;
138       }
139       tmp = strdup("<p>What made you think this cgi takes parameters?\n"
140                    "Anyway, here they are, in case you're interested:</p>\n");
141       string_append(&tmp, p);
142       free(p);
143       if (tmp == NULL)
144       {
145          free_map(exports);
146          return JB_ERR_MEMORY;
147       }
148       if (map(exports, "cgi-parameters", 1, tmp, 0))
149       {
150          return JB_ERR_MEMORY;
151       }
152    }
153    else
154    {
155       if (map(exports, "cgi-parameters", 1, "", 1))
156       {
157          return JB_ERR_MEMORY;
158       }
159    }
160
161    return template_fill_for_cgi(csp, "default", exports, rsp);
162 }
163
164
165
166
167 /*********************************************************************
168  *
169  * Function    :  cgi_error_404
170  *
171  * Description :  CGI function that is called if an unknown action was
172  *                given.
173  *               
174  * Parameters  :
175  *           1 :  csp = Current client state (buffers, headers, etc...)
176  *           2 :  rsp = http_response data structure for output
177  *           3 :  parameters = map of cgi parameters
178  *
179  * CGI Parameters : none
180  *
181  * Returns     :  JB_ERR_OK on success
182  *                JB_ERR_MEMORY on out-of-memory error.  
183  *
184  *********************************************************************/
185 jb_err cgi_error_404(struct client_state *csp,
186                      struct http_response *rsp,
187                      const struct map *parameters)
188 {
189    struct map *exports;
190
191    assert(csp);
192    assert(rsp);
193    assert(parameters);
194
195    if (NULL == (exports = default_exports(csp, NULL)))
196    {
197       return JB_ERR_MEMORY;
198    }
199
200    rsp->status = strdup("404 JunkBuster configuration page not found");
201    if (rsp->status == NULL)
202    {
203       free_map(exports);
204       return JB_ERR_MEMORY;
205    }
206
207    return template_fill_for_cgi(csp, "cgi-error-404", exports, rsp);
208 }
209
210
211 /*********************************************************************
212  *
213  * Function    :  cgi_show_request
214  *
215  * Description :  Show the client's request and what sed() would have
216  *                made of it.
217  *               
218  * Parameters  :
219  *           1 :  csp = Current client state (buffers, headers, etc...)
220  *           2 :  rsp = http_response data structure for output
221  *           3 :  parameters = map of cgi parameters
222  *
223  * CGI Parameters : none
224  *
225  * Returns     :  JB_ERR_OK on success
226  *                JB_ERR_MEMORY on out-of-memory error.  
227  *
228  *********************************************************************/
229 jb_err cgi_show_request(struct client_state *csp,
230                         struct http_response *rsp,
231                         const struct map *parameters)
232 {
233    char *p;
234    struct map *exports;
235
236    assert(csp);
237    assert(rsp);
238    assert(parameters);
239
240    if (NULL == (exports = default_exports(csp, "show-request")))
241    {
242       return JB_ERR_MEMORY;
243    }
244    
245    /*
246     * Repair the damage done to the IOB by get_header()
247     */
248    for (p = csp->iob->buf; p < csp->iob->eod; p++)
249    {
250       if (*p == '\0') *p = '\n';
251    }
252
253    /*
254     * Export the original client's request and the one we would
255     * be sending to the server if this wasn't a CGI call
256     */
257
258    if (map(exports, "client-request", 1, csp->iob->buf, 1))
259    {
260       free_map(exports);
261       return JB_ERR_MEMORY;
262    }
263
264    if (map(exports, "processed-request", 1, sed(client_patterns, add_client_headers, csp), 0))
265    {
266       free_map(exports);
267       return JB_ERR_MEMORY;
268    }
269    
270    return template_fill_for_cgi(csp, "show-request", exports, rsp);
271 }
272
273
274 /*********************************************************************
275  *
276  * Function    :  cgi_send_banner
277  *
278  * Description :  CGI function that returns a banner. 
279  *
280  * Parameters  :
281  *           1 :  csp = Current client state (buffers, headers, etc...)
282  *           2 :  rsp = http_response data structure for output
283  *           3 :  parameters = map of cgi parameters
284  *
285  * CGI Parameters :
286  *           type : Selects the type of banner between "trans" and "jb".
287  *                  Defaults to "jb" if absent or != "trans".
288  *
289  * Returns     :  JB_ERR_OK on success
290  *                JB_ERR_MEMORY on out-of-memory error.  
291  *
292  *********************************************************************/
293 jb_err cgi_send_banner(struct client_state *csp,
294                        struct http_response *rsp,
295                        const struct map *parameters)
296 {
297    if (strcmp(lookup(parameters, "type"), "trans"))
298    {
299       rsp->body = bindup(image_junkbuster_gif_data, image_junkbuster_gif_length);
300       rsp->content_length = image_junkbuster_gif_length;
301    }
302    else
303    {
304       rsp->body = bindup(image_blank_gif_data, image_blank_gif_length);
305       rsp->content_length = image_blank_gif_length;
306    }   
307
308    if (rsp->body == NULL)
309    {
310       return JB_ERR_MEMORY;
311    }
312
313    if (enlist(rsp->headers, "Content-Type: image/gif"))
314    {
315       return JB_ERR_MEMORY;
316    }
317
318    rsp->is_static = 1;
319
320    return JB_ERR_OK;
321
322 }
323
324
325 /*********************************************************************
326  *
327  * Function    :  cgi_show_version
328  *
329  * Description :  CGI function that returns a a web page describing the
330  *                file versions of IJB.
331  *
332  * Parameters  :
333  *           1 :  csp = Current client state (buffers, headers, etc...)
334  *           2 :  rsp = http_response data structure for output
335  *           3 :  parameters = map of cgi parameters
336  *
337  * CGI Parameters : none
338  *
339  * Returns     :  JB_ERR_OK on success
340  *                JB_ERR_MEMORY on out-of-memory error.  
341  *
342  *********************************************************************/
343 jb_err cgi_show_version(struct client_state *csp,
344                         struct http_response *rsp,
345                         const struct map *parameters)
346 {
347    struct map *exports;
348
349    assert(csp);
350    assert(rsp);
351    assert(parameters);
352
353    if (NULL == (exports = default_exports(csp, "show-version")))
354    {
355       return JB_ERR_MEMORY;
356    }
357
358    if (map(exports, "sourceversions", 1, show_rcs(), 0))
359    {
360       free_map(exports);
361       return JB_ERR_MEMORY;
362    }
363
364    return template_fill_for_cgi(csp, "show-version", exports, rsp);
365 }
366
367  
368 /*********************************************************************
369  *
370  * Function    :  cgi_show_status
371  *
372  * Description :  CGI function that returns a a web page describing the
373  *                current status of IJB.
374  *
375  * Parameters  :
376  *           1 :  csp = Current client state (buffers, headers, etc...)
377  *           2 :  rsp = http_response data structure for output
378  *           3 :  parameters = map of cgi parameters
379  *
380  * CGI Parameters :
381  *        file :  Which file to show.  Only first letter is checked,
382  *                valid values are:
383  *                - "p"ermissions (actions) file
384  *                - "r"egex
385  *                - "t"rust
386  *                Default is to show menu and other information.
387  *
388  * Returns     :  JB_ERR_OK on success
389  *                JB_ERR_MEMORY on out-of-memory error.  
390  *
391  *********************************************************************/
392 jb_err cgi_show_status(struct client_state *csp,
393                        struct http_response *rsp,
394                        const struct map *parameters)
395 {
396    char *s = NULL;
397    int i;
398
399    FILE * fp;
400    char buf[BUFFER_SIZE];
401    char * p;
402    const char * filename = NULL;
403    char * file_description = NULL;
404 #ifdef FEATURE_STATISTICS
405    float perc_rej;   /* Percentage of http requests rejected */
406    int local_urls_read;
407    int local_urls_rejected;
408 #endif /* ndef FEATURE_STATISTICS */
409    jb_err err;
410
411    struct map *exports;
412
413    assert(csp);
414    assert(rsp);
415    assert(parameters);
416
417    if (NULL == (exports = default_exports(csp, "show-status")))
418    {
419       return JB_ERR_MEMORY;
420    }
421
422    switch (*(lookup(parameters, "file")))
423    {
424    case 'p':
425       if (csp->actions_list)
426       {
427          filename = csp->actions_list->filename;
428          file_description = "Actions List";
429       }
430       break;
431
432    case 'r':
433       if (csp->rlist)
434       {
435          filename = csp->rlist->filename;
436          file_description = "Regex Filter List";
437       }
438       break;
439
440 #ifdef FEATURE_TRUST
441    case 't':
442       if (csp->tlist)
443       {
444          filename = csp->tlist->filename;
445          file_description = "Trust List";
446       }
447       break;
448 #endif /* def FEATURE_TRUST */
449    }
450
451    if (NULL != filename)
452    {
453       if ( map(exports, "file-description", 1, file_description, 1)
454         || map(exports, "filepath", 1, html_encode(filename), 0) )
455       {
456          free_map(exports);
457          return JB_ERR_MEMORY;
458       }
459
460       if ((fp = fopen(filename, "r")) == NULL)
461       {
462          if (map(exports, "content", 1, "<h1>ERROR OPENING FILE!</h1>", 1))
463          {
464             free_map(exports);
465             return JB_ERR_MEMORY;
466          }
467       }
468       else
469       {
470          s = strdup("");
471          while ((s != NULL) && fgets(buf, sizeof(buf), fp))
472          {
473             p = html_encode(buf);
474             if (p)
475             {
476                string_append(&s, p);
477                freez(p);
478                string_append(&s, "<br>");
479             }
480          }
481          fclose(fp);
482
483          if (map(exports, "contents", 1, s, 0))
484          {
485             free_map(exports);
486             return JB_ERR_MEMORY;
487          }
488       }
489
490       return template_fill_for_cgi(csp, "show-status-file", exports, rsp);
491    }
492
493    if (map(exports, "redirect-url", 1, REDIRECT_URL, 1))
494    {
495       free_map(exports);
496       return JB_ERR_MEMORY;
497    }
498    
499    s = strdup("");
500    for (i=0; i < Argc; i++)
501    {
502       string_append(&s, Argv[i]);
503       string_append(&s, " ");
504    }
505    if (map(exports, "invocation", 1, s, 0))
506    {
507       free_map(exports);
508       return JB_ERR_MEMORY;
509    }
510
511    err = map(exports, "options", 1, csp->config->proxy_args, 1);
512    err = err || show_defines(exports);
513
514 #ifdef FEATURE_STATISTICS
515    local_urls_read     = urls_read;
516    local_urls_rejected = urls_rejected;
517
518    /*
519     * Need to alter the stats not to include the fetch of this
520     * page.
521     *
522     * Can't do following thread safely! doh!
523     *
524     * urls_read--;
525     * urls_rejected--; * This will be incremented subsequently *
526     */
527
528    if (local_urls_read == 0)
529    {
530       err = err || map_block_killer(exports, "have-stats");
531    }
532    else
533    {
534       err = err || map_block_killer(exports, "have-no-stats");
535
536       perc_rej = (float)local_urls_rejected * 100.0F /
537             (float)local_urls_read;
538
539       sprintf(buf, "%d", local_urls_read);
540       err = err || map(exports, "requests-received", 1, buf, 1);
541
542       sprintf(buf, "%d", local_urls_rejected);
543       err = err || map(exports, "requests-blocked", 1, buf, 1);
544
545       sprintf(buf, "%6.2f", perc_rej);
546       err = err || map(exports, "percent-blocked", 1, buf, 1);
547    }
548
549 #else /* ndef FEATURE_STATISTICS */
550    err = err || map_block_killer(exports, "statistics");
551 #endif /* ndef FEATURE_STATISTICS */
552
553    if (csp->actions_list)
554    {
555       err = err || map(exports, "actions-filename", 1,  csp->actions_list->filename, 1);
556    }
557    else
558    {
559       err = err || map(exports, "actions-filename", 1, "None specified", 1);
560    }
561
562    if (csp->rlist)
563    {
564       err = err || map(exports, "re-filter-filename", 1,  csp->rlist->filename, 1);
565    }
566    else
567    {
568       err = err || map(exports, "re-filter-filename", 1, "None specified", 1);
569    }
570
571 #ifdef FEATURE_TRUST
572    if (csp->tlist)
573    {
574       err = err || map(exports, "trust-filename", 1,  csp->tlist->filename, 1);
575    }
576    else
577    {
578       err = err || map(exports, "trust-filename", 1, "None specified", 1);
579    }
580 #else
581    err = err || map_block_killer(exports, "trust-support");
582 #endif /* ndef FEATURE_TRUST */
583
584    if (err)
585    {
586       free_map(exports);
587       return JB_ERR_MEMORY;
588    }
589
590    return template_fill_for_cgi(csp, "show-status", exports, rsp);
591 }
592
593  
594 /*********************************************************************
595  *
596  * Function    :  cgi_show_url_info
597  *
598  * Description :  CGI function that determines and shows which actions
599  *                junkbuster will perform for a given url, and which
600  *                matches starting from the defaults have lead to that.
601  *
602  * Parameters  :
603  *           1 :  csp = Current client state (buffers, headers, etc...)
604  *           2 :  rsp = http_response data structure for output
605  *           3 :  parameters = map of cgi parameters
606  *
607  * CGI Parameters :
608  *            url : The url whose actions are to be determined.
609  *                  If url is unset, the url-given conditional will be
610  *                  set, so that all but the form can be suppressed in
611  *                  the template.
612  *
613  * Returns     :  JB_ERR_OK on success
614  *                JB_ERR_MEMORY on out-of-memory error.  
615  *
616  *********************************************************************/
617 jb_err cgi_show_url_info(struct client_state *csp,
618                          struct http_response *rsp,
619                          const struct map *parameters)
620 {
621    const char *url_param_const;
622    char *host = NULL;
623    struct map *exports;
624
625    assert(csp);
626    assert(rsp);
627    assert(parameters);
628
629    if (NULL == (exports = default_exports(csp, "show-url-info")))
630    {
631       return JB_ERR_MEMORY;
632    }
633
634    url_param_const = lookup(parameters, "url");
635    if (*url_param_const == '\0')
636    {
637       if (map_block_killer(exports, "url-given")
638         || map(exports, "url", 1, "", 1))
639       {
640          free_map(exports);
641          return JB_ERR_MEMORY;
642       }
643    }
644    else
645    {
646       char *url_param;
647       char *matches;
648       char *path;
649       char *s;
650       int port = 80;
651       int hits = 0;
652       struct file_list *fl;
653       struct url_actions *b;
654       struct url_spec url[1];
655       struct current_action_spec action[1];
656       
657       if (NULL == (url_param = strdup(url_param_const)))
658       {
659          free_map(exports);
660          return JB_ERR_MEMORY;
661       }
662
663       host = url_param;
664       host += (strncmp(url_param, "http://", 7)) ? 0 : 7;
665
666       if (map(exports, "url", 1, host, 1)
667        || map(exports, "url-html", 1, html_encode(host), 0))
668       {
669          free(url_param);
670          free_map(exports);
671          return JB_ERR_MEMORY;
672       }
673
674       init_current_action(action);
675
676       s = current_action_to_text(action);
677       if (map(exports, "default", 1, s , 0))
678       {
679          free_current_action(action);
680          free(url_param);
681          free_map(exports);
682          return JB_ERR_MEMORY;
683       }
684
685       if (((fl = csp->actions_list) == NULL) || ((b = fl->f) == NULL))
686       {
687          jb_err err;
688
689          err = map(exports, "matches", 1, "none" , 1)
690             || map(exports, "final", 1, lookup(exports, "default"), 1);
691
692          free_current_action(action);
693          free(url_param);
694
695          if (err)
696          {
697             free_map(exports);
698             return JB_ERR_MEMORY;
699          }
700
701          return template_fill_for_cgi(csp, "show-url-info", exports, rsp);
702       }
703
704       s = strchr(host, '/');
705       if (s != NULL)
706       {
707          path = strdup(s);
708          *s = '\0';
709       }
710       else
711       {
712          path = strdup("");
713       }
714       if (NULL == path)
715       {
716          free_current_action(action);
717          free(url_param);
718          free_map(exports);
719          return JB_ERR_MEMORY;
720       }
721
722       s = strchr(host, ':');
723       if (s != NULL)
724       {
725          *s++ = '\0';
726          port = atoi(s);
727          s = NULL;
728       }
729
730       *url = dsplit(host);
731
732       /* if splitting the domain fails, punt */
733       if (url->dbuf == NULL)
734       {
735          jb_err err;
736          
737          err = map(exports, "matches", 1, "none" , 1)
738             || map(exports, "final", 1, lookup(exports, "default"), 1);
739
740          freez(url_param);
741          freez(path);
742          free_current_action(action);
743
744          if (err)
745          {
746             free_map(exports);
747             return JB_ERR_MEMORY;
748          }
749
750          return template_fill_for_cgi(csp, "show-url-info", exports, rsp);
751       }
752
753       matches = strdup("");
754
755       for (b = b->next; NULL != b; b = b->next)
756       {
757          if ((b->url->port == 0) || (b->url->port == port))
758          {
759             if ((b->url->domain[0] == '\0') || (domaincmp(b->url, url) == 0))
760             {
761                if ((b->url->path == NULL) ||
762 #ifdef REGEX
763                   (regexec(b->url->preg, path, 0, NULL, 0) == 0)
764 #else
765                   (strncmp(b->url->path, path, b->url->pathlen) == 0)
766 #endif
767                )
768                {
769                   s = actions_to_text(b->action);
770                   if (s == NULL)
771                   {
772                      freez(url->dbuf);
773                      freez(url->dvec);
774
775                      free(url_param);
776                      free(path);
777                      free_current_action(action);
778                      free_map(exports);
779                      return JB_ERR_MEMORY;
780                   }
781                   string_append(&matches, "<b>{");
782                   string_append(&matches, s);
783                   string_append(&matches, " }</b><br>\n<code>");
784                   string_append(&matches, b->url->spec);
785                   string_append(&matches, "</code><br>\n<br>\n");
786                   free(s);
787
788                   merge_current_action(action, b->action); /* FIXME: Add error checking */
789                   hits++;
790                }
791             }
792          }
793       }
794
795       freez(url->dbuf);
796       freez(url->dvec);
797
798       free(url_param);
799       free(path);
800
801       if (matches == NULL)
802       {
803          free_current_action(action);
804          free_map(exports);
805          return JB_ERR_MEMORY;
806       }
807
808       if (!hits)
809       {
810          free(matches);
811          matches = strdup("none");
812       }
813       if (map(exports, "matches", 1, matches , 0))
814       {
815          free_current_action(action);
816          free_map(exports);
817          return JB_ERR_MEMORY;
818       }
819
820       s = current_action_to_text(action);
821
822       free_current_action(action);
823
824       if (map(exports, "final", 1, s, 0))
825       {
826          free_map(exports);
827          return JB_ERR_MEMORY;
828       }
829    }
830
831    return template_fill_for_cgi(csp, "show-url-info", exports, rsp);
832 }
833
834
835 /*********************************************************************
836  *
837  * Function    :  cgi_robots_txt
838  *
839  * Description :  CGI function to return "/robots.txt".
840  *
841  * Parameters  :
842  *           1 :  csp = Current client state (buffers, headers, etc...)
843  *           2 :  rsp = http_response data structure for output
844  *           3 :  parameters = map of cgi parameters
845  *
846  * CGI Parameters : None
847  *
848  * Returns     :  JB_ERR_OK on success
849  *                JB_ERR_MEMORY on out-of-memory error.  
850  *
851  *********************************************************************/
852 jb_err cgi_robots_txt(struct client_state *csp,
853                       struct http_response *rsp,
854                       const struct map *parameters)
855 {
856    char buf[100];
857    jb_err err;
858
859    rsp->body = strdup(
860       "# This is the Internet Junkbuster control interface.\n"
861       "# It isn't very useful to index it, and you're likely to break stuff.\n"
862       "# So go away!\n"
863       "\n"
864       "User-agent: *\n"
865       "Disallow: /\n"
866       "\n");
867    if (rsp->body == NULL)
868    {
869       return JB_ERR_MEMORY;
870    }
871
872    err = enlist_unique(rsp->headers, "Content-Type: text/plain", 13);
873
874    rsp->is_static = 1;
875
876    get_http_time(7 * 24 * 60 * 60, buf); /* 7 days into future */
877    err = err || enlist_unique_header(rsp->headers, "Expires", buf);
878
879    return (err ? JB_ERR_MEMORY : JB_ERR_OK);
880 }
881
882
883 /*********************************************************************
884  *
885  * Function    :  show_defines
886  *
887  * Description :  Add to a map the state od all conditional #defines
888  *                used when building
889  *
890  * Parameters  :
891  *           1 :  exports = map to extend
892  *
893  * Returns     :  JB_ERR_OK on success
894  *                JB_ERR_MEMORY on out-of-memory error.  
895  *
896  *********************************************************************/
897 static jb_err show_defines(struct map *exports)
898 {
899    jb_err err = JB_ERR_OK;
900
901 #ifdef FEATURE_ACL
902    err = err || map_conditional(exports, "FEATURE_ACL", 1);
903 #else /* ifndef FEATURE_ACL */
904    err = err || map_conditional(exports, "FEATURE_ACL", 0);
905 #endif /* ndef FEATURE_ACL */
906
907 #ifdef FEATURE_COOKIE_JAR
908    err = err || map_conditional(exports, "FEATURE_COOKIE_JAR", 1);
909 #else /* ifndef FEATURE_COOKIE_JAR */
910    err = err || map_conditional(exports, "FEATURE_COOKIE_JAR", 0);
911 #endif /* ndef FEATURE_COOKIE_JAR */
912
913 #ifdef FEATURE_FAST_REDIRECTS
914    err = err || map_conditional(exports, "FEATURE_FAST_REDIRECTS", 1);
915 #else /* ifndef FEATURE_FAST_REDIRECTS */
916    err = err || map_conditional(exports, "FEATURE_FAST_REDIRECTS", 0);
917 #endif /* ndef FEATURE_FAST_REDIRECTS */
918
919 #ifdef FEATURE_FORCE_LOAD
920    err = err || map_conditional(exports, "FEATURE_FORCE_LOAD", 1);
921 #else /* ifndef FEATURE_FORCE_LOAD */
922    err = err || map_conditional(exports, "FEATURE_FORCE_LOAD", 0);
923 #endif /* ndef FEATURE_FORCE_LOAD */
924
925 #ifdef FEATURE_IMAGE_BLOCKING
926    err = err || map_conditional(exports, "FEATURE_IMAGE_BLOCKING", 1);
927 #else /* ifndef FEATURE_IMAGE_BLOCKING */
928    err = err || map_conditional(exports, "FEATURE_IMAGE_BLOCKING", 0);
929 #endif /* ndef FEATURE_IMAGE_BLOCKING */
930
931 #ifdef FEATURE_IMAGE_DETECT_MSIE
932    err = err || map_conditional(exports, "FEATURE_IMAGE_DETECT_MSIE", 1);
933 #else /* ifndef FEATURE_IMAGE_DETECT_MSIE */
934    err = err || map_conditional(exports, "FEATURE_IMAGE_DETECT_MSIE", 0);
935 #endif /* ndef FEATURE_IMAGE_DETECT_MSIE */
936
937 #ifdef FEATURE_KILL_POPUPS
938    err = err || map_conditional(exports, "FEATURE_KILL_POPUPS", 1);
939 #else /* ifndef FEATURE_KILL_POPUPS */
940    err = err || map_conditional(exports, "FEATURE_KILL_POPUPS", 0);
941 #endif /* ndef FEATURE_KILL_POPUPS */
942
943 #ifdef FEATURE_PTHREAD
944    err = err || map_conditional(exports, "FEATURE_PTHREAD", 1);
945 #else /* ifndef FEATURE_PTHREAD */
946    err = err || map_conditional(exports, "FEATURE_PTHREAD", 0);
947 #endif /* ndef FEATURE_PTHREAD */
948
949 #ifdef FEATURE_STATISTICS
950    err = err || map_conditional(exports, "FEATURE_STATISTICS", 1);
951 #else /* ifndef FEATURE_STATISTICS */
952    err = err || map_conditional(exports, "FEATURE_STATISTICS", 0);
953 #endif /* ndef FEATURE_STATISTICS */
954
955 #ifdef FEATURE_TOGGLE
956    err = err || map_conditional(exports, "FEATURE_TOGGLE", 1);
957 #else /* ifndef FEATURE_TOGGLE */
958    err = err || map_conditional(exports, "FEATURE_TOGGLE", 0);
959 #endif /* ndef FEATURE_TOGGLE */
960
961 #ifdef FEATURE_TRUST
962    err = err || map_conditional(exports, "FEATURE_TRUST", 1);
963 #else /* ifndef FEATURE_TRUST */
964    err = err || map_conditional(exports, "FEATURE_TRUST", 0);
965 #endif /* ndef FEATURE_TRUST */
966
967 #ifdef REGEX_GNU
968    err = err || map_conditional(exports, "REGEX_GNU", 1);
969 #else /* ifndef REGEX_GNU */
970    err = err || map_conditional(exports, "REGEX_GNU", 0);
971 #endif /* def REGEX_GNU */
972
973 #ifdef REGEX_PCRE
974    err = err || map_conditional(exports, "REGEX_PCRE", 1);
975 #else /* ifndef REGEX_PCRE */
976    err = err || map_conditional(exports, "REGEX_PCRE", 0);
977 #endif /* def REGEX_PCRE */
978
979 #ifdef STATIC_PCRE
980    err = err || map_conditional(exports, "STATIC_PCRE", 1);
981 #else /* ifndef STATIC_PCRE */
982    err = err || map_conditional(exports, "STATIC_PCRE", 0);
983 #endif /* ndef STATIC_PCRE */
984
985 #ifdef STATIC_PCRS
986    err = err || map_conditional(exports, "STATIC_PCRS", 1);
987 #else /* ifndef STATIC_PCRS */
988    err = err || map_conditional(exports, "STATIC_PCRS", 0);
989 #endif /* ndef STATIC_PCRS */
990
991    err = err || map(exports, "FORCE_PREFIX", 1, FORCE_PREFIX, 1);
992
993    return err;
994 }
995
996
997 /*********************************************************************
998  *
999  * Function    :  show_rcs
1000  *
1001  * Description :  Create a string with the rcs info for all sourcefiles
1002  *
1003  * Parameters  :  None
1004  *
1005  * Returns     :  A string, or NULL on out-of-memory.
1006  *
1007  *********************************************************************/
1008 static char *show_rcs(void)
1009 {
1010    char *result = strdup("");
1011    char buf[BUFFER_SIZE];
1012
1013    /* Instead of including *all* dot h's in the project (thus creating a
1014     * tremendous amount of dependencies), I will concede to declaring them
1015     * as extern's.  This forces the developer to add to this list, but oh well.
1016     */
1017
1018 #define SHOW_RCS(__x)              \
1019    {                               \
1020       extern const char __x[];     \
1021       sprintf(buf, "%s\n", __x);   \
1022       string_append(&result, buf); \
1023    }
1024
1025    /* In alphabetical order */
1026    SHOW_RCS(actions_h_rcs)
1027    SHOW_RCS(actions_rcs)
1028    SHOW_RCS(cgi_h_rcs)
1029    SHOW_RCS(cgi_rcs)
1030 #ifdef FEATURE_CGI_EDIT_ACTIONS
1031    SHOW_RCS(cgiedit_h_rcs)
1032    SHOW_RCS(cgiedit_rcs)
1033 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1034    SHOW_RCS(cgisimple_h_rcs)
1035    SHOW_RCS(cgisimple_rcs)
1036 #ifdef __MINGW32__
1037    SHOW_RCS(cygwin_h_rcs)
1038 #endif
1039    SHOW_RCS(deanimate_h_rcs)
1040    SHOW_RCS(deanimate_rcs)
1041    SHOW_RCS(encode_h_rcs)
1042    SHOW_RCS(encode_rcs)
1043    SHOW_RCS(errlog_h_rcs)
1044    SHOW_RCS(errlog_rcs)
1045    SHOW_RCS(filters_h_rcs)
1046    SHOW_RCS(filters_rcs)
1047    SHOW_RCS(gateway_h_rcs)
1048    SHOW_RCS(gateway_rcs)
1049 #ifdef GNU_REGEX
1050    SHOW_RCS(gnu_regex_h_rcs)
1051    SHOW_RCS(gnu_regex_rcs)
1052 #endif /* def GNU_REGEX */
1053    SHOW_RCS(jbsockets_h_rcs)
1054    SHOW_RCS(jbsockets_rcs)
1055    SHOW_RCS(jcc_h_rcs)
1056    SHOW_RCS(jcc_rcs)
1057 #ifdef FEATURE_KILL_POPUPS
1058    SHOW_RCS(killpopup_h_rcs)
1059    SHOW_RCS(killpopup_rcs)
1060 #endif /* def FEATURE_KILL_POPUPS */
1061    SHOW_RCS(list_h_rcs)
1062    SHOW_RCS(list_rcs)
1063    SHOW_RCS(loadcfg_h_rcs)
1064    SHOW_RCS(loadcfg_rcs)
1065    SHOW_RCS(loaders_h_rcs)
1066    SHOW_RCS(loaders_rcs)
1067    SHOW_RCS(miscutil_h_rcs)
1068    SHOW_RCS(miscutil_rcs)
1069    SHOW_RCS(parsers_h_rcs)
1070    SHOW_RCS(parsers_rcs)
1071    SHOW_RCS(pcrs_rcs)
1072    SHOW_RCS(pcrs_h_rcs)
1073    SHOW_RCS(project_h_rcs)
1074    SHOW_RCS(ssplit_h_rcs)
1075    SHOW_RCS(ssplit_rcs)
1076 #ifdef _WIN32
1077 #ifndef _WIN_CONSOLE
1078    SHOW_RCS(w32log_h_rcs)
1079    SHOW_RCS(w32log_rcs)
1080    SHOW_RCS(w32res_h_rcs)
1081    SHOW_RCS(w32taskbar_h_rcs)
1082    SHOW_RCS(w32taskbar_rcs)
1083 #endif /* ndef _WIN_CONSOLE */
1084    SHOW_RCS(win32_h_rcs)
1085    SHOW_RCS(win32_rcs)
1086 #endif /* def _WIN32 */
1087
1088 #undef SHOW_RCS
1089
1090    return result;
1091
1092 }
1093
1094
1095 /*
1096   Local Variables:
1097   tab-width: 3
1098   end:
1099 */