curl_url_set.3 8.9 KB

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