]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-http: http-url - Split off http_url_parse_query() from http_url_do_parse().
authorStephan Bosch <stephan.bosch@open-xchange.com>
Wed, 30 Oct 2019 08:48:38 +0000 (09:48 +0100)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Wed, 6 Nov 2019 20:34:08 +0000 (20:34 +0000)
src/lib-http/http-url.c

index 84d7e04bb26c05b5c3a260561a44f15eb7db47fc..1d8ee27856db21efa7d55abaf0cfbb88f7d14ba3 100644 (file)
@@ -221,6 +221,26 @@ http_url_parse_path(struct http_url_parser *url_parser)
        return 1;
 }
 
+static bool
+http_url_parse_query(struct http_url_parser *url_parser, bool have_path)
+{
+       struct uri_parser *parser = &url_parser->parser;
+       struct http_url *url = url_parser->url, *base = url_parser->base;
+       const char *query;
+       int ret;
+
+       if ((ret = uri_parse_query(parser, &query)) < 0)
+               return FALSE;
+       if (url == NULL)
+               return TRUE;
+
+       if (ret > 0)
+               url->enc_query = p_strdup(parser->pool, query);
+       else if (url_parser->relative && !have_path)
+               url->enc_query = p_strdup(parser->pool, base->enc_query);
+       return TRUE;
+}
+
 static bool http_url_do_parse(struct http_url_parser *url_parser)
 {
        struct uri_parser *parser = &url_parser->parser;
@@ -349,14 +369,8 @@ static bool http_url_do_parse(struct http_url_parser *url_parser)
        have_path = (ret > 0);
 
        /* [ "?" query ] */
-       if ((ret = uri_parse_query(parser, &part)) < 0)
+       if (!http_url_parse_query(url_parser, have_path))
                return FALSE;
-       if (ret > 0) {
-               if (url != NULL)
-                       url->enc_query = p_strdup(parser->pool, part);
-       } else if (relative && !have_path && url != NULL) {
-               url->enc_query = p_strdup(parser->pool, base->enc_query);
-       }
 
        /* [ "#" fragment ] */
        if ((ret = uri_parse_fragment(parser, &part)) < 0)