NNG_URL_PARSE(3)
π NNG_URL_PARSE π
okay bestie, so this is the NNG Reference Manual page for nng_url_parse and honestly? it's a whole personality. it takes a URL string and hands you back a struct. iconic behavior. let's get into it π«Ά
β¨ NAME β¨
nng_url_parse β create URL structure from a string
πΈ SYNOPSIS πΈ
#include <nng/nng.h>
int nng_url_parse(nng_url **urlp, const char *str);
π¦ DESCRIPTION π¦
so nng_url_parse() does the thing: it parses the string str, which is supposed to contain an URL that's compliant with RFC 3986 (https://tools.ietf.org/html/rfc3986), and it builds you a fresh nng_url structure holding all the results. a pointer to that shiny new structure gets stashed in urlp. π
and when you're done with the structure? you can absolutely dispose of it whenever it's no longer needed, by calling nng_url_free(). clean up after yourself, queen. π
π§ URL Canonicalization
not only does it parse, it also canonicalizes the results, and here's literally every step it does, no skips:
- The URL is parsed into the various components.
- The
u_scheme,u_hostname,u_host, andu_portmembers are converted to lower case. - Percent-encoded values for unreserved characters (
https://tools.ietf.org/html/rfc3986#section-2.3) converted to their unencoded forms. - Additionally URL percent-encoded values for characters in the path and with numeric values larger than
127(i.e. not ASCII) are decoded. - The resulting
u_pathis checked for invalid UTF-8 sequences, consisting of surrogate pairs, illegal byte sequences, or overlong encodings. If this check fails, then the entire URL is considered invalid, and the function returnsNNG_EINVAL. - Path segments consisting of
.and..are resolved as per RFC 3986 6.2.2.3 (https://tools.ietf.org/html/rfc3986#section-6.2.2.3). - Further, empty path segments are removed, meaning that duplicate slash (
/) separators are removed from the path. - If a port was not specified, but the scheme defines a default port, then
u_portwill be filled in with the value of the default port.
π‘ Tip Only theu_userinfo,u_query, andu_fragmentmembers will ever beNULL. The other members will be filled in with either default values or the empty string if they cannot be determined fromstr.
π RETURN VALUES π
This function returns 0 on success, and non-zero otherwise. slay when it's zero, sad vibes when it's not π
π ERRORS π
NNG_ENOMEMβ Insufficient free memory exists to allocate a message.NNG_EINVALβ An invalid URL was supplied.
π SEE ALSO π
nng_url_clone(3), nng_url_free(3), nng_strerror(3), nng_url(5), nng(7)
and that's the whole page, bestie π this one's from the NNG Reference Manual, dated 2026-06-30. go forth and parse those URLs responsibly β¨π¦πΈ
π¦ where this page comes from
- ubuntu stonking: libnng-dev 1.12.0-1 Β· MIT OR Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms