Get individual URL parts
CURLUhandle stores the individual parts of a URL and the application can extract those pieces individually from the handle at any time. If they are set.
The second argument to
curl_url_get()specifies which part you want extracted. They are all extracted as null-terminated
char *data, so you pass a pointer to such a variable.
rc = curl_url_get(h, CURLUPART_HOST, &host, 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_PASSWORD, &password, 0);
rc = curl_url_get(h, CURLUPART_PORT, &port, 0);
rc = curl_url_get(h, CURLUPART_PATH, &path, 0);
rc = curl_url_get(h, CURLUPART_QUERY, &query, 0);
rc = curl_url_get(h, CURLUPART_FRAGMENT, &fragment, 0);
rc = curl_url_get(h, CURLUPART_ZONEID, &zoneid, 0);
Remember to free the returned string with
curl_freewhen you are done with it!
Extracted parts are not URL decoded unless the user asks for it with the
The different parts are named from their roles in the URL. Imagine a URL that looks like this:
When this URL is parsed by curl, it will store the different components like this:
The one thing that might stick out a little is the Zone id. It is an extra qualifier that can be used for IPv6 numerical addresses, and only for such addresses. It is used like this, where it is set to
For this URL, curl extracts:
... and asking for any other component will then return non-zero as they are missing.