diff options
| author | Garrett D'Amore <garrett@damore.org> | 2019-01-21 22:40:10 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2019-02-16 19:22:27 -0800 |
| commit | 5cf750697624d4fd63cfe26921209d7c30e1a2d2 (patch) | |
| tree | bf11695e5f1ec5e400c87da0cc6ff23935a2eeff /src/core/url.c | |
| parent | ca655b9db689ee0e655248b1a9f166b8db6cc984 (diff) | |
| download | nng-5cf750697624d4fd63cfe26921209d7c30e1a2d2.tar.gz nng-5cf750697624d4fd63cfe26921209d7c30e1a2d2.tar.bz2 nng-5cf750697624d4fd63cfe26921209d7c30e1a2d2.zip | |
fixes #872 create unified nng_stream API
This is a major change, and includes changes to use a polymorphic
stream API for all transports. There have been related bugs fixed
along the way. Additionally the man pages have changed.
The old non-polymorphic APIs are removed now. This is a breaking
change, but the old APIs were never part of any released public API.
Diffstat (limited to 'src/core/url.c')
| -rw-r--r-- | src/core/url.c | 45 |
1 files changed, 31 insertions, 14 deletions
diff --git a/src/core/url.c b/src/core/url.c index 5e2317ea..b2cf77f8 100644 --- a/src/core/url.c +++ b/src/core/url.c @@ -231,8 +231,21 @@ nni_url_default_port(const char *scheme) const char *s; for (int i = 0; (s = nni_url_default_ports[i].scheme) != NULL; i++) { - if (strcmp(s, scheme) == 0) { + size_t l = strlen(s); + if (strncmp(s, scheme, strlen(s)) != 0) { + continue; + } + // It can have a suffix of either "4" or "6" to restrict + // the address family. This is an NNG extension. + switch (scheme[l]) { + case '\0': return (nni_url_default_ports[i].port); + case '4': + case '6': + if (scheme[l + 1] == '\0') { + return (nni_url_default_ports[i].port); + } + break; } } return (""); @@ -463,19 +476,23 @@ error: void nni_url_free(nni_url *url) { - nni_strfree(url->u_rawurl); - nni_strfree(url->u_scheme); - nni_strfree(url->u_userinfo); - nni_strfree(url->u_host); - nni_strfree(url->u_hostname); - nni_strfree(url->u_port); - nni_strfree(url->u_path); - nni_strfree(url->u_query); - nni_strfree(url->u_fragment); - nni_strfree(url->u_requri); - NNI_FREE_STRUCT(url); + if (url != NULL) { + nni_strfree(url->u_rawurl); + nni_strfree(url->u_scheme); + nni_strfree(url->u_userinfo); + nni_strfree(url->u_host); + nni_strfree(url->u_hostname); + nni_strfree(url->u_port); + nni_strfree(url->u_path); + nni_strfree(url->u_query); + nni_strfree(url->u_fragment); + nni_strfree(url->u_requri); + NNI_FREE_STRUCT(url); + } } +#define URL_COPYSTR(d, s) ((s != NULL) && ((d = nni_strdup(s)) == NULL)) + int nni_url_clone(nni_url **dstp, const nni_url *src) { @@ -484,7 +501,6 @@ nni_url_clone(nni_url **dstp, const nni_url *src) if ((dst = NNI_ALLOC_STRUCT(dst)) == NULL) { return (NNG_ENOMEM); } -#define URL_COPYSTR(d, s) ((s != NULL) && ((d = nni_strdup(s)) == NULL)) if (URL_COPYSTR(dst->u_rawurl, src->u_rawurl) || URL_COPYSTR(dst->u_scheme, src->u_scheme) || URL_COPYSTR(dst->u_userinfo, src->u_userinfo) || @@ -498,7 +514,8 @@ nni_url_clone(nni_url **dstp, const nni_url *src) nni_url_free(dst); return (NNG_ENOMEM); } -#undef URL_COPYSTR *dstp = dst; return (0); } + +#undef URL_COPYSTR |
