mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-04 05:04:33 +02:00
Merge branch 'feature/support_ws_user_ctx' into 'master'
httpd: Support user_ctx in websocket handler callback request Closes IDFGH-4732 See merge request espressif/esp-idf!12635
This commit is contained in:
@@ -77,6 +77,7 @@ struct sock_db {
|
|||||||
bool ws_close; /*!< Set to true to close the socket later (when WS Close frame received) */
|
bool ws_close; /*!< Set to true to close the socket later (when WS Close frame received) */
|
||||||
esp_err_t (*ws_handler)(httpd_req_t *r); /*!< WebSocket handler, leave to null if it's not WebSocket */
|
esp_err_t (*ws_handler)(httpd_req_t *r); /*!< WebSocket handler, leave to null if it's not WebSocket */
|
||||||
bool ws_control_frames; /*!< WebSocket flag indicating that control frames should be passed to user handlers */
|
bool ws_control_frames; /*!< WebSocket flag indicating that control frames should be passed to user handlers */
|
||||||
|
void *ws_user_ctx; /*!< Pointer to user context data which will be available to handler for websocket*/
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -722,6 +722,7 @@ static void httpd_req_cleanup(httpd_req_t *r)
|
|||||||
ra->sd = NULL;
|
ra->sd = NULL;
|
||||||
r->handle = NULL;
|
r->handle = NULL;
|
||||||
r->aux = NULL;
|
r->aux = NULL;
|
||||||
|
r->user_ctx = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Function that processes incoming TCP data and
|
/* Function that processes incoming TCP data and
|
||||||
@@ -752,6 +753,8 @@ esp_err_t httpd_req_new(struct httpd_data *hd, struct sock_db *sd)
|
|||||||
esp_err_t ret;
|
esp_err_t ret;
|
||||||
|
|
||||||
#ifdef CONFIG_HTTPD_WS_SUPPORT
|
#ifdef CONFIG_HTTPD_WS_SUPPORT
|
||||||
|
/* Copy user_ctx to the request */
|
||||||
|
r->user_ctx = sd->ws_user_ctx;
|
||||||
/* Handle WebSocket */
|
/* Handle WebSocket */
|
||||||
ESP_LOGD(TAG, LOG_FMT("New request, has WS? %s, sd->ws_handler valid? %s, sd->ws_close? %s"),
|
ESP_LOGD(TAG, LOG_FMT("New request, has WS? %s, sd->ws_handler valid? %s, sd->ws_close? %s"),
|
||||||
sd->ws_handshake_done ? "Yes" : "No",
|
sd->ws_handshake_done ? "Yes" : "No",
|
||||||
|
@@ -329,6 +329,7 @@ esp_err_t httpd_uri(struct httpd_data *hd)
|
|||||||
aux->sd->ws_handshake_done = true;
|
aux->sd->ws_handshake_done = true;
|
||||||
aux->sd->ws_handler = uri->handler;
|
aux->sd->ws_handler = uri->handler;
|
||||||
aux->sd->ws_control_frames = uri->handle_ws_control_frames;
|
aux->sd->ws_control_frames = uri->handle_ws_control_frames;
|
||||||
|
aux->sd->ws_user_ctx = uri->user_ctx;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user