mirror of
https://github.com/cesanta/mongoose.git
synced 2026-10-26 12:14:56 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0a8f839281 | ||
|
|
ab48174bac | ||
|
|
4439251f17 | ||
|
|
f9a6403b11 | ||
|
|
786f46c655 | ||
|
|
5ebd9fe7a5 | ||
|
|
2302ae5e88 | ||
|
|
8b12263dbc | ||
|
|
376d2666a5 | ||
|
|
d90622630f | ||
|
|
da447b1067 | ||
|
|
460d95afc5 | ||
|
|
8f522048d8 | ||
|
|
147c095105 | ||
|
|
fecb11f2fa | ||
|
|
56e50c2dbe | ||
|
|
c1b5e9b260 | ||
|
|
286fa90ee9 | ||
|
|
d63fb70c69 | ||
|
|
4d76a3be4c | ||
|
|
d9c612ef2b | ||
|
|
3b3ca1c1b3 | ||
|
|
2e748fdbf1 | ||
|
|
6c99691d1c | ||
|
|
fd067c8077 | ||
|
|
04012760d1 | ||
|
|
0ec1a141f1 | ||
|
|
7414a4fb06 | ||
|
|
abbd44e276 | ||
|
|
13e80e6bd5 | ||
|
|
ffa981d172 | ||
|
|
806f07db67 | ||
|
|
6746933a3d | ||
|
|
8cb2833fa7 | ||
|
|
1730f3c0c9 | ||
|
|
d6dda04f4f | ||
|
|
1b0825ef4b | ||
|
|
7249b2bd5f | ||
|
|
238bf1a29e | ||
|
|
4cbf81da59 | ||
|
|
d9b7ec18e7 | ||
|
|
ffed9c4d8c | ||
|
|
0dc0c5a0e0 | ||
|
|
57f826ece1 | ||
|
|
729bdebc50 | ||
|
|
2a541175b5 | ||
|
|
5f93f7162f | ||
|
|
3640554503 | ||
|
|
12437fd7fe | ||
|
|
4120f953c7 | ||
|
|
844c7787f9 | ||
|
|
0fe9ec1499 | ||
|
|
b3fb21dacc | ||
|
|
2deaf084e4 | ||
|
|
1b324510cc | ||
|
|
fd839f1827 | ||
|
|
f149f4aab1 | ||
|
|
af6fc64ab9 | ||
|
|
ff159bf30a | ||
|
|
8cdd19bcae | ||
|
|
2efc859829 | ||
|
|
d4a8351464 | ||
|
|
5fa544fc78 | ||
|
|
1070dd2d87 | ||
|
|
af98854ce4 | ||
|
|
7cace648c0 | ||
|
|
447bf4adb0 | ||
|
|
6572c1c692 | ||
|
|
7b48859f8d | ||
|
|
a6230bafe7 | ||
|
|
cc8f1466c7 | ||
|
|
69f810febc | ||
|
|
e5da7440d7 | ||
|
|
849ec1684a | ||
|
|
4f210cd8eb | ||
|
|
285f75764c | ||
|
|
3586203753 | ||
|
|
e406de7e00 | ||
|
|
53ed8502c9 | ||
|
|
ac8c756879 | ||
|
|
07faacdaf9 | ||
|
|
8464844518 | ||
|
|
fe2d1ff027 | ||
|
|
8d129e359e | ||
|
|
39aa56457b | ||
|
|
8491d5da8b | ||
|
|
681196e2c8 | ||
|
|
836ad5ebab | ||
|
|
a3ea1eddfb | ||
|
|
a2c06ac6ba | ||
|
|
a5c697fa2d | ||
|
|
be199b4fe9 | ||
|
|
cc15320cfe | ||
|
|
70bae59ec6 | ||
|
|
d4f3361805 | ||
|
|
332c855d40 | ||
|
|
01e3fa4d13 | ||
|
|
15a0f7a00a | ||
|
|
a751adba2a | ||
|
|
10eed010df | ||
|
|
033ca26216 | ||
|
|
40793cbdce | ||
|
|
48a1b2ec75 | ||
|
|
1a55556c66 | ||
|
|
3edd3ccbe6 | ||
|
|
194933e037 | ||
|
|
38deaedaef | ||
|
|
fc3dd5900c | ||
|
|
b1213425d0 | ||
|
|
40f0b450a8 | ||
|
|
0bab3977a8 | ||
|
|
2c46760b77 | ||
|
|
878c9ae5ae | ||
|
|
c8553de09e | ||
|
|
6738858e11 | ||
|
|
61cd6ab86e | ||
|
|
77704b669a | ||
|
|
770be613d7 | ||
|
|
9790366449 | ||
|
|
89f0a8c530 | ||
|
|
f72a06e25a | ||
|
|
8b975533e5 | ||
|
|
b32f7a9b57 | ||
|
|
e1e0083897 | ||
|
|
ca08ac0e3c | ||
|
|
a5b85b4462 | ||
|
|
3feab3a16d | ||
|
|
5d76e57b81 | ||
|
|
9101cd0339 | ||
|
|
4b2d3f5f5b | ||
|
|
482a471abb | ||
|
|
4d90bb0d02 | ||
|
|
202dfc18be | ||
|
|
13f4742699 | ||
|
|
33e769bd75 | ||
|
|
992f3000ef | ||
|
|
7ea4adae5e | ||
|
|
5ed9991135 | ||
|
|
dc2527c11f | ||
|
|
bee95654f3 | ||
|
|
48296bb1cf | ||
|
|
1ee9735354 | ||
|
|
f8da303ca1 | ||
|
|
6ae6ee9fd2 | ||
|
|
a11eafc5b3 | ||
|
|
efe53b57e4 | ||
|
|
e2330944d4 | ||
|
|
1c18906db7 | ||
|
|
873ceb48bd | ||
|
|
a48b955d89 | ||
|
|
b92fae2bfb | ||
|
|
156be17191 | ||
|
|
92290cfe81 | ||
|
|
29725c97f1 | ||
|
|
56b9cd14cb | ||
|
|
3550cc8f48 | ||
|
|
6a3d01ee6b | ||
|
|
27986213aa | ||
|
|
a2d07ef983 | ||
|
|
3cf4e32d9f | ||
|
|
a54584b716 | ||
|
|
51907e2642 | ||
|
|
5dd9d37ef2 | ||
|
|
f900854e0d | ||
|
|
d20e94f763 | ||
|
|
58de2ad2d7 | ||
|
|
f30c7b75d0 | ||
|
|
c5b8e55e12 | ||
|
|
559874fce7 | ||
|
|
1875653b34 | ||
|
|
6df770e72d | ||
|
|
51d415c8dd | ||
|
|
63bf428c34 | ||
|
|
a5d2772082 | ||
|
|
43c317ef4c | ||
|
|
01ffdb69d0 | ||
|
|
a78f346ac6 | ||
|
|
4ae88c859e | ||
|
|
e8a97f12d7 | ||
|
|
06aabdefbe | ||
|
|
15643f8e67 | ||
|
|
b987df1974 | ||
|
|
cbe63d43df | ||
|
|
e91a7c9599 | ||
|
|
3054952a5e | ||
|
|
3244df9cd1 | ||
|
|
1f75081f6e | ||
|
|
2c83a50a8a | ||
|
|
1c80fc28ee | ||
|
|
810eab9a58 | ||
|
|
256aa0296d | ||
|
|
2eb506c5e0 | ||
|
|
9f78a2902b | ||
|
|
613ae4ee34 | ||
|
|
ab208b71c4 | ||
|
|
68dd8d277d |
No files matched your search
@@ -73,4 +73,8 @@ To submit contributions, sign
|
|||||||
[Cesanta CLA](https://docs.cesanta.com/contributors_la.shtml)
|
[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.
|
||||||
|
|
||||||
|
## Working with the Source Code
|
||||||
|
|
||||||
|
See [tools](https://github.com/cesanta/mongoose/tree/master/tools) directory.
|
||||||
|
|
||||||
[](https://github.com/cesanta/mongoose)
|
[](https://github.com/cesanta/mongoose)
|
||||||
+10
-10
@@ -1,17 +1,17 @@
|
|||||||
---
|
---
|
||||||
title: "CoAP"
|
title: "CoAP API reference"
|
||||||
symbol_kind: "intro"
|
symbol_kind: "intro"
|
||||||
decl_name: "coap.h"
|
decl_name: "coap.h"
|
||||||
items:
|
items:
|
||||||
- { type: file, name: mg_set_protocol_coap.md }
|
- { name: mg_set_protocol_coap.md }
|
||||||
- { type: file, name: mg_coap_add_option.md }
|
- { name: mg_coap_add_option.md }
|
||||||
- { type: file, name: mg_coap_free_options.md }
|
- { name: mg_coap_free_options.md }
|
||||||
- { type: file, name: mg_coap_send_message.md }
|
- { name: mg_coap_send_message.md }
|
||||||
- { type: file, name: mg_coap_send_ack.md }
|
- { name: mg_coap_send_ack.md }
|
||||||
- { type: file, name: mg_coap_parse.md }
|
- { name: mg_coap_parse.md }
|
||||||
- { type: file, name: mg_coap_compose.md }
|
- { name: mg_coap_compose.md }
|
||||||
- { type: file, name: struct_mg_coap_option.md }
|
- { name: struct_mg_coap_option.md }
|
||||||
- { type: file, name: struct_mg_coap_message.md }
|
- { name: struct_mg_coap_message.md }
|
||||||
---
|
---
|
||||||
|
|
||||||
CoAP message format:
|
CoAP message format:
|
||||||
|
|||||||
@@ -8,6 +8,6 @@ signature: |
|
|||||||
size_t len);
|
size_t len);
|
||||||
---
|
---
|
||||||
|
|
||||||
Add new option to mg_coap_message structure.
|
Adds a new option to mg_coap_message structure.
|
||||||
Returns pointer to the newly created option.
|
Returns pointer to the newly created option.
|
||||||
|
|
||||||
@@ -6,6 +6,6 @@ signature: |
|
|||||||
void mg_coap_free_options(struct mg_coap_message *cm);
|
void mg_coap_free_options(struct mg_coap_message *cm);
|
||||||
---
|
---
|
||||||
|
|
||||||
Free the memory allocated for options,
|
Frees the memory allocated for options.
|
||||||
if cm paramater doesn't contain any option does nothing.
|
If the cm paramater doesn't contain any option it does nothing.
|
||||||
|
|
||||||
@@ -6,13 +6,13 @@ signature: |
|
|||||||
uint32_t mg_coap_parse(struct mbuf *io, struct mg_coap_message *cm);
|
uint32_t mg_coap_parse(struct mbuf *io, struct mg_coap_message *cm);
|
||||||
---
|
---
|
||||||
|
|
||||||
Parse COAP message and fills mg_coap_message and returns cm->flags.
|
Parses CoAP message and fills mg_coap_message and returns cm->flags.
|
||||||
This is a helper function.
|
This is a helper function.
|
||||||
|
|
||||||
NOTE: usually CoAP work over UDP, so lack of data means format error,
|
NOTE: usually CoAP works over UDP, so lack of data means format error.
|
||||||
but in theory it is possible to use CoAP over TCP (according to RFC)
|
But, in theory, it is possible to use CoAP over TCP (according to RFC)
|
||||||
|
|
||||||
The caller have to check results and treat COAP_NOT_ENOUGH_DATA according to
|
The caller has to check results and treat COAP_NOT_ENOUGH_DATA according to
|
||||||
underlying protocol:
|
underlying protocol:
|
||||||
|
|
||||||
- in case of UDP COAP_NOT_ENOUGH_DATA means COAP_FORMAT_ERROR,
|
- in case of UDP COAP_NOT_ENOUGH_DATA means COAP_FORMAT_ERROR,
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ signature: |
|
|||||||
uint32_t mg_coap_send_ack(struct mg_connection *nc, uint16_t msg_id);
|
uint32_t mg_coap_send_ack(struct mg_connection *nc, uint16_t msg_id);
|
||||||
---
|
---
|
||||||
|
|
||||||
Compose CoAP acknowledgement from `mg_coap_message`
|
Composes CoAP acknowledgement from `mg_coap_message`
|
||||||
and send it into `nc` connection.
|
and sends it into `nc` connection.
|
||||||
Return value: see `mg_coap_send_message()`
|
Return value: see `mg_coap_send_message()`
|
||||||
|
|
||||||
@@ -7,9 +7,9 @@ signature: |
|
|||||||
struct mg_coap_message *cm);
|
struct mg_coap_message *cm);
|
||||||
---
|
---
|
||||||
|
|
||||||
Compose CoAP message from `mg_coap_message`
|
Composes a CoAP message from `mg_coap_message`
|
||||||
and send it into `nc` connection.
|
and sends it into `nc` connection.
|
||||||
Return 0 on success. On error, it is a bitmask:
|
Returns 0 on success. On error, it is a bitmask:
|
||||||
|
|
||||||
- `#define MG_COAP_ERROR 0x10000`
|
- `#define MG_COAP_ERROR 0x10000`
|
||||||
- `#define MG_COAP_FORMAT_ERROR (MG_COAP_ERROR | 0x20000)`
|
- `#define MG_COAP_FORMAT_ERROR (MG_COAP_ERROR | 0x20000)`
|
||||||
|
|||||||
@@ -6,5 +6,5 @@ signature: |
|
|||||||
int mg_set_protocol_coap(struct mg_connection *nc);
|
int mg_set_protocol_coap(struct mg_connection *nc);
|
||||||
---
|
---
|
||||||
|
|
||||||
Set CoAP protocol handler - trigger CoAP specific events
|
Sets CoAP protocol handler - triggers CoAP specific events.
|
||||||
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
---
|
|
||||||
title: "DNS server"
|
|
||||||
symbol_kind: "intro"
|
|
||||||
decl_name: "dns-server.h"
|
|
||||||
items:
|
|
||||||
- { type: file, name: mg_dns_create_reply.md }
|
|
||||||
- { type: file, name: mg_dns_reply_record.md }
|
|
||||||
- { type: file, name: mg_dns_send_reply.md }
|
|
||||||
---
|
|
||||||
|
|
||||||
Disabled by default; enable with `-DMG_ENABLE_DNS_SERVER`.
|
|
||||||
|
|
||||||
+12
-11
@@ -1,18 +1,19 @@
|
|||||||
---
|
---
|
||||||
title: "DNS"
|
title: "DNS API reference"
|
||||||
symbol_kind: "intro"
|
symbol_kind: "intro"
|
||||||
decl_name: "dns.h"
|
decl_name: "dns.h"
|
||||||
items:
|
items:
|
||||||
- { type: file, name: mg_dns_parse_record_data.md }
|
- { name: mg_dns_parse_record_data.md }
|
||||||
- { type: file, name: mg_send_dns_query.md }
|
- { name: mg_send_dns_query.md }
|
||||||
- { type: file, name: mg_dns_insert_header.md }
|
- { name: mg_dns_insert_header.md }
|
||||||
- { type: file, name: mg_dns_copy_questions.md }
|
- { name: mg_dns_copy_questions.md }
|
||||||
- { type: file, name: mg_dns_encode_record.md }
|
- { name: mg_dns_encode_record.md }
|
||||||
- { type: file, name: mg_parse_dns.md }
|
- { name: mg_dns_encode_name.md }
|
||||||
- { type: file, name: mg_dns_uncompress_name.md }
|
- { name: mg_parse_dns.md }
|
||||||
- { type: file, name: mg_set_protocol_dns.md }
|
- { name: mg_dns_uncompress_name.md }
|
||||||
- { type: file, name: struct_mg_dns_resource_record.md }
|
- { name: mg_set_protocol_dns.md }
|
||||||
- { type: file, name: struct_mg_dns_message.md }
|
- { name: struct_mg_dns_resource_record.md }
|
||||||
|
- { name: struct_mg_dns_message.md }
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -6,10 +6,10 @@ signature: |
|
|||||||
int mg_dns_copy_questions(struct mbuf *io, struct mg_dns_message *msg);
|
int mg_dns_copy_questions(struct mbuf *io, struct mg_dns_message *msg);
|
||||||
---
|
---
|
||||||
|
|
||||||
Append already encoded questions from an existing message.
|
Appends already encoded questions from an existing message.
|
||||||
|
|
||||||
This is useful when generating a DNS reply message which includes
|
This is useful when generating a DNS reply message which includes
|
||||||
all question records.
|
all question records.
|
||||||
|
|
||||||
Return number of appened bytes.
|
Returns the number of appended bytes.
|
||||||
|
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
---
|
||||||
|
title: "mg_dns_encode_name()"
|
||||||
|
decl_name: "mg_dns_encode_name"
|
||||||
|
symbol_kind: "func"
|
||||||
|
signature: |
|
||||||
|
int mg_dns_encode_name(struct mbuf *io, const char *name, size_t len);
|
||||||
|
---
|
||||||
|
|
||||||
|
Encodes a DNS name.
|
||||||
|
|
||||||
@@ -8,18 +8,18 @@ signature: |
|
|||||||
size_t rlen);
|
size_t rlen);
|
||||||
---
|
---
|
||||||
|
|
||||||
Encode and append a DNS resource record to an IO buffer.
|
Encodes and appends a DNS resource record to an IO buffer.
|
||||||
|
|
||||||
The record metadata is taken from the `rr` parameter, while the name and data
|
The record metadata is taken from the `rr` parameter, while the name and data
|
||||||
are taken from the parameters, encoded in the appropriate format depending on
|
are taken from the parameters, encoded in the appropriate format depending on
|
||||||
record type, and stored in the IO buffer. The encoded values might contain
|
record type and stored in the IO buffer. The encoded values might contain
|
||||||
offsets within the IO buffer. It's thus important that the IO buffer doesn't
|
offsets within the IO buffer. It's thus important that the IO buffer doesn't
|
||||||
get trimmed while a sequence of records are encoded while preparing a DNS
|
get trimmed while a sequence of records are encoded while preparing a DNS
|
||||||
*reply.
|
reply.
|
||||||
|
|
||||||
This function doesn't update the `name` and `rdata` pointers in the `rr`
|
This function doesn't update the `name` and `rdata` pointers in the `rr`
|
||||||
*struct
|
struct because they might be invalidated as soon as the IO buffer grows
|
||||||
because they might be invalidated as soon as the IO buffer grows again.
|
again.
|
||||||
|
|
||||||
Return the number of bytes appened or -1 in case of error.
|
Returns the number of bytes appened or -1 in case of error.
|
||||||
|
|
||||||
@@ -7,7 +7,7 @@ signature: |
|
|||||||
struct mg_dns_message *msg);
|
struct mg_dns_message *msg);
|
||||||
---
|
---
|
||||||
|
|
||||||
Insert a DNS header to an IO buffer.
|
Inserts a DNS header to an IO buffer.
|
||||||
|
|
||||||
Return number of bytes inserted.
|
Returns the number of bytes inserted.
|
||||||
|
|
||||||
@@ -8,7 +8,7 @@ signature: |
|
|||||||
size_t data_len);
|
size_t data_len);
|
||||||
---
|
---
|
||||||
|
|
||||||
Parse the record data from a DNS resource record.
|
Parses the record data from a DNS resource record.
|
||||||
|
|
||||||
- A: struct in_addr *ina
|
- A: struct in_addr *ina
|
||||||
- AAAA: struct in6_addr *ina
|
- AAAA: struct in6_addr *ina
|
||||||
|
|||||||
@@ -7,15 +7,15 @@ signature: |
|
|||||||
char *dst, int dst_len);
|
char *dst, int dst_len);
|
||||||
---
|
---
|
||||||
|
|
||||||
Uncompress a DNS compressed name.
|
Uncompresses a DNS compressed name.
|
||||||
|
|
||||||
The containing dns message is required because the compressed encoding
|
The containing DNS message is required because of the compressed encoding
|
||||||
and reference suffixes present elsewhere in the packet.
|
and reference suffixes present elsewhere in the packet.
|
||||||
|
|
||||||
If name is less than `dst_len` characters long, the remainder
|
If the name is less than `dst_len` characters long, the remainder
|
||||||
of `dst` is terminated with `\0' characters. Otherwise, `dst` is not
|
of `dst` is terminated with `\0` characters. Otherwise, `dst` is not
|
||||||
*terminated.
|
terminated.
|
||||||
|
|
||||||
If `dst_len` is 0 `dst` can be NULL.
|
If `dst_len` is 0 `dst` can be NULL.
|
||||||
Return the uncompressed name length.
|
Returns the uncompressed name length.
|
||||||
|
|
||||||
@@ -7,5 +7,5 @@ signature: |
|
|||||||
int query_type);
|
int query_type);
|
||||||
---
|
---
|
||||||
|
|
||||||
Send a DNS query to the remote end.
|
Sends a DNS query to the remote end.
|
||||||
|
|
||||||
@@ -6,11 +6,11 @@ signature: |
|
|||||||
void mg_set_protocol_dns(struct mg_connection *nc);
|
void mg_set_protocol_dns(struct mg_connection *nc);
|
||||||
---
|
---
|
||||||
|
|
||||||
Attach built-in DNS event handler to the given listening connection.
|
Attaches a built-in DNS event handler to the given listening connection.
|
||||||
|
|
||||||
DNS event handler parses incoming UDP packets, treating them as DNS
|
The DNS event handler parses the incoming UDP packets, treating them as DNS
|
||||||
requests. If incoming packet gets successfully parsed by the DNS event
|
requests. If an incoming packet gets successfully parsed by the DNS event
|
||||||
handler, a user event handler will receive `MG_DNS_REQUEST` event, with
|
handler, a user event handler will receive an `MG_DNS_REQUEST` event, with
|
||||||
`ev_data` pointing to the parsed `struct mg_dns_message`.
|
`ev_data` pointing to the parsed `struct mg_dns_message`.
|
||||||
|
|
||||||
See
|
See
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
---
|
||||||
|
title: "DNS server API reference"
|
||||||
|
symbol_kind: "intro"
|
||||||
|
decl_name: "dns_server.h"
|
||||||
|
items:
|
||||||
|
- { name: mg_dns_create_reply.md }
|
||||||
|
- { name: mg_dns_reply_record.md }
|
||||||
|
- { name: mg_dns_send_reply.md }
|
||||||
|
---
|
||||||
|
|
||||||
|
Disabled by default; enable with `-DMG_ENABLE_DNS_SERVER`.
|
||||||
|
|
||||||
+4
-4
@@ -7,18 +7,18 @@ signature: |
|
|||||||
struct mg_dns_message *msg);
|
struct mg_dns_message *msg);
|
||||||
---
|
---
|
||||||
|
|
||||||
Create a DNS reply.
|
Creates a DNS reply.
|
||||||
|
|
||||||
The reply will be based on an existing query message `msg`.
|
The reply will be based on an existing query message `msg`.
|
||||||
The query body will be appended to the output buffer.
|
The query body will be appended to the output buffer.
|
||||||
"reply + recursion allowed" will be added to the message flags and
|
"reply + recursion allowed" will be added to the message flags and the
|
||||||
message's num_answers will be set to 0.
|
message's num_answers will be set to 0.
|
||||||
|
|
||||||
Answer records can be appended with `mg_dns_send_reply` or by lower
|
Answer records can be appended with `mg_dns_send_reply` or by lower
|
||||||
level function defined in the DNS API.
|
level function defined in the DNS API.
|
||||||
|
|
||||||
In order to send the reply use `mg_dns_send_reply`.
|
In order to send a reply use `mg_dns_send_reply`.
|
||||||
It's possible to use a connection's send buffer as reply buffers,
|
It's possible to use a connection's send buffer as reply buffer,
|
||||||
and it will work for both UDP and TCP connections.
|
and it will work for both UDP and TCP connections.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
+3
-3
@@ -9,10 +9,10 @@ signature: |
|
|||||||
size_t rdata_len);
|
size_t rdata_len);
|
||||||
---
|
---
|
||||||
|
|
||||||
Append a DNS reply record to the IO buffer and to the DNS message.
|
Appends a DNS reply record to the IO buffer and to the DNS message.
|
||||||
|
|
||||||
The message num_answers field will be incremented. It's caller's duty
|
The message's num_answers field will be incremented. It's the caller's duty
|
||||||
to ensure num_answers is propertly initialized.
|
to ensure num_answers is properly initialised.
|
||||||
|
|
||||||
Returns -1 on error.
|
Returns -1 on error.
|
||||||
|
|
||||||
+3
-3
@@ -6,12 +6,12 @@ signature: |
|
|||||||
void mg_dns_send_reply(struct mg_connection *nc, struct mg_dns_reply *r);
|
void mg_dns_send_reply(struct mg_connection *nc, struct mg_dns_reply *r);
|
||||||
---
|
---
|
||||||
|
|
||||||
Send a DNS reply through a connection.
|
Sends a DNS reply through a connection.
|
||||||
|
|
||||||
The DNS data is stored in an IO buffer pointed by reply structure in `r`.
|
The DNS data is stored in an IO buffer pointed by reply structure in `r`.
|
||||||
This function mutates the content of that buffer in order to ensure that
|
This function mutates the content of that buffer in order to ensure that
|
||||||
the DNS header reflects size and flags of the mssage, that might have been
|
the DNS header reflects the size and flags of the message, that might have
|
||||||
updated either with `mg_dns_reply_record` or by direct manipulation of
|
been updated either with `mg_dns_reply_record` or by direct manipulation of
|
||||||
`r->message`.
|
`r->message`.
|
||||||
|
|
||||||
Once sent, the IO buffer will be trimmed unless the reply IO buffer
|
Once sent, the IO buffer will be trimmed unless the reply IO buffer
|
||||||
+14
-32
@@ -1,39 +1,21 @@
|
|||||||
---
|
---
|
||||||
title: "HTTP + Websocket"
|
title: "Common API reference"
|
||||||
symbol_kind: "intro"
|
symbol_kind: "intro"
|
||||||
decl_name: "http.h"
|
decl_name: "http.h"
|
||||||
items:
|
items:
|
||||||
- { type: file, name: mg_set_protocol_http_websocket.md }
|
- { name: mg_set_protocol_http_websocket.md }
|
||||||
- { type: file, name: mg_send_websocket_handshake.md }
|
- { name: mg_send_websocket_handshake.md }
|
||||||
- { type: file, name: mg_send_websocket_handshake2.md }
|
- { name: mg_send_websocket_handshake2.md }
|
||||||
- { type: file, name: mg_connect_ws.md }
|
- { name: mg_connect_ws.md }
|
||||||
- { type: file, name: mg_connect_ws_opt.md }
|
- { name: mg_connect_ws_opt.md }
|
||||||
- { type: file, name: mg_send_websocket_frame.md }
|
- { name: mg_send_websocket_frame.md }
|
||||||
- { type: file, name: mg_send_websocket_framev.md }
|
- { name: mg_send_websocket_framev.md }
|
||||||
- { type: file, name: mg_printf_websocket_frame.md }
|
- { name: mg_printf_websocket_frame.md }
|
||||||
- { type: file, name: mg_send_http_chunk.md }
|
- { name: mg_url_decode.md }
|
||||||
- { type: file, name: mg_printf_http_chunk.md }
|
- { name: struct_http_message.md }
|
||||||
- { type: file, name: mg_send_response_line.md }
|
- { name: struct_websocket_message.md }
|
||||||
- { type: file, name: mg_send_head.md }
|
- { name: struct_mg_http_multipart_part.md }
|
||||||
- { type: file, name: mg_printf_html_escape.md }
|
- { name: struct_mg_ssi_call_ctx.md }
|
||||||
- { type: file, name: mg_parse_http.md }
|
|
||||||
- { type: file, name: mg_get_http_header.md }
|
|
||||||
- { type: file, name: mg_http_parse_header.md }
|
|
||||||
- { type: file, name: mg_parse_multipart.md }
|
|
||||||
- { type: file, name: mg_get_http_var.md }
|
|
||||||
- { type: file, name: mg_url_decode.md }
|
|
||||||
- { type: file, name: mg_http_create_digest_auth_header.md }
|
|
||||||
- { type: file, name: mg_connect_http.md }
|
|
||||||
- { type: file, name: mg_connect_http_opt.md }
|
|
||||||
- { type: file, name: mg_serve_http.md }
|
|
||||||
- { type: file, name: mg_register_http_endpoint.md }
|
|
||||||
- { type: file, name: mg_file_upload_handler.md }
|
|
||||||
- { type: file, name: mg_http_check_digest_auth.md }
|
|
||||||
- { type: file, name: mg_fu_fname_fn.md }
|
|
||||||
- { type: file, name: struct_http_message.md }
|
|
||||||
- { type: file, name: struct_websocket_message.md }
|
|
||||||
- { type: file, name: struct_mg_http_multipart_part.md }
|
|
||||||
- { type: file, name: struct_mg_serve_http_opts.md }
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ Helper function that creates an outbound WebSocket connection.
|
|||||||
|
|
||||||
`url` is a URL to connect to. It must be properly URL-encoded, e.g. have
|
`url` is a URL to connect to. It must be properly URL-encoded, e.g. have
|
||||||
no spaces, etc. By default, `mg_connect_ws()` sends Connection and
|
no spaces, etc. By default, `mg_connect_ws()` sends Connection and
|
||||||
Host headers. `extra_headers` is an extra HTTP headers to send, e.g.
|
Host headers. `extra_headers` is an extra HTTP header to send, e.g.
|
||||||
`"User-Agent: my-app\r\n"`.
|
`"User-Agent: my-app\r\n"`.
|
||||||
If `protocol` is not NULL, then a `Sec-WebSocket-Protocol` header is sent.
|
If `protocol` is not NULL, then a `Sec-WebSocket-Protocol` header is sent.
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,6 @@ signature: |
|
|||||||
|
|
||||||
Helper function that creates an outbound WebSocket connection
|
Helper function that creates an outbound WebSocket connection
|
||||||
|
|
||||||
Mostly identical to mg_connect_ws, but allows to provide extra parameters
|
Mostly identical to `mg_connect_ws`, but allows to provide extra parameters
|
||||||
(for example, SSL parameters
|
(for example, SSL parameters)
|
||||||
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
---
|
|
||||||
title: "mg_get_http_var()"
|
|
||||||
decl_name: "mg_get_http_var"
|
|
||||||
symbol_kind: "func"
|
|
||||||
signature: |
|
|
||||||
int mg_get_http_var(const struct mg_str *buf, const char *name, char *dst,
|
|
||||||
size_t dst_len);
|
|
||||||
---
|
|
||||||
|
|
||||||
Fetch an HTTP form variable.
|
|
||||||
|
|
||||||
Fetch a variable `name` from a `buf` into a buffer specified by
|
|
||||||
`dst`, `dst_len`. Destination is always zero-terminated. Return length
|
|
||||||
of a fetched variable. If not found, 0 is returned. `buf` must be
|
|
||||||
valid url-encoded buffer. If destination is too small, `-1` is returned.
|
|
||||||
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
---
|
|
||||||
title: "mg_parse_http()"
|
|
||||||
decl_name: "mg_parse_http"
|
|
||||||
symbol_kind: "func"
|
|
||||||
signature: |
|
|
||||||
int mg_parse_http(const char *s, int n, struct http_message *hm, int is_req);
|
|
||||||
---
|
|
||||||
|
|
||||||
Parse a HTTP message.
|
|
||||||
|
|
||||||
`is_req` should be set to 1 if parsing request, 0 if reply.
|
|
||||||
|
|
||||||
Return number of bytes parsed. If HTTP message is
|
|
||||||
incomplete, `0` is returned. On parse error, negative number is returned.
|
|
||||||
|
|
||||||
@@ -7,8 +7,8 @@ signature: |
|
|||||||
const char *fmt, ...);
|
const char *fmt, ...);
|
||||||
---
|
---
|
||||||
|
|
||||||
Send websocket frame to the remote end.
|
Sends WebSocket frame to the remote end.
|
||||||
|
|
||||||
Like `mg_send_websocket_frame()`, but allows to create formatted message
|
Like `mg_send_websocket_frame()`, but allows to create formatted messages
|
||||||
with `printf()`-like semantics.
|
with `printf()`-like semantics.
|
||||||
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
---
|
|
||||||
title: "mg_send_http_chunk()"
|
|
||||||
decl_name: "mg_send_http_chunk"
|
|
||||||
symbol_kind: "func"
|
|
||||||
signature: |
|
|
||||||
void mg_send_http_chunk(struct mg_connection *nc, const char *buf, size_t len);
|
|
||||||
---
|
|
||||||
|
|
||||||
Send buffer `buf` of size `len` to the client using chunked HTTP encoding.
|
|
||||||
This function first sends buffer size as hex number + newline, then
|
|
||||||
buffer itself, then newline. For example,
|
|
||||||
`mg_send_http_chunk(nc, "foo", 3)` whill append `3\r\nfoo\r\n` string to
|
|
||||||
the `nc->send_mbuf` output IO buffer.
|
|
||||||
|
|
||||||
NOTE: HTTP header "Transfer-Encoding: chunked" should be sent prior to
|
|
||||||
using this function.
|
|
||||||
|
|
||||||
NOTE: do not forget to send empty chunk at the end of the response,
|
|
||||||
to tell the client that everything was sent. Example:
|
|
||||||
|
|
||||||
```
|
|
||||||
mg_printf_http_chunk(nc, "%s", "my response!");
|
|
||||||
mg_send_http_chunk(nc, "", 0); // Tell the client we're finished
|
|
||||||
```
|
|
||||||
|
|
||||||
@@ -7,9 +7,9 @@ signature: |
|
|||||||
const void *data, size_t data_len);
|
const void *data, size_t data_len);
|
||||||
---
|
---
|
||||||
|
|
||||||
Send websocket frame to the remote end.
|
Send WebSocket frame to the remote end.
|
||||||
|
|
||||||
`op_and_flags` specifies frame's type, one of:
|
`op_and_flags` specifies the frame's type. It's one of:
|
||||||
|
|
||||||
- WEBSOCKET_OP_CONTINUE
|
- WEBSOCKET_OP_CONTINUE
|
||||||
- WEBSOCKET_OP_TEXT
|
- WEBSOCKET_OP_TEXT
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ signature: |
|
|||||||
const struct mg_str *strings, int num_strings);
|
const struct mg_str *strings, int num_strings);
|
||||||
---
|
---
|
||||||
|
|
||||||
Send 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.
|
||||||
|
|
||||||
@@ -6,40 +6,41 @@ signature: |
|
|||||||
void mg_set_protocol_http_websocket(struct mg_connection *nc);
|
void mg_set_protocol_http_websocket(struct mg_connection *nc);
|
||||||
---
|
---
|
||||||
|
|
||||||
Attach built-in HTTP event handler to the given connection.
|
Attaches a built-in HTTP event handler to the given connection.
|
||||||
User-defined event handler will receive following extra events:
|
The user-defined event handler will receive following extra events:
|
||||||
|
|
||||||
- MG_EV_HTTP_REQUEST: HTTP request has arrived. Parsed HTTP request
|
- MG_EV_HTTP_REQUEST: HTTP request has arrived. Parsed HTTP request
|
||||||
is passed as
|
is passed as
|
||||||
`struct http_message` through the handler's `void *ev_data` pointer.
|
`struct http_message` through the handler's `void *ev_data` pointer.
|
||||||
- MG_EV_HTTP_MULTIPART_REQUEST: A multipart POST request has received.
|
- MG_EV_HTTP_MULTIPART_REQUEST: A multipart POST request has received.
|
||||||
This event is sent before body is parsed. After this user
|
This event is sent before body is parsed. After this, the user
|
||||||
should expect a sequence of MG_EV_HTTP_PART_BEGIN/DATA/END requests.
|
should expect a sequence of MG_EV_HTTP_PART_BEGIN/DATA/END requests.
|
||||||
This is also the last time when headers and other request fields are
|
This is also the last time when headers and other request fields are
|
||||||
accessible.
|
accessible.
|
||||||
- MG_EV_HTTP_REPLY: HTTP reply has arrived. Parsed HTTP reply is passed as
|
- MG_EV_HTTP_REPLY: The HTTP reply has arrived. The parsed HTTP reply is
|
||||||
`struct http_message` through the handler's `void *ev_data` pointer.
|
passed as `struct http_message` through the handler's `void *ev_data`
|
||||||
- MG_EV_HTTP_CHUNK: HTTP chunked-encoding chunk has arrived.
|
pointer.
|
||||||
Parsed HTTP reply is passed as `struct http_message` through the
|
- MG_EV_HTTP_CHUNK: The HTTP chunked-encoding chunk has arrived.
|
||||||
|
The parsed HTTP reply is passed as `struct http_message` through the
|
||||||
handler's `void *ev_data` pointer. `http_message::body` would contain
|
handler's `void *ev_data` pointer. `http_message::body` would contain
|
||||||
incomplete, reassembled HTTP body.
|
incomplete, reassembled HTTP body.
|
||||||
It will grow with every new chunk arrived, and
|
It will grow with every new chunk that arrives, and it can
|
||||||
potentially can consume a lot of memory. An event handler may process
|
potentially consume a lot of memory. An event handler may process
|
||||||
the body as chunks are coming, and signal Mongoose to delete processed
|
the body as chunks are coming, and signal Mongoose to delete processed
|
||||||
body by setting `MG_F_DELETE_CHUNK` in `mg_connection::flags`. When
|
body by setting `MG_F_DELETE_CHUNK` in `mg_connection::flags`. When
|
||||||
the last zero chunk is received,
|
the last zero chunk is received,
|
||||||
Mongoose sends `MG_EV_HTTP_REPLY` event with
|
Mongoose sends `MG_EV_HTTP_REPLY` event with
|
||||||
full reassembled body (if handler did not signal to delete chunks) or
|
full reassembled body (if handler did not signal to delete chunks) or
|
||||||
with empty body (if handler did signal to delete chunks).
|
with empty body (if handler did signal to delete chunks).
|
||||||
- MG_EV_WEBSOCKET_HANDSHAKE_REQUEST: server has received websocket handshake
|
- MG_EV_WEBSOCKET_HANDSHAKE_REQUEST: server has received the WebSocket
|
||||||
request. `ev_data` contains parsed HTTP request.
|
handshake request. `ev_data` contains parsed HTTP request.
|
||||||
- MG_EV_WEBSOCKET_HANDSHAKE_DONE: server has completed Websocket handshake.
|
- MG_EV_WEBSOCKET_HANDSHAKE_DONE: server has completed the WebSocket
|
||||||
`ev_data` is `NULL`.
|
handshake. `ev_data` is `NULL`.
|
||||||
- MG_EV_WEBSOCKET_FRAME: new websocket frame has arrived. `ev_data` is
|
- MG_EV_WEBSOCKET_FRAME: new WebSocket frame has arrived. `ev_data` is
|
||||||
`struct websocket_message *`
|
`struct websocket_message *`
|
||||||
- MG_EV_HTTP_PART_BEGIN: new part of multipart message is started,
|
- MG_EV_HTTP_PART_BEGIN: new part of multipart message is started,
|
||||||
extra parameters are passed in mg_http_multipart_part
|
extra parameters are passed in mg_http_multipart_part
|
||||||
- MG_EV_HTTP_PART_DATA: new portion of data from multiparted message
|
- MG_EV_HTTP_PART_DATA: new portion of data from the multiparted message
|
||||||
no additional headers are available, only data and data size
|
no additional headers are available, only data and data size
|
||||||
- MG_EV_HTTP_PART_END: final boundary received, analogue to maybe used to
|
- MG_EV_HTTP_PART_END: final boundary received, analogue to maybe used to
|
||||||
find the end of packet
|
find the end of packet
|
||||||
|
|||||||
@@ -7,12 +7,12 @@ signature: |
|
|||||||
int is_form_url_encoded);
|
int is_form_url_encoded);
|
||||||
---
|
---
|
||||||
|
|
||||||
Decode URL-encoded string.
|
Decodes a URL-encoded string.
|
||||||
|
|
||||||
Source string is specified by (`src`, `src_len`), and destination is
|
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 `\0`-terminate the destination. If destination is too small,
|
guarantees to NUL-terminate the destination. If destination is too small,
|
||||||
then 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 decoded string is returned, not counting final `\0`.
|
a length of the decoded string is returned, not counting final NUL.
|
||||||
|
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
---
|
||||||
|
title: "struct mg_ssi_call_ctx"
|
||||||
|
decl_name: "struct mg_ssi_call_ctx"
|
||||||
|
symbol_kind: "struct"
|
||||||
|
signature: |
|
||||||
|
struct mg_ssi_call_ctx {
|
||||||
|
struct http_message *req; /* The request being processed. */
|
||||||
|
struct mg_str file; /* Filesystem path of the file being processed. */
|
||||||
|
struct mg_str arg; /* The argument passed to the tag: <!-- call arg -->. */
|
||||||
|
};
|
||||||
|
---
|
||||||
|
|
||||||
|
SSI call context
|
||||||
|
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
---
|
||||||
|
title: "Client API reference"
|
||||||
|
symbol_kind: "intro"
|
||||||
|
decl_name: "http_client.h"
|
||||||
|
items:
|
||||||
|
- { name: mg_connect_http.md }
|
||||||
|
- { name: mg_connect_http_opt.md }
|
||||||
|
- { name: mg_http_create_digest_auth_header.md }
|
||||||
|
---
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -10,16 +10,16 @@ signature: |
|
|||||||
const char *post_data);
|
const char *post_data);
|
||||||
---
|
---
|
||||||
|
|
||||||
Helper function that creates outbound HTTP connection.
|
Helper function that creates an outbound HTTP connection.
|
||||||
|
|
||||||
`url` is a URL to fetch. It must be properly URL-encoded, e.g. have
|
`url` is the URL to fetch. It must be properly URL-encoded, e.g. have
|
||||||
no spaces, etc. By default, `mg_connect_http()` sends Connection and
|
no spaces, etc. By default, `mg_connect_http()` sends the Connection and
|
||||||
Host headers. `extra_headers` is an extra HTTP headers to send, e.g.
|
Host headers. `extra_headers` is an extra HTTP header to send, e.g.
|
||||||
`"User-Agent: my-app\r\n"`.
|
`"User-Agent: my-app\r\n"`.
|
||||||
If `post_data` is NULL, then GET request is created. Otherwise, POST request
|
If `post_data` is NULL, then a GET request is created. Otherwise, a POST
|
||||||
is created with the specified POST data. Note that if the data being posted
|
request is created with the specified POST data. Note that if the data being
|
||||||
is a form submission, the `Content-Type` header should be set accordingly
|
posted is a form submission, the `Content-Type` header should be set
|
||||||
(see example below).
|
accordingly (see example below).
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
|
|
||||||
+4
-3
@@ -11,8 +11,9 @@ signature: |
|
|||||||
const char *post_data);
|
const char *post_data);
|
||||||
---
|
---
|
||||||
|
|
||||||
Helper function that creates outbound HTTP connection.
|
Helper function that creates an outbound HTTP connection.
|
||||||
|
|
||||||
Mostly identical to mg_connect_http, but allows to provide extra parameters
|
Mostly identical to mg_connect_http, but allows you to provide extra
|
||||||
(for example, SSL parameters
|
*parameters
|
||||||
|
(for example, SSL parameters)
|
||||||
|
|
||||||
+1
-1
@@ -9,5 +9,5 @@ signature: |
|
|||||||
const char *passwd);
|
const char *passwd);
|
||||||
---
|
---
|
||||||
|
|
||||||
Create Digest authentication header for client request.
|
Creates digest authentication header for a client request.
|
||||||
|
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
---
|
||||||
|
title: "Server API reference"
|
||||||
|
symbol_kind: "intro"
|
||||||
|
decl_name: "http_server.h"
|
||||||
|
items:
|
||||||
|
- { name: mg_parse_http.md }
|
||||||
|
- { name: mg_get_http_header.md }
|
||||||
|
- { name: mg_http_parse_header.md }
|
||||||
|
- { name: mg_parse_multipart.md }
|
||||||
|
- { name: mg_get_http_var.md }
|
||||||
|
- { name: mg_serve_http.md }
|
||||||
|
- { name: mg_http_serve_file.md }
|
||||||
|
- { name: mg_register_http_endpoint.md }
|
||||||
|
- { name: mg_file_upload_handler.md }
|
||||||
|
- { name: mg_http_check_digest_auth.md }
|
||||||
|
- { name: mg_send_http_chunk.md }
|
||||||
|
- { name: mg_printf_http_chunk.md }
|
||||||
|
- { name: mg_send_response_line.md }
|
||||||
|
- { name: mg_http_send_redirect.md }
|
||||||
|
- { name: mg_send_head.md }
|
||||||
|
- { name: mg_printf_html_escape.md }
|
||||||
|
- { name: mg_fu_fname_fn.md }
|
||||||
|
- { name: struct_mg_serve_http_opts.md }
|
||||||
|
---
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
+4
-3
@@ -12,9 +12,10 @@ This handler can be used to implement file uploads with minimum code.
|
|||||||
This handler will process MG_EV_HTTP_PART_* events and store file data into
|
This handler will process MG_EV_HTTP_PART_* events and store file data into
|
||||||
a local file.
|
a local file.
|
||||||
`local_name_fn` will be invoked with whatever name was provided by the client
|
`local_name_fn` will be invoked with whatever name was provided by the client
|
||||||
and will expect the name of the local file to open. Return value of NULL will
|
and will expect the name of the local file to open. A return value of NULL
|
||||||
abort file upload (client will get a "403 Forbidden" response). If non-null,
|
will abort file upload (client will get a "403 Forbidden" response). If
|
||||||
the returned string must be heap-allocated and will be freed by the caller.
|
non-null, the returned string must be heap-allocated and will be freed by
|
||||||
|
the caller.
|
||||||
Exception: it is ok to return the same string verbatim.
|
Exception: it is ok to return the same string verbatim.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
File renamed without changes.
+1
-1
@@ -6,7 +6,7 @@ signature: |
|
|||||||
struct mg_str *mg_get_http_header(struct http_message *hm, const char *name);
|
struct mg_str *mg_get_http_header(struct http_message *hm, const char *name);
|
||||||
---
|
---
|
||||||
|
|
||||||
Search and return header `name` in parsed HTTP message `hm`.
|
Searches and returns the header `name` in parsed HTTP message `hm`.
|
||||||
If header is not found, NULL is returned. Example:
|
If header is not found, NULL is returned. Example:
|
||||||
|
|
||||||
struct mg_str *host_hdr = mg_get_http_header(hm, "Host");
|
struct mg_str *host_hdr = mg_get_http_header(hm, "Host");
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
---
|
||||||
|
title: "mg_get_http_var()"
|
||||||
|
decl_name: "mg_get_http_var"
|
||||||
|
symbol_kind: "func"
|
||||||
|
signature: |
|
||||||
|
int mg_get_http_var(const struct mg_str *buf, const char *name, char *dst,
|
||||||
|
size_t dst_len);
|
||||||
|
---
|
||||||
|
|
||||||
|
Fetches a HTTP form variable.
|
||||||
|
|
||||||
|
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
|
||||||
|
a fetched variable. If not found, 0 is returned. `buf` must be valid
|
||||||
|
url-encoded buffer. If destination is too small, `-1` is returned.
|
||||||
|
|
||||||
+1
-1
@@ -7,6 +7,6 @@ signature: |
|
|||||||
FILE *fp);
|
FILE *fp);
|
||||||
---
|
---
|
||||||
|
|
||||||
Authenticate HTTP request against opened passwords file.
|
Authenticates a HTTP request against an opened password file.
|
||||||
Returns 1 if authenticated, 0 otherwise.
|
Returns 1 if authenticated, 0 otherwise.
|
||||||
|
|
||||||
+5
-5
@@ -7,17 +7,17 @@ signature: |
|
|||||||
size_t buf_size);
|
size_t buf_size);
|
||||||
---
|
---
|
||||||
|
|
||||||
Parse HTTP header `hdr`. Find variable `var_name` and store it's value
|
Parses the HTTP header `hdr`. Finds variable `var_name` and stores its value
|
||||||
in the buffer `buf`, `buf_size`. Return 0 if variable not found, non-zero
|
in the buffer `buf`, `buf_size`. Returns 0 if variable not found, non-zero
|
||||||
otherwise.
|
otherwise.
|
||||||
|
|
||||||
This function is supposed to parse
|
This function is supposed to parse cookies, authentication headers, etc.
|
||||||
cookies, authentication headers, etcetera. Example (error handling omitted):
|
Example (error handling omitted):
|
||||||
|
|
||||||
char user[20];
|
char user[20];
|
||||||
struct mg_str *hdr = mg_get_http_header(hm, "Authorization");
|
struct mg_str *hdr = mg_get_http_header(hm, "Authorization");
|
||||||
mg_http_parse_header(hdr, "username", user, sizeof(user));
|
mg_http_parse_header(hdr, "username", user, sizeof(user));
|
||||||
|
|
||||||
Return length of the variable's value. If buffer is not large enough,
|
Returns the length of the variable's value. If buffer is not large enough,
|
||||||
or variable not found, 0 is returned.
|
or variable not found, 0 is returned.
|
||||||
|
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
---
|
||||||
|
title: "mg_http_send_redirect()"
|
||||||
|
decl_name: "mg_http_send_redirect"
|
||||||
|
symbol_kind: "func"
|
||||||
|
signature: |
|
||||||
|
void mg_http_send_redirect(struct mg_connection *nc, int status_code,
|
||||||
|
const struct mg_str location,
|
||||||
|
const struct mg_str extra_headers);
|
||||||
|
---
|
||||||
|
|
||||||
|
Sends a redirect response.
|
||||||
|
`status_code` should be either 301 or 302 and `location` point to the
|
||||||
|
new location.
|
||||||
|
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.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
mg_http_send_redirect(nc, 302, mg_mk_str("/login"), mg_mk_str(NULL));
|
||||||
|
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
---
|
||||||
|
title: "mg_http_serve_file()"
|
||||||
|
decl_name: "mg_http_serve_file"
|
||||||
|
symbol_kind: "func"
|
||||||
|
signature: |
|
||||||
|
void mg_http_serve_file(struct mg_connection *nc, struct http_message *hm,
|
||||||
|
const char *path, const struct mg_str mime_type,
|
||||||
|
const struct mg_str extra_headers);
|
||||||
|
---
|
||||||
|
|
||||||
|
Serves a specific file with a given MIME type and optional extra headers.
|
||||||
|
|
||||||
|
Example code snippet:
|
||||||
|
|
||||||
|
```c
|
||||||
|
static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
|
||||||
|
switch (ev) {
|
||||||
|
case MG_EV_HTTP_REQUEST: {
|
||||||
|
struct http_message *hm = (struct http_message *) ev_data;
|
||||||
|
mg_http_serve_file(nc, hm, "file.txt",
|
||||||
|
mg_mk_str("text/plain"), mg_mk_str(""));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
...
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
---
|
||||||
|
title: "mg_parse_http()"
|
||||||
|
decl_name: "mg_parse_http"
|
||||||
|
symbol_kind: "func"
|
||||||
|
signature: |
|
||||||
|
int mg_parse_http(const char *s, int n, struct http_message *hm, int is_req);
|
||||||
|
---
|
||||||
|
|
||||||
|
Parses a HTTP message.
|
||||||
|
|
||||||
|
`is_req` should be set to 1 if parsing a request, 0 if reply.
|
||||||
|
|
||||||
|
Returns the number of bytes parsed. If HTTP message is
|
||||||
|
incomplete `0` is returned. On parse error, a negative number is returned.
|
||||||
|
|
||||||
+3
-3
@@ -9,13 +9,13 @@ signature: |
|
|||||||
size_t *chunk_len);
|
size_t *chunk_len);
|
||||||
---
|
---
|
||||||
|
|
||||||
Parse buffer `buf`, `buf_len` that contains multipart form data chunks.
|
Parses the buffer `buf`, `buf_len` that contains multipart form data chunks.
|
||||||
Store chunk name in a `var_name`, `var_name_len` buffer.
|
Stores the chunk name in a `var_name`, `var_name_len` buffer.
|
||||||
If a chunk is an uploaded file, then `file_name`, `file_name_len` is
|
If a chunk is an uploaded file, then `file_name`, `file_name_len` is
|
||||||
filled with an uploaded file name. `chunk`, `chunk_len`
|
filled with an uploaded file name. `chunk`, `chunk_len`
|
||||||
points to the chunk data.
|
points to the chunk data.
|
||||||
|
|
||||||
Return: number of bytes to skip to the next chunk, or 0 if there are
|
Return: number of bytes to skip to the next chunk or 0 if there are
|
||||||
no more chunks.
|
no more chunks.
|
||||||
|
|
||||||
Usage example:
|
Usage example:
|
||||||
+1
-1
@@ -6,5 +6,5 @@ signature: |
|
|||||||
void mg_printf_html_escape(struct mg_connection *nc, const char *fmt, ...);
|
void mg_printf_html_escape(struct mg_connection *nc, const char *fmt, ...);
|
||||||
---
|
---
|
||||||
|
|
||||||
Send printf-formatted HTTP chunk, escaping HTML tags.
|
Sends a printf-formatted HTTP chunk, escaping HTML tags.
|
||||||
|
|
||||||
+1
-1
@@ -6,6 +6,6 @@ signature: |
|
|||||||
void mg_printf_http_chunk(struct mg_connection *nc, const char *fmt, ...);
|
void mg_printf_http_chunk(struct mg_connection *nc, const char *fmt, ...);
|
||||||
---
|
---
|
||||||
|
|
||||||
Send printf-formatted HTTP chunk.
|
Sends a printf-formatted HTTP chunk.
|
||||||
Functionality is similar to `mg_send_http_chunk()`.
|
Functionality is similar to `mg_send_http_chunk()`.
|
||||||
|
|
||||||
+2
-2
@@ -7,8 +7,8 @@ signature: |
|
|||||||
mg_event_handler_t handler);
|
mg_event_handler_t handler);
|
||||||
---
|
---
|
||||||
|
|
||||||
Register callback for specified http endpoint
|
Registers a callback for a specified http endpoint
|
||||||
Note: if callback is registered it is called instead of
|
Note: if callback is registered it is called instead of the
|
||||||
callback provided in mg_bind
|
callback provided in mg_bind
|
||||||
|
|
||||||
Example code snippet:
|
Example code snippet:
|
||||||
@@ -7,15 +7,16 @@ signature: |
|
|||||||
int64_t content_length, const char *extra_headers);
|
int64_t content_length, const char *extra_headers);
|
||||||
---
|
---
|
||||||
|
|
||||||
Send response line and headers.
|
Sends the response line and headers.
|
||||||
This function sends response line with the `status_code`, and automatically
|
This function sends the response line with the `status_code`, and
|
||||||
sends one header: either "Content-Length", or "Transfer-Encoding".
|
automatically
|
||||||
|
sends one header: either "Content-Length" or "Transfer-Encoding".
|
||||||
If `content_length` is negative, then "Transfer-Encoding: chunked" header
|
If `content_length` is negative, then "Transfer-Encoding: chunked" header
|
||||||
is sent, otherwise, "Content-Length" header is sent.
|
is sent, otherwise, "Content-Length" header is sent.
|
||||||
|
|
||||||
NOTE: If `Transfer-Encoding` is `chunked`, then message body must be sent
|
NOTE: If `Transfer-Encoding` is `chunked`, then message body must be sent
|
||||||
using `mg_send_http_chunk()` or `mg_printf_http_chunk()` functions.
|
using `mg_send_http_chunk()` or `mg_printf_http_chunk()` functions.
|
||||||
Otherwise, `mg_send()` or `mg_printf()` must be used.
|
Otherwise, `mg_send()` or `mg_printf()` must be used.
|
||||||
Extra headers could be set through `extra_headers` - and note `extra_headers`
|
Extra headers could be set through `extra_headers`. Note `extra_headers`
|
||||||
must NOT be terminated by a new line.
|
must NOT be terminated by a new line.
|
||||||
|
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
---
|
||||||
|
title: "mg_send_http_chunk()"
|
||||||
|
decl_name: "mg_send_http_chunk"
|
||||||
|
symbol_kind: "func"
|
||||||
|
signature: |
|
||||||
|
void mg_send_http_chunk(struct mg_connection *nc, const char *buf, size_t len);
|
||||||
|
---
|
||||||
|
|
||||||
|
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
|
||||||
|
the buffer itself, then the newline. For example,
|
||||||
|
`mg_send_http_chunk(nc, "foo", 3)` whill append the `3\r\nfoo\r\n` string
|
||||||
|
to the `nc->send_mbuf` output IO buffer.
|
||||||
|
|
||||||
|
NOTE: The HTTP header "Transfer-Encoding: chunked" should be sent prior to
|
||||||
|
using this function.
|
||||||
|
|
||||||
|
NOTE: do not forget to send an empty chunk at the end of the response,
|
||||||
|
to tell the client that everything was sent. Example:
|
||||||
|
|
||||||
|
```
|
||||||
|
mg_printf_http_chunk(nc, "%s", "my response!");
|
||||||
|
mg_send_http_chunk(nc, "", 0); // Tell the client we're finished
|
||||||
|
```
|
||||||
|
|
||||||
+2
-2
@@ -3,11 +3,11 @@ title: "mg_send_response_line()"
|
|||||||
decl_name: "mg_send_response_line"
|
decl_name: "mg_send_response_line"
|
||||||
symbol_kind: "func"
|
symbol_kind: "func"
|
||||||
signature: |
|
signature: |
|
||||||
void mg_send_response_line(struct mg_connection *c, int status_code,
|
void mg_send_response_line(struct mg_connection *nc, int status_code,
|
||||||
const char *extra_headers);
|
const char *extra_headers);
|
||||||
---
|
---
|
||||||
|
|
||||||
Send 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 reponse line. `extra_headers` must NOT end end with new line.
|
||||||
Example:
|
Example:
|
||||||
@@ -7,7 +7,7 @@ signature: |
|
|||||||
struct mg_serve_http_opts opts);
|
struct mg_serve_http_opts opts);
|
||||||
---
|
---
|
||||||
|
|
||||||
Serve given HTTP request according to the `options`.
|
Serves given HTTP request according to the `options`.
|
||||||
|
|
||||||
Example code snippet:
|
Example code snippet:
|
||||||
|
|
||||||
+58
-1
@@ -37,7 +37,64 @@ signature: |
|
|||||||
/* Set to "no" to disable directory listing. Enabled by default. */
|
/* Set to "no" to disable directory listing. Enabled by default. */
|
||||||
const char *enable_directory_listing;
|
const char *enable_directory_listing;
|
||||||
|
|
||||||
/* SSI files pattern. If not set, "**.shtml$|**.shtm$" is used. */
|
/*
|
||||||
|
* SSI files pattern. If not set, "**.shtml$|**.shtm$" is used.
|
||||||
|
*
|
||||||
|
* All files that match ssi_pattern are treated as SSI.
|
||||||
|
*
|
||||||
|
* Server Side Includes (SSI) is a simple interpreted server-side scripting
|
||||||
|
* language which is most commonly used to include the contents of a file
|
||||||
|
* into a web page. It can be useful when it is desirable to include a common
|
||||||
|
* piece of code throughout a website, for example, headers and footers.
|
||||||
|
*
|
||||||
|
* In order for a webpage to recognize an SSI-enabled HTML file, the
|
||||||
|
* filename should end with a special extension, by default the extension
|
||||||
|
* should be either .shtml or .shtm
|
||||||
|
*
|
||||||
|
* Unknown SSI directives are silently ignored by Mongoose. Currently,
|
||||||
|
* the following SSI directives are supported:
|
||||||
|
* <!--#include FILE_TO_INCLUDE -->
|
||||||
|
* <!--#exec "COMMAND_TO_EXECUTE" -->
|
||||||
|
* <!--#call COMMAND -->
|
||||||
|
*
|
||||||
|
* Note that <!--#include ...> directive supports three path
|
||||||
|
*specifications:
|
||||||
|
*
|
||||||
|
* <!--#include virtual="path" --> Path is relative to web server root
|
||||||
|
* <!--#include abspath="path" --> Path is absolute or relative to the
|
||||||
|
* web server working dir
|
||||||
|
* <!--#include file="path" -->, Path is relative to current document
|
||||||
|
* <!--#include "path" -->
|
||||||
|
*
|
||||||
|
* The include directive may be used to include the contents of a file or
|
||||||
|
* the result of running a CGI script.
|
||||||
|
*
|
||||||
|
* The exec directive is used to execute
|
||||||
|
* a command on a server, and show command's output. Example:
|
||||||
|
*
|
||||||
|
* <!--#exec "ls -l" -->
|
||||||
|
*
|
||||||
|
* The call directive is a way to invoke a C handler from the HTML page.
|
||||||
|
* On each occurence of <!--#call COMMAND OPTIONAL_PARAMS> directive,
|
||||||
|
* Mongoose calls a registered event handler with MG_EV_SSI_CALL event,
|
||||||
|
* and event parameter will point to the COMMAND OPTIONAL_PARAMS string.
|
||||||
|
* An event handler can output any text, for example by calling
|
||||||
|
* `mg_printf()`. This is a flexible way of generating a web page on
|
||||||
|
* server side by calling a C event handler. Example:
|
||||||
|
*
|
||||||
|
* <!--#call foo --> ... <!--#call bar -->
|
||||||
|
*
|
||||||
|
* In the event handler:
|
||||||
|
* case MG_EV_SSI_CALL: {
|
||||||
|
* const char *param = (const char *) ev_data;
|
||||||
|
* if (strcmp(param, "foo") == 0) {
|
||||||
|
* mg_printf(c, "hello from foo");
|
||||||
|
* } else if (strcmp(param, "bar") == 0) {
|
||||||
|
* mg_printf(c, "hello from bar");
|
||||||
|
* }
|
||||||
|
* break;
|
||||||
|
* }
|
||||||
|
*/
|
||||||
const char *ssi_pattern;
|
const char *ssi_pattern;
|
||||||
|
|
||||||
/* IP ACL. By default, NULL, meaning all IPs are allowed to connect */
|
/* IP ACL. By default, NULL, meaning all IPs are allowed to connect */
|
||||||
+13
-9
@@ -1,12 +1,16 @@
|
|||||||
---
|
---
|
||||||
items:
|
items:
|
||||||
- { type: dir, name: mbuf.h }
|
- { name: mbuf.h }
|
||||||
- { type: dir, name: net.h }
|
- { name: net.h }
|
||||||
- { type: dir, name: http.h }
|
- { name: http.h }
|
||||||
- { type: dir, name: dns.h }
|
- { name: http_server.h }
|
||||||
- { type: dir, name: dns-server.h }
|
- { name: http_client.h }
|
||||||
- { type: dir, name: mqtt.h }
|
- { name: dns.h }
|
||||||
- { type: dir, name: mqtt-broker.h }
|
- { name: dns_server.h }
|
||||||
- { type: dir, name: coap.h }
|
- { name: resolv.h }
|
||||||
- { type: dir, name: util.h }
|
- { name: mqtt.h }
|
||||||
|
- { name: mqtt_server.h }
|
||||||
|
- { name: coap.h }
|
||||||
|
- { name: util.h }
|
||||||
|
- { name: uri.h }
|
||||||
---
|
---
|
||||||
@@ -3,18 +3,18 @@ title: "Memory Buffers"
|
|||||||
symbol_kind: "intro"
|
symbol_kind: "intro"
|
||||||
decl_name: "mbuf.h"
|
decl_name: "mbuf.h"
|
||||||
items:
|
items:
|
||||||
- { type: file, name: mbuf_init.md }
|
- { name: mbuf_init.md }
|
||||||
- { type: file, name: mbuf_free.md }
|
- { name: mbuf_free.md }
|
||||||
- { type: file, name: mbuf_append.md }
|
- { name: mbuf_append.md }
|
||||||
- { type: file, name: mbuf_insert.md }
|
- { name: mbuf_insert.md }
|
||||||
- { type: file, name: mbuf_remove.md }
|
- { name: mbuf_remove.md }
|
||||||
- { type: file, name: mbuf_resize.md }
|
- { name: mbuf_resize.md }
|
||||||
- { type: file, name: mbuf_trim.md }
|
- { name: mbuf_trim.md }
|
||||||
- { type: file, name: struct_mbuf.md }
|
- { name: struct_mbuf.md }
|
||||||
---
|
---
|
||||||
|
|
||||||
Mbufs are mutable/growing memory buffers, like C++ strings.
|
Mbufs are mutable/growing memory buffers, like C++ strings.
|
||||||
Mbuf can append data to the end of a buffer, or insert data into arbitrary
|
Mbuf can append data to the end of a buffer or insert data into arbitrary
|
||||||
position in the middle of a buffer. The buffer grows automatically when
|
position in the middle of a buffer. The buffer grows automatically when
|
||||||
needed.
|
needed.
|
||||||
|
|
||||||
@@ -8,5 +8,5 @@ signature: |
|
|||||||
|
|
||||||
Appends data to the Mbuf.
|
Appends data to the Mbuf.
|
||||||
|
|
||||||
Return the number of bytes appended, or 0 if out of memory.
|
Returns the number of bytes appended or 0 if out of memory.
|
||||||
|
|
||||||
@@ -6,5 +6,5 @@ signature: |
|
|||||||
void mbuf_free(struct mbuf *);
|
void mbuf_free(struct mbuf *);
|
||||||
---
|
---
|
||||||
|
|
||||||
Free the space allocated for the mbuffer and resets the mbuf structure.
|
Frees the space allocated for the mbuffer and resets the mbuf structure.
|
||||||
|
|
||||||
@@ -6,6 +6,6 @@ signature: |
|
|||||||
void mbuf_init(struct mbuf *, size_t initial_capacity);
|
void mbuf_init(struct mbuf *, size_t initial_capacity);
|
||||||
---
|
---
|
||||||
|
|
||||||
Initialize an Mbuf.
|
Initialises an Mbuf.
|
||||||
`initial_capacity` specifies the initial capacity of the mbuf.
|
`initial_capacity` specifies the initial capacity of the mbuf.
|
||||||
|
|
||||||
@@ -6,9 +6,9 @@ signature: |
|
|||||||
size_t mbuf_insert(struct mbuf *, size_t, const void *, size_t);
|
size_t mbuf_insert(struct mbuf *, size_t, const void *, size_t);
|
||||||
---
|
---
|
||||||
|
|
||||||
Insert data at a specified offset in the Mbuf.
|
Inserts data at a specified offset in the Mbuf.
|
||||||
|
|
||||||
Existing data will be shifted forwards and the buffer will
|
Existing data will be shifted forwards and the buffer will
|
||||||
be grown if necessary.
|
be grown if necessary.
|
||||||
Return the number of bytes inserted.
|
Returns the number of bytes inserted.
|
||||||
|
|
||||||
@@ -6,5 +6,5 @@ signature: |
|
|||||||
void mbuf_remove(struct mbuf *, size_t data_size);
|
void mbuf_remove(struct mbuf *, size_t data_size);
|
||||||
---
|
---
|
||||||
|
|
||||||
Remove `data_size` bytes from the beginning of the buffer.
|
Removes `data_size` bytes from the beginning of the buffer.
|
||||||
|
|
||||||
@@ -6,7 +6,7 @@ signature: |
|
|||||||
void mbuf_resize(struct mbuf *, size_t new_size);
|
void mbuf_resize(struct mbuf *, size_t new_size);
|
||||||
---
|
---
|
||||||
|
|
||||||
Resize an Mbuf.
|
Resizes an Mbuf.
|
||||||
|
|
||||||
If `new_size` is smaller than buffer's `len`, the
|
If `new_size` is smaller than buffer's `len`, the
|
||||||
resize is not performed.
|
resize is not performed.
|
||||||
|
|||||||
@@ -6,5 +6,5 @@ signature: |
|
|||||||
void mbuf_trim(struct mbuf *);
|
void mbuf_trim(struct mbuf *);
|
||||||
---
|
---
|
||||||
|
|
||||||
Shrink an Mbuf by resizing its `size` to `len`.
|
Shrinks an Mbuf by resizing its `size` to `len`.
|
||||||
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
---
|
|
||||||
title: "MQTT Broker"
|
|
||||||
symbol_kind: "intro"
|
|
||||||
decl_name: "mqtt-broker.h"
|
|
||||||
items:
|
|
||||||
- { type: file, name: mg_mqtt_broker_init.md }
|
|
||||||
- { type: file, name: mg_mqtt_broker.md }
|
|
||||||
- { type: file, name: mg_mqtt_next.md }
|
|
||||||
- { type: file, name: struct_mg_mqtt_session.md }
|
|
||||||
- { type: file, name: struct_mg_mqtt_broker.md }
|
|
||||||
---
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
+19
-19
@@ -1,26 +1,26 @@
|
|||||||
---
|
---
|
||||||
title: "MQTT"
|
title: "MQTT API reference"
|
||||||
symbol_kind: "intro"
|
symbol_kind: "intro"
|
||||||
decl_name: "mqtt.h"
|
decl_name: "mqtt.h"
|
||||||
items:
|
items:
|
||||||
- { type: file, name: mg_set_protocol_mqtt.md }
|
- { name: mg_set_protocol_mqtt.md }
|
||||||
- { type: file, name: mg_send_mqtt_handshake.md }
|
- { name: mg_send_mqtt_handshake.md }
|
||||||
- { type: file, name: mg_send_mqtt_handshake_opt.md }
|
- { name: mg_send_mqtt_handshake_opt.md }
|
||||||
- { type: file, name: mg_mqtt_publish.md }
|
- { name: mg_mqtt_publish.md }
|
||||||
- { type: file, name: mg_mqtt_subscribe.md }
|
- { name: mg_mqtt_subscribe.md }
|
||||||
- { type: file, name: mg_mqtt_unsubscribe.md }
|
- { name: mg_mqtt_unsubscribe.md }
|
||||||
- { type: file, name: mg_mqtt_disconnect.md }
|
- { name: mg_mqtt_disconnect.md }
|
||||||
- { type: file, name: mg_mqtt_connack.md }
|
- { name: mg_mqtt_connack.md }
|
||||||
- { type: file, name: mg_mqtt_puback.md }
|
- { name: mg_mqtt_puback.md }
|
||||||
- { type: file, name: mg_mqtt_pubrec.md }
|
- { name: mg_mqtt_pubrec.md }
|
||||||
- { type: file, name: mg_mqtt_pubrel.md }
|
- { name: mg_mqtt_pubrel.md }
|
||||||
- { type: file, name: mg_mqtt_pubcomp.md }
|
- { name: mg_mqtt_pubcomp.md }
|
||||||
- { type: file, name: mg_mqtt_suback.md }
|
- { name: mg_mqtt_suback.md }
|
||||||
- { type: file, name: mg_mqtt_unsuback.md }
|
- { name: mg_mqtt_unsuback.md }
|
||||||
- { type: file, name: mg_mqtt_ping.md }
|
- { name: mg_mqtt_ping.md }
|
||||||
- { type: file, name: mg_mqtt_pong.md }
|
- { name: mg_mqtt_pong.md }
|
||||||
- { type: file, name: mg_mqtt_next_subscribe_topic.md }
|
- { name: mg_mqtt_next_subscribe_topic.md }
|
||||||
- { type: file, name: struct_mg_mqtt_topic_expression.md }
|
- { name: struct_mg_mqtt_topic_expression.md }
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -6,5 +6,5 @@ signature: |
|
|||||||
void mg_mqtt_connack(struct mg_connection *nc, uint8_t return_code);
|
void mg_mqtt_connack(struct mg_connection *nc, uint8_t return_code);
|
||||||
---
|
---
|
||||||
|
|
||||||
Send a CONNACK command with a given `return_code`.
|
Sends a CONNACK command with a given `return_code`.
|
||||||
|
|
||||||
@@ -6,5 +6,5 @@ signature: |
|
|||||||
void mg_mqtt_disconnect(struct mg_connection *nc);
|
void mg_mqtt_disconnect(struct mg_connection *nc);
|
||||||
---
|
---
|
||||||
|
|
||||||
Send a DISCONNECT command.
|
Sends a DISCONNECT command.
|
||||||
|
|
||||||
@@ -7,9 +7,9 @@ signature: |
|
|||||||
struct mg_str *topic, uint8_t *qos, int pos);
|
struct mg_str *topic, uint8_t *qos, int pos);
|
||||||
---
|
---
|
||||||
|
|
||||||
Extract the next topic expression from a SUBSCRIBE command payload.
|
Extracts the next topic expression from a SUBSCRIBE command payload.
|
||||||
|
|
||||||
Topic expression name will point to a string in the payload buffer.
|
The topic expression name will point to a string in the payload buffer.
|
||||||
Return the pos of the next topic expression or -1 when the list
|
Returns the pos of the next topic expression or -1 when the list
|
||||||
of topics is exhausted.
|
of topics is exhausted.
|
||||||
|
|
||||||
@@ -6,5 +6,5 @@ signature: |
|
|||||||
void mg_mqtt_ping(struct mg_connection *nc);
|
void mg_mqtt_ping(struct mg_connection *nc);
|
||||||
---
|
---
|
||||||
|
|
||||||
Send a PINGREQ command.
|
Sends a PINGREQ command.
|
||||||
|
|
||||||
@@ -6,5 +6,5 @@ signature: |
|
|||||||
void mg_mqtt_pong(struct mg_connection *nc);
|
void mg_mqtt_pong(struct mg_connection *nc);
|
||||||
---
|
---
|
||||||
|
|
||||||
Send a PINGRESP command.
|
Sends a PINGRESP command.
|
||||||
|
|
||||||
@@ -6,5 +6,5 @@ signature: |
|
|||||||
void mg_mqtt_puback(struct mg_connection *nc, uint16_t message_id);
|
void mg_mqtt_puback(struct mg_connection *nc, uint16_t message_id);
|
||||||
---
|
---
|
||||||
|
|
||||||
Send a PUBACK command with a given `message_id`.
|
Sends a PUBACK command with a given `message_id`.
|
||||||
|
|
||||||
@@ -6,5 +6,5 @@ signature: |
|
|||||||
void mg_mqtt_pubcomp(struct mg_connection *nc, uint16_t message_id);
|
void mg_mqtt_pubcomp(struct mg_connection *nc, uint16_t message_id);
|
||||||
---
|
---
|
||||||
|
|
||||||
Send a PUBCOMP command with a given `message_id`.
|
Sends a PUBCOMP command with a given `message_id`.
|
||||||
|
|
||||||
@@ -8,5 +8,5 @@ signature: |
|
|||||||
size_t len);
|
size_t len);
|
||||||
---
|
---
|
||||||
|
|
||||||
Publish a message to a given topic.
|
Publishes a message to a given topic.
|
||||||
|
|
||||||
@@ -6,5 +6,5 @@ signature: |
|
|||||||
void mg_mqtt_pubrec(struct mg_connection *nc, uint16_t message_id);
|
void mg_mqtt_pubrec(struct mg_connection *nc, uint16_t message_id);
|
||||||
---
|
---
|
||||||
|
|
||||||
Send a PUBREC command with a given `message_id`.
|
Sends a PUBREC command with a given `message_id`.
|
||||||
|
|
||||||
@@ -6,5 +6,5 @@ signature: |
|
|||||||
void mg_mqtt_pubrel(struct mg_connection *nc, uint16_t message_id);
|
void mg_mqtt_pubrel(struct mg_connection *nc, uint16_t message_id);
|
||||||
---
|
---
|
||||||
|
|
||||||
Send a PUBREL command with a given `message_id`.
|
Sends a PUBREL command with a given `message_id`.
|
||||||
|
|
||||||
@@ -7,6 +7,6 @@ signature: |
|
|||||||
uint16_t message_id);
|
uint16_t message_id);
|
||||||
---
|
---
|
||||||
|
|
||||||
Send a SUBACK command with a given `message_id`
|
Sends a SUBACK command with a given `message_id`
|
||||||
and a sequence of granted QoSs.
|
and a sequence of granted QoSs.
|
||||||
|
|
||||||
@@ -8,5 +8,5 @@ signature: |
|
|||||||
size_t topics_len, uint16_t message_id);
|
size_t topics_len, uint16_t message_id);
|
||||||
---
|
---
|
||||||
|
|
||||||
Subscribe to a bunch of topics.
|
Subscribes to a bunch of topics.
|
||||||
|
|
||||||
@@ -6,5 +6,5 @@ signature: |
|
|||||||
void mg_mqtt_unsuback(struct mg_connection *nc, uint16_t message_id);
|
void mg_mqtt_unsuback(struct mg_connection *nc, uint16_t message_id);
|
||||||
---
|
---
|
||||||
|
|
||||||
Send a UNSUBACK command with a given `message_id`.
|
Sends a UNSUBACK command with a given `message_id`.
|
||||||
|
|
||||||
@@ -7,5 +7,5 @@ signature: |
|
|||||||
size_t topics_len, uint16_t message_id);
|
size_t topics_len, uint16_t message_id);
|
||||||
---
|
---
|
||||||
|
|
||||||
Unsubscribe from a bunch of topics.
|
Unsubscribes from a bunch of topics.
|
||||||
|
|
||||||
@@ -6,5 +6,5 @@ signature: |
|
|||||||
void mg_send_mqtt_handshake(struct mg_connection *nc, const char *client_id);
|
void mg_send_mqtt_handshake(struct mg_connection *nc, const char *client_id);
|
||||||
---
|
---
|
||||||
|
|
||||||
Send MQTT handshake.
|
Sends an MQTT handshake.
|
||||||
|
|
||||||
@@ -7,5 +7,5 @@ signature: |
|
|||||||
struct mg_send_mqtt_handshake_opts);
|
struct mg_send_mqtt_handshake_opts);
|
||||||
---
|
---
|
||||||
|
|
||||||
Send MQTT handshake with optional parameters.
|
Sends an MQTT handshake with optional parameters.
|
||||||
|
|
||||||
@@ -6,7 +6,7 @@ signature: |
|
|||||||
void mg_set_protocol_mqtt(struct mg_connection *nc);
|
void mg_set_protocol_mqtt(struct mg_connection *nc);
|
||||||
---
|
---
|
||||||
|
|
||||||
Attach built-in MQTT event handler to the given connection.
|
Attaches a built-in MQTT event handler to the given connection.
|
||||||
|
|
||||||
The user-defined event handler will receive following extra events:
|
The user-defined event handler will receive following extra events:
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
---
|
||||||
|
title: "MQTT Server API reference"
|
||||||
|
symbol_kind: "intro"
|
||||||
|
decl_name: "mqtt_server.h"
|
||||||
|
items:
|
||||||
|
- { name: mg_mqtt_broker_init.md }
|
||||||
|
- { name: mg_mqtt_broker.md }
|
||||||
|
- { name: mg_mqtt_next.md }
|
||||||
|
- { name: struct_mg_mqtt_session.md }
|
||||||
|
- { name: struct_mg_mqtt_broker.md }
|
||||||
|
---
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
+3
-3
@@ -6,10 +6,10 @@ signature: |
|
|||||||
void mg_mqtt_broker(struct mg_connection *brk, int ev, void *data);
|
void mg_mqtt_broker(struct mg_connection *brk, int ev, void *data);
|
||||||
---
|
---
|
||||||
|
|
||||||
Process a MQTT broker message.
|
Processes a MQTT broker message.
|
||||||
|
|
||||||
Listening connection expects a pointer to an initialized `mg_mqtt_broker`
|
The listening connection expects a pointer to an initialised
|
||||||
structure in the `user_data` field.
|
`mg_mqtt_broker` structure in the `user_data` field.
|
||||||
|
|
||||||
Basic usage:
|
Basic usage:
|
||||||
|
|
||||||
+1
-1
@@ -6,5 +6,5 @@ signature: |
|
|||||||
void mg_mqtt_broker_init(struct mg_mqtt_broker *brk, void *user_data);
|
void mg_mqtt_broker_init(struct mg_mqtt_broker *brk, void *user_data);
|
||||||
---
|
---
|
||||||
|
|
||||||
Initialize a MQTT broker.
|
Initialises a MQTT broker.
|
||||||
|
|
||||||
@@ -7,7 +7,7 @@ signature: |
|
|||||||
struct mg_mqtt_session *s);
|
struct mg_mqtt_session *s);
|
||||||
---
|
---
|
||||||
|
|
||||||
Iterate over all mqtt sessions connections. Example:
|
Iterates over all MQTT session connections. Example:
|
||||||
|
|
||||||
```c
|
```c
|
||||||
struct mg_mqtt_session *s;
|
struct mg_mqtt_session *s;
|
||||||
File renamed without changes.
File renamed without changes.
+31
-30
@@ -1,40 +1,41 @@
|
|||||||
---
|
---
|
||||||
title: "Core: TCP/UDP/SSL"
|
title: "Core API: TCP/UDP/SSL"
|
||||||
symbol_kind: "intro"
|
symbol_kind: "intro"
|
||||||
decl_name: "net.h"
|
decl_name: "net.h"
|
||||||
items:
|
items:
|
||||||
- { type: file, name: mg_mgr_init.md }
|
- { name: mg_mgr_init.md }
|
||||||
- { type: file, name: mg_mgr_free.md }
|
- { name: mg_mgr_free.md }
|
||||||
- { type: file, name: mg_mgr_poll.md }
|
- { name: mg_mgr_poll.md }
|
||||||
- { type: file, name: mg_broadcast.md }
|
- { name: mg_broadcast.md }
|
||||||
- { type: file, name: mg_next.md }
|
- { name: mg_next.md }
|
||||||
- { type: file, name: mg_add_sock.md }
|
- { name: mg_add_sock.md }
|
||||||
- { type: file, name: mg_add_sock_opt.md }
|
- { name: mg_add_sock_opt.md }
|
||||||
- { type: file, name: mg_bind.md }
|
- { name: mg_bind.md }
|
||||||
- { type: file, name: mg_bind_opt.md }
|
- { name: mg_bind_opt.md }
|
||||||
- { type: file, name: mg_connect.md }
|
- { name: mg_connect.md }
|
||||||
- { type: file, name: mg_connect_opt.md }
|
- { name: mg_connect_opt.md }
|
||||||
- { type: file, name: mg_set_ssl.md }
|
- { name: mg_set_ssl.md }
|
||||||
- { type: file, name: mg_send.md }
|
- { name: mg_send.md }
|
||||||
- { type: file, name: mg_printf.md }
|
- { name: mg_printf.md }
|
||||||
- { type: file, name: mg_vprintf.md }
|
- { name: mg_vprintf.md }
|
||||||
- { type: file, name: mg_socketpair.md }
|
- { name: mg_socketpair.md }
|
||||||
- { type: file, name: mg_check_ip_acl.md }
|
- { name: mg_check_ip_acl.md }
|
||||||
- { type: file, name: mg_enable_multithreading.md }
|
- { name: mg_enable_multithreading.md }
|
||||||
- { type: file, name: mg_enable_javascript.md }
|
- { name: mg_enable_javascript.md }
|
||||||
- { type: file, name: mg_set_timer.md }
|
- { name: mg_set_timer.md }
|
||||||
- { type: file, name: mg_time.md }
|
- { name: mg_time.md }
|
||||||
- { type: file, name: mg_event_handler_t.md }
|
- { name: mg_event_handler_t.md }
|
||||||
- { type: file, name: struct_mg_mgr.md }
|
- { name: struct_mg_mgr.md }
|
||||||
- { type: file, name: struct_mg_connection.md }
|
- { name: struct_mg_connection.md }
|
||||||
- { type: file, name: struct_mg_add_sock_opts.md }
|
- { name: struct_mg_add_sock_opts.md }
|
||||||
- { type: file, name: struct_mg_bind_opts.md }
|
- { name: struct_mg_bind_opts.md }
|
||||||
- { type: file, name: struct_mg_connect_opts.md }
|
- { name: struct_mg_connect_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
|
||||||
its data structures by mutexes, therefore all functions that are dealing
|
its data structures by mutexes, therefore all functions that are dealing
|
||||||
with particular event manager should be called from the same thread,
|
with a particular event manager should be called from the same thread,
|
||||||
with exception of `mg_broadcast()` function. It is fine to have different
|
with exception of the `mg_broadcast()` function. It is fine to have different
|
||||||
event managers handled by different threads.
|
event managers handled by different threads.
|
||||||
|
|
||||||
@@ -6,8 +6,8 @@ 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 *, sock_t, mg_event_handler_t);
|
||||||
---
|
---
|
||||||
|
|
||||||
Create a connection, associate it with the given socket and event handler,
|
Creates a connection, associates it with the given socket and event handler
|
||||||
and add it to the manager.
|
and adds it to the manager.
|
||||||
|
|
||||||
For more options see the `mg_add_sock_opt` variant.
|
For more options see the `mg_add_sock_opt` variant.
|
||||||
|
|
||||||
@@ -8,8 +8,8 @@ signature: |
|
|||||||
struct mg_add_sock_opts);
|
struct mg_add_sock_opts);
|
||||||
---
|
---
|
||||||
|
|
||||||
Create a connection, associate it with the given socket and event handler,
|
Creates a connection, associates it with the given socket and event handler
|
||||||
and add to the manager.
|
and adds to the manager.
|
||||||
|
|
||||||
See the `mg_add_sock_opts` structure for a description of the options.
|
See the `mg_add_sock_opts` structure for a description of the options.
|
||||||
|
|
||||||
@@ -7,7 +7,7 @@ signature: |
|
|||||||
mg_event_handler_t);
|
mg_event_handler_t);
|
||||||
---
|
---
|
||||||
|
|
||||||
Create listening connection.
|
Creates a listening connection.
|
||||||
|
|
||||||
See `mg_bind_opt` for full documentation.
|
See `mg_bind_opt` for full documentation.
|
||||||
|
|
||||||
@@ -8,19 +8,20 @@ signature: |
|
|||||||
struct mg_bind_opts opts);
|
struct mg_bind_opts opts);
|
||||||
---
|
---
|
||||||
|
|
||||||
Create listening connection.
|
Creates a listening connection.
|
||||||
|
|
||||||
`address` parameter tells which address to bind to. It's format is the same
|
The `address` parameter specifies which address to bind to. It's format is
|
||||||
as for the `mg_connect()` call, where `HOST` part is optional. `address`
|
the same as for the `mg_connect()` call, where `HOST` part is optional.
|
||||||
can be just a port number, e.g. `:8000`. To bind to a specific interface,
|
`address` can be just a port number, e.g. `:8000`. To bind to a specific
|
||||||
an IP address can be specified, e.g. `1.2.3.4:8000`. By default, a TCP
|
interface, an IP address can be specified, e.g. `1.2.3.4:8000`. By default,
|
||||||
connection is created. To create UDP connection, prepend `udp://` prefix,
|
a TCP connection is created. To create UDP connection, prepend `udp://`
|
||||||
e.g. `udp://:8000`. To summarize, `address` paramer has following format:
|
prefix, e.g. `udp://:8000`. To summarize, `address` paramer has following
|
||||||
`[PROTO://][IP_ADDRESS]:PORT`, where `PROTO` could be `tcp` or `udp`.
|
format: `[PROTO://][IP_ADDRESS]:PORT`, where `PROTO` could be `tcp` or
|
||||||
|
`udp`.
|
||||||
|
|
||||||
See the `mg_bind_opts` structure for a description of the optional
|
See the `mg_bind_opts` structure for a description of the optional
|
||||||
parameters.
|
parameters.
|
||||||
|
|
||||||
Return a new listening connection, or `NULL` on error.
|
Returns a new listening connection or `NULL` on error.
|
||||||
NOTE: Connection remains owned by the manager, do not free().
|
NOTE: The connection remains owned by the manager, do not free().
|
||||||
|
|
||||||
@@ -6,14 +6,14 @@ signature: |
|
|||||||
void mg_broadcast(struct mg_mgr *, mg_event_handler_t func, void *, size_t);
|
void mg_broadcast(struct mg_mgr *, mg_event_handler_t func, void *, size_t);
|
||||||
---
|
---
|
||||||
|
|
||||||
Pass a message of a given length to all connections.
|
Passes a message of a given length to all connections.
|
||||||
|
|
||||||
Must be called from a thread that does NOT call `mg_mgr_poll()`.
|
Must be called from a thread that does NOT call `mg_mgr_poll()`.
|
||||||
Note that `mg_broadcast()` is the only function
|
Note that `mg_broadcast()` is the only function
|
||||||
that can be, and must be, called from a different (non-IO) thread.
|
that can be, and must be, called from a different (non-IO) thread.
|
||||||
|
|
||||||
`func` callback function will be called by the IO thread for each
|
`func` callback function will be called by the IO thread for each
|
||||||
connection. When called, event would be `MG_EV_POLL`, and message will
|
connection. When called, the event will be `MG_EV_POLL`, and a message will
|
||||||
be passed as `ev_data` pointer. Maximum message size is capped
|
be passed as the `ev_data` pointer. Maximum message size is capped
|
||||||
by `MG_CTL_MSG_MESSAGE_SIZE` which is set to 8192 bytes.
|
by `MG_CTL_MSG_MESSAGE_SIZE` which is set to 8192 bytes.
|
||||||
|
|
||||||
@@ -13,15 +13,15 @@ Verify given IP address against the ACL.
|
|||||||
Each subnet is
|
Each subnet is
|
||||||
prepended by either a - or a + sign. A plus sign means allow, where a
|
prepended by either a - or a + sign. A plus sign means allow, where a
|
||||||
minus sign means deny. If a subnet mask is omitted, such as `-1.2.3.4`,
|
minus sign means deny. If a subnet mask is omitted, such as `-1.2.3.4`,
|
||||||
this means to deny only that single IP address.
|
it means that only that single IP address is denied.
|
||||||
Subnet masks may vary from 0 to 32, inclusive. The default setting
|
Subnet masks may vary from 0 to 32, inclusive. The default setting
|
||||||
is to allow all accesses. 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 acccesses, only allow 192.168/16 subnet
|
||||||
|
|
||||||
To learn more about subnet masks, see the
|
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].
|
||||||
|
|
||||||
Return -1 if ACL is malformed, 0 if address is disallowed, 1 if allowed.
|
Returns -1 if ACL is malformed, 0 if address is disallowed, 1 if allowed.
|
||||||
|
|
||||||
@@ -7,7 +7,7 @@ signature: |
|
|||||||
mg_event_handler_t handler);
|
mg_event_handler_t handler);
|
||||||
---
|
---
|
||||||
|
|
||||||
Connect to a remote host.
|
Connects to a remote host.
|
||||||
|
|
||||||
See `mg_connect_opt()` for full documentation.
|
See `mg_connect_opt()` for full documentation.
|
||||||
|
|
||||||
@@ -8,11 +8,11 @@ signature: |
|
|||||||
struct mg_connect_opts opts);
|
struct mg_connect_opts opts);
|
||||||
---
|
---
|
||||||
|
|
||||||
Connect to a remote host.
|
Connects to a remote host.
|
||||||
|
|
||||||
`address` format is `[PROTO://]HOST:PORT`. `PROTO` could be `tcp` or `udp`.
|
The `address` format is `[PROTO://]HOST:PORT`. `PROTO` could be `tcp` or
|
||||||
`HOST` could be an IP address,
|
`udp`. `HOST` could be an IP address,
|
||||||
IPv6 address (if Mongoose is compiled with `-DMG_ENABLE_IPV6`), or a host
|
IPv6 address (if Mongoose is compiled with `-DMG_ENABLE_IPV6`) or a host
|
||||||
name. If `HOST` is a name, Mongoose will resolve it asynchronously. Examples
|
name. If `HOST` is a name, Mongoose will resolve it asynchronously. Examples
|
||||||
of valid addresses: `google.com:80`, `udp://1.2.3.4:53`, `10.0.0.1:443`,
|
of valid addresses: `google.com:80`, `udp://1.2.3.4:53`, `10.0.0.1:443`,
|
||||||
`[::1]:80`
|
`[::1]:80`
|
||||||
@@ -20,18 +20,18 @@ of valid addresses: `google.com:80`, `udp://1.2.3.4:53`, `10.0.0.1:443`,
|
|||||||
See the `mg_connect_opts` structure for a description of the optional
|
See the `mg_connect_opts` structure for a description of the optional
|
||||||
parameters.
|
parameters.
|
||||||
|
|
||||||
Returns a new outbound connection, or `NULL` on error.
|
Returns a new outbound connection or `NULL` on error.
|
||||||
|
|
||||||
NOTE: Connection remains owned by the manager, do not free().
|
NOTE: The connection remains owned by the manager, do not free().
|
||||||
|
|
||||||
NOTE: To enable IPv6 addresses, `-DMG_ENABLE_IPV6` should be specified
|
NOTE: To enable IPv6 addresses `-DMG_ENABLE_IPV6` should be specified
|
||||||
in the compilation flags.
|
in the compilation flags.
|
||||||
|
|
||||||
NOTE: New connection will receive `MG_EV_CONNECT` as it's first event
|
NOTE: The new connection will receive `MG_EV_CONNECT` as its first event
|
||||||
which will report connect success status.
|
which will report the connect success status.
|
||||||
If asynchronous resolution fail, or `connect()` syscall fail for whatever
|
If the asynchronous resolution fails or the `connect()` syscall fails for
|
||||||
reason (e.g. with `ECONNREFUSED` or `ENETUNREACH`), then `MG_EV_CONNECT`
|
whatever reason (e.g. with `ECONNREFUSED` or `ENETUNREACH`), then
|
||||||
event report failure. Code example below:
|
`MG_EV_CONNECT` event will report failure. Code example below:
|
||||||
|
|
||||||
```c
|
```c
|
||||||
static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
|
static void ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
|
||||||
|
|||||||
Loaded 100 of 300 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user