mirror of
https://github.com/cesanta/mongoose.git
synced 2026-10-26 12:14:56 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6e50fe4475 | ||
|
|
7942803a75 | ||
|
|
a8b74a9021 | ||
|
|
27a9a62843 | ||
|
|
9b268b6c77 | ||
|
|
3b3ac48edd | ||
|
|
598e96a0cc | ||
|
|
b5dd0e8093 | ||
|
|
9b24fdfd1d | ||
|
|
8313896a85 | ||
|
|
8193302162 | ||
|
|
6e3e5560d0 | ||
|
|
f0c6630a16 | ||
|
|
1db747da29 | ||
|
|
8065439f96 | ||
|
|
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!
|
commercial products - it even runs on the International Space station!
|
||||||
Mongoose makes embedded network programming fast, robust, and easy.
|
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?
|
Looking for a complete IoT firmware solution?
|
||||||
|
|
||||||
@@ -17,9 +17,9 @@ Check out [Mongoose OS](https://mongoose-os.com) - open source embedded operatin
|
|||||||
# Support
|
# Support
|
||||||
- [Study mongoose example code](https://github.com/cesanta/mongoose/tree/master/examples)
|
- [Study mongoose example code](https://github.com/cesanta/mongoose/tree/master/examples)
|
||||||
- [Read User Guide and API reference](https://docs.cesanta.com/mongoose)
|
- [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)
|
- [Support Forum - ask your technical questions here](https://forum.mongoose-os.com/categories/mongoose)
|
||||||
- [Commercial licensing and support available] (https://www.cesanta.com/services-support)
|
- [Commercial licensing and support available](https://www.cesanta.com/licensing.html)
|
||||||
- [Check our latest releases] (https://github.com/cesanta/mongoose/releases)
|
- [Check our latest releases](https://github.com/cesanta/mongoose/releases)
|
||||||
|
|
||||||
# Features
|
# 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.
|
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
|
# 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
|
data exchange over Websocket. Here is a dashboard example that illustrates
|
||||||
the functionality:
|
the functionality:
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
[Developing a new product? Contact us today to discuss how Mongoose can help.
|
[Developing a new product? Contact us today to discuss how Mongoose can help.](https://www.cesanta.com/contact.html)
|
||||||
](https://www.cesanta.com/contact)
|
|
||||||
|
|
||||||
# Contributions
|
# Contributions
|
||||||
|
|
||||||
To submit contributions, sign
|
To submit contributions, sign [Cesanta CLA](https://cesanta.com/cla.html)
|
||||||
[Cesanta CLA](https://docs.cesanta.com/contributors_la.shtml)
|
|
||||||
and send GitHub pull request. You retain the copyright on your contributions.
|
and send GitHub pull request. You retain the copyright on your contributions.
|
||||||
|
|
||||||
# Looking for a pre-compiled Mongoose web server Windows or Mac binary?
|
# 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)
|
- [Download pre-compiled Mongoose web server binary.](https://www.cesanta.com/binary.html)
|
||||||
|
|
||||||
[](https://github.com/cesanta/mongoose)
|
|
||||||
@@ -3,6 +3,7 @@ title: "Server API reference"
|
|||||||
symbol_kind: "intro"
|
symbol_kind: "intro"
|
||||||
decl_name: "http_server.h"
|
decl_name: "http_server.h"
|
||||||
items:
|
items:
|
||||||
|
- { name: mg_check_digest_auth.md }
|
||||||
- { name: mg_file_upload_handler.md }
|
- { name: mg_file_upload_handler.md }
|
||||||
- { name: mg_get_http_basic_auth.md }
|
- { name: mg_get_http_basic_auth.md }
|
||||||
- { name: mg_get_http_header.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: |
|
signature: |
|
||||||
struct mg_mqtt_proto_data {
|
struct mg_mqtt_proto_data {
|
||||||
uint16_t keep_alive;
|
uint16_t keep_alive;
|
||||||
|
double last_control_time;
|
||||||
};
|
};
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ items:
|
|||||||
- { name: mg_check_ip_acl.md }
|
- { name: mg_check_ip_acl.md }
|
||||||
- { name: mg_connect.md }
|
- { name: mg_connect.md }
|
||||||
- { name: mg_connect_opt.md }
|
- { name: mg_connect_opt.md }
|
||||||
- { name: mg_enable_javascript.md }
|
|
||||||
- { name: mg_mgr_free.md }
|
- { name: mg_mgr_free.md }
|
||||||
- { name: mg_mgr_init.md }
|
- { name: mg_mgr_init.md }
|
||||||
- { name: mg_mgr_init_opt.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 */
|
void *user_data; /* User data */
|
||||||
int num_ifaces;
|
int num_ifaces;
|
||||||
struct mg_iface **ifaces; /* network interfaces */
|
struct mg_iface **ifaces; /* network interfaces */
|
||||||
#if MG_ENABLE_JAVASCRIPT
|
const char *nameserver; /* DNS server to use */
|
||||||
struct v7 *v7;
|
|
||||||
#endif
|
|
||||||
const char *nameserver; /* DNS server to use */
|
|
||||||
};
|
};
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@@ -14,16 +14,15 @@ items:
|
|||||||
- { name: mg_hexdump_connection.md }
|
- { name: mg_hexdump_connection.md }
|
||||||
- { name: mg_hexdumpf.md }
|
- { name: mg_hexdumpf.md }
|
||||||
- { name: mg_is_big_endian.md }
|
- { name: mg_is_big_endian.md }
|
||||||
- { name: mg_match_prefix.md }
|
|
||||||
- { name: mg_mbuf_append_base64.md }
|
- { name: mg_mbuf_append_base64.md }
|
||||||
- { name: mg_mbuf_append_base64_putc.md }
|
- { name: mg_mbuf_append_base64_putc.md }
|
||||||
- { name: mg_next_comma_list_entry.md }
|
|
||||||
- { name: mg_open.md }
|
- { name: mg_open.md }
|
||||||
- { name: mg_skip.md }
|
- { name: mg_skip.md }
|
||||||
- { name: mg_sock_addr_to_str.md }
|
- { name: mg_sock_addr_to_str.md }
|
||||||
- { name: mg_sock_to_str.md }
|
- { name: mg_sock_to_str.md }
|
||||||
- { name: mg_start_thread.md }
|
- { name: mg_start_thread.md }
|
||||||
- { name: mg_stat.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"
|
decl_name: "mg_conn_addr_to_str"
|
||||||
symbol_kind: "func"
|
symbol_kind: "func"
|
||||||
signature: |
|
signature: |
|
||||||
void mg_conn_addr_to_str(struct mg_connection *nc, char *buf, size_t len,
|
int mg_conn_addr_to_str(struct mg_connection *c, char *buf, size_t len,
|
||||||
int flags);
|
int flags);
|
||||||
---
|
---
|
||||||
|
|
||||||
Converts a connection's local or remote address into string.
|
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
|
- 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 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"
|
decl_name: "mg_sock_addr_to_str"
|
||||||
symbol_kind: "func"
|
symbol_kind: "func"
|
||||||
signature: |
|
signature: |
|
||||||
void mg_sock_addr_to_str(const union socket_address *sa, char *buf, size_t len,
|
int mg_sock_addr_to_str(const union socket_address *sa, char *buf, size_t len,
|
||||||
int flags);
|
int flags);
|
||||||
---
|
---
|
||||||
|
|
||||||
Convert the socket's address into string.
|
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.
|
||||||
|
|
||||||
File renamed without changes.
@@ -1,7 +0,0 @@
|
|||||||
---
|
|
||||||
title: CoAP
|
|
||||||
items:
|
|
||||||
- { name: server_example.md }
|
|
||||||
- { name: client_example.md }
|
|
||||||
- { name: ../c-api/coap.h/ }
|
|
||||||
---
|
|
||||||
File renamed without changes.
@@ -1,7 +0,0 @@
|
|||||||
---
|
|
||||||
title: DNS client example
|
|
||||||
---
|
|
||||||
|
|
||||||
See https://github.com/cesanta/mongoose/blob/master/mongoose.c and search
|
|
||||||
for the `mg_resolve_async_eh()` function - that is the core of
|
|
||||||
built-in Mongoose async DNS resolver.
|
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
---
|
# Examples
|
||||||
title: DNS server example
|
|
||||||
---
|
|
||||||
|
## DNS server example
|
||||||
|
|
||||||
To create a DNS server, follow this pattern:
|
To create a DNS server, follow this pattern:
|
||||||
|
|
||||||
@@ -71,3 +72,10 @@ int main(int argc, char *argv[]) {
|
|||||||
```
|
```
|
||||||
|
|
||||||
See full [Captive DNS server example](https://github.com/cesanta/mongoose/tree/master/examples/captive_dns_server).
|
See full [Captive DNS server example](https://github.com/cesanta/mongoose/tree/master/examples/captive_dns_server).
|
||||||
|
|
||||||
|
|
||||||
|
## DNS client example
|
||||||
|
|
||||||
|
See https://github.com/cesanta/mongoose/blob/master/mongoose.c and search
|
||||||
|
for the `mg_resolve_async_eh()` function - that is the core of
|
||||||
|
built-in Mongoose async DNS resolver.
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
---
|
|
||||||
title: DNS
|
|
||||||
items:
|
|
||||||
- { name: server_example.md }
|
|
||||||
- { name: client_example.md }
|
|
||||||
- { name: ../c-api/dns.h/ }
|
|
||||||
- { name: ../c-api/dns_server.h/ }
|
|
||||||
---
|
|
||||||
+3
-5
@@ -1,6 +1,4 @@
|
|||||||
---
|
# CGI
|
||||||
title: CGI
|
|
||||||
---
|
|
||||||
|
|
||||||
[CGI](https://en.wikipedia.org/wiki/Common_Gateway_Interface)
|
[CGI](https://en.wikipedia.org/wiki/Common_Gateway_Interface)
|
||||||
is a simple mechanism to generate dynamic content.
|
is a simple mechanism to generate dynamic content.
|
||||||
@@ -16,7 +14,7 @@ CGI file must be executable. Mongoose honours the shebang line - see
|
|||||||
http://en.wikipedia.org/wiki/Shebang_(Unix).
|
http://en.wikipedia.org/wiki/Shebang_(Unix).
|
||||||
|
|
||||||
For example, if both PHP and Perl CGIs are used, then
|
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.
|
of the respective CGI scripts.
|
||||||
|
|
||||||
It is possible to hardcode the path to the CGI interpreter for all
|
It is possible to hardcode the path to the CGI interpreter for all
|
||||||
@@ -32,4 +30,4 @@ Example:
|
|||||||
NOTE: In the CGI handler we don't use explicitly a system call waitpid() for
|
NOTE: In the CGI handler we don't use explicitly a system call waitpid() for
|
||||||
reaping zombie processes. Instead, we set the SIGCHLD handler to SIG_IGN.
|
reaping zombie processes. Instead, we set the SIGCHLD handler to SIG_IGN.
|
||||||
It will cause zombie processes to be reaped automatically.
|
It will cause zombie processes to be reaped automatically.
|
||||||
CAUTION: not all OSes (e.g. QNX) reap zombies if SIGCHLD is ignored.
|
CAUTION: not all OSes (e.g. QNX) reap zombies if SIGCHLD is ignored.
|
||||||
@@ -1,6 +1,4 @@
|
|||||||
---
|
# HTTP client example
|
||||||
title: HTTP client example
|
|
||||||
---
|
|
||||||
|
|
||||||
To create an HTTP client, follow this pattern:
|
To create an HTTP client, follow this pattern:
|
||||||
|
|
||||||
@@ -1,6 +1,4 @@
|
|||||||
---
|
# Digest Authentication
|
||||||
title: Digest Authentication
|
|
||||||
---
|
|
||||||
|
|
||||||
Mongoose has a built-in Digest (MD5) authentication support. In order to
|
Mongoose has a built-in Digest (MD5) authentication support. In order to
|
||||||
enable Digest authentication, create a file `.htpasswd` in the directory
|
enable Digest authentication, create a file `.htpasswd` in the directory
|
||||||
@@ -8,7 +6,7 @@ you would like to protect. That file should be in the format that Apache's
|
|||||||
`htdigest` utility.
|
`htdigest` utility.
|
||||||
|
|
||||||
You can use either Apache `htdigest` utility, or
|
You can use either Apache `htdigest` utility, or
|
||||||
Mongoose pre-build binary (https://www.cesanta.com/products/binary)
|
Mongoose pre-build binary at https://www.cesanta.com/binary.html
|
||||||
to add new users into that file:
|
to add new users into that file:
|
||||||
|
|
||||||
```
|
```
|
||||||
+1
-3
@@ -1,6 +1,4 @@
|
|||||||
---
|
#: HTTP events
|
||||||
title: HTTP events
|
|
||||||
---
|
|
||||||
|
|
||||||
As discussed in the overview, `mg_set_protocol_http_websocket()` function
|
As discussed in the overview, `mg_set_protocol_http_websocket()` function
|
||||||
parses incoming data, treats it as HTTP or WebSocket, and triggers high-level
|
parses incoming data, treats it as HTTP or WebSocket, and triggers high-level
|
||||||
|
|||||||
+1
-3
@@ -1,6 +1,4 @@
|
|||||||
---
|
# Serving files
|
||||||
title: Serving files
|
|
||||||
---
|
|
||||||
|
|
||||||
API function `mg_serve_http()` makes it easy to serve files from a filesystem.
|
API function `mg_serve_http()` makes it easy to serve files from a filesystem.
|
||||||
Generally speaking, that function is an implementation of the HTTP server
|
Generally speaking, that function is an implementation of the HTTP server
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
---
|
|
||||||
title: HTTP
|
|
||||||
items:
|
|
||||||
- { name: server_example.md }
|
|
||||||
- { name: client_example.md }
|
|
||||||
- { name: events.md }
|
|
||||||
- { name: files.md }
|
|
||||||
- { name: cgi.md }
|
|
||||||
- { name: ssi.md }
|
|
||||||
- { name: upload.md }
|
|
||||||
- { name: ssl.md }
|
|
||||||
- { name: digest_auth.md }
|
|
||||||
- { name: ../c-api/http.h/ }
|
|
||||||
- { name: ../c-api/http_server.h/ }
|
|
||||||
- { name: ../c-api/http_client.h/ }
|
|
||||||
---
|
|
||||||
@@ -1,6 +1,4 @@
|
|||||||
---
|
# HTTP server example
|
||||||
title: HTTP server example
|
|
||||||
---
|
|
||||||
|
|
||||||
To create an HTTP server, follow this pattern:
|
To create an HTTP server, follow this pattern:
|
||||||
|
|
||||||
+1
-3
@@ -1,6 +1,4 @@
|
|||||||
---
|
# SSI
|
||||||
title: SSI
|
|
||||||
---
|
|
||||||
|
|
||||||
Server Side Includes (SSI) is a simple interpreted server-side scripting
|
Server Side Includes (SSI) is a simple interpreted server-side scripting
|
||||||
language which is most commonly used to include the contents of a file
|
language which is most commonly used to include the contents of a file
|
||||||
|
|||||||
+2
-4
@@ -1,6 +1,4 @@
|
|||||||
---
|
# Enabling SSL (HTTPS)
|
||||||
title: Enabling HTTPS
|
|
||||||
---
|
|
||||||
|
|
||||||
To enable SSL on the server side, please follow these steps:
|
To enable SSL on the server side, please follow these steps:
|
||||||
|
|
||||||
@@ -30,4 +28,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).
|
||||||
+5
-7
@@ -1,14 +1,12 @@
|
|||||||
---
|
# Handling file uploads
|
||||||
title: Handling file uploads
|
|
||||||
---
|
|
||||||
|
|
||||||
In order to handle file uploads, use the following HTML snippet:
|
In order to handle file uploads, use the following HTML snippet:
|
||||||
|
|
||||||
```HTML
|
```HTML
|
||||||
<form method="POST" action="/upload" enctype="multipart/form-data">
|
<form method="POST" action="/upload" enctype="multipart/form-data">
|
||||||
<input type="file" name="file">
|
<input type="file" name="file">
|
||||||
<input type="submit" value="Upload">
|
<input type="submit" value="Upload">
|
||||||
</form>
|
</form>
|
||||||
```
|
```
|
||||||
|
|
||||||
Uploaded files will be sent to the `/upload` endpoint via the `POST` request.
|
Uploaded files will be sent to the `/upload` endpoint via the `POST` request.
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
---
|
|
||||||
title: MQTT client example
|
|
||||||
---
|
|
||||||
|
|
||||||
See https://github.com/cesanta/mongoose/tree/master/examples/mqtt_client
|
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
# Examples
|
||||||
|
|
||||||
|
- [Client example](https://github.com/cesanta/mongoose/tree/master/examples/mqtt_client)
|
||||||
|
- [Server example](https://github.com/cesanta/mongoose/tree/master/examples/mqtt_broker)
|
||||||
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
---
|
|
||||||
title: MQTT
|
|
||||||
items:
|
|
||||||
- { name: server_example.md }
|
|
||||||
- { name: client_example.md }
|
|
||||||
- { name: ../c-api/mqtt.h/ }
|
|
||||||
- { name: ../c-api/mqtt_server.h/ }
|
|
||||||
---
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
---
|
|
||||||
title: MQTT server example
|
|
||||||
---
|
|
||||||
|
|
||||||
See https://github.com/cesanta/mongoose/tree/master/examples/mqtt_broker
|
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
# Build options
|
||||||
|
|
||||||
|
Mongoose source code ships in a single .c file that contains functionality
|
||||||
|
for all supported protocols (modules). Modules can be disabled at compile
|
||||||
|
time which reduces the executable's size. That can be done by setting preprocessor
|
||||||
|
flags. Also, some preprocessor flags can be used to tune internal Mongoose
|
||||||
|
parameters.
|
||||||
|
|
||||||
|
To set a preprocessor flag during compile time, use the `-D <PREPROCESSOR_FLAG>`
|
||||||
|
compiler option. For example, to disable both MQTT and CoAP,
|
||||||
|
compile the application `my_app.c` like this (assumed UNIX system):
|
||||||
|
|
||||||
|
```
|
||||||
|
$ cc my_app.c mongoose.c -D MG_DISABLE_MQTT -D MG_DISABLE_COAP
|
||||||
|
```
|
||||||
|
## Enabling flags
|
||||||
|
|
||||||
|
- `MG_ENABLE_SSL` Enable [SSL/TLS support](https://docs.cesanta.com/mongoose/master/#/http/ssl.md/) (OpenSSL API)
|
||||||
|
- `MG_ENABLE_IPV6` Enable IPv6 support
|
||||||
|
- `MG_ENABLE_MQTT` enable [MQTT client](https://docs.cesanta.com/mongoose/master/#/mqtt/client_example.md/) (on by default, set to 0 to disable)
|
||||||
|
- `MG_ENABLE_MQTT_BROKER` enable [MQTT broker](https://docs.cesanta.com/mongoose/master/#/mqtt/server_example.md/)
|
||||||
|
- `MG_ENABLE_DNS_SERVER` enable DNS server
|
||||||
|
- `MG_ENABLE_COAP` enable CoAP protocol
|
||||||
|
- `MG_ENABLE_HTTP` Enable HTTP protocol support (on by default, set to 0 to disable)
|
||||||
|
- `MG_ENABLE_HTTP_CGI` Enable [CGI](https://docs.cesanta.com/mongoose/master/#/http/cgi.md/) support
|
||||||
|
- `MG_ENABLE_HTTP_SSI` Enable [Server Side Includes](https://docs.cesanta.com/mongoose/master/#/http/ssi.md/) support
|
||||||
|
- `MG_ENABLE_HTTP_SSI_EXEC` Enable SSI `exec` operator
|
||||||
|
- `MG_ENABLE_HTTP_WEBDAV` enable WebDAV extensions to HTTP
|
||||||
|
- `MG_ENABLE_HTTP_WEBSOCKET` enable WebSocket extension to HTTP (on by default, =0 to disable)
|
||||||
|
- `MG_ENABLE_BROADCAST` enable `mg_broadcast()` API
|
||||||
|
- `MG_ENABLE_GETADDRINFO` enable `getaddrinfo()` in `mg_resolve2()`
|
||||||
|
- `MG_ENABLE_THREADS` enable `mg_start_thread()` API
|
||||||
|
|
||||||
|
## Disabling flags
|
||||||
|
|
||||||
|
- `MG_DISABLE_HTTP_DIGEST_AUTH` disable HTTP Digest (MD5) authorisation support
|
||||||
|
- `CS_DISABLE_SHA1` disable SHA1 support (used by WebSocket)
|
||||||
|
- `CS_DISABLE_MD5` disable MD5 support (used by HTTP auth)
|
||||||
|
- `MG_DISABLE_HTTP_KEEP_ALIVE` useful for embedded systems to save resources
|
||||||
|
|
||||||
|
## Platform specific
|
||||||
|
|
||||||
|
Mongoose tries to detect the target platform whenever possible, but in some cases you have
|
||||||
|
to explicitly declare some peculiarities of your target, such as:
|
||||||
|
|
||||||
|
- `MG_CC3200`: enable workarounds for the TI CC3200 target.
|
||||||
|
- `MG_ESP8266`: enable workarounds for the ESP8266 target, add `RTOS_SDK` to specify the RTOS SDK flavour.
|
||||||
|
|
||||||
|
## Tunables
|
||||||
|
|
||||||
|
- `MG_MALLOC`, `MG_CALLOC`, `MG_REALLOC`, `MG_FREE` allow you to a use custom
|
||||||
|
memory allocator, e.g. `-DMG_MALLOC=my_malloc`
|
||||||
|
- `MG_USE_READ_WRITE` when set replaces calls to `recv` with `read` and `send` with `write`,
|
||||||
|
thus enabling to add any kind of file descriptor (files, serial devices) to an event manager.
|
||||||
|
- `MG_SSL_CRYPTO_MODERN`, `MG_SSL_CRYPTO_OLD` - choose either "Modern" or "Old" ciphers
|
||||||
|
instead of the default "Intermediate" setting.
|
||||||
|
See [this article](https://wiki.mozilla.org/Security/Server_Side_TLS#Recommended_configurations) for details.
|
||||||
|
- `MG_USER_FILE_FUNCTIONS` allow you to use custom file operation, by defining you own `mg_stat`, `mg_fopen`, `mg_open`, `mg_fread` and `mg_fwrite` functions
|
||||||
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
---
|
|
||||||
title: Disabling flags
|
|
||||||
---
|
|
||||||
|
|
||||||
- `MG_DISABLE_HTTP_DIGEST_AUTH` disable HTTP Digest (MD5) authorisation support
|
|
||||||
- `CS_DISABLE_SHA1` disable SHA1 support (used by WebSocket)
|
|
||||||
- `CS_DISABLE_MD5` disable MD5 support (used by HTTP auth)
|
|
||||||
- `MG_DISABLE_HTTP_KEEP_ALIVE` useful for embedded systems to save resources
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
---
|
|
||||||
title: Enabling flags
|
|
||||||
---
|
|
||||||
|
|
||||||
- `MG_ENABLE_SSL` Enable [SSL/TLS support](https://docs.cesanta.com/mongoose/master/#/http/ssl.md/) (OpenSSL API)
|
|
||||||
- `MG_ENABLE_IPV6` Enable IPv6 support
|
|
||||||
- `MG_ENABLE_MQTT` enable [MQTT client](https://docs.cesanta.com/mongoose/master/#/mqtt/client_example.md/) (on by default, set to 0 to disable)
|
|
||||||
- `MG_ENABLE_MQTT_BROKER` enable [MQTT broker](https://docs.cesanta.com/mongoose/master/#/mqtt/server_example.md/)
|
|
||||||
- `MG_ENABLE_DNS_SERVER` enable DNS server
|
|
||||||
- `MG_ENABLE_COAP` enable CoAP protocol
|
|
||||||
- `MG_ENABLE_HTTP` Enable HTTP protocol support (on by default, set to 0 to disable)
|
|
||||||
- `MG_ENABLE_HTTP_CGI` Enable [CGI](https://docs.cesanta.com/mongoose/master/#/http/cgi.md/) support
|
|
||||||
- `MG_ENABLE_HTTP_SSI` Enable [Server Side Includes](https://docs.cesanta.com/mongoose/master/#/http/ssi.md/) support
|
|
||||||
- `MG_ENABLE_HTTP_SSI_EXEC` Enable SSI `exec` operator
|
|
||||||
- `MG_ENABLE_HTTP_WEBDAV` enable WebDAV extensions to HTTP
|
|
||||||
- `MG_ENABLE_HTTP_WEBSOCKET` enable WebSocket extension to HTTP (on by default, =0 to disable)
|
|
||||||
- `MG_ENABLE_BROADCAST` enable `mg_broadcast()` API
|
|
||||||
- `MG_ENABLE_GETADDRINFO` enable `getaddrinfo()` in `mg_resolve2()`
|
|
||||||
- `MG_ENABLE_THREADS` enable `mg_start_thread()` API
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
---
|
|
||||||
title: Build Options
|
|
||||||
items:
|
|
||||||
- { type: file, name: enabling-flags.md }
|
|
||||||
- { type: file, name: disabling-flags.md }
|
|
||||||
- { type: file, name: platform-spec.md }
|
|
||||||
- { type: file, name: tunables.md }
|
|
||||||
---
|
|
||||||
|
|
||||||
Mongoose source code ships in a single .c file that contains functionality
|
|
||||||
for all supported protocols (modules). Modules can be disabled at compile
|
|
||||||
time which reduces the executable's size. That can be done by setting preprocessor
|
|
||||||
flags. Also, some preprocessor flags can be used to tune internal Mongoose
|
|
||||||
parameters.
|
|
||||||
|
|
||||||
To set a preprocessor flag during compile time, use the `-D <PREPROCESSOR_FLAG>`
|
|
||||||
compiler option. For example, to disable both MQTT and CoAP,
|
|
||||||
compile the application `my_app.c` like this (assumed UNIX system):
|
|
||||||
|
|
||||||
```
|
|
||||||
$ cc my_app.c mongoose.c -D MG_DISABLE_MQTT -D MG_DISABLE_COAP
|
|
||||||
```
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
---
|
|
||||||
title: Platform specific
|
|
||||||
---
|
|
||||||
|
|
||||||
Mongoose tries to detect the target platform whenever possible, but in some cases you have
|
|
||||||
to explicitly declare some peculiarities of your target, such as:
|
|
||||||
|
|
||||||
- `MG_CC3200`: enable workarounds for the TI CC3200 target.
|
|
||||||
- `MG_ESP8266`: enable workarounds for the ESP8266 target, add `RTOS_SDK` to specify the RTOS SDK flavour.
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
---
|
|
||||||
title: Tunables
|
|
||||||
---
|
|
||||||
|
|
||||||
- `MG_MALLOC`, `MG_CALLOC`, `MG_REALLOC`, `MG_FREE` allow you to a use custom
|
|
||||||
memory allocator, e.g. `-DMG_MALLOC=my_malloc`
|
|
||||||
- `MG_USE_READ_WRITE` when set replaces calls to `recv` with `read` and `send` with `write`,
|
|
||||||
thus enabling to add any kind of file descriptor (files, serial devices) to an event manager.
|
|
||||||
- `MG_SSL_CRYPTO_MODERN`, `MG_SSL_CRYPTO_OLD` - choose either "Modern" or "Old" ciphers
|
|
||||||
instead of the default "Intermediate" setting.
|
|
||||||
See [this article](https://wiki.mozilla.org/Security/Server_Side_TLS#Recommended_configurations) for details.
|
|
||||||
- `MG_USER_FILE_FUNCTIONS` allow you to use custom file operation, by defining you own `mg_stat`, `mg_fopen`, `mg_open`, `mg_fread` and `mg_fwrite` functions
|
|
||||||
@@ -1,6 +1,4 @@
|
|||||||
---
|
# Design Concept
|
||||||
title: Design Concept
|
|
||||||
---
|
|
||||||
|
|
||||||
Mongoose has three basic data structures:
|
Mongoose has three basic data structures:
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
---
|
# Connection flags
|
||||||
title: Connection flags
|
|
||||||
---
|
|
||||||
|
|
||||||
Each connection has a `flags` bit field. Some flags are set by Mongoose, for
|
Each connection has a `flags` bit field. Some flags are set by Mongoose, for
|
||||||
example if a user creates an outbound UDP connection using a `udp://1.2.3.4:5678`
|
example if a user creates an outbound UDP connection using a `udp://1.2.3.4:5678`
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
---
|
# Event handler function
|
||||||
title: Event handler function
|
|
||||||
---
|
|
||||||
|
|
||||||
Each connection has an event handler function associated with it. That function
|
Each connection has an event handler function associated with it. That function
|
||||||
must be implemented by the user. Event handler is the key element of the Mongoose
|
must be implemented by the user. Event handler is the key element of the Mongoose
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
---
|
# Events
|
||||||
title: Events
|
|
||||||
---
|
|
||||||
|
|
||||||
Mongoose accepts incoming connections, reads and writes data and calls
|
Mongoose accepts incoming connections, reads and writes data and calls
|
||||||
specified event handlers for each connection when appropriate. A typical event
|
specified event handlers for each connection when appropriate. A typical event
|
||||||
|
|||||||
+1
-12
@@ -1,15 +1,4 @@
|
|||||||
---
|
# Introduction
|
||||||
title: Overview
|
|
||||||
items:
|
|
||||||
# - { name: usage-example.md }
|
|
||||||
- { name: concept.md }
|
|
||||||
- { name: mbufs.md }
|
|
||||||
- { name: event-handler.md }
|
|
||||||
- { name: events.md }
|
|
||||||
- { name: conn-flags.md }
|
|
||||||
- { name: build-options }
|
|
||||||
- { name: usage-example.md }
|
|
||||||
---
|
|
||||||
|
|
||||||
Mongoose is a networking library written in C.
|
Mongoose is a networking library written in C.
|
||||||
It is a swiss army knife for embedded network programming.
|
It is a swiss army knife for embedded network programming.
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
---
|
# Memory buffers
|
||||||
title: Memory buffers
|
|
||||||
---
|
|
||||||
|
|
||||||
Each connection has a send and receive buffer, `struct mg_connection::send_mbuf`
|
Each connection has a send and receive buffer, `struct mg_connection::send_mbuf`
|
||||||
and `struct mg_connection::recv_mbuf` respectively. When data arrives,
|
and `struct mg_connection::recv_mbuf` respectively. When data arrives,
|
||||||
@@ -11,4 +9,4 @@ When Mongoose successfully writes data to the socket, it discards data from
|
|||||||
`struct mg_connection::send_mbuf` and sends an `MG_EV_SEND` event. When the connection
|
`struct mg_connection::send_mbuf` and sends an `MG_EV_SEND` event. When the connection
|
||||||
is closed, an `MG_EV_CLOSE` event is sent.
|
is closed, an `MG_EV_CLOSE` event is sent.
|
||||||
|
|
||||||

|

|
||||||
@@ -1,6 +1,4 @@
|
|||||||
---
|
# Example - TCP echo server
|
||||||
title: Example - TCP echo server
|
|
||||||
---
|
|
||||||
|
|
||||||
- Copy `mongoose.c` and `mongoose.h` to your build tree
|
- Copy `mongoose.c` and `mongoose.h` to your build tree
|
||||||
- Write code that uses the Mongoose API, e.g. in `my_app.c`
|
- Write code that uses the Mongoose API, e.g. in `my_app.c`
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ IPATH = . ../.. $(REPO_PATH)
|
|||||||
|
|
||||||
VPATH = ../..
|
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
|
SDK_FLAGS = -DUSE_FREERTOS -DSL_PLATFORM_MULTI_THREADED
|
||||||
# -DTARGET_IS_CC3200 would reduce code size by using functions in ROM
|
# -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)
|
$(FW_ZIP): $(FW_ELF) $(FW_BIN) $(SLFS_FILES)
|
||||||
@echo " Code size: $(shell ls -l $(FW_BIN) | awk '{print $$5}')"
|
@echo " Code size: $(shell ls -l $(FW_BIN) | awk '{print $$5}')"
|
||||||
@echo " GEN $(FW_MANIFEST)"
|
@echo " GEN $(FW_MANIFEST)"
|
||||||
@fw_meta gen_build_info \
|
@fw_meta.py gen_build_info \
|
||||||
--json_output=$(BUILD_INFO_JSON)
|
--json_output=$(BUILD_INFO_JSON)
|
||||||
@cp -v $(SLFS_FILES) out/
|
@cp -v $(SLFS_FILES) out/
|
||||||
@cp $(CC3200_SP_FILE)* $(FW_DIR)
|
@cp $(CC3200_SP_FILE)* $(FW_DIR)
|
||||||
@fw_meta create_manifest \
|
@fw_meta.py create_manifest \
|
||||||
--name=$(PROG) --platform=$(PLATFORM) \
|
--name=$(PROG) --platform=$(PLATFORM) \
|
||||||
--build_info=$(BUILD_INFO_JSON) \
|
--build_info=$(BUILD_INFO_JSON) \
|
||||||
--output=$(FW_MANIFEST) \
|
--output=$(FW_MANIFEST) \
|
||||||
@@ -72,14 +72,14 @@ $(FW_ZIP): $(FW_ELF) $(FW_BIN) $(SLFS_FILES)
|
|||||||
/sys/mcuimg.bin:type=app,src=$(notdir $(FW_BIN)) \
|
/sys/mcuimg.bin:type=app,src=$(notdir $(FW_BIN)) \
|
||||||
$(foreach f,$(SLFS_FILES), $(notdir $(f)):type=slfile,src=$(notdir $(f)))
|
$(foreach f,$(SLFS_FILES), $(notdir $(f)):type=slfile,src=$(notdir $(f)))
|
||||||
@echo " ZIP $@"
|
@echo " ZIP $@"
|
||||||
@fw_meta create_fw \
|
@fw_meta.py create_fw \
|
||||||
--manifest=$(FW_MANIFEST) \
|
--manifest=$(FW_MANIFEST) \
|
||||||
--src_dir=$(FW_DIR) \
|
--src_dir=$(FW_DIR) \
|
||||||
--output=$@
|
--output=$@
|
||||||
|
|
||||||
FREERTOS_SRCS = timers.c list.c queue.c tasks.c port.c heap_3.c osi_freertos.c
|
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
|
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)
|
SDK_SRCS = startup_gcc.c $(FREERTOS_SRCS) $(DRIVER_SRCS) $(SL_SRCS)
|
||||||
IPATH += $(SDK_PATH) $(SDK_PATH)/inc $(SDK_PATH)/driverlib \
|
IPATH += $(SDK_PATH) $(SDK_PATH)/inc $(SDK_PATH)/driverlib \
|
||||||
$(SDK_PATH)/example/common $(SDK_PATH)/oslib \
|
$(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,
|
LOG(LL_ERROR, ("status %d sender %d", e->EventData.deviceEvent.status,
|
||||||
e->EventData.deviceEvent.sender));
|
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
|
||||||
@@ -21,9 +21,9 @@ ifeq ($(SSL_LIB),mbedtls)
|
|||||||
CFLAGS += -DMG_ENABLE_SSL -DMG_SSL_IF=MG_SSL_IF_MBEDTLS -DMG_SSL_MBED_DUMMY_RANDOM -lmbedcrypto -lmbedtls -lmbedx509
|
CFLAGS += -DMG_ENABLE_SSL -DMG_SSL_IF=MG_SSL_IF_MBEDTLS -DMG_SSL_MBED_DUMMY_RANDOM -lmbedcrypto -lmbedtls -lmbedx509
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(JS), yes)
|
ifdef ASAN
|
||||||
V7_PATH = ../../deps/v7
|
CC = clang
|
||||||
CFLAGS_EXTRA += -DMG_ENABLE_JAVASCRIPT -I $(V7_PATH) $(V7_PATH)/v7.c
|
CFLAGS += -fsanitize=address
|
||||||
endif
|
endif
|
||||||
|
|
||||||
$(PROG): $(SOURCES)
|
$(PROG): $(SOURCES)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
PROG = mqtt_broker
|
PROG = mqtt_broker
|
||||||
MODULE_CFLAGS = -DMG_ENABLE_MQTT_BROKER -DMG_ENABLE_HTTP=0
|
MODULE_CFLAGS = -DMG_ENABLE_MQTT_BROKER -DMG_ENABLE_HTTP=0
|
||||||
SSL_LIB=openssl
|
#SSL_LIB=openssl
|
||||||
include ../examples.mk
|
include ../examples.mk
|
||||||
@@ -17,22 +17,31 @@
|
|||||||
|
|
||||||
#include "../../mongoose.h"
|
#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) {
|
int main(void) {
|
||||||
struct mg_mgr mgr;
|
struct mg_mgr mgr;
|
||||||
const char *address = "0.0.0.0:1883";
|
struct mg_connection *c;
|
||||||
struct mg_connection *nc;
|
|
||||||
struct mg_mqtt_broker brk;
|
struct mg_mqtt_broker brk;
|
||||||
|
|
||||||
mg_mgr_init(&mgr, NULL);
|
mg_mgr_init(&mgr, NULL);
|
||||||
mg_mqtt_broker_init(&brk, NULL);
|
mg_mqtt_broker_init(&brk, NULL);
|
||||||
|
|
||||||
if ((nc = mg_bind(&mgr, address, mg_mqtt_broker)) == NULL) {
|
if ((c = mg_bind(&mgr, s_listening_address, ev_handler)) == NULL) {
|
||||||
fprintf(stderr, "mg_bind(%s) failed\n", address);
|
fprintf(stderr, "mg_bind(%s) failed\n", s_listening_address);
|
||||||
exit(EXIT_FAILURE);
|
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
|
* 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;
|
struct mg_mqtt_message *msg = (struct mg_mqtt_message *) p;
|
||||||
(void) nc;
|
(void) nc;
|
||||||
|
|
||||||
#if 0
|
if (ev != MG_EV_POLL) printf("USER HANDLER GOT EVENT %d\n", ev);
|
||||||
if (ev != MG_EV_POLL)
|
|
||||||
printf("USER HANDLER GOT %d\n", ev);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
switch (ev) {
|
switch (ev) {
|
||||||
case MG_EV_CONNECT: {
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -75,11 +75,6 @@ int main(int argc, char *argv[]) {
|
|||||||
s_http_port = argv[++i];
|
s_http_port = argv[++i];
|
||||||
} else if (strcmp(argv[i], "-a") == 0 && i + 1 < argc) {
|
} else if (strcmp(argv[i], "-a") == 0 && i + 1 < argc) {
|
||||||
s_http_server_opts.auth_domain = argv[++i];
|
s_http_server_opts.auth_domain = argv[++i];
|
||||||
#if MG_ENABLE_JAVASCRIPT
|
|
||||||
} else if (strcmp(argv[i], "-j") == 0 && i + 1 < argc) {
|
|
||||||
const char *init_file = argv[++i];
|
|
||||||
mg_enable_javascript(&mgr, v7_create(), init_file);
|
|
||||||
#endif
|
|
||||||
} else if (strcmp(argv[i], "-P") == 0 && i + 1 < argc) {
|
} else if (strcmp(argv[i], "-P") == 0 && i + 1 < argc) {
|
||||||
s_http_server_opts.global_auth_file = argv[++i];
|
s_http_server_opts.global_auth_file = argv[++i];
|
||||||
} else if (strcmp(argv[i], "-A") == 0 && i + 1 < argc) {
|
} else if (strcmp(argv[i], "-A") == 0 && i + 1 < argc) {
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
PROG = socks_server
|
||||||
|
# NOTE(lsm): -DMG_ENABLE_IPV6 won't work for the mingw build
|
||||||
|
MODULE_CFLAGS = -DMG_ENABLE_SOCKS=1 # -DMG_ENABLE_DEBUG=1
|
||||||
|
#SSL_LIB=openssl
|
||||||
|
include ../examples.mk
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017 Cesanta Software Limited
|
||||||
|
* All rights reserved
|
||||||
|
*
|
||||||
|
* Use curl to test, e.g.
|
||||||
|
* curl -i --socks5 127.0.0.1:1080 www.met.ie
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "mongoose.h"
|
||||||
|
|
||||||
|
static const char *s_listening_addr = "1080";
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
struct mg_mgr mgr;
|
||||||
|
struct mg_connection *c;
|
||||||
|
|
||||||
|
mg_mgr_init(&mgr, NULL);
|
||||||
|
|
||||||
|
if ((c = mg_bind(&mgr, s_listening_addr, NULL)) == NULL) {
|
||||||
|
fprintf(stderr, "mg_bind(%s) failed\n", s_listening_addr);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
mg_set_protocol_socks(c);
|
||||||
|
|
||||||
|
printf("Starting socks5 proxy server on %s\n", s_listening_addr);
|
||||||
|
for (;;) {
|
||||||
|
mg_mgr_poll(&mgr, 1000);
|
||||||
|
}
|
||||||
|
mg_mgr_free(&mgr);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
+1217
-514
File diff suppressed because it is too large.
Load diff
+268
-108
@@ -23,7 +23,7 @@
|
|||||||
#ifndef CS_MONGOOSE_SRC_COMMON_H_
|
#ifndef CS_MONGOOSE_SRC_COMMON_H_
|
||||||
#define CS_MONGOOSE_SRC_COMMON_H_
|
#define CS_MONGOOSE_SRC_COMMON_H_
|
||||||
|
|
||||||
#define MG_VERSION "6.7"
|
#define MG_VERSION "6.10"
|
||||||
|
|
||||||
/* Local tweaks, applied before any of Mongoose's own headers. */
|
/* Local tweaks, applied before any of Mongoose's own headers. */
|
||||||
#ifdef MG_LOCALS
|
#ifdef MG_LOCALS
|
||||||
@@ -46,9 +46,10 @@
|
|||||||
#define CS_P_WINDOWS 2
|
#define CS_P_WINDOWS 2
|
||||||
#define CS_P_ESP32 15
|
#define CS_P_ESP32 15
|
||||||
#define CS_P_ESP8266 3
|
#define CS_P_ESP8266 3
|
||||||
#define CS_P_CC3200 4
|
|
||||||
#define CS_P_MSP432 5
|
|
||||||
#define CS_P_CC3100 6
|
#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_TM4C129 14
|
||||||
#define CS_P_MBED 7
|
#define CS_P_MBED 7
|
||||||
#define CS_P_WINCE 8
|
#define CS_P_WINCE 8
|
||||||
@@ -58,15 +59,17 @@
|
|||||||
#define CS_P_NRF52 10
|
#define CS_P_NRF52 10
|
||||||
#define CS_P_PIC32 11
|
#define CS_P_PIC32 11
|
||||||
#define CS_P_STM32 16
|
#define CS_P_STM32 16
|
||||||
/* Next id: 17 */
|
/* Next id: 18 */
|
||||||
|
|
||||||
/* If not specified explicitly, we guess platform by defines. */
|
/* If not specified explicitly, we guess platform by defines. */
|
||||||
#ifndef CS_PLATFORM
|
#ifndef CS_PLATFORM
|
||||||
|
|
||||||
#if defined(TARGET_IS_MSP432P4XX) || defined(__MSP432P401R__)
|
#if defined(TARGET_IS_MSP432P4XX) || defined(__MSP432P401R__)
|
||||||
#define CS_PLATFORM CS_P_MSP432
|
#define CS_PLATFORM CS_P_MSP432
|
||||||
#elif defined(cc3200)
|
#elif defined(cc3200) || defined(TARGET_IS_CC3200)
|
||||||
#define CS_PLATFORM CS_P_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__)
|
#elif defined(__unix__) || defined(__APPLE__)
|
||||||
#define CS_PLATFORM CS_P_UNIX
|
#define CS_PLATFORM CS_P_UNIX
|
||||||
#elif defined(WINCE)
|
#elif defined(WINCE)
|
||||||
@@ -111,8 +114,9 @@
|
|||||||
/* Amalgamated: #include "common/platforms/platform_windows.h" */
|
/* Amalgamated: #include "common/platforms/platform_windows.h" */
|
||||||
/* Amalgamated: #include "common/platforms/platform_esp32.h" */
|
/* Amalgamated: #include "common/platforms/platform_esp32.h" */
|
||||||
/* Amalgamated: #include "common/platforms/platform_esp8266.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_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_mbed.h" */
|
||||||
/* Amalgamated: #include "common/platforms/platform_nrf51.h" */
|
/* Amalgamated: #include "common/platforms/platform_nrf51.h" */
|
||||||
/* Amalgamated: #include "common/platforms/platform_nrf52.h" */
|
/* Amalgamated: #include "common/platforms/platform_nrf52.h" */
|
||||||
@@ -223,14 +227,12 @@
|
|||||||
#endif
|
#endif
|
||||||
#define snprintf _snprintf
|
#define snprintf _snprintf
|
||||||
#define vsnprintf _vsnprintf
|
#define vsnprintf _vsnprintf
|
||||||
#define sleep(x) Sleep((x) *1000)
|
|
||||||
#define to64(x) _atoi64(x)
|
#define to64(x) _atoi64(x)
|
||||||
#if !defined(__MINGW32__) && !defined(__MINGW64__)
|
#if !defined(__MINGW32__) && !defined(__MINGW64__)
|
||||||
#define popen(x, y) _popen((x), (y))
|
#define popen(x, y) _popen((x), (y))
|
||||||
#define pclose(x) _pclose(x)
|
#define pclose(x) _pclose(x)
|
||||||
#define fileno _fileno
|
#define fileno _fileno
|
||||||
#endif
|
#endif
|
||||||
#define rmdir _rmdir
|
|
||||||
#if defined(_MSC_VER) && _MSC_VER >= 1400
|
#if defined(_MSC_VER) && _MSC_VER >= 1400
|
||||||
#define fseeko(x, y, z) _fseeki64((x), (y), (z))
|
#define fseeko(x, y, z) _fseeki64((x), (y), (z))
|
||||||
#else
|
#else
|
||||||
@@ -321,6 +323,9 @@ typedef struct _stati64 cs_stat_t;
|
|||||||
#define MG_NET_IF MG_NET_IF_SOCKET
|
#define MG_NET_IF MG_NET_IF_SOCKET
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
int rmdir(const char *dirname);
|
||||||
|
unsigned int sleep(unsigned int seconds);
|
||||||
|
|
||||||
#endif /* CS_PLATFORM == CS_P_WINDOWS */
|
#endif /* CS_PLATFORM == CS_P_WINDOWS */
|
||||||
#endif /* CS_COMMON_PLATFORMS_PLATFORM_WINDOWS_H_ */
|
#endif /* CS_COMMON_PLATFORMS_PLATFORM_WINDOWS_H_ */
|
||||||
#ifdef MG_MODULE_LINES
|
#ifdef MG_MODULE_LINES
|
||||||
@@ -538,7 +543,9 @@ typedef struct stat cs_stat_t;
|
|||||||
#define SIZE_T_FMT "u"
|
#define SIZE_T_FMT "u"
|
||||||
typedef struct stat cs_stat_t;
|
typedef struct stat cs_stat_t;
|
||||||
#define DIRSEP '/'
|
#define DIRSEP '/'
|
||||||
|
#if !defined(MGOS_VFS_DEFINE_DIRENT)
|
||||||
#define CS_DEFINE_DIRENT
|
#define CS_DEFINE_DIRENT
|
||||||
|
#endif
|
||||||
|
|
||||||
#define to64(x) strtoll(x, NULL, 10)
|
#define to64(x) strtoll(x, NULL, 10)
|
||||||
#define INT64_FMT PRId64
|
#define INT64_FMT PRId64
|
||||||
@@ -546,7 +553,7 @@ typedef struct stat cs_stat_t;
|
|||||||
#define __cdecl
|
#define __cdecl
|
||||||
#define _FILE_OFFSET_BITS 32
|
#define _FILE_OFFSET_BITS 32
|
||||||
|
|
||||||
#ifndef RTOS_SDK
|
#if !defined(RTOS_SDK) && !defined(__cplusplus)
|
||||||
#define fileno(x) -1
|
#define fileno(x) -1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -558,9 +565,9 @@ typedef struct stat cs_stat_t;
|
|||||||
#ifndef MG_NET_IF
|
#ifndef MG_NET_IF
|
||||||
#include <lwip/opt.h>
|
#include <lwip/opt.h>
|
||||||
#if LWIP_SOCKET /* RTOS SDK has LWIP sockets */
|
#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
|
#else
|
||||||
# define MG_NET_IF MG_NET_IF_LWIP_LOW_LEVEL
|
#define MG_NET_IF MG_NET_IF_LWIP_LOW_LEVEL
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -601,7 +608,7 @@ typedef struct stat cs_stat_t;
|
|||||||
|
|
||||||
#include <simplelink.h>
|
#include <simplelink.h>
|
||||||
#include <netapp.h>
|
#include <netapp.h>
|
||||||
#undef timeval
|
#undef timeval
|
||||||
|
|
||||||
typedef int sock_t;
|
typedef int sock_t;
|
||||||
#define INVALID_SOCKET (-1)
|
#define INVALID_SOCKET (-1)
|
||||||
@@ -700,7 +707,7 @@ struct stat {
|
|||||||
};
|
};
|
||||||
|
|
||||||
int _stat(const char *pathname, struct stat *st);
|
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
|
#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_ISDIR(mode) __S_ISTYPE((mode), __S_IFDIR)
|
||||||
#define S_ISREG(mode) __S_ISTYPE((mode), __S_IFREG)
|
#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))
|
#define va_copy(apc, ap) ((apc) = (ap))
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* __TI_COMPILER_VERSION__ */
|
#endif /* __TI_COMPILER_VERSION__ */
|
||||||
|
|
||||||
@@ -838,7 +847,8 @@ int _stat(const char *pathname, struct stat *st);
|
|||||||
#define CS_ENABLE_STDIO 1
|
#define CS_ENABLE_STDIO 1
|
||||||
#endif
|
#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
|
#define MG_ENABLE_FILESYSTEM 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -882,15 +892,15 @@ typedef struct stat cs_stat_t;
|
|||||||
#define __cdecl
|
#define __cdecl
|
||||||
|
|
||||||
#ifndef MG_NET_IF
|
#ifndef MG_NET_IF
|
||||||
# include <lwip/opt.h>
|
#include <lwip/opt.h>
|
||||||
# if LWIP_SOCKET
|
#if LWIP_SOCKET
|
||||||
# define MG_NET_IF MG_NET_IF_SOCKET
|
#define MG_NET_IF MG_NET_IF_SOCKET
|
||||||
# else
|
#else
|
||||||
# define MG_NET_IF MG_NET_IF_LWIP_LOW_LEVEL
|
#define MG_NET_IF MG_NET_IF_LWIP_LOW_LEVEL
|
||||||
# endif
|
#endif
|
||||||
# define MG_LWIP 1
|
#define MG_LWIP 1
|
||||||
#elif MG_NET_IF == MG_NET_IF_SIMPLELINK
|
#elif MG_NET_IF == MG_NET_IF_SIMPLELINK
|
||||||
# include "common/platforms/simplelink/cs_simplelink.h"
|
/* Amalgamated: #include "common/platforms/simplelink/cs_simplelink.h" */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef CS_ENABLE_STDIO
|
#ifndef CS_ENABLE_STDIO
|
||||||
@@ -1012,16 +1022,16 @@ in_addr_t inet_addr(const char *cp);
|
|||||||
|
|
||||||
#define to64(x) strtoll(x, NULL, 10)
|
#define to64(x) strtoll(x, NULL, 10)
|
||||||
|
|
||||||
#define MG_NET_IF MG_NET_IF_LWIP_LOW_LEVEL
|
#define MG_NET_IF MG_NET_IF_LWIP_LOW_LEVEL
|
||||||
#define MG_LWIP 1
|
#define MG_LWIP 1
|
||||||
#define MG_ENABLE_IPV6 1
|
#define MG_ENABLE_IPV6 1
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* For ARM C Compiler, make lwip to export `struct timeval`; for other
|
* For ARM C Compiler, make lwip to export `struct timeval`; for other
|
||||||
* compilers, suppress it.
|
* compilers, suppress it.
|
||||||
*/
|
*/
|
||||||
#if !defined(__ARMCC_VERSION)
|
#if !defined(__ARMCC_VERSION)
|
||||||
# define LWIP_TIMEVAL_PRIVATE 0
|
#define LWIP_TIMEVAL_PRIVATE 0
|
||||||
#else
|
#else
|
||||||
struct timeval;
|
struct timeval;
|
||||||
int gettimeofday(struct timeval *tp, void *tzp);
|
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 to64(x) strtoll(x, NULL, 10)
|
||||||
|
|
||||||
#define MG_NET_IF MG_NET_IF_LWIP_LOW_LEVEL
|
#define MG_NET_IF MG_NET_IF_LWIP_LOW_LEVEL
|
||||||
#define MG_LWIP 1
|
#define MG_LWIP 1
|
||||||
#define MG_ENABLE_IPV6 1
|
#define MG_ENABLE_IPV6 1
|
||||||
|
|
||||||
#if !defined(ENOSPC)
|
#if !defined(ENOSPC)
|
||||||
# define ENOSPC 28 /* No space left on device */
|
#define ENOSPC 28 /* No space left on device */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -1071,7 +1081,7 @@ int gettimeofday(struct timeval *tp, void *tzp);
|
|||||||
* compilers, suppress it.
|
* compilers, suppress it.
|
||||||
*/
|
*/
|
||||||
#if !defined(__ARMCC_VERSION)
|
#if !defined(__ARMCC_VERSION)
|
||||||
# define LWIP_TIMEVAL_PRIVATE 0
|
#define LWIP_TIMEVAL_PRIVATE 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define INT64_FMT PRId64
|
#define INT64_FMT PRId64
|
||||||
@@ -1095,9 +1105,10 @@ int gettimeofday(struct timeval *tp, void *tzp);
|
|||||||
#ifndef CS_COMMON_PLATFORMS_SIMPLELINK_CS_SIMPLELINK_H_
|
#ifndef CS_COMMON_PLATFORMS_SIMPLELINK_CS_SIMPLELINK_H_
|
||||||
#define 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 simplelink.h is already included, all bets are off. */
|
||||||
#if defined(MG_NET_IF) && MG_NET_IF == MG_NET_IF_SIMPLELINK && \
|
#if !defined(__SIMPLELINK_H__)
|
||||||
!defined(__SIMPLELINK_H__)
|
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
@@ -1111,6 +1122,12 @@ int gettimeofday(struct timeval *tp, void *tzp);
|
|||||||
#undef fd_set
|
#undef fd_set
|
||||||
#endif
|
#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
|
/* We want to disable SL_INC_STD_BSD_API_NAMING, so we include user.h ourselves
|
||||||
* and undef it. */
|
* and undef it. */
|
||||||
#define PROVISIONING_API_H_
|
#define PROVISIONING_API_H_
|
||||||
@@ -1120,6 +1137,7 @@ int gettimeofday(struct timeval *tp, void *tzp);
|
|||||||
|
|
||||||
#include <simplelink/include/simplelink.h>
|
#include <simplelink/include/simplelink.h>
|
||||||
#include <simplelink/include/netapp.h>
|
#include <simplelink/include/netapp.h>
|
||||||
|
#endif /* CS_PLATFORM == CS_P_CC3220 */
|
||||||
|
|
||||||
/* Now define only the subset of the BSD API that we use.
|
/* Now define only the subset of the BSD API that we use.
|
||||||
* Notably, close(), read() and write() are not defined. */
|
* Notably, close(), read() and write() are not defined. */
|
||||||
@@ -1182,13 +1200,65 @@ int sl_fs_init(void);
|
|||||||
|
|
||||||
void sl_restart_cb(struct mg_mgr *mgr);
|
void sl_restart_cb(struct mg_mgr *mgr);
|
||||||
|
|
||||||
int sl_set_ssl_opts(struct mg_connection *nc);
|
int sl_set_ssl_opts(int sock, struct mg_connection *nc);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#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_ */
|
#endif /* CS_COMMON_PLATFORMS_SIMPLELINK_CS_SIMPLELINK_H_ */
|
||||||
#ifdef MG_MODULE_LINES
|
#ifdef MG_MODULE_LINES
|
||||||
@@ -1375,18 +1445,18 @@ typedef struct _stati64 {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef _UINTPTR_T_DEFINED
|
#ifndef _UINTPTR_T_DEFINED
|
||||||
typedef unsigned int* uintptr_t;
|
typedef unsigned int *uintptr_t;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define _S_IFREG 2
|
#define _S_IFREG 2
|
||||||
#define _S_IFDIR 4
|
#define _S_IFDIR 4
|
||||||
|
|
||||||
#ifndef S_ISDIR
|
#ifndef S_ISDIR
|
||||||
#define S_ISDIR(x) (((x) & _S_IFDIR) != 0)
|
#define S_ISDIR(x) (((x) &_S_IFDIR) != 0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef S_ISREG
|
#ifndef S_ISREG
|
||||||
#define S_ISREG(x) (((x) & _S_IFREG) != 0)
|
#define S_ISREG(x) (((x) &_S_IFREG) != 0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int open(const char *filename, int oflag, int pmode);
|
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
|
#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.
|
* See https://community.nxp.com/message/630860 for more details.
|
||||||
*
|
*
|
||||||
* Redlib is the default and lacks certain things, so we provide them.
|
* 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
|
#define CS_ENABLE_STDIO 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
char* inet_ntoa(struct in_addr in);
|
char *inet_ntoa(struct in_addr in);
|
||||||
|
|
||||||
#endif /* CS_PLATFORM == CS_P_PIC32 */
|
#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_
|
#ifndef CS_COMMON_CS_TIME_H_
|
||||||
#define CS_COMMON_CS_TIME_H_
|
#define CS_COMMON_CS_TIME_H_
|
||||||
|
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
/* Amalgamated: #include "common/platform.h" */
|
/* Amalgamated: #include "common/platform.h" */
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
@@ -1735,6 +1808,12 @@ extern "C" {
|
|||||||
/* Sub-second granularity time(). */
|
/* Sub-second granularity time(). */
|
||||||
double cs_time(void);
|
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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif /* __cplusplus */
|
#endif /* __cplusplus */
|
||||||
@@ -1757,7 +1836,7 @@ double cs_time(void);
|
|||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif /* __cplusplus */
|
#endif
|
||||||
|
|
||||||
/* Describes chunk of memory */
|
/* Describes chunk of memory */
|
||||||
struct mg_str {
|
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);
|
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_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);
|
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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif /* __cplusplus */
|
#endif
|
||||||
|
|
||||||
#endif /* CS_COMMON_MG_STR_H_ */
|
#endif /* CS_COMMON_MG_STR_H_ */
|
||||||
#ifdef MG_MODULE_LINES
|
#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>
|
#include <stdlib.h>
|
||||||
|
|
||||||
/* Amalgamated: #include "common/platform.h" */
|
/* Amalgamated: #include "common/platform.h" */
|
||||||
|
/* Amalgamated: #include "common/mg_str.h" */
|
||||||
|
|
||||||
#ifndef CS_ENABLE_STRDUP
|
#ifndef CS_ENABLE_STRDUP
|
||||||
#define CS_ENABLE_STRDUP 0
|
#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. */
|
/* Same as mg_asprintf, but takes varargs list. */
|
||||||
int mg_avprintf(char **buf, size_t size, const char *fmt, va_list ap);
|
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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -2910,14 +3025,14 @@ struct { \
|
|||||||
#define MG_ENABLE_IPV6 0
|
#define MG_ENABLE_IPV6 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef MG_ENABLE_JAVASCRIPT
|
|
||||||
#define MG_ENABLE_JAVASCRIPT 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef MG_ENABLE_MQTT
|
#ifndef MG_ENABLE_MQTT
|
||||||
#define MG_ENABLE_MQTT 1
|
#define MG_ENABLE_MQTT 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef MG_ENABLE_SOCKS
|
||||||
|
#define MG_ENABLE_SOCKS 0
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef MG_ENABLE_MQTT_BROKER
|
#ifndef MG_ENABLE_MQTT_BROKER
|
||||||
#define MG_ENABLE_MQTT_BROKER 0
|
#define MG_ENABLE_MQTT_BROKER 0
|
||||||
#endif
|
#endif
|
||||||
@@ -3214,11 +3329,6 @@ int mg_ssl_if_write(struct mg_connection *nc, const void *data, size_t len);
|
|||||||
#ifndef CS_MONGOOSE_SRC_NET_H_
|
#ifndef CS_MONGOOSE_SRC_NET_H_
|
||||||
#define 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/common.h" */
|
||||||
/* Amalgamated: #include "mongoose/src/net_if.h" */
|
/* Amalgamated: #include "mongoose/src/net_if.h" */
|
||||||
/* Amalgamated: #include "common/mbuf.h" */
|
/* Amalgamated: #include "common/mbuf.h" */
|
||||||
@@ -3281,10 +3391,7 @@ struct mg_mgr {
|
|||||||
void *user_data; /* User data */
|
void *user_data; /* User data */
|
||||||
int num_ifaces;
|
int num_ifaces;
|
||||||
struct mg_iface **ifaces; /* network interfaces */
|
struct mg_iface **ifaces; /* network interfaces */
|
||||||
#if MG_ENABLE_JAVASCRIPT
|
const char *nameserver; /* DNS server to use */
|
||||||
struct v7 *v7;
|
|
||||||
#endif
|
|
||||||
const char *nameserver; /* DNS server to use */
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -3748,17 +3855,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);
|
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.
|
* Schedules an MG_EV_TIMER event to be delivered at `timestamp` time.
|
||||||
* `timestamp` is UNIX time (the number of seconds since Epoch). It is
|
* `timestamp` is UNIX time (the number of seconds since Epoch). It is
|
||||||
@@ -3889,8 +3985,12 @@ int mg_normalize_uri_path(const struct mg_str *in, struct mg_str *out);
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif /* __cplusplus */
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
#ifndef MAX_PATH_SIZE
|
#ifndef MG_MAX_PATH
|
||||||
#define MAX_PATH_SIZE 500
|
#ifdef PATH_MAX
|
||||||
|
#define MG_MAX_PATH PATH_MAX
|
||||||
|
#else
|
||||||
|
#define MG_MAX_PATH 256
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -3995,9 +4095,10 @@ void mg_set_close_on_exec(sock_t);
|
|||||||
*
|
*
|
||||||
* If both port number and IP address are printed, they are separated by `:`.
|
* 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.
|
||||||
*/
|
*/
|
||||||
void mg_conn_addr_to_str(struct mg_connection *nc, char *buf, size_t len,
|
int mg_conn_addr_to_str(struct mg_connection *c, char *buf, size_t len,
|
||||||
int flags);
|
int flags);
|
||||||
#if MG_NET_IF == MG_NET_IF_SOCKET
|
#if MG_NET_IF == MG_NET_IF_SOCKET
|
||||||
/* Legacy interface. */
|
/* Legacy interface. */
|
||||||
void mg_sock_to_str(sock_t sock, char *buf, size_t len, int flags);
|
void mg_sock_to_str(sock_t sock, char *buf, size_t len, int flags);
|
||||||
@@ -4008,8 +4109,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.
|
* `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 mg_sock_addr_to_str(const union socket_address *sa, char *buf, size_t len,
|
||||||
int flags);
|
int flags);
|
||||||
|
|
||||||
#if MG_ENABLE_HEXDUMP
|
#if MG_ENABLE_HEXDUMP
|
||||||
/*
|
/*
|
||||||
@@ -4041,32 +4142,6 @@ void mg_hexdump_connection(struct mg_connection *nc, const char *path,
|
|||||||
*/
|
*/
|
||||||
int mg_is_big_endian(void);
|
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.
|
* Use with cs_base64_init/update/finish in order to write out base64 in chunks.
|
||||||
*/
|
*/
|
||||||
@@ -4085,6 +4160,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,
|
void mg_basic_auth_header(const struct mg_str user, const struct mg_str pass,
|
||||||
struct mbuf *buf);
|
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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif /* __cplusplus */
|
#endif /* __cplusplus */
|
||||||
@@ -4121,14 +4204,6 @@ extern "C" {
|
|||||||
#define MG_MAX_HTTP_REQUEST_SIZE 1024
|
#define MG_MAX_HTTP_REQUEST_SIZE 1024
|
||||||
#endif
|
#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
|
#ifndef MG_MAX_HTTP_SEND_MBUF
|
||||||
#define MG_MAX_HTTP_SEND_MBUF 1024
|
#define MG_MAX_HTTP_SEND_MBUF 1024
|
||||||
#endif
|
#endif
|
||||||
@@ -4865,6 +4940,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,
|
int mg_http_check_digest_auth(struct http_message *hm, const char *auth_domain,
|
||||||
FILE *fp);
|
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.
|
* 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
|
* This function sends the buffer size as hex number + newline first, then
|
||||||
@@ -5070,6 +5157,7 @@ int mg_http_create_digest_auth_header(char *buf, size_t buf_len,
|
|||||||
struct mg_mqtt_message {
|
struct mg_mqtt_message {
|
||||||
int cmd;
|
int cmd;
|
||||||
int qos;
|
int qos;
|
||||||
|
int len; /* message length in the IO buffer */
|
||||||
struct mg_str topic;
|
struct mg_str topic;
|
||||||
struct mg_str payload;
|
struct mg_str payload;
|
||||||
|
|
||||||
@@ -5105,6 +5193,7 @@ struct mg_send_mqtt_handshake_opts {
|
|||||||
/* mg_mqtt_proto_data should be in header to allow external access to it */
|
/* mg_mqtt_proto_data should be in header to allow external access to it */
|
||||||
struct mg_mqtt_proto_data {
|
struct mg_mqtt_proto_data {
|
||||||
uint16_t keep_alive;
|
uint16_t keep_alive;
|
||||||
|
double last_control_time;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Message types */
|
/* Message types */
|
||||||
@@ -5303,7 +5392,9 @@ int mg_mqtt_vmatch_topic_expression(const char *exp, struct mg_str topic);
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif /* __cplusplus */
|
#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;
|
struct mg_mqtt_broker;
|
||||||
|
|
||||||
@@ -5945,3 +6036,72 @@ struct mg_connection *mg_sntp_get_time(struct mg_mgr *mgr,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* CS_MONGOOSE_SRC_SNTP_H_ */
|
#endif /* CS_MONGOOSE_SRC_SNTP_H_ */
|
||||||
|
#ifdef MG_MODULE_LINES
|
||||||
|
#line 1 "mongoose/src/socks.h"
|
||||||
|
#endif
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2017 Cesanta Software Limited
|
||||||
|
* All rights reserved
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef CS_MONGOOSE_SRC_SOCKS_H_
|
||||||
|
#define CS_MONGOOSE_SRC_SOCKS_H_
|
||||||
|
|
||||||
|
#if MG_ENABLE_SOCKS
|
||||||
|
|
||||||
|
#define MG_SOCKS_VERSION 5
|
||||||
|
|
||||||
|
#define MG_SOCKS_HANDSHAKE_DONE MG_F_USER_1
|
||||||
|
#define MG_SOCKS_CONNECT_DONE MG_F_USER_2
|
||||||
|
|
||||||
|
/* SOCKS5 handshake methods */
|
||||||
|
enum mg_socks_handshake_method {
|
||||||
|
MG_SOCKS_HANDSHAKE_NOAUTH = 0, /* Handshake method - no authentication */
|
||||||
|
MG_SOCKS_HANDSHAKE_GSSAPI = 1, /* Handshake method - GSSAPI auth */
|
||||||
|
MG_SOCKS_HANDSHAKE_USERPASS = 2, /* Handshake method - user/password auth */
|
||||||
|
MG_SOCKS_HANDSHAKE_FAILURE = 0xff, /* Handshake method - failure */
|
||||||
|
};
|
||||||
|
|
||||||
|
/* SOCKS5 commands */
|
||||||
|
enum mg_socks_command {
|
||||||
|
MG_SOCKS_CMD_CONNECT = 1, /* Command: CONNECT */
|
||||||
|
MG_SOCKS_CMD_BIND = 2, /* Command: BIND */
|
||||||
|
MG_SOCKS_CMD_UDP_ASSOCIATE = 3, /* Command: UDP ASSOCIATE */
|
||||||
|
};
|
||||||
|
|
||||||
|
/* SOCKS5 address types */
|
||||||
|
enum mg_socks_address_type {
|
||||||
|
MG_SOCKS_ADDR_IPV4 = 1, /* Address type: IPv4 */
|
||||||
|
MG_SOCKS_ADDR_DOMAIN = 3, /* Address type: Domain name */
|
||||||
|
MG_SOCKS_ADDR_IPV6 = 4, /* Address type: IPv6 */
|
||||||
|
};
|
||||||
|
|
||||||
|
/* SOCKS5 response codes */
|
||||||
|
enum mg_socks_response {
|
||||||
|
MG_SOCKS_SUCCESS = 0, /* Response: success */
|
||||||
|
MG_SOCKS_FAILURE = 1, /* Response: failure */
|
||||||
|
MG_SOCKS_NOT_ALLOWED = 2, /* Response: connection not allowed */
|
||||||
|
MG_SOCKS_NET_UNREACHABLE = 3, /* Response: network unreachable */
|
||||||
|
MG_SOCKS_HOST_UNREACHABLE = 4, /* Response: network unreachable */
|
||||||
|
MG_SOCKS_CONN_REFUSED = 5, /* Response: network unreachable */
|
||||||
|
MG_SOCKS_TTL_EXPIRED = 6, /* Response: network unreachable */
|
||||||
|
MG_SOCKS_CMD_NOT_SUPPORTED = 7, /* Response: network unreachable */
|
||||||
|
MG_SOCKS_ADDR_NOT_SUPPORTED = 8, /* Response: network unreachable */
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
|
/* Turn the connection into the SOCKS server */
|
||||||
|
void mg_set_protocol_socks(struct mg_connection *c);
|
||||||
|
|
||||||
|
/* Create socks tunnel for the client connection */
|
||||||
|
struct mg_iface *mg_socks_mk_iface(struct mg_mgr *, const char *proxy_addr);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
+6
-2
@@ -99,9 +99,9 @@ def resolve(path, parent_name):
|
|||||||
else:
|
else:
|
||||||
p = os.path.join(args.include_path, path)
|
p = os.path.join(args.include_path, path)
|
||||||
if os.path.exists(p) and not args.norel:
|
if os.path.exists(p) and not args.norel:
|
||||||
p = os.path.realpath(p).replace('%s/' % os.getcwd(), '')
|
p = os.path.realpath(p).replace('%s%s' % (os.getcwd(), os.sep), '')
|
||||||
# print >>sys.stderr, '%s -> %s (cwd %s)' % (path, p, os.getcwd())
|
# print >>sys.stderr, '%s -> %s (cwd %s)' % (path, p, os.getcwd())
|
||||||
return p
|
return p.replace(os.sep, '/')
|
||||||
|
|
||||||
def emit_line_directive(out, name, parent_name):
|
def emit_line_directive(out, name, parent_name):
|
||||||
print >>out, '''#ifdef %(prefix)s_MODULE_LINES
|
print >>out, '''#ifdef %(prefix)s_MODULE_LINES
|
||||||
@@ -148,6 +148,10 @@ if args.first:
|
|||||||
|
|
||||||
# emitting
|
# emitting
|
||||||
|
|
||||||
|
if sys.platform == "win32":
|
||||||
|
import os, msvcrt
|
||||||
|
msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
|
||||||
|
|
||||||
if args.public:
|
if args.public:
|
||||||
print '#include "%s"' % (args.public)
|
print '#include "%s"' % (args.public)
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user