curl_url_get.3 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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_get 3 "6 Aug 2018" "libcurl" "libcurl Manual"
  23. .SH NAME
  24. curl_url_get - extract a part from a URL
  25. .SH SYNOPSIS
  26. .B #include <curl/curl.h>
  27. .nf
  28. CURLUcode curl_url_get(CURLU *url,
  29. CURLUPart what,
  30. char **part,
  31. unsigned int flags)
  32. .fi
  33. .SH DESCRIPTION
  34. Given the \fIurl\fP handle of an already parsed URL, this function lets the
  35. user extract individual pieces from it.
  36. The \fIwhat\fP argument should be the particular part to extract (see list
  37. below) and \fIpart\fP points to a 'char *' to get updated to point to a newly
  38. allocated string with the contents.
  39. The \fIflags\fP argument is a bitmask with individual features.
  40. The returned part pointer must be freed with \fIcurl_free(3)\fP after use.
  41. .SH FLAGS
  42. The flags argument is zero, one or more bits set in a bitmask.
  43. .IP CURLU_DEFAULT_PORT
  44. If the handle has no port stored, this option will make \fIcurl_url_get(3)\fP
  45. return the default port for the used scheme.
  46. .IP CURLU_DEFAULT_SCHEME
  47. If the handle has no scheme stored, this option will make
  48. \fIcurl_url_get(3)\fP return the default scheme instead of error.
  49. .IP CURLU_NO_DEFAULT_PORT
  50. Instructs \fIcurl_url_get(3)\fP to not return a port number if it matches the
  51. default port for the scheme.
  52. .IP CURLU_URLDECODE
  53. Asks \fIcurl_url_get(3)\fP to URL decode the contents before returning it. It
  54. will not attempt to decode the scheme, the port number or the full URL.
  55. The query component will also get plus-to-space conversion as a bonus when
  56. this bit is set.
  57. Note that this URL decoding is charset unaware and you will get a zero
  58. terminated string back with data that could be intended for a particular
  59. encoding.
  60. If there's any byte values lower than 32 in the decoded string, the get
  61. operation will return an error instead.
  62. .SH PARTS
  63. .IP CURLUPART_URL
  64. When asked to return the full URL, \fIcurl_url_get(3)\fP will return a
  65. normalized and possibly cleaned up version of what was previously parsed.
  66. .IP CURLUPART_SCHEME
  67. Scheme cannot be URL decoded on get.
  68. .IP CURLUPART_USER
  69. .IP CURLUPART_PASSWORD
  70. .IP CURLUPART_OPTIONS
  71. .IP CURLUPART_HOST
  72. .IP CURLUPART_PORT
  73. Port cannot be URL decoded on get.
  74. .IP CURLUPART_PATH
  75. .IP CURLUPART_QUERY
  76. The query part will also get pluses converted to space when asked to URL
  77. decode on get with the CURLU_URLDECODE bit.
  78. .IP CURLUPART_FRAGMENT
  79. .SH RETURN VALUE
  80. Returns a CURLUcode error value, which is CURLUE_OK (0) if everything went
  81. fine.
  82. If this function returns an error, no URL part is returned.
  83. .SH EXAMPLE
  84. .nf
  85. CURLUcode rc;
  86. CURLU *url = curl_url();
  87. rc = curl_url_set(url, CURLUPART_URL, "https://example.com", 0);
  88. if(!rc) {
  89. char *scheme;
  90. rc = curl_url_get(url, CURLUPART_SCHEME, &scheme, 0);
  91. if(!rc) {
  92. printf("the scheme is %s\\n", scheme);
  93. curl_free(scheme);
  94. }
  95. curl_url_cleanup(url);
  96. }
  97. .fi
  98. .SH AVAILABILITY
  99. Added in curl 7.62.0
  100. .SH "SEE ALSO"
  101. .BR curl_url_cleanup "(3), " curl_url "(3), " curl_url_set "(3), "
  102. .BR curl_url_dup "(3), "