mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-05 05:34:32 +02:00
esp_http_server: Run format.sh script to fix code style issues
This commit is contained in:
@@ -197,7 +197,7 @@ esp_err_t httpd_sess_new(struct httpd_data *hd, int newfd);
|
|||||||
* @brief Processes incoming HTTP requests
|
* @brief Processes incoming HTTP requests
|
||||||
*
|
*
|
||||||
* @param[in] hd Server instance data
|
* @param[in] hd Server instance data
|
||||||
* @param[in] session session
|
* @param[in] session Session
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
* - ESP_OK : on successfully receiving, parsing and responding to a request
|
* - ESP_OK : on successfully receiving, parsing and responding to a request
|
||||||
|
@@ -25,8 +25,8 @@
|
|||||||
#include "ctrl_sock.h"
|
#include "ctrl_sock.h"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
fd_set *fdset;
|
fd_set *fdset;
|
||||||
struct httpd_data *hd;
|
struct httpd_data *hd;
|
||||||
} process_session_context_t;
|
} process_session_context_t;
|
||||||
|
|
||||||
static const char *TAG = "httpd";
|
static const char *TAG = "httpd";
|
||||||
@@ -44,7 +44,7 @@ static esp_err_t httpd_accept_conn(struct httpd_data *hd, int listen_fd)
|
|||||||
* therefore httpd_accept_conn() will be called again, but this time
|
* therefore httpd_accept_conn() will be called again, but this time
|
||||||
* with space available for one session
|
* with space available for one session
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct sockaddr_in addr_from;
|
struct sockaddr_in addr_from;
|
||||||
@@ -60,12 +60,12 @@ static esp_err_t httpd_accept_conn(struct httpd_data *hd, int listen_fd)
|
|||||||
/* Set recv timeout of this fd as per config */
|
/* Set recv timeout of this fd as per config */
|
||||||
tv.tv_sec = hd->config.recv_wait_timeout;
|
tv.tv_sec = hd->config.recv_wait_timeout;
|
||||||
tv.tv_usec = 0;
|
tv.tv_usec = 0;
|
||||||
setsockopt(new_fd, SOL_SOCKET, SO_RCVTIMEO, (const char*)&tv, sizeof(tv));
|
setsockopt(new_fd, SOL_SOCKET, SO_RCVTIMEO, (const char *)&tv, sizeof(tv));
|
||||||
|
|
||||||
/* Set send timeout of this fd as per config */
|
/* Set send timeout of this fd as per config */
|
||||||
tv.tv_sec = hd->config.send_wait_timeout;
|
tv.tv_sec = hd->config.send_wait_timeout;
|
||||||
tv.tv_usec = 0;
|
tv.tv_usec = 0;
|
||||||
setsockopt(new_fd, SOL_SOCKET, SO_SNDTIMEO, (const char*)&tv, sizeof(tv));
|
setsockopt(new_fd, SOL_SOCKET, SO_SNDTIMEO, (const char *)&tv, sizeof(tv));
|
||||||
|
|
||||||
if (ESP_OK != httpd_sess_new(hd, new_fd)) {
|
if (ESP_OK != httpd_sess_new(hd, new_fd)) {
|
||||||
ESP_LOGW(TAG, LOG_FMT("session creation failed"));
|
ESP_LOGW(TAG, LOG_FMT("session creation failed"));
|
||||||
@@ -170,24 +170,24 @@ static void httpd_process_ctrl_msg(struct httpd_data *hd)
|
|||||||
// Called for each session from httpd_server
|
// Called for each session from httpd_server
|
||||||
static int httpd_process_session(struct sock_db *session, void *context)
|
static int httpd_process_session(struct sock_db *session, void *context)
|
||||||
{
|
{
|
||||||
if ((!session) || (!context)) {
|
if ((!session) || (!context)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (session->fd < 0) {
|
if (session->fd < 0) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
process_session_context_t * ctx=(process_session_context_t*)context;
|
process_session_context_t *ctx = (process_session_context_t *)context;
|
||||||
int fd=session->fd;
|
int fd = session->fd;
|
||||||
|
|
||||||
if (FD_ISSET(fd, ctx->fdset) || httpd_sess_pending(ctx->hd,session)) {
|
if (FD_ISSET(fd, ctx->fdset) || httpd_sess_pending(ctx->hd, session)) {
|
||||||
ESP_LOGD(TAG, LOG_FMT("processing socket %d"), fd);
|
ESP_LOGD(TAG, LOG_FMT("processing socket %d"), fd);
|
||||||
if (httpd_sess_process(ctx->hd, session) != ESP_OK) {
|
if (httpd_sess_process(ctx->hd, session) != ESP_OK) {
|
||||||
httpd_sess_delete(ctx->hd, session); // Delete session
|
httpd_sess_delete(ctx->hd, session); // Delete session
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Manage in-coming connection or data requests */
|
/* Manage in-coming connection or data requests */
|
||||||
@@ -417,8 +417,8 @@ esp_err_t httpd_start(httpd_handle_t *handle, const httpd_config_t *config)
|
|||||||
*/
|
*/
|
||||||
if (CONFIG_LWIP_MAX_SOCKETS < config->max_open_sockets + 3) {
|
if (CONFIG_LWIP_MAX_SOCKETS < config->max_open_sockets + 3) {
|
||||||
ESP_LOGE(TAG, "Configuration option max_open_sockets is too large (max allowed %d)\n\t"
|
ESP_LOGE(TAG, "Configuration option max_open_sockets is too large (max allowed %d)\n\t"
|
||||||
"Either decrease this or configure LWIP_MAX_SOCKETS to a larger value",
|
"Either decrease this or configure LWIP_MAX_SOCKETS to a larger value",
|
||||||
CONFIG_LWIP_MAX_SOCKETS - 3);
|
CONFIG_LWIP_MAX_SOCKETS - 3);
|
||||||
return ESP_ERR_INVALID_ARG;
|
return ESP_ERR_INVALID_ARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -76,59 +76,59 @@ static int enum_function(struct sock_db *session, void *context)
|
|||||||
enum_context_t *ctx = (enum_context_t *) context;
|
enum_context_t *ctx = (enum_context_t *) context;
|
||||||
int found = 0;
|
int found = 0;
|
||||||
switch (ctx->task) {
|
switch (ctx->task) {
|
||||||
// Initialize session
|
// Initialize session
|
||||||
case HTTPD_TASK_INIT:
|
case HTTPD_TASK_INIT:
|
||||||
session->fd = -1;
|
session->fd = -1;
|
||||||
session->ctx = NULL;
|
session->ctx = NULL;
|
||||||
break;
|
break;
|
||||||
// Get active session
|
// Get active session
|
||||||
case HTTPD_TASK_GET_ACTIVE:
|
case HTTPD_TASK_GET_ACTIVE:
|
||||||
found = (session->fd != -1);
|
found = (session->fd != -1);
|
||||||
break;
|
break;
|
||||||
// Get free slot
|
// Get free slot
|
||||||
case HTTPD_TASK_GET_FREE:
|
case HTTPD_TASK_GET_FREE:
|
||||||
found = (session->fd < 0);
|
found = (session->fd < 0);
|
||||||
break;
|
break;
|
||||||
// Find fd
|
// Find fd
|
||||||
case HTTPD_TASK_FIND_FD:
|
case HTTPD_TASK_FIND_FD:
|
||||||
found = (session->fd == ctx->fd);
|
found = (session->fd == ctx->fd);
|
||||||
break;
|
break;
|
||||||
// Set descriptor
|
// Set descriptor
|
||||||
case HTTPD_TASK_SET_DESCRIPTOR:
|
case HTTPD_TASK_SET_DESCRIPTOR:
|
||||||
if (session->fd != -1) {
|
if (session->fd != -1) {
|
||||||
FD_SET(session->fd, ctx->fdset);
|
FD_SET(session->fd, ctx->fdset);
|
||||||
if (session->fd > ctx->max_fd) {
|
if (session->fd > ctx->max_fd) {
|
||||||
ctx->max_fd = session->fd;
|
ctx->max_fd = session->fd;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
// Delete invalid session
|
break;
|
||||||
case HTTPD_TASK_DELETE_INVALID:
|
// Delete invalid session
|
||||||
if (!fd_is_valid(session->fd)) {
|
case HTTPD_TASK_DELETE_INVALID:
|
||||||
ESP_LOGW(TAG, LOG_FMT("Closing invalid socket %d"), session->fd);
|
if (!fd_is_valid(session->fd)) {
|
||||||
httpd_sess_delete(ctx->hd, session);
|
ESP_LOGW(TAG, LOG_FMT("Closing invalid socket %d"), session->fd);
|
||||||
}
|
httpd_sess_delete(ctx->hd, session);
|
||||||
break;
|
}
|
||||||
// Find lowest lru
|
break;
|
||||||
case HTTPD_TASK_FIND_LOWEST_LRU:
|
// Find lowest lru
|
||||||
// Found free slot - no need to check other sessions
|
case HTTPD_TASK_FIND_LOWEST_LRU:
|
||||||
if (session->fd == -1) {
|
// Found free slot - no need to check other sessions
|
||||||
return 0;
|
if (session->fd == -1) {
|
||||||
}
|
|
||||||
// Check/update lowest lru
|
|
||||||
if (session->lru_counter < ctx->lru_counter) {
|
|
||||||
ctx->lru_counter = session->lru_counter;
|
|
||||||
ctx->session = session;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case HTTPD_TASK_CLOSE:
|
|
||||||
if (session->fd!=-1) {
|
|
||||||
ESP_LOGD(TAG, LOG_FMT("cleaning up socket %d"), session->fd);
|
|
||||||
httpd_sess_delete(ctx->hd, session);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
// Check/update lowest lru
|
||||||
|
if (session->lru_counter < ctx->lru_counter) {
|
||||||
|
ctx->lru_counter = session->lru_counter;
|
||||||
|
ctx->session = session;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case HTTPD_TASK_CLOSE:
|
||||||
|
if (session->fd != -1) {
|
||||||
|
ESP_LOGD(TAG, LOG_FMT("cleaning up socket %d"), session->fd);
|
||||||
|
httpd_sess_delete(ctx->hd, session);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
if (found) {
|
if (found) {
|
||||||
ctx->session = session;
|
ctx->session = session;
|
||||||
@@ -155,9 +155,9 @@ static void httpd_sess_close(void *arg)
|
|||||||
|
|
||||||
struct sock_db *httpd_sess_get_free(struct httpd_data *hd)
|
struct sock_db *httpd_sess_get_free(struct httpd_data *hd)
|
||||||
{
|
{
|
||||||
if ((!hd) || (hd->hd_sd_active_count == hd->config.max_open_sockets)) {
|
if ((!hd) || (hd->hd_sd_active_count == hd->config.max_open_sockets)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
enum_context_t context = {
|
enum_context_t context = {
|
||||||
.task = HTTPD_TASK_GET_FREE
|
.task = HTTPD_TASK_GET_FREE
|
||||||
};
|
};
|
||||||
@@ -179,7 +179,7 @@ struct sock_db *httpd_sess_get(struct httpd_data *hd, int sockfd)
|
|||||||
// Check if called inside a request handler, and the session sockfd in use is same as the parameter
|
// Check if called inside a request handler, and the session sockfd in use is same as the parameter
|
||||||
// => Just return the pointer to the sock_db corresponding to the request
|
// => Just return the pointer to the sock_db corresponding to the request
|
||||||
if ((hd->hd_req_aux.sd) && (hd->hd_req_aux.sd->fd == sockfd)) {
|
if ((hd->hd_req_aux.sd) && (hd->hd_req_aux.sd->fd == sockfd)) {
|
||||||
return hd->hd_req_aux.sd;
|
return hd->hd_req_aux.sd;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum_context_t context = {
|
enum_context_t context = {
|
||||||
@@ -236,8 +236,7 @@ void httpd_sess_free_ctx(void **ctx, httpd_free_ctx_fn_t free_fn)
|
|||||||
}
|
}
|
||||||
if (free_fn) {
|
if (free_fn) {
|
||||||
free_fn(*ctx);
|
free_fn(*ctx);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
free(*ctx);
|
free(*ctx);
|
||||||
}
|
}
|
||||||
*ctx = NULL;
|
*ctx = NULL;
|
||||||
@@ -272,7 +271,7 @@ void *httpd_sess_get_ctx(httpd_handle_t handle, int sockfd)
|
|||||||
// Check if the function has been called from inside a
|
// Check if the function has been called from inside a
|
||||||
// request handler, in which case fetch the context from
|
// request handler, in which case fetch the context from
|
||||||
// the httpd_req_t structure
|
// the httpd_req_t structure
|
||||||
struct httpd_data * hd = (struct httpd_data *) handle;
|
struct httpd_data *hd = (struct httpd_data *) handle;
|
||||||
if (hd->hd_req_aux.sd == session) {
|
if (hd->hd_req_aux.sd == session) {
|
||||||
return hd->hd_req.sess_ctx;
|
return hd->hd_req.sess_ctx;
|
||||||
}
|
}
|
||||||
@@ -357,7 +356,7 @@ void httpd_sess_delete_invalid(struct httpd_data *hd)
|
|||||||
|
|
||||||
void httpd_sess_delete(struct httpd_data *hd, struct sock_db *session)
|
void httpd_sess_delete(struct httpd_data *hd, struct sock_db *session)
|
||||||
{
|
{
|
||||||
if ((!hd) || (!session) || (session->fd<0)) {
|
if ((!hd) || (!session) || (session->fd < 0)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -366,8 +365,7 @@ void httpd_sess_delete(struct httpd_data *hd, struct sock_db *session)
|
|||||||
// Call close function if defined
|
// Call close function if defined
|
||||||
if (hd->config.close_fn) {
|
if (hd->config.close_fn) {
|
||||||
hd->config.close_fn(hd, session->fd);
|
hd->config.close_fn(hd, session->fd);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
close(session->fd);
|
close(session->fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -477,18 +475,18 @@ esp_err_t httpd_sess_trigger_close_(httpd_handle_t handle, struct sock_db *sessi
|
|||||||
|
|
||||||
esp_err_t httpd_sess_trigger_close(httpd_handle_t handle, int sockfd)
|
esp_err_t httpd_sess_trigger_close(httpd_handle_t handle, int sockfd)
|
||||||
{
|
{
|
||||||
struct sock_db *session = httpd_sess_get(handle, sockfd);
|
struct sock_db *session = httpd_sess_get(handle, sockfd);
|
||||||
if (!session) {
|
if (!session) {
|
||||||
return ESP_ERR_NOT_FOUND;
|
return ESP_ERR_NOT_FOUND;
|
||||||
}
|
}
|
||||||
return httpd_sess_trigger_close_(handle,session);
|
return httpd_sess_trigger_close_(handle, session);
|
||||||
}
|
}
|
||||||
|
|
||||||
void httpd_sess_close_all(struct httpd_data *hd)
|
void httpd_sess_close_all(struct httpd_data *hd)
|
||||||
{
|
{
|
||||||
enum_context_t context = {
|
enum_context_t context = {
|
||||||
.task = HTTPD_TASK_CLOSE,
|
.task = HTTPD_TASK_CLOSE,
|
||||||
.hd = hd
|
.hd = hd
|
||||||
};
|
};
|
||||||
httpd_sess_enum(hd, enum_function, &context);
|
httpd_sess_enum(hd, enum_function, &context);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user