Add SSI include file=, include virtual=

This commit is contained in:
cpq
2021-01-02 17:57:51 +00:00
parent 86824795a0
commit c7e09bd7b4
24 changed files with 289 additions and 29 deletions
+3 -2
View File
@@ -129,7 +129,8 @@ static void cb(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
u->token);
mg_http_printf_chunk(c, "");
} else {
mg_http_serve_dir(c, ev_data, "web_root");
struct mg_http_serve_opts opts = {.root_dir = "web_root"};
mg_http_serve_dir(c, ev_data, &opts);
}
}
}
@@ -146,7 +147,7 @@ static void broadcast_mjpeg_frame(struct mg_mgr *mgr) {
char *data = mg_file_read(path); // Read next file
struct mg_connection *c;
for (c = mgr->conns; c != NULL; c = c->next) {
if (c->label[0] != 'S') continue; // Skip non-stream connections
if (c->label[0] != 'S') continue; // Skip non-stream connections
if (data == NULL || size == 0) continue; // Skip on file read error
mg_printf(c,
"--foo\r\nContent-Type: image/jpeg\r\n"
+2 -1
View File
@@ -66,7 +66,8 @@ static void cb(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
c->label[0] = 'W'; // Mark ourselves as a config watcher
mg_printf(c, "HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n");
} else {
mg_http_serve_dir(c, ev_data, "web_root");
struct mg_http_serve_opts opts = {.root_dir = "web_root"};
mg_http_serve_dir(c, ev_data, &opts);
}
}
}
+1 -1
View File
@@ -1,6 +1,6 @@
PROG ?= example
ROOT ?= $(realpath $(CURDIR)/../..)
DEFS ?= -DMG_ENABLE_LINES=1 -DMG_ENABLE_DIRECTORY_LISTING=1
DEFS ?= -DMG_ENABLE_LINES=1 -DMG_ENABLE_DIRECTORY_LISTING=1 -DMG_ENABLE_SSI=1
CFLAGS ?= -I../.. -W -Wall -DMG_ENABLE_IPV6=1 $(DEFS) $(EXTRA)
VCFLAGS = /nologo /W3 /O2 /I../.. $(DEFS) $(EXTRA)
VC98 = docker run --rm -e WINEDEBUG=-all -v $(ROOT):$(ROOT) -w $(CURDIR) docker.io/mdashnet/vc98
+9 -4
View File
@@ -8,11 +8,13 @@ static const char *s_web_root_dir = ".";
static const char *s_listening_address = "http://localhost:8000";
static const char *s_enable_hexdump = "no";
static const char *s_rewrites = "";
static const char *s_ssi_pattern = "#.shtml";
static void cb(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
if (ev == MG_EV_HTTP_MSG) {
// struct mg_http_message *hm = (struct mg_http_message *) ev_data;
mg_http_serve_dir(c, ev_data, s_web_root_dir);
struct mg_http_serve_opts opts = {.root_dir = s_web_root_dir,
.ssi_pattern = s_ssi_pattern};
mg_http_serve_dir(c, ev_data, &opts);
}
(void) fn_data;
}
@@ -23,11 +25,12 @@ static void usage(const char *prog) {
"\nUsage: %s OPTIONS\n"
" -D LEVEL - debug level, from 0 to 4, default: '%s'\n"
" -H yes|no - enable traffic hexdump, default: '%s'\n"
" -S GLOB - glob pattern for SSI files, default: '%s'\n"
" -d DIR - directory to serve, default: '%s'\n"
" -l ADDR - listening address, default: '%s'\n"
" -r LIST - list of URI=DIR,... URI rewrites, default: '%s'\n",
MG_VERSION, prog, s_debug_level, s_enable_hexdump, s_web_root_dir,
s_listening_address, s_rewrites);
MG_VERSION, prog, s_debug_level, s_enable_hexdump, s_ssi_pattern,
s_web_root_dir, s_listening_address, s_rewrites);
exit(EXIT_FAILURE);
}
@@ -44,6 +47,8 @@ int main(int argc, char *argv[]) {
s_debug_level = argv[++i];
} else if (strcmp(argv[i], "-H") == 0) {
s_enable_hexdump = argv[++i];
} else if (strcmp(argv[i], "-S") == 0) {
s_ssi_pattern = argv[++i];
} else if (strcmp(argv[i], "-l") == 0) {
s_listening_address = argv[++i];
} else if (strcmp(argv[i], "-r") == 0) {
+2 -1
View File
@@ -12,7 +12,8 @@ static void cb(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
if (mg_http_match_uri(hm, "/upload")) {
mg_http_upload(c, hm, "/tmp");
} else {
mg_http_serve_dir(c, ev_data, "web_root");
struct mg_http_serve_opts opts = {.root_dir = "web_root"};
mg_http_serve_dir(c, ev_data, &opts);
}
}
}
+2 -1
View File
@@ -34,7 +34,8 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
mg_http_reply(c, 200, "", "{\"result\": \"%.*s\"}\n", (int) hm->uri.len,
hm->uri.ptr);
} else {
mg_http_serve_dir(c, ev_data, s_web_directory); // Serve static files
struct mg_http_serve_opts opts = {.root_dir = s_web_directory};
mg_http_serve_dir(c, ev_data, &opts);
}
}
(void) fn_data;
+2 -1
View File
@@ -16,7 +16,8 @@ static void cb(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
c->label[0] = 'L'; // Mark that connection as live log listener
mg_printf(c, "HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n");
} else {
mg_http_serve_dir(c, ev_data, "web_root");
struct mg_http_serve_opts opts = {.root_dir = "web_root"};
mg_http_serve_dir(c, ev_data, &opts);
}
}
}
+2 -1
View File
@@ -71,7 +71,8 @@ static void cb(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
u->token);
mg_http_printf_chunk(c, "");
} else {
mg_http_serve_dir(c, ev_data, "web_root");
struct mg_http_serve_opts opts = {.root_dir = "web_root"};
mg_http_serve_dir(c, ev_data, &opts);
}
}
}
+3 -2
View File
@@ -18,7 +18,8 @@ static void cb(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
"Pragma: no-cache\r\nExpires: Thu, 01 Dec 1994 16:00:00 GMT\r\n"
"Content-Type: multipart/x-mixed-replace; boundary=--foo\r\n\r\n");
} else {
mg_http_serve_dir(c, ev_data, "web_root");
struct mg_http_serve_opts opts = {.root_dir = "web_root"};
mg_http_serve_dir(c, ev_data, &opts);
}
}
}
@@ -35,7 +36,7 @@ static void broadcast_mjpeg_frame(struct mg_mgr *mgr) {
char *data = mg_file_read(path); // Read next file
struct mg_connection *c;
for (c = mgr->conns; c != NULL; c = c->next) {
if (c->label[0] != 'S') continue; // Skip non-stream connections
if (c->label[0] != 'S') continue; // Skip non-stream connections
if (data == NULL || size == 0) continue; // Skip on file read error
mg_printf(c,
"--foo\r\nContent-Type: image/jpeg\r\n"
+2 -1
View File
@@ -27,7 +27,8 @@ static void fn(struct mg_connection *c, int ev, void *ev_data, void *fn_data) {
mg_http_reply(c, 200, "", "{\"result\": %d}\n", 123);
} else {
// Serve static files
mg_http_serve_dir(c, ev_data, s_web_directory);
struct mg_http_serve_opts opts = {.root_dir = s_web_directory};
mg_http_serve_dir(c, ev_data, &opts);
}
} else if (ev == MG_EV_WS_MSG) {
// Got websocket frame. Received data is wm->data. Echo it back!