MIDAS
Loading...
Searching...
No Matches
mongoose v6.4 web server library

Classes

struct  mbuf
 
struct  cs_sha1_ctx
 
struct  MD5Context
 
struct  cs_base64_ctx
 
struct  json_token
 
union  socket_address
 
struct  mg_str
 
struct  mg_mgr
 
struct  mg_connection
 
struct  mg_add_sock_opts
 
struct  mg_bind_opts
 
struct  mg_connect_opts
 
struct  http_message
 
struct  websocket_message
 
struct  mg_http_multipart_part
 
struct  mg_serve_http_opts
 
struct  mg_rpc_request
 
struct  mg_rpc_reply
 
struct  mg_rpc_error
 
struct  mg_mqtt_message
 
struct  mg_mqtt_topic_expression
 
struct  mg_send_mqtt_handshake_opts
 
struct  mg_dns_resource_record
 
struct  mg_dns_message
 
struct  mg_resolve_async_opts
 

Macros

#define MG_VERSION   "6.4"
 
#define CS_COMMON_PLATFORM_H_
 
#define CS_P_CUSTOM   0
 
#define CS_P_UNIX   1
 
#define CS_P_WINDOWS   2
 
#define CS_P_ESP_LWIP   3
 
#define CS_P_CC3200   4
 
#define CS_P_MSP432   5
 
#define NORETURN
 
#define UNUSED
 
#define NOINLINE
 
#define WARN_UNUSED_RESULT
 
#define ARRAY_SIZE(array)   (sizeof(array) / sizeof(array[0]))
 
#define CS_COMMON_PLATFORMS_PLATFORM_WINDOWS_H_
 
#define CS_COMMON_PLATFORMS_PLATFORM_UNIX_H_
 
#define CS_COMMON_PLATFORMS_PLATFORM_ESP_LWIP_H_
 
#define CS_COMMON_PLATFORMS_PLATFORM_CC3200_H_
 
#define CS_COMMON_PLATFORMS_PLATFORM_MSP432_H_
 
#define CS_COMMON_PLATFORMS_SIMPLELINK_CS_SIMPLELINK_H_
 
#define CS_COMMON_CS_DBG_H_
 
#define LOG(l, x)
 
#define DBG(x)
 
#define CS_COMMON_CS_TIME_H_
 
#define CS_COMMON_MBUF_H_
 
#define MBUF_SIZE_MULTIPLIER   1.5
 
#define CS_COMMON_SHA1_H_
 
#define CS_COMMON_MD5_H_
 
#define CS_COMMON_BASE64_H_
 
#define CS_COMMON_STR_UTIL_H_
 
#define CS_MONGOOSE_DEPS_FROZEN_FROZEN_H_
 
#define JSON_STRING_INVALID   -1
 
#define JSON_STRING_INCOMPLETE   -2
 
#define JSON_TOKEN_ARRAY_TOO_SMALL   -3
 
#define CS_COMMON_CS_DIRENT_H_
 
#define CS_MONGOOSE_SRC_NET_H_
 
#define MG_VPRINTF_BUFFER_SIZE   100
 
#define MG_RECV_FUNC(s, b, l, f)   recv(s, b, l, f)
 
#define MG_SEND_FUNC(s, b, l, f)   send(s, b, l, f)
 
#define MG_EV_POLL   0 /* Sent to each connection on each mg_mgr_poll() call */
 
#define MG_EV_ACCEPT   1 /* New connection accepted. union socket_address * */
 
#define MG_EV_CONNECT   2 /* connect() succeeded or failed. int * */
 
#define MG_EV_RECV   3 /* Data has benn received. int *num_bytes */
 
#define MG_EV_SEND   4 /* Data has been written to a socket. int *num_bytes */
 
#define MG_EV_CLOSE   5 /* Connection is closed. NULL */
 
#define MG_EV_TIMER   6 /* now >= conn->ev_timer_time. double * */
 
#define MG_F_LISTENING   (1 << 0) /* This connection is listening */
 
#define MG_F_UDP   (1 << 1) /* This connection is UDP */
 
#define MG_F_RESOLVING   (1 << 2) /* Waiting for async resolver */
 
#define MG_F_CONNECTING   (1 << 3) /* connect() call in progress */
 
#define MG_F_SSL_HANDSHAKE_DONE   (1 << 4) /* SSL specific */
 
#define MG_F_WANT_READ   (1 << 5) /* SSL specific */
 
#define MG_F_WANT_WRITE   (1 << 6) /* SSL specific */
 
#define MG_F_IS_WEBSOCKET   (1 << 7) /* Websocket specific */
 
#define MG_F_SEND_AND_CLOSE   (1 << 10) /* Push remaining data and close */
 
#define MG_F_CLOSE_IMMEDIATELY   (1 << 11) /* Disconnect */
 
#define MG_F_WEBSOCKET_NO_DEFRAG   (1 << 12) /* Websocket specific */
 
#define MG_F_DELETE_CHUNK   (1 << 13) /* HTTP specific */
 
#define MG_F_USER_1   (1 << 20) /* Flags left for application */
 
#define MG_F_USER_2   (1 << 21)
 
#define MG_F_USER_3   (1 << 22)
 
#define MG_F_USER_4   (1 << 23)
 
#define MG_F_USER_5   (1 << 24)
 
#define MG_F_USER_6   (1 << 25)
 
#define CS_MONGOOSE_SRC_NET_IF_H_
 
#define CS_MONGOOSE_SRC_URI_H_
 
#define CS_MONGOOSE_SRC_UTIL_H_
 
#define MAX_PATH_SIZE   500
 
#define MG_SOCK_STRINGIFY_IP   1
 
#define MG_SOCK_STRINGIFY_PORT   2
 
#define MG_SOCK_STRINGIFY_REMOTE   4
 
#define MG_MK_STR(str_literal)    { str_literal, sizeof(str_literal) - 1 }
 
#define CS_MONGOOSE_SRC_HTTP_H_
 
#define MG_MAX_HTTP_HEADERS   20
 
#define MG_MAX_HTTP_REQUEST_SIZE   1024
 
#define MG_MAX_PATH   256
 
#define MG_MAX_HTTP_SEND_MBUF   1024
 
#define MG_WEBSOCKET_PING_INTERVAL_SECONDS   5
 
#define MG_CGI_ENVIRONMENT_SIZE   8192
 
#define MG_MAX_CGI_ENVIR_VARS   64
 
#define MG_ENV_EXPORT_TO_CGI   "MONGOOSE_CGI"
 
#define MG_EV_HTTP_REQUEST   100 /* struct http_message * */
 
#define MG_EV_HTTP_REPLY   101 /* struct http_message * */
 
#define MG_EV_HTTP_CHUNK   102 /* struct http_message * */
 
#define MG_EV_SSI_CALL   105 /* char * */
 
#define MG_EV_WEBSOCKET_HANDSHAKE_REQUEST   111 /* NULL */
 
#define MG_EV_WEBSOCKET_HANDSHAKE_DONE   112 /* NULL */
 
#define MG_EV_WEBSOCKET_FRAME   113 /* struct websocket_message * */
 
#define MG_EV_WEBSOCKET_CONTROL_FRAME   114 /* struct websocket_message * */
 
#define WEBSOCKET_OP_CONTINUE   0
 
#define WEBSOCKET_OP_TEXT   1
 
#define WEBSOCKET_OP_BINARY   2
 
#define WEBSOCKET_OP_CLOSE   8
 
#define WEBSOCKET_OP_PING   9
 
#define WEBSOCKET_OP_PONG   10
 
#define WEBSOCKET_DONT_FIN   0x100
 
#define CS_MONGOOSE_SRC_JSON_RPC_H_
 
#define JSON_RPC_PARSE_ERROR   (-32700)
 
#define JSON_RPC_INVALID_REQUEST_ERROR   (-32600)
 
#define JSON_RPC_METHOD_NOT_FOUND_ERROR   (-32601)
 
#define JSON_RPC_INVALID_PARAMS_ERROR   (-32602)
 
#define JSON_RPC_INTERNAL_ERROR   (-32603)
 
#define JSON_RPC_SERVER_ERROR   (-32000)
 
#define CS_MONGOOSE_SRC_MQTT_H_
 
#define MG_MQTT_CMD_CONNECT   1
 
#define MG_MQTT_CMD_CONNACK   2
 
#define MG_MQTT_CMD_PUBLISH   3
 
#define MG_MQTT_CMD_PUBACK   4
 
#define MG_MQTT_CMD_PUBREC   5
 
#define MG_MQTT_CMD_PUBREL   6
 
#define MG_MQTT_CMD_PUBCOMP   7
 
#define MG_MQTT_CMD_SUBSCRIBE   8
 
#define MG_MQTT_CMD_SUBACK   9
 
#define MG_MQTT_CMD_UNSUBSCRIBE   10
 
#define MG_MQTT_CMD_UNSUBACK   11
 
#define MG_MQTT_CMD_PINGREQ   12
 
#define MG_MQTT_CMD_PINGRESP   13
 
#define MG_MQTT_CMD_DISCONNECT   14
 
#define MG_MQTT_EVENT_BASE   200
 
#define MG_EV_MQTT_CONNECT   (MG_MQTT_EVENT_BASE + MG_MQTT_CMD_CONNECT)
 
#define MG_EV_MQTT_CONNACK   (MG_MQTT_EVENT_BASE + MG_MQTT_CMD_CONNACK)
 
#define MG_EV_MQTT_PUBLISH   (MG_MQTT_EVENT_BASE + MG_MQTT_CMD_PUBLISH)
 
#define MG_EV_MQTT_PUBACK   (MG_MQTT_EVENT_BASE + MG_MQTT_CMD_PUBACK)
 
#define MG_EV_MQTT_PUBREC   (MG_MQTT_EVENT_BASE + MG_MQTT_CMD_PUBREC)
 
#define MG_EV_MQTT_PUBREL   (MG_MQTT_EVENT_BASE + MG_MQTT_CMD_PUBREL)
 
#define MG_EV_MQTT_PUBCOMP   (MG_MQTT_EVENT_BASE + MG_MQTT_CMD_PUBCOMP)
 
#define MG_EV_MQTT_SUBSCRIBE   (MG_MQTT_EVENT_BASE + MG_MQTT_CMD_SUBSCRIBE)
 
#define MG_EV_MQTT_SUBACK   (MG_MQTT_EVENT_BASE + MG_MQTT_CMD_SUBACK)
 
#define MG_EV_MQTT_UNSUBSCRIBE   (MG_MQTT_EVENT_BASE + MG_MQTT_CMD_UNSUBSCRIBE)
 
#define MG_EV_MQTT_UNSUBACK   (MG_MQTT_EVENT_BASE + MG_MQTT_CMD_UNSUBACK)
 
#define MG_EV_MQTT_PINGREQ   (MG_MQTT_EVENT_BASE + MG_MQTT_CMD_PINGREQ)
 
#define MG_EV_MQTT_PINGRESP   (MG_MQTT_EVENT_BASE + MG_MQTT_CMD_PINGRESP)
 
#define MG_EV_MQTT_DISCONNECT   (MG_MQTT_EVENT_BASE + MG_MQTT_CMD_DISCONNECT)
 
#define MG_MQTT_RETAIN   0x1
 
#define MG_MQTT_DUP   0x4
 
#define MG_MQTT_QOS(qos)   ((qos) << 1)
 
#define MG_MQTT_GET_QOS(flags)   (((flags) &0x6) >> 1)
 
#define MG_MQTT_SET_QOS(flags, qos)   (flags) = ((flags) & ~0x6) | ((qos) << 1)
 
#define MG_MQTT_CLEAN_SESSION   0x02
 
#define MG_MQTT_HAS_WILL   0x04
 
#define MG_MQTT_WILL_RETAIN   0x20
 
#define MG_MQTT_HAS_PASSWORD   0x40
 
#define MG_MQTT_HAS_USER_NAME   0x80
 
#define MG_MQTT_GET_WILL_QOS(flags)   (((flags) &0x18) >> 3)
 
#define MG_MQTT_SET_WILL_QOS(flags, qos)    (flags) = ((flags) & ~0x18) | ((qos) << 3)
 
#define MG_EV_MQTT_CONNACK_ACCEPTED   0
 
#define MG_EV_MQTT_CONNACK_UNACCEPTABLE_VERSION   1
 
#define MG_EV_MQTT_CONNACK_IDENTIFIER_REJECTED   2
 
#define MG_EV_MQTT_CONNACK_SERVER_UNAVAILABLE   3
 
#define MG_EV_MQTT_CONNACK_BAD_AUTH   4
 
#define MG_EV_MQTT_CONNACK_NOT_AUTHORIZED   5
 
#define CS_MONGOOSE_SRC_MQTT_BROKER_H_
 
#define CS_MONGOOSE_SRC_DNS_H_
 
#define MG_DNS_A_RECORD   0x01 /* Lookup IP address */
 
#define MG_DNS_CNAME_RECORD   0x05 /* Lookup CNAME */
 
#define MG_DNS_AAAA_RECORD   0x1c /* Lookup IPv6 address */
 
#define MG_DNS_MX_RECORD   0x0f /* Lookup mail server for domain */
 
#define MG_MAX_DNS_QUESTIONS   32
 
#define MG_MAX_DNS_ANSWERS   32
 
#define MG_DNS_MESSAGE   100 /* High-level DNS message event */
 
#define CS_MONGOOSE_SRC_DNS_SERVER_H_
 
#define CS_MONGOOSE_SRC_RESOLV_H_
 
#define CS_MONGOOSE_SRC_COAP_H_
 

Typedefs

typedef struct MD5Context MD5_CTX
 
typedef void(* cs_base64_putc_t) (char, void *)
 
typedef voidSSL
 
typedef voidSSL_CTX
 
typedef void(* mg_event_handler_t) (struct mg_connection *, int ev, void *)
 
typedef int(* mg_rpc_handler_t) (char *buf, int len, struct mg_rpc_request *req)
 
typedef void(* mg_resolve_callback_t) (struct mg_dns_message *dns_message, void *user_data, enum mg_resolve_err)
 

Enumerations

enum  cs_log_level {
  LL_NONE = -1 , LL_ERROR = 0 , LL_WARN = 1 , LL_INFO = 2 ,
  LL_DEBUG = 3 , LL_VERBOSE_DEBUG = 4 , _LL_MIN = -2 , _LL_MAX = 5
}
 
enum  json_type {
  JSON_TYPE_EOF = 0 , JSON_TYPE_STRING = 1 , JSON_TYPE_NUMBER = 2 , JSON_TYPE_OBJECT = 3 ,
  JSON_TYPE_TRUE = 4 , JSON_TYPE_FALSE = 5 , JSON_TYPE_NULL = 6 , JSON_TYPE_ARRAY = 7
}
 
enum  mg_dns_resource_record_kind { MG_DNS_INVALID_RECORD = 0 , MG_DNS_QUESTION , MG_DNS_ANSWER }
 
enum  mg_resolve_err { MG_RESOLVE_OK = 0 , MG_RESOLVE_NO_ANSWERS = 1 , MG_RESOLVE_EXCEEDED_RETRY_COUNT = 2 , MG_RESOLVE_TIMEOUT = 3 }
 

Functions

void cs_log_set_level (enum cs_log_level level)
 
void cs_log_set_file (FILE *file)
 
void cs_log_print_prefix (const char *func)
 
void cs_log_printf (const char *fmt,...)
 
double cs_time (void)
 
void mbuf_init (struct mbuf *, size_t initial_capacity)
 
void mbuf_free (struct mbuf *)
 
size_t mbuf_append (struct mbuf *, const void *data, size_t data_size)
 
size_t mbuf_insert (struct mbuf *, size_t, const void *, size_t)
 
void mbuf_remove (struct mbuf *, size_t data_size)
 
void mbuf_resize (struct mbuf *, size_t new_size)
 
void mbuf_trim (struct mbuf *)
 
void cs_sha1_init (cs_sha1_ctx *)
 
void cs_sha1_update (cs_sha1_ctx *, const unsigned char *data, uint32_t len)
 
void cs_sha1_final (unsigned char digest[20], cs_sha1_ctx *)
 
void cs_hmac_sha1 (const unsigned char *key, size_t key_len, const unsigned char *text, size_t text_len, unsigned char out[20])
 
void MD5_Init (MD5_CTX *c)
 
void MD5_Update (MD5_CTX *c, const unsigned char *data, size_t len)
 
void MD5_Final (unsigned char *md, MD5_CTX *c)
 
charcs_md5 (char buf[33],...)
 
void cs_to_hex (char *to, const unsigned char *p, size_t len)
 
void cs_base64_init (struct cs_base64_ctx *ctx, cs_base64_putc_t putc, void *user_data)
 
void cs_base64_update (struct cs_base64_ctx *ctx, const char *str, size_t len)
 
void cs_base64_finish (struct cs_base64_ctx *ctx)
 
void cs_base64_encode (const unsigned char *src, int src_len, char *dst)
 
void cs_fprint_base64 (FILE *f, const unsigned char *src, int src_len)
 
int cs_base64_decode (const unsigned char *s, int len, char *dst)
 
size_t c_strnlen (const char *s, size_t maxlen)
 
int c_snprintf (char *buf, size_t buf_size, const char *format,...)
 
int c_vsnprintf (char *buf, size_t buf_size, const char *format, va_list ap)
 
const charc_strnstr (const char *s, const char *find, size_t slen)
 
int parse_json (const char *json_string, int json_string_length, struct json_token *tokens_array, int size_of_tokens_array)
 
struct json_tokenparse_json2 (const char *json_string, int string_length)
 
struct json_tokenfind_json_token (struct json_token *toks, const char *path)
 
int json_emit_long (char *buf, int buf_len, long value)
 
int json_emit_double (char *buf, int buf_len, double value)
 
int json_emit_quoted_str (char *buf, int buf_len, const char *str, int len)
 
int json_emit_unquoted_str (char *buf, int buf_len, const char *str, int len)
 
int json_emit (char *buf, int buf_len, const char *fmt,...)
 
int json_emit_va (char *buf, int buf_len, const char *fmt, va_list)
 
void mg_mgr_init (struct mg_mgr *mgr, void *user_data)
 
void mg_mgr_free (struct mg_mgr *)
 
time_t mg_mgr_poll (struct mg_mgr *, int milli)
 
void mg_broadcast (struct mg_mgr *, mg_event_handler_t func, void *, size_t)
 
struct mg_connectionmg_next (struct mg_mgr *, struct mg_connection *)
 
struct mg_connectionmg_add_sock (struct mg_mgr *, sock_t, mg_event_handler_t)
 
struct mg_connectionmg_add_sock_opt (struct mg_mgr *, sock_t, mg_event_handler_t, struct mg_add_sock_opts)
 
struct mg_connectionmg_bind (struct mg_mgr *, const char *, mg_event_handler_t)
 
struct mg_connectionmg_bind_opt (struct mg_mgr *mgr, const char *address, mg_event_handler_t handler, struct mg_bind_opts opts)
 
struct mg_connectionmg_connect (struct mg_mgr *mgr, const char *address, mg_event_handler_t handler)
 
struct mg_connectionmg_connect_opt (struct mg_mgr *mgr, const char *address, mg_event_handler_t handler, struct mg_connect_opts opts)
 
const charmg_set_ssl (struct mg_connection *nc, const char *cert, const char *ca_cert)
 
void mg_send (struct mg_connection *, const void *buf, int len)
 
int mg_printf (struct mg_connection *, const char *fmt,...)
 
int mg_vprintf (struct mg_connection *, const char *fmt, va_list ap)
 
int mg_socketpair (sock_t[2], int sock_type)
 
int mg_resolve (const char *domain_name, char *ip_addr_buf, size_t buf_len)
 
int mg_check_ip_acl (const char *acl, uint32_t remote_ip)
 
void mg_enable_multithreading (struct mg_connection *nc)
 
double mg_set_timer (struct mg_connection *c, double timestamp)
 
double mg_time (void)
 
void mg_if_connect_tcp (struct mg_connection *nc, const union socket_address *sa)
 
void mg_if_connect_udp (struct mg_connection *nc)
 
void mg_if_connect_cb (struct mg_connection *nc, int err)
 
int mg_if_listen_tcp (struct mg_connection *nc, union socket_address *sa)
 
struct mg_connectionmg_if_accept_new_conn (struct mg_connection *lc)
 
void mg_if_accept_tcp_cb (struct mg_connection *nc, union socket_address *sa, size_t sa_len)
 
int mg_if_listen_udp (struct mg_connection *nc, union socket_address *sa)
 
void mg_if_tcp_send (struct mg_connection *nc, const void *buf, size_t len)
 
void mg_if_udp_send (struct mg_connection *nc, const void *buf, size_t len)
 
void mg_if_sent_cb (struct mg_connection *nc, int num_sent)
 
void mg_if_recv_tcp_cb (struct mg_connection *nc, void *buf, int len)
 
void mg_if_recv_udp_cb (struct mg_connection *nc, void *buf, int len, union socket_address *sa, size_t sa_len)
 
void mg_if_recved (struct mg_connection *nc, size_t len)
 
void mg_if_poll (struct mg_connection *nc, time_t now)
 
void mg_if_timer (struct mg_connection *c, double now)
 
int mg_if_create_conn (struct mg_connection *nc)
 
void mg_if_destroy_conn (struct mg_connection *nc)
 
void mg_close_conn (struct mg_connection *nc)
 
void mg_if_get_conn_addr (struct mg_connection *nc, int remote, union socket_address *sa)
 
void mg_sock_set (struct mg_connection *nc, sock_t sock)
 
int mg_parse_uri (struct mg_str uri, struct mg_str *scheme, struct mg_str *user_info, struct mg_str *host, unsigned int *port, struct mg_str *path, struct mg_str *query, struct mg_str *fragment)
 
int mg_normalize_uri_path (const struct mg_str *in, struct mg_str *out)
 
const charmg_skip (const char *s, const char *end_string, const char *delimiters, struct mg_str *v)
 
int mg_ncasecmp (const char *s1, const char *s2, size_t len)
 
int mg_casecmp (const char *s1, const char *s2)
 
int mg_vcmp (const struct mg_str *str2, const char *str1)
 
int mg_vcasecmp (const struct mg_str *str2, const char *str1)
 
int mg_base64_decode (const unsigned char *s, int len, char *dst)
 
void mg_base64_encode (const unsigned char *src, int src_len, char *dst)
 
int mg_stat (const char *path, cs_stat_t *st)
 
FILEmg_fopen (const char *path, const char *mode)
 
int mg_open (const char *path, int flag, int mode)
 
void mg_set_close_on_exec (sock_t)
 
void mg_conn_addr_to_str (struct mg_connection *nc, char *buf, size_t len, int flags)
 
void mg_sock_to_str (sock_t sock, char *buf, size_t len, int flags)
 
void mg_sock_addr_to_str (const union socket_address *sa, char *buf, size_t len, int flags)
 
int mg_hexdump (const void *buf, int len, char *dst, int dst_len)
 
void mg_hexdump_connection (struct mg_connection *nc, const char *path, const void *buf, int num_bytes, int ev)
 
int mg_avprintf (char **buf, size_t size, const char *fmt, va_list ap)
 
int mg_is_big_endian (void)
 
const charmg_next_comma_list_entry (const char *list, struct mg_str *val, struct mg_str *eq_val)
 
int mg_match_prefix (const char *pattern, int pattern_len, const char *str)
 
int mg_match_prefix_n (const struct mg_str pattern, const struct mg_str str)
 
struct mg_str mg_mk_str (const char *s)
 
void mg_set_protocol_http_websocket (struct mg_connection *nc)
 
void mg_send_websocket_handshake (struct mg_connection *nc, const char *uri, const char *extra_headers)
 
void mg_send_websocket_handshake2 (struct mg_connection *nc, const char *path, const char *host, const char *protocol, const char *extra_headers)
 
struct mg_connectionmg_connect_ws (struct mg_mgr *mgr, mg_event_handler_t event_handler, const char *url, const char *protocol, const char *extra_headers)
 
struct mg_connectionmg_connect_ws_opt (struct mg_mgr *mgr, mg_event_handler_t ev_handler, struct mg_connect_opts opts, const char *url, const char *protocol, const char *extra_headers)
 
void mg_send_websocket_frame (struct mg_connection *nc, int op_and_flags, const void *data, size_t data_len)
 
void mg_send_websocket_framev (struct mg_connection *nc, int op_and_flags, const struct mg_str *strings, int num_strings)
 
void mg_printf_websocket_frame (struct mg_connection *nc, int op_and_flags, const char *fmt,...)
 
void mg_send_http_chunk (struct mg_connection *nc, const char *buf, size_t len)
 
void mg_printf_http_chunk (struct mg_connection *nc, const char *fmt,...)
 
void mg_send_response_line (struct mg_connection *c, int status_code, const char *extra_headers)
 
void mg_send_head (struct mg_connection *n, int status_code, int64_t content_length, const char *extra_headers)
 
void mg_printf_html_escape (struct mg_connection *nc, const char *fmt,...)
 
int mg_parse_http (const char *s, int n, struct http_message *hm, int is_req)
 
struct mg_strmg_get_http_header (struct http_message *hm, const char *name)
 
int mg_http_parse_header (struct mg_str *hdr, const char *var_name, char *buf, size_t buf_size)
 
size_t mg_parse_multipart (const char *buf, size_t buf_len, char *var_name, size_t var_name_len, char *file_name, size_t file_name_len, const char **chunk, size_t *chunk_len)
 
int mg_get_http_var (const struct mg_str *buf, const char *name, char *dst, size_t dst_len)
 
int mg_url_decode (const char *src, int src_len, char *dst, int dst_len, int is_form_url_encoded)
 
int mg_http_create_digest_auth_header (char *buf, size_t buf_len, const char *method, const char *uri, const char *auth_domain, const char *user, const char *passwd)
 
struct mg_connectionmg_connect_http (struct mg_mgr *mgr, mg_event_handler_t event_handler, const char *url, const char *extra_headers, const char *post_data)
 
struct mg_connectionmg_connect_http_opt (struct mg_mgr *mgr, mg_event_handler_t ev_handler, struct mg_connect_opts opts, const char *url, const char *extra_headers, const char *post_data)
 
void mg_serve_http (struct mg_connection *nc, struct http_message *hm, struct mg_serve_http_opts opts)
 
void mg_register_http_endpoint (struct mg_connection *nc, const char *uri_path, mg_event_handler_t handler)
 
int mg_rpc_parse_reply (const char *buf, int len, struct json_token *toks, int max_toks, struct mg_rpc_reply *, struct mg_rpc_error *)
 
int mg_rpc_create_request (char *buf, int len, const char *method, const char *id, const char *params_fmt,...)
 
int mg_rpc_create_reply (char *buf, int len, const struct mg_rpc_request *req, const char *result_fmt,...)
 
int mg_rpc_create_error (char *buf, int len, struct mg_rpc_request *req, int code, const char *message, const char *fmt,...)
 
int mg_rpc_create_std_error (char *buf, int len, struct mg_rpc_request *req, int code)
 
int mg_rpc_dispatch (const char *buf, int, char *dst, int dst_len, const char **methods, mg_rpc_handler_t *handlers)
 
void mg_set_protocol_mqtt (struct mg_connection *nc)
 
void mg_send_mqtt_handshake (struct mg_connection *nc, const char *client_id)
 
void mg_send_mqtt_handshake_opt (struct mg_connection *nc, const char *client_id, struct mg_send_mqtt_handshake_opts)
 
void mg_mqtt_publish (struct mg_connection *nc, const char *topic, uint16_t message_id, int flags, const void *data, size_t len)
 
void mg_mqtt_subscribe (struct mg_connection *nc, const struct mg_mqtt_topic_expression *topics, size_t topics_len, uint16_t message_id)
 
void mg_mqtt_unsubscribe (struct mg_connection *nc, char **topics, size_t topics_len, uint16_t message_id)
 
void mg_mqtt_disconnect (struct mg_connection *nc)
 
void mg_mqtt_connack (struct mg_connection *nc, uint8_t return_code)
 
void mg_mqtt_puback (struct mg_connection *nc, uint16_t message_id)
 
void mg_mqtt_pubrec (struct mg_connection *nc, uint16_t message_id)
 
void mg_mqtt_pubrel (struct mg_connection *nc, uint16_t message_id)
 
void mg_mqtt_pubcomp (struct mg_connection *nc, uint16_t message_id)
 
void mg_mqtt_suback (struct mg_connection *nc, uint8_t *qoss, size_t qoss_len, uint16_t message_id)
 
void mg_mqtt_unsuback (struct mg_connection *nc, uint16_t message_id)
 
void mg_mqtt_ping (struct mg_connection *nc)
 
void mg_mqtt_pong (struct mg_connection *nc)
 
int mg_mqtt_next_subscribe_topic (struct mg_mqtt_message *msg, struct mg_str *topic, uint8_t *qos, int pos)
 
struct mg_dns_resource_recordmg_dns_next_record (struct mg_dns_message *msg, int query, struct mg_dns_resource_record *prev)
 
int mg_dns_parse_record_data (struct mg_dns_message *msg, struct mg_dns_resource_record *rr, void *data, size_t data_len)
 
void mg_send_dns_query (struct mg_connection *nc, const char *name, int query_type)
 
int mg_dns_insert_header (struct mbuf *io, size_t pos, struct mg_dns_message *msg)
 
int mg_dns_copy_body (struct mbuf *io, struct mg_dns_message *msg)
 
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)
 
int mg_parse_dns (const char *buf, int len, struct mg_dns_message *msg)
 
size_t mg_dns_uncompress_name (struct mg_dns_message *msg, struct mg_str *name, char *dst, int dst_len)
 
void mg_set_protocol_dns (struct mg_connection *nc)
 
int mg_resolve_async (struct mg_mgr *mgr, const char *name, int query, mg_resolve_callback_t cb, void *data)
 
int mg_resolve_async_opt (struct mg_mgr *mgr, const char *name, int query, mg_resolve_callback_t cb, void *data, struct mg_resolve_async_opts opts)
 
int mg_resolve_from_hosts_file (const char *host, union socket_address *usa)
 

Variables

enum cs_log_level cs_log_level
 
