mirror of
https://github.com/cesanta/mongoose.git
synced 2026-10-30 12:50:58 +00:00
Rename Mongoose constants: NS_ -> MG_, NSF_ -> MG_F_
PUBLISHED_FROM=c9cc54df1883aa17606de2b1ffb30f0cd687d037
This commit is contained in:
1 parent
32ab35f61f
commit
e1dd3f06fe
41 files changed
+887
-883
No files matched your search
@@ -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;
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
PROG = captive_dns_server
|
||||
MODULE_CFLAGS=-DNS_ENABLE_DNS_SERVER
|
||||
MODULE_CFLAGS=-DMG_ENABLE_DNS_SERVER
|
||||
|
||||
include ../rules.mk
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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"]
|
||||
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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)
|
||||
@@ -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)
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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];
|
||||
|
||||
|
||||
@@ -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)
|
||||
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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)
|
||||
@@ -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) {
|
||||
|
||||
@@ -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)
|
||||
@@ -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:
|
||||
|
||||
+2
-2
@@ -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)
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -67,7 +67,7 @@
|
||||
<h3>How to show device parameters on the page</h3>
|
||||
<p>This page has embedded
|
||||
<code><!--#call parameter_name --></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
|
||||
then can print some content, which will replace the
|
||||
<code><!--#call parameter_name --></code> block.
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user