http_header.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // Copyright 2015-2018 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #ifndef _HTTP_HEADER_H_
  14. #define _HTTP_HEADER_H_
  15. #include "aos/queue.h"
  16. #include "transport/tperrors.h"
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. typedef struct http_header *http_header_handle_t;
  21. typedef struct http_header_item *http_header_item_handle_t;
  22. /**
  23. * @brief initialize and allocate the memory for the header object
  24. *
  25. * @return
  26. * - http_header_handle_t
  27. * - NULL if any errors
  28. */
  29. http_header_handle_t http_header_init();
  30. /**
  31. * @brief Cleanup and free all http header pairs
  32. *
  33. * @param[in] header The header
  34. *
  35. * @return
  36. * - WEB_OK
  37. * - WEB_FAIL
  38. */
  39. web_err_t http_header_clean(http_header_handle_t header);
  40. /**
  41. * @brief Cleanup with http_header_clean and destroy http header handle object
  42. *
  43. * @param[in] header The header
  44. *
  45. * @return
  46. * - WEB_OK
  47. * - WEB_FAIL
  48. */
  49. web_err_t http_header_destroy(http_header_handle_t header);
  50. /**
  51. * @brief Add a key-value pair of http header to the list,
  52. * note that with value = NULL, this function will remove the header with `key` already exists in the list.
  53. *
  54. * @param[in] header The header
  55. * @param[in] key The key
  56. * @param[in] value The value
  57. *
  58. * @return
  59. * - WEB_OK
  60. * - WEB_FAIL
  61. */
  62. web_err_t http_header_set(http_header_handle_t header, const char *key, const char *value);
  63. /**
  64. * @brief Sample as `http_header_set` but the value can be formated
  65. *
  66. * @param[in] header The header
  67. * @param[in] key The key
  68. * @param[in] format The format
  69. * @param[in] ... format parameters
  70. *
  71. * @return Total length of value
  72. */
  73. int http_header_set_format(http_header_handle_t header, const char *key, const char *format, ...);
  74. /**
  75. * @brief Get a value of header in header list
  76. * The address of the value will be assign set to `value` parameter or NULL if no header with the key exists in the list
  77. *
  78. * @param[in] header The header
  79. * @param[in] key The key
  80. * @param[out] value The value
  81. *
  82. * @return
  83. * - WEB_OK
  84. * - WEB_FAIL
  85. */
  86. web_err_t http_header_get(http_header_handle_t header, const char *key, char **value);
  87. /**
  88. * @brief Create HTTP header string from the header with index, output string to buffer with buffer_len
  89. * Also return the last index of header was generated
  90. *
  91. * @param[in] header The header
  92. * @param[in] index The index
  93. * @param buffer The buffer
  94. * @param buffer_len The buffer length
  95. *
  96. * @return The last index of header was generated
  97. */
  98. int http_header_generate_string(http_header_handle_t header, int index, char *buffer, int *buffer_len);
  99. /**
  100. * @brief Remove the header with key from the headers list
  101. *
  102. * @param[in] header The header
  103. * @param[in] key The key
  104. *
  105. * @return
  106. * - WEB_OK
  107. * - WEB_FAIL
  108. */
  109. web_err_t http_header_delete(http_header_handle_t header, const char *key);
  110. #ifdef __cplusplus
  111. }
  112. #endif
  113. #endif