diff options
| author | Garrett D'Amore <garrett@damore.org> | 2018-02-02 10:57:18 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2018-02-02 10:57:18 -0800 |
| commit | 490bc97dbf76fae2a99c8bacd5fd9be332d68b90 (patch) | |
| tree | 5504c23957e99ef5290c9048fedc27b1dbc25e77 | |
| parent | 5e5f814d63d4e00365b0ae726bc18831aa28e88f (diff) | |
| download | nng-490bc97dbf76fae2a99c8bacd5fd9be332d68b90.tar.gz nng-490bc97dbf76fae2a99c8bacd5fd9be332d68b90.tar.bz2 nng-490bc97dbf76fae2a99c8bacd5fd9be332d68b90.zip | |
Add, and document, the url->u_requri member.
This member is the value passed in actual HTTP protocol, so it
is useful with the function nng_http_req_set_uri().
| -rw-r--r-- | docs/nng_url_parse.adoc | 42 | ||||
| -rw-r--r-- | src/core/url.c | 8 | ||||
| -rw-r--r-- | src/core/url.h | 19 | ||||
| -rw-r--r-- | src/nng.h | 2 | ||||
| -rw-r--r-- | src/supplemental/http/http_msg.c | 2 | ||||
| -rw-r--r-- | tests/url.c | 18 |
6 files changed, 37 insertions, 54 deletions
diff --git a/docs/nng_url_parse.adoc b/docs/nng_url_parse.adoc index 0ea0cd1d..9d4be764 100644 --- a/docs/nng_url_parse.adoc +++ b/docs/nng_url_parse.adoc @@ -33,30 +33,21 @@ is stored in _urlp_. The `nng_url` structure has at least the following members: -`char *u_scheme`:: The scheme, such as `http`. Always lower case. - -`char *u_rawurl`:: An unparsed form of the raw URL, with only minimal - canonicalization performed. - -`char *u_userinfo`:: The userinfo component if one was present, - `NULL` otherwise. - -`char *u_host`:: The full host, including hostname, and colon and port - if present, otehrwise the empty string. - -`char *u_hostname`:: The hostname if present, otherwise the empty string. - Always lower case. - -`char *u_port`:: The port if present. If not present, a default port - will be stored here. If no default is available, then - the empty string. - -`char *u_path`:: The path component if present, or the empty string - otherwise. - -`char *u_query`:: The query component if present, NULL otherwise. - -`char *u_fragment`:: The fragment if present, NULL otherwise. +[source, c] +---- +struct nng_url { + char *u_scheme; // Scheme, such as "http"; always lower case. + char *u_rawurl; // Unparsed URL, with minimal canonicalization. + char *u_userinfo; // Userinfo component, or NULL. + char *u_host; // Full host, including port if present. + char *u_hostname; // Hostname only (or address), or empy string. + char *u_port; // Port number, may be default or empty string. + char *u_path; // Path if present, empty string otherwise. + char *u_query; // Query info if present, NULL otherwise. + char *u_fragment; // Fragment if present, NULL otherwise. + char *u_requri; // Request-URI (path[?query][#fragment]) +}; +---- === URL Canonicalization @@ -82,6 +73,9 @@ follows: 8. If a port was not specified, but the scheme defines a default port, then `u_port` will be filled in with the value of the default port. +TIP: Only the `u_userinfo`, `u_query`, and `u_fragment` members will ever be + `NULL`. The other members will be filled in with either default values + or the empty string if they cannot be determined from _str_. == RETURN VALUES diff --git a/src/core/url.c b/src/core/url.c index 88a0cf0a..6a2a4e53 100644 --- a/src/core/url.c +++ b/src/core/url.c @@ -340,11 +340,11 @@ nni_url_parse(nni_url **urlp, const char *raw) url->u_host[len] = '\0'; s += len; - if ((rv = url_canonify_uri(&url->u_rawpath, s)) != 0) { + if ((rv = url_canonify_uri(&url->u_requri, s)) != 0) { goto error; } - s = url->u_rawpath; + s = url->u_requri; for (len = 0; (c = s[len]) != '\0'; len++) { if ((c == '?') || (c == '#')) { break; @@ -450,7 +450,7 @@ nni_url_free(nni_url *url) nni_strfree(url->u_path); nni_strfree(url->u_query); nni_strfree(url->u_fragment); - nni_strfree(url->u_rawpath); + nni_strfree(url->u_requri); NNI_FREE_STRUCT(url); } @@ -469,7 +469,7 @@ nni_url_clone(nni_url **dstp, const nni_url *src) URL_COPYSTR(dst->u_host, src->u_host) || URL_COPYSTR(dst->u_hostname, src->u_hostname) || URL_COPYSTR(dst->u_port, src->u_port) || - URL_COPYSTR(dst->u_rawpath, src->u_rawpath) || + URL_COPYSTR(dst->u_requri, src->u_requri) || URL_COPYSTR(dst->u_path, src->u_path) || URL_COPYSTR(dst->u_query, src->u_query) || URL_COPYSTR(dst->u_fragment, src->u_fragment)) { diff --git a/src/core/url.h b/src/core/url.h index b3407277..b96401bd 100644 --- a/src/core/url.h +++ b/src/core/url.h @@ -11,22 +11,11 @@ #ifndef CORE_URL_H #define CORE_URL_H -struct nni_url { - char *u_rawurl; // never NULL - char *u_scheme; // never NULL - char *u_userinfo; // will be NULL if not specified - char *u_host; // including colon and port - char *u_hostname; // name only, will be "" if not specified - char *u_port; // port, will be "" if not specified - char *u_path; // path, will be "" if not specified - char *u_query; // without '?', will be NULL if not specified - char *u_fragment; // without '#', will be NULL if not specified - char *u_rawpath; // includes query and fragment, "" if not specified -}; +#include "core/defs.h" -extern int nni_url_parse(nni_url **, const char *path); -extern void nni_url_free(nni_url *); -extern int nni_url_clone(nni_url **, const nni_url *); +extern int nni_url_parse(nni_url **, const char *path); +extern void nni_url_free(nni_url *); +extern int nni_url_clone(nni_url **, const nni_url *); extern const char *nni_url_default_port(const char *); #endif // CORE_URL_H @@ -761,7 +761,7 @@ typedef struct nng_url { char *u_path; // path, will be "" if not specified char *u_query; // without '?', will be NULL if not specified char *u_fragment; // without '#', will be NULL if not specified - char *u_rawpath; // includes query and fragment, "" if not specified + char *u_requri; // includes query and fragment, "" if not specified } nng_url; // nng_url_parse parses a URL string into a structured form. diff --git a/src/supplemental/http/http_msg.c b/src/supplemental/http/http_msg.c index 81c1b453..9a5bac68 100644 --- a/src/supplemental/http/http_msg.c +++ b/src/supplemental/http/http_msg.c @@ -591,7 +591,7 @@ nni_http_req_alloc(nni_http_req **reqp, const nni_url *url) if (url != NULL) { const char *host; int rv; - if ((req->uri = nni_strdup(url->u_rawpath)) == NULL) { + if ((req->uri = nni_strdup(url->u_requri)) == NULL) { NNI_FREE_STRUCT(req); return (NNG_ENOMEM); } diff --git a/tests/url.c b/tests/url.c index a4b4457b..c35feee1 100644 --- a/tests/url.c +++ b/tests/url.c @@ -26,7 +26,7 @@ TestMain("URLs", { So(strcmp(url->u_hostname, "www.google.com") == 0); So(strcmp(url->u_port, "80") == 0); So(strcmp(url->u_path, "") == 0); - So(strcmp(url->u_rawpath, "") == 0); + So(strcmp(url->u_requri, "") == 0); So(url->u_query == NULL); So(url->u_fragment == NULL); So(url->u_userinfo == NULL); @@ -41,7 +41,7 @@ TestMain("URLs", { So(strcmp(url->u_hostname, "www.google.com") == 0); So(strcmp(url->u_port, "1234") == 0); So(strcmp(url->u_path, "") == 0); - So(strcmp(url->u_rawpath, "") == 0); + So(strcmp(url->u_requri, "") == 0); So(url->u_query == NULL); So(url->u_fragment == NULL); So(url->u_userinfo == NULL); @@ -57,7 +57,7 @@ TestMain("URLs", { So(strcmp(url->u_hostname, "www.google.com") == 0); So(strcmp(url->u_port, "1234") == 0); So(strcmp(url->u_path, "/somewhere") == 0); - So(strcmp(url->u_rawpath, "/somewhere") == 0); + So(strcmp(url->u_requri, "/somewhere") == 0); So(url->u_userinfo == NULL); So(url->u_query == NULL); So(url->u_fragment == NULL); @@ -73,7 +73,7 @@ TestMain("URLs", { So(strcmp(url->u_hostname, "www.google.com") == 0); So(strcmp(url->u_port, "1234") == 0); So(strcmp(url->u_path, "/somewhere") == 0); - So(strcmp(url->u_rawpath, "/somewhere") == 0); + So(strcmp(url->u_requri, "/somewhere") == 0); So(url->u_query == NULL); So(url->u_fragment == NULL); nng_url_free(url); @@ -88,7 +88,7 @@ TestMain("URLs", { So(strcmp(url->u_port, "80") == 0); So(strcmp(url->u_path, "/somewhere") == 0); So(strcmp(url->u_query, "result=yes") == 0); - So(strcmp(url->u_rawpath, "/somewhere?result=yes") == 0); + So(strcmp(url->u_requri, "/somewhere?result=yes") == 0); So(url->u_userinfo == NULL); So(url->u_fragment == NULL); nng_url_free(url); @@ -105,7 +105,7 @@ TestMain("URLs", { So(strcmp(url->u_path, "/somewhere") == 0); So(strcmp(url->u_query, "result=yes") == 0); So(strcmp(url->u_fragment, "chapter1") == 0); - So(strcmp(url->u_rawpath, "/somewhere?result=yes#chapter1") == + So(strcmp(url->u_requri, "/somewhere?result=yes#chapter1") == 0); So(url->u_userinfo == NULL); nng_url_free(url); @@ -120,7 +120,7 @@ TestMain("URLs", { So(strcmp(url->u_port, "80") == 0); So(strcmp(url->u_path, "/somewhere") == 0); So(strcmp(url->u_fragment, "chapter2") == 0); - So(strcmp(url->u_rawpath, "/somewhere#chapter2") == 0); + So(strcmp(url->u_requri, "/somewhere#chapter2") == 0); So(url->u_query == NULL); So(url->u_userinfo == NULL); nng_url_free(url); @@ -134,7 +134,7 @@ TestMain("URLs", { So(strcmp(url->u_path, "") == 0); So(strcmp(url->u_port, "80") == 0); So(strcmp(url->u_fragment, "chapter3") == 0); - So(strcmp(url->u_rawpath, "#chapter3") == 0); + So(strcmp(url->u_requri, "#chapter3") == 0); So(url->u_query == NULL); So(url->u_userinfo == NULL); nng_url_free(url); @@ -149,7 +149,7 @@ TestMain("URLs", { So(strcmp(url->u_path, "") == 0); So(strcmp(url->u_port, "80") == 0); So(strcmp(url->u_query, "color=red") == 0); - So(strcmp(url->u_rawpath, "?color=red") == 0); + So(strcmp(url->u_requri, "?color=red") == 0); So(url->u_fragment == NULL); So(url->u_userinfo == NULL); nng_url_free(url); |
