1 const char cgisimple_rcs[] = "$Id: cgisimple.c,v 1.22 2002/03/24 16:18:15 jongfoster Exp $";
2 /*********************************************************************
4 * File : $Source: /cvsroot/ijbswa/current/cgisimple.c,v $
6 * Purpose : Simple CGIs to get information about Privoxy's
9 * Functions declared include:
12 * Copyright : Written by and Copyright (C) 2001 the SourceForge
13 * Privoxy team. http://www.privoxy.org/
15 * Based on the Internet Junkbuster originally written
16 * by and Copyright (C) 1997 Anonymous Coders and
17 * Junkbusters Corporation. http://www.junkbusters.com
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.
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.
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.
38 * $Log: cgisimple.c,v $
39 * Revision 1.22 2002/03/24 16:18:15 jongfoster
42 * Revision 1.21 2002/03/24 15:23:33 jongfoster
45 * Revision 1.20 2002/03/24 13:25:43 swa
46 * name change related issues
48 * Revision 1.19 2002/03/16 23:54:06 jongfoster
49 * Adding graceful termination feature, to help look for memory leaks.
50 * If you enable this (which, by design, has to be done by hand
51 * editing config.h) and then go to http://i.j.b/die, then the program
52 * will exit cleanly after the *next* request. It should free all the
53 * memory that was used.
55 * Revision 1.18 2002/03/12 01:44:49 oes
56 * Changed default for "blocked" image from jb logo to checkboard pattern
58 * Revision 1.17 2002/03/08 16:43:18 oes
59 * Added choice beween GIF and PNG built-in images
61 * Revision 1.16 2002/03/07 03:48:38 oes
62 * - Changed built-in images from GIF to PNG
63 * (with regard to Unisys patent issue)
64 * - Added a 4x4 pattern PNG which is less intrusive
65 * than the logo but also clearly marks the deleted banners
67 * Revision 1.15 2002/03/06 22:54:35 jongfoster
68 * Automated function-comment nitpicking.
70 * Revision 1.14 2002/03/02 04:14:50 david__schmidt
71 * Clean up a little CRLF unpleasantness that suddenly appeared
73 * Revision 1.13 2002/02/21 00:10:37 jongfoster
74 * Adding send-banner?type=auto option
76 * Revision 1.12 2002/01/23 01:03:32 jongfoster
77 * Fixing gcc [CygWin] compiler warnings
79 * Revision 1.11 2002/01/23 00:01:04 jongfoster
80 * Adding cgi_transparent_gif() for http://i.j.b/t
81 * Adding missing html_encode() to many CGI functions.
82 * Adding urlmatch.[ch] to http://i.j.b/show-version
84 * Revision 1.10 2002/01/17 21:10:37 jongfoster
85 * Changes to cgi_show_url_info to use new matching code from urlmatch.c.
86 * Also fixing a problem in the same function with improperly quoted URLs
87 * in output HTML, and adding code to handle https:// URLs correctly.
89 * Revision 1.9 2001/11/30 23:09:15 jongfoster
90 * Now reports on FEATURE_CGI_EDIT_ACTIONS
91 * Removing FEATURE_DENY_GZIP from template
93 * Revision 1.8 2001/11/13 00:14:07 jongfoster
94 * Fixing stupid bug now I've figured out what || means.
95 * (It always returns 0 or 1, not one of it's paramaters.)
97 * Revision 1.7 2001/10/23 21:48:19 jongfoster
98 * Cleaning up error handling in CGI functions - they now send back
99 * a HTML error page and should never cause a FATAL error. (Fixes one
100 * potential source of "denial of service" attacks).
102 * CGI actions file editor that works and is actually useful.
104 * Ability to toggle JunkBuster remotely using a CGI call.
106 * You can turn off both the above features in the main configuration
107 * file, e.g. if you are running a multi-user proxy.
109 * Revision 1.6 2001/10/14 22:00:32 jongfoster
110 * Adding support for a 404 error when an invalid CGI page is requested.
112 * Revision 1.5 2001/10/07 15:30:41 oes
113 * Removed FEATURE_DENY_GZIP
115 * Revision 1.4 2001/10/02 15:31:12 oes
116 * Introduced show-request cgi
118 * Revision 1.3 2001/09/22 16:34:44 jongfoster
119 * Removing unneeded #includes
121 * Revision 1.2 2001/09/19 18:01:11 oes
122 * Fixed comments; cosmetics
124 * Revision 1.1 2001/09/16 17:08:54 jongfoster
125 * Moving simple CGI functions from cgi.c to new file cgisimple.c
128 **********************************************************************/
134 #include <sys/types.h>
141 #define snprintf _snprintf
142 #endif /* def _WIN32 */
146 #include "cgisimple.h"
152 #include "miscutil.h"
155 #include "urlmatch.h"
157 const char cgisimple_h_rcs[] = CGISIMPLE_H_VERSION;
160 static char *show_rcs(void);
161 static jb_err show_defines(struct map *exports);
164 /*********************************************************************
166 * Function : cgi_default
168 * Description : CGI function that is called if no action was given.
169 * Lists menu of available unhidden CGIs.
172 * 1 : csp = Current client state (buffers, headers, etc...)
173 * 2 : rsp = http_response data structure for output
174 * 3 : parameters = map of cgi parameters
176 * CGI Parameters : none
178 * Returns : JB_ERR_OK on success
179 * JB_ERR_MEMORY on out-of-memory
180 * (Problems other than out-of-memory should be
181 * handled by this routine - it should set the
182 * rsp appropriately and return "success")
184 *********************************************************************/
185 jb_err cgi_default(struct client_state *csp,
186 struct http_response *rsp,
187 const struct map *parameters)
196 if (NULL == (exports = default_exports(csp, "")))
198 return JB_ERR_MEMORY;
201 /* If there were other parameters, export a dump as "cgi-parameters" */
202 if (parameters->first)
204 tmp = strdup("<p>What made you think this cgi takes parameters?\n"
205 "Anyway, here they are, in case you're interested:</p>\n");
206 string_join(&tmp, dump_map(parameters));
210 return JB_ERR_MEMORY;
212 if (map(exports, "cgi-parameters", 1, tmp, 0))
214 return JB_ERR_MEMORY;
219 if (map(exports, "cgi-parameters", 1, "", 1))
221 return JB_ERR_MEMORY;
225 return template_fill_for_cgi(csp, "default", exports, rsp);
231 /*********************************************************************
233 * Function : cgi_error_404
235 * Description : CGI function that is called if an unknown action was
239 * 1 : csp = Current client state (buffers, headers, etc...)
240 * 2 : rsp = http_response data structure for output
241 * 3 : parameters = map of cgi parameters
243 * CGI Parameters : none
245 * Returns : JB_ERR_OK on success
246 * JB_ERR_MEMORY on out-of-memory error.
248 *********************************************************************/
249 jb_err cgi_error_404(struct client_state *csp,
250 struct http_response *rsp,
251 const struct map *parameters)
259 if (NULL == (exports = default_exports(csp, NULL)))
261 return JB_ERR_MEMORY;
264 rsp->status = strdup("404 Privoxy configuration page not found");
265 if (rsp->status == NULL)
268 return JB_ERR_MEMORY;
271 return template_fill_for_cgi(csp, "cgi-error-404", exports, rsp);
275 #ifdef FEATURE_GRACEFUL_TERMINATION
276 /*********************************************************************
280 * Description : CGI function to shut down Privoxy.
281 * NOTE: Turning this on in a production build
282 * would be a BAD idea. An EXTREMELY BAD idea.
283 * In short, don't do it.
286 * 1 : csp = Current client state (buffers, headers, etc...)
287 * 2 : rsp = http_response data structure for output
288 * 3 : parameters = map of cgi parameters
290 * CGI Parameters : none
292 * Returns : JB_ERR_OK on success
293 * JB_ERR_MEMORY on out-of-memory error.
295 *********************************************************************/
296 jb_err cgi_die (struct client_state *csp,
297 struct http_response *rsp,
298 const struct map *parameters)
308 * I don't really care what gets sent back to the browser.
309 * Take the easy option - "out of memory" page.
312 return JB_ERR_MEMORY;
314 #endif /* def FEATURE_GRACEFUL_TERMINATION */
317 /*********************************************************************
319 * Function : cgi_show_request
321 * Description : Show the client's request and what sed() would have
325 * 1 : csp = Current client state (buffers, headers, etc...)
326 * 2 : rsp = http_response data structure for output
327 * 3 : parameters = map of cgi parameters
329 * CGI Parameters : none
331 * Returns : JB_ERR_OK on success
332 * JB_ERR_MEMORY on out-of-memory error.
334 *********************************************************************/
335 jb_err cgi_show_request(struct client_state *csp,
336 struct http_response *rsp,
337 const struct map *parameters)
346 if (NULL == (exports = default_exports(csp, "show-request")))
348 return JB_ERR_MEMORY;
352 * Repair the damage done to the IOB by get_header()
354 for (p = csp->iob->buf; p < csp->iob->eod; p++)
356 if (*p == '\0') *p = '\n';
360 * Export the original client's request and the one we would
361 * be sending to the server if this wasn't a CGI call
364 if (map(exports, "client-request", 1, html_encode(csp->iob->buf), 0))
367 return JB_ERR_MEMORY;
370 if (map(exports, "processed-request", 1, html_encode_and_free_original(
371 sed(client_patterns, add_client_headers, csp)), 0))
374 return JB_ERR_MEMORY;
377 return template_fill_for_cgi(csp, "show-request", exports, rsp);
381 /*********************************************************************
383 * Function : cgi_send_banner
385 * Description : CGI function that returns a banner.
388 * 1 : csp = Current client state (buffers, headers, etc...)
389 * 2 : rsp = http_response data structure for output
390 * 3 : parameters = map of cgi parameters
393 * type : Selects the type of banner between "trans", "logo",
394 * and "auto". Defaults to "logo" if absent or invalid.
395 * "auto" means to select as if we were image-blocking.
396 * (Only the first character really counts).
398 * Returns : JB_ERR_OK on success
399 * JB_ERR_MEMORY on out-of-memory error.
401 *********************************************************************/
402 jb_err cgi_send_banner(struct client_state *csp,
403 struct http_response *rsp,
404 const struct map *parameters)
406 char imagetype = lookup(parameters, "type")[0];
408 if (imagetype == 'a') /* auto */
410 /* Default to pattern */
412 #ifdef FEATURE_IMAGE_BLOCKING
413 if ((csp->action->flags & ACTION_IMAGE_BLOCKER) != 0)
415 /* determine HOW images should be blocked */
416 const char * p = csp->action->string[ACTION_STRING_IMAGE_BLOCKER];
418 /* and handle accordingly: */
419 if ((p != NULL) && (0 == strcmpic(p, "blank")))
423 else if ((p != NULL) && (0 == strcmpic(p, "pattern")))
428 #endif /* def FEATURE_IMAGE_BLOCKING */
431 if ((imagetype == 'b') || (imagetype == 't')) /* blank / transparent */
433 rsp->body = bindup(image_blank_data, image_blank_length);
434 rsp->content_length = image_blank_length;
439 rsp->body = bindup(image_pattern_data, image_pattern_length);
440 rsp->content_length = image_pattern_length;
443 if (rsp->body == NULL)
445 return JB_ERR_MEMORY;
448 if (enlist(rsp->headers, "Content-Type: " BUILTIN_IMAGE_MIMETYPE))
450 return JB_ERR_MEMORY;
460 /*********************************************************************
462 * Function : cgi_transparent_image
464 * Description : CGI function that sends a 1x1 transparent image.
467 * 1 : csp = Current client state (buffers, headers, etc...)
468 * 2 : rsp = http_response data structure for output
469 * 3 : parameters = map of cgi parameters
471 * CGI Parameters : None
473 * Returns : JB_ERR_OK on success
474 * JB_ERR_MEMORY on out-of-memory error.
476 *********************************************************************/
477 jb_err cgi_transparent_image(struct client_state *csp,
478 struct http_response *rsp,
479 const struct map *parameters)
481 rsp->body = bindup(image_blank_data, image_blank_length);
482 rsp->content_length = image_blank_length;
484 if (rsp->body == NULL)
486 return JB_ERR_MEMORY;
489 if (enlist(rsp->headers, "Content-Type: " BUILTIN_IMAGE_MIMETYPE))
491 return JB_ERR_MEMORY;
501 /*********************************************************************
503 * Function : cgi_show_version
505 * Description : CGI function that returns a a web page describing the
506 * file versions of Privoxy.
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
513 * CGI Parameters : none
515 * Returns : JB_ERR_OK on success
516 * JB_ERR_MEMORY on out-of-memory error.
518 *********************************************************************/
519 jb_err cgi_show_version(struct client_state *csp,
520 struct http_response *rsp,
521 const struct map *parameters)
529 if (NULL == (exports = default_exports(csp, "show-version")))
531 return JB_ERR_MEMORY;
534 if (map(exports, "sourceversions", 1, show_rcs(), 0))
537 return JB_ERR_MEMORY;
540 return template_fill_for_cgi(csp, "show-version", exports, rsp);
544 /*********************************************************************
546 * Function : cgi_show_status
548 * Description : CGI function that returns a a web page describing the
549 * current status of Privoxy.
552 * 1 : csp = Current client state (buffers, headers, etc...)
553 * 2 : rsp = http_response data structure for output
554 * 3 : parameters = map of cgi parameters
557 * file : Which file to show. Only first letter is checked,
559 * - "p"ermissions (actions) file
562 * Default is to show menu and other information.
564 * Returns : JB_ERR_OK on success
565 * JB_ERR_MEMORY on out-of-memory error.
567 *********************************************************************/
568 jb_err cgi_show_status(struct client_state *csp,
569 struct http_response *rsp,
570 const struct map *parameters)
576 char buf[BUFFER_SIZE];
577 const char * filename = NULL;
578 char * file_description = NULL;
579 #ifdef FEATURE_STATISTICS
580 float perc_rej; /* Percentage of http requests rejected */
582 int local_urls_rejected;
583 #endif /* ndef FEATURE_STATISTICS */
592 if (NULL == (exports = default_exports(csp, "show-status")))
594 return JB_ERR_MEMORY;
597 switch (*(lookup(parameters, "file")))
600 if (csp->actions_list)
602 filename = csp->actions_list->filename;
603 file_description = "Actions List";
610 filename = csp->rlist->filename;
611 file_description = "Regex Filter List";
619 filename = csp->tlist->filename;
620 file_description = "Trust List";
623 #endif /* def FEATURE_TRUST */
626 if (NULL != filename)
628 if ( map(exports, "file-description", 1, file_description, 1)
629 || map(exports, "filepath", 1, html_encode(filename), 0) )
632 return JB_ERR_MEMORY;
635 if ((fp = fopen(filename, "r")) == NULL)
637 if (map(exports, "content", 1, "<h1>ERROR OPENING FILE!</h1>", 1))
640 return JB_ERR_MEMORY;
646 while ((s != NULL) && fgets(buf, sizeof(buf), fp))
648 string_join (&s, html_encode(buf));
649 string_append(&s, "<br>");
653 if (map(exports, "contents", 1, s, 0))
656 return JB_ERR_MEMORY;
660 return template_fill_for_cgi(csp, "show-status-file", exports, rsp);
663 if (map(exports, "redirect-url", 1, html_encode(REDIRECT_URL), 0))
666 return JB_ERR_MEMORY;
670 for (i = 0; (s != NULL) && (i < Argc); i++)
672 string_join (&s, html_encode(Argv[i]));
673 string_append(&s, " ");
675 if (map(exports, "invocation", 1, s, 0))
678 return JB_ERR_MEMORY;
681 err = map(exports, "options", 1, csp->config->proxy_args, 1);
682 if (!err) err = show_defines(exports);
684 #ifdef FEATURE_STATISTICS
685 local_urls_read = urls_read;
686 local_urls_rejected = urls_rejected;
689 * Need to alter the stats not to include the fetch of this
692 * Can't do following thread safely! doh!
695 * urls_rejected--; * This will be incremented subsequently *
698 if (local_urls_read == 0)
700 if (!err) err = map_block_killer(exports, "have-stats");
704 if (!err) err = map_block_killer(exports, "have-no-stats");
706 perc_rej = (float)local_urls_rejected * 100.0F /
707 (float)local_urls_read;
709 sprintf(buf, "%d", local_urls_read);
710 if (!err) err = map(exports, "requests-received", 1, buf, 1);
712 sprintf(buf, "%d", local_urls_rejected);
713 if (!err) err = map(exports, "requests-blocked", 1, buf, 1);
715 sprintf(buf, "%6.2f", perc_rej);
716 if (!err) err = map(exports, "percent-blocked", 1, buf, 1);
719 #else /* ndef FEATURE_STATISTICS */
720 err = err || map_block_killer(exports, "statistics");
721 #endif /* ndef FEATURE_STATISTICS */
723 if (csp->actions_list)
725 if (!err) err = map(exports, "actions-filename", 1, html_encode(csp->actions_list->filename), 0);
729 if (!err) err = map(exports, "actions-filename", 1, "None specified", 1);
734 if (!err) err = map(exports, "re-filter-filename", 1, html_encode(csp->rlist->filename), 0);
738 if (!err) err = map(exports, "re-filter-filename", 1, "None specified", 1);
744 if (!err) err = map(exports, "trust-filename", 1, html_encode(csp->tlist->filename), 0);
748 if (!err) err = map(exports, "trust-filename", 1, "None specified", 1);
751 if (!err) err = map_block_killer(exports, "trust-support");
752 #endif /* ndef FEATURE_TRUST */
757 return JB_ERR_MEMORY;
760 return template_fill_for_cgi(csp, "show-status", exports, rsp);
764 /*********************************************************************
766 * Function : cgi_show_url_info
768 * Description : CGI function that determines and shows which actions
769 * Privoxy will perform for a given url, and which
770 * matches starting from the defaults have lead to that.
773 * 1 : csp = Current client state (buffers, headers, etc...)
774 * 2 : rsp = http_response data structure for output
775 * 3 : parameters = map of cgi parameters
778 * url : The url whose actions are to be determined.
779 * If url is unset, the url-given conditional will be
780 * set, so that all but the form can be suppressed in
783 * Returns : JB_ERR_OK on success
784 * JB_ERR_MEMORY on out-of-memory error.
786 *********************************************************************/
787 jb_err cgi_show_url_info(struct client_state *csp,
788 struct http_response *rsp,
789 const struct map *parameters)
798 if (NULL == (exports = default_exports(csp, "show-url-info")))
800 return JB_ERR_MEMORY;
804 * Get the url= parameter (if present) and remove any leading/trailing spaces.
806 url_param = strdup(lookup(parameters, "url"));
807 if (url_param == NULL)
810 return JB_ERR_MEMORY;
815 * Handle prefixes. 4 possibilities:
816 * 1) "http://" or "https://" prefix present and followed by URL - OK
817 * 2) Only the "http://" or "https://" part is present, no URL - change
818 * to empty string so it will be detected later as "no URL".
819 * 3) Parameter specified but doesn't contain "http(s?)://" - add a
821 * 4) Parameter not specified or is empty string - let this fall through
822 * for now, next block of code will handle it.
824 if (0 == strncmp(url_param, "http://", 7))
826 if (url_param[7] == '\0')
829 * Empty URL (just prefix).
830 * Make it totally empty so it's caught by the next if()
835 else if (0 == strncmp(url_param, "https://", 8))
837 if (url_param[8] == '\0')
840 * Empty URL (just prefix).
841 * Make it totally empty so it's caught by the next if()
846 else if (url_param[0] != '\0')
849 * Unknown prefix - assume http://
851 char * url_param_prefixed = malloc(7 + 1 + strlen(url_param));
852 if (NULL == url_param_prefixed)
856 return JB_ERR_MEMORY;
858 strcpy(url_param_prefixed, "http://");
859 strcpy(url_param_prefixed + 7, url_param);
861 url_param = url_param_prefixed;
865 if (url_param[0] == '\0')
867 /* URL paramater not specified, display query form only. */
869 if (map_block_killer(exports, "url-given")
870 || map(exports, "url", 1, "", 1))
873 return JB_ERR_MEMORY;
878 /* Given a URL, so query it. */
883 struct file_list *fl;
884 struct url_actions *b;
885 struct http_request url_to_query[1];
886 struct current_action_spec action[1];
888 if (map(exports, "url", 1, html_encode(url_param), 0))
892 return JB_ERR_MEMORY;
895 init_current_action(action);
897 if (map(exports, "default", 1, html_encode_and_free_original(
898 current_action_to_text(action)), 0))
900 free_current_action(action);
903 return JB_ERR_MEMORY;
906 if (((fl = csp->actions_list) == NULL) || ((b = fl->f) == NULL))
908 err = map(exports, "matches", 1, "none" , 1);
909 if (!err) err = map(exports, "final", 1, lookup(exports, "default"), 1);
911 free_current_action(action);
917 return JB_ERR_MEMORY;
920 return template_fill_for_cgi(csp, "show-url-info", exports, rsp);
923 err = parse_http_url(url_param, url_to_query, csp);
927 if (err == JB_ERR_MEMORY)
929 free_current_action(action);
931 return JB_ERR_MEMORY;
937 err = map(exports, "matches", 1, "<b>[Invalid URL specified!]</b>" , 1);
938 if (!err) err = map(exports, "final", 1, lookup(exports, "default"), 1);
940 free_current_action(action);
945 return JB_ERR_MEMORY;
948 return template_fill_for_cgi(csp, "show-url-info", exports, rsp);
952 * We have a warning about SSL paths. Hide it for insecure sites.
954 if (!url_to_query->ssl)
956 if (map_block_killer(exports, "https"))
958 free_current_action(action);
960 return JB_ERR_MEMORY;
964 matches = strdup("");
966 for (b = b->next; (b != NULL) && (matches != NULL); b = b->next)
968 if (url_match(b->url, url_to_query))
970 string_append(&matches, "<b>{");
971 string_join (&matches, html_encode_and_free_original(
972 actions_to_text(b->action)));
973 string_append(&matches, " }</b><br>\n<code>");
974 string_join (&matches, html_encode(b->url->spec));
975 string_append(&matches, "</code><br>\n<br>\n");
977 if (merge_current_action(action, b->action))
980 free_http_request(url_to_query);
981 free_current_action(action);
983 return JB_ERR_MEMORY;
989 free_http_request(url_to_query);
993 free_current_action(action);
995 return JB_ERR_MEMORY;
1001 matches = strdup("none");
1003 if (map(exports, "matches", 1, matches , 0))
1005 free_current_action(action);
1007 return JB_ERR_MEMORY;
1010 s = html_encode_and_free_original(current_action_to_text(action));
1012 free_current_action(action);
1014 if (map(exports, "final", 1, s, 0))
1017 return JB_ERR_MEMORY;
1021 return template_fill_for_cgi(csp, "show-url-info", exports, rsp);
1025 /*********************************************************************
1027 * Function : cgi_robots_txt
1029 * Description : CGI function to return "/robots.txt".
1032 * 1 : csp = Current client state (buffers, headers, etc...)
1033 * 2 : rsp = http_response data structure for output
1034 * 3 : parameters = map of cgi parameters
1036 * CGI Parameters : None
1038 * Returns : JB_ERR_OK on success
1039 * JB_ERR_MEMORY on out-of-memory error.
1041 *********************************************************************/
1042 jb_err cgi_robots_txt(struct client_state *csp,
1043 struct http_response *rsp,
1044 const struct map *parameters)
1050 "# This is the Privoxy control interface.\n"
1051 "# It isn't very useful to index it, and you're likely to break stuff.\n"
1057 if (rsp->body == NULL)
1059 return JB_ERR_MEMORY;
1062 err = enlist_unique(rsp->headers, "Content-Type: text/plain", 13);
1066 get_http_time(7 * 24 * 60 * 60, buf); /* 7 days into future */
1067 if (!err) err = enlist_unique_header(rsp->headers, "Expires", buf);
1069 return (err ? JB_ERR_MEMORY : JB_ERR_OK);
1073 /*********************************************************************
1075 * Function : show_defines
1077 * Description : Add to a map the state od all conditional #defines
1078 * used when building
1081 * 1 : exports = map to extend
1083 * Returns : JB_ERR_OK on success
1084 * JB_ERR_MEMORY on out-of-memory error.
1086 *********************************************************************/
1087 static jb_err show_defines(struct map *exports)
1089 jb_err err = JB_ERR_OK;
1092 if (!err) err = map_conditional(exports, "FEATURE_ACL", 1);
1093 #else /* ifndef FEATURE_ACL */
1094 if (!err) err = map_conditional(exports, "FEATURE_ACL", 0);
1095 #endif /* ndef FEATURE_ACL */
1097 #ifdef FEATURE_CGI_EDIT_ACTIONS
1098 if (!err) err = map_conditional(exports, "FEATURE_CGI_EDIT_ACTIONS", 1);
1099 #else /* ifndef FEATURE_COOKIE_JAR */
1100 if (!err) err = map_conditional(exports, "FEATURE_CGI_EDIT_ACTIONS", 0);
1101 #endif /* ndef FEATURE_COOKIE_JAR */
1103 #ifdef FEATURE_COOKIE_JAR
1104 if (!err) err = map_conditional(exports, "FEATURE_COOKIE_JAR", 1);
1105 #else /* ifndef FEATURE_COOKIE_JAR */
1106 if (!err) err = map_conditional(exports, "FEATURE_COOKIE_JAR", 0);
1107 #endif /* ndef FEATURE_COOKIE_JAR */
1109 #ifdef FEATURE_FAST_REDIRECTS
1110 if (!err) err = map_conditional(exports, "FEATURE_FAST_REDIRECTS", 1);
1111 #else /* ifndef FEATURE_FAST_REDIRECTS */
1112 if (!err) err = map_conditional(exports, "FEATURE_FAST_REDIRECTS", 0);
1113 #endif /* ndef FEATURE_FAST_REDIRECTS */
1115 #ifdef FEATURE_FORCE_LOAD
1116 if (!err) err = map_conditional(exports, "FEATURE_FORCE_LOAD", 1);
1117 #else /* ifndef FEATURE_FORCE_LOAD */
1118 if (!err) err = map_conditional(exports, "FEATURE_FORCE_LOAD", 0);
1119 #endif /* ndef FEATURE_FORCE_LOAD */
1121 #ifdef FEATURE_IMAGE_BLOCKING
1122 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_BLOCKING", 1);
1123 #else /* ifndef FEATURE_IMAGE_BLOCKING */
1124 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_BLOCKING", 0);
1125 #endif /* ndef FEATURE_IMAGE_BLOCKING */
1127 #ifdef FEATURE_IMAGE_DETECT_MSIE
1128 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_DETECT_MSIE", 1);
1129 #else /* ifndef FEATURE_IMAGE_DETECT_MSIE */
1130 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_DETECT_MSIE", 0);
1131 #endif /* ndef FEATURE_IMAGE_DETECT_MSIE */
1133 #ifdef FEATURE_KILL_POPUPS
1134 if (!err) err = map_conditional(exports, "FEATURE_KILL_POPUPS", 1);
1135 #else /* ifndef FEATURE_KILL_POPUPS */
1136 if (!err) err = map_conditional(exports, "FEATURE_KILL_POPUPS", 0);
1137 #endif /* ndef FEATURE_KILL_POPUPS */
1139 #ifdef FEATURE_NO_GIFS
1140 if (!err) err = map_conditional(exports, "FEATURE_NO_GIFS", 1);
1141 #else /* ifndef FEATURE_NO_GIFS */
1142 if (!err) err = map_conditional(exports, "FEATURE_NO_GIFS", 0);
1143 #endif /* ndef FEATURE_NO_GIFS */
1145 #ifdef FEATURE_PTHREAD
1146 if (!err) err = map_conditional(exports, "FEATURE_PTHREAD", 1);
1147 #else /* ifndef FEATURE_PTHREAD */
1148 if (!err) err = map_conditional(exports, "FEATURE_PTHREAD", 0);
1149 #endif /* ndef FEATURE_PTHREAD */
1151 #ifdef FEATURE_STATISTICS
1152 if (!err) err = map_conditional(exports, "FEATURE_STATISTICS", 1);
1153 #else /* ifndef FEATURE_STATISTICS */
1154 if (!err) err = map_conditional(exports, "FEATURE_STATISTICS", 0);
1155 #endif /* ndef FEATURE_STATISTICS */
1157 #ifdef FEATURE_TOGGLE
1158 if (!err) err = map_conditional(exports, "FEATURE_TOGGLE", 1);
1159 #else /* ifndef FEATURE_TOGGLE */
1160 if (!err) err = map_conditional(exports, "FEATURE_TOGGLE", 0);
1161 #endif /* ndef FEATURE_TOGGLE */
1163 #ifdef FEATURE_TRUST
1164 if (!err) err = map_conditional(exports, "FEATURE_TRUST", 1);
1165 #else /* ifndef FEATURE_TRUST */
1166 if (!err) err = map_conditional(exports, "FEATURE_TRUST", 0);
1167 #endif /* ndef FEATURE_TRUST */
1170 if (!err) err = map_conditional(exports, "REGEX_GNU", 1);
1171 #else /* ifndef REGEX_GNU */
1172 if (!err) err = map_conditional(exports, "REGEX_GNU", 0);
1173 #endif /* def REGEX_GNU */
1176 if (!err) err = map_conditional(exports, "REGEX_PCRE", 1);
1177 #else /* ifndef REGEX_PCRE */
1178 if (!err) err = map_conditional(exports, "REGEX_PCRE", 0);
1179 #endif /* def REGEX_PCRE */
1182 if (!err) err = map_conditional(exports, "STATIC_PCRE", 1);
1183 #else /* ifndef STATIC_PCRE */
1184 if (!err) err = map_conditional(exports, "STATIC_PCRE", 0);
1185 #endif /* ndef STATIC_PCRE */
1188 if (!err) err = map_conditional(exports, "STATIC_PCRS", 1);
1189 #else /* ifndef STATIC_PCRS */
1190 if (!err) err = map_conditional(exports, "STATIC_PCRS", 0);
1191 #endif /* ndef STATIC_PCRS */
1193 if (!err) err = map(exports, "FORCE_PREFIX", 1, FORCE_PREFIX, 1);
1199 /*********************************************************************
1201 * Function : show_rcs
1203 * Description : Create a string with the rcs info for all sourcefiles
1207 * Returns : A string, or NULL on out-of-memory.
1209 *********************************************************************/
1210 static char *show_rcs(void)
1212 char *result = strdup("");
1213 char buf[BUFFER_SIZE];
1215 /* Instead of including *all* dot h's in the project (thus creating a
1216 * tremendous amount of dependencies), I will concede to declaring them
1217 * as extern's. This forces the developer to add to this list, but oh well.
1220 #define SHOW_RCS(__x) \
1222 extern const char __x[]; \
1223 sprintf(buf, "%s\n", __x); \
1224 string_append(&result, buf); \
1227 /* In alphabetical order */
1228 SHOW_RCS(actions_h_rcs)
1229 SHOW_RCS(actions_rcs)
1232 #ifdef FEATURE_CGI_EDIT_ACTIONS
1233 SHOW_RCS(cgiedit_h_rcs)
1234 SHOW_RCS(cgiedit_rcs)
1235 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1236 SHOW_RCS(cgisimple_h_rcs)
1237 SHOW_RCS(cgisimple_rcs)
1239 SHOW_RCS(cygwin_h_rcs)
1241 SHOW_RCS(deanimate_h_rcs)
1242 SHOW_RCS(deanimate_rcs)
1243 SHOW_RCS(encode_h_rcs)
1244 SHOW_RCS(encode_rcs)
1245 SHOW_RCS(errlog_h_rcs)
1246 SHOW_RCS(errlog_rcs)
1247 SHOW_RCS(filters_h_rcs)
1248 SHOW_RCS(filters_rcs)
1249 SHOW_RCS(gateway_h_rcs)
1250 SHOW_RCS(gateway_rcs)
1252 SHOW_RCS(gnu_regex_h_rcs)
1253 SHOW_RCS(gnu_regex_rcs)
1254 #endif /* def GNU_REGEX */
1255 SHOW_RCS(jbsockets_h_rcs)
1256 SHOW_RCS(jbsockets_rcs)
1259 #ifdef FEATURE_KILL_POPUPS
1260 SHOW_RCS(killpopup_h_rcs)
1261 SHOW_RCS(killpopup_rcs)
1262 #endif /* def FEATURE_KILL_POPUPS */
1263 SHOW_RCS(list_h_rcs)
1265 SHOW_RCS(loadcfg_h_rcs)
1266 SHOW_RCS(loadcfg_rcs)
1267 SHOW_RCS(loaders_h_rcs)
1268 SHOW_RCS(loaders_rcs)
1269 SHOW_RCS(miscutil_h_rcs)
1270 SHOW_RCS(miscutil_rcs)
1271 SHOW_RCS(parsers_h_rcs)
1272 SHOW_RCS(parsers_rcs)
1274 SHOW_RCS(pcrs_h_rcs)
1275 SHOW_RCS(project_h_rcs)
1276 SHOW_RCS(ssplit_h_rcs)
1277 SHOW_RCS(ssplit_rcs)
1278 SHOW_RCS(urlmatch_h_rcs)
1279 SHOW_RCS(urlmatch_rcs)
1281 #ifndef _WIN_CONSOLE
1282 SHOW_RCS(w32log_h_rcs)
1283 SHOW_RCS(w32log_rcs)
1284 SHOW_RCS(w32res_h_rcs)
1285 SHOW_RCS(w32taskbar_h_rcs)
1286 SHOW_RCS(w32taskbar_rcs)
1287 #endif /* ndef _WIN_CONSOLE */
1288 SHOW_RCS(win32_h_rcs)
1290 #endif /* def _WIN32 */