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 | ||
|
|
acfc66cd60 | ||
|
|
6f140202ad | ||
|
|
cfe77a3d58 | ||
|
|
a0527a7f0e | ||
|
|
c90cffa688 | ||
|
|
d7a633bfa3 | ||
|
|
0ea3cdd228 | ||
|
|
ddef065493 | ||
|
|
ac857d18db | ||
|
|
663e928d65 | ||
|
|
189cd8c5f6 | ||
|
|
692f436b3d | ||
|
|
2e65ce8272 | ||
|
|
a35e5bd966 | ||
|
|
83fe5a17f3 | ||
|
|
49bbfaf130 | ||
|
|
cd9c7dcbec | ||
|
|
f868fc861b | ||
|
|
84907d5bc4 | ||
|
|
1cee8a16b9 | ||
|
|
57e32b87c7 | ||
|
|
6926655513 | ||
|
|
8354319e72 | ||
|
|
f9596cc1db | ||
|
|
b2e2ad9a45 | ||
|
|
a07fb2be51 | ||
|
|
7f259f2a79 | ||
|
|
7c0493071f | ||
|
|
c60fe0c6f6 | ||
|
|
8ce34af9f3 | ||
|
|
82761bb875 | ||
|
|
08a10a8af5 | ||
|
|
bd130136bc | ||
|
|
fb04203b72 | ||
|
|
4172c190e5 | ||
|
|
920abd627b | ||
|
|
02b7399f9a | ||
|
|
b8402ed073 | ||
|
|
06c5c4d2a4 | ||
|
|
57a4ec31d1 | ||
|
|
511c9a6d4a | ||
|
|
8ec47111d5 | ||
|
|
8b67274cc0 | ||
|
|
af22fb7a06 | ||
|
|
df5fff5e72 | ||
|
|
d9243d1c0b | ||
|
|
2fb145d39d | ||
|
|
14094aaef7 | ||
|
|
ec752645ee | ||
|
|
ceb2f1da41 | ||
|
|
aab857a66e | ||
|
|
066be0fe30 | ||
|
|
380e87ddfa | ||
|
|
e9a7a2af18 | ||
|
|
a83e7d8c42 | ||
|
|
bf7dd7ac63 | ||
|
|
0fc3370859 | ||
|
|
c416012f97 | ||
|
|
d3a8862bd8 | ||
|
|
08353731ef | ||
|
|
16700244b0 | ||
|
|
49ca223e9c | ||
|
|
38efe632ae | ||
|
|
39a3bb7e44 | ||
|
|
920e8d9145 | ||
|
|
aed6d05d8c | ||
|
|
d85d95a40b | ||
|
|
b5dd54a404 | ||
|
|
f7c0a2ee15 | ||
|
|
874b5bfdbf | ||
|
|
71d09722be | ||
|
|
349d25dccf | ||
|
|
3942914945 | ||
|
|
60c16bbb5d | ||
|
|
70b5f4130e | ||
|
|
17cfecc5c3 | ||
|
|
ebdd18769b | ||
|
|
f974fddd2a | ||
|
|
b1a46da309 | ||
|
|
81879be4be | ||
|
|
0a094d4c1f | ||
|
|
66a96410d4 | ||
|
|
d4b23f08b6 | ||
|
|
d6d956b9d8 | ||
|
|
383b2a48c5 | ||
|
|
ab1c464950 | ||
|
|
f20b5191f2 | ||
|
|
fc113d64f5 | ||
|
|
6f6b12bee7 | ||
|
|
4e6c2867da | ||
|
|
54989e819a | ||
|
|
bf505bb68d | ||
|
|
4072062b72 | ||
|
|
d6ba37dc3c | ||
|
|
a58d21aa28 | ||
|
|
6e8d4129b2 | ||
|
|
2485a8f8d9 | ||
|
|
1ae908f6d5 | ||
|
|
6b923bdff1 | ||
|
|
d39969d1e6 | ||
|
|
eaef5bd133 | ||
|
|
7cc7df8c0e | ||
|
|
551f393da7 | ||
|
|
e81f8373a2 | ||
|
|
dfa83f2c85 | ||
|
|
91bdbc5193 | ||
|
|
707b9ed2d6 | ||
|
|
cd6b846e22 | ||
|
|
807e4ea6ec | ||
|
|
507e8bfac9 | ||
|
|
2ea63a0ea6 | ||
|
|
7988acbff4 | ||
|
|
b8c3740446 | ||
|
|
7bdbd80552 | ||
|
|
577ad2599c |
No files matched your search
@@ -0,0 +1,9 @@
|
|||||||
|
binary/
|
||||||
|
deps/
|
||||||
|
docker/
|
||||||
|
docs/
|
||||||
|
examples/
|
||||||
|
platforms/
|
||||||
|
src/
|
||||||
|
test/
|
||||||
|
multilingual/
|
||||||
@@ -8,18 +8,18 @@ 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?
|
||||||
|
|
||||||
Check out [Mongoose OS](https://mongoose-iot.com) - open source embedded operating system for low-power connected microcontrollers. Secure, designed for Internet of Things, complete environment for prototyping, development and managing.
|
Check out [Mongoose OS](https://mongoose-os.com) - open source embedded operating system for low-power connected microcontrollers. Secure, designed for Internet of Things, complete environment for prototyping, development and managing.
|
||||||
|
|
||||||
# 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-iot.com) - open source embedded operati
|
|||||||
|
|
||||||
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)
|
|
||||||
@@ -7,5 +7,5 @@ signature: |
|
|||||||
---
|
---
|
||||||
|
|
||||||
Frees the memory allocated for options.
|
Frees the memory allocated for options.
|
||||||
If the cm paramater doesn't contain any option it does nothing.
|
If the cm parameter doesn't contain any option it does nothing.
|
||||||
|
|
||||||
@@ -21,5 +21,5 @@ This function doesn't update the `name` and `rdata` pointers in the `rr`
|
|||||||
struct because they might be invalidated as soon as the IO buffer grows
|
struct because they might be invalidated as soon as the IO buffer grows
|
||||||
again.
|
again.
|
||||||
|
|
||||||
Returns the number of bytes appened or -1 in case of error.
|
Returns the number of bytes appended or -1 in case of error.
|
||||||
|
|
||||||
@@ -11,6 +11,7 @@ items:
|
|||||||
- { name: mg_send_websocket_handshake.md }
|
- { name: mg_send_websocket_handshake.md }
|
||||||
- { name: mg_send_websocket_handshake2.md }
|
- { name: mg_send_websocket_handshake2.md }
|
||||||
- { name: mg_send_websocket_handshake3.md }
|
- { name: mg_send_websocket_handshake3.md }
|
||||||
|
- { name: mg_send_websocket_handshake3v.md }
|
||||||
- { name: mg_set_protocol_http_websocket.md }
|
- { name: mg_set_protocol_http_websocket.md }
|
||||||
- { name: mg_url_decode.md }
|
- { name: mg_url_decode.md }
|
||||||
- { name: struct_http_message.md }
|
- { name: struct_http_message.md }
|
||||||
|
|||||||
@@ -4,9 +4,8 @@ decl_name: "mg_connect_ws"
|
|||||||
symbol_kind: "func"
|
symbol_kind: "func"
|
||||||
signature: |
|
signature: |
|
||||||
struct mg_connection *mg_connect_ws(struct mg_mgr *mgr,
|
struct mg_connection *mg_connect_ws(struct mg_mgr *mgr,
|
||||||
mg_event_handler_t event_handler,
|
MG_CB(mg_event_handler_t event_handler,
|
||||||
const char *url, const char *protocol,
|
void *user_data);
|
||||||
const char *extra_headers);
|
|
||||||
---
|
---
|
||||||
|
|
||||||
Helper function that creates an outbound WebSocket connection.
|
Helper function that creates an outbound WebSocket connection.
|
||||||
|
|||||||
@@ -3,11 +3,8 @@ title: "mg_connect_ws_opt()"
|
|||||||
decl_name: "mg_connect_ws_opt"
|
decl_name: "mg_connect_ws_opt"
|
||||||
symbol_kind: "func"
|
symbol_kind: "func"
|
||||||
signature: |
|
signature: |
|
||||||
struct mg_connection *mg_connect_ws_opt(struct mg_mgr *mgr,
|
struct mg_connection *mg_connect_ws_opt(
|
||||||
mg_event_handler_t ev_handler,
|
struct mg_mgr *mgr, MG_CB(mg_event_handler_t ev_handler, void *user_data);
|
||||||
struct mg_connect_opts opts,
|
|
||||||
const char *url, const char *protocol,
|
|
||||||
const char *extra_headers);
|
|
||||||
---
|
---
|
||||||
|
|
||||||
Helper function that creates an outbound WebSocket connection
|
Helper function that creates an outbound WebSocket connection
|
||||||
|
|||||||
@@ -9,5 +9,6 @@ signature: |
|
|||||||
|
|
||||||
Sends multiple websocket frames.
|
Sends multiple websocket frames.
|
||||||
|
|
||||||
Like `mg_send_websocket_frame()`, but composes a frame from multiple buffers.
|
Like `mg_send_websocket_frame()`, but composes a frame from multiple
|
||||||
|
*buffers.
|
||||||
|
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
---
|
||||||
|
title: "mg_send_websocket_handshake3v()"
|
||||||
|
decl_name: "mg_send_websocket_handshake3v"
|
||||||
|
symbol_kind: "func"
|
||||||
|
signature: |
|
||||||
|
void mg_send_websocket_handshake3v(struct mg_connection *nc,
|
||||||
|
const struct mg_str path,
|
||||||
|
const struct mg_str host,
|
||||||
|
const struct mg_str protocol,
|
||||||
|
const struct mg_str extra_headers,
|
||||||
|
const struct mg_str user,
|
||||||
|
const struct mg_str pass);
|
||||||
|
---
|
||||||
|
|
||||||
|
Same as mg_send_websocket_handshake3 but with strings not necessarily
|
||||||
|
NUL-temrinated
|
||||||
|
|
||||||
@@ -13,6 +13,7 @@ Source string is specified by (`src`, `src_len`), and destination is
|
|||||||
(`dst`, `dst_len`). If `is_form_url_encoded` is non-zero, then
|
(`dst`, `dst_len`). If `is_form_url_encoded` is non-zero, then
|
||||||
`+` character is decoded as a blank space character. This function
|
`+` character is decoded as a blank space character. This function
|
||||||
guarantees to NUL-terminate the destination. If destination is too small,
|
guarantees to NUL-terminate the destination. If destination is too small,
|
||||||
then the source string is partially decoded and `-1` is returned. Otherwise,
|
then the source string is partially decoded and `-1` is returned.
|
||||||
|
*Otherwise,
|
||||||
a length of the decoded string is returned, not counting final NUL.
|
a length of the decoded string is returned, not counting final NUL.
|
||||||
|
|
||||||
@@ -5,6 +5,7 @@ symbol_kind: "struct"
|
|||||||
signature: |
|
signature: |
|
||||||
struct http_message {
|
struct http_message {
|
||||||
struct mg_str message; /* Whole message: request line + headers + body */
|
struct mg_str message; /* Whole message: request line + headers + body */
|
||||||
|
struct mg_str body; /* Message body. 0-length for requests with no body */
|
||||||
|
|
||||||
/* HTTP Request line (or HTTP response line) */
|
/* HTTP Request line (or HTTP response line) */
|
||||||
struct mg_str method; /* "GET" */
|
struct mg_str method; /* "GET" */
|
||||||
@@ -28,9 +29,6 @@ signature: |
|
|||||||
/* Headers */
|
/* Headers */
|
||||||
struct mg_str header_names[MG_MAX_HTTP_HEADERS];
|
struct mg_str header_names[MG_MAX_HTTP_HEADERS];
|
||||||
struct mg_str header_values[MG_MAX_HTTP_HEADERS];
|
struct mg_str header_values[MG_MAX_HTTP_HEADERS];
|
||||||
|
|
||||||
/* Message body */
|
|
||||||
struct mg_str body; /* Zero-length for requests with no body */
|
|
||||||
};
|
};
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@@ -3,11 +3,9 @@ title: "mg_connect_http()"
|
|||||||
decl_name: "mg_connect_http"
|
decl_name: "mg_connect_http"
|
||||||
symbol_kind: "func"
|
symbol_kind: "func"
|
||||||
signature: |
|
signature: |
|
||||||
struct mg_connection *mg_connect_http(struct mg_mgr *mgr,
|
struct mg_connection *mg_connect_http(
|
||||||
mg_event_handler_t event_handler,
|
struct mg_mgr *mgr,
|
||||||
const char *url,
|
MG_CB(mg_event_handler_t event_handler, void *user_data);
|
||||||
const char *extra_headers,
|
|
||||||
const char *post_data);
|
|
||||||
---
|
---
|
||||||
|
|
||||||
Helper function that creates an outbound HTTP connection.
|
Helper function that creates an outbound HTTP connection.
|
||||||
|
|||||||
@@ -3,12 +3,8 @@ title: "mg_connect_http_opt()"
|
|||||||
decl_name: "mg_connect_http_opt"
|
decl_name: "mg_connect_http_opt"
|
||||||
symbol_kind: "func"
|
symbol_kind: "func"
|
||||||
signature: |
|
signature: |
|
||||||
struct mg_connection *mg_connect_http_opt(struct mg_mgr *mgr,
|
struct mg_connection *mg_connect_http_opt(
|
||||||
mg_event_handler_t ev_handler,
|
struct mg_mgr *mgr, MG_CB(mg_event_handler_t ev_handler, void *user_data);
|
||||||
struct mg_connect_opts opts,
|
|
||||||
const char *url,
|
|
||||||
const char *extra_headers,
|
|
||||||
const char *post_data);
|
|
||||||
---
|
---
|
||||||
|
|
||||||
Helper function that creates an outbound HTTP connection.
|
Helper function that creates an outbound HTTP connection.
|
||||||
|
|||||||
@@ -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().
|
||||||
|
|
||||||
@@ -4,7 +4,8 @@ decl_name: "mg_file_upload_handler"
|
|||||||
symbol_kind: "func"
|
symbol_kind: "func"
|
||||||
signature: |
|
signature: |
|
||||||
void mg_file_upload_handler(struct mg_connection *nc, int ev, void *ev_data,
|
void mg_file_upload_handler(struct mg_connection *nc, int ev, void *ev_data,
|
||||||
mg_fu_fname_fn local_name_fn);
|
mg_fu_fname_fn local_name_fn
|
||||||
|
MG_UD_ARG(void *user_data);
|
||||||
---
|
---
|
||||||
|
|
||||||
File upload handler.
|
File upload handler.
|
||||||
|
|||||||
@@ -12,5 +12,6 @@ Fetches a HTTP form variable.
|
|||||||
Fetches a variable `name` from a `buf` into a buffer specified by `dst`,
|
Fetches a variable `name` from a `buf` into a buffer specified by `dst`,
|
||||||
`dst_len`. The destination is always zero-terminated. Returns the length of
|
`dst_len`. The destination is always zero-terminated. Returns the length of
|
||||||
a fetched variable. If not found, 0 is returned. `buf` must be valid
|
a fetched variable. If not found, 0 is returned. `buf` must be valid
|
||||||
url-encoded buffer. If destination is too small, `-1` is returned.
|
url-encoded buffer. If destination is too small or an error occured,
|
||||||
|
negative number is returned.
|
||||||
|
|
||||||
@@ -12,7 +12,7 @@ Sends a redirect response.
|
|||||||
`status_code` should be either 301 or 302 and `location` point to the
|
`status_code` should be either 301 or 302 and `location` point to the
|
||||||
new location.
|
new location.
|
||||||
If `extra_headers` is not empty, then `extra_headers` are also sent
|
If `extra_headers` is not empty, then `extra_headers` are also sent
|
||||||
after the reponse line. `extra_headers` must NOT end end with new line.
|
after the response line. `extra_headers` must NOT end end with new line.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,8 @@ decl_name: "mg_register_http_endpoint"
|
|||||||
symbol_kind: "func"
|
symbol_kind: "func"
|
||||||
signature: |
|
signature: |
|
||||||
void mg_register_http_endpoint(struct mg_connection *nc, const char *uri_path,
|
void mg_register_http_endpoint(struct mg_connection *nc, const char *uri_path,
|
||||||
mg_event_handler_t handler);
|
MG_CB(mg_event_handler_t handler,
|
||||||
|
void *user_data);
|
||||||
---
|
---
|
||||||
|
|
||||||
Registers a callback for a specified http endpoint
|
Registers a callback for a specified http endpoint
|
||||||
@@ -20,7 +21,7 @@ static void handle_hello1(struct mg_connection *nc, int ev, void *ev_data) {
|
|||||||
nc->flags |= MG_F_SEND_AND_CLOSE;
|
nc->flags |= MG_F_SEND_AND_CLOSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_hello1(struct mg_connection *nc, int ev, void *ev_data) {
|
static void handle_hello2(struct mg_connection *nc, int ev, void *ev_data) {
|
||||||
(void) ev; (void) ev_data;
|
(void) ev; (void) ev_data;
|
||||||
mg_printf(nc, "HTTP/1.0 200 OK\r\n\r\n[I am Hello2]");
|
mg_printf(nc, "HTTP/1.0 200 OK\r\n\r\n[I am Hello2]");
|
||||||
nc->flags |= MG_F_SEND_AND_CLOSE;
|
nc->flags |= MG_F_SEND_AND_CLOSE;
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ signature: |
|
|||||||
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
|
||||||
the buffer itself, then the newline. For example,
|
the buffer itself, then the newline. For example,
|
||||||
`mg_send_http_chunk(nc, "foo", 3)` whill append the `3\r\nfoo\r\n` string
|
`mg_send_http_chunk(nc, "foo", 3)` will append the `3\r\nfoo\r\n` string
|
||||||
to the `nc->send_mbuf` output IO buffer.
|
to the `nc->send_mbuf` output IO buffer.
|
||||||
|
|
||||||
NOTE: The HTTP header "Transfer-Encoding: chunked" should be sent prior to
|
NOTE: The HTTP header "Transfer-Encoding: chunked" should be sent prior to
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ signature: |
|
|||||||
|
|
||||||
Sends the response status line.
|
Sends the response status line.
|
||||||
If `extra_headers` is not NULL, then `extra_headers` are also sent
|
If `extra_headers` is not NULL, then `extra_headers` are also sent
|
||||||
after the reponse line. `extra_headers` must NOT end end with new line.
|
after the response line. `extra_headers` must NOT end end with new line.
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
mg_send_response_line(nc, 200, "Access-Control-Allow-Origin: *");
|
mg_send_response_line(nc, 200, "Access-Control-Allow-Origin: *");
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ decl_name: "mqtt.h"
|
|||||||
items:
|
items:
|
||||||
- { name: mg_mqtt_connack.md }
|
- { name: mg_mqtt_connack.md }
|
||||||
- { name: mg_mqtt_disconnect.md }
|
- { name: mg_mqtt_disconnect.md }
|
||||||
|
- { name: mg_mqtt_match_topic_expression.md }
|
||||||
- { name: mg_mqtt_next_subscribe_topic.md }
|
- { name: mg_mqtt_next_subscribe_topic.md }
|
||||||
- { name: mg_mqtt_ping.md }
|
- { name: mg_mqtt_ping.md }
|
||||||
- { name: mg_mqtt_pong.md }
|
- { name: mg_mqtt_pong.md }
|
||||||
@@ -17,6 +18,7 @@ items:
|
|||||||
- { name: mg_mqtt_subscribe.md }
|
- { name: mg_mqtt_subscribe.md }
|
||||||
- { name: mg_mqtt_unsuback.md }
|
- { name: mg_mqtt_unsuback.md }
|
||||||
- { name: mg_mqtt_unsubscribe.md }
|
- { name: mg_mqtt_unsubscribe.md }
|
||||||
|
- { name: mg_mqtt_vmatch_topic_expression.md }
|
||||||
- { name: mg_send_mqtt_handshake.md }
|
- { name: mg_send_mqtt_handshake.md }
|
||||||
- { name: mg_send_mqtt_handshake_opt.md }
|
- { name: mg_send_mqtt_handshake_opt.md }
|
||||||
- { name: mg_set_protocol_mqtt.md }
|
- { name: mg_set_protocol_mqtt.md }
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
---
|
||||||
|
title: "mg_mqtt_match_topic_expression()"
|
||||||
|
decl_name: "mg_mqtt_match_topic_expression"
|
||||||
|
symbol_kind: "func"
|
||||||
|
signature: |
|
||||||
|
int mg_mqtt_match_topic_expression(struct mg_str exp, struct mg_str topic);
|
||||||
|
---
|
||||||
|
|
||||||
|
Matches a topic against a topic expression
|
||||||
|
|
||||||
|
Returns 1 if it matches; 0 otherwise.
|
||||||
|
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
---
|
||||||
|
title: "mg_mqtt_vmatch_topic_expression()"
|
||||||
|
decl_name: "mg_mqtt_vmatch_topic_expression"
|
||||||
|
symbol_kind: "func"
|
||||||
|
signature: |
|
||||||
|
int mg_mqtt_vmatch_topic_expression(const char *exp, struct mg_str topic);
|
||||||
|
---
|
||||||
|
|
||||||
|
Same as `mg_mqtt_match_topic_expression()`, but takes `exp` as a
|
||||||
|
NULL-terminated string.
|
||||||
|
|
||||||
@@ -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,8 +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_enable_multithreading.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 }
|
||||||
@@ -33,7 +31,6 @@ items:
|
|||||||
- { name: struct_mg_connection.md }
|
- { name: struct_mg_connection.md }
|
||||||
- { name: struct_mg_mgr.md }
|
- { name: struct_mg_mgr.md }
|
||||||
- { name: struct_mg_mgr_init_opts.md }
|
- { name: struct_mg_mgr_init_opts.md }
|
||||||
- { name: struct_mg_multithreading_opts.md }
|
|
||||||
---
|
---
|
||||||
|
|
||||||
NOTE: Mongoose manager is single threaded. It does not protect
|
NOTE: Mongoose manager is single threaded. It does not protect
|
||||||
|
|||||||
@@ -3,7 +3,9 @@ title: "mg_add_sock()"
|
|||||||
decl_name: "mg_add_sock"
|
decl_name: "mg_add_sock"
|
||||||
symbol_kind: "func"
|
symbol_kind: "func"
|
||||||
signature: |
|
signature: |
|
||||||
struct mg_connection *mg_add_sock(struct mg_mgr *, sock_t, mg_event_handler_t);
|
struct mg_connection *mg_add_sock(struct mg_mgr *mgr, sock_t sock,
|
||||||
|
MG_CB(mg_event_handler_t handler,
|
||||||
|
void *user_data);
|
||||||
---
|
---
|
||||||
|
|
||||||
Creates a connection, associates it with the given socket and event handler
|
Creates a connection, associates it with the given socket and event handler
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ title: "mg_add_sock_opt()"
|
|||||||
decl_name: "mg_add_sock_opt"
|
decl_name: "mg_add_sock_opt"
|
||||||
symbol_kind: "func"
|
symbol_kind: "func"
|
||||||
signature: |
|
signature: |
|
||||||
struct mg_connection *mg_add_sock_opt(struct mg_mgr *, sock_t,
|
struct mg_connection *mg_add_sock_opt(struct mg_mgr *mgr, sock_t sock,
|
||||||
mg_event_handler_t,
|
MG_CB(mg_event_handler_t handler,
|
||||||
struct mg_add_sock_opts);
|
void *user_data);
|
||||||
---
|
---
|
||||||
|
|
||||||
Creates a connection, associates it with the given socket and event handler
|
Creates a connection, associates it with the given socket and event handler
|
||||||
|
|||||||
@@ -3,8 +3,9 @@ title: "mg_bind()"
|
|||||||
decl_name: "mg_bind"
|
decl_name: "mg_bind"
|
||||||
symbol_kind: "func"
|
symbol_kind: "func"
|
||||||
signature: |
|
signature: |
|
||||||
struct mg_connection *mg_bind(struct mg_mgr *, const char *,
|
struct mg_connection *mg_bind(struct mg_mgr *mgr, const char *address,
|
||||||
mg_event_handler_t);
|
MG_CB(mg_event_handler_t handler,
|
||||||
|
void *user_data);
|
||||||
---
|
---
|
||||||
|
|
||||||
Creates a listening connection.
|
Creates a listening connection.
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ decl_name: "mg_bind_opt"
|
|||||||
symbol_kind: "func"
|
symbol_kind: "func"
|
||||||
signature: |
|
signature: |
|
||||||
struct mg_connection *mg_bind_opt(struct mg_mgr *mgr, const char *address,
|
struct mg_connection *mg_bind_opt(struct mg_mgr *mgr, const char *address,
|
||||||
mg_event_handler_t handler,
|
MG_CB(mg_event_handler_t handler,
|
||||||
struct mg_bind_opts opts);
|
void *user_data);
|
||||||
---
|
---
|
||||||
|
|
||||||
Creates a listening connection.
|
Creates a listening connection.
|
||||||
@@ -15,7 +15,7 @@ the same as for the `mg_connect()` call, where `HOST` part is optional.
|
|||||||
`address` can be just a port number, e.g. `:8000`. To bind to a specific
|
`address` can be just a port number, e.g. `:8000`. To bind to a specific
|
||||||
interface, an IP address can be specified, e.g. `1.2.3.4:8000`. By default,
|
interface, an IP address can be specified, e.g. `1.2.3.4:8000`. By default,
|
||||||
a TCP connection is created. To create UDP connection, prepend `udp://`
|
a TCP connection is created. To create UDP connection, prepend `udp://`
|
||||||
prefix, e.g. `udp://:8000`. To summarize, `address` paramer has following
|
prefix, e.g. `udp://:8000`. To summarize, `address` parameter has following
|
||||||
format: `[PROTO://][IP_ADDRESS]:PORT`, where `PROTO` could be `tcp` or
|
format: `[PROTO://][IP_ADDRESS]:PORT`, where `PROTO` could be `tcp` or
|
||||||
`udp`.
|
`udp`.
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,8 @@ title: "mg_broadcast()"
|
|||||||
decl_name: "mg_broadcast"
|
decl_name: "mg_broadcast"
|
||||||
symbol_kind: "func"
|
symbol_kind: "func"
|
||||||
signature: |
|
signature: |
|
||||||
void mg_broadcast(struct mg_mgr *, mg_event_handler_t func, void *, size_t);
|
void mg_broadcast(struct mg_mgr *mgr, mg_event_handler_t cb, void *data,
|
||||||
|
size_t len);
|
||||||
---
|
---
|
||||||
|
|
||||||
Passes a message of a given length to all connections.
|
Passes a message of a given length to all connections.
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ Subnet masks may vary from 0 to 32, inclusive. The default setting
|
|||||||
is to allow all access. On each request the full list is traversed,
|
is to allow all access. On each request the full list is traversed,
|
||||||
and the last match wins. Example:
|
and the last match wins. Example:
|
||||||
|
|
||||||
`-0.0.0.0/0,+192.168/16` - deny all acccesses, only allow 192.168/16 subnet
|
`-0.0.0.0/0,+192.168/16` - deny all accesses, only allow 192.168/16 subnet
|
||||||
|
|
||||||
To learn more about subnet masks, see this
|
To learn more about subnet masks, see this
|
||||||
link:https://en.wikipedia.org/wiki/Subnetwork[Wikipedia page on Subnetwork].
|
link:https://en.wikipedia.org/wiki/Subnetwork[Wikipedia page on Subnetwork].
|
||||||
|
|||||||
@@ -4,7 +4,8 @@ decl_name: "mg_connect"
|
|||||||
symbol_kind: "func"
|
symbol_kind: "func"
|
||||||
signature: |
|
signature: |
|
||||||
struct mg_connection *mg_connect(struct mg_mgr *mgr, const char *address,
|
struct mg_connection *mg_connect(struct mg_mgr *mgr, const char *address,
|
||||||
mg_event_handler_t handler);
|
MG_CB(mg_event_handler_t handler,
|
||||||
|
void *user_data);
|
||||||
---
|
---
|
||||||
|
|
||||||
Connects to a remote host.
|
Connects to a remote host.
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ decl_name: "mg_connect_opt"
|
|||||||
symbol_kind: "func"
|
symbol_kind: "func"
|
||||||
signature: |
|
signature: |
|
||||||
struct mg_connection *mg_connect_opt(struct mg_mgr *mgr, const char *address,
|
struct mg_connection *mg_connect_opt(struct mg_mgr *mgr, const char *address,
|
||||||
mg_event_handler_t handler,
|
MG_CB(mg_event_handler_t handler,
|
||||||
struct mg_connect_opts opts);
|
void *user_data);
|
||||||
---
|
---
|
||||||
|
|
||||||
Connects to a remote host.
|
Connects to a remote host.
|
||||||
|
|||||||
@@ -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.
|
|
||||||
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
---
|
|
||||||
title: "mg_enable_multithreading()"
|
|
||||||
decl_name: "mg_enable_multithreading"
|
|
||||||
symbol_kind: "func"
|
|
||||||
signature: |
|
|
||||||
void mg_enable_multithreading(struct mg_connection *nc);
|
|
||||||
---
|
|
||||||
|
|
||||||
Enables multi-threaded handling for the given listening connection `nc`.
|
|
||||||
For each accepted connection, Mongoose will create a separate thread
|
|
||||||
and run an event handler in that thread. Thus, if an event handler is doing
|
|
||||||
a blocking call or some long computation, it will not slow down
|
|
||||||
other connections.
|
|
||||||
|
|
||||||
@@ -4,7 +4,7 @@ decl_name: "mg_event_handler_t"
|
|||||||
symbol_kind: "typedef"
|
symbol_kind: "typedef"
|
||||||
signature: |
|
signature: |
|
||||||
typedef void (*mg_event_handler_t)(struct mg_connection *nc, int ev,
|
typedef void (*mg_event_handler_t)(struct mg_connection *nc, int ev,
|
||||||
void *ev_data);
|
void *ev_data MG_UD_ARG(void *user_data));
|
||||||
---
|
---
|
||||||
|
|
||||||
Callback function (event handler) prototype. Must be defined by the user.
|
Callback function (event handler) prototype. Must be defined by the user.
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ title: "mg_next()"
|
|||||||
decl_name: "mg_next"
|
decl_name: "mg_next"
|
||||||
symbol_kind: "func"
|
symbol_kind: "func"
|
||||||
signature: |
|
signature: |
|
||||||
struct mg_connection *mg_next(struct mg_mgr *, struct mg_connection *);
|
struct mg_connection *mg_next(struct mg_mgr *mgr, struct mg_connection *c);
|
||||||
---
|
---
|
||||||
|
|
||||||
Iterates over all active connections.
|
Iterates over all active connections.
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ signature: |
|
|||||||
unsigned int flags; /* Extra connection flags */
|
unsigned int flags; /* Extra connection flags */
|
||||||
const char **error_string; /* Placeholder for the error string */
|
const char **error_string; /* Placeholder for the error string */
|
||||||
struct mg_iface *iface; /* Interface instance */
|
struct mg_iface *iface; /* Interface instance */
|
||||||
|
const char *nameserver; /* DNS server to use, NULL for default */
|
||||||
#if MG_ENABLE_SSL
|
#if MG_ENABLE_SSL
|
||||||
/*
|
/*
|
||||||
* SSL settings.
|
* SSL settings.
|
||||||
@@ -44,6 +45,15 @@ signature: |
|
|||||||
* name verification.
|
* name verification.
|
||||||
*/
|
*/
|
||||||
const char *ssl_server_name;
|
const char *ssl_server_name;
|
||||||
|
/*
|
||||||
|
* PSK identity and key. Identity is a NUL-terminated string and key is a hex
|
||||||
|
* string. Key must be either 16 or 32 bytes (32 or 64 hex digits) for AES-128
|
||||||
|
* or AES-256 respectively.
|
||||||
|
* Note: Default list of cipher suites does not include PSK suites, if you
|
||||||
|
* want to use PSK you will need to set ssl_cipher_suites as well.
|
||||||
|
*/
|
||||||
|
const char *ssl_psk_identity;
|
||||||
|
const char *ssl_psk_key;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
---
|
---
|
||||||
|
|||||||
@@ -31,8 +31,8 @@ signature: |
|
|||||||
* void pointers, since some archs might have fat pointers for functions.
|
* void pointers, since some archs might have fat pointers for functions.
|
||||||
*/
|
*/
|
||||||
mg_event_handler_t f;
|
mg_event_handler_t f;
|
||||||
} priv_1; /* Used by mg_enable_multithreading() */
|
} priv_1;
|
||||||
void *priv_2; /* Used by mg_enable_multithreading() */
|
void *priv_2;
|
||||||
void *mgr_data; /* Implementation-specific event manager's data. */
|
void *mgr_data; /* Implementation-specific event manager's data. */
|
||||||
struct mg_iface *iface;
|
struct mg_iface *iface;
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
|
|||||||
@@ -14,9 +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
|
|
||||||
};
|
};
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@@ -4,9 +4,10 @@ decl_name: "struct mg_mgr_init_opts"
|
|||||||
symbol_kind: "struct"
|
symbol_kind: "struct"
|
||||||
signature: |
|
signature: |
|
||||||
struct mg_mgr_init_opts {
|
struct mg_mgr_init_opts {
|
||||||
struct mg_iface_vtable *main_iface;
|
const struct mg_iface_vtable *main_iface;
|
||||||
int num_ifaces;
|
int num_ifaces;
|
||||||
struct mg_iface_vtable **ifaces;
|
const struct mg_iface_vtable **ifaces;
|
||||||
|
const char *nameserver;
|
||||||
};
|
};
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
---
|
|
||||||
title: "struct mg_multithreading_opts"
|
|
||||||
decl_name: "struct mg_multithreading_opts"
|
|
||||||
symbol_kind: "struct"
|
|
||||||
signature: |
|
|
||||||
struct mg_multithreading_opts {
|
|
||||||
int poll_timeout; /* Polling interval */
|
|
||||||
};
|
|
||||||
---
|
|
||||||
|
|
||||||
Optional parameters for mg_enable_multithreading_opt()
|
|
||||||
|
|
||||||
@@ -6,6 +6,7 @@ items:
|
|||||||
- { name: mg_resolve_async.md }
|
- { name: mg_resolve_async.md }
|
||||||
- { name: mg_resolve_async_opt.md }
|
- { name: mg_resolve_async_opt.md }
|
||||||
- { name: mg_resolve_from_hosts_file.md }
|
- { name: mg_resolve_from_hosts_file.md }
|
||||||
|
- { name: mg_set_nameserver.md }
|
||||||
- { name: struct_mg_resolve_async_opts.md }
|
- { name: struct_mg_resolve_async_opts.md }
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
---
|
||||||
|
title: "mg_set_nameserver()"
|
||||||
|
decl_name: "mg_set_nameserver"
|
||||||
|
symbol_kind: "func"
|
||||||
|
signature: |
|
||||||
|
void mg_set_nameserver(struct mg_mgr *mgr, const char *nameserver);
|
||||||
|
---
|
||||||
|
|
||||||
|
Set default DNS server
|
||||||
|
|
||||||
@@ -4,7 +4,7 @@ decl_name: "struct mg_resolve_async_opts"
|
|||||||
symbol_kind: "struct"
|
symbol_kind: "struct"
|
||||||
signature: |
|
signature: |
|
||||||
struct mg_resolve_async_opts {
|
struct mg_resolve_async_opts {
|
||||||
const char *nameserver_url;
|
const char *nameserver;
|
||||||
int max_retries; /* defaults to 2 if zero */
|
int max_retries; /* defaults to 2 if zero */
|
||||||
int timeout; /* in seconds; defaults to 5 if zero */
|
int timeout; /* in seconds; defaults to 5 if zero */
|
||||||
int accept_literal; /* pseudo-resolve literal ipv4 and ipv6 addrs */
|
int accept_literal; /* pseudo-resolve literal ipv4 and ipv6 addrs */
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ title: "URI"
|
|||||||
symbol_kind: "intro"
|
symbol_kind: "intro"
|
||||||
decl_name: "uri.h"
|
decl_name: "uri.h"
|
||||||
items:
|
items:
|
||||||
|
- { name: mg_assemble_uri.md }
|
||||||
- { name: mg_parse_uri.md }
|
- { name: mg_parse_uri.md }
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
---
|
||||||
|
title: "mg_assemble_uri()"
|
||||||
|
decl_name: "mg_assemble_uri"
|
||||||
|
symbol_kind: "func"
|
||||||
|
signature: |
|
||||||
|
int mg_assemble_uri(const struct mg_str *scheme, const struct mg_str *user_info,
|
||||||
|
const struct mg_str *host, unsigned int port,
|
||||||
|
const struct mg_str *path, const struct mg_str *query,
|
||||||
|
const struct mg_str *fragment, int normalize_path,
|
||||||
|
struct mg_str *uri);
|
||||||
|
---
|
||||||
|
|
||||||
|
Assemble URI from parts. Any of the inputs can be NULL or zero-length mg_str.
|
||||||
|
|
||||||
|
If normalize_path is true, path is normalized by resolving relative refs.
|
||||||
|
|
||||||
|
Result is a heap-allocated string (uri->p must be free()d after use).
|
||||||
|
|
||||||
|
Returns 0 on success, -1 on error.
|
||||||
|
|
||||||
@@ -3,7 +3,7 @@ title: "mg_parse_uri()"
|
|||||||
decl_name: "mg_parse_uri"
|
decl_name: "mg_parse_uri"
|
||||||
symbol_kind: "func"
|
symbol_kind: "func"
|
||||||
signature: |
|
signature: |
|
||||||
int mg_parse_uri(struct mg_str uri, struct mg_str *scheme,
|
int mg_parse_uri(const struct mg_str uri, struct mg_str *scheme,
|
||||||
struct mg_str *user_info, struct mg_str *host,
|
struct mg_str *user_info, struct mg_str *host,
|
||||||
unsigned int *port, struct mg_str *path, struct mg_str *query,
|
unsigned int *port, struct mg_str *path, struct mg_str *query,
|
||||||
struct mg_str *fragment);
|
struct mg_str *fragment);
|
||||||
|
|||||||
@@ -8,19 +8,21 @@ items:
|
|||||||
- { name: mg_basic_auth_header.md }
|
- { name: mg_basic_auth_header.md }
|
||||||
- { name: mg_conn_addr_to_str.md }
|
- { name: mg_conn_addr_to_str.md }
|
||||||
- { name: mg_fopen.md }
|
- { name: mg_fopen.md }
|
||||||
|
- { name: mg_fread.md }
|
||||||
|
- { name: mg_fwrite.md }
|
||||||
- { name: mg_hexdump.md }
|
- { name: mg_hexdump.md }
|
||||||
- { name: mg_hexdump_connection.md }
|
- { name: mg_hexdump_connection.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,7 +3,8 @@ title: "mg_basic_auth_header()"
|
|||||||
decl_name: "mg_basic_auth_header"
|
decl_name: "mg_basic_auth_header"
|
||||||
symbol_kind: "func"
|
symbol_kind: "func"
|
||||||
signature: |
|
signature: |
|
||||||
void mg_basic_auth_header(const char *user, const char *pass, struct mbuf *buf);
|
void mg_basic_auth_header(const struct mg_str user, const struct mg_str pass,
|
||||||
|
struct mbuf *buf);
|
||||||
---
|
---
|
||||||
|
|
||||||
Generate a Basic Auth header and appends it to buf.
|
Generate a Basic Auth header and appends it to buf.
|
||||||
|
|||||||
@@ -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.
|
||||||
@@ -18,4 +18,5 @@ see `MG_SOCK_STRINGIFY_*` definitions.
|
|||||||
|
|
||||||
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.
|
||||||
|
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
---
|
||||||
|
title: "mg_fread()"
|
||||||
|
decl_name: "mg_fread"
|
||||||
|
symbol_kind: "func"
|
||||||
|
signature: |
|
||||||
|
size_t mg_fread(void *ptr, size_t size, size_t count, FILE *f);
|
||||||
|
---
|
||||||
|
|
||||||
|
Reads data from the given file stream.
|
||||||
|
|
||||||
|
Return value is a number of bytes readen.
|
||||||
|
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
---
|
||||||
|
title: "mg_fwrite()"
|
||||||
|
decl_name: "mg_fwrite"
|
||||||
|
symbol_kind: "func"
|
||||||
|
signature: |
|
||||||
|
size_t mg_fwrite(const void *ptr, size_t size, size_t count, FILE *f);
|
||||||
|
---
|
||||||
|
|
||||||
|
Writes data to the given file stream.
|
||||||
|
|
||||||
|
Return value is a number of bytes wtitten.
|
||||||
|
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
---
|
||||||
|
title: "mg_hexdumpf()"
|
||||||
|
decl_name: "mg_hexdumpf"
|
||||||
|
symbol_kind: "func"
|
||||||
|
signature: |
|
||||||
|
void mg_hexdumpf(FILE *fp, const void *buf, int len);
|
||||||
|
---
|
||||||
|
|
||||||
|
Same as mg_hexdump, but with output going to file instead of a buffer.
|
||||||
|
|
||||||
@@ -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,5 +0,0 @@
|
|||||||
---
|
|
||||||
title: DNS client example
|
|
||||||
---
|
|
||||||
|
|
||||||
TBD
|
|
||||||
@@ -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/ }
|
|
||||||
---
|
|
||||||
@@ -2,4 +2,8 @@
|
|||||||
title: Overview
|
title: Overview
|
||||||
---
|
---
|
||||||
|
|
||||||
TBD
|
Mongoose uses non-blocking DNS resolver. For each name to be resolved,
|
||||||
|
it first checks the `/etc/hosts` file (or, `hosts` on Windows).
|
||||||
|
If the entry is not found there, then the `8.8.8.8` DNS server is queried.
|
||||||
|
When IP address is found, Mongoose proceeds with making the connection
|
||||||
|
with the resolved IP address.
|
||||||
+6
-4
@@ -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
|
||||||
@@ -29,3 +27,7 @@ Example:
|
|||||||
```c
|
```c
|
||||||
opts.cgi_interpreter = "C:\\ruby\\ruby.exe";
|
opts.cgi_interpreter = "C:\\ruby\\ruby.exe";
|
||||||
```
|
```
|
||||||
|
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.
|
||||||
|
It will cause zombie processes to be reaped automatically.
|
||||||
|
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:
|
||||||
|
|
||||||
@@ -18,8 +16,9 @@ static int exit_flag = 0;
|
|||||||
|
|
||||||
static void ev_handler(struct mg_connection *c, int ev, void *p) {
|
static void ev_handler(struct mg_connection *c, int ev, void *p) {
|
||||||
if (ev == MG_EV_HTTP_REPLY) {
|
if (ev == MG_EV_HTTP_REPLY) {
|
||||||
|
struct http_message *hm = (struct http_message *)p;
|
||||||
c->flags |= MG_F_CLOSE_IMMEDIATELY;
|
c->flags |= MG_F_CLOSE_IMMEDIATELY;
|
||||||
fwrite(hm->message.p, 1, hm->message.len, stdout);
|
fwrite(hm->message.p, 1, (int)hm->message.len, stdout);
|
||||||
putchar('\n');
|
putchar('\n');
|
||||||
exit_flag = 1;
|
exit_flag = 1;
|
||||||
} else if (ev == MG_EV_CLOSE) {
|
} else if (ev == MG_EV_CLOSE) {
|
||||||
@@ -31,7 +30,7 @@ int main(void) {
|
|||||||
struct mg_mgr mgr;
|
struct mg_mgr mgr;
|
||||||
|
|
||||||
mg_mgr_init(&mgr, NULL);
|
mg_mgr_init(&mgr, NULL);
|
||||||
mg_connect_http(mgr, ev_handler, url, NULL, NULL);
|
mg_connect_http(&mgr, ev_handler, url, NULL, NULL);
|
||||||
|
|
||||||
|
|
||||||
while (exit_flag == 0) {
|
while (exit_flag == 0) {
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
# Digest Authentication
|
||||||
|
|
||||||
|
Mongoose has a built-in Digest (MD5) authentication support. In order to
|
||||||
|
enable Digest authentication, create a file `.htpasswd` in the directory
|
||||||
|
you would like to protect. That file should be in the format that Apache's
|
||||||
|
`htdigest` utility.
|
||||||
|
|
||||||
|
You can use either Apache `htdigest` utility, or
|
||||||
|
Mongoose pre-build binary at https://www.cesanta.com/binary.html
|
||||||
|
to add new users into that file:
|
||||||
|
|
||||||
|
```
|
||||||
|
mongoose -A /path/to/.htdigest mydomain.com joe joes_password
|
||||||
|
```
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
---
|
|
||||||
title: Digest Authentication
|
|
||||||
---
|
|
||||||
|
|
||||||
TBD
|
|
||||||
+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:
|
||||||
|
|
||||||
@@ -30,8 +28,8 @@ static void ev_handler(struct mg_connection *c, int ev, void *p) {
|
|||||||
|
|
||||||
// We have received an HTTP request. Parsed request is contained in `hm`.
|
// We have received an HTTP request. Parsed request is contained in `hm`.
|
||||||
// Send HTTP reply to the client which shows full original request.
|
// Send HTTP reply to the client which shows full original request.
|
||||||
mg_send_head(c, 200, hm.message.len, "Content-Type: text/plain");
|
mg_send_head(c, 200, hm->message.len, "Content-Type: text/plain");
|
||||||
mg_printf(c, "%.*s", hm.message.len, hm.message.p);
|
mg_printf(c, "%.*s", (int)hm->message.len, hm->message.p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
+2
-4
@@ -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
|
||||||
@@ -35,7 +33,7 @@ The exec directive is used to execute a command on a server,
|
|||||||
and show command's output. Example: `<!--#exec "ls -l" -->`
|
and show command's output. Example: `<!--#exec "ls -l" -->`
|
||||||
|
|
||||||
The call directive is a way to invoke a C handler from the HTML page.
|
The call directive is a way to invoke a C handler from the HTML page.
|
||||||
On each occurence of `<!--#call PARAMS -->` directive,
|
On each occurrence of `<!--#call PARAMS -->` directive,
|
||||||
Mongoose calls a registered event handler with `MG_EV_SSI_CALL` event.
|
Mongoose calls a registered event handler with `MG_EV_SSI_CALL` event.
|
||||||
Event parameter will point to the `PARAMS` string.
|
Event parameter will point to the `PARAMS` string.
|
||||||
An event handler can output any text, for example by calling
|
An event handler can output any text, for example by calling
|
||||||
|
|||||||
+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
|
|
||||||
---
|
|
||||||
|
|
||||||
TBD
|
|
||||||
@@ -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
|
|
||||||
---
|
|
||||||
|
|
||||||
TBD
|
|
||||||
@@ -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
|
|
||||||
- `MG_DISABLE_SHA1` disable SHA1 support (used by WebSocket)
|
|
||||||
- `MG_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,11 +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.
|
|
||||||
@@ -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`
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
*.exe
|
|
||||||
@@ -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 \
|
||||||
|
|||||||
@@ -40,22 +40,22 @@ void cs_log_set_level(enum cs_log_level level);
|
|||||||
|
|
||||||
void cs_log_set_file(FILE *file);
|
void cs_log_set_file(FILE *file);
|
||||||
|
|
||||||
extern enum cs_log_level cs_log_level;
|
extern enum cs_log_level cs_log_threshold;
|
||||||
void cs_log_print_prefix(const char *func);
|
void cs_log_print_prefix(const char *func);
|
||||||
void cs_log_printf(const char *fmt, ...);
|
void cs_log_printf(const char *fmt, ...);
|
||||||
|
|
||||||
#define LOG(l, x) \
|
#define LOG(l, x) \
|
||||||
if (cs_log_level >= l) { \
|
if (cs_log_threshold >= l) { \
|
||||||
cs_log_print_prefix(__func__); \
|
cs_log_print_prefix(__func__); \
|
||||||
cs_log_printf x; \
|
cs_log_printf x; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef CS_NDEBUG
|
#ifndef CS_NDEBUG
|
||||||
|
|
||||||
#define DBG(x) \
|
#define DBG(x) \
|
||||||
if (cs_log_level >= LL_VERBOSE_DEBUG) { \
|
if (cs_log_threshold >= LL_VERBOSE_DEBUG) { \
|
||||||
cs_log_print_prefix(__func__); \
|
cs_log_print_prefix(__func__); \
|
||||||
cs_log_printf x; \
|
cs_log_printf x; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#else /* NDEBUG */
|
#else /* NDEBUG */
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
SDK_VER=$(shell cat sdk.version)
|
||||||
|
|
||||||
|
.PHONY: all
|
||||||
|
|
||||||
|
MG_PATH = $(realpath $(PWD)/../../)
|
||||||
|
|
||||||
|
all:
|
||||||
|
docker run --rm -it -v $(MG_PATH):/esp32_idf \
|
||||||
|
$(SDK_VER) \
|
||||||
|
bash -c "cd esp32_idf/examples/ESP32_IDF && \
|
||||||
|
make -f Makefile.build defconfig && make -f Makefile.build"
|
||||||
|
|
||||||
|
clean:
|
||||||
|
docker run --rm -it -v $(MG_PATH):/esp32_idf \
|
||||||
|
$(SDK_VER) \
|
||||||
|
bash -c "rm -rf esp32_idf/examples/ESP32_IDF/build"
|
||||||
Loaded 100 of 154 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user