Commit e1dd3f06 authored by Sergey Lyubka's avatar Sergey Lyubka Committed by Sergey Lyubka

Rename Mongoose constants: NS_ -> MG_, NSF_ -> MG_F_

    PUBLISHED_FROM=c9cc54df1883aa17606de2b1ffb30f0cd687d037
parent 32ab35f6
...@@ -10,9 +10,9 @@ static struct mg_serve_http_opts s_http_server_opts; ...@@ -10,9 +10,9 @@ static struct mg_serve_http_opts s_http_server_opts;
static int s_sig_num = 0; static int s_sig_num = 0;
static void *s_db_handle = NULL; static void *s_db_handle = NULL;
static const char *s_db_path = "api_server.db"; 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_get_method = MG_STR("GET");
static const struct mg_str s_put_method = NS_STR("PUT"); static const struct mg_str s_put_method = MG_STR("PUT");
static const struct mg_str s_delele_method = NS_STR("DELETE"); static const struct mg_str s_delele_method = MG_STR("DELETE");
static void signal_handler(int sig_num) { static void signal_handler(int sig_num) {
signal(sig_num, signal_handler); signal(sig_num, signal_handler);
...@@ -28,12 +28,12 @@ static int is_equal(const struct mg_str *s1, const struct mg_str *s2) { ...@@ -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 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 http_message *hm = (struct http_message *) ev_data;
struct mg_str key; struct mg_str key;
switch (ev) { switch (ev) {
case NS_HTTP_REQUEST: case MG_EV_HTTP_REQUEST:
if (has_prefix(&hm->uri, &api_prefix)) { if (has_prefix(&hm->uri, &api_prefix)) {
key.p = hm->uri.p + api_prefix.len; key.p = hm->uri.p + api_prefix.len;
key.len = hm->uri.len - api_prefix.len; key.len = hm->uri.len - api_prefix.len;
......
...@@ -96,9 +96,9 @@ static void rfc_ev_handler(struct mg_connection *nc, int ev, void *ev_data) { ...@@ -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)); int len = get_data_to_send(buf, sizeof(buf));
mg_printf(nc, "POST %s HTTP/1.0\r\nHost: %s\r\nContent-Lenght: %d" 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); "\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 { } else {
nc->flags |= NSF_CLOSE_IMMEDIATELY; nc->flags |= MG_F_CLOSE_IMMEDIATELY;
} }
break; break;
default: default:
......
...@@ -98,7 +98,7 @@ static void rfs_ev_handler(struct mg_connection *nc, int ev, void *ev_data) { ...@@ -98,7 +98,7 @@ static void rfs_ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
mg_send_http_chunk(nc, "", 0); mg_send_http_chunk(nc, "", 0);
break; break;
case NS_SEND: case NS_SEND:
nc->flags |= NSF_CLOSE_IMMEDIATELY; nc->flags |= MG_F_CLOSE_IMMEDIATELY;
break; break;
default: default:
......
PROG = captive_dns_server PROG = captive_dns_server
MODULE_CFLAGS=-DNS_ENABLE_DNS_SERVER MODULE_CFLAGS=-DMG_ENABLE_DNS_SERVER
include ../rules.mk include ../rules.mk
...@@ -23,13 +23,13 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) { ...@@ -23,13 +23,13 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
int i; int i;
switch (ev) { switch (ev) {
case NS_DNS_MESSAGE: case MG_DNS_MESSAGE:
msg = (struct mg_dmg_message *) ev_data; msg = (struct mg_dmg_message *) ev_data;
reply = mg_dmg_create_reply(&nc->send_mbuf, msg); reply = mg_dmg_create_reply(&nc->send_mbuf, msg);
for (i = 0; i < msg->num_questions; i++) { for (i = 0; i < msg->num_questions; i++) {
rr = &msg->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, mg_dmg_reply_record(&reply, rr, NULL, rr->rtype, 3600,
&s_our_ip_addr, 4); &s_our_ip_addr, 4);
} }
...@@ -37,8 +37,8 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) { ...@@ -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 * We don't set the error flag even if there were no answers
* maching the NS_DNS_A_RECORD query type. * maching the MG_DNS_A_RECORD query type.
* This indicates that we have (syntetic) answers for NS_DNS_A_RECORD. * This indicates that we have (syntetic) answers for MG_DNS_A_RECORD.
* See http://goo.gl/QWvufr for a distinction between NXDOMAIN and NODATA. * See http://goo.gl/QWvufr for a distinction between NXDOMAIN and NODATA.
*/ */
......
PROG = coap_client PROG = coap_client
SOURCES = $(PROG).c ../../mongoose.c 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) all: $(PROG)
......
...@@ -13,13 +13,13 @@ static char* s_default_address = "udp://coap.me:5683"; ...@@ -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) { static void coap_handler(struct mg_connection *nc, int ev, void *p) {
switch (ev) { switch (ev) {
case NS_CONNECT: { case MG_EV_CONNECT: {
struct mg_coap_message cm; struct mg_coap_message cm;
uint32_t res; uint32_t res;
memset(&cm, 0, sizeof(cm)); memset(&cm, 0, sizeof(cm));
cm.msg_id = 1; cm.msg_id = 1;
cm.msg_type = NS_COAP_MSG_CON; cm.msg_type = MG_COAP_MSG_CON;
printf("Sending CON...\n"); printf("Sending CON...\n");
res = mg_coap_send_message(nc, &cm); res = mg_coap_send_message(nc, &cm);
if (res == 0) { if (res == 0) {
...@@ -30,8 +30,8 @@ static void coap_handler(struct mg_connection *nc, int ev, void *p) { ...@@ -30,8 +30,8 @@ static void coap_handler(struct mg_connection *nc, int ev, void *p) {
} }
break; break;
} }
case NS_COAP_ACK: case MG_EV_COAP_ACK:
case NS_COAP_RST: { case MG_EV_COAP_RST: {
struct mg_coap_message *cm = (struct mg_coap_message *)p; struct mg_coap_message *cm = (struct mg_coap_message *)p;
printf("ACK/RST for message with msg_id = %d received\n", printf("ACK/RST for message with msg_id = %d received\n",
cm->msg_id); cm->msg_id);
......
PROG = coap_server PROG = coap_server
SOURCES = $(PROG).c ../../mongoose.c 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) all: $(PROG)
......
...@@ -19,7 +19,7 @@ static void signal_handler(int sig_num) { ...@@ -19,7 +19,7 @@ static void signal_handler(int sig_num) {
static void coap_handler(struct mg_connection *nc, int ev, void *p) { static void coap_handler(struct mg_connection *nc, int ev, void *p) {
switch (ev) { switch (ev) {
case NS_COAP_CON: { case MG_EV_COAP_CON: {
uint32_t res; uint32_t res;
struct mg_coap_message *cm = (struct mg_coap_message *)p; struct mg_coap_message *cm = (struct mg_coap_message *)p;
printf("CON with msg_id = %d received\n", cm->msg_id); 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) { ...@@ -32,9 +32,9 @@ static void coap_handler(struct mg_connection *nc, int ev, void *p) {
} }
break; break;
} }
case NS_COAP_NOC: case MG_EV_COAP_NOC:
case NS_COAP_ACK: case MG_EV_COAP_ACK:
case NS_COAP_RST: { case MG_EV_COAP_RST: {
struct mg_coap_message *cm = (struct mg_coap_message *)p; struct mg_coap_message *cm = (struct mg_coap_message *)p;
printf("ACK/RST/NOC with msg_id = %d received\n", printf("ACK/RST/NOC with msg_id = %d received\n",
cm->msg_id); cm->msg_id);
......
PROG = http_client PROG = http_client
SOURCES = $(PROG).c ../../mongoose.c 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) all: $(PROG)
......
...@@ -15,14 +15,14 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) { ...@@ -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; struct http_message *hm = (struct http_message *) ev_data;
switch (ev) { switch (ev) {
case NS_CONNECT: case MG_EV_CONNECT:
if (* (int *) ev_data != 0) { if (* (int *) ev_data != 0) {
fprintf(stderr, "connect() failed: %s\n", strerror(* (int *) ev_data)); fprintf(stderr, "connect() failed: %s\n", strerror(* (int *) ev_data));
s_exit_flag = 1; s_exit_flag = 1;
} }
break; break;
case NS_HTTP_REPLY: case MG_EV_HTTP_REPLY:
nc->flags |= NSF_CLOSE_IMMEDIATELY; nc->flags |= MG_F_CLOSE_IMMEDIATELY;
if (s_show_headers) { if (s_show_headers) {
fwrite(hm->message.p, 1, hm->message.len, stdout); fwrite(hm->message.p, 1, hm->message.len, stdout);
} else { } else {
......
...@@ -36,13 +36,13 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) { ...@@ -36,13 +36,13 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
char buf[100]; char buf[100];
switch (ev) { switch (ev) {
case NS_HTTP_REQUEST: case MG_EV_HTTP_REQUEST:
mg_rpc_dispatch(hm->body.p, hm->body.len, buf, sizeof(buf), mg_rpc_dispatch(hm->body.p, hm->body.len, buf, sizeof(buf),
methods, handlers); methods, handlers);
mg_printf(nc, "HTTP/1.0 200 OK\r\nContent-Length: %d\r\n" mg_printf(nc, "HTTP/1.0 200 OK\r\nContent-Length: %d\r\n"
"Content-Type: application/json\r\n\r\n%s", "Content-Type: application/json\r\n\r\n%s",
(int) strlen(buf), buf); (int) strlen(buf), buf);
nc->flags |= NSF_SEND_AND_CLOSE; nc->flags |= MG_F_SEND_AND_CLOSE;
break; break;
default: default:
break; break;
......
...@@ -4,7 +4,7 @@ COPY load_balancer.c /mongoose/ ...@@ -4,7 +4,7 @@ COPY load_balancer.c /mongoose/
WORKDIR /mongoose WORKDIR /mongoose
RUN mkdir /mongoose/certs; \ RUN mkdir /mongoose/certs; \
sed -i 's:#include "../../mongoose.h":#include "mongoose.h":' load_balancer.c; \ 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 EXPOSE 8000
VOLUME ["/mongoose/certs"] VOLUME ["/mongoose/certs"]
ENTRYPOINT ["/mongoose/load_balancer"] ENTRYPOINT ["/mongoose/load_balancer"]
...@@ -8,13 +8,13 @@ CFLAGS = -W -Wall -pthread $(CFLAGS_EXTRA) ...@@ -8,13 +8,13 @@ CFLAGS = -W -Wall -pthread $(CFLAGS_EXTRA)
ifeq ($(SSL), openssl) ifeq ($(SSL), openssl)
OPENSSL_PATH = ./openssl-0.9.8 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 CFLAGS_EXTRA += /link /libpath:$(OPENSSL_PATH)/lib ssleay32.lib libeay32.lib
endif endif
ifeq ($(SSL), krypton) ifeq ($(SSL), krypton)
KRYPTON_PATH = ../../../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 endif
all: $(PROG) all: $(PROG)
...@@ -23,7 +23,7 @@ $(PROG): $(SOURCES) ...@@ -23,7 +23,7 @@ $(PROG): $(SOURCES)
$(CC) $(SOURCES) -o $@ $(CFLAGS) $(CC) $(SOURCES) -o $@ $(CFLAGS)
$(PROG).exe: $(SOURCES) $(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) test: $(PROG)
$(MAKE) -C ../api_server $(MAKE) -C ../api_server
......
...@@ -60,7 +60,7 @@ static int s_num_vhost_backends = 0, s_num_default_backends = 0; ...@@ -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_sig_num = 0;
static int s_backend_keepalive = 0; static int s_backend_keepalive = 0;
static FILE *s_log_file = NULL; static FILE *s_log_file = NULL;
#ifdef NS_ENABLE_SSL #ifdef MG_ENABLE_SSL
const char *s_ssl_cert = NULL; const char *s_ssl_cert = NULL;
#endif #endif
...@@ -87,7 +87,7 @@ static void respond_with_error(struct conn_data *conn, const char *err_line) { ...@@ -87,7 +87,7 @@ static void respond_with_error(struct conn_data *conn, const char *err_line) {
send_http_err(nc, err_line); send_http_err(nc, err_line);
conn->client.flags.headers_sent = 1; 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) { 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, ...@@ -203,10 +203,10 @@ static void forward(struct conn_data *conn, struct http_message *hm,
} }
/* Headers. */ /* 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 hn = hm->header_names[i];
struct mg_str hv = hm->header_values[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, * If we terminate SSL and backend redirects to local HTTP port,
* strip protocol to let client use HTTPS. * strip protocol to let client use HTTPS.
...@@ -330,17 +330,17 @@ static void idle_backend_handler(struct mg_connection *nc, int ev, ...@@ -330,17 +330,17 @@ static void idle_backend_handler(struct mg_connection *nc, int ev,
bec->idle_deadline); bec->idle_deadline);
#endif #endif
switch (ev) { switch (ev) {
case NS_POLL: { case MG_EV_POLL: {
if (bec->idle_deadline > 0 && now > bec->idle_deadline) { if (bec->idle_deadline > 0 && now > bec->idle_deadline) {
#ifdef DEBUG #ifdef DEBUG
write_log("bec=%p nc=%p closing due to idleness\n", bec, bec->nc); write_log("bec=%p nc=%p closing due to idleness\n", bec, bec->nc);
#endif #endif
bec->nc->flags |= NSF_CLOSE_IMMEDIATELY; bec->nc->flags |= MG_F_CLOSE_IMMEDIATELY;
} }
break; break;
} }
case NS_CLOSE: { case MG_EV_CLOSE: {
#ifdef DEBUG #ifdef DEBUG
write_log("bec=%p closed\n", bec); write_log("bec=%p closed\n", bec);
#endif #endif
...@@ -377,14 +377,14 @@ void release_backend(struct conn_data *conn) { ...@@ -377,14 +377,14 @@ void release_backend(struct conn_data *conn) {
STAILQ_REMOVE_HEAD(&be->conns, conns); STAILQ_REMOVE_HEAD(&be->conns, conns);
be->num_conns--; be->num_conns--;
bec->idle_deadline = 0; bec->idle_deadline = 0;
bec->nc->flags = NSF_CLOSE_IMMEDIATELY; bec->nc->flags = MG_F_CLOSE_IMMEDIATELY;
#ifdef DEBUG #ifdef DEBUG
write_log("bec=%p evicted\n", bec); write_log("bec=%p evicted\n", bec);
#endif #endif
} }
} else { } else {
bec->idle_deadline = 0; bec->idle_deadline = 0;
bec->nc->flags |= NSF_CLOSE_IMMEDIATELY; bec->nc->flags |= MG_F_CLOSE_IMMEDIATELY;
} }
memset(&conn->backend, 0, sizeof(conn->backend)); memset(&conn->backend, 0, sizeof(conn->backend));
} }
...@@ -399,7 +399,7 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) { ...@@ -399,7 +399,7 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
#endif #endif
if (conn == NULL) { if (conn == NULL) {
if (ev == NS_ACCEPT) { if (ev == MG_EV_ACCEPT) {
conn = calloc(1, sizeof(*conn)); conn = calloc(1, sizeof(*conn));
if (conn == NULL) { if (conn == NULL) {
send_http_err(nc, s_error_500); send_http_err(nc, s_error_500);
...@@ -413,15 +413,15 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) { ...@@ -413,15 +413,15 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
} }
return; return;
} else { } else {
nc->flags |= NSF_CLOSE_IMMEDIATELY; nc->flags |= MG_F_CLOSE_IMMEDIATELY;
return; return;
} }
} }
if (ev != NS_POLL) conn->last_activity = now; if (ev != MG_EV_POLL) conn->last_activity = now;
switch (ev) { switch (ev) {
case NS_HTTP_REQUEST: { /* From client */ case MG_EV_HTTP_REQUEST: { /* From client */
assert(conn != NULL); assert(conn != NULL);
assert(conn->be_conn == NULL); assert(conn->be_conn == NULL);
struct http_message *hm = (struct http_message *) ev_data; 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) { ...@@ -434,7 +434,7 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
if (conn->backend.nc == NULL) { if (conn->backend.nc == NULL) {
/* This is a redirect, we're done. */ /* 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; break;
} }
...@@ -442,7 +442,7 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) { ...@@ -442,7 +442,7 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
break; break;
} }
case NS_CONNECT: { /* To backend */ case MG_EV_CONNECT: { /* To backend */
assert(conn != NULL); assert(conn != NULL);
assert(conn->be_conn != NULL); assert(conn->be_conn != NULL);
int status = *(int *) ev_data; int status = *(int *) ev_data;
...@@ -458,14 +458,14 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) { ...@@ -458,14 +458,14 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
break; break;
} }
case NS_HTTP_REPLY: { /* From backend */ case MG_EV_HTTP_REPLY: { /* From backend */
assert(conn != NULL); assert(conn != NULL);
struct http_message *hm = (struct http_message *) ev_data; struct http_message *hm = (struct http_message *) ev_data;
conn->backend.flags.keep_alive = s_backend_keepalive && is_keep_alive(hm); conn->backend.flags.keep_alive = s_backend_keepalive && is_keep_alive(hm);
forward(conn, hm, &conn->backend, &conn->client); forward(conn, hm, &conn->backend, &conn->client);
release_backend(conn); release_backend(conn);
if (!conn->client.flags.keep_alive) { if (!conn->client.flags.keep_alive) {
conn->client.nc->flags |= NSF_SEND_AND_CLOSE; conn->client.nc->flags |= MG_F_SEND_AND_CLOSE;
} else { } else {
#ifdef DEBUG #ifdef DEBUG
write_log("conn=%p remains open\n", conn); 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) { ...@@ -474,19 +474,19 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
break; break;
} }
case NS_POLL: { case MG_EV_POLL: {
assert(conn != NULL); assert(conn != NULL);
if (now - conn->last_activity > CONN_IDLE_TIMEOUT && if (now - conn->last_activity > CONN_IDLE_TIMEOUT &&
conn->backend.nc == NULL /* not waiting for backend */) { conn->backend.nc == NULL /* not waiting for backend */) {
#ifdef DEBUG #ifdef DEBUG
write_log("conn=%p has been idle for too long\n", conn); 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 #endif
} }
break; break;
} }
case NS_CLOSE: { case MG_EV_CLOSE: {
assert(conn != NULL); assert(conn != NULL);
if (nc == conn->client.nc) { if (nc == conn->client.nc) {
#ifdef DEBUG #ifdef DEBUG
...@@ -495,7 +495,7 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) { ...@@ -495,7 +495,7 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
#endif #endif
conn->client.nc = NULL; conn->client.nc = NULL;
if (conn->backend.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) { } else if (nc == conn->backend.nc) {
#ifdef DEBUG #ifdef DEBUG
...@@ -520,7 +520,7 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) { ...@@ -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) { static void print_usage_and_exit(const char *prog_name) {
fprintf(stderr, fprintf(stderr,
"Usage: %s [-D debug_dump_file] [-p http_port] [-l log] [-k]" "Usage: %s [-D debug_dump_file] [-p http_port] [-l log] [-k]"
#if NS_ENABLE_SSL #if MG_ENABLE_SSL
"[-s ssl_cert] " "[-s ssl_cert] "
#endif #endif
"<[-r] [-v vhost] -b uri_prefix[=replacement] host_port> ... \n", "<[-r] [-v vhost] -b uri_prefix[=replacement] host_port> ... \n",
...@@ -589,7 +589,7 @@ int main(int argc, char *argv[]) { ...@@ -589,7 +589,7 @@ int main(int argc, char *argv[]) {
vhost = NULL; vhost = NULL;
redirect = 0; redirect = 0;
i += 2; i += 2;
#ifdef NS_ENABLE_SSL #ifdef MG_ENABLE_SSL
} else if (strcmp(argv[i], "-s") == 0 && i + 1 < argc) { } else if (strcmp(argv[i], "-s") == 0 && i + 1 < argc) {
s_ssl_cert = argv[++i]; s_ssl_cert = argv[++i];
#endif #endif
...@@ -604,7 +604,7 @@ int main(int argc, char *argv[]) { ...@@ -604,7 +604,7 @@ int main(int argc, char *argv[]) {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
#if NS_ENABLE_SSL #if MG_ENABLE_SSL
if (s_ssl_cert != NULL) { if (s_ssl_cert != NULL) {
const char *err_str = mg_set_ssl(nc, s_ssl_cert, NULL); const char *err_str = mg_set_ssl(nc, s_ssl_cert, NULL);
if (err_str != NULL) { if (err_str != NULL) {
......
PROG = mqtt_broker PROG = mqtt_broker
SOURCES = $(PROG).c ../../mongoose.c 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) all: $(PROG)
...@@ -8,7 +8,7 @@ $(PROG): $(SOURCES) ...@@ -8,7 +8,7 @@ $(PROG): $(SOURCES)
$(CC) $(SOURCES) -o $@ $(CFLAGS) $(CC) $(SOURCES) -o $@ $(CFLAGS)
$(PROG).exe: $(SOURCES) $(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: clean:
rm -rf *.gc* *.dSYM *.exe *.obj *.o a.out $(PROG) rm -rf *.gc* *.dSYM *.exe *.obj *.o a.out $(PROG)
PROG = mqtt_client PROG = mqtt_client
SOURCES = $(PROG).c ../../mongoose.c 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) all: $(PROG)
...@@ -8,7 +8,7 @@ $(PROG): $(SOURCES) ...@@ -8,7 +8,7 @@ $(PROG): $(SOURCES)
$(CC) $(SOURCES) -o $@ $(CFLAGS) $(CC) $(SOURCES) -o $@ $(CFLAGS)
$(PROG).exe: $(SOURCES) $(PROG).exe: $(SOURCES)
cl $(SOURCES) /I../.. /DNS_ENABLE_SSL /MD /Fe$@ cl $(SOURCES) /I../.. /DMG_ENABLE_SSL /MD /Fe$@
clean: clean:
rm -rf *.gc* *.dSYM *.exe *.obj *.o a.out $(PROG) rm -rf *.gc* *.dSYM *.exe *.obj *.o a.out $(PROG)
...@@ -26,30 +26,30 @@ static void ev_handler(struct mg_connection *nc, int ev, void *p) { ...@@ -26,30 +26,30 @@ static void ev_handler(struct mg_connection *nc, int ev, void *p) {
(void) nc; (void) nc;
#if 0 #if 0
if (ev != NS_POLL) if (ev != MG_EV_POLL)
printf("USER HANDLER GOT %d\n", ev); printf("USER HANDLER GOT %d\n", ev);
#endif #endif
switch (ev) { switch (ev) {
case NS_CONNECT: case MG_EV_CONNECT:
mg_set_protocol_mqtt(nc); mg_set_protocol_mqtt(nc);
mg_send_mqtt_handshake(nc, "dummy"); mg_send_mqtt_handshake(nc, "dummy");
break; break;
case NS_MQTT_CONNACK: case MG_EV_MQTT_CONNACK:
if (msg->connack_ret_code != NS_MQTT_CONNACK_ACCEPTED) { if (msg->connack_ret_code != MG_EV_MQTT_CONNACK_ACCEPTED) {
printf("Got mqtt connection error: %d\n", msg->connack_ret_code); printf("Got mqtt connection error: %d\n", msg->connack_ret_code);
exit(1); exit(1);
} }
printf("Subscribing to '/stuff'\n"); printf("Subscribing to '/stuff'\n");
mg_mqtt_subscribe(nc, topic_expressions, sizeof(topic_expressions)/sizeof(*topic_expressions), 42); mg_mqtt_subscribe(nc, topic_expressions, sizeof(topic_expressions)/sizeof(*topic_expressions), 42);
break; break;
case NS_MQTT_PUBACK: case MG_EV_MQTT_PUBACK:
printf("Message publishing acknowledged (msg_id: %d)\n", msg->message_id); printf("Message publishing acknowledged (msg_id: %d)\n", msg->message_id);
break; break;
case NS_MQTT_SUBACK: case MG_EV_MQTT_SUBACK:
printf("Subscription acknowledged, forwarding to '/test'\n"); printf("Subscription acknowledged, forwarding to '/test'\n");
break; break;
case NS_MQTT_PUBLISH: case MG_EV_MQTT_PUBLISH:
{ {
#if 0 #if 0
char hex[1024] = {0}; char hex[1024] = {0};
...@@ -60,10 +60,10 @@ static void ev_handler(struct mg_connection *nc, int ev, void *p) { ...@@ -60,10 +60,10 @@ static void ev_handler(struct mg_connection *nc, int ev, void *p) {
#endif #endif
printf("Forwarding to /test\n"); 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; break;
case NS_CLOSE: case MG_EV_CLOSE:
printf("Connection closed\n"); printf("Connection closed\n");
exit(1); exit(1);
} }
......
PROG = multithreaded_restful_server PROG = multithreaded_restful_server
SOURCES = $(PROG).c ../../mongoose.c SOURCES = $(PROG).c ../../mongoose.c
APP_FLAGS = -DNS_ENABLE_THREADS $(CFLAGS_EXTRA) APP_FLAGS = -DMG_ENABLE_THREADS $(CFLAGS_EXTRA)
ifeq ($(OS), Windows_NT) ifeq ($(OS), Windows_NT)
APP_FLAGS += advapi32.lib APP_FLAGS += advapi32.lib
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
static const char *s_http_port = "8000"; static const char *s_http_port = "8000";
static void ev_handler(struct mg_connection *c, int ev, void *p) { 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; struct http_message *hm = (struct http_message *) p;
char reply[100]; char reply[100];
......
PROG = nc PROG = nc
SOURCES = $(PROG).c ../../mongoose.c 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) all: $(PROG)
...@@ -8,7 +8,7 @@ $(PROG): $(SOURCES) ...@@ -8,7 +8,7 @@ $(PROG): $(SOURCES)
$(CC) $(SOURCES) -o $@ $(CFLAGS) $(CC) $(SOURCES) -o $@ $(CFLAGS)
$(PROG).exe: $(SOURCES) $(PROG).exe: $(SOURCES)
cl $(SOURCES) /I../.. /DNS_ENABLE_SSL /MD /Fe$@ cl $(SOURCES) /I../.. /DMG_ENABLE_SSL /MD /Fe$@
clean: clean:
rm -rf *.gc* *.dSYM *.exe *.obj *.o a.out $(PROG) rm -rf *.gc* *.dSYM *.exe *.obj *.o a.out $(PROG)
...@@ -46,9 +46,9 @@ static void on_stdin_read(struct mg_connection *nc, int ev, void *p) { ...@@ -46,9 +46,9 @@ static void on_stdin_read(struct mg_connection *nc, int ev, void *p) {
if (ch < 0) { if (ch < 0) {
// EOF is received from stdin. Schedule the connection to close // 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) { if (nc->send_mbuf.len <= 0) {
nc->flags |= NSF_CLOSE_IMMEDIATELY; nc->flags |= MG_F_CLOSE_IMMEDIATELY;
} }
} else { } else {
// A character is received from stdin. Send it to the connection. // 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) { ...@@ -74,16 +74,16 @@ static void ev_handler(struct mg_connection *nc, int ev, void *p) {
(void) p; (void) p;
switch (ev) { switch (ev) {
case NS_ACCEPT: case MG_EV_ACCEPT:
case NS_CONNECT: case MG_EV_CONNECT:
mg_start_thread(stdio_thread_func, nc->mgr); mg_start_thread(stdio_thread_func, nc->mgr);
break; break;
case NS_CLOSE: case MG_EV_CLOSE:
s_received_signal = 1; s_received_signal = 1;
break; break;
case NS_RECV: case MG_EV_RECV:
fwrite(nc->recv_mbuf.buf, 1, nc->recv_mbuf.len, stdout); fwrite(nc->recv_mbuf.buf, 1, nc->recv_mbuf.len, stdout);
mbuf_remove(&nc->recv_mbuf, nc->recv_mbuf.len); mbuf_remove(&nc->recv_mbuf, nc->recv_mbuf.len);
break; break;
......
PROG = publish_subscribe PROG = publish_subscribe
SOURCES = $(PROG).c ../../mongoose.c 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) all: $(PROG)
......
...@@ -29,7 +29,7 @@ static void *stdin_thread(void *param) { ...@@ -29,7 +29,7 @@ static void *stdin_thread(void *param) {
static void server_handler(struct mg_connection *nc, int ev, void *p) { static void server_handler(struct mg_connection *nc, int ev, void *p) {
(void) p; (void) p;
if (ev == NS_RECV) { if (ev == MG_EV_RECV) {
// Push received message to all ncections // Push received message to all ncections
struct mbuf *io = &nc->recv_mbuf; struct mbuf *io = &nc->recv_mbuf;
struct mg_connection *c; struct mg_connection *c;
...@@ -45,14 +45,14 @@ static void client_handler(struct mg_connection *conn, int ev, void *p) { ...@@ -45,14 +45,14 @@ static void client_handler(struct mg_connection *conn, int ev, void *p) {
struct mbuf *io = &conn->recv_mbuf; struct mbuf *io = &conn->recv_mbuf;
(void) p; (void) p;
if (ev == NS_CONNECT) { if (ev == MG_EV_CONNECT) {
if (conn->flags & NSF_CLOSE_IMMEDIATELY) { if (conn->flags & MG_F_CLOSE_IMMEDIATELY) {
printf("%s\n", "Error connecting to server!"); printf("%s\n", "Error connecting to server!");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
printf("%s\n", "Connected to server. Type a message and press enter."); printf("%s\n", "Connected to server. Type a message and press enter.");
} else if (ev == NS_RECV) { } else if (ev == MG_EV_RECV) {
if (conn->flags & NSF_USER_1) { if (conn->flags & MG_F_USER_1) {
// Received data from the stdin, forward it to the server // Received data from the stdin, forward it to the server
struct mg_connection *c = (struct mg_connection *) conn->user_data; struct mg_connection *c = (struct mg_connection *) conn->user_data;
mg_send(c, io->buf, io->len); mg_send(c, io->buf, io->len);
...@@ -62,7 +62,7 @@ static void client_handler(struct mg_connection *conn, int ev, void *p) { ...@@ -62,7 +62,7 @@ static void client_handler(struct mg_connection *conn, int ev, void *p) {
fwrite(io->buf, io->len, 1, stdout); fwrite(io->buf, io->len, 1, stdout);
mbuf_remove(io, io->len); 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 // Connection has closed, most probably cause server has stopped
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
...@@ -93,7 +93,7 @@ int main(int argc, char *argv[]) { ...@@ -93,7 +93,7 @@ int main(int argc, char *argv[]) {
// The other end of a pair goes inside the server // The other end of a pair goes inside the server
ioconn = mg_add_sock(&mgr, fds[0], client_handler); 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; ioconn->user_data = server_conn;
} else { } else {
......
NS=../../mongoose.c NS=../../mongoose.c
FLAGS = ../../mongoose.c -I../.. 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 PROGS = device_side cloud_side
all: $(PROGS) all: $(PROGS)
......
...@@ -28,11 +28,11 @@ static void push_frame_to_clients(struct mg_mgr *mgr, ...@@ -28,11 +28,11 @@ static void push_frame_to_clients(struct mg_mgr *mgr,
const struct websocket_message *wm) { const struct websocket_message *wm) {
struct mg_connection *nc; 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. * my scanning the connection list provided by the mongoose manager.
*/ */
for (nc = mg_next(mgr, NULL); nc != NULL; nc = mg_next(mgr, nc)) { 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" mg_printf(nc, "--w00t\r\nContent-Type: image/jpeg\r\n"
"Content-Length: %lu\r\n\r\n", (unsigned long) wm->size); "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, ...@@ -50,7 +50,7 @@ static void send_command_to_the_device(struct mg_mgr *mgr,
const struct mg_str *cmd) { const struct mg_str *cmd) {
struct mg_connection *nc; struct mg_connection *nc;
for (nc = mg_next(mgr, NULL); nc != NULL; nc = mg_next(mgr, 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); 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); 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) { ...@@ -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; struct http_message *hm = (struct http_message *) ev_data;
switch (ev) { switch (ev) {
case NS_HTTP_REQUEST: case MG_EV_HTTP_REQUEST:
if (mg_vcmp(&hm->uri, "/mjpg") == 0) { 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", mg_printf(nc, "%s",
"HTTP/1.0 200 OK\r\n" "HTTP/1.0 200 OK\r\n"
"Cache-Control: no-cache\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) { ...@@ -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); mg_serve_http(nc, hm, web_root_opts);
} }
break; break;
case NS_WEBSOCKET_FRAME: case MG_EV_WEBSOCKET_FRAME:
printf("Got websocket frame, size %lu\n", (unsigned long) wm->size); printf("Got websocket frame, size %lu\n", (unsigned long) wm->size);
push_frame_to_clients(nc->mgr, wm); push_frame_to_clients(nc->mgr, wm);
break; break;
......
...@@ -85,7 +85,7 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) { ...@@ -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; struct websocket_message *wm = (struct websocket_message *) ev_data;
switch (ev) { switch (ev) {
case NS_CONNECT: case MG_EV_CONNECT:
printf("Reconnect: %s\n", * (int *) ev_data == 0 ? "ok" : "failed"); printf("Reconnect: %s\n", * (int *) ev_data == 0 ? "ok" : "failed");
if (* (int *) ev_data == 0) { if (* (int *) ev_data == 0) {
/* /*
...@@ -102,14 +102,14 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) { ...@@ -102,14 +102,14 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
mg_send_websocket_handshake(nc, "/stream", NULL); mg_send_websocket_handshake(nc, "/stream", NULL);
} }
break; break;
case NS_CLOSE: case MG_EV_CLOSE:
printf("Connection %p closed\n", nc); printf("Connection %p closed\n", nc);
client = NULL; client = NULL;
break; break;
case NS_POLL: case MG_EV_POLL:
send_mjpg_frame(nc, s_mjpg_file); send_mjpg_frame(nc, s_mjpg_file);
break; break;
case NS_WEBSOCKET_FRAME: case MG_EV_WEBSOCKET_FRAME:
printf("Got control command: [%.*s]\n", (int) wm->size, wm->data); printf("Got control command: [%.*s]\n", (int) wm->size, wm->data);
perform_control_command((const char*)wm->data, wm->size); perform_control_command((const char*)wm->data, wm->size);
break; break;
......
...@@ -16,7 +16,7 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) { ...@@ -16,7 +16,7 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
int connect_status; int connect_status;
switch (ev) { switch (ev) {
case NS_CONNECT: case MG_EV_CONNECT:
connect_status = * (int *) ev_data; connect_status = * (int *) ev_data;
if (connect_status == 0) { if (connect_status == 0) {
printf("Connected to %s, sending request...\n", s_target_address); 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) { ...@@ -28,9 +28,9 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
s_exit_flag = 1; s_exit_flag = 1;
} }
break; break;
case NS_HTTP_REPLY: case MG_EV_HTTP_REPLY:
printf("Got reply:\n%.*s\n", (int) hm->body.len, hm->body.p); 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; s_exit_flag = 1;
break; break;
default: default:
......
...@@ -3,9 +3,9 @@ SOURCES = $(PROG).c ../../mongoose.c ...@@ -3,9 +3,9 @@ SOURCES = $(PROG).c ../../mongoose.c
CFLAGS = -W -Wall -I../.. $(CFLAGS_EXTRA) CFLAGS = -W -Wall -I../.. $(CFLAGS_EXTRA)
ifeq ($(SSL), openssl) ifeq ($(SSL), openssl)
CFLAGS += -DNS_ENABLE_SSL -lssl -lcrypto -lcrypto CFLAGS += -DMG_ENABLE_SSL -lssl -lcrypto -lcrypto
else ifeq ($(SSL), krypton) else ifeq ($(SSL), krypton)
CFLAGS += -DNS_ENABLE_SSL ../../../krypton/krypton.c CFLAGS += -DMG_ENABLE_SSL ../../../krypton/krypton.c
endif endif
all: $(PROG) all: $(PROG)
...@@ -14,7 +14,7 @@ $(PROG): $(SOURCES) ...@@ -14,7 +14,7 @@ $(PROG): $(SOURCES)
$(CC) $(SOURCES) -o $@ $(CFLAGS) $(CC) $(SOURCES) -o $@ $(CFLAGS)
$(PROG).exe: $(SOURCES) $(PROG).exe: $(SOURCES)
cl $(SOURCES) /I../.. /MD /DNS_ENABLE_THREADS /Fe$@ advapi32.lib cl $(SOURCES) /I../.. /MD /DMG_ENABLE_THREADS /Fe$@ advapi32.lib
clean: clean:
rm -rf *.gc* *.dSYM *.exe *.obj *.o a.out $(PROG) rm -rf *.gc* *.dSYM *.exe *.obj *.o a.out $(PROG)
...@@ -29,7 +29,7 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) { ...@@ -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; struct http_message *hm = (struct http_message *) ev_data;
switch (ev) { switch (ev) {
case NS_HTTP_REQUEST: case MG_EV_HTTP_REQUEST:
if (mg_vcmp(&hm->uri, "/api/v1/sum") == 0) { if (mg_vcmp(&hm->uri, "/api/v1/sum") == 0) {
handle_sum_call(nc, hm); /* Handle RESTful call */ handle_sum_call(nc, hm); /* Handle RESTful call */
} else if (mg_vcmp(&hm->uri, "/printcontent") == 0) { } else if (mg_vcmp(&hm->uri, "/printcontent") == 0) {
...@@ -51,7 +51,7 @@ int main(int argc, char *argv[]) { ...@@ -51,7 +51,7 @@ int main(int argc, char *argv[]) {
struct mg_connection *nc; struct mg_connection *nc;
int i; int i;
char *cp; char *cp;
#ifdef NS_ENABLE_SSL #ifdef MG_ENABLE_SSL
const char *ssl_cert = NULL; const char *ssl_cert = NULL;
#endif #endif
...@@ -73,11 +73,11 @@ int main(int argc, char *argv[]) { ...@@ -73,11 +73,11 @@ int main(int argc, char *argv[]) {
s_http_server_opts.per_directory_auth_file = argv[++i]; s_http_server_opts.per_directory_auth_file = argv[++i];
} else if (strcmp(argv[i], "-r") == 0 && i + 1 < argc) { } else if (strcmp(argv[i], "-r") == 0 && i + 1 < argc) {
s_http_server_opts.url_rewrites = argv[++i]; 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) { } else if (strcmp(argv[i], "-i") == 0 && i + 1 < argc) {
s_http_server_opts.cgi_interpreter = argv[++i]; s_http_server_opts.cgi_interpreter = argv[++i];
#endif #endif
#ifdef NS_ENABLE_SSL #ifdef MG_ENABLE_SSL
} else if (strcmp(argv[i], "-s") == 0 && i + 1 < argc) { } else if (strcmp(argv[i], "-s") == 0 && i + 1 < argc) {
ssl_cert = argv[++i]; ssl_cert = argv[++i];
#endif #endif
...@@ -91,7 +91,7 @@ int main(int argc, char *argv[]) { ...@@ -91,7 +91,7 @@ int main(int argc, char *argv[]) {
exit(1); exit(1);
} }
#ifdef NS_ENABLE_SSL #ifdef MG_ENABLE_SSL
if (ssl_cert != NULL) { if (ssl_cert != NULL) {
const char *err_str = mg_set_ssl(nc, ssl_cert, NULL); const char *err_str = mg_set_ssl(nc, ssl_cert, NULL);
if (err_str != NULL) { if (err_str != NULL) {
......
...@@ -3,9 +3,9 @@ SOURCES = $(PROG).c ../../mongoose.c ...@@ -3,9 +3,9 @@ SOURCES = $(PROG).c ../../mongoose.c
CFLAGS = -W -Wall -I../.. $(CFLAGS_EXTRA) CFLAGS = -W -Wall -I../.. $(CFLAGS_EXTRA)
ifeq ($(SSL), openssl) ifeq ($(SSL), openssl)
CFLAGS += -DNS_ENABLE_SSL -lssl -lcrypto -lcrypto CFLAGS += -DMG_ENABLE_SSL -lssl -lcrypto -lcrypto
else ifeq ($(SSL), krypton) else ifeq ($(SSL), krypton)
CFLAGS += -DNS_ENABLE_SSL ../../../krypton/krypton.c CFLAGS += -DMG_ENABLE_SSL ../../../krypton/krypton.c
endif endif
all: $(PROG) all: $(PROG)
...@@ -14,7 +14,7 @@ $(PROG): $(SOURCES) ...@@ -14,7 +14,7 @@ $(PROG): $(SOURCES)
$(CC) $(SOURCES) -o $@ $(CFLAGS) $(CC) $(SOURCES) -o $@ $(CFLAGS)
$(PROG).exe: $(SOURCES) $(PROG).exe: $(SOURCES)
cl $(SOURCES) /I../.. /MD /DNS_ENABLE_THREADS /Fe$@ advapi32.lib cl $(SOURCES) /I../.. /MD /DMG_ENABLE_THREADS /Fe$@ advapi32.lib
clean: clean:
rm -rf *.gc* *.dSYM *.exe *.obj *.o a.out $(PROG) rm -rf *.gc* *.dSYM *.exe *.obj *.o a.out $(PROG)
...@@ -34,16 +34,16 @@ static void s3_handler(struct mg_connection *nc, int ev, void *ev_data) { ...@@ -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; struct mg_connection *nc2 = (struct mg_connection *) nc->user_data;
switch (ev) { switch (ev) {
case NS_HTTP_REPLY: case MG_EV_HTTP_REPLY:
if (nc2 != NULL) { if (nc2 != NULL) {
mg_printf_http_chunk(nc2, "Error: %.*s", (int) hm->message.len, mg_printf_http_chunk(nc2, "Error: %.*s", (int) hm->message.len,
hm->message.p); hm->message.p);
mg_send_http_chunk(nc2, "", 0); mg_send_http_chunk(nc2, "", 0);
} }
unlink_conns(nc); unlink_conns(nc);
nc->flags |= NSF_SEND_AND_CLOSE; nc->flags |= MG_F_SEND_AND_CLOSE;
break; break;
case NS_CLOSE: case MG_EV_CLOSE:
unlink_conns(nc); unlink_conns(nc);
break; break;
default: default:
...@@ -118,14 +118,14 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) { ...@@ -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; struct http_message *hm = (struct http_message *) ev_data;
switch (ev) { switch (ev) {
case NS_HTTP_REQUEST: case MG_EV_HTTP_REQUEST:
if (mg_vcmp(&hm->uri, "/upload") == 0) { if (mg_vcmp(&hm->uri, "/upload") == 0) {
handle_api_call(nc, hm); /* Handle RESTful call */ handle_api_call(nc, hm); /* Handle RESTful call */
} else { } else {
mg_serve_http(nc, hm, s_http_server_opts); /* Serve static content */ mg_serve_http(nc, hm, s_http_server_opts); /* Serve static content */
} }
break; break;
case NS_CLOSE: case MG_EV_CLOSE:
unlink_conns(nc); unlink_conns(nc);
break; break;
default: default:
......
SOURCES = $(PROG).c ../../mongoose.c 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) all: $(PROG)
...@@ -7,7 +7,7 @@ $(PROG): $(SOURCES) ...@@ -7,7 +7,7 @@ $(PROG): $(SOURCES)
$(CC) $(SOURCES) -o $@ $(CFLAGS) $(CC) $(SOURCES) -o $@ $(CFLAGS)
$(PROG).exe: $(SOURCES) $(PROG).exe: $(SOURCES)
cl $(SOURCES) /I../.. /DNS_ENABLE_SSL /MD /Fe$@ cl $(SOURCES) /I../.. /DMG_ENABLE_SSL /MD /Fe$@
clean: clean:
rm -rf *.gc* *.dSYM *.exe *.obj *.o a.out $(PROG) rm -rf *.gc* *.dSYM *.exe *.obj *.o a.out $(PROG)
PROG = settings_panel PROG = settings_panel
SOURCES = $(PROG).c ../../mongoose.c 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) all: $(PROG)
......
...@@ -38,14 +38,14 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) { ...@@ -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; struct http_message *hm = (struct http_message *) ev_data;
switch (ev) { switch (ev) {
case NS_HTTP_REQUEST: case MG_EV_HTTP_REQUEST:
if (mg_vcmp(&hm->uri, "/save") == 0) { if (mg_vcmp(&hm->uri, "/save") == 0) {
handle_save(nc, hm); /* Handle RESTful call */ handle_save(nc, hm); /* Handle RESTful call */
} else { } else {
mg_serve_http(nc, hm, s_http_server_opts); /* Serve static content */ mg_serve_http(nc, hm, s_http_server_opts); /* Serve static content */
} }
break; break;
case NS_SSI_CALL: case MG_EV_SSI_CALL:
handle_ssi_call(nc, ev_data); handle_ssi_call(nc, ev_data);
break; break;
default: default:
......
...@@ -67,7 +67,7 @@ ...@@ -67,7 +67,7 @@
<h3>How to show device parameters on the page</h3> <h3>How to show device parameters on the page</h3>
<p>This page has embedded <p>This page has embedded
<code>&lt;!--#call parameter_name --&gt;</code> blocks. For each such <code>&lt;!--#call parameter_name --&gt;</code> blocks. For each such
block, mongoose triggers <code>NS_SSI_CALL</code> event, passing block, mongoose triggers <code>MG_EV_SSI_CALL</code> event, passing
<code>parameter_name</code> string as an event parameter. A callback <code>parameter_name</code> string as an event parameter. A callback
then can print some content, which will replace the then can print some content, which will replace the
<code>&lt;!--#call parameter_name --&gt;</code> block. <code>&lt;!--#call parameter_name --&gt;</code> block.
......
...@@ -7,7 +7,7 @@ static const char *s_http_port = "8000"; ...@@ -7,7 +7,7 @@ static const char *s_http_port = "8000";
static struct mg_serve_http_opts s_http_server_opts; static struct mg_serve_http_opts s_http_server_opts;
static void ev_handler(struct mg_connection *nc, int ev, void *p) { 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); mg_serve_http(nc, p, s_http_server_opts);
} }
} }
......
...@@ -23,7 +23,7 @@ static void ev_handler(struct mg_connection *nc, int ev, void *p) { ...@@ -23,7 +23,7 @@ static void ev_handler(struct mg_connection *nc, int ev, void *p) {
(void) p; (void) p;
switch (ev) { switch (ev) {
case NS_RECV: case MG_EV_RECV:
mg_send(nc, io->buf, io->len); // Echo message back mg_send(nc, io->buf, io->len); // Echo message back
mbuf_remove(io, io->len); // Discard message from recv buffer mbuf_remove(io, io->len); // Discard message from recv buffer
break; break;
......
...@@ -15,7 +15,7 @@ static void signal_handler(int sig_num) { ...@@ -15,7 +15,7 @@ static void signal_handler(int sig_num) {
} }
static int is_websocket(const struct mg_connection *nc) { 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) { 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) { ...@@ -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; struct websocket_message *wm = (struct websocket_message *) ev_data;
switch (ev) { switch (ev) {
case NS_HTTP_REQUEST: case MG_EV_HTTP_REQUEST:
/* Usual HTTP request - serve static files */ /* Usual HTTP request - serve static files */
mg_serve_http(nc, hm, s_http_server_opts); mg_serve_http(nc, hm, s_http_server_opts);
nc->flags |= NSF_SEND_AND_CLOSE; nc->flags |= MG_F_SEND_AND_CLOSE;
break; break;
case NS_WEBSOCKET_HANDSHAKE_DONE: case MG_EV_WEBSOCKET_HANDSHAKE_DONE:
/* New websocket connection. Tell everybody. */ /* New websocket connection. Tell everybody. */
broadcast(nc, "joined", 6); broadcast(nc, "joined", 6);
break; break;
case NS_WEBSOCKET_FRAME: case MG_EV_WEBSOCKET_FRAME:
/* New websocket message. Tell everybody. */ /* New websocket message. Tell everybody. */
broadcast(nc, (char *) wm->data, wm->size); broadcast(nc, (char *) wm->data, wm->size);
break; break;
case NS_CLOSE: case MG_EV_CLOSE:
/* Disconnect. Tell everybody. */ /* Disconnect. Tell everybody. */
if (is_websocket(nc)) { if (is_websocket(nc)) {
broadcast(nc, "left", 4); broadcast(nc, "left", 4);
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment