mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
esp_http_client: Update to support build for linux
This commit is contained in:
parent
43e4383bb7
commit
1c77e13d35
@ -1,3 +1,7 @@
|
||||
if(NOT ${IDF_TARGET} STREQUAL "linux")
|
||||
set(req lwip)
|
||||
endif()
|
||||
|
||||
idf_component_register(SRCS "esp_http_client.c"
|
||||
"lib/http_auth.c"
|
||||
"lib/http_header.c"
|
||||
@ -5,5 +9,5 @@ idf_component_register(SRCS "esp_http_client.c"
|
||||
INCLUDE_DIRS "include"
|
||||
PRIV_INCLUDE_DIRS "lib/include"
|
||||
# lwip is a public requirement because esp_http_client.h includes sys/socket.h
|
||||
REQUIRES lwip
|
||||
REQUIRES ${req}
|
||||
PRIV_REQUIRES tcp_transport http_parser)
|
||||
|
@ -8,7 +8,6 @@
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "esp_system.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_check.h"
|
||||
#include "http_parser.h"
|
||||
@ -20,6 +19,7 @@
|
||||
#include "sdkconfig.h"
|
||||
#include "esp_http_client.h"
|
||||
#include "errno.h"
|
||||
#include "esp_random.h"
|
||||
|
||||
#ifdef CONFIG_ESP_HTTP_CLIENT_ENABLE_HTTPS
|
||||
#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)
|
||||
{
|
||||
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;
|
||||
client->is_chunk_complete = true;
|
||||
return 0;
|
||||
|
@ -9,11 +9,10 @@
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "lwip/sockets.h"
|
||||
#include "sys/socket.h"
|
||||
#include "esp_rom_md5.h"
|
||||
#include "esp_tls_crypto.h"
|
||||
|
||||
#include "esp_system.h"
|
||||
#include "esp_log.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;
|
||||
}
|
||||
}
|
||||
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\"",
|
||||
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) {
|
||||
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);
|
||||
auth_str = temp_auth_str;
|
||||
}
|
||||
@ -134,18 +143,20 @@ _digest_exit:
|
||||
|
||||
char *http_auth_basic(const char *username, const char *password)
|
||||
{
|
||||
int out;
|
||||
size_t out;
|
||||
char *user_info = NULL;
|
||||
char *digest = NULL;
|
||||
esp_err_t ret = ESP_OK;
|
||||
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_crypto_base64_encode(NULL, 0, &n, (const unsigned char *)user_info, strlen(user_info));
|
||||
digest = calloc(1, 6 + n + 1);
|
||||
ESP_GOTO_ON_FALSE(digest, ESP_FAIL, _basic_exit, TAG, "Memory exhausted");
|
||||
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:
|
||||
free(user_info);
|
||||
return (ret == ESP_OK) ? digest : NULL;
|
||||
|
Loading…
x
Reference in New Issue
Block a user