gnurl_url_get(3)
πΈ 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 makescurl_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 makescurl_url_get(3)return the default scheme instead of throwing an error. no scheme? no problem.CURLU_NO_DEFAULT_PORTβ tellscurl_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β askscurl_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
32in 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 inCURLUPART_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 theCURLU_URLDECODEbit.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
- nixos 26.05: libgnurl 7.72.0
- nixpkgs unstable: libgnurl 7.72.0
- Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms