curl_url_set.3 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. Given the \fIurl\fP handle of an already parsed URL, this function lets the
  37. user set/update individual pieces of it.
  38. The \fIpart\fP argument should identify the particular URL part (see list
  39. below) to set or change, with \fIcontent\fP pointing to a null-terminated
  40. string with the new contents for that URL part. The contents should be in the
  41. form and encoding they'd use in a URL: URL encoded.
  42. The application does not have to keep \fIcontent\fP around after a successful
  43. call.
  44. Setting a part to a NULL pointer will effectively remove that part's contents
  45. from the \fICURLU\fP handle.
  46. By default, this API only accepts URLs using schemes for protocols that are
  47. supported built-in. To make libcurl parse URLs generically even for schemes it
  48. does not know about, the \fBCURLU_NON_SUPPORT_SCHEME\fP flags bit must be
  49. set. Otherwise, this function returns \fICURLUE_UNSUPPORTED_SCHEME\fP on URL
  50. schemes it does not recognize.
  51. This function call has no particular maximum length for any provided input
  52. string. In the real world, excessively long field in URLs will cause problems
  53. even if this API accepts them.
  54. When setting or updating contents of individual URL parts, this API might
  55. accept data that would not be otherwise possible to set in the string when it
  56. gets populated as a result of a full URL parse. Beware. If done so, extracting
  57. a full URL later on from such components might render an invalid URL.
  58. The \fIflags\fP argument is a bitmask with independent features.
  59. .SH PARTS
  60. .IP CURLUPART_URL
  61. Allows the full URL of the handle to be replaced. If the handle already is
  62. populated with a URL, the new URL can be relative to the previous.
  63. When successfully setting a new URL, relative or absolute, the handle contents
  64. will be replaced with the information of the newly set URL.
  65. Pass a pointer to a null-terminated string to the \fIurl\fP parameter. The
  66. string must point to a correctly formatted "RFC 3986+" URL or be a NULL
  67. pointer.
  68. Unless \fICURLU_NO_AUTHORITY\fP is set, a blank host name is not allowed in
  69. the URL.
  70. .IP CURLUPART_SCHEME
  71. Scheme cannot be URL decoded on set. libcurl only accepts setting schemes up
  72. to 40 bytes long.
  73. .IP CURLUPART_USER
  74. .IP CURLUPART_PASSWORD
  75. .IP CURLUPART_OPTIONS
  76. The options field is an optional field that might follow the password in the
  77. userinfo part. It is only recognized/used when parsing URLs for the following
  78. schemes: pop3, smtp and imap. This function however allows users to
  79. independently set this field at will.
  80. .IP CURLUPART_HOST
  81. The host name. If it is IDNA the string must then be encoded as your locale
  82. says or UTF-8 (when WinIDN is used). If it is a bracketed IPv6 numeric address
  83. it may contain a zone id (or you can use CURLUPART_ZONEID).
  84. Unless \fICURLU_NO_AUTHORITY\fP is set, a blank host name is not allowed to set.
  85. .IP CURLUPART_ZONEID
  86. If the host name is a numeric IPv6 address, this field can also be set.
  87. .IP CURLUPART_PORT
  88. Port cannot be URL encoded on set. The given port number is provided as a
  89. string and the decimal number must be between 1 and 65535. Anything else will
  90. return an error.
  91. .IP CURLUPART_PATH
  92. If a path is set in the URL without a leading slash, a slash will be prepended
  93. automatically.
  94. .IP CURLUPART_QUERY
  95. The query part will also get spaces converted to pluses when asked to URL
  96. encode on set with the \fICURLU_URLENCODE\fP bit.
  97. If used together with the \fICURLU_APPENDQUERY\fP bit, the provided part is
  98. appended on the end of the existing query.
  99. The question mark in the URL is not part of the actual query contents.
  100. .IP CURLUPART_FRAGMENT
  101. The hash sign in the URL is not part of the actual fragment contents.
  102. .SH FLAGS
  103. The flags argument is zero, one or more bits set in a bitmask.
  104. .IP CURLU_APPENDQUERY
  105. Can be used when setting the \fICURLUPART_QUERY\fP component. The provided new
  106. part will then instead be appended at the end of the existing query - and if
  107. the previous part did not end with an ampersand (&), an ampersand gets
  108. inserted before the new appended part.
  109. When \fICURLU_APPENDQUERY\fP is used together with \fICURLU_URLENCODE\fP, the
  110. first '=' symbol will not be URL encoded.
  111. .IP CURLU_NON_SUPPORT_SCHEME
  112. If set, allows \fIcurl_url_set(3)\fP to set a non-supported scheme.
  113. .IP CURLU_URLENCODE
  114. When set, \fIcurl_url_set(3)\fP URL encodes the part on entry, except for
  115. scheme, port and URL.
  116. When setting the path component with URL encoding enabled, the slash character
  117. will be skipped.
  118. The query part gets space-to-plus conversion before the URL conversion.
  119. This URL encoding is charset unaware and will convert the input on a
  120. byte-by-byte manner.
  121. .IP CURLU_DEFAULT_SCHEME
  122. If set, will make libcurl allow the URL to be set without a scheme and then
  123. sets that to the default scheme: HTTPS. Overrides the \fICURLU_GUESS_SCHEME\fP
  124. option if both are set.
  125. .IP CURLU_GUESS_SCHEME
  126. If set, will make libcurl allow the URL to be set without a scheme and it
  127. instead "guesses" which scheme that was intended based on the host name. If
  128. the outermost sub-domain name matches DICT, FTP, IMAP, LDAP, POP3 or SMTP then
  129. that scheme will be used, otherwise it picks HTTP. Conflicts with the
  130. \fICURLU_DEFAULT_SCHEME\fP option which takes precedence if both are set.
  131. .IP CURLU_NO_AUTHORITY
  132. If set, skips authority checks. The RFC allows individual schemes to omit the
  133. host part (normally the only mandatory part of the authority), but libcurl
  134. cannot know whether this is permitted for custom schemes. Specifying the flag
  135. permits empty authority sections, similar to how file scheme is handled.
  136. .IP CURLU_PATH_AS_IS
  137. When set for \fBCURLUPART_URL\fP, this makes libcurl skip the normalization of
  138. the path. That is the procedure where curl otherwise removes sequences of
  139. dot-slash and dot-dot etc. The same option used for transfers is called
  140. \fICURLOPT_PATH_AS_IS(3)\fP.
  141. .IP CURLU_ALLOW_SPACE
  142. If set, the URL parser allows space (ASCII 32) where possible. The URL
  143. syntax does normally not allow spaces anywhere, but they should be encoded as
  144. %20 or '+'. When spaces are allowed, they are still not allowed in the scheme.
  145. When space is used and allowed in a URL, it will be stored as-is unless
  146. \fICURLU_URLENCODE\fP is also set, which then makes libcurl URL-encode the
  147. space before stored. This affects how the URL will be constructed when
  148. \fIcurl_url_get(3)\fP is subsequently used to extract the full URL or
  149. individual parts. (Added in 7.78.0)
  150. .IP CURLU_DISALLOW_USER
  151. If set, the URL parser will not accept embedded credentials for the
  152. \fBCURLUPART_URL\fP, and will instead return \fBCURLUE_USER_NOT_ALLOWED\fP for
  153. such URLs.
  154. .SH EXAMPLE
  155. .nf
  156. CURLUcode rc;
  157. CURLU *url = curl_url();
  158. rc = curl_url_set(url, CURLUPART_URL, "https://example.com", 0);
  159. if(!rc) {
  160. char *scheme;
  161. /* change it to an FTP URL */
  162. rc = curl_url_set(url, CURLUPART_SCHEME, "ftp", 0);
  163. }
  164. curl_url_cleanup(url);
  165. .fi
  166. .SH AVAILABILITY
  167. Added in 7.62.0. CURLUPART_ZONEID was added in 7.65.0.
  168. .SH RETURN VALUE
  169. Returns a \fICURLUcode\fP error value, which is CURLUE_OK (0) if everything
  170. went fine. See the \fIlibcurl-errors(3)\fP man page for the full list with
  171. descriptions.
  172. The input string passed to \fIcurl_url_set(3)\fP must be shorter than eight
  173. million bytes. Otherwise this function returns \fBCURLUE_MALFORMED_INPUT\fP.
  174. If this function returns an error, no URL part is set.
  175. .SH "SEE ALSO"
  176. .BR curl_url_cleanup "(3), " curl_url "(3), " curl_url_get "(3), "
  177. .BR curl_url_dup "(3), " curl_url_strerror "(3), " CURLOPT_CURLU "(3)"