1 const char cgisimple_rcs[] = "$Id: cgisimple.c,v 1.26 2002/04/04 00:36:36 gliptak 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.26 2002/04/04 00:36:36 gliptak
40 * always use pcre for matching
42 * Revision 1.25 2002/04/03 22:28:03 gliptak
43 * Removed references to gnu_regex
45 * Revision 1.24 2002/04/02 16:12:47 oes
46 * Fix: moving misplaced lines into #ifdef FEATURE_FORCE
48 * Revision 1.23 2002/03/26 22:29:54 swa
49 * we have a new homepage!
51 * Revision 1.22 2002/03/24 16:18:15 jongfoster
54 * Revision 1.21 2002/03/24 15:23:33 jongfoster
57 * Revision 1.20 2002/03/24 13:25:43 swa
58 * name change related issues
60 * Revision 1.19 2002/03/16 23:54:06 jongfoster
61 * Adding graceful termination feature, to help look for memory leaks.
62 * If you enable this (which, by design, has to be done by hand
63 * editing config.h) and then go to http://i.j.b/die, then the program
64 * will exit cleanly after the *next* request. It should free all the
65 * memory that was used.
67 * Revision 1.18 2002/03/12 01:44:49 oes
68 * Changed default for "blocked" image from jb logo to checkboard pattern
70 * Revision 1.17 2002/03/08 16:43:18 oes
71 * Added choice beween GIF and PNG built-in images
73 * Revision 1.16 2002/03/07 03:48:38 oes
74 * - Changed built-in images from GIF to PNG
75 * (with regard to Unisys patent issue)
76 * - Added a 4x4 pattern PNG which is less intrusive
77 * than the logo but also clearly marks the deleted banners
79 * Revision 1.15 2002/03/06 22:54:35 jongfoster
80 * Automated function-comment nitpicking.
82 * Revision 1.14 2002/03/02 04:14:50 david__schmidt
83 * Clean up a little CRLF unpleasantness that suddenly appeared
85 * Revision 1.13 2002/02/21 00:10:37 jongfoster
86 * Adding send-banner?type=auto option
88 * Revision 1.12 2002/01/23 01:03:32 jongfoster
89 * Fixing gcc [CygWin] compiler warnings
91 * Revision 1.11 2002/01/23 00:01:04 jongfoster
92 * Adding cgi_transparent_gif() for http://i.j.b/t
93 * Adding missing html_encode() to many CGI functions.
94 * Adding urlmatch.[ch] to http://i.j.b/show-version
96 * Revision 1.10 2002/01/17 21:10:37 jongfoster
97 * Changes to cgi_show_url_info to use new matching code from urlmatch.c.
98 * Also fixing a problem in the same function with improperly quoted URLs
99 * in output HTML, and adding code to handle https:// URLs correctly.
101 * Revision 1.9 2001/11/30 23:09:15 jongfoster
102 * Now reports on FEATURE_CGI_EDIT_ACTIONS
103 * Removing FEATURE_DENY_GZIP from template
105 * Revision 1.8 2001/11/13 00:14:07 jongfoster
106 * Fixing stupid bug now I've figured out what || means.
107 * (It always returns 0 or 1, not one of it's paramaters.)
109 * Revision 1.7 2001/10/23 21:48:19 jongfoster
110 * Cleaning up error handling in CGI functions - they now send back
111 * a HTML error page and should never cause a FATAL error. (Fixes one
112 * potential source of "denial of service" attacks).
114 * CGI actions file editor that works and is actually useful.
116 * Ability to toggle JunkBuster remotely using a CGI call.
118 * You can turn off both the above features in the main configuration
119 * file, e.g. if you are running a multi-user proxy.
121 * Revision 1.6 2001/10/14 22:00:32 jongfoster
122 * Adding support for a 404 error when an invalid CGI page is requested.
124 * Revision 1.5 2001/10/07 15:30:41 oes
125 * Removed FEATURE_DENY_GZIP
127 * Revision 1.4 2001/10/02 15:31:12 oes
128 * Introduced show-request cgi
130 * Revision 1.3 2001/09/22 16:34:44 jongfoster
131 * Removing unneeded #includes
133 * Revision 1.2 2001/09/19 18:01:11 oes
134 * Fixed comments; cosmetics
136 * Revision 1.1 2001/09/16 17:08:54 jongfoster
137 * Moving simple CGI functions from cgi.c to new file cgisimple.c
140 **********************************************************************/
146 #include <sys/types.h>
153 #define snprintf _snprintf
154 #endif /* def _WIN32 */
158 #include "cgisimple.h"
164 #include "miscutil.h"
167 #include "urlmatch.h"
170 const char cgisimple_h_rcs[] = CGISIMPLE_H_VERSION;
173 static char *show_rcs(void);
174 static jb_err show_defines(struct map *exports);
177 /*********************************************************************
179 * Function : cgi_default
181 * Description : CGI function that is called if no action was given.
182 * Lists menu of available unhidden CGIs.
185 * 1 : csp = Current client state (buffers, headers, etc...)
186 * 2 : rsp = http_response data structure for output
187 * 3 : parameters = map of cgi parameters
189 * CGI Parameters : none
191 * Returns : JB_ERR_OK on success
192 * JB_ERR_MEMORY on out-of-memory
193 * (Problems other than out-of-memory should be
194 * handled by this routine - it should set the
195 * rsp appropriately and return "success")
197 *********************************************************************/
198 jb_err cgi_default(struct client_state *csp,
199 struct http_response *rsp,
200 const struct map *parameters)
209 if (NULL == (exports = default_exports(csp, "")))
211 return JB_ERR_MEMORY;
214 /* If there were other parameters, export a dump as "cgi-parameters" */
215 if (parameters->first)
217 tmp = strdup("<p>What made you think this cgi takes parameters?\n"
218 "Anyway, here they are, in case you're interested:</p>\n");
219 string_join(&tmp, dump_map(parameters));
223 return JB_ERR_MEMORY;
225 if (map(exports, "cgi-parameters", 1, tmp, 0))
227 return JB_ERR_MEMORY;
232 if (map(exports, "cgi-parameters", 1, "", 1))
234 return JB_ERR_MEMORY;
238 return template_fill_for_cgi(csp, "default", exports, rsp);
244 /*********************************************************************
246 * Function : cgi_error_404
248 * Description : CGI function that is called if an unknown action was
252 * 1 : csp = Current client state (buffers, headers, etc...)
253 * 2 : rsp = http_response data structure for output
254 * 3 : parameters = map of cgi parameters
256 * CGI Parameters : none
258 * Returns : JB_ERR_OK on success
259 * JB_ERR_MEMORY on out-of-memory error.
261 *********************************************************************/
262 jb_err cgi_error_404(struct client_state *csp,
263 struct http_response *rsp,
264 const struct map *parameters)
272 if (NULL == (exports = default_exports(csp, NULL)))
274 return JB_ERR_MEMORY;
277 rsp->status = strdup("404 Privoxy configuration page not found");
278 if (rsp->status == NULL)
281 return JB_ERR_MEMORY;
284 return template_fill_for_cgi(csp, "cgi-error-404", exports, rsp);
288 #ifdef FEATURE_GRACEFUL_TERMINATION
289 /*********************************************************************
293 * Description : CGI function to shut down Privoxy.
294 * NOTE: Turning this on in a production build
295 * would be a BAD idea. An EXTREMELY BAD idea.
296 * In short, don't do it.
299 * 1 : csp = Current client state (buffers, headers, etc...)
300 * 2 : rsp = http_response data structure for output
301 * 3 : parameters = map of cgi parameters
303 * CGI Parameters : none
305 * Returns : JB_ERR_OK on success
306 * JB_ERR_MEMORY on out-of-memory error.
308 *********************************************************************/
309 jb_err cgi_die (struct client_state *csp,
310 struct http_response *rsp,
311 const struct map *parameters)
321 * I don't really care what gets sent back to the browser.
322 * Take the easy option - "out of memory" page.
325 return JB_ERR_MEMORY;
327 #endif /* def FEATURE_GRACEFUL_TERMINATION */
330 /*********************************************************************
332 * Function : cgi_show_request
334 * Description : Show the client's request and what sed() would have
338 * 1 : csp = Current client state (buffers, headers, etc...)
339 * 2 : rsp = http_response data structure for output
340 * 3 : parameters = map of cgi parameters
342 * CGI Parameters : none
344 * Returns : JB_ERR_OK on success
345 * JB_ERR_MEMORY on out-of-memory error.
347 *********************************************************************/
348 jb_err cgi_show_request(struct client_state *csp,
349 struct http_response *rsp,
350 const struct map *parameters)
359 if (NULL == (exports = default_exports(csp, "show-request")))
361 return JB_ERR_MEMORY;
365 * Repair the damage done to the IOB by get_header()
367 for (p = csp->iob->buf; p < csp->iob->eod; p++)
369 if (*p == '\0') *p = '\n';
373 * Export the original client's request and the one we would
374 * be sending to the server if this wasn't a CGI call
377 if (map(exports, "client-request", 1, html_encode(csp->iob->buf), 0))
380 return JB_ERR_MEMORY;
383 if (map(exports, "processed-request", 1, html_encode_and_free_original(
384 sed(client_patterns, add_client_headers, csp)), 0))
387 return JB_ERR_MEMORY;
390 return template_fill_for_cgi(csp, "show-request", exports, rsp);
394 /*********************************************************************
396 * Function : cgi_send_banner
398 * Description : CGI function that returns a banner.
401 * 1 : csp = Current client state (buffers, headers, etc...)
402 * 2 : rsp = http_response data structure for output
403 * 3 : parameters = map of cgi parameters
406 * type : Selects the type of banner between "trans", "logo",
407 * and "auto". Defaults to "logo" if absent or invalid.
408 * "auto" means to select as if we were image-blocking.
409 * (Only the first character really counts).
411 * Returns : JB_ERR_OK on success
412 * JB_ERR_MEMORY on out-of-memory error.
414 *********************************************************************/
415 jb_err cgi_send_banner(struct client_state *csp,
416 struct http_response *rsp,
417 const struct map *parameters)
419 char imagetype = lookup(parameters, "type")[0];
421 if (imagetype == 'a') /* auto */
423 /* Default to pattern */
425 #ifdef FEATURE_IMAGE_BLOCKING
426 if ((csp->action->flags & ACTION_IMAGE_BLOCKER) != 0)
428 /* determine HOW images should be blocked */
429 const char * p = csp->action->string[ACTION_STRING_IMAGE_BLOCKER];
431 /* and handle accordingly: */
432 if ((p != NULL) && (0 == strcmpic(p, "blank")))
436 else if ((p != NULL) && (0 == strcmpic(p, "pattern")))
441 #endif /* def FEATURE_IMAGE_BLOCKING */
444 if ((imagetype == 'b') || (imagetype == 't')) /* blank / transparent */
446 rsp->body = bindup(image_blank_data, image_blank_length);
447 rsp->content_length = image_blank_length;
452 rsp->body = bindup(image_pattern_data, image_pattern_length);
453 rsp->content_length = image_pattern_length;
456 if (rsp->body == NULL)
458 return JB_ERR_MEMORY;
461 if (enlist(rsp->headers, "Content-Type: " BUILTIN_IMAGE_MIMETYPE))
463 return JB_ERR_MEMORY;
473 /*********************************************************************
475 * Function : cgi_transparent_image
477 * Description : CGI function that sends a 1x1 transparent image.
480 * 1 : csp = Current client state (buffers, headers, etc...)
481 * 2 : rsp = http_response data structure for output
482 * 3 : parameters = map of cgi parameters
484 * CGI Parameters : None
486 * Returns : JB_ERR_OK on success
487 * JB_ERR_MEMORY on out-of-memory error.
489 *********************************************************************/
490 jb_err cgi_transparent_image(struct client_state *csp,
491 struct http_response *rsp,
492 const struct map *parameters)
494 rsp->body = bindup(image_blank_data, image_blank_length);
495 rsp->content_length = image_blank_length;
497 if (rsp->body == NULL)
499 return JB_ERR_MEMORY;
502 if (enlist(rsp->headers, "Content-Type: " BUILTIN_IMAGE_MIMETYPE))
504 return JB_ERR_MEMORY;
514 /*********************************************************************
516 * Function : cgi_send_stylesheet
518 * Description : CGI function that sends a css stylesheet found
519 * in the cgi-style.css template
522 * 1 : csp = Current client state (buffers, headers, etc...)
523 * 2 : rsp = http_response data structure for output
524 * 3 : parameters = map of cgi parameters
526 * CGI Parameters : None
528 * Returns : JB_ERR_OK on success
529 * JB_ERR_MEMORY on out-of-memory error.
531 *********************************************************************/
532 jb_err cgi_send_stylesheet(struct client_state *csp,
533 struct http_response *rsp,
534 const struct map *parameters)
541 err = template_load(csp, &rsp->body, "cgi-style.css");
543 if (err == JB_ERR_FILE)
546 * No way to tell user; send empty stylesheet
548 log_error(LOG_LEVEL_ERROR, "Could not find cgi-style.css template");
552 return err; /* JB_ERR_MEMORY */
555 if (enlist(rsp->headers, "Content-Type: text/css"))
557 return JB_ERR_MEMORY;
565 /*********************************************************************
567 * Function : cgi_show_version
569 * Description : CGI function that returns a a web page describing the
570 * file versions of Privoxy.
573 * 1 : csp = Current client state (buffers, headers, etc...)
574 * 2 : rsp = http_response data structure for output
575 * 3 : parameters = map of cgi parameters
577 * CGI Parameters : none
579 * Returns : JB_ERR_OK on success
580 * JB_ERR_MEMORY on out-of-memory error.
582 *********************************************************************/
583 jb_err cgi_show_version(struct client_state *csp,
584 struct http_response *rsp,
585 const struct map *parameters)
593 if (NULL == (exports = default_exports(csp, "show-version")))
595 return JB_ERR_MEMORY;
598 if (map(exports, "sourceversions", 1, show_rcs(), 0))
601 return JB_ERR_MEMORY;
604 return template_fill_for_cgi(csp, "show-version", exports, rsp);
608 /*********************************************************************
610 * Function : cgi_show_status
612 * Description : CGI function that returns a a web page describing the
613 * current status of Privoxy.
616 * 1 : csp = Current client state (buffers, headers, etc...)
617 * 2 : rsp = http_response data structure for output
618 * 3 : parameters = map of cgi parameters
621 * file : Which file to show. Only first letter is checked,
623 * - "p"ermissions (actions) file
626 * Default is to show menu and other information.
628 * Returns : JB_ERR_OK on success
629 * JB_ERR_MEMORY on out-of-memory error.
631 *********************************************************************/
632 jb_err cgi_show_status(struct client_state *csp,
633 struct http_response *rsp,
634 const struct map *parameters)
640 char buf[BUFFER_SIZE];
641 const char * filename = NULL;
642 char * file_description = NULL;
643 #ifdef FEATURE_STATISTICS
644 float perc_rej; /* Percentage of http requests rejected */
646 int local_urls_rejected;
647 #endif /* ndef FEATURE_STATISTICS */
656 if (NULL == (exports = default_exports(csp, "show-status")))
658 return JB_ERR_MEMORY;
661 switch (*(lookup(parameters, "file")))
664 if (csp->actions_list)
666 filename = csp->actions_list->filename;
667 file_description = "Actions List";
674 filename = csp->rlist->filename;
675 file_description = "Regex Filter List";
683 filename = csp->tlist->filename;
684 file_description = "Trust List";
687 #endif /* def FEATURE_TRUST */
690 if (NULL != filename)
692 if ( map(exports, "file-description", 1, file_description, 1)
693 || map(exports, "filepath", 1, html_encode(filename), 0) )
696 return JB_ERR_MEMORY;
699 if ((fp = fopen(filename, "r")) == NULL)
701 if (map(exports, "content", 1, "<h1>ERROR OPENING FILE!</h1>", 1))
704 return JB_ERR_MEMORY;
710 while ((s != NULL) && fgets(buf, sizeof(buf), fp))
712 string_join (&s, html_encode(buf));
716 if (map(exports, "contents", 1, s, 0))
719 return JB_ERR_MEMORY;
723 return template_fill_for_cgi(csp, "show-status-file", exports, rsp);
726 if (map(exports, "redirect-url", 1, html_encode(REDIRECT_URL), 0))
729 return JB_ERR_MEMORY;
733 for (i = 0; (s != NULL) && (i < Argc); i++)
735 string_join (&s, html_encode(Argv[i]));
736 string_append(&s, " ");
738 if (map(exports, "invocation", 1, s, 0))
741 return JB_ERR_MEMORY;
744 err = map(exports, "options", 1, csp->config->proxy_args, 1);
745 if (!err) err = show_defines(exports);
747 #ifdef FEATURE_STATISTICS
748 local_urls_read = urls_read;
749 local_urls_rejected = urls_rejected;
752 * Need to alter the stats not to include the fetch of this
755 * Can't do following thread safely! doh!
758 * urls_rejected--; * This will be incremented subsequently *
761 if (local_urls_read == 0)
763 if (!err) err = map_block_killer(exports, "have-stats");
767 if (!err) err = map_block_killer(exports, "have-no-stats");
769 perc_rej = (float)local_urls_rejected * 100.0F /
770 (float)local_urls_read;
772 sprintf(buf, "%d", local_urls_read);
773 if (!err) err = map(exports, "requests-received", 1, buf, 1);
775 sprintf(buf, "%d", local_urls_rejected);
776 if (!err) err = map(exports, "requests-blocked", 1, buf, 1);
778 sprintf(buf, "%6.2f", perc_rej);
779 if (!err) err = map(exports, "percent-blocked", 1, buf, 1);
782 #else /* ndef FEATURE_STATISTICS */
783 err = err || map_block_killer(exports, "statistics");
784 #endif /* ndef FEATURE_STATISTICS */
786 if (csp->actions_list)
788 if (!err) err = map(exports, "actions-filename", 1, html_encode(csp->actions_list->filename), 0);
792 if (!err) err = map(exports, "actions-filename", 1, "None specified", 1);
797 if (!err) err = map(exports, "re-filter-filename", 1, html_encode(csp->rlist->filename), 0);
801 if (!err) err = map(exports, "re-filter-filename", 1, "None specified", 1);
807 if (!err) err = map(exports, "trust-filename", 1, html_encode(csp->tlist->filename), 0);
811 if (!err) err = map(exports, "trust-filename", 1, "None specified", 1);
814 if (!err) err = map_block_killer(exports, "trust-support");
815 #endif /* ndef FEATURE_TRUST */
820 return JB_ERR_MEMORY;
823 return template_fill_for_cgi(csp, "show-status", exports, rsp);
827 /*********************************************************************
829 * Function : cgi_show_url_info
831 * Description : CGI function that determines and shows which actions
832 * Privoxy will perform for a given url, and which
833 * matches starting from the defaults have lead to that.
836 * 1 : csp = Current client state (buffers, headers, etc...)
837 * 2 : rsp = http_response data structure for output
838 * 3 : parameters = map of cgi parameters
841 * url : The url whose actions are to be determined.
842 * If url is unset, the url-given conditional will be
843 * set, so that all but the form can be suppressed in
846 * Returns : JB_ERR_OK on success
847 * JB_ERR_MEMORY on out-of-memory error.
849 *********************************************************************/
850 jb_err cgi_show_url_info(struct client_state *csp,
851 struct http_response *rsp,
852 const struct map *parameters)
861 if (NULL == (exports = default_exports(csp, "show-url-info")))
863 return JB_ERR_MEMORY;
867 * Get the url= parameter (if present) and remove any leading/trailing spaces.
869 url_param = strdup(lookup(parameters, "url"));
870 if (url_param == NULL)
873 return JB_ERR_MEMORY;
878 * Handle prefixes. 4 possibilities:
879 * 1) "http://" or "https://" prefix present and followed by URL - OK
880 * 2) Only the "http://" or "https://" part is present, no URL - change
881 * to empty string so it will be detected later as "no URL".
882 * 3) Parameter specified but doesn't contain "http(s?)://" - add a
884 * 4) Parameter not specified or is empty string - let this fall through
885 * for now, next block of code will handle it.
887 if (0 == strncmp(url_param, "http://", 7))
889 if (url_param[7] == '\0')
892 * Empty URL (just prefix).
893 * Make it totally empty so it's caught by the next if()
898 else if (0 == strncmp(url_param, "https://", 8))
900 if (url_param[8] == '\0')
903 * Empty URL (just prefix).
904 * Make it totally empty so it's caught by the next if()
909 else if (url_param[0] != '\0')
912 * Unknown prefix - assume http://
914 char * url_param_prefixed = malloc(7 + 1 + strlen(url_param));
915 if (NULL == url_param_prefixed)
919 return JB_ERR_MEMORY;
921 strcpy(url_param_prefixed, "http://");
922 strcpy(url_param_prefixed + 7, url_param);
924 url_param = url_param_prefixed;
928 if (url_param[0] == '\0')
930 /* URL paramater not specified, display query form only. */
932 if (map_block_killer(exports, "url-given")
933 || map(exports, "url", 1, "", 1))
936 return JB_ERR_MEMORY;
941 /* Given a URL, so query it. */
946 struct file_list *fl;
947 struct url_actions *b;
948 struct http_request url_to_query[1];
949 struct current_action_spec action[1];
951 if (map(exports, "url", 1, html_encode(url_param), 0))
955 return JB_ERR_MEMORY;
958 init_current_action(action);
960 if (map(exports, "default", 1, html_encode_and_free_original(
961 current_action_to_text(action)), 0))
963 free_current_action(action);
966 return JB_ERR_MEMORY;
969 if (((fl = csp->actions_list) == NULL) || ((b = fl->f) == NULL))
971 err = map(exports, "matches", 1, "none" , 1);
972 if (!err) err = map(exports, "final", 1, lookup(exports, "default"), 1);
974 free_current_action(action);
980 return JB_ERR_MEMORY;
983 return template_fill_for_cgi(csp, "show-url-info", exports, rsp);
986 err = parse_http_url(url_param, url_to_query, csp);
990 if (err == JB_ERR_MEMORY)
992 free_current_action(action);
994 return JB_ERR_MEMORY;
1000 err = map(exports, "matches", 1, "<b>[Invalid URL specified!]</b>" , 1);
1001 if (!err) err = map(exports, "final", 1, lookup(exports, "default"), 1);
1003 free_current_action(action);
1008 return JB_ERR_MEMORY;
1011 return template_fill_for_cgi(csp, "show-url-info", exports, rsp);
1015 * We have a warning about SSL paths. Hide it for insecure sites.
1017 if (!url_to_query->ssl)
1019 if (map_block_killer(exports, "https"))
1021 free_current_action(action);
1023 return JB_ERR_MEMORY;
1027 matches = strdup("");
1029 for (b = b->next; (b != NULL) && (matches != NULL); b = b->next)
1031 if (url_match(b->url, url_to_query))
1033 string_append(&matches, "<b>{");
1034 string_join (&matches, html_encode_and_free_original(
1035 actions_to_text(b->action)));
1036 string_append(&matches, " }</b><br>\n<code>");
1037 string_join (&matches, html_encode(b->url->spec));
1038 string_append(&matches, "</code><br>\n<br>\n");
1040 if (merge_current_action(action, b->action))
1043 free_http_request(url_to_query);
1044 free_current_action(action);
1046 return JB_ERR_MEMORY;
1052 free_http_request(url_to_query);
1054 if (matches == NULL)
1056 free_current_action(action);
1058 return JB_ERR_MEMORY;
1064 matches = strdup("none");
1066 if (map(exports, "matches", 1, matches , 0))
1068 free_current_action(action);
1070 return JB_ERR_MEMORY;
1073 s = html_encode_and_free_original(current_action_to_text(action));
1075 free_current_action(action);
1077 if (map(exports, "final", 1, s, 0))
1080 return JB_ERR_MEMORY;
1084 return template_fill_for_cgi(csp, "show-url-info", exports, rsp);
1088 /*********************************************************************
1090 * Function : cgi_robots_txt
1092 * Description : CGI function to return "/robots.txt".
1095 * 1 : csp = Current client state (buffers, headers, etc...)
1096 * 2 : rsp = http_response data structure for output
1097 * 3 : parameters = map of cgi parameters
1099 * CGI Parameters : None
1101 * Returns : JB_ERR_OK on success
1102 * JB_ERR_MEMORY on out-of-memory error.
1104 *********************************************************************/
1105 jb_err cgi_robots_txt(struct client_state *csp,
1106 struct http_response *rsp,
1107 const struct map *parameters)
1113 "# This is the Privoxy control interface.\n"
1114 "# It isn't very useful to index it, and you're likely to break stuff.\n"
1120 if (rsp->body == NULL)
1122 return JB_ERR_MEMORY;
1125 err = enlist_unique(rsp->headers, "Content-Type: text/plain", 13);
1129 get_http_time(7 * 24 * 60 * 60, buf); /* 7 days into future */
1130 if (!err) err = enlist_unique_header(rsp->headers, "Expires", buf);
1132 return (err ? JB_ERR_MEMORY : JB_ERR_OK);
1136 /*********************************************************************
1138 * Function : show_defines
1140 * Description : Add to a map the state od all conditional #defines
1141 * used when building
1144 * 1 : exports = map to extend
1146 * Returns : JB_ERR_OK on success
1147 * JB_ERR_MEMORY on out-of-memory error.
1149 *********************************************************************/
1150 static jb_err show_defines(struct map *exports)
1152 jb_err err = JB_ERR_OK;
1155 if (!err) err = map_conditional(exports, "FEATURE_ACL", 1);
1156 #else /* ifndef FEATURE_ACL */
1157 if (!err) err = map_conditional(exports, "FEATURE_ACL", 0);
1158 #endif /* ndef FEATURE_ACL */
1160 #ifdef FEATURE_CGI_EDIT_ACTIONS
1161 if (!err) err = map_conditional(exports, "FEATURE_CGI_EDIT_ACTIONS", 1);
1162 #else /* ifndef FEATURE_COOKIE_JAR */
1163 if (!err) err = map_conditional(exports, "FEATURE_CGI_EDIT_ACTIONS", 0);
1164 #endif /* ndef FEATURE_COOKIE_JAR */
1166 #ifdef FEATURE_COOKIE_JAR
1167 if (!err) err = map_conditional(exports, "FEATURE_COOKIE_JAR", 1);
1168 #else /* ifndef FEATURE_COOKIE_JAR */
1169 if (!err) err = map_conditional(exports, "FEATURE_COOKIE_JAR", 0);
1170 #endif /* ndef FEATURE_COOKIE_JAR */
1172 #ifdef FEATURE_FAST_REDIRECTS
1173 if (!err) err = map_conditional(exports, "FEATURE_FAST_REDIRECTS", 1);
1174 #else /* ifndef FEATURE_FAST_REDIRECTS */
1175 if (!err) err = map_conditional(exports, "FEATURE_FAST_REDIRECTS", 0);
1176 #endif /* ndef FEATURE_FAST_REDIRECTS */
1178 #ifdef FEATURE_FORCE_LOAD
1179 if (!err) err = map_conditional(exports, "FEATURE_FORCE_LOAD", 1);
1180 if (!err) err = map(exports, "FORCE_PREFIX", 1, FORCE_PREFIX, 1);
1181 #else /* ifndef FEATURE_FORCE_LOAD */
1182 if (!err) err = map_conditional(exports, "FEATURE_FORCE_LOAD", 0);
1183 if (!err) err = map(exports, "FORCE_PREFIX", 1, "(none - disabled)", 1);
1184 #endif /* ndef FEATURE_FORCE_LOAD */
1186 #ifdef FEATURE_IMAGE_BLOCKING
1187 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_BLOCKING", 1);
1188 #else /* ifndef FEATURE_IMAGE_BLOCKING */
1189 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_BLOCKING", 0);
1190 #endif /* ndef FEATURE_IMAGE_BLOCKING */
1192 #ifdef FEATURE_IMAGE_DETECT_MSIE
1193 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_DETECT_MSIE", 1);
1194 #else /* ifndef FEATURE_IMAGE_DETECT_MSIE */
1195 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_DETECT_MSIE", 0);
1196 #endif /* ndef FEATURE_IMAGE_DETECT_MSIE */
1198 #ifdef FEATURE_KILL_POPUPS
1199 if (!err) err = map_conditional(exports, "FEATURE_KILL_POPUPS", 1);
1200 #else /* ifndef FEATURE_KILL_POPUPS */
1201 if (!err) err = map_conditional(exports, "FEATURE_KILL_POPUPS", 0);
1202 #endif /* ndef FEATURE_KILL_POPUPS */
1204 #ifdef FEATURE_NO_GIFS
1205 if (!err) err = map_conditional(exports, "FEATURE_NO_GIFS", 1);
1206 #else /* ifndef FEATURE_NO_GIFS */
1207 if (!err) err = map_conditional(exports, "FEATURE_NO_GIFS", 0);
1208 #endif /* ndef FEATURE_NO_GIFS */
1210 #ifdef FEATURE_PTHREAD
1211 if (!err) err = map_conditional(exports, "FEATURE_PTHREAD", 1);
1212 #else /* ifndef FEATURE_PTHREAD */
1213 if (!err) err = map_conditional(exports, "FEATURE_PTHREAD", 0);
1214 #endif /* ndef FEATURE_PTHREAD */
1216 #ifdef FEATURE_STATISTICS
1217 if (!err) err = map_conditional(exports, "FEATURE_STATISTICS", 1);
1218 #else /* ifndef FEATURE_STATISTICS */
1219 if (!err) err = map_conditional(exports, "FEATURE_STATISTICS", 0);
1220 #endif /* ndef FEATURE_STATISTICS */
1222 #ifdef FEATURE_TOGGLE
1223 if (!err) err = map_conditional(exports, "FEATURE_TOGGLE", 1);
1224 #else /* ifndef FEATURE_TOGGLE */
1225 if (!err) err = map_conditional(exports, "FEATURE_TOGGLE", 0);
1226 #endif /* ndef FEATURE_TOGGLE */
1228 #ifdef FEATURE_TRUST
1229 if (!err) err = map_conditional(exports, "FEATURE_TRUST", 1);
1230 #else /* ifndef FEATURE_TRUST */
1231 if (!err) err = map_conditional(exports, "FEATURE_TRUST", 0);
1232 #endif /* ndef FEATURE_TRUST */
1235 if (!err) err = map_conditional(exports, "STATIC_PCRE", 1);
1236 #else /* ifndef STATIC_PCRE */
1237 if (!err) err = map_conditional(exports, "STATIC_PCRE", 0);
1238 #endif /* ndef STATIC_PCRE */
1241 if (!err) err = map_conditional(exports, "STATIC_PCRS", 1);
1242 #else /* ifndef STATIC_PCRS */
1243 if (!err) err = map_conditional(exports, "STATIC_PCRS", 0);
1244 #endif /* ndef STATIC_PCRS */
1250 /*********************************************************************
1252 * Function : show_rcs
1254 * Description : Create a string with the rcs info for all sourcefiles
1258 * Returns : A string, or NULL on out-of-memory.
1260 *********************************************************************/
1261 static char *show_rcs(void)
1263 char *result = strdup("");
1264 char buf[BUFFER_SIZE];
1266 /* Instead of including *all* dot h's in the project (thus creating a
1267 * tremendous amount of dependencies), I will concede to declaring them
1268 * as extern's. This forces the developer to add to this list, but oh well.
1271 #define SHOW_RCS(__x) \
1273 extern const char __x[]; \
1274 sprintf(buf, "%s\n", __x); \
1275 string_append(&result, buf); \
1278 /* In alphabetical order */
1279 SHOW_RCS(actions_h_rcs)
1280 SHOW_RCS(actions_rcs)
1283 #ifdef FEATURE_CGI_EDIT_ACTIONS
1284 SHOW_RCS(cgiedit_h_rcs)
1285 SHOW_RCS(cgiedit_rcs)
1286 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1287 SHOW_RCS(cgisimple_h_rcs)
1288 SHOW_RCS(cgisimple_rcs)
1290 SHOW_RCS(cygwin_h_rcs)
1292 SHOW_RCS(deanimate_h_rcs)
1293 SHOW_RCS(deanimate_rcs)
1294 SHOW_RCS(encode_h_rcs)
1295 SHOW_RCS(encode_rcs)
1296 SHOW_RCS(errlog_h_rcs)
1297 SHOW_RCS(errlog_rcs)
1298 SHOW_RCS(filters_h_rcs)
1299 SHOW_RCS(filters_rcs)
1300 SHOW_RCS(gateway_h_rcs)
1301 SHOW_RCS(gateway_rcs)
1302 SHOW_RCS(jbsockets_h_rcs)
1303 SHOW_RCS(jbsockets_rcs)
1306 #ifdef FEATURE_KILL_POPUPS
1307 SHOW_RCS(killpopup_h_rcs)
1308 SHOW_RCS(killpopup_rcs)
1309 #endif /* def FEATURE_KILL_POPUPS */
1310 SHOW_RCS(list_h_rcs)
1312 SHOW_RCS(loadcfg_h_rcs)
1313 SHOW_RCS(loadcfg_rcs)
1314 SHOW_RCS(loaders_h_rcs)
1315 SHOW_RCS(loaders_rcs)
1316 SHOW_RCS(miscutil_h_rcs)
1317 SHOW_RCS(miscutil_rcs)
1318 SHOW_RCS(parsers_h_rcs)
1319 SHOW_RCS(parsers_rcs)
1321 SHOW_RCS(pcrs_h_rcs)
1322 SHOW_RCS(project_h_rcs)
1323 SHOW_RCS(ssplit_h_rcs)
1324 SHOW_RCS(ssplit_rcs)
1325 SHOW_RCS(urlmatch_h_rcs)
1326 SHOW_RCS(urlmatch_rcs)
1328 #ifndef _WIN_CONSOLE
1329 SHOW_RCS(w32log_h_rcs)
1330 SHOW_RCS(w32log_rcs)
1331 SHOW_RCS(w32res_h_rcs)
1332 SHOW_RCS(w32taskbar_h_rcs)
1333 SHOW_RCS(w32taskbar_rcs)
1334 #endif /* ndef _WIN_CONSOLE */
1335 SHOW_RCS(win32_h_rcs)
1337 #endif /* def _WIN32 */