1 const char cgisimple_rcs[] = "$Id: cgisimple.c,v 1.50 2007/01/23 15:51:17 fabiankeil 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-2007 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.50 2007/01/23 15:51:17 fabiankeil
40 * Add favicon delivery functions.
42 * Revision 1.49 2007/01/20 16:29:38 fabiankeil
43 * Suppress edit buttons for action files if Privoxy has
44 * no write access. Suggested by Roland in PR 1564026.
46 * Revision 1.48 2007/01/20 15:31:31 fabiankeil
47 * Display warning if show-url-info CGI page
48 * is used while Privoxy is toggled off.
50 * Revision 1.47 2007/01/12 15:07:10 fabiankeil
51 * Use zalloc in cgi_send_user_manual.
53 * Revision 1.46 2007/01/02 12:49:46 fabiankeil
54 * Add FEATURE_ZLIB to the list of conditional
55 * defines at the show-status page.
57 * Revision 1.45 2006/12/28 18:16:41 fabiankeil
58 * Fixed gcc43 compiler warnings, zero out cgi_send_user_manual's
59 * body memory before using it, replaced sprintf calls with snprintf.
61 * Revision 1.44 2006/12/22 14:19:27 fabiankeil
62 * Removed checks whether or not AF_FILES have
63 * data structures associated with them in cgi_show_status.
64 * It doesn't matter as we're only interested in the file names.
66 * For the action files the checks were always true,
67 * but they prevented empty filter files from being
68 * listed. Fixes parts of BR 1619208.
70 * Revision 1.43 2006/12/17 17:57:56 fabiankeil
71 * - Added FEATURE_GRACEFUL_TERMINATION to the
72 * "conditional #defines" section
73 * - Escaped ampersands in generated HTML.
74 * - Renamed re-filter-filename to re-filter-filenames
76 * Revision 1.42 2006/11/21 15:43:12 fabiankeil
77 * Add special treatment for WIN32 to make sure
78 * cgi_send_user_manual opens the files in binary mode.
79 * Fixes BR 1600411 and unbreaks image delivery.
81 * Remove outdated comment.
83 * Revision 1.41 2006/10/09 19:18:28 roro
84 * Redirect http://p.p/user-manual (without trailing slash) to
85 * http://p.p/user-manual/ (with trailing slash), otherwise links will be broken.
87 * Revision 1.40 2006/09/09 13:05:33 fabiankeil
88 * Modified cgi_send_user_manual to serve binary
89 * content without destroying it first. Should also be
90 * faster now. Added ".jpg" check for Content-Type guessing.
92 * Revision 1.39 2006/09/08 09:49:23 fabiankeil
93 * Deliver documents in the user-manual directory
94 * with "Content-Type text/css" if their filename
97 * Revision 1.38 2006/09/06 18:45:03 fabiankeil
98 * Incorporate modified version of Roland Rosenfeld's patch to
99 * optionally access the user-manual via Privoxy. Closes patch 679075.
101 * Formatting changed to Privoxy style, added call to
102 * cgi_error_no_template if the requested file doesn't
103 * exist and modified check whether or not Privoxy itself
104 * should serve the manual. Should work cross-platform now.
106 * Revision 1.37 2006/07/18 14:48:45 david__schmidt
107 * Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
108 * with what was really the latest development (the v_3_0_branch branch)
110 * Revision 1.35.2.7 2006/01/29 23:10:56 david__schmidt
111 * Multiple filter file support
113 * Revision 1.35.2.6 2005/07/04 03:13:43 david__schmidt
114 * Undo some damaging memory leak patches
116 * Revision 1.35.2.5 2005/05/07 21:50:55 david__schmidt
117 * A few memory leaks plugged (mostly on error paths)
119 * Revision 1.35.2.4 2005/04/04 02:21:24 david__schmidt
120 * Another instance of:
121 * Don't show "Edit" buttons #ifndef FEATURE_CGI_EDIT_ACTIONS
122 * Thanks to Magnus Holmgren for the patch
124 * Revision 1.35.2.3 2003/12/17 16:34:15 oes
125 * - Prevent line wrap beween "View/Edit" link buttons on status page
126 * - Some (mostly irrelevant) fixes for Out-of-mem-case handling
128 * Revision 1.35.2.2 2003/04/03 13:48:28 oes
129 * Don't show "Edit" buttons #ifndef FEATURE_CGI_EDIT_ACTIONS
131 * Revision 1.35.2.1 2002/07/04 15:02:38 oes
132 * Added ability to send redirects to send-banner CGI, so that it can completely mimic the image blocking action if called with type=auto
134 * Revision 1.35.2.1 2002/07/01 17:32:04 morcego
135 * Applying patch from Andreas as provided by Hal on the list.
136 * Message-ID: <20020701121218.V1606@feenix.burgiss.net>
138 * Revision 1.35 2002/05/12 21:44:44 jongfoster
139 * Adding amiga.[ch] revision information, if on an amiga.
141 * Revision 1.34 2002/04/30 12:06:12 oes
142 * Deleted unused code from default_cgi
144 * Revision 1.33 2002/04/30 11:14:52 oes
145 * Made csp the first parameter in *action_to_html
147 * Revision 1.32 2002/04/26 18:29:13 jongfoster
148 * Fixing this Visual C++ warning:
149 * cgisimple.c(775) : warning C4018: '<' : signed/unsigned mismatch
151 * Revision 1.31 2002/04/26 12:54:36 oes
152 * - Kill obsolete REDIRECT_URL code
153 * - Error handling fixes
154 * - Style sheet related HTML snipplet changes
155 * - cgi_show_url_info:
156 * - Matches now in table, actions on single lines,
158 * - standard.action suppressed
159 * - Buttons to View and Edit AFs
161 * Revision 1.30 2002/04/24 02:18:08 oes
162 * - show-status is now the starting point for editing
163 * the actions files, generate list of all AFs with buttons
164 * for viewing and editing, new look for file list (Jon:
165 * buttons now aligned ;-P ), view mode now supports multiple
166 * AFs, name changes, no view links for unspecified files,
167 * no edit link for standard.action.
169 * - Jon's multiple AF patch: cgi_show_url_info now uses all
170 * AFs and marks the output accordingly
172 * Revision 1.29 2002/04/10 13:38:35 oes
173 * load_template signature changed
175 * Revision 1.28 2002/04/07 15:42:12 jongfoster
176 * Fixing send-banner?type=auto when the image-blocker is
177 * a redirect to send-banner
179 * Revision 1.27 2002/04/05 15:50:48 oes
180 * added send-stylesheet CGI
182 * Revision 1.26 2002/04/04 00:36:36 gliptak
183 * always use pcre for matching
185 * Revision 1.25 2002/04/03 22:28:03 gliptak
186 * Removed references to gnu_regex
188 * Revision 1.24 2002/04/02 16:12:47 oes
189 * Fix: moving misplaced lines into #ifdef FEATURE_FORCE
191 * Revision 1.23 2002/03/26 22:29:54 swa
192 * we have a new homepage!
194 * Revision 1.22 2002/03/24 16:18:15 jongfoster
197 * Revision 1.21 2002/03/24 15:23:33 jongfoster
200 * Revision 1.20 2002/03/24 13:25:43 swa
201 * name change related issues
203 * Revision 1.19 2002/03/16 23:54:06 jongfoster
204 * Adding graceful termination feature, to help look for memory leaks.
205 * If you enable this (which, by design, has to be done by hand
206 * editing config.h) and then go to http://i.j.b/die, then the program
207 * will exit cleanly after the *next* request. It should free all the
208 * memory that was used.
210 * Revision 1.18 2002/03/12 01:44:49 oes
211 * Changed default for "blocked" image from jb logo to checkboard pattern
213 * Revision 1.17 2002/03/08 16:43:18 oes
214 * Added choice beween GIF and PNG built-in images
216 * Revision 1.16 2002/03/07 03:48:38 oes
217 * - Changed built-in images from GIF to PNG
218 * (with regard to Unisys patent issue)
219 * - Added a 4x4 pattern PNG which is less intrusive
220 * than the logo but also clearly marks the deleted banners
222 * Revision 1.15 2002/03/06 22:54:35 jongfoster
223 * Automated function-comment nitpicking.
225 * Revision 1.14 2002/03/02 04:14:50 david__schmidt
226 * Clean up a little CRLF unpleasantness that suddenly appeared
228 * Revision 1.13 2002/02/21 00:10:37 jongfoster
229 * Adding send-banner?type=auto option
231 * Revision 1.12 2002/01/23 01:03:32 jongfoster
232 * Fixing gcc [CygWin] compiler warnings
234 * Revision 1.11 2002/01/23 00:01:04 jongfoster
235 * Adding cgi_transparent_gif() for http://i.j.b/t
236 * Adding missing html_encode() to many CGI functions.
237 * Adding urlmatch.[ch] to http://i.j.b/show-version
239 * Revision 1.10 2002/01/17 21:10:37 jongfoster
240 * Changes to cgi_show_url_info to use new matching code from urlmatch.c.
241 * Also fixing a problem in the same function with improperly quoted URLs
242 * in output HTML, and adding code to handle https:// URLs correctly.
244 * Revision 1.9 2001/11/30 23:09:15 jongfoster
245 * Now reports on FEATURE_CGI_EDIT_ACTIONS
246 * Removing FEATURE_DENY_GZIP from template
248 * Revision 1.8 2001/11/13 00:14:07 jongfoster
249 * Fixing stupid bug now I've figured out what || means.
250 * (It always returns 0 or 1, not one of it's paramaters.)
252 * Revision 1.7 2001/10/23 21:48:19 jongfoster
253 * Cleaning up error handling in CGI functions - they now send back
254 * a HTML error page and should never cause a FATAL error. (Fixes one
255 * potential source of "denial of service" attacks).
257 * CGI actions file editor that works and is actually useful.
259 * Ability to toggle JunkBuster remotely using a CGI call.
261 * You can turn off both the above features in the main configuration
262 * file, e.g. if you are running a multi-user proxy.
264 * Revision 1.6 2001/10/14 22:00:32 jongfoster
265 * Adding support for a 404 error when an invalid CGI page is requested.
267 * Revision 1.5 2001/10/07 15:30:41 oes
268 * Removed FEATURE_DENY_GZIP
270 * Revision 1.4 2001/10/02 15:31:12 oes
271 * Introduced show-request cgi
273 * Revision 1.3 2001/09/22 16:34:44 jongfoster
274 * Removing unneeded #includes
276 * Revision 1.2 2001/09/19 18:01:11 oes
277 * Fixed comments; cosmetics
279 * Revision 1.1 2001/09/16 17:08:54 jongfoster
280 * Moving simple CGI functions from cgi.c to new file cgisimple.c
283 **********************************************************************/
289 #include <sys/types.h>
297 #endif /* def HAVE_ACCESS */
300 #define snprintf _snprintf
301 #endif /* def _WIN32 */
305 #include "cgisimple.h"
311 #include "miscutil.h"
314 #include "urlmatch.h"
317 const char cgisimple_h_rcs[] = CGISIMPLE_H_VERSION;
320 static char *show_rcs(void);
321 static jb_err show_defines(struct map *exports);
324 * 16x16 ico blobs for favicon delivery functions.
326 const char default_favicon_data[] =
327 "\000\000\001\000\001\000\020\020\002\000\000\000\000\000\260"
328 "\000\000\000\026\000\000\000\050\000\000\000\020\000\000\000"
329 "\040\000\000\000\001\000\001\000\000\000\000\000\100\000\000"
330 "\000\000\000\000\000\000\000\000\000\002\000\000\000\000\000"
331 "\000\000\377\377\377\000\377\000\052\000\017\360\000\000\077"
332 "\374\000\000\161\376\000\000\161\376\000\000\361\377\000\000"
333 "\361\377\000\000\360\017\000\000\360\007\000\000\361\307\000"
334 "\000\361\307\000\000\361\307\000\000\360\007\000\000\160\036"
335 "\000\000\177\376\000\000\077\374\000\000\017\360\000\000\360"
336 "\017\000\000\300\003\000\000\200\001\000\000\200\001\000\000"
337 "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
338 "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
339 "\000\000\200\001\000\000\200\001\000\000\300\003\000\000\360"
341 const char error_favicon_data[] =
342 "\000\000\001\000\001\000\020\020\002\000\000\000\000\000\260"
343 "\000\000\000\026\000\000\000\050\000\000\000\020\000\000\000"
344 "\040\000\000\000\001\000\001\000\000\000\000\000\100\000\000"
345 "\000\000\000\000\000\000\000\000\000\002\000\000\000\000\000"
346 "\000\000\377\377\377\000\000\000\377\000\017\360\000\000\077"
347 "\374\000\000\161\376\000\000\161\376\000\000\361\377\000\000"
348 "\361\377\000\000\360\017\000\000\360\007\000\000\361\307\000"
349 "\000\361\307\000\000\361\307\000\000\360\007\000\000\160\036"
350 "\000\000\177\376\000\000\077\374\000\000\017\360\000\000\360"
351 "\017\000\000\300\003\000\000\200\001\000\000\200\001\000\000"
352 "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
353 "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
354 "\000\000\200\001\000\000\200\001\000\000\300\003\000\000\360"
356 const size_t default_favicon_length = sizeof(default_favicon_data) - 1;
357 const size_t error_favicon_length = sizeof(error_favicon_data) - 1;
359 /*********************************************************************
361 * Function : cgi_default
363 * Description : CGI function that is called for the CGI_SITE_1_HOST
364 * and CGI_SITE_2_HOST/CGI_SITE_2_PATH base URLs.
365 * Boring - only exports the default exports.
368 * 1 : csp = Current client state (buffers, headers, etc...)
369 * 2 : rsp = http_response data structure for output
370 * 3 : parameters = map of cgi parameters
372 * CGI Parameters : none
374 * Returns : JB_ERR_OK on success
375 * JB_ERR_MEMORY on out-of-memory
377 *********************************************************************/
378 jb_err cgi_default(struct client_state *csp,
379 struct http_response *rsp,
380 const struct map *parameters)
387 if (NULL == (exports = default_exports(csp, "")))
389 return JB_ERR_MEMORY;
392 return template_fill_for_cgi(csp, "default", exports, rsp);
396 /*********************************************************************
398 * Function : cgi_error_404
400 * Description : CGI function that is called if an unknown action was
404 * 1 : csp = Current client state (buffers, headers, etc...)
405 * 2 : rsp = http_response data structure for output
406 * 3 : parameters = map of cgi parameters
408 * CGI Parameters : none
410 * Returns : JB_ERR_OK on success
411 * JB_ERR_MEMORY on out-of-memory error.
413 *********************************************************************/
414 jb_err cgi_error_404(struct client_state *csp,
415 struct http_response *rsp,
416 const struct map *parameters)
424 if (NULL == (exports = default_exports(csp, NULL)))
426 return JB_ERR_MEMORY;
429 rsp->status = strdup("404 Privoxy configuration page not found");
430 if (rsp->status == NULL)
433 return JB_ERR_MEMORY;
436 return template_fill_for_cgi(csp, "cgi-error-404", exports, rsp);
440 #ifdef FEATURE_GRACEFUL_TERMINATION
441 /*********************************************************************
445 * Description : CGI function to shut down Privoxy.
446 * NOTE: Turning this on in a production build
447 * would be a BAD idea. An EXTREMELY BAD idea.
448 * In short, don't do it.
451 * 1 : csp = Current client state (buffers, headers, etc...)
452 * 2 : rsp = http_response data structure for output
453 * 3 : parameters = map of cgi parameters
455 * CGI Parameters : none
457 * Returns : JB_ERR_OK on success
458 * JB_ERR_MEMORY on out-of-memory error.
460 *********************************************************************/
461 jb_err cgi_die (struct client_state *csp,
462 struct http_response *rsp,
463 const struct map *parameters)
473 * I don't really care what gets sent back to the browser.
474 * Take the easy option - "out of memory" page.
477 return JB_ERR_MEMORY;
479 #endif /* def FEATURE_GRACEFUL_TERMINATION */
482 /*********************************************************************
484 * Function : cgi_show_request
486 * Description : Show the client's request and what sed() would have
490 * 1 : csp = Current client state (buffers, headers, etc...)
491 * 2 : rsp = http_response data structure for output
492 * 3 : parameters = map of cgi parameters
494 * CGI Parameters : none
496 * Returns : JB_ERR_OK on success
497 * JB_ERR_MEMORY on out-of-memory error.
499 *********************************************************************/
500 jb_err cgi_show_request(struct client_state *csp,
501 struct http_response *rsp,
502 const struct map *parameters)
511 if (NULL == (exports = default_exports(csp, "show-request")))
513 return JB_ERR_MEMORY;
517 * Repair the damage done to the IOB by get_header()
519 for (p = csp->iob->buf; p < csp->iob->eod; p++)
521 if (*p == '\0') *p = '\n';
525 * Export the original client's request and the one we would
526 * be sending to the server if this wasn't a CGI call
529 if (map(exports, "client-request", 1, html_encode(csp->iob->buf), 0))
532 return JB_ERR_MEMORY;
535 if (map(exports, "processed-request", 1, html_encode_and_free_original(
536 sed(client_patterns, add_client_headers, csp)), 0))
539 return JB_ERR_MEMORY;
542 return template_fill_for_cgi(csp, "show-request", exports, rsp);
546 /*********************************************************************
548 * Function : cgi_send_banner
550 * Description : CGI function that returns a banner.
553 * 1 : csp = Current client state (buffers, headers, etc...)
554 * 2 : rsp = http_response data structure for output
555 * 3 : parameters = map of cgi parameters
558 * type : Selects the type of banner between "trans", "logo",
559 * and "auto". Defaults to "logo" if absent or invalid.
560 * "auto" means to select as if we were image-blocking.
561 * (Only the first character really counts; b and t are
564 * Returns : JB_ERR_OK on success
565 * JB_ERR_MEMORY on out-of-memory error.
567 *********************************************************************/
568 jb_err cgi_send_banner(struct client_state *csp,
569 struct http_response *rsp,
570 const struct map *parameters)
572 char imagetype = lookup(parameters, "type")[0];
575 * If type is auto, then determine the right thing
576 * to do from the set-image-blocker action
578 if (imagetype == 'a')
585 #ifdef FEATURE_IMAGE_BLOCKING
586 if ((csp->action->flags & ACTION_IMAGE_BLOCKER) != 0)
588 static const char prefix1[] = CGI_PREFIX "send-banner?type=";
589 static const char prefix2[] = "http://" CGI_SITE_1_HOST "/send-banner?type=";
590 const char *p = csp->action->string[ACTION_STRING_IMAGE_BLOCKER];
594 /* Use default - nothing to do here. */
596 else if (0 == strcmpic(p, "blank"))
600 else if (0 == strcmpic(p, "pattern"))
606 * If the action is to call this CGI, determine
609 else if (0 == strncmpic(p, prefix1, sizeof(prefix1) - 1))
611 imagetype = p[sizeof(prefix1) - 1];
613 else if (0 == strncmpic(p, prefix2, sizeof(prefix2) - 1))
615 imagetype = p[sizeof(prefix2) - 1];
619 * Everything else must (should) be a URL to
627 #endif /* def FEATURE_IMAGE_BLOCKING */
631 * Now imagetype is either the non-auto type we were called with,
632 * or it was auto and has since been determined. In any case, we
633 * can proceed to actually answering the request by sending a redirect
634 * or an image as appropriate:
636 if (imagetype == 'r')
638 rsp->status = strdup("302 Local Redirect from Privoxy");
639 if (rsp->status == NULL)
641 return JB_ERR_MEMORY;
643 if (enlist_unique_header(rsp->headers, "Location",
644 csp->action->string[ACTION_STRING_IMAGE_BLOCKER]))
646 return JB_ERR_MEMORY;
651 if ((imagetype == 'b') || (imagetype == 't'))
653 rsp->body = bindup(image_blank_data, image_blank_length);
654 rsp->content_length = image_blank_length;
658 rsp->body = bindup(image_pattern_data, image_pattern_length);
659 rsp->content_length = image_pattern_length;
662 if (rsp->body == NULL)
664 return JB_ERR_MEMORY;
666 if (enlist(rsp->headers, "Content-Type: " BUILTIN_IMAGE_MIMETYPE))
668 return JB_ERR_MEMORY;
679 /*********************************************************************
681 * Function : cgi_transparent_image
683 * Description : CGI function that sends a 1x1 transparent image.
686 * 1 : csp = Current client state (buffers, headers, etc...)
687 * 2 : rsp = http_response data structure for output
688 * 3 : parameters = map of cgi parameters
690 * CGI Parameters : None
692 * Returns : JB_ERR_OK on success
693 * JB_ERR_MEMORY on out-of-memory error.
695 *********************************************************************/
696 jb_err cgi_transparent_image(struct client_state *csp,
697 struct http_response *rsp,
698 const struct map *parameters)
700 rsp->body = bindup(image_blank_data, image_blank_length);
701 rsp->content_length = image_blank_length;
703 if (rsp->body == NULL)
705 return JB_ERR_MEMORY;
708 if (enlist(rsp->headers, "Content-Type: " BUILTIN_IMAGE_MIMETYPE))
710 return JB_ERR_MEMORY;
720 /*********************************************************************
722 * Function : cgi_send_default_favicon
724 * Description : CGI function that sends the standard favicon.
727 * 1 : csp = Current client state (buffers, headers, etc...)
728 * 2 : rsp = http_response data structure for output
729 * 3 : parameters = map of cgi parameters
731 * CGI Parameters : None
733 * Returns : JB_ERR_OK on success
734 * JB_ERR_MEMORY on out-of-memory error.
736 *********************************************************************/
737 jb_err cgi_send_default_favicon(struct client_state *csp,
738 struct http_response *rsp,
739 const struct map *parameters)
741 rsp->body = bindup(default_favicon_data, default_favicon_length);
742 rsp->content_length = default_favicon_length;
744 if (rsp->body == NULL)
746 return JB_ERR_MEMORY;
749 if (enlist(rsp->headers, "Content-Type: image/x-icon"))
751 return JB_ERR_MEMORY;
761 /*********************************************************************
763 * Function : cgi_send_error_favicon
765 * Description : CGI function that sends the favicon for error pages.
768 * 1 : csp = Current client state (buffers, headers, etc...)
769 * 2 : rsp = http_response data structure for output
770 * 3 : parameters = map of cgi parameters
772 * CGI Parameters : None
774 * Returns : JB_ERR_OK on success
775 * JB_ERR_MEMORY on out-of-memory error.
777 *********************************************************************/
778 jb_err cgi_send_error_favicon(struct client_state *csp,
779 struct http_response *rsp,
780 const struct map *parameters)
782 rsp->body = bindup(error_favicon_data, error_favicon_length);
783 rsp->content_length = error_favicon_length;
785 if (rsp->body == NULL)
787 return JB_ERR_MEMORY;
790 if (enlist(rsp->headers, "Content-Type: image/x-icon"))
792 return JB_ERR_MEMORY;
802 /*********************************************************************
804 * Function : cgi_send_stylesheet
806 * Description : CGI function that sends a css stylesheet found
807 * in the cgi-style.css template
810 * 1 : csp = Current client state (buffers, headers, etc...)
811 * 2 : rsp = http_response data structure for output
812 * 3 : parameters = map of cgi parameters
814 * CGI Parameters : None
816 * Returns : JB_ERR_OK on success
817 * JB_ERR_MEMORY on out-of-memory error.
819 *********************************************************************/
820 jb_err cgi_send_stylesheet(struct client_state *csp,
821 struct http_response *rsp,
822 const struct map *parameters)
829 err = template_load(csp, &rsp->body, "cgi-style.css", 0);
831 if (err == JB_ERR_FILE)
834 * No way to tell user; send empty stylesheet
836 log_error(LOG_LEVEL_ERROR, "Could not find cgi-style.css template");
840 return err; /* JB_ERR_MEMORY */
843 if (enlist(rsp->headers, "Content-Type: text/css"))
845 return JB_ERR_MEMORY;
851 /*********************************************************************
853 * Function : cgi_send_user_manual
855 * Description : CGI function that sends a file in the user
859 * 1 : csp = Current client state (buffers, headers, etc...)
860 * 2 : rsp = http_response data structure for output
861 * 3 : parameters = map of cgi parameters
863 * CGI Parameters : file=name.html, the name of the HTML file
864 * (relative to user-manual from config)
866 * Returns : JB_ERR_OK on success
867 * JB_ERR_MEMORY on out-of-memory error.
869 *********************************************************************/
870 jb_err cgi_send_user_manual(struct client_state *csp,
871 struct http_response *rsp,
872 const struct map *parameters)
874 const char * filename;
877 jb_err err = JB_ERR_OK;
884 if (!parameters->first)
886 /* requested http://p.p/user-manual (without trailing slash) */
887 return cgi_redirect(rsp, CGI_PREFIX "user-manual/");
890 get_string_param(parameters, "file", &filename);
891 /* Check paramter for hack attempts */
892 if (filename && strchr(filename, '/'))
894 return JB_ERR_CGI_PARAMS;
896 if (filename && strstr(filename, ".."))
898 return JB_ERR_CGI_PARAMS;
901 full_path = make_path(csp->config->usermanual, filename ? filename : "index.html");
902 if (full_path == NULL)
904 return JB_ERR_MEMORY;
907 /* Open user-manual file */
910 * XXX: Do we support other operating systems that
911 * require special treatment to fopen in binary mode?
913 if (NULL == (fp = fopen(full_path, "rb")))
915 if (NULL == (fp = fopen(full_path, "r")))
916 #endif /* def WIN32 */
918 log_error(LOG_LEVEL_ERROR, "Cannot open user-manual file %s: %E", full_path);
919 err = cgi_error_no_template(csp, rsp, full_path);
924 /* Get file length */
925 fseek(fp, 0, SEEK_END);
926 length = (size_t)ftell(fp);
927 fseek(fp, 0, SEEK_SET);
929 /* Allocate memory and load the file directly into the body */
930 rsp->body = (char *)zalloc(length+1);
935 return JB_ERR_MEMORY;
937 if (!fread(rsp->body, length, 1, fp))
940 * This happens if we didn't fopen in binary mode.
941 * If it does, we just log it and serve what we got.
943 log_error(LOG_LEVEL_ERROR, "Couldn't completely read user-manual file %s.", full_path);
948 rsp->content_length = length;
950 /* Guess correct Content-Type based on the filename's ending */
953 length = strlen(filename);
959 if((length>=4) && !strcmp(&filename[length-4], ".css"))
961 err = enlist(rsp->headers, "Content-Type: text/css");
963 else if((length>=4) && !strcmp(&filename[length-4], ".jpg"))
965 err = enlist(rsp->headers, "Content-Type: image/jpeg");
969 err = enlist(rsp->headers, "Content-Type: text/html");
976 /*********************************************************************
978 * Function : cgi_show_version
980 * Description : CGI function that returns a a web page describing the
981 * file versions of Privoxy.
984 * 1 : csp = Current client state (buffers, headers, etc...)
985 * 2 : rsp = http_response data structure for output
986 * 3 : parameters = map of cgi parameters
988 * CGI Parameters : none
990 * Returns : JB_ERR_OK on success
991 * JB_ERR_MEMORY on out-of-memory error.
993 *********************************************************************/
994 jb_err cgi_show_version(struct client_state *csp,
995 struct http_response *rsp,
996 const struct map *parameters)
1004 if (NULL == (exports = default_exports(csp, "show-version")))
1006 return JB_ERR_MEMORY;
1009 if (map(exports, "sourceversions", 1, show_rcs(), 0))
1012 return JB_ERR_MEMORY;
1015 return template_fill_for_cgi(csp, "show-version", exports, rsp);
1019 /*********************************************************************
1021 * Function : cgi_show_status
1023 * Description : CGI function that returns a web page describing the
1024 * current status of Privoxy.
1027 * 1 : csp = Current client state (buffers, headers, etc...)
1028 * 2 : rsp = http_response data structure for output
1029 * 3 : parameters = map of cgi parameters
1032 * file : Which file to show. Only first letter is checked,
1034 * - "p"ermissions (actions) file
1037 * Default is to show menu and other information.
1039 * Returns : JB_ERR_OK on success
1040 * JB_ERR_MEMORY on out-of-memory error.
1042 *********************************************************************/
1043 jb_err cgi_show_status(struct client_state *csp,
1044 struct http_response *rsp,
1045 const struct map *parameters)
1052 char buf[BUFFER_SIZE];
1053 const char * filename = NULL;
1054 char * file_description = NULL;
1055 #ifdef FEATURE_STATISTICS
1056 float perc_rej; /* Percentage of http requests rejected */
1057 int local_urls_read;
1058 int local_urls_rejected;
1059 #endif /* ndef FEATURE_STATISTICS */
1060 jb_err err = JB_ERR_OK;
1062 struct map *exports;
1068 if (NULL == (exports = default_exports(csp, "show-status")))
1070 return JB_ERR_MEMORY;
1073 switch (*(lookup(parameters, "file")))
1076 if (!get_number_param(csp, parameters, "index", &i) && i < MAX_AF_FILES && csp->actions_list[i])
1078 filename = csp->actions_list[i]->filename;
1079 file_description = "Actions File";
1084 if (!get_number_param(csp, parameters, "index", &i) && i < MAX_AF_FILES && csp->rlist[i])
1086 filename = csp->rlist[i]->filename;
1087 file_description = "Filter File";
1091 #ifdef FEATURE_TRUST
1095 filename = csp->tlist->filename;
1096 file_description = "Trust File";
1099 #endif /* def FEATURE_TRUST */
1102 if (NULL != filename)
1104 if ( map(exports, "file-description", 1, file_description, 1)
1105 || map(exports, "filepath", 1, html_encode(filename), 0) )
1108 return JB_ERR_MEMORY;
1111 if ((fp = fopen(filename, "r")) == NULL)
1113 if (map(exports, "content", 1, "<h1>ERROR OPENING FILE!</h1>", 1))
1116 return JB_ERR_MEMORY;
1122 while ((s != NULL) && fgets(buf, sizeof(buf), fp))
1124 string_join (&s, html_encode(buf));
1128 if (map(exports, "contents", 1, s, 0))
1131 return JB_ERR_MEMORY;
1135 return template_fill_for_cgi(csp, "show-status-file", exports, rsp);
1139 for (j = 0; (s != NULL) && (j < Argc); j++)
1141 if (!err) err = string_join (&s, html_encode(Argv[j]));
1142 if (!err) err = string_append(&s, " ");
1144 if (!err) err = map(exports, "invocation", 1, s, 0);
1146 if (!err) err = map(exports, "options", 1, csp->config->proxy_args, 1);
1147 if (!err) err = show_defines(exports);
1152 return JB_ERR_MEMORY;
1155 #ifdef FEATURE_STATISTICS
1156 local_urls_read = urls_read;
1157 local_urls_rejected = urls_rejected;
1160 * Need to alter the stats not to include the fetch of this
1163 * Can't do following thread safely! doh!
1166 * urls_rejected--; * This will be incremented subsequently *
1169 if (local_urls_read == 0)
1171 if (!err) err = map_block_killer(exports, "have-stats");
1175 if (!err) err = map_block_killer(exports, "have-no-stats");
1177 perc_rej = (float)local_urls_rejected * 100.0F /
1178 (float)local_urls_read;
1180 snprintf(buf, sizeof(buf), "%d", local_urls_read);
1181 if (!err) err = map(exports, "requests-received", 1, buf, 1);
1183 snprintf(buf, sizeof(buf), "%d", local_urls_rejected);
1184 if (!err) err = map(exports, "requests-blocked", 1, buf, 1);
1186 snprintf(buf, sizeof(buf), "%6.2f", perc_rej);
1187 if (!err) err = map(exports, "percent-blocked", 1, buf, 1);
1190 #else /* ndef FEATURE_STATISTICS */
1191 err = err || map_block_killer(exports, "statistics");
1192 #endif /* ndef FEATURE_STATISTICS */
1195 * List all action files in use, together with view and edit links,
1196 * except for standard.action, which should only be viewable. (Not
1197 * enforced in the editor itself)
1198 * FIXME: Shouldn't include hardwired HTML here, use line template instead!
1201 for (i = 0; i < MAX_AF_FILES; i++)
1203 if (csp->actions_list[i] != NULL)
1205 if (!err) err = string_append(&s, "<tr><td>");
1206 if (!err) err = string_join(&s, html_encode(csp->actions_list[i]->filename));
1207 snprintf(buf, 100, "</td><td class=\"buttons\"><a href=\"/show-status?file=actions&index=%d\">View</a>", i);
1208 if (!err) err = string_append(&s, buf);
1210 #ifdef FEATURE_CGI_EDIT_ACTIONS
1211 if (NULL == strstr(csp->actions_list[i]->filename, "standard.action") && NULL != csp->config->actions_file_short[i])
1214 if (access(csp->config->actions_file[i], W_OK) == 0)
1216 #endif /* def HAVE_ACCESS */
1217 snprintf(buf, 100, " <a href=\"/edit-actions-list?f=%s\">Edit</a>",
1218 csp->config->actions_file_short[i]);
1219 if (!err) err = string_append(&s, buf);
1224 if (!err) err = string_append(&s, " <strong>No write access.</strong>");
1226 #endif /* def HAVE_ACCESS */
1230 if (!err) err = string_append(&s, "</td></tr>\n");
1235 if (!err) err = map(exports, "actions-filenames", 1, s, 0);
1239 if (!err) err = map(exports, "actions-filenames", 1, "<tr><td>None specified</td></tr>", 1);
1243 * List all re_filterfiles in use, together with view options.
1244 * FIXME: Shouldn't include hardwired HTML here, use line template instead!
1247 for (i = 0; i < MAX_AF_FILES; i++)
1249 if (csp->rlist[i] != NULL)
1251 if (!err) err = string_append(&s, "<tr><td>");
1252 if (!err) err = string_join(&s, html_encode(csp->rlist[i]->filename));
1254 "</td><td class=\"buttons\"><a href=\"/show-status?file=filter&index=%d\">View</a>", i);
1255 if (!err) err = string_append(&s, buf);
1256 if (!err) err = string_append(&s, "</td></tr>\n");
1261 if (!err) err = map(exports, "re-filter-filenames", 1, s, 0);
1265 if (!err) err = map(exports, "re-filter-filenames", 1, "<tr><td>None specified</td></tr>", 1);
1266 if (!err) err = map_block_killer(exports, "have-filterfile");
1269 #ifdef FEATURE_TRUST
1272 if (!err) err = map(exports, "trust-filename", 1, html_encode(csp->tlist->filename), 0);
1276 if (!err) err = map(exports, "trust-filename", 1, "None specified", 1);
1277 if (!err) err = map_block_killer(exports, "have-trustfile");
1280 if (!err) err = map_block_killer(exports, "trust-support");
1281 #endif /* ndef FEATURE_TRUST */
1286 return JB_ERR_MEMORY;
1289 return template_fill_for_cgi(csp, "show-status", exports, rsp);
1293 /*********************************************************************
1295 * Function : cgi_show_url_info
1297 * Description : CGI function that determines and shows which actions
1298 * Privoxy will perform for a given url, and which
1299 * matches starting from the defaults have lead to that.
1302 * 1 : csp = Current client state (buffers, headers, etc...)
1303 * 2 : rsp = http_response data structure for output
1304 * 3 : parameters = map of cgi parameters
1307 * url : The url whose actions are to be determined.
1308 * If url is unset, the url-given conditional will be
1309 * set, so that all but the form can be suppressed in
1312 * Returns : JB_ERR_OK on success
1313 * JB_ERR_MEMORY on out-of-memory error.
1315 *********************************************************************/
1316 jb_err cgi_show_url_info(struct client_state *csp,
1317 struct http_response *rsp,
1318 const struct map *parameters)
1321 struct map *exports;
1328 if (NULL == (exports = default_exports(csp, "show-url-info")))
1330 return JB_ERR_MEMORY;
1334 * Get the url= parameter (if present) and remove any leading/trailing spaces.
1336 url_param = strdup(lookup(parameters, "url"));
1337 if (url_param == NULL)
1340 return JB_ERR_MEMORY;
1345 * Handle prefixes. 4 possibilities:
1346 * 1) "http://" or "https://" prefix present and followed by URL - OK
1347 * 2) Only the "http://" or "https://" part is present, no URL - change
1348 * to empty string so it will be detected later as "no URL".
1349 * 3) Parameter specified but doesn't contain "http(s?)://" - add a
1351 * 4) Parameter not specified or is empty string - let this fall through
1352 * for now, next block of code will handle it.
1354 if (0 == strncmp(url_param, "http://", 7))
1356 if (url_param[7] == '\0')
1359 * Empty URL (just prefix).
1360 * Make it totally empty so it's caught by the next if()
1362 url_param[0] = '\0';
1365 else if (0 == strncmp(url_param, "https://", 8))
1367 if (url_param[8] == '\0')
1370 * Empty URL (just prefix).
1371 * Make it totally empty so it's caught by the next if()
1373 url_param[0] = '\0';
1376 else if (url_param[0] != '\0')
1379 * Unknown prefix - assume http://
1381 char * url_param_prefixed = malloc(7 + 1 + strlen(url_param));
1382 if (NULL == url_param_prefixed)
1386 return JB_ERR_MEMORY;
1388 strcpy(url_param_prefixed, "http://");
1389 strcpy(url_param_prefixed + 7, url_param);
1391 url_param = url_param_prefixed;
1395 * Hide "toggle off" warning if Privoxy is toggled on.
1398 #ifdef FEATURE_TOGGLE
1399 (global_toggle_state == 1) &&
1400 #endif /* def FEATURE_TOGGLE */
1401 map_block_killer(exports, "privoxy-is-toggled-off")
1405 return JB_ERR_MEMORY;
1408 if (url_param[0] == '\0')
1410 /* URL paramater not specified, display query form only. */
1412 if (map_block_killer(exports, "url-given")
1413 || map(exports, "url", 1, "", 1))
1416 return JB_ERR_MEMORY;
1421 /* Given a URL, so query it. */
1426 struct file_list *fl;
1427 struct url_actions *b;
1428 struct http_request url_to_query[1];
1429 struct current_action_spec action[1];
1432 if (map(exports, "url", 1, html_encode(url_param), 0))
1436 return JB_ERR_MEMORY;
1439 init_current_action(action);
1441 if (map(exports, "default", 1, current_action_to_html(csp, action), 0))
1443 free_current_action(action);
1446 return JB_ERR_MEMORY;
1449 err = parse_http_url(url_param, url_to_query, csp);
1453 if (err == JB_ERR_MEMORY)
1455 free_http_request(url_to_query);
1456 free_current_action(action);
1458 return JB_ERR_MEMORY;
1464 err = map(exports, "matches", 1, "<b>[Invalid URL specified!]</b>" , 1);
1465 if (!err) err = map(exports, "final", 1, lookup(exports, "default"), 1);
1467 free_current_action(action);
1468 free_http_request(url_to_query);
1473 return JB_ERR_MEMORY;
1476 return template_fill_for_cgi(csp, "show-url-info", exports, rsp);
1480 * We have a warning about SSL paths. Hide it for insecure sites.
1482 if (!url_to_query->ssl)
1484 if (map_block_killer(exports, "https"))
1486 free_current_action(action);
1488 free_http_request(url_to_query);
1489 return JB_ERR_MEMORY;
1493 matches = strdup("<table summary=\"\" class=\"transparent\">");
1495 for (i = 0; i < MAX_AF_FILES; i++)
1497 if (NULL == csp->config->actions_file_short[i]
1498 || !strcmp(csp->config->actions_file_short[i], "standard")) continue;
1502 if ((fl = csp->actions_list[i]) != NULL)
1504 if ((b = fl->f) != NULL)
1506 /* FIXME: Hardcoded HTML! */
1507 string_append(&matches, "<tr><th>In file: ");
1508 string_join (&matches, html_encode(csp->config->actions_file_short[i]));
1509 snprintf(buf, 150, ".action <a class=\"cmd\" href=\"/show-status?file=actions&index=%d\">", i);
1510 string_append(&matches, buf);
1511 string_append(&matches, "View</a>");
1512 #ifdef FEATURE_CGI_EDIT_ACTIONS
1513 string_append(&matches, " <a class=\"cmd\" href=\"/edit-actions-list?f=");
1514 string_join (&matches, html_encode(csp->config->actions_file_short[i]));
1515 string_append(&matches, "\">Edit</a>");
1517 string_append(&matches, "</th></tr>\n");
1524 for (; (b != NULL) && (matches != NULL); b = b->next)
1526 if (url_match(b->url, url_to_query))
1528 string_append(&matches, "<tr><td>{");
1529 string_join (&matches, actions_to_html(csp, b->action));
1530 string_append(&matches, " }<br>\n<code>");
1531 string_join (&matches, html_encode(b->url->spec));
1532 string_append(&matches, "</code></td></tr>\n");
1534 if (merge_current_action(action, b->action))
1537 free_http_request(url_to_query);
1538 free_current_action(action);
1540 return JB_ERR_MEMORY;
1548 string_append(&matches, "<tr><td>(no matches in this file)</td></tr>\n");
1551 string_append(&matches, "</table>\n");
1554 * Fill in forwarding settings.
1556 * The possibilities are:
1558 * - http forwarding only
1559 * - socks4(a) forwarding only
1560 * - socks4(a) and http forwarding.
1562 * XXX: Parts of this code could be reused for the
1563 * "forwarding-failed" template which currently doesn't
1564 * display the proxy port and an eventuell second forwarder.
1567 const struct forward_spec * fwd = forward_url(url_to_query, csp);
1569 if ((fwd->gateway_host == NULL) && (fwd->forward_host == NULL))
1571 if (!err) err = map_block_killer(exports, "socks-forwarder");
1572 if (!err) err = map_block_killer(exports, "http-forwarder");
1576 char port[10]; /* We save proxy ports as int but need a string here */
1578 if (!err) err = map_block_killer(exports, "no-forwarder");
1580 if (fwd->gateway_host != NULL)
1582 if (!err) err = map(exports, "socks-type", 1, (fwd->type == SOCKS_4) ?
1583 "socks4" : "socks4a", 1);
1584 if (!err) err = map(exports, "gateway-host", 1, fwd->gateway_host, 1);
1585 snprintf(port, sizeof(port), "%d", fwd->gateway_port);
1586 if (!err) err = map(exports, "gateway-port", 1, port, 1);
1590 if (!err) err = map_block_killer(exports, "socks-forwarder");
1593 if (fwd->forward_host != NULL)
1595 if (!err) err = map(exports, "forward-host", 1, fwd->forward_host, 1);
1596 snprintf(port, sizeof(port), "%d", fwd->forward_port);
1597 if (!err) err = map(exports, "forward-port", 1, port, 1);
1601 if (!err) err = map_block_killer(exports, "http-forwarder");
1606 free_http_request(url_to_query);
1608 if (err || matches == NULL)
1610 free_current_action(action);
1612 return JB_ERR_MEMORY;
1615 if (map(exports, "matches", 1, matches , 0))
1617 free_current_action(action);
1619 return JB_ERR_MEMORY;
1622 s = current_action_to_html(csp, action);
1624 free_current_action(action);
1626 if (map(exports, "final", 1, s, 0))
1629 return JB_ERR_MEMORY;
1633 return template_fill_for_cgi(csp, "show-url-info", exports, rsp);
1637 /*********************************************************************
1639 * Function : cgi_robots_txt
1641 * Description : CGI function to return "/robots.txt".
1644 * 1 : csp = Current client state (buffers, headers, etc...)
1645 * 2 : rsp = http_response data structure for output
1646 * 3 : parameters = map of cgi parameters
1648 * CGI Parameters : None
1650 * Returns : JB_ERR_OK on success
1651 * JB_ERR_MEMORY on out-of-memory error.
1653 *********************************************************************/
1654 jb_err cgi_robots_txt(struct client_state *csp,
1655 struct http_response *rsp,
1656 const struct map *parameters)
1662 "# This is the Privoxy control interface.\n"
1663 "# It isn't very useful to index it, and you're likely to break stuff.\n"
1669 if (rsp->body == NULL)
1671 return JB_ERR_MEMORY;
1674 err = enlist_unique(rsp->headers, "Content-Type: text/plain", 13);
1678 get_http_time(7 * 24 * 60 * 60, buf); /* 7 days into future */
1679 if (!err) err = enlist_unique_header(rsp->headers, "Expires", buf);
1681 return (err ? JB_ERR_MEMORY : JB_ERR_OK);
1685 /*********************************************************************
1687 * Function : show_defines
1689 * Description : Add to a map the state od all conditional #defines
1690 * used when building
1693 * 1 : exports = map to extend
1695 * Returns : JB_ERR_OK on success
1696 * JB_ERR_MEMORY on out-of-memory error.
1698 *********************************************************************/
1699 static jb_err show_defines(struct map *exports)
1701 jb_err err = JB_ERR_OK;
1704 if (!err) err = map_conditional(exports, "FEATURE_ACL", 1);
1705 #else /* ifndef FEATURE_ACL */
1706 if (!err) err = map_conditional(exports, "FEATURE_ACL", 0);
1707 #endif /* ndef FEATURE_ACL */
1709 #ifdef FEATURE_CGI_EDIT_ACTIONS
1710 if (!err) err = map_conditional(exports, "FEATURE_CGI_EDIT_ACTIONS", 1);
1711 #else /* ifndef FEATURE_COOKIE_JAR */
1712 if (!err) err = map_conditional(exports, "FEATURE_CGI_EDIT_ACTIONS", 0);
1713 #endif /* ndef FEATURE_COOKIE_JAR */
1715 #ifdef FEATURE_COOKIE_JAR
1716 if (!err) err = map_conditional(exports, "FEATURE_COOKIE_JAR", 1);
1717 #else /* ifndef FEATURE_COOKIE_JAR */
1718 if (!err) err = map_conditional(exports, "FEATURE_COOKIE_JAR", 0);
1719 #endif /* ndef FEATURE_COOKIE_JAR */
1721 #ifdef FEATURE_FAST_REDIRECTS
1722 if (!err) err = map_conditional(exports, "FEATURE_FAST_REDIRECTS", 1);
1723 #else /* ifndef FEATURE_FAST_REDIRECTS */
1724 if (!err) err = map_conditional(exports, "FEATURE_FAST_REDIRECTS", 0);
1725 #endif /* ndef FEATURE_FAST_REDIRECTS */
1727 #ifdef FEATURE_FORCE_LOAD
1728 if (!err) err = map_conditional(exports, "FEATURE_FORCE_LOAD", 1);
1729 if (!err) err = map(exports, "FORCE_PREFIX", 1, FORCE_PREFIX, 1);
1730 #else /* ifndef FEATURE_FORCE_LOAD */
1731 if (!err) err = map_conditional(exports, "FEATURE_FORCE_LOAD", 0);
1732 if (!err) err = map(exports, "FORCE_PREFIX", 1, "(none - disabled)", 1);
1733 #endif /* ndef FEATURE_FORCE_LOAD */
1735 #ifdef FEATURE_GRACEFUL_TERMINATION
1736 if (!err) err = map_conditional(exports, "FEATURE_GRACEFUL_TERMINATION", 1);
1737 #else /* ifndef FEATURE_GRACEFUL_TERMINATION */
1738 if (!err) err = map_conditional(exports, "FEATURE_GRACEFUL_TERMINATION", 0);
1739 #endif /* ndef FEATURE_GRACEFUL_TERMINATION */
1741 #ifdef FEATURE_IMAGE_BLOCKING
1742 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_BLOCKING", 1);
1743 #else /* ifndef FEATURE_IMAGE_BLOCKING */
1744 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_BLOCKING", 0);
1745 #endif /* ndef FEATURE_IMAGE_BLOCKING */
1747 #ifdef FEATURE_IMAGE_DETECT_MSIE
1748 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_DETECT_MSIE", 1);
1749 #else /* ifndef FEATURE_IMAGE_DETECT_MSIE */
1750 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_DETECT_MSIE", 0);
1751 #endif /* ndef FEATURE_IMAGE_DETECT_MSIE */
1753 #ifdef FEATURE_KILL_POPUPS
1754 if (!err) err = map_conditional(exports, "FEATURE_KILL_POPUPS", 1);
1755 #else /* ifndef FEATURE_KILL_POPUPS */
1756 if (!err) err = map_conditional(exports, "FEATURE_KILL_POPUPS", 0);
1757 #endif /* ndef FEATURE_KILL_POPUPS */
1759 #ifdef FEATURE_NO_GIFS
1760 if (!err) err = map_conditional(exports, "FEATURE_NO_GIFS", 1);
1761 #else /* ifndef FEATURE_NO_GIFS */
1762 if (!err) err = map_conditional(exports, "FEATURE_NO_GIFS", 0);
1763 #endif /* ndef FEATURE_NO_GIFS */
1765 #ifdef FEATURE_PTHREAD
1766 if (!err) err = map_conditional(exports, "FEATURE_PTHREAD", 1);
1767 #else /* ifndef FEATURE_PTHREAD */
1768 if (!err) err = map_conditional(exports, "FEATURE_PTHREAD", 0);
1769 #endif /* ndef FEATURE_PTHREAD */
1771 #ifdef FEATURE_STATISTICS
1772 if (!err) err = map_conditional(exports, "FEATURE_STATISTICS", 1);
1773 #else /* ifndef FEATURE_STATISTICS */
1774 if (!err) err = map_conditional(exports, "FEATURE_STATISTICS", 0);
1775 #endif /* ndef FEATURE_STATISTICS */
1777 #ifdef FEATURE_TOGGLE
1778 if (!err) err = map_conditional(exports, "FEATURE_TOGGLE", 1);
1779 #else /* ifndef FEATURE_TOGGLE */
1780 if (!err) err = map_conditional(exports, "FEATURE_TOGGLE", 0);
1781 #endif /* ndef FEATURE_TOGGLE */
1783 #ifdef FEATURE_TRUST
1784 if (!err) err = map_conditional(exports, "FEATURE_TRUST", 1);
1785 #else /* ifndef FEATURE_TRUST */
1786 if (!err) err = map_conditional(exports, "FEATURE_TRUST", 0);
1787 #endif /* ndef FEATURE_TRUST */
1790 if (!err) err = map_conditional(exports, "FEATURE_ZLIB", 1);
1791 #else /* ifndef FEATURE_ZLIB */
1792 if (!err) err = map_conditional(exports, "FEATURE_ZLIB", 0);
1793 #endif /* ndef FEATURE_ZLIB */
1796 if (!err) err = map_conditional(exports, "STATIC_PCRE", 1);
1797 #else /* ifndef STATIC_PCRE */
1798 if (!err) err = map_conditional(exports, "STATIC_PCRE", 0);
1799 #endif /* ndef STATIC_PCRE */
1802 if (!err) err = map_conditional(exports, "STATIC_PCRS", 1);
1803 #else /* ifndef STATIC_PCRS */
1804 if (!err) err = map_conditional(exports, "STATIC_PCRS", 0);
1805 #endif /* ndef STATIC_PCRS */
1811 /*********************************************************************
1813 * Function : show_rcs
1815 * Description : Create a string with the rcs info for all sourcefiles
1819 * Returns : A string, or NULL on out-of-memory.
1821 *********************************************************************/
1822 static char *show_rcs(void)
1824 char *result = strdup("");
1825 char buf[BUFFER_SIZE];
1827 /* Instead of including *all* dot h's in the project (thus creating a
1828 * tremendous amount of dependencies), I will concede to declaring them
1829 * as extern's. This forces the developer to add to this list, but oh well.
1832 #define SHOW_RCS(__x) \
1834 extern const char __x[]; \
1835 snprintf(buf, sizeof(buf), " %s\n", __x); \
1836 string_append(&result, buf); \
1839 /* In alphabetical order */
1840 SHOW_RCS(actions_h_rcs)
1841 SHOW_RCS(actions_rcs)
1843 SHOW_RCS(amiga_h_rcs)
1845 #endif /* def AMIGA */
1848 #ifdef FEATURE_CGI_EDIT_ACTIONS
1849 SHOW_RCS(cgiedit_h_rcs)
1850 SHOW_RCS(cgiedit_rcs)
1851 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1852 SHOW_RCS(cgisimple_h_rcs)
1853 SHOW_RCS(cgisimple_rcs)
1855 SHOW_RCS(cygwin_h_rcs)
1857 SHOW_RCS(deanimate_h_rcs)
1858 SHOW_RCS(deanimate_rcs)
1859 SHOW_RCS(encode_h_rcs)
1860 SHOW_RCS(encode_rcs)
1861 SHOW_RCS(errlog_h_rcs)
1862 SHOW_RCS(errlog_rcs)
1863 SHOW_RCS(filters_h_rcs)
1864 SHOW_RCS(filters_rcs)
1865 SHOW_RCS(gateway_h_rcs)
1866 SHOW_RCS(gateway_rcs)
1867 SHOW_RCS(jbsockets_h_rcs)
1868 SHOW_RCS(jbsockets_rcs)
1871 #ifdef FEATURE_KILL_POPUPS
1872 SHOW_RCS(killpopup_h_rcs)
1873 SHOW_RCS(killpopup_rcs)
1874 #endif /* def FEATURE_KILL_POPUPS */
1875 SHOW_RCS(list_h_rcs)
1877 SHOW_RCS(loadcfg_h_rcs)
1878 SHOW_RCS(loadcfg_rcs)
1879 SHOW_RCS(loaders_h_rcs)
1880 SHOW_RCS(loaders_rcs)
1881 SHOW_RCS(miscutil_h_rcs)
1882 SHOW_RCS(miscutil_rcs)
1883 SHOW_RCS(parsers_h_rcs)
1884 SHOW_RCS(parsers_rcs)
1886 SHOW_RCS(pcrs_h_rcs)
1887 SHOW_RCS(project_h_rcs)
1888 SHOW_RCS(ssplit_h_rcs)
1889 SHOW_RCS(ssplit_rcs)
1890 SHOW_RCS(urlmatch_h_rcs)
1891 SHOW_RCS(urlmatch_rcs)
1893 #ifndef _WIN_CONSOLE
1894 SHOW_RCS(w32log_h_rcs)
1895 SHOW_RCS(w32log_rcs)
1896 SHOW_RCS(w32res_h_rcs)
1897 SHOW_RCS(w32taskbar_h_rcs)
1898 SHOW_RCS(w32taskbar_rcs)
1899 #endif /* ndef _WIN_CONSOLE */
1900 SHOW_RCS(win32_h_rcs)
1902 #endif /* def _WIN32 */