charmbuf::buf
 
size_t mbuf::len
 
size_t mbuf::size
 
uint32_t cs_sha1_ctx::state [5]
 
uint32_t cs_sha1_ctx::count [2]
 
unsigned char cs_sha1_ctx::buffer [64]
 
uint32_t MD5Context::buf [4]
 
uint32_t MD5Context::bits [2]
 
unsigned char MD5Context::in [64]
 
cs_base64_putc_t cs_base64_ctx::b64_putc
 
unsigned char cs_base64_ctx::chunk [3]
 
int cs_base64_ctx::chunk_size
 
voidcs_base64_ctx::user_data
 
const charjson_token::ptr
 
int json_token::len
 
int json_token::num_desc
 
enum json_type json_token::type
 
struct sockaddr socket_address::sa
 
struct sockaddr_in socket_address::sin
 
struct sockaddr socket_address::sin6
 
const charmg_str::p
 
size_t mg_str::len
 
struct mg_connectionmg_mgr::active_connections
 
const charmg_mgr::hexdump_file
 
sock_t mg_mgr::ctl [2]
 
voidmg_mgr::user_data
 
voidmg_mgr::mgr_data
 
struct mg_connectionmg_connection::next
 
struct mg_connectionmg_connection::prev
 
struct mg_connectionmg_connection::listener
 
struct mg_mgrmg_connection::mgr
 
sock_t mg_connection::sock
 
int mg_connection::err
 
union socket_address mg_connection::sa
 
size_t mg_connection::recv_mbuf_limit
 
struct mbuf mg_connection::recv_mbuf
 
struct mbuf mg_connection::send_mbuf
 
SSLmg_connection::ssl
 
SSL_CTXmg_connection::ssl_ctx
 
time_t mg_connection::last_io_time
 
double mg_connection::ev_timer_time
 
mg_event_handler_t mg_connection::proto_handler
 
voidmg_connection::proto_data
 
void(* mg_connection::proto_data_destructor )(void *proto_data)
 
mg_event_handler_t mg_connection::handler
 
voidmg_connection::user_data
 
void *   mg_connection::v 
 
mg_event_handler_t   mg_connection::f 
 
union { 
 
   void *   mg_connection::v 
 
   mg_event_handler_t   mg_connection::f 
 
mg_connection::priv_1 
 
voidmg_connection::priv_2
 
voidmg_connection::mgr_data
 
unsigned long mg_connection::flags
 
voidmg_add_sock_opts::user_data
 
unsigned int mg_add_sock_opts::flags
 
const char ** mg_add_sock_opts::error_string
 
voidmg_bind_opts::user_data
 
unsigned int mg_bind_opts::flags
 
const char ** mg_bind_opts::error_string
 
voidmg_connect_opts::user_data
 
unsigned int mg_connect_opts::flags
 
const char ** mg_connect_opts::error_string
 
struct mg_str http_message::message
 
struct mg_str http_message::method
 
struct mg_str http_message::uri
 
struct mg_str http_message::proto
 
int http_message::resp_code
 
struct mg_str http_message::resp_status_msg
 
struct mg_str http_message::query_string
 
struct mg_str http_message::header_names [MG_MAX_HTTP_HEADERS]
 
struct mg_str http_message::header_values [MG_MAX_HTTP_HEADERS]
 
struct mg_str http_message::body
 
unsigned charwebsocket_message::data
 
size_t websocket_message::size
 
unsigned char websocket_message::flags
 
const charmg_http_multipart_part::file_name
 
const charmg_http_multipart_part::var_name
 
struct mg_str mg_http_multipart_part::data
 
int mg_http_multipart_part::status
 
voidmg_http_multipart_part::user_data
 
const charmg_serve_http_opts::document_root
 
const charmg_serve_http_opts::index_files
 
const charmg_serve_http_opts::per_directory_auth_file
 
const charmg_serve_http_opts::auth_domain
 
const charmg_serve_http_opts::global_auth_file
 
const charmg_serve_http_opts::enable_directory_listing
 
const charmg_serve_http_opts::ssi_pattern
 
const charmg_serve_http_opts::ip_acl
 
const charmg_serve_http_opts::url_rewrites
 
const charmg_serve_http_opts::dav_document_root
 
const charmg_serve_http_opts::dav_auth_file
 
const charmg_serve_http_opts::hidden_file_pattern
 
const charmg_serve_http_opts::cgi_file_pattern
 
const charmg_serve_http_opts::cgi_interpreter
 
const charmg_serve_http_opts::custom_mime_types
 
const charmg_serve_http_opts::extra_headers
 
struct json_tokenmg_rpc_request::message
 
struct json_tokenmg_rpc_request::id
 
struct json_tokenmg_rpc_request::method
 
struct json_tokenmg_rpc_request::params
 
struct json_tokenmg_rpc_reply::message
 
struct json_tokenmg_rpc_reply::id
 
struct json_tokenmg_rpc_reply::result
 
struct json_tokenmg_rpc_error::message
 
struct json_tokenmg_rpc_error::id
 
struct json_tokenmg_rpc_error::error_code
 
struct json_tokenmg_rpc_error::error_message
 
struct json_tokenmg_rpc_error::error_data
 
int mg_mqtt_message::cmd
 
struct mg_str mg_mqtt_message::payload
 
int mg_mqtt_message::qos
 
uint8_t mg_mqtt_message::connack_ret_code
 
uint16_t mg_mqtt_message::message_id
 
charmg_mqtt_message::topic
 
const charmg_mqtt_topic_expression::topic
 
uint8_t mg_mqtt_topic_expression::qos
 
unsigned char mg_send_mqtt_handshake_opts::flags
 
uint16_t mg_send_mqtt_handshake_opts::keep_alive
 
const charmg_send_mqtt_handshake_opts::will_topic
 
const charmg_send_mqtt_handshake_opts::will_message
 
const charmg_send_mqtt_handshake_opts::user_name
 
const charmg_send_mqtt_handshake_opts::password
 
struct mg_str mg_dns_resource_record::name
 
int mg_dns_resource_record::rtype
 
int mg_dns_resource_record::rclass
 
int mg_dns_resource_record::ttl
 
enum mg_dns_resource_record_kind mg_dns_resource_record::kind
 
struct mg_str mg_dns_resource_record::rdata
 
struct mg_str mg_dns_message::pkt
 
uint16_t mg_dns_message::flags
 
uint16_t mg_dns_message::transaction_id
 
int mg_dns_message::num_questions
 
int mg_dns_message::num_answers
 
struct mg_dns_resource_record mg_dns_message::questions [MG_MAX_DNS_QUESTIONS]
 
struct mg_dns_resource_record mg_dns_message::answers [MG_MAX_DNS_ANSWERS]
 
const charmg_resolve_async_opts::nameserver_url
 
int mg_resolve_async_opts::max_retries
 
int mg_resolve_async_opts::timeout
 
int mg_resolve_async_opts::accept_literal
 
int mg_resolve_async_opts::only_literal
 
struct mg_connection ** mg_resolve_async_opts::dns_conn
 

Detailed Description


Macro Definition Documentation

◆ ARRAY_SIZE

#define ARRAY_SIZE (   array)    (sizeof(array) / sizeof(array[0]))

Definition at line 119 of file mongoose6.h.

◆ CS_COMMON_BASE64_H_

#define CS_COMMON_BASE64_H_

Definition at line 967 of file mongoose6.h.

◆ CS_COMMON_CS_DBG_H_

#define CS_COMMON_CS_DBG_H_

Definition at line 739 of file mongoose6.h.

◆ CS_COMMON_CS_DIRENT_H_

#define CS_COMMON_CS_DIRENT_H_

Definition at line 1106 of file mongoose6.h.

◆ CS_COMMON_CS_TIME_H_

#define CS_COMMON_CS_TIME_H_

Definition at line 799 of file mongoose6.h.

◆ CS_COMMON_MBUF_H_

#define CS_COMMON_MBUF_H_

Definition at line 820 of file mongoose6.h.

◆ CS_COMMON_MD5_H_

#define CS_COMMON_MD5_H_

Definition at line 923 of file mongoose6.h.

◆ CS_COMMON_PLATFORM_H_

#define CS_COMMON_PLATFORM_H_

Definition at line 70 of file mongoose6.h.

◆ CS_COMMON_PLATFORMS_PLATFORM_CC3200_H_

#define CS_COMMON_PLATFORMS_PLATFORM_CC3200_H_

Definition at line 419 of file mongoose6.h.

◆ CS_COMMON_PLATFORMS_PLATFORM_ESP_LWIP_H_

#define CS_COMMON_PLATFORMS_PLATFORM_ESP_LWIP_H_

Definition at line 363 of file mongoose6.h.

◆ CS_COMMON_PLATFORMS_PLATFORM_MSP432_H_

#define CS_COMMON_PLATFORMS_PLATFORM_MSP432_H_

Definition at line 536 of file mongoose6.h.

◆ CS_COMMON_PLATFORMS_PLATFORM_UNIX_H_

#define CS_COMMON_PLATFORMS_PLATFORM_UNIX_H_

Definition at line 266 of file mongoose6.h.

◆ CS_COMMON_PLATFORMS_PLATFORM_WINDOWS_H_

#define CS_COMMON_PLATFORMS_PLATFORM_WINDOWS_H_

Definition at line 124 of file mongoose6.h.

◆ CS_COMMON_PLATFORMS_SIMPLELINK_CS_SIMPLELINK_H_

#define CS_COMMON_PLATFORMS_SIMPLELINK_CS_SIMPLELINK_H_

Definition at line 630 of file mongoose6.h.

◆ CS_COMMON_SHA1_H_

#define CS_COMMON_SHA1_H_

Definition at line 889 of file mongoose6.h.

◆ CS_COMMON_STR_UTIL_H_

#define CS_COMMON_STR_UTIL_H_

Definition at line 1009 of file mongoose6.h.

◆ CS_MONGOOSE_DEPS_FROZEN_FROZEN_H_

#define CS_MONGOOSE_DEPS_FROZEN_FROZEN_H_

Definition at line 1052 of file mongoose6.h.

◆ CS_MONGOOSE_SRC_COAP_H_

#define CS_MONGOOSE_SRC_COAP_H_

Definition at line 3501 of file mongoose6.h.

◆ CS_MONGOOSE_SRC_DNS_H_

#define CS_MONGOOSE_SRC_DNS_H_

Definition at line 3156 of file mongoose6.h.

◆ CS_MONGOOSE_SRC_DNS_SERVER_H_

#define CS_MONGOOSE_SRC_DNS_SERVER_H_

Definition at line 3311 of file mongoose6.h.

◆ CS_MONGOOSE_SRC_HTTP_H_

#define CS_MONGOOSE_SRC_HTTP_H_

Definition at line 2023 of file mongoose6.h.

◆ CS_MONGOOSE_SRC_JSON_RPC_H_

#define CS_MONGOOSE_SRC_JSON_RPC_H_

Definition at line 2723 of file mongoose6.h.

◆ CS_MONGOOSE_SRC_MQTT_BROKER_H_

#define CS_MONGOOSE_SRC_MQTT_BROKER_H_

Definition at line 3068 of file mongoose6.h.

◆ CS_MONGOOSE_SRC_MQTT_H_

#define CS_MONGOOSE_SRC_MQTT_H_

Definition at line 2873 of file mongoose6.h.

◆ CS_MONGOOSE_SRC_NET_H_

#define CS_MONGOOSE_SRC_NET_H_

Definition at line 1160 of file mongoose6.h.

◆ CS_MONGOOSE_SRC_NET_IF_H_

#define CS_MONGOOSE_SRC_NET_IF_H_

Definition at line 1659 of file mongoose6.h.

◆ CS_MONGOOSE_SRC_RESOLV_H_

#define CS_MONGOOSE_SRC_RESOLV_H_

Definition at line 3402 of file mongoose6.h.

◆ CS_MONGOOSE_SRC_URI_H_

#define CS_MONGOOSE_SRC_URI_H_

Definition at line 1743 of file mongoose6.h.

◆ CS_MONGOOSE_SRC_UTIL_H_

#define CS_MONGOOSE_SRC_UTIL_H_

Definition at line 1794 of file mongoose6.h.

◆ CS_P_CC3200

#define CS_P_CC3200   4

Definition at line 80 of file mongoose6.h.

◆ CS_P_CUSTOM

#define CS_P_CUSTOM   0

Definition at line 76 of file mongoose6.h.

◆ CS_P_ESP_LWIP

#define CS_P_ESP_LWIP   3

Definition at line 79 of file mongoose6.h.

◆ CS_P_MSP432

#define CS_P_MSP432   5

Definition at line 81 of file mongoose6.h.

◆ CS_P_UNIX

#define CS_P_UNIX   1

Definition at line 77 of file mongoose6.h.

◆ CS_P_WINDOWS

#define CS_P_WINDOWS   2

Definition at line 78 of file mongoose6.h.

◆ DBG

#define DBG (   x)
Value:
}
cs_log_level
Definition mongoose6.h:741
void cs_log_printf(const char *fmt,...)
@ LL_VERBOSE_DEBUG
Definition mongoose6.h:747
TH1X EXPRT * h1_book(const char *name, const char *title, int bins, double min, double max)
Definition rmidas.h:24

Definition at line 773 of file mongoose6.h.

774 { \
776 cs_log_printf x; \
777 }

◆ JSON_RPC_INTERNAL_ERROR

#define JSON_RPC_INTERNAL_ERROR   (-32603)

Definition at line 2810 of file mongoose6.h.

◆ JSON_RPC_INVALID_PARAMS_ERROR

#define JSON_RPC_INVALID_PARAMS_ERROR   (-32602)

Definition at line 2809 of file mongoose6.h.

◆ JSON_RPC_INVALID_REQUEST_ERROR

#define JSON_RPC_INVALID_REQUEST_ERROR   (-32600)

Definition at line 2807 of file mongoose6.h.

◆ JSON_RPC_METHOD_NOT_FOUND_ERROR

#define JSON_RPC_METHOD_NOT_FOUND_ERROR   (-32601)

Definition at line 2808 of file mongoose6.h.

◆ JSON_RPC_PARSE_ERROR

#define JSON_RPC_PARSE_ERROR   (-32700)

Definition at line 2806 of file mongoose6.h.

◆ JSON_RPC_SERVER_ERROR

#define JSON_RPC_SERVER_ERROR   (-32000)

Definition at line 2811 of file mongoose6.h.

◆ JSON_STRING_INCOMPLETE

#define JSON_STRING_INCOMPLETE   -2

Definition at line 1080 of file mongoose6.h.

◆ JSON_STRING_INVALID

#define JSON_STRING_INVALID   -1

Definition at line 1079 of file mongoose6.h.

◆ JSON_TOKEN_ARRAY_TOO_SMALL

#define JSON_TOKEN_ARRAY_TOO_SMALL   -3

Definition at line 1081 of file mongoose6.h.

◆ LOG

#define LOG (   l,
 
)
Value:

Definition at line 765 of file mongoose6.h.

766 { \
768 cs_log_printf x; \
769 }

◆ MAX_PATH_SIZE

#define MAX_PATH_SIZE   500

Definition at line 1804 of file mongoose6.h.

◆ MBUF_SIZE_MULTIPLIER

#define MBUF_SIZE_MULTIPLIER   1.5

Definition at line 829 of file mongoose6.h.

◆ MG_CGI_ENVIRONMENT_SIZE

#define MG_CGI_ENVIRONMENT_SIZE   8192

Definition at line 2055 of file mongoose6.h.

◆ MG_DNS_A_RECORD

#define MG_DNS_A_RECORD   0x01 /* Lookup IP address */

Definition at line 3163 of file mongoose6.h.

◆ MG_DNS_AAAA_RECORD

#define MG_DNS_AAAA_RECORD   0x1c /* Lookup IPv6 address */

Definition at line 3165 of file mongoose6.h.

◆ MG_DNS_CNAME_RECORD

#define MG_DNS_CNAME_RECORD   0x05 /* Lookup CNAME */

Definition at line 3164 of file mongoose6.h.

◆ MG_DNS_MESSAGE

#define MG_DNS_MESSAGE   100 /* High-level DNS message event */

Definition at line 3171 of file mongoose6.h.

◆ MG_DNS_MX_RECORD

#define MG_DNS_MX_RECORD   0x0f /* Lookup mail server for domain */

Definition at line 3166 of file mongoose6.h.

◆ MG_ENV_EXPORT_TO_CGI

#define MG_ENV_EXPORT_TO_CGI   "MONGOOSE_CGI"

Definition at line 2063 of file mongoose6.h.

◆ MG_EV_ACCEPT

#define MG_EV_ACCEPT   1 /* New connection accepted. union socket_address * */

Definition at line 1220 of file mongoose6.h.

◆ MG_EV_CLOSE

#define MG_EV_CLOSE   5 /* Connection is closed. NULL */

Definition at line 1224 of file mongoose6.h.

◆ MG_EV_CONNECT

#define MG_EV_CONNECT   2 /* connect() succeeded or failed. int * */

Definition at line 1221 of file mongoose6.h.

◆ MG_EV_HTTP_CHUNK

#define MG_EV_HTTP_CHUNK   102 /* struct http_message * */

Definition at line 2116 of file mongoose6.h.

◆ MG_EV_HTTP_REPLY

#define MG_EV_HTTP_REPLY   101 /* struct http_message * */

Definition at line 2115 of file mongoose6.h.

◆ MG_EV_HTTP_REQUEST

#define MG_EV_HTTP_REQUEST   100 /* struct http_message * */

Definition at line 2114 of file mongoose6.h.

◆ MG_EV_MQTT_CONNACK

#define MG_EV_MQTT_CONNACK   (MG_MQTT_EVENT_BASE + MG_MQTT_CMD_CONNACK)

Definition at line 2918 of file mongoose6.h.

◆ MG_EV_MQTT_CONNACK_ACCEPTED

#define MG_EV_MQTT_CONNACK_ACCEPTED   0

Definition at line 2950 of file mongoose6.h.

◆ MG_EV_MQTT_CONNACK_BAD_AUTH

#define MG_EV_MQTT_CONNACK_BAD_AUTH   4

Definition at line 2954 of file mongoose6.h.

◆ MG_EV_MQTT_CONNACK_IDENTIFIER_REJECTED

#define MG_EV_MQTT_CONNACK_IDENTIFIER_REJECTED   2

Definition at line 2952 of file mongoose6.h.

◆ MG_EV_MQTT_CONNACK_NOT_AUTHORIZED

#define MG_EV_MQTT_CONNACK_NOT_AUTHORIZED   5

Definition at line 2955 of file mongoose6.h.

◆ MG_EV_MQTT_CONNACK_SERVER_UNAVAILABLE

#define MG_EV_MQTT_CONNACK_SERVER_UNAVAILABLE   3

Definition at line 2953 of file mongoose6.h.

◆ MG_EV_MQTT_CONNACK_UNACCEPTABLE_VERSION

#define MG_EV_MQTT_CONNACK_UNACCEPTABLE_VERSION   1

Definition at line 2951 of file mongoose6.h.

◆ MG_EV_MQTT_CONNECT

#define MG_EV_MQTT_CONNECT   (MG_MQTT_EVENT_BASE + MG_MQTT_CMD_CONNECT)

Definition at line 2917 of file mongoose6.h.

◆ MG_EV_MQTT_DISCONNECT

#define MG_EV_MQTT_DISCONNECT   (MG_MQTT_EVENT_BASE + MG_MQTT_CMD_DISCONNECT)

Definition at line 2930 of file mongoose6.h.

◆ MG_EV_MQTT_PINGREQ

#define MG_EV_MQTT_PINGREQ   (MG_MQTT_EVENT_BASE + MG_MQTT_CMD_PINGREQ)

Definition at line 2928 of file mongoose6.h.

◆ MG_EV_MQTT_PINGRESP

#define MG_EV_MQTT_PINGRESP   (MG_MQTT_EVENT_BASE + MG_MQTT_CMD_PINGRESP)

Definition at line 2929 of file mongoose6.h.

◆ MG_EV_MQTT_PUBACK

#define MG_EV_MQTT_PUBACK   (MG_MQTT_EVENT_BASE + MG_MQTT_CMD_PUBACK)

Definition at line 2920 of file mongoose6.h.

◆ MG_EV_MQTT_PUBCOMP

#define MG_EV_MQTT_PUBCOMP   (MG_MQTT_EVENT_BASE + MG_MQTT_CMD_PUBCOMP)

Definition at line 2923 of file mongoose6.h.

◆ MG_EV_MQTT_PUBLISH

#define MG_EV_MQTT_PUBLISH   (MG_MQTT_EVENT_BASE + MG_MQTT_CMD_PUBLISH)

Definition at line 2919 of file mongoose6.h.

◆ MG_EV_MQTT_PUBREC

#define MG_EV_MQTT_PUBREC   (MG_MQTT_EVENT_BASE + MG_MQTT_CMD_PUBREC)

Definition at line 2921 of file mongoose6.h.

◆ MG_EV_MQTT_PUBREL

#define MG_EV_MQTT_PUBREL   (MG_MQTT_EVENT_BASE + MG_MQTT_CMD_PUBREL)

Definition at line 2922 of file mongoose6.h.

◆ MG_EV_MQTT_SUBACK

#define MG_EV_MQTT_SUBACK   (MG_MQTT_EVENT_BASE + MG_MQTT_CMD_SUBACK)

Definition at line 2925 of file mongoose6.h.

◆ MG_EV_MQTT_SUBSCRIBE

#define MG_EV_MQTT_SUBSCRIBE   (MG_MQTT_EVENT_BASE + MG_MQTT_CMD_SUBSCRIBE)

Definition at line 2924 of file mongoose6.h.

◆ MG_EV_MQTT_UNSUBACK

#define MG_EV_MQTT_UNSUBACK   (MG_MQTT_EVENT_BASE + MG_MQTT_CMD_UNSUBACK)

Definition at line 2927 of file mongoose6.h.

◆ MG_EV_MQTT_UNSUBSCRIBE

#define MG_EV_MQTT_UNSUBSCRIBE   (MG_MQTT_EVENT_BASE + MG_MQTT_CMD_UNSUBSCRIBE)

Definition at line 2926 of file mongoose6.h.

◆ MG_EV_POLL

#define MG_EV_POLL   0 /* Sent to each connection on each mg_mgr_poll() call */

Definition at line 1219 of file mongoose6.h.

◆ MG_EV_RECV

#define MG_EV_RECV   3 /* Data has benn received. int *num_bytes */

Definition at line 1222 of file mongoose6.h.

◆ MG_EV_SEND

#define MG_EV_SEND   4 /* Data has been written to a socket. int *num_bytes */

Definition at line 1223 of file mongoose6.h.

◆ MG_EV_SSI_CALL

#define MG_EV_SSI_CALL   105 /* char * */

Definition at line 2117 of file mongoose6.h.

◆ MG_EV_TIMER

#define MG_EV_TIMER   6 /* now >= conn->ev_timer_time. double * */

Definition at line 1225 of file mongoose6.h.

◆ MG_EV_WEBSOCKET_CONTROL_FRAME

#define MG_EV_WEBSOCKET_CONTROL_FRAME   114 /* struct websocket_message * */

Definition at line 2122 of file mongoose6.h.

◆ MG_EV_WEBSOCKET_FRAME

#define MG_EV_WEBSOCKET_FRAME   113 /* struct websocket_message * */

Definition at line 2121 of file mongoose6.h.

◆ MG_EV_WEBSOCKET_HANDSHAKE_DONE

#define MG_EV_WEBSOCKET_HANDSHAKE_DONE   112 /* NULL */

Definition at line 2120 of file mongoose6.h.

◆ MG_EV_WEBSOCKET_HANDSHAKE_REQUEST

#define MG_EV_WEBSOCKET_HANDSHAKE_REQUEST   111 /* NULL */

Definition at line 2119 of file mongoose6.h.

◆ MG_F_CLOSE_IMMEDIATELY

#define MG_F_CLOSE_IMMEDIATELY   (1 << 11) /* Disconnect */

Definition at line 1289 of file mongoose6.h.

◆ MG_F_CONNECTING

#define MG_F_CONNECTING   (1 << 3) /* connect() call in progress */

Definition at line 1281 of file mongoose6.h.

◆ MG_F_DELETE_CHUNK

#define MG_F_DELETE_CHUNK   (1 << 13) /* HTTP specific */

Definition at line 1291 of file mongoose6.h.

◆ MG_F_IS_WEBSOCKET

#define MG_F_IS_WEBSOCKET   (1 << 7) /* Websocket specific */

Definition at line 1285 of file mongoose6.h.

◆ MG_F_LISTENING

#define MG_F_LISTENING   (1 << 0) /* This connection is listening */

Definition at line 1278 of file mongoose6.h.

◆ MG_F_RESOLVING

#define MG_F_RESOLVING   (1 << 2) /* Waiting for async resolver */

Definition at line 1280 of file mongoose6.h.

◆ MG_F_SEND_AND_CLOSE

#define MG_F_SEND_AND_CLOSE   (1 << 10) /* Push remaining data and close */

Definition at line 1288 of file mongoose6.h.

◆ MG_F_SSL_HANDSHAKE_DONE

#define MG_F_SSL_HANDSHAKE_DONE   (1 << 4) /* SSL specific */

Definition at line 1282 of file mongoose6.h.

◆ MG_F_UDP

#define MG_F_UDP   (1 << 1) /* This connection is UDP */

Definition at line 1279 of file mongoose6.h.

◆ MG_F_USER_1

#define MG_F_USER_1   (1 << 20) /* Flags left for application */

Definition at line 1293 of file mongoose6.h.

◆ MG_F_USER_2

#define MG_F_USER_2   (1 << 21)

Definition at line 1294 of file mongoose6.h.

◆ MG_F_USER_3

#define MG_F_USER_3   (1 << 22)

Definition at line 1295 of file mongoose6.h.

◆ MG_F_USER_4

#define MG_F_USER_4   (1 << 23)

Definition at line 1296 of file mongoose6.h.

◆ MG_F_USER_5

#define MG_F_USER_5   (1 << 24)

Definition at line 1297 of file mongoose6.h.

◆ MG_F_USER_6

#define MG_F_USER_6   (1 << 25)

Definition at line 1298 of file mongoose6.h.

◆ MG_F_WANT_READ

#define MG_F_WANT_READ   (1 << 5) /* SSL specific */

Definition at line 1283 of file mongoose6.h.

◆ MG_F_WANT_WRITE

#define MG_F_WANT_WRITE   (1 << 6) /* SSL specific */

Definition at line 1284 of file mongoose6.h.

◆ MG_F_WEBSOCKET_NO_DEFRAG

#define MG_F_WEBSOCKET_NO_DEFRAG   (1 << 12) /* Websocket specific */

Definition at line 1290 of file mongoose6.h.

◆ MG_MAX_CGI_ENVIR_VARS

#define MG_MAX_CGI_ENVIR_VARS   64

Definition at line 2059 of file mongoose6.h.

◆ MG_MAX_DNS_ANSWERS

#define MG_MAX_DNS_ANSWERS   32

Definition at line 3169 of file mongoose6.h.

◆ MG_MAX_DNS_QUESTIONS

#define MG_MAX_DNS_QUESTIONS   32

Definition at line 3168 of file mongoose6.h.

◆ MG_MAX_HTTP_HEADERS

#define MG_MAX_HTTP_HEADERS   20

Definition at line 2031 of file mongoose6.h.

◆ MG_MAX_HTTP_REQUEST_SIZE

#define MG_MAX_HTTP_REQUEST_SIZE   1024

Definition at line 2035 of file mongoose6.h.

◆ MG_MAX_HTTP_SEND_MBUF

#define MG_MAX_HTTP_SEND_MBUF   1024

Definition at line 2047 of file mongoose6.h.

◆ MG_MAX_PATH

#define MG_MAX_PATH   256

Definition at line 2042 of file mongoose6.h.

◆ MG_MK_STR

#define MG_MK_STR (   str_literal)     { str_literal, sizeof(str_literal) - 1 }

Definition at line 2006 of file mongoose6.h.

2007 { str_literal, sizeof(str_literal) - 1 }

◆ MG_MQTT_CLEAN_SESSION

#define MG_MQTT_CLEAN_SESSION   0x02

Definition at line 2940 of file mongoose6.h.

◆ MG_MQTT_CMD_CONNACK

#define MG_MQTT_CMD_CONNACK   2

Definition at line 2901 of file mongoose6.h.

◆ MG_MQTT_CMD_CONNECT

#define MG_MQTT_CMD_CONNECT   1

Definition at line 2900 of file mongoose6.h.

◆ MG_MQTT_CMD_DISCONNECT

#define MG_MQTT_CMD_DISCONNECT   14

Definition at line 2913 of file mongoose6.h.

◆ MG_MQTT_CMD_PINGREQ

#define MG_MQTT_CMD_PINGREQ   12

Definition at line 2911 of file mongoose6.h.

◆ MG_MQTT_CMD_PINGRESP

#define MG_MQTT_CMD_PINGRESP   13

Definition at line 2912 of file mongoose6.h.

◆ MG_MQTT_CMD_PUBACK

#define MG_MQTT_CMD_PUBACK   4

Definition at line 2903 of file mongoose6.h.

◆ MG_MQTT_CMD_PUBCOMP

#define MG_MQTT_CMD_PUBCOMP   7

Definition at line 2906 of file mongoose6.h.

◆ MG_MQTT_CMD_PUBLISH

#define MG_MQTT_CMD_PUBLISH   3

Definition at line 2902 of file mongoose6.h.

◆ MG_MQTT_CMD_PUBREC

#define MG_MQTT_CMD_PUBREC   5

Definition at line 2904 of file mongoose6.h.

◆ MG_MQTT_CMD_PUBREL

#define MG_MQTT_CMD_PUBREL   6

Definition at line 2905 of file mongoose6.h.

◆ MG_MQTT_CMD_SUBACK

#define MG_MQTT_CMD_SUBACK   9

Definition at line 2908 of file mongoose6.h.

◆ MG_MQTT_CMD_SUBSCRIBE

#define MG_MQTT_CMD_SUBSCRIBE   8

