Sortix nightly manual
This manual documents Sortix nightly, a development build that has not been officially released. You can instead view this document in the latest official manual.
libcurl-url(3) | Library Functions Manual | libcurl-url(3) |
NAME
libcurl-url - URL interface overviewDESCRIPTION
The URL interface provides functions for parsing and generating URLs.INCLUDE
You still only include <curl/curl.h> in your code.DUPLICATE
When you need a copy of a handle, just duplicate it with curl_url_dup(3):CURLU *nh = curl_url_dup(h);
PARSING
By setting a URL to the handle with curl_url_set(3), the URL is parsed and stored in the handle. If the URL is not syntactically correct it returns an error instead.rc = curl_url_set(h, CURLUPART_URL,
"https://example.com:449/foo/bar?name=moo", 0);
REDIRECT
When a handle already contains info about a URL, setting a relative URL makes it "redirect" to that.rc = curl_url_set(h, CURLUPART_URL, "../test?another", 0);
GET URL
The CURLU handle represents a URL and you can easily extract that with curl_url_get(3):char *url;
rc = curl_url_get(h, CURLUPART_URL, &url, 0);
curl_free(url);
The zero in the fourth argument is a bitmask for changing specific features.
GET PARTS
When a URL has been parsed or parts have been set, you can extract those pieces from the handle at any time.rc = curl_url_get(h, CURLUPART_FRAGMENT, &fragment, 0);
rc = curl_url_get(h, CURLUPART_HOST, &host, 0);
rc = curl_url_get(h, CURLUPART_PASSWORD, &password, 0);
rc = curl_url_get(h, CURLUPART_PATH, &path, 0);
rc = curl_url_get(h, CURLUPART_PORT, &port, 0);
rc = curl_url_get(h, CURLUPART_QUERY, &query, 0);
rc = curl_url_get(h, CURLUPART_SCHEME, &scheme, 0);
rc = curl_url_get(h, CURLUPART_USER, &user, 0);
rc = curl_url_get(h, CURLUPART_ZONEID, &zoneid, 0);
SET PARTS
A user set individual URL parts, either after having parsed a full URL or instead of parsing such.rc = curl_url_set(urlp, CURLUPART_FRAGMENT, "anchor", 0);
rc = curl_url_set(urlp, CURLUPART_HOST, "www.example.com", 0);
rc = curl_url_set(urlp, CURLUPART_PASSWORD, "doe", 0);
rc = curl_url_set(urlp, CURLUPART_PATH, "/index.html", 0);
rc = curl_url_set(urlp, CURLUPART_PORT, "443", 0);
rc = curl_url_set(urlp, CURLUPART_QUERY, "name=john", 0);
rc = curl_url_set(urlp, CURLUPART_SCHEME, "https", 0);
rc = curl_url_set(urlp, CURLUPART_USER, "john", 0);
rc = curl_url_set(urlp, CURLUPART_ZONEID, "eth0", 0);
CURLU_APPENDQUERY
An application can append a string to the right end of the query part with the CURLU_APPENDQUERY flag to curl_url_set(3).rc = curl_url_set(urlp, CURLUPART_QUERY, "hat=1", CURLU_APPENDQUERY);
rc = curl_url_set(urlp, CURLUPART_QUERY, "candy=N&N",
CURLU_APPENDQUERY | CURLU_URLENCODE);
https://example.com/?shoes=2&hat=1&candy=N%26N
NOTES
A URL with a literal IPv6 address can be parsed even when IPv6 support is not enabled.SEE ALSO
CURLOPT_URL(3), curl_url(3), curl_url_cleanup(3), curl_url_dup(3), curl_url_get(3), curl_url_set(3), curl_url_strerror(3)2024-11-21 | libcurl |