2021-05-31 08:06:09 -04:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
2017-11-13 22:16:20 -05:00
|
|
|
|
|
|
|
|
|
|
|
#ifndef _HTTP_UTILS_H_
|
|
|
|
#define _HTTP_UTILS_H_
|
|
|
|
#include <sys/time.h>
|
2019-04-16 05:58:38 -04:00
|
|
|
|
2017-11-13 22:16:20 -05:00
|
|
|
/**
|
|
|
|
* @brief Assign new_str to *str pointer, and realloc *str if it not NULL
|
|
|
|
*
|
|
|
|
* @param str pointer to string pointer
|
|
|
|
* @param new_str assign this tring to str
|
2021-02-06 22:37:49 -05:00
|
|
|
* @param len length of string, less than 0 if new_str is zero terminated
|
2017-11-13 22:16:20 -05:00
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - new_str pointer
|
|
|
|
* - NULL
|
|
|
|
*/
|
|
|
|
char *http_utils_assign_string(char **str, const char *new_str, int len);
|
|
|
|
|
2021-01-07 06:47:22 -05:00
|
|
|
/**
|
2021-02-06 22:37:49 -05:00
|
|
|
* @brief Realloc *str and append new_str to it if new_str is not NULL; return *str pointer if new_str is NULL
|
2021-01-07 06:47:22 -05:00
|
|
|
*
|
|
|
|
* @param str pointer to string pointer
|
2021-02-06 22:37:49 -05:00
|
|
|
* @param new_str append this string to str
|
|
|
|
* @param len length of string, less than 0 if new_str is zero terminated
|
2021-01-07 06:47:22 -05:00
|
|
|
*
|
|
|
|
* @return
|
2021-02-06 22:37:49 -05:00
|
|
|
* - *str pointer
|
2021-01-07 06:47:22 -05:00
|
|
|
*/
|
|
|
|
char *http_utils_append_string(char **str, const char *new_str, int len);
|
|
|
|
|
2017-11-13 22:16:20 -05:00
|
|
|
/**
|
|
|
|
* @brief Remove white space at begin and end of string
|
|
|
|
*
|
|
|
|
* @param[in] str The string
|
|
|
|
*
|
|
|
|
* @return New strings have been trimmed
|
|
|
|
*/
|
|
|
|
void http_utils_trim_whitespace(char **str);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Gets the string between 2 string.
|
|
|
|
* It will allocate a new memory space for this string, so you need to free it when no longer use
|
|
|
|
*
|
|
|
|
* @param[in] str The source string
|
|
|
|
* @param[in] begin The begin string
|
|
|
|
* @param[in] end The end string
|
|
|
|
*
|
|
|
|
* @return The string between begin and end
|
|
|
|
*/
|
|
|
|
char *http_utils_get_string_between(const char *str, const char *begin, const char *end);
|
|
|
|
|
2023-10-19 08:57:08 -04:00
|
|
|
/**
|
|
|
|
* @brief Returns a string that contains the part after the search string till the end of the source string.
|
|
|
|
* It will allocate a new memory space for this string, so you need to free it when no longer used
|
|
|
|
*
|
|
|
|
* @param[in] str The source string
|
|
|
|
* @param[in] begin The search string
|
|
|
|
*
|
|
|
|
* @return The string between begin and the end of str
|
|
|
|
*/
|
|
|
|
char *http_utils_get_string_after(const char *str, const char *begin);
|
|
|
|
|
2017-11-13 22:16:20 -05:00
|
|
|
/**
|
|
|
|
* @brief Join 2 strings to one
|
|
|
|
* It will allocate a new memory space for this string, so you need to free it when no longer use
|
|
|
|
*
|
|
|
|
* @param[in] first_str The first string
|
|
|
|
* @param[in] len_first The length first
|
|
|
|
* @param[in] second_str The second string
|
|
|
|
* @param[in] len_second The length second
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - New string pointer
|
|
|
|
* - NULL: Invalid input
|
|
|
|
*/
|
2020-11-16 23:48:35 -05:00
|
|
|
char *http_utils_join_string(const char *first_str, size_t len_first, const char *second_str, size_t len_second);
|
2017-11-13 22:16:20 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Check if ``str`` is start with ``start``
|
|
|
|
*
|
|
|
|
* @param[in] str The string
|
|
|
|
* @param[in] start The start
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - (-1) if length of ``start`` larger than length of ``str``
|
|
|
|
* - (1) if ``start`` NOT starts with ``start``
|
|
|
|
* - (0) if ``str`` starts with ``start``
|
|
|
|
*/
|
|
|
|
int http_utils_str_starts_with(const char *str, const char *start);
|
|
|
|
|
|
|
|
#endif
|