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
75 CURLUPART_PORT
76 Port cannot be URL decoded on get.
77
78 CURLUPART_PATH
79
80 CURLUPART_QUERY
81 The query part will also get pluses converted to space when
82 asked to URL decode on get with the CURLU_URLDECODE bit.
83
84 CURLUPART_FRAGMENT
85
87 Returns a CURLUcode error value, which is CURLUE_OK (0) if everything
88 went fine.
89
90 If this function returns an error, no URL part is returned.
91
93 CURLUcode rc;
94 CURLU *url = curl_url();
95 rc = curl_url_set(url, CURLUPART_URL, "https://example.com", 0);
96 if(!rc) {
97 char *scheme;
98 rc = curl_url_get(url, CURLUPART_SCHEME, &scheme, 0);
99 if(!rc) {
100 printf("the scheme is %s\n", scheme);
101 curl_free(scheme);
102 }
103 curl_url_cleanup(url);
104 }
105
107 Added in curl 7.62.0
108
110 curl_url_cleanup(3), curl_url(3), curl_url_set(3), curl_url_dup(3),
111
112
113
114libcurl 7.64.0 October 08, 2018 curl_url_get(3)