refactor: change project structure
This commit is contained in:
10
include/core/epoll_utils.h
Normal file
10
include/core/epoll_utils.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#ifndef CWS_EPOLL_UTILS_H
|
||||
#define CWS_EPOLL_UTILS_H
|
||||
|
||||
int cws_epoll_add(int epfd, int sockfd);
|
||||
|
||||
int cws_epoll_del(int epfd, int sockfd);
|
||||
|
||||
int cws_epoll_create_with_fd(int fd);
|
||||
|
||||
#endif
|
||||
@@ -6,8 +6,8 @@
|
||||
#include <signal.h>
|
||||
|
||||
#include "config/config.h"
|
||||
#include "utils/utils.h"
|
||||
#include "worker.h"
|
||||
#include "core/worker.h"
|
||||
#include "utils/net_utils.h"
|
||||
|
||||
/* Clients max queue */
|
||||
#define CWS_SERVER_BACKLOG 128
|
||||
@@ -5,8 +5,8 @@
|
||||
#include <pthread.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "../config/config.h"
|
||||
#include "../utils/utils.h"
|
||||
#include "config/config.h"
|
||||
#include "utils/net_utils.h"
|
||||
|
||||
extern volatile sig_atomic_t cws_server_run;
|
||||
|
||||
13
include/http/mime.h
Normal file
13
include/http/mime.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#ifndef CWS_MIME_H
|
||||
#define CWS_MIME_H
|
||||
|
||||
#define ARR_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
|
||||
|
||||
typedef struct mimetype {
|
||||
const char *ext;
|
||||
const char *type;
|
||||
} mimetype;
|
||||
|
||||
int http_get_content_type(char *location_path, char *content_type);
|
||||
|
||||
#endif
|
||||
@@ -5,11 +5,9 @@
|
||||
#include <myclib/mystring.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#define ARR_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
|
||||
|
||||
#define CWS_HTTP_CONTENT_TYPE 64
|
||||
#define CWS_HTTP_HEADER_MAX 512
|
||||
#define CWS_HTTP_HEADER_CONTENT_MAX 1024
|
||||
#define CWS_HTTP_CONTENT_TYPE 64
|
||||
|
||||
typedef enum cws_http_method {
|
||||
HTTP_GET,
|
||||
@@ -26,11 +24,6 @@ typedef enum cws_http_status {
|
||||
HTTP_NOT_IMPLEMENTED,
|
||||
} cws_http_status_e;
|
||||
|
||||
typedef struct mimetype {
|
||||
const char *ext;
|
||||
const char *type;
|
||||
} mimetype;
|
||||
|
||||
typedef struct cws_http {
|
||||
int sockfd;
|
||||
cws_http_method_e method;
|
||||
14
include/http/response.h
Normal file
14
include/http/response.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#ifndef CWS_RESPONSE_H
|
||||
#define CWS_RESPONSE_H
|
||||
|
||||
#include "http/request.h"
|
||||
#include <sys/types.h>
|
||||
|
||||
size_t http_simple_html(char **response, cws_http_status_e status, char *title, char *description);
|
||||
|
||||
size_t http_response_builder(char **response, cws_http_status_e status, char *content_type,
|
||||
char *body, size_t body_len_bytes);
|
||||
|
||||
void cws_http_send_response(cws_http_s *request, cws_http_status_e status);
|
||||
|
||||
#endif
|
||||
@@ -1,7 +0,0 @@
|
||||
#include "utils/utils.h"
|
||||
|
||||
cws_server_ret cws_epoll_add(int epfd, int sockfd);
|
||||
|
||||
cws_server_ret cws_epoll_del(int epfd, int sockfd);
|
||||
|
||||
int cws_epoll_create_with_fd(int fd);
|
||||
@@ -1,8 +1,6 @@
|
||||
#ifndef CWS_COLORS_H
|
||||
#define CWS_COLORS_H
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
/* ANSI color escape sequences */
|
||||
#define RED "\033[31m"
|
||||
#define GREEN "\033[32m"
|
||||
|
||||
16
include/utils/hash_utils.h
Normal file
16
include/utils/hash_utils.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#ifndef CWS_HASH_UTILS_H
|
||||
#define CWS_HASH_UTILS_H
|
||||
|
||||
unsigned int my_str_hash_fn(const void *key);
|
||||
|
||||
bool my_str_equal_fn(const void *a, const void *b);
|
||||
|
||||
void my_str_free_fn(void *value);
|
||||
|
||||
unsigned int my_int_hash_fn(const void *key);
|
||||
|
||||
bool my_int_equal_fn(const void *a, const void *b);
|
||||
|
||||
void my_int_free_key_fn(void *key);
|
||||
|
||||
#endif
|
||||
@@ -33,13 +33,4 @@ cws_server_ret cws_fd_set_nonblocking(int sockfd);
|
||||
|
||||
void cws_utils_get_client_ip(struct sockaddr_storage *sa, char *ip);
|
||||
|
||||
/* Functions used for hash maps */
|
||||
unsigned int my_str_hash_fn(const void *key);
|
||||
bool my_str_equal_fn(const void *a, const void *b);
|
||||
void my_str_free_fn(void *value);
|
||||
|
||||
unsigned int my_int_hash_fn(const void *key);
|
||||
bool my_int_equal_fn(const void *a, const void *b);
|
||||
void my_int_free_key_fn(void *key);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user