Definition at line 2907 of file mongoose6.h.

◆ MG_MQTT_CMD_UNSUBACK

#define MG_MQTT_CMD_UNSUBACK   11

Definition at line 2910 of file mongoose6.h.

◆ MG_MQTT_CMD_UNSUBSCRIBE

#define MG_MQTT_CMD_UNSUBSCRIBE   10

Definition at line 2909 of file mongoose6.h.

◆ MG_MQTT_DUP

#define MG_MQTT_DUP   0x4

Definition at line 2934 of file mongoose6.h.

◆ MG_MQTT_EVENT_BASE

#define MG_MQTT_EVENT_BASE   200

Definition at line 2916 of file mongoose6.h.

◆ MG_MQTT_GET_QOS

#define MG_MQTT_GET_QOS (   flags)    (((flags) &0x6) >> 1)

Definition at line 2936 of file mongoose6.h.

◆ MG_MQTT_GET_WILL_QOS

#define MG_MQTT_GET_WILL_QOS (   flags)    (((flags) &0x18) >> 3)

Definition at line 2945 of file mongoose6.h.

◆ MG_MQTT_HAS_PASSWORD

#define MG_MQTT_HAS_PASSWORD   0x40

Definition at line 2943 of file mongoose6.h.

◆ MG_MQTT_HAS_USER_NAME

#define MG_MQTT_HAS_USER_NAME   0x80

Definition at line 2944 of file mongoose6.h.

◆ MG_MQTT_HAS_WILL

#define MG_MQTT_HAS_WILL   0x04

Definition at line 2941 of file mongoose6.h.

◆ MG_MQTT_QOS

#define MG_MQTT_QOS (   qos)    ((qos) << 1)

Definition at line 2935 of file mongoose6.h.

◆ MG_MQTT_RETAIN

#define MG_MQTT_RETAIN   0x1

Definition at line 2933 of file mongoose6.h.

◆ MG_MQTT_SET_QOS

#define MG_MQTT_SET_QOS (   flags,
  qos 
)    (flags) = ((flags) & ~0x6) | ((qos) << 1)

Definition at line 2937 of file mongoose6.h.

◆ MG_MQTT_SET_WILL_QOS

#define MG_MQTT_SET_WILL_QOS (   flags,
  qos 
)     (flags) = ((flags) & ~0x18) | ((qos) << 3)

Definition at line 2946 of file mongoose6.h.

◆ MG_MQTT_WILL_RETAIN

#define MG_MQTT_WILL_RETAIN   0x20

Definition at line 2942 of file mongoose6.h.

◆ MG_RECV_FUNC

#define MG_RECV_FUNC (   s,
  b,
  l,
 
)    recv(s, b, l, f)

Definition at line 1186 of file mongoose6.h.

◆ MG_SEND_FUNC

#define MG_SEND_FUNC (   s,
  b,
  l,
 
)    send(s, b, l, f)

Definition at line 1187 of file mongoose6.h.

◆ MG_SOCK_STRINGIFY_IP

#define MG_SOCK_STRINGIFY_IP   1

Definition at line 1904 of file mongoose6.h.

◆ MG_SOCK_STRINGIFY_PORT

#define MG_SOCK_STRINGIFY_PORT   2

Definition at line 1905 of file mongoose6.h.

◆ MG_SOCK_STRINGIFY_REMOTE

#define MG_SOCK_STRINGIFY_REMOTE   4

Definition at line 1906 of file mongoose6.h.

◆ MG_VERSION

#define MG_VERSION   "6.4"

Definition at line 26 of file mongoose6.h.

◆ MG_VPRINTF_BUFFER_SIZE

#define MG_VPRINTF_BUFFER_SIZE   100

Definition at line 1179 of file mongoose6.h.

◆ MG_WEBSOCKET_PING_INTERVAL_SECONDS

#define MG_WEBSOCKET_PING_INTERVAL_SECONDS   5

Definition at line 2051 of file mongoose6.h.

◆ NOINLINE

#define NOINLINE

Definition at line 114 of file mongoose6.h.

◆ NORETURN

#define NORETURN

Definition at line 112 of file mongoose6.h.

◆ UNUSED

#define UNUSED

Definition at line 113 of file mongoose6.h.

◆ WARN_UNUSED_RESULT

#define WARN_UNUSED_RESULT

Definition at line 115 of file mongoose6.h.

◆ WEBSOCKET_DONT_FIN

#define WEBSOCKET_DONT_FIN   0x100

Definition at line 2365 of file mongoose6.h.

◆ WEBSOCKET_OP_BINARY

#define WEBSOCKET_OP_BINARY   2

Definition at line 2348 of file mongoose6.h.

◆ WEBSOCKET_OP_CLOSE

#define WEBSOCKET_OP_CLOSE   8

Definition at line 2349 of file mongoose6.h.

◆ WEBSOCKET_OP_CONTINUE

#define WEBSOCKET_OP_CONTINUE   0

Definition at line 2346 of file mongoose6.h.

◆ WEBSOCKET_OP_PING

#define WEBSOCKET_OP_PING   9

Definition at line 2350 of file mongoose6.h.

◆ WEBSOCKET_OP_PONG

#define WEBSOCKET_OP_PONG   10

Definition at line 2351 of file mongoose6.h.

◆ WEBSOCKET_OP_TEXT

#define WEBSOCKET_OP_TEXT   1

Definition at line 2347 of file mongoose6.h.

Typedef Documentation

◆ cs_base64_putc_t

typedef void(* cs_base64_putc_t) (char, void *)

Definition at line 977 of file mongoose6.h.

◆ MD5_CTX

◆ mg_event_handler_t

typedef void(* mg_event_handler_t) (struct mg_connection *, int ev, void *)

Definition at line 1216 of file mongoose6.h.

◆ mg_resolve_callback_t

typedef void(* mg_resolve_callback_t) (struct mg_dns_message *dns_message, void *user_data, enum mg_resolve_err)

Definition at line 3416 of file mongoose6.h.

◆ mg_rpc_handler_t

typedef int(* mg_rpc_handler_t) (char *buf, int len, struct mg_rpc_request *req)

Definition at line 2830 of file mongoose6.h.

◆ SSL

Definition at line 1174 of file mongoose6.h.

◆ SSL_CTX

Definition at line 1175 of file mongoose6.h.

Enumeration Type Documentation

◆ cs_log_level

Enumerator
LL_NONE 
LL_ERROR 
LL_WARN 
LL_INFO 
LL_DEBUG 
LL_VERBOSE_DEBUG 
_LL_MIN 
_LL_MAX 

Definition at line 741 of file mongoose6.h.

741 {
742 LL_NONE = -1,
743 LL_ERROR = 0,
744 LL_WARN = 1,
745 LL_INFO = 2,
746 LL_DEBUG = 3,
748
749 _LL_MIN = -2,
750 _LL_MAX = 5,
751};
@ LL_INFO
Definition mongoose6.h:745
@ LL_DEBUG
Definition mongoose6.h:746
@ LL_ERROR
Definition mongoose6.h:743
@ LL_NONE
Definition mongoose6.h:742
@ _LL_MAX
Definition mongoose6.h:750
@ LL_WARN
Definition mongoose6.h:744
@ _LL_MIN
Definition mongoose6.h:749

◆ json_type

Enumerator
JSON_TYPE_EOF 
JSON_TYPE_STRING 
JSON_TYPE_NUMBER 
JSON_TYPE_OBJECT 
JSON_TYPE_TRUE 
JSON_TYPE_FALSE 
JSON_TYPE_NULL 
JSON_TYPE_ARRAY 

Definition at line 1060 of file mongoose6.h.

1060 {
1061 JSON_TYPE_EOF = 0, /* End of parsed tokens marker */
1062 JSON_TYPE_STRING = 1,
1063 JSON_TYPE_NUMBER = 2,
1064 JSON_TYPE_OBJECT = 3,
1065 JSON_TYPE_TRUE = 4,
1066 JSON_TYPE_FALSE = 5,
1067 JSON_TYPE_NULL = 6,
1068 JSON_TYPE_ARRAY = 7
1069};
@ JSON_TYPE_STRING
Definition mongoose6.h:1062
@ JSON_TYPE_TRUE
Definition mongoose6.h:1065
@ JSON_TYPE_OBJECT
Definition mongoose6.h:1064
@ JSON_TYPE_NUMBER
Definition mongoose6.h:1063
@ JSON_TYPE_ARRAY
Definition mongoose6.h:1068
@ JSON_TYPE_EOF
Definition mongoose6.h:1061
@ JSON_TYPE_FALSE
Definition mongoose6.h:1066
@ JSON_TYPE_NULL
Definition mongoose6.h:1067

◆ mg_dns_resource_record_kind

Enumerator
MG_DNS_INVALID_RECORD 
MG_DNS_QUESTION 
MG_DNS_ANSWER 

Definition at line 3173 of file mongoose6.h.

3173 {
3177};
@ MG_DNS_INVALID_RECORD
Definition mongoose6.h:3174
@ MG_DNS_ANSWER
Definition mongoose6.h:3176
@ MG_DNS_QUESTION
Definition mongoose6.h:3175

◆ mg_resolve_err

Enumerator
MG_RESOLVE_OK 
MG_RESOLVE_NO_ANSWERS 
MG_RESOLVE_EXCEEDED_RETRY_COUNT 
MG_RESOLVE_TIMEOUT 

Definition at line 3409 of file mongoose6.h.

3409 {
3410 MG_RESOLVE_OK = 0,
3414};
@ MG_RESOLVE_TIMEOUT
Definition mongoose6.h:3413
@ MG_RESOLVE_EXCEEDED_RETRY_COUNT
Definition mongoose6.h:3412
@ MG_RESOLVE_OK
Definition mongoose6.h:3410
@ MG_RESOLVE_NO_ANSWERS
Definition mongoose6.h:3411

Function Documentation

◆ c_snprintf()

int c_snprintf ( char buf,
size_t  buf_size,
const char format,
  ... 
)

Definition at line 2061 of file mongoose614.cxx.

2061 {
2062 int result;
2063 va_list ap;
2064 va_start(ap, fmt);
2065 result = c_vsnprintf(buf, buf_size, fmt, ap);
2066 va_end(ap);
2067 return result;
2068}
int c_vsnprintf(char *buf, size_t buf_size, const char *fmt, va_list ap) WEAK
Here is the call graph for this function:

◆ c_strnlen()

size_t c_strnlen ( const char s,
size_t  maxlen 
)

Definition at line 1860 of file mongoose614.cxx.

1860 {
1861 size_t l = 0;
1862 for (; l < maxlen && s[l] != '\0'; l++) {
1863 }
1864 return l;
1865}
Here is the call graph for this function:

◆ c_strnstr()

const char * c_strnstr ( const char s,
const char find,
size_t  slen 
)

Definition at line 2102 of file mongoose614.cxx.

2102 {
2103 size_t find_length = strlen(find);
2104 size_t i;
2105
2106 for (i = 0; i < slen; i++) {
2107 if (i + find_length > slen) {
2108 return NULL;
2109 }
2110
2111 if (strncmp(&s[i], find, find_length) == 0) {
2112 return &s[i];
2113 }
2114 }
2115
2116 return NULL;
2117}
INT i
Definition mdump.cxx:32
Here is the call graph for this function:

◆ c_vsnprintf()

int c_vsnprintf ( char buf,
size_t  buf_size,
const char format,
va_list  ap 
)

Definition at line 1923 of file mongoose614.cxx.

1923 {
1924 int ch, i = 0, len_mod, flags, precision, field_width;
1925
1926 while ((ch = *fmt++) != '\0') {
1927 if (ch != '%') {
1929 } else {
1930 /*
1931 * Conversion specification:
1932 * zero or more flags (one of: # 0 - <space> + ')
1933 * an optional minimum field width (digits)
1934 * an optional precision (. followed by digits, or *)
1935 * an optional length modifier (one of: hh h l ll L q j z t)
1936 * conversion specifier (one of: d i o u x X e E f F g G a A c s p n)
1937 */
1938 flags = field_width = precision = len_mod = 0;
1939
1940 /* Flags. only zero-pad flag is supported. */
1941 if (*fmt == '0') {
1942 flags |= C_SNPRINTF_FLAG_ZERO;
1943 }
1944
1945 /* Field width */
1946 while (*fmt >= '0' && *fmt <= '9') {
1947 field_width *= 10;
1948 field_width += *fmt++ - '0';
1949 }
1950 /* Dynamic field width */
1951 if (*fmt == '*') {
1952 field_width = va_arg(ap, int);
1953 fmt++;
1954 }
1955
1956 /* Precision */
1957 if (*fmt == '.') {
1958 fmt++;
1959 if (*fmt == '*') {
1960 precision = va_arg(ap, int);
1961 fmt++;
1962 } else {
1963 while (*fmt >= '0' && *fmt <= '9') {
1964 precision *= 10;
1965 precision += *fmt++ - '0';
1966 }
1967 }
1968 }
1969
1970 /* Length modifier */
1971 switch (*fmt) {
1972 case 'h':
1973 case 'l':
1974 case 'L':
1975 case 'I':
1976 case 'q':
1977 case 'j':
1978 case 'z':
1979 case 't':
1980 len_mod = *fmt++;
1981 if (*fmt == 'h') {
1982 len_mod = 'H';
1983 fmt++;
1984 }
1985 if (*fmt == 'l') {
1986 len_mod = 'q';
1987 fmt++;
1988 }
1989 break;
1990 }
1991
1992 ch = *fmt++;
1993 if (ch == 's') {
1994 const char *s = va_arg(ap, const char *); /* Always fetch parameter */
1995 int j;
1996 int pad = field_width - (precision >= 0 ? c_strnlen(s, precision) : 0);
1997 for (j = 0; j < pad; j++) {
1999 }
2000
2001 /* `s` may be NULL in case of %.*s */
2002 if (s != NULL) {
2003 /* Ignore negative and 0 precisions */
2004 for (j = 0; (precision <= 0 || j < precision) && s[j] != '\0'; j++) {
2006 }
2007 }
2008 } else if (ch == 'c') {
2009 ch = va_arg(ap, int); /* Always fetch parameter */
2011 } else if (ch == 'd' && len_mod == 0) {
2012 i += c_itoa(buf + i, buf_size - i, va_arg(ap, int), 10, flags,
2013 field_width);
2014 } else if (ch == 'd' && len_mod == 'l') {
2015 i += c_itoa(buf + i, buf_size - i, va_arg(ap, long), 10, flags,
2016 field_width);
2017#ifdef SSIZE_MAX
2018 } else if (ch == 'd' && len_mod == 'z') {
2019 i += c_itoa(buf + i, buf_size - i, va_arg(ap, ssize_t), 10, flags,
2020 field_width);
2021#endif
2022 } else if (ch == 'd' && len_mod == 'q') {
2023 i += c_itoa(buf + i, buf_size - i, va_arg(ap, int64_t), 10, flags,
2024 field_width);
2025 } else if ((ch == 'x' || ch == 'u') && len_mod == 0) {
2026 i += c_itoa(buf + i, buf_size - i, va_arg(ap, unsigned),
2027 ch == 'x' ? 16 : 10, flags, field_width);
2028 } else if ((ch == 'x' || ch == 'u') && len_mod == 'l') {
2029 i += c_itoa(buf + i, buf_size - i, va_arg(ap, unsigned long),
2030 ch == 'x' ? 16 : 10, flags, field_width);
2031 } else if ((ch == 'x' || ch == 'u') && len_mod == 'z') {
2032 i += c_itoa(buf + i, buf_size - i, va_arg(ap, size_t),
2033 ch == 'x' ? 16 : 10, flags, field_width);
2034 } else if (ch == 'p') {
2035 unsigned long num = (unsigned long) (uintptr_t) va_arg(ap, void *);
2038 i += c_itoa(buf + i, buf_size - i, num, 16, flags, 0);
2039 } else {
2040#ifndef NO_LIBC
2041 /*
2042 * TODO(lsm): abort is not nice in a library, remove it
2043 * Also, ESP8266 SDK doesn't have it
2044 */
2045 abort();
2046#endif
2047 }
2048 }
2049 }
2050
2051 /* Zero-terminate the result */
2052 if (buf_size > 0) {
2053 buf[i < (int) buf_size ? i : (int) buf_size - 1] = '\0';
2054 }
2055
2056 return i;
2057}
size_t c_strnlen(const char *s, size_t maxlen) WEAK
static int c_itoa(char *buf, size_t buf_size, int64_t num, int base, int flags, int field_width)
#define C_SNPRINTF_FLAG_ZERO
#define C_SNPRINTF_APPEND_CHAR(ch)
INT j
Definition odbhist.cxx:40
Here is the call graph for this function:

◆ cs_base64_decode()

int cs_base64_decode ( const unsigned char s,
int  len,
char dst 
)

Definition at line 305 of file mongoose6.cxx.

305 {
306 unsigned char a, b, c, d;
307 int orig_len = len;
308 while (len >= 4 && (a = from_b64(s[0])) != 255 &&
309 (b = from_b64(s[1])) != 255 && (c = from_b64(s[2])) != 255 &&
310 (d = from_b64(s[3])) != 255) {
311 s += 4;
312 len -= 4;
313 if (a == 200 || b == 200) break; /* '=' can't be there */
314 *dst++ = a << 2 | b >> 4;
315 if (c == 200) break;
316 *dst++ = b << 4 | c >> 2;
317 if (d == 200) break;
318 *dst++ = c << 6 | d;
319 }
320 *dst = 0;
321 return orig_len - len;
322}
static unsigned char from_b64(unsigned char ch)
double d
Definition system.cxx:1311
char c
Definition system.cxx:1310
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cs_base64_encode()

void cs_base64_encode ( const unsigned char src,
int  src_len,
char dst 
)

Definition at line 241 of file mongoose6.cxx.

241 {
243}
#define BASE64_ENCODE_BODY

◆ cs_base64_finish()

void cs_base64_finish ( struct cs_base64_ctx ctx)

Definition at line 195 of file mongoose6.cxx.

195 {
196 if (ctx->chunk_size > 0) {
197 int i;
198 memset(&ctx->chunk[ctx->chunk_size], 0, 3 - ctx->chunk_size);
200 for (i = 0; i < (3 - ctx->chunk_size); i++) {
201 ctx->b64_putc('=', ctx->user_data);
202 }
203 }
204}
void * user_data
Definition mongoose6.h:984
cs_base64_putc_t b64_putc
Definition mongoose6.h:981
unsigned char chunk[3]
Definition mongoose6.h:982
static void cs_base64_emit_chunk(struct cs_base64_ctx *ctx)
Here is the call graph for this function:

◆ cs_base64_init()

void cs_base64_init ( struct cs_base64_ctx ctx,
cs_base64_putc_t  putc,
void user_data 
)

Definition at line 176 of file mongoose6.cxx.

177 {
178 ctx->chunk_size = 0;
179 ctx->b64_putc = b64_putc;
180 ctx->user_data = user_data;
181}

◆ cs_base64_update()

void cs_base64_update ( struct cs_base64_ctx ctx,
const char str,
size_t  len 
)

Definition at line 183 of file mongoose6.cxx.

183 {
184 const unsigned char *src = (const unsigned char *) str;
185 size_t i;
186 for (i = 0; i < len; i++) {
187 ctx->chunk[ctx->chunk_size++] = src[i];
188 if (ctx->chunk_size == 3) {
190 ctx->chunk_size = 0;
191 }
192 }
193}
char str[256]
Definition odbhist.cxx:33
Here is the call graph for this function:

◆ cs_fprint_base64()

void cs_fprint_base64 ( FILE f,
const unsigned char src,
int  src_len 
)

Definition at line 257 of file mongoose6.cxx.

257 {
259}

◆ cs_hmac_sha1()

void cs_hmac_sha1 ( const unsigned char key,
size_t  key_len,
const unsigned char text,
size_t  text_len,
unsigned char  out[20] 
)

Definition at line 1714 of file mongoose6.cxx.

1716 {
1717 cs_sha1_ctx ctx;
1718 unsigned char buf1[64], buf2[64], tmp_key[20], i;
1719
1720 if (keylen > sizeof(buf1)) {
1721 cs_sha1_init(&ctx);
1722 cs_sha1_update(&ctx, key, keylen);
1723 cs_sha1_final(tmp_key, &ctx);
1724 key = tmp_key;
1725 keylen = sizeof(tmp_key);
1726 }
1727
1728 memset(buf1, 0, sizeof(buf1));
1729 memset(buf2, 0, sizeof(buf2));
1730 memcpy(buf1, key, keylen);
1731 memcpy(buf2, key, keylen);
1732
1733 for (i = 0; i < sizeof(buf1); i++) {
1734 buf1[i] ^= 0x36;
1735 buf2[i] ^= 0x5c;
1736 }
1737
1738 cs_sha1_init(&ctx);
1739 cs_sha1_update(&ctx, buf1, sizeof(buf1));
1740 cs_sha1_update(&ctx, data, datalen);
1741 cs_sha1_final(out, &ctx);
1742
1743 cs_sha1_init(&ctx);
1744 cs_sha1_update(&ctx, buf2, sizeof(buf2));
1745 cs_sha1_update(&ctx, out, 20);
1746 cs_sha1_final(out, &ctx);
1747}
void cs_sha1_final(unsigned char digest[20], cs_sha1_ctx *context)
void cs_sha1_update(cs_sha1_ctx *context, const unsigned char *data, uint32_t len)
void cs_sha1_init(cs_sha1_ctx *context)
void * data
Definition mana.cxx:268
KEY key
Definition mdump.cxx:34
Here is the call graph for this function:

◆ cs_log_print_prefix()

void cs_log_print_prefix ( const char func)

Definition at line 355 of file mongoose6.cxx.

355 {
357 fprintf(cs_log_file, "%-20s ", func);
358#ifdef CS_LOG_TS_DIFF
359 {
360 double now = cs_time();
361 fprintf(cs_log_file, "%7u ", (unsigned int) ((now - cs_log_ts) * 1000000));
362 cs_log_ts = now;
363 }
364#endif
365}
double cs_time()
FILE * cs_log_file
Here is the call graph for this function:

◆ cs_log_printf()

void cs_log_printf ( const char fmt,
  ... 
)

Definition at line 367 of file mongoose6.cxx.

367 {
368 va_list ap;
369 va_start(ap, fmt);
370 vfprintf(cs_log_file, fmt, ap);
371 va_end(ap);
372 fputc('\n', cs_log_file);
374}
Here is the call graph for this function:

◆ cs_log_set_file()

void cs_log_set_file ( FILE file)

Definition at line 376 of file mongoose6.cxx.

376 {
378}

◆ cs_log_set_level()

void cs_log_set_level ( enum cs_log_level  level)

Definition at line 723 of file mongoose614.cxx.

723 {
725#if CS_LOG_ENABLE_TS_DIFF && CS_ENABLE_STDIO
726 cs_log_ts = cs_time();
727#endif
728}
Here is the call graph for this function:

◆ cs_md5()

char * cs_md5 ( char  buf[33],
  ... 
)

Definition at line 1377 of file mongoose6.cxx.

1377 {
1378 unsigned char hash[16];
1379 const unsigned char *p;
1380 va_list ap;
1381 MD5_CTX ctx;
1382
1383 MD5_Init(&ctx);
1384
1385 va_start(ap, buf);
1386 while ((p = va_arg(ap, const unsigned char *) ) != NULL) {
1387 size_t len = va_arg(ap, size_t);
1388 MD5_Update(&ctx, p, len);
1389 }
1390 va_end(ap);
1391
1392 MD5_Final(hash, &ctx);
1393 cs_to_hex(buf, hash, sizeof(hash));
1394
1395 return buf;
1396}
void MD5_Init(MD5_CTX *ctx)
void cs_to_hex(char *to, const unsigned char *p, size_t len)
void MD5_Update(MD5_CTX *ctx, const unsigned char *buf, size_t len)
void MD5_Final(unsigned char digest[16], MD5_CTX *ctx)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cs_sha1_final()

void cs_sha1_final ( unsigned char  digest[20],
cs_sha1_ctx context 
)

Definition at line 1690 of file mongoose6.cxx.

1690 {
1691 unsigned i;
1692 unsigned char finalcount[8], c;
1693
1694 for (i = 0; i < 8; i++) {
1695 finalcount[i] = (unsigned char) ((context->count[(i >= 4 ? 0 : 1)] >>
1696 ((3 - (i & 3)) * 8)) &
1697 255);
1698 }
1699 c = 0200;
1700 cs_sha1_update(context, &c, 1);
1701 while ((context->count[0] & 504) != 448) {
1702 c = 0000;
1703 cs_sha1_update(context, &c, 1);
1704 }
1705 cs_sha1_update(context, finalcount, 8);
1706 for (i = 0; i < 20; i++) {
1707 digest[i] =
1708 (unsigned char) ((context->state[i >> 2] >> ((3 - (i & 3)) * 8)) & 255);
1709 }
1710 memset(context, '\0', sizeof(*context));
1711 memset(&finalcount, '\0', sizeof(finalcount));
1712}
uint32_t state[5]
Definition mongoose6.h:899
uint32_t count[2]
Definition mongoose6.h:900
Here is the call graph for this function:

◆ cs_sha1_init()

void cs_sha1_init ( cs_sha1_ctx context)

Definition at line 1661 of file mongoose6.cxx.

1661 {
1662 context->state[0] = 0x67452301;
1663 context->state[1] = 0xEFCDAB89;
1664 context->state[2] = 0x98BADCFE;
1665 context->state[3] = 0x10325476;
1666 context->state[4] = 0xC3D2E1F0;
1667 context->count[0] = context->count[1] = 0;
1668}

◆ cs_sha1_update()

void cs_sha1_update ( cs_sha1_ctx context,
const unsigned char data,
uint32_t  len 
)

Definition at line 1670 of file mongoose6.cxx.

1671 {
1672 uint32_t i, j;
1673
1674 j = context->count[0];
1675 if ((context->count[0] += len << 3) < j) context->count[1]++;
1676 context->count[1] += (len >> 29);
1677 j = (j >> 3) & 63;
1678 if ((j + len) > 63) {
1679 memcpy(&context->buffer[j], data, (i = 64 - j));
1680 cs_sha1_transform(context->state, context->buffer);
1681 for (; i + 63 < len; i += 64) {
1682 cs_sha1_transform(context->state, &data[i]);
1683 }
1684 j = 0;
1685 } else
1686 i = 0;
1687 memcpy(&context->buffer[j], &data[i], len - i);
1688}
unsigned char buffer[64]
Definition mongoose6.h:901
void cs_sha1_transform(uint32_t state[5], const unsigned char buffer[64])
Here is the call graph for this function:

◆ cs_time()

double cs_time ( void  )

Definition at line 931 of file mongoose614.cxx.

931 {
932 double now;
933#ifndef _WIN32
934 struct timeval tv;
935 if (gettimeofday(&tv, NULL /* tz */) != 0) return 0;
936 now = (double) tv.tv_sec + (((double) tv.tv_usec) / 1000000.0);
937#else
942 /*
943 * 1. VC 6.0 doesn't support conversion uint64 -> double, so, using int64
944 * This should not cause a problems in this (21th) century
945 * 2. Windows FILETIME is a number of 100-nanosecond intervals since January
946 * 1, 1601 while time_t is a number of _seconds_ since January 1, 1970 UTC,
947 * thus, we need to convert to seconds and adjust amount (subtract 11644473600
948 * seconds)
949 */
950 now = (double) (((int64_t) ftime.dwLowDateTime +
951 ((int64_t) ftime.dwHighDateTime << 32)) /
952 10000000.0) -
953 11644473600;
954#endif /* _WIN32 */
955 return now;
956}
int gettimeofday(struct timeval *tp, void *tzp)
timeval tv
Definition msysmon.cxx:1095
Here is the call graph for this function:

◆ cs_to_hex()

void cs_to_hex ( char to,
const unsigned char p,
size_t  len 
)

Definition at line 2132 of file mongoose614.cxx.

2132 {
2133 static const char *hex = "0123456789abcdef";
2134
2135 for (; len--; p++) {
2136 *to++ = hex[p[0] >> 4];
2137 *to++ = hex[p[0] & 0x0f];
2138 }
2139 *to = '\0';
2140}
Here is the call graph for this function:

◆ find_json_token()

struct json_token * find_json_token ( struct json_token toks,
const char path 
)

Definition at line 958 of file mongoose6.cxx.

958 {
959 while (path != 0 && path[0] != '\0') {
960 int i, ind2 = 0, ind = -1, skip = 2, n = path_part_len(path);
961 if (path[0] == '[') {
962 if (toks->type != JSON_TYPE_ARRAY || !is_digit(path[1])) return 0;
963 for (ind = 0, n = 1; path[n] != ']' && path[n] != '\0'; n++) {
964 if (!is_digit(path[n])) return 0;
965 ind *= 10;
966 ind += path[n] - '0';
967 }
968 if (path[n++] != ']') return 0;
969 skip = 1; /* In objects, we skip 2 elems while iterating, in arrays 1. */
970 } else if (toks->type != JSON_TYPE_OBJECT)
971 return 0;
972 toks++;
973 for (i = 0; i < toks[-1].num_desc; i += skip, ind2++) {
974 /* ind == -1 indicated that we're iterating an array, not object */
975 if (ind == -1 && toks[i].type != JSON_TYPE_STRING) return 0;
976 if (ind2 == ind ||
977 (ind == -1 && toks[i].len == n && compare(path, toks[i].ptr, n))) {
978 i += skip - 1;
979 break;
980 };
981 if (toks[i - 1 + skip].type == JSON_TYPE_ARRAY ||
982 toks[i - 1 + skip].type == JSON_TYPE_OBJECT) {
983 i += toks[i - 1 + skip].num_desc;
984 }
985 }
986 if (i == toks[-1].num_desc) return 0;
987 path += n;
988 if (path[0] == '.') path++;
989 if (path[0] == '\0') return &toks[i];
990 toks += i;
991 }
992 return 0;
993}
DWORD n[4]
Definition mana.cxx:247
INT type
Definition mana.cxx:269
static char * skip(char **buf, const char *delimiters)
static int path_part_len(const char *p)
static int compare(const char *s, const char *str, int len)
static int is_digit(int ch)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ json_emit()

