urlapi.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #ifndef CURLINC_URLAPI_H
  2. #define CURLINC_URLAPI_H
  3. /***************************************************************************
  4. * _ _ ____ _
  5. * Project ___| | | | _ \| |
  6. * / __| | | | |_) | |
  7. * | (__| |_| | _ <| |___
  8. * \___|\___/|_| \_\_____|
  9. *
  10. * Copyright (C) 2018 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al.
  11. *
  12. * This software is licensed as described in the file COPYING, which
  13. * you should have received as part of this distribution. The terms
  14. * are also available at https://curl.se/docs/copyright.html.
  15. *
  16. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  17. * copies of the Software, and permit persons to whom the Software is
  18. * furnished to do so, under the terms of the COPYING file.
  19. *
  20. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  21. * KIND, either express or implied.
  22. *
  23. ***************************************************************************/
  24. #include "curl.h"
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif
  28. /* the error codes for the URL API */
  29. typedef enum {
  30. CURLUE_OK,
  31. CURLUE_BAD_HANDLE, /* 1 */
  32. CURLUE_BAD_PARTPOINTER, /* 2 */
  33. CURLUE_MALFORMED_INPUT, /* 3 */
  34. CURLUE_BAD_PORT_NUMBER, /* 4 */
  35. CURLUE_UNSUPPORTED_SCHEME, /* 5 */
  36. CURLUE_URLDECODE, /* 6 */
  37. CURLUE_OUT_OF_MEMORY, /* 7 */
  38. CURLUE_USER_NOT_ALLOWED, /* 8 */
  39. CURLUE_UNKNOWN_PART, /* 9 */
  40. CURLUE_NO_SCHEME, /* 10 */
  41. CURLUE_NO_USER, /* 11 */
  42. CURLUE_NO_PASSWORD, /* 12 */
  43. CURLUE_NO_OPTIONS, /* 13 */
  44. CURLUE_NO_HOST, /* 14 */
  45. CURLUE_NO_PORT, /* 15 */
  46. CURLUE_NO_QUERY, /* 16 */
  47. CURLUE_NO_FRAGMENT, /* 17 */
  48. CURLUE_LAST
  49. } CURLUcode;
  50. typedef enum {
  51. CURLUPART_URL,
  52. CURLUPART_SCHEME,
  53. CURLUPART_USER,
  54. CURLUPART_PASSWORD,
  55. CURLUPART_OPTIONS,
  56. CURLUPART_HOST,
  57. CURLUPART_PORT,
  58. CURLUPART_PATH,
  59. CURLUPART_QUERY,
  60. CURLUPART_FRAGMENT,
  61. CURLUPART_ZONEID /* added in 7.65.0 */
  62. } CURLUPart;
  63. #define CURLU_DEFAULT_PORT (1<<0) /* return default port number */
  64. #define CURLU_NO_DEFAULT_PORT (1<<1) /* act as if no port number was set,
  65. if the port number matches the
  66. default for the scheme */
  67. #define CURLU_DEFAULT_SCHEME (1<<2) /* return default scheme if
  68. missing */
  69. #define CURLU_NON_SUPPORT_SCHEME (1<<3) /* allow non-supported scheme */
  70. #define CURLU_PATH_AS_IS (1<<4) /* leave dot sequences */
  71. #define CURLU_DISALLOW_USER (1<<5) /* no user+password allowed */
  72. #define CURLU_URLDECODE (1<<6) /* URL decode on get */
  73. #define CURLU_URLENCODE (1<<7) /* URL encode on set */
  74. #define CURLU_APPENDQUERY (1<<8) /* append a form style part */
  75. #define CURLU_GUESS_SCHEME (1<<9) /* legacy curl-style guessing */
  76. #define CURLU_NO_AUTHORITY (1<<10) /* Allow empty authority when the
  77. scheme is unknown. */
  78. #define CURLU_ALLOW_SPACE (1<<11) /* Allow spaces in the URL */
  79. typedef struct Curl_URL CURLU;
  80. /*
  81. * curl_url() creates a new CURLU handle and returns a pointer to it.
  82. * Must be freed with curl_url_cleanup().
  83. */
  84. CURL_EXTERN CURLU *curl_url(void);
  85. /*
  86. * curl_url_cleanup() frees the CURLU handle and related resources used for
  87. * the URL parsing. It will not free strings previously returned with the URL
  88. * API.
  89. */
  90. CURL_EXTERN void curl_url_cleanup(CURLU *handle);
  91. /*
  92. * curl_url_dup() duplicates a CURLU handle and returns a new copy. The new
  93. * handle must also be freed with curl_url_cleanup().
  94. */
  95. CURL_EXTERN CURLU *curl_url_dup(CURLU *in);
  96. /*
  97. * curl_url_get() extracts a specific part of the URL from a CURLU
  98. * handle. Returns error code. The returned pointer MUST be freed with
  99. * curl_free() afterwards.
  100. */
  101. CURL_EXTERN CURLUcode curl_url_get(CURLU *handle, CURLUPart what,
  102. char **part, unsigned int flags);
  103. /*
  104. * curl_url_set() sets a specific part of the URL in a CURLU handle. Returns
  105. * error code. The passed in string will be copied. Passing a NULL instead of
  106. * a part string, clears that part.
  107. */
  108. CURL_EXTERN CURLUcode curl_url_set(CURLU *handle, CURLUPart what,
  109. const char *part, unsigned int flags);
  110. /*
  111. * curl_url_strerror() turns a CURLUcode value into the equivalent human
  112. * readable error string. This is useful for printing meaningful error
  113. * messages.
  114. */
  115. CURL_EXTERN const char *curl_url_strerror(CURLUcode);
  116. #ifdef __cplusplus
  117. } /* end of extern "C" */
  118. #endif
  119. #endif /* CURLINC_URLAPI_H */