2
0

curl_url_set.3 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. .\" **************************************************************************
  2. .\" * _ _ ____ _
  3. .\" * Project ___| | | | _ \| |
  4. .\" * / __| | | | |_) | |
  5. .\" * | (__| |_| | _ <| |___
  6. .\" * \___|\___/|_| \_\_____|
  7. .\" *
  8. .\" * Copyright (C) 1998 - 2020, 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.haxx.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. .\" **************************************************************************
  22. .TH curl_url_set 3 "6 Aug 2018" "libcurl" "libcurl Manual"
  23. .SH NAME
  24. curl_url_set - set a URL part
  25. .SH SYNOPSIS
  26. .B #include <curl/curl.h>
  27. CURLUcode curl_url_set(CURLU *url,
  28. CURLUPart part,
  29. const char *content,
  30. unsigned int flags)
  31. .fi
  32. .SH DESCRIPTION
  33. Given the \fIurl\fP handle of an already parsed URL, this function lets the
  34. user set/update individual pieces of it.
  35. The \fIpart\fP argument should identify the particular URL part (see list
  36. below) to set or change, with \fIcontent\fP pointing to a null-terminated
  37. string with the new contents for that URL part. The contents should be in the
  38. form and encoding they'd use in a URL: URL encoded.
  39. Setting a part to a NULL pointer will effectively remove that part's contents
  40. from the CURLU handle.
  41. The \fIflags\fP argument is a bitmask with independent features.
  42. .SH PARTS
  43. .IP CURLUPART_URL
  44. Allows the full URL of the handle to be replaced. If the handle already is
  45. populated with a URL, the new URL can be relative to the previous.
  46. When successfully setting a new URL, relative or absolute, the handle contents
  47. will be replaced with the information of the newly set URL.
  48. Pass a pointer to a null-terminated string to the \fIurl\fP parameter. The
  49. string must point to a correctly formatted "RFC 3986+" URL or be a NULL
  50. pointer.
  51. .IP CURLUPART_SCHEME
  52. Scheme cannot be URL decoded on set.
  53. .IP CURLUPART_USER
  54. .IP CURLUPART_PASSWORD
  55. .IP CURLUPART_OPTIONS
  56. .IP CURLUPART_HOST
  57. The host name. If it is IDNA the string must then be encoded as your locale
  58. says or UTF-8 (when WinIDN is used). If it is a bracketed IPv6 numeric address
  59. it may contain a zone id (or you can use CURLUPART_ZONEID).
  60. .IP CURLUPART_ZONEID
  61. If the host name is a numeric IPv6 address, this field can also be set.
  62. .IP CURLUPART_PORT
  63. Port cannot be URL encoded on set. The given port number is provided as a
  64. string and the decimal number must be between 1 and 65535. Anything else will
  65. return an error.
  66. .IP CURLUPART_PATH
  67. If a path is set in the URL without a leading slash, a slash will be inserted
  68. automatically when this URL is read from the handle.
  69. .IP CURLUPART_QUERY
  70. The query part will also get spaces converted to pluses when asked to URL
  71. encode on set with the CURLU_URLENCODE bit.
  72. If used together with the \fICURLU_APPENDQUERY\fP bit, the provided part will
  73. be appended on the end of the existing query - and if the previous part didn't
  74. end with an ampersand (&), an ampersand will be inserted before the new
  75. appended part.
  76. When \fICURLU_APPENDQUERY\fP is used together with \fICURLU_URLENCODE\fP, the
  77. first '=' symbol will not be URL encoded.
  78. The question mark in the URL is not part of the actual query contents.
  79. .IP CURLUPART_FRAGMENT
  80. The hash sign in the URL is not part of the actual fragment contents.
  81. .SH FLAGS
  82. The flags argument is zero, one or more bits set in a bitmask.
  83. .IP CURLU_NON_SUPPORT_SCHEME
  84. If set, allows \fIcurl_url_set(3)\fP to set a non-supported scheme.
  85. .IP CURLU_URLENCODE
  86. When set, \fIcurl_url_set(3)\fP URL encodes the part on entry, except for
  87. scheme, port and URL.
  88. When setting the path component with URL encoding enabled, the slash character
  89. will be skipped.
  90. The query part gets space-to-plus conversion before the URL conversion.
  91. This URL encoding is charset unaware and will convert the input on a
  92. byte-by-byte manner.
  93. .IP CURLU_DEFAULT_SCHEME
  94. If set, will make libcurl allow the URL to be set without a scheme and then
  95. sets that to the default scheme: HTTPS. Overrides the \fICURLU_GUESS_SCHEME\fP
  96. option if both are set.
  97. .IP CURLU_GUESS_SCHEME
  98. If set, will make libcurl allow the URL to be set without a scheme and it
  99. instead "guesses" which scheme that was intended based on the host name. If
  100. the outermost sub-domain name matches DICT, FTP, IMAP, LDAP, POP3 or SMTP then
  101. that scheme will be used, otherwise it picks HTTP. Conflicts with the
  102. \fICURLU_DEFAULT_SCHEME\fP option which takes precedence if both are set.
  103. .IP CURLU_NO_AUTHORITY
  104. If set, skips authority checks. The RFC allows individual schemes to omit the
  105. host part (normally the only mandatory part of the authority), but libcurl
  106. cannot know whether this is permitted for custom schemes. Specifying the flag
  107. permits empty authority sections, similar to how file scheme is handled.
  108. .SH RETURN VALUE
  109. Returns a CURLUcode error value, which is CURLUE_OK (0) if everything went
  110. fine.
  111. A URL string passed on to \fIcurl_url_set(3)\fP for the \fBCURLUPART_URL\fP
  112. part, must be shorter than 8000000 bytes otherwise it returns
  113. \fBCURLUE_MALFORMED_INPUT\fP (added in 7.65.0).
  114. If this function returns an error, no URL part is returned.
  115. .SH EXAMPLE
  116. .nf
  117. CURLUcode rc;
  118. CURLU *url = curl_url();
  119. rc = curl_url_set(url, CURLUPART_URL, "https://example.com", 0);
  120. if(!rc) {
  121. char *scheme;
  122. /* change it to an FTP URL */
  123. rc = curl_url_set(url, CURLUPART_SCHEME, "ftp", 0);
  124. }
  125. curl_url_cleanup(url);
  126. .fi
  127. .SH AVAILABILITY
  128. Added in curl 7.62.0. CURLUPART_ZONEID was added in 7.65.0.
  129. .SH "SEE ALSO"
  130. .BR curl_url_cleanup "(3), " curl_url "(3), " curl_url_get "(3), "
  131. .BR curl_url_dup "(3), "