int json_emit ( char buf,
int  buf_len,
const char fmt,
  ... 
)

Definition at line 1142 of file mongoose6.cxx.

1142 {
1143 int len;
1144 va_list ap;
1145
1146 va_start(ap, fmt);
1147 len = json_emit_va(buf, buf_len, fmt, ap);
1148 va_end(ap);
1149
1150 return len;
1151}
int json_emit_va(char *s, int s_len, const char *fmt, va_list ap)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ json_emit_double()

int json_emit_double ( char buf,
int  buf_len,
double  value 
)

Definition at line 1002 of file mongoose6.cxx.

1002 {
1003 char tmp[20];
1004 int n = snprintf(tmp, sizeof(tmp), "%g", value);
1005 strncpy(buf, tmp, buf_len > 0 ? buf_len : 0);
1006 return n;
1007}
double value[100]
Definition odbhist.cxx:42
Here is the call graph for this function:
Here is the caller graph for this function:

◆ json_emit_long()

int json_emit_long ( char buf,
int  buf_len,
long  value 
)

◆ json_emit_quoted_str()

int json_emit_quoted_str ( char buf,
int  buf_len,
const char str,
int  len 
)

Definition at line 1009 of file mongoose6.cxx.

1009 {
1010 const char *begin = s, *end = s + s_len, *str_end = str + len;
1011 char ch;
1012
1013#define EMIT(x) \
1014 do { \
1015 if (s < end) *s = x; \
1016 s++; \
1017 } while (0)
1018
1019 EMIT('"');
1020 while (str < str_end) {
1021 ch = *str++;
1022 switch (ch) {
1023 case '"':
1024 EMIT('\\');
1025 EMIT('"');
1026 break;
1027 case '\\':
1028 EMIT('\\');
1029 EMIT('\\');
1030 break;
1031 case '\b':
1032 EMIT('\\');
1033 EMIT('b');
1034 break;
1035 case '\f':
1036 EMIT('\\');
1037 EMIT('f');
1038 break;
1039 case '\n':
1040 EMIT('\\');
1041 EMIT('n');
1042 break;
1043 case '\r':
1044 EMIT('\\');
1045 EMIT('r');
1046 break;
1047 case '\t':
1048 EMIT('\\');
1049 EMIT('t');
1050 break;
1051 default:
1052 EMIT(ch);
1053 }
1054 }
1055 EMIT('"');
1056 if (s < end) {
1057 *s = '\0';
1058 }
1059
1060 return s - begin;
1061}
#define end
#define begin
#define EMIT(x)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ json_emit_unquoted_str()

int json_emit_unquoted_str ( char buf,
int  buf_len,
const char str,
int  len 
)

Definition at line 1063 of file mongoose6.cxx.

1063 {
1064 if (buf_len > 0 && len > 0) {
1065 int n = len < buf_len ? len : buf_len;
1066 memcpy(buf, str, n);
1067 if (n < buf_len) {
1068 buf[n] = '\0';
1069 }
1070 }
1071 return len;
1072}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ json_emit_va()

int json_emit_va ( char buf,
int  buf_len,
const char fmt,
va_list  ap 
)

Definition at line 1074 of file mongoose6.cxx.

1074 {
1075 const char *end = s + s_len, *str, *orig = s;
1076 size_t len;
1077
1078 while (*fmt != '\0') {
1079 switch (*fmt) {
1080 case '[':
1081 case ']':
1082 case '{':
1083 case '}':
1084 case ',':
1085 case ':':
1086 case ' ':
1087 case '\r':
1088 case '\n':
1089 case '\t':
1090 if (s < end) {
1091 *s = *fmt;
1092 }
1093 s++;
1094 break;
1095 case 'i':
1096 s += json_emit_long(s, end - s, va_arg(ap, long) );
1097 break;
1098 case 'f':
1099 s += json_emit_double(s, end - s, va_arg(ap, double) );
1100 break;
1101 case 'v':
1102 str = va_arg(ap, char *);
1103 len = va_arg(ap, size_t);
1104 s += json_emit_quoted_str(s, end - s, str, len);
1105 break;
1106 case 'V':
1107 str = va_arg(ap, char *);
1108 len = va_arg(ap, size_t);
1109 s += json_emit_unquoted_str(s, end - s, str, len);
1110 break;
1111 case 's':
1112 str = va_arg(ap, char *);
1113 s += json_emit_quoted_str(s, end - s, str, strlen(str));
1114 break;
1115 case 'S':
1116 str = va_arg(ap, char *);
1117 s += json_emit_unquoted_str(s, end - s, str, strlen(str));
1118 break;
1119 case 'T':
1120 s += json_emit_unquoted_str(s, end - s, "true", 4);
1121 break;
1122 case 'F':
1123 s += json_emit_unquoted_str(s, end - s, "false", 5);
1124 break;
1125 case 'N':
1126 s += json_emit_unquoted_str(s, end - s, "null", 4);
1127 break;
1128 default:
1129 return 0;
1130 }
1131 fmt++;
1132 }
1133
1134 /* Best-effort to 0-terminate generated string */
1135 if (s < end) {
1136 *s = '\0';
1137 }
1138
1139 return s - orig;
1140}
int json_emit_unquoted_str(char *buf, int buf_len, const char *str, int len)
int json_emit_double(char *buf, int buf_len, double value)
int json_emit_quoted_str(char *s, int s_len, const char *str, int len)
int json_emit_long(char *buf, int buf_len, long int value)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mbuf_append()

size_t mbuf_append ( struct mbuf a,
const void data,
size_t  data_size 
)

Definition at line 1623 of file mongoose614.cxx.

1623 {
1624 return mbuf_insert(a, a->len, buf, len);
1625}
size_t mbuf_insert(struct mbuf *a, size_t off, const void *buf, size_t) WEAK
size_t len
Definition mongoose6.h:835
Here is the call graph for this function:

◆ mbuf_free()

void mbuf_free ( struct mbuf mbuf)

Definition at line 1551 of file mongoose614.cxx.

1551 {
1552 if (mbuf->buf != NULL) {
1553 MBUF_FREE(mbuf->buf);
1554 mbuf_init(mbuf, 0);
1555 }
1556}
char * buf
Definition mongoose6.h:834
void mbuf_init(struct mbuf *mbuf, size_t initial_size) WEAK
#define MBUF_FREE
Here is the call graph for this function:

◆ mbuf_init()

void mbuf_init ( struct mbuf mbuf,
size_t  initial_capacity 
)

Definition at line 1544 of file mongoose614.cxx.

1544 {
1545 mbuf->len = mbuf->size = 0;
1546 mbuf->buf = NULL;
1548}
void mbuf_resize(struct mbuf *a, size_t new_size) WEAK
size_t size
Definition mongoose6.h:836
Here is the call graph for this function:

◆ mbuf_insert()

size_t mbuf_insert ( struct mbuf a,
size_t  off,
const void buf,
size_t  len 
)

Definition at line 1579 of file mongoose614.cxx.

1579 {
1580 char *p = NULL;
1581
1582 assert(a != NULL);
1583 assert(a->len <= a->size);
1584 assert(off <= a->len);
1585
1586 /* check overflow */
1587 if (~(size_t) 0 - (size_t) a->buf < len) return 0;
1588
1589 if (a->len + len <= a->size) {
1590 memmove(a->buf + off + len, a->buf + off, a->len - off);
1591 if (buf != NULL) {
1592 memcpy(a->buf + off, buf, len);
1593 }
1594 a->len += len;
1595 } else {
1596 size_t min_size = (a->len + len);
1600 }
1601 p = (char *) MBUF_REALLOC(a->buf, new_size);
1602 if (p == NULL && new_size != min_size) {
1604 p = (char *) MBUF_REALLOC(a->buf, new_size);
1605 }
1606 if (p != NULL) {
1607 a->buf = p;
1608 if (off != a->len) {
1609 memmove(a->buf + off + len, a->buf + off, a->len - off);
1610 }
1611 if (buf != NULL) memcpy(a->buf + off, buf, len);
1612 a->len += len;
1613 a->size = new_size;
1614 } else {
1615 len = 0;
1616 }
1617 }
1618
1619 return len;
1620}
#define MBUF_SIZE_MULTIPLIER
Definition mongoose6.h:829
#define MBUF_REALLOC
#define MBUF_SIZE_MAX_HEADROOM
Here is the call graph for this function:

◆ mbuf_remove()

void mbuf_remove ( struct mbuf mb,
size_t  data_size 
)

Definition at line 1644 of file mongoose614.cxx.

1644 {
1645 if (n > 0 && n <= mb->len) {
1646 memmove(mb->buf, mb->buf + n, mb->len - n);
1647 mb->len -= n;
1648 }
1649}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mbuf_resize()

void mbuf_resize ( struct mbuf a,
size_t  new_size 
)

Definition at line 1559 of file mongoose614.cxx.

1559 {
1560 if (new_size > a->size || (new_size < a->size && new_size >= a->len)) {
1561 char *buf = (char *) MBUF_REALLOC(a->buf, new_size);
1562 /*
1563 * In case realloc fails, there's not much we can do, except keep things as
1564 * they are. Note that NULL is a valid return value from realloc when
1565 * size == 0, but that is covered too.
1566 */
1567 if (buf == NULL && new_size != 0) return;
1568 a->buf = buf;
1569 a->size = new_size;
1570 }
1571}
Here is the call graph for this function:

◆ mbuf_trim()

void mbuf_trim ( struct mbuf mbuf)

Definition at line 1574 of file mongoose614.cxx.

1574 {
1576}
Here is the call graph for this function:

◆ MD5_Final()

void MD5_Final ( unsigned char md,
MD5_CTX c 
)

◆ MD5_Init()

void MD5_Init ( MD5_CTX c)

Definition at line 1204 of file mongoose6.cxx.

1204 {
1205 ctx->buf[0] = 0x67452301;
1206 ctx->buf[1] = 0xefcdab89;
1207 ctx->buf[2] = 0x98badcfe;
1208 ctx->buf[3] = 0x10325476;
1209
1210 ctx->bits[0] = 0;
1211 ctx->bits[1] = 0;
1212}
Here is the caller graph for this function:

◆ MD5_Update()

void MD5_Update ( MD5_CTX c,
const unsigned char data,
size_t  len 
)

Definition at line 1296 of file mongoose6.cxx.

1296 {
1297 uint32_t t;
1298
1299 t = ctx->bits[0];
1300 if ((ctx->bits[0] = t + ((uint32_t) len << 3)) < t) ctx->bits[1]++;
1301 ctx->bits[1] += (uint32_t) len >> 29;
1302
1303 t = (t >> 3) & 0x3f;
1304
1305 if (t) {
1306 unsigned char *p = (unsigned char *) ctx->in + t;
1307
1308 t = 64 - t;
1309 if (len < t) {
1310 memcpy(p, buf, len);
1311 return;
1312 }
1313 memcpy(p, buf, t);
1314 byteReverse(ctx->in, 16);
1315 MD5Transform(ctx->buf, (uint32_t *) ctx->in);
1316 buf += t;
1317 len -= t;
1318 }
1319
1320 while (len >= 64) {
1321 memcpy(ctx->in, buf, 64);
1322 byteReverse(ctx->in, 16);
1323 MD5Transform(ctx->buf, (uint32_t *) ctx->in);
1324 buf += 64;
1325 len -= 64;
1326 }
1327
1328 memcpy(ctx->in, buf, len);
1329}
static void MD5Transform(uint32_t buf[4], uint32_t const in[16])
static void byteReverse(unsigned char *buf, unsigned longs)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_add_sock()

struct mg_connection * mg_add_sock ( struct mg_mgr s,
sock_t  sock,
mg_event_handler_t  callback 
)

Definition at line 3062 of file mongoose6.cxx.

3063 {
3064 struct mg_add_sock_opts opts;
3065 memset(&opts, 0, sizeof(opts));
3066 return mg_add_sock_opt(s, sock, callback, opts);
3067}
struct mg_connection * mg_add_sock_opt(struct mg_mgr *s, sock_t sock, mg_event_handler_t callback, struct mg_add_sock_opts opts)
struct callback_addr callback
Definition mserver.cxx:22
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_add_sock_opt()

struct mg_connection * mg_add_sock_opt ( struct mg_mgr s,
sock_t  sock,
mg_event_handler_t  callback,
struct mg_add_sock_opts  opts 
)

Definition at line 3051 of file mongoose6.cxx.

3053 {
3055 if (nc != NULL) {
3056 mg_sock_set(nc, sock);
3057 mg_add_conn(nc->mgr, nc);
3058 }
3059 return nc;
3060}
void mg_sock_set(struct mg_connection *nc, sock_t sock)
struct mg_mgr * mgr
Definition mongoose6.h:1249
MG_INTERNAL struct mg_connection * mg_create_connection_base(struct mg_mgr *mgr, mg_event_handler_t callback, struct mg_add_sock_opts opts)
MG_INTERNAL void mg_add_conn(struct mg_mgr *mgr, struct mg_connection *c)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_avprintf()

int mg_avprintf ( char **  buf,
size_t  size,
const char fmt,
va_list  ap 
)

Definition at line 2213 of file mongoose614.cxx.

2213 {
2215 int len;
2216
2217 va_copy(ap_copy, ap);
2218 len = vsnprintf(*buf, size, fmt, ap_copy);
2219 va_end(ap_copy);
2220
2221 if (len < 0) {
2222 /* eCos and Windows are not standard-compliant and return -1 when
2223 * the buffer is too small. Keep allocating larger buffers until we
2224 * succeed or out of memory. */
2225 *buf = NULL; /* LCOV_EXCL_START */
2226 while (len < 0) {
2227 MG_FREE(*buf);
2228 if (size == 0) {
2229 size = 5;
2230 }
2231 size *= 2;
2232 if ((*buf = (char *) MG_MALLOC(size)) == NULL) {
2233 len = -1;
2234 break;
2235 }
2236 va_copy(ap_copy, ap);
2237 len = vsnprintf(*buf, size - 1, fmt, ap_copy);
2238 va_end(ap_copy);
2239 }
2240
2241 /*
2242 * Microsoft version of vsnprintf() is not always null-terminated, so put
2243 * the terminator manually
2244 */
2245 (*buf)[len] = 0;
2246 /* LCOV_EXCL_STOP */
2247 } else if (len >= (int) size) {
2248 /* Standard-compliant code path. Allocate a buffer that is large enough. */
2249 if ((*buf = (char *) MG_MALLOC(len + 1)) == NULL) {
2250 len = -1; /* LCOV_EXCL_LINE */
2251 } else { /* LCOV_EXCL_LINE */
2252 va_copy(ap_copy, ap);
2253 len = vsnprintf(*buf, len + 1, fmt, ap_copy);
2254 va_end(ap_copy);
2255 }
2256 }
2257
2258 return len;
2259}
#define MG_MALLOC
#define MG_FREE
Here is the call graph for this function:

◆ mg_base64_decode()

int mg_base64_decode ( const unsigned char s,
int  len,
char dst 
)

Definition at line 7878 of file mongoose6.cxx.

7878 {
7879 return cs_base64_decode(s, len, dst);
7880}
int cs_base64_decode(const unsigned char *s, int len, char *dst)
Here is the call graph for this function:

◆ mg_base64_encode()

void mg_base64_encode ( const unsigned char src,
int  src_len,
char dst 
)

Definition at line 7874 of file mongoose6.cxx.

7874 {
7875 cs_base64_encode(src, src_len, dst);
7876}
void cs_base64_encode(const unsigned char *src, int src_len, char *dst)
Here is the call graph for this function:

◆ mg_bind()

struct mg_connection * mg_bind ( struct mg_mgr srv,
const char address,
mg_event_handler_t  event_handler 
)

Definition at line 2898 of file mongoose6.cxx.

2899 {
2900 struct mg_bind_opts opts;
2901 memset(&opts, 0, sizeof(opts));
2902 return mg_bind_opt(srv, address, event_handler, opts);
2903}
struct mg_connection * mg_bind_opt(struct mg_mgr *mgr, const char *address, mg_event_handler_t callback, struct mg_bind_opts opts)
Here is the call graph for this function:

◆ mg_bind_opt()

struct mg_connection * mg_bind_opt ( struct mg_mgr mgr,
const char address,
mg_event_handler_t  handler,
struct mg_bind_opts  opts 
)

Definition at line 2905 of file mongoose6.cxx.

2907 {
2908 union socket_address sa;
2909 struct mg_connection *nc = NULL;
2910 int proto, rc;
2912 char host[MG_MAX_HOST_LEN];
2913
2915
2916 if (mg_parse_address(address, &sa, &proto, host, sizeof(host)) <= 0) {
2917 MG_SET_PTRPTR(opts.error_string, "cannot parse address");
2918 return NULL;
2919 }
2920
2922 if (nc == NULL) {
2923 return NULL;
2924 }
2925
2926 nc->sa = sa;
2927 nc->flags |= MG_F_LISTENING;
2928 if (proto == SOCK_DGRAM) {
2929 nc->flags |= MG_F_UDP;
2930 rc = mg_if_listen_udp(nc, &nc->sa);
2931 } else {
2932 rc = mg_if_listen_tcp(nc, &nc->sa);
2933 }
2934 if (rc != 0) {
2935 DBG(("Failed to open listener: %d", rc));
2936 MG_SET_PTRPTR(opts.error_string, "failed to open listener");
2937 mg_destroy_conn(nc);
2938 return NULL;
2939 }
2940#ifdef MG_ENABLE_SSL
2941 if (opts.ssl_cert != NULL || opts.ssl_ca_cert != NULL) {
2942 const char *err = mg_set_ssl(nc, opts.ssl_cert, opts.ssl_ca_cert);
2943 if (err != NULL) {
2944 MG_SET_PTRPTR(opts.error_string, err);
2945 mg_destroy_conn(nc);
2946 return NULL;
2947 }
2948 }
2949#endif /* MG_ENABLE_SSL */
2950 mg_add_conn(nc->mgr, nc);
2951
2952 return nc;
2953}
#define DBG(x)
Definition mongoose6.h:773
const char * mg_set_ssl(struct mg_connection *nc, const char *cert, const char *ca_cert)
union socket_address sa
Definition mongoose6.h:1253
#define MG_F_LISTENING
Definition mongoose6.h:1278
int mg_if_listen_udp(struct mg_connection *nc, union socket_address *sa)
#define MG_F_UDP
Definition mongoose6.h:1279
int mg_if_listen_tcp(struct mg_connection *nc, union socket_address *sa)
unsigned long flags
Definition mongoose6.h:1276
struct sockaddr sa
Definition mongoose6.h:1195
#define MG_COPY_COMMON_CONNECTION_OPTIONS(dst, src)
MG_INTERNAL struct mg_connection * mg_create_connection(struct mg_mgr *mgr, mg_event_handler_t callback, struct mg_add_sock_opts opts)
static void mg_destroy_conn(struct mg_connection *conn)
#define MG_MAX_HOST_LEN
MG_INTERNAL int mg_parse_address(const char *str, union socket_address *sa, int *proto, char *host, size_t host_len)
#define MG_SET_PTRPTR(_ptr, _v)
Definition mongoose6.cxx:37
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_broadcast()

void mg_broadcast ( struct mg_mgr mgr,
mg_event_handler_t  func,
void data,
size_t  len 
)

Definition at line 2960 of file mongoose6.cxx.

2961 {
2962 struct ctl_msg ctl_msg;
2963
2964 /*
2965 * Mongoose manager has a socketpair, `struct mg_mgr::ctl`,
2966 * where `mg_broadcast()` pushes the message.
2967 * `mg_mgr_poll()` wakes up, reads a message from the socket pair, and calls
2968 * specified callback for each connection. Thus the callback function executes
2969 * in event manager thread.
2970 */
2971 if (mgr->ctl[0] != INVALID_SOCKET && data != NULL &&
2972 len < sizeof(ctl_msg.message)) {
2973 size_t dummy;
2974
2975 ctl_msg.callback = cb;
2976 memcpy(ctl_msg.message, data, len);
2977 dummy = MG_SEND_FUNC(mgr->ctl[0], (char *) &ctl_msg,
2978 offsetof(struct ctl_msg, message) + len, 0);
2979 dummy = MG_RECV_FUNC(mgr->ctl[0], (char *) &len, 1, 0);
2980 (void) dummy; /* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=25509 */
2981 }
2982}
#define MG_SEND_FUNC(s, b, l, f)
Definition mongoose6.h:1187
sock_t ctl[2]
Definition mongoose6.h:1234
#define MG_RECV_FUNC(s, b, l, f)
Definition mongoose6.h:1186
#define message(type, str)
#define INVALID_SOCKET
char message[MG_CTL_MSG_MESSAGE_SIZE]
mg_event_handler_t callback
Here is the call graph for this function:

◆ mg_casecmp()

int mg_casecmp ( const char s1,
const char s2 
)

Definition at line 2198 of file mongoose614.cxx.

2198 {
2199 return mg_ncasecmp(s1, s2, (size_t) ~0);
2200}
int mg_ncasecmp(const char *s1, const char *s2, size_t len) WEAK
Here is the call graph for this function:

◆ mg_check_ip_acl()

int mg_check_ip_acl ( const char acl,
uint32_t  remote_ip 
)

Definition at line 3005 of file mongoose6.cxx.

3005 {
3006 int allowed, flag;
3007 uint32_t net, mask;
3008 struct mg_str vec;
3009
3010 /* If any ACL is set, deny by default */
3011 allowed = (acl == NULL || *acl == '\0') ? '+' : '-';
3012
3013 while ((acl = mg_next_comma_list_entry(acl, &vec, NULL)) != NULL) {
3014 flag = vec.p[0];
3015 if ((flag != '+' && flag != '-') ||
3016 parse_net(&vec.p[1], &net, &mask) == 0) {
3017 return -1;
3018 }
3019
3020 if (net == (remote_ip & mask)) {
3021 allowed = flag;
3022 }
3023 }
3024
3025 DBG(("%08x %c", remote_ip, allowed));
3026 return allowed == '+';
3027}
const char * mg_next_comma_list_entry(const char *list, struct mg_str *val, struct mg_str *eq_val)
#define mask(slot)
Definition midas_macro.h:54
static int parse_net(const char *spec, uint32_t *net, uint32_t *mask)
Here is the call graph for this function:

◆ mg_close_conn()

void mg_close_conn ( struct mg_connection nc)

Definition at line 2546 of file mongoose614.cxx.

2546 {
2547 /* See if there's any remaining data to deliver. Skip if user completely
2548 * throttled the connection there will be no progress anyway. */
2549 if (conn->sock != INVALID_SOCKET && mg_do_recv(conn) == -2) {
2550 /* Receive is throttled, wait. */
2551 conn->flags |= MG_F_RECV_AND_CLOSE;
2552 return;
2553 }
2554#if MG_ENABLE_SSL
2555 if (conn->flags & MG_F_SSL_HANDSHAKE_DONE) {
2557 }
2558#endif
2559 /*
2560 * Clearly mark the connection as going away (if not already).
2561 * Some net_if impls (LwIP) need this for cleanly handling half-dead conns.
2562 */
2563 conn->flags |= MG_F_CLOSE_IMMEDIATELY;
2564 mg_remove_conn(conn);
2565 conn->iface->vtable->destroy_conn(conn);
2566 mg_call(conn, NULL, conn->user_data, MG_EV_CLOSE, NULL);
2567 mg_destroy_conn(conn, 0 /* destroy_if */);
2568}
#define MG_F_CLOSE_IMMEDIATELY
Definition mongoose6.h:1289
#define MG_F_SSL_HANDSHAKE_DONE
Definition mongoose6.h:1282
#define MG_EV_CLOSE
Definition mongoose6.h:1224
MG_INTERNAL void mg_remove_conn(struct mg_connection *c)
static int mg_do_recv(struct mg_connection *nc)
void mg_destroy_conn(struct mg_connection *conn, int destroy_if)
MG_INTERNAL void mg_call(struct mg_connection *nc, mg_event_handler_t ev_handler, void *user_data, int ev, void *ev_data)
#define MG_F_RECV_AND_CLOSE
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_conn_addr_to_str()

void mg_conn_addr_to_str ( struct mg_connection nc,
char buf,
size_t  len,
int  flags 
)

Definition at line 7962 of file mongoose6.cxx.

7963 {
7964 union socket_address sa;
7965 memset(&sa, 0, sizeof(sa));
7967 mg_sock_addr_to_str(&sa, buf, len, flags);
7968}
void mg_if_get_conn_addr(struct mg_connection *nc, int remote, union socket_address *sa)
#define MG_SOCK_STRINGIFY_REMOTE
Definition mongoose6.h:1906
void mg_sock_addr_to_str(const union socket_address *sa, char *buf, size_t len, int flags)
Here is the call graph for this function:

◆ mg_connect()

struct mg_connection * mg_connect ( struct mg_mgr mgr,
const char address,
mg_event_handler_t  handler 
)

Definition at line 2814 of file mongoose6.cxx.

2815 {
2816 struct mg_connect_opts opts;
2817 memset(&opts, 0, sizeof(opts));
2818 return mg_connect_opt(mgr, address, callback, opts);
2819}
struct mg_connection * mg_connect_opt(struct mg_mgr *mgr, const char *address, mg_event_handler_t callback, struct mg_connect_opts opts)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_connect_http()

struct mg_connection * mg_connect_http ( struct mg_mgr mgr,
mg_event_handler_t  event_handler,
const char url,
const char extra_headers,
const char post_data 
)

Definition at line 7692 of file mongoose6.cxx.

7696 {
7697 struct mg_connect_opts opts;
7698 memset(&opts, 0, sizeof(opts));
7699 return mg_connect_http_opt(mgr, ev_handler, opts, url, extra_headers,
7700 post_data);
7701}
struct mg_connection * mg_connect_http_opt(struct mg_mgr *mgr, mg_event_handler_t ev_handler, struct mg_connect_opts opts, const char *url, const char *extra_headers, const char *post_data)
Here is the call graph for this function:

◆ mg_connect_http_opt()

struct mg_connection * mg_connect_http_opt ( struct mg_mgr mgr,
mg_event_handler_t  ev_handler,
struct mg_connect_opts  opts,
const char url,
const char extra_headers,
const char post_data 
)

Definition at line 7666 of file mongoose6.cxx.

7671 {
7672 char *addr = NULL;
7673 const char *path = NULL;
7675 mgr, ev_handler, opts, "http://", "https://", url, &path, &addr);
7676
7677 if (nc == NULL) {
7678 return NULL;
7679 }
7680
7681 mg_printf(nc, "%s %s HTTP/1.1\r\nHost: %s\r\nContent-Length: %" SIZE_T_FMT
7682 "\r\n%s\r\n%s",
7683 post_data == NULL ? "GET" : "POST", path, addr,
7684 post_data == NULL ? 0 : strlen(post_data),
7685 extra_headers == NULL ? "" : extra_headers,
7686 post_data == NULL ? "" : post_data);
7687
7688 MG_FREE(addr);
7689 return nc;
7690}
int mg_printf(struct mg_connection *conn, const char *fmt,...)
char addr[128]
Definition mcnaf.cxx:104
struct mg_connection * mg_connect_http_base(struct mg_mgr *mgr, mg_event_handler_t ev_handler, struct mg_connect_opts opts, const char *schema, const char *schema_ssl, const char *url, const char **path, char **addr)
#define MG_FREE
Definition mongoose6.cxx:26
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_connect_opt()

struct mg_connection * mg_connect_opt ( struct mg_mgr mgr,
const char address,
mg_event_handler_t  handler,
struct mg_connect_opts  opts 
)

Definition at line 2821 of file mongoose6.cxx.

2823 {
2824 struct mg_connection *nc = NULL;
2825 int proto, rc;
2827 char host[MG_MAX_HOST_LEN];
2828
2830
2831 if ((nc = mg_create_connection(mgr, callback, add_sock_opts)) == NULL) {
2832 return NULL;
2833 } else if ((rc = mg_parse_address(address, &nc->sa, &proto, host,
2834 sizeof(host))) < 0) {
2835 /* Address is malformed */
2836 MG_SET_PTRPTR(opts.error_string, "cannot parse address");
2837 mg_destroy_conn(nc);
2838 return NULL;
2839 }
2841 nc->flags |= (proto == SOCK_DGRAM) ? MG_F_UDP : 0;
2842 nc->user_data = opts.user_data;
2843
2844#ifdef MG_ENABLE_SSL
2845 if (opts.ssl_cert != NULL || opts.ssl_ca_cert != NULL) {
2846 const char *err = mg_set_ssl(nc, opts.ssl_cert, opts.ssl_ca_cert);
2847 if (err != NULL) {
2848 MG_SET_PTRPTR(opts.error_string, err);
2849 mg_destroy_conn(nc);
2850 return NULL;
2851 }
2852 if (opts.ssl_ca_cert != NULL && (opts.ssl_server_name == NULL ||
2853 strcmp(opts.ssl_server_name, "*") != 0)) {
2854 if (opts.ssl_server_name == NULL) opts.ssl_server_name = host;
2855#ifdef SSL_KRYPTON
2856 SSL_CTX_kr_set_verify_name(nc->ssl_ctx, opts.ssl_server_name);
2857#else
2858 /* TODO(rojer): Implement server name verification on OpenSSL. */
2859 MG_SET_PTRPTR(opts.error_string,
2860 "Server name verification requested but is not supported");
2861 mg_destroy_conn(nc);
2862 return NULL;
2863#endif /* SSL_KRYPTON */
2864 }
2865 }
2866#endif /* MG_ENABLE_SSL */
2867
2868 if (rc == 0) {
2869#ifndef MG_DISABLE_RESOLVER
2870 /*
2871 * DNS resolution is required for host.
2872 * mg_parse_address() fills port in nc->sa, which we pass to resolve_cb()
2873 */
2874 struct mg_connection *dns_conn = NULL;
2875 struct mg_resolve_async_opts o;
2876 memset(&o, 0, sizeof(o));
2877 o.dns_conn = &dns_conn;
2879 o) != 0) {
2880 MG_SET_PTRPTR(opts.error_string, "cannot schedule DNS lookup");
2881 mg_destroy_conn(nc);
2882 return NULL;
2883 }
2884 nc->priv_2 = dns_conn;
2885 nc->flags |= MG_F_RESOLVING;
2886 return nc;
2887#else
2888 MG_SET_PTRPTR(opts.error_string, "Resolver is disabled");
2889 mg_destroy_conn(nc);
2890 return NULL;
2891#endif
2892 } else {
2893 /* Address is parsed and resolved to IP. proceed with connect() */
2894 return mg_do_connect(nc, proto, &nc->sa);
2895 }
2896}
void * user_data
Definition mongoose6.h:1265
int mg_resolve_async_opt(struct mg_mgr *mgr, const char *name, int query, mg_resolve_callback_t cb, void *data, struct mg_resolve_async_opts opts)
struct mg_connection ** dns_conn
Definition mongoose6.h:3426
#define MG_DNS_A_RECORD
Definition mongoose6.h:3163
#define MG_F_RESOLVING
Definition mongoose6.h:1280
SSL_CTX * ssl_ctx
Definition mongoose6.h:1258
static void resolve_cb(struct mg_dns_message *msg, void *data, enum mg_resolve_err e)
#define _MG_ALLOWED_CONNECT_FLAGS_MASK
MG_INTERNAL struct mg_connection * mg_do_connect(struct mg_connection *nc, int proto, union socket_address *sa)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_connect_ws()

