|
@@ -8,6 +8,7 @@
|
|
|
#include <freertos/task.h>
|
|
#include <freertos/task.h>
|
|
|
#include <esp_log.h>
|
|
#include <esp_log.h>
|
|
|
#include <esp_err.h>
|
|
#include <esp_err.h>
|
|
|
|
|
+#include <inttypes.h>
|
|
|
#include "esp_random.h"
|
|
#include "esp_random.h"
|
|
|
|
|
|
|
|
#include <esp_http_server.h>
|
|
#include <esp_http_server.h>
|
|
@@ -34,7 +35,7 @@ static void protocomm_httpd_session_close(void *ctx)
|
|
|
* request is for the same session.
|
|
* request is for the same session.
|
|
|
*/
|
|
*/
|
|
|
if (sock_session_id != PROTOCOMM_NO_SESSION_ID) {
|
|
if (sock_session_id != PROTOCOMM_NO_SESSION_ID) {
|
|
|
- ESP_LOGW(TAG, "Resetting socket session id as socket %d was closed", sock_session_id);
|
|
|
|
|
|
|
+ ESP_LOGW(TAG, "Resetting socket session id as socket %" PRId32 "was closed", sock_session_id);
|
|
|
sock_session_id = PROTOCOMM_NO_SESSION_ID;
|
|
sock_session_id = PROTOCOMM_NO_SESSION_ID;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -56,12 +57,12 @@ static esp_err_t common_post_handler(httpd_req_t *req)
|
|
|
if (httpd_req_get_hdr_value_str(req, "Cookie", cookie_buf, sizeof(cookie_buf)) == ESP_OK) {
|
|
if (httpd_req_get_hdr_value_str(req, "Cookie", cookie_buf, sizeof(cookie_buf)) == ESP_OK) {
|
|
|
ESP_LOGD(TAG, "Received cookie %s", cookie_buf);
|
|
ESP_LOGD(TAG, "Received cookie %s", cookie_buf);
|
|
|
char session_cookie[20] = {0};
|
|
char session_cookie[20] = {0};
|
|
|
- snprintf(session_cookie, sizeof(session_cookie), "session=%u", cookie_session_id);
|
|
|
|
|
|
|
+ snprintf(session_cookie, sizeof(session_cookie), "session=%" PRIu32, cookie_session_id);
|
|
|
/* If a cookie is found, check it against the session id. If it matches,
|
|
/* If a cookie is found, check it against the session id. If it matches,
|
|
|
* it means that this is a continuation of the same session.
|
|
* it means that this is a continuation of the same session.
|
|
|
*/
|
|
*/
|
|
|
if (strcmp(session_cookie, cookie_buf) == 0) {
|
|
if (strcmp(session_cookie, cookie_buf) == 0) {
|
|
|
- ESP_LOGD(TAG, "Continuing Session %u", cookie_session_id);
|
|
|
|
|
|
|
+ ESP_LOGD(TAG, "Continuing Session %" PRIu32, cookie_session_id);
|
|
|
/* If we reach here, it means that the client supports cookies and so the
|
|
/* If we reach here, it means that the client supports cookies and so the
|
|
|
* socket session id would no more be required for checking.
|
|
* socket session id would no more be required for checking.
|
|
|
*/
|
|
*/
|
|
@@ -70,7 +71,7 @@ static esp_err_t common_post_handler(httpd_req_t *req)
|
|
|
}
|
|
}
|
|
|
} else if (cur_sock_session_id == sock_session_id) {
|
|
} else if (cur_sock_session_id == sock_session_id) {
|
|
|
/* If the socket number matches, we assume it to be the same session */
|
|
/* If the socket number matches, we assume it to be the same session */
|
|
|
- ESP_LOGD(TAG, "Continuing Socket Session %u", sock_session_id);
|
|
|
|
|
|
|
+ ESP_LOGD(TAG, "Continuing Socket Session %" PRIu32, sock_session_id);
|
|
|
same_session = true;
|
|
same_session = true;
|
|
|
}
|
|
}
|
|
|
if (!same_session) {
|
|
if (!same_session) {
|
|
@@ -78,11 +79,11 @@ static esp_err_t common_post_handler(httpd_req_t *req)
|
|
|
* first close any existing sessions as applicable.
|
|
* first close any existing sessions as applicable.
|
|
|
*/
|
|
*/
|
|
|
if (cookie_session_id != PROTOCOMM_NO_SESSION_ID) {
|
|
if (cookie_session_id != PROTOCOMM_NO_SESSION_ID) {
|
|
|
- ESP_LOGW(TAG, "Closing session with ID: %u", cookie_session_id);
|
|
|
|
|
|
|
+ ESP_LOGW(TAG, "Closing session with ID: %" PRIu32, cookie_session_id);
|
|
|
if (pc_httpd->sec && pc_httpd->sec->close_transport_session) {
|
|
if (pc_httpd->sec && pc_httpd->sec->close_transport_session) {
|
|
|
ret = pc_httpd->sec->close_transport_session(pc_httpd->sec_inst, cookie_session_id);
|
|
ret = pc_httpd->sec->close_transport_session(pc_httpd->sec_inst, cookie_session_id);
|
|
|
if (ret != ESP_OK) {
|
|
if (ret != ESP_OK) {
|
|
|
- ESP_LOGW(TAG, "Error closing session with ID: %u", cookie_session_id);
|
|
|
|
|
|
|
+ ESP_LOGW(TAG, "Error closing session with ID: %" PRIu32, cookie_session_id);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
cookie_session_id = PROTOCOMM_NO_SESSION_ID;
|
|
cookie_session_id = PROTOCOMM_NO_SESSION_ID;
|
|
@@ -104,7 +105,7 @@ static esp_err_t common_post_handler(httpd_req_t *req)
|
|
|
}
|
|
}
|
|
|
cookie_session_id = cur_cookie_session_id;
|
|
cookie_session_id = cur_cookie_session_id;
|
|
|
sock_session_id = cur_sock_session_id;
|
|
sock_session_id = cur_sock_session_id;
|
|
|
- ESP_LOGD(TAG, "New socket session ID: %d", sock_session_id);
|
|
|
|
|
|
|
+ ESP_LOGD(TAG, "New socket session ID: %" PRId32, sock_session_id);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (req->content_len <= 0) {
|
|
if (req->content_len <= 0) {
|
|
@@ -147,7 +148,7 @@ static esp_err_t common_post_handler(httpd_req_t *req)
|
|
|
}
|
|
}
|
|
|
/* If this is a new session, send the session id in a cookie */
|
|
/* If this is a new session, send the session id in a cookie */
|
|
|
if (!same_session) {
|
|
if (!same_session) {
|
|
|
- snprintf(cookie_buf, sizeof(cookie_buf), "session=%u", cookie_session_id);
|
|
|
|
|
|
|
+ snprintf(cookie_buf, sizeof(cookie_buf), "session=%" PRIu32, cookie_session_id);
|
|
|
ESP_LOGD(TAG, "Setting cookie %s", cookie_buf);
|
|
ESP_LOGD(TAG, "Setting cookie %s", cookie_buf);
|
|
|
httpd_resp_set_hdr(req, "Set-Cookie", cookie_buf);
|
|
httpd_resp_set_hdr(req, "Set-Cookie", cookie_buf);
|
|
|
}
|
|
}
|