mirror of
https://github.com/cesanta/mongoose.git
synced 2026-10-25 12:04:47 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
62c896a872 | ||
|
|
2db07dfc3b | ||
|
|
34eb3f1e66 | ||
|
|
9d30e892e9 | ||
|
|
0aaba7a461 | ||
|
|
3d6b568c6e | ||
|
|
2b2816cfe4 | ||
|
|
2fa18b47db | ||
|
|
c8af7cdd27 | ||
|
|
f857f6394f | ||
|
|
97d733e129 | ||
|
|
77e44c7c0e | ||
|
|
abf89d32d9 | ||
|
|
177e05deb2 | ||
|
|
eb5645241c | ||
|
|
202300952c | ||
|
|
c7bea65ae7 | ||
|
|
d5a9000d46 | ||
|
|
f62018451f | ||
|
|
0a93e301c9 | ||
|
|
6fe9cae62a | ||
|
|
38e984a008 | ||
|
|
09e4254718 | ||
|
|
d4b55c4ceb | ||
|
|
7d5479985d | ||
|
|
6517af3dea | ||
|
|
7632a5e4af | ||
|
|
7f20c41dd5 | ||
|
|
66b23b11b0 | ||
|
|
448b44094a | ||
|
|
8bbb44f90c | ||
|
|
0fba87c755 | ||
|
|
fea648496c | ||
|
|
944a6b761c | ||
|
|
f1ae183752 | ||
|
|
a0ece4e969 | ||
|
|
0bb14abbdd | ||
|
|
4c37e49274 | ||
|
|
2a2bc33a89 | ||
|
|
41558bbf64 | ||
|
|
4d0cc95ff4 | ||
|
|
cfd28a4f7a | ||
|
|
5a0b6fc35a | ||
|
|
3e59e1c465 | ||
|
|
ae611a6e55 | ||
|
|
a7a2e3deb1 | ||
|
|
cae0a1cbc0 | ||
|
|
244e5f67d3 | ||
|
|
ff078882d5 | ||
|
|
8d76733fad | ||
|
|
fb3a5a7d90 | ||
|
|
f374ac5f9a | ||
|
|
02707364f0 | ||
|
|
104106b9cf | ||
|
|
474e065a30 | ||
|
|
27094896b1 | ||
|
|
cd48bcfd7d | ||
|
|
5baeba53d7 | ||
|
|
3a3b433849 | ||
|
|
a2192ae483 | ||
|
|
023b55f2e5 | ||
|
|
e4309d472b | ||
|
|
c5452fc2ec | ||
|
|
f78ee9d42e | ||
|
|
c8416cc17d | ||
|
|
cf0a969a65 | ||
|
|
06670d3401 | ||
|
|
7c0493071f | ||
|
|
c60fe0c6f6 |
No files matched your search
@@ -8,7 +8,7 @@ used by vast number of open source and
|
||||
commercial products - it even runs on the International Space station!
|
||||
Mongoose makes embedded network programming fast, robust, and easy.
|
||||
|
||||
- [Download Mongoose Source Code here](https://www.cesanta.com)
|
||||
- [Download Mongoose Source Code here](https://www.cesanta.com/download.html)
|
||||
|
||||
Looking for a complete IoT firmware solution?
|
||||
|
||||
@@ -17,9 +17,9 @@ Check out [Mongoose OS](https://mongoose-os.com) - open source embedded operatin
|
||||
# Support
|
||||
- [Study mongoose example code](https://github.com/cesanta/mongoose/tree/master/examples)
|
||||
- [Read User Guide and API reference](https://docs.cesanta.com/mongoose)
|
||||
- [Support Forum - ask your technical questions here] (http://forum.cesanta.com/index.php?p=/categories/mongoose)
|
||||
- [Commercial licensing and support available] (https://www.cesanta.com/services-support)
|
||||
- [Check our latest releases] (https://github.com/cesanta/mongoose/releases)
|
||||
- [Support Forum - ask your technical questions here](https://forum.mongoose-os.com/categories/mongoose)
|
||||
- [Commercial licensing and support available](https://www.cesanta.com/licensing.html)
|
||||
- [Check our latest releases](https://github.com/cesanta/mongoose/releases)
|
||||
|
||||
# Features
|
||||
|
||||
@@ -47,7 +47,7 @@ Check out [Mongoose OS](https://mongoose-os.com) - open source embedded operatin
|
||||
|
||||
Mongoose is released under Commercial and [GNU GPL v.2](http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) open source licenses.
|
||||
|
||||
Commercial Projects: [Contact us for commercial license.] (https://www.cesanta.com/contact)
|
||||
Commercial Projects: [Contact us for commercial license.](https://www.cesanta.com/contact.html)
|
||||
|
||||
# Dashboard Example
|
||||
|
||||
@@ -55,18 +55,14 @@ Mongoose is often used to implement device dashboards and real-time
|
||||
data exchange over Websocket. Here is a dashboard example that illustrates
|
||||
the functionality:
|
||||
|
||||

|
||||

|
||||
|
||||
[Developing a new product? Contact us today to discuss how Mongoose can help.
|
||||
](https://www.cesanta.com/contact)
|
||||
[Developing a new product? Contact us today to discuss how Mongoose can help.](https://www.cesanta.com/contact.html)
|
||||
|
||||
# Contributions
|
||||
|
||||
To submit contributions, sign
|
||||
[Cesanta CLA](https://docs.cesanta.com/contributors_la.shtml)
|
||||
To submit contributions, sign [Cesanta CLA](https://cesanta.com/cla.html)
|
||||
and send GitHub pull request. You retain the copyright on your contributions.
|
||||
|
||||
# Looking for a pre-compiled Mongoose web server Windows or Mac binary?
|
||||
- [Download pre-compiled Mongoose web server binary.](https://www.cesanta.com/products/binary)
|
||||
|
||||
[](https://github.com/cesanta/mongoose)
|
||||
- [Download pre-compiled Mongoose web server binary.](https://www.cesanta.com/binary.html)
|
||||
@@ -3,6 +3,7 @@ title: "Server API reference"
|
||||
symbol_kind: "intro"
|
||||
decl_name: "http_server.h"
|
||||
items:
|
||||
- { name: mg_check_digest_auth.md }
|
||||
- { name: mg_file_upload_handler.md }
|
||||
- { name: mg_get_http_basic_auth.md }
|
||||
- { name: mg_get_http_header.md }
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
---
|
||||
title: "mg_check_digest_auth()"
|
||||
decl_name: "mg_check_digest_auth"
|
||||
symbol_kind: "func"
|
||||
signature: |
|
||||
int mg_check_digest_auth(struct mg_str method, struct mg_str uri,
|
||||
struct mg_str username, struct mg_str cnonce,
|
||||
struct mg_str response, struct mg_str qop,
|
||||
struct mg_str nc, struct mg_str nonce,
|
||||
struct mg_str auth_domain, FILE *fp);
|
||||
---
|
||||
|
||||
Authenticates given response params against an opened password file.
|
||||
Returns 1 if authenticated, 0 otherwise.
|
||||
|
||||
It's used by mg_http_check_digest_auth().
|
||||
|
||||
@@ -5,6 +5,7 @@ symbol_kind: "struct"
|
||||
signature: |
|
||||
struct mg_mqtt_proto_data {
|
||||
uint16_t keep_alive;
|
||||
double last_control_time;
|
||||
};
|
||||
---
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@ items:
|
||||
- { name: mg_check_ip_acl.md }
|
||||
- { name: mg_connect.md }
|
||||
- { name: mg_connect_opt.md }
|
||||
- { name: mg_enable_javascript.md }
|
||||
- { name: mg_mgr_free.md }
|
||||
- { name: mg_mgr_init.md }
|
||||
- { name: mg_mgr_init_opt.md }
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
---
|
||||
title: "mg_enable_javascript()"
|
||||
decl_name: "mg_enable_javascript"
|
||||
symbol_kind: "func"
|
||||
signature: |
|
||||
enum v7_err mg_enable_javascript(struct mg_mgr *m, struct v7 *v7,
|
||||
const char *init_js_file_name);
|
||||
---
|
||||
|
||||
Enables server-side JavaScript scripting.
|
||||
Requires a `-DMG_ENABLE_JAVASCRIPT` compilation flag and V7 engine sources.
|
||||
V7 instance must not be destroyed during manager's lifetime.
|
||||
Returns a V7 error.
|
||||
|
||||
@@ -14,10 +14,7 @@ signature: |
|
||||
void *user_data; /* User data */
|
||||
int num_ifaces;
|
||||
struct mg_iface **ifaces; /* network interfaces */
|
||||
#if MG_ENABLE_JAVASCRIPT
|
||||
struct v7 *v7;
|
||||
#endif
|
||||
const char *nameserver; /* DNS server to use */
|
||||
const char *nameserver; /* DNS server to use */
|
||||
};
|
||||
---
|
||||
|
||||
|
||||
@@ -14,16 +14,15 @@ items:
|
||||
- { name: mg_hexdump_connection.md }
|
||||
- { name: mg_hexdumpf.md }
|
||||
- { name: mg_is_big_endian.md }
|
||||
- { name: mg_match_prefix.md }
|
||||
- { name: mg_mbuf_append_base64.md }
|
||||
- { name: mg_mbuf_append_base64_putc.md }
|
||||
- { name: mg_next_comma_list_entry.md }
|
||||
- { name: mg_open.md }
|
||||
- { name: mg_skip.md }
|
||||
- { name: mg_sock_addr_to_str.md }
|
||||
- { name: mg_sock_to_str.md }
|
||||
- { name: mg_start_thread.md }
|
||||
- { name: mg_stat.md }
|
||||
- { name: mg_url_encode.md }
|
||||
---
|
||||
|
||||
|
||||
|
||||
@@ -3,8 +3,8 @@ title: "mg_conn_addr_to_str()"
|
||||
decl_name: "mg_conn_addr_to_str"
|
||||
symbol_kind: "func"
|
||||
signature: |
|
||||
void mg_conn_addr_to_str(struct mg_connection *nc, char *buf, size_t len,
|
||||
int flags);
|
||||
int mg_conn_addr_to_str(struct mg_connection *c, char *buf, size_t len,
|
||||
int flags);
|
||||
---
|
||||
|
||||
Converts a connection's local or remote address into string.
|
||||
@@ -17,5 +17,6 @@ see `MG_SOCK_STRINGIFY_*` definitions.
|
||||
- MG_SOCK_STRINGIFY_REMOTE - print remote peer's IP/port, not local address
|
||||
|
||||
If both port number and IP address are printed, they are separated by `:`.
|
||||
If compiled with `-DMG_ENABLE_IPV6`, IPv6 addresses are supported.
|
||||
If compiled with `-DMG_ENABLE_IPV6`, IPv6 addresses are supported.
|
||||
Return length of the stringified address.
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
---
|
||||
title: "mg_match_prefix()"
|
||||
decl_name: "mg_match_prefix"
|
||||
symbol_kind: "func"
|
||||
signature: |
|
||||
int mg_match_prefix(const char *pattern, int pattern_len, const char *str);
|
||||
---
|
||||
|
||||
Matches 0-terminated string (mg_match_prefix) or string with given length
|
||||
mg_match_prefix_n against a glob pattern.
|
||||
|
||||
Match is case-insensitive. Returns number of bytes matched, or -1 if no
|
||||
match.
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
---
|
||||
title: "mg_next_comma_list_entry()"
|
||||
decl_name: "mg_next_comma_list_entry"
|
||||
symbol_kind: "func"
|
||||
signature: |
|
||||
const char *mg_next_comma_list_entry(const char *list, struct mg_str *val,
|
||||
struct mg_str *eq_val);
|
||||
---
|
||||
|
||||
A helper function for traversing a comma separated list of values.
|
||||
It returns a list pointer shifted to the next value or NULL if the end
|
||||
of the list found.
|
||||
The value is stored in a val vector. If the value has a form "x=y", then
|
||||
eq_val vector is initialised to point to the "y" part, and val vector length
|
||||
is adjusted to point only to "x".
|
||||
If the list is just a comma separated list of entries, like "aa,bb,cc" then
|
||||
`eq_val` will contain zero-length string.
|
||||
|
||||
The purpose of this function is to parse comma separated string without
|
||||
any copying/memory allocation.
|
||||
|
||||
@@ -3,8 +3,8 @@ title: "mg_sock_addr_to_str()"
|
||||
decl_name: "mg_sock_addr_to_str"
|
||||
symbol_kind: "func"
|
||||
signature: |
|
||||
void mg_sock_addr_to_str(const union socket_address *sa, char *buf, size_t len,
|
||||
int flags);
|
||||
int mg_sock_addr_to_str(const union socket_address *sa, char *buf, size_t len,
|
||||
int flags);
|
||||
---
|
||||
|
||||
Convert the socket's address into string.
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
---
|
||||
title: "mg_url_encode()"
|
||||
decl_name: "mg_url_encode"
|
||||
symbol_kind: "func"
|
||||
signature: |
|
||||
struct mg_str mg_url_encode(const struct mg_str src);
|
||||
---
|
||||
|
||||
URL-escape the specified string.
|
||||
All non-printable characters are escaped, plus `._-$,;~()/`.
|
||||
Input need not be NUL-terminated, but the returned string is.
|
||||
Returned string is heap-allocated and must be free()'d.
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ CGI file must be executable. Mongoose honours the shebang line - see
|
||||
http://en.wikipedia.org/wiki/Shebang_(Unix).
|
||||
|
||||
For example, if both PHP and Perl CGIs are used, then
|
||||
``#!/path/to/php-cgi.exe` and ``#!/path/to/perl.exe` must be the first lines
|
||||
`#!/path/to/php-cgi.exe` and `#!/path/to/perl.exe` must be the first lines
|
||||
of the respective CGI scripts.
|
||||
|
||||
It is possible to hardcode the path to the CGI interpreter for all
|
||||
|
||||
+1
-1
@@ -30,4 +30,4 @@ int main(void) {
|
||||
}
|
||||
```
|
||||
|
||||
For the full example, please see the [Simplest HTTPS server example](https://github.com/cesanta/dev/tree/master/mongoose/examples/simplest_web_server_ssl).
|
||||
For the full example, please see the [Simplest HTTPS server example](https://github.com/cesanta/mongoose/tree/master/examples/simplest_web_server_ssl).
|
||||
@@ -22,7 +22,7 @@ IPATH = . ../.. $(REPO_PATH)
|
||||
|
||||
VPATH = ../..
|
||||
|
||||
MONGOOSE_FEATURES = -DMG_ENABLE_SSL -DMG_ENABLE_HTTP_STREAMING_MULTIPART
|
||||
MONGOOSE_FEATURES = -DMG_ENABLE_SSL -DMG_ENABLE_HTTP_STREAMING_MULTIPART -DMG_MODULE_LINES
|
||||
|
||||
SDK_FLAGS = -DUSE_FREERTOS -DSL_PLATFORM_MULTI_THREADED
|
||||
# -DTARGET_IS_CC3200 would reduce code size by using functions in ROM
|
||||
@@ -58,11 +58,11 @@ $(FW_DIR):
|
||||
$(FW_ZIP): $(FW_ELF) $(FW_BIN) $(SLFS_FILES)
|
||||
@echo " Code size: $(shell ls -l $(FW_BIN) | awk '{print $$5}')"
|
||||
@echo " GEN $(FW_MANIFEST)"
|
||||
@fw_meta gen_build_info \
|
||||
@fw_meta.py gen_build_info \
|
||||
--json_output=$(BUILD_INFO_JSON)
|
||||
@cp -v $(SLFS_FILES) out/
|
||||
@cp $(CC3200_SP_FILE)* $(FW_DIR)
|
||||
@fw_meta create_manifest \
|
||||
@fw_meta.py create_manifest \
|
||||
--name=$(PROG) --platform=$(PLATFORM) \
|
||||
--build_info=$(BUILD_INFO_JSON) \
|
||||
--output=$(FW_MANIFEST) \
|
||||
@@ -72,14 +72,14 @@ $(FW_ZIP): $(FW_ELF) $(FW_BIN) $(SLFS_FILES)
|
||||
/sys/mcuimg.bin:type=app,src=$(notdir $(FW_BIN)) \
|
||||
$(foreach f,$(SLFS_FILES), $(notdir $(f)):type=slfile,src=$(notdir $(f)))
|
||||
@echo " ZIP $@"
|
||||
@fw_meta create_fw \
|
||||
@fw_meta.py create_fw \
|
||||
--manifest=$(FW_MANIFEST) \
|
||||
--src_dir=$(FW_DIR) \
|
||||
--output=$@
|
||||
|
||||
FREERTOS_SRCS = timers.c list.c queue.c tasks.c port.c heap_3.c osi_freertos.c
|
||||
DRIVER_SRCS = cpu.c gpio.c gpio_if.c i2c.c i2c_if.c interrupt.c pin.c prcm.c spi.c uart.c udma.c utils.c
|
||||
SL_SRCS = socket.c wlan.c driver.c device.c netapp.c netcfg.c network_common.c cc_pal.c fs.c
|
||||
SL_SRCS = socket.c wlan.c driver.c device.c netapp.c netcfg.c network_common.c timer.c cc_pal.c fs.c
|
||||
SDK_SRCS = startup_gcc.c $(FREERTOS_SRCS) $(DRIVER_SRCS) $(SL_SRCS)
|
||||
IPATH += $(SDK_PATH) $(SDK_PATH)/inc $(SDK_PATH)/driverlib \
|
||||
$(SDK_PATH)/example/common $(SDK_PATH)/oslib \
|
||||
|
||||
@@ -294,3 +294,16 @@ void SimpleLinkGeneralEventHandler(SlDeviceEvent_t *e) {
|
||||
LOG(LL_ERROR, ("status %d sender %d", e->EventData.deviceEvent.status,
|
||||
e->EventData.deviceEvent.sender));
|
||||
}
|
||||
|
||||
#ifndef __TI_COMPILER_VERSION__
|
||||
int _gettimeofday_r(struct _reent *r, struct timeval *tp, void *tz) {
|
||||
#else
|
||||
int gettimeofday(struct timeval *tp, void *tz) {
|
||||
#endif
|
||||
unsigned long sec;
|
||||
unsigned short msec;
|
||||
MAP_PRCMRTCGet(&sec, &msec);
|
||||
tp->tv_sec = sec;
|
||||
tp->tv_usec = ((unsigned long) msec) * 1000;
|
||||
return 0;
|
||||
}
|
||||
@@ -1 +1 @@
|
||||
docker.cesanta.com/cc3200-build:1.2.0-r8
|
||||
docker.cesanta.com/cc3200-build:1.3.0-r2
|
||||
@@ -1,4 +1,4 @@
|
||||
PROG = mqtt_broker
|
||||
MODULE_CFLAGS = -DMG_ENABLE_MQTT_BROKER -DMG_ENABLE_HTTP=0
|
||||
SSL_LIB=openssl
|
||||
#SSL_LIB=openssl
|
||||
include ../examples.mk
|
||||
@@ -17,22 +17,31 @@
|
||||
|
||||
#include "../../mongoose.h"
|
||||
|
||||
static const char *s_listening_address = "0.0.0.0:1883";
|
||||
|
||||
static void ev_handler(struct mg_connection *c, int ev, void *ev_data) {
|
||||
if (ev != MG_EV_POLL) printf("USER HANDLER GOT EVENT %d\n", ev);
|
||||
/* Do your custom event processing here */
|
||||
mg_mqtt_broker(c, ev, ev_data);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
struct mg_mgr mgr;
|
||||
const char *address = "0.0.0.0:1883";
|
||||
struct mg_connection *nc;
|
||||
struct mg_connection *c;
|
||||
struct mg_mqtt_broker brk;
|
||||
|
||||
mg_mgr_init(&mgr, NULL);
|
||||
mg_mqtt_broker_init(&brk, NULL);
|
||||
|
||||
if ((nc = mg_bind(&mgr, address, mg_mqtt_broker)) == NULL) {
|
||||
fprintf(stderr, "mg_bind(%s) failed\n", address);
|
||||
if ((c = mg_bind(&mgr, s_listening_address, ev_handler)) == NULL) {
|
||||
fprintf(stderr, "mg_bind(%s) failed\n", s_listening_address);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
nc->user_data = &brk;
|
||||
mg_mqtt_broker_init(&brk, NULL);
|
||||
c->user_data = &brk;
|
||||
mg_set_protocol_mqtt(c);
|
||||
|
||||
printf("MQTT broker started on %s\n", address);
|
||||
printf("MQTT broker started on %s\n", s_listening_address);
|
||||
|
||||
/*
|
||||
* TODO: Add a HTTP status page that shows current sessions
|
||||
|
||||
@@ -27,10 +27,7 @@ static void ev_handler(struct mg_connection *nc, int ev, void *p) {
|
||||
struct mg_mqtt_message *msg = (struct mg_mqtt_message *) p;
|
||||
(void) nc;
|
||||
|
||||
#if 0
|
||||
if (ev != MG_EV_POLL)
|
||||
printf("USER HANDLER GOT %d\n", ev);
|
||||
#endif
|
||||
if (ev != MG_EV_POLL) printf("USER HANDLER GOT EVENT %d\n", ev);
|
||||
|
||||
switch (ev) {
|
||||
case MG_EV_CONNECT: {
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
PROG = mqtt_over_websocket_server
|
||||
MODULE_CFLAGS = -DMG_ENABLE_MQTT_BROKER=1
|
||||
#SSL_LIB=mbedtls
|
||||
include ../examples.mk
|
||||
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* Copyright (c) 2014 Cesanta Software Limited
|
||||
* All rights reserved
|
||||
* This software is dual-licensed: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation. For the terms of this
|
||||
* license, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* You are free to use this software under the terms of the GNU General
|
||||
* Public License, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU General Public License for more details.
|
||||
*
|
||||
* Alternatively, you can license this software under a commercial
|
||||
* license, as set out in <https://www.cesanta.com/license>.
|
||||
*/
|
||||
|
||||
#include "mongoose.h"
|
||||
|
||||
static const char *s_mqtt_address = "0.0.0.0:1883";
|
||||
static const char *s_http_address = "0.0.0.0:8080";
|
||||
|
||||
static void unproxy(struct mg_connection *c) {
|
||||
struct mg_connection *pc = (struct mg_connection *) c->user_data;
|
||||
if (pc != NULL) {
|
||||
pc->flags |= MG_F_CLOSE_IMMEDIATELY;
|
||||
pc->user_data = NULL;
|
||||
c->user_data = NULL;
|
||||
}
|
||||
printf("Closing connection %p\n", c);
|
||||
}
|
||||
|
||||
static void proxy_handler(struct mg_connection *c, int ev, void *ev_data) {
|
||||
if (ev == MG_EV_POLL) return;
|
||||
printf("%p %s EVENT %d %p\n", c, __func__, ev, ev_data);
|
||||
switch (ev) {
|
||||
case MG_EV_CLOSE: {
|
||||
unproxy(c);
|
||||
break;
|
||||
}
|
||||
case MG_EV_RECV: {
|
||||
struct mg_connection *pc = (struct mg_connection *) c->user_data;
|
||||
if (pc != NULL) {
|
||||
mg_send_websocket_frame(pc, WEBSOCKET_OP_BINARY, c->recv_mbuf.buf,
|
||||
c->recv_mbuf.len);
|
||||
mbuf_remove(&c->recv_mbuf, c->recv_mbuf.len);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void http_handler(struct mg_connection *c, int ev, void *ev_data) {
|
||||
struct mg_connection *pc = (struct mg_connection *) c->user_data;
|
||||
if (ev == MG_EV_POLL) return;
|
||||
printf("%p %s EVENT %d %p\n", c, __func__, ev, ev_data);
|
||||
/* Do your custom event processing here */
|
||||
switch (ev) {
|
||||
case MG_EV_WEBSOCKET_HANDSHAKE_DONE: {
|
||||
pc = mg_connect(c->mgr, s_mqtt_address, proxy_handler);
|
||||
pc->user_data = c;
|
||||
c->user_data = pc;
|
||||
printf("Created proxy connection %p\n", pc);
|
||||
break;
|
||||
}
|
||||
case MG_EV_WEBSOCKET_FRAME: {
|
||||
struct websocket_message *wm = (struct websocket_message *) ev_data;
|
||||
if (pc != NULL) {
|
||||
printf("Forwarding %d bytes\n", (int) wm->size);
|
||||
mg_send(pc, wm->data, wm->size);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case MG_EV_CLOSE: {
|
||||
unproxy(c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void mqtt_handler(struct mg_connection *c, int ev, void *ev_data) {
|
||||
if (ev == MG_EV_POLL) return;
|
||||
printf("%p %s EVENT %d %p\n", c, __func__, ev, ev_data);
|
||||
/* Do your custom event processing here */
|
||||
switch (ev) {
|
||||
case MG_EV_CLOSE:
|
||||
printf("Closing MQTT connection %p\n", c);
|
||||
break;
|
||||
}
|
||||
mg_mqtt_broker(c, ev, ev_data);
|
||||
}
|
||||
|
||||
static void start_mqtt_server(struct mg_mgr *mgr, const char *addr) {
|
||||
struct mg_connection *c;
|
||||
static struct mg_mqtt_broker brk; // static is important - must not perish
|
||||
if ((c = mg_bind(mgr, addr, mqtt_handler)) == NULL) {
|
||||
fprintf(stderr, "Cannot start MQTT server on port [%s]\n", addr);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
mg_mqtt_broker_init(&brk, NULL);
|
||||
c->user_data = &brk;
|
||||
mg_set_protocol_mqtt(c);
|
||||
printf("MQTT server started on %s\n", addr);
|
||||
}
|
||||
|
||||
static void start_http_server(struct mg_mgr *mgr, const char *addr) {
|
||||
struct mg_connection *c;
|
||||
if ((c = mg_bind(mgr, addr, http_handler)) == NULL) {
|
||||
fprintf(stderr, "Cannot start HTTP server on port [%s]\n", addr);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
mg_set_protocol_http_websocket(c);
|
||||
printf("HTTP server started on %s\n", addr);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
struct mg_mgr mgr;
|
||||
mg_mgr_init(&mgr, NULL);
|
||||
start_http_server(&mgr, s_http_address);
|
||||
start_mqtt_server(&mgr, s_mqtt_address);
|
||||
for (;;) {
|
||||
mg_mgr_poll(&mgr, 1000);
|
||||
}
|
||||
}
|
||||
+746
-462
File diff suppressed because it is too large.
Load diff
+194
-107
@@ -23,7 +23,7 @@
|
||||
#ifndef CS_MONGOOSE_SRC_COMMON_H_
|
||||
#define CS_MONGOOSE_SRC_COMMON_H_
|
||||
|
||||
#define MG_VERSION "6.7"
|
||||
#define MG_VERSION "6.9"
|
||||
|
||||
/* Local tweaks, applied before any of Mongoose's own headers. */
|
||||
#ifdef MG_LOCALS
|
||||
@@ -46,9 +46,10 @@
|
||||
#define CS_P_WINDOWS 2
|
||||
#define CS_P_ESP32 15
|
||||
#define CS_P_ESP8266 3
|
||||
#define CS_P_CC3200 4
|
||||
#define CS_P_MSP432 5
|
||||
#define CS_P_CC3100 6
|
||||
#define CS_P_CC3200 4
|
||||
#define CS_P_CC3220 17
|
||||
#define CS_P_MSP432 5
|
||||
#define CS_P_TM4C129 14
|
||||
#define CS_P_MBED 7
|
||||
#define CS_P_WINCE 8
|
||||
@@ -58,15 +59,17 @@
|
||||
#define CS_P_NRF52 10
|
||||
#define CS_P_PIC32 11
|
||||
#define CS_P_STM32 16
|
||||
/* Next id: 17 */
|
||||
/* Next id: 18 */
|
||||
|
||||
/* If not specified explicitly, we guess platform by defines. */
|
||||
#ifndef CS_PLATFORM
|
||||
|
||||
#if defined(TARGET_IS_MSP432P4XX) || defined(__MSP432P401R__)
|
||||
#define CS_PLATFORM CS_P_MSP432
|
||||
#elif defined(cc3200)
|
||||
#elif defined(cc3200) || defined(TARGET_IS_CC3200)
|
||||
#define CS_PLATFORM CS_P_CC3200
|
||||
#elif defined(cc3220) || defined(TARGET_IS_CC3220)
|
||||
#define CS_PLATFORM CS_P_CC3220
|
||||
#elif defined(__unix__) || defined(__APPLE__)
|
||||
#define CS_PLATFORM CS_P_UNIX
|
||||
#elif defined(WINCE)
|
||||
@@ -111,8 +114,9 @@
|
||||
/* Amalgamated: #include "common/platforms/platform_windows.h" */
|
||||
/* Amalgamated: #include "common/platforms/platform_esp32.h" */
|
||||
/* Amalgamated: #include "common/platforms/platform_esp8266.h" */
|
||||
/* Amalgamated: #include "common/platforms/platform_cc3200.h" */
|
||||
/* Amalgamated: #include "common/platforms/platform_cc3100.h" */
|
||||
/* Amalgamated: #include "common/platforms/platform_cc3200.h" */
|
||||
/* Amalgamated: #include "common/platforms/platform_cc3220.h" */
|
||||
/* Amalgamated: #include "common/platforms/platform_mbed.h" */
|
||||
/* Amalgamated: #include "common/platforms/platform_nrf51.h" */
|
||||
/* Amalgamated: #include "common/platforms/platform_nrf52.h" */
|
||||
@@ -223,14 +227,12 @@
|
||||
#endif
|
||||
#define snprintf _snprintf
|
||||
#define vsnprintf _vsnprintf
|
||||
#define sleep(x) Sleep((x) *1000)
|
||||
#define to64(x) _atoi64(x)
|
||||
#if !defined(__MINGW32__) && !defined(__MINGW64__)
|
||||
#define popen(x, y) _popen((x), (y))
|
||||
#define pclose(x) _pclose(x)
|
||||
#define fileno _fileno
|
||||
#endif
|
||||
#define rmdir _rmdir
|
||||
#if defined(_MSC_VER) && _MSC_VER >= 1400
|
||||
#define fseeko(x, y, z) _fseeki64((x), (y), (z))
|
||||
#else
|
||||
@@ -321,6 +323,9 @@ typedef struct _stati64 cs_stat_t;
|
||||
#define MG_NET_IF MG_NET_IF_SOCKET
|
||||
#endif
|
||||
|
||||
int rmdir(const char *dirname);
|
||||
unsigned int sleep(unsigned int seconds);
|
||||
|
||||
#endif /* CS_PLATFORM == CS_P_WINDOWS */
|
||||
#endif /* CS_COMMON_PLATFORMS_PLATFORM_WINDOWS_H_ */
|
||||
#ifdef MG_MODULE_LINES
|
||||
@@ -538,7 +543,9 @@ typedef struct stat cs_stat_t;
|
||||
#define SIZE_T_FMT "u"
|
||||
typedef struct stat cs_stat_t;
|
||||
#define DIRSEP '/'
|
||||
#if !defined(MGOS_VFS_DEFINE_DIRENT)
|
||||
#define CS_DEFINE_DIRENT
|
||||
#endif
|
||||
|
||||
#define to64(x) strtoll(x, NULL, 10)
|
||||
#define INT64_FMT PRId64
|
||||
@@ -546,7 +553,7 @@ typedef struct stat cs_stat_t;
|
||||
#define __cdecl
|
||||
#define _FILE_OFFSET_BITS 32
|
||||
|
||||
#ifndef RTOS_SDK
|
||||
#if !defined(RTOS_SDK) && !defined(__cplusplus)
|
||||
#define fileno(x) -1
|
||||
#endif
|
||||
|
||||
@@ -558,9 +565,9 @@ typedef struct stat cs_stat_t;
|
||||
#ifndef MG_NET_IF
|
||||
#include <lwip/opt.h>
|
||||
#if LWIP_SOCKET /* RTOS SDK has LWIP sockets */
|
||||
# define MG_NET_IF MG_NET_IF_SOCKET
|
||||
#define MG_NET_IF MG_NET_IF_SOCKET
|
||||
#else
|
||||
# define MG_NET_IF MG_NET_IF_LWIP_LOW_LEVEL
|
||||
#define MG_NET_IF MG_NET_IF_LWIP_LOW_LEVEL
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -601,7 +608,7 @@ typedef struct stat cs_stat_t;
|
||||
|
||||
#include <simplelink.h>
|
||||
#include <netapp.h>
|
||||
#undef timeval
|
||||
#undef timeval
|
||||
|
||||
typedef int sock_t;
|
||||
#define INVALID_SOCKET (-1)
|
||||
@@ -700,7 +707,7 @@ struct stat {
|
||||
};
|
||||
|
||||
int _stat(const char *pathname, struct stat *st);
|
||||
#define stat(a, b) _stat(a, b)
|
||||
int stat(const char *pathname, struct stat *st);
|
||||
|
||||
#define __S_IFMT 0170000
|
||||
|
||||
@@ -716,8 +723,10 @@ int _stat(const char *pathname, struct stat *st);
|
||||
#define S_ISDIR(mode) __S_ISTYPE((mode), __S_IFDIR)
|
||||
#define S_ISREG(mode) __S_ISTYPE((mode), __S_IFREG)
|
||||
|
||||
/* As of 5.2.7, TI compiler does not support va_copy() yet. */
|
||||
/* 5.x series compilers don't have va_copy, 16.x do. */
|
||||
#if __TI_COMPILER_VERSION__ < 16000000
|
||||
#define va_copy(apc, ap) ((apc) = (ap))
|
||||
#endif
|
||||
|
||||
#endif /* __TI_COMPILER_VERSION__ */
|
||||
|
||||
@@ -838,7 +847,8 @@ int _stat(const char *pathname, struct stat *st);
|
||||
#define CS_ENABLE_STDIO 1
|
||||
#endif
|
||||
|
||||
#if (defined(CC3200_FS_SPIFFS) || defined(CC3200_FS_SLFS)) && !defined(MG_ENABLE_FILESYSTEM)
|
||||
#if (defined(CC3200_FS_SPIFFS) || defined(CC3200_FS_SLFS)) && \
|
||||
!defined(MG_ENABLE_FILESYSTEM)
|
||||
#define MG_ENABLE_FILESYSTEM 1
|
||||
#endif
|
||||
|
||||
@@ -882,15 +892,15 @@ typedef struct stat cs_stat_t;
|
||||
#define __cdecl
|
||||
|
||||
#ifndef MG_NET_IF
|
||||
# include <lwip/opt.h>
|
||||
# if LWIP_SOCKET
|
||||
# define MG_NET_IF MG_NET_IF_SOCKET
|
||||
# else
|
||||
# define MG_NET_IF MG_NET_IF_LWIP_LOW_LEVEL
|
||||
# endif
|
||||
# define MG_LWIP 1
|
||||
#include <lwip/opt.h>
|
||||
#if LWIP_SOCKET
|
||||
#define MG_NET_IF MG_NET_IF_SOCKET
|
||||
#else
|
||||
#define MG_NET_IF MG_NET_IF_LWIP_LOW_LEVEL
|
||||
#endif
|
||||
#define MG_LWIP 1
|
||||
#elif MG_NET_IF == MG_NET_IF_SIMPLELINK
|
||||
# include "common/platforms/simplelink/cs_simplelink.h"
|
||||
/* Amalgamated: #include "common/platforms/simplelink/cs_simplelink.h" */
|
||||
#endif
|
||||
|
||||
#ifndef CS_ENABLE_STDIO
|
||||
@@ -1012,16 +1022,16 @@ in_addr_t inet_addr(const char *cp);
|
||||
|
||||
#define to64(x) strtoll(x, NULL, 10)
|
||||
|
||||
#define MG_NET_IF MG_NET_IF_LWIP_LOW_LEVEL
|
||||
#define MG_LWIP 1
|
||||
#define MG_ENABLE_IPV6 1
|
||||
#define MG_NET_IF MG_NET_IF_LWIP_LOW_LEVEL
|
||||
#define MG_LWIP 1
|
||||
#define MG_ENABLE_IPV6 1
|
||||
|
||||
/*
|
||||
* For ARM C Compiler, make lwip to export `struct timeval`; for other
|
||||
* compilers, suppress it.
|
||||
*/
|
||||
#if !defined(__ARMCC_VERSION)
|
||||
# define LWIP_TIMEVAL_PRIVATE 0
|
||||
#define LWIP_TIMEVAL_PRIVATE 0
|
||||
#else
|
||||
struct timeval;
|
||||
int gettimeofday(struct timeval *tp, void *tzp);
|
||||
@@ -1058,12 +1068,12 @@ int gettimeofday(struct timeval *tp, void *tzp);
|
||||
|
||||
#define to64(x) strtoll(x, NULL, 10)
|
||||
|
||||
#define MG_NET_IF MG_NET_IF_LWIP_LOW_LEVEL
|
||||
#define MG_LWIP 1
|
||||
#define MG_ENABLE_IPV6 1
|
||||
#define MG_NET_IF MG_NET_IF_LWIP_LOW_LEVEL
|
||||
#define MG_LWIP 1
|
||||
#define MG_ENABLE_IPV6 1
|
||||
|
||||
#if !defined(ENOSPC)
|
||||
# define ENOSPC 28 /* No space left on device */
|
||||
#define ENOSPC 28 /* No space left on device */
|
||||
#endif
|
||||
|
||||
/*
|
||||
@@ -1071,7 +1081,7 @@ int gettimeofday(struct timeval *tp, void *tzp);
|
||||
* compilers, suppress it.
|
||||
*/
|
||||
#if !defined(__ARMCC_VERSION)
|
||||
# define LWIP_TIMEVAL_PRIVATE 0
|
||||
#define LWIP_TIMEVAL_PRIVATE 0
|
||||
#endif
|
||||
|
||||
#define INT64_FMT PRId64
|
||||
@@ -1095,9 +1105,10 @@ int gettimeofday(struct timeval *tp, void *tzp);
|
||||
#ifndef CS_COMMON_PLATFORMS_SIMPLELINK_CS_SIMPLELINK_H_
|
||||
#define CS_COMMON_PLATFORMS_SIMPLELINK_CS_SIMPLELINK_H_
|
||||
|
||||
#if defined(MG_NET_IF) && MG_NET_IF == MG_NET_IF_SIMPLELINK
|
||||
|
||||
/* If simplelink.h is already included, all bets are off. */
|
||||
#if defined(MG_NET_IF) && MG_NET_IF == MG_NET_IF_SIMPLELINK && \
|
||||
!defined(__SIMPLELINK_H__)
|
||||
#if !defined(__SIMPLELINK_H__)
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
@@ -1111,6 +1122,12 @@ int gettimeofday(struct timeval *tp, void *tzp);
|
||||
#undef fd_set
|
||||
#endif
|
||||
|
||||
#if CS_PLATFORM == CS_P_CC3220
|
||||
#include <ti/drivers/net/wifi/porting/user.h>
|
||||
#include <ti/drivers/net/wifi/simplelink.h>
|
||||
#include <ti/drivers/net/wifi/sl_socket.h>
|
||||
#include <ti/drivers/net/wifi/netapp.h>
|
||||
#else
|
||||
/* We want to disable SL_INC_STD_BSD_API_NAMING, so we include user.h ourselves
|
||||
* and undef it. */
|
||||
#define PROVISIONING_API_H_
|
||||
@@ -1120,6 +1137,7 @@ int gettimeofday(struct timeval *tp, void *tzp);
|
||||
|
||||
#include <simplelink/include/simplelink.h>
|
||||
#include <simplelink/include/netapp.h>
|
||||
#endif /* CS_PLATFORM == CS_P_CC3220 */
|
||||
|
||||
/* Now define only the subset of the BSD API that we use.
|
||||
* Notably, close(), read() and write() are not defined. */
|
||||
@@ -1188,7 +1206,59 @@ int sl_set_ssl_opts(struct mg_connection *nc);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* MG_NET_IF == MG_NET_IF_SIMPLELINK && !defined(__SIMPLELINK_H__) */
|
||||
#endif /* !defined(__SIMPLELINK_H__) */
|
||||
|
||||
/* Compatibility with older versions of SimpleLink */
|
||||
#if SL_MAJOR_VERSION_NUM < 2
|
||||
|
||||
#define SL_ERROR_BSD_EAGAIN SL_EAGAIN
|
||||
#define SL_ERROR_BSD_EALREADY SL_EALREADY
|
||||
#define SL_ERROR_BSD_ENOPROTOOPT SL_ENOPROTOOPT
|
||||
#define SL_ERROR_BSD_ESECDATEERROR SL_ESECDATEERROR
|
||||
#define SL_ERROR_BSD_ESECSNOVERIFY SL_ESECSNOVERIFY
|
||||
#define SL_ERROR_FS_FAILED_TO_ALLOCATE_MEM SL_FS_ERR_FAILED_TO_ALLOCATE_MEM
|
||||
#define SL_ERROR_FS_FILE_HAS_NOT_BEEN_CLOSE_CORRECTLY \
|
||||
SL_FS_FILE_HAS_NOT_BEEN_CLOSE_CORRECTLY
|
||||
#define SL_ERROR_FS_FILE_NAME_EXIST SL_FS_FILE_NAME_EXIST
|
||||
#define SL_ERROR_FS_FILE_NOT_EXISTS SL_FS_ERR_FILE_NOT_EXISTS
|
||||
#define SL_ERROR_FS_NO_AVAILABLE_NV_INDEX SL_FS_ERR_NO_AVAILABLE_NV_INDEX
|
||||
#define SL_ERROR_FS_NOT_ENOUGH_STORAGE_SPACE SL_FS_ERR_NO_AVAILABLE_BLOCKS
|
||||
#define SL_ERROR_FS_NOT_SUPPORTED SL_FS_ERR_NOT_SUPPORTED
|
||||
#define SL_ERROR_FS_WRONG_FILE_NAME SL_FS_WRONG_FILE_NAME
|
||||
#define SL_ERROR_FS_INVALID_HANDLE SL_FS_ERR_INVALID_HANDLE
|
||||
#define SL_NETCFG_MAC_ADDRESS_GET SL_MAC_ADDRESS_GET
|
||||
#define SL_SOCKET_FD_ZERO SL_FD_ZERO
|
||||
#define SL_SOCKET_FD_SET SL_FD_SET
|
||||
#define SL_SOCKET_FD_ISSET SL_FD_ISSET
|
||||
#define SL_SO_SECURE_DOMAIN_NAME_VERIFICATION SO_SECURE_DOMAIN_NAME_VERIFICATION
|
||||
|
||||
#define SL_FS_READ FS_MODE_OPEN_READ
|
||||
#define SL_FS_WRITE FS_MODE_OPEN_WRITE
|
||||
|
||||
#define SL_FI_FILE_SIZE(fi) ((fi).FileLen)
|
||||
#define SL_FI_FILE_MAX_SIZE(fi) ((fi).AllocatedLen)
|
||||
|
||||
#define SlDeviceVersion_t SlVersionFull
|
||||
#define sl_DeviceGet sl_DevGet
|
||||
#define SL_DEVICE_GENERAL SL_DEVICE_GENERAL_CONFIGURATION
|
||||
#define SL_LEN_TYPE _u8
|
||||
#define SL_OPT_TYPE _u8
|
||||
|
||||
#else /* SL_MAJOR_VERSION_NUM >= 2 */
|
||||
|
||||
#define FS_MODE_OPEN_CREATE(max_size, flag) \
|
||||
(SL_FS_CREATE | SL_FS_CREATE_MAX_SIZE(max_size))
|
||||
#define SL_FI_FILE_SIZE(fi) ((fi).Len)
|
||||
#define SL_FI_FILE_MAX_SIZE(fi) ((fi).MaxSize)
|
||||
|
||||
#define SL_LEN_TYPE _u16
|
||||
#define SL_OPT_TYPE _u16
|
||||
|
||||
#endif /* SL_MAJOR_VERSION_NUM < 2 */
|
||||
|
||||
int slfs_open(const unsigned char *fname, uint32_t flags);
|
||||
|
||||
#endif /* MG_NET_IF == MG_NET_IF_SIMPLELINK */
|
||||
|
||||
#endif /* CS_COMMON_PLATFORMS_SIMPLELINK_CS_SIMPLELINK_H_ */
|
||||
#ifdef MG_MODULE_LINES
|
||||
@@ -1375,18 +1445,18 @@ typedef struct _stati64 {
|
||||
#endif
|
||||
|
||||
#ifndef _UINTPTR_T_DEFINED
|
||||
typedef unsigned int* uintptr_t;
|
||||
typedef unsigned int *uintptr_t;
|
||||
#endif
|
||||
|
||||
#define _S_IFREG 2
|
||||
#define _S_IFDIR 4
|
||||
|
||||
#ifndef S_ISDIR
|
||||
#define S_ISDIR(x) (((x) & _S_IFDIR) != 0)
|
||||
#define S_ISDIR(x) (((x) &_S_IFDIR) != 0)
|
||||
#endif
|
||||
|
||||
#ifndef S_ISREG
|
||||
#define S_ISREG(x) (((x) & _S_IFREG) != 0)
|
||||
#define S_ISREG(x) (((x) &_S_IFREG) != 0)
|
||||
#endif
|
||||
|
||||
int open(const char *filename, int oflag, int pmode);
|
||||
@@ -1423,7 +1493,8 @@ typedef struct stat cs_stat_t;
|
||||
#define MG_NET_IF MG_NET_IF_LWIP_LOW_LEVEL
|
||||
|
||||
/*
|
||||
* LPCXpress comes with 3 C library implementations: Newlib, NewlibNano and Redlib.
|
||||
* LPCXpress comes with 3 C library implementations: Newlib, NewlibNano and
|
||||
*Redlib.
|
||||
* See https://community.nxp.com/message/630860 for more details.
|
||||
*
|
||||
* Redlib is the default and lacks certain things, so we provide them.
|
||||
@@ -1519,7 +1590,7 @@ typedef TCP_SOCKET sock_t;
|
||||
#define CS_ENABLE_STDIO 1
|
||||
#endif
|
||||
|
||||
char* inet_ntoa(struct in_addr in);
|
||||
char *inet_ntoa(struct in_addr in);
|
||||
|
||||
#endif /* CS_PLATFORM == CS_P_PIC32 */
|
||||
|
||||
@@ -1726,6 +1797,8 @@ void cs_hmac_sha1(const unsigned char *key, size_t key_len,
|
||||
#ifndef CS_COMMON_CS_TIME_H_
|
||||
#define CS_COMMON_CS_TIME_H_
|
||||
|
||||
#include <time.h>
|
||||
|
||||
/* Amalgamated: #include "common/platform.h" */
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -1735,6 +1808,12 @@ extern "C" {
|
||||
/* Sub-second granularity time(). */
|
||||
double cs_time(void);
|
||||
|
||||
/*
|
||||
* Similar to (non-standard) timegm, converts broken-down time into the number
|
||||
* of seconds since Unix Epoch.
|
||||
*/
|
||||
double cs_timegm(const struct tm *tm);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
@@ -1757,7 +1836,7 @@ double cs_time(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
#endif
|
||||
|
||||
/* Describes chunk of memory */
|
||||
struct mg_str {
|
||||
@@ -1799,12 +1878,19 @@ struct mg_str mg_strdup(const struct mg_str s);
|
||||
*/
|
||||
struct mg_str mg_strdup_nul(const struct mg_str s);
|
||||
|
||||
/*
|
||||
* Locates character in a string.
|
||||
*/
|
||||
const char *mg_strchr(const struct mg_str s, int c);
|
||||
|
||||
int mg_strcmp(const struct mg_str str1, const struct mg_str str2);
|
||||
int mg_strncmp(const struct mg_str str1, const struct mg_str str2, size_t n);
|
||||
|
||||
const char *mg_strstr(const struct mg_str haystack, const struct mg_str needle);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif
|
||||
|
||||
#endif /* CS_COMMON_MG_STR_H_ */
|
||||
#ifdef MG_MODULE_LINES
|
||||
@@ -1953,6 +2039,7 @@ int cs_base64_decode(const unsigned char *s, int len, char *dst, int *dec_len);
|
||||
#include <stdlib.h>
|
||||
|
||||
/* Amalgamated: #include "common/platform.h" */
|
||||
/* Amalgamated: #include "common/mg_str.h" */
|
||||
|
||||
#ifndef CS_ENABLE_STRDUP
|
||||
#define CS_ENABLE_STRDUP 0
|
||||
@@ -2047,6 +2134,34 @@ int mg_asprintf(char **buf, size_t size, const char *fmt, ...);
|
||||
/* Same as mg_asprintf, but takes varargs list. */
|
||||
int mg_avprintf(char **buf, size_t size, const char *fmt, va_list ap);
|
||||
|
||||
/*
|
||||
* A helper function for traversing a comma separated list of values.
|
||||
* It returns a list pointer shifted to the next value or NULL if the end
|
||||
* of the list found.
|
||||
* The value is stored in a val vector. If the value has a form "x=y", then
|
||||
* eq_val vector is initialised to point to the "y" part, and val vector length
|
||||
* is adjusted to point only to "x".
|
||||
* If the list is just a comma separated list of entries, like "aa,bb,cc" then
|
||||
* `eq_val` will contain zero-length string.
|
||||
*
|
||||
* The purpose of this function is to parse comma separated string without
|
||||
* any copying/memory allocation.
|
||||
*/
|
||||
const char *mg_next_comma_list_entry(const char *list, struct mg_str *val,
|
||||
struct mg_str *eq_val);
|
||||
struct mg_str mg_next_comma_list_entry_n(struct mg_str list, struct mg_str *val,
|
||||
struct mg_str *eq_val);
|
||||
|
||||
/*
|
||||
* Matches 0-terminated string (mg_match_prefix) or string with given length
|
||||
* mg_match_prefix_n against a glob pattern.
|
||||
*
|
||||
* Match is case-insensitive. Returns number of bytes matched, or -1 if no
|
||||
* match.
|
||||
*/
|
||||
int mg_match_prefix(const char *pattern, int pattern_len, const char *str);
|
||||
int mg_match_prefix_n(const struct mg_str pattern, const struct mg_str str);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -2910,10 +3025,6 @@ struct { \
|
||||
#define MG_ENABLE_IPV6 0
|
||||
#endif
|
||||
|
||||
#ifndef MG_ENABLE_JAVASCRIPT
|
||||
#define MG_ENABLE_JAVASCRIPT 0
|
||||
#endif
|
||||
|
||||
#ifndef MG_ENABLE_MQTT
|
||||
#define MG_ENABLE_MQTT 1
|
||||
#endif
|
||||
@@ -3214,11 +3325,6 @@ int mg_ssl_if_write(struct mg_connection *nc, const void *data, size_t len);
|
||||
#ifndef CS_MONGOOSE_SRC_NET_H_
|
||||
#define CS_MONGOOSE_SRC_NET_H_
|
||||
|
||||
#if MG_ENABLE_JAVASCRIPT
|
||||
#define EXCLUDE_COMMON
|
||||
#include <v7.h>
|
||||
#endif
|
||||
|
||||
/* Amalgamated: #include "mongoose/src/common.h" */
|
||||
/* Amalgamated: #include "mongoose/src/net_if.h" */
|
||||
/* Amalgamated: #include "common/mbuf.h" */
|
||||
@@ -3281,10 +3387,7 @@ struct mg_mgr {
|
||||
void *user_data; /* User data */
|
||||
int num_ifaces;
|
||||
struct mg_iface **ifaces; /* network interfaces */
|
||||
#if MG_ENABLE_JAVASCRIPT
|
||||
struct v7 *v7;
|
||||
#endif
|
||||
const char *nameserver; /* DNS server to use */
|
||||
const char *nameserver; /* DNS server to use */
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -3748,17 +3851,6 @@ int mg_resolve(const char *domain_name, char *ip_addr_buf, size_t buf_len);
|
||||
*/
|
||||
int mg_check_ip_acl(const char *acl, uint32_t remote_ip);
|
||||
|
||||
#if MG_ENABLE_JAVASCRIPT
|
||||
/*
|
||||
* Enables server-side JavaScript scripting.
|
||||
* Requires a `-DMG_ENABLE_JAVASCRIPT` compilation flag and V7 engine sources.
|
||||
* V7 instance must not be destroyed during manager's lifetime.
|
||||
* Returns a V7 error.
|
||||
*/
|
||||
enum v7_err mg_enable_javascript(struct mg_mgr *m, struct v7 *v7,
|
||||
const char *init_js_file_name);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Schedules an MG_EV_TIMER event to be delivered at `timestamp` time.
|
||||
* `timestamp` is UNIX time (the number of seconds since Epoch). It is
|
||||
@@ -3889,8 +3981,12 @@ int mg_normalize_uri_path(const struct mg_str *in, struct mg_str *out);
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#ifndef MAX_PATH_SIZE
|
||||
#define MAX_PATH_SIZE 500
|
||||
#ifndef MG_MAX_PATH
|
||||
#ifdef PATH_MAX
|
||||
#define MG_MAX_PATH PATH_MAX
|
||||
#else
|
||||
#define MG_MAX_PATH 256
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
@@ -3995,9 +4091,10 @@ void mg_set_close_on_exec(sock_t);
|
||||
*
|
||||
* If both port number and IP address are printed, they are separated by `:`.
|
||||
* If compiled with `-DMG_ENABLE_IPV6`, IPv6 addresses are supported.
|
||||
* Return length of the stringified address.
|
||||
*/
|
||||
void mg_conn_addr_to_str(struct mg_connection *nc, char *buf, size_t len,
|
||||
int flags);
|
||||
int mg_conn_addr_to_str(struct mg_connection *c, char *buf, size_t len,
|
||||
int flags);
|
||||
#if MG_NET_IF == MG_NET_IF_SOCKET
|
||||
/* Legacy interface. */
|
||||
void mg_sock_to_str(sock_t sock, char *buf, size_t len, int flags);
|
||||
@@ -4008,8 +4105,8 @@ void mg_sock_to_str(sock_t sock, char *buf, size_t len, int flags);
|
||||
*
|
||||
* `flags` is MG_SOCK_STRINGIFY_IP and/or MG_SOCK_STRINGIFY_PORT.
|
||||
*/
|
||||
void mg_sock_addr_to_str(const union socket_address *sa, char *buf, size_t len,
|
||||
int flags);
|
||||
int mg_sock_addr_to_str(const union socket_address *sa, char *buf, size_t len,
|
||||
int flags);
|
||||
|
||||
#if MG_ENABLE_HEXDUMP
|
||||
/*
|
||||
@@ -4041,32 +4138,6 @@ void mg_hexdump_connection(struct mg_connection *nc, const char *path,
|
||||
*/
|
||||
int mg_is_big_endian(void);
|
||||
|
||||
/*
|
||||
* A helper function for traversing a comma separated list of values.
|
||||
* It returns a list pointer shifted to the next value or NULL if the end
|
||||
* of the list found.
|
||||
* The value is stored in a val vector. If the value has a form "x=y", then
|
||||
* eq_val vector is initialised to point to the "y" part, and val vector length
|
||||
* is adjusted to point only to "x".
|
||||
* If the list is just a comma separated list of entries, like "aa,bb,cc" then
|
||||
* `eq_val` will contain zero-length string.
|
||||
*
|
||||
* The purpose of this function is to parse comma separated string without
|
||||
* any copying/memory allocation.
|
||||
*/
|
||||
const char *mg_next_comma_list_entry(const char *list, struct mg_str *val,
|
||||
struct mg_str *eq_val);
|
||||
|
||||
/*
|
||||
* Matches 0-terminated string (mg_match_prefix) or string with given length
|
||||
* mg_match_prefix_n against a glob pattern.
|
||||
*
|
||||
* Match is case-insensitive. Returns number of bytes matched, or -1 if no
|
||||
* match.
|
||||
*/
|
||||
int mg_match_prefix(const char *pattern, int pattern_len, const char *str);
|
||||
int mg_match_prefix_n(const struct mg_str pattern, const struct mg_str str);
|
||||
|
||||
/*
|
||||
* Use with cs_base64_init/update/finish in order to write out base64 in chunks.
|
||||
*/
|
||||
@@ -4085,6 +4156,14 @@ void mg_mbuf_append_base64(struct mbuf *mbuf, const void *data, size_t len);
|
||||
void mg_basic_auth_header(const struct mg_str user, const struct mg_str pass,
|
||||
struct mbuf *buf);
|
||||
|
||||
/*
|
||||
* URL-escape the specified string.
|
||||
* All non-printable characters are escaped, plus `._-$,;~()/`.
|
||||
* Input need not be NUL-terminated, but the returned string is.
|
||||
* Returned string is heap-allocated and must be free()'d.
|
||||
*/
|
||||
struct mg_str mg_url_encode(const struct mg_str src);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
@@ -4121,14 +4200,6 @@ extern "C" {
|
||||
#define MG_MAX_HTTP_REQUEST_SIZE 1024
|
||||
#endif
|
||||
|
||||
#ifndef MG_MAX_PATH
|
||||
#ifdef PATH_MAX
|
||||
#define MG_MAX_PATH PATH_MAX
|
||||
#else
|
||||
#define MG_MAX_PATH 256
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef MG_MAX_HTTP_SEND_MBUF
|
||||
#define MG_MAX_HTTP_SEND_MBUF 1024
|
||||
#endif
|
||||
@@ -4865,6 +4936,18 @@ void mg_register_http_endpoint_opt(struct mg_connection *nc,
|
||||
int mg_http_check_digest_auth(struct http_message *hm, const char *auth_domain,
|
||||
FILE *fp);
|
||||
|
||||
/*
|
||||
* Authenticates given response params against an opened password file.
|
||||
* Returns 1 if authenticated, 0 otherwise.
|
||||
*
|
||||
* It's used by mg_http_check_digest_auth().
|
||||
*/
|
||||
int mg_check_digest_auth(struct mg_str method, struct mg_str uri,
|
||||
struct mg_str username, struct mg_str cnonce,
|
||||
struct mg_str response, struct mg_str qop,
|
||||
struct mg_str nc, struct mg_str nonce,
|
||||
struct mg_str auth_domain, FILE *fp);
|
||||
|
||||
/*
|
||||
* Sends buffer `buf` of size `len` to the client using chunked HTTP encoding.
|
||||
* This function sends the buffer size as hex number + newline first, then
|
||||
@@ -5070,6 +5153,7 @@ int mg_http_create_digest_auth_header(char *buf, size_t buf_len,
|
||||
struct mg_mqtt_message {
|
||||
int cmd;
|
||||
int qos;
|
||||
int len; /* message length in the IO buffer */
|
||||
struct mg_str topic;
|
||||
struct mg_str payload;
|
||||
|
||||
@@ -5105,6 +5189,7 @@ struct mg_send_mqtt_handshake_opts {
|
||||
/* mg_mqtt_proto_data should be in header to allow external access to it */
|
||||
struct mg_mqtt_proto_data {
|
||||
uint16_t keep_alive;
|
||||
double last_control_time;
|
||||
};
|
||||
|
||||
/* Message types */
|
||||
@@ -5303,7 +5388,9 @@ int mg_mqtt_vmatch_topic_expression(const char *exp, struct mg_str topic);
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#define MG_MQTT_MAX_SESSION_SUBSCRIPTIONS 512;
|
||||
#ifndef MG_MQTT_MAX_SESSION_SUBSCRIPTIONS
|
||||
#define MG_MQTT_MAX_SESSION_SUBSCRIPTIONS 512
|
||||
#endif
|
||||
|
||||
struct mg_mqtt_broker;
|
||||
|
||||
|
||||
Reference in new issue
Block a user