new homepage and remove warnings

This commit is contained in:
2025-04-22 18:59:49 +02:00
parent aebecfb4c2
commit b4f71b0c53
9 changed files with 77 additions and 39 deletions

View File

@@ -17,7 +17,7 @@ $ cd build
$ meson compile
```
And then run `cws`!
And then run `server`!
## Docs

View File

@@ -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
@@ -22,7 +23,7 @@ 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 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 */

View File

@@ -1,6 +0,0 @@
#ifndef CWS_MAIN_H
#define CWS_MAIN_H
#include <stdio.h>
#endif

View File

@@ -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)

View File

@@ -1,4 +1,4 @@
#include "main.h"
#include <stdio.h>
#include "client/client.h"
#include "utils/colors.h"

View File

@@ -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"

View File

@@ -1,12 +1,14 @@
#include "main.h"
#include <stdio.h>
#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");
}

View File

@@ -2,18 +2,20 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>CWS</title>
<link rel="stylesheet" href="style.css">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,100..900;1,100..900&display=swap"
rel="stylesheet">
<link rel="stylesheet" href="style.css" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@400;600;800&display=swap" rel="stylesheet" />
</head>
<body>
<h1 style="text-align: center">Hello from CWS!</h1>
<div>
<h1>Hello from <span class="highlight">CWS</span>!</h1>
<p>Try to open an image <a href="/cws.jpg" target="_blank">here</a>.</p>
</div>
</body>
</html>

View File

@@ -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);
}
}