thttp_url.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Copyright (C) 2010-2015 Mamadou DIOP.
  3. *
  4. * This file is part of Open Source Doubango Framework.
  5. *
  6. * DOUBANGO is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * DOUBANGO is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with DOUBANGO.
  18. *
  19. */
  20. /**@file thttp_url.h
  21. * @brief HTTP/HTTPS URL.
  22. *
  23. */
  24. #ifndef TINYHTTP_URL_H
  25. #define TINYHTTP_URL_H
  26. #include "tinyhttp_config.h"
  27. #include "tsk_object.h"
  28. #include "tsk_params.h"
  29. #include "tsk_buffer.h"
  30. THTTP_BEGIN_DECLS
  31. #define THTTP_URL_IS_SECURE(url) ((url && url->type==thttp_url_https) ? 1 : 0)
  32. /** Url type.
  33. */
  34. typedef enum thttp_url_type_e {
  35. thttp_url_unknown,
  36. thttp_url_http,
  37. thttp_url_https,
  38. }
  39. thttp_url_type_t;
  40. typedef enum thttp_host_type_e {
  41. thttp_host_unknown,
  42. thttp_host_hostname,
  43. thttp_host_ipv4,
  44. thttp_host_ipv6
  45. }
  46. thttp_host_type_t;
  47. ////////////////////////////////////////////////////////////////////////////////////////////////////
  48. /// @struct thttp_url_t
  49. ///
  50. /// @brief HTTP/HTTPS URL.
  51. ///
  52. /// ABNF (Compact: From RFC 1738): httpurl = "http://" hostport [ "/" hpath [ "?" search ]]
  53. /// hpath = hsegment *[ "/" hsegment ]
  54. /// hsegment = *[ uchar | ";" | ":" | "@" | "&" | "=" ]
  55. /// search = *[ uchar | ";" | ":" | "@" | "&" | "=" ]
  56. ////////////////////////////////////////////////////////////////////////////////////////////////////
  57. typedef struct thttp_url_s {
  58. TSK_DECLARE_OBJECT;
  59. thttp_url_type_t type;
  60. char *scheme;
  61. char *host; /**< Host name. Hostname or IPv4address or IPv6address. */
  62. char *hpath;
  63. char *search;
  64. thttp_host_type_t host_type; /**< IPv4 or IPv6 or domain name. */
  65. uint16_t port;
  66. }
  67. thttp_url_t;
  68. TINYHTTP_API int thttp_url_serialize(const thttp_url_t *url, tsk_buffer_t *output);
  69. TINYHTTP_API char* thttp_url_tostring(const thttp_url_t *url);
  70. TINYHTTP_API thttp_url_t *thttp_url_clone(const thttp_url_t *url);
  71. TINYHTTP_API tsk_bool_t thttp_url_isvalid(const char* urlstring);
  72. thttp_url_t* thttp_url_create(thttp_url_type_t type);
  73. TINYHTTP_GEXTERN const tsk_object_def_t *thttp_url_def_t;
  74. THTTP_END_DECLS
  75. #endif /* TINYHTTP_URL_H */