mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-11 16:44:35 +02:00
esp_http_client: Update to support build for linux
This commit is contained in:
@@ -1,3 +1,7 @@
|
|||||||
|
if(NOT ${IDF_TARGET} STREQUAL "linux")
|
||||||
|
set(req lwip)
|
||||||
|
endif()
|
||||||
|
|
||||||
idf_component_register(SRCS "esp_http_client.c"
|
idf_component_register(SRCS "esp_http_client.c"
|
||||||
"lib/http_auth.c"
|
"lib/http_auth.c"
|
||||||
"lib/http_header.c"
|
"lib/http_header.c"
|
||||||
@@ -5,5 +9,5 @@ idf_component_register(SRCS "esp_http_client.c"
|
|||||||
INCLUDE_DIRS "include"
|
INCLUDE_DIRS "include"
|
||||||
PRIV_INCLUDE_DIRS "lib/include"
|
PRIV_INCLUDE_DIRS "lib/include"
|
||||||
# lwip is a public requirement because esp_http_client.h includes sys/socket.h
|
# lwip is a public requirement because esp_http_client.h includes sys/socket.h
|
||||||
REQUIRES lwip
|
REQUIRES ${req}
|
||||||
PRIV_REQUIRES tcp_transport http_parser)
|
PRIV_REQUIRES tcp_transport http_parser)
|
||||||
|
@@ -8,7 +8,6 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
|
||||||
#include "esp_system.h"
|
|
||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
#include "esp_check.h"
|
#include "esp_check.h"
|
||||||
#include "http_parser.h"
|
#include "http_parser.h"
|
||||||
@@ -20,6 +19,7 @@
|
|||||||
#include "sdkconfig.h"
|
#include "sdkconfig.h"
|
||||||
#include "esp_http_client.h"
|
#include "esp_http_client.h"
|
||||||
#include "errno.h"
|
#include "errno.h"
|
||||||
|
#include "esp_random.h"
|
||||||
|
|
||||||
#ifdef CONFIG_ESP_HTTP_CLIENT_ENABLE_HTTPS
|
#ifdef CONFIG_ESP_HTTP_CLIENT_ENABLE_HTTPS
|
||||||
#include "esp_transport_ssl.h"
|
#include "esp_transport_ssl.h"
|
||||||
@@ -298,7 +298,7 @@ static int http_on_body(http_parser *parser, const char *at, size_t length)
|
|||||||
|
|
||||||
static int http_on_message_complete(http_parser *parser)
|
static int http_on_message_complete(http_parser *parser)
|
||||||
{
|
{
|
||||||
ESP_LOGD(TAG, "http_on_message_complete, parser=%x", (int)parser);
|
ESP_LOGD(TAG, "http_on_message_complete, parser=%x", parser);
|
||||||
esp_http_client_handle_t client = parser->data;
|
esp_http_client_handle_t client = parser->data;
|
||||||
client->is_chunk_complete = true;
|
client->is_chunk_complete = true;
|
||||||
return 0;
|
return 0;
|
||||||
|
@@ -9,11 +9,10 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
#include "lwip/sockets.h"
|
#include "sys/socket.h"
|
||||||
#include "esp_rom_md5.h"
|
#include "esp_rom_md5.h"
|
||||||
#include "esp_tls_crypto.h"
|
#include "esp_tls_crypto.h"
|
||||||
|
|
||||||
#include "esp_system.h"
|
|
||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
#include "esp_check.h"
|
#include "esp_check.h"
|
||||||
|
|
||||||
@@ -117,11 +116,21 @@ char *http_auth_digest(const char *username, const char *password, esp_http_auth
|
|||||||
goto _digest_exit;
|
goto _digest_exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
asprintf(&auth_str, "Digest username=\"%s\", realm=\"%s\", nonce=\"%s\", uri=\"%s\", algorithm=\"MD5\", "
|
int rc = asprintf(&auth_str, "Digest username=\"%s\", realm=\"%s\", nonce=\"%s\", uri=\"%s\", algorithm=\"MD5\", "
|
||||||
"response=\"%s\", qop=%s, nc=%08x, cnonce=\"%016llx\"",
|
"response=\"%s\", qop=%s, nc=%08x, cnonce=\"%016llx\"",
|
||||||
username, auth_data->realm, auth_data->nonce, auth_data->uri, digest, auth_data->qop, auth_data->nc, auth_data->cnonce);
|
username, auth_data->realm, auth_data->nonce, auth_data->uri, digest, auth_data->qop, auth_data->nc, auth_data->cnonce);
|
||||||
|
if (rc < 0) {
|
||||||
|
ESP_LOGE(TAG, "asprintf() returned: %d", rc);
|
||||||
|
ret = ESP_FAIL;
|
||||||
|
goto _digest_exit;
|
||||||
|
}
|
||||||
if (auth_data->opaque) {
|
if (auth_data->opaque) {
|
||||||
asprintf(&temp_auth_str, "%s, opaque=\"%s\"", auth_str, auth_data->opaque);
|
rc = asprintf(&temp_auth_str, "%s, opaque=\"%s\"", auth_str, auth_data->opaque);
|
||||||
|
if (rc < 0) {
|
||||||
|
ESP_LOGE(TAG, "asprintf() returned: %d", rc);
|
||||||
|
ret = ESP_FAIL;
|
||||||
|
goto _digest_exit;
|
||||||
|
}
|
||||||
free(auth_str);
|
free(auth_str);
|
||||||
auth_str = temp_auth_str;
|
auth_str = temp_auth_str;
|
||||||
}
|
}
|
||||||
@@ -134,18 +143,20 @@ _digest_exit:
|
|||||||
|
|
||||||
char *http_auth_basic(const char *username, const char *password)
|
char *http_auth_basic(const char *username, const char *password)
|
||||||
{
|
{
|
||||||
int out;
|
size_t out;
|
||||||
char *user_info = NULL;
|
char *user_info = NULL;
|
||||||
char *digest = NULL;
|
char *digest = NULL;
|
||||||
esp_err_t ret = ESP_OK;
|
esp_err_t ret = ESP_OK;
|
||||||
size_t n = 0;
|
size_t n = 0;
|
||||||
asprintf(&user_info, "%s:%s", username, password);
|
if (asprintf(&user_info, "%s:%s", username, password) < 0) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
ESP_RETURN_ON_FALSE(user_info, NULL, TAG, "Memory exhausted");
|
ESP_RETURN_ON_FALSE(user_info, NULL, TAG, "Memory exhausted");
|
||||||
esp_crypto_base64_encode(NULL, 0, &n, (const unsigned char *)user_info, strlen(user_info));
|
esp_crypto_base64_encode(NULL, 0, &n, (const unsigned char *)user_info, strlen(user_info));
|
||||||
digest = calloc(1, 6 + n + 1);
|
digest = calloc(1, 6 + n + 1);
|
||||||
ESP_GOTO_ON_FALSE(digest, ESP_FAIL, _basic_exit, TAG, "Memory exhausted");
|
ESP_GOTO_ON_FALSE(digest, ESP_FAIL, _basic_exit, TAG, "Memory exhausted");
|
||||||
strcpy(digest, "Basic ");
|
strcpy(digest, "Basic ");
|
||||||
esp_crypto_base64_encode((unsigned char *)digest + 6, n, (size_t *)&out, (const unsigned char *)user_info, strlen(user_info));
|
esp_crypto_base64_encode((unsigned char *)digest + 6, n, &out, (const unsigned char *)user_info, strlen(user_info));
|
||||||
_basic_exit:
|
_basic_exit:
|
||||||
free(user_info);
|
free(user_info);
|
||||||
return (ret == ESP_OK) ? digest : NULL;
|
return (ret == ESP_OK) ? digest : NULL;
|
||||||
|
Reference in New Issue
Block a user