diff --git a/examples/api_server/api_server.c b/examples/api_server/api_server.c
index 445b0cf8..7f994717 100644
--- a/examples/api_server/api_server.c
+++ b/examples/api_server/api_server.c
@@ -10,9 +10,9 @@ static struct mg_serve_http_opts s_http_server_opts;
static int s_sig_num = 0;
static void *s_db_handle = NULL;
static const char *s_db_path = "api_server.db";
-static const struct mg_str s_get_method = NS_STR("GET");
-static const struct mg_str s_put_method = NS_STR("PUT");
-static const struct mg_str s_delele_method = NS_STR("DELETE");
+static const struct mg_str s_get_method = MG_STR("GET");
+static const struct mg_str s_put_method = MG_STR("PUT");
+static const struct mg_str s_delele_method = MG_STR("DELETE");
static void signal_handler(int sig_num) {
signal(sig_num, signal_handler);
@@ -28,12 +28,12 @@ static int is_equal(const struct mg_str *s1, const struct mg_str *s2) {
}
static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
- static const struct mg_str api_prefix = NS_STR("/api/v1");
+ static const struct mg_str api_prefix = MG_STR("/api/v1");
struct http_message *hm = (struct http_message *) ev_data;
struct mg_str key;
switch (ev) {
- case NS_HTTP_REQUEST:
+ case MG_EV_HTTP_REQUEST:
if (has_prefix(&hm->uri, &api_prefix)) {
key.p = hm->uri.p + api_prefix.len;
key.len = hm->uri.len - api_prefix.len;
diff --git a/examples/arduino_restful_client/arduino_restful_client.ino b/examples/arduino_restful_client/arduino_restful_client.ino
index e81179b0..3f964e58 100644
--- a/examples/arduino_restful_client/arduino_restful_client.ino
+++ b/examples/arduino_restful_client/arduino_restful_client.ino
@@ -96,9 +96,9 @@ static void rfc_ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
int len = get_data_to_send(buf, sizeof(buf));
mg_printf(nc, "POST %s HTTP/1.0\r\nHost: %s\r\nContent-Lenght: %d"
"\r\n\r\n%s", s_request, s_target_address, len, buf);
- nc->flags |= NSF_SEND_AND_CLOSE;
+ nc->flags |= MG_F_SEND_AND_CLOSE;
} else {
- nc->flags |= NSF_CLOSE_IMMEDIATELY;
+ nc->flags |= MG_F_CLOSE_IMMEDIATELY;
}
break;
default:
diff --git a/examples/arduino_restful_server/arduino_restful_server.ino b/examples/arduino_restful_server/arduino_restful_server.ino
index 7232dc5d..f45ed18e 100644
--- a/examples/arduino_restful_server/arduino_restful_server.ino
+++ b/examples/arduino_restful_server/arduino_restful_server.ino
@@ -98,7 +98,7 @@ static void rfs_ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
mg_send_http_chunk(nc, "", 0);
break;
case NS_SEND:
- nc->flags |= NSF_CLOSE_IMMEDIATELY;
+ nc->flags |= MG_F_CLOSE_IMMEDIATELY;
break;
default:
diff --git a/examples/captive_dns_server/Makefile b/examples/captive_dns_server/Makefile
index aabf5ac5..86640fd3 100644
--- a/examples/captive_dns_server/Makefile
+++ b/examples/captive_dns_server/Makefile
@@ -1,4 +1,4 @@
PROG = captive_dns_server
-MODULE_CFLAGS=-DNS_ENABLE_DNS_SERVER
+MODULE_CFLAGS=-DMG_ENABLE_DNS_SERVER
include ../rules.mk
diff --git a/examples/captive_dns_server/captive_dns_server.c b/examples/captive_dns_server/captive_dns_server.c
index fb4a668a..0fda50a8 100644
--- a/examples/captive_dns_server/captive_dns_server.c
+++ b/examples/captive_dns_server/captive_dns_server.c
@@ -23,13 +23,13 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
int i;
switch (ev) {
- case NS_DNS_MESSAGE:
+ case MG_DNS_MESSAGE:
msg = (struct mg_dmg_message *) ev_data;
reply = mg_dmg_create_reply(&nc->send_mbuf, msg);
for (i = 0; i < msg->num_questions; i++) {
rr = &msg->questions[i];
- if (rr->rtype == NS_DNS_A_RECORD) {
+ if (rr->rtype == MG_DNS_A_RECORD) {
mg_dmg_reply_record(&reply, rr, NULL, rr->rtype, 3600,
&s_our_ip_addr, 4);
}
@@ -37,8 +37,8 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
/*
* We don't set the error flag even if there were no answers
- * maching the NS_DNS_A_RECORD query type.
- * This indicates that we have (syntetic) answers for NS_DNS_A_RECORD.
+ * maching the MG_DNS_A_RECORD query type.
+ * This indicates that we have (syntetic) answers for MG_DNS_A_RECORD.
* See http://goo.gl/QWvufr for a distinction between NXDOMAIN and NODATA.
*/
diff --git a/examples/coap_client/Makefile b/examples/coap_client/Makefile
index 312fbeb1..1726c41c 100644
--- a/examples/coap_client/Makefile
+++ b/examples/coap_client/Makefile
@@ -1,6 +1,6 @@
PROG = coap_client
SOURCES = $(PROG).c ../../mongoose.c
-CFLAGS = -W -Wall -I../.. $(CFLAGS_EXTRA) -DNS_ENABLE_COAP
+CFLAGS = -W -Wall -I../.. $(CFLAGS_EXTRA) -DMG_ENABLE_COAP
all: $(PROG)
diff --git a/examples/coap_client/coap_client.c b/examples/coap_client/coap_client.c
index f36b2fa0..639b61c7 100644
--- a/examples/coap_client/coap_client.c
+++ b/examples/coap_client/coap_client.c
@@ -13,13 +13,13 @@ static char* s_default_address = "udp://coap.me:5683";
static void coap_handler(struct mg_connection *nc, int ev, void *p) {
switch (ev) {
- case NS_CONNECT: {
+ case MG_EV_CONNECT: {
struct mg_coap_message cm;
uint32_t res;
memset(&cm, 0, sizeof(cm));
cm.msg_id = 1;
- cm.msg_type = NS_COAP_MSG_CON;
+ cm.msg_type = MG_COAP_MSG_CON;
printf("Sending CON...\n");
res = mg_coap_send_message(nc, &cm);
if (res == 0) {
@@ -30,8 +30,8 @@ static void coap_handler(struct mg_connection *nc, int ev, void *p) {
}
break;
}
- case NS_COAP_ACK:
- case NS_COAP_RST: {
+ case MG_EV_COAP_ACK:
+ case MG_EV_COAP_RST: {
struct mg_coap_message *cm = (struct mg_coap_message *)p;
printf("ACK/RST for message with msg_id = %d received\n",
cm->msg_id);
diff --git a/examples/coap_server/Makefile b/examples/coap_server/Makefile
index 2990a47f..c2920f95 100644
--- a/examples/coap_server/Makefile
+++ b/examples/coap_server/Makefile
@@ -1,6 +1,6 @@
PROG = coap_server
SOURCES = $(PROG).c ../../mongoose.c
-CFLAGS = -W -Wall -I../.. $(CFLAGS_EXTRA) -DNS_ENABLE_COAP
+CFLAGS = -W -Wall -I../.. $(CFLAGS_EXTRA) -DMG_ENABLE_COAP
all: $(PROG)
diff --git a/examples/coap_server/coap_server.c b/examples/coap_server/coap_server.c
index 34e99fbc..8e4b3a0a 100644
--- a/examples/coap_server/coap_server.c
+++ b/examples/coap_server/coap_server.c
@@ -19,7 +19,7 @@ static void signal_handler(int sig_num) {
static void coap_handler(struct mg_connection *nc, int ev, void *p) {
switch (ev) {
- case NS_COAP_CON: {
+ case MG_EV_COAP_CON: {
uint32_t res;
struct mg_coap_message *cm = (struct mg_coap_message *)p;
printf("CON with msg_id = %d received\n", cm->msg_id);
@@ -32,9 +32,9 @@ static void coap_handler(struct mg_connection *nc, int ev, void *p) {
}
break;
}
- case NS_COAP_NOC:
- case NS_COAP_ACK:
- case NS_COAP_RST: {
+ case MG_EV_COAP_NOC:
+ case MG_EV_COAP_ACK:
+ case MG_EV_COAP_RST: {
struct mg_coap_message *cm = (struct mg_coap_message *)p;
printf("ACK/RST/NOC with msg_id = %d received\n",
cm->msg_id);
diff --git a/examples/http_client/Makefile b/examples/http_client/Makefile
index 2da47c2c..93932ad0 100644
--- a/examples/http_client/Makefile
+++ b/examples/http_client/Makefile
@@ -1,6 +1,6 @@
PROG = http_client
SOURCES = $(PROG).c ../../mongoose.c
-CFLAGS = -W -Wall -I../.. -DNS_ENABLE_SSL -lssl -lcrypto -pthread $(CFLAGS_EXTRA)
+CFLAGS = -W -Wall -I../.. -DMG_ENABLE_SSL -lssl -lcrypto -pthread $(CFLAGS_EXTRA)
all: $(PROG)
diff --git a/examples/http_client/http_client.c b/examples/http_client/http_client.c
index 97b9b35b..5017d8b1 100644
--- a/examples/http_client/http_client.c
+++ b/examples/http_client/http_client.c
@@ -15,14 +15,14 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
struct http_message *hm = (struct http_message *) ev_data;
switch (ev) {
- case NS_CONNECT:
+ case MG_EV_CONNECT:
if (* (int *) ev_data != 0) {
fprintf(stderr, "connect() failed: %s\n", strerror(* (int *) ev_data));
s_exit_flag = 1;
}
break;
- case NS_HTTP_REPLY:
- nc->flags |= NSF_CLOSE_IMMEDIATELY;
+ case MG_EV_HTTP_REPLY:
+ nc->flags |= MG_F_CLOSE_IMMEDIATELY;
if (s_show_headers) {
fwrite(hm->message.p, 1, hm->message.len, stdout);
} else {
diff --git a/examples/json_rpc_server/json_rpc_server.c b/examples/json_rpc_server/json_rpc_server.c
index ad39e291..9df45527 100644
--- a/examples/json_rpc_server/json_rpc_server.c
+++ b/examples/json_rpc_server/json_rpc_server.c
@@ -36,13 +36,13 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
char buf[100];
switch (ev) {
- case NS_HTTP_REQUEST:
+ case MG_EV_HTTP_REQUEST:
mg_rpc_dispatch(hm->body.p, hm->body.len, buf, sizeof(buf),
methods, handlers);
mg_printf(nc, "HTTP/1.0 200 OK\r\nContent-Length: %d\r\n"
"Content-Type: application/json\r\n\r\n%s",
(int) strlen(buf), buf);
- nc->flags |= NSF_SEND_AND_CLOSE;
+ nc->flags |= MG_F_SEND_AND_CLOSE;
break;
default:
break;
diff --git a/examples/load_balancer/Dockerfile b/examples/load_balancer/Dockerfile
index 7c88956b..caeec8a9 100644
--- a/examples/load_balancer/Dockerfile
+++ b/examples/load_balancer/Dockerfile
@@ -4,7 +4,7 @@ COPY load_balancer.c /mongoose/
WORKDIR /mongoose
RUN mkdir /mongoose/certs; \
sed -i 's:#include "../../mongoose.h":#include "mongoose.h":' load_balancer.c; \
- cc load_balancer.c mongoose.c -o load_balancer -W -Wall -pthread -DNS_ENABLE_SSL -lssl -lcrypto
+ cc load_balancer.c mongoose.c -o load_balancer -W -Wall -pthread -DMG_ENABLE_SSL -lssl -lcrypto
EXPOSE 8000
VOLUME ["/mongoose/certs"]
ENTRYPOINT ["/mongoose/load_balancer"]
diff --git a/examples/load_balancer/Makefile b/examples/load_balancer/Makefile
index 34ccc884..50ac1285 100644
--- a/examples/load_balancer/Makefile
+++ b/examples/load_balancer/Makefile
@@ -8,13 +8,13 @@ CFLAGS = -W -Wall -pthread $(CFLAGS_EXTRA)
ifeq ($(SSL), openssl)
OPENSSL_PATH = ./openssl-0.9.8
- CFLAGS_EXTRA += -DNS_ENABLE_SSL -I$(OPENSSL_PATH)/include
+ CFLAGS_EXTRA += -DMG_ENABLE_SSL -I$(OPENSSL_PATH)/include
CFLAGS_EXTRA += /link /libpath:$(OPENSSL_PATH)/lib ssleay32.lib libeay32.lib
endif
ifeq ($(SSL), krypton)
KRYPTON_PATH = ../../../krypton
- CFLAGS_EXTRA += -DNS_ENABLE_SSL $(KRYPTON_PATH)/krypton.c -I$(KRYPTON_PATH)
+ CFLAGS_EXTRA += -DMG_ENABLE_SSL $(KRYPTON_PATH)/krypton.c -I$(KRYPTON_PATH)
endif
all: $(PROG)
@@ -23,7 +23,7 @@ $(PROG): $(SOURCES)
$(CC) $(SOURCES) -o $@ $(CFLAGS)
$(PROG).exe: $(SOURCES)
- cl $(SOURCES) /I.. /MD /Fe$@ /DNS_ENABLE_THREADS advapi32.lib $(CFLAGS_EXTRA)
+ cl $(SOURCES) /I.. /MD /Fe$@ /DMG_ENABLE_THREADS advapi32.lib $(CFLAGS_EXTRA)
test: $(PROG)
$(MAKE) -C ../api_server
diff --git a/examples/load_balancer/load_balancer.c b/examples/load_balancer/load_balancer.c
index fb01dfa7..6b049519 100644
--- a/examples/load_balancer/load_balancer.c
+++ b/examples/load_balancer/load_balancer.c
@@ -60,7 +60,7 @@ static int s_num_vhost_backends = 0, s_num_default_backends = 0;
static int s_sig_num = 0;
static int s_backend_keepalive = 0;
static FILE *s_log_file = NULL;
-#ifdef NS_ENABLE_SSL
+#ifdef MG_ENABLE_SSL
const char *s_ssl_cert = NULL;
#endif
@@ -87,7 +87,7 @@ static void respond_with_error(struct conn_data *conn, const char *err_line) {
send_http_err(nc, err_line);
conn->client.flags.headers_sent = 1;
}
- nc->flags |= NSF_SEND_AND_CLOSE;
+ nc->flags |= MG_F_SEND_AND_CLOSE;
}
static int has_prefix(const struct mg_str *uri, const char *prefix) {
@@ -203,10 +203,10 @@ static void forward(struct conn_data *conn, struct http_message *hm,
}
/* Headers. */
- for (i = 0; i < NS_MAX_HTTP_HEADERS && hm->header_names[i].len > 0; i++) {
+ for (i = 0; i < MG_MAX_HTTP_HEADERS && hm->header_names[i].len > 0; i++) {
struct mg_str hn = hm->header_names[i];
struct mg_str hv = hm->header_values[i];
-#ifdef NS_ENABLE_SSL
+#ifdef MG_ENABLE_SSL
/*
* If we terminate SSL and backend redirects to local HTTP port,
* strip protocol to let client use HTTPS.
@@ -330,17 +330,17 @@ static void idle_backend_handler(struct mg_connection *nc, int ev,
bec->idle_deadline);
#endif
switch (ev) {
- case NS_POLL: {
+ case MG_EV_POLL: {
if (bec->idle_deadline > 0 && now > bec->idle_deadline) {
#ifdef DEBUG
write_log("bec=%p nc=%p closing due to idleness\n", bec, bec->nc);
#endif
- bec->nc->flags |= NSF_CLOSE_IMMEDIATELY;
+ bec->nc->flags |= MG_F_CLOSE_IMMEDIATELY;
}
break;
}
- case NS_CLOSE: {
+ case MG_EV_CLOSE: {
#ifdef DEBUG
write_log("bec=%p closed\n", bec);
#endif
@@ -377,14 +377,14 @@ void release_backend(struct conn_data *conn) {
STAILQ_REMOVE_HEAD(&be->conns, conns);
be->num_conns--;
bec->idle_deadline = 0;
- bec->nc->flags = NSF_CLOSE_IMMEDIATELY;
+ bec->nc->flags = MG_F_CLOSE_IMMEDIATELY;
#ifdef DEBUG
write_log("bec=%p evicted\n", bec);
#endif
}
} else {
bec->idle_deadline = 0;
- bec->nc->flags |= NSF_CLOSE_IMMEDIATELY;
+ bec->nc->flags |= MG_F_CLOSE_IMMEDIATELY;
}
memset(&conn->backend, 0, sizeof(conn->backend));
}
@@ -399,7 +399,7 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
#endif
if (conn == NULL) {
- if (ev == NS_ACCEPT) {
+ if (ev == MG_EV_ACCEPT) {
conn = calloc(1, sizeof(*conn));
if (conn == NULL) {
send_http_err(nc, s_error_500);
@@ -413,15 +413,15 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
}
return;
} else {
- nc->flags |= NSF_CLOSE_IMMEDIATELY;
+ nc->flags |= MG_F_CLOSE_IMMEDIATELY;
return;
}
}
- if (ev != NS_POLL) conn->last_activity = now;
+ if (ev != MG_EV_POLL) conn->last_activity = now;
switch (ev) {
- case NS_HTTP_REQUEST: { /* From client */
+ case MG_EV_HTTP_REQUEST: { /* From client */
assert(conn != NULL);
assert(conn->be_conn == NULL);
struct http_message *hm = (struct http_message *) ev_data;
@@ -434,7 +434,7 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
if (conn->backend.nc == NULL) {
/* This is a redirect, we're done. */
- conn->client.nc->flags |= NSF_SEND_AND_CLOSE;
+ conn->client.nc->flags |= MG_F_SEND_AND_CLOSE;
break;
}
@@ -442,7 +442,7 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
break;
}
- case NS_CONNECT: { /* To backend */
+ case MG_EV_CONNECT: { /* To backend */
assert(conn != NULL);
assert(conn->be_conn != NULL);
int status = *(int *) ev_data;
@@ -458,14 +458,14 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
break;
}
- case NS_HTTP_REPLY: { /* From backend */
+ case MG_EV_HTTP_REPLY: { /* From backend */
assert(conn != NULL);
struct http_message *hm = (struct http_message *) ev_data;
conn->backend.flags.keep_alive = s_backend_keepalive && is_keep_alive(hm);
forward(conn, hm, &conn->backend, &conn->client);
release_backend(conn);
if (!conn->client.flags.keep_alive) {
- conn->client.nc->flags |= NSF_SEND_AND_CLOSE;
+ conn->client.nc->flags |= MG_F_SEND_AND_CLOSE;
} else {
#ifdef DEBUG
write_log("conn=%p remains open\n", conn);
@@ -474,19 +474,19 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
break;
}
- case NS_POLL: {
+ case MG_EV_POLL: {
assert(conn != NULL);
if (now - conn->last_activity > CONN_IDLE_TIMEOUT &&
conn->backend.nc == NULL /* not waiting for backend */) {
#ifdef DEBUG
write_log("conn=%p has been idle for too long\n", conn);
- conn->client.nc->flags |= NSF_SEND_AND_CLOSE;
+ conn->client.nc->flags |= MG_F_SEND_AND_CLOSE;
#endif
}
break;
}
- case NS_CLOSE: {
+ case MG_EV_CLOSE: {
assert(conn != NULL);
if (nc == conn->client.nc) {
#ifdef DEBUG
@@ -495,7 +495,7 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
#endif
conn->client.nc = NULL;
if (conn->backend.nc != NULL) {
- conn->backend.nc->flags |= NSF_CLOSE_IMMEDIATELY;
+ conn->backend.nc->flags |= MG_F_CLOSE_IMMEDIATELY;
}
} else if (nc == conn->backend.nc) {
#ifdef DEBUG
@@ -520,7 +520,7 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
static void print_usage_and_exit(const char *prog_name) {
fprintf(stderr,
"Usage: %s [-D debug_dump_file] [-p http_port] [-l log] [-k]"
-#if NS_ENABLE_SSL
+#if MG_ENABLE_SSL
"[-s ssl_cert] "
#endif
"<[-r] [-v vhost] -b uri_prefix[=replacement] host_port> ... \n",
@@ -589,7 +589,7 @@ int main(int argc, char *argv[]) {
vhost = NULL;
redirect = 0;
i += 2;
-#ifdef NS_ENABLE_SSL
+#ifdef MG_ENABLE_SSL
} else if (strcmp(argv[i], "-s") == 0 && i + 1 < argc) {
s_ssl_cert = argv[++i];
#endif
@@ -604,7 +604,7 @@ int main(int argc, char *argv[]) {
exit(EXIT_FAILURE);
}
-#if NS_ENABLE_SSL
+#if MG_ENABLE_SSL
if (s_ssl_cert != NULL) {
const char *err_str = mg_set_ssl(nc, s_ssl_cert, NULL);
if (err_str != NULL) {
diff --git a/examples/mqtt_broker/Makefile b/examples/mqtt_broker/Makefile
index 4e5590c1..f97d4000 100644
--- a/examples/mqtt_broker/Makefile
+++ b/examples/mqtt_broker/Makefile
@@ -1,6 +1,6 @@
PROG = mqtt_broker
SOURCES = $(PROG).c ../../mongoose.c
-CFLAGS = -W -Wall -I../.. -pthread -DNS_ENABLE_SSL -DNS_ENABLE_MQTT_BROKER -lssl -lcrypto $(CFLAGS_EXTRA)
+CFLAGS = -W -Wall -I../.. -pthread -DMG_ENABLE_SSL -DMG_ENABLE_MQTT_BROKER -lssl -lcrypto $(CFLAGS_EXTRA)
all: $(PROG)
@@ -8,7 +8,7 @@ $(PROG): $(SOURCES)
$(CC) $(SOURCES) -o $@ $(CFLAGS)
$(PROG).exe: $(SOURCES)
- cl $(SOURCES) /I../.. /DNS_ENABLE_SSL /DNS_ENABLE_MQTT_BROKER /MD /Fe$@
+ cl $(SOURCES) /I../.. /DMG_ENABLE_SSL /DMG_ENABLE_MQTT_BROKER /MD /Fe$@
clean:
rm -rf *.gc* *.dSYM *.exe *.obj *.o a.out $(PROG)
diff --git a/examples/mqtt_client/Makefile b/examples/mqtt_client/Makefile
index e36a83d5..7ad990dd 100644
--- a/examples/mqtt_client/Makefile
+++ b/examples/mqtt_client/Makefile
@@ -1,6 +1,6 @@
PROG = mqtt_client
SOURCES = $(PROG).c ../../mongoose.c
-CFLAGS = -W -Wall -I../.. -pthread -DNS_ENABLE_SSL -lssl -lcrypto $(CFLAGS_EXTRA)
+CFLAGS = -W -Wall -I../.. -pthread -DMG_ENABLE_SSL -lssl -lcrypto $(CFLAGS_EXTRA)
all: $(PROG)
@@ -8,7 +8,7 @@ $(PROG): $(SOURCES)
$(CC) $(SOURCES) -o $@ $(CFLAGS)
$(PROG).exe: $(SOURCES)
- cl $(SOURCES) /I../.. /DNS_ENABLE_SSL /MD /Fe$@
+ cl $(SOURCES) /I../.. /DMG_ENABLE_SSL /MD /Fe$@
clean:
rm -rf *.gc* *.dSYM *.exe *.obj *.o a.out $(PROG)
diff --git a/examples/mqtt_client/mqtt_client.c b/examples/mqtt_client/mqtt_client.c
index 005e6c17..704ed9ea 100644
--- a/examples/mqtt_client/mqtt_client.c
+++ b/examples/mqtt_client/mqtt_client.c
@@ -26,30 +26,30 @@ static void ev_handler(struct mg_connection *nc, int ev, void *p) {
(void) nc;
#if 0
- if (ev != NS_POLL)
+ if (ev != MG_EV_POLL)
printf("USER HANDLER GOT %d\n", ev);
#endif
switch (ev) {
- case NS_CONNECT:
+ case MG_EV_CONNECT:
mg_set_protocol_mqtt(nc);
mg_send_mqtt_handshake(nc, "dummy");
break;
- case NS_MQTT_CONNACK:
- if (msg->connack_ret_code != NS_MQTT_CONNACK_ACCEPTED) {
+ case MG_EV_MQTT_CONNACK:
+ if (msg->connack_ret_code != MG_EV_MQTT_CONNACK_ACCEPTED) {
printf("Got mqtt connection error: %d\n", msg->connack_ret_code);
exit(1);
}
printf("Subscribing to '/stuff'\n");
mg_mqtt_subscribe(nc, topic_expressions, sizeof(topic_expressions)/sizeof(*topic_expressions), 42);
break;
- case NS_MQTT_PUBACK:
+ case MG_EV_MQTT_PUBACK:
printf("Message publishing acknowledged (msg_id: %d)\n", msg->message_id);
break;
- case NS_MQTT_SUBACK:
+ case MG_EV_MQTT_SUBACK:
printf("Subscription acknowledged, forwarding to '/test'\n");
break;
- case NS_MQTT_PUBLISH:
+ case MG_EV_MQTT_PUBLISH:
{
#if 0
char hex[1024] = {0};
@@ -60,10 +60,10 @@ static void ev_handler(struct mg_connection *nc, int ev, void *p) {
#endif
printf("Forwarding to /test\n");
- mg_mqtt_publish(nc, "/test", 65, NS_MQTT_QOS(0), msg->payload.p, msg->payload.len);
+ mg_mqtt_publish(nc, "/test", 65, MG_MQTT_QOS(0), msg->payload.p, msg->payload.len);
}
break;
- case NS_CLOSE:
+ case MG_EV_CLOSE:
printf("Connection closed\n");
exit(1);
}
diff --git a/examples/multithreaded_restful_server/Makefile b/examples/multithreaded_restful_server/Makefile
index 6885b8c8..7e7db3b1 100644
--- a/examples/multithreaded_restful_server/Makefile
+++ b/examples/multithreaded_restful_server/Makefile
@@ -1,6 +1,6 @@
PROG = multithreaded_restful_server
SOURCES = $(PROG).c ../../mongoose.c
-APP_FLAGS = -DNS_ENABLE_THREADS $(CFLAGS_EXTRA)
+APP_FLAGS = -DMG_ENABLE_THREADS $(CFLAGS_EXTRA)
ifeq ($(OS), Windows_NT)
APP_FLAGS += advapi32.lib
diff --git a/examples/multithreaded_restful_server/multithreaded_restful_server.c b/examples/multithreaded_restful_server/multithreaded_restful_server.c
index 3cf248d7..8287888f 100644
--- a/examples/multithreaded_restful_server/multithreaded_restful_server.c
+++ b/examples/multithreaded_restful_server/multithreaded_restful_server.c
@@ -12,7 +12,7 @@
static const char *s_http_port = "8000";
static void ev_handler(struct mg_connection *c, int ev, void *p) {
- if (ev == NS_HTTP_REQUEST) {
+ if (ev == MG_EV_HTTP_REQUEST) {
struct http_message *hm = (struct http_message *) p;
char reply[100];
diff --git a/examples/netcat/Makefile b/examples/netcat/Makefile
index 62c8d161..71b75b92 100644
--- a/examples/netcat/Makefile
+++ b/examples/netcat/Makefile
@@ -1,6 +1,6 @@
PROG = nc
SOURCES = $(PROG).c ../../mongoose.c
-CFLAGS = -W -Wall -I../.. -pthread -DNS_ENABLE_SSL -DNS_ENABLE_THREADS -lssl -lcrypto $(CFLAGS_EXTRA)
+CFLAGS = -W -Wall -I../.. -pthread -DMG_ENABLE_SSL -DMG_ENABLE_THREADS -lssl -lcrypto $(CFLAGS_EXTRA)
all: $(PROG)
@@ -8,7 +8,7 @@ $(PROG): $(SOURCES)
$(CC) $(SOURCES) -o $@ $(CFLAGS)
$(PROG).exe: $(SOURCES)
- cl $(SOURCES) /I../.. /DNS_ENABLE_SSL /MD /Fe$@
+ cl $(SOURCES) /I../.. /DMG_ENABLE_SSL /MD /Fe$@
clean:
rm -rf *.gc* *.dSYM *.exe *.obj *.o a.out $(PROG)
diff --git a/examples/netcat/nc.c b/examples/netcat/nc.c
index eceb6583..e4bbaf5f 100644
--- a/examples/netcat/nc.c
+++ b/examples/netcat/nc.c
@@ -46,9 +46,9 @@ static void on_stdin_read(struct mg_connection *nc, int ev, void *p) {
if (ch < 0) {
// EOF is received from stdin. Schedule the connection to close
- nc->flags |= NSF_SEND_AND_CLOSE;
+ nc->flags |= MG_F_SEND_AND_CLOSE;
if (nc->send_mbuf.len <= 0) {
- nc->flags |= NSF_CLOSE_IMMEDIATELY;
+ nc->flags |= MG_F_CLOSE_IMMEDIATELY;
}
} else {
// A character is received from stdin. Send it to the connection.
@@ -74,16 +74,16 @@ static void ev_handler(struct mg_connection *nc, int ev, void *p) {
(void) p;
switch (ev) {
- case NS_ACCEPT:
- case NS_CONNECT:
+ case MG_EV_ACCEPT:
+ case MG_EV_CONNECT:
mg_start_thread(stdio_thread_func, nc->mgr);
break;
- case NS_CLOSE:
+ case MG_EV_CLOSE:
s_received_signal = 1;
break;
- case NS_RECV:
+ case MG_EV_RECV:
fwrite(nc->recv_mbuf.buf, 1, nc->recv_mbuf.len, stdout);
mbuf_remove(&nc->recv_mbuf, nc->recv_mbuf.len);
break;
diff --git a/examples/publish_subscribe/Makefile b/examples/publish_subscribe/Makefile
index 8330d2b9..98f2900a 100644
--- a/examples/publish_subscribe/Makefile
+++ b/examples/publish_subscribe/Makefile
@@ -1,6 +1,6 @@
PROG = publish_subscribe
SOURCES = $(PROG).c ../../mongoose.c
-CFLAGS = -W -Wall -I../.. -DNS_ENABLE_THREADS -pthread $(CFLAGS_EXTRA)
+CFLAGS = -W -Wall -I../.. -DMG_ENABLE_THREADS -pthread $(CFLAGS_EXTRA)
all: $(PROG)
diff --git a/examples/publish_subscribe/publish_subscribe.c b/examples/publish_subscribe/publish_subscribe.c
index 0ce5b6d5..3f601249 100644
--- a/examples/publish_subscribe/publish_subscribe.c
+++ b/examples/publish_subscribe/publish_subscribe.c
@@ -29,7 +29,7 @@ static void *stdin_thread(void *param) {
static void server_handler(struct mg_connection *nc, int ev, void *p) {
(void) p;
- if (ev == NS_RECV) {
+ if (ev == MG_EV_RECV) {
// Push received message to all ncections
struct mbuf *io = &nc->recv_mbuf;
struct mg_connection *c;
@@ -45,14 +45,14 @@ static void client_handler(struct mg_connection *conn, int ev, void *p) {
struct mbuf *io = &conn->recv_mbuf;
(void) p;
- if (ev == NS_CONNECT) {
- if (conn->flags & NSF_CLOSE_IMMEDIATELY) {
+ if (ev == MG_EV_CONNECT) {
+ if (conn->flags & MG_F_CLOSE_IMMEDIATELY) {
printf("%s\n", "Error connecting to server!");
exit(EXIT_FAILURE);
}
printf("%s\n", "Connected to server. Type a message and press enter.");
- } else if (ev == NS_RECV) {
- if (conn->flags & NSF_USER_1) {
+ } else if (ev == MG_EV_RECV) {
+ if (conn->flags & MG_F_USER_1) {
// Received data from the stdin, forward it to the server
struct mg_connection *c = (struct mg_connection *) conn->user_data;
mg_send(c, io->buf, io->len);
@@ -62,7 +62,7 @@ static void client_handler(struct mg_connection *conn, int ev, void *p) {
fwrite(io->buf, io->len, 1, stdout);
mbuf_remove(io, io->len);
}
- } else if (ev == NS_CLOSE) {
+ } else if (ev == MG_EV_CLOSE) {
// Connection has closed, most probably cause server has stopped
exit(EXIT_SUCCESS);
}
@@ -93,7 +93,7 @@ int main(int argc, char *argv[]) {
// The other end of a pair goes inside the server
ioconn = mg_add_sock(&mgr, fds[0], client_handler);
- ioconn->flags |= NSF_USER_1; // Mark this so we know this is a stdin
+ ioconn->flags |= MG_F_USER_1; // Mark this so we know this is a stdin
ioconn->user_data = server_conn;
} else {
diff --git a/examples/raspberry_pi_mjpeg_led/Makefile b/examples/raspberry_pi_mjpeg_led/Makefile
index cb56be58..31ed1a44 100644
--- a/examples/raspberry_pi_mjpeg_led/Makefile
+++ b/examples/raspberry_pi_mjpeg_led/Makefile
@@ -1,6 +1,6 @@
NS=../../mongoose.c
FLAGS = ../../mongoose.c -I../..
-CFLAGS=-W -Wall -DNS_ENABLE_THREADS -pthread $(CFLAGS_EXTRA)
+CFLAGS=-W -Wall -DMG_ENABLE_THREADS -pthread $(CFLAGS_EXTRA)
PROGS = device_side cloud_side
all: $(PROGS)
diff --git a/examples/raspberry_pi_mjpeg_led/cloud_side.c b/examples/raspberry_pi_mjpeg_led/cloud_side.c
index 15341305..987cb9be 100644
--- a/examples/raspberry_pi_mjpeg_led/cloud_side.c
+++ b/examples/raspberry_pi_mjpeg_led/cloud_side.c
@@ -28,11 +28,11 @@ static void push_frame_to_clients(struct mg_mgr *mgr,
const struct websocket_message *wm) {
struct mg_connection *nc;
/*
- * mjpeg connections are tagged with the NSF_USER_2 flag so we can find them
+ * mjpeg connections are tagged with the MG_F_USER_2 flag so we can find them
* my scanning the connection list provided by the mongoose manager.
*/
for (nc = mg_next(mgr, NULL); nc != NULL; nc = mg_next(mgr, nc)) {
- if (!(nc->flags & NSF_USER_2)) continue; // Ignore un-marked requests
+ if (!(nc->flags & MG_F_USER_2)) continue; // Ignore un-marked requests
mg_printf(nc, "--w00t\r\nContent-Type: image/jpeg\r\n"
"Content-Length: %lu\r\n\r\n", (unsigned long) wm->size);
@@ -50,7 +50,7 @@ static void send_command_to_the_device(struct mg_mgr *mgr,
const struct mg_str *cmd) {
struct mg_connection *nc;
for (nc = mg_next(mgr, NULL); nc != NULL; nc = mg_next(mgr, nc)) {
- if (!(nc->flags & NSF_IS_WEBSOCKET)) continue; // Ignore non-websocket requests
+ if (!(nc->flags & MG_F_IS_WEBSOCKET)) continue; // Ignore non-websocket requests
mg_send_websocket_frame(nc, WEBSOCKET_OP_TEXT, cmd->p, cmd->len);
printf("Sent API command [%.*s] to %p\n", (int) cmd->len, cmd->p, nc);
@@ -73,9 +73,9 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
struct http_message *hm = (struct http_message *) ev_data;
switch (ev) {
- case NS_HTTP_REQUEST:
+ case MG_EV_HTTP_REQUEST:
if (mg_vcmp(&hm->uri, "/mjpg") == 0) {
- nc->flags |= NSF_USER_2; /* Set a mark on image requests */
+ nc->flags |= MG_F_USER_2; /* Set a mark on image requests */
mg_printf(nc, "%s",
"HTTP/1.0 200 OK\r\n"
"Cache-Control: no-cache\r\n"
@@ -99,7 +99,7 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
mg_serve_http(nc, hm, web_root_opts);
}
break;
- case NS_WEBSOCKET_FRAME:
+ case MG_EV_WEBSOCKET_FRAME:
printf("Got websocket frame, size %lu\n", (unsigned long) wm->size);
push_frame_to_clients(nc->mgr, wm);
break;
diff --git a/examples/raspberry_pi_mjpeg_led/device_side.c b/examples/raspberry_pi_mjpeg_led/device_side.c
index 90989f9c..fbca7559 100644
--- a/examples/raspberry_pi_mjpeg_led/device_side.c
+++ b/examples/raspberry_pi_mjpeg_led/device_side.c
@@ -85,7 +85,7 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
struct websocket_message *wm = (struct websocket_message *) ev_data;
switch (ev) {
- case NS_CONNECT:
+ case MG_EV_CONNECT:
printf("Reconnect: %s\n", * (int *) ev_data == 0 ? "ok" : "failed");
if (* (int *) ev_data == 0) {
/*
@@ -102,14 +102,14 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
mg_send_websocket_handshake(nc, "/stream", NULL);
}
break;
- case NS_CLOSE:
+ case MG_EV_CLOSE:
printf("Connection %p closed\n", nc);
client = NULL;
break;
- case NS_POLL:
+ case MG_EV_POLL:
send_mjpg_frame(nc, s_mjpg_file);
break;
- case NS_WEBSOCKET_FRAME:
+ case MG_EV_WEBSOCKET_FRAME:
printf("Got control command: [%.*s]\n", (int) wm->size, wm->data);
perform_control_command((const char*)wm->data, wm->size);
break;
diff --git a/examples/restful_client/restful_client.c b/examples/restful_client/restful_client.c
index ec73f894..e29e607f 100644
--- a/examples/restful_client/restful_client.c
+++ b/examples/restful_client/restful_client.c
@@ -16,7 +16,7 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
int connect_status;
switch (ev) {
- case NS_CONNECT:
+ case MG_EV_CONNECT:
connect_status = * (int *) ev_data;
if (connect_status == 0) {
printf("Connected to %s, sending request...\n", s_target_address);
@@ -28,9 +28,9 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
s_exit_flag = 1;
}
break;
- case NS_HTTP_REPLY:
+ case MG_EV_HTTP_REPLY:
printf("Got reply:\n%.*s\n", (int) hm->body.len, hm->body.p);
- nc->flags |= NSF_SEND_AND_CLOSE;
+ nc->flags |= MG_F_SEND_AND_CLOSE;
s_exit_flag = 1;
break;
default:
diff --git a/examples/restful_server/Makefile b/examples/restful_server/Makefile
index e259c1b7..fa46eeef 100644
--- a/examples/restful_server/Makefile
+++ b/examples/restful_server/Makefile
@@ -3,9 +3,9 @@ SOURCES = $(PROG).c ../../mongoose.c
CFLAGS = -W -Wall -I../.. $(CFLAGS_EXTRA)
ifeq ($(SSL), openssl)
- CFLAGS += -DNS_ENABLE_SSL -lssl -lcrypto -lcrypto
+ CFLAGS += -DMG_ENABLE_SSL -lssl -lcrypto -lcrypto
else ifeq ($(SSL), krypton)
- CFLAGS += -DNS_ENABLE_SSL ../../../krypton/krypton.c
+ CFLAGS += -DMG_ENABLE_SSL ../../../krypton/krypton.c
endif
all: $(PROG)
@@ -14,7 +14,7 @@ $(PROG): $(SOURCES)
$(CC) $(SOURCES) -o $@ $(CFLAGS)
$(PROG).exe: $(SOURCES)
- cl $(SOURCES) /I../.. /MD /DNS_ENABLE_THREADS /Fe$@ advapi32.lib
+ cl $(SOURCES) /I../.. /MD /DMG_ENABLE_THREADS /Fe$@ advapi32.lib
clean:
rm -rf *.gc* *.dSYM *.exe *.obj *.o a.out $(PROG)
diff --git a/examples/restful_server/restful_server.c b/examples/restful_server/restful_server.c
index 80c1da19..7a1acb50 100644
--- a/examples/restful_server/restful_server.c
+++ b/examples/restful_server/restful_server.c
@@ -29,7 +29,7 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
struct http_message *hm = (struct http_message *) ev_data;
switch (ev) {
- case NS_HTTP_REQUEST:
+ case MG_EV_HTTP_REQUEST:
if (mg_vcmp(&hm->uri, "/api/v1/sum") == 0) {
handle_sum_call(nc, hm); /* Handle RESTful call */
} else if (mg_vcmp(&hm->uri, "/printcontent") == 0) {
@@ -51,7 +51,7 @@ int main(int argc, char *argv[]) {
struct mg_connection *nc;
int i;
char *cp;
-#ifdef NS_ENABLE_SSL
+#ifdef MG_ENABLE_SSL
const char *ssl_cert = NULL;
#endif
@@ -73,11 +73,11 @@ int main(int argc, char *argv[]) {
s_http_server_opts.per_directory_auth_file = argv[++i];
} else if (strcmp(argv[i], "-r") == 0 && i + 1 < argc) {
s_http_server_opts.url_rewrites = argv[++i];
-#ifndef NS_DISABLE_CGI
+#ifndef MG_DISABLE_CGI
} else if (strcmp(argv[i], "-i") == 0 && i + 1 < argc) {
s_http_server_opts.cgi_interpreter = argv[++i];
#endif
-#ifdef NS_ENABLE_SSL
+#ifdef MG_ENABLE_SSL
} else if (strcmp(argv[i], "-s") == 0 && i + 1 < argc) {
ssl_cert = argv[++i];
#endif
@@ -91,7 +91,7 @@ int main(int argc, char *argv[]) {
exit(1);
}
-#ifdef NS_ENABLE_SSL
+#ifdef MG_ENABLE_SSL
if (ssl_cert != NULL) {
const char *err_str = mg_set_ssl(nc, ssl_cert, NULL);
if (err_str != NULL) {
diff --git a/examples/restful_server_s3/Makefile b/examples/restful_server_s3/Makefile
index 55fccbcb..224555f4 100644
--- a/examples/restful_server_s3/Makefile
+++ b/examples/restful_server_s3/Makefile
@@ -3,9 +3,9 @@ SOURCES = $(PROG).c ../../mongoose.c
CFLAGS = -W -Wall -I../.. $(CFLAGS_EXTRA)
ifeq ($(SSL), openssl)
- CFLAGS += -DNS_ENABLE_SSL -lssl -lcrypto -lcrypto
+ CFLAGS += -DMG_ENABLE_SSL -lssl -lcrypto -lcrypto
else ifeq ($(SSL), krypton)
- CFLAGS += -DNS_ENABLE_SSL ../../../krypton/krypton.c
+ CFLAGS += -DMG_ENABLE_SSL ../../../krypton/krypton.c
endif
all: $(PROG)
@@ -14,7 +14,7 @@ $(PROG): $(SOURCES)
$(CC) $(SOURCES) -o $@ $(CFLAGS)
$(PROG).exe: $(SOURCES)
- cl $(SOURCES) /I../.. /MD /DNS_ENABLE_THREADS /Fe$@ advapi32.lib
+ cl $(SOURCES) /I../.. /MD /DMG_ENABLE_THREADS /Fe$@ advapi32.lib
clean:
rm -rf *.gc* *.dSYM *.exe *.obj *.o a.out $(PROG)
diff --git a/examples/restful_server_s3/restful_server_s3.c b/examples/restful_server_s3/restful_server_s3.c
index 90536cd2..a3731f98 100644
--- a/examples/restful_server_s3/restful_server_s3.c
+++ b/examples/restful_server_s3/restful_server_s3.c
@@ -34,16 +34,16 @@ static void s3_handler(struct mg_connection *nc, int ev, void *ev_data) {
struct mg_connection *nc2 = (struct mg_connection *) nc->user_data;
switch (ev) {
- case NS_HTTP_REPLY:
+ case MG_EV_HTTP_REPLY:
if (nc2 != NULL) {
mg_printf_http_chunk(nc2, "Error: %.*s", (int) hm->message.len,
hm->message.p);
mg_send_http_chunk(nc2, "", 0);
}
unlink_conns(nc);
- nc->flags |= NSF_SEND_AND_CLOSE;
+ nc->flags |= MG_F_SEND_AND_CLOSE;
break;
- case NS_CLOSE:
+ case MG_EV_CLOSE:
unlink_conns(nc);
break;
default:
@@ -118,14 +118,14 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
struct http_message *hm = (struct http_message *) ev_data;
switch (ev) {
- case NS_HTTP_REQUEST:
+ case MG_EV_HTTP_REQUEST:
if (mg_vcmp(&hm->uri, "/upload") == 0) {
handle_api_call(nc, hm); /* Handle RESTful call */
} else {
mg_serve_http(nc, hm, s_http_server_opts); /* Serve static content */
}
break;
- case NS_CLOSE:
+ case MG_EV_CLOSE:
unlink_conns(nc);
break;
default:
diff --git a/examples/rules.mk b/examples/rules.mk
index 0d40124c..06502591 100644
--- a/examples/rules.mk
+++ b/examples/rules.mk
@@ -1,5 +1,5 @@
SOURCES = $(PROG).c ../../mongoose.c
-CFLAGS = -W -Wall -I../.. -pthread -DNS_ENABLE_SSL -DNS_ENABLE_IPV6 -DNS_ENABLE_THREADS -lssl -lcrypto $(CFLAGS_EXTRA) $(MODULE_CFLAGS)
+CFLAGS = -W -Wall -I../.. -pthread -DMG_ENABLE_SSL -DMG_ENABLE_IPV6 -DMG_ENABLE_THREADS -lssl -lcrypto $(CFLAGS_EXTRA) $(MODULE_CFLAGS)
all: $(PROG)
@@ -7,7 +7,7 @@ $(PROG): $(SOURCES)
$(CC) $(SOURCES) -o $@ $(CFLAGS)
$(PROG).exe: $(SOURCES)
- cl $(SOURCES) /I../.. /DNS_ENABLE_SSL /MD /Fe$@
+ cl $(SOURCES) /I../.. /DMG_ENABLE_SSL /MD /Fe$@
clean:
rm -rf *.gc* *.dSYM *.exe *.obj *.o a.out $(PROG)
diff --git a/examples/settings_panel_for_a_device/Makefile b/examples/settings_panel_for_a_device/Makefile
index eb3fab97..ff57b6f4 100644
--- a/examples/settings_panel_for_a_device/Makefile
+++ b/examples/settings_panel_for_a_device/Makefile
@@ -1,6 +1,6 @@
PROG = settings_panel
SOURCES = $(PROG).c ../../mongoose.c
-CFLAGS = -W -Wall -I../.. -DNS_ENABLE_SSL -lssl -lcrypto $(CFLAGS_EXTRA)
+CFLAGS = -W -Wall -I../.. -DMG_ENABLE_SSL -lssl -lcrypto $(CFLAGS_EXTRA)
all: $(PROG)
diff --git a/examples/settings_panel_for_a_device/settings_panel.c b/examples/settings_panel_for_a_device/settings_panel.c
index 6772075a..26206e24 100644
--- a/examples/settings_panel_for_a_device/settings_panel.c
+++ b/examples/settings_panel_for_a_device/settings_panel.c
@@ -38,14 +38,14 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
struct http_message *hm = (struct http_message *) ev_data;
switch (ev) {
- case NS_HTTP_REQUEST:
+ case MG_EV_HTTP_REQUEST:
if (mg_vcmp(&hm->uri, "/save") == 0) {
handle_save(nc, hm); /* Handle RESTful call */
} else {
mg_serve_http(nc, hm, s_http_server_opts); /* Serve static content */
}
break;
- case NS_SSI_CALL:
+ case MG_EV_SSI_CALL:
handle_ssi_call(nc, ev_data);
break;
default:
diff --git a/examples/settings_panel_for_a_device/web_root/index.shtml b/examples/settings_panel_for_a_device/web_root/index.shtml
index 8bdb432d..c0f113e8 100644
--- a/examples/settings_panel_for_a_device/web_root/index.shtml
+++ b/examples/settings_panel_for_a_device/web_root/index.shtml
@@ -67,7 +67,7 @@
How to show device parameters on the page
This page has embedded
<!--#call parameter_name -->
blocks. For each such
- block, mongoose triggers NS_SSI_CALL
event, passing
+ block, mongoose triggers MG_EV_SSI_CALL
event, passing
parameter_name
string as an event parameter. A callback
then can print some content, which will replace the
<!--#call parameter_name -->
block.
diff --git a/examples/simplest_web_server/simplest_web_server.c b/examples/simplest_web_server/simplest_web_server.c
index 479f94d1..af0b3fda 100644
--- a/examples/simplest_web_server/simplest_web_server.c
+++ b/examples/simplest_web_server/simplest_web_server.c
@@ -7,7 +7,7 @@ static const char *s_http_port = "8000";
static struct mg_serve_http_opts s_http_server_opts;
static void ev_handler(struct mg_connection *nc, int ev, void *p) {
- if (ev == NS_HTTP_REQUEST) {
+ if (ev == MG_EV_HTTP_REQUEST) {
mg_serve_http(nc, p, s_http_server_opts);
}
}
diff --git a/examples/tcp_echo_server/echo_server.c b/examples/tcp_echo_server/echo_server.c
index a2700db6..ad16a311 100644
--- a/examples/tcp_echo_server/echo_server.c
+++ b/examples/tcp_echo_server/echo_server.c
@@ -23,7 +23,7 @@ static void ev_handler(struct mg_connection *nc, int ev, void *p) {
(void) p;
switch (ev) {
- case NS_RECV:
+ case MG_EV_RECV:
mg_send(nc, io->buf, io->len); // Echo message back
mbuf_remove(io, io->len); // Discard message from recv buffer
break;
diff --git a/examples/websocket_chat/websocket_chat.c b/examples/websocket_chat/websocket_chat.c
index 34411c1d..a9bf9d87 100644
--- a/examples/websocket_chat/websocket_chat.c
+++ b/examples/websocket_chat/websocket_chat.c
@@ -15,7 +15,7 @@ static void signal_handler(int sig_num) {
}
static int is_websocket(const struct mg_connection *nc) {
- return nc->flags & NSF_IS_WEBSOCKET;
+ return nc->flags & MG_F_IS_WEBSOCKET;
}
static void broadcast(struct mg_connection *nc, const char *msg, size_t len) {
@@ -33,20 +33,20 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
struct websocket_message *wm = (struct websocket_message *) ev_data;
switch (ev) {
- case NS_HTTP_REQUEST:
+ case MG_EV_HTTP_REQUEST:
/* Usual HTTP request - serve static files */
mg_serve_http(nc, hm, s_http_server_opts);
- nc->flags |= NSF_SEND_AND_CLOSE;
+ nc->flags |= MG_F_SEND_AND_CLOSE;
break;
- case NS_WEBSOCKET_HANDSHAKE_DONE:
+ case MG_EV_WEBSOCKET_HANDSHAKE_DONE:
/* New websocket connection. Tell everybody. */
broadcast(nc, "joined", 6);
break;
- case NS_WEBSOCKET_FRAME:
+ case MG_EV_WEBSOCKET_FRAME:
/* New websocket message. Tell everybody. */
broadcast(nc, (char *) wm->data, wm->size);
break;
- case NS_CLOSE:
+ case MG_EV_CLOSE:
/* Disconnect. Tell everybody. */
if (is_websocket(nc)) {
broadcast(nc, "left", 4);
diff --git a/mongoose.c b/mongoose.c
index c7bb2b19..981807ad 100644
--- a/mongoose.c
+++ b/mongoose.c
@@ -8,76 +8,76 @@
* All rights reserved
*/
-#ifndef NS_INTERNAL_HEADER_INCLUDED
-#define NS_INTERNAL_HEADER_INCLUDED
+#ifndef MG_INTERNAL_HEADER_INCLUDED
+#define MG_INTERNAL_HEADER_INCLUDED
-#ifndef NS_MALLOC
-#define NS_MALLOC malloc
+#ifndef MG_MALLOC
+#define MG_MALLOC malloc
#endif
-#ifndef NS_CALLOC
-#define NS_CALLOC calloc
+#ifndef MG_CALLOC
+#define MG_CALLOC calloc
#endif
-#ifndef NS_REALLOC
-#define NS_REALLOC realloc
+#ifndef MG_REALLOC
+#define MG_REALLOC realloc
#endif
-#ifndef NS_FREE
-#define NS_FREE free
+#ifndef MG_FREE
+#define MG_FREE free
#endif
#ifndef MBUF_REALLOC
-#define MBUF_REALLOC NS_REALLOC
+#define MBUF_REALLOC MG_REALLOC
#endif
#ifndef MBUF_FREE
-#define MBUF_FREE NS_FREE
+#define MBUF_FREE MG_FREE
#endif
-#define NS_SET_PTRPTR(_ptr, _v) \
+#define MG_SET_PTRPTR(_ptr, _v) \
do { \
if (_ptr) *(_ptr) = _v; \
} while (0)
-#ifndef NS_INTERNAL
-#define NS_INTERNAL static
+#ifndef MG_INTERNAL
+#define MG_INTERNAL static
#endif
-#if !defined(NS_MGR_EV_MGR) && defined(__linux__)
-#define NS_MGR_EV_MGR 1 /* epoll() */
+#if !defined(MG_MGR_EV_MGR) && defined(__linux__)
+#define MG_MGR_EV_MGR 1 /* epoll() */
#endif
-#if !defined(NS_MGR_EV_MGR)
-#define NS_MGR_EV_MGR 0 /* select() */
+#if !defined(MG_MGR_EV_MGR)
+#define MG_MGR_EV_MGR 0 /* select() */
#endif
#ifdef PICOTCP
#define NO_LIBC
-#define NS_DISABLE_FILESYSTEM
-#define NS_DISABLE_POPEN
-#define NS_DISABLE_CGI
-#define NS_DISABLE_DIRECTORY_LISTING
-#define NS_DISABLE_SOCKETPAIR
-#define NS_DISABLE_PFS
+#define MG_DISABLE_FILESYSTEM
+#define MG_DISABLE_POPEN
+#define MG_DISABLE_CGI
+#define MG_DISABLE_DIRECTORY_LISTING
+#define MG_DISABLE_SOCKETPAIR
+#define MG_DISABLE_PFS
#endif
/* Amalgamated: #include "../mongoose.h" */
/* internals that need to be accessible in unit tests */
-NS_INTERNAL struct mg_connection *mg_finish_connect(struct mg_connection *nc,
+MG_INTERNAL struct mg_connection *mg_finish_connect(struct mg_connection *nc,
int proto,
union socket_address *sa,
struct mg_add_sock_opts);
-NS_INTERNAL int mg_parse_address(const char *str, union socket_address *sa,
+MG_INTERNAL int mg_parse_address(const char *str, union socket_address *sa,
int *proto, char *host, size_t host_len);
-NS_INTERNAL void mg_call(struct mg_connection *, int ev, void *ev_data);
-NS_INTERNAL void mg_forward(struct mg_connection *, struct mg_connection *);
-NS_INTERNAL void mg_add_conn(struct mg_mgr *mgr, struct mg_connection *c);
-NS_INTERNAL void mg_remove_conn(struct mg_connection *c);
+MG_INTERNAL void mg_call(struct mg_connection *, int ev, void *ev_data);
+MG_INTERNAL void mg_forward(struct mg_connection *, struct mg_connection *);
+MG_INTERNAL void mg_add_conn(struct mg_mgr *mgr, struct mg_connection *c);
+MG_INTERNAL void mg_remove_conn(struct mg_connection *c);
-#ifndef NS_DISABLE_FILESYSTEM
-NS_INTERNAL int find_index_file(char *, size_t, const char *, cs_stat_t *);
+#ifndef MG_DISABLE_FILESYSTEM
+MG_INTERNAL int find_index_file(char *, size_t, const char *, cs_stat_t *);
#endif
#ifdef _WIN32
@@ -90,12 +90,12 @@ void to_wchar(const char *path, wchar_t *wbuf, size_t wbuf_len);
* beginning of the buffer.
*
* If chunks get reassembled, modify hm->body to point to the reassembled
- * body and fire NS_HTTP_CHUNK event. If handler sets NSF_DELETE_CHUNK
+ * body and fire MG_EV_HTTP_CHUNK event. If handler sets MG_F_DELETE_CHUNK
* in nc->flags, delete reassembled body from the mbuf.
*
* Return reassembled body size.
*/
-NS_INTERNAL size_t mg_handle_chunked(struct mg_connection *nc,
+MG_INTERNAL size_t mg_handle_chunked(struct mg_connection *nc,
struct http_message *hm, char *buf,
size_t blen);
@@ -103,7 +103,7 @@ NS_INTERNAL size_t mg_handle_chunked(struct mg_connection *nc,
extern void *(*test_malloc)(size_t);
extern void *(*test_calloc)(size_t, size_t);
-#endif /* NS_INTERNAL_HEADER_INCLUDED */
+#endif /* MG_INTERNAL_HEADER_INCLUDED */
#ifdef NS_MODULE_LINES
#line 1 "src/../../common/mbuf.c"
/**/
@@ -1118,12 +1118,12 @@ void to_wchar(const char *path, wchar_t *wbuf, size_t wbuf_len) {
* for systems which do not natively support it (e.g. Windows).
*/
-#ifndef NS_FREE
-#define NS_FREE free
+#ifndef MG_FREE
+#define MG_FREE free
#endif
-#ifndef NS_MALLOC
-#define NS_MALLOC malloc
+#ifndef MG_MALLOC
+#define MG_MALLOC malloc
#endif
#ifdef _WIN32
@@ -1134,7 +1134,7 @@ DIR *opendir(const char *name) {
if (name == NULL) {
SetLastError(ERROR_BAD_ARGUMENTS);
- } else if ((dir = (DIR *) NS_MALLOC(sizeof(*dir))) == NULL) {
+ } else if ((dir = (DIR *) MG_MALLOC(sizeof(*dir))) == NULL) {
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
} else {
to_wchar(name, wpath, ARRAY_SIZE(wpath));
@@ -1144,7 +1144,7 @@ DIR *opendir(const char *name) {
dir->handle = FindFirstFileW(wpath, &dir->info);
dir->result.d_name[0] = '\0';
} else {
- NS_FREE(dir);
+ MG_FREE(dir);
dir = NULL;
}
}
@@ -1158,7 +1158,7 @@ int closedir(DIR *dir) {
if (dir != NULL) {
if (dir->handle != INVALID_HANDLE_VALUE)
result = FindClose(dir->handle) ? 0 : -1;
- NS_FREE(dir);
+ MG_FREE(dir);
} else {
result = -1;
SetLastError(ERROR_BAD_ARGUMENTS);
@@ -1719,28 +1719,28 @@ int json_emit(char *buf, int buf_len, const char *fmt, ...) {
/* Amalgamated: #include "internal.h" */
-#if NS_MGR_EV_MGR == 1 /* epoll() */
+#if MG_MGR_EV_MGR == 1 /* epoll() */
#include
#endif
-#define NS_CTL_MSG_MESSAGE_SIZE 8192
-#define NS_READ_BUFFER_SIZE 1024
-#define NS_UDP_RECEIVE_BUFFER_SIZE 1500
-#define NS_VPRINTF_BUFFER_SIZE 100
-#define NS_MAX_HOST_LEN 200
+#define MG_CTL_MSG_MESSAGE_SIZE 8192
+#define MG_READ_BUFFER_SIZE 1024
+#define MG_UDP_RECEIVE_BUFFER_SIZE 1500
+#define MG_VPRINTF_BUFFER_SIZE 100
+#define MG_MAX_HOST_LEN 200
-#define NS_COPY_COMMON_CONNECTION_OPTIONS(dst, src) \
+#define MG_COPY_COMMON_CONNECTION_OPTIONS(dst, src) \
memcpy(dst, src, sizeof(*dst));
/* Which flags can be pre-set by the user at connection creation time. */
-#define _NS_ALLOWED_CONNECT_FLAGS_MASK \
- (NSF_USER_1 | NSF_USER_2 | NSF_USER_3 | NSF_USER_4 | NSF_USER_5 | \
- NSF_USER_6 | NSF_WEBSOCKET_NO_DEFRAG)
+#define _MG_ALLOWED_CONNECT_FLAGS_MASK \
+ (MG_F_USER_1 | MG_F_USER_2 | MG_F_USER_3 | MG_F_USER_4 | MG_F_USER_5 | \
+ MG_F_USER_6 | MG_F_WEBSOCKET_NO_DEFRAG)
/* Which flags should be modifiable by user's callbacks. */
-#define _NS_CALLBACK_MODIFIABLE_FLAGS_MASK \
- (NSF_USER_1 | NSF_USER_2 | NSF_USER_3 | NSF_USER_4 | NSF_USER_5 | \
- NSF_USER_6 | NSF_WEBSOCKET_NO_DEFRAG | NSF_SEND_AND_CLOSE | NSF_DONT_SEND | \
- NSF_CLOSE_IMMEDIATELY | NSF_IS_WEBSOCKET)
+#define _MG_CALLBACK_MODIFIABLE_FLAGS_MASK \
+ (MG_F_USER_1 | MG_F_USER_2 | MG_F_USER_3 | MG_F_USER_4 | MG_F_USER_5 | \
+ MG_F_USER_6 | MG_F_WEBSOCKET_NO_DEFRAG | MG_F_SEND_AND_CLOSE | \
+ MG_F_DONT_SEND | MG_F_CLOSE_IMMEDIATELY | MG_F_IS_WEBSOCKET)
#ifndef intptr_t
#define intptr_t long
@@ -1748,7 +1748,7 @@ int json_emit(char *buf, int buf_len, const char *fmt, ...) {
struct ctl_msg {
mg_event_handler_t callback;
- char message[NS_CTL_MSG_MESSAGE_SIZE];
+ char message[MG_CTL_MSG_MESSAGE_SIZE];
};
static void mg_ev_mgr_init(struct mg_mgr *mgr);
@@ -1756,7 +1756,7 @@ static void mg_ev_mgr_free(struct mg_mgr *mgr);
static void mg_ev_mgr_add_conn(struct mg_connection *nc);
static void mg_ev_mgr_remove_conn(struct mg_connection *nc);
-NS_INTERNAL void mg_add_conn(struct mg_mgr *mgr, struct mg_connection *c) {
+MG_INTERNAL void mg_add_conn(struct mg_mgr *mgr, struct mg_connection *c) {
c->mgr = mgr;
c->next = mgr->active_connections;
mgr->active_connections = c;
@@ -1765,25 +1765,25 @@ NS_INTERNAL void mg_add_conn(struct mg_mgr *mgr, struct mg_connection *c) {
mg_ev_mgr_add_conn(c);
}
-NS_INTERNAL void mg_remove_conn(struct mg_connection *conn) {
+MG_INTERNAL void mg_remove_conn(struct mg_connection *conn) {
if (conn->prev == NULL) conn->mgr->active_connections = conn->next;
if (conn->prev) conn->prev->next = conn->next;
if (conn->next) conn->next->prev = conn->prev;
mg_ev_mgr_remove_conn(conn);
}
-NS_INTERNAL void mg_call(struct mg_connection *nc, int ev, void *ev_data) {
+MG_INTERNAL void mg_call(struct mg_connection *nc, int ev, void *ev_data) {
unsigned long flags_before;
mg_event_handler_t ev_handler;
DBG(("%p flags=%lu ev=%d ev_data=%p rmbl=%d", nc, nc->flags, ev, ev_data,
(int) nc->recv_mbuf.len));
-#ifndef NS_DISABLE_FILESYSTEM
+#ifndef MG_DISABLE_FILESYSTEM
/* LCOV_EXCL_START */
- if (nc->mgr->hexdump_file != NULL && ev != NS_POLL &&
- ev != NS_SEND /* handled separately */) {
- int len = (ev == NS_RECV ? *(int *) ev_data : 0);
+ if (nc->mgr->hexdump_file != NULL && ev != MG_EV_POLL &&
+ ev != MG_EV_SEND /* handled separately */) {
+ int len = (ev == MG_EV_RECV ? *(int *) ev_data : 0);
mg_hexdump_connection(nc, nc->mgr->hexdump_file, len, ev);
}
/* LCOV_EXCL_STOP */
@@ -1798,15 +1798,15 @@ NS_INTERNAL void mg_call(struct mg_connection *nc, int ev, void *ev_data) {
flags_before = nc->flags;
ev_handler(nc, ev, ev_data);
if (nc->flags != flags_before) {
- nc->flags = (flags_before & ~_NS_CALLBACK_MODIFIABLE_FLAGS_MASK) |
- (nc->flags & _NS_CALLBACK_MODIFIABLE_FLAGS_MASK);
+ nc->flags = (flags_before & ~_MG_CALLBACK_MODIFIABLE_FLAGS_MASK) |
+ (nc->flags & _MG_CALLBACK_MODIFIABLE_FLAGS_MASK);
}
}
DBG(("call done, flags %d", (int) nc->flags));
}
static size_t mg_out(struct mg_connection *nc, const void *buf, size_t len) {
- if (nc->flags & NSF_UDP) {
+ if (nc->flags & MG_F_UDP) {
int n = sendto(nc->sock, buf, len, 0, &nc->sa.sa, sizeof(nc->sa.sin));
DBG(("%p %d %d %d %s:%hu", nc, nc->sock, n, errno,
inet_ntoa(nc->sa.sin.sin_addr), ntohs(nc->sa.sin.sin_port)));
@@ -1830,7 +1830,7 @@ static void mg_destroy_conn(struct mg_connection *conn) {
}
mbuf_free(&conn->recv_mbuf);
mbuf_free(&conn->send_mbuf);
-#ifdef NS_ENABLE_SSL
+#ifdef MG_ENABLE_SSL
if (conn->ssl != NULL) {
SSL_free(conn->ssl);
}
@@ -1838,13 +1838,13 @@ static void mg_destroy_conn(struct mg_connection *conn) {
SSL_CTX_free(conn->ssl_ctx);
}
#endif
- NS_FREE(conn);
+ MG_FREE(conn);
}
static void mg_close_conn(struct mg_connection *conn) {
DBG(("%p %lu", conn, conn->flags));
- if (!(conn->flags & NSF_CONNECTING)) {
- mg_call(conn, NS_CLOSE, NULL);
+ if (!(conn->flags & MG_F_CONNECTING)) {
+ mg_call(conn, MG_EV_CLOSE, NULL);
}
mg_remove_conn(conn);
mg_destroy_conn(conn);
@@ -1860,19 +1860,19 @@ void mg_mgr_init(struct mg_mgr *s, void *user_data) {
WSADATA data;
WSAStartup(MAKEWORD(2, 2), &data);
}
-#elif !defined(AVR_LIBC) && !defined(NS_ESP8266)
+#elif !defined(AVR_LIBC) && !defined(MG_ESP8266)
/* Ignore SIGPIPE signal, so if client cancels the request, it
* won't kill the whole process. */
signal(SIGPIPE, SIG_IGN);
#endif
-#ifndef NS_DISABLE_SOCKETPAIR
+#ifndef MG_DISABLE_SOCKETPAIR
do {
mg_socketpair(s->ctl, SOCK_DGRAM);
} while (s->ctl[0] == INVALID_SOCKET);
#endif
-#ifdef NS_ENABLE_SSL
+#ifdef MG_ENABLE_SSL
{
static int init_done;
if (!init_done) {
@@ -1907,14 +1907,14 @@ void mg_mgr_free(struct mg_mgr *s) {
}
int mg_vprintf(struct mg_connection *nc, const char *fmt, va_list ap) {
- char mem[NS_VPRINTF_BUFFER_SIZE], *buf = mem;
+ char mem[MG_VPRINTF_BUFFER_SIZE], *buf = mem;
int len;
if ((len = mg_avprintf(&buf, sizeof(mem), fmt, ap)) > 0) {
mg_out(nc, buf, len);
}
if (buf != mem && buf != NULL) {
- NS_FREE(buf); /* LCOV_EXCL_LINE */
+ MG_FREE(buf); /* LCOV_EXCL_LINE */
} /* LCOV_EXCL_LINE */
return len;
@@ -1933,7 +1933,7 @@ static void mg_set_non_blocking_mode(sock_t sock) {
#ifdef _WIN32
unsigned long on = 1;
ioctlsocket(sock, FIONBIO, &on);
-#elif defined(NS_CC3200)
+#elif defined(MG_CC3200)
cc3200_set_non_blocking_mode(sock);
#else
int flags = fcntl(sock, F_GETFL, 0);
@@ -1941,7 +1941,7 @@ static void mg_set_non_blocking_mode(sock_t sock) {
#endif
}
-#ifndef NS_DISABLE_SOCKETPAIR
+#ifndef MG_DISABLE_SOCKETPAIR
int mg_socketpair(sock_t sp[2], int sock_type) {
union socket_address sa;
sock_t sock;
@@ -1983,11 +1983,11 @@ int mg_socketpair(sock_t sp[2], int sock_type) {
return ret;
}
-#endif /* NS_DISABLE_SOCKETPAIR */
+#endif /* MG_DISABLE_SOCKETPAIR */
/* TODO(lsm): use non-blocking resolver */
static int mg_resolve2(const char *host, struct in_addr *ina) {
-#ifdef NS_ENABLE_GETADDRINFO
+#ifdef MG_ENABLE_GETADDRINFO
int rv = 0;
struct addrinfo hints, *servinfo, *p;
struct sockaddr_in *h = NULL;
@@ -2013,7 +2013,7 @@ static int mg_resolve2(const char *host, struct in_addr *ina) {
return 1;
}
return 0;
-#endif /* NS_ENABLE_GETADDRINFO */
+#endif /* MG_ENABLE_GETADDRINFO */
}
int mg_resolve(const char *host, char *buf, size_t n) {
@@ -2021,18 +2021,18 @@ int mg_resolve(const char *host, char *buf, size_t n) {
return mg_resolve2(host, &ad) ? snprintf(buf, n, "%s", inet_ntoa(ad)) : 0;
}
-NS_INTERNAL struct mg_connection *mg_create_connection(
+MG_INTERNAL struct mg_connection *mg_create_connection(
struct mg_mgr *mgr, mg_event_handler_t callback,
struct mg_add_sock_opts opts) {
struct mg_connection *conn;
- if ((conn = (struct mg_connection *) NS_MALLOC(sizeof(*conn))) != NULL) {
+ if ((conn = (struct mg_connection *) MG_MALLOC(sizeof(*conn))) != NULL) {
memset(conn, 0, sizeof(*conn));
conn->sock = INVALID_SOCKET;
conn->handler = callback;
conn->mgr = mgr;
conn->last_io_time = time(NULL);
- conn->flags = opts.flags & _NS_ALLOWED_CONNECT_FLAGS_MASK;
+ conn->flags = opts.flags & _MG_ALLOWED_CONNECT_FLAGS_MASK;
conn->user_data = opts.user_data;
/*
* SIZE_MAX is defined as a long long constant in
@@ -2046,8 +2046,8 @@ NS_INTERNAL struct mg_connection *mg_create_connection(
}
/* Associate a socket to a connection and and add to the manager. */
-NS_INTERNAL void mg_set_sock(struct mg_connection *nc, sock_t sock) {
-#if !defined(NS_CC3200) && !defined(NS_ESP8266)
+MG_INTERNAL void mg_set_sock(struct mg_connection *nc, sock_t sock) {
+#if !defined(MG_CC3200) && !defined(MG_ESP8266)
/* Can't get non-blocking connect to work.
* TODO(rojer): Figure out why it fails where blocking succeeds.
*/
@@ -2065,7 +2065,7 @@ NS_INTERNAL void mg_set_sock(struct mg_connection *nc, sock_t sock) {
*
* HOST could be IPv4/IPv6 address or a host name.
* `host` is a destination buffer to hold parsed HOST part. Shoud be at least
- * NS_MAX_HOST_LEN bytes long.
+ * MG_MAX_HOST_LEN bytes long.
* `proto` is a returned socket type, either SOCK_STREAM or SOCK_DGRAM
*
* Return:
@@ -2073,11 +2073,11 @@ NS_INTERNAL void mg_set_sock(struct mg_connection *nc, sock_t sock) {
* 0 if HOST needs DNS lookup
* >0 length of the address string
*/
-NS_INTERNAL int mg_parse_address(const char *str, union socket_address *sa,
+MG_INTERNAL int mg_parse_address(const char *str, union socket_address *sa,
int *proto, char *host, size_t host_len) {
unsigned int a, b, c, d, port = 0;
int len = 0;
-#ifdef NS_ENABLE_IPV6
+#ifdef MG_ENABLE_IPV6
char buf[100];
#endif
@@ -2103,14 +2103,14 @@ NS_INTERNAL int mg_parse_address(const char *str, union socket_address *sa,
sa->sin.sin_addr.s_addr =
htonl(((uint32_t) a << 24) | ((uint32_t) b << 16) | c << 8 | d);
sa->sin.sin_port = htons((uint16_t) port);
-#ifdef NS_ENABLE_IPV6
+#ifdef MG_ENABLE_IPV6
} else if (sscanf(str, "[%99[^]]]:%u%n", buf, &port, &len) == 2 &&
inet_pton(AF_INET6, buf, &sa->sin6.sin6_addr)) {
/* IPv6 address, e.g. [3ffe:2a00:100:7031::1]:8080 */
sa->sin6.sin6_family = AF_INET6;
sa->sin.sin_port = htons((uint16_t) port);
#endif
-#ifndef NS_DISABLE_RESOLVER
+#ifndef MG_DISABLE_RESOLVER
} else if (strlen(str) < host_len &&
sscanf(str, "%[^ :]:%u%n", host, &port, &len) == 2) {
sa->sin.sin_port = htons((uint16_t) port);
@@ -2134,12 +2134,12 @@ static sock_t mg_open_listening_socket(union socket_address *sa, int proto) {
socklen_t sa_len =
(sa->sa.sa_family == AF_INET) ? sizeof(sa->sin) : sizeof(sa->sin6);
sock_t sock = INVALID_SOCKET;
-#ifndef NS_CC3200
+#ifndef MG_CC3200
int on = 1;
#endif
if ((sock = socket(sa->sa.sa_family, proto, 0)) != INVALID_SOCKET &&
-#ifndef NS_CC3200 /* CC3200 doesn't support either */
+#ifndef MG_CC3200 /* CC3200 doesn't support either */
#if defined(_WIN32) && defined(SO_EXCLUSIVEADDRUSE)
/* "Using SO_REUSEADDR and SO_EXCLUSIVEADDRUSE" http://goo.gl/RmrFTm */
!setsockopt(sock, SOL_SOCKET, SO_EXCLUSIVEADDRUSE, (void *) &on,
@@ -2158,11 +2158,11 @@ static sock_t mg_open_listening_socket(union socket_address *sa, int proto) {
*/
!setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void *) &on, sizeof(on)) &&
#endif
-#endif /* !NS_CC3200 */
+#endif /* !MG_CC3200 */
!bind(sock, &sa->sa, sa_len) &&
(proto == SOCK_DGRAM || listen(sock, SOMAXCONN) == 0)) {
-#ifndef NS_CC3200 /* TODO(rojer): Fix this. */
+#ifndef MG_CC3200 /* TODO(rojer): Fix this. */
mg_set_non_blocking_mode(sock);
/* In case port was set to 0, get the real port number */
(void) getsockname(sock, &sa->sa, &sa_len);
@@ -2175,7 +2175,7 @@ static sock_t mg_open_listening_socket(union socket_address *sa, int proto) {
return sock;
}
-#ifdef NS_ENABLE_SSL
+#ifdef MG_ENABLE_SSL
/*
* Certificate generation script is at
* https://github.com/cesanta/mongoose/blob/master/scripts/generate_ssl_certificates.sh
@@ -2186,7 +2186,7 @@ static sock_t mg_open_listening_socket(union socket_address *sa, int proto) {
* https://wiki.mozilla.org/Security/Server_Side_TLS#Recommended_configurations
*/
static const char mg_s_cipher_list[] =
-#if defined(NS_SSL_CRYPTO_MODERN)
+#if defined(MG_SSL_CRYPTO_MODERN)
"ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:"
"ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:"
"DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:"
@@ -2196,7 +2196,7 @@ static const char mg_s_cipher_list[] =
"DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:"
"DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:"
"!aNULL:!eNULL:!EXPORT:!DES:!RC4:!3DES:!MD5:!PSK"
-#elif defined(NS_SSL_CRYPTO_OLD)
+#elif defined(MG_SSL_CRYPTO_OLD)
"ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:"
"ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:"
"DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:"
@@ -2224,7 +2224,7 @@ static const char mg_s_cipher_list[] =
#endif
;
-#ifndef NS_DISABLE_PFS
+#ifndef MG_DISABLE_PFS
/*
* Default DH params for PFS cipher negotiation. This is a 2048-bit group.
* Will be used if none are provided by the user in the certificate file.
@@ -2259,7 +2259,7 @@ static int mg_use_cert(SSL_CTX *ctx, const char *pem_file) {
} else if (SSL_CTX_use_certificate_file(ctx, pem_file, 1) == 0 ||
SSL_CTX_use_PrivateKey_file(ctx, pem_file, 1) == 0) {
return -2;
-#ifndef NS_DISABLE_PFS
+#ifndef MG_DISABLE_PFS
} else {
BIO *bio = NULL;
DH *dh = NULL;
@@ -2312,20 +2312,20 @@ const char *mg_set_ssl(struct mg_connection *nc, const char *cert,
const char *ca_cert) {
const char *result = NULL;
- if ((nc->flags & NSF_LISTENING) &&
+ if ((nc->flags & MG_F_LISTENING) &&
(nc->ssl_ctx = SSL_CTX_new(SSLv23_server_method())) == NULL) {
result = "SSL_CTX_new() failed";
- } else if (!(nc->flags & NSF_LISTENING) &&
+ } else if (!(nc->flags & MG_F_LISTENING) &&
(nc->ssl_ctx = SSL_CTX_new(SSLv23_client_method())) == NULL) {
result = "SSL_CTX_new() failed";
} else if (mg_use_cert(nc->ssl_ctx, cert) != 0) {
result = "Invalid ssl cert";
} else if (mg_use_ca_cert(nc->ssl_ctx, ca_cert) != 0) {
result = "Invalid CA cert";
- } else if (!(nc->flags & NSF_LISTENING) &&
+ } else if (!(nc->flags & MG_F_LISTENING) &&
(nc->ssl = SSL_new(nc->ssl_ctx)) == NULL) {
result = "SSL_new() failed";
- } else if (!(nc->flags & NSF_LISTENING) && nc->sock != INVALID_SOCKET) {
+ } else if (!(nc->flags & MG_F_LISTENING) && nc->sock != INVALID_SOCKET) {
/*
* Socket is open here only if we are connecting to IP address
* and does not open if we are connecting using async DNS resolver
@@ -2342,11 +2342,11 @@ const char *mg_set_ssl(struct mg_connection *nc, const char *cert,
static int mg_ssl_err(struct mg_connection *conn, int res) {
int ssl_err = SSL_get_error(conn->ssl, res);
- if (ssl_err == SSL_ERROR_WANT_READ) conn->flags |= NSF_WANT_READ;
- if (ssl_err == SSL_ERROR_WANT_WRITE) conn->flags |= NSF_WANT_WRITE;
+ if (ssl_err == SSL_ERROR_WANT_READ) conn->flags |= MG_F_WANT_READ;
+ if (ssl_err == SSL_ERROR_WANT_WRITE) conn->flags |= MG_F_WANT_WRITE;
return ssl_err;
}
-#endif /* NS_ENABLE_SSL */
+#endif /* MG_ENABLE_SSL */
static struct mg_connection *accept_conn(struct mg_connection *ls) {
struct mg_connection *c = NULL;
@@ -2358,7 +2358,7 @@ static struct mg_connection *accept_conn(struct mg_connection *ls) {
if ((sock = accept(ls->sock, &sa.sa, &len)) == INVALID_SOCKET) {
} else if ((c = mg_add_sock(ls->mgr, sock, ls->handler)) == NULL) {
closesocket(sock);
-#ifdef NS_ENABLE_SSL
+#ifdef MG_ENABLE_SSL
} else if (ls->ssl_ctx != NULL && ((c->ssl = SSL_new(ls->ssl_ctx)) == NULL ||
SSL_set_fd(c->ssl, sock) != 1)) {
DBG(("SSL error"));
@@ -2372,7 +2372,7 @@ static struct mg_connection *accept_conn(struct mg_connection *ls) {
c->user_data = ls->user_data;
c->recv_mbuf_limit = ls->recv_mbuf_limit;
if (c->ssl == NULL) { /* SSL connections need to perform handshake. */
- mg_call(c, NS_ACCEPT, &sa);
+ mg_call(c, MG_EV_ACCEPT, &sa);
}
DBG(("%p %d %p %p", c, c->sock, c->ssl_ctx, c->ssl));
}
@@ -2381,13 +2381,13 @@ static struct mg_connection *accept_conn(struct mg_connection *ls) {
}
static int mg_is_error(int n) {
-#ifdef NS_CC3200
+#ifdef MG_CC3200
DBG(("n = %d, errno = %d", n, errno));
if (n < 0) errno = n;
#endif
return n == 0 || (n < 0 && errno != EINTR && errno != EINPROGRESS &&
errno != EAGAIN && errno != EWOULDBLOCK
-#ifdef NS_CC3200
+#ifdef MG_CC3200
&& errno != SL_EALREADY
#endif
#ifdef _WIN32
@@ -2404,43 +2404,43 @@ static size_t recv_avail_size(struct mg_connection *conn, size_t max) {
return avail > max ? max : avail;
}
-#ifdef NS_ENABLE_SSL
+#ifdef MG_ENABLE_SSL
static void mg_ssl_begin(struct mg_connection *nc) {
int server_side = nc->listener != NULL;
int res = server_side ? SSL_accept(nc->ssl) : SSL_connect(nc->ssl);
if (res == 1) {
- nc->flags |= NSF_SSL_HANDSHAKE_DONE;
- nc->flags &= ~(NSF_WANT_READ | NSF_WANT_WRITE);
+ nc->flags |= MG_F_SSL_HANDSHAKE_DONE;
+ nc->flags &= ~(MG_F_WANT_READ | MG_F_WANT_WRITE);
if (server_side) {
union socket_address sa;
socklen_t sa_len = sizeof(sa);
/* In case port was set to 0, get the real port number */
(void) getsockname(nc->sock, &sa.sa, &sa_len);
- mg_call(nc, NS_ACCEPT, &sa);
+ mg_call(nc, MG_EV_ACCEPT, &sa);
}
} else {
int ssl_err = mg_ssl_err(nc, res);
if (ssl_err != SSL_ERROR_WANT_READ && ssl_err != SSL_ERROR_WANT_WRITE) {
- nc->flags |= NSF_CLOSE_IMMEDIATELY;
+ nc->flags |= MG_F_CLOSE_IMMEDIATELY;
}
}
}
-#endif /* NS_ENABLE_SSL */
+#endif /* MG_ENABLE_SSL */
static void mg_read_from_socket(struct mg_connection *conn) {
- char buf[NS_READ_BUFFER_SIZE];
+ char buf[MG_READ_BUFFER_SIZE];
int n = 0;
- if (conn->flags & NSF_CONNECTING) {
+ if (conn->flags & MG_F_CONNECTING) {
int ok = 1, ret;
-#if !defined(NS_CC3200) && !defined(NS_ESP8266)
+#if !defined(MG_CC3200) && !defined(MG_ESP8266)
socklen_t len = sizeof(ok);
#endif
(void) ret;
-#if defined(NS_CC3200) || defined(NS_ESP8266)
+#if defined(MG_CC3200) || defined(MG_ESP8266)
/* On CC3200 and ESP8266 we use blocking connect. If we got as far as this,
* this means connect() was successful.
* TODO(rojer): Figure out why it fails where blocking succeeds.
@@ -2450,32 +2450,32 @@ static void mg_read_from_socket(struct mg_connection *conn) {
#else
ret = getsockopt(conn->sock, SOL_SOCKET, SO_ERROR, (char *) &ok, &len);
#endif
-#ifdef NS_ENABLE_SSL
+#ifdef MG_ENABLE_SSL
if (ret == 0 && ok == 0 && conn->ssl != NULL) {
mg_ssl_begin(conn);
}
#endif
DBG(("%p connect ok=%d", conn, ok));
if (ok != 0) {
- conn->flags |= NSF_CLOSE_IMMEDIATELY;
+ conn->flags |= MG_F_CLOSE_IMMEDIATELY;
} else {
- conn->flags &= ~NSF_CONNECTING;
+ conn->flags &= ~MG_F_CONNECTING;
}
- mg_call(conn, NS_CONNECT, &ok);
+ mg_call(conn, MG_EV_CONNECT, &ok);
return;
}
-#ifdef NS_ENABLE_SSL
+#ifdef MG_ENABLE_SSL
if (conn->ssl != NULL) {
- if (conn->flags & NSF_SSL_HANDSHAKE_DONE) {
+ if (conn->flags & MG_F_SSL_HANDSHAKE_DONE) {
/* SSL library may have more bytes ready to read then we ask to read.
* Therefore, read in a loop until we read everything. Without the loop,
* we skip to the next select() cycle which can just timeout. */
while ((n = SSL_read(conn->ssl, buf, sizeof(buf))) > 0) {
DBG(("%p %d bytes <- %d (SSL)", conn, n, conn->sock));
mbuf_append(&conn->recv_mbuf, buf, n);
- mg_call(conn, NS_RECV, &n);
- if (conn->flags & NSF_CLOSE_IMMEDIATELY) break;
+ mg_call(conn, MG_EV_RECV, &n);
+ if (conn->flags & MG_F_CLOSE_IMMEDIATELY) break;
}
mg_ssl_err(conn, n);
} else {
@@ -2484,17 +2484,17 @@ static void mg_read_from_socket(struct mg_connection *conn) {
}
} else
#endif
- while ((n = (int) NS_RECV_FUNC(
+ while ((n = (int) MG_EV_RECV_FUNC(
conn->sock, buf, recv_avail_size(conn, sizeof(buf)), 0)) > 0) {
DBG(("%p %d bytes (PLAIN) <- %d", conn, n, conn->sock));
mbuf_append(&conn->recv_mbuf, buf, n);
- mg_call(conn, NS_RECV, &n);
- if (conn->flags & NSF_CLOSE_IMMEDIATELY) break;
+ mg_call(conn, MG_EV_RECV, &n);
+ if (conn->flags & MG_F_CLOSE_IMMEDIATELY) break;
}
DBG(("recv returns %d", n));
if (mg_is_error(n)) {
- conn->flags |= NSF_CLOSE_IMMEDIATELY;
+ conn->flags |= MG_F_CLOSE_IMMEDIATELY;
}
}
@@ -2504,20 +2504,20 @@ static void mg_write_to_socket(struct mg_connection *conn) {
assert(io->len > 0);
-#ifdef NS_ENABLE_SSL
+#ifdef MG_ENABLE_SSL
if (conn->ssl != NULL) {
- if (conn->flags & NSF_SSL_HANDSHAKE_DONE) {
+ if (conn->flags & MG_F_SSL_HANDSHAKE_DONE) {
n = SSL_write(conn->ssl, io->buf, io->len);
if (n <= 0) {
int ssl_err = mg_ssl_err(conn, n);
if (ssl_err == SSL_ERROR_WANT_READ || ssl_err == SSL_ERROR_WANT_WRITE) {
return; /* Call us again */
} else {
- conn->flags |= NSF_CLOSE_IMMEDIATELY;
+ conn->flags |= MG_F_CLOSE_IMMEDIATELY;
}
} else {
/* Successful SSL operation, clear off SSL wait flags */
- conn->flags &= ~(NSF_WANT_READ | NSF_WANT_WRITE);
+ conn->flags &= ~(MG_F_WANT_READ | MG_F_WANT_WRITE);
}
} else {
mg_ssl_begin(conn);
@@ -2526,24 +2526,24 @@ static void mg_write_to_socket(struct mg_connection *conn) {
} else
#endif
{
- n = (int) NS_SEND_FUNC(conn->sock, io->buf, io->len, 0);
+ n = (int) MG_EV_SEND_FUNC(conn->sock, io->buf, io->len, 0);
}
DBG(("%p %d bytes -> %d", conn, n, conn->sock));
if (mg_is_error(n)) {
- conn->flags |= NSF_CLOSE_IMMEDIATELY;
+ conn->flags |= MG_F_CLOSE_IMMEDIATELY;
} else if (n > 0) {
-#ifndef NS_DISABLE_FILESYSTEM
+#ifndef MG_DISABLE_FILESYSTEM
/* LCOV_EXCL_START */
if (conn->mgr->hexdump_file != NULL) {
- mg_hexdump_connection(conn, conn->mgr->hexdump_file, n, NS_SEND);
+ mg_hexdump_connection(conn, conn->mgr->hexdump_file, n, MG_EV_SEND);
}
/* LCOV_EXCL_STOP */
#endif
mbuf_remove(io, n);
}
- mg_call(conn, NS_SEND, &n);
+ mg_call(conn, MG_EV_SEND, &n);
}
int mg_send(struct mg_connection *conn, const void *buf, int len) {
@@ -2552,7 +2552,7 @@ int mg_send(struct mg_connection *conn, const void *buf, int len) {
static void mg_handle_udp(struct mg_connection *ls) {
struct mg_connection nc;
- char buf[NS_UDP_RECEIVE_BUFFER_SIZE];
+ char buf[MG_UDP_RECEIVE_BUFFER_SIZE];
int n;
socklen_t s_len = sizeof(nc.sa);
@@ -2570,11 +2570,11 @@ static void mg_handle_udp(struct mg_connection *ls) {
nc.recv_mbuf.buf = buf;
nc.recv_mbuf.len = nc.recv_mbuf.size = n;
nc.listener = ls;
- nc.flags = NSF_UDP;
+ nc.flags = MG_F_UDP;
- /* Call NS_RECV handler */
+ /* Call MG_EV_RECV handler */
DBG(("%p %d bytes received", ls, n));
- mg_call(&nc, NS_RECV, &n);
+ mg_call(&nc, MG_EV_RECV, &n);
/*
* See https://github.com/cesanta/mongoose/issues/207
@@ -2584,9 +2584,9 @@ static void mg_handle_udp(struct mg_connection *ls) {
}
}
-#define _NSF_FD_CAN_READ 1
-#define _NSF_FD_CAN_WRITE 1 << 1
-#define _NSF_FD_ERROR 1 << 2
+#define _MG_F_FD_CAN_READ 1
+#define _MG_F_FD_CAN_WRITE 1 << 1
+#define _MG_F_FD_ERROR 1 << 2
static void mg_mgr_handle_connection(struct mg_connection *nc, int fd_flags,
time_t now) {
@@ -2594,74 +2594,74 @@ static void mg_mgr_handle_connection(struct mg_connection *nc, int fd_flags,
fd_flags, nc->flags, (int) nc->recv_mbuf.len, (int) nc->send_mbuf.len));
if (fd_flags != 0) nc->last_io_time = now;
- if (nc->flags & NSF_CONNECTING) {
+ if (nc->flags & MG_F_CONNECTING) {
if (fd_flags != 0) {
mg_read_from_socket(nc);
}
return;
}
- if (nc->flags & NSF_LISTENING) {
+ if (nc->flags & MG_F_LISTENING) {
/*
* We're not looping here, and accepting just one connection at
* a time. The reason is that eCos does not respect non-blocking
* flag on a listening socket and hangs in a loop.
*/
- if (fd_flags & _NSF_FD_CAN_READ) accept_conn(nc);
+ if (fd_flags & _MG_F_FD_CAN_READ) accept_conn(nc);
return;
}
- if (fd_flags & _NSF_FD_CAN_READ) {
- if (nc->flags & NSF_UDP) {
+ if (fd_flags & _MG_F_FD_CAN_READ) {
+ if (nc->flags & MG_F_UDP) {
mg_handle_udp(nc);
} else {
mg_read_from_socket(nc);
}
- if (nc->flags & NSF_CLOSE_IMMEDIATELY) return;
+ if (nc->flags & MG_F_CLOSE_IMMEDIATELY) return;
}
- if ((fd_flags & _NSF_FD_CAN_WRITE) && !(nc->flags & NSF_DONT_SEND) &&
- !(nc->flags & NSF_UDP)) { /* Writes to UDP sockets are not buffered. */
+ if ((fd_flags & _MG_F_FD_CAN_WRITE) && !(nc->flags & MG_F_DONT_SEND) &&
+ !(nc->flags & MG_F_UDP)) { /* Writes to UDP sockets are not buffered. */
mg_write_to_socket(nc);
}
- if (!(fd_flags & (_NSF_FD_CAN_READ | _NSF_FD_CAN_WRITE))) {
- mg_call(nc, NS_POLL, &now);
+ if (!(fd_flags & (_MG_F_FD_CAN_READ | _MG_F_FD_CAN_WRITE))) {
+ mg_call(nc, MG_EV_POLL, &now);
}
DBG(("%p after fd=%d nc_flags=%lu rmbl=%d smbl=%d", nc, nc->sock, nc->flags,
(int) nc->recv_mbuf.len, (int) nc->send_mbuf.len));
}
-#ifndef NS_DISABLE_SOCKETPAIR
+#ifndef MG_DISABLE_SOCKETPAIR
static void mg_mgr_handle_ctl_sock(struct mg_mgr *mgr) {
struct ctl_msg ctl_msg;
int len =
- (int) NS_RECV_FUNC(mgr->ctl[1], (char *) &ctl_msg, sizeof(ctl_msg), 0);
- NS_SEND_FUNC(mgr->ctl[1], ctl_msg.message, 1, 0);
+ (int) MG_EV_RECV_FUNC(mgr->ctl[1], (char *) &ctl_msg, sizeof(ctl_msg), 0);
+ MG_EV_SEND_FUNC(mgr->ctl[1], ctl_msg.message, 1, 0);
if (len >= (int) sizeof(ctl_msg.callback) && ctl_msg.callback != NULL) {
struct mg_connection *nc;
for (nc = mg_next(mgr, NULL); nc != NULL; nc = mg_next(mgr, nc)) {
- ctl_msg.callback(nc, NS_POLL, ctl_msg.message);
+ ctl_msg.callback(nc, MG_EV_POLL, ctl_msg.message);
}
}
}
#endif
-#if NS_MGR_EV_MGR == 1 /* epoll() */
+#if MG_MGR_EV_MGR == 1 /* epoll() */
-#ifndef NS_EPOLL_MAX_EVENTS
-#define NS_EPOLL_MAX_EVENTS 100
+#ifndef MG_EPOLL_MAX_EVENTS
+#define MG_EPOLL_MAX_EVENTS 100
#endif
-#define _NS_EPF_EV_EPOLLIN (1 << 0)
-#define _NS_EPF_EV_EPOLLOUT (1 << 1)
-#define _NS_EPF_NO_POLL (1 << 2)
+#define _MG_EPF_EV_EPOLLIN (1 << 0)
+#define _MG_EPF_EV_EPOLLOUT (1 << 1)
+#define _MG_EPF_NO_POLL (1 << 2)
static uint32_t mg_epf_to_evflags(unsigned int epf) {
uint32_t result = 0;
- if (epf & _NS_EPF_EV_EPOLLIN) result |= EPOLLIN;
- if (epf & _NS_EPF_EV_EPOLLOUT) result |= EPOLLOUT;
+ if (epf & _MG_EPF_EV_EPOLLIN) result |= EPOLLIN;
+ if (epf & _MG_EPF_EV_EPOLLOUT) result |= EPOLLOUT;
return result;
}
@@ -2672,8 +2672,8 @@ static void mg_ev_mgr_epoll_set_flags(const struct mg_connection *nc,
if (nc->recv_mbuf.len < nc->recv_mbuf_limit) {
ev->events |= EPOLLIN;
}
- if ((nc->flags & NSF_CONNECTING) ||
- (nc->send_mbuf.len > 0 && !(nc->flags & NSF_DONT_SEND))) {
+ if ((nc->flags & MG_F_CONNECTING) ||
+ (nc->send_mbuf.len > 0 && !(nc->flags & MG_F_DONT_SEND))) {
ev->events |= EPOLLOUT;
}
}
@@ -2699,7 +2699,7 @@ static void mg_ev_mgr_epoll_ctl(struct mg_connection *nc, int op) {
static void mg_ev_mgr_init(struct mg_mgr *mgr) {
int epoll_fd;
DBG(("%p using epoll()", mgr));
- epoll_fd = epoll_create(NS_EPOLL_MAX_EVENTS /* unused but required */);
+ epoll_fd = epoll_create(MG_EPOLL_MAX_EVENTS /* unused but required */);
if (epoll_fd < 0) {
perror("epoll_ctl");
abort();
@@ -2731,12 +2731,12 @@ static void mg_ev_mgr_remove_conn(struct mg_connection *nc) {
time_t mg_mgr_poll(struct mg_mgr *mgr, int timeout_ms) {
int epoll_fd = (intptr_t) mgr->mgr_data;
- struct epoll_event events[NS_EPOLL_MAX_EVENTS];
+ struct epoll_event events[MG_EPOLL_MAX_EVENTS];
struct mg_connection *nc, *next;
int num_ev, fd_flags;
time_t now;
- num_ev = epoll_wait(epoll_fd, events, NS_EPOLL_MAX_EVENTS, timeout_ms);
+ num_ev = epoll_wait(epoll_fd, events, MG_EPOLL_MAX_EVENTS, timeout_ms);
now = time(NULL);
DBG(("epoll_wait @ %ld num_ev=%d", (long) now, num_ev));
@@ -2748,26 +2748,26 @@ time_t mg_mgr_poll(struct mg_mgr *mgr, int timeout_ms) {
mg_mgr_handle_ctl_sock(mgr);
continue;
}
- fd_flags = ((ev->events & (EPOLLIN | EPOLLHUP)) ? _NSF_FD_CAN_READ : 0) |
- ((ev->events & (EPOLLOUT)) ? _NSF_FD_CAN_WRITE : 0) |
- ((ev->events & (EPOLLERR)) ? _NSF_FD_ERROR : 0);
+ fd_flags = ((ev->events & (EPOLLIN | EPOLLHUP)) ? _MG_F_FD_CAN_READ : 0) |
+ ((ev->events & (EPOLLOUT)) ? _MG_F_FD_CAN_WRITE : 0) |
+ ((ev->events & (EPOLLERR)) ? _MG_F_FD_ERROR : 0);
mg_mgr_handle_connection(nc, fd_flags, now);
epf = (intptr_t) nc->mgr_data;
- epf ^= _NS_EPF_NO_POLL;
+ epf ^= _MG_EPF_NO_POLL;
nc->mgr_data = (void *) epf;
}
for (nc = mgr->active_connections; nc != NULL; nc = next) {
next = nc->next;
- if (!(((intptr_t) nc->mgr_data) & _NS_EPF_NO_POLL)) {
+ if (!(((intptr_t) nc->mgr_data) & _MG_EPF_NO_POLL)) {
mg_mgr_handle_connection(nc, 0, now);
} else {
intptr_t epf = (intptr_t) nc->mgr_data;
- epf ^= _NS_EPF_NO_POLL;
+ epf ^= _MG_EPF_NO_POLL;
nc->mgr_data = (void *) epf;
}
- if ((nc->flags & NSF_CLOSE_IMMEDIATELY) ||
- (nc->send_mbuf.len == 0 && (nc->flags & NSF_SEND_AND_CLOSE))) {
+ if ((nc->flags & MG_F_CLOSE_IMMEDIATELY) ||
+ (nc->send_mbuf.len == 0 && (nc->flags & MG_F_SEND_AND_CLOSE))) {
mg_close_conn(nc);
} else {
mg_ev_mgr_epoll_ctl(nc, EPOLL_CTL_MOD);
@@ -2821,14 +2821,14 @@ time_t mg_mgr_poll(struct mg_mgr *mgr, int milli) {
for (nc = mgr->active_connections; nc != NULL; nc = tmp) {
tmp = nc->next;
- if (!(nc->flags & NSF_WANT_WRITE) &&
+ if (!(nc->flags & MG_F_WANT_WRITE) &&
nc->recv_mbuf.len < nc->recv_mbuf_limit) {
mg_add_to_set(nc->sock, &read_set, &max_fd);
}
- if (((nc->flags & NSF_CONNECTING) && !(nc->flags & NSF_WANT_READ)) ||
- (nc->send_mbuf.len > 0 && !(nc->flags & NSF_CONNECTING) &&
- !(nc->flags & NSF_DONT_SEND))) {
+ if (((nc->flags & MG_F_CONNECTING) && !(nc->flags & MG_F_WANT_READ)) ||
+ (nc->send_mbuf.len > 0 && !(nc->flags & MG_F_CONNECTING) &&
+ !(nc->flags & MG_F_DONT_SEND))) {
mg_add_to_set(nc->sock, &write_set, &max_fd);
mg_add_to_set(nc->sock, &err_set, &max_fd);
}
@@ -2841,7 +2841,7 @@ time_t mg_mgr_poll(struct mg_mgr *mgr, int milli) {
now = time(NULL);
DBG(("select @ %ld num_ev=%d", (long) now, num_selected));
-#ifndef NS_DISABLE_SOCKETPAIR
+#ifndef MG_DISABLE_SOCKETPAIR
if (num_selected > 0 && mgr->ctl[1] != INVALID_SOCKET &&
FD_ISSET(mgr->ctl[1], &read_set)) {
mg_mgr_handle_ctl_sock(mgr);
@@ -2851,15 +2851,15 @@ time_t mg_mgr_poll(struct mg_mgr *mgr, int milli) {
for (nc = mgr->active_connections; nc != NULL; nc = tmp) {
int fd_flags = 0;
if (num_selected > 0) {
- fd_flags = (FD_ISSET(nc->sock, &read_set) ? _NSF_FD_CAN_READ : 0) |
- (FD_ISSET(nc->sock, &write_set) ? _NSF_FD_CAN_WRITE : 0) |
- (FD_ISSET(nc->sock, &err_set) ? _NSF_FD_ERROR : 0);
+ fd_flags = (FD_ISSET(nc->sock, &read_set) ? _MG_F_FD_CAN_READ : 0) |
+ (FD_ISSET(nc->sock, &write_set) ? _MG_F_FD_CAN_WRITE : 0) |
+ (FD_ISSET(nc->sock, &err_set) ? _MG_F_FD_ERROR : 0);
}
-#ifdef NS_CC3200
+#ifdef MG_CC3200
// CC3200 does not report UDP sockets as writeable.
- if (nc->flags & NSF_UDP &&
- (nc->send_mbuf.len > 0 || nc->flags & NSF_CONNECTING)) {
- fd_flags |= _NSF_FD_CAN_WRITE;
+ if (nc->flags & MG_F_UDP &&
+ (nc->send_mbuf.len > 0 || nc->flags & MG_F_CONNECTING)) {
+ fd_flags |= _MG_F_FD_CAN_WRITE;
}
#endif
tmp = nc->next;
@@ -2868,8 +2868,8 @@ time_t mg_mgr_poll(struct mg_mgr *mgr, int milli) {
for (nc = mgr->active_connections; nc != NULL; nc = tmp) {
tmp = nc->next;
- if ((nc->flags & NSF_CLOSE_IMMEDIATELY) ||
- (nc->send_mbuf.len == 0 && (nc->flags & NSF_SEND_AND_CLOSE))) {
+ if ((nc->flags & MG_F_CLOSE_IMMEDIATELY) ||
+ (nc->send_mbuf.len == 0 && (nc->flags & MG_F_SEND_AND_CLOSE))) {
mg_close_conn(nc);
}
}
@@ -2882,10 +2882,10 @@ time_t mg_mgr_poll(struct mg_mgr *mgr, int milli) {
/*
* Schedules an async connect for a resolved address and proto.
* Called from two places: `mg_connect_opt()` and from async resolver.
- * When called from the async resolver, it must trigger `NS_CONNECT` event
+ * When called from the async resolver, it must trigger `MG_EV_CONNECT` event
* with a failure flag to indicate connection failure.
*/
-NS_INTERNAL struct mg_connection *mg_finish_connect(struct mg_connection *nc,
+MG_INTERNAL struct mg_connection *mg_finish_connect(struct mg_connection *nc,
int proto,
union socket_address *sa,
struct mg_add_sock_opts o) {
@@ -2897,42 +2897,42 @@ NS_INTERNAL struct mg_connection *mg_finish_connect(struct mg_connection *nc,
if ((sock = socket(AF_INET, proto, 0)) == INVALID_SOCKET) {
int failure = errno;
- NS_SET_PTRPTR(o.error_string, "cannot create socket");
- if (nc->flags & NSF_CONNECTING) {
- mg_call(nc, NS_CONNECT, &failure);
+ MG_SET_PTRPTR(o.error_string, "cannot create socket");
+ if (nc->flags & MG_F_CONNECTING) {
+ mg_call(nc, MG_EV_CONNECT, &failure);
}
mg_destroy_conn(nc);
return NULL;
}
-#if !defined(NS_CC3200) && !defined(NS_ESP8266)
+#if !defined(MG_CC3200) && !defined(MG_ESP8266)
mg_set_non_blocking_mode(sock);
#endif
rc = (proto == SOCK_DGRAM) ? 0 : connect(sock, &sa->sa, sizeof(sa->sin));
if (rc != 0 && mg_is_error(rc)) {
- NS_SET_PTRPTR(o.error_string, "cannot connect to socket");
- if (nc->flags & NSF_CONNECTING) {
- mg_call(nc, NS_CONNECT, &rc);
+ MG_SET_PTRPTR(o.error_string, "cannot connect to socket");
+ if (nc->flags & MG_F_CONNECTING) {
+ mg_call(nc, MG_EV_CONNECT, &rc);
}
mg_destroy_conn(nc);
close(sock);
return NULL;
}
- /* Fire NS_CONNECT on next poll. */
- nc->flags |= NSF_CONNECTING;
+ /* Fire MG_EV_CONNECT on next poll. */
+ nc->flags |= MG_F_CONNECTING;
/* No mg_destroy_conn() call after this! */
mg_set_sock(nc, sock);
-#ifdef NS_ENABLE_SSL
+#ifdef MG_ENABLE_SSL
/*
* If we are using async resolver, socket isn't open
* before this place, so
* for SSL connections we have to add socket to SSL fd set
*/
- if (nc->ssl != NULL && !(nc->flags & NSF_LISTENING)) {
+ if (nc->ssl != NULL && !(nc->flags & MG_F_LISTENING)) {
SSL_set_fd(nc->ssl, nc->sock);
}
#endif
@@ -2940,10 +2940,10 @@ NS_INTERNAL struct mg_connection *mg_finish_connect(struct mg_connection *nc,
return nc;
}
-#ifndef NS_DISABLE_RESOLVER
+#ifndef MG_DISABLE_RESOLVER
/*
* Callback for the async resolver on mg_connect_opt() call.
- * Main task of this function is to trigger NS_CONNECT event with
+ * Main task of this function is to trigger MG_EV_CONNECT event with
* either failure (and dealloc the connection)
* or success (and proceed with connect()
*/
@@ -2957,7 +2957,7 @@ static void resolve_cb(struct mg_dmg_message *msg, void *data) {
* Take the first DNS A answer and run...
*/
for (i = 0; i < msg->num_answers; i++) {
- if (msg->answers[i].rtype == NS_DNS_A_RECORD) {
+ if (msg->answers[i].rtype == MG_DNS_A_RECORD) {
static struct mg_add_sock_opts opts;
/*
* Async resolver guarantees that there is at least one answer.
@@ -2965,9 +2965,9 @@ static void resolve_cb(struct mg_dmg_message *msg, void *data) {
*/
mg_dmg_parse_record_data(msg, &msg->answers[i], &nc->sa.sin.sin_addr,
4);
- /* Make mg_finish_connect() trigger NS_CONNECT on failure */
- nc->flags |= NSF_CONNECTING;
- mg_finish_connect(nc, nc->flags & NSF_UDP ? SOCK_DGRAM : SOCK_STREAM,
+ /* Make mg_finish_connect() trigger MG_EV_CONNECT on failure */
+ nc->flags |= MG_F_CONNECTING;
+ mg_finish_connect(nc, nc->flags & MG_F_UDP ? SOCK_DGRAM : SOCK_STREAM,
&nc->sa, opts);
return;
}
@@ -2975,9 +2975,9 @@ static void resolve_cb(struct mg_dmg_message *msg, void *data) {
}
/*
- * If we get there was no NS_DNS_A_RECORD in the answer
+ * If we get there was no MG_DNS_A_RECORD in the answer
*/
- mg_call(nc, NS_CONNECT, &failure);
+ mg_call(nc, MG_EV_CONNECT, &failure);
mg_destroy_conn(nc);
}
#endif
@@ -2994,38 +2994,38 @@ struct mg_connection *mg_connect_opt(struct mg_mgr *mgr, const char *address,
struct mg_connection *nc = NULL;
int proto, rc;
struct mg_add_sock_opts add_sock_opts;
- char host[NS_MAX_HOST_LEN];
+ char host[MG_MAX_HOST_LEN];
- NS_COPY_COMMON_CONNECTION_OPTIONS(&add_sock_opts, &opts);
+ MG_COPY_COMMON_CONNECTION_OPTIONS(&add_sock_opts, &opts);
if ((nc = mg_create_connection(mgr, callback, add_sock_opts)) == NULL) {
return NULL;
} else if ((rc = mg_parse_address(address, &nc->sa, &proto, host,
sizeof(host))) < 0) {
/* Address is malformed */
- NS_SET_PTRPTR(opts.error_string, "cannot parse address");
+ MG_SET_PTRPTR(opts.error_string, "cannot parse address");
mg_destroy_conn(nc);
return NULL;
}
- nc->flags |= opts.flags & _NS_ALLOWED_CONNECT_FLAGS_MASK;
- nc->flags |= (proto == SOCK_DGRAM) ? NSF_UDP : 0;
+ nc->flags |= opts.flags & _MG_ALLOWED_CONNECT_FLAGS_MASK;
+ nc->flags |= (proto == SOCK_DGRAM) ? MG_F_UDP : 0;
nc->user_data = opts.user_data;
if (rc == 0) {
-#ifndef NS_DISABLE_RESOLVER
+#ifndef MG_DISABLE_RESOLVER
/*
* DNS resolution is required for host.
* mg_parse_address() fills port in nc->sa, which we pass to resolve_cb()
*/
- if (mg_resolve_async(nc->mgr, host, NS_DNS_A_RECORD, resolve_cb, nc) != 0) {
- NS_SET_PTRPTR(opts.error_string, "cannot schedule DNS lookup");
+ if (mg_resolve_async(nc->mgr, host, MG_DNS_A_RECORD, resolve_cb, nc) != 0) {
+ MG_SET_PTRPTR(opts.error_string, "cannot schedule DNS lookup");
mg_destroy_conn(nc);
return NULL;
}
return nc;
#else
- NS_SET_PTRPTR(opts.error_string, "Resolver is disabled");
+ MG_SET_PTRPTR(opts.error_string, "Resolver is disabled");
mg_destroy_conn(nc);
return NULL;
#endif
@@ -3049,15 +3049,15 @@ struct mg_connection *mg_bind_opt(struct mg_mgr *mgr, const char *address,
int proto;
sock_t sock;
struct mg_add_sock_opts add_sock_opts;
- char host[NS_MAX_HOST_LEN];
+ char host[MG_MAX_HOST_LEN];
- NS_COPY_COMMON_CONNECTION_OPTIONS(&add_sock_opts, &opts);
+ MG_COPY_COMMON_CONNECTION_OPTIONS(&add_sock_opts, &opts);
if (mg_parse_address(address, &sa, &proto, host, sizeof(host)) <= 0) {
- NS_SET_PTRPTR(opts.error_string, "cannot parse address");
+ MG_SET_PTRPTR(opts.error_string, "cannot parse address");
} else if ((sock = mg_open_listening_socket(&sa, proto)) == INVALID_SOCKET) {
DBG(("Failed to open listener: %d", errno));
- NS_SET_PTRPTR(opts.error_string, "failed to open listener");
+ MG_SET_PTRPTR(opts.error_string, "failed to open listener");
} else if ((nc = mg_add_sock_opt(mgr, sock, callback, add_sock_opts)) ==
NULL) {
/* opts.error_string set by mg_add_sock_opt */
@@ -3068,9 +3068,9 @@ struct mg_connection *mg_bind_opt(struct mg_mgr *mgr, const char *address,
nc->handler = callback;
if (proto == SOCK_DGRAM) {
- nc->flags |= NSF_UDP;
+ nc->flags |= MG_F_UDP;
} else {
- nc->flags |= NSF_LISTENING;
+ nc->flags |= MG_F_LISTENING;
}
DBG(("%p sock %d/%d", nc, sock, proto));
@@ -3114,9 +3114,9 @@ void mg_broadcast(struct mg_mgr *mgr, mg_event_handler_t cb, void *data,
len < sizeof(ctl_msg.message)) {
ctl_msg.callback = cb;
memcpy(ctl_msg.message, data, len);
- NS_SEND_FUNC(mgr->ctl[0], (char *) &ctl_msg,
- offsetof(struct ctl_msg, message) + len, 0);
- NS_RECV_FUNC(mgr->ctl[0], (char *) &len, 1, 0);
+ MG_EV_SEND_FUNC(mgr->ctl[0], (char *) &ctl_msg,
+ offsetof(struct ctl_msg, message) + len, 0);
+ MG_EV_RECV_FUNC(mgr->ctl[0], (char *) &len, 1, 0);
}
}
@@ -3179,7 +3179,7 @@ void mg_forward(struct mg_connection *from, struct mg_connection *to) {
/* Amalgamated: #include "internal.h" */
-#ifdef NS_ENABLE_THREADS
+#ifdef MG_ENABLE_THREADS
static void multithreaded_ev_handler(struct mg_connection *c, int ev, void *p);
@@ -3210,7 +3210,7 @@ static void link_conns(struct mg_connection *c1, struct mg_connection *c2) {
static void unlink_conns(struct mg_connection *c) {
struct mg_connection *peer = (struct mg_connection *) c->priv_2;
if (peer != NULL) {
- peer->flags |= NSF_SEND_AND_CLOSE;
+ peer->flags |= MG_F_SEND_AND_CLOSE;
peer->priv_2 = NULL;
}
c->priv_2 = NULL;
@@ -3218,9 +3218,9 @@ static void unlink_conns(struct mg_connection *c) {
static void forwarder_ev_handler(struct mg_connection *c, int ev, void *p) {
(void) p;
- if (ev == NS_RECV && c->priv_2) {
+ if (ev == MG_EV_RECV && c->priv_2) {
mg_forward(c, (struct mg_connection *) c->priv_2);
- } else if (ev == NS_CLOSE) {
+ } else if (ev == MG_EV_CLOSE) {
unlink_conns(c);
}
}
@@ -3263,7 +3263,7 @@ static void spawn_handling_thread(struct mg_connection *nc) {
static void multithreaded_ev_handler(struct mg_connection *c, int ev, void *p) {
(void) p;
- if (ev == NS_ACCEPT) {
+ if (ev == MG_EV_ACCEPT) {
spawn_handling_thread(c);
c->handler = forwarder_ev_handler;
}
@@ -3284,7 +3284,7 @@ void mg_enable_multithreading(struct mg_connection *nc) {
* All rights reserved
*/
-#ifndef NS_DISABLE_HTTP
+#ifndef MG_DISABLE_HTTP
/* Amalgamated: #include "internal.h" */
@@ -3311,8 +3311,8 @@ struct proto_data_http {
*/
struct cgi_env_block {
struct mg_connection *nc;
- char buf[NS_CGI_ENVIRONMENT_SIZE]; /* Environment buffer */
- const char *vars[NS_MAX_CGI_ENVIR_VARS]; /* char *envp[] */
+ char buf[MG_CGI_ENVIRONMENT_SIZE]; /* Environment buffer */
+ const char *vars[MG_MAX_CGI_ENVIR_VARS]; /* char *envp[] */
int len; /* Space taken */
int nvars; /* Number of variables in envp[] */
};
@@ -3374,7 +3374,7 @@ static const struct {
MIME_ENTRY("bmp", "image/bmp"),
{NULL, 0, NULL}};
-#ifndef NS_DISABLE_FILESYSTEM
+#ifndef MG_DISABLE_FILESYSTEM
static int mg_mkdir(const char *path, uint32_t mode) {
#ifndef _WIN32
@@ -3545,7 +3545,7 @@ struct mg_str *mg_get_http_header(struct http_message *hm, const char *name) {
return NULL;
}
-#ifndef NS_DISABLE_HTTP_WEBSOCKET
+#ifndef MG_DISABLE_HTTP_WEBSOCKET
static int is_ws_fragment(unsigned char flags) {
return (flags & 0x80) == 0 || (flags & 0x0f) == 0;
@@ -3558,9 +3558,9 @@ static int is_ws_first_fragment(unsigned char flags) {
static void handle_incoming_websocket_frame(struct mg_connection *nc,
struct websocket_message *wsm) {
if (wsm->flags & 0x8) {
- nc->handler(nc, NS_WEBSOCKET_CONTROL_FRAME, wsm);
+ nc->handler(nc, MG_EV_WEBSOCKET_CONTROL_FRAME, wsm);
} else {
- nc->handler(nc, NS_WEBSOCKET_FRAME, wsm);
+ nc->handler(nc, MG_EV_WEBSOCKET_FRAME, wsm);
}
}
@@ -3572,7 +3572,7 @@ static int deliver_websocket_data(struct mg_connection *nc) {
*e = p + buf_len;
unsigned *sizep = (unsigned *) &p[1]; /* Size ptr for defragmented frames */
int ok, reass = buf_len > 0 && is_ws_fragment(p[0]) &&
- !(nc->flags & NSF_WEBSOCKET_NO_DEFRAG);
+ !(nc->flags & MG_F_WEBSOCKET_NO_DEFRAG);
/* If that's a continuation frame that must be reassembled, handle it */
if (reass && !is_ws_first_fragment(p[0]) && buf_len >= 1 + sizeof(*sizep) &&
@@ -3643,7 +3643,7 @@ static int deliver_websocket_data(struct mg_connection *nc) {
/* If client closes, close too */
if ((buf[0] & 0x0f) == WEBSOCKET_OP_CLOSE) {
- nc->flags |= NSF_SEND_AND_CLOSE;
+ nc->flags |= MG_F_SEND_AND_CLOSE;
}
}
@@ -3670,7 +3670,7 @@ static uint32_t ws_random_mask() {
* mongoose use cases and thus can be disabled, e.g. when porting to a platform
* that lacks random().
*/
-#if NS_DISABLE_WS_RANDOM_MASK
+#if MG_DISABLE_WS_RANDOM_MASK
return 0xefbeadde; /* generated with a random number generator, I swear */
#else
if (sizeof(long) >= 4) {
@@ -3735,7 +3735,7 @@ void mg_send_websocket_frame(struct mg_connection *nc, int op, const void *data,
ws_mask_frame(&nc->send_mbuf, &ctx);
if (op == WEBSOCKET_OP_CLOSE) {
- nc->flags |= NSF_SEND_AND_CLOSE;
+ nc->flags |= MG_F_SEND_AND_CLOSE;
}
}
@@ -3757,7 +3757,7 @@ void mg_send_websocket_framev(struct mg_connection *nc, int op,
ws_mask_frame(&nc->send_mbuf, &ctx);
if (op == WEBSOCKET_OP_CLOSE) {
- nc->flags |= NSF_SEND_AND_CLOSE;
+ nc->flags |= MG_F_SEND_AND_CLOSE;
}
}
@@ -3774,7 +3774,7 @@ void mg_printf_websocket_frame(struct mg_connection *nc, int op,
va_end(ap);
if (buf != mem && buf != NULL) {
- NS_FREE(buf);
+ MG_FREE(buf);
}
}
@@ -3782,16 +3782,16 @@ static void websocket_handler(struct mg_connection *nc, int ev, void *ev_data) {
nc->handler(nc, ev, ev_data);
switch (ev) {
- case NS_RECV:
+ case MG_EV_RECV:
do {
} while (deliver_websocket_data(nc));
break;
- case NS_POLL:
+ case MG_EV_POLL:
/* Ping idle websocket connections */
{
time_t now = *(time_t *) ev_data;
- if (nc->flags & NSF_IS_WEBSOCKET &&
- now > nc->last_io_time + NS_WEBSOCKET_PING_INTERVAL_SECONDS) {
+ if (nc->flags & MG_F_IS_WEBSOCKET &&
+ now > nc->last_io_time + MG_WEBSOCKET_PING_INTERVAL_SECONDS) {
mg_send_websocket_frame(nc, WEBSOCKET_OP_PING, "", 0);
}
}
@@ -3821,7 +3821,7 @@ static void ws_handshake(struct mg_connection *nc, const struct mg_str *key) {
b64_sha, "\r\n\r\n");
}
-#endif /* NS_DISABLE_HTTP_WEBSOCKET */
+#endif /* MG_DISABLE_HTTP_WEBSOCKET */
static void free_http_proto_data(struct mg_connection *nc) {
struct proto_data_http *dp = (struct proto_data_http *) nc->proto_data;
@@ -3830,16 +3830,16 @@ static void free_http_proto_data(struct mg_connection *nc) {
fclose(dp->fp);
}
if (dp->cgi_nc != NULL) {
- dp->cgi_nc->flags |= NSF_CLOSE_IMMEDIATELY;
+ dp->cgi_nc->flags |= MG_F_CLOSE_IMMEDIATELY;
}
- NS_FREE(dp);
+ MG_FREE(dp);
nc->proto_data = NULL;
}
}
static void transfer_file_data(struct mg_connection *nc) {
struct proto_data_http *dp = (struct proto_data_http *) nc->proto_data;
- char buf[NS_MAX_HTTP_SEND_IOBUF];
+ char buf[MG_MAX_HTTP_SEND_IOBUF];
int64_t left = dp->cl - dp->sent;
size_t n = 0, to_read = 0;
@@ -3878,7 +3878,7 @@ static void transfer_file_data(struct mg_connection *nc) {
if (dp->cgi_nc != NULL) {
mg_forward(nc, dp->cgi_nc);
} else {
- nc->flags |= NSF_SEND_AND_CLOSE;
+ nc->flags |= MG_F_SEND_AND_CLOSE;
}
}
}
@@ -3921,7 +3921,7 @@ static size_t parse_chunk(char *buf, size_t len, char **chunk_data,
return i + 2;
}
-NS_INTERNAL size_t mg_handle_chunked(struct mg_connection *nc,
+MG_INTERNAL size_t mg_handle_chunked(struct mg_connection *nc,
struct http_message *hm, char *buf,
size_t blen) {
struct proto_data_http *dp;
@@ -3930,8 +3930,8 @@ NS_INTERNAL size_t mg_handle_chunked(struct mg_connection *nc,
/* If not allocated, allocate proto_data to hold reassembled offset */
if (nc->proto_data == NULL &&
- (nc->proto_data = NS_CALLOC(1, sizeof(*dp))) == NULL) {
- nc->flags |= NSF_CLOSE_IMMEDIATELY;
+ (nc->proto_data = MG_CALLOC(1, sizeof(*dp))) == NULL) {
+ nc->flags |= MG_F_CLOSE_IMMEDIATELY;
return 0;
}
@@ -3963,12 +3963,12 @@ NS_INTERNAL size_t mg_handle_chunked(struct mg_connection *nc,
nc->recv_mbuf.len -= i - body_len;
dp->body_len = body_len;
- /* Send NS_HTTP_CHUNK event */
- nc->flags &= ~NSF_DELETE_CHUNK;
- nc->handler(nc, NS_HTTP_CHUNK, hm);
+ /* Send MG_EV_HTTP_CHUNK event */
+ nc->flags &= ~MG_F_DELETE_CHUNK;
+ nc->handler(nc, MG_EV_HTTP_CHUNK, hm);
- /* Delete processed data if user set NSF_DELETE_CHUNK flag */
- if (nc->flags & NSF_DELETE_CHUNK) {
+ /* Delete processed data if user set MG_F_DELETE_CHUNK flag */
+ if (nc->flags & MG_F_DELETE_CHUNK) {
memset(buf, 0, body_len);
memmove(buf, buf + body_len, blen - i);
nc->recv_mbuf.len -= body_len;
@@ -3988,18 +3988,18 @@ static void http_handler(struct mg_connection *nc, int ev, void *ev_data) {
struct http_message hm;
int req_len;
const int is_req = (nc->listener != NULL);
-#ifndef NS_DISABLE_HTTP_WEBSOCKET
+#ifndef MG_DISABLE_HTTP_WEBSOCKET
struct mg_str *vec;
#endif
/*
* For HTTP messages without Content-Length, always send HTTP message
- * before NS_CLOSE message.
+ * before MG_EV_CLOSE message.
*/
- if (ev == NS_CLOSE && io->len > 0 &&
+ if (ev == MG_EV_CLOSE && io->len > 0 &&
mg_parse_http(io->buf, io->len, &hm, is_req) > 0) {
hm.message.len = io->len;
hm.body.len = io->buf + io->len - hm.body.p;
- nc->handler(nc, is_req ? NS_HTTP_REQUEST : NS_HTTP_REPLY, &hm);
+ nc->handler(nc, is_req ? MG_EV_HTTP_REQUEST : MG_EV_HTTP_REPLY, &hm);
free_http_proto_data(nc);
}
@@ -4009,7 +4009,7 @@ static void http_handler(struct mg_connection *nc, int ev, void *ev_data) {
nc->handler(nc, ev, ev_data);
- if (ev == NS_RECV) {
+ if (ev == MG_EV_RECV) {
struct mg_str *s;
req_len = mg_parse_http(io->buf, io->len, &hm, is_req);
@@ -4019,42 +4019,43 @@ static void http_handler(struct mg_connection *nc, int ev, void *ev_data) {
mg_handle_chunked(nc, &hm, io->buf + req_len, io->len - req_len);
}
- if (req_len < 0 || (req_len == 0 && io->len >= NS_MAX_HTTP_REQUEST_SIZE)) {
- nc->flags |= NSF_CLOSE_IMMEDIATELY;
+ if (req_len < 0 || (req_len == 0 && io->len >= MG_MAX_HTTP_REQUEST_SIZE)) {
+ nc->flags |= MG_F_CLOSE_IMMEDIATELY;
} else if (req_len == 0) {
/* Do nothing, request is not yet fully buffered */
}
-#ifndef NS_DISABLE_HTTP_WEBSOCKET
+#ifndef MG_DISABLE_HTTP_WEBSOCKET
else if (nc->listener == NULL &&
mg_get_http_header(&hm, "Sec-WebSocket-Accept")) {
/* We're websocket client, got handshake response from server. */
/* TODO(lsm): check the validity of accept Sec-WebSocket-Accept */
mbuf_remove(io, req_len);
nc->proto_handler = websocket_handler;
- nc->flags |= NSF_IS_WEBSOCKET;
- nc->handler(nc, NS_WEBSOCKET_HANDSHAKE_DONE, NULL);
- websocket_handler(nc, NS_RECV, ev_data);
+ nc->flags |= MG_F_IS_WEBSOCKET;
+ nc->handler(nc, MG_EV_WEBSOCKET_HANDSHAKE_DONE, NULL);
+ websocket_handler(nc, MG_EV_RECV, ev_data);
} else if (nc->listener != NULL &&
(vec = mg_get_http_header(&hm, "Sec-WebSocket-Key")) != NULL) {
/* This is a websocket request. Switch protocol handlers. */
mbuf_remove(io, req_len);
nc->proto_handler = websocket_handler;
- nc->flags |= NSF_IS_WEBSOCKET;
+ nc->flags |= MG_F_IS_WEBSOCKET;
/* Send handshake */
- nc->handler(nc, NS_WEBSOCKET_HANDSHAKE_REQUEST, &hm);
- if (!(nc->flags & NSF_CLOSE_IMMEDIATELY)) {
+ nc->handler(nc, MG_EV_WEBSOCKET_HANDSHAKE_REQUEST, &hm);
+ if (!(nc->flags & MG_F_CLOSE_IMMEDIATELY)) {
if (nc->send_mbuf.len == 0) {
ws_handshake(nc, vec);
}
- nc->handler(nc, NS_WEBSOCKET_HANDSHAKE_DONE, NULL);
- websocket_handler(nc, NS_RECV, ev_data);
+ nc->handler(nc, MG_EV_WEBSOCKET_HANDSHAKE_DONE, NULL);
+ websocket_handler(nc, MG_EV_RECV, ev_data);
}
}
-#endif /* NS_DISABLE_HTTP_WEBSOCKET */
+#endif /* MG_DISABLE_HTTP_WEBSOCKET */
else if (hm.message.len <= io->len) {
/* Whole HTTP message is fully buffered, call event handler */
- nc->handler(nc, nc->listener ? NS_HTTP_REQUEST : NS_HTTP_REPLY, &hm);
+ nc->handler(nc, nc->listener ? MG_EV_HTTP_REQUEST : MG_EV_HTTP_REPLY,
+ &hm);
mbuf_remove(io, hm.message.len);
}
}
@@ -4064,7 +4065,7 @@ void mg_set_protocol_http_websocket(struct mg_connection *nc) {
nc->proto_handler = http_handler;
}
-#ifndef NS_DISABLE_HTTP_WEBSOCKET
+#ifndef MG_DISABLE_HTTP_WEBSOCKET
void mg_send_websocket_handshake(struct mg_connection *nc, const char *uri,
const char *extra_headers) {
@@ -4082,9 +4083,9 @@ void mg_send_websocket_handshake(struct mg_connection *nc, const char *uri,
uri, key, extra_headers == NULL ? "" : extra_headers);
}
-#endif /* NS_DISABLE_HTTP_WEBSOCKET */
+#endif /* MG_DISABLE_HTTP_WEBSOCKET */
-#ifndef NS_DISABLE_FILESYSTEM
+#ifndef MG_DISABLE_FILESYSTEM
static void send_http_error(struct mg_connection *nc, int code,
const char *reason) {
if (reason == NULL) {
@@ -4093,7 +4094,7 @@ static void send_http_error(struct mg_connection *nc, int code,
mg_printf(nc, "HTTP/1.1 %d %s\r\nContent-Length: 0\r\n\r\n", code, reason);
}
-#ifndef NS_DISABLE_SSI
+#ifndef MG_DISABLE_SSI
static void send_ssi_file(struct mg_connection *, const char *, FILE *, int,
const struct mg_serve_http_opts *);
@@ -4151,7 +4152,7 @@ static void do_ssi_include(struct mg_connection *nc, const char *ssi, char *tag,
}
}
-#ifndef NS_DISABLE_POPEN
+#ifndef MG_DISABLE_POPEN
static void do_ssi_exec(struct mg_connection *nc, char *tag) {
char cmd[BUFSIZ];
FILE *fp;
@@ -4165,10 +4166,10 @@ static void do_ssi_exec(struct mg_connection *nc, char *tag) {
pclose(fp);
}
}
-#endif /* !NS_DISABLE_POPEN */
+#endif /* !MG_DISABLE_POPEN */
static void do_ssi_call(struct mg_connection *nc, char *tag) {
- mg_call(nc, NS_SSI_CALL, tag);
+ mg_call(nc, MG_EV_SSI_CALL, tag);
}
/*
@@ -4178,10 +4179,10 @@ static void do_ssi_call(struct mg_connection *nc, char *tag) {
static void send_ssi_file(struct mg_connection *nc, const char *path, FILE *fp,
int include_level,
const struct mg_serve_http_opts *opts) {
- static const struct mg_str btag = NS_STR("