urlapi.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #ifndef __CURL_URLAPI_H
  2. #define __CURL_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;
  61. #define CURLU_DEFAULT_PORT (1<<0) /* return default port number */
  62. #define CURLU_NO_DEFAULT_PORT (1<<1) /* act as if no port number was set,
  63. if the port number matches the
  64. default for the scheme */
  65. #define CURLU_DEFAULT_SCHEME (1<<2) /* return default scheme if
  66. missing */
  67. #define CURLU_NON_SUPPORT_SCHEME (1<<3) /* allow non-supported scheme */
  68. #define CURLU_PATH_AS_IS (1<<4) /* leave dot sequences */
  69. #define CURLU_DISALLOW_USER (1<<5) /* no user+password allowed */
  70. #define CURLU_URLDECODE (1<<6) /* URL decode on get */
  71. #define CURLU_URLENCODE (1<<7) /* URL encode on set */
  72. #define CURLU_APPENDQUERY (1<<8) /* append a form style part */
  73. #define CURLU_GUESS_SCHEME (1<<9) /* legacy curl-style guessing */
  74. typedef struct Curl_URL CURLU;
  75. /*
  76. * curl_url() creates a new CURLU handle and returns a pointer to it.
  77. * Must be freed with curl_url_cleanup().
  78. */
  79. CURL_EXTERN CURLU *curl_url(void);
  80. /*
  81. * curl_url_cleanup() frees the CURLU handle and related resources used for
  82. * the URL parsing. It will not free strings previously returned with the URL
  83. * API.
  84. */
  85. CURL_EXTERN void curl_url_cleanup(CURLU *handle);
  86. /*
  87. * curl_url_dup() duplicates a CURLU handle and returns a new copy. The new
  88. * handle must also be freed with curl_url_cleanup().
  89. */
  90. CURL_EXTERN CURLU *curl_url_dup(CURLU *in);
  91. /*
  92. * curl_url_get() extracts a specific part of the URL from a CURLU
  93. * handle. Returns error code. The returned pointer MUST be freed with
  94. * curl_free() afterwards.
  95. */
  96. CURL_EXTERN CURLUcode curl_url_get(CURLU *handle, CURLUPart what,
  97. char **part, unsigned int flags);
  98. /*
  99. * curl_url_set() sets a specific part of the URL in a CURLU handle. Returns
  100. * error code. The passed in string will be copied. Passing a NULL instead of
  101. * a part string, clears that part.
  102. */
  103. CURL_EXTERN CURLUcode curl_url_set(CURLU *handle, CURLUPart what,
  104. const char *part, unsigned int flags);
  105. #ifdef __cplusplus
  106. } /* end of extern "C" */
  107. #endif
  108. #endif