1 const char cgisimple_rcs[] = "$Id: cgisimple.c,v 1.23 2002/03/26 22:29:54 swa 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.23 2002/03/26 22:29:54 swa
40 * we have a new homepage!
42 * Revision 1.22 2002/03/24 16:18:15 jongfoster
45 * Revision 1.21 2002/03/24 15:23:33 jongfoster
48 * Revision 1.20 2002/03/24 13:25:43 swa
49 * name change related issues
51 * Revision 1.19 2002/03/16 23:54:06 jongfoster
52 * Adding graceful termination feature, to help look for memory leaks.
53 * If you enable this (which, by design, has to be done by hand
54 * editing config.h) and then go to http://i.j.b/die, then the program
55 * will exit cleanly after the *next* request. It should free all the
56 * memory that was used.
58 * Revision 1.18 2002/03/12 01:44:49 oes
59 * Changed default for "blocked" image from jb logo to checkboard pattern
61 * Revision 1.17 2002/03/08 16:43:18 oes
62 * Added choice beween GIF and PNG built-in images
64 * Revision 1.16 2002/03/07 03:48:38 oes
65 * - Changed built-in images from GIF to PNG
66 * (with regard to Unisys patent issue)
67 * - Added a 4x4 pattern PNG which is less intrusive
68 * than the logo but also clearly marks the deleted banners
70 * Revision 1.15 2002/03/06 22:54:35 jongfoster
71 * Automated function-comment nitpicking.
73 * Revision 1.14 2002/03/02 04:14:50 david__schmidt
74 * Clean up a little CRLF unpleasantness that suddenly appeared
76 * Revision 1.13 2002/02/21 00:10:37 jongfoster
77 * Adding send-banner?type=auto option
79 * Revision 1.12 2002/01/23 01:03:32 jongfoster
80 * Fixing gcc [CygWin] compiler warnings
82 * Revision 1.11 2002/01/23 00:01:04 jongfoster
83 * Adding cgi_transparent_gif() for http://i.j.b/t
84 * Adding missing html_encode() to many CGI functions.
85 * Adding urlmatch.[ch] to http://i.j.b/show-version
87 * Revision 1.10 2002/01/17 21:10:37 jongfoster
88 * Changes to cgi_show_url_info to use new matching code from urlmatch.c.
89 * Also fixing a problem in the same function with improperly quoted URLs
90 * in output HTML, and adding code to handle https:// URLs correctly.
92 * Revision 1.9 2001/11/30 23:09:15 jongfoster
93 * Now reports on FEATURE_CGI_EDIT_ACTIONS
94 * Removing FEATURE_DENY_GZIP from template
96 * Revision 1.8 2001/11/13 00:14:07 jongfoster
97 * Fixing stupid bug now I've figured out what || means.
98 * (It always returns 0 or 1, not one of it's paramaters.)
100 * Revision 1.7 2001/10/23 21:48:19 jongfoster
101 * Cleaning up error handling in CGI functions - they now send back
102 * a HTML error page and should never cause a FATAL error. (Fixes one
103 * potential source of "denial of service" attacks).
105 * CGI actions file editor that works and is actually useful.
107 * Ability to toggle JunkBuster remotely using a CGI call.
109 * You can turn off both the above features in the main configuration
110 * file, e.g. if you are running a multi-user proxy.
112 * Revision 1.6 2001/10/14 22:00:32 jongfoster
113 * Adding support for a 404 error when an invalid CGI page is requested.
115 * Revision 1.5 2001/10/07 15:30:41 oes
116 * Removed FEATURE_DENY_GZIP
118 * Revision 1.4 2001/10/02 15:31:12 oes
119 * Introduced show-request cgi
121 * Revision 1.3 2001/09/22 16:34:44 jongfoster
122 * Removing unneeded #includes
124 * Revision 1.2 2001/09/19 18:01:11 oes
125 * Fixed comments; cosmetics
127 * Revision 1.1 2001/09/16 17:08:54 jongfoster
128 * Moving simple CGI functions from cgi.c to new file cgisimple.c
131 **********************************************************************/
137 #include <sys/types.h>
144 #define snprintf _snprintf
145 #endif /* def _WIN32 */
149 #include "cgisimple.h"
155 #include "miscutil.h"
158 #include "urlmatch.h"
160 const char cgisimple_h_rcs[] = CGISIMPLE_H_VERSION;
163 static char *show_rcs(void);
164 static jb_err show_defines(struct map *exports);
167 /*********************************************************************
169 * Function : cgi_default
171 * Description : CGI function that is called if no action was given.
172 * Lists menu of available unhidden CGIs.
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
179 * CGI Parameters : none
181 * Returns : JB_ERR_OK on success
182 * JB_ERR_MEMORY on out-of-memory
183 * (Problems other than out-of-memory should be
184 * handled by this routine - it should set the
185 * rsp appropriately and return "success")
187 *********************************************************************/
188 jb_err cgi_default(struct client_state *csp,
189 struct http_response *rsp,
190 const struct map *parameters)
199 if (NULL == (exports = default_exports(csp, "")))
201 return JB_ERR_MEMORY;
204 /* If there were other parameters, export a dump as "cgi-parameters" */
205 if (parameters->first)
207 tmp = strdup("<p>What made you think this cgi takes parameters?\n"
208 "Anyway, here they are, in case you're interested:</p>\n");
209 string_join(&tmp, dump_map(parameters));
213 return JB_ERR_MEMORY;
215 if (map(exports, "cgi-parameters", 1, tmp, 0))
217 return JB_ERR_MEMORY;
222 if (map(exports, "cgi-parameters", 1, "", 1))
224 return JB_ERR_MEMORY;
228 return template_fill_for_cgi(csp, "default", exports, rsp);
234 /*********************************************************************
236 * Function : cgi_error_404
238 * Description : CGI function that is called if an unknown action was
242 * 1 : csp = Current client state (buffers, headers, etc...)
243 * 2 : rsp = http_response data structure for output
244 * 3 : parameters = map of cgi parameters
246 * CGI Parameters : none
248 * Returns : JB_ERR_OK on success
249 * JB_ERR_MEMORY on out-of-memory error.
251 *********************************************************************/
252 jb_err cgi_error_404(struct client_state *csp,
253 struct http_response *rsp,
254 const struct map *parameters)
262 if (NULL == (exports = default_exports(csp, NULL)))
264 return JB_ERR_MEMORY;
267 rsp->status = strdup("404 Privoxy configuration page not found");
268 if (rsp->status == NULL)
271 return JB_ERR_MEMORY;
274 return template_fill_for_cgi(csp, "cgi-error-404", exports, rsp);
278 #ifdef FEATURE_GRACEFUL_TERMINATION
279 /*********************************************************************
283 * Description : CGI function to shut down Privoxy.
284 * NOTE: Turning this on in a production build
285 * would be a BAD idea. An EXTREMELY BAD idea.
286 * In short, don't do it.
289 * 1 : csp = Current client state (buffers, headers, etc...)
290 * 2 : rsp = http_response data structure for output
291 * 3 : parameters = map of cgi parameters
293 * CGI Parameters : none
295 * Returns : JB_ERR_OK on success
296 * JB_ERR_MEMORY on out-of-memory error.
298 *********************************************************************/
299 jb_err cgi_die (struct client_state *csp,
300 struct http_response *rsp,
301 const struct map *parameters)
311 * I don't really care what gets sent back to the browser.
312 * Take the easy option - "out of memory" page.
315 return JB_ERR_MEMORY;
317 #endif /* def FEATURE_GRACEFUL_TERMINATION */
320 /*********************************************************************
322 * Function : cgi_show_request
324 * Description : Show the client's request and what sed() would have
328 * 1 : csp = Current client state (buffers, headers, etc...)
329 * 2 : rsp = http_response data structure for output
330 * 3 : parameters = map of cgi parameters
332 * CGI Parameters : none
334 * Returns : JB_ERR_OK on success
335 * JB_ERR_MEMORY on out-of-memory error.
337 *********************************************************************/
338 jb_err cgi_show_request(struct client_state *csp,
339 struct http_response *rsp,
340 const struct map *parameters)
349 if (NULL == (exports = default_exports(csp, "show-request")))
351 return JB_ERR_MEMORY;
355 * Repair the damage done to the IOB by get_header()
357 for (p = csp->iob->buf; p < csp->iob->eod; p++)
359 if (*p == '\0') *p = '\n';
363 * Export the original client's request and the one we would
364 * be sending to the server if this wasn't a CGI call
367 if (map(exports, "client-request", 1, html_encode(csp->iob->buf), 0))
370 return JB_ERR_MEMORY;
373 if (map(exports, "processed-request", 1, html_encode_and_free_original(
374 sed(client_patterns, add_client_headers, csp)), 0))
377 return JB_ERR_MEMORY;
380 return template_fill_for_cgi(csp, "show-request", exports, rsp);
384 /*********************************************************************
386 * Function : cgi_send_banner
388 * Description : CGI function that returns a banner.
391 * 1 : csp = Current client state (buffers, headers, etc...)
392 * 2 : rsp = http_response data structure for output
393 * 3 : parameters = map of cgi parameters
396 * type : Selects the type of banner between "trans", "logo",
397 * and "auto". Defaults to "logo" if absent or invalid.
398 * "auto" means to select as if we were image-blocking.
399 * (Only the first character really counts).
401 * Returns : JB_ERR_OK on success
402 * JB_ERR_MEMORY on out-of-memory error.
404 *********************************************************************/
405 jb_err cgi_send_banner(struct client_state *csp,
406 struct http_response *rsp,
407 const struct map *parameters)
409 char imagetype = lookup(parameters, "type")[0];
411 if (imagetype == 'a') /* auto */
413 /* Default to pattern */
415 #ifdef FEATURE_IMAGE_BLOCKING
416 if ((csp->action->flags & ACTION_IMAGE_BLOCKER) != 0)
418 /* determine HOW images should be blocked */
419 const char * p = csp->action->string[ACTION_STRING_IMAGE_BLOCKER];
421 /* and handle accordingly: */
422 if ((p != NULL) && (0 == strcmpic(p, "blank")))
426 else if ((p != NULL) && (0 == strcmpic(p, "pattern")))
431 #endif /* def FEATURE_IMAGE_BLOCKING */
434 if ((imagetype == 'b') || (imagetype == 't')) /* blank / transparent */
436 rsp->body = bindup(image_blank_data, image_blank_length);
437 rsp->content_length = image_blank_length;
442 rsp->body = bindup(image_pattern_data, image_pattern_length);
443 rsp->content_length = image_pattern_length;
446 if (rsp->body == NULL)
448 return JB_ERR_MEMORY;
451 if (enlist(rsp->headers, "Content-Type: " BUILTIN_IMAGE_MIMETYPE))
453 return JB_ERR_MEMORY;
463 /*********************************************************************
465 * Function : cgi_transparent_image
467 * Description : CGI function that sends a 1x1 transparent image.
470 * 1 : csp = Current client state (buffers, headers, etc...)
471 * 2 : rsp = http_response data structure for output
472 * 3 : parameters = map of cgi parameters
474 * CGI Parameters : None
476 * Returns : JB_ERR_OK on success
477 * JB_ERR_MEMORY on out-of-memory error.
479 *********************************************************************/
480 jb_err cgi_transparent_image(struct client_state *csp,
481 struct http_response *rsp,
482 const struct map *parameters)
484 rsp->body = bindup(image_blank_data, image_blank_length);
485 rsp->content_length = image_blank_length;
487 if (rsp->body == NULL)
489 return JB_ERR_MEMORY;
492 if (enlist(rsp->headers, "Content-Type: " BUILTIN_IMAGE_MIMETYPE))
494 return JB_ERR_MEMORY;
504 /*********************************************************************
506 * Function : cgi_show_version
508 * Description : CGI function that returns a a web page describing the
509 * file versions of Privoxy.
512 * 1 : csp = Current client state (buffers, headers, etc...)
513 * 2 : rsp = http_response data structure for output
514 * 3 : parameters = map of cgi parameters
516 * CGI Parameters : none
518 * Returns : JB_ERR_OK on success
519 * JB_ERR_MEMORY on out-of-memory error.
521 *********************************************************************/
522 jb_err cgi_show_version(struct client_state *csp,
523 struct http_response *rsp,
524 const struct map *parameters)
532 if (NULL == (exports = default_exports(csp, "show-version")))
534 return JB_ERR_MEMORY;
537 if (map(exports, "sourceversions", 1, show_rcs(), 0))
540 return JB_ERR_MEMORY;
543 return template_fill_for_cgi(csp, "show-version", exports, rsp);
547 /*********************************************************************
549 * Function : cgi_show_status
551 * Description : CGI function that returns a a web page describing the
552 * current status of Privoxy.
555 * 1 : csp = Current client state (buffers, headers, etc...)
556 * 2 : rsp = http_response data structure for output
557 * 3 : parameters = map of cgi parameters
560 * file : Which file to show. Only first letter is checked,
562 * - "p"ermissions (actions) file
565 * Default is to show menu and other information.
567 * Returns : JB_ERR_OK on success
568 * JB_ERR_MEMORY on out-of-memory error.
570 *********************************************************************/
571 jb_err cgi_show_status(struct client_state *csp,
572 struct http_response *rsp,
573 const struct map *parameters)
579 char buf[BUFFER_SIZE];
580 const char * filename = NULL;
581 char * file_description = NULL;
582 #ifdef FEATURE_STATISTICS
583 float perc_rej; /* Percentage of http requests rejected */
585 int local_urls_rejected;
586 #endif /* ndef FEATURE_STATISTICS */
595 if (NULL == (exports = default_exports(csp, "show-status")))
597 return JB_ERR_MEMORY;
600 switch (*(lookup(parameters, "file")))
603 if (csp->actions_list)
605 filename = csp->actions_list->filename;
606 file_description = "Actions List";
613 filename = csp->rlist->filename;
614 file_description = "Regex Filter List";
622 filename = csp->tlist->filename;
623 file_description = "Trust List";
626 #endif /* def FEATURE_TRUST */
629 if (NULL != filename)
631 if ( map(exports, "file-description", 1, file_description, 1)
632 || map(exports, "filepath", 1, html_encode(filename), 0) )
635 return JB_ERR_MEMORY;
638 if ((fp = fopen(filename, "r")) == NULL)
640 if (map(exports, "content", 1, "<h1>ERROR OPENING FILE!</h1>", 1))
643 return JB_ERR_MEMORY;
649 while ((s != NULL) && fgets(buf, sizeof(buf), fp))
651 string_join (&s, html_encode(buf));
652 string_append(&s, "<br>");
656 if (map(exports, "contents", 1, s, 0))
659 return JB_ERR_MEMORY;
663 return template_fill_for_cgi(csp, "show-status-file", exports, rsp);
666 if (map(exports, "redirect-url", 1, html_encode(REDIRECT_URL), 0))
669 return JB_ERR_MEMORY;
673 for (i = 0; (s != NULL) && (i < Argc); i++)
675 string_join (&s, html_encode(Argv[i]));
676 string_append(&s, " ");
678 if (map(exports, "invocation", 1, s, 0))
681 return JB_ERR_MEMORY;
684 err = map(exports, "options", 1, csp->config->proxy_args, 1);
685 if (!err) err = show_defines(exports);
687 #ifdef FEATURE_STATISTICS
688 local_urls_read = urls_read;
689 local_urls_rejected = urls_rejected;
692 * Need to alter the stats not to include the fetch of this
695 * Can't do following thread safely! doh!
698 * urls_rejected--; * This will be incremented subsequently *
701 if (local_urls_read == 0)
703 if (!err) err = map_block_killer(exports, "have-stats");
707 if (!err) err = map_block_killer(exports, "have-no-stats");
709 perc_rej = (float)local_urls_rejected * 100.0F /
710 (float)local_urls_read;
712 sprintf(buf, "%d", local_urls_read);
713 if (!err) err = map(exports, "requests-received", 1, buf, 1);
715 sprintf(buf, "%d", local_urls_rejected);
716 if (!err) err = map(exports, "requests-blocked", 1, buf, 1);
718 sprintf(buf, "%6.2f", perc_rej);
719 if (!err) err = map(exports, "percent-blocked", 1, buf, 1);
722 #else /* ndef FEATURE_STATISTICS */
723 err = err || map_block_killer(exports, "statistics");
724 #endif /* ndef FEATURE_STATISTICS */
726 if (csp->actions_list)
728 if (!err) err = map(exports, "actions-filename", 1, html_encode(csp->actions_list->filename), 0);
732 if (!err) err = map(exports, "actions-filename", 1, "None specified", 1);
737 if (!err) err = map(exports, "re-filter-filename", 1, html_encode(csp->rlist->filename), 0);
741 if (!err) err = map(exports, "re-filter-filename", 1, "None specified", 1);
747 if (!err) err = map(exports, "trust-filename", 1, html_encode(csp->tlist->filename), 0);
751 if (!err) err = map(exports, "trust-filename", 1, "None specified", 1);
754 if (!err) err = map_block_killer(exports, "trust-support");
755 #endif /* ndef FEATURE_TRUST */
760 return JB_ERR_MEMORY;
763 return template_fill_for_cgi(csp, "show-status", exports, rsp);
767 /*********************************************************************
769 * Function : cgi_show_url_info
771 * Description : CGI function that determines and shows which actions
772 * Privoxy will perform for a given url, and which
773 * matches starting from the defaults have lead to that.
776 * 1 : csp = Current client state (buffers, headers, etc...)
777 * 2 : rsp = http_response data structure for output
778 * 3 : parameters = map of cgi parameters
781 * url : The url whose actions are to be determined.
782 * If url is unset, the url-given conditional will be
783 * set, so that all but the form can be suppressed in
786 * Returns : JB_ERR_OK on success
787 * JB_ERR_MEMORY on out-of-memory error.
789 *********************************************************************/
790 jb_err cgi_show_url_info(struct client_state *csp,
791 struct http_response *rsp,
792 const struct map *parameters)
801 if (NULL == (exports = default_exports(csp, "show-url-info")))
803 return JB_ERR_MEMORY;
807 * Get the url= parameter (if present) and remove any leading/trailing spaces.
809 url_param = strdup(lookup(parameters, "url"));
810 if (url_param == NULL)
813 return JB_ERR_MEMORY;
818 * Handle prefixes. 4 possibilities:
819 * 1) "http://" or "https://" prefix present and followed by URL - OK
820 * 2) Only the "http://" or "https://" part is present, no URL - change
821 * to empty string so it will be detected later as "no URL".
822 * 3) Parameter specified but doesn't contain "http(s?)://" - add a
824 * 4) Parameter not specified or is empty string - let this fall through
825 * for now, next block of code will handle it.
827 if (0 == strncmp(url_param, "http://", 7))
829 if (url_param[7] == '\0')
832 * Empty URL (just prefix).
833 * Make it totally empty so it's caught by the next if()
838 else if (0 == strncmp(url_param, "https://", 8))
840 if (url_param[8] == '\0')
843 * Empty URL (just prefix).
844 * Make it totally empty so it's caught by the next if()
849 else if (url_param[0] != '\0')
852 * Unknown prefix - assume http://
854 char * url_param_prefixed = malloc(7 + 1 + strlen(url_param));
855 if (NULL == url_param_prefixed)
859 return JB_ERR_MEMORY;
861 strcpy(url_param_prefixed, "http://");
862 strcpy(url_param_prefixed + 7, url_param);
864 url_param = url_param_prefixed;
868 if (url_param[0] == '\0')
870 /* URL paramater not specified, display query form only. */
872 if (map_block_killer(exports, "url-given")
873 || map(exports, "url", 1, "", 1))
876 return JB_ERR_MEMORY;
881 /* Given a URL, so query it. */
886 struct file_list *fl;
887 struct url_actions *b;
888 struct http_request url_to_query[1];
889 struct current_action_spec action[1];
891 if (map(exports, "url", 1, html_encode(url_param), 0))
895 return JB_ERR_MEMORY;
898 init_current_action(action);
900 if (map(exports, "default", 1, html_encode_and_free_original(
901 current_action_to_text(action)), 0))
903 free_current_action(action);
906 return JB_ERR_MEMORY;
909 if (((fl = csp->actions_list) == NULL) || ((b = fl->f) == NULL))
911 err = map(exports, "matches", 1, "none" , 1);
912 if (!err) err = map(exports, "final", 1, lookup(exports, "default"), 1);
914 free_current_action(action);
920 return JB_ERR_MEMORY;
923 return template_fill_for_cgi(csp, "show-url-info", exports, rsp);
926 err = parse_http_url(url_param, url_to_query, csp);
930 if (err == JB_ERR_MEMORY)
932 free_current_action(action);
934 return JB_ERR_MEMORY;
940 err = map(exports, "matches", 1, "<b>[Invalid URL specified!]</b>" , 1);
941 if (!err) err = map(exports, "final", 1, lookup(exports, "default"), 1);
943 free_current_action(action);
948 return JB_ERR_MEMORY;
951 return template_fill_for_cgi(csp, "show-url-info", exports, rsp);
955 * We have a warning about SSL paths. Hide it for insecure sites.
957 if (!url_to_query->ssl)
959 if (map_block_killer(exports, "https"))
961 free_current_action(action);
963 return JB_ERR_MEMORY;
967 matches = strdup("");
969 for (b = b->next; (b != NULL) && (matches != NULL); b = b->next)
971 if (url_match(b->url, url_to_query))
973 string_append(&matches, "<b>{");
974 string_join (&matches, html_encode_and_free_original(
975 actions_to_text(b->action)));
976 string_append(&matches, " }</b><br>\n<code>");
977 string_join (&matches, html_encode(b->url->spec));
978 string_append(&matches, "</code><br>\n<br>\n");
980 if (merge_current_action(action, b->action))
983 free_http_request(url_to_query);
984 free_current_action(action);
986 return JB_ERR_MEMORY;
992 free_http_request(url_to_query);
996 free_current_action(action);
998 return JB_ERR_MEMORY;
1004 matches = strdup("none");
1006 if (map(exports, "matches", 1, matches , 0))
1008 free_current_action(action);
1010 return JB_ERR_MEMORY;
1013 s = html_encode_and_free_original(current_action_to_text(action));
1015 free_current_action(action);
1017 if (map(exports, "final", 1, s, 0))
1020 return JB_ERR_MEMORY;
1024 return template_fill_for_cgi(csp, "show-url-info", exports, rsp);
1028 /*********************************************************************
1030 * Function : cgi_robots_txt
1032 * Description : CGI function to return "/robots.txt".
1035 * 1 : csp = Current client state (buffers, headers, etc...)
1036 * 2 : rsp = http_response data structure for output
1037 * 3 : parameters = map of cgi parameters
1039 * CGI Parameters : None
1041 * Returns : JB_ERR_OK on success
1042 * JB_ERR_MEMORY on out-of-memory error.
1044 *********************************************************************/
1045 jb_err cgi_robots_txt(struct client_state *csp,
1046 struct http_response *rsp,
1047 const struct map *parameters)
1053 "# This is the Privoxy control interface.\n"
1054 "# It isn't very useful to index it, and you're likely to break stuff.\n"
1060 if (rsp->body == NULL)
1062 return JB_ERR_MEMORY;
1065 err = enlist_unique(rsp->headers, "Content-Type: text/plain", 13);
1069 get_http_time(7 * 24 * 60 * 60, buf); /* 7 days into future */
1070 if (!err) err = enlist_unique_header(rsp->headers, "Expires", buf);
1072 return (err ? JB_ERR_MEMORY : JB_ERR_OK);
1076 /*********************************************************************
1078 * Function : show_defines
1080 * Description : Add to a map the state od all conditional #defines
1081 * used when building
1084 * 1 : exports = map to extend
1086 * Returns : JB_ERR_OK on success
1087 * JB_ERR_MEMORY on out-of-memory error.
1089 *********************************************************************/
1090 static jb_err show_defines(struct map *exports)
1092 jb_err err = JB_ERR_OK;
1095 if (!err) err = map_conditional(exports, "FEATURE_ACL", 1);
1096 #else /* ifndef FEATURE_ACL */
1097 if (!err) err = map_conditional(exports, "FEATURE_ACL", 0);
1098 #endif /* ndef FEATURE_ACL */
1100 #ifdef FEATURE_CGI_EDIT_ACTIONS
1101 if (!err) err = map_conditional(exports, "FEATURE_CGI_EDIT_ACTIONS", 1);
1102 #else /* ifndef FEATURE_COOKIE_JAR */
1103 if (!err) err = map_conditional(exports, "FEATURE_CGI_EDIT_ACTIONS", 0);
1104 #endif /* ndef FEATURE_COOKIE_JAR */
1106 #ifdef FEATURE_COOKIE_JAR
1107 if (!err) err = map_conditional(exports, "FEATURE_COOKIE_JAR", 1);
1108 #else /* ifndef FEATURE_COOKIE_JAR */
1109 if (!err) err = map_conditional(exports, "FEATURE_COOKIE_JAR", 0);
1110 #endif /* ndef FEATURE_COOKIE_JAR */
1112 #ifdef FEATURE_FAST_REDIRECTS
1113 if (!err) err = map_conditional(exports, "FEATURE_FAST_REDIRECTS", 1);
1114 #else /* ifndef FEATURE_FAST_REDIRECTS */
1115 if (!err) err = map_conditional(exports, "FEATURE_FAST_REDIRECTS", 0);
1116 #endif /* ndef FEATURE_FAST_REDIRECTS */
1118 #ifdef FEATURE_FORCE_LOAD
1119 if (!err) err = map_conditional(exports, "FEATURE_FORCE_LOAD", 1);
1120 if (!err) err = map(exports, "FORCE_PREFIX", 1, FORCE_PREFIX, 1);
1121 #else /* ifndef FEATURE_FORCE_LOAD */
1122 if (!err) err = map_conditional(exports, "FEATURE_FORCE_LOAD", 0);
1123 if (!err) err = map(exports, "FORCE_PREFIX", 1, "(none - disabled)", 1);
1124 #endif /* ndef FEATURE_FORCE_LOAD */
1126 #ifdef FEATURE_IMAGE_BLOCKING
1127 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_BLOCKING", 1);
1128 #else /* ifndef FEATURE_IMAGE_BLOCKING */
1129 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_BLOCKING", 0);
1130 #endif /* ndef FEATURE_IMAGE_BLOCKING */
1132 #ifdef FEATURE_IMAGE_DETECT_MSIE
1133 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_DETECT_MSIE", 1);
1134 #else /* ifndef FEATURE_IMAGE_DETECT_MSIE */
1135 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_DETECT_MSIE", 0);
1136 #endif /* ndef FEATURE_IMAGE_DETECT_MSIE */
1138 #ifdef FEATURE_KILL_POPUPS
1139 if (!err) err = map_conditional(exports, "FEATURE_KILL_POPUPS", 1);
1140 #else /* ifndef FEATURE_KILL_POPUPS */
1141 if (!err) err = map_conditional(exports, "FEATURE_KILL_POPUPS", 0);
1142 #endif /* ndef FEATURE_KILL_POPUPS */
1144 #ifdef FEATURE_NO_GIFS
1145 if (!err) err = map_conditional(exports, "FEATURE_NO_GIFS", 1);
1146 #else /* ifndef FEATURE_NO_GIFS */
1147 if (!err) err = map_conditional(exports, "FEATURE_NO_GIFS", 0);
1148 #endif /* ndef FEATURE_NO_GIFS */
1150 #ifdef FEATURE_PTHREAD
1151 if (!err) err = map_conditional(exports, "FEATURE_PTHREAD", 1);
1152 #else /* ifndef FEATURE_PTHREAD */
1153 if (!err) err = map_conditional(exports, "FEATURE_PTHREAD", 0);
1154 #endif /* ndef FEATURE_PTHREAD */
1156 #ifdef FEATURE_STATISTICS
1157 if (!err) err = map_conditional(exports, "FEATURE_STATISTICS", 1);
1158 #else /* ifndef FEATURE_STATISTICS */
1159 if (!err) err = map_conditional(exports, "FEATURE_STATISTICS", 0);
1160 #endif /* ndef FEATURE_STATISTICS */
1162 #ifdef FEATURE_TOGGLE
1163 if (!err) err = map_conditional(exports, "FEATURE_TOGGLE", 1);
1164 #else /* ifndef FEATURE_TOGGLE */
1165 if (!err) err = map_conditional(exports, "FEATURE_TOGGLE", 0);
1166 #endif /* ndef FEATURE_TOGGLE */
1168 #ifdef FEATURE_TRUST
1169 if (!err) err = map_conditional(exports, "FEATURE_TRUST", 1);
1170 #else /* ifndef FEATURE_TRUST */
1171 if (!err) err = map_conditional(exports, "FEATURE_TRUST", 0);
1172 #endif /* ndef FEATURE_TRUST */
1175 if (!err) err = map_conditional(exports, "REGEX_GNU", 1);
1176 #else /* ifndef REGEX_GNU */
1177 if (!err) err = map_conditional(exports, "REGEX_GNU", 0);
1178 #endif /* def REGEX_GNU */
1181 if (!err) err = map_conditional(exports, "REGEX_PCRE", 1);
1182 #else /* ifndef REGEX_PCRE */
1183 if (!err) err = map_conditional(exports, "REGEX_PCRE", 0);
1184 #endif /* def REGEX_PCRE */
1187 if (!err) err = map_conditional(exports, "STATIC_PCRE", 1);
1188 #else /* ifndef STATIC_PCRE */
1189 if (!err) err = map_conditional(exports, "STATIC_PCRE", 0);
1190 #endif /* ndef STATIC_PCRE */
1193 if (!err) err = map_conditional(exports, "STATIC_PCRS", 1);
1194 #else /* ifndef STATIC_PCRS */
1195 if (!err) err = map_conditional(exports, "STATIC_PCRS", 0);
1196 #endif /* ndef STATIC_PCRS */
1202 /*********************************************************************
1204 * Function : show_rcs
1206 * Description : Create a string with the rcs info for all sourcefiles
1210 * Returns : A string, or NULL on out-of-memory.
1212 *********************************************************************/
1213 static char *show_rcs(void)
1215 char *result = strdup("");
1216 char buf[BUFFER_SIZE];
1218 /* Instead of including *all* dot h's in the project (thus creating a
1219 * tremendous amount of dependencies), I will concede to declaring them
1220 * as extern's. This forces the developer to add to this list, but oh well.
1223 #define SHOW_RCS(__x) \
1225 extern const char __x[]; \
1226 sprintf(buf, "%s\n", __x); \
1227 string_append(&result, buf); \
1230 /* In alphabetical order */
1231 SHOW_RCS(actions_h_rcs)
1232 SHOW_RCS(actions_rcs)
1235 #ifdef FEATURE_CGI_EDIT_ACTIONS
1236 SHOW_RCS(cgiedit_h_rcs)
1237 SHOW_RCS(cgiedit_rcs)
1238 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1239 SHOW_RCS(cgisimple_h_rcs)
1240 SHOW_RCS(cgisimple_rcs)
1242 SHOW_RCS(cygwin_h_rcs)
1244 SHOW_RCS(deanimate_h_rcs)
1245 SHOW_RCS(deanimate_rcs)
1246 SHOW_RCS(encode_h_rcs)
1247 SHOW_RCS(encode_rcs)
1248 SHOW_RCS(errlog_h_rcs)
1249 SHOW_RCS(errlog_rcs)
1250 SHOW_RCS(filters_h_rcs)
1251 SHOW_RCS(filters_rcs)
1252 SHOW_RCS(gateway_h_rcs)
1253 SHOW_RCS(gateway_rcs)
1255 SHOW_RCS(gnu_regex_h_rcs)
1256 SHOW_RCS(gnu_regex_rcs)
1257 #endif /* def GNU_REGEX */
1258 SHOW_RCS(jbsockets_h_rcs)
1259 SHOW_RCS(jbsockets_rcs)
1262 #ifdef FEATURE_KILL_POPUPS
1263 SHOW_RCS(killpopup_h_rcs)
1264 SHOW_RCS(killpopup_rcs)
1265 #endif /* def FEATURE_KILL_POPUPS */
1266 SHOW_RCS(list_h_rcs)
1268 SHOW_RCS(loadcfg_h_rcs)
1269 SHOW_RCS(loadcfg_rcs)
1270 SHOW_RCS(loaders_h_rcs)
1271 SHOW_RCS(loaders_rcs)
1272 SHOW_RCS(miscutil_h_rcs)
1273 SHOW_RCS(miscutil_rcs)
1274 SHOW_RCS(parsers_h_rcs)
1275 SHOW_RCS(parsers_rcs)
1277 SHOW_RCS(pcrs_h_rcs)
1278 SHOW_RCS(project_h_rcs)
1279 SHOW_RCS(ssplit_h_rcs)
1280 SHOW_RCS(ssplit_rcs)
1281 SHOW_RCS(urlmatch_h_rcs)
1282 SHOW_RCS(urlmatch_rcs)
1284 #ifndef _WIN_CONSOLE
1285 SHOW_RCS(w32log_h_rcs)
1286 SHOW_RCS(w32log_rcs)
1287 SHOW_RCS(w32res_h_rcs)
1288 SHOW_RCS(w32taskbar_h_rcs)
1289 SHOW_RCS(w32taskbar_rcs)
1290 #endif /* ndef _WIN_CONSOLE */
1291 SHOW_RCS(win32_h_rcs)
1293 #endif /* def _WIN32 */