adjust naming convention and initial config support

This commit is contained in:
2025-04-24 17:24:13 +02:00
parent b4f71b0c53
commit dd9e2f557b
19 changed files with 217 additions and 263 deletions

View File

@@ -1,33 +1,35 @@
#ifndef CWS_HTTP_H
#define CWS_HTTP_H
#define WWW "../www" /**< Directory used to get html files */
#define CWS_WWW "../www" /**< Directory used to get html files */
/** In the future I'll move conf stuff under a server struct, I can skip just because I want something that works */
#define LOCATION_LEN 512
#define LOCATION_PATH_LEN 1024
#define HTTP_VERSION_LEN 8
#define USER_AGENT_LEN 1024
#define HOST_LEN 1024
#define CWS_HTTP_LOCATION_LEN 512
#define CWS_HTTP_LOCATION_PATH_LEN 1024
#define CWS_HTTP_VERSION_LEN 8
#define CWS_HTTP_USER_AGENT_LEN 1024
#define CWS_HTTP_HOST_LEN 1024
enum http_method {
GET, /**< GET method */
POST, /**< POST method */
};
typedef enum cws_http_method_t {
CWS_HTTP_GET, /**< GET method */
CWS_HTTP_POST, /**< POST method */
CWS_HTTP_PUT,
CWS_HTTP_DELETE,
} cws_http_method;
/* In the future I'll add HEAD, PUT, DELETE */
/**
* @brief HTTP request struct
*
*/
typedef struct http {
int sockfd; /**< Socket file descriptor */
enum http_method method; /**< HTTP request method */
char location[LOCATION_LEN]; /**< Resource requested */
char location_path[LOCATION_PATH_LEN]; /**< Resource path */
char http_version[HTTP_VERSION_LEN]; /**< HTTP version */
char user_agent[USER_AGENT_LEN]; /**< User-Agent */
char host[HOST_LEN]; /**< Host */
} http_t;
typedef struct cws_http_t {
int sockfd; /**< Socket file descriptor */
cws_http_method method; /**< HTTP request method */
char location[CWS_HTTP_LOCATION_LEN]; /**< Resource requested */
char location_path[CWS_HTTP_LOCATION_PATH_LEN]; /**< Full resource path */
char http_version[CWS_HTTP_VERSION_LEN]; /**< HTTP version */
char user_agent[CWS_HTTP_USER_AGENT_LEN]; /**< User-Agent */
char host[CWS_HTTP_HOST_LEN]; /**< Host */
} cws_http;
/* Connection */
/* Accept-Encoding */
/* Accept-Language */
@@ -35,18 +37,18 @@ typedef struct http {
/**
* @brief Parses a HTTP request
*
* @param request_str[in] The http request sent to the server
* @param[in] request_str The http request sent to the server
* @return Returns a http_t pointer to the request
*/
http_t *http_parse(char *request_str, int sockfd);
cws_http *cws_http_parse(char *request_str, int sockfd);
void http_parse_method(http_t *request, const char *method);
void http_get_content_type(http_t *request, char *content_type);
void cws_http_parse_method(cws_http *request, const char *method);
void cws_http_get_content_type(cws_http *request, char *content_type);
void http_send_response(http_t *request);
void http_send_not_found(http_t *request);
void http_send_not_implemented(http_t *request);
void cws_http_send_response(cws_http *request);
void cws_http_send_not_found(cws_http *request);
void cws_http_send_not_implemented(cws_http *request);
void http_free(http_t *request);
void cws_http_free(cws_http *request);
#endif