fix(esp_http_client): updated defination for macro mem_check

This commit replace macro MEM_CHECK with return on failure and
updated usage of reespctive APIs' in IDF.
This also update th prototype of API esp_http_client_add_auth().

Closes https://github.com/espressif/esp-idf/issues/14463
This commit is contained in:
nilesh.kale
2024-09-11 14:50:50 +05:30
parent ea55be3d8a
commit a0bcffcce9
7 changed files with 243 additions and 79 deletions

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -81,11 +81,9 @@ static esp_err_t http_header_new_item(http_header_handle_t header, const char *k
item = calloc(1, sizeof(http_header_item_t));
ESP_RETURN_ON_FALSE(item, ESP_ERR_NO_MEM, TAG, "Memory exhausted");
http_utils_assign_string(&item->key, key, -1);
ESP_GOTO_ON_FALSE(item->key, ESP_ERR_NO_MEM, _header_new_item_exit, TAG, "Memory exhausted");
ESP_GOTO_ON_FALSE_DEBUG(http_utils_assign_string(&item->key, key, -1), ESP_ERR_NO_MEM, _header_new_item_exit, TAG, "Failed to assign string");
http_utils_trim_whitespace(&item->key);
http_utils_assign_string(&item->value, value, -1);
ESP_GOTO_ON_FALSE(item->value, ESP_ERR_NO_MEM, _header_new_item_exit, TAG, "Memory exhausted");
ESP_GOTO_ON_FALSE_DEBUG(http_utils_assign_string(&item->value, value, -1), ESP_ERR_NO_MEM, _header_new_item_exit, TAG, "Failed to assign string");
http_utils_trim_whitespace(&item->value);
STAILQ_INSERT_TAIL(header, item, next);
return ret;
@@ -167,7 +165,7 @@ int http_header_set_format(http_header_handle_t header, const char *key, const c
int http_header_generate_string(http_header_handle_t header, int index, char *buffer, int *buffer_len)
{
http_header_item_handle_t item;
int siz = 0;
int size = 0;
int idx = 0;
int ret_idx = -1;
bool is_end = false;
@@ -175,13 +173,13 @@ int http_header_generate_string(http_header_handle_t header, int index, char *bu
// iterate over the header entries to calculate buffer size and determine last item
STAILQ_FOREACH(item, header, next) {
if (item->value && idx >= index) {
siz += strlen(item->key);
siz += strlen(item->value);
siz += 4; //': ' and '\r\n'
size += strlen(item->key);
size += strlen(item->value);
size += 4; //': ' and '\r\n'
}
idx ++;
if (siz + 1 > *buffer_len - 2) {
if (size + 1 > *buffer_len - 2) {
// if this item would not fit to the buffer, return the index of the last fitting one
ret_idx = idx - 1;
ESP_LOGE(TAG, "Buffer length is small to fit all the headers");
@@ -189,7 +187,7 @@ int http_header_generate_string(http_header_handle_t header, int index, char *bu
}
}
if (siz == 0) {
if (size == 0) {
return 0;
}
if (ret_idx < 0) {
@@ -198,7 +196,7 @@ int http_header_generate_string(http_header_handle_t header, int index, char *bu
is_end = true;
}
// iterate again over the header entries to write only the fitting indeces
// iterate again over the header entries to write only the fitting indices
int str_len = 0;
idx = 0;
STAILQ_FOREACH(item, header, next) {