1 const char cgisimple_rcs[] = "$Id: cgisimple.c,v 1.28 2002/04/07 15:42:12 jongfoster Exp $";
2 /*********************************************************************
4 * File : $Source: /cvsroot/ijbswa/current/cgisimple.c,v $
6 * Purpose : Simple CGIs to get information about Privoxy's
9 * Functions declared include:
12 * Copyright : Written by and Copyright (C) 2001 the SourceForge
13 * Privoxy team. http://www.privoxy.org/
15 * Based on the Internet Junkbuster originally written
16 * by and Copyright (C) 1997 Anonymous Coders and
17 * Junkbusters Corporation. http://www.junkbusters.com
19 * This program is free software; you can redistribute it
20 * and/or modify it under the terms of the GNU General
21 * Public License as published by the Free Software
22 * Foundation; either version 2 of the License, or (at
23 * your option) any later version.
25 * This program is distributed in the hope that it will
26 * be useful, but WITHOUT ANY WARRANTY; without even the
27 * implied warranty of MERCHANTABILITY or FITNESS FOR A
28 * PARTICULAR PURPOSE. See the GNU General Public
29 * License for more details.
31 * The GNU General Public License should be included with
32 * this file. If not, you can view it at
33 * http://www.gnu.org/copyleft/gpl.html
34 * or write to the Free Software Foundation, Inc., 59
35 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
38 * $Log: cgisimple.c,v $
39 * Revision 1.28 2002/04/07 15:42:12 jongfoster
40 * Fixing send-banner?type=auto when the image-blocker is
41 * a redirect to send-banner
43 * Revision 1.27 2002/04/05 15:50:48 oes
44 * added send-stylesheet CGI
46 * Revision 1.26 2002/04/04 00:36:36 gliptak
47 * always use pcre for matching
49 * Revision 1.25 2002/04/03 22:28:03 gliptak
50 * Removed references to gnu_regex
52 * Revision 1.24 2002/04/02 16:12:47 oes
53 * Fix: moving misplaced lines into #ifdef FEATURE_FORCE
55 * Revision 1.23 2002/03/26 22:29:54 swa
56 * we have a new homepage!
58 * Revision 1.22 2002/03/24 16:18:15 jongfoster
61 * Revision 1.21 2002/03/24 15:23:33 jongfoster
64 * Revision 1.20 2002/03/24 13:25:43 swa
65 * name change related issues
67 * Revision 1.19 2002/03/16 23:54:06 jongfoster
68 * Adding graceful termination feature, to help look for memory leaks.
69 * If you enable this (which, by design, has to be done by hand
70 * editing config.h) and then go to http://i.j.b/die, then the program
71 * will exit cleanly after the *next* request. It should free all the
72 * memory that was used.
74 * Revision 1.18 2002/03/12 01:44:49 oes
75 * Changed default for "blocked" image from jb logo to checkboard pattern
77 * Revision 1.17 2002/03/08 16:43:18 oes
78 * Added choice beween GIF and PNG built-in images
80 * Revision 1.16 2002/03/07 03:48:38 oes
81 * - Changed built-in images from GIF to PNG
82 * (with regard to Unisys patent issue)
83 * - Added a 4x4 pattern PNG which is less intrusive
84 * than the logo but also clearly marks the deleted banners
86 * Revision 1.15 2002/03/06 22:54:35 jongfoster
87 * Automated function-comment nitpicking.
89 * Revision 1.14 2002/03/02 04:14:50 david__schmidt
90 * Clean up a little CRLF unpleasantness that suddenly appeared
92 * Revision 1.13 2002/02/21 00:10:37 jongfoster
93 * Adding send-banner?type=auto option
95 * Revision 1.12 2002/01/23 01:03:32 jongfoster
96 * Fixing gcc [CygWin] compiler warnings
98 * Revision 1.11 2002/01/23 00:01:04 jongfoster
99 * Adding cgi_transparent_gif() for http://i.j.b/t
100 * Adding missing html_encode() to many CGI functions.
101 * Adding urlmatch.[ch] to http://i.j.b/show-version
103 * Revision 1.10 2002/01/17 21:10:37 jongfoster
104 * Changes to cgi_show_url_info to use new matching code from urlmatch.c.
105 * Also fixing a problem in the same function with improperly quoted URLs
106 * in output HTML, and adding code to handle https:// URLs correctly.
108 * Revision 1.9 2001/11/30 23:09:15 jongfoster
109 * Now reports on FEATURE_CGI_EDIT_ACTIONS
110 * Removing FEATURE_DENY_GZIP from template
112 * Revision 1.8 2001/11/13 00:14:07 jongfoster
113 * Fixing stupid bug now I've figured out what || means.
114 * (It always returns 0 or 1, not one of it's paramaters.)
116 * Revision 1.7 2001/10/23 21:48:19 jongfoster
117 * Cleaning up error handling in CGI functions - they now send back
118 * a HTML error page and should never cause a FATAL error. (Fixes one
119 * potential source of "denial of service" attacks).
121 * CGI actions file editor that works and is actually useful.
123 * Ability to toggle JunkBuster remotely using a CGI call.
125 * You can turn off both the above features in the main configuration
126 * file, e.g. if you are running a multi-user proxy.
128 * Revision 1.6 2001/10/14 22:00:32 jongfoster
129 * Adding support for a 404 error when an invalid CGI page is requested.
131 * Revision 1.5 2001/10/07 15:30:41 oes
132 * Removed FEATURE_DENY_GZIP
134 * Revision 1.4 2001/10/02 15:31:12 oes
135 * Introduced show-request cgi
137 * Revision 1.3 2001/09/22 16:34:44 jongfoster
138 * Removing unneeded #includes
140 * Revision 1.2 2001/09/19 18:01:11 oes
141 * Fixed comments; cosmetics
143 * Revision 1.1 2001/09/16 17:08:54 jongfoster
144 * Moving simple CGI functions from cgi.c to new file cgisimple.c
147 **********************************************************************/
153 #include <sys/types.h>
160 #define snprintf _snprintf
161 #endif /* def _WIN32 */
165 #include "cgisimple.h"
171 #include "miscutil.h"
174 #include "urlmatch.h"
177 const char cgisimple_h_rcs[] = CGISIMPLE_H_VERSION;
180 static char *show_rcs(void);
181 static jb_err show_defines(struct map *exports);
184 /*********************************************************************
186 * Function : cgi_default
188 * Description : CGI function that is called if no action was given.
189 * Lists menu of available unhidden CGIs.
192 * 1 : csp = Current client state (buffers, headers, etc...)
193 * 2 : rsp = http_response data structure for output
194 * 3 : parameters = map of cgi parameters
196 * CGI Parameters : none
198 * Returns : JB_ERR_OK on success
199 * JB_ERR_MEMORY on out-of-memory
200 * (Problems other than out-of-memory should be
201 * handled by this routine - it should set the
202 * rsp appropriately and return "success")
204 *********************************************************************/
205 jb_err cgi_default(struct client_state *csp,
206 struct http_response *rsp,
207 const struct map *parameters)
216 if (NULL == (exports = default_exports(csp, "")))
218 return JB_ERR_MEMORY;
221 /* If there were other parameters, export a dump as "cgi-parameters" */
222 if (parameters->first)
224 tmp = strdup("<p>What made you think this cgi takes parameters?\n"
225 "Anyway, here they are, in case you're interested:</p>\n");
226 string_join(&tmp, dump_map(parameters));
230 return JB_ERR_MEMORY;
232 if (map(exports, "cgi-parameters", 1, tmp, 0))
234 return JB_ERR_MEMORY;
239 if (map(exports, "cgi-parameters", 1, "", 1))
241 return JB_ERR_MEMORY;
245 return template_fill_for_cgi(csp, "default", exports, rsp);
251 /*********************************************************************
253 * Function : cgi_error_404
255 * Description : CGI function that is called if an unknown action was
259 * 1 : csp = Current client state (buffers, headers, etc...)
260 * 2 : rsp = http_response data structure for output
261 * 3 : parameters = map of cgi parameters
263 * CGI Parameters : none
265 * Returns : JB_ERR_OK on success
266 * JB_ERR_MEMORY on out-of-memory error.
268 *********************************************************************/
269 jb_err cgi_error_404(struct client_state *csp,
270 struct http_response *rsp,
271 const struct map *parameters)
279 if (NULL == (exports = default_exports(csp, NULL)))
281 return JB_ERR_MEMORY;
284 rsp->status = strdup("404 Privoxy configuration page not found");
285 if (rsp->status == NULL)
288 return JB_ERR_MEMORY;
291 return template_fill_for_cgi(csp, "cgi-error-404", exports, rsp);
295 #ifdef FEATURE_GRACEFUL_TERMINATION
296 /*********************************************************************
300 * Description : CGI function to shut down Privoxy.
301 * NOTE: Turning this on in a production build
302 * would be a BAD idea. An EXTREMELY BAD idea.
303 * In short, don't do it.
306 * 1 : csp = Current client state (buffers, headers, etc...)
307 * 2 : rsp = http_response data structure for output
308 * 3 : parameters = map of cgi parameters
310 * CGI Parameters : none
312 * Returns : JB_ERR_OK on success
313 * JB_ERR_MEMORY on out-of-memory error.
315 *********************************************************************/
316 jb_err cgi_die (struct client_state *csp,
317 struct http_response *rsp,
318 const struct map *parameters)
328 * I don't really care what gets sent back to the browser.
329 * Take the easy option - "out of memory" page.
332 return JB_ERR_MEMORY;
334 #endif /* def FEATURE_GRACEFUL_TERMINATION */
337 /*********************************************************************
339 * Function : cgi_show_request
341 * Description : Show the client's request and what sed() would have
345 * 1 : csp = Current client state (buffers, headers, etc...)
346 * 2 : rsp = http_response data structure for output
347 * 3 : parameters = map of cgi parameters
349 * CGI Parameters : none
351 * Returns : JB_ERR_OK on success
352 * JB_ERR_MEMORY on out-of-memory error.
354 *********************************************************************/
355 jb_err cgi_show_request(struct client_state *csp,
356 struct http_response *rsp,
357 const struct map *parameters)
366 if (NULL == (exports = default_exports(csp, "show-request")))
368 return JB_ERR_MEMORY;
372 * Repair the damage done to the IOB by get_header()
374 for (p = csp->iob->buf; p < csp->iob->eod; p++)
376 if (*p == '\0') *p = '\n';
380 * Export the original client's request and the one we would
381 * be sending to the server if this wasn't a CGI call
384 if (map(exports, "client-request", 1, html_encode(csp->iob->buf), 0))
387 return JB_ERR_MEMORY;
390 if (map(exports, "processed-request", 1, html_encode_and_free_original(
391 sed(client_patterns, add_client_headers, csp)), 0))
394 return JB_ERR_MEMORY;
397 return template_fill_for_cgi(csp, "show-request", exports, rsp);
401 /*********************************************************************
403 * Function : cgi_send_banner
405 * Description : CGI function that returns a banner.
408 * 1 : csp = Current client state (buffers, headers, etc...)
409 * 2 : rsp = http_response data structure for output
410 * 3 : parameters = map of cgi parameters
413 * type : Selects the type of banner between "trans", "logo",
414 * and "auto". Defaults to "logo" if absent or invalid.
415 * "auto" means to select as if we were image-blocking.
416 * (Only the first character really counts).
418 * Returns : JB_ERR_OK on success
419 * JB_ERR_MEMORY on out-of-memory error.
421 *********************************************************************/
422 jb_err cgi_send_banner(struct client_state *csp,
423 struct http_response *rsp,
424 const struct map *parameters)
426 char imagetype = lookup(parameters, "type")[0];
428 if (imagetype == 'a') /* auto */
430 /* Default to pattern */
432 #ifdef FEATURE_IMAGE_BLOCKING
433 if ((csp->action->flags & ACTION_IMAGE_BLOCKER) != 0)
435 static const char prefix1[] = CGI_PREFIX "send-banner?type=";
436 static const char prefix2[] = "http://" CGI_SITE_1_HOST "/send-banner?type=";
438 /* determine HOW images should be blocked */
439 const char * p = csp->action->string[ACTION_STRING_IMAGE_BLOCKER];
441 /* and handle accordingly: */
444 /* Use default - nothing to do here. */
446 else if (0 == strcmpic(p, "blank"))
450 else if (0 == strcmpic(p, "pattern"))
454 else if (0 == strncmpic(p, prefix1, sizeof(prefix1) - 1))
456 imagetype = p[sizeof(prefix1) - 1];
458 else if (0 == strncmpic(p, prefix2, sizeof(prefix2) - 1))
460 imagetype = p[sizeof(prefix2) - 1];
463 #endif /* def FEATURE_IMAGE_BLOCKING */
466 if ((imagetype == 'b') || (imagetype == 't')) /* blank / transparent */
468 rsp->body = bindup(image_blank_data, image_blank_length);
469 rsp->content_length = image_blank_length;
474 rsp->body = bindup(image_pattern_data, image_pattern_length);
475 rsp->content_length = image_pattern_length;
478 if (rsp->body == NULL)
480 return JB_ERR_MEMORY;
483 if (enlist(rsp->headers, "Content-Type: " BUILTIN_IMAGE_MIMETYPE))
485 return JB_ERR_MEMORY;
495 /*********************************************************************
497 * Function : cgi_transparent_image
499 * Description : CGI function that sends a 1x1 transparent image.
502 * 1 : csp = Current client state (buffers, headers, etc...)
503 * 2 : rsp = http_response data structure for output
504 * 3 : parameters = map of cgi parameters
506 * CGI Parameters : None
508 * Returns : JB_ERR_OK on success
509 * JB_ERR_MEMORY on out-of-memory error.
511 *********************************************************************/
512 jb_err cgi_transparent_image(struct client_state *csp,
513 struct http_response *rsp,
514 const struct map *parameters)
516 rsp->body = bindup(image_blank_data, image_blank_length);
517 rsp->content_length = image_blank_length;
519 if (rsp->body == NULL)
521 return JB_ERR_MEMORY;
524 if (enlist(rsp->headers, "Content-Type: " BUILTIN_IMAGE_MIMETYPE))
526 return JB_ERR_MEMORY;
536 /*********************************************************************
538 * Function : cgi_send_stylesheet
540 * Description : CGI function that sends a css stylesheet found
541 * in the cgi-style.css template
544 * 1 : csp = Current client state (buffers, headers, etc...)
545 * 2 : rsp = http_response data structure for output
546 * 3 : parameters = map of cgi parameters
548 * CGI Parameters : None
550 * Returns : JB_ERR_OK on success
551 * JB_ERR_MEMORY on out-of-memory error.
553 *********************************************************************/
554 jb_err cgi_send_stylesheet(struct client_state *csp,
555 struct http_response *rsp,
556 const struct map *parameters)
563 err = template_load(csp, &rsp->body, "cgi-style.css", 0);
565 if (err == JB_ERR_FILE)
568 * No way to tell user; send empty stylesheet
570 log_error(LOG_LEVEL_ERROR, "Could not find cgi-style.css template");
574 return err; /* JB_ERR_MEMORY */
577 if (enlist(rsp->headers, "Content-Type: text/css"))
579 return JB_ERR_MEMORY;
587 /*********************************************************************
589 * Function : cgi_show_version
591 * Description : CGI function that returns a a web page describing the
592 * file versions of Privoxy.
595 * 1 : csp = Current client state (buffers, headers, etc...)
596 * 2 : rsp = http_response data structure for output
597 * 3 : parameters = map of cgi parameters
599 * CGI Parameters : none
601 * Returns : JB_ERR_OK on success
602 * JB_ERR_MEMORY on out-of-memory error.
604 *********************************************************************/
605 jb_err cgi_show_version(struct client_state *csp,
606 struct http_response *rsp,
607 const struct map *parameters)
615 if (NULL == (exports = default_exports(csp, "show-version")))
617 return JB_ERR_MEMORY;
620 if (map(exports, "sourceversions", 1, show_rcs(), 0))
623 return JB_ERR_MEMORY;
626 return template_fill_for_cgi(csp, "show-version", exports, rsp);
630 /*********************************************************************
632 * Function : cgi_show_status
634 * Description : CGI function that returns a a web page describing the
635 * current status of Privoxy.
638 * 1 : csp = Current client state (buffers, headers, etc...)
639 * 2 : rsp = http_response data structure for output
640 * 3 : parameters = map of cgi parameters
643 * file : Which file to show. Only first letter is checked,
645 * - "p"ermissions (actions) file
648 * Default is to show menu and other information.
650 * Returns : JB_ERR_OK on success
651 * JB_ERR_MEMORY on out-of-memory error.
653 *********************************************************************/
654 jb_err cgi_show_status(struct client_state *csp,
655 struct http_response *rsp,
656 const struct map *parameters)
662 char buf[BUFFER_SIZE];
663 const char * filename = NULL;
664 char * file_description = NULL;
665 #ifdef FEATURE_STATISTICS
666 float perc_rej; /* Percentage of http requests rejected */
668 int local_urls_rejected;
669 #endif /* ndef FEATURE_STATISTICS */
678 if (NULL == (exports = default_exports(csp, "show-status")))
680 return JB_ERR_MEMORY;
683 switch (*(lookup(parameters, "file")))
686 if (csp->actions_list)
688 filename = csp->actions_list->filename;
689 file_description = "Actions List";
696 filename = csp->rlist->filename;
697 file_description = "Regex Filter List";
705 filename = csp->tlist->filename;
706 file_description = "Trust List";
709 #endif /* def FEATURE_TRUST */
712 if (NULL != filename)
714 if ( map(exports, "file-description", 1, file_description, 1)
715 || map(exports, "filepath", 1, html_encode(filename), 0) )
718 return JB_ERR_MEMORY;
721 if ((fp = fopen(filename, "r")) == NULL)
723 if (map(exports, "content", 1, "<h1>ERROR OPENING FILE!</h1>", 1))
726 return JB_ERR_MEMORY;
732 while ((s != NULL) && fgets(buf, sizeof(buf), fp))
734 string_join (&s, html_encode(buf));
738 if (map(exports, "contents", 1, s, 0))
741 return JB_ERR_MEMORY;
745 return template_fill_for_cgi(csp, "show-status-file", exports, rsp);
748 if (map(exports, "redirect-url", 1, html_encode(REDIRECT_URL), 0))
751 return JB_ERR_MEMORY;
755 for (i = 0; (s != NULL) && (i < Argc); i++)
757 string_join (&s, html_encode(Argv[i]));
758 string_append(&s, " ");
760 if (map(exports, "invocation", 1, s, 0))
763 return JB_ERR_MEMORY;
766 err = map(exports, "options", 1, csp->config->proxy_args, 1);
767 if (!err) err = show_defines(exports);
769 #ifdef FEATURE_STATISTICS
770 local_urls_read = urls_read;
771 local_urls_rejected = urls_rejected;
774 * Need to alter the stats not to include the fetch of this
777 * Can't do following thread safely! doh!
780 * urls_rejected--; * This will be incremented subsequently *
783 if (local_urls_read == 0)
785 if (!err) err = map_block_killer(exports, "have-stats");
789 if (!err) err = map_block_killer(exports, "have-no-stats");
791 perc_rej = (float)local_urls_rejected * 100.0F /
792 (float)local_urls_read;
794 sprintf(buf, "%d", local_urls_read);
795 if (!err) err = map(exports, "requests-received", 1, buf, 1);
797 sprintf(buf, "%d", local_urls_rejected);
798 if (!err) err = map(exports, "requests-blocked", 1, buf, 1);
800 sprintf(buf, "%6.2f", perc_rej);
801 if (!err) err = map(exports, "percent-blocked", 1, buf, 1);
804 #else /* ndef FEATURE_STATISTICS */
805 err = err || map_block_killer(exports, "statistics");
806 #endif /* ndef FEATURE_STATISTICS */
808 if (csp->actions_list)
810 if (!err) err = map(exports, "actions-filename", 1, html_encode(csp->actions_list->filename), 0);
814 if (!err) err = map(exports, "actions-filename", 1, "None specified", 1);
819 if (!err) err = map(exports, "re-filter-filename", 1, html_encode(csp->rlist->filename), 0);
823 if (!err) err = map(exports, "re-filter-filename", 1, "None specified", 1);
829 if (!err) err = map(exports, "trust-filename", 1, html_encode(csp->tlist->filename), 0);
833 if (!err) err = map(exports, "trust-filename", 1, "None specified", 1);
836 if (!err) err = map_block_killer(exports, "trust-support");
837 #endif /* ndef FEATURE_TRUST */
842 return JB_ERR_MEMORY;
845 return template_fill_for_cgi(csp, "show-status", exports, rsp);
849 /*********************************************************************
851 * Function : cgi_show_url_info
853 * Description : CGI function that determines and shows which actions
854 * Privoxy will perform for a given url, and which
855 * matches starting from the defaults have lead to that.
858 * 1 : csp = Current client state (buffers, headers, etc...)
859 * 2 : rsp = http_response data structure for output
860 * 3 : parameters = map of cgi parameters
863 * url : The url whose actions are to be determined.
864 * If url is unset, the url-given conditional will be
865 * set, so that all but the form can be suppressed in
868 * Returns : JB_ERR_OK on success
869 * JB_ERR_MEMORY on out-of-memory error.
871 *********************************************************************/
872 jb_err cgi_show_url_info(struct client_state *csp,
873 struct http_response *rsp,
874 const struct map *parameters)
883 if (NULL == (exports = default_exports(csp, "show-url-info")))
885 return JB_ERR_MEMORY;
889 * Get the url= parameter (if present) and remove any leading/trailing spaces.
891 url_param = strdup(lookup(parameters, "url"));
892 if (url_param == NULL)
895 return JB_ERR_MEMORY;
900 * Handle prefixes. 4 possibilities:
901 * 1) "http://" or "https://" prefix present and followed by URL - OK
902 * 2) Only the "http://" or "https://" part is present, no URL - change
903 * to empty string so it will be detected later as "no URL".
904 * 3) Parameter specified but doesn't contain "http(s?)://" - add a
906 * 4) Parameter not specified or is empty string - let this fall through
907 * for now, next block of code will handle it.
909 if (0 == strncmp(url_param, "http://", 7))
911 if (url_param[7] == '\0')
914 * Empty URL (just prefix).
915 * Make it totally empty so it's caught by the next if()
920 else if (0 == strncmp(url_param, "https://", 8))
922 if (url_param[8] == '\0')
925 * Empty URL (just prefix).
926 * Make it totally empty so it's caught by the next if()
931 else if (url_param[0] != '\0')
934 * Unknown prefix - assume http://
936 char * url_param_prefixed = malloc(7 + 1 + strlen(url_param));
937 if (NULL == url_param_prefixed)
941 return JB_ERR_MEMORY;
943 strcpy(url_param_prefixed, "http://");
944 strcpy(url_param_prefixed + 7, url_param);
946 url_param = url_param_prefixed;
950 if (url_param[0] == '\0')
952 /* URL paramater not specified, display query form only. */
954 if (map_block_killer(exports, "url-given")
955 || map(exports, "url", 1, "", 1))
958 return JB_ERR_MEMORY;
963 /* Given a URL, so query it. */
968 struct file_list *fl;
969 struct url_actions *b;
970 struct http_request url_to_query[1];
971 struct current_action_spec action[1];
973 if (map(exports, "url", 1, html_encode(url_param), 0))
977 return JB_ERR_MEMORY;
980 init_current_action(action);
982 if (map(exports, "default", 1, html_encode_and_free_original(
983 current_action_to_text(action)), 0))
985 free_current_action(action);
988 return JB_ERR_MEMORY;
991 if (((fl = csp->actions_list) == NULL) || ((b = fl->f) == NULL))
993 err = map(exports, "matches", 1, "none" , 1);
994 if (!err) err = map(exports, "final", 1, lookup(exports, "default"), 1);
996 free_current_action(action);
1002 return JB_ERR_MEMORY;
1005 return template_fill_for_cgi(csp, "show-url-info", exports, rsp);
1008 err = parse_http_url(url_param, url_to_query, csp);
1012 if (err == JB_ERR_MEMORY)
1014 free_current_action(action);
1016 return JB_ERR_MEMORY;
1022 err = map(exports, "matches", 1, "<b>[Invalid URL specified!]</b>" , 1);
1023 if (!err) err = map(exports, "final", 1, lookup(exports, "default"), 1);
1025 free_current_action(action);
1030 return JB_ERR_MEMORY;
1033 return template_fill_for_cgi(csp, "show-url-info", exports, rsp);
1037 * We have a warning about SSL paths. Hide it for insecure sites.
1039 if (!url_to_query->ssl)
1041 if (map_block_killer(exports, "https"))
1043 free_current_action(action);
1045 return JB_ERR_MEMORY;
1049 matches = strdup("");
1051 for (b = b->next; (b != NULL) && (matches != NULL); b = b->next)
1053 if (url_match(b->url, url_to_query))
1055 string_append(&matches, "<b>{");
1056 string_join (&matches, html_encode_and_free_original(
1057 actions_to_text(b->action)));
1058 string_append(&matches, " }</b><br>\n<code>");
1059 string_join (&matches, html_encode(b->url->spec));
1060 string_append(&matches, "</code><br>\n<br>\n");
1062 if (merge_current_action(action, b->action))
1065 free_http_request(url_to_query);
1066 free_current_action(action);
1068 return JB_ERR_MEMORY;
1074 free_http_request(url_to_query);
1076 if (matches == NULL)
1078 free_current_action(action);
1080 return JB_ERR_MEMORY;
1086 matches = strdup("none");
1088 if (map(exports, "matches", 1, matches , 0))
1090 free_current_action(action);
1092 return JB_ERR_MEMORY;
1095 s = html_encode_and_free_original(current_action_to_text(action));
1097 free_current_action(action);
1099 if (map(exports, "final", 1, s, 0))
1102 return JB_ERR_MEMORY;
1106 return template_fill_for_cgi(csp, "show-url-info", exports, rsp);
1110 /*********************************************************************
1112 * Function : cgi_robots_txt
1114 * Description : CGI function to return "/robots.txt".
1117 * 1 : csp = Current client state (buffers, headers, etc...)
1118 * 2 : rsp = http_response data structure for output
1119 * 3 : parameters = map of cgi parameters
1121 * CGI Parameters : None
1123 * Returns : JB_ERR_OK on success
1124 * JB_ERR_MEMORY on out-of-memory error.
1126 *********************************************************************/
1127 jb_err cgi_robots_txt(struct client_state *csp,
1128 struct http_response *rsp,
1129 const struct map *parameters)
1135 "# This is the Privoxy control interface.\n"
1136 "# It isn't very useful to index it, and you're likely to break stuff.\n"
1142 if (rsp->body == NULL)
1144 return JB_ERR_MEMORY;
1147 err = enlist_unique(rsp->headers, "Content-Type: text/plain", 13);
1151 get_http_time(7 * 24 * 60 * 60, buf); /* 7 days into future */
1152 if (!err) err = enlist_unique_header(rsp->headers, "Expires", buf);
1154 return (err ? JB_ERR_MEMORY : JB_ERR_OK);
1158 /*********************************************************************
1160 * Function : show_defines
1162 * Description : Add to a map the state od all conditional #defines
1163 * used when building
1166 * 1 : exports = map to extend
1168 * Returns : JB_ERR_OK on success
1169 * JB_ERR_MEMORY on out-of-memory error.
1171 *********************************************************************/
1172 static jb_err show_defines(struct map *exports)
1174 jb_err err = JB_ERR_OK;
1177 if (!err) err = map_conditional(exports, "FEATURE_ACL", 1);
1178 #else /* ifndef FEATURE_ACL */
1179 if (!err) err = map_conditional(exports, "FEATURE_ACL", 0);
1180 #endif /* ndef FEATURE_ACL */
1182 #ifdef FEATURE_CGI_EDIT_ACTIONS
1183 if (!err) err = map_conditional(exports, "FEATURE_CGI_EDIT_ACTIONS", 1);
1184 #else /* ifndef FEATURE_COOKIE_JAR */
1185 if (!err) err = map_conditional(exports, "FEATURE_CGI_EDIT_ACTIONS", 0);
1186 #endif /* ndef FEATURE_COOKIE_JAR */
1188 #ifdef FEATURE_COOKIE_JAR
1189 if (!err) err = map_conditional(exports, "FEATURE_COOKIE_JAR", 1);
1190 #else /* ifndef FEATURE_COOKIE_JAR */
1191 if (!err) err = map_conditional(exports, "FEATURE_COOKIE_JAR", 0);
1192 #endif /* ndef FEATURE_COOKIE_JAR */
1194 #ifdef FEATURE_FAST_REDIRECTS
1195 if (!err) err = map_conditional(exports, "FEATURE_FAST_REDIRECTS", 1);
1196 #else /* ifndef FEATURE_FAST_REDIRECTS */
1197 if (!err) err = map_conditional(exports, "FEATURE_FAST_REDIRECTS", 0);
1198 #endif /* ndef FEATURE_FAST_REDIRECTS */
1200 #ifdef FEATURE_FORCE_LOAD
1201 if (!err) err = map_conditional(exports, "FEATURE_FORCE_LOAD", 1);
1202 if (!err) err = map(exports, "FORCE_PREFIX", 1, FORCE_PREFIX, 1);
1203 #else /* ifndef FEATURE_FORCE_LOAD */
1204 if (!err) err = map_conditional(exports, "FEATURE_FORCE_LOAD", 0);
1205 if (!err) err = map(exports, "FORCE_PREFIX", 1, "(none - disabled)", 1);
1206 #endif /* ndef FEATURE_FORCE_LOAD */
1208 #ifdef FEATURE_IMAGE_BLOCKING
1209 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_BLOCKING", 1);
1210 #else /* ifndef FEATURE_IMAGE_BLOCKING */
1211 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_BLOCKING", 0);
1212 #endif /* ndef FEATURE_IMAGE_BLOCKING */
1214 #ifdef FEATURE_IMAGE_DETECT_MSIE
1215 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_DETECT_MSIE", 1);
1216 #else /* ifndef FEATURE_IMAGE_DETECT_MSIE */
1217 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_DETECT_MSIE", 0);
1218 #endif /* ndef FEATURE_IMAGE_DETECT_MSIE */
1220 #ifdef FEATURE_KILL_POPUPS
1221 if (!err) err = map_conditional(exports, "FEATURE_KILL_POPUPS", 1);
1222 #else /* ifndef FEATURE_KILL_POPUPS */
1223 if (!err) err = map_conditional(exports, "FEATURE_KILL_POPUPS", 0);
1224 #endif /* ndef FEATURE_KILL_POPUPS */
1226 #ifdef FEATURE_NO_GIFS
1227 if (!err) err = map_conditional(exports, "FEATURE_NO_GIFS", 1);
1228 #else /* ifndef FEATURE_NO_GIFS */
1229 if (!err) err = map_conditional(exports, "FEATURE_NO_GIFS", 0);
1230 #endif /* ndef FEATURE_NO_GIFS */
1232 #ifdef FEATURE_PTHREAD
1233 if (!err) err = map_conditional(exports, "FEATURE_PTHREAD", 1);
1234 #else /* ifndef FEATURE_PTHREAD */
1235 if (!err) err = map_conditional(exports, "FEATURE_PTHREAD", 0);
1236 #endif /* ndef FEATURE_PTHREAD */
1238 #ifdef FEATURE_STATISTICS
1239 if (!err) err = map_conditional(exports, "FEATURE_STATISTICS", 1);
1240 #else /* ifndef FEATURE_STATISTICS */
1241 if (!err) err = map_conditional(exports, "FEATURE_STATISTICS", 0);
1242 #endif /* ndef FEATURE_STATISTICS */
1244 #ifdef FEATURE_TOGGLE
1245 if (!err) err = map_conditional(exports, "FEATURE_TOGGLE", 1);
1246 #else /* ifndef FEATURE_TOGGLE */
1247 if (!err) err = map_conditional(exports, "FEATURE_TOGGLE", 0);
1248 #endif /* ndef FEATURE_TOGGLE */
1250 #ifdef FEATURE_TRUST
1251 if (!err) err = map_conditional(exports, "FEATURE_TRUST", 1);
1252 #else /* ifndef FEATURE_TRUST */
1253 if (!err) err = map_conditional(exports, "FEATURE_TRUST", 0);
1254 #endif /* ndef FEATURE_TRUST */
1257 if (!err) err = map_conditional(exports, "STATIC_PCRE", 1);
1258 #else /* ifndef STATIC_PCRE */
1259 if (!err) err = map_conditional(exports, "STATIC_PCRE", 0);
1260 #endif /* ndef STATIC_PCRE */
1263 if (!err) err = map_conditional(exports, "STATIC_PCRS", 1);
1264 #else /* ifndef STATIC_PCRS */
1265 if (!err) err = map_conditional(exports, "STATIC_PCRS", 0);
1266 #endif /* ndef STATIC_PCRS */
1272 /*********************************************************************
1274 * Function : show_rcs
1276 * Description : Create a string with the rcs info for all sourcefiles
1280 * Returns : A string, or NULL on out-of-memory.
1282 *********************************************************************/
1283 static char *show_rcs(void)
1285 char *result = strdup("");
1286 char buf[BUFFER_SIZE];
1288 /* Instead of including *all* dot h's in the project (thus creating a
1289 * tremendous amount of dependencies), I will concede to declaring them
1290 * as extern's. This forces the developer to add to this list, but oh well.
1293 #define SHOW_RCS(__x) \
1295 extern const char __x[]; \
1296 sprintf(buf, "%s\n", __x); \
1297 string_append(&result, buf); \
1300 /* In alphabetical order */
1301 SHOW_RCS(actions_h_rcs)
1302 SHOW_RCS(actions_rcs)
1305 #ifdef FEATURE_CGI_EDIT_ACTIONS
1306 SHOW_RCS(cgiedit_h_rcs)
1307 SHOW_RCS(cgiedit_rcs)
1308 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1309 SHOW_RCS(cgisimple_h_rcs)
1310 SHOW_RCS(cgisimple_rcs)
1312 SHOW_RCS(cygwin_h_rcs)
1314 SHOW_RCS(deanimate_h_rcs)
1315 SHOW_RCS(deanimate_rcs)
1316 SHOW_RCS(encode_h_rcs)
1317 SHOW_RCS(encode_rcs)
1318 SHOW_RCS(errlog_h_rcs)
1319 SHOW_RCS(errlog_rcs)
1320 SHOW_RCS(filters_h_rcs)
1321 SHOW_RCS(filters_rcs)
1322 SHOW_RCS(gateway_h_rcs)
1323 SHOW_RCS(gateway_rcs)
1324 SHOW_RCS(jbsockets_h_rcs)
1325 SHOW_RCS(jbsockets_rcs)
1328 #ifdef FEATURE_KILL_POPUPS
1329 SHOW_RCS(killpopup_h_rcs)
1330 SHOW_RCS(killpopup_rcs)
1331 #endif /* def FEATURE_KILL_POPUPS */
1332 SHOW_RCS(list_h_rcs)
1334 SHOW_RCS(loadcfg_h_rcs)
1335 SHOW_RCS(loadcfg_rcs)
1336 SHOW_RCS(loaders_h_rcs)
1337 SHOW_RCS(loaders_rcs)
1338 SHOW_RCS(miscutil_h_rcs)
1339 SHOW_RCS(miscutil_rcs)
1340 SHOW_RCS(parsers_h_rcs)
1341 SHOW_RCS(parsers_rcs)
1343 SHOW_RCS(pcrs_h_rcs)
1344 SHOW_RCS(project_h_rcs)
1345 SHOW_RCS(ssplit_h_rcs)
1346 SHOW_RCS(ssplit_rcs)
1347 SHOW_RCS(urlmatch_h_rcs)
1348 SHOW_RCS(urlmatch_rcs)
1350 #ifndef _WIN_CONSOLE
1351 SHOW_RCS(w32log_h_rcs)
1352 SHOW_RCS(w32log_rcs)
1353 SHOW_RCS(w32res_h_rcs)
1354 SHOW_RCS(w32taskbar_h_rcs)
1355 SHOW_RCS(w32taskbar_rcs)
1356 #endif /* ndef _WIN_CONSOLE */
1357 SHOW_RCS(win32_h_rcs)
1359 #endif /* def _WIN32 */