thttp_header.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Copyright (C) 2010-2011 Mamadou Diop.
  3. *
  4. * Contact: Mamadou Diop <diopmamadou(at)doubango[dot]org>
  5. *
  6. * This file is part of Open Source Doubango Framework.
  7. *
  8. * DOUBANGO is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * DOUBANGO is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with DOUBANGO.
  20. *
  21. */
  22. /**@file thttp_header.h
  23. * @brief Defines a HTTP header (field-name: field-value).
  24. *
  25. * @author Mamadou Diop <diopmamadou(at)doubango[dot]org>
  26. *
  27. */
  28. #ifndef TINYHTTP_HEADER_H
  29. #define TINYHTTP_HEADER_H
  30. #include "tinyhttp_config.h"
  31. #include "tsk_ragel_state.h"
  32. #include "tsk_params.h"
  33. #include "tsk_object.h"
  34. #include "tsk_safeobj.h"
  35. #include "tsk_memory.h"
  36. #include "tsk_string.h"
  37. #include "tsk_list.h"
  38. #include "tsk_buffer.h"
  39. THTTP_BEGIN_DECLS
  40. #define THTTP_HEADER(self) ((thttp_header_t*)(self))
  41. #define THTTP_HEADER_PARAMS(self) (THTTP_HEADER(self)->params)
  42. // FD
  43. struct thttp_header_s;
  44. typedef int (*thttp_header_value_tostring_f)(const struct thttp_header_s* header, tsk_buffer_t* output);
  45. #define THTTP_HEADER_VALUE_TOSTRING_F(self) ((thttp_header_value_tostring_f)(self))
  46. /**
  47. * @enum thttp_header_type_e
  48. *
  49. * @brief List of all supported headers.
  50. **/
  51. typedef enum thttp_header_type_e {
  52. thttp_htype_Authorization,
  53. thttp_htype_Content_Length,
  54. thttp_htype_Content_Type,
  55. thttp_htype_Dummy,
  56. thttp_htype_ETag,
  57. thttp_htype_Proxy_Authenticate,
  58. thttp_htype_Proxy_Authorization,
  59. thttp_htype_Sec_WebSocket_Accept,
  60. thttp_htype_Sec_WebSocket_Protocol,
  61. thttp_htype_Sec_WebSocket_Key,
  62. thttp_htype_Sec_WebSocket_Version,
  63. thttp_htype_Transfer_Encoding,
  64. thttp_htype_WWW_Authenticate,
  65. }
  66. thttp_header_type_t;
  67. /*================================
  68. */
  69. typedef struct thttp_header_s {
  70. TSK_DECLARE_OBJECT;
  71. thttp_header_type_t type;
  72. thttp_header_value_tostring_f tostring;
  73. tsk_params_L_t *params;
  74. }
  75. thttp_header_t;
  76. #define THTTP_DECLARE_HEADER thttp_header_t __header__
  77. typedef tsk_list_t thttp_headers_L_t; /**< List of @ref thttp_header_t elements. */
  78. /*
  79. ================================*/
  80. TINYHTTP_API const char *thttp_header_get_name(thttp_header_type_t type);
  81. TINYHTTP_API const char *thttp_header_get_nameex(const thttp_header_t *self);
  82. TINYHTTP_API char thttp_header_get_param_separator(const thttp_header_t *self);
  83. TINYHTTP_API int thttp_header_serialize(const thttp_header_t *self, tsk_buffer_t *output);
  84. TINYHTTP_API char* thttp_header_tostring(const thttp_header_t *self);
  85. TINYHTTP_API char* thttp_header_value_tostring(const thttp_header_t *self);
  86. THTTP_END_DECLS
  87. #endif /* TINYHTTP_HEADERS_H */