Skip to content
Snippets Groups Projects
Commit 3eb4eb80 authored by Dmitry Frank's avatar Dmitry Frank
Browse files

Fix mongoose docs generation

PUBLISHED_FROM=331821dcd1f7dc8a94581cd8a9b51aa00a89fddc
parent ab000c68
No related branches found
No related tags found
No related merge requests found
Showing
with 369 additions and 0 deletions
---
title: "DNS API reference"
symbol_kind: "intro"
decl_name: "mg_dns.h"
items:
- { name: mg_dns_copy_questions.md }
- { name: mg_dns_encode_name.md }
- { name: mg_dns_encode_record.md }
- { name: mg_dns_insert_header.md }
- { name: mg_dns_parse_record_data.md }
- { name: mg_dns_uncompress_name.md }
- { name: mg_parse_dns.md }
- { name: mg_send_dns_query.md }
- { name: mg_set_protocol_dns.md }
- { name: struct_mg_dns_message.md }
- { name: struct_mg_dns_resource_record.md }
---
---
title: "mg_dns_copy_questions()"
decl_name: "mg_dns_copy_questions"
symbol_kind: "func"
signature: |
int mg_dns_copy_questions(struct mbuf *io, struct mg_dns_message *msg);
---
Appends already encoded questions from an existing message.
This is useful when generating a DNS reply message which includes
all question records.
Returns the number of appended bytes.
---
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.
---
title: "mg_dns_encode_record()"
decl_name: "mg_dns_encode_record"
symbol_kind: "func"
signature: |
int mg_dns_encode_record(struct mbuf *io, struct mg_dns_resource_record *rr,
const char *name, size_t nlen, const void *rdata,
size_t rlen);
---
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
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
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
reply.
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
again.
Returns the number of bytes appended or -1 in case of error.
---
title: "mg_dns_insert_header()"
decl_name: "mg_dns_insert_header"
symbol_kind: "func"
signature: |
int mg_dns_insert_header(struct mbuf *io, size_t pos,
struct mg_dns_message *msg);
---
Inserts a DNS header to an IO buffer.
Returns the number of bytes inserted.
---
title: "mg_dns_parse_record_data()"
decl_name: "mg_dns_parse_record_data"
symbol_kind: "func"
signature: |
int mg_dns_parse_record_data(struct mg_dns_message *msg,
struct mg_dns_resource_record *rr, void *data,
size_t data_len);
---
Parses the record data from a DNS resource record.
- A: struct in_addr *ina
- AAAA: struct in6_addr *ina
- CNAME: char buffer
Returns -1 on error.
TODO(mkm): MX
---
title: "mg_dns_uncompress_name()"
decl_name: "mg_dns_uncompress_name"
symbol_kind: "func"
signature: |
size_t mg_dns_uncompress_name(struct mg_dns_message *msg, struct mg_str *name,
char *dst, int dst_len);
---
Uncompresses a DNS compressed name.
The containing DNS message is required because of the compressed encoding
and reference suffixes present elsewhere in the packet.
If the name is less than `dst_len` characters long, the remainder
of `dst` is terminated with `\0` characters. Otherwise, `dst` is not
terminated.
If `dst_len` is 0 `dst` can be NULL.
Returns the uncompressed name length.
---
title: "mg_parse_dns()"
decl_name: "mg_parse_dns"
symbol_kind: "func"
signature: |
int mg_parse_dns(const char *buf, int len, struct mg_dns_message *msg);
---
Low-level: parses a DNS response.
---
title: "mg_send_dns_query()"
decl_name: "mg_send_dns_query"
symbol_kind: "func"
signature: |
void mg_send_dns_query(struct mg_connection *nc, const char *name,
int query_type);
---
Sends a DNS query to the remote end.
---
title: "mg_set_protocol_dns()"
decl_name: "mg_set_protocol_dns"
symbol_kind: "func"
signature: |
void mg_set_protocol_dns(struct mg_connection *nc);
---
Attaches a built-in DNS event handler to the given listening connection.
The DNS event handler parses the incoming UDP packets, treating them as DNS
requests. If an incoming packet gets successfully parsed by the DNS event
handler, a user event handler will receive an `MG_DNS_REQUEST` event, with
`ev_data` pointing to the parsed `struct mg_dns_message`.
See
[captive_dns_server](https://github.com/cesanta/mongoose/tree/master/examples/captive_dns_server)
example on how to handle DNS request and send DNS reply.
---
title: "struct mg_dns_message"
decl_name: "struct mg_dns_message"
symbol_kind: "struct"
signature: |
struct mg_dns_message {
struct mg_str pkt; /* packet body */
uint16_t flags;
uint16_t transaction_id;
int num_questions;
int num_answers;
struct mg_dns_resource_record questions[MG_MAX_DNS_QUESTIONS];
struct mg_dns_resource_record answers[MG_MAX_DNS_ANSWERS];
};
---
DNS message (request and response).
---
title: "struct mg_dns_resource_record"
decl_name: "struct mg_dns_resource_record"
symbol_kind: "struct"
signature: |
struct mg_dns_resource_record {
struct mg_str name; /* buffer with compressed name */
int rtype;
int rclass;
int ttl;
enum mg_dns_resource_record_kind kind;
struct mg_str rdata; /* protocol data (can be a compressed name) */
};
---
DNS resource record.
---
title: "DNS server API reference"
symbol_kind: "intro"
decl_name: "mg_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`.
---
title: "mg_dns_create_reply()"
decl_name: "mg_dns_create_reply"
symbol_kind: "func"
signature: |
struct mg_dns_reply mg_dns_create_reply(struct mbuf *io,
struct mg_dns_message *msg);
---
Creates a DNS reply.
The reply will be based on an existing query message `msg`.
The query body will be appended to the output buffer.
"reply + recursion allowed" will be added to the message flags and the
message's num_answers will be set to 0.
Answer records can be appended with `mg_dns_send_reply` or by lower
level function defined in the DNS API.
In order to send a reply use `mg_dns_send_reply`.
It's possible to use a connection's send buffer as reply buffer,
and it will work for both UDP and TCP connections.
Example:
```c
reply = mg_dns_create_reply(&nc->send_mbuf, msg);
for (i = 0; i < msg->num_questions; i++) {
rr = &msg->questions[i];
if (rr->rtype == MG_DNS_A_RECORD) {
mg_dns_reply_record(&reply, rr, 3600, &dummy_ip_addr, 4);
}
}
mg_dns_send_reply(nc, &reply);
```
---
title: "mg_dns_reply_record()"
decl_name: "mg_dns_reply_record"
symbol_kind: "func"
signature: |
int mg_dns_reply_record(struct mg_dns_reply *reply,
struct mg_dns_resource_record *question,
const char *name, int rtype, int ttl, const void *rdata,
size_t rdata_len);
---
Appends a DNS reply record to the IO buffer and to the DNS message.
The message's num_answers field will be incremented. It's the caller's duty
to ensure num_answers is properly initialised.
Returns -1 on error.
---
title: "mg_dns_send_reply()"
decl_name: "mg_dns_send_reply"
symbol_kind: "func"
signature: |
void mg_dns_send_reply(struct mg_connection *nc, struct mg_dns_reply *r);
---
Sends a DNS reply through a connection.
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
the DNS header reflects the size and flags of the message, that might have
been updated either with `mg_dns_reply_record` or by direct manipulation of
`r->message`.
Once sent, the IO buffer will be trimmed unless the reply IO buffer
is the connection's send buffer and the connection is not in UDP mode.
---
title: "Common API reference"
symbol_kind: "intro"
decl_name: "mg_http.h"
items:
- { name: mg_connect_ws.md }
- { name: mg_connect_ws_opt.md }
- { name: mg_http_is_authorized.md }
- { name: mg_http_send_digest_auth_request.md }
- { name: mg_printf_websocket_frame.md }
- { name: mg_send_websocket_frame.md }
- { name: mg_send_websocket_framev.md }
- { name: mg_send_websocket_handshake.md }
- { name: mg_send_websocket_handshake2.md }
- { name: mg_send_websocket_handshake3.md }
- { name: mg_send_websocket_handshake3v.md }
- { name: mg_set_protocol_http_websocket.md }
- { name: mg_url_decode.md }
- { name: struct_http_message.md }
- { name: struct_mg_http_multipart_part.md }
- { name: struct_mg_ssi_call_ctx.md }
- { name: struct_websocket_message.md }
---
---
title: "mg_connect_ws()"
decl_name: "mg_connect_ws"
symbol_kind: "func"
signature: |
struct mg_connection *mg_connect_ws(struct mg_mgr *mgr,
MG_CB(mg_event_handler_t event_handler,
void *user_data);
---
Helper function that creates an outbound WebSocket connection.
`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
Host headers. `extra_headers` is an extra HTTP header to send, e.g.
`"User-Agent: my-app\r\n"`.
If `protocol` is not NULL, then a `Sec-WebSocket-Protocol` header is sent.
Examples:
```c
nc1 = mg_connect_ws(mgr, ev_handler_1, "ws://echo.websocket.org", NULL,
NULL);
nc2 = mg_connect_ws(mgr, ev_handler_1, "wss://echo.websocket.org", NULL,
NULL);
nc3 = mg_connect_ws(mgr, ev_handler_1, "ws://api.cesanta.com",
"clubby.cesanta.com", NULL);
```
---
title: "mg_connect_ws_opt()"
decl_name: "mg_connect_ws_opt"
symbol_kind: "func"
signature: |
struct mg_connection *mg_connect_ws_opt(
struct mg_mgr *mgr, MG_CB(mg_event_handler_t ev_handler, void *user_data);
---
Helper function that creates an outbound WebSocket connection
Mostly identical to `mg_connect_ws`, but allows to provide extra parameters
(for example, SSL parameters)
---
title: "mg_http_is_authorized()"
decl_name: "mg_http_is_authorized"
symbol_kind: "func"
signature: |
int mg_http_is_authorized(struct http_message *hm, struct mg_str path,
const char *domain, const char *passwords_file,
int flags);
---
Checks whether an http request is authorized. `domain` is the authentication
realm, `passwords_file` is a htdigest file (can be created e.g. with
`htdigest` utility). If either `domain` or `passwords_file` is NULL, this
function always returns 1; otherwise checks the authentication in the
http request and returns 1 only if there is a match; 0 otherwise.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment