]> granicus.if.org Git - libevent/commitdiff
Make evhttp_uri non-public, and give it accessor functions.
authorNick Mathewson <nickm@torproject.org>
Thu, 21 Oct 2010 18:41:12 +0000 (14:41 -0400)
committerNick Mathewson <nickm@torproject.org>
Thu, 21 Oct 2010 18:52:52 +0000 (14:52 -0400)
http.c
include/event2/http.h
test/regress_http.c

diff --git a/http.c b/http.c
index e4b8e31a3a3e7ed6348fdf7dafcbaecf38adb5b5..321920072b6e8d760c7b99ac8cd6997ba00efb8b 100644 (file)
--- a/http.c
+++ b/http.c
@@ -2465,7 +2465,7 @@ evhttp_parse_query__checked_20(const char *str, struct evkeyvalq *headers,
                uri = evhttp_uri_parse(str);
                if (!uri)
                        goto error;
-               query_part = uri->query;
+               query_part = evhttp_uri_get_query(uri);
        } else {
                query_part = str;
        }
@@ -3347,6 +3347,25 @@ bind_socket(const char *address, ev_uint16_t port, int reuse)
        return (fd);
 }
 
+struct evhttp_uri {
+       char *scheme; /* scheme; e.g http, ftp etc */
+       char *userinfo; /* userinfo (typically username:pass), or NULL */
+       char *host; /* hostname, IP address, or NULL */
+       int port; /* port, or zero */
+       char *path; /* path, or "". */
+       char *query; /* query, or NULL */
+       char *fragment; /* fragment or NULL */
+};
+
+struct evhttp_uri *
+evhttp_uri_new(void)
+{
+       struct evhttp_uri *uri = mm_calloc(sizeof(struct evhttp_uri), 1);
+       if (uri)
+               uri->port = -1;
+       return uri;
+}
+
 /* Return true of the string starting at s and ending immediately before eos
  * is a valid URI scheme according to RFC3986
  */
@@ -3689,7 +3708,6 @@ evhttp_uri_free(struct evhttp_uri *uri)
        _URI_FREE_STR(fragment);
 
        mm_free(uri);
-
 #undef _URI_FREE_STR
 }
 
@@ -3756,3 +3774,121 @@ err:
        return output;
 #undef _URI_ADD
 }
