Base for sneedmc.org
This commit is contained in:
parent
46c0be23e8
commit
b64f37334d
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
*.o
|
||||
sneedmc
|
5
css.h
Normal file
5
css.h
Normal 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
19
index.h
Normal 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";
|
||||
|
@ -1 +0,0 @@
|
||||
a:
|
26
main.c
26
main.c
@ -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){
|
||||
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
mongoose.o
BIN
mongoose.o
Binary file not shown.
Loading…
Reference in New Issue
Block a user