Upgrade busybox to 1.7.2 - clean up insmod crap - add some lineno/programname fixes...
[openwrt/openwrt.git] / package / busybox / patches / 350-httpd_redir.patch
1 Index: busybox-1.7.2/include/usage.h
2 ===================================================================
3 --- busybox-1.7.2.orig/include/usage.h 2007-10-04 17:12:35.230910708 +0200
4 +++ busybox-1.7.2/include/usage.h 2007-10-04 17:32:12.994027602 +0200
5 @@ -1350,7 +1350,8 @@
6 USE_FEATURE_HTTPD_BASIC_AUTH(" [-r realm]") \
7 USE_FEATURE_HTTPD_AUTH_MD5(" [-m pass]") \
8 " [-h home]" \
9 - " [-d/-e string]"
10 + " [-d/-e string]" \
11 + " [-R <path> [-H <host>]]"
12 #define httpd_full_usage \
13 "Listen for incoming HTTP requests" \
14 "\n\nOptions:" \
15 @@ -1368,6 +1369,8 @@
16 "\n -h HOME Home directory (default .)" \
17 "\n -e STRING HTML encode STRING" \
18 "\n -d STRING URL decode STRING" \
19 + "\n -R PATH Redirect target path" \
20 + "\n -H HOST Redirect target host" \
21
22 #define hwclock_trivial_usage \
23 "[-r|--show] [-s|--hctosys] [-w|--systohc]" \
24 Index: busybox-1.7.2/networking/httpd.c
25 ===================================================================
26 --- busybox-1.7.2.orig/networking/httpd.c 2007-10-04 17:13:12.509035065 +0200
27 +++ busybox-1.7.2/networking/httpd.c 2007-10-04 17:32:33.711208213 +0200
28 @@ -230,6 +230,8 @@
29
30 const char *found_mime_type;
31 const char *found_moved_temporarily;
32 + const char *redirect_path;
33 + const char *redirect_host;
34 Htaccess_IP *ip_a_d; /* config allow/deny lines */
35
36 USE_FEATURE_HTTPD_BASIC_AUTH(const char *g_realm;)
37 @@ -264,6 +266,8 @@
38 #define home_httpd (G.home_httpd )
39 #define found_mime_type (G.found_mime_type )
40 #define found_moved_temporarily (G.found_moved_temporarily)
41 +#define redirect_path (G.redirect_path )
42 +#define redirect_host (G.redirect_host )
43 #define ContentLength (G.ContentLength )
44 #define last_mod (G.last_mod )
45 #define ip_a_d (G.ip_a_d )
46 @@ -901,8 +905,11 @@
47 }
48 #endif
49 if (responseNum == HTTP_MOVED_TEMPORARILY) {
50 - len += sprintf(iobuf + len, "Location: %s/%s%s\r\n",
51 + len += sprintf(iobuf + len, "Location: %s%s%s%s%s%s\r\n",
52 + (redirect_host ? "http://" : ""),
53 + (redirect_host ? redirect_host : ""),
54 found_moved_temporarily,
55 + (redirect_host ? "" : "/"),
56 (g_query ? "?" : ""),
57 (g_query ? g_query : ""));
58 }
59 @@ -1730,8 +1737,12 @@
60 *++urlp = '\0'; /* so keep last character */
61 tptr = urlp; /* end ptr */
62
63 + /* redirect active */
64 + if (redirect_path && (strncmp(urlcopy, redirect_path, strlen(redirect_path)) != 0))
65 + found_moved_temporarily = redirect_path;
66 +
67 /* If URL is a directory, add '/' */
68 - if (tptr[-1] != '/') {
69 + if (!redirect_path && (tptr[-1] != '/')) {
70 if (is_directory(urlcopy + 1, 1, &sb)) {
71 found_moved_temporarily = urlcopy;
72 }
73 @@ -2004,7 +2015,9 @@
74 #endif
75
76 enum {
77 - c_opt_config_file = 0,
78 + R_opt_redirect_path = 0,
79 + H_opt_redirect_host,
80 + c_opt_config_file,
81 d_opt_decode_url,
82 h_opt_home_httpd,
83 USE_FEATURE_HTTPD_ENCODE_URL_STR(e_opt_encode_url,)
84 @@ -2053,12 +2066,13 @@
85 /* We do not "absolutize" path given by -h (home) opt.
86 * If user gives relative path in -h, $SCRIPT_FILENAME can end up
87 * relative too. */
88 - opt = getopt32(argv, "c:d:h:"
89 + opt = getopt32(argv, "R:H:c:d:h:"
90 USE_FEATURE_HTTPD_ENCODE_URL_STR("e:")
91 USE_FEATURE_HTTPD_BASIC_AUTH("r:")
92 USE_FEATURE_HTTPD_AUTH_MD5("m:")
93 USE_FEATURE_HTTPD_SETUID("u:")
94 "p:ifv",
95 + &redirect_path, &redirect_host,
96 &configFile, &url_for_decode, &home_httpd
97 USE_FEATURE_HTTPD_ENCODE_URL_STR(, &url_for_encode)
98 USE_FEATURE_HTTPD_BASIC_AUTH(, &g_realm)