1*6236dae4SAndroid Build Coastguard Worker--- 2*6236dae4SAndroid Build Coastguard Workerc: Copyright (C) Daniel Stenberg, <[email protected]>, et al. 3*6236dae4SAndroid Build Coastguard WorkerSPDX-License-Identifier: curl 4*6236dae4SAndroid Build Coastguard WorkerTitle: curl_url_set 5*6236dae4SAndroid Build Coastguard WorkerSection: 3 6*6236dae4SAndroid Build Coastguard WorkerSource: libcurl 7*6236dae4SAndroid Build Coastguard WorkerSee-also: 8*6236dae4SAndroid Build Coastguard Worker - CURLOPT_CURLU (3) 9*6236dae4SAndroid Build Coastguard Worker - curl_url (3) 10*6236dae4SAndroid Build Coastguard Worker - curl_url_cleanup (3) 11*6236dae4SAndroid Build Coastguard Worker - curl_url_dup (3) 12*6236dae4SAndroid Build Coastguard Worker - curl_url_get (3) 13*6236dae4SAndroid Build Coastguard Worker - curl_url_strerror (3) 14*6236dae4SAndroid Build Coastguard WorkerProtocol: 15*6236dae4SAndroid Build Coastguard Worker - All 16*6236dae4SAndroid Build Coastguard WorkerAdded-in: 7.78.0 17*6236dae4SAndroid Build Coastguard Worker--- 18*6236dae4SAndroid Build Coastguard Worker 19*6236dae4SAndroid Build Coastguard Worker# NAME 20*6236dae4SAndroid Build Coastguard Worker 21*6236dae4SAndroid Build Coastguard Workercurl_url_set - set a URL part 22*6236dae4SAndroid Build Coastguard Worker 23*6236dae4SAndroid Build Coastguard Worker# SYNOPSIS 24*6236dae4SAndroid Build Coastguard Worker 25*6236dae4SAndroid Build Coastguard Worker~~~c 26*6236dae4SAndroid Build Coastguard Worker#include <curl/curl.h> 27*6236dae4SAndroid Build Coastguard Worker 28*6236dae4SAndroid Build Coastguard WorkerCURLUcode curl_url_set(CURLU *url, 29*6236dae4SAndroid Build Coastguard Worker CURLUPart part, 30*6236dae4SAndroid Build Coastguard Worker const char *content, 31*6236dae4SAndroid Build Coastguard Worker unsigned int flags); 32*6236dae4SAndroid Build Coastguard Worker~~~ 33*6236dae4SAndroid Build Coastguard Worker 34*6236dae4SAndroid Build Coastguard Worker# DESCRIPTION 35*6236dae4SAndroid Build Coastguard Worker 36*6236dae4SAndroid Build Coastguard WorkerThe *url* handle to work on, passed in as the first argument, must be a 37*6236dae4SAndroid Build Coastguard Workerhandle previously created by curl_url(3) or curl_url_dup(3). 38*6236dae4SAndroid Build Coastguard Worker 39*6236dae4SAndroid Build Coastguard WorkerThis function sets or updates individual URL components, or parts, held by the 40*6236dae4SAndroid Build Coastguard WorkerURL object the handle identifies. 41*6236dae4SAndroid Build Coastguard Worker 42*6236dae4SAndroid Build Coastguard WorkerThe *part* argument should identify the particular URL part (see list below) 43*6236dae4SAndroid Build Coastguard Workerto set or change, with *content* pointing to a null-terminated string with the 44*6236dae4SAndroid Build Coastguard Workernew contents for that URL part. The contents should be in the form and 45*6236dae4SAndroid Build Coastguard Workerencoding they would use in a URL: URL encoded. 46*6236dae4SAndroid Build Coastguard Worker 47*6236dae4SAndroid Build Coastguard WorkerWhen setting a part in the URL object that was previously already set, it 48*6236dae4SAndroid Build Coastguard Workerreplaces the data that was previously stored for that part with the new 49*6236dae4SAndroid Build Coastguard Worker*content*. 50*6236dae4SAndroid Build Coastguard Worker 51*6236dae4SAndroid Build Coastguard WorkerThe caller does not have to keep *content* around after a successful call 52*6236dae4SAndroid Build Coastguard Workeras this function copies the content. 53*6236dae4SAndroid Build Coastguard Worker 54*6236dae4SAndroid Build Coastguard WorkerSetting a part to a NULL pointer removes that part's contents from the *CURLU* 55*6236dae4SAndroid Build Coastguard Workerhandle. 56*6236dae4SAndroid Build Coastguard Worker 57*6236dae4SAndroid Build Coastguard WorkerThis function has an 8 MB maximum length limit for all provided input strings. 58*6236dae4SAndroid Build Coastguard WorkerIn the real world, excessively long fields in URLs cause problems even if this 59*6236dae4SAndroid Build Coastguard Workerfunction accepts them. 60*6236dae4SAndroid Build Coastguard Worker 61*6236dae4SAndroid Build Coastguard WorkerWhen setting or updating contents of individual URL parts, curl_url_set(3) 62*6236dae4SAndroid Build Coastguard Workermight accept data that would not be otherwise possible to set in the string 63*6236dae4SAndroid Build Coastguard Workerwhen it gets populated as a result of a full URL parse. Beware. If done so, 64*6236dae4SAndroid Build Coastguard Workerextracting a full URL later on from such components might render an invalid 65*6236dae4SAndroid Build Coastguard WorkerURL. 66*6236dae4SAndroid Build Coastguard Worker 67*6236dae4SAndroid Build Coastguard WorkerThe *flags* argument is a bitmask with independent features. 68*6236dae4SAndroid Build Coastguard Worker 69*6236dae4SAndroid Build Coastguard Worker# PARTS 70*6236dae4SAndroid Build Coastguard Worker 71*6236dae4SAndroid Build Coastguard Worker## CURLUPART_URL 72*6236dae4SAndroid Build Coastguard Worker 73*6236dae4SAndroid Build Coastguard WorkerAllows the full URL of the handle to be replaced. If the handle already is 74*6236dae4SAndroid Build Coastguard Workerpopulated with a URL, the new URL can be relative to the previous. 75*6236dae4SAndroid Build Coastguard Worker 76*6236dae4SAndroid Build Coastguard WorkerWhen successfully setting a new URL, relative or absolute, the handle contents 77*6236dae4SAndroid Build Coastguard Workeris replaced with the components of the newly set URL. 78*6236dae4SAndroid Build Coastguard Worker 79*6236dae4SAndroid Build Coastguard WorkerPass a pointer to a null-terminated string to the *url* parameter. The string 80*6236dae4SAndroid Build Coastguard Workermust point to a correctly formatted "RFC 3986+" URL or be a NULL pointer. The 81*6236dae4SAndroid Build Coastguard WorkerURL parser only understands and parses the subset of URLS that are 82*6236dae4SAndroid Build Coastguard Worker"hierarchical" and therefore contain a :// separator - not the ones that are 83*6236dae4SAndroid Build Coastguard Workernormally specified with only a colon separator. 84*6236dae4SAndroid Build Coastguard Worker 85*6236dae4SAndroid Build Coastguard WorkerBy default this API only parses URLs using schemes for protocols that are 86*6236dae4SAndroid Build Coastguard Workersupported built-in. To make libcurl parse URLs generically even for schemes it 87*6236dae4SAndroid Build Coastguard Workerdoes not know about, the **CURLU_NON_SUPPORT_SCHEME** flags bit must be set. 88*6236dae4SAndroid Build Coastguard WorkerOtherwise, this function returns *CURLUE_UNSUPPORTED_SCHEME* for URL schemes 89*6236dae4SAndroid Build Coastguard Workerit does not recognize. 90*6236dae4SAndroid Build Coastguard Worker 91*6236dae4SAndroid Build Coastguard WorkerUnless *CURLU_NO_AUTHORITY* is set, a blank hostname is not allowed in 92*6236dae4SAndroid Build Coastguard Workerthe URL. 93*6236dae4SAndroid Build Coastguard Worker 94*6236dae4SAndroid Build Coastguard WorkerWhen a full URL is set (parsed), the hostname component is stored URL decoded. 95*6236dae4SAndroid Build Coastguard Worker 96*6236dae4SAndroid Build Coastguard Worker## CURLUPART_SCHEME 97*6236dae4SAndroid Build Coastguard Worker 98*6236dae4SAndroid Build Coastguard WorkerScheme cannot be URL decoded on set. libcurl only accepts setting schemes up 99*6236dae4SAndroid Build Coastguard Workerto 40 bytes long. 100*6236dae4SAndroid Build Coastguard Worker 101*6236dae4SAndroid Build Coastguard Worker## CURLUPART_USER 102*6236dae4SAndroid Build Coastguard Worker 103*6236dae4SAndroid Build Coastguard WorkerIf only the user part is set and not the password, the URL is represented with 104*6236dae4SAndroid Build Coastguard Workera blank password. 105*6236dae4SAndroid Build Coastguard Worker 106*6236dae4SAndroid Build Coastguard Worker## CURLUPART_PASSWORD 107*6236dae4SAndroid Build Coastguard Worker 108*6236dae4SAndroid Build Coastguard WorkerIf only the password part is set and not the user, the URL is represented with 109*6236dae4SAndroid Build Coastguard Workera blank user. 110*6236dae4SAndroid Build Coastguard Worker 111*6236dae4SAndroid Build Coastguard Worker## CURLUPART_OPTIONS 112*6236dae4SAndroid Build Coastguard Worker 113*6236dae4SAndroid Build Coastguard WorkerThe options field is an optional field that might follow the password in the 114*6236dae4SAndroid Build Coastguard Workeruserinfo part. It is only recognized/used when parsing URLs for the following 115*6236dae4SAndroid Build Coastguard Workerschemes: pop3, smtp and imap. This function however allows users to 116*6236dae4SAndroid Build Coastguard Workerindependently set this field. 117*6236dae4SAndroid Build Coastguard Worker 118*6236dae4SAndroid Build Coastguard Worker## CURLUPART_HOST 119*6236dae4SAndroid Build Coastguard Worker 120*6236dae4SAndroid Build Coastguard WorkerThe hostname. If it is International Domain Name (IDN) the string must then be 121*6236dae4SAndroid Build Coastguard Workerencoded as your locale says or UTF-8 (when WinIDN is used). If it is a 122*6236dae4SAndroid Build Coastguard Workerbracketed IPv6 numeric address it may contain a zone id (or you can use 123*6236dae4SAndroid Build Coastguard Worker*CURLUPART_ZONEID*). 124*6236dae4SAndroid Build Coastguard Worker 125*6236dae4SAndroid Build Coastguard WorkerNote that if you set an IPv6 address, it gets ruined and causes an error if 126*6236dae4SAndroid Build Coastguard Workeryou also set the CURLU_URLENCODE flag. 127*6236dae4SAndroid Build Coastguard Worker 128*6236dae4SAndroid Build Coastguard WorkerUnless *CURLU_NO_AUTHORITY* is set, a blank hostname is not allowed to set. 129*6236dae4SAndroid Build Coastguard Worker 130*6236dae4SAndroid Build Coastguard Worker## CURLUPART_ZONEID 131*6236dae4SAndroid Build Coastguard Worker 132*6236dae4SAndroid Build Coastguard WorkerIf the hostname is a numeric IPv6 address, this field can also be set. 133*6236dae4SAndroid Build Coastguard Worker 134*6236dae4SAndroid Build Coastguard Worker## CURLUPART_PORT 135*6236dae4SAndroid Build Coastguard Worker 136*6236dae4SAndroid Build Coastguard WorkerThe port number cannot be URL encoded on set. The given port number is 137*6236dae4SAndroid Build Coastguard Workerprovided as a string and the decimal number in it must be between 0 and 138*6236dae4SAndroid Build Coastguard Worker65535. Anything else returns an error. 139*6236dae4SAndroid Build Coastguard Worker 140*6236dae4SAndroid Build Coastguard Worker## CURLUPART_PATH 141*6236dae4SAndroid Build Coastguard Worker 142*6236dae4SAndroid Build Coastguard WorkerIf a path is set in the URL without a leading slash, a slash is prepended 143*6236dae4SAndroid Build Coastguard Workerautomatically. 144*6236dae4SAndroid Build Coastguard Worker 145*6236dae4SAndroid Build Coastguard Worker## CURLUPART_QUERY 146*6236dae4SAndroid Build Coastguard Worker 147*6236dae4SAndroid Build Coastguard WorkerThe query part gets spaces converted to pluses when asked to URL encode on set 148*6236dae4SAndroid Build Coastguard Workerwith the *CURLU_URLENCODE* bit. 149*6236dae4SAndroid Build Coastguard Worker 150*6236dae4SAndroid Build Coastguard WorkerIf used together with the *CURLU_APPENDQUERY* bit, the provided part is 151*6236dae4SAndroid Build Coastguard Workerappended on the end of the existing query. 152*6236dae4SAndroid Build Coastguard Worker 153*6236dae4SAndroid Build Coastguard WorkerThe question mark in the URL is not part of the actual query contents. 154*6236dae4SAndroid Build Coastguard Worker 155*6236dae4SAndroid Build Coastguard Worker## CURLUPART_FRAGMENT 156*6236dae4SAndroid Build Coastguard Worker 157*6236dae4SAndroid Build Coastguard WorkerThe hash sign in the URL is not part of the actual fragment contents. 158*6236dae4SAndroid Build Coastguard Worker 159*6236dae4SAndroid Build Coastguard Worker# FLAGS 160*6236dae4SAndroid Build Coastguard Worker 161*6236dae4SAndroid Build Coastguard WorkerThe flags argument is zero, one or more bits set in a bitmask. 162*6236dae4SAndroid Build Coastguard Worker 163*6236dae4SAndroid Build Coastguard Worker## CURLU_APPENDQUERY 164*6236dae4SAndroid Build Coastguard Worker 165*6236dae4SAndroid Build Coastguard WorkerCan be used when setting the *CURLUPART_QUERY* component. The provided new 166*6236dae4SAndroid Build Coastguard Workerpart is then appended at the end of the existing query - and if the previous 167*6236dae4SAndroid Build Coastguard Workerpart did not end with an ampersand (&), an ampersand gets inserted before the 168*6236dae4SAndroid Build Coastguard Workernew appended part. 169*6236dae4SAndroid Build Coastguard Worker 170*6236dae4SAndroid Build Coastguard WorkerWhen *CURLU_APPENDQUERY* is used together with *CURLU_URLENCODE*, the 171*6236dae4SAndroid Build Coastguard Workerfirst '=' symbol is not URL encoded. 172*6236dae4SAndroid Build Coastguard Worker 173*6236dae4SAndroid Build Coastguard Worker## CURLU_NON_SUPPORT_SCHEME 174*6236dae4SAndroid Build Coastguard Worker 175*6236dae4SAndroid Build Coastguard WorkerIf set, allows curl_url_set(3) to set a non-supported scheme. It then of 176*6236dae4SAndroid Build Coastguard Workercourse cannot know if the provided scheme is a valid one or not. 177*6236dae4SAndroid Build Coastguard Worker 178*6236dae4SAndroid Build Coastguard Worker## CURLU_URLENCODE 179*6236dae4SAndroid Build Coastguard Worker 180*6236dae4SAndroid Build Coastguard WorkerWhen set, curl_url_set(3) URL encodes the part on entry, except for 181*6236dae4SAndroid Build Coastguard Worker**scheme**, **port** and **URL**. 182*6236dae4SAndroid Build Coastguard Worker 183*6236dae4SAndroid Build Coastguard WorkerWhen setting the path component with URL encoding enabled, the slash character 184*6236dae4SAndroid Build Coastguard Workeris skipped. 185*6236dae4SAndroid Build Coastguard Worker 186*6236dae4SAndroid Build Coastguard WorkerThe query part gets space-to-plus converted before the URL conversion is 187*6236dae4SAndroid Build Coastguard Workerapplied. 188*6236dae4SAndroid Build Coastguard Worker 189*6236dae4SAndroid Build Coastguard WorkerThis URL encoding is charset unaware and converts the input in a byte-by-byte 190*6236dae4SAndroid Build Coastguard Workermanner. 191*6236dae4SAndroid Build Coastguard Worker 192*6236dae4SAndroid Build Coastguard Worker## CURLU_DEFAULT_SCHEME 193*6236dae4SAndroid Build Coastguard Worker 194*6236dae4SAndroid Build Coastguard WorkerIf set, allows the URL to be set without a scheme and then sets that to the 195*6236dae4SAndroid Build Coastguard Workerdefault scheme: HTTPS. Overrides the *CURLU_GUESS_SCHEME* option if both are 196*6236dae4SAndroid Build Coastguard Workerset. 197*6236dae4SAndroid Build Coastguard Worker 198*6236dae4SAndroid Build Coastguard Worker## CURLU_GUESS_SCHEME 199*6236dae4SAndroid Build Coastguard Worker 200*6236dae4SAndroid Build Coastguard WorkerIf set, allows the URL to be set without a scheme and it instead "guesses" 201*6236dae4SAndroid Build Coastguard Workerwhich scheme that was intended based on the hostname. If the outermost 202*6236dae4SAndroid Build Coastguard Workersubdomain name matches DICT, FTP, IMAP, LDAP, POP3 or SMTP then that scheme is 203*6236dae4SAndroid Build Coastguard Workerused, otherwise it picks HTTP. Conflicts with the *CURLU_DEFAULT_SCHEME* 204*6236dae4SAndroid Build Coastguard Workeroption which takes precedence if both are set. 205*6236dae4SAndroid Build Coastguard Worker 206*6236dae4SAndroid Build Coastguard WorkerIf guessing is not allowed and there is no default scheme set, trying to parse 207*6236dae4SAndroid Build Coastguard Workera URL without a scheme returns error. 208*6236dae4SAndroid Build Coastguard Worker 209*6236dae4SAndroid Build Coastguard WorkerIf the scheme ends up set as a result of guessing, i.e. it is not actually 210*6236dae4SAndroid Build Coastguard Workerpresent in the parsed URL, it can later be figured out by using the 211*6236dae4SAndroid Build Coastguard Worker**CURLU_NO_GUESS_SCHEME** flag when subsequently getting the URL or the scheme 212*6236dae4SAndroid Build Coastguard Workerwith curl_url_get(3). 213*6236dae4SAndroid Build Coastguard Worker 214*6236dae4SAndroid Build Coastguard Worker## CURLU_NO_AUTHORITY 215*6236dae4SAndroid Build Coastguard Worker 216*6236dae4SAndroid Build Coastguard WorkerIf set, skips authority checks. The RFC allows individual schemes to omit the 217*6236dae4SAndroid Build Coastguard Workerhost part (normally the only mandatory part of the authority), but libcurl 218*6236dae4SAndroid Build Coastguard Workercannot know whether this is permitted for custom schemes. Specifying the flag 219*6236dae4SAndroid Build Coastguard Workerpermits empty authority sections, similar to how file scheme is handled. 220*6236dae4SAndroid Build Coastguard Worker 221*6236dae4SAndroid Build Coastguard Worker## CURLU_PATH_AS_IS 222*6236dae4SAndroid Build Coastguard Worker 223*6236dae4SAndroid Build Coastguard WorkerWhen set for **CURLUPART_URL**, this skips the normalization of the 224*6236dae4SAndroid Build Coastguard Workerpath. That is the procedure where libcurl otherwise removes sequences of 225*6236dae4SAndroid Build Coastguard Workerdot-slash and dot-dot etc. The same option used for transfers is called 226*6236dae4SAndroid Build Coastguard WorkerCURLOPT_PATH_AS_IS(3). 227*6236dae4SAndroid Build Coastguard Worker 228*6236dae4SAndroid Build Coastguard Worker## CURLU_ALLOW_SPACE 229*6236dae4SAndroid Build Coastguard Worker 230*6236dae4SAndroid Build Coastguard WorkerIf set, the URL parser allows space (ASCII 32) where possible. The URL syntax 231*6236dae4SAndroid Build Coastguard Workerdoes normally not allow spaces anywhere, but they should be encoded as %20 232*6236dae4SAndroid Build Coastguard Workeror '+'. When spaces are allowed, they are still not allowed in the scheme. 233*6236dae4SAndroid Build Coastguard WorkerWhen space is used and allowed in a URL, it is stored as-is unless 234*6236dae4SAndroid Build Coastguard Worker*CURLU_URLENCODE* is also set, which then makes libcurl URL encode the 235*6236dae4SAndroid Build Coastguard Workerspace before stored. This affects how the URL is constructed when 236*6236dae4SAndroid Build Coastguard Workercurl_url_get(3) is subsequently used to extract the full URL or 237*6236dae4SAndroid Build Coastguard Workerindividual parts. (Added in 7.78.0) 238*6236dae4SAndroid Build Coastguard Worker 239*6236dae4SAndroid Build Coastguard Worker## CURLU_DISALLOW_USER 240*6236dae4SAndroid Build Coastguard Worker 241*6236dae4SAndroid Build Coastguard WorkerIf set, the URL parser does not accept embedded credentials for the 242*6236dae4SAndroid Build Coastguard Worker**CURLUPART_URL**, and instead returns **CURLUE_USER_NOT_ALLOWED** for 243*6236dae4SAndroid Build Coastguard Workersuch URLs. 244*6236dae4SAndroid Build Coastguard Worker 245*6236dae4SAndroid Build Coastguard Worker# %PROTOCOLS% 246*6236dae4SAndroid Build Coastguard Worker 247*6236dae4SAndroid Build Coastguard Worker# EXAMPLE 248*6236dae4SAndroid Build Coastguard Worker 249*6236dae4SAndroid Build Coastguard Worker~~~c 250*6236dae4SAndroid Build Coastguard Workerint main(void) 251*6236dae4SAndroid Build Coastguard Worker{ 252*6236dae4SAndroid Build Coastguard Worker CURLUcode rc; 253*6236dae4SAndroid Build Coastguard Worker CURLU *url = curl_url(); 254*6236dae4SAndroid Build Coastguard Worker rc = curl_url_set(url, CURLUPART_URL, "https://example.com", 0); 255*6236dae4SAndroid Build Coastguard Worker if(!rc) { 256*6236dae4SAndroid Build Coastguard Worker /* change it to an FTP URL */ 257*6236dae4SAndroid Build Coastguard Worker rc = curl_url_set(url, CURLUPART_SCHEME, "ftp", 0); 258*6236dae4SAndroid Build Coastguard Worker } 259*6236dae4SAndroid Build Coastguard Worker curl_url_cleanup(url); 260*6236dae4SAndroid Build Coastguard Worker} 261*6236dae4SAndroid Build Coastguard Worker~~~ 262*6236dae4SAndroid Build Coastguard Worker 263*6236dae4SAndroid Build Coastguard Worker# %AVAILABILITY% 264*6236dae4SAndroid Build Coastguard Worker 265*6236dae4SAndroid Build Coastguard Worker# RETURN VALUE 266*6236dae4SAndroid Build Coastguard Worker 267*6236dae4SAndroid Build Coastguard WorkerReturns a *CURLUcode* error value, which is CURLUE_OK (0) if everything 268*6236dae4SAndroid Build Coastguard Workerwent fine. See the libcurl-errors(3) man page for the full list with 269*6236dae4SAndroid Build Coastguard Workerdescriptions. 270*6236dae4SAndroid Build Coastguard Worker 271*6236dae4SAndroid Build Coastguard WorkerThe input string passed to curl_url_set(3) must be shorter than eight 272*6236dae4SAndroid Build Coastguard Workermillion bytes. Otherwise this function returns **CURLUE_MALFORMED_INPUT**. 273*6236dae4SAndroid Build Coastguard Worker 274*6236dae4SAndroid Build Coastguard WorkerIf this function returns an error, no URL part is set. 275