curl_url_set.3 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. .\" generated by cd2nroff 0.1 from curl_url_set.md
  2. .TH curl_url_set 3 "2025-01-17" libcurl
  3. .SH NAME
  4. curl_url_set \- set a URL part
  5. .SH SYNOPSIS
  6. .nf
  7. #include <curl/curl.h>
  8. CURLUcode curl_url_set(CURLU *url,
  9. CURLUPart part,
  10. const char *content,
  11. unsigned int flags);
  12. .fi
  13. .SH DESCRIPTION
  14. The \fIurl\fP handle to work on, passed in as the first argument, must be a
  15. handle previously created by \fIcurl_url(3)\fP or \fIcurl_url_dup(3)\fP.
  16. This function sets or updates individual URL components, or parts, held by the
  17. URL object the handle identifies.
  18. The \fIpart\fP argument should identify the particular URL part (see list below)
  19. to set or change, with \fIcontent\fP pointing to a null\-terminated string with the
  20. new contents for that URL part. The contents should be in the form and
  21. encoding they would use in a URL: URL encoded.
  22. When setting a part in the URL object that was previously already set, it
  23. replaces the data that was previously stored for that part with the new
  24. \fIcontent\fP.
  25. The caller does not have to keep \fIcontent\fP around after a successful call
  26. as this function copies the content.
  27. Setting a part to a NULL pointer removes that part\(aqs contents from the \fICURLU\fP
  28. handle.
  29. This function has an 8 MB maximum length limit for all provided input strings.
  30. In the real world, excessively long fields in URLs cause problems even if this
  31. function accepts them.
  32. When setting or updating contents of individual URL parts, \fIcurl_url_set(3)\fP
  33. might accept data that would not be otherwise possible to set in the string
  34. when it gets populated as a result of a full URL parse. Beware. If done so,
  35. extracting a full URL later on from such components might render an invalid
  36. URL.
  37. The \fIflags\fP argument is a bitmask with independent features.
  38. .SH PARTS
  39. .IP CURLUPART_URL
  40. Allows the full URL of the handle to be replaced. If the handle already is
  41. populated with a URL, the new URL can be relative to the previous.
  42. When successfully setting a new URL, relative or absolute, the handle contents
  43. is replaced with the components of the newly set URL.
  44. Pass a pointer to a null\-terminated string to the \fIurl\fP parameter. The string
  45. must point to a correctly formatted "RFC 3986+" URL or be a NULL pointer. The
  46. URL parser only understands and parses the subset of URLS that are
  47. \&"hierarchical" and therefore contain a :// separator \- not the ones that are
  48. normally specified with only a colon separator.
  49. By default this API only parses URLs using schemes for protocols that are
  50. supported built\-in. To make libcurl parse URLs generically even for schemes it
  51. does not know about, the \fBCURLU_NON_SUPPORT_SCHEME\fP flags bit must be set.
  52. Otherwise, this function returns \fICURLUE_UNSUPPORTED_SCHEME\fP for URL schemes
  53. it does not recognize.
  54. Unless \fICURLU_NO_AUTHORITY\fP is set, a blank hostname is not allowed in
  55. the URL.
  56. .IP CURLUPART_SCHEME
  57. Scheme cannot be URL decoded on set. libcurl only accepts setting schemes up
  58. to 40 bytes long.
  59. .IP CURLUPART_USER
  60. If only the user part is set and not the password, the URL is represented with
  61. a blank password.
  62. .IP CURLUPART_PASSWORD
  63. If only the password part is set and not the user, the URL is represented with
  64. a blank user.
  65. .IP CURLUPART_OPTIONS
  66. The options field is an optional field that might follow the password in the
  67. userinfo part. It is only recognized/used when parsing URLs for the following
  68. schemes: pop3, smtp and imap. This function however allows users to
  69. independently set this field.
  70. .IP CURLUPART_HOST
  71. The hostname. If it is International Domain Name (IDN) the string must then be
  72. encoded as your locale says or UTF\-8 (when WinIDN is used). If it is a
  73. bracketed IPv6 numeric address it may contain a zone id (or you can use
  74. \fICURLUPART_ZONEID\fP).
  75. Note that if you set an IPv6 address, it gets ruined and causes an error if
  76. you also set the CURLU_URLENCODE flag.
  77. Unless \fICURLU_NO_AUTHORITY\fP is set, a blank hostname is not allowed to set.
  78. .IP CURLUPART_ZONEID
  79. If the hostname is a numeric IPv6 address, this field can also be set.
  80. .IP CURLUPART_PORT
  81. The port number cannot be URL encoded on set. The given port number is
  82. provided as a string and the decimal number in it must be between 0 and
  83. 65535. Anything else returns an error.
  84. .IP CURLUPART_PATH
  85. If a path is set in the URL without a leading slash, a slash is prepended
  86. automatically.
  87. .IP CURLUPART_QUERY
  88. The query part gets spaces converted to pluses when asked to URL encode on set
  89. with the \fICURLU_URLENCODE\fP bit.
  90. If used together with the \fICURLU_APPENDQUERY\fP bit, the provided part is
  91. appended on the end of the existing query.
  92. The question mark in the URL is not part of the actual query contents.
  93. .IP CURLUPART_FRAGMENT
  94. The hash sign in the URL is not part of the actual fragment contents.
  95. .SH FLAGS
  96. The flags argument is zero, one or more bits set in a bitmask.
  97. .IP CURLU_APPENDQUERY
  98. Can be used when setting the \fICURLUPART_QUERY\fP component. The provided new
  99. part is then appended at the end of the existing query \- and if the previous
  100. part did not end with an ampersand (&), an ampersand gets inserted before the
  101. new appended part.
  102. When \fICURLU_APPENDQUERY\fP is used together with \fICURLU_URLENCODE\fP, the
  103. first \(aq=\(aq symbol is not URL encoded.
  104. .IP CURLU_NON_SUPPORT_SCHEME
  105. If set, allows \fIcurl_url_set(3)\fP to set a non\-supported scheme. It then of
  106. course cannot know if the provided scheme is a valid one or not.
  107. .IP CURLU_URLENCODE
  108. When set, \fIcurl_url_set(3)\fP URL encodes the part on entry, except for
  109. \fBscheme\fP, \fBport\fP and \fBURL\fP.
  110. When setting the path component with URL encoding enabled, the slash character
  111. is skipped.
  112. The query part gets space\-to\-plus converted before the URL conversion is
  113. applied.
  114. This URL encoding is charset unaware and converts the input in a byte\-by\-byte
  115. manner.
  116. .IP CURLU_DEFAULT_SCHEME
  117. If set, allows the URL to be set without a scheme and then sets that to the
  118. default scheme: HTTPS. Overrides the \fICURLU_GUESS_SCHEME\fP option if both are
  119. set.
  120. .IP CURLU_GUESS_SCHEME
  121. If set, allows the URL to be set without a scheme and it instead "guesses"
  122. which scheme that was intended based on the hostname. If the outermost
  123. subdomain name matches DICT, FTP, IMAP, LDAP, POP3 or SMTP then that scheme is
  124. used, otherwise it picks HTTP. Conflicts with the \fICURLU_DEFAULT_SCHEME\fP
  125. option which takes precedence if both are set.
  126. If guessing is not allowed and there is no default scheme set, trying to parse
  127. a URL without a scheme returns error.
  128. If the scheme ends up set as a result of guessing, i.e. it is not actually
  129. present in the parsed URL, it can later be figured out by using the
  130. \fBCURLU_NO_GUESS_SCHEME\fP flag when subsequently getting the URL or the scheme
  131. with \fIcurl_url_get(3)\fP.
  132. .IP CURLU_NO_AUTHORITY
  133. If set, skips authority checks. The RFC allows individual schemes to omit the
  134. host part (normally the only mandatory part of the authority), but libcurl
  135. cannot know whether this is permitted for custom schemes. Specifying the flag
  136. permits empty authority sections, similar to how file scheme is handled.
  137. .IP CURLU_PATH_AS_IS
  138. When set for \fBCURLUPART_URL\fP, this skips the normalization of the
  139. path. That is the procedure where libcurl otherwise removes sequences of
  140. dot\-slash and dot\-dot etc. The same option used for transfers is called
  141. \fICURLOPT_PATH_AS_IS(3)\fP.
  142. .IP CURLU_ALLOW_SPACE
  143. If set, the URL parser allows space (ASCII 32) where possible. The URL syntax
  144. does normally not allow spaces anywhere, but they should be encoded as %20
  145. or \(aq+\(aq. When spaces are allowed, they are still not allowed in the scheme.
  146. When space is used and allowed in a URL, it is stored as\-is unless
  147. \fICURLU_URLENCODE\fP is also set, which then makes libcurl URL encode the
  148. space before stored. This affects how the URL is constructed when
  149. \fIcurl_url_get(3)\fP is subsequently used to extract the full URL or
  150. individual parts. (Added in 7.78.0)
  151. .IP CURLU_DISALLOW_USER
  152. If set, the URL parser does not accept embedded credentials for the
  153. \fBCURLUPART_URL\fP, and instead returns \fBCURLUE_USER_NOT_ALLOWED\fP for
  154. such URLs.
  155. .SH PROTOCOLS
  156. This functionality affects all supported protocols
  157. .SH EXAMPLE
  158. .nf
  159. int main(void)
  160. {
  161. CURLUcode rc;
  162. CURLU *url = curl_url();
  163. rc = curl_url_set(url, CURLUPART_URL, "https://example.com", 0);
  164. if(!rc) {
  165. /* change it to an FTP URL */
  166. rc = curl_url_set(url, CURLUPART_SCHEME, "ftp", 0);
  167. }
  168. curl_url_cleanup(url);
  169. }
  170. .fi
  171. .SH AVAILABILITY
  172. Added in curl 7.78.0
  173. .SH RETURN VALUE
  174. Returns a \fICURLUcode\fP error value, which is CURLUE_OK (0) if everything
  175. went fine. See the \fIlibcurl\-errors(3)\fP man page for the full list with
  176. descriptions.
  177. The input string passed to \fIcurl_url_set(3)\fP must be shorter than eight
  178. million bytes. Otherwise this function returns \fBCURLUE_MALFORMED_INPUT\fP.
  179. If this function returns an error, no URL part is set.
  180. .SH SEE ALSO
  181. .BR CURLOPT_CURLU (3),
  182. .BR curl_url (3),
  183. .BR curl_url_cleanup (3),
  184. .BR curl_url_dup (3),
  185. .BR curl_url_get (3),
  186. .BR curl_url_strerror (3)