remove http_match_uri()

This commit is contained in:
Sergio R. Caprile 2024-04-17 16:13:10 -03:00
parent e6bf658271
commit ef61d6ea48
34 changed files with 83 additions and 93 deletions

View File

@ -32,7 +32,7 @@ static void simple_http_listener(struct mg_connection *c, int ev, void *ev_data)
struct mg_http_message *hm = (struct mg_http_message *) ev_data; struct mg_http_message *hm = (struct mg_http_message *) ev_data;
// If the requested URI is "/api/hi", send a simple JSON response back // If the requested URI is "/api/hi", send a simple JSON response back
if (mg_http_match_uri(hm, "/api/hi")) { if (mg_match(hm->uri, mg_str("/api/hi"), NULL)) {
// Use mg_http_reply() API function to generate JSON response. It adds a // Use mg_http_reply() API function to generate JSON response. It adds a
// Content-Length header automatically. In the response, we show // Content-Length header automatically. In the response, we show
// the requested URI and HTTP body: // the requested URI and HTTP body:

View File

@ -273,33 +273,33 @@ static void fn(struct mg_connection *c, int ev, void *ev_data) {
struct mg_http_message *hm = (struct mg_http_message *) ev_data; struct mg_http_message *hm = (struct mg_http_message *) ev_data;
struct user *u = authenticate(hm); struct user *u = authenticate(hm);
if (mg_http_match_uri(hm, "/api/#") && u == NULL) { if (mg_match(hm->uri, mg_str("/api/#"), NULL) && u == NULL) {
mg_http_reply(c, 403, "", "Not Authorised\n"); mg_http_reply(c, 403, "", "Not Authorised\n");
} else if (mg_http_match_uri(hm, "/api/login")) { } else if (mg_match(hm->uri, mg_str("/api/login"), NULL)) {
handle_login(c, u); handle_login(c, u);
} else if (mg_http_match_uri(hm, "/api/logout")) { } else if (mg_match(hm->uri, mg_str("/api/logout"), NULL)) {
handle_logout(c); handle_logout(c);
} else if (mg_http_match_uri(hm, "/api/debug")) { } else if (mg_match(hm->uri, mg_str("/api/debug"), NULL)) {
handle_debug(c, hm); handle_debug(c, hm);
} else if (mg_http_match_uri(hm, "/api/stats/get")) { } else if (mg_match(hm->uri, mg_str("/api/stats/get"), NULL)) {
handle_stats_get(c); handle_stats_get(c);
} else if (mg_http_match_uri(hm, "/api/events/get")) { } else if (mg_match(hm->uri, mg_str("/api/events/get"), NULL)) {
handle_events_get(c, hm); handle_events_get(c, hm);
} else if (mg_http_match_uri(hm, "/api/settings/get")) { } else if (mg_match(hm->uri, mg_str("/api/settings/get"), NULL)) {
handle_settings_get(c); handle_settings_get(c);
} else if (mg_http_match_uri(hm, "/api/settings/set")) { } else if (mg_match(hm->uri, mg_str("/api/settings/set"), NULL)) {
handle_settings_set(c, hm->body); handle_settings_set(c, hm->body);
} else if (mg_http_match_uri(hm, "/api/firmware/upload")) { } else if (mg_match(hm->uri, mg_str("/api/firmware/upload"), NULL)) {
handle_firmware_upload(c, hm); handle_firmware_upload(c, hm);
} else if (mg_http_match_uri(hm, "/api/firmware/commit")) { } else if (mg_match(hm->uri, mg_str("/api/firmware/commit"), NULL)) {
handle_firmware_commit(c); handle_firmware_commit(c);
} else if (mg_http_match_uri(hm, "/api/firmware/rollback")) { } else if (mg_match(hm->uri, mg_str("/api/firmware/rollback"), NULL)) {
handle_firmware_rollback(c); handle_firmware_rollback(c);
} else if (mg_http_match_uri(hm, "/api/firmware/status")) { } else if (mg_match(hm->uri, mg_str("/api/firmware/status"), NULL)) {
handle_firmware_status(c); handle_firmware_status(c);
} else if (mg_http_match_uri(hm, "/api/device/reset")) { } else if (mg_match(hm->uri, mg_str("/api/device/reset"), NULL)) {
handle_device_reset(c); handle_device_reset(c);
} else if (mg_http_match_uri(hm, "/api/device/eraselast")) { } else if (mg_match(hm->uri, mg_str("/api/device/eraselast"), NULL)) {
handle_device_eraselast(c); handle_device_eraselast(c);
} else { } else {
struct mg_http_serve_opts opts; struct mg_http_serve_opts opts;

View File

@ -40,7 +40,7 @@ static void handle_uploads(struct mg_connection *c, int ev, void *ev_data) {
// HTTP headers but not necessarily full HTTP body // HTTP headers but not necessarily full HTTP body
if (ev == MG_EV_HTTP_HDRS) { if (ev == MG_EV_HTTP_HDRS) {
struct mg_http_message *hm = (struct mg_http_message *) ev_data; struct mg_http_message *hm = (struct mg_http_message *) ev_data;
if (mg_http_match_uri(hm, "/upload/#")) { if (mg_match(hm->uri, mg_str("/upload/#"), NULL)) {
c->pfn = NULL; // Silence HTTP protocol handler, we'll take over c->pfn = NULL; // Silence HTTP protocol handler, we'll take over
if (!authuser(hm)) { if (!authuser(hm)) {
mg_http_reply(c, 403, "", "Denied\n"); mg_http_reply(c, 403, "", "Denied\n");

View File

@ -21,7 +21,7 @@ static void cb(struct mg_connection *c, int ev, void *ev_data) {
struct mg_http_message *hm = (struct mg_http_message *) ev_data; struct mg_http_message *hm = (struct mg_http_message *) ev_data;
MG_INFO(("New request to: [%.*s], body size: %lu", (int) hm->uri.len, MG_INFO(("New request to: [%.*s], body size: %lu", (int) hm->uri.len,
hm->uri.buf, (unsigned long) hm->body.len)); hm->uri.buf, (unsigned long) hm->body.len));
if (mg_http_match_uri(hm, "/upload")) { if (mg_match(hm->uri, mg_str("/upload"), NULL)) {
struct mg_http_part part; struct mg_http_part part;
size_t ofs = 0; size_t ofs = 0;
while ((ofs = mg_http_next_multipart(hm->body, ofs, &part)) > 0) { while ((ofs = mg_http_next_multipart(hm->body, ofs, &part)) > 0) {

View File

@ -9,7 +9,7 @@
static void cb(struct mg_connection *c, int ev, void *ev_data) { static void cb(struct mg_connection *c, int ev, void *ev_data) {
if (ev == MG_EV_HTTP_MSG) { if (ev == MG_EV_HTTP_MSG) {
struct mg_http_message *hm = (struct mg_http_message *) ev_data; struct mg_http_message *hm = (struct mg_http_message *) ev_data;
if (mg_http_match_uri(hm, "/upload")) { if (mg_match(hm->uri, mg_str("/upload"), NULL)) {
mg_http_upload(c, hm, &mg_fs_posix, "/tmp", 99999); mg_http_upload(c, hm, &mg_fs_posix, "/tmp", 99999);
} else { } else {
struct mg_http_serve_opts opts = {.root_dir = "web_root"}; struct mg_http_serve_opts opts = {.root_dir = "web_root"};

View File

@ -68,7 +68,7 @@ static void fn(struct mg_connection *c, int ev, void *ev_data) {
} }
if (ev == MG_EV_HTTP_MSG) { if (ev == MG_EV_HTTP_MSG) {
struct mg_http_message *hm = (struct mg_http_message *) ev_data; struct mg_http_message *hm = (struct mg_http_message *) ev_data;
if (mg_http_match_uri(hm, "/api/stats")) { if (mg_match(hm->uri, mg_str("/api/stats"), NULL)) {
// Print some statistics about currently established connections // Print some statistics about currently established connections
mg_printf(c, "HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"); mg_printf(c, "HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n");
mg_http_printf_chunk(c, "ID PROTO TYPE LOCAL REMOTE\n"); mg_http_printf_chunk(c, "ID PROTO TYPE LOCAL REMOTE\n");
@ -81,7 +81,7 @@ static void fn(struct mg_connection *c, int ev, void *ev_data) {
mg_print_ip, &t->loc, mg_print_ip, &t->rem); mg_print_ip, &t->loc, mg_print_ip, &t->rem);
} }
mg_http_printf_chunk(c, ""); // Don't forget the last empty chunk mg_http_printf_chunk(c, ""); // Don't forget the last empty chunk
} else if (mg_http_match_uri(hm, "/api/f2/*")) { } else if (mg_match(hm->uri, mg_str("/api/f2/*"), NULL)) {
mg_http_reply(c, 200, "", "{\"result\": \"%.*s\"}\n", (int) hm->uri.len, mg_http_reply(c, 200, "", "{\"result\": \"%.*s\"}\n", (int) hm->uri.len,
hm->uri.buf); hm->uri.buf);
} else { } else {

View File

@ -44,7 +44,7 @@ static size_t printdata(mg_pfn_t out, void *ptr, va_list *ap) {
static void fn(struct mg_connection *c, int ev, void *ev_data) { static void fn(struct mg_connection *c, int ev, void *ev_data) {
if (ev == MG_EV_HTTP_MSG) { if (ev == MG_EV_HTTP_MSG) {
struct mg_http_message *hm = ev_data; struct mg_http_message *hm = ev_data;
if (mg_http_match_uri(hm, "/api/data")) { if (mg_match(hm->uri, mg_str("/api/data"), NULL)) {
const char *headers = "content-type: text/json\r\n"; const char *headers = "content-type: text/json\r\n";
long start = getparam(hm, "$.start"); long start = getparam(hm, "$.start");
long version = getparam(hm, "$.version"); long version = getparam(hm, "$.version");

View File

@ -33,7 +33,7 @@ static void fn(struct mg_connection *c, int ev, void *ev_data) {
c->data[0] = 'W'; // Mark this connection as an established WS client c->data[0] = 'W'; // Mark this connection as an established WS client
} else if (ev == MG_EV_HTTP_MSG) { } else if (ev == MG_EV_HTTP_MSG) {
struct mg_http_message *hm = (struct mg_http_message *) ev_data; struct mg_http_message *hm = (struct mg_http_message *) ev_data;
if (mg_http_match_uri(hm, "/websocket")) { if (mg_match(hm->uri, mg_str("/websocket"), NULL)) {
// Upgrade to websocket. From now on, a connection is a full-duplex // Upgrade to websocket. From now on, a connection is a full-duplex
// Websocket connection, which will receive MG_EV_WS_MSG events. // Websocket connection, which will receive MG_EV_WS_MSG events.
mg_ws_upgrade(c, hm, NULL); mg_ws_upgrade(c, hm, NULL);

View File

@ -10,10 +10,10 @@
static void cb(struct mg_connection *c, int ev, void *ev_data) { static void cb(struct mg_connection *c, int ev, void *ev_data) {
if (ev == MG_EV_HTTP_MSG) { if (ev == MG_EV_HTTP_MSG) {
struct mg_http_message *hm = (struct mg_http_message *) ev_data; struct mg_http_message *hm = (struct mg_http_message *) ev_data;
if (mg_http_match_uri(hm, "/api/log/static")) { if (mg_match(hm->uri, mg_str("/api/log/static"), NULL)) {
struct mg_http_serve_opts opts = {.root_dir = NULL}; struct mg_http_serve_opts opts = {.root_dir = NULL};
mg_http_serve_file(c, hm, "log.txt", &opts); mg_http_serve_file(c, hm, "log.txt", &opts);
} else if (mg_http_match_uri(hm, "/api/log/live")) { } else if (mg_match(hm->uri, mg_str("/api/log/live"), NULL)) {
c->data[0] = 'L'; // Mark that connection as live log listener c->data[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"); mg_printf(c, "HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n");
} else { } else {

View File

@ -58,11 +58,11 @@ static void fn2(struct mg_connection *c, int ev, void *ev_data) {
static void fn(struct mg_connection *c, int ev, void *ev_data) { static void fn(struct mg_connection *c, int ev, void *ev_data) {
if (ev == MG_EV_HTTP_MSG) { if (ev == MG_EV_HTTP_MSG) {
struct mg_http_message *hm = (struct mg_http_message *) ev_data; struct mg_http_message *hm = (struct mg_http_message *) ev_data;
if (mg_http_match_uri(hm, "/api/debug")) { if (mg_match(hm->uri, mg_str("/api/debug"), NULL)) {
int level = mg_json_get_long(hm->body, "$.level", MG_LL_DEBUG); int level = mg_json_get_long(hm->body, "$.level", MG_LL_DEBUG);
mg_log_set(level); mg_log_set(level);
mg_http_reply(c, 200, "", "Debug level set to %d\n", level); mg_http_reply(c, 200, "", "Debug level set to %d\n", level);
} else if (mg_http_match_uri(hm, "/api/url")) { } else if (mg_match(hm->uri, mg_str("/api/url"), NULL)) {
char *url = mg_json_get_str(hm->body, "$.url"); char *url = mg_json_get_str(hm->body, "$.url");
if (url == NULL) { if (url == NULL) {
mg_http_reply(c, 200, NULL, "no url, rl %d\r\n", (int) c->recv.len); mg_http_reply(c, 200, NULL, "no url, rl %d\r\n", (int) c->recv.len);

View File

@ -253,15 +253,15 @@ static void fn(struct mg_connection *c, int ev, void *ev_data) {
} else if (ev == MG_EV_HTTP_MSG) { } else if (ev == MG_EV_HTTP_MSG) {
struct mg_http_message *hm = (struct mg_http_message *) ev_data; struct mg_http_message *hm = (struct mg_http_message *) ev_data;
if (mg_http_match_uri(hm, "/api/settings/get")) { if (mg_match(hm->uri, mg_str("/api/settings/get"), NULL)) {
handle_settings_get(c); handle_settings_get(c);
} else if (mg_http_match_uri(hm, "/api/settings/set")) { } else if (mg_match(hm->uri, mg_str("/api/settings/set"), NULL)) {
handle_settings_set(c, hm->body); handle_settings_set(c, hm->body);
} else if (mg_http_match_uri(hm, "/api/settings/set")) { } else if (mg_match(hm->uri, mg_str("/api/settings/set"), NULL)) {
handle_settings_set(c, hm->body); handle_settings_set(c, hm->body);
} else if (mg_http_match_uri(hm, "/api/modbus/exec")) { } else if (mg_match(hm->uri, mg_str("/api/modbus/exec"), NULL)) {
handle_modbus_exec(c, hm->body); handle_modbus_exec(c, hm->body);
} else if (mg_http_match_uri(hm, "/api/device/reset")) { } else if (mg_match(hm->uri, mg_str("/api/device/reset"), NULL)) {
mg_timer_add(c->mgr, 500, 0, (void (*)(void *)) mg_device_reset, NULL); mg_timer_add(c->mgr, 500, 0, (void (*)(void *)) mg_device_reset, NULL);
mg_http_reply(c, 200, s_json_header, "true\n"); mg_http_reply(c, 200, s_json_header, "true\n");
} else { } else {

View File

@ -52,7 +52,7 @@ static void fn(struct mg_connection *c, int ev, void *ev_data) {
start_thread(thread_function, data); // Start thread and pass data start_thread(thread_function, data); // Start thread and pass data
} else if (ev == MG_EV_HTTP_MSG) { } else if (ev == MG_EV_HTTP_MSG) {
struct mg_http_message *hm = (struct mg_http_message *) ev_data; struct mg_http_message *hm = (struct mg_http_message *) ev_data;
if (mg_http_match_uri(hm, "/websocket")) { if (mg_match(hm->uri, mg_str("/websocket"), NULL)) {
mg_ws_upgrade(c, hm, NULL); // Upgrade HTTP to Websocket mg_ws_upgrade(c, hm, NULL); // Upgrade HTTP to Websocket
c->data[0] = 'W'; // Set some unique mark on a connection c->data[0] = 'W'; // Set some unique mark on a connection
} else { } else {

View File

@ -42,7 +42,7 @@ static void *thread_function(void *param) {
static void fn(struct mg_connection *c, int ev, void *ev_data) { static void fn(struct mg_connection *c, int ev, void *ev_data) {
if (ev == MG_EV_HTTP_MSG) { if (ev == MG_EV_HTTP_MSG) {
struct mg_http_message *hm = (struct mg_http_message *) ev_data; struct mg_http_message *hm = (struct mg_http_message *) ev_data;
if (mg_http_match_uri(hm, "/fast")) { if (mg_match(hm->uri, mg_str("/fast"), NULL)) {
// Single-threaded code path, for performance comparison // Single-threaded code path, for performance comparison
// The /fast URI responds immediately // The /fast URI responds immediately
mg_http_reply(c, 200, "Host: foo.com\r\n", "hi\n"); mg_http_reply(c, 200, "Host: foo.com\r\n", "hi\n");

View File

@ -66,7 +66,7 @@ static bool usb_up(struct mg_tcpip_if *ifp) {
static void fn(struct mg_connection *c, int ev, void *ev_data) { static void fn(struct mg_connection *c, int ev, void *ev_data) {
if (ev == MG_EV_HTTP_MSG) { if (ev == MG_EV_HTTP_MSG) {
struct mg_http_message *hm = (struct mg_http_message *) ev_data; struct mg_http_message *hm = (struct mg_http_message *) ev_data;
if (mg_http_match_uri(hm, "/api/debug")) { if (mg_match(hm->uri, mg_str("/api/debug"), NULL)) {
int level = mg_json_get_long(hm->body, "$.level", MG_LL_DEBUG); int level = mg_json_get_long(hm->body, "$.level", MG_LL_DEBUG);
mg_log_set(level); mg_log_set(level);
mg_http_reply(c, 200, "", "Debug level set to %d\n", level); mg_http_reply(c, 200, "", "Debug level set to %d\n", level);

View File

@ -66,7 +66,7 @@ static bool usb_up(struct mg_tcpip_if *ifp) {
static void fn(struct mg_connection *c, int ev, void *ev_data) { static void fn(struct mg_connection *c, int ev, void *ev_data) {
if (ev == MG_EV_HTTP_MSG) { if (ev == MG_EV_HTTP_MSG) {
struct mg_http_message *hm = (struct mg_http_message *) ev_data; struct mg_http_message *hm = (struct mg_http_message *) ev_data;
if (mg_http_match_uri(hm, "/api/debug")) { if (mg_match(hm->uri, mg_str("/api/debug"), NULL)) {
int level = mg_json_get_long(hm->body, "$.level", MG_LL_DEBUG); int level = mg_json_get_long(hm->body, "$.level", MG_LL_DEBUG);
mg_log_set(level); mg_log_set(level);
mg_http_reply(c, 200, "", "Debug level set to %d\n", level); mg_http_reply(c, 200, "", "Debug level set to %d\n", level);

View File

@ -46,13 +46,13 @@ static void fn(struct mg_connection *c, int ev, void *ev_data) {
struct mg_tcpip_if *ifp = (struct mg_tcpip_if *) c->fn_data; struct mg_tcpip_if *ifp = (struct mg_tcpip_if *) c->fn_data;
if (ev == MG_EV_HTTP_MSG) { if (ev == MG_EV_HTTP_MSG) {
struct mg_http_message *hm = (struct mg_http_message *) ev_data; struct mg_http_message *hm = (struct mg_http_message *) ev_data;
if (mg_http_match_uri(hm, "/api/hello")) { // Request to /api/hello if (mg_match(hm->uri, mg_str("/api/hello"), NULL)) { // Request to /api/hello
mg_http_reply(c, 200, "", "{%m:%u,%m:%u,%m:%u,%m:%u,%m:%u}\n", mg_http_reply(c, 200, "", "{%m:%u,%m:%u,%m:%u,%m:%u,%m:%u}\n",
MG_ESC("eth"), ifp->state, MG_ESC("frames_received"), MG_ESC("eth"), ifp->state, MG_ESC("frames_received"),
ifp->nrecv, MG_ESC("frames_sent"), ifp->nsent, ifp->nrecv, MG_ESC("frames_sent"), ifp->nsent,
MG_ESC("frames_dropped"), ifp->ndrop, MG_ESC("frames_dropped"), ifp->ndrop,
MG_ESC("interface_errors"), ifp->nerr); MG_ESC("interface_errors"), ifp->nerr);
} else if (mg_http_match_uri(hm, "/")) { // Index page } else if (mg_match(hm->uri, mg_str("/"), NULL)) { // Index page
mg_http_reply( mg_http_reply(
c, 200, "", "%s", c, 200, "", "%s",
"<html><head><link rel='icon' href='data:;base64,='></head><body>" "<html><head><link rel='icon' href='data:;base64,='></head><body>"

View File

@ -64,7 +64,7 @@ static bool usb_up(struct mg_tcpip_if *ifp) {
static void fn(struct mg_connection *c, int ev, void *ev_data) { static void fn(struct mg_connection *c, int ev, void *ev_data) {
if (ev == MG_EV_HTTP_MSG) { if (ev == MG_EV_HTTP_MSG) {
struct mg_http_message *hm = (struct mg_http_message *) ev_data; struct mg_http_message *hm = (struct mg_http_message *) ev_data;
if (mg_http_match_uri(hm, "/api/debug")) { if (mg_match(hm->uri, mg_str("/api/debug"), NULL)) {
int level = mg_json_get_long(hm->body, "$.level", MG_LL_DEBUG); int level = mg_json_get_long(hm->body, "$.level", MG_LL_DEBUG);
mg_log_set(level); mg_log_set(level);
mg_http_reply(c, 200, "", "Debug level set to %d\n", level); mg_http_reply(c, 200, "", "Debug level set to %d\n", level);

View File

@ -14,7 +14,7 @@ static const char *s_web_root = "web_root";
static void fn(struct mg_connection *c, int ev, void *ev_data) { static void fn(struct mg_connection *c, int ev, void *ev_data) {
if (ev == MG_EV_HTTP_MSG) { if (ev == MG_EV_HTTP_MSG) {
struct mg_http_message *hm = (struct mg_http_message *) ev_data; struct mg_http_message *hm = (struct mg_http_message *) ev_data;
if (mg_http_match_uri(hm, "/websocket")) { if (mg_match(hm->uri, mg_str("/websocket"), NULL)) {
mg_ws_upgrade(c, hm, NULL); // Upgrade HTTP to Websocket mg_ws_upgrade(c, hm, NULL); // Upgrade HTTP to Websocket
c->data[0] = 'W'; // Set some unique mark on a connection c->data[0] = 'W'; // Set some unique mark on a connection
} else { } else {

View File

@ -198,13 +198,13 @@ void uart_bridge_fn(struct mg_connection *c, int ev, void *ev_data) {
// mg_log_set(MG_LL_DEBUG); // Set log level // mg_log_set(MG_LL_DEBUG); // Set log level
} else if (ev == MG_EV_HTTP_MSG) { } else if (ev == MG_EV_HTTP_MSG) {
struct mg_http_message *hm = (struct mg_http_message *) ev_data; struct mg_http_message *hm = (struct mg_http_message *) ev_data;
if (mg_http_match_uri(hm, "/api/hi")) { if (mg_match(hm->uri, mg_str("/api/hi"), NULL)) {
mg_http_reply(c, 200, "", "hi\n"); // Testing endpoint mg_http_reply(c, 200, "", "hi\n"); // Testing endpoint
} else if (mg_http_match_uri(hm, "/api/config/set")) { } else if (mg_match(hm->uri, mg_str("/api/config/set"), NULL)) {
config_apply(hm->body); config_apply(hm->body);
config_write(hm->body); config_write(hm->body);
mg_http_reply(c, 200, "", "true\n"); mg_http_reply(c, 200, "", "true\n");
} else if (mg_http_match_uri(hm, "/api/config/get")) { } else if (mg_match(hm->uri, mg_str("/api/config/get"), NULL)) {
mg_http_reply(c, 200, "Content-Type: application/json\r\n", mg_http_reply(c, 200, "Content-Type: application/json\r\n",
"{%m:{%m:%m,%m:%s},%m:{%m:%m,%m:%s},%m:{%m:%m,%m:%s}," "{%m:{%m:%m,%m:%s},%m:{%m:%m,%m:%s},%m:{%m:%m,%m:%s},"
"%m:%d,%m:%d,%m:%d}\n", "%m:%d,%m:%d,%m:%d}\n",

View File

@ -9,7 +9,7 @@
static void cb(struct mg_connection *c, int ev, void *ev_data) { static void cb(struct mg_connection *c, int ev, void *ev_data) {
if (ev == MG_EV_HTTP_MSG) { if (ev == MG_EV_HTTP_MSG) {
struct mg_http_message *hm = (struct mg_http_message *) ev_data; struct mg_http_message *hm = (struct mg_http_message *) ev_data;
if (mg_http_match_uri(hm, "/api/video1")) { if (mg_match(hm->uri, mg_str("/api/video1"), NULL)) {
c->data[0] = 'S'; // Mark that connection as live streamer c->data[0] = 'S'; // Mark that connection as live streamer
mg_printf( mg_printf(
c, "%s", c, "%s",

View File

@ -17,11 +17,11 @@ static void fn(struct mg_connection *c, int ev, void *ev_data) {
// c->is_hexdumping = 1; // c->is_hexdumping = 1;
} else if (ev == MG_EV_HTTP_MSG) { } else if (ev == MG_EV_HTTP_MSG) {
struct mg_http_message *hm = (struct mg_http_message *) ev_data; struct mg_http_message *hm = (struct mg_http_message *) ev_data;
if (mg_http_match_uri(hm, "/websocket")) { if (mg_match(hm->uri, mg_str("/websocket"), NULL)) {
// Upgrade to websocket. From now on, a connection is a full-duplex // Upgrade to websocket. From now on, a connection is a full-duplex
// Websocket connection, which will receive MG_EV_WS_MSG events. // Websocket connection, which will receive MG_EV_WS_MSG events.
mg_ws_upgrade(c, hm, NULL); mg_ws_upgrade(c, hm, NULL);
} else if (mg_http_match_uri(hm, "/rest")) { } else if (mg_match(hm->uri, mg_str("/rest"), NULL)) {
// Serve REST response // Serve REST response
mg_http_reply(c, 200, "", "{\"result\": %d}\n", 123); mg_http_reply(c, 200, "", "{\"result\": %d}\n", 123);
} else { } else {

View File

@ -47,14 +47,14 @@ void fn(struct mg_connection *c, int ev, void *ev_data) {
if (ev == MG_EV_HTTP_MSG) { if (ev == MG_EV_HTTP_MSG) {
struct mg_http_message *hm = (struct mg_http_message *) ev_data; struct mg_http_message *hm = (struct mg_http_message *) ev_data;
struct user *u = getuser(hm); struct user *u = getuser(hm);
if (u == NULL && mg_http_match_uri(hm, "/api/#")) { if (u == NULL && mg_match(hm->uri, mg_str("/api/#"), NULL)) {
// All URIs starting with /api/ must be authenticated // All URIs starting with /api/ must be authenticated
mg_http_reply(c, 403, "", "Denied\n"); mg_http_reply(c, 403, "", "Denied\n");
} else if (mg_http_match_uri(hm, "/api/data")) { } else if (mg_match(hm->uri, mg_str("/api/data"), NULL)) {
mg_http_reply(c, 200, "Content-Type: application/json\r\n", mg_http_reply(c, 200, "Content-Type: application/json\r\n",
"{%m:%m,%m:%m}\n", MG_ESC("text"), MG_ESC("Hello!"), "{%m:%m,%m:%m}\n", MG_ESC("text"), MG_ESC("Hello!"),
MG_ESC("data"), MG_ESC("somedata")); MG_ESC("data"), MG_ESC("somedata"));
} else if (mg_http_match_uri(hm, "/api/login")) { } else if (mg_match(hm->uri, mg_str("/api/login"), NULL)) {
mg_http_reply(c, 200, "Content-Type: application/json\r\n", mg_http_reply(c, 200, "Content-Type: application/json\r\n",
"{%m:%m,%m:%m}\n", MG_ESC("user"), MG_ESC(u->name), "{%m:%m,%m:%m}\n", MG_ESC("user"), MG_ESC(u->name),
MG_ESC("token"), MG_ESC(u->token)); MG_ESC("token"), MG_ESC(u->token));

View File

@ -36,12 +36,12 @@ static void fn(struct mg_connection *c, int ev, void *ev_data) {
s_config.sub = strdup(MQTT_SUBSCRIBE_TOPIC); s_config.sub = strdup(MQTT_SUBSCRIBE_TOPIC);
} else if (ev == MG_EV_HTTP_MSG) { } else if (ev == MG_EV_HTTP_MSG) {
struct mg_http_message *hm = (struct mg_http_message *) ev_data; struct mg_http_message *hm = (struct mg_http_message *) ev_data;
if (mg_http_match_uri(hm, "/api/config/get")) { if (mg_match(hm->uri, mg_str("/api/config/get"), NULL)) {
mg_http_reply(c, 200, "Content-Type: application/json\r\n", mg_http_reply(c, 200, "Content-Type: application/json\r\n",
"{%m:%m,%m:%m,%m:%m}\n", MG_ESC("url"), "{%m:%m,%m:%m,%m:%m}\n", MG_ESC("url"),
MG_ESC(s_config.url), MG_ESC("pub"), MG_ESC(s_config.pub), MG_ESC(s_config.url), MG_ESC("pub"), MG_ESC(s_config.pub),
MG_ESC("sub"), MG_ESC(s_config.sub)); MG_ESC("sub"), MG_ESC(s_config.sub));
} else if (mg_http_match_uri(hm, "/api/config/set")) { } else if (mg_match(hm->uri, mg_str("/api/config/set"), NULL)) {
struct mg_str json = hm->body; struct mg_str json = hm->body;
update_config(json, "$.url", &s_config.url); update_config(json, "$.url", &s_config.url);
update_config(json, "$.pub", &s_config.pub); update_config(json, "$.pub", &s_config.pub);

View File

@ -40,7 +40,7 @@ static size_t printdata(mg_pfn_t out, void *ptr, va_list *ap) {
static void fn(struct mg_connection *c, int ev, void *ev_data) { static void fn(struct mg_connection *c, int ev, void *ev_data) {
if (ev == MG_EV_HTTP_MSG) { if (ev == MG_EV_HTTP_MSG) {
struct mg_http_message *hm = ev_data; struct mg_http_message *hm = ev_data;
if (mg_http_match_uri(hm, "/api/data")) { if (mg_match(hm->uri, mg_str("/api/data"), NULL)) {
long version = getparam(hm, "$.version"); long version = getparam(hm, "$.version");
if (version > 0 && version == s_version) { if (version > 0 && version == s_version) {
// Version match: no changes // Version match: no changes

View File

@ -13,7 +13,7 @@ static const char *s_web_root = "web_root";
static void fn(struct mg_connection *c, int ev, void *ev_data) { static void fn(struct mg_connection *c, int ev, void *ev_data) {
if (ev == MG_EV_HTTP_MSG) { if (ev == MG_EV_HTTP_MSG) {
struct mg_http_message *hm = (struct mg_http_message *) ev_data; struct mg_http_message *hm = (struct mg_http_message *) ev_data;
if (mg_http_match_uri(hm, "/api/watch")) { if (mg_match(hm->uri, mg_str("/api/watch"), NULL)) {
mg_ws_upgrade(c, hm, NULL); // Upgrade HTTP to Websocket mg_ws_upgrade(c, hm, NULL); // Upgrade HTTP to Websocket
c->data[0] = 'W'; // Set some unique mark on the connection c->data[0] = 'W'; // Set some unique mark on the connection
} else { } else {

View File

@ -16,10 +16,10 @@ static const char *s_root_dir = "web_root";
static void fn(struct mg_connection *c, int ev, void *ev_data) { static void fn(struct mg_connection *c, int ev, void *ev_data) {
if (ev == MG_EV_HTTP_MSG) { if (ev == MG_EV_HTTP_MSG) {
struct mg_http_message *hm = (struct mg_http_message *) ev_data; struct mg_http_message *hm = (struct mg_http_message *) ev_data;
if (mg_http_match_uri(hm, "/api/f1")) { if (mg_match(hm->uri, mg_str("/api/f1"), NULL)) {
mg_http_reply(c, 200, "Content-Type: application/json\r\n", "{%m:%d}\n", mg_http_reply(c, 200, "Content-Type: application/json\r\n", "{%m:%d}\n",
MG_ESC("result"), 123); MG_ESC("result"), 123);
} else if (mg_http_match_uri(hm, "/api/sum")) { } else if (mg_match(hm->uri, mg_str("/api/sum"), NULL)) {
// Attempt to fetch a JSON array from the body, hm->body // Attempt to fetch a JSON array from the body, hm->body
struct mg_str json = hm->body; struct mg_str json = hm->body;
double num1, num2; double num1, num2;

View File

@ -282,23 +282,23 @@ static void fn(struct mg_connection *c, int ev, void *ev_data) {
struct mg_http_message *hm = (struct mg_http_message *) ev_data; struct mg_http_message *hm = (struct mg_http_message *) ev_data;
struct user *u = authenticate(hm); struct user *u = authenticate(hm);
if (mg_http_match_uri(hm, "/api/#") && u == NULL) { if (mg_match(hm->uri, mg_str("/api/#"), NULL) && u == NULL) {
mg_http_reply(c, 403, "", "Not Authorised\n"); mg_http_reply(c, 403, "", "Not Authorised\n");
} else if (mg_http_match_uri(hm, "/api/login")) { } else if (mg_match(hm->uri, mg_str("/api/login"), NULL)) {
handle_login(c, u); handle_login(c, u);
} else if (mg_http_match_uri(hm, "/api/logout")) { } else if (mg_match(hm->uri, mg_str("/api/logout"), NULL)) {
handle_logout(c); handle_logout(c);
} else if (mg_http_match_uri(hm, "/api/debug")) { } else if (mg_match(hm->uri, mg_str("/api/debug"), NULL)) {
handle_debug(c, hm); handle_debug(c, hm);
} else if (mg_http_match_uri(hm, "/api/stats/get")) { } else if (mg_match(hm->uri, mg_str("/api/stats/get"), NULL)) {
handle_stats_get(c); handle_stats_get(c);
} else if (mg_http_match_uri(hm, "/api/events/get")) { } else if (mg_match(hm->uri, mg_str("/api/events/get"), NULL)) {
handle_events_get(c); handle_events_get(c);
} else if (mg_http_match_uri(hm, "/api/devices/get")) { } else if (mg_match(hm->uri, mg_str("/api/devices/get"), NULL)) {
handle_devices_get(c); handle_devices_get(c);
} else if (mg_http_match_uri(hm, "/api/dhcp/get")) { } else if (mg_match(hm->uri, mg_str("/api/dhcp/get"), NULL)) {
handle_dhcp_get(c); handle_dhcp_get(c);
} else if (mg_http_match_uri(hm, "/api/dhcp/set")) { } else if (mg_match(hm->uri, mg_str("/api/dhcp/set"), NULL)) {
handle_dhcp_set(c, hm->body); handle_dhcp_set(c, hm->body);
} else { } else {
struct mg_http_serve_opts opts; struct mg_http_serve_opts opts;

View File

@ -19,7 +19,7 @@ static void wcb(struct mg_connection *c, int ev, void *ev_data) {
struct mg_http_message *hm = ev_data; struct mg_http_message *hm = ev_data;
MG_INFO(("%.*s %.*s %ld", (int) hm->method.len, hm->method.buf, MG_INFO(("%.*s %.*s %ld", (int) hm->method.len, hm->method.buf,
(int) hm->uri.len, hm->uri.buf, (long) hm->body.len)); (int) hm->uri.len, hm->uri.buf, (long) hm->body.len));
if (mg_http_match_uri(hm, "/api/#")) { // REST API requests if (mg_match(hm->uri, mg_str("/api/#"), NULL)) { // REST API requests
// Print some statistics about currently established connections // Print some statistics about currently established connections
mg_printf(c, "HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"); mg_printf(c, "HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n");
mg_http_printf_chunk(c, "ID PROTO TYPE LOCAL REMOTE\n"); mg_http_printf_chunk(c, "ID PROTO TYPE LOCAL REMOTE\n");

View File

@ -21,11 +21,11 @@ static void fn(struct mg_connection *c, int ev, void *ev_data) {
mg_tls_init(c, &opts); mg_tls_init(c, &opts);
} else if (ev == MG_EV_HTTP_MSG) { } else if (ev == MG_EV_HTTP_MSG) {
struct mg_http_message *hm = (struct mg_http_message *) ev_data; struct mg_http_message *hm = (struct mg_http_message *) ev_data;
if (mg_http_match_uri(hm, "/websocket")) { if (mg_match(hm->uri, mg_str("/websocket"), NULL)) {
// Upgrade to websocket. From now on, a connection is a full-duplex // Upgrade to websocket. From now on, a connection is a full-duplex
// Websocket connection, which will receive MG_EV_WS_MSG events. // Websocket connection, which will receive MG_EV_WS_MSG events.
mg_ws_upgrade(c, hm, NULL); mg_ws_upgrade(c, hm, NULL);
} else if (mg_http_match_uri(hm, "/rest")) { } else if (mg_match(hm->uri, mg_str("/rest"), NULL)) {
// Serve REST response // Serve REST response
mg_http_reply(c, 200, "", "{\"result\": %d}\n", 123); mg_http_reply(c, 200, "", "{\"result\": %d}\n", 123);
} }

View File

@ -3130,10 +3130,6 @@ struct mg_str mg_http_get_header_var(struct mg_str s, struct mg_str v) {
return mg_str_n(NULL, 0); return mg_str_n(NULL, 0);
} }
bool mg_http_match_uri(const struct mg_http_message *hm, const char *glob) {
return mg_match(hm->uri, mg_str(glob), NULL);
}
long mg_http_upload(struct mg_connection *c, struct mg_http_message *hm, long mg_http_upload(struct mg_connection *c, struct mg_http_message *hm,
struct mg_fs *fs, const char *dir, size_t max_size) { struct mg_fs *fs, const char *dir, size_t max_size) {
char buf[20] = "0", file[MG_PATH_MAX], path[MG_PATH_MAX]; char buf[20] = "0", file[MG_PATH_MAX], path[MG_PATH_MAX];
@ -3295,11 +3291,11 @@ static void http_cb(struct mg_connection *c, int ev, void *ev_data) {
static void mg_hfn(struct mg_connection *c, int ev, void *ev_data) { static void mg_hfn(struct mg_connection *c, int ev, void *ev_data) {
if (ev == MG_EV_HTTP_MSG) { if (ev == MG_EV_HTTP_MSG) {
struct mg_http_message *hm = (struct mg_http_message *) ev_data; struct mg_http_message *hm = (struct mg_http_message *) ev_data;
if (mg_http_match_uri(hm, "/quit")) { if (mg_match(hm->uri, mg_str("/quit"), NULL)) {
mg_http_reply(c, 200, "", "ok\n"); mg_http_reply(c, 200, "", "ok\n");
c->is_draining = 1; c->is_draining = 1;
c->data[0] = 'X'; c->data[0] = 'X';
} else if (mg_http_match_uri(hm, "/debug")) { } else if (mg_match(hm->uri, mg_str("/debug"), NULL)) {
int level = (int) mg_json_get_long(hm->body, "$.level", MG_LL_DEBUG); int level = (int) mg_json_get_long(hm->body, "$.level", MG_LL_DEBUG);
mg_log_set(level); mg_log_set(level);
mg_http_reply(c, 200, "", "Debug level set to %d\n", level); mg_http_reply(c, 200, "", "Debug level set to %d\n", level);

View File

@ -2153,7 +2153,6 @@ int mg_http_get_var(const struct mg_str *, const char *name, char *, size_t);
int mg_url_decode(const char *s, size_t n, char *to, size_t to_len, int form); int mg_url_decode(const char *s, size_t n, char *to, size_t to_len, int form);
size_t mg_url_encode(const char *s, size_t n, char *buf, size_t len); size_t mg_url_encode(const char *s, size_t n, char *buf, size_t len);
void mg_http_creds(struct mg_http_message *, char *, size_t, char *, size_t); void mg_http_creds(struct mg_http_message *, char *, size_t, char *, size_t);
bool mg_http_match_uri(const struct mg_http_message *, const char *glob);
long mg_http_upload(struct mg_connection *c, struct mg_http_message *hm, long mg_http_upload(struct mg_connection *c, struct mg_http_message *hm,
struct mg_fs *fs, const char *dir, size_t max_size); struct mg_fs *fs, const char *dir, size_t max_size);
void mg_http_bauth(struct mg_connection *, const char *user, const char *pass); void mg_http_bauth(struct mg_connection *, const char *user, const char *pass);

View File

@ -914,10 +914,6 @@ struct mg_str mg_http_get_header_var(struct mg_str s, struct mg_str v) {
return mg_str_n(NULL, 0); return mg_str_n(NULL, 0);
} }
bool mg_http_match_uri(const struct mg_http_message *hm, const char *glob) {
return mg_match(hm->uri, mg_str(glob), NULL);
}
long mg_http_upload(struct mg_connection *c, struct mg_http_message *hm, long mg_http_upload(struct mg_connection *c, struct mg_http_message *hm,
struct mg_fs *fs, const char *dir, size_t max_size) { struct mg_fs *fs, const char *dir, size_t max_size) {
char buf[20] = "0", file[MG_PATH_MAX], path[MG_PATH_MAX]; char buf[20] = "0", file[MG_PATH_MAX], path[MG_PATH_MAX];
@ -1079,11 +1075,11 @@ static void http_cb(struct mg_connection *c, int ev, void *ev_data) {
static void mg_hfn(struct mg_connection *c, int ev, void *ev_data) { static void mg_hfn(struct mg_connection *c, int ev, void *ev_data) {
if (ev == MG_EV_HTTP_MSG) { if (ev == MG_EV_HTTP_MSG) {
struct mg_http_message *hm = (struct mg_http_message *) ev_data; struct mg_http_message *hm = (struct mg_http_message *) ev_data;
if (mg_http_match_uri(hm, "/quit")) { if (mg_match(hm->uri, mg_str("/quit"), NULL)) {
mg_http_reply(c, 200, "", "ok\n"); mg_http_reply(c, 200, "", "ok\n");
c->is_draining = 1; c->is_draining = 1;
c->data[0] = 'X'; c->data[0] = 'X';
} else if (mg_http_match_uri(hm, "/debug")) { } else if (mg_match(hm->uri, mg_str("/debug"), NULL)) {
int level = (int) mg_json_get_long(hm->body, "$.level", MG_LL_DEBUG); int level = (int) mg_json_get_long(hm->body, "$.level", MG_LL_DEBUG);
mg_log_set(level); mg_log_set(level);
mg_http_reply(c, 200, "", "Debug level set to %d\n", level); mg_http_reply(c, 200, "", "Debug level set to %d\n", level);

View File

@ -57,7 +57,6 @@ int mg_http_get_var(const struct mg_str *, const char *name, char *, size_t);
int mg_url_decode(const char *s, size_t n, char *to, size_t to_len, int form); int mg_url_decode(const char *s, size_t n, char *to, size_t to_len, int form);
size_t mg_url_encode(const char *s, size_t n, char *buf, size_t len); size_t mg_url_encode(const char *s, size_t n, char *buf, size_t len);
void mg_http_creds(struct mg_http_message *, char *, size_t, char *, size_t); void mg_http_creds(struct mg_http_message *, char *, size_t, char *, size_t);
bool mg_http_match_uri(const struct mg_http_message *, const char *glob);
long mg_http_upload(struct mg_connection *c, struct mg_http_message *hm, long mg_http_upload(struct mg_connection *c, struct mg_http_message *hm,
struct mg_fs *fs, const char *dir, size_t max_size); struct mg_fs *fs, const char *dir, size_t max_size);
void mg_http_bauth(struct mg_connection *, const char *user, const char *pass); void mg_http_bauth(struct mg_connection *, const char *user, const char *pass);

View File

@ -630,35 +630,35 @@ static void eh1(struct mg_connection *c, int ev, void *ev_data) {
struct mg_http_message *hm = (struct mg_http_message *) ev_data; struct mg_http_message *hm = (struct mg_http_message *) ev_data;
MG_INFO(("[%.*s %.*s] message len %d", (int) hm->method.len, hm->method.buf, MG_INFO(("[%.*s %.*s] message len %d", (int) hm->method.len, hm->method.buf,
(int) hm->uri.len, hm->uri.buf, (int) hm->message.len)); (int) hm->uri.len, hm->uri.buf, (int) hm->message.len));
if (mg_http_match_uri(hm, "/foo/*")) { if (mg_match(hm->uri, mg_str("/foo/*"), NULL)) {
mg_http_reply(c, 200, "", "uri: %.*s", hm->uri.len - 5, hm->uri.buf + 5); mg_http_reply(c, 200, "", "uri: %.*s", hm->uri.len - 5, hm->uri.buf + 5);
} else if (mg_http_match_uri(hm, "/ws")) { } else if (mg_match(hm->uri, mg_str("/ws"), NULL)) {
mg_ws_upgrade(c, hm, NULL); mg_ws_upgrade(c, hm, NULL);
} else if (mg_http_match_uri(hm, "/body")) { } else if (mg_match(hm->uri, mg_str("/body"), NULL)) {
mg_http_reply(c, 200, "", "%.*s", (int) hm->body.len, hm->body.buf); mg_http_reply(c, 200, "", "%.*s", (int) hm->body.len, hm->body.buf);
} else if (mg_http_match_uri(hm, "/bar")) { } else if (mg_match(hm->uri, mg_str("/bar"), NULL)) {
mg_http_reply(c, 404, "", "not found"); mg_http_reply(c, 404, "", "not found");
} else if (mg_http_match_uri(hm, "/no_reason")) { } else if (mg_match(hm->uri, mg_str("/no_reason"), NULL)) {
mg_printf(c, "%s", "HTTP/1.0 200\r\nContent-Length: 2\r\n\r\nok"); mg_printf(c, "%s", "HTTP/1.0 200\r\nContent-Length: 2\r\n\r\nok");
} else if (mg_http_match_uri(hm, "/badroot")) { } else if (mg_match(hm->uri, mg_str("/badroot"), NULL)) {
struct mg_http_serve_opts sopts; struct mg_http_serve_opts sopts;
memset(&sopts, 0, sizeof(sopts)); memset(&sopts, 0, sizeof(sopts));
sopts.root_dir = "/BAAADDD!"; sopts.root_dir = "/BAAADDD!";
mg_http_serve_dir(c, hm, &sopts); mg_http_serve_dir(c, hm, &sopts);
} else if (mg_http_match_uri(hm, "/creds")) { } else if (mg_match(hm->uri, mg_str("/creds"), NULL)) {
char user[100], pass[100]; char user[100], pass[100];
mg_http_creds(hm, user, sizeof(user), pass, sizeof(pass)); mg_http_creds(hm, user, sizeof(user), pass, sizeof(pass));
mg_http_reply(c, 200, "", "[%s]:[%s]", user, pass); mg_http_reply(c, 200, "", "[%s]:[%s]", user, pass);
} else if (mg_http_match_uri(hm, "/upload")) { } else if (mg_match(hm->uri, mg_str("/upload"), NULL)) {
mg_http_upload(c, hm, &mg_fs_posix, ".", 99999); mg_http_upload(c, hm, &mg_fs_posix, ".", 99999);
c->is_hexdumping = 1; c->is_hexdumping = 1;
} else if (mg_http_match_uri(hm, "/test/")) { } else if (mg_match(hm->uri, mg_str("/test/"), NULL)) {
struct mg_http_serve_opts sopts; struct mg_http_serve_opts sopts;
memset(&sopts, 0, sizeof(sopts)); memset(&sopts, 0, sizeof(sopts));
sopts.root_dir = "."; sopts.root_dir = ".";
sopts.extra_headers = "A: B\r\nC: D\r\n"; sopts.extra_headers = "A: B\r\nC: D\r\n";
mg_http_serve_dir(c, hm, &sopts); mg_http_serve_dir(c, hm, &sopts);
} else if (mg_http_match_uri(hm, "/servefile")) { } else if (mg_match(hm->uri, mg_str("/servefile"), NULL)) {
struct mg_http_serve_opts sopts; struct mg_http_serve_opts sopts;
memset(&sopts, 0, sizeof(sopts)); memset(&sopts, 0, sizeof(sopts));
sopts.mime_types = "foo=a/b,txt=c/d"; sopts.mime_types = "foo=a/b,txt=c/d";
@ -1116,13 +1116,13 @@ static void h4(struct mg_connection *c, int ev, void *ev_data) {
struct mg_http_message *hm = (struct mg_http_message *) ev_data; struct mg_http_message *hm = (struct mg_http_message *) ev_data;
MG_INFO(("[%.*s %.*s] message len %d", (int) hm->method.len, hm->method.buf, MG_INFO(("[%.*s %.*s] message len %d", (int) hm->method.len, hm->method.buf,
(int) hm->uri.len, hm->uri.buf, (int) hm->message.len)); (int) hm->uri.len, hm->uri.buf, (int) hm->message.len));
if (mg_http_match_uri(hm, "/a/#")) { if (mg_match(hm->uri, mg_str("/a/#"), NULL)) {
struct mg_http_serve_opts opts; struct mg_http_serve_opts opts;
memset(&opts, 0, sizeof(opts)); memset(&opts, 0, sizeof(opts));
opts.root_dir = "/a=./test/data"; opts.root_dir = "/a=./test/data";
opts.page404 = "./test/data/404.html"; // existing 404 page opts.page404 = "./test/data/404.html"; // existing 404 page
mg_http_serve_dir(c, hm, &opts); mg_http_serve_dir(c, hm, &opts);
} else if (mg_http_match_uri(hm, "/b/#")) { } else if (mg_match(hm->uri, mg_str("/b/#"), NULL)) {
struct mg_http_serve_opts opts; struct mg_http_serve_opts opts;
memset(&opts, 0, sizeof(opts)); memset(&opts, 0, sizeof(opts));
opts.root_dir = "/b=./test/data"; opts.root_dir = "/b=./test/data";
@ -2343,7 +2343,7 @@ static void test_crc32(void) {
static void us(struct mg_connection *c, int ev, void *ev_data) { static void us(struct mg_connection *c, int ev, void *ev_data) {
struct mg_http_message *hm = (struct mg_http_message *) ev_data; struct mg_http_message *hm = (struct mg_http_message *) ev_data;
if (ev == MG_EV_HTTP_MSG && mg_http_match_uri(hm, "/upload")) { if (ev == MG_EV_HTTP_MSG && mg_match(hm->uri, mg_str("/upload"), NULL)) {
MG_DEBUG(("Got all %lu bytes!", (unsigned long) hm->body.len)); MG_DEBUG(("Got all %lu bytes!", (unsigned long) hm->body.len));
MG_DEBUG(("Query string: [%.*s]", (int) hm->query.len, hm->query.buf)); MG_DEBUG(("Query string: [%.*s]", (int) hm->query.len, hm->query.buf));
// MG_DEBUG(("Body:\n%.*s", (int) hm->body.len, hm->body.buf)); // MG_DEBUG(("Body:\n%.*s", (int) hm->body.len, hm->body.buf));