struct mg_connection * mg_connect_ws ( struct mg_mgr mgr,
mg_event_handler_t  event_handler,
const char url,
const char protocol,
const char extra_headers 
)

Definition at line 7723 of file mongoose6.cxx.

7726 {
7727 struct mg_connect_opts opts;
7728 memset(&opts, 0, sizeof(opts));
7729 return mg_connect_ws_opt(mgr, ev_handler, opts, url, protocol, extra_headers);
7730}
struct mg_connection * mg_connect_ws_opt(struct mg_mgr *mgr, mg_event_handler_t ev_handler, struct mg_connect_opts opts, const char *url, const char *protocol, const char *extra_headers)
Here is the call graph for this function:

◆ mg_connect_ws_opt()

struct mg_connection * mg_connect_ws_opt ( struct mg_mgr mgr,
mg_event_handler_t  ev_handler,
struct mg_connect_opts  opts,
const char url,
const char protocol,
const char extra_headers 
)

Definition at line 7703 of file mongoose6.cxx.

7707 {
7708 char *addr = NULL;
7709 const char *path = NULL;
7711 mgr, ev_handler, opts, "ws://", "wss://", url, &path, &addr);
7712
7713 if (nc == NULL) {
7714 return NULL;
7715 }
7716
7717 mg_send_websocket_handshake2(nc, path, addr, protocol, extra_headers);
7718
7719 MG_FREE(addr);
7720 return nc;
7721}
void mg_send_websocket_handshake2(struct mg_connection *nc, const char *path, const char *host, const char *protocol, const char *extra_headers)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_dns_copy_body()

int mg_dns_copy_body ( struct mbuf io,
struct mg_dns_message msg 
)

Definition at line 8882 of file mongoose6.cxx.

8882 {
8883 return mbuf_append(io, msg->pkt.p + sizeof(struct mg_dns_header),
8884 msg->pkt.len - sizeof(struct mg_dns_header));
8885}
size_t len
Definition mongoose6.h:1207
size_t mbuf_append(struct mbuf *a, const void *buf, size_t len)
struct mg_str pkt
Definition mongoose6.h:3191
const char * p
Definition mongoose6.h:1206
Here is the call graph for this function:

◆ mg_dns_encode_record()

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 
)

Definition at line 8916 of file mongoose6.cxx.

8918 {
8919 size_t pos = io->len;
8920 uint16_t u16;
8921 uint32_t u32;
8922
8923 if (rr->kind == MG_DNS_INVALID_RECORD) {
8924 return -1; /* LCOV_EXCL_LINE */
8925 }
8926
8927 if (mg_dns_encode_name(io, name, nlen) == -1) {
8928 return -1;
8929 }
8930
8931 u16 = htons(rr->rtype);
8932 mbuf_append(io, &u16, 2);
8933 u16 = htons(rr->rclass);
8934 mbuf_append(io, &u16, 2);
8935
8936 if (rr->kind == MG_DNS_ANSWER) {
8937 u32 = htonl(rr->ttl);
8938 mbuf_append(io, &u32, 4);
8939
8940 if (rr->rtype == MG_DNS_CNAME_RECORD) {
8941 int clen;
8942 /* fill size after encoding */
8943 size_t off = io->len;
8944 mbuf_append(io, &u16, 2);
8945 if ((clen = mg_dns_encode_name(io, (const char *) rdata, rlen)) == -1) {
8946 return -1;
8947 }
8948 u16 = clen;
8949 io->buf[off] = u16 >> 8;
8950 io->buf[off + 1] = u16 & 0xff;
8951 } else {
8952 u16 = htons(rlen);
8953 mbuf_append(io, &u16, 2);
8954 mbuf_append(io, rdata, rlen);
8955 }
8956 }
8957
8958 return io->len - pos;
8959}
#define MG_DNS_CNAME_RECORD
Definition mongoose6.h:3164
#define name(x)
Definition midas_macro.h:24
static int mg_dns_encode_name(struct mbuf *io, const char *name, size_t len)
Here is the call graph for this function:

◆ mg_dns_insert_header()

int mg_dns_insert_header ( struct mbuf io,
size_t  pos,
struct mg_dns_message msg 
)

Definition at line 8869 of file mongoose6.cxx.

8870 {
8871 struct mg_dns_header header;
8872
8873 memset(&header, 0, sizeof(header));
8874 header.transaction_id = msg->transaction_id;
8875 header.flags = htons(msg->flags);
8876 header.num_questions = htons(msg->num_questions);
8877 header.num_answers = htons(msg->num_answers);
8878
8879 return mbuf_insert(io, pos, &header, sizeof(header));
8880}
uint16_t flags
Definition mongoose6.h:3192
uint16_t transaction_id
Definition mongoose6.h:3193
Here is the call graph for this function:

◆ mg_dns_next_record()

struct mg_dns_resource_record * mg_dns_next_record ( struct mg_dns_message msg,
int  query,
struct mg_dns_resource_record prev 
)

Definition at line 8826 of file mongoose6.cxx.

8828 {
8829 struct mg_dns_resource_record *rr;
8830
8831 for (rr = (prev == NULL ? msg->answers : prev + 1);
8832 rr - msg->answers < msg->num_answers; rr++) {
8833 if (rr->rtype == query) {
8834 return rr;
8835 }
8836 }
8837 return NULL;
8838}
struct mg_dns_resource_record answers[MG_MAX_DNS_ANSWERS]
Definition mongoose6.h:3197
Here is the call graph for this function:

◆ mg_dns_parse_record_data()

int mg_dns_parse_record_data ( struct mg_dns_message msg,
struct mg_dns_resource_record rr,
void data,
size_t  data_len 
)

Definition at line 8840 of file mongoose6.cxx.

8842 {
8843 switch (rr->rtype) {
8844 case MG_DNS_A_RECORD:
8845 if (data_len < sizeof(struct in_addr)) {
8846 return -1;
8847 }
8848 if (rr->rdata.p + data_len > msg->pkt.p + msg->pkt.len) {
8849 return -1;
8850 }
8851 memcpy(data, rr->rdata.p, data_len);
8852 return 0;
8853#ifdef MG_ENABLE_IPV6
8854 case MG_DNS_AAAA_RECORD:
8855 if (data_len < sizeof(struct in6_addr)) {
8856 return -1; /* LCOV_EXCL_LINE */
8857 }
8858 memcpy(data, rr->rdata.p, data_len);
8859 return 0;
8860#endif
8862 mg_dns_uncompress_name(msg, &rr->rdata, (char *) data, data_len);
8863 return 0;
8864 }
8865
8866 return -1;
8867}
#define MG_DNS_AAAA_RECORD
Definition mongoose6.h:3165
size_t mg_dns_uncompress_name(struct mg_dns_message *msg, struct mg_str *name, char *dst, int dst_len)
Here is the call graph for this function:

◆ mg_dns_uncompress_name()

size_t mg_dns_uncompress_name ( struct mg_dns_message msg,
struct mg_str name,
char dst,
int  dst_len 
)

Definition at line 9084 of file mongoose6.cxx.

9085 {
9086 int chunk_len;
9087 char *old_dst = dst;
9088 const unsigned char *data = (unsigned char *) name->p;
9089 const unsigned char *end = (unsigned char *) msg->pkt.p + msg->pkt.len;
9090
9091 if (data >= end) {
9092 return 0;
9093 }
9094
9095 while ((chunk_len = *data++)) {
9096 int leeway = dst_len - (dst - old_dst);
9097 if (data >= end) {
9098 return 0;
9099 }
9100
9101 if (chunk_len & 0xc0) {
9102 uint16_t off = (data[-1] & (~0xc0)) << 8 | data[0];
9103 if (off >= msg->pkt.len) {
9104 return 0;
9105 }
9106 data = (unsigned char *) msg->pkt.p + off;
9107 continue;
9108 }
9109 if (chunk_len > leeway) {
9110 chunk_len = leeway;
9111 }
9112
9113 if (data + chunk_len >= end) {
9114 return 0;
9115 }
9116
9117 memcpy(dst, data, chunk_len);
9118 data += chunk_len;
9119 dst += chunk_len;
9120 leeway -= chunk_len;
9121 if (leeway == 0) {
9122 return dst - old_dst;
9123 }
9124 *dst++ = '.';
9125 }
9126
9127 if (dst != old_dst) {
9128 *--dst = 0;
9129 }
9130 return dst - old_dst;
9131}
Here is the call graph for this function:

◆ mg_enable_multithreading()

void mg_enable_multithreading ( struct mg_connection nc)

◆ mg_fopen()

static FILE * mg_fopen ( const char path,
const char mode 
)

Definition at line 2331 of file mongoose4.cxx.

2331 {
2332#ifdef _WIN32
2333 wchar_t wbuf[PATH_MAX], wmode[20];
2334 to_unicode(path, wbuf, ARRAY_SIZE(wbuf));
2336 return _wfopen(wbuf, wmode);
2337#else
2338 return fopen(path, mode);
2339#endif
2340}
#define ARRAY_SIZE(array)
#define PATH_MAX
Here is the call graph for this function:

◆ mg_get_http_header()

struct mg_str * mg_get_http_header ( struct http_message hm,
const char name 
)

Definition at line 4466 of file mongoose6.cxx.

4466 {
4467 size_t i, len = strlen(name);
4468
4469 for (i = 0; hm->header_names[i].len > 0; i++) {
4470 struct mg_str *h = &hm->header_names[i], *v = &hm->header_values[i];
4471 if (h->p != NULL && h->len == len && !mg_ncasecmp(h->p, name, len))
4472 return v;
4473 }
4474
4475 return NULL;
4476}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_get_http_var()

int mg_get_http_var ( const struct mg_str buf,
const char name,
char dst,
size_t  dst_len 
)

Definition at line 5990 of file mongoose6.cxx.

5991 {
5992 const char *p, *e, *s;
5993 size_t name_len;
5994 int len;
5995
5996 if (dst == NULL || dst_len == 0) {
5997 len = -2;
5998 } else if (buf->p == NULL || name == NULL || buf->len == 0) {
5999 len = -1;
6000 dst[0] = '\0';
6001 } else {
6002 name_len = strlen(name);
6003 e = buf->p + buf->len;
6004 len = -1;
6005 dst[0] = '\0';
6006
6007 for (p = buf->p; p + name_len < e; p++) {
6008 if ((p == buf->p || p[-1] == '&') && p[name_len] == '=' &&
6009 !mg_ncasecmp(name, p, name_len)) {
6010 p += name_len + 1;
6011 s = (const char *) memchr(p, '&', (size_t)(e - p));
6012 if (s == NULL) {
6013 s = e;
6014 }
6015 len = mg_url_decode(p, (size_t)(s - p), dst, dst_len, 1);
6016 if (len == -1) {
6017 len = -2;
6018 }
6019 break;
6020 }
6021 }
6022 }
6023
6024 return len;
6025}
int mg_url_decode(const char *src, int src_len, char *dst, int dst_len, int is_form_url_encoded)
static double e(void)
Definition tinyexpr.c:136
Here is the call graph for this function:

◆ mg_hexdump()

int mg_hexdump ( const void buf,
int  len,
char dst,
int  dst_len 
)

Definition at line 7971 of file mongoose6.cxx.

7971 {
7972 const unsigned char *p = (const unsigned char *) buf;
7973 char ascii[17] = "";
7974 int i, idx, n = 0;
7975
7976 for (i = 0; i < len; i++) {
7977 idx = i % 16;
7978 if (idx == 0) {
7979 if (i > 0) n += snprintf(dst + n, dst_len - n, " %s\n", ascii);
7980 n += snprintf(dst + n, dst_len - n, "%04x ", i);
7981 }
7982 n += snprintf(dst + n, dst_len - n, " %02x", p[i]);
7983 ascii[idx] = p[i] < 0x20 || p[i] > 0x7e ? '.' : p[i];
7984 ascii[idx + 1] = '\0';
7985 }
7986
7987 while (i++ % 16) n += snprintf(dst + n, dst_len - n, "%s", " ");
7988 n += snprintf(dst + n, dst_len - n, " %s\n\n", ascii);
7989
7990 return n;
7991}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_hexdump_connection()

void mg_hexdump_connection ( struct mg_connection nc,
const char path,
const void buf,
int  num_bytes,
int  ev 
)

Definition at line 8031 of file mongoose6.cxx.

8032 {
8033#if !defined(NO_LIBC) && !defined(MG_DISABLE_STDIO)
8034 FILE *fp = NULL;
8035 char *hexbuf, src[60], dst[60];
8036 int buf_size = num_bytes * 5 + 100;
8037
8038 if (strcmp(path, "-") == 0) {
8039 fp = stdout;
8040 } else if (strcmp(path, "--") == 0) {
8041 fp = stderr;
8042#ifndef MG_DISABLE_FILESYSTEM
8043 } else {
8044 fp = fopen(path, "a");
8045#endif
8046 }
8047 if (fp == NULL) return;
8048
8049 mg_conn_addr_to_str(nc, src, sizeof(src),
8051 mg_conn_addr_to_str(nc, dst, sizeof(dst), MG_SOCK_STRINGIFY_IP |
8054 fprintf(
8055 fp, "%lu %p %s %s %s %d\n", (unsigned long) time(NULL), (void *) nc, src,
8056 ev == MG_EV_RECV ? "<-" : ev == MG_EV_SEND
8057 ? "->"
8058 : ev == MG_EV_ACCEPT
8059 ? "<A"
8060 : ev == MG_EV_CONNECT ? "C>" : "XX",
8061 dst, num_bytes);
8062 if (num_bytes > 0 && (hexbuf = (char *) MG_MALLOC(buf_size)) != NULL) {
8063 mg_hexdump(buf, num_bytes, hexbuf, buf_size);
8064 fprintf(fp, "%s", hexbuf);
8065 MG_FREE(hexbuf);
8066 }
8067 if (fp != stdin && fp != stdout) fclose(fp);
8068#endif
8069}
#define MG_SOCK_STRINGIFY_PORT
Definition mongoose6.h:1905
#define MG_EV_RECV
Definition mongoose6.h:1222
void mg_conn_addr_to_str(struct mg_connection *nc, char *buf, size_t len, int flags)
#define MG_EV_CONNECT
Definition mongoose6.h:1221
#define MG_SOCK_STRINGIFY_IP
Definition mongoose6.h:1904
int mg_hexdump(const void *buf, int len, char *dst, int dst_len)
#define MG_EV_SEND
Definition mongoose6.h:1223
#define MG_EV_ACCEPT
Definition mongoose6.h:1220
static FILE * fp
#define MG_MALLOC
Definition mongoose6.cxx:14
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_http_create_digest_auth_header()

int mg_http_create_digest_auth_header ( char buf,
size_t  buf_len,
const char method,
const char uri,
const char auth_domain,
const char user,
const char passwd 
)

Definition at line 6156 of file mongoose6.cxx.

6159 {
6160 static const char colon[] = ":", qop[] = "auth";
6161 static const size_t one = 1;
6162 char ha1[33], resp[33], cnonce[40];
6163
6164 snprintf(cnonce, sizeof(cnonce), "%x", (unsigned int) time(NULL));
6165 cs_md5(ha1, user, (size_t) strlen(user), colon, one, auth_domain,
6166 (size_t) strlen(auth_domain), colon, one, passwd,
6167 (size_t) strlen(passwd), NULL);
6168 mg_mkmd5resp(method, strlen(method), uri, strlen(uri), ha1, sizeof(ha1) - 1,
6169 cnonce, strlen(cnonce), "1", one, cnonce, strlen(cnonce), qop,
6170 sizeof(qop) - 1, resp);
6171 return snprintf(buf, buf_len,
6172 "Authorization: Digest username=\"%s\","
6173 "realm=\"%s\",uri=\"%s\",qop=%s,nc=1,cnonce=%s,"
6174 "nonce=%s,response=%s\r\n",
6175 user, auth_domain, uri, qop, cnonce, cnonce, resp);
6176}
char * cs_md5(char buf[33],...)
static void mg_mkmd5resp(const char *method, size_t method_len, const char *uri, size_t uri_len, const char *ha1, size_t ha1_len, const char *nonce, size_t nonce_len, const char *nc, size_t nc_len, const char *cnonce, size_t cnonce_len, const char *qop, size_t qop_len, char *resp)
Here is the call graph for this function:

◆ mg_http_parse_header()

int mg_http_parse_header ( struct mg_str hdr,
const char var_name,
char buf,
size_t  buf_size 
)

Definition at line 6084 of file mongoose6.cxx.

6085 {
6086 int ch = ' ', ch1 = ',', len = 0, n = strlen(var_name);
6087 const char *p, *end = hdr ? hdr->p + hdr->len : NULL, *s = NULL;
6088
6089 if (buf != NULL && buf_size > 0) buf[0] = '\0';
6090 if (hdr == NULL) return 0;
6091
6092 /* Find where variable starts */
6093 for (s = hdr->p; s != NULL && s + n < end; s++) {
6094 if ((s == hdr->p || s[-1] == ch || s[-1] == ch1) && s[n] == '=' &&
6095 !memcmp(s, var_name, n))
6096 break;
6097 }
6098
6099 if (s != NULL && &s[n + 1] < end) {
6100 s += n + 1;
6101 if (*s == '"' || *s == '\'') {
6102 ch = ch1 = *s++;
6103 }
6104 p = s;
6105 while (p < end && p[0] != ch && p[0] != ch1 && len < (int) buf_size) {
6106 if (ch != ' ' && p[0] == '\\' && p[1] == ch) p++;
6107 buf[len++] = *p++;
6108 }
6109 if (len >= (int) buf_size || (ch != ' ' && *p != ch)) {
6110 len = 0;
6111 } else {
6112 if (len > 0 && s[len - 1] == ',') len--;
6113 if (len > 0 && s[len - 1] == ';') len--;
6114 buf[len] = '\0';
6115 }
6116 }
6117
6118 return len;
6119}
char var_name[256]
Definition odbhist.cxx:41
Here is the call graph for this function:

◆ mg_if_accept_new_conn()

struct mg_connection * mg_if_accept_new_conn ( struct mg_connection lc)

Definition at line 2619 of file mongoose6.cxx.

2619 {
2620 struct mg_add_sock_opts opts;
2621 struct mg_connection *nc;
2622 memset(&opts, 0, sizeof(opts));
2623 nc = mg_create_connection(lc->mgr, lc->handler, opts);
2624 if (nc == NULL) return NULL;
2625 nc->listener = lc;
2626 nc->proto_handler = lc->proto_handler;
2627 nc->user_data = lc->user_data;
2629 mg_add_conn(nc->mgr, nc);
2630 DBG(("%p %p %d %d, %p %p", lc, nc, nc->sock, (int) nc->flags, lc->ssl_ctx,
2631 nc->ssl));
2632 return nc;
2633}
mg_event_handler_t handler
Definition mongoose6.h:1264
struct mg_connection * listener
Definition mongoose6.h:1248
size_t recv_mbuf_limit
Definition mongoose6.h:1254
mg_event_handler_t proto_handler
Definition mongoose6.h:1261
Here is the call graph for this function:

◆ mg_if_accept_tcp_cb()

void mg_if_accept_tcp_cb ( struct mg_connection nc,
union socket_address sa,
size_t  sa_len 
)

Definition at line 2635 of file mongoose6.cxx.

2636 {
2637 (void) sa_len;
2638 nc->sa = *sa;
2639 mg_call(nc, NULL, MG_EV_ACCEPT, &nc->sa);
2640}
MG_INTERNAL void mg_call(struct mg_connection *nc, mg_event_handler_t ev_handler, int ev, void *ev_data)
Here is the call graph for this function:

◆ mg_if_connect_cb()

void mg_if_connect_cb ( struct mg_connection nc,
int  err 
)

Definition at line 2758 of file mongoose6.cxx.

2758 {
2759 DBG(("%p connect, err=%d", nc, err));
2760 nc->flags &= ~MG_F_CONNECTING;
2761 if (err != 0) {
2763 }
2764 mg_call(nc, NULL, MG_EV_CONNECT, &err);
2765}
Here is the call graph for this function:

◆ mg_if_connect_tcp()

void mg_if_connect_tcp ( struct mg_connection nc,
const union socket_address sa 
)

Definition at line 3125 of file mongoose6.cxx.

3126 {
3127 int rc;
3128 nc->sock = socket(AF_INET, SOCK_STREAM, 0);
3129 if (nc->sock < 0) {
3130 nc->sock = INVALID_SOCKET;
3131 nc->err = errno ? errno : 1;
3132 return;
3133 }
3134#if !defined(MG_SOCKET_SIMPLELINK) && !defined(MG_ESP8266)
3136#endif
3137 rc = connect(nc->sock, &sa->sa, sizeof(sa->sin));
3138 nc->err = mg_is_error(rc) ? errno : 0;
3139 DBG(("%p sock %d err %d", nc, nc->sock, nc->err));
3140}
struct sockaddr_in sin
Definition mongoose6.h:1196
static int mg_is_error(void)
void mg_set_non_blocking_mode(sock_t sock)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_if_connect_udp()

void mg_if_connect_udp ( struct mg_connection nc)

Definition at line 3142 of file mongoose6.cxx.

3142 {
3143 nc->sock = socket(AF_INET, SOCK_DGRAM, 0);
3144 if (nc->sock < 0) {
3145 nc->sock = INVALID_SOCKET;
3146 nc->err = errno ? errno : 1;
3147 return;
3148 }
3149 nc->err = 0;
3150}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_if_create_conn()

int mg_if_create_conn ( struct mg_connection nc)

Definition at line 3181 of file mongoose6.cxx.

3181 {
3182 (void) nc;
3183 return 1;
3184}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_if_destroy_conn()

void mg_if_destroy_conn ( struct mg_connection nc)

Definition at line 3186 of file mongoose6.cxx.

3186 {
3187 if (nc->sock == INVALID_SOCKET) return;
3188 if (!(nc->flags & MG_F_UDP)) {
3189 closesocket(nc->sock);
3190 } else {
3191 /* Only close outgoing UDP sockets or listeners. */
3192 if (nc->listener == NULL) closesocket(nc->sock);
3193 }
3194 /*
3195 * avoid users accidentally double close a socket
3196 * because it can lead to difficult to debug situations.
3197 * It would happen only if reusing a destroyed mg_connection
3198 * but it's not always possible to run the code through an
3199 * address sanitizer.
3200 */
3201 nc->sock = INVALID_SOCKET;
3202}
#define closesocket(s)
Definition melog.cxx:29
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_if_get_conn_addr()

void mg_if_get_conn_addr ( struct mg_connection nc,
int  remote,
union socket_address sa 
)

Definition at line 3773 of file mongoose6.cxx.

3774 {
3775#ifndef MG_SOCKET_SIMPLELINK
3776 mg_sock_get_addr(nc->sock, remote, sa);
3777#else
3778 /* SimpleLink does not provide a way to get socket's peer address after
3779 * accept or connect. Address hould have been preserved in the connection,
3780 * so we do our best here by using it. */
3781 if (remote) memcpy(sa, &nc->sa, sizeof(*sa));
3782#endif
3783}
static void mg_sock_get_addr(sock_t sock, int remote, union socket_address *sa)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_if_listen_tcp()

int mg_if_listen_tcp ( struct mg_connection nc,
union socket_address sa 
)

Definition at line 3152 of file mongoose6.cxx.

3152 {
3154 if (sock == INVALID_SOCKET) {
3155 return (errno ? errno : 1);
3156 }
3157 mg_sock_set(nc, sock);
3158 return 0;
3159}
static sock_t mg_open_listening_socket(union socket_address *sa, int proto)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_if_listen_udp()

int mg_if_listen_udp ( struct mg_connection nc,
union socket_address sa 
)

Definition at line 3161 of file mongoose6.cxx.

3161 {
3163 if (sock < 0) return (errno ? errno : 1);
3164 mg_sock_set(nc, sock);
3165 return 0;
3166}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_if_poll()

void mg_if_poll ( struct mg_connection nc,
time_t  now 
)

Definition at line 2150 of file mongoose6.cxx.

2150 {
2151 if (nc->ssl == NULL || (nc->flags & MG_F_SSL_HANDSHAKE_DONE)) {
2152 mg_call(nc, NULL, MG_EV_POLL, &now);
2153 }
2154}
#define MG_EV_POLL
Definition mongoose6.h:1219
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_if_recv_tcp_cb()

void mg_if_recv_tcp_cb ( struct mg_connection nc,
void buf,
int  len 
)

Definition at line 2687 of file mongoose6.cxx.

2687 {
2688 mg_recv_common(nc, buf, len);
2689}
static void mg_recv_common(struct mg_connection *nc, void *buf, int len)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_if_recv_udp_cb()

void mg_if_recv_udp_cb ( struct mg_connection nc,
void buf,
int  len,
union socket_address sa,
size_t  sa_len 
)

Definition at line 2691 of file mongoose6.cxx.

2692 {
2693 assert(nc->flags & MG_F_UDP);
2694 DBG(("%p %u", nc, (unsigned int) len));
2695 if (nc->flags & MG_F_LISTENING) {
2696 struct mg_connection *lc = nc;
2697 /*
2698 * Do we have an existing connection for this source?
2699 * This is very inefficient for long connection lists.
2700 */
2701 for (nc = mg_next(lc->mgr, NULL); nc != NULL; nc = mg_next(lc->mgr, nc)) {
2702 if (memcmp(&nc->sa.sa, &sa->sa, sa_len) == 0 && nc->listener == lc) {
2703 break;
2704 }
2705 }
2706 if (nc == NULL) {
2707 struct mg_add_sock_opts opts;
2708 memset(&opts, 0, sizeof(opts));
2709 /* Create fake connection w/out sock initialization */
2710 nc = mg_create_connection_base(lc->mgr, lc->handler, opts);
2711 if (nc != NULL) {
2712 nc->sock = lc->sock;
2713 nc->listener = lc;
2714 nc->sa = *sa;
2715 nc->proto_handler = lc->proto_handler;
2716 nc->user_data = lc->user_data;
2718 nc->flags = MG_F_UDP;
2719 mg_add_conn(lc->mgr, nc);
2720 mg_call(nc, NULL, MG_EV_ACCEPT, &nc->sa);
2721 } else {
2722 DBG(("OOM"));
2723 /* No return here, we still need to drop on the floor */
2724 }
2725 }
2726 }
2727 if (nc != NULL) {
2728 mg_recv_common(nc, buf, len);
2729 } else {
2730 /* Drop on the floor. */
2731 MG_FREE(buf);
2732 mg_if_recved(nc, len);
2733 }
2734}
struct mg_connection * mg_next(struct mg_mgr *s, struct mg_connection *conn)
void mg_if_recved(struct mg_connection *nc, size_t len)
Here is the call graph for this function:

◆ mg_if_recved()

void mg_if_recved ( struct mg_connection nc,
size_t  len 
)

Definition at line 3176 of file mongoose6.cxx.

3176 {
3177 (void) nc;
3178 (void) len;
3179}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_if_sent_cb()

void mg_if_sent_cb ( struct mg_connection nc,
int  num_sent 
)

Definition at line 2656 of file mongoose6.cxx.

2656 {
2657 if (num_sent < 0) {
2659 }
2660 mg_call(nc, NULL, MG_EV_SEND, &num_sent);
2661}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_if_tcp_send()

void mg_if_tcp_send ( struct mg_connection nc,
const void buf,
size_t  len 
)

Definition at line 3168 of file mongoose6.cxx.

3168 {
3169 mbuf_append(&nc->send_mbuf, buf, len);
3170}
struct mbuf send_mbuf
Definition mongoose6.h:1256
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_if_timer()

void mg_if_timer ( struct mg_connection c,
double  now 
)

Definition at line 2136 of file mongoose6.cxx.

2136 {
2137 if (c->ev_timer_time > 0 && now >= c->ev_timer_time) {
2138 double old_value = c->ev_timer_time;
2140 /*
2141 * To prevent timer firing all the time, reset the timer after delivery.
2142 * However, in case user sets it to new value, do not reset.
2143 */
2144 if (c->ev_timer_time == old_value) {
2145 c->ev_timer_time = 0;
2146 }
2147 }
2148}
#define MG_EV_TIMER
Definition mongoose6.h:1225
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_if_udp_send()

void mg_if_udp_send ( struct mg_connection nc,
const void buf,
size_t  len 
)

Definition at line 3172 of file mongoose6.cxx.

3172 {
3173 mbuf_append(&nc->send_mbuf, buf, len);
3174}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_is_big_endian()

int mg_is_big_endian ( void  )

Definition at line 8072 of file mongoose6.cxx.

8072 {
8073 static const int n = 1;
8074 /* TODO(mkm) use compiletime check with 4-byte char literal */
8075 return ((char *) &n)[0] == 0;
8076}

◆ mg_match_prefix()

size_t mg_match_prefix ( const char pattern,
int  pattern_len,
const char str 
)

Definition at line 2354 of file mongoose614.cxx.

2354 {
2355 const struct mg_str pstr = {pattern, (size_t) pattern_len};
2356 struct mg_str s = {str, 0};
2357 if (str != NULL) s.len = strlen(str);
2358 return mg_match_prefix_n(pstr, s);
2359}
size_t mg_match_prefix_n(const struct mg_str, const struct mg_str) WEAK
Here is the call graph for this function:

◆ mg_match_prefix_n()

size_t mg_match_prefix_n ( const struct mg_str  pattern,
const struct mg_str  str 
)

Definition at line 2308 of file mongoose614.cxx.

2308 {
2309 const char *or_str;
2310 size_t res = 0, len = 0, i = 0, j = 0;
2311
2312 if ((or_str = (const char *) memchr(pattern.p, '|', pattern.len)) != NULL ||
2313 (or_str = (const char *) memchr(pattern.p, ',', pattern.len)) != NULL) {
2314 struct mg_str pstr = {pattern.p, (size_t)(or_str - pattern.p)};
2316 if (res > 0) return res;
2317 pstr.p = or_str + 1;
2318 pstr.len = (pattern.p + pattern.len) - (or_str + 1);
2319 return mg_match_prefix_n(pstr, str);
2320 }
2321
2322 for (; i < pattern.len && j < str.len; i++, j++) {
2323 if (pattern.p[i] == '?') {
2324 continue;
2325 } else if (pattern.p[i] == '*') {
2326 i++;
2327 if (i < pattern.len && pattern.p[i] == '*') {
2328 i++;
2329 len = str.len - j;
2330 } else {
2331 len = 0;
2332 while (j + len < str.len && str.p[j + len] != '/') len++;
2333 }
2334 if (i == pattern.len || (pattern.p[i] == '$' && i == pattern.len - 1))
2335 return j + len;
2336 do {
2337 const struct mg_str pstr = {pattern.p + i, pattern.len - i};
2338 const struct mg_str sstr = {str.p + j + len, str.len - j - len};
2340 } while (res == 0 && len != 0 && len-- > 0);
2341 return res == 0 ? 0 : j + res + len;
2342 } else if (str_util_lowercase(&pattern.p[i]) !=
2343 str_util_lowercase(&str.p[j])) {
2344 break;
2345 }
2346 }
2347 if (i < pattern.len && pattern.p[i] == '$') {
2348 return j == str.len ? str.len : 0;
2349 }
2350 return i == pattern.len ? j : 0;
2351}
static int str_util_lowercase(const char *s)
Here is the call graph for this function:

◆ mg_mgr_free()

void mg_mgr_free ( struct mg_mgr m)

Definition at line 2238 of file mongoose6.cxx.

2238 {
2239 struct mg_connection *conn, *tmp_conn;
2240
2241 DBG(("%p", m));
2242 if (m == NULL) return;
2243 /* Do one last poll, see https://github.com/cesanta/mongoose/issues/286 */
2244 mg_mgr_poll(m, 0);
2245
2246#ifndef MG_DISABLE_SOCKETPAIR
2247 if (m->ctl[0] != INVALID_SOCKET) closesocket(m->ctl[0]);
2248 if (m->ctl[1] != INVALID_SOCKET) closesocket(m->ctl[1]);
2249 m->ctl[0] = m->ctl[1] = INVALID_SOCKET;
2250#endif
2251
2252 for (conn = m->active_connections; conn != NULL; conn = tmp_conn) {
2253 tmp_conn = conn->next;
2254 mg_close_conn(conn);
2255 }
2256
2257 mg_ev_mgr_free(m);
2258}
time_t mg_mgr_poll(struct mg_mgr *mgr, int timeout_ms)
struct mg_connection * active_connections
Definition mongoose6.h:1231
struct mg_connection * next
Definition mongoose6.h:1247
void mg_close_conn(struct mg_connection *conn)
void mg_ev_mgr_free(struct mg_mgr *mgr)
Here is the call graph for this function:

◆ mg_mgr_init()

void mg_mgr_init ( struct mg_mgr mgr,
void user_data 
)

Definition at line 2179 of file mongoose6.cxx.

2179 {
2180 memset(m, 0, sizeof(*m));
2181#ifndef MG_DISABLE_SOCKETPAIR
2182 m->ctl[0] = m->ctl[1] = INVALID_SOCKET;
2183#endif
2184 m->user_data = user_data;
2185
2186#ifdef _WIN32
2187 {
2188 WSADATA data;
2189 WSAStartup(MAKEWORD(2, 2), &data);
2190 }
2191#elif defined(__unix__)
2192 /* Ignore SIGPIPE signal, so if client cancels the request, it
2193 * won't kill the whole process. */
2195#endif
2196
2197#ifdef MG_ENABLE_SSL
2198 {
2199 static int init_done;
2200 if (!init_done) {
2202 init_done++;
2203 }
2204 }
2205#endif
2206
2207 mg_ev_mgr_init(m);
2208 DBG(("=================================="));
2209 DBG(("init mgr=%p", m));
2210}
void mg_ev_mgr_init(struct mg_mgr *mgr)
Here is the call graph for this function:

◆ mg_mgr_poll()

time_t mg_mgr_poll ( struct mg_mgr mgr,
int  milli 
)

Definition at line 3594 of file mongoose6.cxx.

3594 {
3595 double now = mg_time();
3596 double min_timer;
3597 struct mg_connection *nc, *tmp;
3598 struct timeval tv;
3601 int num_fds, num_ev, num_timers = 0;
3602
3603 FD_ZERO(&read_set);
3605 FD_ZERO(&err_set);
3606#ifndef MG_DISABLE_SOCKETPAIR
3607 mg_add_to_set(mgr->ctl[1], &read_set, &max_fd);
3608#endif
3609
3610 /*
3611 * Note: it is ok to have connections with sock == INVALID_SOCKET in the list,
3612 * e.g. timer-only "connections".
3613 */
3614 min_timer = 0;
3615 for (nc = mgr->active_connections, num_fds = 0; nc != NULL; nc = tmp) {
3616 tmp = nc->next;
3617
3618 //printf("nc %p -> mg_mgr_poll, mgr %p %p, pd %p, fp %p\n", nc, nc->mgr, mgr, nc->proto_data, (nc->proto_data?*(FILE**)nc->proto_data:NULL));
3619
3620 if (nc->sock != INVALID_SOCKET) {
3621 num_fds++;
3622
3623 if (!(nc->flags & MG_F_WANT_WRITE) &&
3624 nc->recv_mbuf.len < nc->recv_mbuf_limit &&
3625 (!(nc->flags & MG_F_UDP) || nc->listener == NULL)) {
3627 }
3628
3629 if (((nc->flags & MG_F_CONNECTING) && !(nc->flags & MG_F_WANT_READ)) ||
3630 (nc->send_mbuf.len > 0 && !(nc->flags & MG_F_CONNECTING))) {
3633 }
3634 }
3635
3636 if (nc->ev_timer_time > 0) {
3637 if (num_timers == 0 || nc->ev_timer_time < min_timer) {
3639 }
3640 num_timers++;
3641 }
3642 }
3643
3644 /*
3645 * If there is a timer to be fired earlier than the requested timeout,
3646 * adjust the timeout.
3647 */
3648 if (num_timers > 0) {
3649 double timer_timeout_ms = (min_timer - mg_time()) * 1000 + 1 /* rounding */;
3652 }
3653 }
3654 if (timeout_ms < 0) timeout_ms = 0;
3655
3656 tv.tv_sec = timeout_ms / 1000;
3657 tv.tv_usec = (timeout_ms % 1000) * 1000;
3658
3659 num_ev = select((int) max_fd + 1, &read_set, &write_set, &err_set, &tv);
3660 now = mg_time();
3661 DBG(("select @ %ld num_ev=%d of %d, timeout=%d", (long) now, num_ev, num_fds,
3662 timeout_ms));
3663
3664#ifndef MG_DISABLE_SOCKETPAIR
3665 if (num_ev > 0 && mgr->ctl[1] != INVALID_SOCKET &&
3666 FD_ISSET(mgr->ctl[1], &read_set)) {
3668 }
3669#endif
3670
3671 for (nc = mgr->active_connections; nc != NULL; nc = tmp) {
3672 int fd_flags = 0;
3673 if (nc->sock != INVALID_SOCKET) {
3674 if (num_ev > 0) {
3675 fd_flags = (FD_ISSET(nc->sock, &read_set) &&
3676 (!(nc->flags & MG_F_UDP) || nc->listener == NULL)
3678 : 0) |
3679 (FD_ISSET(nc->sock, &write_set) ? _MG_F_FD_CAN_WRITE : 0) |
3680 (FD_ISSET(nc->sock, &err_set) ? _MG_F_FD_ERROR : 0);
3681 }
3682#ifdef MG_SOCKET_SIMPLELINK
3683 /* SimpleLink does not report UDP sockets as writeable. */
3684 if (nc->flags & MG_F_UDP &&
3685 (nc->send_mbuf.len > 0 || nc->flags & MG_F_CONNECTING)) {
3687 }
3688#endif
3689#ifdef MG_LWIP
3690 /* With LWIP socket emulation layer, we don't get write events */
3692#endif
3693 }
3694 tmp = nc->next;
3696 }
3697
3698 for (nc = mgr->active_connections; nc != NULL; nc = tmp) {
3699 tmp = nc->next;
3700 if ((nc->flags & MG_F_CLOSE_IMMEDIATELY) ||
3701 (nc->send_mbuf.len == 0 && (nc->flags & MG_F_SEND_AND_CLOSE))) {
3702 //printf("nc %p -> mg_close_conn, mgr %p %p, pd %p, fp %p\n", nc, nc->mgr, mgr, nc->proto_data, (nc->proto_data?*(FILE**)nc->proto_data:NULL));
3703 mg_close_conn(nc);
3704 }
3705 }
3706
3707 return now;
3708}
#define MG_F_WANT_READ
Definition mongoose6.h:1283
struct mbuf recv_mbuf
Definition mongoose6.h:1255
double mg_time()
double ev_timer_time
Definition mongoose6.h:1260
#define MG_F_WANT_WRITE
Definition mongoose6.h:1284
#define MG_F_CONNECTING
Definition mongoose6.h:1281
#define MG_F_SEND_AND_CLOSE
Definition mongoose6.h:1288
#define _MG_F_FD_ERROR
#define _MG_F_FD_CAN_READ
static void mg_mgr_handle_ctl_sock(struct mg_mgr *mgr)
#define _MG_F_FD_CAN_WRITE
void mg_add_to_set(sock_t sock, fd_set *set, sock_t *max_fd)
void mg_mgr_handle_conn(struct mg_connection *nc, int fd_flags, double now)
Here is the call graph for this function:

◆ mg_mk_str()

struct mg_str mg_mk_str ( const char s)

Definition at line 1694 of file mongoose614.cxx.

1694 {
1695 struct mg_str ret = {s, 0};
1696 if (s != NULL) ret.len = strlen(s);
1697 return ret;
1698}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_mqtt_connack()

void mg_mqtt_connack ( struct mg_connection nc,
uint8_t  return_code 
)

Definition at line 8566 of file mongoose6.cxx.

8566 {
8567 uint8_t unused = 0;
8568 mg_send(nc, &unused, 1);
8569 mg_send(nc, &return_code, 1);
8571}
#define MG_MQTT_CMD_CONNACK
Definition mongoose6.h:2901
void mg_send(struct mg_connection *nc, const void *buf, int len)
static void mg_mqtt_prepend_header(struct mg_connection *nc, uint8_t cmd, uint8_t flags, size_t len)
Here is the call graph for this function:

◆ mg_mqtt_disconnect()

void mg_mqtt_disconnect ( struct mg_connection nc)

Definition at line 8624 of file mongoose6.cxx.

8624 {
8626}
#define MG_MQTT_CMD_DISCONNECT
Definition mongoose6.h:2913
Here is the call graph for this function:

◆ mg_mqtt_next_subscribe_topic()

int mg_mqtt_next_subscribe_topic ( struct mg_mqtt_message msg,
struct mg_str topic,
uint8_t qos,
int  pos 
)

Definition at line 8535 of file mongoose6.cxx.

8536 {
8537 unsigned char *buf = (unsigned char *) msg->payload.p + pos;
8538 if ((size_t) pos >= msg->payload.len) {
8539 return -1;
8540 }
8541
8542 topic->len = buf[0] << 8 | buf[1];
8543 topic->p = (char *) buf + 2;
8544 *qos = buf[2 + topic->len];
8545 return pos + 2 + topic->len + 1;
8546}
struct mg_str payload
Definition mongoose6.h:2878

◆ mg_mqtt_ping()

void mg_mqtt_ping ( struct mg_connection nc)

Definition at line 8616 of file mongoose6.cxx.

8616 {
8618}
#define MG_MQTT_CMD_PINGREQ
Definition mongoose6.h:2911
Here is the call graph for this function:

◆ mg_mqtt_pong()

void mg_mqtt_pong ( struct mg_connection nc)

Definition at line 8620 of file mongoose6.cxx.

8620 {
8622}
#define MG_MQTT_CMD_PINGRESP
Definition mongoose6.h:2912
Here is the call graph for this function:

◆ mg_mqtt_puback()

void mg_mqtt_puback ( struct mg_connection nc,
uint16_t  message_id 
)

Definition at line 8585 of file mongoose6.cxx.

8585 {
8587}
#define MG_MQTT_CMD_PUBACK
Definition mongoose6.h:2903
static void mg_send_mqtt_short_command(struct mg_connection *nc, uint8_t cmd, uint16_t message_id)
Here is the call graph for this function:

◆ mg_mqtt_pubcomp()

void mg_mqtt_pubcomp ( struct mg_connection nc,
uint16_t  message_id 
)

Definition at line 8597 of file mongoose6.cxx.

8597 {
8599}
#define MG_MQTT_CMD_PUBCOMP
Definition mongoose6.h:2906
Here is the call graph for this function:

◆ mg_mqtt_publish()

void mg_mqtt_publish ( struct mg_connection nc,
const char topic,
uint16_t  message_id,
int  flags,
const void data,
size_t  len 
)

Definition at line 8496 of file mongoose6.cxx.

8498 {
8499 size_t old_len = nc->send_mbuf.len;
8500
8501 uint16_t topic_len = htons(strlen(topic));
8502 uint16_t message_id_net = htons(message_id);
8503
8504 mg_send(nc, &topic_len, 2);
8505 mg_send(nc, topic, strlen(topic));
8506 if (MG_MQTT_GET_QOS(flags) > 0) {
8507 mg_send(nc, &message_id_net, 2);
8508 }
8509 mg_send(nc, data, len);
8510
8512 nc->send_mbuf.len - old_len);
8513}
#define MG_MQTT_GET_QOS(flags)
Definition mongoose6.h:2936
#define MG_MQTT_CMD_PUBLISH
Definition mongoose6.h:2902
Here is the call graph for this function:

