From 3d075fad7496ec126c5087d1c36ab7a4af73ce16 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Mon, 22 Jan 2018 14:05:10 -0800 Subject: fixes #219 transports should take URL structure instead of string address This eliminates a bunch of redundant URL parsing, using the common URL logic we already have in place. While here I fixed a problem with the TLS and WSS test suites that was failing on older Ubuntu -- apparently older versions of mbedTLS were unhappy if selecting OPTIONAL verification without a validate certificate chain. --- src/core/url.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/core/url.c') diff --git a/src/core/url.c b/src/core/url.c index a5b4fd06..3d8898bd 100644 --- a/src/core/url.c +++ b/src/core/url.c @@ -453,4 +453,31 @@ nni_url_free(nni_url *url) nni_strfree(url->u_fragment); nni_strfree(url->u_rawpath); NNI_FREE_STRUCT(url); +} + +int +nni_url_clone(nni_url **dstp, const nni_url *src) +{ + nni_url *dst; + + 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) || + 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_path, src->u_path) || + URL_COPYSTR(dst->u_query, src->u_query) || + URL_COPYSTR(dst->u_fragment, src->u_fragment)) { + nni_url_free(dst); + return (NNG_ENOMEM); + } +#undef URL_COPYSTR + *dstp = dst; + return (0); } \ No newline at end of file -- cgit v1.2.3-70-g09d2