refresh all package patches in the buildroot using quilt
[openwrt.git] / package / busybox / patches / 350-httpd_redir.patch
1 Index: busybox-1.4.2/include/usage.h
2 ===================================================================
3 --- busybox-1.4.2.orig/include/usage.h  2007-06-04 13:21:32.103096256 +0200
4 +++ busybox-1.4.2/include/usage.h       2007-06-04 13:21:35.005655000 +0200
5 @@ -1257,7 +1257,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 server requests" \
14         "\n\nOptions:\n" \
15 @@ -1273,7 +1274,9 @@
16         "       -m PASS         Crypt PASS with md5 algorithm\n") \
17         "       -h HOME         Specifies http HOME directory (default ./)\n" \
18         "       -e STRING       HTML encode STRING\n" \
19 -       "       -d STRING       URL decode STRING"
20 +       "       -d STRING       URL decode STRING\n" \
21 +       "       -R PATH         Redirect target path\n" \
22 +       "       -H HOST         Redirect target host"
23  
24  #define hwclock_trivial_usage \
25         "[-r|--show] [-s|--hctosys] [-w|--systohc] [-l|--localtime] [-u|--utc]"
26 Index: busybox-1.4.2/networking/httpd.c
27 ===================================================================
28 --- busybox-1.4.2.orig/networking/httpd.c       2007-06-04 13:21:34.588718384 +0200
29 +++ busybox-1.4.2/networking/httpd.c    2007-06-04 13:21:35.006654848 +0200
30 @@ -140,6 +140,8 @@
31         USE_FEATURE_HTTPD_CGI(char *user_agent;)
32  
33         const char *configFile;
34 +       const char *redirectPath;
35 +       const char *redirectHost;
36  
37         unsigned int rmt_ip;
38  #if ENABLE_FEATURE_HTTPD_CGI || DEBUG
39 @@ -880,8 +882,11 @@
40         }
41  #endif
42         if (responseNum == HTTP_MOVED_TEMPORARILY) {
43 -               len += sprintf(buf+len, "Location: %s/%s%s\r\n",
44 +               len += sprintf(buf+len, "Location: %s%s%s%s%s%s\r\n",
45 +                               (config->redirectHost ? "http://" : ""),
46 +                               (config->redirectHost ? config->redirectHost : ""),
47                                 config->found_moved_temporarily,
48 +                               (config->redirectHost ? "" : "/"),
49                                 (config->query ? "?" : ""),
50                                 (config->query ? config->query : ""));
51         }
52 @@ -1594,8 +1599,12 @@
53                 *++purl = '\0';       /* so keep last character */
54                 test = purl;          /* end ptr */
55  
56 +               /* redirect active */
57 +               if (config->redirectPath && (strncmp(url, config->redirectPath, strlen(config->redirectPath)) != 0))
58 +                       config->found_moved_temporarily = config->redirectPath;
59 +
60                 /* If URL is directory, adding '/' */
61 -               if (test[-1] != '/') {
62 +               if(!config->redirectPath && (test[-1] != '/')) {
63                         if (is_directory(url + 1, 1, &sb)) {
64                                 config->found_moved_temporarily = url;
65                         }
66 @@ -1897,7 +1906,9 @@
67  #endif
68  
69  enum {
70 -       c_opt_config_file = 0,
71 +       R_opt_redirect_path = 0,
72 +       H_opt_redirect_host,
73 +       c_opt_config_file,
74         d_opt_decode_url,
75         h_opt_home_httpd,
76         USE_FEATURE_HTTPD_ENCODE_URL_STR(e_opt_encode_url,)
77 @@ -1919,7 +1930,7 @@
78         OPT_FOREGROUND  = 1 << p_opt_foreground,
79  };
80  
81 -static const char httpd_opts[] = "c:d:h:"
82 +static const char httpd_opts[] = "R:H:c:d:h:"
83         USE_FEATURE_HTTPD_ENCODE_URL_STR("e:")
84         USE_FEATURE_HTTPD_BASIC_AUTH("r:")
85         USE_FEATURE_HTTPD_AUTH_MD5("m:")
86 @@ -1951,6 +1962,7 @@
87         config->ContentLength = -1;
88  
89         opt = getopt32(argc, argv, httpd_opts,
90 +                       &(config->redirectPath), &(config->redirectHost),
91                         &(config->configFile), &url_for_decode, &home_httpd
92                         USE_FEATURE_HTTPD_ENCODE_URL_STR(, &url_for_encode)
93                         USE_FEATURE_HTTPD_BASIC_AUTH(, &(config->realm))