Commit be20ced0 authored by valenok's avatar valenok

parse_url() fixed

parent 25578841
...@@ -3703,28 +3703,24 @@ static void discard_current_request_from_buffer(struct mg_connection *conn) { ...@@ -3703,28 +3703,24 @@ static void discard_current_request_from_buffer(struct mg_connection *conn) {
} }
conn->data_len -= conn->request_len + body_len; conn->data_len -= conn->request_len + body_len;
memmove(conn->buf, conn->buf + conn->request_len + body_len, (size_t)conn->data_len); memmove(conn->buf, conn->buf + conn->request_len + body_len,
(size_t) conn->data_len);
} }
static int parse_url(const char *url, char *host, int *port) { static int parse_url(const char *url, char *host, int *port) {
int len; int len;
if (url == NULL) { if (sscanf(url, "%*[htps]://%1024[^:]:%d%n", host, port, &len) == 2 ||
return 0; sscanf(url, "%1024[^:]:%d%n", host, port, &len) == 2) {
}; } else if (sscanf(url, "%*[htps]://%1024[^/]%n", host, &len) == 1) {
*port = 80;
if (!strncmp(url, "http://", 7)) {
url += 7;
}
if (sscanf(url, "%1024[^:]:%d/%n", host, port, &len) == 2) {
} else { } else {
sscanf(url, "%1024[^/]/%n", host, &len); sscanf(url, "%1024[^/]%n", host, &len);
*port = 80; *port = 80;
} }
DEBUG_TRACE(("Host:%s, port:%d", host, *port)); DEBUG_TRACE(("Host:%s, port:%d", host, *port));
return len > 0 && url[len - 1] == '/' ? len - 1 : len; return len;
} }
static void handle_proxy_request(struct mg_connection *conn) { static void handle_proxy_request(struct mg_connection *conn) {
...@@ -3734,7 +3730,7 @@ static void handle_proxy_request(struct mg_connection *conn) { ...@@ -3734,7 +3730,7 @@ static void handle_proxy_request(struct mg_connection *conn) {
DEBUG_TRACE(("URL: %s", ri->uri)); DEBUG_TRACE(("URL: %s", ri->uri));
if (conn->request_info.uri[0] == '/' || if (conn->request_info.uri[0] == '/' ||
(len = parse_url(ri->uri, host, &port)) == 0) { (ri->uri == NULL || (len = parse_url(ri->uri, host, &port))) == 0) {
return; return;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment