Skip to content

Commit 24be422

Browse files
committed
Merge branch 'bugfix/missing-esp-goto-on-false-debug' into 'master'
fix: Fixed missing macros declarations in esp_check.h See merge request espressif/esp-idf!36352
2 parents 70ead76 + dcb43e0 commit 24be422

File tree

4 files changed

+65
-79
lines changed

4 files changed

+65
-79
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: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ static int http_on_header_field(http_parser *parser, const char *at, size_t leng
256256
{
257257
esp_http_client_t *client = parser->data;
258258
http_on_header_event(client);
259-
ESP_RETURN_ON_FALSE_DEBUG(http_utils_append_string(&client->current_header_key, at, length), -1, TAG, "Failed to append string");
259+
HTTP_RET_ON_FALSE_DBG(http_utils_append_string(&client->current_header_key, at, length), -1, TAG, "Failed to append string");
260260

261261
return 0;
262262
}
@@ -268,14 +268,14 @@ static int http_on_header_value(http_parser *parser, const char *at, size_t leng
268268
return 0;
269269
}
270270
if (strcasecmp(client->current_header_key, "Location") == 0) {
271-
ESP_RETURN_ON_FALSE_DEBUG(http_utils_append_string(&client->location, at, length), -1, TAG, "Failed to append string");
271+
HTTP_RET_ON_FALSE_DBG(http_utils_append_string(&client->location, at, length), -1, TAG, "Failed to append string");
272272
} else if (strcasecmp(client->current_header_key, "Transfer-Encoding") == 0
273273
&& memcmp(at, "chunked", length) == 0) {
274274
client->response->is_chunked = true;
275275
} else if (strcasecmp(client->current_header_key, "WWW-Authenticate") == 0) {
276-
ESP_RETURN_ON_FALSE_DEBUG(http_utils_append_string(&client->auth_header, at, length), -1, TAG, "Failed to append string");
276+
HTTP_RET_ON_FALSE_DBG(http_utils_append_string(&client->auth_header, at, length), -1, TAG, "Failed to append string");
277277
}
278-
ESP_RETURN_ON_FALSE_DEBUG(http_utils_append_string(&client->current_header_value, at, length), -1, TAG, "Failed to append string");
278+
HTTP_RET_ON_FALSE_DBG(http_utils_append_string(&client->current_header_value, at, length), -1, TAG, "Failed to append string");
279279
return 0;
280280
}
281281

@@ -555,12 +555,12 @@ static esp_err_t _set_config(esp_http_client_handle_t client, const esp_http_cli
555555
}
556556