+
+const char *
+evhttp_uri_get_scheme(const struct evhttp_uri *uri)
+{
+       return uri->scheme;
+}
+const char *
+evhttp_uri_get_userinfo(const struct evhttp_uri *uri)
+{
+       return uri->userinfo;
+}
+const char *
+evhttp_uri_get_host(const struct evhttp_uri *uri)
+{
+       return uri->host;
+}
+int
+evhttp_uri_get_port(const struct evhttp_uri *uri)
+{
+       return uri->port;
+}
+const char *
+evhttp_uri_get_path(const struct evhttp_uri *uri)
+{
+       return uri->path;
+}
+const char *
+evhttp_uri_get_query(const struct evhttp_uri *uri)
+{
+       return uri->query;
+}
+const char *
+evhttp_uri_get_fragment(const struct evhttp_uri *uri)
+{
+       return uri->fragment;
+}
+
+#define _URI_SET_STR(f) do {                                   \
+       if (uri->f)                                             \
+               mm_free(uri->f);                                \
+       if (f) {                                                \
+               if ((uri->f = mm_strdup(f)) == NULL) {          \
+                       event_warn("%s: strdup()", __func__);   \
+                       return -1;                              \
+               }                                               \
+       } else {                                                \
+               uri->f = NULL;                                  \
+       }                                                       \
+       } while(0)
+
+int
+evhttp_uri_set_scheme(struct evhttp_uri *uri, const char *scheme)
+{
+       if (scheme && !scheme_ok(scheme, scheme+strlen(scheme)))
+               return -1;
+
+       _URI_SET_STR(scheme);
+       return 0;
+}
+int
+evhttp_uri_set_userinfo(struct evhttp_uri *uri, const char *userinfo)
+{
+       if (userinfo && !userinfo_ok(userinfo, userinfo+strlen(userinfo)))
+               return -1;
+       _URI_SET_STR(userinfo);
+       return 0;
+}
+int
+evhttp_uri_set_host(struct evhttp_uri *uri, const char *host)
+{
+       if (host) {
+               if (host[0] == '[') {
+                       if (! bracket_addr_ok(host, host+strlen(host)))
+                               return -1;
+               } else {
+                       if (! regname_ok(host, host+strlen(host)))
+                               return -1;
+               }
+       }
+
+       _URI_SET_STR(host);
+       return 0;
+}
+int
+evhttp_uri_set_port(struct evhttp_uri *uri, int port)
+{
+       if (port < -1)
+               return -1;
+       uri->port = port;
+       return 0;
+}
+#define end_of_cpath(cp,aq) ((const char*)(end_of_path(((char*)(cp)), (aq))))
+
+int
+evhttp_uri_set_path(struct evhttp_uri *uri, const char *path)
+{
+       if (path && end_of_cpath(path, 0) != path+strlen(path))
+               return -1;
+
+       _URI_SET_STR(path);
+       return 0;
+}
+int
+evhttp_uri_set_query(struct evhttp_uri *uri, const char *query)
+{
+       if (query && end_of_cpath(query, 1) != query+strlen(query))
+               return -1;
+       _URI_SET_STR(query);
+       return 0;
+}
+int
+evhttp_uri_set_fragment(struct evhttp_uri *uri, const char *fragment)
+{
+       if (fragment && end_of_cpath(fragment, 1) != fragment+strlen(fragment))
+               return -1;
+       _URI_SET_STR(fragment);
+       return 0;
+}
index d882061c738eae54e76e00291d2f486b9c68ff02..3fdd1f9883cde2c33297f66154b2844cd664049f 100644 (file)
@@ -632,17 +632,70 @@ int evhttp_parse_query__checked_20(const char *uri, struct evkeyvalq *headers,
 char *evhttp_htmlescape(const char *html);
 
 /**
- * A structure to hold a parsed URI.
- */
-struct evhttp_uri {
-       char *scheme; /* scheme; e.g http, ftp etc */
-       char *host; /* hostname, IP address, or NULL */
-       char *userinfo; /* userinfo (typically username:pass), or NULL */
-       int port; /* port, or zero */
-       char *path; /* path, or "". */
-       char *query; /* query, or NULL */
-       char *fragment; /* fragment or NULL */
-};
+ * A structure to hold a parsed URI or Relative-Ref conforming to RFC3986.
+ */
+struct evhttp_uri;
+
+/**
+ * Return a new empty evhttp_uri with no fields set.
+ */
+struct evhttp_uri *evhttp_uri_new(void);
+
+/** Return the scheme of an evhttp_uri, or NULL if there is no scheme has
+ * been set and the evhttp_uri contains a Relative-Ref. */
+const char *evhttp_uri_get_scheme(const struct evhttp_uri *uri);
+/**
+ * Return the userinfo part of an evhttp_uri, or NULL if it has no userinfo
+ * set.
+ */
+const char *evhttp_uri_get_userinfo(const struct evhttp_uri *uri);
+/**
+ * Return the host part of an evhttp_uri, or NULL if it has no host set.
+ * The host may either be a regular hostname (conforming to the RFC 3986
+ * "regname" production), or an IPv4 address, or the empty string, or a
+ * bracketed IPv6 address, or a bracketed 'IP-Future' address.
+ *
+ * Note that having a NULL host means that the URI has no authority
+ * section, but having an empty-string host means that the URI has an
+ * authority section with no host part.  For example,
+ * "mailto:user@example.com" has a host of NULL, but "file:///etc/motd"
+ * has a host of "".
+ */
+const char *evhttp_uri_get_host(const struct evhttp_uri *uri);
+/** Return the port part of an evhttp_uri, or -1 if there is no port set. */
+int evhttp_uri_get_port(const struct evhttp_uri *uri);
+/** Return the path part of an evhttp_uri, or NULL if it has no path set */
+const char *evhttp_uri_get_path(const struct evhttp_uri *uri);
+/** Return the query part of an evhttp_uri (excluding the leading "?"), or
+ * NULL if it has no query set */
+const char *evhttp_uri_get_query(const struct evhttp_uri *uri);
+/** Return the fragment part of an evhttp_uri (excluding the leading "#"),
+ * or NULL if it has no fragment set */
+const char *evhttp_uri_get_fragment(const struct evhttp_uri *uri);
+
+/** Set the scheme of an evhttp_uri, or clear the scheme if scheme==NULL.
+ * Returns 0 on success, -1 if scheme is not well-formed. */
+int evhttp_uri_set_scheme(struct evhttp_uri *uri, const char *scheme);
+/** Set the userinfo of an evhttp_uri, or clear the userinfo if userinfo==NULL.
+ * Returns 0 on success, -1 if userinfo is not well-formed. */
+int evhttp_uri_set_userinfo(struct evhttp_uri *uri, const char *userinfo);
+/** Set the host of an evhttp_uri, or clear the host if host==NULL.
+ * Returns 0 on success, -1 if host is not well-formed. */
+int evhttp_uri_set_host(struct evhttp_uri *uri, const char *host);
+/** Set the port of an evhttp_uri, or clear the port if port==-1.
+ * Returns 0 on success, -1 if port is not well-formed. */
+int evhttp_uri_set_port(struct evhttp_uri *uri, int port);
+/** Set the path of an evhttp_uri, or clear the path if path==NULL.
+ * Returns 0 on success, -1 if path is not well-formed. */
+int evhttp_uri_set_path(struct evhttp_uri *uri, const char *path);
+/** Set the query of an evhttp_uri, or clear the query if query==NULL.
+ * The query should not include a leading "?".
+ * Returns 0 on success, -1 if query is not well-formed. */
+int evhttp_uri_set_query(struct evhttp_uri *uri, const char *query);
+/** Set the fragment of an evhttp_uri, or clear the fragment if fragment==NULL.
+ * The fragment should not include a leading "#".
+ * Returns 0 on success, -1 if fragment is not well-formed. */
+int evhttp_uri_set_fragment(struct evhttp_uri *uri, const char *fragment);
 
 /**
  * Helper function to parse a URI-Reference as specified by RFC3986.
index 34d2781e1e6602a8a31c6866231a678ad8d8ca29..f90e98c38eff5095a412b8670e5cf2b38f23b467 100644 (file)
@@ -1766,263 +1766,262 @@ http_parse_uri_test(void *ptr)
        BAD("://www.example.com/");
 
        /* bad URIs: joining */
-       uri = calloc(sizeof(struct evhttp_uri),1);
-       uri->host = (char*)"www.example.com";
+       uri = evhttp_uri_new();
+       tt_want(0==evhttp_uri_set_host(uri, "www.example.com"));
        tt_want(evhttp_uri_join(uri, url_tmp, sizeof(url_tmp)) != NULL);
        /* not enough space: */
        tt_want(evhttp_uri_join(uri, url_tmp, 3) == NULL);
        /* host is set, but path doesn't start with "/": */
-       uri->path = (char*)"hi_mom";
+       tt_want(0==evhttp_uri_set_path(uri, "hi_mom"));
        tt_want(evhttp_uri_join(uri, url_tmp, sizeof(url_tmp)) == NULL);
        tt_want(evhttp_uri_join(uri, NULL, sizeof(url_tmp))==NULL);
        tt_want(evhttp_uri_join(uri, url_tmp, 0)==NULL);
-       free(uri);
-
+       evhttp_uri_free(uri);
        uri = evhttp_uri_parse("mailto:foo@bar");
        tt_want(uri != NULL);
-       tt_want(uri->host == NULL);
-       tt_want(uri->userinfo == NULL);
-       tt_want(uri->port == -1);
-       tt_want(!strcmp(uri->scheme, "mailto"));
-       tt_want(!strcmp(uri->path, "foo@bar"));
-       tt_want(uri->query == NULL);
-       tt_want(uri->fragment == NULL);
+       tt_want(evhttp_uri_get_host(uri) == NULL);
+       tt_want(evhttp_uri_get_userinfo(uri) == NULL);
+       tt_want(evhttp_uri_get_port(uri) == -1);
+       tt_want(!strcmp(evhttp_uri_get_scheme(uri), "mailto"));
+       tt_want(!strcmp(evhttp_uri_get_path(uri), "foo@bar"));
+       tt_want(evhttp_uri_get_query(uri) == NULL);
+       tt_want(evhttp_uri_get_fragment(uri) == NULL);
        TT_URI("mailto:foo@bar");
        evhttp_uri_free(uri);
 
        uri = evhttp_uri_parse("http://www.test.com/?q=t%33est");
-       tt_want(strcmp(uri->scheme, "http") == 0);
-       tt_want(strcmp(uri->host, "www.test.com") == 0);
-       tt_want(strcmp(uri->path, "/") == 0);
-       tt_want(strcmp(uri->query, "q=t%33est") == 0);
-       tt_want(uri->userinfo == NULL);
-       tt_want(uri->port == -1);
-       tt_want(uri->fragment == NULL);
+       tt_want(strcmp(evhttp_uri_get_scheme(uri), "http") == 0);
+       tt_want(strcmp(evhttp_uri_get_host(uri), "www.test.com") == 0);
+       tt_want(strcmp(evhttp_uri_get_path(uri), "/") == 0);
+       tt_want(strcmp(evhttp_uri_get_query(uri), "q=t%33est") == 0);
+       tt_want(evhttp_uri_get_userinfo(uri) == NULL);
+       tt_want(evhttp_uri_get_port(uri) == -1);
+       tt_want(evhttp_uri_get_fragment(uri) == NULL);
        TT_URI("http://www.test.com/?q=t%33est");
        evhttp_uri_free(uri);
 
        uri = evhttp_uri_parse("http://%77ww.test.com");
-       tt_want(strcmp(uri->scheme, "http") == 0);
-       tt_want(strcmp(uri->host, "%77ww.test.com") == 0);
-       tt_want(strcmp(uri->path, "") == 0);
-       tt_want(uri->query == NULL);
-       tt_want(uri->userinfo == NULL);
-       tt_want(uri->port == -1);
-       tt_want(uri->fragment == NULL);
+       tt_want(strcmp(evhttp_uri_get_scheme(uri), "http") == 0);
+       tt_want(strcmp(evhttp_uri_get_host(uri), "%77ww.test.com") == 0);
+       tt_want(strcmp(evhttp_uri_get_path(uri), "") == 0);
+       tt_want(evhttp_uri_get_query(uri) == NULL);
+       tt_want(evhttp_uri_get_userinfo(uri) == NULL);
+       tt_want(evhttp_uri_get_port(uri) == -1);
+       tt_want(evhttp_uri_get_fragment(uri) == NULL);
        TT_URI("http://%77ww.test.com");
        evhttp_uri_free(uri);
 
        uri = evhttp_uri_parse("http://www.test.com?q=test");
-       tt_want(strcmp(uri->scheme, "http") == 0);
-       tt_want(strcmp(uri->host, "www.test.com") == 0);
-       tt_want(strcmp(uri->path, "") == 0);
-       tt_want(strcmp(uri->query, "q=test") == 0);
-       tt_want(uri->userinfo == NULL);
-       tt_want(uri->port == -1);
-       tt_want(uri->fragment == NULL);
+       tt_want(strcmp(evhttp_uri_get_scheme(uri), "http") == 0);
+       tt_want(strcmp(evhttp_uri_get_host(uri), "www.test.com") == 0);
+       tt_want(strcmp(evhttp_uri_get_path(uri), "") == 0);
+       tt_want(strcmp(evhttp_uri_get_query(uri), "q=test") == 0);
+       tt_want(evhttp_uri_get_userinfo(uri) == NULL);
+       tt_want(evhttp_uri_get_port(uri) == -1);
+       tt_want(evhttp_uri_get_fragment(uri) == NULL);
        TT_URI("http://www.test.com?q=test");
        evhttp_uri_free(uri);
 
        uri = evhttp_uri_parse("http://www.test.com#fragment");
-       tt_want(strcmp(uri->scheme, "http") == 0);
-       tt_want(strcmp(uri->host, "www.test.com") == 0);
-       tt_want(strcmp(uri->path, "") == 0);
-       tt_want(uri->query == NULL);
-       tt_want(uri->userinfo == NULL);
-       tt_want(uri->port == -1);
-       tt_want_str_op(uri->fragment, ==, "fragment");
+       tt_want(strcmp(evhttp_uri_get_scheme(uri), "http") == 0);
+       tt_want(strcmp(evhttp_uri_get_host(uri), "www.test.com") == 0);
+       tt_want(strcmp(evhttp_uri_get_path(uri), "") == 0);
+       tt_want(evhttp_uri_get_query(uri) == NULL);
+       tt_want(evhttp_uri_get_userinfo(uri) == NULL);
+       tt_want(evhttp_uri_get_port(uri) == -1);
+       tt_want_str_op(evhttp_uri_get_fragment(uri), ==, "fragment");
        TT_URI("http://www.test.com#fragment");
        evhttp_uri_free(uri);
 
        uri = evhttp_uri_parse("http://8000/");
-       tt_want(strcmp(uri->scheme, "http") == 0);
-       tt_want(strcmp(uri->host, "8000") == 0);
-       tt_want(strcmp(uri->path, "/") == 0);
-       tt_want(uri->query == NULL);
-       tt_want(uri->userinfo == NULL);
-       tt_want(uri->port == -1);
-       tt_want(uri->fragment == NULL);
+       tt_want(strcmp(evhttp_uri_get_scheme(uri), "http") == 0);
+       tt_want(strcmp(evhttp_uri_get_host(uri), "8000") == 0);
+       tt_want(strcmp(evhttp_uri_get_path(uri), "/") == 0);
+       tt_want(evhttp_uri_get_query(uri) == NULL);
+       tt_want(evhttp_uri_get_userinfo(uri) == NULL);
+       tt_want(evhttp_uri_get_port(uri) == -1);
+       tt_want(evhttp_uri_get_fragment(uri) == NULL);
        TT_URI("http://8000/");
        evhttp_uri_free(uri);
 
        uri = evhttp_uri_parse("http://:8000/");
-       tt_want(strcmp(uri->scheme, "http") == 0);
-       tt_want(strcmp(uri->host, "") == 0);
-       tt_want(strcmp(uri->path, "/") == 0);
-       tt_want(uri->query == NULL);
-       tt_want(uri->userinfo == NULL);
-       tt_want(uri->port == 8000);
-       tt_want(uri->fragment == NULL);
+       tt_want(strcmp(evhttp_uri_get_scheme(uri), "http") == 0);
+       tt_want(strcmp(evhttp_uri_get_host(uri), "") == 0);
+       tt_want(strcmp(evhttp_uri_get_path(uri), "/") == 0);
+       tt_want(evhttp_uri_get_query(uri) == NULL);
+       tt_want(evhttp_uri_get_userinfo(uri) == NULL);
+       tt_want(evhttp_uri_get_port(uri) == 8000);
+       tt_want(evhttp_uri_get_fragment(uri) == NULL);
        TT_URI("http://:8000/");
        evhttp_uri_free(uri);
 
        uri = evhttp_uri_parse("http://www.test.com:/"); /* empty port */
-       tt_want(strcmp(uri->scheme, "http") == 0);
-       tt_want(strcmp(uri->host, "www.test.com") == 0);
-       tt_want_str_op(uri->path, ==, "/");
-       tt_want(uri->query == NULL);
-       tt_want(uri->userinfo == NULL);
-       tt_want(uri->port == -1);
-       tt_want(uri->fragment == NULL);
+       tt_want(strcmp(evhttp_uri_get_scheme(uri), "http") == 0);
+       tt_want(strcmp(evhttp_uri_get_host(uri), "www.test.com") == 0);
+       tt_want_str_op(evhttp_uri_get_path(uri), ==, "/");
+       tt_want(evhttp_uri_get_query(uri) == NULL);
+       tt_want(evhttp_uri_get_userinfo(uri) == NULL);
+       tt_want(evhttp_uri_get_port(uri) == -1);
+       tt_want(evhttp_uri_get_fragment(uri) == NULL);
        TT_URI("http://www.test.com/");
        evhttp_uri_free(uri);
 
        uri = evhttp_uri_parse("http://www.test.com:"); /* empty port 2 */
-       tt_want(strcmp(uri->scheme, "http") == 0);
-       tt_want(strcmp(uri->host, "www.test.com") == 0);
-       tt_want(strcmp(uri->path, "") == 0);
-       tt_want(uri->query == NULL);
-       tt_want(uri->userinfo == NULL);
-       tt_want(uri->port == -1);
-       tt_want(uri->fragment == NULL);
+       tt_want(strcmp(evhttp_uri_get_scheme(uri), "http") == 0);
+       tt_want(strcmp(evhttp_uri_get_host(uri), "www.test.com") == 0);
+       tt_want(strcmp(evhttp_uri_get_path(uri), "") == 0);
+       tt_want(evhttp_uri_get_query(uri) == NULL);
+       tt_want(evhttp_uri_get_userinfo(uri) == NULL);
+       tt_want(evhttp_uri_get_port(uri) == -1);
+       tt_want(evhttp_uri_get_fragment(uri) == NULL);
        TT_URI("http://www.test.com");
        evhttp_uri_free(uri);
 
        uri = evhttp_uri_parse("ftp://www.test.com/?q=test");
-       tt_want(strcmp(uri->scheme, "ftp") == 0);
-       tt_want(strcmp(uri->host, "www.test.com") == 0);
-       tt_want(strcmp(uri->path, "/") == 0);
-       tt_want(strcmp(uri->query, "q=test") == 0);
-       tt_want(uri->userinfo == NULL);
-       tt_want(uri->port == -1);
-       tt_want(uri->fragment == NULL);
+       tt_want(strcmp(evhttp_uri_get_scheme(uri), "ftp") == 0);
+       tt_want(strcmp(evhttp_uri_get_host(uri), "www.test.com") == 0);
+       tt_want(strcmp(evhttp_uri_get_path(uri), "/") == 0);
+       tt_want(strcmp(evhttp_uri_get_query(uri), "q=test") == 0);
+       tt_want(evhttp_uri_get_userinfo(uri) == NULL);
+       tt_want(evhttp_uri_get_port(uri) == -1);
+       tt_want(evhttp_uri_get_fragment(uri) == NULL);
        TT_URI("ftp://www.test.com/?q=test");
        evhttp_uri_free(uri);
 
        uri = evhttp_uri_parse("ftp://[::1]:999/?q=test");
-       tt_want(strcmp(uri->scheme, "ftp") == 0);
-       tt_want(strcmp(uri->host, "[::1]") == 0);
-       tt_want(strcmp(uri->path, "/") == 0);
-       tt_want(strcmp(uri->query, "q=test") == 0);
-       tt_want(uri->userinfo == NULL);
-       tt_want(uri->port == 999);
-       tt_want(uri->fragment == NULL);
+       tt_want(strcmp(evhttp_uri_get_scheme(uri), "ftp") == 0);
+       tt_want(strcmp(evhttp_uri_get_host(uri), "[::1]") == 0);
+       tt_want(strcmp(evhttp_uri_get_path(uri), "/") == 0);
+       tt_want(strcmp(evhttp_uri_get_query(uri), "q=test") == 0);
+       tt_want(evhttp_uri_get_userinfo(uri) == NULL);
+       tt_want(evhttp_uri_get_port(uri) == 999);
+       tt_want(evhttp_uri_get_fragment(uri) == NULL);
        TT_URI("ftp://[::1]:999/?q=test");
        evhttp_uri_free(uri);
 
        uri = evhttp_uri_parse("ftp://[ff00::127.0.0.1]/?q=test");
-       tt_want(strcmp(uri->scheme, "ftp") == 0);
-       tt_want(strcmp(uri->host, "[ff00::127.0.0.1]") == 0);
-       tt_want(strcmp(uri->path, "/") == 0);
-       tt_want(strcmp(uri->query, "q=test") == 0);
-       tt_want(uri->userinfo == NULL);
-       tt_want(uri->port == -1);
-       tt_want(uri->fragment == NULL);
+       tt_want(strcmp(evhttp_uri_get_scheme(uri), "ftp") == 0);
+       tt_want(strcmp(evhttp_uri_get_host(uri), "[ff00::127.0.0.1]") == 0);
+       tt_want(strcmp(evhttp_uri_get_path(uri), "/") == 0);
+       tt_want(strcmp(evhttp_uri_get_query(uri), "q=test") == 0);
+       tt_want(evhttp_uri_get_userinfo(uri) == NULL);
+       tt_want(evhttp_uri_get_port(uri) == -1);
+       tt_want(evhttp_uri_get_fragment(uri) == NULL);
        TT_URI("ftp://[ff00::127.0.0.1]/?q=test");
        evhttp_uri_free(uri);
 
        uri = evhttp_uri_parse("ftp://[v99.not_(any:time)_soon]/?q=test");
-       tt_want(strcmp(uri->scheme, "ftp") == 0);
-       tt_want(strcmp(uri->host, "[v99.not_(any:time)_soon]") == 0);
-       tt_want(strcmp(uri->path, "/") == 0);
-       tt_want(strcmp(uri->query, "q=test") == 0);
-       tt_want(uri->userinfo == NULL);
-       tt_want(uri->port == -1);
-       tt_want(uri->fragment == NULL);
+       tt_want(strcmp(evhttp_uri_get_scheme(uri), "ftp") == 0);
+       tt_want(strcmp(evhttp_uri_get_host(uri), "[v99.not_(any:time)_soon]") == 0);
+       tt_want(strcmp(evhttp_uri_get_path(uri), "/") == 0);
+       tt_want(strcmp(evhttp_uri_get_query(uri), "q=test") == 0);
+       tt_want(evhttp_uri_get_userinfo(uri) == NULL);
+       tt_want(evhttp_uri_get_port(uri) == -1);
+       tt_want(evhttp_uri_get_fragment(uri) == NULL);
        TT_URI("ftp://[v99.not_(any:time)_soon]/?q=test");
        evhttp_uri_free(uri);
 
        uri = evhttp_uri_parse("scheme://user:pass@foo.com:42/?q=test&s=some+thing#fragment");
-       tt_want(strcmp(uri->scheme, "scheme") == 0);
-       tt_want(strcmp(uri->userinfo, "user:pass") == 0);
-       tt_want(strcmp(uri->host, "foo.com") == 0);
-       tt_want(uri->port == 42);
-       tt_want(strcmp(uri->path, "/") == 0);
-       tt_want(strcmp(uri->query, "q=test&s=some+thing") == 0);
-       tt_want(strcmp(uri->fragment, "fragment") == 0);
+       tt_want(strcmp(evhttp_uri_get_scheme(uri), "scheme") == 0);
+       tt_want(strcmp(evhttp_uri_get_userinfo(uri), "user:pass") == 0);
+       tt_want(strcmp(evhttp_uri_get_host(uri), "foo.com") == 0);
+       tt_want(evhttp_uri_get_port(uri) == 42);
+       tt_want(strcmp(evhttp_uri_get_path(uri), "/") == 0);
+       tt_want(strcmp(evhttp_uri_get_query(uri), "q=test&s=some+thing") == 0);
+       tt_want(strcmp(evhttp_uri_get_fragment(uri), "fragment") == 0);
        TT_URI("scheme://user:pass@foo.com:42/?q=test&s=some+thing#fragment");
        evhttp_uri_free(uri);
 
        uri = evhttp_uri_parse("scheme://user@foo.com/#fragment");
-       tt_want(strcmp(uri->scheme, "scheme") == 0);
-       tt_want(strcmp(uri->userinfo, "user") == 0);
-       tt_want(strcmp(uri->host, "foo.com") == 0);
-       tt_want(uri->port == -1);
-       tt_want(strcmp(uri->path, "/") == 0);
-       tt_want(uri->query == NULL);
-       tt_want(strcmp(uri->fragment, "fragment") == 0);
+       tt_want(strcmp(evhttp_uri_get_scheme(uri), "scheme") == 0);
+       tt_want(strcmp(evhttp_uri_get_userinfo(uri), "user") == 0);
+       tt_want(strcmp(evhttp_uri_get_host(uri), "foo.com") == 0);
+       tt_want(evhttp_uri_get_port(uri) == -1);
+       tt_want(strcmp(evhttp_uri_get_path(uri), "/") == 0);
+       tt_want(evhttp_uri_get_query(uri) == NULL);
+       tt_want(strcmp(evhttp_uri_get_fragment(uri), "fragment") == 0);
        TT_URI("scheme://user@foo.com/#fragment");
        evhttp_uri_free(uri);
 
        uri = evhttp_uri_parse("scheme://%75ser@foo.com/#frag@ment");
-       tt_want(strcmp(uri->scheme, "scheme") == 0);
-       tt_want(strcmp(uri->userinfo, "%75ser") == 0);
-       tt_want(strcmp(uri->host, "foo.com") == 0);
-       tt_want(uri->port == -1);
-       tt_want(strcmp(uri->path, "/") == 0);
-       tt_want(uri->query == NULL);
-       tt_want(strcmp(uri->fragment, "frag@ment") == 0);
+       tt_want(strcmp(evhttp_uri_get_scheme(uri), "scheme") == 0);
+       tt_want(strcmp(evhttp_uri_get_userinfo(uri), "%75ser") == 0);
+       tt_want(strcmp(evhttp_uri_get_host(uri), "foo.com") == 0);
+       tt_want(evhttp_uri_get_port(uri) == -1);
+       tt_want(strcmp(evhttp_uri_get_path(uri), "/") == 0);
+       tt_want(evhttp_uri_get_query(uri) == NULL);
+       tt_want(strcmp(evhttp_uri_get_fragment(uri), "frag@ment") == 0);
        TT_URI("scheme://%75ser@foo.com/#frag@ment");
        evhttp_uri_free(uri);
 
        uri = evhttp_uri_parse("file:///some/path/to/the/file");
-       tt_want(strcmp(uri->scheme, "file") == 0);
-       tt_want(uri->userinfo == NULL);
-       tt_want(strcmp(uri->host, "") == 0);
-       tt_want(uri->port == -1);
-       tt_want(strcmp(uri->path, "/some/path/to/the/file") == 0);
-       tt_want(uri->query == NULL);
-       tt_want(uri->fragment == NULL);
+       tt_want(strcmp(evhttp_uri_get_scheme(uri), "file") == 0);
+       tt_want(evhttp_uri_get_userinfo(uri) == NULL);
+       tt_want(strcmp(evhttp_uri_get_host(uri), "") == 0);
+       tt_want(evhttp_uri_get_port(uri) == -1);
+       tt_want(strcmp(evhttp_uri_get_path(uri), "/some/path/to/the/file") == 0);
+       tt_want(evhttp_uri_get_query(uri) == NULL);
+       tt_want(evhttp_uri_get_fragment(uri) == NULL);
        TT_URI("file:///some/path/to/the/file");
        evhttp_uri_free(uri);
 
        uri = evhttp_uri_parse("///some/path/to/the-file");
        tt_want(uri != NULL);
-       tt_want(uri->scheme == NULL);
-       tt_want(uri->userinfo == NULL);
-       tt_want(strcmp(uri->host, "") == 0);
-       tt_want(uri->port == -1);
-       tt_want(strcmp(uri->path, "/some/path/to/the-file") == 0);
-       tt_want(uri->query == NULL);
-       tt_want(uri->fragment == NULL);
+       tt_want(evhttp_uri_get_scheme(uri) == NULL);
+       tt_want(evhttp_uri_get_userinfo(uri) == NULL);
+       tt_want(strcmp(evhttp_uri_get_host(uri), "") == 0);
+       tt_want(evhttp_uri_get_port(uri) == -1);
+       tt_want(strcmp(evhttp_uri_get_path(uri), "/some/path/to/the-file") == 0);
+       tt_want(evhttp_uri_get_query(uri) == NULL);
+       tt_want(evhttp_uri_get_fragment(uri) == NULL);
        TT_URI("///some/path/to/the-file");
        evhttp_uri_free(uri);
 
        uri = evhttp_uri_parse("/s:ome/path/to/the-file?q=99#fred");
        tt_want(uri != NULL);
-       tt_want(uri->scheme == NULL);
-       tt_want(uri->userinfo == NULL);
-       tt_want(uri->host == NULL);
-       tt_want(uri->port == -1);
-       tt_want(strcmp(uri->path, "/s:ome/path/to/the-file") == 0);
-       tt_want(strcmp(uri->query, "q=99") == 0);
-       tt_want(strcmp(uri->fragment, "fred") == 0);
+       tt_want(evhttp_uri_get_scheme(uri) == NULL);
+       tt_want(evhttp_uri_get_userinfo(uri) == NULL);
+       tt_want(evhttp_uri_get_host(uri) == NULL);
+       tt_want(evhttp_uri_get_port(uri) == -1);
+       tt_want(strcmp(evhttp_uri_get_path(uri), "/s:ome/path/to/the-file") == 0);
+       tt_want(strcmp(evhttp_uri_get_query(uri), "q=99") == 0);
+       tt_want(strcmp(evhttp_uri_get_fragment(uri), "fred") == 0);
        TT_URI("/s:ome/path/to/the-file?q=99#fred");
        evhttp_uri_free(uri);
 
        uri = evhttp_uri_parse("relative/path/with/co:lon");
        tt_want(uri != NULL);
-       tt_want(uri->scheme == NULL);
-       tt_want(uri->userinfo == NULL);
-       tt_want(uri->host == NULL);
-       tt_want(uri->port == -1);
-       tt_want(strcmp(uri->path, "relative/path/with/co:lon") == 0);
-       tt_want(uri->query == NULL);
-       tt_want(uri->fragment == NULL);
+       tt_want(evhttp_uri_get_scheme(uri) == NULL);
+       tt_want(evhttp_uri_get_userinfo(uri) == NULL);
+       tt_want(evhttp_uri_get_host(uri) == NULL);
+       tt_want(evhttp_uri_get_port(uri) == -1);
+       tt_want(strcmp(evhttp_uri_get_path(uri), "relative/path/with/co:lon") == 0);
+       tt_want(evhttp_uri_get_query(uri) == NULL);
+       tt_want(evhttp_uri_get_fragment(uri) == NULL);
        TT_URI("relative/path/with/co:lon");
        evhttp_uri_free(uri);
 
        uri = evhttp_uri_parse("bob?q=99&q2=q?33#fr?ed");
        tt_want(uri != NULL);
-       tt_want(uri->scheme == NULL);
-       tt_want(uri->userinfo == NULL);
-       tt_want(uri->host == NULL);
-       tt_want(uri->port == -1);
-       tt_want(strcmp(uri->path, "bob") == 0);
-       tt_want(strcmp(uri->query, "q=99&q2=q?33") == 0);
-       tt_want(strcmp(uri->fragment, "fr?ed") == 0);
+       tt_want(evhttp_uri_get_scheme(uri) == NULL);
+       tt_want(evhttp_uri_get_userinfo(uri) == NULL);
+       tt_want(evhttp_uri_get_host(uri) == NULL);
+       tt_want(evhttp_uri_get_port(uri) == -1);
+       tt_want(strcmp(evhttp_uri_get_path(uri), "bob") == 0);
+       tt_want(strcmp(evhttp_uri_get_query(uri), "q=99&q2=q?33") == 0);
+       tt_want(strcmp(evhttp_uri_get_fragment(uri), "fr?ed") == 0);
        TT_URI("bob?q=99&q2=q?33#fr?ed");
        evhttp_uri_free(uri);
 
        uri = evhttp_uri_parse("#fr?ed");
        tt_want(uri != NULL);
-       tt_want(uri->scheme == NULL);
-       tt_want(uri->userinfo == NULL);
-       tt_want(uri->host == NULL);
-       tt_want(uri->port == -1);
-       tt_want(strcmp(uri->path, "") == 0);
-       tt_want(uri->query == NULL);
-       tt_want(strcmp(uri->fragment, "fr?ed") == 0);
+       tt_want(evhttp_uri_get_scheme(uri) == NULL);
+       tt_want(evhttp_uri_get_userinfo(uri) == NULL);
+       tt_want(evhttp_uri_get_host(uri) == NULL);
+       tt_want(evhttp_uri_get_port(uri) == -1);
+       tt_want(strcmp(evhttp_uri_get_path(uri), "") == 0);
+       tt_want(evhttp_uri_get_query(uri) == NULL);
+       tt_want(strcmp(evhttp_uri_get_fragment(uri), "fr?ed") == 0);
        TT_URI("#fr?ed");
        evhttp_uri_free(uri);
 }