From 6737dc5458f885966f0767fb2909cf2ae9a07505 Mon Sep 17 00:00:00 2001 From: Laukik Hase Date: Mon, 4 Apr 2022 12:02:15 +0530 Subject: [PATCH] sh2lib: Update deprecated esp_tls API --- sh2lib/idf_component.yml | 2 +- sh2lib/sh2lib.c | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/sh2lib/idf_component.yml b/sh2lib/idf_component.yml index ff1e11c..d4bfb39 100644 --- a/sh2lib/idf_component.yml +++ b/sh2lib/idf_component.yml @@ -1,4 +1,4 @@ -version: "1.0.1" +version: "1.0.2" description: HTTP2 TLS Abstraction Layer url: https://github.com/espressif/idf-extra-components/tree/master/sh2lib dependencies: diff --git a/sh2lib/sh2lib.c b/sh2lib/sh2lib.c index 9d512b6..6d30282 100644 --- a/sh2lib/sh2lib.c +++ b/sh2lib/sh2lib.c @@ -246,10 +246,23 @@ int sh2lib_connect(struct sh2lib_config_t *cfg, struct sh2lib_handle *hd) .non_block = true, .timeout_ms = 10 * 1000, }; + +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0) + hd->http2_tls = esp_tls_init(); + if (!hd->http2_tls) { + ESP_LOGE(TAG, "Failed to allocate esp_tls handle!"); + goto error; + } + + // NOTE: This API is an alternative to previous `esp_tls_conn_http_new` from ESP-IDF v5.0 onwards. + if (esp_tls_conn_http_new_sync(cfg->uri, &tls_cfg, hd->http2_tls) != 1) { +#else if ((hd->http2_tls = esp_tls_conn_http_new(cfg->uri, &tls_cfg)) == NULL) { +#endif ESP_LOGE(TAG, "[sh2-connect] esp-tls connection failed"); goto error; } + struct http_parser_url u; http_parser_url_init(&u); http_parser_parse_url(cfg->uri, strlen(cfg->uri), 0, &u);