Skip to content

Commit dcb43e0

Browse files
committed
fix(esp_common): move some DEBUG macros to http client component
In commit a0bcffc, some ESP_RETURN and ESP_GOTO debug macros were introduced. But this caused a regression with CONFIG_COMPILER_OPTIMIZATION_CHECKS_SILENT case. Its better to move this macros to HTTP client component itself, as the debug log is still desired for the specific use-case.
1 parent fdb1897 commit dcb43e0

File tree

4 files changed

+66
-80
lines changed

4 files changed

+66
-80
lines changed

components/esp_common/include/esp_check.h

Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -307,18 +307,6 @@ extern "C" {
307307
} \
308308
} while(0)
309309

310-
/**
311-
* Macro which can be used to check the error code. If the code is not ESP_OK, it prints the message and returns.
312-
* It logs the message in debug mode.
313-
*/
314-
#define ESP_RETURN_ON_ERROR_DEBUG(x, log_tag, format, ...) do { \
315-
esp_err_t err_rc_ = (x); \
316-
if (unlikely(err_rc_ != ESP_OK)) { \
317-
ESP_LOGD(log_tag, "%s(%d): " format, __FUNCTION__, __LINE__, ##__VA_ARGS__); \
318-
return err_rc_; \
319-
} \
320-
} while(0)
321-
322310
/**
323311
* A version of ESP_RETURN_ON_ERROR() macro that can be called from ISR.
324312
*/
@@ -366,20 +354,6 @@ extern "C" {
366354
} \
367355
} while(0)
368356

369-
/**
370-
* Macro which can be used to check the error code. If the code is not ESP_OK, it prints the message,
371-
* sets the local variable 'ret' to the code, and then exits by jumping to 'goto_tag'.
372-
* It logs the message in debug mode.
373-
*/
374-
#define ESP_GOTO_ON_ERROR_DEBUG(x, goto_tag, log_tag, format, ...) do { \
375-
esp_err_t err_rc_ = (x); \
376-
if (unlikely(err_rc_ != ESP_OK)) { \
377-
ESP_LOGD(log_tag, "%s(%d): " format, __FUNCTION__, __LINE__, ##__VA_ARGS__); \
378-
ret = err_rc_; \
379-
goto goto_tag; \
380-
} \
381-
} while(0)
382-
383357
/**
384358
* A version of ESP_GOTO_ON_ERROR() macro that can be called from ISR.
385359
*/
@@ -403,18 +377,6 @@ extern "C" {
403377
} \
404378
} while(0)
405379

406-
/**
407-
* Macro which can be used to check the condition. If the condition is not 'true', it prints the message
408-
* and returns with the supplied 'err_code'.
409-
* It logs the message in debug mode.
410-
*/
411-
#define ESP_RETURN_ON_FALSE_DEBUG(a, err_code, log_tag, format, ...) do { \
412-
if (unlikely(!(a))) { \
413-
ESP_LOGD(log_tag, "%s(%d): " format, __FUNCTION__, __LINE__, ##__VA_ARGS__); \
414-
return err_code; \
415-
} \
416-
} while(0)
417-
418380
/**
419381
* A version of ESP_RETURN_ON_FALSE() macro that can be called from ISR.
420382
*/
@@ -458,19 +420,6 @@ extern "C" {
458420
} \
459421
} while (0)
460422

461-
/**
462-
* Macro which can be used to check the condition. If the condition is not 'true', it prints the message,
463-
* sets the local variable 'ret' to the supplied 'err_code', and then exits by jumping to 'goto_tag'.
464-
* It logs the message in debug mode.
465-
*/
466-
#define ESP_GOTO_ON_FALSE_DEBUG(a, err_code, goto_tag, log_tag, format, ...) do { \
467-
if (unlikely(!(a))) { \
468-
ESP_LOGD(log_tag, "%s(%d): " format, __FUNCTION__, __LINE__, ##__VA_ARGS__); \
469-
ret = err_code; \
470-
goto goto_tag; \
471-
} \
472-
} while (0)
473-
474423
/**
475424
* A version of ESP_GOTO_ON_FALSE() macro that can be called from ISR.
476425
*/

components/esp_http_client/esp_http_client.c

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -255,7 +255,7 @@ static int http_on_header_field(http_parser *parser, const char *at, size_t leng
255255
{
256256
esp_http_client_t *client = parser->data;
257257
http_on_header_event(client);
258-
ESP_RETURN_ON_FALSE_DEBUG(http_utils_append_string(&client->current_header_key, at, length), -1, TAG, "Failed to append string");
258+
HTTP_RET_ON_FALSE_DBG(http_utils_append_string(&client->current_header_key, at, length), -1, TAG, "Failed to append string");
259259

260260
return 0;
261261
}
@@ -267,14 +267,14 @@ static int http_on_header_value(http_parser *parser, const char *at, size_t leng
267267
return 0;
268268
}
269269
if (strcasecmp(client->current_header_key, "Location") == 0) {
270-
ESP_RETURN_ON_FALSE_DEBUG(http_utils_append_string(&client->location, at, length), -1, TAG, "Failed to append string");
270+
HTTP_RET_ON_FALSE_DBG(http_utils_append_string(&client->location, at, length), -1, TAG, "Failed to append string");
271271
} else if (strcasecmp(client->current_header_key, "Transfer-Encoding") == 0
272272
&& memcmp(at, "chunked", length) == 0) {
273273
client->response->is_chunked = true;
274274
} else if (strcasecmp(client->current_header_key, "WWW-Authenticate") == 0) {
275-
ESP_RETURN_ON_FALSE_DEBUG(http_utils_append_string(&client->auth_header, at, length), -1, TAG, "Failed to append string");
275+
HTTP_RET_ON_FALSE_DBG(http_utils_append_string(&client->auth_header, at, length), -1, TAG, "Failed to append string");
276276
}
277-
ESP_RETURN_ON_FALSE_DEBUG(http_utils_append_string(&client->current_header_value, at, length), -1, TAG, "Failed to append string");
277+
HTTP_RET_ON_FALSE_DBG(http_utils_append_string(&client->current_header_value, at, length), -1, TAG, "Failed to append string");
278278
return 0;
279279
}
280280

@@ -554,12 +554,12 @@ static esp_err_t _set_config(esp_http_client_handle_t client, const esp_http_cli
554554
}
555555

556556
if (config->transport_type == HTTP_TRANSPORT_OVER_SSL) {
557-
ESP_GOTO_ON_FALSE_DEBUG(http_utils_assign_string(&client->connection_info.scheme, "https", -1), ESP_ERR_NO_MEM, error, TAG, "failed to assign string");
557+
HTTP_GOTO_ON_FALSE_DBG(http_utils_assign_string(&client->connection_info.scheme, "https", -1), ESP_ERR_NO_MEM, error, TAG, "failed to assign string");
558558
if (client->connection_info.port == 0) {
559559
client->connection_info.port = DEFAULT_HTTPS_PORT;
560560
}
561561
} else {
562-
ESP_GOTO_ON_FALSE_DEBUG(http_utils_assign_string(&client->connection_info.scheme, "http", -1), ESP_ERR_NO_MEM, error, TAG, "failed to assign string");
562+
HTTP_GOTO_ON_FALSE_DBG(http_utils_assign_string(&client->connection_info.scheme, "http", -1), ESP_ERR_NO_MEM, error, TAG, "failed to assign string");
563563
if (client->connection_info.port == 0) {
564564
client->connection_info.port = DEFAULT_HTTP_PORT;
565565
}
@@ -639,11 +639,11 @@ static esp_err_t esp_http_client_prepare_digest_auth(esp_http_client_handle_t cl
639639
// Freeing the allocated memory for auth_data->uri and setting it to NULL to prevent potential memory leaks
640640
free(client->auth_data->uri);
641641
client->auth_data->uri = NULL;
642-
ESP_GOTO_ON_FALSE_DEBUG(http_utils_assign_string(&client->auth_data->uri, client->connection_info.path, -1), ESP_ERR_NO_MEM, error, TAG, "failed to assign string");
642+
HTTP_GOTO_ON_FALSE_DBG(http_utils_assign_string(&client->auth_data->uri, client->connection_info.path, -1), ESP_ERR_NO_MEM, error, TAG, "failed to assign string");
643643

644644
if (client->connection_info.query) {
645-
ESP_GOTO_ON_FALSE_DEBUG(http_utils_append_string(&client->auth_data->uri, "?", -1), ESP_ERR_NO_MEM, error, TAG, "Failed to append string");
646-
ESP_GOTO_ON_FALSE_DEBUG(http_utils_append_string(&client->auth_data->uri, client->connection_info.query, -1), ESP_ERR_NO_MEM, error, TAG, "Failed to append string");
645+
HTTP_GOTO_ON_FALSE_DBG(http_utils_append_string(&client->auth_data->uri, "?", -1), ESP_ERR_NO_MEM, error, TAG, "Failed to append string");
646+
HTTP_GOTO_ON_FALSE_DBG(http_utils_append_string(&client->auth_data->uri, client->connection_info.query, -1), ESP_ERR_NO_MEM, error, TAG, "Failed to append string");
647647
}
648648

649649
client->auth_data->cnonce = ((uint64_t)esp_random() << 32) + esp_random();
@@ -1101,7 +1101,7 @@ esp_err_t esp_http_client_set_url(esp_http_client_handle_t client, const char *u
11011101
old_port = client->connection_info.port;
11021102

11031103
if (purl.field_data[UF_HOST].len) {
1104-
ESP_GOTO_ON_FALSE_DEBUG(http_utils_assign_string(&client->connection_info.host, url + purl.field_data[UF_HOST].off, purl.field_data[UF_HOST].len), ESP_ERR_NO_MEM, error, TAG, "failed to assign string");
1104+
HTTP_GOTO_ON_FALSE_DBG(http_utils_assign_string(&client->connection_info.host, url + purl.field_data[UF_HOST].off, purl.field_data[UF_HOST].len), ESP_ERR_NO_MEM, error, TAG, "failed to assign string");
11051105
}
11061106
// Close the connection if host was changed
11071107
if (old_host && client->connection_info.host
@@ -1122,7 +1122,7 @@ esp_err_t esp_http_client_set_url(esp_http_client_handle_t client, const char *u
11221122
}
11231123

11241124
if (purl.field_data[UF_SCHEMA].len) {
1125-
ESP_GOTO_ON_FALSE_DEBUG(http_utils_assign_string(&client->connection_info.scheme, url + purl.field_data[UF_SCHEMA].off, purl.field_data[UF_SCHEMA].len), ESP_ERR_NO_MEM, error, TAG, "failed to assign string");
1125+
HTTP_GOTO_ON_FALSE_DBG(http_utils_assign_string(&client->connection_info.scheme, url + purl.field_data[UF_SCHEMA].off, purl.field_data[UF_SCHEMA].len), ESP_ERR_NO_MEM, error, TAG, "failed to assign string");
11261126

11271127
if (strcasecmp(client->connection_info.scheme, "http") == 0) {
11281128
client->connection_info.port = DEFAULT_HTTP_PORT;
@@ -1143,16 +1143,16 @@ esp_err_t esp_http_client_set_url(esp_http_client_handle_t client, const char *u
11431143

11441144
if (purl.field_data[UF_USERINFO].len) {
11451145
char *user_info = NULL;
1146-
ESP_GOTO_ON_FALSE_DEBUG(http_utils_assign_string(&user_info, url + purl.field_data[UF_USERINFO].off, purl.field_data[UF_USERINFO].len), ESP_ERR_NO_MEM, error, TAG, "failed to assign string");
1146+
HTTP_GOTO_ON_FALSE_DBG(http_utils_assign_string(&user_info, url + purl.field_data[UF_USERINFO].off, purl.field_data[UF_USERINFO].len), ESP_ERR_NO_MEM, error, TAG, "failed to assign string");
11471147
if (user_info) {
11481148
char *username = user_info;
11491149
char *password = strchr(user_info, ':');
11501150
if (password) {
11511151
*password = 0;
11521152
password ++;
1153-
ESP_GOTO_ON_FALSE_DEBUG(http_utils_assign_string(&client->connection_info.password, password, -1), ESP_ERR_NO_MEM, error, TAG, "failed to assign string");
1153+
HTTP_GOTO_ON_FALSE_DBG(http_utils_assign_string(&client->connection_info.password, password, -1), ESP_ERR_NO_MEM, error, TAG, "failed to assign string");
11541154
}
1155-
ESP_GOTO_ON_FALSE_DEBUG(http_utils_assign_string(&client->connection_info.username, username, -1), ESP_ERR_NO_MEM, error, TAG, "failed to assign string");
1155+
HTTP_GOTO_ON_FALSE_DBG(http_utils_assign_string(&client->connection_info.username, username, -1), ESP_ERR_NO_MEM, error, TAG, "failed to assign string");
11561156
free(user_info);
11571157
} else {
11581158
return ESP_ERR_NO_MEM;
@@ -1161,13 +1161,13 @@ esp_err_t esp_http_client_set_url(esp_http_client_handle_t client, const char *u
11611161

11621162
//Reset path and query if there are no information
11631163
if (purl.field_data[UF_PATH].len) {
1164-
ESP_GOTO_ON_FALSE_DEBUG(http_utils_assign_string(&client->connection_info.path, url + purl.field_data[UF_PATH].off, purl.field_data[UF_PATH].len), ESP_ERR_NO_MEM, error, TAG, "failed to assign string");
1164+
HTTP_GOTO_ON_FALSE_DBG(http_utils_assign_string(&client->connection_info.path, url + purl.field_data[UF_PATH].off, purl.field_data[UF_PATH].len), ESP_ERR_NO_MEM, error, TAG, "failed to assign string");
11651165
} else {
1166-
ESP_GOTO_ON_FALSE_DEBUG(http_utils_assign_string(&client->connection_info.path, "/", -1), ESP_ERR_NO_MEM, error, TAG, "failed to assign string");
1166+
HTTP_GOTO_ON_FALSE_DBG(http_utils_assign_string(&client->connection_info.path, "/", -1), ESP_ERR_NO_MEM, error, TAG, "failed to assign string");
11671167
}
11681168

11691169
if (purl.field_data[UF_QUERY].len) {
1170-
ESP_GOTO_ON_FALSE_DEBUG(http_utils_assign_string(&client->connection_info.query, url + purl.field_data[UF_QUERY].off, purl.field_data[UF_QUERY].len), ESP_ERR_NO_MEM, error, TAG, "failed to assign string");
1170+
HTTP_GOTO_ON_FALSE_DBG(http_utils_assign_string(&client->connection_info.query, url + purl.field_data[UF_QUERY].off, purl.field_data[UF_QUERY].len), ESP_ERR_NO_MEM, error, TAG, "failed to assign string");
11711171
} else if (client->connection_info.query) {
11721172
free(client->connection_info.query);
11731173
client->connection_info.query = NULL;
@@ -1792,7 +1792,7 @@ esp_err_t esp_http_client_set_auth_data(esp_http_client_handle_t client, const c
17921792
if (client == NULL || auth_data == NULL || len <= 0) {
17931793
return ESP_ERR_INVALID_ARG;
17941794
}
1795-
ESP_RETURN_ON_FALSE_DEBUG(http_utils_append_string(&client->auth_header, auth_data, len), ESP_ERR_NO_MEM, TAG, "Failed to append string");
1795+
HTTP_RET_ON_FALSE_DBG(http_utils_append_string(&client->auth_header, auth_data, len), ESP_ERR_NO_MEM, TAG, "Failed to append string");
17961796
return ESP_OK;
17971797
}
17981798

@@ -1841,20 +1841,20 @@ esp_err_t esp_http_client_add_auth(esp_http_client_handle_t client)
18411841
client->auth_data->method = strdup(HTTP_METHOD_MAPPING[client->connection_info.method]);
18421842

18431843
client->auth_data->nc = 1;
1844-
ESP_RETURN_ON_ERROR_DEBUG(http_utils_get_substring_between(auth_header, "realm=\"", "\"", &client->auth_data->realm), TAG, "Unable to extract substring between specified strings");
1845-
ESP_RETURN_ON_ERROR_DEBUG(http_utils_get_substring_between(auth_header, "algorithm=", ",", &client->auth_data->algorithm), TAG, "Unable to extract substring between specified strings");
1844+
HTTP_RET_ON_ERR_DBG(http_utils_get_substring_between(auth_header, "realm=\"", "\"", &client->auth_data->realm), TAG, "Unable to extract substring between specified strings");
1845+
HTTP_RET_ON_ERR_DBG(http_utils_get_substring_between(auth_header, "algorithm=", ",", &client->auth_data->algorithm), TAG, "Unable to extract substring between specified strings");
18461846

18471847
if (client->auth_data->algorithm == NULL) {
1848-
ESP_RETURN_ON_ERROR_DEBUG(http_utils_get_substring_after(auth_header, "algorithm=", &client->auth_data->algorithm), TAG, "Unable to extract substring after specified string");
1848+
HTTP_RET_ON_ERR_DBG(http_utils_get_substring_after(auth_header, "algorithm=", &client->auth_data->algorithm), TAG, "Unable to extract substring after specified string");
18491849
}
18501850

18511851
if (client->auth_data->algorithm == NULL) {
18521852
client->auth_data->algorithm = strdup("MD5");
18531853
}
18541854

1855-
ESP_RETURN_ON_ERROR_DEBUG(http_utils_get_substring_between(auth_header, "qop=\"", "\"", &client->auth_data->qop), TAG, "Unable to extract substring between specified strings");
1856-
ESP_RETURN_ON_ERROR_DEBUG(http_utils_get_substring_between(auth_header, "nonce=\"", "\"", &client->auth_data->nonce), TAG, "Unable to extract substring between specified strings");
1857-
ESP_RETURN_ON_ERROR_DEBUG(http_utils_get_substring_between(auth_header, "opaque=\"", "\"", &client->auth_data->opaque), TAG, "Unable to extract substring between specified strings");
1855+
HTTP_RET_ON_ERR_DBG(http_utils_get_substring_between(auth_header, "qop=\"", "\"", &client->auth_data->qop), TAG, "Unable to extract substring between specified strings");
1856+
HTTP_RET_ON_ERR_DBG(http_utils_get_substring_between(auth_header, "nonce=\"", "\"", &client->auth_data->nonce), TAG, "Unable to extract substring between specified strings");
1857+
HTTP_RET_ON_ERR_DBG(http_utils_get_substring_between(auth_header, "opaque=\"", "\"", &client->auth_data->opaque), TAG, "Unable to extract substring between specified strings");
18581858
client->process_again = 1;
18591859

18601860
return ESP_OK;

components/esp_http_client/lib/http_header.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ static esp_err_t http_header_new_item(http_header_handle_t header, const char *k
8181

8282
item = calloc(1, sizeof(http_header_item_t));
8383
ESP_RETURN_ON_FALSE(item, ESP_ERR_NO_MEM, TAG, "Memory exhausted");
84-
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");
84+
HTTP_GOTO_ON_FALSE_DBG(http_utils_assign_string(&item->key, key, -1), ESP_ERR_NO_MEM, _header_new_item_exit, TAG, "Failed to assign string");
8585
http_utils_trim_whitespace(&item->key);
86-
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");
86+
HTTP_GOTO_ON_FALSE_DBG(http_utils_assign_string(&item->value, value, -1), ESP_ERR_NO_MEM, _header_new_item_exit, TAG, "Failed to assign string");
8787
http_utils_trim_whitespace(&item->value);
8888
STAILQ_INSERT_TAIL(header, item, next);
8989
return ret;

0 commit comments

Comments
 (0)