◆ mg_mqtt_pubrec()

void mg_mqtt_pubrec ( struct mg_connection nc,
uint16_t  message_id 
)

Definition at line 8589 of file mongoose6.cxx.

8589 {
8591}
#define MG_MQTT_CMD_PUBREC
Definition mongoose6.h:2904
Here is the call graph for this function:

◆ mg_mqtt_pubrel()

void mg_mqtt_pubrel ( struct mg_connection nc,
uint16_t  message_id 
)

Definition at line 8593 of file mongoose6.cxx.

8593 {
8595}
#define MG_MQTT_CMD_PUBREL
Definition mongoose6.h:2905
Here is the call graph for this function:

◆ mg_mqtt_suback()

void mg_mqtt_suback ( struct mg_connection nc,
uint8_t qoss,
size_t  qoss_len,
uint16_t  message_id 
)

Definition at line 8601 of file mongoose6.cxx.

8602 {
8603 size_t i;
8604 uint16_t message_id_net = htons(message_id);
8605 mg_send(nc, &message_id_net, 2);
8606 for (i = 0; i < qoss_len; i++) {
8607 mg_send(nc, &qoss[i], 1);
8608 }
8610}
#define MG_MQTT_QOS(qos)
Definition mongoose6.h:2935
#define MG_MQTT_CMD_SUBACK
Definition mongoose6.h:2908
Here is the call graph for this function:

◆ mg_mqtt_subscribe()

void mg_mqtt_subscribe ( struct mg_connection nc,
const struct mg_mqtt_topic_expression topics,
size_t  topics_len,
uint16_t  message_id 
)

Definition at line 8515 of file mongoose6.cxx.

8517 {
8518 size_t old_len = nc->send_mbuf.len;
8519
8520 uint16_t message_id_n = htons(message_id);
8521 size_t i;
8522
8523 mg_send(nc, (char *) &message_id_n, 2);
8524 for (i = 0; i < topics_len; i++) {
8526 mg_send(nc, &topic_len_n, 2);
8527 mg_send(nc, topics[i].topic, strlen(topics[i].topic));
8528 mg_send(nc, &topics[i].qos, 1);
8529 }
8530
8532 nc->send_mbuf.len - old_len);
8533}
#define MG_MQTT_CMD_SUBSCRIBE
Definition mongoose6.h:2907
Here is the call graph for this function:

◆ mg_mqtt_unsuback()

void mg_mqtt_unsuback ( struct mg_connection nc,
uint16_t  message_id 
)

Definition at line 8612 of file mongoose6.cxx.

8612 {
8614}
#define MG_MQTT_CMD_UNSUBACK
Definition mongoose6.h:2910
Here is the call graph for this function:

◆ mg_mqtt_unsubscribe()

void mg_mqtt_unsubscribe ( struct mg_connection nc,
char **  topics,
size_t  topics_len,
uint16_t  message_id 
)

Definition at line 8548 of file mongoose6.cxx.

8549 {
8550 size_t old_len = nc->send_mbuf.len;
8551
8552 uint16_t message_id_n = htons(message_id);
8553 size_t i;
8554
8555 mg_send(nc, (char *) &message_id_n, 2);
8556 for (i = 0; i < topics_len; i++) {
8558 mg_send(nc, &topic_len_n, 2);
8559 mg_send(nc, topics[i], strlen(topics[i]));
8560 }
8561
8563 nc->send_mbuf.len - old_len);
8564}
#define MG_MQTT_CMD_UNSUBSCRIBE
Definition mongoose6.h:2909
Here is the call graph for this function:

◆ mg_ncasecmp()

int mg_ncasecmp ( const char s1,
const char s2,
size_t  len 
)

Definition at line 2187 of file mongoose614.cxx.

2187 {
2188 int diff = 0;
2189
2190 if (len > 0) do {
2192 } while (diff == 0 && s1[-1] != '\0' && --len > 0);
2193
2194 return diff;
2195}
Here is the call graph for this function:

◆ mg_next()

struct mg_connection * mg_next ( struct mg_mgr s,
struct mg_connection conn 
)

Definition at line 2955 of file mongoose6.cxx.

2955 {
2956 return conn == NULL ? s->active_connections : conn->next;
2957}
Here is the call graph for this function:

◆ mg_next_comma_list_entry()

const char * mg_next_comma_list_entry ( const char list,
struct mg_str val,
struct mg_str eq_val 
)

Definition at line 2263 of file mongoose614.cxx.

2264 {
2266 return ret.p;
2267}
struct mg_str mg_mk_str(const char *s) WEAK
struct mg_str mg_next_comma_list_entry_n(struct mg_str list, struct mg_str *val, struct mg_str *eq_val) WEAK
static te_expr * list(state *s)
Definition tinyexpr.c:567
Here is the call graph for this function:

◆ mg_normalize_uri_path()

int mg_normalize_uri_path ( const struct mg_str in,
struct mg_str out 
)

Definition at line 4042 of file mongoose6.cxx.

4042 {
4043 const char *s = in->p, *se = s + in->len;
4044 char *cp = (char *) out->p, *d;
4045
4046 if (in->len == 0 || *s != '/') {
4047 out->len = 0;
4048 return 0;
4049 }
4050
4051 d = cp;
4052
4053 while (s < se) {
4054 const char *next = s;
4055 struct mg_str component;
4056 parse_uri_component(&next, se, '/', &component);
4057 if (mg_vcmp(&component, ".") == 0) {
4058 /* Yum. */
4059 } else if (mg_vcmp(&component, "..") == 0) {
4060 /* Backtrack to previous slash. */
4061 if (d > cp + 1 && *(d - 1) == '/') d--;
4062 while (d > cp && *(d - 1) != '/') d--;
4063 } else {
4064 memmove(d, s, next - s);
4065 d += next - s;
4066 }
4067 s = next;
4068 }
4069 if (d == cp) *d++ = '/';
4070
4071 out->p = cp;
4072 out->len = d - cp;
4073 return 1;
4074}
int mg_vcmp(const struct mg_str *str1, const char *str2)
static void parse_uri_component(const char **p, const char *end, char sep, struct mg_str *res)
Here is the call graph for this function:

◆ mg_open()

int mg_open ( const char path,
int  flag,
int  mode 
)

Definition at line 7863 of file mongoose6.cxx.

7863 { /* LCOV_EXCL_LINE */
7864#ifdef _WIN32
7865 wchar_t wpath[MAX_PATH_SIZE];
7866 to_wchar(path, wpath, ARRAY_SIZE(wpath));
7867 return _wopen(wpath, flag, mode);
7868#else
7869 return open(path, flag, mode); /* LCOV_EXCL_LINE */
7870#endif
7871}
#define MAX_PATH_SIZE
Definition mongoose6.h:1804
#define ARRAY_SIZE(array)
Definition mongoose6.h:119
Here is the call graph for this function:

◆ mg_parse_dns()

int mg_parse_dns ( const char buf,
int  len,
struct mg_dns_message msg 
)

Definition at line 9048 of file mongoose6.cxx.

9048 {
9049 struct mg_dns_header *header = (struct mg_dns_header *) buf;
9050 unsigned char *data = (unsigned char *) buf + sizeof(*header);
9051 unsigned char *end = (unsigned char *) buf + len;
9052 int i;
9053
9054 memset(msg, 0, sizeof(*msg));
9055 msg->pkt.p = buf;
9056 msg->pkt.len = len;
9057
9058 if (len < (int) sizeof(*header)) return -1;
9059
9060 msg->transaction_id = header->transaction_id;
9061 msg->flags = ntohs(header->flags);
9062 msg->num_questions = ntohs(header->num_questions);
9063 if (msg->num_questions > (int) ARRAY_SIZE(msg->questions)) {
9064 msg->num_questions = (int) ARRAY_SIZE(msg->questions);
9065 }
9066 msg->num_answers = ntohs(header->num_answers);
9067 if (msg->num_answers > (int) ARRAY_SIZE(msg->answers)) {
9068 msg->num_answers = (int) ARRAY_SIZE(msg->answers);
9069 }
9070
9071 for (i = 0; i < msg->num_questions; i++) {
9073 if (data == NULL) return -1;
9074 }
9075
9076 for (i = 0; i < msg->num_answers; i++) {
9078 if (data == NULL) return -1;
9079 }
9080
9081 return 0;
9082}
struct mg_dns_resource_record questions[MG_MAX_DNS_QUESTIONS]
Definition mongoose6.h:3196
static unsigned char * mg_parse_dns_resource_record(unsigned char *data, unsigned char *end, struct mg_dns_resource_record *rr, int reply)
uint16_t transaction_id
uint16_t num_questions
uint16_t num_answers
Here is the call graph for this function:

◆ mg_parse_http()

int mg_parse_http ( const char s,
int  n,
struct http_message hm,
int  is_req 
)

Definition at line 4402 of file mongoose6.cxx.

4402 {
4403 const char *end, *qs;
4404 int len = mg_http_get_request_len(s, n);
4405
4406 if (len <= 0) return len;
4407
4408 memset(hm, 0, sizeof(*hm));
4409 hm->message.p = s;
4410 hm->body.p = s + len;
4411 hm->message.len = hm->body.len = (size_t) ~0;
4412 end = s + len;
4413
4414 /* Request is fully buffered. Skip leading whitespaces. */
4415 while (s < end && isspace(*(unsigned char *) s)) s++;
4416
4417 if (is_req) {
4418 /* Parse request line: method, URI, proto */
4419 s = mg_skip(s, end, " ", &hm->method);
4420 s = mg_skip(s, end, " ", &hm->uri);
4421 s = mg_skip(s, end, "\r\n", &hm->proto);
4422 if (hm->uri.p <= hm->method.p || hm->proto.p <= hm->uri.p) return -1;
4423
4424 /* If URI contains '?' character, initialize query_string */
4425 if ((qs = (char *) memchr(hm->uri.p, '?', hm->uri.len)) != NULL) {
4426 hm->query_string.p = qs + 1;
4427 hm->query_string.len = &hm->uri.p[hm->uri.len] - (qs + 1);
4428 hm->uri.len = qs - hm->uri.p;
4429 }
4430 } else {
4431 s = mg_skip(s, end, " ", &hm->proto);
4432 if (end - s < 4 || s[3] != ' ') return -1;
4433 hm->resp_code = atoi(s);
4434 if (hm->resp_code < 100 || hm->resp_code >= 600) return -1;
4435 s += 4;
4436 s = mg_skip(s, end, "\r\n", &hm->resp_status_msg);
4437 }
4438
4439 s = mg_http_parse_headers(s, end, len, hm);
4440
4441 /*
4442 * mg_parse_http() is used to parse both HTTP requests and HTTP
4443 * responses. If HTTP response does not have Content-Length set, then
4444 * body is read until socket is closed, i.e. body.len is infinite (~0).
4445 *
4446 * For HTTP requests though, according to
4447 * http://tools.ietf.org/html/rfc7231#section-8.1.3,
4448 * only POST and PUT methods have defined body semantics.
4449 * Therefore, if Content-Length is not specified and methods are
4450 * not one of PUT or POST, set body length to 0.
4451 *
4452 * So,
4453 * if it is HTTP request, and Content-Length is not set,
4454 * and method is not (PUT or POST) then reset body length to zero.
4455 */
4456 if (hm->body.len == (size_t) ~0 && is_req &&
4457 mg_vcasecmp(&hm->method, "PUT") != 0 &&
4458 mg_vcasecmp(&hm->method, "POST") != 0) {
4459 hm->body.len = 0;
4460 hm->message.len = len;
4461 }
4462
4463 return len;
4464}
int mg_vcasecmp(const struct mg_str *str1, const char *str2)
const char * mg_skip(const char *s, const char *end, const char *delims, struct mg_str *v)
static const char * mg_http_parse_headers(const char *s, const char *end, int len, struct http_message *req)
static int mg_http_get_request_len(const char *s, int buf_len)
Here is the call graph for this function:

◆ mg_parse_multipart()

size_t mg_parse_multipart ( const char buf,
size_t  buf_len,
char var_name,
size_t  var_name_len,
char file_name,
size_t  file_name_len,
const char **  chunk,
size_t chunk_len 
)

Definition at line 7732 of file mongoose6.cxx.

7735 {
7736 static const char cd[] = "Content-Disposition: ";
7737 size_t hl, bl, n, ll, pos, cdl = sizeof(cd) - 1;
7738
7739 if (buf == NULL || buf_len <= 0) return 0;
7740 if ((hl = mg_http_get_request_len(buf, buf_len)) <= 0) return 0;
7741 if (buf[0] != '-' || buf[1] != '-' || buf[2] == '\n') return 0;
7742
7743 /* Get boundary length */
7744 bl = mg_get_line_len(buf, buf_len);
7745
7746 /* Loop through headers, fetch variable name and file name */
7747 var_name[0] = file_name[0] = '\0';
7748 for (n = bl; (ll = mg_get_line_len(buf + n, hl - n)) > 0; n += ll) {
7749 if (mg_ncasecmp(cd, buf + n, cdl) == 0) {
7750 struct mg_str header;
7751 header.p = buf + n + cdl;
7752 header.len = ll - (cdl + 2);
7753 mg_http_parse_header(&header, "name", var_name, var_name_len);
7754 mg_http_parse_header(&header, "filename", file_name, file_name_len);
7755 }
7756 }
7757
7758 /* Scan through the body, search for terminating boundary */
7759 for (pos = hl; pos + (bl - 2) < buf_len; pos++) {
7760 if (buf[pos] == '-' && !memcmp(buf, &buf[pos], bl - 2)) {
7761 if (data_len != NULL) *data_len = (pos - 2) - hl;
7762 if (data != NULL) *data = buf + hl;
7763 return pos;
7764 }
7765 }
7766
7767 return 0;
7768}
int mg_http_parse_header(struct mg_str *hdr, const char *var_name, char *buf, size_t buf_size)
INT bl
Definition mdump.cxx:29
static size_t mg_get_line_len(const char *buf, size_t buf_len)
char file_name[256]
Definition odbhist.cxx:41
Here is the call graph for this function:

◆ mg_parse_uri()

int mg_parse_uri ( struct mg_str  uri,
struct mg_str scheme,
struct mg_str user_info,
struct mg_str host,
unsigned int port,
struct mg_str path,
struct mg_str query,
struct mg_str fragment 
)

Definition at line 3926 of file mongoose6.cxx.

3929 {
3930 struct mg_str rscheme = {0, 0}, ruser_info = {0, 0}, rhost = {0, 0},
3931 rpath = {0, 0}, rquery = {0, 0}, rfragment = {0, 0};
3932 unsigned int rport = 0;
3933 enum {
3934 P_START,
3937 P_HOST,
3938 P_PORT,
3939 P_REST
3940 } state = P_START;
3941
3942 const char *p = uri.p, *end = p + uri.len;
3943 while (p < end) {
3944 switch (state) {
3945 case P_START:
3946 /*
3947 * expecting on of:
3948 * - `scheme://xxxx`
3949 * - `xxxx:port`
3950 * - `xxxx/path`
3951 */
3952 for (; p < end; p++) {
3953 if (*p == ':') {
3955 break;
3956 } else if (*p == '/') {
3957 state = P_REST;
3958 break;
3959 }
3960 }
3961 if (state == P_START || state == P_REST) {
3962 rhost.p = uri.p;
3963 rhost.len = p - uri.p;
3964 }
3965 break;
3966 case P_SCHEME_OR_PORT:
3967 if (end - p >= 3 && memcmp(p, "://", 3) == 0) {
3968 rscheme.p = uri.p;
3969 rscheme.len = p - uri.p;
3971 p += 2; /* point to last separator char */
3972 } else {
3973 rhost.p = uri.p;
3974 rhost.len = p - uri.p;
3975 state = P_PORT;
3976 }
3977 break;
3978 case P_USER_INFO:
3979 p++;
3980 ruser_info.p = p;
3981 for (; p < end; p++) {
3982 if (*p == '@') {
3983 state = P_HOST;
3984 break;
3985 } else if (*p == '/') {
3986 break;
3987 }
3988 }
3989 if (p == end || *p == '/') {
3990 /* backtrack and parse as host */
3991 state = P_HOST;
3992 p = ruser_info.p;
3993 }
3994 ruser_info.len = p - ruser_info.p;
3995 break;
3996 case P_HOST:
3997 if (*p == '@') p++;
3998 rhost.p = p;
3999 for (; p < end; p++) {
4000 if (*p == ':') {
4001 state = P_PORT;
4002 break;
4003 } else if (*p == '/') {
4004 state = P_REST;
4005 break;
4006 }
4007 }
4008 rhost.len = p - rhost.p;
4009 break;
4010 case P_PORT:
4011 p++;
4012 for (; p < end; p++) {
4013 if (*p == '/') {
4014 state = P_REST;
4015 break;
4016 }
4017 rport *= 10;
4018 rport += *p - '0';
4019 }
4020 break;
4021 case P_REST:
4022 /* `p` points to separator. `path` includes the separator */
4023 parse_uri_component(&p, end, '?', &rpath);
4024 parse_uri_component(&p, end, '#', &rquery);
4026 break;
4027 }
4028 }
4029
4030 if (scheme != 0) *scheme = rscheme;
4031 if (user_info != 0) *user_info = ruser_info;
4032 if (host != 0) *host = rhost;
4033 if (port != 0) *port = rport;
4034 if (path != 0) *path = rpath;
4035 if (query != 0) *query = rquery;
4036 if (fragment != 0) *fragment = rfragment;
4037
4038 return 0;
4039}
Here is the call graph for this function:

◆ mg_printf()

int mg_printf ( struct mg_connection conn,
const char fmt,
  ... 
)

Definition at line 1922 of file mongoose4.cxx.

1922 {
1923 va_list ap;
1924 va_start(ap, fmt);
1925 return mg_vprintf(conn, fmt, ap);
1926}
int mg_vprintf(struct mg_connection *conn, const char *fmt, va_list ap)
Here is the call graph for this function:

◆ mg_printf_html_escape()

void mg_printf_html_escape ( struct mg_connection nc,
const char fmt,
  ... 
)

Definition at line 6057 of file mongoose6.cxx.

6057 {
6058 char mem[MG_VPRINTF_BUFFER_SIZE], *buf = mem;
6059 int i, j, len;
6060 va_list ap;
6061
6062 va_start(ap, fmt);
6063 len = mg_avprintf(&buf, sizeof(mem), fmt, ap);
6064 va_end(ap);
6065
6066 if (len >= 0) {
6067 for (i = j = 0; i < len; i++) {
6068 if (buf[i] == '<' || buf[i] == '>') {
6069 mg_send(nc, buf + j, i - j);
6070 mg_send(nc, buf[i] == '<' ? "&lt;" : "&gt;", 4);
6071 j = i + 1;
6072 }
6073 }
6074 mg_send(nc, buf + j, i - j);
6075 }
6076
6077 /* LCOV_EXCL_START */
6078 if (buf != mem && buf != NULL) {
6079 MG_FREE(buf);
6080 }
6081 /* LCOV_EXCL_STOP */
6082}
int mg_avprintf(char **buf, size_t size, const char *fmt, va_list ap)
#define MG_VPRINTF_BUFFER_SIZE
Definition mongoose6.h:1179
Here is the call graph for this function:

◆ mg_printf_http_chunk()

void mg_printf_http_chunk ( struct mg_connection nc,
const char fmt,
  ... 
)

Definition at line 6037 of file mongoose6.cxx.

6037 {
6038 char mem[MG_VPRINTF_BUFFER_SIZE], *buf = mem;
6039 int len;
6040 va_list ap;
6041
6042 va_start(ap, fmt);
6043 len = mg_avprintf(&buf, sizeof(mem), fmt, ap);
6044 va_end(ap);
6045
6046 if (len >= 0) {
6047 mg_send_http_chunk(nc, buf, len);
6048 }
6049
6050 /* LCOV_EXCL_START */
6051 if (buf != mem && buf != NULL) {
6052 MG_FREE(buf);
6053 }
6054 /* LCOV_EXCL_STOP */
6055}
void mg_send_http_chunk(struct mg_connection *nc, const char *buf, size_t len)
Here is the call graph for this function:

◆ mg_printf_websocket_frame()

void mg_printf_websocket_frame ( struct mg_connection nc,
int  op_and_flags,
const char fmt,
  ... 
)

Definition at line 4697 of file mongoose6.cxx.

4698 {
4699 char mem[MG_VPRINTF_BUFFER_SIZE], *buf = mem;
4700 va_list ap;
4701 int len;
4702
4703 va_start(ap, fmt);
4704 if ((len = mg_avprintf(&buf, sizeof(mem), fmt, ap)) > 0) {
4705 mg_send_websocket_frame(nc, op, buf, len);
4706 }
4707 va_end(ap);
4708
4709 if (buf != mem && buf != NULL) {
4710 MG_FREE(buf);
4711 }
4712}
void mg_send_websocket_frame(struct mg_connection *nc, int op, const void *data, size_t len)
Here is the call graph for this function:

◆ mg_register_http_endpoint()

void mg_register_http_endpoint ( struct mg_connection nc,
const char uri_path,
mg_event_handler_t  handler 
)

Definition at line 7770 of file mongoose6.cxx.

7771 {
7773 struct mg_http_endpoint *new_ep =
7774 (struct mg_http_endpoint *) calloc(1, sizeof(*new_ep));
7776 new_ep->name_len = strlen(new_ep->name);
7777 new_ep->handler = handler;
7778 new_ep->next = pd->endpoints;
7779 pd->endpoints = new_ep;
7780}
static struct mg_http_proto_data * mg_http_get_proto_data(struct mg_connection *c)
const char * name
mg_event_handler_t handler
Here is the call graph for this function:

◆ mg_resolve()

int mg_resolve ( const char domain_name,
char ip_addr_buf,
size_t  buf_len 
)

Definition at line 2315 of file mongoose6.cxx.

2315 {
2316 struct in_addr ad;
2317 return mg_resolve2(host, &ad) ? snprintf(buf, n, "%s", inet_ntoa(ad)) : 0;
2318}
char * inet_ntoa(struct in_addr n)
static int mg_resolve2(const char *host, struct in_addr *ina)
Here is the call graph for this function:

◆ mg_resolve_async()

int mg_resolve_async ( struct mg_mgr mgr,
const char name,
int  query,
mg_resolve_callback_t  cb,
void data 
)

Definition at line 9447 of file mongoose6.cxx.

9448 {
9450 memset(&opts, 0, sizeof(opts));
9451 return mg_resolve_async_opt(mgr, name, query, cb, data, opts);
9452}
Here is the call graph for this function:

◆ mg_resolve_async_opt()

int mg_resolve_async_opt ( struct mg_mgr mgr,
const char name,
int  query,
mg_resolve_callback_t  cb,
void data,
struct mg_resolve_async_opts  opts 
)

Definition at line 9454 of file mongoose6.cxx.

9456 {
9457 struct mg_resolve_async_request *req;
9458 struct mg_connection *dns_nc;
9459 const char *nameserver = opts.nameserver_url;
9460
9461 DBG(("%s %d %p", name, query, opts.dns_conn));
9462
9463 /* resolve with DNS */
9464 req = (struct mg_resolve_async_request *) MG_CALLOC(1, sizeof(*req));
9465 if (req == NULL) {
9466 return -1;
9467 }
9468
9469 memset(req->name, 0, sizeof(req->name));
9470 strncpy(req->name, name, sizeof(req->name)-1);
9471 req->query = query;
9472 req->callback = cb;
9473 req->data = data;
9474 /* TODO(mkm): parse defaults out of resolve.conf */
9475 req->max_retries = opts.max_retries ? opts.max_retries : 2;
9476 req->timeout = opts.timeout ? opts.timeout : 5;
9477
9478 /* Lazily initialize dns server */
9479 if (nameserver == NULL && mg_dns_server[0] == '\0' &&
9481 -1) {
9483 }
9484
9485 if (nameserver == NULL) {
9486 nameserver = mg_dns_server;
9487 }
9488
9489 dns_nc = mg_connect(mgr, nameserver, mg_resolve_async_eh);
9490 if (dns_nc == NULL) {
9491 free(req);
9492 return -1;
9493 }
9494 dns_nc->user_data = req;
9495 if (opts.dns_conn != NULL) {
9496 *opts.dns_conn = dns_nc;
9497 }
9498
9499 return 0;
9500}
struct mg_connection * mg_connect(struct mg_mgr *mgr, const char *address, mg_event_handler_t callback)
static void mg_resolve_async_eh(struct mg_connection *nc, int ev, void *data)
MG_INTERNAL char mg_dns_server[300]
#define MG_CALLOC
Definition mongoose6.cxx:18
static const char * mg_default_dns_server
static int mg_get_ip_address_of_nameserver(char *name, size_t name_len)
mg_resolve_callback_t callback
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_resolve_from_hosts_file()

int mg_resolve_from_hosts_file ( const char host,
union socket_address usa 
)

Definition at line 9352 of file mongoose6.cxx.

9352 {
9353#ifndef MG_DISABLE_FILESYSTEM
9354 /* TODO(mkm) cache /etc/hosts */
9355 FILE *fp;
9356 char line[1024];
9357 char *p;
9358 char alias[256];
9359 unsigned int a, b, c, d;
9360 int len = 0;
9361
9362 if ((fp = fopen("/etc/hosts", "r")) == NULL) {
9363 return -1;
9364 }
9365
9366 for (; fgets(line, sizeof(line), fp) != NULL;) {
9367 if (line[0] == '#') continue;
9368
9369 if (sscanf(line, "%u.%u.%u.%u%n", &a, &b, &c, &d, &len) == 0) {
9370 /* TODO(mkm): handle ipv6 */
9371 continue;
9372 }
9373 for (p = line + len; sscanf(p, "%s%n", alias, &len) == 1; p += len) {
9374 if (strcmp(alias, name) == 0) {
9375 usa->sin.sin_addr.s_addr = htonl(a << 24 | b << 16 | c << 8 | d);
9376 fclose(fp);
9377 return 0;
9378 }
9379 }
9380 }
9381
9382 fclose(fp);
9383#endif
9384
9385 return -1;
9386}
struct sockaddr_in sin
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_rpc_create_error()

int mg_rpc_create_error ( char buf,
int  len,
struct mg_rpc_request req,
int  code,
const char message,
const char fmt,
  ... 
)

Definition at line 8219 of file mongoose6.cxx.

8220 {
8221 va_list ap;
8222 int n = 0;
8223
8224 n += json_emit(buf + n, len - n, "{s:s,s:V,s:{s:i,s:s,s:", "jsonrpc", "2.0",
8225 "id", req->id == NULL ? "null" : req->id->ptr,
8226 req->id == NULL ? 4 : req->id->len, "error", "code",
8227 (long) code, "message", message, "data");
8228 va_start(ap, fmt);
8229 n += json_emit_va(buf + n, len - n, fmt, ap);
8230 va_end(ap);
8231
8232 n += json_emit(buf + n, len - n, "}}");
8233
8234 return n;
8235}
struct json_token * id
Definition mongoose6.h:2732
int json_emit(char *buf, int buf_len, const char *fmt,...)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_rpc_create_reply()

int mg_rpc_create_reply ( char buf,
int  len,
const struct mg_rpc_request req,
const char result_fmt,
  ... 
)

Definition at line 8179 of file mongoose6.cxx.

8180 {
8181 static const struct json_token null_tok = {"null", 4, 0, JSON_TYPE_NULL};
8182 const struct json_token *id = req->id == NULL ? &null_tok : req->id;
8183 va_list ap;
8184 int n = 0;
8185
8186 n += json_emit(buf + n, len - n, "{s:s,s:", "jsonrpc", "2.0", "id");
8187 if (id->type == JSON_TYPE_STRING) {
8188 n += json_emit_quoted_str(buf + n, len - n, id->ptr, id->len);
8189 } else {
8190 n += json_emit_unquoted_str(buf + n, len - n, id->ptr, id->len);
8191 }
8192 n += json_emit(buf + n, len - n, ",s:", "result");
8193
8194 va_start(ap, result_fmt);
8195 n += json_emit_va(buf + n, len - n, result_fmt, ap);
8196 va_end(ap);
8197
8198 n += json_emit(buf + n, len - n, "}");
8199
8200 return n;
8201}
const char * ptr
Definition mongoose6.h:1072
enum json_type type
Definition mongoose6.h:1075
Here is the call graph for this function:

◆ mg_rpc_create_request()

int mg_rpc_create_request ( char buf,
int  len,
const char method,
const char id,
const char params_fmt,
  ... 
)

Definition at line 8203 of file mongoose6.cxx.

8204 {
8205 va_list ap;
8206 int n = 0;
8207
8208 n += json_emit(buf + n, len - n, "{s:s,s:s,s:s,s:", "jsonrpc", "2.0", "id",
8209 id, "method", method, "params");
8210 va_start(ap, params_fmt);
8211 n += json_emit_va(buf + n, len - n, params_fmt, ap);
8212 va_end(ap);
8213
8214 n += json_emit(buf + n, len - n, "}");
8215
8216 return n;
8217}
Here is the call graph for this function:

◆ mg_rpc_create_std_error()

int mg_rpc_create_std_error ( char buf,
int  len,
struct mg_rpc_request req,
int  code 
)

Definition at line 8237 of file mongoose6.cxx.

8238 {
8239 const char *message = NULL;
8240
8241 switch (code) {
8243 message = "parse error";
8244 break;
8246 message = "invalid request";
8247 break;
8249 message = "method not found";
8250 break;
8252 message = "invalid parameters";
8253 break;
8255 message = "server error";
8256 break;
8257 default:
8258 message = "unspecified error";
8259 break;
8260 }
8261
8262 return mg_rpc_create_error(buf, len, req, code, message, "N");
8263}
#define JSON_RPC_INVALID_PARAMS_ERROR
Definition mongoose6.h:2809
int mg_rpc_create_error(char *buf, int len, struct mg_rpc_request *req, int code, const char *message, const char *fmt,...)
#define JSON_RPC_SERVER_ERROR
Definition mongoose6.h:2811
#define JSON_RPC_PARSE_ERROR
Definition mongoose6.h:2806
#define JSON_RPC_METHOD_NOT_FOUND_ERROR
Definition mongoose6.h:2808
#define JSON_RPC_INVALID_REQUEST_ERROR
Definition mongoose6.h:2807
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_rpc_dispatch()

int mg_rpc_dispatch ( const char buf,
int  len,
char dst,
int  dst_len,
const char **  methods,
mg_rpc_handler_t handlers 
)

Definition at line 8265 of file mongoose6.cxx.

8266 {
8267 struct json_token tokens[200];
8268 struct mg_rpc_request req;
8269 int i, n;
8270
8271 memset(&req, 0, sizeof(req));
8272 n = parse_json(buf, len, tokens, sizeof(tokens) / sizeof(tokens[0]));
8273 if (n <= 0) {
8276 return mg_rpc_create_std_error(dst, dst_len, &req, err_code);
8277 }
8278
8279 req.message = tokens;
8280 req.id = find_json_token(tokens, "id");
8281 req.method = find_json_token(tokens, "method");
8282 req.params = find_json_token(tokens, "params");
8283
8284 if (req.id == NULL || req.method == NULL) {
8285 return mg_rpc_create_std_error(dst, dst_len, &req,
8287 }
8288
8289 for (i = 0; methods[i] != NULL; i++) {
8290 int mlen = strlen(methods[i]);
8291 if (mlen == req.method->len &&
8292 memcmp(methods[i], req.method->ptr, mlen) == 0)
8293 break;
8294 }
8295
8296 if (methods[i] == NULL) {
8297 return mg_rpc_create_std_error(dst, dst_len, &req,
8299 }
8300
8301 return handlers[i](dst, dst_len, &req);
8302}
int parse_json(const char *s, int s_len, struct json_token *arr, int arr_len)
struct json_token * find_json_token(struct json_token *toks, const char *path)
int mg_rpc_create_std_error(char *buf, int len, struct mg_rpc_request *req, int code)
#define JSON_STRING_INVALID
Definition mongoose6.h:1079
Here is the call graph for this function:

◆ mg_rpc_parse_reply()

int mg_rpc_parse_reply ( const char buf,
int  len,
struct json_token toks,
int  max_toks,
struct mg_rpc_reply rep,
struct mg_rpc_error er 
)

Definition at line 8304 of file mongoose6.cxx.

8306 {
8307 int n = parse_json(buf, len, toks, max_toks);
8308
8309 memset(rep, 0, sizeof(*rep));
8310 memset(er, 0, sizeof(*er));
8311
8312 if (n > 0) {
8313 if ((rep->result = find_json_token(toks, "result")) != NULL) {
8314 rep->message = toks;
8315 rep->id = find_json_token(toks, "id");
8316 } else {
8317 er->message = toks;
8318 er->id = find_json_token(toks, "id");
8319 er->error_code = find_json_token(toks, "error.code");
8320 er->error_message = find_json_token(toks, "error.message");
8321 er->error_data = find_json_token(toks, "error.data");
8322 }
8323 }
8324 return n;
8325}
Here is the call graph for this function:

◆ mg_send()

void mg_send ( struct mg_connection nc,
const void buf,
int  len 
)

Definition at line 2642 of file mongoose6.cxx.

2642 {
2643 nc->last_io_time = mg_time();
2644 if (nc->flags & MG_F_UDP) {
2645 mg_if_udp_send(nc, buf, len);
2646 } else {
2647 mg_if_tcp_send(nc, buf, len);
2648 }
2649#if !defined(NO_LIBC) && !defined(MG_DISABLE_HEXDUMP)
2650 if (nc->mgr && nc->mgr->hexdump_file != NULL) {
2651 mg_hexdump_connection(nc, nc->mgr->hexdump_file, buf, len, MG_EV_SEND);
2652 }
2653#endif
2654}
const char * hexdump_file
Definition mongoose6.h:1232
void mg_if_tcp_send(struct mg_connection *nc, const void *buf, size_t len)
void mg_hexdump_connection(struct mg_connection *nc, const char *path, const void *buf, int num_bytes, int ev)
void mg_if_udp_send(struct mg_connection *nc, const void *buf, size_t len)
time_t last_io_time
Definition mongoose6.h:1259
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_send_dns_query()

void mg_send_dns_query ( struct mg_connection nc,
const char name,
int  query_type 
)

Definition at line 8961 of file mongoose6.cxx.

8962 {
8963 struct mg_dns_message *msg =
8964 (struct mg_dns_message *) MG_CALLOC(1, sizeof(*msg));
8965 struct mbuf pkt;
8966 struct mg_dns_resource_record *rr = &msg->questions[0];
8967
8968 DBG(("%s %d", name, query_type));
8969
8970 mbuf_init(&pkt, 64 /* Start small, it'll grow as needed. */);
8971
8972 msg->transaction_id = ++mg_dns_tid;
8973 msg->flags = 0x100;
8974 msg->num_questions = 1;
8975
8976 mg_dns_insert_header(&pkt, 0, msg);
8977
8978 rr->rtype = query_type;
8979 rr->rclass = 1; /* Class: inet */
8980 rr->kind = MG_DNS_QUESTION;
8981
8982 if (mg_dns_encode_record(&pkt, rr, name, strlen(name), NULL, 0) == -1) {
8983 /* TODO(mkm): return an error code */
8984 goto cleanup; /* LCOV_EXCL_LINE */
8985 }
8986
8987 /* TCP DNS requires messages to be prefixed with len */
8988 if (!(nc->flags & MG_F_UDP)) {
8989 uint16_t len = htons(pkt.len);
8990 mbuf_insert(&pkt, 0, &len, 2);
8991 }
8992
8993 mg_send(nc, pkt.buf, pkt.len);
8994 mbuf_free(&pkt);
8995
8996cleanup:
8997 MG_FREE(msg);
8998}
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)
int mg_dns_insert_header(struct mbuf *io, size_t pos, struct mg_dns_message *msg)
void mbuf_free(struct mbuf *mbuf)
static int mg_dns_tid
Here is the call graph for this function:

◆ mg_send_head()

void mg_send_head ( struct mg_connection n,
int  status_code,
int64_t  content_length,
const char extra_headers 
)

Definition at line 5626 of file mongoose6.cxx.

5627 {
5628 mg_send_response_line(c, status_code, extra_headers);
5629 if (content_length < 0) {
5630 mg_printf(c, "%s", "Transfer-Encoding: chunked\r\n");
5631 } else {
5632 mg_printf(c, "Content-Length: %" INT64_FMT "\r\n", content_length);
5633 }
5634 mg_send(c, "\r\n", 2);
5635}
void mg_send_response_line(struct mg_connection *nc, int status_code, const char *extra_headers)
#define INT64_FMT
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_send_http_chunk()

void mg_send_http_chunk ( struct mg_connection nc,
const char buf,
size_t  len 
)

Definition at line 6027 of file mongoose6.cxx.

6027 {
6028 char chunk_size[50];
6029 int n;
6030
6031 n = snprintf(chunk_size, sizeof(chunk_size), "%lX\r\n", (unsigned long) len);
6032 mg_send(nc, chunk_size, n);
6033 mg_send(nc, buf, len);
6034 mg_send(nc, "\r\n", 2);
6035}
Here is the call graph for this function:

◆ mg_send_mqtt_handshake()

void mg_send_mqtt_handshake ( struct mg_connection nc,
const char client_id 
)

Definition at line 8438 of file mongoose6.cxx.

8438 {
8439 static struct mg_send_mqtt_handshake_opts opts;
8440 mg_send_mqtt_handshake_opt(nc, client_id, opts);
8441}
void mg_send_mqtt_handshake_opt(struct mg_connection *nc, const char *client_id, struct mg_send_mqtt_handshake_opts opts)
Here is the call graph for this function:

◆ mg_send_mqtt_handshake_opt()

void mg_send_mqtt_handshake_opt ( struct mg_connection nc,
const char client_id,
struct mg_send_mqtt_handshake_opts  opts 
)

Definition at line 8443 of file mongoose6.cxx.

8444 {
8445 uint8_t header = MG_MQTT_CMD_CONNECT << 4;
8447 uint16_t keep_alive;
8449
8450 /*
8451 * 9: version_header(len, magic_string, version_number), 1: flags, 2:
8452 * keep-alive timer,
8453 * 2: client_identifier_len, n: client_id
8454 */
8455 rem_len = 9 + 1 + 2 + 2 + strlen(client_id);
8456
8457 mg_send(nc, &header, 1);
8458 mg_send(nc, &rem_len, 1);
8459 mg_send(nc, "\00\06MQIsdp\03", 9);
8460 mg_send(nc, &opts.flags, 1);
8461
8462 if (opts.keep_alive == 0) {
8463 opts.keep_alive = 60;
8464 }
8465 keep_alive = htons(opts.keep_alive);
8466 mg_send(nc, &keep_alive, 2);
8467
8468 client_id_len = htons(strlen(client_id));
8469 mg_send(nc, &client_id_len, 2);
8470 mg_send(nc, client_id, strlen(client_id));
8471}
#define MG_MQTT_CMD_CONNECT
Definition mongoose6.h:2900
Here is the call graph for this function:

◆ mg_send_response_line()

void mg_send_response_line ( struct mg_connection c,
int  status_code,
const char extra_headers 
)

Definition at line 5588 of file mongoose6.cxx.

5589 {
5590 const char *status_message = "OK";
5591 switch (status_code) {
5592 case 206:
5593 status_message = "Partial Content";
5594 break;
5595 case 301:
5596 status_message = "Moved";
5597 break;
5598 case 302:
5599 status_message = "Found";
5600 break;
5601 case 401:
5602 status_message = "Unauthorized";
5603 break;
5604 case 403:
5605 status_message = "Forbidden";
5606 break;
5607 case 404:
5608 status_message = "Not Found";
5609 break;
5610 case 416:
5611 status_message = "Requested range not satisfiable";
5612 break;
5613 case 418:
5614 status_message = "I'm a teapot";
5615 break;
5616 case 500:
5617 status_message = "Internal Server Error";
5618 break;
5619 }
5620 mg_printf(nc, "HTTP/1.1 %d %s\r\n", status_code, status_message);
5621 if (extra_headers != NULL) {
5622 mg_printf(nc, "%s\r\n", extra_headers);
5623 }
5624}
Here is the call graph for this function:

◆ mg_send_websocket_frame()

void mg_send_websocket_frame ( struct mg_connection nc,
int  op_and_flags,
const void data,
size_t  data_len 
)

Definition at line 4661 of file mongoose6.cxx.

4662 {
4663 struct ws_mask_ctx ctx;
4664 DBG(("%p %d %d", nc, op, (int) len));
4665 mg_send_ws_header(nc, op, len, &ctx);
4666 mg_send(nc, data, len);
4667
4668 mg_ws_mask_frame(&nc->send_mbuf, &ctx);
4669
4670 if (op == WEBSOCKET_OP_CLOSE) {
4672 }
4673}
#define WEBSOCKET_OP_CLOSE
Definition mongoose6.h:2349
static void mg_ws_mask_frame(struct mbuf *mbuf, struct ws_mask_ctx *ctx)
static void mg_send_ws_header(struct mg_connection *nc, int op, size_t len, struct ws_mask_ctx *ctx)
Here is the call graph for this function:

◆ mg_send_websocket_framev()

void mg_send_websocket_framev ( struct mg_connection nc,
int  op_and_flags,
const struct mg_str strings,
int  num_strings 
)

Definition at line 4675 of file mongoose6.cxx.

4676 {
4677 struct ws_mask_ctx ctx;
4678 int i;
4679 int len = 0;
4680 for (i = 0; i < strvcnt; i++) {
4681 len += strv[i].len;
4682 }
4683
4684 mg_send_ws_header(nc, op, len, &ctx);
4685
4686 for (i = 0; i < strvcnt; i++) {
4687 mg_send(nc, strv[i].p, strv[i].len);
4688 }
4689
4690 mg_ws_mask_frame(&nc->send_mbuf, &ctx);
4691
4692 if (op == WEBSOCKET_OP_CLOSE) {
4694 }
4695}
Here is the call graph for this function:

◆ mg_send_websocket_handshake()

void mg_send_websocket_handshake ( struct mg_connection nc,
const char uri,
const char extra_headers 
)

Definition at line 5580 of file mongoose6.cxx.

5581 {
5583 extra_headers);
5584}
#define MG_WS_NO_HOST_HEADER_MAGIC
Here is the call graph for this function:

◆ mg_send_websocket_handshake2()

void mg_send_websocket_handshake2 ( struct mg_connection nc,
const char path,
const char host,
const char protocol,
const char extra_headers 
)

Definition at line 5551 of file mongoose6.cxx.

5553 {
5554 /* pretty poor source of randomness, TODO fix */
5555 unsigned long random = (unsigned long) path;
5556 char key[sizeof(random) * 3];
5557
5558 mg_base64_encode((unsigned char *) &random, sizeof(random), key);
5559 mg_printf(nc,
5560 "GET %s HTTP/1.1\r\n"
5561 "Upgrade: websocket\r\n"
5562 "Connection: Upgrade\r\n"
5563 "Sec-WebSocket-Version: 13\r\n"
5564 "Sec-WebSocket-Key: %s\r\n",
5565 path, key);
5566
5567 /* TODO(mkm): take default hostname from http proto data if host == NULL */
5568 if (host != MG_WS_NO_HOST_HEADER_MAGIC) {
5569 mg_printf(nc, "Host: %s\r\n", host);
5570 }
5571 if (protocol != NULL) {
5572 mg_printf(nc, "Sec-WebSocket-Protocol: %s\r\n", protocol);
5573 }
5574 if (extra_headers != NULL) {
5575 mg_printf(nc, "%s", extra_headers);
5576 }
5577 mg_printf(nc, "\r\n");
5578}
void mg_base64_encode(const unsigned char *src, int src_len, char *dst)
long int random(void)
Here is the call graph for this function:

◆ mg_serve_http()

void mg_serve_http ( struct mg_connection nc,
struct http_message hm,
struct mg_serve_http_opts  opts 
)

Definition at line 7512 of file mongoose6.cxx.

7513 {
7514 char *path = NULL;
7515 struct mg_str *hdr, path_info;
7516 uint32_t remote_ip = ntohl(*(uint32_t *) &nc->sa.sin.sin_addr);
7517
7518 if (mg_check_ip_acl(opts.ip_acl, remote_ip) != 1) {
7519 /* Not allowed to connect */
7520 mg_http_send_error(nc, 403, NULL);
7522 return;
7523 }
7524
7526 return;
7527 }
7528
7529 if (opts.document_root == NULL) {
7530 opts.document_root = ".";
7531 }
7532 if (opts.per_directory_auth_file == NULL) {
7533 opts.per_directory_auth_file = ".htpasswd";
7534 }
7535 if (opts.enable_directory_listing == NULL) {
7536 opts.enable_directory_listing = "yes";
7537 }
7538 if (opts.cgi_file_pattern == NULL) {
7539 opts.cgi_file_pattern = "**.cgi$|**.php$";
7540 }
7541 if (opts.ssi_pattern == NULL) {
7542 opts.ssi_pattern = "**.shtml$|**.shtm$";
7543 }
7544 if (opts.index_files == NULL) {
7545 opts.index_files = "index.html,index.htm,index.shtml,index.cgi,index.php";
7546 }
7547 /* Normalize path - resolve "." and ".." (in-place). */
7548 if (!mg_normalize_uri_path(&hm->uri, &hm->uri)) {
7549 mg_http_send_error(nc, 400, NULL);
7550 return;
7551 }
7552 if (mg_uri_to_local_path(hm, &opts, &path, &path_info) == 0) {
7553 mg_http_send_error(nc, 404, NULL);
7554 return;
7555 }
7556 mg_send_http_file(nc, path, &path_info, hm, &opts);
7557
7558 MG_FREE(path);
7559 path = NULL;
7560
7561 /* Close connection for non-keep-alive requests */
7562 if (mg_vcmp(&hm->proto, "HTTP/1.1") != 0 ||
7563 ((hdr = mg_get_http_header(hm, "Connection")) != NULL &&
7564 mg_vcmp(hdr, "keep-alive") != 0)) {
7565#if 0
7567#endif
7568 }
7569}
int mg_normalize_uri_path(const struct mg_str *in, struct mg_str *out)
struct mg_str * mg_get_http_header(struct http_message *hm, const char *name)
int mg_check_ip_acl(const char *acl, uint32_t remote_ip)
MG_INTERNAL int mg_uri_to_local_path(struct http_message *hm, const struct mg_serve_http_opts *opts, char **local_path, struct mg_str *remainder)
MG_INTERNAL void mg_send_http_file(struct mg_connection *nc, char *path, const struct mg_str *path_info, struct http_message *hm, struct mg_serve_http_opts *opts)
static void mg_http_send_error(struct mg_connection *nc, int code, const char *reason)
static int mg_http_send_port_based_redirect(struct mg_connection *c, struct http_message *hm, const struct mg_serve_http_opts *opts)
Here is the call graph for this function:

◆ mg_set_close_on_exec()

void mg_set_close_on_exec ( sock_t  sock)

Definition at line 7906 of file mongoose6.cxx.

7906 {
7907#ifdef _WIN32
7909#elif defined(__unix__)
7910 fcntl(sock, F_SETFD, FD_CLOEXEC);
7911#else
7912 (void) sock;
7913#endif
7914}
Here is the call graph for this function:

◆ mg_set_protocol_dns()

void mg_set_protocol_dns ( struct mg_connection nc)

Definition at line 9164 of file mongoose6.cxx.

9164 {
9166}
static void dns_handler(struct mg_connection *nc, int ev, void *ev_data)
Here is the call graph for this function:

◆ mg_set_protocol_http_websocket()

void mg_set_protocol_http_websocket ( struct mg_connection nc)

Definition at line 5545 of file mongoose6.cxx.

5545 {
5547}
void mg_http_handler(struct mg_connection *nc, int ev, void *ev_data)
Here is the call graph for this function:

◆ mg_set_protocol_mqtt()

void mg_set_protocol_mqtt ( struct mg_connection nc)

Definition at line 8434 of file mongoose6.cxx.

8434 {
8436}
static void mqtt_handler(struct mg_connection *nc, int ev, void *ev_data)
Here is the call graph for this function:

◆ mg_set_ssl()

const char * mg_set_ssl ( struct mg_connection nc,
const char cert,
const char ca_cert 
)
Here is the caller graph for this function:

◆ mg_set_timer()

double mg_set_timer ( struct mg_connection c,
double  timestamp 
)

Definition at line 3035 of file mongoose6.cxx.

3035 {
3036 double result = c->ev_timer_time;
3037 c->ev_timer_time = timestamp;
3038 /*
3039 * If this connection is resolving, it's not in the list of active
3040 * connections, so not processed yet. It has a DNS resolver connection
3041 * linked to it. Set up a timer for the DNS connection.
3042 */
3043 DBG(("%p %p %d -> %lu", c, c->priv_2, c->flags & MG_F_RESOLVING,
3044 (unsigned long) timestamp));
3045 if ((c->flags & MG_F_RESOLVING) && c->priv_2 != NULL) {
3046 ((struct mg_connection *) c->priv_2)->ev_timer_time = timestamp;
3047 }
3048 return result;
3049}
Here is the call graph for this function:

◆ mg_skip()

const char * mg_skip ( const char s,
const char end_string,
const char delimiters,
struct mg_str v 
)

Definition at line 7795 of file mongoose6.cxx.

7796 {
7797 v->p = s;
7798 while (s < end && strchr(delims, *(unsigned char *) s) == NULL) s++;
7799 v->len = s - v->p;
7800 while (s < end && strchr(delims, *(unsigned char *) s) != NULL) s++;
7801 return s;
7802}
Here is the call graph for this function:

◆ mg_sock_addr_to_str()

void mg_sock_addr_to_str ( const union socket_address sa,
char buf,
size_t  len,
int  flags 
)

Definition at line 7916 of file mongoose6.cxx.

7917 {
7918 int is_v6;
7919 if (buf == NULL || len <= 0) return;
7920 buf[0] = '\0';
7921#if defined(MG_ENABLE_IPV6)
7922 is_v6 = sa->sa.sa_family == AF_INET6;
7923#else
7924 is_v6 = 0;
7925#endif
7926 if (flags & MG_SOCK_STRINGIFY_IP) {
7927#if defined(MG_ENABLE_IPV6)
7928 const void *addr = NULL;
7929 char *start = buf;
7930 socklen_t capacity = len;
7931 if (!is_v6) {
7932 addr = &sa->sin.sin_addr;
7933 } else {
7934 addr = (void *) &sa->sin6.sin6_addr;
7935 if (flags & MG_SOCK_STRINGIFY_PORT) {
7936 *buf = '[';
7937 start++;
7938 capacity--;
7939 }
7940 }
7941 if (inet_ntop(sa->sa.sa_family, addr, start, capacity) == NULL) {
7942 *buf = '\0';
7943 }
7944#elif defined(_WIN32) || defined(MG_LWIP)
7945 /* Only Windoze Vista (and newer) have inet_ntop() */
7946 strncpy(buf, inet_ntoa(sa->sin.sin_addr), len);
7947#else
7948 inet_ntop(AF_INET, (void *) &sa->sin.sin_addr, buf, len);
7949#endif
7950 }
7951 if (flags & MG_SOCK_STRINGIFY_PORT) {
7952 int port = ntohs(sa->sin.sin_port);
7953 if (flags & MG_SOCK_STRINGIFY_IP) {
7954 snprintf(buf + strlen(buf), len - (strlen(buf) + 1), "%s:%d",
7955 (is_v6 ? "]" : ""), port);
7956 } else {
7957 snprintf(buf, len, "%d", port);
7958 }
7959 }
7960}
struct sockaddr sin6
Definition mongoose6.h:1200
const char * inet_ntop(int af, const void *src, char *dst, socklen_t size)
Here is the call graph for this function:

◆ mg_sock_set()

void mg_sock_set ( struct mg_connection nc,
sock_t  sock 
)

Definition at line 3556 of file mongoose6.cxx.

3556 {
3559 nc->sock = sock;
3560 DBG(("%p %d", nc, sock));
3561}
void mg_set_close_on_exec(sock_t sock)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_sock_to_str()

void mg_sock_to_str ( sock_t  sock,
char buf,
size_t  len,
int  flags 
)

Definition at line 3766 of file mongoose6.cxx.

3766 {
3767 union socket_address sa;
3769 mg_sock_addr_to_str(&sa, buf, len, flags);
3770}
Here is the call graph for this function:

◆ mg_socketpair()

int mg_socketpair ( sock_t  sp[2],
int  sock_type 
)

Definition at line 3711 of file mongoose6.cxx.

3711 {
3712 union socket_address sa;
3713 sock_t sock;
3714 socklen_t len = sizeof(sa.sin);
3715 int ret = 0;
3716
3717 sock = sp[0] = sp[1] = INVALID_SOCKET;
3718
3719 (void) memset(&sa, 0, sizeof(sa));
3720 sa.sin.sin_family = AF_INET;
3721 sa.sin.sin_port = htons(0);
3722 sa.sin.sin_addr.s_addr = htonl(0x7f000001); /* 127.0.0.1 */
3723
3724 if ((sock = socket(AF_INET, sock_type, 0)) == INVALID_SOCKET) {
3725 } else if (bind(sock, &sa.sa, len) != 0) {
3726 } else if (sock_type == SOCK_STREAM && listen(sock, 1) != 0) {
3727 } else if (getsockname(sock, &sa.sa, &len) != 0) {
3728 } else if ((sp[0] = socket(AF_INET, sock_type, 0)) == INVALID_SOCKET) {
3729 } else if (connect(sp[0], &sa.sa, len) != 0) {
3730 } else if (sock_type == SOCK_DGRAM &&
3731 (getsockname(sp[0], &sa.sa, &len) != 0 ||
3732 connect(sock, &sa.sa, len) != 0)) {
3733 } else if ((sp[1] = (sock_type == SOCK_DGRAM ? sock
3734 : accept(sock, &sa.sa, &len))) ==
3736 } else {
3739 if (sock_type == SOCK_STREAM) closesocket(sock);
3740 ret = 1;
3741 }
3742
3743 if (!ret) {
3744 if (sp[0] != INVALID_SOCKET) closesocket(sp[0]);
3745 if (sp[1] != INVALID_SOCKET) closesocket(sp[1]);
3746 if (sock != INVALID_SOCKET) closesocket(sock);
3747 sock = sp[0] = sp[1] = INVALID_SOCKET;
3748 }
3749
3750 return ret;
3751}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_stat()

int mg_stat ( const char path,
cs_stat_t st 
)

Definition at line 7841 of file mongoose6.cxx.

7841 {
7842#ifdef _WIN32
7843 wchar_t wpath[MAX_PATH_SIZE];
7844 to_wchar(path, wpath, ARRAY_SIZE(wpath));
7845 DBG(("[%ls] -> %d", wpath, _wstati64(wpath, st)));
7846 return _wstati64(wpath, (struct _stati64 *) st);
7847#else
7848 return stat(path, st);
7849#endif
7850}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_time()

double mg_time ( void  )

Definition at line 3069 of file mongoose6.cxx.

3069 {
3070 return cs_time();
3071}
Here is the call graph for this function:

◆ mg_url_decode()

int mg_url_decode ( const char src,
int  src_len,
char dst,
int  dst_len,
int  is_form_url_encoded 
)

Definition at line 2606 of file mongoose4.cxx.

2607 {
2608 int i, j, a, b;
2609#define HEXTOI(x) (isdigit(x) ? x - '0' : x - 'W')
2610
2611 for (i = j = 0; i < src_len && j < dst_len - 1; i++, j++) {
2612 if (src[i] == '%' && i < src_len - 2 &&
2613 isxdigit(* (const unsigned char *) (src + i + 1)) &&
2614 isxdigit(* (const unsigned char *) (src + i + 2))) {
2615 a = tolower(* (const unsigned char *) (src + i + 1));
2616 b = tolower(* (const unsigned char *) (src + i + 2));
2617 dst[j] = (char) ((HEXTOI(a) << 4) | HEXTOI(b));
2618 i += 2;
2619 } else if (is_form_url_encoded && src[i] == '+') {
2620 dst[j] = ' ';
2621 } else {
2622 dst[j] = src[i];
2623 }
2624 }
2625
2626 dst[j] = '\0'; // Null-terminate the destination
2627
2628 return i >= src_len ? j : -1;
2629}
#define HEXTOI(x)

◆ mg_vcasecmp()

int mg_vcasecmp ( const struct mg_str str2,
const char str1 
)

Definition at line 1717 of file mongoose614.cxx.

1717 {
1718 size_t n2 = strlen(str2), n1 = str1->len;
1719 int r = mg_ncasecmp(str1->p, str2, (n1 < n2) ? n1 : n2);
1720 if (r == 0) {
1721 return n1 - n2;
1722 }
1723 return r;
1724}
Here is the call graph for this function:

◆ mg_vcmp()

int mg_vcmp ( const struct mg_str str2,
const char str1 
)

Definition at line 1707 of file mongoose614.cxx.

1707 {
1708 size_t n2 = strlen(str2), n1 = str1->len;
1709 int r = strncmp(str1->p, str2, (n1 < n2) ? n1 : n2);
1710 if (r == 0) {
1711 return n1 - n2;
1712 }
1713 return r;
1714}
Here is the call graph for this function:

◆ mg_vprintf()

int mg_vprintf ( struct mg_connection conn,
const char fmt,
va_list  ap 
)

Definition at line 1908 of file mongoose4.cxx.

1908 {
1909 char mem[MG_BUF_LEN], *buf = mem;
1910 int len;
1911
1912 if ((len = alloc_vprintf(&buf, sizeof(mem), fmt, ap)) > 0) {
1913 len = mg_write(conn, buf, (size_t) len);
1914 }
1915 if (buf != mem && buf != NULL) {
1916 free(buf);
1917 }
1918
1919 return len;
1920}
int mg_write(struct mg_connection *conn, const void *buf, int len)
static int alloc_vprintf(char **buf, size_t size, const char *fmt, va_list ap)
#define MG_BUF_LEN
Here is the call graph for this function:

◆ parse_json()

int parse_json ( const char json_string,
int  json_string_length,
struct json_token tokens_array,
int  size_of_tokens_array 
)

Definition at line 923 of file mongoose6.cxx.

923 {
924 struct frozen frozen;
925
926 memset(&frozen, 0, sizeof(frozen));
927 frozen.end = s + s_len;
928 frozen.cur = s;
929 frozen.tokens = arr;
931
932 TRY(doit(&frozen));
933
934 return frozen.cur - s;
935}
static int doit(struct frozen *f)
#define TRY(expr)
const char * end
const char * cur
int max_tokens
struct json_token * tokens
Here is the call graph for this function:
Here is the caller graph for this function:

◆ parse_json2()

struct json_token * parse_json2 ( const char json_string,
int  string_length 
)

Definition at line 937 of file mongoose6.cxx.

937 {
938 struct frozen frozen;
939
940 memset(&frozen, 0, sizeof(frozen));
941 frozen.end = s + s_len;
942 frozen.cur = s;
943 frozen.do_realloc = 1;
944
945 if (doit(&frozen) < 0) {
946 FROZEN_FREE((void *) frozen.tokens);
948 }
949 return frozen.tokens;
950}
#define FROZEN_FREE
int do_realloc
Here is the call graph for this function:

Variable Documentation

◆ accept_literal

int mg_resolve_async_opts::accept_literal

Definition at line 3424 of file mongoose6.h.

◆ active_connections

struct mg_connection * mg_mgr::active_connections

Definition at line 1231 of file mongoose6.h.

◆ answers

struct mg_dns_resource_record mg_dns_message::answers

Definition at line 3197 of file mongoose6.h.

◆ auth_domain

const char* mg_serve_http_opts::auth_domain

Definition at line 2539 of file mongoose6.h.

◆ b64_putc

cs_base64_putc_t cs_base64_ctx::b64_putc

Definition at line 981 of file mongoose6.h.

◆ bits

uint32_t MD5Context::bits

Definition at line 932 of file mongoose6.h.

◆ body

struct mg_str http_message::body

Definition at line 2094 of file mongoose6.h.

◆ buf [1/2]

char * mbuf::buf

Definition at line 834 of file mongoose6.h.

◆ buf [2/2]

uint32_t MD5Context::buf

Definition at line 931 of file mongoose6.h.

◆ buffer

unsigned char cs_sha1_ctx::buffer

Definition at line 901 of file mongoose6.h.

◆ cgi_file_pattern

const char* mg_serve_http_opts::cgi_file_pattern

Definition at line 2597 of file mongoose6.h.

◆ cgi_interpreter

const char* mg_serve_http_opts::cgi_interpreter

Definition at line 2600 of file mongoose6.h.

◆ chunk

unsigned char cs_base64_ctx::chunk

Definition at line 982 of file mongoose6.h.

◆ chunk_size

int cs_base64_ctx::chunk_size

Definition at line 983 of file mongoose6.h.

◆ cmd

int mg_mqtt_message::cmd

Definition at line 2877 of file mongoose6.h.

◆ connack_ret_code

uint8_t mg_mqtt_message::connack_ret_code

Definition at line 2880 of file mongoose6.h.

◆ count

uint32_t cs_sha1_ctx::count

Definition at line 900 of file mongoose6.h.

◆ cs_log_level

Definition at line 340 of file mongoose6.cxx.

◆ ctl

sock_t mg_mgr::ctl[2]

Definition at line 1234 of file mongoose6.h.

◆ custom_mime_types

const char* mg_serve_http_opts::custom_mime_types

Definition at line 2606 of file mongoose6.h.

◆ data [1/2]

unsigned char * websocket_message::data

Definition at line 2099 of file mongoose6.h.

◆ data [2/2]

struct mg_str mg_http_multipart_part::data

Definition at line 2108 of file mongoose6.h.

◆ dav_auth_file

const char* mg_serve_http_opts::dav_auth_file

Definition at line 2591 of file mongoose6.h.

◆ dav_document_root

const char* mg_serve_http_opts::dav_document_root

Definition at line 2585 of file mongoose6.h.

◆ dns_conn

struct mg_connection ** mg_resolve_async_opts::dns_conn

Definition at line 3426 of file mongoose6.h.

◆ document_root

const char* mg_serve_http_opts::document_root

Definition at line 2522 of file mongoose6.h.

◆ enable_directory_listing

const char* mg_serve_http_opts::enable_directory_listing

Definition at line 2552 of file mongoose6.h.

◆ err

int mg_connection::err

Definition at line 1252 of file mongoose6.h.

◆ error_code

struct json_token* mg_rpc_error::error_code

Definition at line 2748 of file mongoose6.h.

◆ error_data

struct json_token* mg_rpc_error::error_data

Definition at line 2750 of file mongoose6.h.

◆ error_message

struct json_token* mg_rpc_error::error_message

Definition at line 2749 of file mongoose6.h.

◆ error_string [1/3]

const char ** mg_add_sock_opts::error_string

Definition at line 1368 of file mongoose6.h.

◆ error_string [2/3]

const char ** mg_bind_opts::error_string

Definition at line 1398 of file mongoose6.h.

◆ error_string [3/3]

const char ** mg_connect_opts::error_string

Definition at line 1438 of file mongoose6.h.

◆ ev_timer_time

double mg_connection::ev_timer_time

Definition at line 1260 of file mongoose6.h.

◆ extra_headers

const char* mg_serve_http_opts::extra_headers

Definition at line 2612 of file mongoose6.h.

◆ [] [1/2]

mg_event_handler_t { ... } ::f

Definition at line 1272 of file mongoose6.h.

◆ f [2/2]

mg_event_handler_t mg_connection::f

Definition at line 1272 of file mongoose6.h.

◆ file_name

const char * mg_http_multipart_part::file_name

Definition at line 2106 of file mongoose6.h.

◆ flags [1/7]

unsigned long mg_connection::flags

Definition at line 1276 of file mongoose6.h.

◆ flags [2/7]

unsigned int mg_add_sock_opts::flags

Definition at line 1367 of file mongoose6.h.

◆ flags [3/7]

unsigned int mg_bind_opts::flags

Definition at line 1397 of file mongoose6.h.

◆ flags [4/7]

unsigned int mg_connect_opts::flags

Definition at line 1437 of file mongoose6.h.

◆ flags [5/7]

unsigned char websocket_message::flags

Definition at line 2101 of file mongoose6.h.

◆ flags [6/7]

unsigned char mg_send_mqtt_handshake_opts::flags

Definition at line 2891 of file mongoose6.h.

◆ flags [7/7]

uint16_t mg_dns_message::flags

Definition at line 3192 of file mongoose6.h.

◆ global_auth_file

const char* mg_serve_http_opts::global_auth_file

Definition at line 2549 of file mongoose6.h.

◆ handler

mg_event_handler_t mg_connection::handler

Definition at line 1264 of file mongoose6.h.

◆ header_names

struct mg_str http_message::header_names

Definition at line 2090 of file mongoose6.h.

◆ header_values

struct mg_str http_message::header_values

Definition at line 2091 of file mongoose6.h.

◆ hexdump_file

const char* mg_mgr::hexdump_file

Definition at line 1232 of file mongoose6.h.

◆ hidden_file_pattern

const char* mg_serve_http_opts::hidden_file_pattern

Definition at line 2594 of file mongoose6.h.

◆ id [1/3]

struct json_token* mg_rpc_request::id

Definition at line 2732 of file mongoose6.h.

◆ id [2/3]

struct json_token* mg_rpc_reply::id

Definition at line 2740 of file mongoose6.h.

◆ id [3/3]

struct json_token* mg_rpc_error::id

Definition at line 2747 of file mongoose6.h.

◆ in

unsigned char MD5Context::in

Definition at line 933 of file mongoose6.h.

◆ index_files

const char* mg_serve_http_opts::index_files

Definition at line 2525 of file mongoose6.h.

◆ ip_acl

const char* mg_serve_http_opts::ip_acl

Definition at line 2558 of file mongoose6.h.

◆ keep_alive

uint16_t mg_send_mqtt_handshake_opts::keep_alive

Definition at line 2892 of file mongoose6.h.

◆ kind

enum mg_dns_resource_record_kind mg_dns_resource_record::kind

Definition at line 3185 of file mongoose6.h.

◆ last_io_time

time_t mg_connection::last_io_time

Definition at line 1259 of file mongoose6.h.

◆ len [1/3]

size_t mbuf::len

Definition at line 835 of file mongoose6.h.

◆ len [2/3]

int json_token::len

Definition at line 1073 of file mongoose6.h.

◆ len [3/3]

size_t mg_str::len

Definition at line 1207 of file mongoose6.h.

◆ listener

struct mg_connection * mg_connection::listener

Definition at line 1248 of file mongoose6.h.

◆ max_retries

int mg_resolve_async_opts::max_retries

Definition at line 3422 of file mongoose6.h.

◆ message [1/4]

struct mg_str http_message::message

Definition at line 2068 of file mongoose6.h.

◆ message [2/4]

struct json_token* mg_rpc_request::message

Definition at line 2731 of file mongoose6.h.

◆ message [3/4]

struct json_token* mg_rpc_reply::message

Definition at line 2739 of file mongoose6.h.

◆ message [4/4]

struct json_token* mg_rpc_error::message

Definition at line 2746 of file mongoose6.h.

◆ message_id

uint16_t mg_mqtt_message::message_id

Definition at line 2881 of file mongoose6.h.

◆ method [1/2]

struct mg_str http_message::method

Definition at line 2071 of file mongoose6.h.

◆ method [2/2]

struct json_token* mg_rpc_request::method

Definition at line 2733 of file mongoose6.h.

◆ mgr

struct mg_mgr * mg_connection::mgr

Definition at line 1249 of file mongoose6.h.

◆ mgr_data [1/2]

void* mg_mgr::mgr_data

Definition at line 1237 of file mongoose6.h.

◆ mgr_data [2/2]

void * mg_connection::mgr_data

Definition at line 1275 of file mongoose6.h.

◆ name

struct mg_str mg_dns_resource_record::name

Definition at line 3181 of file mongoose6.h.

◆ nameserver_url

const char* mg_resolve_async_opts::nameserver_url

Definition at line 3421 of file mongoose6.h.

◆ next

struct mg_connection * mg_connection::next

Definition at line 1247 of file mongoose6.h.

◆ num_answers

int mg_dns_message::num_answers

Definition at line 3195 of file mongoose6.h.

◆ num_desc

int json_token::num_desc

Definition at line 1074 of file mongoose6.h.

◆ num_questions

int mg_dns_message::num_questions

Definition at line 3194 of file mongoose6.h.

◆ only_literal

int mg_resolve_async_opts::only_literal

Definition at line 3425 of file mongoose6.h.

◆ p

const char * mg_str::p

Definition at line 1206 of file mongoose6.h.

◆ params

struct json_token* mg_rpc_request::params

Definition at line 2734 of file mongoose6.h.

◆ password

const char * mg_send_mqtt_handshake_opts::password

Definition at line 2896 of file mongoose6.h.

◆ payload

struct mg_str mg_mqtt_message::payload

Definition at line 2878 of file mongoose6.h.

◆ per_directory_auth_file

const char* mg_serve_http_opts::per_directory_auth_file

Definition at line 2536 of file mongoose6.h.

◆ pkt

struct mg_str mg_dns_message::pkt

Definition at line 3191 of file mongoose6.h.

◆ prev

struct mg_connection * mg_connection::prev

Definition at line 1247 of file mongoose6.h.

◆ [union]

union { ... } mg_connection::priv_1

◆ priv_2

void * mg_connection::priv_2

Definition at line 1274 of file mongoose6.h.

◆ proto

struct mg_str http_message::proto

Definition at line 2073 of file mongoose6.h.

◆ proto_data

void * mg_connection::proto_data

Definition at line 1262 of file mongoose6.h.

◆ proto_data_destructor

void(* mg_connection::proto_data_destructor)(void *proto_data)

Definition at line 1263 of file mongoose6.h.

◆ proto_handler

mg_event_handler_t mg_connection::proto_handler

Definition at line 1261 of file mongoose6.h.

◆ ptr

const char* json_token::ptr

Definition at line 1072 of file mongoose6.h.

◆ qos [1/2]

int mg_mqtt_message::qos

Definition at line 2879 of file mongoose6.h.

◆ qos [2/2]

uint8_t mg_mqtt_topic_expression::qos

Definition at line 2887 of file mongoose6.h.

◆ query_string

struct mg_str http_message::query_string

Definition at line 2087 of file mongoose6.h.

◆ questions

struct mg_dns_resource_record mg_dns_message::questions

Definition at line 3196 of file mongoose6.h.

◆ rclass

int mg_dns_resource_record::rclass

Definition at line 3183 of file mongoose6.h.

◆ rdata

struct mg_str mg_dns_resource_record::rdata

Definition at line 3186 of file mongoose6.h.

◆ recv_mbuf

struct mbuf mg_connection::recv_mbuf

Definition at line 1255 of file mongoose6.h.

◆ recv_mbuf_limit

size_t mg_connection::recv_mbuf_limit

Definition at line 1254 of file mongoose6.h.

◆ resp_code

int http_message::resp_code

Definition at line 2076 of file mongoose6.h.

◆ resp_status_msg

struct mg_str http_message::resp_status_msg

Definition at line 2077 of file mongoose6.h.

◆ result

struct json_token* mg_rpc_reply::result

Definition at line 2741 of file mongoose6.h.

◆ rtype

int mg_dns_resource_record::rtype

Definition at line 3182 of file mongoose6.h.

◆ sa [1/2]

struct sockaddr socket_address::sa

Definition at line 1195 of file mongoose6.h.

◆ sa [2/2]

union socket_address mg_connection::sa

Definition at line 1253 of file mongoose6.h.

◆ send_mbuf

struct mbuf mg_connection::send_mbuf

Definition at line 1256 of file mongoose6.h.

◆ sin

struct sockaddr_in socket_address::sin

Definition at line 1196 of file mongoose6.h.

◆ sin6

struct sockaddr socket_address::sin6

Definition at line 1200 of file mongoose6.h.

◆ size [1/2]

size_t mbuf::size

Definition at line 836 of file mongoose6.h.

◆ size [2/2]

size_t websocket_message::size

Definition at line 2100 of file mongoose6.h.

◆ sock

sock_t mg_connection::sock

Definition at line 1251 of file mongoose6.h.

◆ ssi_pattern

const char* mg_serve_http_opts::ssi_pattern

Definition at line 2555 of file mongoose6.h.

◆ ssl

SSL * mg_connection::ssl

Definition at line 1257 of file mongoose6.h.

◆ ssl_ctx

SSL_CTX* mg_connection::ssl_ctx

Definition at line 1258 of file mongoose6.h.

◆ state

uint32_t cs_sha1_ctx::state

Definition at line 899 of file mongoose6.h.

◆ status

int mg_http_multipart_part::status

Definition at line 2109 of file mongoose6.h.

◆ timeout

int mg_resolve_async_opts::timeout

Definition at line 3423 of file mongoose6.h.

◆ topic [1/2]

struct mg_str mg_mqtt_message::topic

Definition at line 2882 of file mongoose6.h.

◆ topic [2/2]

const char * mg_mqtt_topic_expression::topic

Definition at line 2886 of file mongoose6.h.

◆ transaction_id

uint16_t mg_dns_message::transaction_id

Definition at line 3193 of file mongoose6.h.

◆ ttl

int mg_dns_resource_record::ttl

Definition at line 3184 of file mongoose6.h.

◆ type

enum json_type json_token::type

Definition at line 1075 of file mongoose6.h.

◆ uri

struct mg_str http_message::uri

Definition at line 2072 of file mongoose6.h.

◆ url_rewrites

const char* mg_serve_http_opts::url_rewrites

Definition at line 2582 of file mongoose6.h.

◆ user_data [1/7]

void * cs_base64_ctx::user_data

Definition at line 984 of file mongoose6.h.

◆ user_data [2/7]

void * mg_mgr::user_data

Definition at line 1236 of file mongoose6.h.

◆ user_data [3/7]

void * mg_connection::user_data

Definition at line 1265 of file mongoose6.h.

◆ user_data [4/7]

void * mg_add_sock_opts::user_data

Definition at line 1366 of file mongoose6.h.

◆ user_data [5/7]

void * mg_bind_opts::user_data

Definition at line 1396 of file mongoose6.h.

◆ user_data [6/7]

void * mg_connect_opts::user_data

Definition at line 1436 of file mongoose6.h.

◆ user_data [7/7]

void * mg_http_multipart_part::user_data

Definition at line 2110 of file mongoose6.h.

◆ user_name

const char * mg_send_mqtt_handshake_opts::user_name

Definition at line 2895 of file mongoose6.h.

◆ [] [1/2]

void* { ... } ::v

Definition at line 1267 of file mongoose6.h.

◆ v [2/2]

void* mg_connection::v

Definition at line 1267 of file mongoose6.h.

◆ var_name

const char * mg_http_multipart_part::var_name

Definition at line 2107 of file mongoose6.h.

◆ will_message

const char * mg_send_mqtt_handshake_opts::will_message

Definition at line 2894 of file mongoose6.h.

◆ will_topic

const char * mg_send_mqtt_handshake_opts::will_topic

Definition at line 2893 of file mongoose6.h.