curl_url_set.3 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. .\" **************************************************************************
  2. .\" * _ _ ____ _
  3. .\" * Project ___| | | | _ \| |
  4. .\" * / __| | | | |_) | |
  5. .\" * | (__| |_| | _ <| |___
  6. .\" * \___|\___/|_| \_\_____|
  7. .\" *
  8. .\" * Copyright (C) 1998 - 2018, 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 zero 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 zero 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 can use IDNA. The string must then be encoded as your locale
  58. says or UTF-8 (when winidn is used).
  59. .IP CURLUPART_PORT
  60. Port cannot be URL encoded on set.
  61. .IP CURLUPART_PATH
  62. If a path is set in the URL without a leading slash, a slash will be inserted
  63. automatically when this URL is read from the handle.
  64. .IP CURLUPART_QUERY
  65. The query part will also get spaces converted to pluses when asked to URL
  66. encode on set with the CURLU_URLENCODE bit.
  67. If used together with the \fICURLU_APPENDQUERY\fP bit, the provided part will
  68. be appended on the end of the existing query - and if the previous part didn't
  69. end with an ampersand (&), an ampersand will be inserted before the new
  70. appended part.
  71. When \fICURLU_APPENDQUERY\fP is used together with \fICURLU_URLENCODE\fP, the
  72. first '=' symbol will not be URL encoded.
  73. The question mark in the URL is not part of the actual query contents.
  74. .IP CURLUPART_FRAGMENT
  75. The hash sign in the URL is not part of the actual fragment contents.
  76. .SH FLAGS
  77. The flags argument is zero, one or more bits set in a bitmask.
  78. .IP CURLU_NON_SUPPORT_SCHEME
  79. If set, allows \fIcurl_url_set(3)\fP to set a non-supported scheme.
  80. .IP CURLU_URLENCODE
  81. When set, \fIcurl_url_set(3)\fP URL encodes the part on entry, except for
  82. scheme, port and URL.
  83. When setting the path component with URL encoding enabled, the slash character
  84. will be skipped.
  85. The query part gets space-to-plus conversion before the URL conversion.
  86. This URL encoding is charset unaware and will convert the input on a
  87. byte-by-byte manner.
  88. .IP CURLU_DEFAULT_SCHEME
  89. If set, will make libcurl allow the URL to be set without a scheme and then
  90. sets that to the default scheme: HTTPS. Overrides the \fICURLU_GUESS_SCHEME\fP
  91. option if both are set.
  92. .IP CURLU_GUESS_SCHEME
  93. If set, will make libcurl allow the URL to be set without a scheme and it
  94. instead "guesses" which scheme that was intended based on the host name. If
  95. the outermost sub-domain name matches DICT, FTP, IMAP, LDAP, POP3 or SMTP then
  96. that scheme will be used, otherwise it picks HTTP. Conflicts with the
  97. \fICURLU_DEFAULT_SCHEME\fP option which takes precedence if both are set.
  98. .SH RETURN VALUE
  99. Returns a CURLUcode error value, which is CURLUE_OK (0) if everything went
  100. fine.
  101. If this function returns an error, no URL part is returned.
  102. .SH EXAMPLE
  103. .nf
  104. CURLUcode rc;
  105. CURLU *url = curl_url();
  106. rc = curl_url_set(url, CURLUPART_URL, "https://example.com", 0);
  107. if(!rc) {
  108. char *scheme;
  109. /* change it to an FTP URL */
  110. rc = curl_url_set(url, CURLUPART_SCHEME, "ftp", 0);
  111. }
  112. curl_url_cleanup(url);
  113. .fi
  114. .SH AVAILABILITY
  115. Added in curl 7.62.0
  116. .SH "SEE ALSO"
  117. .BR curl_url_cleanup "(3), " curl_url "(3), " curl_url_get "(3), "
  118. .BR curl_url_dup "(3), "