557557
if (config->transport_type == HTTP_TRANSPORT_OVER_SSL) {
558-
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");
558+
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");
559559
if (client->connection_info.port == 0) {
560560
client->connection_info.port = DEFAULT_HTTPS_PORT;
561561
}
562562
} else {
563-
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");
563+
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");
564564
if (client->connection_info.port == 0) {
565565
client->connection_info.port = DEFAULT_HTTP_PORT;
566566
}
@@ -640,11 +640,11 @@ static esp_err_t esp_http_client_prepare_digest_auth(esp_http_client_handle_t cl
640640
// Freeing the allocated memory for auth_data->uri and setting it to NULL to prevent potential memory leaks
641641
free(client->auth_data->uri);
642642
client->auth_data->uri = NULL;
643-
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");
643+
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");
644644

645645
if (client->connection_info.query) {
646-
ESP_GOTO_ON_FALSE_DEBUG(http_utils_append_string(&client->auth_data->uri, "?", -1), ESP_ERR_NO_MEM, error, TAG, "Failed to append string");
647-
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");
646+
HTTP_GOTO_ON_FALSE_DBG(http_utils_append_string(&client->auth_data->uri, "?", -1), ESP_ERR_NO_MEM, error, TAG, "Failed to append string");
647+
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");
648648
}
649649

650650
client->auth_data->cnonce = ((uint64_t)esp_random() << 32) + esp_random();
@@ -1121,7 +1121,7 @@ esp_err_t esp_http_client_set_url(esp_http_client_handle_t client, const char *u
11211121
old_port = client->connection_info.port;
11221122

11231123
if (purl.field_data[UF_HOST].len) {
1124-
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");
1124+
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");
11251125
}
11261126
// Close the connection if host was changed
11271127
if (old_host && client->connection_info.host
@@ -1142,7 +1142,7 @@ esp_err_t esp_http_client_set_url(esp_http_client_handle_t client, const char *u
11421142
}
11431143

11441144
if (purl.field_data[UF_SCHEMA].len) {
1145-
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");
1145+
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");
11461146

11471147
if (strcasecmp(client->connection_info.scheme, "http") == 0) {
11481148
client->connection_info.port = DEFAULT_HTTP_PORT;
@@ -1163,16 +1163,16 @@ esp_err_t esp_http_client_set_url(esp_http_client_handle_t client, const char *u
11631163

11641164
if (purl.field_data[UF_USERINFO].len) {
11651165
char *user_info = NULL;
1166-
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");
1166+
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");
11671167
if (user_info) {
11681168
char *username = user_info;
11691169
char *password = strchr(user_info, ':');
11701170
if (password) {
11711171
*password = 0;
11721172
password ++;
1173-
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");
1173+
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");
11741174
}
1175-
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");
1175+
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");
11761176
free(user_info);
11771177
} else {
11781178
return ESP_ERR_NO_MEM;
@@ -1181,13 +1181,13 @@ esp_err_t esp_http_client_set_url(esp_http_client_handle_t client, const char *u
11811181

11821182
//Reset path and query if there are no information
11831183
if (purl.field_data[UF_PATH].len) {
1184-
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");
1184+
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");
11851185
} else {
1186-
ESP_GOTO_ON_FALSE_DEBUG(http_utils_assign_string(&client->connection_info.path, "/", -1), ESP_ERR_NO_MEM, error, TAG, "failed to assign string");
1186+
HTTP_GOTO_ON_FALSE_DBG(http_utils_assign_string(&client->connection_info.path, "/", -1), ESP_ERR_NO_MEM, error, TAG, "failed to assign string");
11871187
}
11881188

11891189
if (purl.field_data[UF_QUERY].len) {
1190-
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");
1190+
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");
11911191
} else if (client->connection_info.query) {
11921192
free(client->connection_info.query);
11931193
client->connection_info.query = NULL;
@@ -1812,7 +1812,7 @@ esp_err_t esp_http_client_set_auth_data(esp_http_client_handle_t client, const c
18121812
if (client == NULL || auth_data == NULL || len <= 0) {
18131813
return ESP_ERR_INVALID_ARG;
18141814
}
1815-
ESP_RETURN_ON_FALSE_DEBUG(http_utils_append_string(&client->auth_header, auth_data, len), ESP_ERR_NO_MEM, TAG, "Failed to append string");
1815+
HTTP_RET_ON_FALSE_DBG(http_utils_append_string(&client->auth_header, auth_data, len), ESP_ERR_NO_MEM, TAG, "Failed to append string");
18161816
return ESP_OK;
18171817
}
18181818

@@ -1861,20 +1861,20 @@ esp_err_t esp_http_client_add_auth(esp_http_client_handle_t client)
18611861
client->auth_data->method = strdup(HTTP_METHOD_MAPPING[client->connection_info.method]);
18621862

18631863
client->auth_data->nc = 1;
1864-
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");
1865-
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");
1864+
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");
1865+
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");
18661866

18671867
if (client->auth_data->algorithm == NULL) {
1868-
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");
1868+
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");
18691869
}
18701870

18711871
if (client->auth_data->algorithm == NULL) {
18721872
client->auth_data->algorithm = strdup("MD5");
18731873
}
18741874

1875-
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");
1876-
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");
1877-
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");
1875+
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");
1876+
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");
1877+
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");
18781878
client->process_again = 1;
18791879

18801880
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;

components/esp_http_client/lib/include/http_utils.h

Lines changed: 38 additions & 1 deletion
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
*/
@@ -9,6 +9,43 @@
99
#define _HTTP_UTILS_H_
1010
#include <sys/time.h>
1111

12+
/**
13+
* Macro which can be used to check the error code. If the code is not ESP_OK, it prints the message and returns.
14+
* It logs the message in debug mode.
15+
*/
16+
#define HTTP_RET_ON_ERR_DBG(x, log_tag, format, ...) do { \
17+
esp_err_t err_rc_ = (x); \
18+
if (unlikely(err_rc_ != ESP_OK)) { \
19+
ESP_LOGD(log_tag, "%s(%d): " format, __FUNCTION__, __LINE__, ##__VA_ARGS__); \
20+
return err_rc_; \
21+
} \
22+
} while(0)
23+
24+
/**
25+
* Macro which can be used to check the condition. If the condition is not 'true', it prints the message
26+
* and returns with the supplied 'err_code'.
27+
* It logs the message in debug mode.
28+
*/
29+
#define HTTP_RET_ON_FALSE_DBG(a, err_code, log_tag, format, ...) do { \
30+
if (unlikely(!(a))) { \
31+
ESP_LOGD(log_tag, "%s(%d): " format, __FUNCTION__, __LINE__, ##__VA_ARGS__); \
32+
return err_code; \
33+
} \
34+
} while(0)
35+
36+
/**
37+
* Macro which can be used to check the condition. If the condition is not 'true', it prints the message,
38+
* sets the local variable 'ret' to the supplied 'err_code', and then exits by jumping to 'goto_tag'.
39+
* It logs the message in debug mode.
40+
*/
41+
#define HTTP_GOTO_ON_FALSE_DBG(a, err_code, goto_tag, log_tag, format, ...) do { \
42+
if (unlikely(!(a))) { \
43+
ESP_LOGD(log_tag, "%s(%d): " format, __FUNCTION__, __LINE__, ##__VA_ARGS__); \
44+
ret = err_code; \
45+
goto goto_tag; \
46+
} \
47+
} while (0)
48+
1249
/**
1350
* @brief Assign new_str to *str pointer, and realloc *str if it not NULL
1451
*

0 commit comments

Comments
 (0)