urlapi.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #ifndef CURLINC_URLAPI_H
  2. #define CURLINC_URLAPI_H
  3. /***************************************************************************
  4. * _ _ ____ _
  5. * Project ___| | | | _ \| |
  6. * / __| | | | |_) | |
  7. * | (__| |_| | _ <| |___
  8. * \___|\___/|_| \_\_____|
  9. *
  10. * Copyright (C) 2018 - 2019, 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.haxx.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. } CURLUcode;
  49. typedef enum {
  50. CURLUPART_URL,
  51. CURLUPART_SCHEME,
  52. CURLUPART_USER,
  53. CURLUPART_PASSWORD,
  54. CURLUPART_OPTIONS,
  55. CURLUPART_HOST,
  56. CURLUPART_PORT,
  57. CURLUPART_PATH,
  58. CURLUPART_QUERY,
  59. CURLUPART_FRAGMENT,
  60. CURLUPART_ZONEID /* added in 7.65.0 */
  61. } CURLUPart;
  62. #define CURLU_DEFAULT_PORT (1<<0) /* return default port number */
  63. #define CURLU_NO_DEFAULT_PORT (1<<1) /* act as if no port number was set,
  64. if the port number matches the
  65. default for the scheme */
  66. #define CURLU_DEFAULT_SCHEME (1<<2) /* return default scheme if
  67. missing */
  68. #define CURLU_NON_SUPPORT_SCHEME (1<<3) /* allow non-supported scheme */
  69. #define CURLU_PATH_AS_IS (1<<4) /* leave dot sequences */
  70. #define CURLU_DISALLOW_USER (1<<5) /* no user+password allowed */
  71. #define CURLU_URLDECODE (1<<6) /* URL decode on get */
  72. #define CURLU_URLENCODE (1<<7) /* URL encode on set */
  73. #define CURLU_APPENDQUERY (1<<8) /* append a form style part */
  74. #define CURLU_GUESS_SCHEME (1<<9) /* legacy curl-style guessing */
  75. #define CURLU_NO_AUTHORITY (1<<10) /* Allow empty authority when the
  76. scheme is unknown. */
  77. typedef struct Curl_URL CURLU;
  78. /*
  79. * curl_url() creates a new CURLU handle and returns a pointer to it.
  80. * Must be freed with curl_url_cleanup().
  81. */
  82. CURL_EXTERN CURLU *curl_url(void);
  83. /*
  84. * curl_url_cleanup() frees the CURLU handle and related resources used for
  85. * the URL parsing. It will not free strings previously returned with the URL
  86. * API.
  87. */
  88. CURL_EXTERN void curl_url_cleanup(CURLU *handle);
  89. /*
  90. * curl_url_dup() duplicates a CURLU handle and returns a new copy. The new
  91. * handle must also be freed with curl_url_cleanup().
  92. */
  93. CURL_EXTERN CURLU *curl_url_dup(CURLU *in);
  94. /*
  95. * curl_url_get() extracts a specific part of the URL from a CURLU
  96. * handle. Returns error code. The returned pointer MUST be freed with
  97. * curl_free() afterwards.
  98. */
  99. CURL_EXTERN CURLUcode curl_url_get(CURLU *handle, CURLUPart what,
  100. char **part, unsigned int flags);
  101. /*
  102. * curl_url_set() sets a specific part of the URL in a CURLU handle. Returns
  103. * error code. The passed in string will be copied. Passing a NULL instead of
  104. * a part string, clears that part.
  105. */
  106. CURL_EXTERN CURLUcode curl_url_set(CURLU *handle, CURLUPart what,
  107. const char *part, unsigned int flags);
  108. #ifdef __cplusplus
  109. } /* end of extern "C" */
  110. #endif
  111. #endif /* CURLINC_URLAPI_H */