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              If the host part is an IPv6 numeric address, the zoneid will not
75              be part of the extracted host  but  is  provided  separately  in
76              CURLUPART_ZONEID.
77
78       CURLUPART_ZONEID
79              If  the  host  name  is a numeric IPv6 address, this field might
80              also be set.
81
82       CURLUPART_PORT
83              Port cannot be URL decoded on get.
84
85       CURLUPART_PATH
86
87       CURLUPART_QUERY
88              The query part will also get  pluses  converted  to  space  when
89              asked to URL decode on get with the CURLU_URLDECODE bit.
90
91       CURLUPART_FRAGMENT
92

RETURN VALUE

94       Returns  a  CURLUcode error value, which is CURLUE_OK (0) if everything
95       went fine.
96
97       If this function returns an error, no URL part is returned.
98

EXAMPLE

100         CURLUcode rc;
101         CURLU *url = curl_url();
102         rc = curl_url_set(url, CURLUPART_URL, "https://example.com", 0);
103         if(!rc) {
104           char *scheme;
105           rc = curl_url_get(url, CURLUPART_SCHEME, &scheme, 0);
106           if(!rc) {
107             printf("the scheme is %s\n", scheme);
108             curl_free(scheme);
109           }
110           curl_url_cleanup(url);
111         }
112

AVAILABILITY

114       Added in curl 7.62.0. CURLUPART_ZONEID was added in 7.65.0.
115

SEE ALSO

117       curl_url_cleanup(3), curl_url(3), curl_url_set(3), curl_url_dup(3),
118
119
120
121libcurl 7.66.0                   May 03, 2019                  curl_url_get(3)
Impressum