1curl_url_get(3) libcurl Manual curl_url_get(3)
2
3
4
6 curl_url_get - extract a part from a URL
7
9 #include <curl/curl.h>
10
11 CURLUcode curl_url_get(CURLU *url,
12 CURLUPart what,
13 char **part,
14 unsigned int flags)
15
17 Given the url handle of an already parsed URL, this function lets the
18 user extract individual pieces from it.
19
20 The what argument should be the particular part to extract (see list
21 below) and part points to a 'char *' to get updated to point to a newly
22 allocated string with the contents.
23
24 The flags argument is a bitmask with individual features.
25
26 The returned part pointer must be freed with curl_free(3) after use.
27
29 The flags argument is zero, one or more bits set in a bitmask.
30
31 CURLU_DEFAULT_PORT
32 If the handle has no port stored, this option will make
33 curl_url_get(3) return the default port for the used scheme.
34
35 CURLU_DEFAULT_SCHEME
36 If the handle has no scheme stored, this option will make
37 curl_url_get(3) return the default scheme instead of error.
38
39 CURLU_NO_DEFAULT_PORT
40 Instructs curl_url_get(3) to not return a port number if it
41 matches the default port for the scheme.
42
43 CURLU_URLDECODE
44 Asks curl_url_get(3) to URL decode the contents before returning
45 it. It will not attempt to decode the scheme, the port number or
46 the full URL.
47
48 The query component will also get plus-to-space conversion as a
49 bonus when this bit is set.
50
51 Note that this URL decoding is charset unaware and you will get
52 a zero terminated string back with data that could be intended
53 for a particular encoding.
54
55 If there's any byte values lower than 32 in the decoded string,
56 the get operation will return an error instead.
57
59 CURLUPART_URL
60 When asked to return the full URL, curl_url_get(3) will return a
61 normalized and possibly cleaned up version of what was previ‐
62 ously parsed.
63
64 CURLUPART_SCHEME
65 Scheme cannot be URL decoded on get.
66
67 CURLUPART_USER
68
69 CURLUPART_PASSWORD
70
71 CURLUPART_OPTIONS
72
73 CURLUPART_HOST
74 The host name. If it is an IPv6 numeric address, the zoneid will
75 not be part of it but is provided separately in CURLU‐
76 PART_ZONEID. IPv6 numerical addresses are returned within brack‐
77 ets ([]).
78
79 CURLUPART_ZONEID
80 If the host name is a numeric IPv6 address, this field might
81 also be set.
82
83 CURLUPART_PORT
84 Port cannot be URL decoded on get.
85
86 CURLUPART_PATH
87
88 CURLUPART_QUERY
89 The query part will also get pluses converted to space when
90 asked to URL decode on get with the CURLU_URLDECODE bit.
91
92 CURLUPART_FRAGMENT
93
95 Returns a CURLUcode error value, which is CURLUE_OK (0) if everything
96 went fine.
97
98 If this function returns an error, no URL part is returned.
99
101 CURLUcode rc;
102 CURLU *url = curl_url();
103 rc = curl_url_set(url, CURLUPART_URL, "https://example.com", 0);
104 if(!rc) {
105 char *scheme;
106 rc = curl_url_get(url, CURLUPART_SCHEME, &scheme, 0);
107 if(!rc) {
108 printf("the scheme is %s\n", scheme);
109 curl_free(scheme);
110 }
111 curl_url_cleanup(url);
112 }
113
115 Added in curl 7.62.0. CURLUPART_ZONEID was added in 7.65.0.
116
118 curl_url_cleanup(3), curl_url(3), curl_url_set(3), curl_url_dup(3),
119
120
121
122libcurl 7.71.1 September 25, 2019 curl_url_get(3)