Skip to content
Snippets Groups Projects
Commit a177285b authored by Andy Green's avatar Andy Green
Browse files

cgi: fix QUERY_STRING

parent 85277640
Branches
Tags
No related merge requests found
...@@ -1705,6 +1705,11 @@ void ...@@ -1705,6 +1705,11 @@ void
lws_peer_dump_from_wsi(struct lws *wsi); lws_peer_dump_from_wsi(struct lws *wsi);
#endif #endif
#ifdef LWS_WITH_HTTP_PROXY
hubbub_error
html_parser_cb(const hubbub_token *token, void *pw);
#endif
void void
__lws_remove_from_timeout_list(struct lws *wsi); __lws_remove_from_timeout_list(struct lws *wsi);
......
...@@ -112,10 +112,10 @@ lws_cgi(struct lws *wsi, const char * const *exec_array, int script_uri_path_len ...@@ -112,10 +112,10 @@ lws_cgi(struct lws *wsi, const char * const *exec_array, int script_uri_path_len
int timeout_secs, const struct lws_protocol_vhost_options *mp_cgienv) int timeout_secs, const struct lws_protocol_vhost_options *mp_cgienv)
{ {
struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi]; struct lws_context_per_thread *pt = &wsi->context->pt[(int)wsi->tsi];
char *env_array[30], cgi_path[400], e[1024], *p = e, char *env_array[30], cgi_path[500], e[1024], *p = e,
*end = p + sizeof(e) - 1, tok[256], *t, *sum, *sumend; *end = p + sizeof(e) - 1, tok[256], *t, *sum, *sumend;
struct lws_cgi *cgi; struct lws_cgi *cgi;
int n, m = 0, i, uritok = -1; int n, m = 0, i, uritok = -1, c;
/* /*
* give the master wsi a cgi struct * give the master wsi a cgi struct
...@@ -217,7 +217,7 @@ lws_cgi(struct lws *wsi, const char * const *exec_array, int script_uri_path_len ...@@ -217,7 +217,7 @@ lws_cgi(struct lws *wsi, const char * const *exec_array, int script_uri_path_len
}; };
static const char * const meth_names[] = { static const char * const meth_names[] = {
"GET", "POST", "OPTIONS", "PUT", "PATCH", "DELETE", "GET", "POST", "OPTIONS", "PUT", "PATCH", "DELETE",
"CONNECT", ":path" "CONNECT", "HEAD", ":path"
}; };
if (script_uri_path_len >= 0) if (script_uri_path_len >= 0)
...@@ -233,34 +233,28 @@ lws_cgi(struct lws *wsi, const char * const *exec_array, int script_uri_path_len ...@@ -233,34 +233,28 @@ lws_cgi(struct lws *wsi, const char * const *exec_array, int script_uri_path_len
// if (script_uri_path_len < 0) // if (script_uri_path_len < 0)
// uritok = 0; // uritok = 0;
if (uritok >= 0) {
lws_snprintf(cgi_path, sizeof(cgi_path) - 1,
"REQUEST_URI=%s",
lws_hdr_simple_ptr(wsi, uritok));
cgi_path[sizeof(cgi_path) - 1] = '\0';
env_array[n++] = cgi_path;
}
if (m >= 0) { if (m >= 0) {
env_array[n++] = p; env_array[n++] = p;
if (m < 8) { if (m < 8) {
p += lws_snprintf(p, end - p, p += lws_snprintf(p, end - p,
"REQUEST_METHOD=%s", "REQUEST_METHOD=%s",
meth_names[m]); meth_names[m]);
sum += lws_snprintf(sum, sumend - sum, "%s ", meth_names[m]); sum += lws_snprintf(sum, sumend - sum, "%s ",
meth_names[m]);
} else { } else {
p += lws_snprintf(p, end - p, p += lws_snprintf(p, end - p,
"REQUEST_METHOD=%s", "REQUEST_METHOD=%s",
lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_COLON_METHOD)); lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_COLON_METHOD));
sum += lws_snprintf(sum, sumend - sum, "%s ", sum += lws_snprintf(sum, sumend - sum, "%s ",
lws_hdr_simple_ptr(wsi, WSI_TOKEN_HTTP_COLON_METHOD)); lws_hdr_simple_ptr(wsi,
WSI_TOKEN_HTTP_COLON_METHOD));
} }
p++; p++;
} }
if (uritok >= 0) if (uritok >= 0)
sum += lws_snprintf(sum, sumend - sum, "%s ", sum += lws_snprintf(sum, sumend - sum, "%s ",
lws_hdr_simple_ptr(wsi, uritok)); lws_hdr_simple_ptr(wsi, uritok));
env_array[n++] = p; env_array[n++] = p;
p += lws_snprintf(p, end - p, "QUERY_STRING="); p += lws_snprintf(p, end - p, "QUERY_STRING=");
...@@ -287,13 +281,23 @@ lws_cgi(struct lws *wsi, const char * const *exec_array, int script_uri_path_len ...@@ -287,13 +281,23 @@ lws_cgi(struct lws *wsi, const char * const *exec_array, int script_uri_path_len
p--; p--;
*p++ = '\0'; *p++ = '\0';
if (uritok >= 0) {
strcpy(cgi_path, "REQUEST_URI=");
c = lws_hdr_copy(wsi, cgi_path + 12,
sizeof(cgi_path) - 12, uritok);
if (c < 0)
goto bail3;
cgi_path[sizeof(cgi_path) - 1] = '\0';
env_array[n++] = cgi_path;
}
sum += lws_snprintf(sum, sumend - sum, "%s", env_array[n - 1]); sum += lws_snprintf(sum, sumend - sum, "%s", env_array[n - 1]);
if (script_uri_path_len >= 0) { if (script_uri_path_len >= 0) {
env_array[n++] = p; env_array[n++] = p;
p += lws_snprintf(p, end - p, "PATH_INFO=%s", p += lws_snprintf(p, end - p, "PATH_INFO=%s",
lws_hdr_simple_ptr(wsi, uritok) + cgi_path + 12 + script_uri_path_len);
script_uri_path_len);
p++; p++;
} }
} }
...@@ -352,7 +356,7 @@ lws_cgi(struct lws *wsi, const char * const *exec_array, int script_uri_path_len ...@@ -352,7 +356,7 @@ lws_cgi(struct lws *wsi, const char * const *exec_array, int script_uri_path_len
env_array[n++] = p; env_array[n++] = p;
p += lws_snprintf(p, end - p, "%s=%s", mp_cgienv->name, p += lws_snprintf(p, end - p, "%s=%s", mp_cgienv->name,
mp_cgienv->value); mp_cgienv->value);
lwsl_debug(" Applying mount-specific cgi env '%s'\n", lwsl_info(" Applying mount-specific cgi env '%s'\n",
env_array[n - 1]); env_array[n - 1]);
p++; p++;
mp_cgienv = mp_cgienv->next; mp_cgienv = mp_cgienv->next;
...@@ -363,7 +367,7 @@ lws_cgi(struct lws *wsi, const char * const *exec_array, int script_uri_path_len ...@@ -363,7 +367,7 @@ lws_cgi(struct lws *wsi, const char * const *exec_array, int script_uri_path_len
#if 0 #if 0
for (m = 0; m < n; m++) for (m = 0; m < n; m++)
lwsl_err(" %s\n", env_array[m]); lwsl_info(" %s\n", env_array[m]);
#endif #endif
/* /*
......
...@@ -717,7 +717,7 @@ lws_client_reset(struct lws **pwsi, int ssl, const char *address, int port, ...@@ -717,7 +717,7 @@ lws_client_reset(struct lws **pwsi, int ssl, const char *address, int port,
} }
#ifdef LWS_WITH_HTTP_PROXY #ifdef LWS_WITH_HTTP_PROXY
static hubbub_error hubbub_error
html_parser_cb(const hubbub_token *token, void *pw) html_parser_cb(const hubbub_token *token, void *pw)
{ {
struct lws_rewrite *r = (struct lws_rewrite *)pw; struct lws_rewrite *r = (struct lws_rewrite *)pw;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment