http_utils.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #ifndef _HTTP_UTILS_H_
  7. #define _HTTP_UTILS_H_
  8. #include <sys/time.h>
  9. /**
  10. * @brief Assign new_str to *str pointer, and realloc *str if it not NULL
  11. *
  12. * @param str pointer to string pointer
  13. * @param new_str assign this tring to str
  14. * @param len length of string, less than 0 if new_str is zero terminated
  15. *
  16. * @return
  17. * - new_str pointer
  18. * - NULL
  19. */
  20. char *http_utils_assign_string(char **str, const char *new_str, int len);
  21. /**
  22. * @brief Realloc *str and append new_str to it if new_str is not NULL; return *str pointer if new_str is NULL
  23. *
  24. * @param str pointer to string pointer
  25. * @param new_str append this string to str
  26. * @param len length of string, less than 0 if new_str is zero terminated
  27. *
  28. * @return
  29. * - *str pointer
  30. */
  31. char *http_utils_append_string(char **str, const char *new_str, int len);
  32. /**
  33. * @brief Remove white space at begin and end of string
  34. *
  35. * @param[in] str The string
  36. *
  37. * @return New strings have been trimmed
  38. */
  39. void http_utils_trim_whitespace(char **str);
  40. /**
  41. * @brief Gets the string between 2 string.
  42. * It will allocate a new memory space for this string, so you need to free it when no longer use
  43. *
  44. * @param[in] str The source string
  45. * @param[in] begin The begin string
  46. * @param[in] end The end string
  47. *
  48. * @return The string between begin and end
  49. */
  50. char *http_utils_get_string_between(const char *str, const char *begin, const char *end);
  51. /**
  52. * @brief Join 2 strings to one
  53. * It will allocate a new memory space for this string, so you need to free it when no longer use
  54. *
  55. * @param[in] first_str The first string
  56. * @param[in] len_first The length first
  57. * @param[in] second_str The second string
  58. * @param[in] len_second The length second
  59. *
  60. * @return
  61. * - New string pointer
  62. * - NULL: Invalid input
  63. */
  64. char *http_utils_join_string(const char *first_str, size_t len_first, const char *second_str, size_t len_second);
  65. /**
  66. * @brief Check if ``str`` is start with ``start``
  67. *
  68. * @param[in] str The string
  69. * @param[in] start The start
  70. *
  71. * @return
  72. * - (-1) if length of ``start`` larger than length of ``str``
  73. * - (1) if ``start`` NOT starts with ``start``
  74. * - (0) if ``str`` starts with ``start``
  75. */
  76. int http_utils_str_starts_with(const char *str, const char *start);
  77. #endif