1 const char cgisimple_rcs[] = "$Id: cgisimple.c,v 1.20 2002/03/24 13:25:43 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://ijbswa.sourceforge.net
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.20 2002/03/24 13:25:43 swa
40 * name change related issues
42 * Revision 1.19 2002/03/16 23:54:06 jongfoster
43 * Adding graceful termination feature, to help look for memory leaks.
44 * If you enable this (which, by design, has to be done by hand
45 * editing config.h) and then go to http://i.j.b/die, then the program
46 * will exit cleanly after the *next* request. It should free all the
47 * memory that was used.
49 * Revision 1.18 2002/03/12 01:44:49 oes
50 * Changed default for "blocked" image from jb logo to checkboard pattern
52 * Revision 1.17 2002/03/08 16:43:18 oes
53 * Added choice beween GIF and PNG built-in images
55 * Revision 1.16 2002/03/07 03:48:38 oes
56 * - Changed built-in images from GIF to PNG
57 * (with regard to Unisys patent issue)
58 * - Added a 4x4 pattern PNG which is less intrusive
59 * than the logo but also clearly marks the deleted banners
61 * Revision 1.15 2002/03/06 22:54:35 jongfoster
62 * Automated function-comment nitpicking.
64 * Revision 1.14 2002/03/02 04:14:50 david__schmidt
65 * Clean up a little CRLF unpleasantness that suddenly appeared
67 * Revision 1.13 2002/02/21 00:10:37 jongfoster
68 * Adding send-banner?type=auto option
70 * Revision 1.12 2002/01/23 01:03:32 jongfoster
71 * Fixing gcc [CygWin] compiler warnings
73 * Revision 1.11 2002/01/23 00:01:04 jongfoster
74 * Adding cgi_transparent_gif() for http://i.j.b/t
75 * Adding missing html_encode() to many CGI functions.
76 * Adding urlmatch.[ch] to http://i.j.b/show-version
78 * Revision 1.10 2002/01/17 21:10:37 jongfoster
79 * Changes to cgi_show_url_info to use new matching code from urlmatch.c.
80 * Also fixing a problem in the same function with improperly quoted URLs
81 * in output HTML, and adding code to handle https:// URLs correctly.
83 * Revision 1.9 2001/11/30 23:09:15 jongfoster
84 * Now reports on FEATURE_CGI_EDIT_ACTIONS
85 * Removing FEATURE_DENY_GZIP from template
87 * Revision 1.8 2001/11/13 00:14:07 jongfoster
88 * Fixing stupid bug now I've figured out what || means.
89 * (It always returns 0 or 1, not one of it's paramaters.)
91 * Revision 1.7 2001/10/23 21:48:19 jongfoster
92 * Cleaning up error handling in CGI functions - they now send back
93 * a HTML error page and should never cause a FATAL error. (Fixes one
94 * potential source of "denial of service" attacks).
96 * CGI actions file editor that works and is actually useful.
98 * Ability to toggle JunkBuster remotely using a CGI call.
100 * You can turn off both the above features in the main configuration
101 * file, e.g. if you are running a multi-user proxy.
103 * Revision 1.6 2001/10/14 22:00:32 jongfoster
104 * Adding support for a 404 error when an invalid CGI page is requested.
106 * Revision 1.5 2001/10/07 15:30:41 oes
107 * Removed FEATURE_DENY_GZIP
109 * Revision 1.4 2001/10/02 15:31:12 oes
110 * Introduced show-request cgi
112 * Revision 1.3 2001/09/22 16:34:44 jongfoster
113 * Removing unneeded #includes
115 * Revision 1.2 2001/09/19 18:01:11 oes
116 * Fixed comments; cosmetics
118 * Revision 1.1 2001/09/16 17:08:54 jongfoster
119 * Moving simple CGI functions from cgi.c to new file cgisimple.c
122 **********************************************************************/
128 #include <sys/types.h>
135 #define snprintf _snprintf
136 #endif /* def _WIN32 */
140 #include "cgisimple.h"
146 #include "miscutil.h"
149 #include "urlmatch.h"
151 const char cgisimple_h_rcs[] = CGISIMPLE_H_VERSION;
154 static char *show_rcs(void);
155 static jb_err show_defines(struct map *exports);
158 /*********************************************************************
160 * Function : cgi_default
162 * Description : CGI function that is called if no action was given.
163 * Lists menu of available unhidden CGIs.
166 * 1 : csp = Current client state (buffers, headers, etc...)
167 * 2 : rsp = http_response data structure for output
168 * 3 : parameters = map of cgi parameters
170 * CGI Parameters : none
172 * Returns : JB_ERR_OK on success
173 * JB_ERR_MEMORY on out-of-memory
174 * (Problems other than out-of-memory should be
175 * handled by this routine - it should set the
176 * rsp appropriately and return "success")
178 *********************************************************************/
179 jb_err cgi_default(struct client_state *csp,
180 struct http_response *rsp,
181 const struct map *parameters)
190 if (NULL == (exports = default_exports(csp, "")))
192 return JB_ERR_MEMORY;
195 /* If there were other parameters, export a dump as "cgi-parameters" */
196 if (parameters->first)
198 tmp = strdup("<p>What made you think this cgi takes parameters?\n"
199 "Anyway, here they are, in case you're interested:</p>\n");
200 string_join(&tmp, dump_map(parameters));
204 return JB_ERR_MEMORY;
206 if (map(exports, "cgi-parameters", 1, tmp, 0))
208 return JB_ERR_MEMORY;
213 if (map(exports, "cgi-parameters", 1, "", 1))
215 return JB_ERR_MEMORY;
219 return template_fill_for_cgi(csp, "default", exports, rsp);
225 /*********************************************************************
227 * Function : cgi_error_404
229 * Description : CGI function that is called if an unknown action was
233 * 1 : csp = Current client state (buffers, headers, etc...)
234 * 2 : rsp = http_response data structure for output
235 * 3 : parameters = map of cgi parameters
237 * CGI Parameters : none
239 * Returns : JB_ERR_OK on success
240 * JB_ERR_MEMORY on out-of-memory error.
242 *********************************************************************/
243 jb_err cgi_error_404(struct client_state *csp,
244 struct http_response *rsp,
245 const struct map *parameters)
253 if (NULL == (exports = default_exports(csp, NULL)))
255 return JB_ERR_MEMORY;
258 rsp->status = strdup("404 Privoxy configuration page not found");
259 if (rsp->status == NULL)
262 return JB_ERR_MEMORY;
265 return template_fill_for_cgi(csp, "cgi-error-404", exports, rsp);
269 #ifdef FEATURE_GRACEFUL_TERMINATION
270 /*********************************************************************
274 * Description : CGI function to shut down Privoxy.
275 * NOTE: Turning this on in a production build
276 * would be a BAD idea. An EXTREMELY BAD idea.
277 * In short, don't do it.
280 * 1 : csp = Current client state (buffers, headers, etc...)
281 * 2 : rsp = http_response data structure for output
282 * 3 : parameters = map of cgi parameters
284 * CGI Parameters : none
286 * Returns : JB_ERR_OK on success
287 * JB_ERR_MEMORY on out-of-memory error.
289 *********************************************************************/
290 jb_err cgi_die (struct client_state *csp,
291 struct http_response *rsp,
292 const struct map *parameters)
302 * I don't really care what gets sent back to the browser.
303 * Take the easy option - "out of memory" page.
306 return JB_ERR_MEMORY;
308 #endif /* def FEATURE_GRACEFUL_TERMINATION */
311 /*********************************************************************
313 * Function : cgi_show_request
315 * Description : Show the client's request and what sed() would have
319 * 1 : csp = Current client state (buffers, headers, etc...)
320 * 2 : rsp = http_response data structure for output
321 * 3 : parameters = map of cgi parameters
323 * CGI Parameters : none
325 * Returns : JB_ERR_OK on success
326 * JB_ERR_MEMORY on out-of-memory error.
328 *********************************************************************/
329 jb_err cgi_show_request(struct client_state *csp,
330 struct http_response *rsp,
331 const struct map *parameters)
340 if (NULL == (exports = default_exports(csp, "show-request")))
342 return JB_ERR_MEMORY;
346 * Repair the damage done to the IOB by get_header()
348 for (p = csp->iob->buf; p < csp->iob->eod; p++)
350 if (*p == '\0') *p = '\n';
354 * Export the original client's request and the one we would
355 * be sending to the server if this wasn't a CGI call
358 if (map(exports, "client-request", 1, html_encode(csp->iob->buf), 0))
361 return JB_ERR_MEMORY;
364 if (map(exports, "processed-request", 1, html_encode_and_free_original(
365 sed(client_patterns, add_client_headers, csp)), 0))
368 return JB_ERR_MEMORY;
371 return template_fill_for_cgi(csp, "show-request", exports, rsp);
375 /*********************************************************************
377 * Function : cgi_send_banner
379 * Description : CGI function that returns a banner.
382 * 1 : csp = Current client state (buffers, headers, etc...)
383 * 2 : rsp = http_response data structure for output
384 * 3 : parameters = map of cgi parameters
387 * type : Selects the type of banner between "trans", "logo",
388 * and "auto". Defaults to "logo" if absent or invalid.
389 * "auto" means to select as if we were image-blocking.
390 * (Only the first character really counts).
392 * Returns : JB_ERR_OK on success
393 * JB_ERR_MEMORY on out-of-memory error.
395 *********************************************************************/
396 jb_err cgi_send_banner(struct client_state *csp,
397 struct http_response *rsp,
398 const struct map *parameters)
400 char imagetype = lookup(parameters, "type")[0];
402 if (imagetype == 'a') /* auto */
404 /* Default to logo */
406 #ifdef FEATURE_IMAGE_BLOCKING
407 if ((csp->action->flags & ACTION_IMAGE_BLOCKER) != 0)
409 /* determine HOW images should be blocked */
410 const char * p = csp->action->string[ACTION_STRING_IMAGE_BLOCKER];
412 /* and handle accordingly: */
413 if ((p != NULL) && (0 == strcmpic(p, "blank")))
417 else if ((p != NULL) && (0 == strcmpic(p, "pattern")))
422 #endif /* def FEATURE_IMAGE_BLOCKING */
425 if ((imagetype == 'b') || (imagetype == 't')) /* blank / transparent */
427 rsp->body = bindup(image_blank_data, image_blank_length);
428 rsp->content_length = image_blank_length;
431 else if (imagetype == 'l') /* logo */
433 rsp->body = bindup(image_logo_data, image_logo_length);
434 rsp->content_length = image_logo_length;
438 rsp->body = bindup(image_pattern_data, image_pattern_length);
439 rsp->content_length = image_pattern_length;
442 if (rsp->body == NULL)
444 return JB_ERR_MEMORY;
447 if (enlist(rsp->headers, "Content-Type: " BUILTIN_IMAGE_MIMETYPE))
449 return JB_ERR_MEMORY;
459 /*********************************************************************
461 * Function : cgi_transparent_image
463 * Description : CGI function that sends a 1x1 transparent image.
466 * 1 : csp = Current client state (buffers, headers, etc...)
467 * 2 : rsp = http_response data structure for output
468 * 3 : parameters = map of cgi parameters
470 * CGI Parameters : None
472 * Returns : JB_ERR_OK on success
473 * JB_ERR_MEMORY on out-of-memory error.
475 *********************************************************************/
476 jb_err cgi_transparent_image(struct client_state *csp,
477 struct http_response *rsp,
478 const struct map *parameters)
480 rsp->body = bindup(image_blank_data, image_blank_length);
481 rsp->content_length = image_blank_length;
483 if (rsp->body == NULL)
485 return JB_ERR_MEMORY;
488 if (enlist(rsp->headers, "Content-Type: " BUILTIN_IMAGE_MIMETYPE))
490 return JB_ERR_MEMORY;
500 /*********************************************************************
502 * Function : cgi_show_version
504 * Description : CGI function that returns a a web page describing the
505 * file versions of Privoxy.
508 * 1 : csp = Current client state (buffers, headers, etc...)
509 * 2 : rsp = http_response data structure for output
510 * 3 : parameters = map of cgi parameters
512 * CGI Parameters : none
514 * Returns : JB_ERR_OK on success
515 * JB_ERR_MEMORY on out-of-memory error.
517 *********************************************************************/
518 jb_err cgi_show_version(struct client_state *csp,
519 struct http_response *rsp,
520 const struct map *parameters)
528 if (NULL == (exports = default_exports(csp, "show-version")))
530 return JB_ERR_MEMORY;
533 if (map(exports, "sourceversions", 1, show_rcs(), 0))
536 return JB_ERR_MEMORY;
539 return template_fill_for_cgi(csp, "show-version", exports, rsp);
543 /*********************************************************************
545 * Function : cgi_show_status
547 * Description : CGI function that returns a a web page describing the
548 * current status of Privoxy.
551 * 1 : csp = Current client state (buffers, headers, etc...)
552 * 2 : rsp = http_response data structure for output
553 * 3 : parameters = map of cgi parameters
556 * file : Which file to show. Only first letter is checked,
558 * - "p"ermissions (actions) file
561 * Default is to show menu and other information.
563 * Returns : JB_ERR_OK on success
564 * JB_ERR_MEMORY on out-of-memory error.
566 *********************************************************************/
567 jb_err cgi_show_status(struct client_state *csp,
568 struct http_response *rsp,
569 const struct map *parameters)
575 char buf[BUFFER_SIZE];
576 const char * filename = NULL;
577 char * file_description = NULL;
578 #ifdef FEATURE_STATISTICS
579 float perc_rej; /* Percentage of http requests rejected */
581 int local_urls_rejected;
582 #endif /* ndef FEATURE_STATISTICS */
591 if (NULL == (exports = default_exports(csp, "show-status")))
593 return JB_ERR_MEMORY;
596 switch (*(lookup(parameters, "file")))
599 if (csp->actions_list)
601 filename = csp->actions_list->filename;
602 file_description = "Actions List";
609 filename = csp->rlist->filename;
610 file_description = "Regex Filter List";
618 filename = csp->tlist->filename;
619 file_description = "Trust List";
622 #endif /* def FEATURE_TRUST */
625 if (NULL != filename)
627 if ( map(exports, "file-description", 1, file_description, 1)
628 || map(exports, "filepath", 1, html_encode(filename), 0) )
631 return JB_ERR_MEMORY;
634 if ((fp = fopen(filename, "r")) == NULL)
636 if (map(exports, "content", 1, "<h1>ERROR OPENING FILE!</h1>", 1))
639 return JB_ERR_MEMORY;
645 while ((s != NULL) && fgets(buf, sizeof(buf), fp))
647 string_join (&s, html_encode(buf));
648 string_append(&s, "<br>");
652 if (map(exports, "contents", 1, s, 0))
655 return JB_ERR_MEMORY;
659 return template_fill_for_cgi(csp, "show-status-file", exports, rsp);
662 if (map(exports, "redirect-url", 1, html_encode(REDIRECT_URL), 0))
665 return JB_ERR_MEMORY;
669 for (i = 0; (s != NULL) && (i < Argc); i++)
671 string_join (&s, html_encode(Argv[i]));
672 string_append(&s, " ");
674 if (map(exports, "invocation", 1, s, 0))
677 return JB_ERR_MEMORY;
680 err = map(exports, "options", 1, csp->config->proxy_args, 1);
681 if (!err) err = show_defines(exports);
683 #ifdef FEATURE_STATISTICS
684 local_urls_read = urls_read;
685 local_urls_rejected = urls_rejected;
688 * Need to alter the stats not to include the fetch of this
691 * Can't do following thread safely! doh!
694 * urls_rejected--; * This will be incremented subsequently *
697 if (local_urls_read == 0)
699 if (!err) err = map_block_killer(exports, "have-stats");
703 if (!err) err = map_block_killer(exports, "have-no-stats");
705 perc_rej = (float)local_urls_rejected * 100.0F /
706 (float)local_urls_read;
708 sprintf(buf, "%d", local_urls_read);
709 if (!err) err = map(exports, "requests-received", 1, buf, 1);
711 sprintf(buf, "%d", local_urls_rejected);
712 if (!err) err = map(exports, "requests-blocked", 1, buf, 1);
714 sprintf(buf, "%6.2f", perc_rej);
715 if (!err) err = map(exports, "percent-blocked", 1, buf, 1);
718 #else /* ndef FEATURE_STATISTICS */
719 err = err || map_block_killer(exports, "statistics");
720 #endif /* ndef FEATURE_STATISTICS */
722 if (csp->actions_list)
724 if (!err) err = map(exports, "actions-filename", 1, html_encode(csp->actions_list->filename), 0);
728 if (!err) err = map(exports, "actions-filename", 1, "None specified", 1);
733 if (!err) err = map(exports, "re-filter-filename", 1, html_encode(csp->rlist->filename), 0);
737 if (!err) err = map(exports, "re-filter-filename", 1, "None specified", 1);
743 if (!err) err = map(exports, "trust-filename", 1, html_encode(csp->tlist->filename), 0);
747 if (!err) err = map(exports, "trust-filename", 1, "None specified", 1);
750 if (!err) err = map_block_killer(exports, "trust-support");
751 #endif /* ndef FEATURE_TRUST */
756 return JB_ERR_MEMORY;
759 return template_fill_for_cgi(csp, "show-status", exports, rsp);
763 /*********************************************************************
765 * Function : cgi_show_url_info
767 * Description : CGI function that determines and shows which actions
768 * Privoxy will perform for a given url, and which
769 * matches starting from the defaults have lead to that.
772 * 1 : csp = Current client state (buffers, headers, etc...)
773 * 2 : rsp = http_response data structure for output
774 * 3 : parameters = map of cgi parameters
777 * url : The url whose actions are to be determined.
778 * If url is unset, the url-given conditional will be
779 * set, so that all but the form can be suppressed in
782 * Returns : JB_ERR_OK on success
783 * JB_ERR_MEMORY on out-of-memory error.
785 *********************************************************************/
786 jb_err cgi_show_url_info(struct client_state *csp,
787 struct http_response *rsp,
788 const struct map *parameters)
797 if (NULL == (exports = default_exports(csp, "show-url-info")))
799 return JB_ERR_MEMORY;
803 * Get the url= parameter (if present) and remove any leading/trailing spaces.
805 url_param = strdup(lookup(parameters, "url"));
806 if (url_param == NULL)
809 return JB_ERR_MEMORY;
814 * Handle prefixes. 4 possibilities:
815 * 1) "http://" or "https://" prefix present and followed by URL - OK
816 * 2) Only the "http://" or "https://" part is present, no URL - change
817 * to empty string so it will be detected later as "no URL".
818 * 3) Parameter specified but doesn't contain "http(s?)://" - add a
820 * 4) Parameter not specified or is empty string - let this fall through
821 * for now, next block of code will handle it.
823 if (0 == strncmp(url_param, "http://", 7))
825 if (url_param[7] == '\0')
828 * Empty URL (just prefix).
829 * Make it totally empty so it's caught by the next if()
834 else if (0 == strncmp(url_param, "https://", 8))
836 if (url_param[8] == '\0')
839 * Empty URL (just prefix).
840 * Make it totally empty so it's caught by the next if()
845 else if (url_param[0] != '\0')
848 * Unknown prefix - assume http://
850 char * url_param_prefixed = malloc(7 + 1 + strlen(url_param));
851 if (NULL == url_param_prefixed)
855 return JB_ERR_MEMORY;
857 strcpy(url_param_prefixed, "http://");
858 strcpy(url_param_prefixed + 7, url_param);
860 url_param = url_param_prefixed;
864 if (url_param[0] == '\0')
866 /* URL paramater not specified, display query form only. */
868 if (map_block_killer(exports, "url-given")
869 || map(exports, "url", 1, "", 1))
872 return JB_ERR_MEMORY;
877 /* Given a URL, so query it. */
882 struct file_list *fl;
883 struct url_actions *b;
884 struct http_request url_to_query[1];
885 struct current_action_spec action[1];
887 if (map(exports, "url", 1, html_encode(url_param), 0))
891 return JB_ERR_MEMORY;
894 init_current_action(action);
896 if (map(exports, "default", 1, html_encode_and_free_original(
897 current_action_to_text(action)), 0))
899 free_current_action(action);
902 return JB_ERR_MEMORY;
905 if (((fl = csp->actions_list) == NULL) || ((b = fl->f) == NULL))
907 err = map(exports, "matches", 1, "none" , 1);
908 if (!err) err = map(exports, "final", 1, lookup(exports, "default"), 1);
910 free_current_action(action);
916 return JB_ERR_MEMORY;
919 return template_fill_for_cgi(csp, "show-url-info", exports, rsp);
922 err = parse_http_url(url_param, url_to_query, csp);
926 if (err == JB_ERR_MEMORY)
928 free_current_action(action);
930 return JB_ERR_MEMORY;
936 err = map(exports, "matches", 1, "<b>[Invalid URL specified!]</b>" , 1);
937 if (!err) err = map(exports, "final", 1, lookup(exports, "default"), 1);
939 free_current_action(action);
944 return JB_ERR_MEMORY;
947 return template_fill_for_cgi(csp, "show-url-info", exports, rsp);
951 * We have a warning about SSL paths. Hide it for insecure sites.
953 if (!url_to_query->ssl)
955 if (map_block_killer(exports, "https"))
957 free_current_action(action);
959 return JB_ERR_MEMORY;
963 matches = strdup("");
965 for (b = b->next; (b != NULL) && (matches != NULL); b = b->next)
967 if (url_match(b->url, url_to_query))
969 string_append(&matches, "<b>{");
970 string_join (&matches, html_encode_and_free_original(
971 actions_to_text(b->action)));
972 string_append(&matches, " }</b><br>\n<code>");
973 string_join (&matches, html_encode(b->url->spec));
974 string_append(&matches, "</code><br>\n<br>\n");
976 if (merge_current_action(action, b->action))
979 free_http_request(url_to_query);
980 free_current_action(action);
982 return JB_ERR_MEMORY;
988 free_http_request(url_to_query);
992 free_current_action(action);
994 return JB_ERR_MEMORY;
1000 matches = strdup("none");
1002 if (map(exports, "matches", 1, matches , 0))
1004 free_current_action(action);
1006 return JB_ERR_MEMORY;
1009 s = html_encode_and_free_original(current_action_to_text(action));
1011 free_current_action(action);
1013 if (map(exports, "final", 1, s, 0))
1016 return JB_ERR_MEMORY;
1020 return template_fill_for_cgi(csp, "show-url-info", exports, rsp);
1024 /*********************************************************************
1026 * Function : cgi_robots_txt
1028 * Description : CGI function to return "/robots.txt".
1031 * 1 : csp = Current client state (buffers, headers, etc...)
1032 * 2 : rsp = http_response data structure for output
1033 * 3 : parameters = map of cgi parameters
1035 * CGI Parameters : None
1037 * Returns : JB_ERR_OK on success
1038 * JB_ERR_MEMORY on out-of-memory error.
1040 *********************************************************************/
1041 jb_err cgi_robots_txt(struct client_state *csp,
1042 struct http_response *rsp,
1043 const struct map *parameters)
1049 "# This is the Privoxy control interface.\n"
1050 "# It isn't very useful to index it, and you're likely to break stuff.\n"
1056 if (rsp->body == NULL)
1058 return JB_ERR_MEMORY;
1061 err = enlist_unique(rsp->headers, "Content-Type: text/plain", 13);
1065 get_http_time(7 * 24 * 60 * 60, buf); /* 7 days into future */
1066 if (!err) err = enlist_unique_header(rsp->headers, "Expires", buf);
1068 return (err ? JB_ERR_MEMORY : JB_ERR_OK);
1072 /*********************************************************************
1074 * Function : show_defines
1076 * Description : Add to a map the state od all conditional #defines
1077 * used when building
1080 * 1 : exports = map to extend
1082 * Returns : JB_ERR_OK on success
1083 * JB_ERR_MEMORY on out-of-memory error.
1085 *********************************************************************/
1086 static jb_err show_defines(struct map *exports)
1088 jb_err err = JB_ERR_OK;
1091 if (!err) err = map_conditional(exports, "FEATURE_ACL", 1);
1092 #else /* ifndef FEATURE_ACL */
1093 if (!err) err = map_conditional(exports, "FEATURE_ACL", 0);
1094 #endif /* ndef FEATURE_ACL */
1096 #ifdef FEATURE_CGI_EDIT_ACTIONS
1097 if (!err) err = map_conditional(exports, "FEATURE_CGI_EDIT_ACTIONS", 1);
1098 #else /* ifndef FEATURE_COOKIE_JAR */
1099 if (!err) err = map_conditional(exports, "FEATURE_CGI_EDIT_ACTIONS", 0);
1100 #endif /* ndef FEATURE_COOKIE_JAR */
1102 #ifdef FEATURE_COOKIE_JAR
1103 if (!err) err = map_conditional(exports, "FEATURE_COOKIE_JAR", 1);
1104 #else /* ifndef FEATURE_COOKIE_JAR */
1105 if (!err) err = map_conditional(exports, "FEATURE_COOKIE_JAR", 0);
1106 #endif /* ndef FEATURE_COOKIE_JAR */
1108 #ifdef FEATURE_FAST_REDIRECTS
1109 if (!err) err = map_conditional(exports, "FEATURE_FAST_REDIRECTS", 1);
1110 #else /* ifndef FEATURE_FAST_REDIRECTS */
1111 if (!err) err = map_conditional(exports, "FEATURE_FAST_REDIRECTS", 0);
1112 #endif /* ndef FEATURE_FAST_REDIRECTS */
1114 #ifdef FEATURE_FORCE_LOAD
1115 if (!err) err = map_conditional(exports, "FEATURE_FORCE_LOAD", 1);
1116 #else /* ifndef FEATURE_FORCE_LOAD */
1117 if (!err) err = map_conditional(exports, "FEATURE_FORCE_LOAD", 0);
1118 #endif /* ndef FEATURE_FORCE_LOAD */
1120 #ifdef FEATURE_IMAGE_BLOCKING
1121 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_BLOCKING", 1);
1122 #else /* ifndef FEATURE_IMAGE_BLOCKING */
1123 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_BLOCKING", 0);
1124 #endif /* ndef FEATURE_IMAGE_BLOCKING */
1126 #ifdef FEATURE_IMAGE_DETECT_MSIE
1127 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_DETECT_MSIE", 1);
1128 #else /* ifndef FEATURE_IMAGE_DETECT_MSIE */
1129 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_DETECT_MSIE", 0);
1130 #endif /* ndef FEATURE_IMAGE_DETECT_MSIE */
1132 #ifdef FEATURE_KILL_POPUPS
1133 if (!err) err = map_conditional(exports, "FEATURE_KILL_POPUPS", 1);
1134 #else /* ifndef FEATURE_KILL_POPUPS */
1135 if (!err) err = map_conditional(exports, "FEATURE_KILL_POPUPS", 0);
1136 #endif /* ndef FEATURE_KILL_POPUPS */
1138 #ifdef FEATURE_NO_GIFS
1139 if (!err) err = map_conditional(exports, "FEATURE_NO_GIFS", 1);
1140 #else /* ifndef FEATURE_NO_GIFS */
1141 if (!err) err = map_conditional(exports, "FEATURE_NO_GIFS", 0);
1142 #endif /* ndef FEATURE_NO_GIFS */
1144 #ifdef FEATURE_PTHREAD
1145 if (!err) err = map_conditional(exports, "FEATURE_PTHREAD", 1);
1146 #else /* ifndef FEATURE_PTHREAD */
1147 if (!err) err = map_conditional(exports, "FEATURE_PTHREAD", 0);
1148 #endif /* ndef FEATURE_PTHREAD */
1150 #ifdef FEATURE_STATISTICS
1151 if (!err) err = map_conditional(exports, "FEATURE_STATISTICS", 1);
1152 #else /* ifndef FEATURE_STATISTICS */
1153 if (!err) err = map_conditional(exports, "FEATURE_STATISTICS", 0);
1154 #endif /* ndef FEATURE_STATISTICS */
1156 #ifdef FEATURE_TOGGLE
1157 if (!err) err = map_conditional(exports, "FEATURE_TOGGLE", 1);
1158 #else /* ifndef FEATURE_TOGGLE */
1159 if (!err) err = map_conditional(exports, "FEATURE_TOGGLE", 0);
1160 #endif /* ndef FEATURE_TOGGLE */
1162 #ifdef FEATURE_TRUST
1163 if (!err) err = map_conditional(exports, "FEATURE_TRUST", 1);
1164 #else /* ifndef FEATURE_TRUST */
1165 if (!err) err = map_conditional(exports, "FEATURE_TRUST", 0);
1166 #endif /* ndef FEATURE_TRUST */
1169 if (!err) err = map_conditional(exports, "REGEX_GNU", 1);
1170 #else /* ifndef REGEX_GNU */
1171 if (!err) err = map_conditional(exports, "REGEX_GNU", 0);
1172 #endif /* def REGEX_GNU */
1175 if (!err) err = map_conditional(exports, "REGEX_PCRE", 1);
1176 #else /* ifndef REGEX_PCRE */
1177 if (!err) err = map_conditional(exports, "REGEX_PCRE", 0);
1178 #endif /* def REGEX_PCRE */
1181 if (!err) err = map_conditional(exports, "STATIC_PCRE", 1);
1182 #else /* ifndef STATIC_PCRE */
1183 if (!err) err = map_conditional(exports, "STATIC_PCRE", 0);
1184 #endif /* ndef STATIC_PCRE */
1187 if (!err) err = map_conditional(exports, "STATIC_PCRS", 1);
1188 #else /* ifndef STATIC_PCRS */
1189 if (!err) err = map_conditional(exports, "STATIC_PCRS", 0);
1190 #endif /* ndef STATIC_PCRS */
1192 if (!err) err = map(exports, "FORCE_PREFIX", 1, FORCE_PREFIX, 1);
1198 /*********************************************************************
1200 * Function : show_rcs
1202 * Description : Create a string with the rcs info for all sourcefiles
1206 * Returns : A string, or NULL on out-of-memory.
1208 *********************************************************************/
1209 static char *show_rcs(void)
1211 char *result = strdup("");
1212 char buf[BUFFER_SIZE];
1214 /* Instead of including *all* dot h's in the project (thus creating a
1215 * tremendous amount of dependencies), I will concede to declaring them
1216 * as extern's. This forces the developer to add to this list, but oh well.
1219 #define SHOW_RCS(__x) \
1221 extern const char __x[]; \
1222 sprintf(buf, "%s\n", __x); \
1223 string_append(&result, buf); \
1226 /* In alphabetical order */
1227 SHOW_RCS(actions_h_rcs)
1228 SHOW_RCS(actions_rcs)
1231 #ifdef FEATURE_CGI_EDIT_ACTIONS
1232 SHOW_RCS(cgiedit_h_rcs)
1233 SHOW_RCS(cgiedit_rcs)
1234 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1235 SHOW_RCS(cgisimple_h_rcs)
1236 SHOW_RCS(cgisimple_rcs)
1238 SHOW_RCS(cygwin_h_rcs)
1240 SHOW_RCS(deanimate_h_rcs)
1241 SHOW_RCS(deanimate_rcs)
1242 SHOW_RCS(encode_h_rcs)
1243 SHOW_RCS(encode_rcs)
1244 SHOW_RCS(errlog_h_rcs)
1245 SHOW_RCS(errlog_rcs)
1246 SHOW_RCS(filters_h_rcs)
1247 SHOW_RCS(filters_rcs)
1248 SHOW_RCS(gateway_h_rcs)
1249 SHOW_RCS(gateway_rcs)
1251 SHOW_RCS(gnu_regex_h_rcs)
1252 SHOW_RCS(gnu_regex_rcs)
1253 #endif /* def GNU_REGEX */
1254 SHOW_RCS(jbsockets_h_rcs)
1255 SHOW_RCS(jbsockets_rcs)
1258 #ifdef FEATURE_KILL_POPUPS
1259 SHOW_RCS(killpopup_h_rcs)
1260 SHOW_RCS(killpopup_rcs)
1261 #endif /* def FEATURE_KILL_POPUPS */
1262 SHOW_RCS(list_h_rcs)
1264 SHOW_RCS(loadcfg_h_rcs)
1265 SHOW_RCS(loadcfg_rcs)
1266 SHOW_RCS(loaders_h_rcs)
1267 SHOW_RCS(loaders_rcs)
1268 SHOW_RCS(miscutil_h_rcs)
1269 SHOW_RCS(miscutil_rcs)
1270 SHOW_RCS(parsers_h_rcs)
1271 SHOW_RCS(parsers_rcs)
1273 SHOW_RCS(pcrs_h_rcs)
1274 SHOW_RCS(project_h_rcs)
1275 SHOW_RCS(ssplit_h_rcs)
1276 SHOW_RCS(ssplit_rcs)
1277 SHOW_RCS(urlmatch_h_rcs)
1278 SHOW_RCS(urlmatch_rcs)
1280 #ifndef _WIN_CONSOLE
1281 SHOW_RCS(w32log_h_rcs)
1282 SHOW_RCS(w32log_rcs)
1283 SHOW_RCS(w32res_h_rcs)
1284 SHOW_RCS(w32taskbar_h_rcs)
1285 SHOW_RCS(w32taskbar_rcs)
1286 #endif /* ndef _WIN_CONSOLE */
1287 SHOW_RCS(win32_h_rcs)
1289 #endif /* def _WIN32 */