Base for sneedmc.org

This commit is contained in:
sneedium 2022-02-17 12:40:33 -05:00
parent 46c0be23e8
commit b64f37334d
8 changed files with 53 additions and 4 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*.o
sneedmc

5
css.h Normal file
View File

@ -0,0 +1,5 @@
static const char *BASIC_STYLE =
"<style>\r\n"
"body { background-color: white; color: black; }\r\n"
"</style>\r\n";

19
index.h Normal file
View File

@ -0,0 +1,19 @@
static const char *INDEX_HTML =
"<!DOCTYPE html>\r\n"
"<html>\r\n"
"<head>\r\n"
"<title>SneedMC</title>\r\n"
"%s"
"</head>\r\n"
"<body>\r\n"
"<h1>SneedMC</h1>\r\n"
"<p>WIP site for SneedMC, written in pure Mongoose.</p>\r\n"
"<p>Links:</p>\r\n"
"<li><a href='src'>Website Source</a></li>\r\n"
"<li><a href='gh'>SneedMC</a></li>\r\n"
"<li>asd</li>\r\n"
"<li></li>\r\n"
"<li></li>\r\n"
"</body>\r\n"
"</html>\r\n";

View File

@ -1 +0,0 @@
a:

30
main.c
View File

@ -1,6 +1,10 @@
#include "mongoose.h"
char *port = "6333";
#include "index.h"
#include "css.h"
// sneed in phone number, backwards
char *port = "33367";
void trim(char *str) {
char *_str = str;
@ -11,6 +15,17 @@ void trim(char *str) {
memmove(str, _str, len + 1);
}
bool eq(const char *src, const char *comp, size_t len) {
return (strncmp(src, comp, len) == 0);
}
void redir(struct mg_connection *nc, char *to) {
char *loc = malloc(strlen(to) + 14);
sprintf(loc, "Location: %s\r\n", to);
mg_http_reply(nc, 302, loc, to);
}
static void ev_handler(struct mg_connection *nc, int ev, void *p, void *f) {
if (ev == MG_EV_HTTP_MSG) {
struct mg_http_message *hm = (struct mg_http_message *) p;
@ -49,8 +64,17 @@ static void ev_handler(struct mg_connection *nc, int ev, void *p, void *f) {
if (strncmp(hm->method.ptr, "POST", hm->method.len) == 0) {
} else if (strncmp(hm->method.ptr, "GET", hm->method.len) == 0){
struct mg_http_serve_opts opts = {.root_dir = "."}; // Serve local dir
mg_http_serve_dir(nc, p, &opts);
if (eq(uri, "", 1) || eq(uri, "index.html", 11)) {
// allow for dynamic stuff in the future
mg_http_reply(nc, 200, "", INDEX_HTML, BASIC_STYLE);
} else if (eq(uri, "src", 4)) {
redir(nc, "https://github.com/Sneederix/sneedmc.org");
} else if (eq(uri, "gh", 3)) {
redir(nc, "https://github.com/Sneederix/SneedMC");
} else {
struct mg_http_serve_opts opts = {.root_dir = "."}; // Serve local dir
mg_http_serve_dir(nc, p, &opts);
}
} else {
mg_http_reply(nc, 405, "Allow: GET, POST\r\n", "");
}

BIN
main.o

Binary file not shown.

Binary file not shown.

BIN
sneedmc

Binary file not shown.