1 const char cgisimple_rcs[] = "$Id: cgisimple.c,v 1.61 2008/01/26 11:13:25 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.61 2008/01/26 11:13:25 fabiankeil
40 * If enable-edit-actions is disabled, hide the edit buttons and explain why.
42 * Revision 1.60 2007/10/27 13:12:13 fabiankeil
43 * Finish 1.49 and check write access before
44 * showing edit buttons on show-url-info page.
46 * Revision 1.59 2007/10/19 16:42:36 fabiankeil
47 * Plug memory leak I introduced five months ago.
48 * Yay Valgrind and Privoxy-Regression-Test.
50 * Revision 1.58 2007/07/21 12:19:50 fabiankeil
51 * If show-url-info is called with an URL that Privoxy
52 * would reject as invalid, don't show unresolved forwarding
53 * variables, "final matches" or claim the site's secure.
55 * Revision 1.57 2007/06/01 16:53:05 fabiankeil
56 * Adjust cgi_show_url_info() to show what forward-override{}
57 * would do with the requested URL (instead of showing how the
58 * request for the CGI page would be forwarded if it wasn't a
61 * Revision 1.56 2007/05/21 10:50:35 fabiankeil
62 * - Use strlcpy() instead of strcpy().
63 * - Stop treating actions files special. Expect a complete file name
64 * (with or without path) like it's done for the rest of the files.
66 * - Don't rerun sed() in cgi_show_request().
68 * Revision 1.55 2007/04/13 13:36:46 fabiankeil
69 * Reference action files in CGI URLs by id instead
70 * of using the first part of the file name.
71 * Fixes BR 1694250 and BR 1590556.
73 * Revision 1.54 2007/04/09 18:11:35 fabiankeil
74 * Don't mistake VC++'s _snprintf() for a snprintf() replacement.
76 * Revision 1.53 2007/04/08 13:21:04 fabiankeil
77 * Reference action files in CGI URLs by id instead
78 * of using the first part of the file name.
79 * Fixes BR 1694250 and BR 1590556.
81 * Revision 1.52 2007/02/13 15:10:26 fabiankeil
82 * Apparently fopen()ing in "binary" mode doesn't require
83 * #ifdefs, it's already done without them in cgiedit.c.
85 * Revision 1.51 2007/02/10 16:55:22 fabiankeil
86 * - Show forwarding settings on the show-url-info page
87 * - Fix some HTML syntax errors.
89 * Revision 1.50 2007/01/23 15:51:17 fabiankeil
90 * Add favicon delivery functions.
92 * Revision 1.49 2007/01/20 16:29:38 fabiankeil
93 * Suppress edit buttons for action files if Privoxy has
94 * no write access. Suggested by Roland in PR 1564026.
96 * Revision 1.48 2007/01/20 15:31:31 fabiankeil
97 * Display warning if show-url-info CGI page
98 * is used while Privoxy is toggled off.
100 * Revision 1.47 2007/01/12 15:07:10 fabiankeil
101 * Use zalloc in cgi_send_user_manual.
103 * Revision 1.46 2007/01/02 12:49:46 fabiankeil
104 * Add FEATURE_ZLIB to the list of conditional
105 * defines at the show-status page.
107 * Revision 1.45 2006/12/28 18:16:41 fabiankeil
108 * Fixed gcc43 compiler warnings, zero out cgi_send_user_manual's
109 * body memory before using it, replaced sprintf calls with snprintf.
111 * Revision 1.44 2006/12/22 14:19:27 fabiankeil
112 * Removed checks whether or not AF_FILES have
113 * data structures associated with them in cgi_show_status.
114 * It doesn't matter as we're only interested in the file names.
116 * For the action files the checks were always true,
117 * but they prevented empty filter files from being
118 * listed. Fixes parts of BR 1619208.
120 * Revision 1.43 2006/12/17 17:57:56 fabiankeil
121 * - Added FEATURE_GRACEFUL_TERMINATION to the
122 * "conditional #defines" section
123 * - Escaped ampersands in generated HTML.
124 * - Renamed re-filter-filename to re-filter-filenames
126 * Revision 1.42 2006/11/21 15:43:12 fabiankeil
127 * Add special treatment for WIN32 to make sure
128 * cgi_send_user_manual opens the files in binary mode.
129 * Fixes BR 1600411 and unbreaks image delivery.
131 * Remove outdated comment.
133 * Revision 1.41 2006/10/09 19:18:28 roro
134 * Redirect http://p.p/user-manual (without trailing slash) to
135 * http://p.p/user-manual/ (with trailing slash), otherwise links will be broken.
137 * Revision 1.40 2006/09/09 13:05:33 fabiankeil
138 * Modified cgi_send_user_manual to serve binary
139 * content without destroying it first. Should also be
140 * faster now. Added ".jpg" check for Content-Type guessing.
142 * Revision 1.39 2006/09/08 09:49:23 fabiankeil
143 * Deliver documents in the user-manual directory
144 * with "Content-Type text/css" if their filename
147 * Revision 1.38 2006/09/06 18:45:03 fabiankeil
148 * Incorporate modified version of Roland Rosenfeld's patch to
149 * optionally access the user-manual via Privoxy. Closes patch 679075.
151 * Formatting changed to Privoxy style, added call to
152 * cgi_error_no_template if the requested file doesn't
153 * exist and modified check whether or not Privoxy itself
154 * should serve the manual. Should work cross-platform now.
156 * Revision 1.37 2006/07/18 14:48:45 david__schmidt
157 * Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
158 * with what was really the latest development (the v_3_0_branch branch)
160 * Revision 1.35.2.7 2006/01/29 23:10:56 david__schmidt
161 * Multiple filter file support
163 * Revision 1.35.2.6 2005/07/04 03:13:43 david__schmidt
164 * Undo some damaging memory leak patches
166 * Revision 1.35.2.5 2005/05/07 21:50:55 david__schmidt
167 * A few memory leaks plugged (mostly on error paths)
169 * Revision 1.35.2.4 2005/04/04 02:21:24 david__schmidt
170 * Another instance of:
171 * Don't show "Edit" buttons #ifndef FEATURE_CGI_EDIT_ACTIONS
172 * Thanks to Magnus Holmgren for the patch
174 * Revision 1.35.2.3 2003/12/17 16:34:15 oes
175 * - Prevent line wrap beween "View/Edit" link buttons on status page
176 * - Some (mostly irrelevant) fixes for Out-of-mem-case handling
178 * Revision 1.35.2.2 2003/04/03 13:48:28 oes
179 * Don't show "Edit" buttons #ifndef FEATURE_CGI_EDIT_ACTIONS
181 * Revision 1.35.2.1 2002/07/04 15:02:38 oes
182 * Added ability to send redirects to send-banner CGI, so that it can completely mimic the image blocking action if called with type=auto
184 * Revision 1.35.2.1 2002/07/01 17:32:04 morcego
185 * Applying patch from Andreas as provided by Hal on the list.
186 * Message-ID: <20020701121218.V1606@feenix.burgiss.net>
188 * Revision 1.35 2002/05/12 21:44:44 jongfoster
189 * Adding amiga.[ch] revision information, if on an amiga.
191 * Revision 1.34 2002/04/30 12:06:12 oes
192 * Deleted unused code from default_cgi
194 * Revision 1.33 2002/04/30 11:14:52 oes
195 * Made csp the first parameter in *action_to_html
197 * Revision 1.32 2002/04/26 18:29:13 jongfoster
198 * Fixing this Visual C++ warning:
199 * cgisimple.c(775) : warning C4018: '<' : signed/unsigned mismatch
201 * Revision 1.31 2002/04/26 12:54:36 oes
202 * - Kill obsolete REDIRECT_URL code
203 * - Error handling fixes
204 * - Style sheet related HTML snipplet changes
205 * - cgi_show_url_info:
206 * - Matches now in table, actions on single lines,
208 * - standard.action suppressed
209 * - Buttons to View and Edit AFs
211 * Revision 1.30 2002/04/24 02:18:08 oes
212 * - show-status is now the starting point for editing
213 * the actions files, generate list of all AFs with buttons
214 * for viewing and editing, new look for file list (Jon:
215 * buttons now aligned ;-P ), view mode now supports multiple
216 * AFs, name changes, no view links for unspecified files,
217 * no edit link for standard.action.
219 * - Jon's multiple AF patch: cgi_show_url_info now uses all
220 * AFs and marks the output accordingly
222 * Revision 1.29 2002/04/10 13:38:35 oes
223 * load_template signature changed
225 * Revision 1.28 2002/04/07 15:42:12 jongfoster
226 * Fixing send-banner?type=auto when the image-blocker is
227 * a redirect to send-banner
229 * Revision 1.27 2002/04/05 15:50:48 oes
230 * added send-stylesheet CGI
232 * Revision 1.26 2002/04/04 00:36:36 gliptak
233 * always use pcre for matching
235 * Revision 1.25 2002/04/03 22:28:03 gliptak
236 * Removed references to gnu_regex
238 * Revision 1.24 2002/04/02 16:12:47 oes
239 * Fix: moving misplaced lines into #ifdef FEATURE_FORCE
241 * Revision 1.23 2002/03/26 22:29:54 swa
242 * we have a new homepage!
244 * Revision 1.22 2002/03/24 16:18:15 jongfoster
247 * Revision 1.21 2002/03/24 15:23:33 jongfoster
250 * Revision 1.20 2002/03/24 13:25:43 swa
251 * name change related issues
253 * Revision 1.19 2002/03/16 23:54:06 jongfoster
254 * Adding graceful termination feature, to help look for memory leaks.
255 * If you enable this (which, by design, has to be done by hand
256 * editing config.h) and then go to http://i.j.b/die, then the program
257 * will exit cleanly after the *next* request. It should free all the
258 * memory that was used.
260 * Revision 1.18 2002/03/12 01:44:49 oes
261 * Changed default for "blocked" image from jb logo to checkboard pattern
263 * Revision 1.17 2002/03/08 16:43:18 oes
264 * Added choice beween GIF and PNG built-in images
266 * Revision 1.16 2002/03/07 03:48:38 oes
267 * - Changed built-in images from GIF to PNG
268 * (with regard to Unisys patent issue)
269 * - Added a 4x4 pattern PNG which is less intrusive
270 * than the logo but also clearly marks the deleted banners
272 * Revision 1.15 2002/03/06 22:54:35 jongfoster
273 * Automated function-comment nitpicking.
275 * Revision 1.14 2002/03/02 04:14:50 david__schmidt
276 * Clean up a little CRLF unpleasantness that suddenly appeared
278 * Revision 1.13 2002/02/21 00:10:37 jongfoster
279 * Adding send-banner?type=auto option
281 * Revision 1.12 2002/01/23 01:03:32 jongfoster
282 * Fixing gcc [CygWin] compiler warnings
284 * Revision 1.11 2002/01/23 00:01:04 jongfoster
285 * Adding cgi_transparent_gif() for http://i.j.b/t
286 * Adding missing html_encode() to many CGI functions.
287 * Adding urlmatch.[ch] to http://i.j.b/show-version
289 * Revision 1.10 2002/01/17 21:10:37 jongfoster
290 * Changes to cgi_show_url_info to use new matching code from urlmatch.c.
291 * Also fixing a problem in the same function with improperly quoted URLs
292 * in output HTML, and adding code to handle https:// URLs correctly.
294 * Revision 1.9 2001/11/30 23:09:15 jongfoster
295 * Now reports on FEATURE_CGI_EDIT_ACTIONS
296 * Removing FEATURE_DENY_GZIP from template
298 * Revision 1.8 2001/11/13 00:14:07 jongfoster
299 * Fixing stupid bug now I've figured out what || means.
300 * (It always returns 0 or 1, not one of it's paramaters.)
302 * Revision 1.7 2001/10/23 21:48:19 jongfoster
303 * Cleaning up error handling in CGI functions - they now send back
304 * a HTML error page and should never cause a FATAL error. (Fixes one
305 * potential source of "denial of service" attacks).
307 * CGI actions file editor that works and is actually useful.
309 * Ability to toggle JunkBuster remotely using a CGI call.
311 * You can turn off both the above features in the main configuration
312 * file, e.g. if you are running a multi-user proxy.
314 * Revision 1.6 2001/10/14 22:00:32 jongfoster
315 * Adding support for a 404 error when an invalid CGI page is requested.
317 * Revision 1.5 2001/10/07 15:30:41 oes
318 * Removed FEATURE_DENY_GZIP
320 * Revision 1.4 2001/10/02 15:31:12 oes
321 * Introduced show-request cgi
323 * Revision 1.3 2001/09/22 16:34:44 jongfoster
324 * Removing unneeded #includes
326 * Revision 1.2 2001/09/19 18:01:11 oes
327 * Fixed comments; cosmetics
329 * Revision 1.1 2001/09/16 17:08:54 jongfoster
330 * Moving simple CGI functions from cgi.c to new file cgisimple.c
333 **********************************************************************/
339 #include <sys/types.h>
347 #endif /* def HAVE_ACCESS */
351 #include "cgisimple.h"
357 #include "miscutil.h"
360 #include "urlmatch.h"
363 const char cgisimple_h_rcs[] = CGISIMPLE_H_VERSION;
366 static char *show_rcs(void);
367 static jb_err show_defines(struct map *exports);
370 * 16x16 ico blobs for favicon delivery functions.
372 const char default_favicon_data[] =
373 "\000\000\001\000\001\000\020\020\002\000\000\000\000\000\260"
374 "\000\000\000\026\000\000\000\050\000\000\000\020\000\000\000"
375 "\040\000\000\000\001\000\001\000\000\000\000\000\100\000\000"
376 "\000\000\000\000\000\000\000\000\000\002\000\000\000\000\000"
377 "\000\000\377\377\377\000\377\000\052\000\017\360\000\000\077"
378 "\374\000\000\161\376\000\000\161\376\000\000\361\377\000\000"
379 "\361\377\000\000\360\017\000\000\360\007\000\000\361\307\000"
380 "\000\361\307\000\000\361\307\000\000\360\007\000\000\160\036"
381 "\000\000\177\376\000\000\077\374\000\000\017\360\000\000\360"
382 "\017\000\000\300\003\000\000\200\001\000\000\200\001\000\000"
383 "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
384 "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
385 "\000\000\200\001\000\000\200\001\000\000\300\003\000\000\360"
387 const char error_favicon_data[] =
388 "\000\000\001\000\001\000\020\020\002\000\000\000\000\000\260"
389 "\000\000\000\026\000\000\000\050\000\000\000\020\000\000\000"
390 "\040\000\000\000\001\000\001\000\000\000\000\000\100\000\000"
391 "\000\000\000\000\000\000\000\000\000\002\000\000\000\000\000"
392 "\000\000\377\377\377\000\000\000\377\000\017\360\000\000\077"
393 "\374\000\000\161\376\000\000\161\376\000\000\361\377\000\000"
394 "\361\377\000\000\360\017\000\000\360\007\000\000\361\307\000"
395 "\000\361\307\000\000\361\307\000\000\360\007\000\000\160\036"
396 "\000\000\177\376\000\000\077\374\000\000\017\360\000\000\360"
397 "\017\000\000\300\003\000\000\200\001\000\000\200\001\000\000"
398 "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
399 "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
400 "\000\000\200\001\000\000\200\001\000\000\300\003\000\000\360"
402 const size_t default_favicon_length = sizeof(default_favicon_data) - 1;
403 const size_t error_favicon_length = sizeof(error_favicon_data) - 1;
405 /*********************************************************************
407 * Function : cgi_default
409 * Description : CGI function that is called for the CGI_SITE_1_HOST
410 * and CGI_SITE_2_HOST/CGI_SITE_2_PATH base URLs.
411 * Boring - only exports the default exports.
414 * 1 : csp = Current client state (buffers, headers, etc...)
415 * 2 : rsp = http_response data structure for output
416 * 3 : parameters = map of cgi parameters
418 * CGI Parameters : none
420 * Returns : JB_ERR_OK on success
421 * JB_ERR_MEMORY on out-of-memory
423 *********************************************************************/
424 jb_err cgi_default(struct client_state *csp,
425 struct http_response *rsp,
426 const struct map *parameters)
433 if (NULL == (exports = default_exports(csp, "")))
435 return JB_ERR_MEMORY;
438 return template_fill_for_cgi(csp, "default", exports, rsp);
442 /*********************************************************************
444 * Function : cgi_error_404
446 * Description : CGI function that is called if an unknown action was
450 * 1 : csp = Current client state (buffers, headers, etc...)
451 * 2 : rsp = http_response data structure for output
452 * 3 : parameters = map of cgi parameters
454 * CGI Parameters : none
456 * Returns : JB_ERR_OK on success
457 * JB_ERR_MEMORY on out-of-memory error.
459 *********************************************************************/
460 jb_err cgi_error_404(struct client_state *csp,
461 struct http_response *rsp,
462 const struct map *parameters)
470 if (NULL == (exports = default_exports(csp, NULL)))
472 return JB_ERR_MEMORY;
475 rsp->status = strdup("404 Privoxy configuration page not found");
476 if (rsp->status == NULL)
479 return JB_ERR_MEMORY;
482 return template_fill_for_cgi(csp, "cgi-error-404", exports, rsp);
486 #ifdef FEATURE_GRACEFUL_TERMINATION
487 /*********************************************************************
491 * Description : CGI function to shut down Privoxy.
492 * NOTE: Turning this on in a production build
493 * would be a BAD idea. An EXTREMELY BAD idea.
494 * In short, don't do it.
497 * 1 : csp = Current client state (buffers, headers, etc...)
498 * 2 : rsp = http_response data structure for output
499 * 3 : parameters = map of cgi parameters
501 * CGI Parameters : none
503 * Returns : JB_ERR_OK on success
504 * JB_ERR_MEMORY on out-of-memory error.
506 *********************************************************************/
507 jb_err cgi_die (struct client_state *csp,
508 struct http_response *rsp,
509 const struct map *parameters)
519 * I don't really care what gets sent back to the browser.
520 * Take the easy option - "out of memory" page.
523 return JB_ERR_MEMORY;
525 #endif /* def FEATURE_GRACEFUL_TERMINATION */
528 /*********************************************************************
530 * Function : cgi_show_request
532 * Description : Show the client's request and what sed() would have
536 * 1 : csp = Current client state (buffers, headers, etc...)
537 * 2 : rsp = http_response data structure for output
538 * 3 : parameters = map of cgi parameters
540 * CGI Parameters : none
542 * Returns : JB_ERR_OK on success
543 * JB_ERR_MEMORY on out-of-memory error.
545 *********************************************************************/
546 jb_err cgi_show_request(struct client_state *csp,
547 struct http_response *rsp,
548 const struct map *parameters)
557 if (NULL == (exports = default_exports(csp, "show-request")))
559 return JB_ERR_MEMORY;
563 * Repair the damage done to the IOB by get_header()
565 for (p = csp->iob->buf; p < csp->iob->eod; p++)
567 if (*p == '\0') *p = '\n';
571 * Export the original client's request and the one we would
572 * be sending to the server if this wasn't a CGI call
575 if (map(exports, "client-request", 1, html_encode(csp->iob->buf), 0))
578 return JB_ERR_MEMORY;
581 if (map(exports, "processed-request", 1,
582 html_encode_and_free_original(list_to_text(csp->headers)), 0))
585 return JB_ERR_MEMORY;
588 return template_fill_for_cgi(csp, "show-request", exports, rsp);
592 /*********************************************************************
594 * Function : cgi_send_banner
596 * Description : CGI function that returns a banner.
599 * 1 : csp = Current client state (buffers, headers, etc...)
600 * 2 : rsp = http_response data structure for output
601 * 3 : parameters = map of cgi parameters
604 * type : Selects the type of banner between "trans", "logo",
605 * and "auto". Defaults to "logo" if absent or invalid.
606 * "auto" means to select as if we were image-blocking.
607 * (Only the first character really counts; b and t are
610 * Returns : JB_ERR_OK on success
611 * JB_ERR_MEMORY on out-of-memory error.
613 *********************************************************************/
614 jb_err cgi_send_banner(struct client_state *csp,
615 struct http_response *rsp,
616 const struct map *parameters)
618 char imagetype = lookup(parameters, "type")[0];
621 * If type is auto, then determine the right thing
622 * to do from the set-image-blocker action
624 if (imagetype == 'a')
631 #ifdef FEATURE_IMAGE_BLOCKING
632 if ((csp->action->flags & ACTION_IMAGE_BLOCKER) != 0)
634 static const char prefix1[] = CGI_PREFIX "send-banner?type=";
635 static const char prefix2[] = "http://" CGI_SITE_1_HOST "/send-banner?type=";
636 const char *p = csp->action->string[ACTION_STRING_IMAGE_BLOCKER];
640 /* Use default - nothing to do here. */
642 else if (0 == strcmpic(p, "blank"))
646 else if (0 == strcmpic(p, "pattern"))
652 * If the action is to call this CGI, determine
655 else if (0 == strncmpic(p, prefix1, sizeof(prefix1) - 1))
657 imagetype = p[sizeof(prefix1) - 1];
659 else if (0 == strncmpic(p, prefix2, sizeof(prefix2) - 1))
661 imagetype = p[sizeof(prefix2) - 1];
665 * Everything else must (should) be a URL to
673 #endif /* def FEATURE_IMAGE_BLOCKING */
677 * Now imagetype is either the non-auto type we were called with,
678 * or it was auto and has since been determined. In any case, we
679 * can proceed to actually answering the request by sending a redirect
680 * or an image as appropriate:
682 if (imagetype == 'r')
684 rsp->status = strdup("302 Local Redirect from Privoxy");
685 if (rsp->status == NULL)
687 return JB_ERR_MEMORY;
689 if (enlist_unique_header(rsp->headers, "Location",
690 csp->action->string[ACTION_STRING_IMAGE_BLOCKER]))
692 return JB_ERR_MEMORY;
697 if ((imagetype == 'b') || (imagetype == 't'))
699 rsp->body = bindup(image_blank_data, image_blank_length);
700 rsp->content_length = image_blank_length;
704 rsp->body = bindup(image_pattern_data, image_pattern_length);
705 rsp->content_length = image_pattern_length;
708 if (rsp->body == NULL)
710 return JB_ERR_MEMORY;
712 if (enlist(rsp->headers, "Content-Type: " BUILTIN_IMAGE_MIMETYPE))
714 return JB_ERR_MEMORY;
725 /*********************************************************************
727 * Function : cgi_transparent_image
729 * Description : CGI function that sends a 1x1 transparent image.
732 * 1 : csp = Current client state (buffers, headers, etc...)
733 * 2 : rsp = http_response data structure for output
734 * 3 : parameters = map of cgi parameters
736 * CGI Parameters : None
738 * Returns : JB_ERR_OK on success
739 * JB_ERR_MEMORY on out-of-memory error.
741 *********************************************************************/
742 jb_err cgi_transparent_image(struct client_state *csp,
743 struct http_response *rsp,
744 const struct map *parameters)
746 rsp->body = bindup(image_blank_data, image_blank_length);
747 rsp->content_length = image_blank_length;
749 if (rsp->body == NULL)
751 return JB_ERR_MEMORY;
754 if (enlist(rsp->headers, "Content-Type: " BUILTIN_IMAGE_MIMETYPE))
756 return JB_ERR_MEMORY;
766 /*********************************************************************
768 * Function : cgi_send_default_favicon
770 * Description : CGI function that sends the standard favicon.
773 * 1 : csp = Current client state (buffers, headers, etc...)
774 * 2 : rsp = http_response data structure for output
775 * 3 : parameters = map of cgi parameters
777 * CGI Parameters : None
779 * Returns : JB_ERR_OK on success
780 * JB_ERR_MEMORY on out-of-memory error.
782 *********************************************************************/
783 jb_err cgi_send_default_favicon(struct client_state *csp,
784 struct http_response *rsp,
785 const struct map *parameters)
787 rsp->body = bindup(default_favicon_data, default_favicon_length);
788 rsp->content_length = default_favicon_length;
790 if (rsp->body == NULL)
792 return JB_ERR_MEMORY;
795 if (enlist(rsp->headers, "Content-Type: image/x-icon"))
797 return JB_ERR_MEMORY;
807 /*********************************************************************
809 * Function : cgi_send_error_favicon
811 * Description : CGI function that sends the favicon for error pages.
814 * 1 : csp = Current client state (buffers, headers, etc...)
815 * 2 : rsp = http_response data structure for output
816 * 3 : parameters = map of cgi parameters
818 * CGI Parameters : None
820 * Returns : JB_ERR_OK on success
821 * JB_ERR_MEMORY on out-of-memory error.
823 *********************************************************************/
824 jb_err cgi_send_error_favicon(struct client_state *csp,
825 struct http_response *rsp,
826 const struct map *parameters)
828 rsp->body = bindup(error_favicon_data, error_favicon_length);
829 rsp->content_length = error_favicon_length;
831 if (rsp->body == NULL)
833 return JB_ERR_MEMORY;
836 if (enlist(rsp->headers, "Content-Type: image/x-icon"))
838 return JB_ERR_MEMORY;
848 /*********************************************************************
850 * Function : cgi_send_stylesheet
852 * Description : CGI function that sends a css stylesheet found
853 * in the cgi-style.css template
856 * 1 : csp = Current client state (buffers, headers, etc...)
857 * 2 : rsp = http_response data structure for output
858 * 3 : parameters = map of cgi parameters
860 * CGI Parameters : None
862 * Returns : JB_ERR_OK on success
863 * JB_ERR_MEMORY on out-of-memory error.
865 *********************************************************************/
866 jb_err cgi_send_stylesheet(struct client_state *csp,
867 struct http_response *rsp,
868 const struct map *parameters)
875 err = template_load(csp, &rsp->body, "cgi-style.css", 0);
877 if (err == JB_ERR_FILE)
880 * No way to tell user; send empty stylesheet
882 log_error(LOG_LEVEL_ERROR, "Could not find cgi-style.css template");
886 return err; /* JB_ERR_MEMORY */
889 if (enlist(rsp->headers, "Content-Type: text/css"))
891 return JB_ERR_MEMORY;
897 /*********************************************************************
899 * Function : cgi_send_user_manual
901 * Description : CGI function that sends a file in the user
905 * 1 : csp = Current client state (buffers, headers, etc...)
906 * 2 : rsp = http_response data structure for output
907 * 3 : parameters = map of cgi parameters
909 * CGI Parameters : file=name.html, the name of the HTML file
910 * (relative to user-manual from config)
912 * Returns : JB_ERR_OK on success
913 * JB_ERR_MEMORY on out-of-memory error.
915 *********************************************************************/
916 jb_err cgi_send_user_manual(struct client_state *csp,
917 struct http_response *rsp,
918 const struct map *parameters)
920 const char * filename;
923 jb_err err = JB_ERR_OK;
930 if (!parameters->first)
932 /* requested http://p.p/user-manual (without trailing slash) */
933 return cgi_redirect(rsp, CGI_PREFIX "user-manual/");
936 get_string_param(parameters, "file", &filename);
937 /* Check paramter for hack attempts */
938 if (filename && strchr(filename, '/'))
940 return JB_ERR_CGI_PARAMS;
942 if (filename && strstr(filename, ".."))
944 return JB_ERR_CGI_PARAMS;
947 full_path = make_path(csp->config->usermanual, filename ? filename : "index.html");
948 if (full_path == NULL)
950 return JB_ERR_MEMORY;
953 /* Open user-manual file */
954 if (NULL == (fp = fopen(full_path, "rb")))
956 log_error(LOG_LEVEL_ERROR, "Cannot open user-manual file %s: %E", full_path);
957 err = cgi_error_no_template(csp, rsp, full_path);
962 /* Get file length */
963 fseek(fp, 0, SEEK_END);
964 length = (size_t)ftell(fp);
965 fseek(fp, 0, SEEK_SET);
967 /* Allocate memory and load the file directly into the body */
968 rsp->body = (char *)zalloc(length+1);
973 return JB_ERR_MEMORY;
975 if (!fread(rsp->body, length, 1, fp))
978 * May happen if the file size changes between fseek() and fread().
979 * If it does, we just log it and serve what we got.
981 log_error(LOG_LEVEL_ERROR, "Couldn't completely read user-manual file %s.", full_path);
986 rsp->content_length = length;
988 /* Guess correct Content-Type based on the filename's ending */
991 length = strlen(filename);
997 if((length>=4) && !strcmp(&filename[length-4], ".css"))
999 err = enlist(rsp->headers, "Content-Type: text/css");
1001 else if((length>=4) && !strcmp(&filename[length-4], ".jpg"))
1003 err = enlist(rsp->headers, "Content-Type: image/jpeg");
1007 err = enlist(rsp->headers, "Content-Type: text/html");
1014 /*********************************************************************
1016 * Function : cgi_show_version
1018 * Description : CGI function that returns a a web page describing the
1019 * file versions of Privoxy.
1022 * 1 : csp = Current client state (buffers, headers, etc...)
1023 * 2 : rsp = http_response data structure for output
1024 * 3 : parameters = map of cgi parameters
1026 * CGI Parameters : none
1028 * Returns : JB_ERR_OK on success
1029 * JB_ERR_MEMORY on out-of-memory error.
1031 *********************************************************************/
1032 jb_err cgi_show_version(struct client_state *csp,
1033 struct http_response *rsp,
1034 const struct map *parameters)
1036 struct map *exports;
1042 if (NULL == (exports = default_exports(csp, "show-version")))
1044 return JB_ERR_MEMORY;
1047 if (map(exports, "sourceversions", 1, show_rcs(), 0))
1050 return JB_ERR_MEMORY;
1053 return template_fill_for_cgi(csp, "show-version", exports, rsp);
1057 /*********************************************************************
1059 * Function : cgi_show_status
1061 * Description : CGI function that returns a web page describing the
1062 * current status of Privoxy.
1065 * 1 : csp = Current client state (buffers, headers, etc...)
1066 * 2 : rsp = http_response data structure for output
1067 * 3 : parameters = map of cgi parameters
1070 * file : Which file to show. Only first letter is checked,
1072 * - "p"ermissions (actions) file
1075 * Default is to show menu and other information.
1077 * Returns : JB_ERR_OK on success
1078 * JB_ERR_MEMORY on out-of-memory error.
1080 *********************************************************************/
1081 jb_err cgi_show_status(struct client_state *csp,
1082 struct http_response *rsp,
1083 const struct map *parameters)
1090 char buf[BUFFER_SIZE];
1091 const char * filename = NULL;
1092 char * file_description = NULL;
1093 #ifdef FEATURE_STATISTICS
1094 float perc_rej; /* Percentage of http requests rejected */
1095 int local_urls_read;
1096 int local_urls_rejected;
1097 #endif /* ndef FEATURE_STATISTICS */
1098 jb_err err = JB_ERR_OK;
1100 struct map *exports;
1106 if (NULL == (exports = default_exports(csp, "show-status")))
1108 return JB_ERR_MEMORY;
1111 switch (*(lookup(parameters, "file")))
1114 if (!get_number_param(csp, parameters, "index", &i) && i < MAX_AF_FILES && csp->actions_list[i])
1116 filename = csp->actions_list[i]->filename;
1117 file_description = "Actions File";
1122 if (!get_number_param(csp, parameters, "index", &i) && i < MAX_AF_FILES && csp->rlist[i])
1124 filename = csp->rlist[i]->filename;
1125 file_description = "Filter File";
1129 #ifdef FEATURE_TRUST
1133 filename = csp->tlist->filename;
1134 file_description = "Trust File";
1137 #endif /* def FEATURE_TRUST */
1140 if (NULL != filename)
1142 if ( map(exports, "file-description", 1, file_description, 1)
1143 || map(exports, "filepath", 1, html_encode(filename), 0) )
1146 return JB_ERR_MEMORY;
1149 if ((fp = fopen(filename, "r")) == NULL)
1151 if (map(exports, "content", 1, "<h1>ERROR OPENING FILE!</h1>", 1))
1154 return JB_ERR_MEMORY;
1160 while ((s != NULL) && fgets(buf, sizeof(buf), fp))
1162 string_join (&s, html_encode(buf));
1166 if (map(exports, "contents", 1, s, 0))
1169 return JB_ERR_MEMORY;
1173 return template_fill_for_cgi(csp, "show-status-file", exports, rsp);
1177 for (j = 0; (s != NULL) && (j < Argc); j++)
1179 if (!err) err = string_join (&s, html_encode(Argv[j]));
1180 if (!err) err = string_append(&s, " ");
1182 if (!err) err = map(exports, "invocation", 1, s, 0);
1184 if (!err) err = map(exports, "options", 1, csp->config->proxy_args, 1);
1185 if (!err) err = show_defines(exports);
1190 return JB_ERR_MEMORY;
1193 #ifdef FEATURE_STATISTICS
1194 local_urls_read = urls_read;
1195 local_urls_rejected = urls_rejected;
1198 * Need to alter the stats not to include the fetch of this
1201 * Can't do following thread safely! doh!
1204 * urls_rejected--; * This will be incremented subsequently *
1207 if (local_urls_read == 0)
1209 if (!err) err = map_block_killer(exports, "have-stats");
1213 if (!err) err = map_block_killer(exports, "have-no-stats");
1215 perc_rej = (float)local_urls_rejected * 100.0F /
1216 (float)local_urls_read;
1218 snprintf(buf, sizeof(buf), "%d", local_urls_read);
1219 if (!err) err = map(exports, "requests-received", 1, buf, 1);
1221 snprintf(buf, sizeof(buf), "%d", local_urls_rejected);
1222 if (!err) err = map(exports, "requests-blocked", 1, buf, 1);
1224 snprintf(buf, sizeof(buf), "%6.2f", perc_rej);
1225 if (!err) err = map(exports, "percent-blocked", 1, buf, 1);
1228 #else /* ndef FEATURE_STATISTICS */
1229 err = err || map_block_killer(exports, "statistics");
1230 #endif /* ndef FEATURE_STATISTICS */
1233 * List all action files in use, together with view and edit links,
1234 * except for standard.action, which should only be viewable. (Not
1235 * enforced in the editor itself)
1236 * FIXME: Shouldn't include hardwired HTML here, use line template instead!
1239 for (i = 0; i < MAX_AF_FILES; i++)
1241 if (csp->actions_list[i] != NULL)
1243 if (!err) err = string_append(&s, "<tr><td>");
1244 if (!err) err = string_join(&s, html_encode(csp->actions_list[i]->filename));
1245 snprintf(buf, sizeof(buf),
1246 "</td><td class=\"buttons\"><a href=\"/show-status?file=actions&index=%d\">View</a>", i);
1247 if (!err) err = string_append(&s, buf);
1249 #ifdef FEATURE_CGI_EDIT_ACTIONS
1250 if ((csp->config->feature_flags & RUNTIME_FEATURE_CGI_EDIT_ACTIONS)
1251 && (NULL == strstr(csp->actions_list[i]->filename, "standard.action"))
1252 && (NULL != csp->config->actions_file_short[i]))
1255 if (access(csp->config->actions_file[i], W_OK) == 0)
1257 #endif /* def HAVE_ACCESS */
1258 snprintf(buf, sizeof(buf), " <a href=\"/edit-actions-list?f=%d\">Edit</a>", i);
1259 if (!err) err = string_append(&s, buf);
1264 if (!err) err = string_append(&s, " <strong>No write access.</strong>");
1266 #endif /* def HAVE_ACCESS */
1270 if (!err) err = string_append(&s, "</td></tr>\n");
1275 if (!err) err = map(exports, "actions-filenames", 1, s, 0);
1279 if (!err) err = map(exports, "actions-filenames", 1, "<tr><td>None specified</td></tr>", 1);
1283 * List all re_filterfiles in use, together with view options.
1284 * FIXME: Shouldn't include hardwired HTML here, use line template instead!
1287 for (i = 0; i < MAX_AF_FILES; i++)
1289 if (csp->rlist[i] != NULL)
1291 if (!err) err = string_append(&s, "<tr><td>");
1292 if (!err) err = string_join(&s, html_encode(csp->rlist[i]->filename));
1294 "</td><td class=\"buttons\"><a href=\"/show-status?file=filter&index=%d\">View</a>", i);
1295 if (!err) err = string_append(&s, buf);
1296 if (!err) err = string_append(&s, "</td></tr>\n");
1301 if (!err) err = map(exports, "re-filter-filenames", 1, s, 0);
1305 if (!err) err = map(exports, "re-filter-filenames", 1, "<tr><td>None specified</td></tr>", 1);
1306 if (!err) err = map_block_killer(exports, "have-filterfile");
1309 #ifdef FEATURE_TRUST
1312 if (!err) err = map(exports, "trust-filename", 1, html_encode(csp->tlist->filename), 0);
1316 if (!err) err = map(exports, "trust-filename", 1, "None specified", 1);
1317 if (!err) err = map_block_killer(exports, "have-trustfile");
1320 if (!err) err = map_block_killer(exports, "trust-support");
1321 #endif /* ndef FEATURE_TRUST */
1323 #ifdef FEATURE_CGI_EDIT_ACTIONS
1324 if (!err && (csp->config->feature_flags & RUNTIME_FEATURE_CGI_EDIT_ACTIONS))
1326 err = map_block_killer(exports, "cgi-editor-is-disabled");
1328 #endif /* ndef CGI_EDIT_ACTIONS */
1333 return JB_ERR_MEMORY;
1336 return template_fill_for_cgi(csp, "show-status", exports, rsp);
1340 /*********************************************************************
1342 * Function : cgi_show_url_info
1344 * Description : CGI function that determines and shows which actions
1345 * Privoxy will perform for a given url, and which
1346 * matches starting from the defaults have lead to that.
1349 * 1 : csp = Current client state (buffers, headers, etc...)
1350 * 2 : rsp = http_response data structure for output
1351 * 3 : parameters = map of cgi parameters
1354 * url : The url whose actions are to be determined.
1355 * If url is unset, the url-given conditional will be
1356 * set, so that all but the form can be suppressed in
1359 * Returns : JB_ERR_OK on success
1360 * JB_ERR_MEMORY on out-of-memory error.
1362 *********************************************************************/
1363 jb_err cgi_show_url_info(struct client_state *csp,
1364 struct http_response *rsp,
1365 const struct map *parameters)
1368 struct map *exports;
1375 if (NULL == (exports = default_exports(csp, "show-url-info")))
1377 return JB_ERR_MEMORY;
1381 * Get the url= parameter (if present) and remove any leading/trailing spaces.
1383 url_param = strdup(lookup(parameters, "url"));
1384 if (url_param == NULL)
1387 return JB_ERR_MEMORY;
1392 * Handle prefixes. 4 possibilities:
1393 * 1) "http://" or "https://" prefix present and followed by URL - OK
1394 * 2) Only the "http://" or "https://" part is present, no URL - change
1395 * to empty string so it will be detected later as "no URL".
1396 * 3) Parameter specified but doesn't contain "http(s?)://" - add a
1398 * 4) Parameter not specified or is empty string - let this fall through
1399 * for now, next block of code will handle it.
1401 if (0 == strncmp(url_param, "http://", 7))
1403 if (url_param[7] == '\0')
1406 * Empty URL (just prefix).
1407 * Make it totally empty so it's caught by the next if()
1409 url_param[0] = '\0';
1412 else if (0 == strncmp(url_param, "https://", 8))
1414 if (url_param[8] == '\0')
1417 * Empty URL (just prefix).
1418 * Make it totally empty so it's caught by the next if()
1420 url_param[0] = '\0';
1423 else if (url_param[0] != '\0')
1426 * Unknown prefix - assume http://
1428 const size_t url_param_prefixed_size = 7 + 1 + strlen(url_param);
1429 char * url_param_prefixed = malloc(url_param_prefixed_size);
1430 if (NULL == url_param_prefixed)
1434 return JB_ERR_MEMORY;
1436 strlcpy(url_param_prefixed, "http://", url_param_prefixed_size);
1437 strlcat(url_param_prefixed, url_param, url_param_prefixed_size);
1439 url_param = url_param_prefixed;
1443 * Hide "toggle off" warning if Privoxy is toggled on.
1446 #ifdef FEATURE_TOGGLE
1447 (global_toggle_state == 1) &&
1448 #endif /* def FEATURE_TOGGLE */
1449 map_block_killer(exports, "privoxy-is-toggled-off")
1453 return JB_ERR_MEMORY;
1456 if (url_param[0] == '\0')
1458 /* URL paramater not specified, display query form only. */
1460 if (map_block_killer(exports, "url-given")
1461 || map(exports, "url", 1, "", 1))
1464 return JB_ERR_MEMORY;
1469 /* Given a URL, so query it. */
1474 struct file_list *fl;
1475 struct url_actions *b;
1476 struct http_request url_to_query[1];
1477 struct current_action_spec action[1];
1480 if (map(exports, "url", 1, html_encode(url_param), 0))
1484 return JB_ERR_MEMORY;
1487 init_current_action(action);
1489 if (map(exports, "default", 1, current_action_to_html(csp, action), 0))
1491 free_current_action(action);
1494 return JB_ERR_MEMORY;
1497 err = parse_http_url(url_param, url_to_query, csp);
1501 if (err == JB_ERR_MEMORY)
1503 free_http_request(url_to_query);
1504 free_current_action(action);
1506 return JB_ERR_MEMORY;
1512 err = map(exports, "matches", 1, "<b>[Invalid URL specified!]</b>" , 1);
1513 if (!err) err = map(exports, "final", 1, lookup(exports, "default"), 1);
1514 if (!err) err = map_block_killer(exports, "valid-url");
1516 free_current_action(action);
1517 free_http_request(url_to_query);
1522 return JB_ERR_MEMORY;
1525 return template_fill_for_cgi(csp, "show-url-info", exports, rsp);
1529 * We have a warning about SSL paths. Hide it for unencrypted sites.
1531 if (!url_to_query->ssl)
1533 if (map_block_killer(exports, "https"))
1535 free_current_action(action);
1537 free_http_request(url_to_query);
1538 return JB_ERR_MEMORY;
1542 matches = strdup("<table summary=\"\" class=\"transparent\">");
1544 for (i = 0; i < MAX_AF_FILES; i++)
1546 if (NULL == csp->config->actions_file_short[i]
1547 || !strcmp(csp->config->actions_file_short[i], "standard.action")) continue;
1551 if ((fl = csp->actions_list[i]) != NULL)
1553 if ((b = fl->f) != NULL)
1555 /* FIXME: Hardcoded HTML! */
1556 string_append(&matches, "<tr><th>In file: ");
1557 string_join (&matches, html_encode(csp->config->actions_file_short[i]));
1558 snprintf(buf, sizeof(buf), " <a class=\"cmd\" href=\"/show-status?file=actions&index=%d\">", i);
1559 string_append(&matches, buf);
1560 string_append(&matches, "View</a>");
1561 #ifdef FEATURE_CGI_EDIT_ACTIONS
1562 if (csp->config->feature_flags & RUNTIME_FEATURE_CGI_EDIT_ACTIONS)
1565 if (access(csp->config->actions_file[i], W_OK) == 0)
1567 #endif /* def HAVE_ACCESS */
1568 snprintf(buf, sizeof(buf),
1569 " <a class=\"cmd\" href=\"/edit-actions-list?f=%d\">", i);
1570 string_append(&matches, buf);
1571 string_append(&matches, "Edit</a>");
1576 string_append(&matches, " <strong>No write access.</strong>");
1578 #endif /* def HAVE_ACCESS */
1580 #endif /* FEATURE_CGI_EDIT_ACTIONS */
1582 string_append(&matches, "</th></tr>\n");
1589 for (; (b != NULL) && (matches != NULL); b = b->next)
1591 if (url_match(b->url, url_to_query))
1593 string_append(&matches, "<tr><td>{");
1594 string_join (&matches, actions_to_html(csp, b->action));
1595 string_append(&matches, " }<br>\n<code>");
1596 string_join (&matches, html_encode(b->url->spec));
1597 string_append(&matches, "</code></td></tr>\n");
1599 if (merge_current_action(action, b->action))
1602 free_http_request(url_to_query);
1603 free_current_action(action);
1605 return JB_ERR_MEMORY;
1613 string_append(&matches, "<tr><td>(no matches in this file)</td></tr>\n");
1616 string_append(&matches, "</table>\n");
1619 * XXX: Kludge to make sure the "Forward settings" section
1620 * shows what forward-override{} would do with the requested URL.
1621 * No one really cares how the CGI request would be forwarded
1622 * if it wasn't intercepted as CGI request in the first place.
1624 * From here on the action bitmask will no longer reflect
1625 * the real url (http://config.privoxy.org/show-url-info?url=.*),
1626 * but luckily it's no longer required later on anyway.
1628 free_current_action(csp->action);
1629 url_actions(url_to_query, csp);
1632 * Fill in forwarding settings.
1634 * The possibilities are:
1636 * - http forwarding only
1637 * - socks4(a) forwarding only
1638 * - socks4(a) and http forwarding.
1640 * XXX: Parts of this code could be reused for the
1641 * "forwarding-failed" template which currently doesn't
1642 * display the proxy port and an eventual second forwarder.
1645 const struct forward_spec * fwd = forward_url(url_to_query, csp);
1647 if ((fwd->gateway_host == NULL) && (fwd->forward_host == NULL))
1649 if (!err) err = map_block_killer(exports, "socks-forwarder");
1650 if (!err) err = map_block_killer(exports, "http-forwarder");
1654 char port[10]; /* We save proxy ports as int but need a string here */
1656 if (!err) err = map_block_killer(exports, "no-forwarder");
1658 if (fwd->gateway_host != NULL)
1660 if (!err) err = map(exports, "socks-type", 1, (fwd->type == SOCKS_4) ?
1661 "socks4" : "socks4a", 1);
1662 if (!err) err = map(exports, "gateway-host", 1, fwd->gateway_host, 1);
1663 snprintf(port, sizeof(port), "%d", fwd->gateway_port);
1664 if (!err) err = map(exports, "gateway-port", 1, port, 1);
1668 if (!err) err = map_block_killer(exports, "socks-forwarder");
1671 if (fwd->forward_host != NULL)
1673 if (!err) err = map(exports, "forward-host", 1, fwd->forward_host, 1);
1674 snprintf(port, sizeof(port), "%d", fwd->forward_port);
1675 if (!err) err = map(exports, "forward-port", 1, port, 1);
1679 if (!err) err = map_block_killer(exports, "http-forwarder");
1684 free_http_request(url_to_query);
1686 if (err || matches == NULL)
1688 free_current_action(action);
1690 return JB_ERR_MEMORY;
1693 if (map(exports, "matches", 1, matches , 0))
1695 free_current_action(action);
1697 return JB_ERR_MEMORY;
1700 s = current_action_to_html(csp, action);
1702 free_current_action(action);
1704 if (map(exports, "final", 1, s, 0))
1707 return JB_ERR_MEMORY;
1711 return template_fill_for_cgi(csp, "show-url-info", exports, rsp);
1715 /*********************************************************************
1717 * Function : cgi_robots_txt
1719 * Description : CGI function to return "/robots.txt".
1722 * 1 : csp = Current client state (buffers, headers, etc...)
1723 * 2 : rsp = http_response data structure for output
1724 * 3 : parameters = map of cgi parameters
1726 * CGI Parameters : None
1728 * Returns : JB_ERR_OK on success
1729 * JB_ERR_MEMORY on out-of-memory error.
1731 *********************************************************************/
1732 jb_err cgi_robots_txt(struct client_state *csp,
1733 struct http_response *rsp,
1734 const struct map *parameters)
1740 "# This is the Privoxy control interface.\n"
1741 "# It isn't very useful to index it, and you're likely to break stuff.\n"
1747 if (rsp->body == NULL)
1749 return JB_ERR_MEMORY;
1752 err = enlist_unique(rsp->headers, "Content-Type: text/plain", 13);
1756 get_http_time(7 * 24 * 60 * 60, buf); /* 7 days into future */
1757 if (!err) err = enlist_unique_header(rsp->headers, "Expires", buf);
1759 return (err ? JB_ERR_MEMORY : JB_ERR_OK);
1763 /*********************************************************************
1765 * Function : show_defines
1767 * Description : Add to a map the state od all conditional #defines
1768 * used when building
1771 * 1 : exports = map to extend
1773 * Returns : JB_ERR_OK on success
1774 * JB_ERR_MEMORY on out-of-memory error.
1776 *********************************************************************/
1777 static jb_err show_defines(struct map *exports)
1779 jb_err err = JB_ERR_OK;
1782 if (!err) err = map_conditional(exports, "FEATURE_ACL", 1);
1783 #else /* ifndef FEATURE_ACL */
1784 if (!err) err = map_conditional(exports, "FEATURE_ACL", 0);
1785 #endif /* ndef FEATURE_ACL */
1787 #ifdef FEATURE_CGI_EDIT_ACTIONS
1788 if (!err) err = map_conditional(exports, "FEATURE_CGI_EDIT_ACTIONS", 1);
1789 #else /* ifndef FEATURE_COOKIE_JAR */
1790 if (!err) err = map_conditional(exports, "FEATURE_CGI_EDIT_ACTIONS", 0);
1791 #endif /* ndef FEATURE_COOKIE_JAR */
1793 #ifdef FEATURE_COOKIE_JAR
1794 if (!err) err = map_conditional(exports, "FEATURE_COOKIE_JAR", 1);
1795 #else /* ifndef FEATURE_COOKIE_JAR */
1796 if (!err) err = map_conditional(exports, "FEATURE_COOKIE_JAR", 0);
1797 #endif /* ndef FEATURE_COOKIE_JAR */
1799 #ifdef FEATURE_FAST_REDIRECTS
1800 if (!err) err = map_conditional(exports, "FEATURE_FAST_REDIRECTS", 1);
1801 #else /* ifndef FEATURE_FAST_REDIRECTS */
1802 if (!err) err = map_conditional(exports, "FEATURE_FAST_REDIRECTS", 0);
1803 #endif /* ndef FEATURE_FAST_REDIRECTS */
1805 #ifdef FEATURE_FORCE_LOAD
1806 if (!err) err = map_conditional(exports, "FEATURE_FORCE_LOAD", 1);
1807 if (!err) err = map(exports, "FORCE_PREFIX", 1, FORCE_PREFIX, 1);
1808 #else /* ifndef FEATURE_FORCE_LOAD */
1809 if (!err) err = map_conditional(exports, "FEATURE_FORCE_LOAD", 0);
1810 if (!err) err = map(exports, "FORCE_PREFIX", 1, "(none - disabled)", 1);
1811 #endif /* ndef FEATURE_FORCE_LOAD */
1813 #ifdef FEATURE_GRACEFUL_TERMINATION
1814 if (!err) err = map_conditional(exports, "FEATURE_GRACEFUL_TERMINATION", 1);
1815 #else /* ifndef FEATURE_GRACEFUL_TERMINATION */
1816 if (!err) err = map_conditional(exports, "FEATURE_GRACEFUL_TERMINATION", 0);
1817 #endif /* ndef FEATURE_GRACEFUL_TERMINATION */
1819 #ifdef FEATURE_IMAGE_BLOCKING
1820 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_BLOCKING", 1);
1821 #else /* ifndef FEATURE_IMAGE_BLOCKING */
1822 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_BLOCKING", 0);
1823 #endif /* ndef FEATURE_IMAGE_BLOCKING */
1825 #ifdef FEATURE_IMAGE_DETECT_MSIE
1826 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_DETECT_MSIE", 1);
1827 #else /* ifndef FEATURE_IMAGE_DETECT_MSIE */
1828 if (!err) err = map_conditional(exports, "FEATURE_IMAGE_DETECT_MSIE", 0);
1829 #endif /* ndef FEATURE_IMAGE_DETECT_MSIE */
1831 #ifdef FEATURE_KILL_POPUPS
1832 if (!err) err = map_conditional(exports, "FEATURE_KILL_POPUPS", 1);
1833 #else /* ifndef FEATURE_KILL_POPUPS */
1834 if (!err) err = map_conditional(exports, "FEATURE_KILL_POPUPS", 0);
1835 #endif /* ndef FEATURE_KILL_POPUPS */
1837 #ifdef FEATURE_NO_GIFS
1838 if (!err) err = map_conditional(exports, "FEATURE_NO_GIFS", 1);
1839 #else /* ifndef FEATURE_NO_GIFS */
1840 if (!err) err = map_conditional(exports, "FEATURE_NO_GIFS", 0);
1841 #endif /* ndef FEATURE_NO_GIFS */
1843 #ifdef FEATURE_PTHREAD
1844 if (!err) err = map_conditional(exports, "FEATURE_PTHREAD", 1);
1845 #else /* ifndef FEATURE_PTHREAD */
1846 if (!err) err = map_conditional(exports, "FEATURE_PTHREAD", 0);
1847 #endif /* ndef FEATURE_PTHREAD */
1849 #ifdef FEATURE_STATISTICS
1850 if (!err) err = map_conditional(exports, "FEATURE_STATISTICS", 1);
1851 #else /* ifndef FEATURE_STATISTICS */
1852 if (!err) err = map_conditional(exports, "FEATURE_STATISTICS", 0);
1853 #endif /* ndef FEATURE_STATISTICS */
1855 #ifdef FEATURE_TOGGLE
1856 if (!err) err = map_conditional(exports, "FEATURE_TOGGLE", 1);
1857 #else /* ifndef FEATURE_TOGGLE */
1858 if (!err) err = map_conditional(exports, "FEATURE_TOGGLE", 0);
1859 #endif /* ndef FEATURE_TOGGLE */
1861 #ifdef FEATURE_TRUST
1862 if (!err) err = map_conditional(exports, "FEATURE_TRUST", 1);
1863 #else /* ifndef FEATURE_TRUST */
1864 if (!err) err = map_conditional(exports, "FEATURE_TRUST", 0);
1865 #endif /* ndef FEATURE_TRUST */
1868 if (!err) err = map_conditional(exports, "FEATURE_ZLIB", 1);
1869 #else /* ifndef FEATURE_ZLIB */
1870 if (!err) err = map_conditional(exports, "FEATURE_ZLIB", 0);
1871 #endif /* ndef FEATURE_ZLIB */
1874 if (!err) err = map_conditional(exports, "STATIC_PCRE", 1);
1875 #else /* ifndef STATIC_PCRE */
1876 if (!err) err = map_conditional(exports, "STATIC_PCRE", 0);
1877 #endif /* ndef STATIC_PCRE */
1880 if (!err) err = map_conditional(exports, "STATIC_PCRS", 1);
1881 #else /* ifndef STATIC_PCRS */
1882 if (!err) err = map_conditional(exports, "STATIC_PCRS", 0);
1883 #endif /* ndef STATIC_PCRS */
1889 /*********************************************************************
1891 * Function : show_rcs
1893 * Description : Create a string with the rcs info for all sourcefiles
1897 * Returns : A string, or NULL on out-of-memory.
1899 *********************************************************************/
1900 static char *show_rcs(void)
1902 char *result = strdup("");
1903 char buf[BUFFER_SIZE];
1905 /* Instead of including *all* dot h's in the project (thus creating a
1906 * tremendous amount of dependencies), I will concede to declaring them
1907 * as extern's. This forces the developer to add to this list, but oh well.
1910 #define SHOW_RCS(__x) \
1912 extern const char __x[]; \
1913 snprintf(buf, sizeof(buf), " %s\n", __x); \
1914 string_append(&result, buf); \
1917 /* In alphabetical order */
1918 SHOW_RCS(actions_h_rcs)
1919 SHOW_RCS(actions_rcs)
1921 SHOW_RCS(amiga_h_rcs)
1923 #endif /* def AMIGA */
1926 #ifdef FEATURE_CGI_EDIT_ACTIONS
1927 SHOW_RCS(cgiedit_h_rcs)
1928 SHOW_RCS(cgiedit_rcs)
1929 #endif /* def FEATURE_CGI_EDIT_ACTIONS */
1930 SHOW_RCS(cgisimple_h_rcs)
1931 SHOW_RCS(cgisimple_rcs)
1933 SHOW_RCS(cygwin_h_rcs)
1935 SHOW_RCS(deanimate_h_rcs)
1936 SHOW_RCS(deanimate_rcs)
1937 SHOW_RCS(encode_h_rcs)
1938 SHOW_RCS(encode_rcs)
1939 SHOW_RCS(errlog_h_rcs)
1940 SHOW_RCS(errlog_rcs)
1941 SHOW_RCS(filters_h_rcs)
1942 SHOW_RCS(filters_rcs)
1943 SHOW_RCS(gateway_h_rcs)
1944 SHOW_RCS(gateway_rcs)
1945 SHOW_RCS(jbsockets_h_rcs)
1946 SHOW_RCS(jbsockets_rcs)
1949 #ifdef FEATURE_KILL_POPUPS
1950 SHOW_RCS(killpopup_h_rcs)
1951 SHOW_RCS(killpopup_rcs)
1952 #endif /* def FEATURE_KILL_POPUPS */
1953 SHOW_RCS(list_h_rcs)
1955 SHOW_RCS(loadcfg_h_rcs)
1956 SHOW_RCS(loadcfg_rcs)
1957 SHOW_RCS(loaders_h_rcs)
1958 SHOW_RCS(loaders_rcs)
1959 SHOW_RCS(miscutil_h_rcs)
1960 SHOW_RCS(miscutil_rcs)
1961 SHOW_RCS(parsers_h_rcs)
1962 SHOW_RCS(parsers_rcs)
1964 SHOW_RCS(pcrs_h_rcs)
1965 SHOW_RCS(project_h_rcs)
1966 SHOW_RCS(ssplit_h_rcs)
1967 SHOW_RCS(ssplit_rcs)
1968 SHOW_RCS(urlmatch_h_rcs)
1969 SHOW_RCS(urlmatch_rcs)
1971 #ifndef _WIN_CONSOLE
1972 SHOW_RCS(w32log_h_rcs)
1973 SHOW_RCS(w32log_rcs)
1974 SHOW_RCS(w32res_h_rcs)
1975 SHOW_RCS(w32taskbar_h_rcs)
1976 SHOW_RCS(w32taskbar_rcs)
1977 #endif /* ndef _WIN_CONSOLE */
1978 SHOW_RCS(win32_h_rcs)
1980 #endif /* def _WIN32 */