diff options
| author | Garrett D'Amore <garrett@damore.org> | 2024-11-23 08:55:21 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2024-11-23 09:40:32 -0800 |
| commit | 8f29c19954b7e4f0e47036b37b36ab9cd386ad70 (patch) | |
| tree | 535b12c11e1049f80edd4b7b5564c8e3ebcfb07d /src/core/url.c | |
| parent | d1a0201e25ca2bf1d28c753aef47795144733b8d (diff) | |
| download | nng-8f29c19954b7e4f0e47036b37b36ab9cd386ad70.tar.gz nng-8f29c19954b7e4f0e47036b37b36ab9cd386ad70.tar.bz2 nng-8f29c19954b7e4f0e47036b37b36ab9cd386ad70.zip | |
dialers: add nng_dial_url and nng_dialer_create_url
This allows a URL object to be used for dialing, which may
be easier than using a string if you already have the URL object.
Diffstat (limited to 'src/core/url.c')
| -rw-r--r-- | src/core/url.c | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/core/url.c b/src/core/url.c index 699734a7..530e299c 100644 --- a/src/core/url.c +++ b/src/core/url.c @@ -325,8 +325,8 @@ nni_url_default_port(const char *scheme) // Nanomsg URLs are always of the first form, we always require a // scheme with a leading //, such as http:// or tcp://. So our parser // is a bit more restricted, but sufficient for our needs. -int -nni_url_parse_inline(nng_url *url, const char *raw) +static int +nni_url_parse_inline_inner(nng_url *url, const char *raw) { size_t len; const char *s; @@ -508,6 +508,16 @@ nni_url_parse_inline(nng_url *url, const char *raw) } int +nni_url_parse_inline(nng_url *url, const char *raw) +{ + int rv = nni_url_parse_inline_inner(url, raw); + if (rv != 0) { + nni_url_fini(url); + } + return (rv); +} + +int nng_url_parse(nng_url **urlp, const char *raw) { nng_url *url; @@ -517,7 +527,7 @@ nng_url_parse(nng_url **urlp, const char *raw) return (NNG_ENOMEM); } if ((rv = nni_url_parse_inline(url, raw)) != 0) { - nng_url_free(url); + NNI_FREE_STRUCT(url); return (rv); } *urlp = url; @@ -529,6 +539,8 @@ nni_url_fini(nng_url *url) { if (url->u_bufsz != 0) { nni_free(url->u_buffer, url->u_bufsz); + url->u_buffer = NULL; + url->u_bufsz = 0; } } |
