http_utils.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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, 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 Remove white space at begin and end of string
  31. *
  32. * @param[in] str The string
  33. *
  34. * @return New strings have been trimmed
  35. */
  36. void http_utils_trim_whitespace(char **str);
  37. /**
  38. * @brief Gets the string between 2 string.
  39. * It will allocate a new memory space for this string, so you need to free it when no longer use
  40. *
  41. * @param[in] str The source string
  42. * @param[in] begin The begin string
  43. * @param[in] end The end string
  44. *
  45. * @return The string between begin and end
  46. */
  47. char *http_utils_get_string_between(const char *str, const char *begin, const char *end);
  48. /**
  49. * @brief Join 2 strings to one
  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] first_str The first string
  53. * @param[in] len_first The length first
  54. * @param[in] second_str The second string
  55. * @param[in] len_second The length second
  56. *
  57. * @return
  58. * - New string pointer
  59. * - NULL: Invalid input
  60. */
  61. char *http_utils_join_string(const char *first_str, int len_first, const char *second_str, int len_second);
  62. /**
  63. * @brief Check if ``str`` is start with ``start``
  64. *
  65. * @param[in] str The string
  66. * @param[in] start The start
  67. *
  68. * @return
  69. * - (-1) if length of ``start`` larger than length of ``str``
  70. * - (1) if ``start`` NOT starts with ``start``
  71. * - (0) if ``str`` starts with ``start``
  72. */
  73. int http_utils_str_starts_with(const char *str, const char *start);
  74. #define HTTP_MEM_CHECK(TAG, a, action) ESP_TRANSPORT_MEM_CHECK(TAG, a, action)
  75. #endif