style: rename structs/enums
This commit is contained in:
@@ -10,32 +10,32 @@
|
||||
#define CWS_HTTP_HEADER_MAX 512
|
||||
#define CWS_HTTP_HEADER_CONTENT_MAX 1024
|
||||
|
||||
typedef enum cws_http_method_t {
|
||||
typedef enum cws_http_method {
|
||||
CWS_HTTP_GET,
|
||||
CWS_HTTP_POST,
|
||||
CWS_HTTP_PUT,
|
||||
CWS_HTTP_DELETE,
|
||||
CWS_HTTP_HEAD,
|
||||
} cws_http_method;
|
||||
} cws_http_method_e;
|
||||
|
||||
typedef enum cws_http_status_t {
|
||||
typedef enum cws_http_status {
|
||||
CWS_HTTP_OK,
|
||||
CWS_HTTP_NOT_FOUND,
|
||||
CWS_HTTP_NOT_IMPLEMENTED,
|
||||
} cws_http_status;
|
||||
} cws_http_status_e;
|
||||
|
||||
/**
|
||||
* @brief HTTP request struct
|
||||
*
|
||||
*/
|
||||
typedef struct cws_http_t {
|
||||
int sockfd; /**< Socket file descriptor */
|
||||
cws_http_method method; /**< HTTP request method */
|
||||
string_s *location; /**< Resource requested */
|
||||
string_s *location_path; /**< Full resource path */
|
||||
string_s *http_version; /**< HTTP version */
|
||||
hashmap_s *headers; /**< Headers hash map */
|
||||
} cws_http;
|
||||
typedef struct cws_http {
|
||||
int sockfd; /**< Socket file descriptor */
|
||||
cws_http_method_e method; /**< HTTP request method */
|
||||
string_s *location; /**< Resource requested */
|
||||
string_s *location_path; /**< Full resource path */
|
||||
string_s *http_version; /**< HTTP version */
|
||||
hashmap_s *headers; /**< Headers hash map */
|
||||
} cws_http_s;
|
||||
|
||||
/**
|
||||
* @brief Parses a HTTP request
|
||||
@@ -43,22 +43,22 @@ typedef struct cws_http_t {
|
||||
* @param[in] request_str The http request sent to the server
|
||||
* @return Returns a http_t pointer to the request
|
||||
*/
|
||||
cws_http *cws_http_parse(string_s *request_str, int sockfd, cws_config *config);
|
||||
cws_http_s *cws_http_parse(string_s *request_str, int sockfd, cws_config_s *config);
|
||||
|
||||
int cws_http_get_content_type(cws_http *request, char *content_type);
|
||||
int cws_http_get_content_type(cws_http_s *request, char *content_type);
|
||||
|
||||
/**
|
||||
* @brief Build the http response
|
||||
*
|
||||
* @return Returns the size of the response
|
||||
*/
|
||||
size_t cws_http_response_builder(char **response, char *http_version, cws_http_status status, char *content_type, char *connection, char *body,
|
||||
size_t cws_http_response_builder(char **response, char *http_version, cws_http_status_e status, char *content_type, char *connection, char *body,
|
||||
size_t body_len_bytes);
|
||||
|
||||
void cws_http_send_response(cws_http *request, cws_http_status status);
|
||||
int cws_http_send_resource(cws_http *request);
|
||||
void cws_http_send_simple_html(cws_http *request, cws_http_status status, char *title, char *description);
|
||||
void cws_http_send_response(cws_http_s *request, cws_http_status_e status);
|
||||
int cws_http_send_resource(cws_http_s *request);
|
||||
void cws_http_send_simple_html(cws_http_s *request, cws_http_status_e status, char *title, char *description);
|
||||
|
||||
void cws_http_free(cws_http *request);
|
||||
void cws_http_free(cws_http_s *request);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
/* Main server loop */
|
||||
extern volatile sig_atomic_t cws_server_run;
|
||||
|
||||
typedef enum cws_server_ret_t {
|
||||
typedef enum cws_server_ret {
|
||||
CWS_SERVER_OK,
|
||||
CWS_SERVER_CONFIG,
|
||||
CWS_SERVER_FD_ERROR,
|
||||
@@ -45,8 +45,8 @@ typedef enum cws_server_ret_t {
|
||||
CWS_SERVER_WORKER_ERROR,
|
||||
} cws_server_ret;
|
||||
|
||||
cws_server_ret cws_server_start(cws_config *config);
|
||||
cws_server_ret cws_server_loop(int server_fd, cws_config *config);
|
||||
cws_server_ret cws_server_start(cws_config_s *config);
|
||||
cws_server_ret cws_server_loop(int server_fd, cws_config_s *config);
|
||||
int cws_server_handle_new_client(int server_fd, hashmap_s *clients);
|
||||
int cws_server_accept_client(int server_fd, struct sockaddr_storage *their_sa, socklen_t *theirsa_size);
|
||||
cws_server_ret cws_fd_set_nonblocking(int sockfd);
|
||||
|
||||
@@ -6,22 +6,22 @@
|
||||
|
||||
#include "server/server.h"
|
||||
|
||||
typedef struct cws_worker_t {
|
||||
typedef struct cws_worker {
|
||||
int epfd;
|
||||
int pipefd[2];
|
||||
size_t clients_num;
|
||||
pthread_t thread;
|
||||
hashmap_s *clients;
|
||||
cws_config *config;
|
||||
} cws_worker;
|
||||
cws_config_s *config;
|
||||
} cws_worker_s;
|
||||
|
||||
cws_worker **cws_worker_init(size_t workers_num, hashmap_s *clients, cws_config *config);
|
||||
void cws_worker_free(cws_worker **workers, size_t workers_num);
|
||||
cws_worker_s **cws_worker_init(size_t workers_num, hashmap_s *clients, cws_config_s *config);
|
||||
void cws_worker_free(cws_worker_s **workers, size_t workers_num);
|
||||
void *cws_worker_loop(void *arg);
|
||||
|
||||
void cws_server_close_client(int epfd, int client_fd, hashmap_s *clients);
|
||||
cws_server_ret cws_epoll_add(int epfd, int sockfd, uint32_t events);
|
||||
cws_server_ret cws_epoll_del(int epfd, int sockfd);
|
||||
cws_server_ret cws_server_handle_client_data(int epfd, int client_fd, hashmap_s *clients, cws_config *config);
|
||||
cws_server_ret cws_server_handle_client_data(int epfd, int client_fd, hashmap_s *clients, cws_config_s *config);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -3,24 +3,22 @@
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
struct cws_virtual_host_t {
|
||||
typedef struct cws_vhost {
|
||||
char *domain;
|
||||
char *root;
|
||||
bool ssl;
|
||||
char *cert;
|
||||
char *key;
|
||||
};
|
||||
typedef struct cws_virtual_host_t cws_virtual_host;
|
||||
} cws_vhost_s;
|
||||
|
||||
struct cws_config_t {
|
||||
typedef struct cws_config {
|
||||
char *hostname;
|
||||
char *port;
|
||||
cws_virtual_host *virtual_hosts;
|
||||
cws_vhost_s *virtual_hosts;
|
||||
unsigned virtual_hosts_count;
|
||||
};
|
||||
typedef struct cws_config_t cws_config;
|
||||
} cws_config_s;
|
||||
|
||||
cws_config *cws_config_init(void);
|
||||
void cws_config_free(cws_config *config);
|
||||
cws_config_s *cws_config_init(void);
|
||||
void cws_config_free(cws_config_s *config);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user