NNG_URL_PARSE(3)

πŸ“¦
version 1.12.0 Β· 4 versions
, in ubuntu stonking

πŸ’– 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:

  1. The URL is parsed into the various components.
  2. The u_scheme, u_hostname, u_host, and u_port members are converted to lower case.
  3. Percent-encoded values for unreserved characters (https://tools.ietf.org/html/rfc3986#section-2.3) converted to their unencoded forms.
  4. Additionally URL percent-encoded values for characters in the path and with numeric values larger than 127 (i.e. not ASCII) are decoded.
  5. The resulting u_path is 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 returns NNG_EINVAL.
  6. 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).
  7. Further, empty path segments are removed, meaning that duplicate slash (/) separators are removed from the path.
  8. If a port was not specified, but the scheme defines a default port, then u_port will be filled in with the value of the default port.
πŸ’‘ Tip Only the u_userinfo, u_query, and u_fragment members will ever be NULL. The other members will be filled in with either default values or the empty string if they cannot be determined from str.

🌈 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