From 8f29c19954b7e4f0e47036b37b36ab9cd386ad70 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Sat, 23 Nov 2024 08:55:21 -0800 Subject: 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. --- src/core/url.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'src/core/url.c') 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; @@ -507,6 +507,16 @@ nni_url_parse_inline(nng_url *url, const char *raw) return (0); } +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) { @@ -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; } } -- cgit v1.2.3-70-g09d2