gnurl_url_get(3)

πŸ“¦ version 7.72.0, in nixos 26.05, nixpkgs unstable

🌸 NAME 🌸

okay bestie, this is gnurl_url_get(3) from the libgnurl Manual πŸ’– and the actual function in question is curl_url_get β€” it extracts a part from a URL. that's the whole vibe. no cap.


✨ SYNOPSIS ✨

#include <gnurl/curl.h>

CURLUcode curl_url_get(CURLU *url,
                       CURLUPart what,
                       char **part,
                       unsigned int flags)

πŸ’– DESCRIPTION πŸ’–

so you've got a url handle of an already parsed URL, right? this function lets you pull individual pieces out of it like you're picking charms for a bracelet 🫢.

the what argument is the particular part you want to extract (see the list below, bestie), and part points to a char * that gets updated to point at a newly allocated string holding the contents. iconic.

the flags argument is a bitmask, and each bit is its own little feature switch. ✨

the returned part pointer must be freed with curl_free(3) after use. don't forget, or it's giving leak energy 😭.


🚩 FLAGS 🚩

the flags argument is zero, one or more bits set in a bitmask. slay.

  • CURLU_DEFAULT_PORT β€” if the handle has no port stored, this option makes curl_url_get(3) return the default port for the scheme in use. default port to the rescue πŸ’…
  • CURLU_DEFAULT_SCHEME β€” if the handle has no scheme stored, this option makes curl_url_get(3) return the default scheme instead of throwing an error. no scheme? no problem.
  • CURLU_NO_DEFAULT_PORT β€” tells curl_url_get(3) not to return a port number if it matches the default port for the scheme. like, we already know, bestie.
  • CURLU_URLDECODE β€” asks curl_url_get(3) to URL decode the contents before returning them. it will not attempt to decode the scheme, the port number, or the full URL. nope, not those.
    • the query component will also get plus-to-space conversion as a bonus when this bit is set. cute little extra πŸŽ€
    • note that this URL decoding is charset unaware, and you'll get a zero terminated string back with data that could be intended for a particular encoding. it's not doing the charset homework for you.
    • if there's any byte values lower than 32 in the decoded string, the get operation will return an error instead. so watch out for that, fr fr 😭

🧩 PARTS 🧩

  • CURLUPART_URL β€” when asked to return the full URL, curl_url_get(3) returns a normalized and possibly cleaned up version of what was previously parsed. glow-up behavior ✨
  • CURLUPART_SCHEME β€” scheme cannot be URL decoded on get. periodt.
  • CURLUPART_USER β€” the user part.
  • CURLUPART_PASSWORD β€” the password part.
  • CURLUPART_OPTIONS β€” the options part.
  • CURLUPART_HOST β€” the host name. if it's an IPv6 numeric address, the zoneid will not be part of it, but is provided separately in CURLUPART_ZONEID. IPv6 numerical addresses are returned within brackets ([]). bracket moment πŸ’…
  • CURLUPART_ZONEID β€” if the host name is a numeric IPv6 address, this field might also be set.
  • CURLUPART_PORT β€” port cannot be URL decoded on get.
  • CURLUPART_PATH β€” the path part.
  • CURLUPART_QUERY β€” the query part will also get pluses converted to space when asked to URL decode on get with the CURLU_URLDECODE bit.
  • CURLUPART_FRAGMENT β€” the fragment part.

πŸ” RETURN VALUE πŸ”

returns a CURLUcode error value, which is CURLUE_OK (0) if everything went fine. we love a happy ending 🫢.

if this function returns an error, no URL part is returned. so no half-gotten parts, bestie.


πŸ§ͺ EXAMPLE πŸ§ͺ

         CURLUcode rc;
         CURLU *url = curl_url();
         rc = curl_url_set(url, CURLUPART_URL, "https://example.com", 0);
         if(!rc) {
           char *scheme;
           rc = curl_url_get(url, CURLUPART_SCHEME, &scheme, 0);
           if(!rc) {
             printf("the scheme is %s\n", scheme);
             curl_free(scheme);
           }
           curl_url_cleanup(url);
         }

πŸ—“οΈ AVAILABILITY πŸ—“οΈ

added in curl 7.62.0. CURLUPART_ZONEID was added in 7.65.0. history icon behavior πŸ‘‘


πŸ‘€ SEE ALSO πŸ‘€


and that's the page, bestie πŸ’– signed off from the libcurl edition, dated 6 Aug 2018, under gnurl_url_get(3) β€” mwah πŸ’‹βœ¨

πŸ“¦ where this page comes from