1= nng_url_parse(3) 2// 3// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech> 4// Copyright 2018 Capitar IT Group BV <info@capitar.com> 5// 6// This document is supplied under the terms of the MIT License, a 7// copy of which should be located in the distribution where this 8// file was obtained (LICENSE.txt). A copy of the license may also be 9// found online at https://opensource.org/licenses/MIT. 10// 11 12== NAME 13 14nng_url_parse - create URL structure from a string 15 16== SYNOPSIS 17 18[source, c] 19---- 20#include <nng/nng.h> 21 22int nng_url_parse(nng_url **urlp, const char *str); 23---- 24 25== DESCRIPTION 26 27The `nng_url_parse()` function parses the string _str_ containing an 28https://tools.ietf.org/html/rfc3986[RFC 3986] compliant URL, and creates 29an 30xref:nng_url.5.adoc[`nng_url`] structure containing the results. 31A pointer to the resulting structure is stored in _urlp_. 32 33The structure may disposed of when no longer needed by calling 34xref:nng_url_free.3.adoc[`nng_url_free()`]. 35 36=== URL Canonicalization 37 38The `nng_url_parse()` function also canonicalizes the results, as 39follows: 40 41 1. The URL is parsed into the various components. 42 2. The `u_scheme`, `u_hostname`, `u_host`, and `u_port` members are 43 converted to lower case. 44 3. Percent-encoded values for 45 https://tools.ietf.org/html/rfc3986#section-2.3[unreserved characters] 46 converted to their unencoded forms. 47 4. Additionally URL percent-encoded values for characters in the path 48 and with numeric values larger than 127 (i.e. not ASCII) are decoded. 49 5. The resulting `u_path` is checked for invalid UTF-8 sequences, consisting 50 of surrogate pairs, illegal byte sequences, or overlong encodings. 51 If this check fails, then the entire URL is considered invalid, and 52 the function returns `NNG_EINVAL`. 53 6. Path segments consisting of `.` and `..` are resolved as per 54 https://tools.ietf.org/html/rfc3986#section-6.2.2.3[RFC 3986 6.2.2.3]. 55 7. Further, empty path segments are removed, meaning that duplicate 56 slash (`/`) separators are removed from the path. 57 8. If a port was not specified, but the scheme defines a default 58 port, then `u_port` will be filled in with the value of the default port. 59 60TIP: Only the `u_userinfo`, `u_query`, and `u_fragment` members will ever be 61 `NULL`. The other members will be filled in with either default values 62 or the empty string if they cannot be determined from _str_. 63 64== RETURN VALUES 65 66This function returns 0 on success, and non-zero otherwise. 67 68 69== ERRORS 70 71[horizontal] 72`NNG_ENOMEM`:: Insufficient free memory exists to allocate a message. 73`NNG_EINVAL`:: An invalid URL was supplied. 74 75 76== SEE ALSO 77 78[.text-left] 79xref:nng_url_clone.3.adoc[nng_url_clone(3)], 80xref:nng_url_free.3.adoc[nng_url_free(3)], 81xref:nng_strerror.3.adoc[nng_strerror(3)], 82xref:nng_url.5.adoc[nng_url(5)], 83xref:nng.7.adoc[nng(7)] 84