diff options
| author | Garrett D'Amore <garrett@damore.org> | 2024-11-23 08:23:50 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2024-11-23 09:40:32 -0800 |
| commit | d1a0201e25ca2bf1d28c753aef47795144733b8d (patch) | |
| tree | 4bae8b2644a657bb6738f363664e9ecac5c3e18a /src | |
| parent | ec5042f8d2a5be027c7c549966dc6e4566921748 (diff) | |
| download | nng-d1a0201e25ca2bf1d28c753aef47795144733b8d.tar.gz nng-d1a0201e25ca2bf1d28c753aef47795144733b8d.tar.bz2 nng-d1a0201e25ca2bf1d28c753aef47795144733b8d.zip | |
Add nni_url_clone_inline.
The idea is to allow nng_dialer_create_url() and such to avoid having
to reparse a URL that we already have.
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/url.c | 25 | ||||
| -rw-r--r-- | src/core/url.h | 1 |
2 files changed, 18 insertions, 8 deletions
diff --git a/src/core/url.c b/src/core/url.c index 472e70b2..699734a7 100644 --- a/src/core/url.c +++ b/src/core/url.c @@ -610,16 +610,10 @@ nni_url_asprintf_port(char **str, const nng_url *url, int port) #define URL_COPYSTR(d, s) ((s != NULL) && ((d = nni_strdup(s)) == NULL)) int -nng_url_clone(nng_url **dstp, const nng_url *src) +nni_url_clone_inline(nng_url *dst, const nng_url *src) { - nng_url *dst; - - if ((dst = NNI_ALLOC_STRUCT(dst)) == NULL) { - return (NNG_ENOMEM); - } if (src->u_bufsz != 0) { if ((dst->u_buffer = nni_alloc(dst->u_bufsz)) == NULL) { - NNI_FREE_STRUCT(dst); return (NNG_ENOMEM); } dst->u_bufsz = src->u_bufsz; @@ -646,12 +640,27 @@ nng_url_clone(nng_url **dstp, const nng_url *src) } dst->u_scheme = src->u_scheme; dst->u_port = src->u_port; - *dstp = dst; return (0); } #undef URL_COPYSTR +int +nng_url_clone(nng_url **dstp, const nng_url *src) +{ + nng_url *dst; + int rv; + if ((dst = NNI_ALLOC_STRUCT(dst)) == NULL) { + return (NNG_ENOMEM); + } + if ((rv = nni_url_clone_inline(dst, src) != 0)) { + NNI_FREE_STRUCT(dst); + return (rv); + } + *dstp = dst; + return (0); +} + // nni_url_to_address resolves a URL into a sockaddr, assuming the URL is for // an IP address. int diff --git a/src/core/url.h b/src/core/url.h index bb6b2382..d552d453 100644 --- a/src/core/url.h +++ b/src/core/url.h @@ -33,6 +33,7 @@ extern int nni_url_asprintf_port(char **, const nng_url *, int); extern size_t nni_url_decode(uint8_t *, const char *, size_t); extern int nni_url_to_address(nng_sockaddr *, const nng_url *); extern int nni_url_parse_inline(nng_url *, const char *); +extern int nni_url_clone_inline(nng_url *, const nng_url *); extern void nni_url_fini(nng_url *); #endif // CORE_URL_H |
