diff --git a/README.md b/README.md index 3b68d7a..75b677f 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ $ cd build $ meson compile ``` -And then run `cws`! +And then run `server`! ## Docs diff --git a/include/http/http.h b/include/http/http.h index 72b7e69..ef16279 100644 --- a/include/http/http.h +++ b/include/http/http.h @@ -3,7 +3,8 @@ #define 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 1024 +#define LOCATION_LEN 512 +#define LOCATION_PATH_LEN 1024 #define HTTP_VERSION_LEN 8 #define USER_AGENT_LEN 1024 #define HOST_LEN 1024 @@ -19,13 +20,13 @@ enum http_method { * */ 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_LEN]; /**< Resource path */ - char http_version[HTTP_VERSION_LEN]; /**< HTTP version */ - char user_agent[USER_AGENT_LEN]; /**< User-Agent */ - char host[HOST_LEN]; /**< Host */ + 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; /* Connection */ /* Accept-Encoding */ diff --git a/include/main.h b/include/main.h deleted file mode 100644 index a75e5dd..0000000 --- a/include/main.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef CWS_MAIN_H -#define CWS_MAIN_H - -#include - -#endif \ No newline at end of file diff --git a/meson.build b/meson.build index c3067b6..bc1e25c 100644 --- a/meson.build +++ b/meson.build @@ -1,6 +1,7 @@ -project('cws', 'c', version : '1.0.0') +project('cws', 'c', version : '0.1.0') subdir('src') + incdir = include_directories('include') executable('server', server, include_directories : incdir) diff --git a/src/client/main.c b/src/client/main.c index 7013401..7a8b81d 100644 --- a/src/client/main.c +++ b/src/client/main.c @@ -1,4 +1,4 @@ -#include "main.h" +#include #include "client/client.h" #include "utils/colors.h" diff --git a/src/http/http.c b/src/http/http.c index 18cb540..62b4831 100644 --- a/src/http/http.c +++ b/src/http/http.c @@ -21,7 +21,7 @@ http_t *http_parse(char *request_str, int sockfd) { if (pch == NULL) { return NULL; } - printf("[http] method: %s\n", pch); + printf("[client::http] method: %s\n", pch); http_parse_method(request, pch); /* Parse location */ @@ -29,24 +29,24 @@ http_t *http_parse(char *request_str, int sockfd) { if (pch == NULL) { return NULL; } - printf("[http] location: %s\n", pch); + printf("[client::http] location: %s\n", pch); strncpy(request->location, pch, LOCATION_LEN); /* Parse location path */ /* TODO: Prevent Path Traversal */ if (strcmp(request->location, "/") == 0) { - snprintf(request->location_path, LOCATION_LEN, "%s/index.html", WWW); + snprintf(request->location_path, LOCATION_PATH_LEN, "%s/index.html", WWW); } else { - snprintf(request->location_path, LOCATION_LEN, "%s%s", WWW, request->location); + snprintf(request->location_path, LOCATION_PATH_LEN, "%s%s", WWW, request->location); } - fprintf(stdout, "[http] location path: %s\n", request->location_path); + fprintf(stdout, "[client::http] location path: %s\n", request->location_path); /* Parse HTTP version */ pch = strtok(NULL, " \r\n"); if (pch == NULL) { return NULL; } - printf("[http] version: %s\n", pch); + printf("[client::http] version: %s\n", pch); strncpy(request->http_version, pch, HTTP_VERSION_LEN); /* Parse other stuff... */ @@ -96,7 +96,7 @@ void http_send_response(http_t *request) { fread(file_data, 1, content_length, file); fclose(file); - char response_header[1024]; + char response_header[2048]; snprintf(response_header, sizeof response_header, "%s 200 OK\r\n" "Content-Type: %s\r\n" diff --git a/src/main.c b/src/main.c index c501701..82ae4ca 100644 --- a/src/main.c +++ b/src/main.c @@ -1,12 +1,14 @@ -#include "main.h" +#include #include "server/server.h" #include "utils/colors.h" int main(int argc, char **argv) { - fprintf(stdout, BOLD GREEN "[server] Running cws on http://localhost:%s...\n" RESET, "3030"); + const char *default_port = "3030"; - int ret = start_server(NULL, "3030"); + fprintf(stdout, BOLD GREEN "[server] Running cws on http://localhost:%s...\n" RESET, default_port); + + int ret = start_server(NULL, default_port); if (ret < 0) { fprintf(stderr, BOLD RED "Unable to start web server\n"); } diff --git a/www/index.html b/www/index.html index cc281a9..4b77ebe 100644 --- a/www/index.html +++ b/www/index.html @@ -2,18 +2,20 @@ - - + + CWS - - - - + + + + -

Hello from CWS!

+
+

Hello from CWS!

+

Try to open an image here.

+
\ No newline at end of file diff --git a/www/style.css b/www/style.css index dcc84f2..ea8d8e3 100644 --- a/www/style.css +++ b/www/style.css @@ -1,11 +1,49 @@ body { - background-color: lightcoral; - color: white; + margin: 0; + height: 100vh; font-family: "Montserrat", sans-serif; - + background: linear-gradient(135deg, #ff6a6a, #ff9472); display: flex; justify-content: center; align-items: center; - height: 100vh; + color: white; +} + +h1 { + font-size: 3rem; + margin-bottom: 1rem; + font-weight: 800; +} + +.highlight { + color: #ffe678; +} + +p { + font-size: 1.2rem; + font-weight: 400; margin: 0; } + +a { + color: #ffffff; + font-weight: 600; + text-decoration: underline; + transition: color 0.3s; +} + +a:hover { + color: #ffe678; +} + +@keyframes fadeIn { + from { + opacity: 0; + transform: translateY(10px); + } + + to { + opacity: 1; + transform: translateY(0); + } +} \ No newline at end of file