Skip to content

Commit bd920d2

Browse files
committed
Merge branch 'bugfix/softap_prov_session' into 'master'
protocomm_httpd: Restart security session if request is received on a new session See merge request espressif/esp-idf!8633
2 parents 5f2be35 + 05852bc commit bd920d2

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

components/protocomm/src/transports/protocomm_httpd.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,17 @@ static uint32_t session_id = PROTOCOMM_NO_SESSION_ID;
3131

3232
#define MAX_REQ_BODY_LEN 4096
3333

34+
static void protocomm_httpd_session_close(void *ctx)
35+
{
36+
if (pc_httpd->sec && pc_httpd->sec->close_transport_session) {
37+
ESP_LOGW(TAG, "Closing session as socket %d was closed", session_id);
38+
if (pc_httpd->sec->close_transport_session((protocomm_security_handle_t)ctx, session_id) != ESP_OK) {
39+
ESP_LOGW(TAG, "Error closing session with ID: %d", session_id);
40+
}
41+
}
42+
session_id = PROTOCOMM_NO_SESSION_ID;
43+
}
44+
3445
static esp_err_t common_post_handler(httpd_req_t *req)
3546
{
3647
esp_err_t ret;
@@ -42,6 +53,7 @@ static esp_err_t common_post_handler(httpd_req_t *req)
4253
int cur_session_id = httpd_req_to_sockfd(req);
4354

4455
if (cur_session_id != session_id) {
56+
ESP_LOGI(TAG, "Creating new session: %d", cur_session_id);
4557
/* Initialize new security session */
4658
if (session_id != PROTOCOMM_NO_SESSION_ID) {
4759
ESP_LOGD(TAG, "Closing session with ID: %d", session_id);
@@ -62,6 +74,9 @@ static esp_err_t common_post_handler(httpd_req_t *req)
6274
ret = ESP_FAIL;
6375
goto out;
6476
}
77+
req->sess_ctx = pc_httpd->sec_inst;
78+
req->free_ctx = protocomm_httpd_session_close;
79+
6580
}
6681
session_id = cur_session_id;
6782
ESP_LOGD(TAG, "New session with ID: %d", cur_session_id);

0 commit comments

Comments
 (0)