http_utils.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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_UTILS_H_
  14. #define _HTTP_UTILS_H_
  15. #include <sys/time.h>
  16. #include "esp_transport_utils.h"
  17. /**
  18. * @brief Assign new_str to *str pointer, and realloc *str if it not NULL
  19. *
  20. * @param str pointer to string pointer
  21. * @param new_str assign this tring to str
  22. * @param len length of string, less than 0 if new_str is zero terminated
  23. *
  24. * @return
  25. * - new_str pointer
  26. * - NULL
  27. */
  28. char *http_utils_assign_string(char **str, const char *new_str, int len);
  29. /**
  30. * @brief Realloc *str and append new_str to it if new_str is not NULL; return *str pointer if new_str is NULL
  31. *
  32. * @param str pointer to string pointer
  33. * @param new_str append this string to str
  34. * @param len length of string, less than 0 if new_str is zero terminated
  35. *
  36. * @return
  37. * - *str pointer
  38. */
  39. char *http_utils_append_string(char **str, const char *new_str, int len);
  40. /**
  41. * @brief Remove white space at begin and end of string
  42. *
  43. * @param[in] str The string
  44. *
  45. * @return New strings have been trimmed
  46. */
  47. void http_utils_trim_whitespace(char **str);
  48. /**
  49. * @brief Gets the string between 2 string.
  50. * It will allocate a new memory space for this string, so you need to free it when no longer use
  51. *
  52. * @param[in] str The source string
  53. * @param[in] begin The begin string
  54. * @param[in] end The end string
  55. *
  56. * @return The string between begin and end
  57. */
  58. char *http_utils_get_string_between(const char *str, const char *begin, const char *end);
  59. /**
  60. * @brief Join 2 strings to one
  61. * It will allocate a new memory space for this string, so you need to free it when no longer use
  62. *
  63. * @param[in] first_str The first string
  64. * @param[in] len_first The length first
  65. * @param[in] second_str The second string
  66. * @param[in] len_second The length second
  67. *
  68. * @return
  69. * - New string pointer
  70. * - NULL: Invalid input
  71. */
  72. char *http_utils_join_string(const char *first_str, int len_first, const char *second_str, int len_second);
  73. /**
  74. * @brief Check if ``str`` is start with ``start``
  75. *
  76. * @param[in] str The string
  77. * @param[in] start The start
  78. *
  79. * @return
  80. * - (-1) if length of ``start`` larger than length of ``str``
  81. * - (1) if ``start`` NOT starts with ``start``
  82. * - (0) if ``str`` starts with ``start``
  83. */
  84. int http_utils_str_starts_with(const char *str, const char *start);
  85. #define HTTP_MEM_CHECK(TAG, a, action) ESP_TRANSPORT_MEM_CHECK(TAG, a, action)
  86. #endif