new homepage and remove warnings
This commit is contained in:
@@ -17,7 +17,7 @@ $ cd build
|
|||||||
$ meson compile
|
$ meson compile
|
||||||
```
|
```
|
||||||
|
|
||||||
And then run `cws`!
|
And then run `server`!
|
||||||
|
|
||||||
## Docs
|
## Docs
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,8 @@
|
|||||||
|
|
||||||
#define WWW "../www" /**< Directory used to get html files */
|
#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 */
|
/** 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 HTTP_VERSION_LEN 8
|
||||||
#define USER_AGENT_LEN 1024
|
#define USER_AGENT_LEN 1024
|
||||||
#define HOST_LEN 1024
|
#define HOST_LEN 1024
|
||||||
@@ -19,13 +20,13 @@ enum http_method {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
typedef struct http {
|
typedef struct http {
|
||||||
int sockfd; /**< Socket file descriptor */
|
int sockfd; /**< Socket file descriptor */
|
||||||
enum http_method method; /**< HTTP request method */
|
enum http_method method; /**< HTTP request method */
|
||||||
char location[LOCATION_LEN]; /**< Resource requested */
|
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 http_version[HTTP_VERSION_LEN]; /**< HTTP version */
|
||||||
char user_agent[USER_AGENT_LEN]; /**< User-Agent */
|
char user_agent[USER_AGENT_LEN]; /**< User-Agent */
|
||||||
char host[HOST_LEN]; /**< Host */
|
char host[HOST_LEN]; /**< Host */
|
||||||
} http_t;
|
} http_t;
|
||||||
/* Connection */
|
/* Connection */
|
||||||
/* Accept-Encoding */
|
/* Accept-Encoding */
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
#ifndef CWS_MAIN_H
|
|
||||||
#define CWS_MAIN_H
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
project('cws', 'c', version : '1.0.0')
|
project('cws', 'c', version : '0.1.0')
|
||||||
|
|
||||||
subdir('src')
|
subdir('src')
|
||||||
|
|
||||||
incdir = include_directories('include')
|
incdir = include_directories('include')
|
||||||
|
|
||||||
executable('server', server, include_directories : incdir)
|
executable('server', server, include_directories : incdir)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "main.h"
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "client/client.h"
|
#include "client/client.h"
|
||||||
#include "utils/colors.h"
|
#include "utils/colors.h"
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ http_t *http_parse(char *request_str, int sockfd) {
|
|||||||
if (pch == NULL) {
|
if (pch == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
printf("[http] method: %s\n", pch);
|
printf("[client::http] method: %s\n", pch);
|
||||||
http_parse_method(request, pch);
|
http_parse_method(request, pch);
|
||||||
|
|
||||||
/* Parse location */
|
/* Parse location */
|
||||||
@@ -29,24 +29,24 @@ http_t *http_parse(char *request_str, int sockfd) {
|
|||||||
if (pch == NULL) {
|
if (pch == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
printf("[http] location: %s\n", pch);
|
printf("[client::http] location: %s\n", pch);
|
||||||
strncpy(request->location, pch, LOCATION_LEN);
|
strncpy(request->location, pch, LOCATION_LEN);
|
||||||
|
|
||||||
/* Parse location path */
|
/* Parse location path */
|
||||||
/* TODO: Prevent Path Traversal */
|
/* TODO: Prevent Path Traversal */
|
||||||
if (strcmp(request->location, "/") == 0) {
|
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 {
|
} 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 */
|
/* Parse HTTP version */
|
||||||
pch = strtok(NULL, " \r\n");
|
pch = strtok(NULL, " \r\n");
|
||||||
if (pch == NULL) {
|
if (pch == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
printf("[http] version: %s\n", pch);
|
printf("[client::http] version: %s\n", pch);
|
||||||
strncpy(request->http_version, pch, HTTP_VERSION_LEN);
|
strncpy(request->http_version, pch, HTTP_VERSION_LEN);
|
||||||
|
|
||||||
/* Parse other stuff... */
|
/* Parse other stuff... */
|
||||||
@@ -96,7 +96,7 @@ void http_send_response(http_t *request) {
|
|||||||
fread(file_data, 1, content_length, file);
|
fread(file_data, 1, content_length, file);
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
|
||||||
char response_header[1024];
|
char response_header[2048];
|
||||||
snprintf(response_header, sizeof response_header,
|
snprintf(response_header, sizeof response_header,
|
||||||
"%s 200 OK\r\n"
|
"%s 200 OK\r\n"
|
||||||
"Content-Type: %s\r\n"
|
"Content-Type: %s\r\n"
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
#include "main.h"
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "server/server.h"
|
#include "server/server.h"
|
||||||
#include "utils/colors.h"
|
#include "utils/colors.h"
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
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) {
|
if (ret < 0) {
|
||||||
fprintf(stderr, BOLD RED "Unable to start web server\n");
|
fprintf(stderr, BOLD RED "Unable to start web server\n");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,18 +2,20 @@
|
|||||||
<html lang="en">
|
<html lang="en">
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>CWS</title>
|
<title>CWS</title>
|
||||||
<link rel="stylesheet" href="style.css">
|
<link rel="stylesheet" href="style.css" />
|
||||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
||||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
<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"
|
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@400;600;800&display=swap" rel="stylesheet" />
|
||||||
rel="stylesheet">
|
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<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>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
@@ -1,11 +1,49 @@
|
|||||||
body {
|
body {
|
||||||
background-color: lightcoral;
|
margin: 0;
|
||||||
color: white;
|
height: 100vh;
|
||||||
font-family: "Montserrat", sans-serif;
|
font-family: "Montserrat", sans-serif;
|
||||||
|
background: linear-gradient(135deg, #ff6a6a, #ff9472);
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: 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;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user