1curl_url_get(3)                 libcurl Manual                 curl_url_get(3)
2
3
4

NAME

6       curl_url_get - extract a part from a URL
7

SYNOPSIS

9       #include <curl/curl.h>
10
11       CURLUcode curl_url_get(CURLU *url,
12                              CURLUPart what,
13                              char **part,
14                              unsigned int flags)
15

DESCRIPTION

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

FLAGS

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

PARTS

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              part will be '/' even if no path is supplied in the URL.
88
89       CURLUPART_QUERY
90              The  initial  question  mark  that  denotes the beginning of the
91              query part is a delimiter only.  It is not  part  of  the  query
92              contents.
93
94
95              A  not-present  query will lead part to be set to NULL.  A zero-
96              length query will lead part to be set to a zero-length string.
97
98              The query part will also get  pluses  converted  to  space  when
99              asked to URL decode on get with the CURLU_URLDECODE bit.
100
101       CURLUPART_FRAGMENT
102

RETURN VALUE

104       Returns  a  CURLUcode error value, which is CURLUE_OK (0) if everything
105       went fine.
106
107       If this function returns an error, no URL part is returned.
108

EXAMPLE

110         CURLUcode rc;
111         CURLU *url = curl_url();
112         rc = curl_url_set(url, CURLUPART_URL, "https://example.com", 0);
113         if(!rc) {
114           char *scheme;
115           rc = curl_url_get(url, CURLUPART_SCHEME, &scheme, 0);
116           if(!rc) {
117             printf("the scheme is %s\n", scheme);
118             curl_free(scheme);
119           }
120           curl_url_cleanup(url);
121         }
122

AVAILABILITY

124       Added in curl 7.62.0. CURLUPART_ZONEID was added in 7.65.0.
125

SEE ALSO

127       curl_url_cleanup(3),  curl_url(3),  curl_url_set(3),   curl_url_dup(3),
128       CURLOPT_CURLU(3),
129
130
131
132libcurl 7.79.1                  August 13, 2021                curl_url_get(3)
Impressum