fix http parser and config
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
#ifndef CWS_HTTP_H
|
||||
#define CWS_HTTP_H
|
||||
|
||||
#include "utils/config.h"
|
||||
#include "utils/hashmap.h"
|
||||
|
||||
#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 CWS_HTTP_LOCATION_LEN 512
|
||||
#define CWS_HTTP_LOCATION_PATH_LEN 1024
|
||||
#define CWS_HTTP_VERSION_LEN 8
|
||||
@@ -14,8 +13,8 @@ typedef enum cws_http_method_t {
|
||||
CWS_HTTP_POST, /**< POST method */
|
||||
CWS_HTTP_PUT,
|
||||
CWS_HTTP_DELETE,
|
||||
CWS_HTTP_HEAD,
|
||||
} cws_http_method;
|
||||
/* In the future I'll add HEAD, PUT, DELETE */
|
||||
|
||||
/**
|
||||
* @brief HTTP request struct
|
||||
@@ -39,7 +38,7 @@ 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(char *request_str, int sockfd);
|
||||
cws_http *cws_http_parse(char *request_str, int sockfd, cws_config *config);
|
||||
|
||||
void cws_http_parse_method(cws_http *request, const char *method);
|
||||
void cws_http_get_content_type(cws_http *request, char *content_type);
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <netdb.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include "utils/config.h"
|
||||
#include "utils/hashmap.h"
|
||||
|
||||
/* Clients max queue */
|
||||
@@ -21,11 +22,10 @@ extern volatile bool cws_server_run;
|
||||
/**
|
||||
* @brief Runs the server
|
||||
*
|
||||
* @param[in] hostname The hostname of the server (default localhost, it could be NULL)
|
||||
* @param[in] service The service (found in /etc/services) or the port where to run
|
||||
* @param[in] config The server's config
|
||||
* @return 0 on success, -1 on error
|
||||
*/
|
||||
int cws_server_start(const char *hostname, const char *service);
|
||||
int cws_server_start(cws_config *config);
|
||||
|
||||
/**
|
||||
* @brief Setups hints object
|
||||
@@ -41,7 +41,7 @@ void cws_server_setup_hints(struct addrinfo *hints, size_t len, const char *host
|
||||
*
|
||||
* @param[in,out] sockfd Socket of the commincation endpoint
|
||||
*/
|
||||
void cws_server_loop(int sockfd);
|
||||
void cws_server_loop(int sockfd, cws_config *config);
|
||||
|
||||
/**
|
||||
* @brief Adds a file descriptor to the interest list
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
#define CWS_CONFIG_H
|
||||
|
||||
typedef struct cws_config_t {
|
||||
char *host;
|
||||
char *hostname;
|
||||
char *port;
|
||||
|
||||
char *www;
|
||||
char *cert;
|
||||
char *key;
|
||||
} cws_config;
|
||||
|
||||
Reference in New Issue
Block a user