curl_url_set.3 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. .\" **************************************************************************
  2. .\" * _ _ ____ _
  3. .\" * Project ___| | | | _ \| |
  4. .\" * / __| | | | |_) | |
  5. .\" * | (__| |_| | _ <| |___
  6. .\" * \___|\___/|_| \_\_____|
  7. .\" *
  8. .\" * Copyright (C) 1998 - 2022, 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 Manual"
  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. The \fIflags\fP argument is a bitmask with independent features.
  52. .SH PARTS
  53. .IP CURLUPART_URL
  54. Allows the full URL of the handle to be replaced. If the handle already is
  55. populated with a URL, the new URL can be relative to the previous.
  56. When successfully setting a new URL, relative or absolute, the handle contents
  57. will be replaced with the information of the newly set URL.
  58. Pass a pointer to a null-terminated string to the \fIurl\fP parameter. The
  59. string must point to a correctly formatted "RFC 3986+" URL or be a NULL
  60. pointer.
  61. .IP CURLUPART_SCHEME
  62. Scheme cannot be URL decoded on set. libcurl only accepts setting schemes up
  63. to 40 bytes long.
  64. .IP CURLUPART_USER
  65. .IP CURLUPART_PASSWORD
  66. .IP CURLUPART_OPTIONS
  67. .IP CURLUPART_HOST
  68. The host name. If it is IDNA the string must then be encoded as your locale
  69. says or UTF-8 (when WinIDN is used). If it is a bracketed IPv6 numeric address
  70. it may contain a zone id (or you can use CURLUPART_ZONEID).
  71. .IP CURLUPART_ZONEID
  72. If the host name is a numeric IPv6 address, this field can also be set.
  73. .IP CURLUPART_PORT
  74. Port cannot be URL encoded on set. The given port number is provided as a
  75. string and the decimal number must be between 1 and 65535. Anything else will
  76. return an error.
  77. .IP CURLUPART_PATH
  78. If a path is set in the URL without a leading slash, a slash will be inserted
  79. automatically when this URL is read from the handle.
  80. .IP CURLUPART_QUERY
  81. The query part will also get spaces converted to pluses when asked to URL
  82. encode on set with the \fICURLU_URLENCODE\fP bit.
  83. If used together with the \fICURLU_APPENDQUERY\fP bit, the provided part will
  84. be appended on the end of the existing query - and if the previous part did not
  85. end with an ampersand (&), an ampersand will be inserted before the new
  86. appended part.
  87. When \fICURLU_APPENDQUERY\fP is used together with \fICURLU_URLENCODE\fP, the
  88. first '=' symbol will not be URL encoded.
  89. The question mark in the URL is not part of the actual query contents.
  90. .IP CURLUPART_FRAGMENT
  91. The hash sign in the URL is not part of the actual fragment contents.
  92. .SH FLAGS
  93. The flags argument is zero, one or more bits set in a bitmask.
  94. .IP CURLU_NON_SUPPORT_SCHEME
  95. If set, allows \fIcurl_url_set(3)\fP to set a non-supported scheme.
  96. .IP CURLU_URLENCODE
  97. When set, \fIcurl_url_set(3)\fP URL encodes the part on entry, except for
  98. scheme, port and URL.
  99. When setting the path component with URL encoding enabled, the slash character
  100. will be skipped.
  101. The query part gets space-to-plus conversion before the URL conversion.
  102. This URL encoding is charset unaware and will convert the input on a
  103. byte-by-byte manner.
  104. .IP CURLU_DEFAULT_SCHEME
  105. If set, will make libcurl allow the URL to be set without a scheme and then
  106. sets that to the default scheme: HTTPS. Overrides the \fICURLU_GUESS_SCHEME\fP
  107. option if both are set.
  108. .IP CURLU_GUESS_SCHEME
  109. If set, will make libcurl allow the URL to be set without a scheme and it
  110. instead "guesses" which scheme that was intended based on the host name. If
  111. the outermost sub-domain name matches DICT, FTP, IMAP, LDAP, POP3 or SMTP then
  112. that scheme will be used, otherwise it picks HTTP. Conflicts with the
  113. \fICURLU_DEFAULT_SCHEME\fP option which takes precedence if both are set.
  114. .IP CURLU_NO_AUTHORITY
  115. If set, skips authority checks. The RFC allows individual schemes to omit the
  116. host part (normally the only mandatory part of the authority), but libcurl
  117. cannot know whether this is permitted for custom schemes. Specifying the flag
  118. permits empty authority sections, similar to how file scheme is handled.
  119. .IP CURLU_PATH_AS_IS
  120. When set for \fBCURLUPART_URL\fP, this makes libcurl skip the normalization of
  121. the path. That is the procedure where curl otherwise removes sequences of
  122. dot-slash and dot-dot etc. The same option used for transfers is called
  123. \fICURLOPT_PATH_AS_IS(3)\fP.
  124. .IP CURLU_ALLOW_SPACE
  125. If set, a the URL parser allows space (ASCII 32) where possible. The URL
  126. syntax does normally not allow spaces anywhere, but they should be encoded as
  127. %20 or '+'. When spaces are allowed, they are still not allowed in the scheme.
  128. When space is used and allowed in a URL, it will be stored as-is unless
  129. \fICURLU_URLENCODE\fP is also set, which then makes libcurl URL-encode the
  130. space before stored. This affects how the URL will be constructed when
  131. \fIcurl_url_get(3)\fP is subsequently used to extract the full URL or
  132. individual parts. (Added in 7.78.0)
  133. .SH EXAMPLE
  134. .nf
  135. CURLUcode rc;
  136. CURLU *url = curl_url();
  137. rc = curl_url_set(url, CURLUPART_URL, "https://example.com", 0);
  138. if(!rc) {
  139. char *scheme;
  140. /* change it to an FTP URL */
  141. rc = curl_url_set(url, CURLUPART_SCHEME, "ftp", 0);
  142. }
  143. curl_url_cleanup(url);
  144. .fi
  145. .SH AVAILABILITY
  146. Added in 7.62.0. CURLUPART_ZONEID was added in 7.65.0.
  147. .SH RETURN VALUE
  148. Returns a \fICURLUcode\fP error value, which is CURLUE_OK (0) if everything
  149. went fine. See the \fIlibcurl-errors(3)\fP man page for the full list with
  150. descriptions.
  151. A URL string passed on to \fIcurl_url_set(3)\fP for the \fBCURLUPART_URL\fP
  152. part, must be shorter than 8000000 bytes otherwise it returns
  153. \fBCURLUE_MALFORMED_INPUT\fP (added in 7.65.0).
  154. If this function returns an error, no URL part is set.
  155. .SH "SEE ALSO"
  156. .BR curl_url_cleanup "(3), " curl_url "(3), " curl_url_get "(3), "
  157. .BR curl_url_dup "(3), " curl_url_strerror "(3), " CURLOPT_CURLU "(3)"