Teonet library  0.4.7
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
mongoose.c File Reference
#include "mongoose.h"
#include <string.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

Macros

#define MG_INTERNAL_HEADER_INCLUDED
 
#define MG_MALLOC   malloc
 
#define MG_CALLOC   calloc
 
#define MG_REALLOC   realloc
 
#define MG_FREE   free
 
#define MBUF_REALLOC   MG_REALLOC
 
#define MBUF_FREE   MG_FREE
 
#define MG_SET_PTRPTR(_ptr, _v)
 
#define MG_INTERNAL   static
 
#define MG_MGR_EV_MGR   0 /* select() */
 
#define NUM_UPPERCASES   ('Z' - 'A' + 1)
 
#define NUM_LETTERS   (NUM_UPPERCASES * 2)
 
#define NUM_DIGITS   ('9' - '0' + 1)
 
#define BASE64_ENCODE_BODY
 
#define BASE64_OUT(ch)
 
#define BASE64_FLUSH()
 
#define BASE64_OUT(ch)
 
#define BASE64_FLUSH()
 
#define _CRT_SECURE_NO_WARNINGS   /* Disable deprecation warning in VS2005+ */
 
#define FROZEN_REALLOC   realloc
 
#define FROZEN_FREE   free
 
#define EXPECT(cond, err_code)   do { if (!(cond)) return (err_code); } while (0)
 
#define TRY(expr)   do { int _n = expr; if (_n < 0) return _n; } while (0)
 
#define END_OF_STRING   (-1)
 
#define EMIT(x)   do { if (s < end) *s = x; s++; } while (0)
 
#define F1(x, y, z)   (z ^ (x & (y ^ z)))
 
#define F2(x, y, z)   F1(z, x, y)
 
#define F3(x, y, z)   (x ^ y ^ z)
 
#define F4(x, y, z)   (y ^ (x | ~z))
 
#define MD5STEP(f, w, x, y, z, data, s)   (w += f(x, y, z) + data, w = w << s | w >> (32 - s), w += x)
 
#define SHA1HANDSOFF
 
#define rol(value, bits)   (((value) << (bits)) | ((value) >> (32 - (bits))))
 
#define blk(i)
 
#define R0(v, w, x, y, z, i)
 
#define R1(v, w, x, y, z, i)
 
#define R2(v, w, x, y, z, i)
 
#define R3(v, w, x, y, z, i)
 
#define R4(v, w, x, y, z, i)
 
#define C_SNPRINTF_APPEND_CHAR(ch)
 
#define C_SNPRINTF_FLAG_ZERO   1
 
#define MG_CTL_MSG_MESSAGE_SIZE   8192
 
#define MG_VPRINTF_BUFFER_SIZE   100
 
#define MG_MAX_HOST_LEN   200
 
#define MG_COPY_COMMON_CONNECTION_OPTIONS(dst, src)   memcpy(dst, src, sizeof(*dst));
 
#define _MG_ALLOWED_CONNECT_FLAGS_MASK
 
#define _MG_CALLBACK_MODIFIABLE_FLAGS_MASK
 
#define intptr_t   long
 
#define MG_TCP_RECV_BUFFER_SIZE   1024
 
#define MG_UDP_RECV_BUFFER_SIZE   1500
 
#define _MG_F_FD_CAN_READ   1
 
#define _MG_F_FD_CAN_WRITE   1 << 1
 
#define _MG_F_FD_ERROR   1 << 2
 
#define MIME_ENTRY(_ext, _type)   { _ext, sizeof(_ext) - 1, _type }
 
#define HEXTOI(x)   (isdigit(x) ? x - '0' : x - 'W')
 
#define MG_DEFAULT_NAMESERVER   "8.8.8.8"
 

Enumerations

enum  http_proto_data_type { DATA_NONE, DATA_FILE, DATA_PUT, DATA_CGI }
 

Functions

MG_INTERNAL struct mg_connectionmg_do_connect (struct mg_connection *nc, int proto, union socket_address *sa)
 
MG_INTERNAL int mg_parse_address (const char *str, union socket_address *sa, int *proto, char *host, size_t host_len)
 
MG_INTERNAL void mg_call (struct mg_connection *nc, mg_event_handler_t ev_handler, int ev, void *ev_data)
 
MG_INTERNAL void mg_forward (struct mg_connection *, struct mg_connection *)
 
MG_INTERNAL void mg_add_conn (struct mg_mgr *mgr, struct mg_connection *c)
 
MG_INTERNAL void mg_remove_conn (struct mg_connection *c)
 
MG_INTERNAL int find_index_file (char *, size_t, const char *, cs_stat_t *)
 
MG_INTERNAL size_t mg_handle_chunked (struct mg_connection *nc, struct http_message *hm, char *buf, size_t blen)
 
MG_INTERNAL time_t mg_parse_date_string (const char *datetime)
 
MG_INTERNAL int mg_is_not_modified (struct http_message *hm, cs_stat_t *st)
 
void cs_base64_init (struct cs_base64_ctx *ctx, cs_base64_putc_t b64_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)
 
void cs_log_printf (const char *fmt,...)
 
void cs_log_set_level (enum cs_log_level level)
 
int parse_json (const char *s, int s_len, struct json_token *arr, int arr_len)
 
struct json_tokenparse_json2 (const char *s, int s_len)
 
struct json_tokenfind_json_token (struct json_token *toks, const char *path)
 
int json_emit_long (char *buf, int buf_len, long int value)
 
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_unquoted_str (char *buf, int buf_len, const char *str, int len)
 
int json_emit_va (char *s, int s_len, const char *fmt, va_list ap)
 
int json_emit (char *buf, int buf_len, const char *fmt,...)
 
void MD5_Init (MD5_CTX *ctx)
 
void MD5_Update (MD5_CTX *ctx, const unsigned char *buf, size_t len)
 
void MD5_Final (unsigned char digest[16], MD5_CTX *ctx)
 
void cs_to_hex (char *to, const unsigned char *p, size_t len)
 
char * cs_md5 (char buf[33],...)
 
void mbuf_init (struct mbuf *mbuf, size_t initial_size)
 
void mbuf_free (struct mbuf *mbuf)
 
void mbuf_resize (struct mbuf *a, size_t new_size)
 
void mbuf_trim (struct mbuf *mbuf)
 
size_t mbuf_insert (struct mbuf *a, size_t off, const void *buf, size_t len)
 
size_t mbuf_append (struct mbuf *a, const void *buf, size_t len)
 
void mbuf_remove (struct mbuf *mb, size_t n)
 
void cs_sha1_transform (uint32_t state[5], const unsigned char buffer[64])
 
void cs_sha1_init (cs_sha1_ctx *context)
 
void cs_sha1_update (cs_sha1_ctx *context, const unsigned char *data, uint32_t len)
 
void cs_sha1_final (unsigned char digest[20], cs_sha1_ctx *context)
 
void cs_hmac_sha1 (const unsigned char *key, size_t keylen, const unsigned char *data, size_t datalen, unsigned char out[20])
 
size_t strnlen (const char *s, size_t maxlen)
 
int c_vsnprintf (char *buf, size_t buf_size, const char *fmt, va_list ap)
 
int c_snprintf (char *buf, size_t buf_size, const char *fmt,...)
 
int mg_is_error (int n)
 
void mg_set_non_blocking_mode (sock_t sock)
 
void mg_ev_mgr_init (struct mg_mgr *mgr)
 
void mg_ev_mgr_free (struct mg_mgr *mgr)
 
void mg_ev_mgr_add_conn (struct mg_connection *nc)
 
void mg_ev_mgr_remove_conn (struct mg_connection *nc)
 
void mg_if_poll (struct mg_connection *nc, time_t now)
 
void mg_close_conn (struct mg_connection *conn)
 
void mg_mgr_init (struct mg_mgr *m, void *user_data)
 
void mg_mgr_free (struct mg_mgr *m)
 
int mg_vprintf (struct mg_connection *nc, const char *fmt, va_list ap)
 
int mg_printf (struct mg_connection *conn, const char *fmt,...)
 
int mg_resolve (const char *host, char *buf, size_t n)
 
MG_INTERNAL struct mg_connectionmg_create_connection (struct mg_mgr *mgr, mg_event_handler_t callback, struct mg_add_sock_opts opts)
 
struct mg_connectionmg_if_accept_tcp_cb (struct mg_connection *lc, union socket_address *sa, size_t sa_len)
 
void mg_send (struct mg_connection *nc, const void *buf, int 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_connect_cb (struct mg_connection *nc, int err)
 
struct mg_connectionmg_connect (struct mg_mgr *mgr, const char *address, mg_event_handler_t callback)
 
struct mg_connectionmg_connect_opt (struct mg_mgr *mgr, const char *address, mg_event_handler_t callback, struct mg_connect_opts opts)
 
struct mg_connectionmg_bind (struct mg_mgr *srv, const char *address, mg_event_handler_t event_handler)
 
struct mg_connectionmg_bind_opt (struct mg_mgr *mgr, const char *address, mg_event_handler_t callback, struct mg_bind_opts opts)
 
struct mg_connectionmg_next (struct mg_mgr *s, struct mg_connection *conn)
 
void mg_broadcast (struct mg_mgr *mgr, mg_event_handler_t cb, void *data, size_t len)
 
int mg_check_ip_acl (const char *acl, uint32_t remote_ip)
 
void mg_if_connect_tcp (struct mg_connection *nc, const union socket_address *sa)
 
void mg_if_connect_udp (struct mg_connection *nc)
 
int mg_if_listen_tcp (struct mg_connection *nc, union socket_address *sa)
 
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_recved (struct mg_connection *nc, size_t len)
 
void mg_if_destroy_conn (struct mg_connection *nc)
 
void mg_mgr_handle_conn (struct mg_connection *nc, int fd_flags, time_t now)
 
struct mg_connectionmg_add_sock (struct mg_mgr *s, sock_t sock, mg_event_handler_t callback)
 
struct mg_connectionmg_add_sock_opt (struct mg_mgr *s, sock_t sock, mg_event_handler_t callback, struct mg_add_sock_opts opts)
 
void mg_add_to_set (sock_t sock, fd_set *set, sock_t *max_fd)
 
time_t mg_mgr_poll (struct mg_mgr *mgr, int milli)
 
int mg_socketpair (sock_t sp[2], int sock_type)
 
void mg_sock_to_str (sock_t sock, char *buf, size_t len, int flags)
 
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)
 
void mg_send_websocket_frame (struct mg_connection *nc, int op, const void *data, size_t len)
 
void mg_send_websocket_framev (struct mg_connection *nc, int op, const struct mg_str *strv, int strvcnt)
 
void mg_printf_websocket_frame (struct mg_connection *nc, int op, const char *fmt,...)
 
void http_handler (struct mg_connection *nc, int ev, void *ev_data)
 
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_response_line (struct mg_connection *nc, int status_code, const char *extra_headers)
 
void mg_send_head (struct mg_connection *c, int status_code, int64_t content_length, const char *extra_headers)
 
int mg_get_http_var (const struct mg_str *buf, const char *name, char *dst, size_t dst_len)
 
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_printf_html_escape (struct mg_connection *nc, const char *fmt,...)
 
int mg_http_parse_header (struct mg_str *hdr, const char *var_name, char *buf, size_t buf_size)
 
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)
 
void mg_send_http_file (struct mg_connection *nc, char *path, size_t path_buf_len, struct http_message *hm, struct mg_serve_http_opts *opts)
 
void mg_serve_http (struct mg_connection *nc, struct http_message *hm, struct mg_serve_http_opts opts)
 
struct mg_connectionmg_connect_http (struct mg_mgr *mgr, mg_event_handler_t ev_handler, const char *url, const char *extra_headers, const char *post_data)
 
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 **data, size_t *data_len)
 
const char * mg_skip (const char *s, const char *end, const char *delims, 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_vcasecmp (const struct mg_str *str1, const char *str2)
 
int mg_vcmp (const struct mg_str *str1, const char *str2)
 
int mg_stat (const char *path, cs_stat_t *st)
 
FILE * mg_fopen (const char *path, const char *mode)
 
int mg_open (const char *path, int flag, int mode)
 
void mg_base64_encode (const unsigned char *src, int src_len, char *dst)
 
int mg_base64_decode (const unsigned char *s, int len, char *dst)
 
void mg_set_close_on_exec (sock_t sock)
 
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)
 
int mg_avprintf (char **buf, size_t size, const char *fmt, va_list ap)
 
void mg_hexdump_connection (struct mg_connection *nc, const char *path, int num_bytes, int ev)
 
int mg_is_big_endian (void)
 
const char * mg_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_rpc_create_reply (char *buf, int len, const struct mg_rpc_request *req, const char *result_fmt,...)
 
int mg_rpc_create_request (char *buf, int len, const char *method, const char *id, const char *params_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 len, char *dst, int dst_len, const char **methods, mg_rpc_handler_t *handlers)
 
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)
 
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 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)
 
int mg_mqtt_next_subscribe_topic (struct mg_mqtt_message *msg, struct mg_str *topic, uint8_t *qos, int pos)
 
void mg_mqtt_unsubscribe (struct mg_connection *nc, char **topics, size_t topics_len, uint16_t message_id)
 
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)
 
void mg_mqtt_disconnect (struct mg_connection *nc)
 
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)
 
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)
 
void mg_send_dns_query (struct mg_connection *nc, const char *name, int query_type)
 
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_from_hosts_file (const char *name, union socket_address *usa)
 
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)
 

Variables

void *(* test_malloc )(size_t)
 
void *(* test_calloc )(size_t, size_t)
 
enum cs_log_level s_cs_log_level
 
MG_INTERNAL char mg_dns_server [256]
 

Macro Definition Documentation

#define _CRT_SECURE_NO_WARNINGS   /* Disable deprecation warning in VS2005+ */
#define _MG_ALLOWED_CONNECT_FLAGS_MASK
Value:
#define MG_F_USER_2
Definition: mongoose.h:754
#define MG_F_USER_1
Definition: mongoose.h:753
#define MG_F_USER_6
Definition: mongoose.h:758
#define MG_F_USER_3
Definition: mongoose.h:755
#define MG_F_USER_4
Definition: mongoose.h:756
#define MG_F_WEBSOCKET_NO_DEFRAG
Definition: mongoose.h:750
#define MG_F_USER_5
Definition: mongoose.h:757

Referenced by mg_connect_opt(), and mg_create_connection().

#define _MG_CALLBACK_MODIFIABLE_FLAGS_MASK
Value:
#define MG_F_USER_2
Definition: mongoose.h:754
#define MG_F_USER_1
Definition: mongoose.h:753
#define MG_F_USER_6
Definition: mongoose.h:758
#define MG_F_USER_3
Definition: mongoose.h:755
#define MG_F_USER_4
Definition: mongoose.h:756
#define MG_F_DELETE_CHUNK
Definition: mongoose.h:751
#define MG_F_SEND_AND_CLOSE
Definition: mongoose.h:748
#define MG_F_WEBSOCKET_NO_DEFRAG
Definition: mongoose.h:750
#define MG_F_CLOSE_IMMEDIATELY
Definition: mongoose.h:749
#define MG_F_IS_WEBSOCKET
Definition: mongoose.h:745
#define MG_F_USER_5
Definition: mongoose.h:757

Referenced by mg_call().

#define _MG_F_FD_CAN_READ   1

Referenced by mg_mgr_handle_conn(), and mg_mgr_poll().

#define _MG_F_FD_CAN_WRITE   1 << 1

Referenced by mg_mgr_handle_conn(), and mg_mgr_poll().

#define _MG_F_FD_ERROR   1 << 2

Referenced by mg_mgr_poll().

#define BASE64_ENCODE_BODY
Value:
static const char *b64 = \
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; \
int i, j, a, b, c; \
\
for (i = j = 0; i < src_len; i += 3) { \
a = src[i]; \
b = i + 1 >= src_len ? 0 : src[i + 1]; \
c = i + 2 >= src_len ? 0 : src[i + 2]; \
BASE64_OUT(b64[a >> 2]); \
BASE64_OUT(b64[((a & 3) << 4) | (b >> 4)]); \
if (i + 1 < src_len) { \
BASE64_OUT(b64[(b & 15) << 2 | (c >> 6)]); \
} \
if (i + 2 < src_len) { \
BASE64_OUT(b64[c & 63]); \
} \
} \
\
while (j % 4 != 0) { \
BASE64_OUT('='); \
} \
if(!(yy_init))
Definition: lexer-filter.c:653
#define BASE64_OUT(ch)
Definition: mongoose.c:241
#define BASE64_FLUSH()
Definition: mongoose.c:247

Referenced by cs_base64_encode(), and cs_fprint_base64().

#define BASE64_FLUSH ( )
Value:
do { \
dst[j++] = '\0'; \
} while (0)
#define BASE64_FLUSH ( )
#define BASE64_OUT (   ch)
Value:
do { \
dst[j++] = (ch); \
} while (0)
#define BASE64_OUT (   ch)
Value:
do { \
fprintf(f, "%c", (ch)); \
j++; \
} while (0)
#define blk (   i)
Value:
(block->l[i & 15] = rol(block->l[(i + 13) & 15] ^ block->l[(i + 8) & 15] ^ \
block->l[(i + 2) & 15] ^ block->l[i & 15], \
1))
#define rol(value, bits)
Definition: mongoose.c:1306
#define C_SNPRINTF_APPEND_CHAR (   ch)
Value:
do { \
if (i < (int) buf_size) buf[i] = ch; \
i++; \
} while (0)
if(!(yy_init))
Definition: lexer-filter.c:653

Referenced by c_vsnprintf().

#define C_SNPRINTF_FLAG_ZERO   1

Referenced by c_vsnprintf().

#define EMIT (   x)    do { if (s < end) *s = x; s++; } while (0)

Referenced by json_emit_quoted_str().

#define END_OF_STRING   (-1)
#define EXPECT (   cond,
  err_code 
)    do { if (!(cond)) return (err_code); } while (0)
#define F1 (   x,
  y,
 
)    (z ^ (x & (y ^ z)))
#define F2 (   x,
  y,
 
)    F1(z, x, y)
#define F3 (   x,
  y,
 
)    (x ^ y ^ z)
#define F4 (   x,
  y,
 
)    (y ^ (x | ~z))
#define FROZEN_FREE   free

Referenced by parse_json2().

#define FROZEN_REALLOC   realloc
#define HEXTOI (   x)    (isdigit(x) ? x - '0' : x - 'W')
#define intptr_t   long
#define MBUF_FREE   MG_FREE

Referenced by mbuf_free().

#define MBUF_REALLOC   MG_REALLOC

Referenced by mbuf_insert(), and mbuf_resize().

#define MD5STEP (   f,
  w,
  x,
  y,
  z,
  data,
 
)    (w += f(x, y, z) + data, w = w << s | w >> (32 - s), w += x)
#define MG_CALLOC   calloc
#define MG_COPY_COMMON_CONNECTION_OPTIONS (   dst,
  src 
)    memcpy(dst, src, sizeof(*dst));

Referenced by mg_bind_opt(), and mg_connect_opt().

#define MG_CTL_MSG_MESSAGE_SIZE   8192
#define MG_DEFAULT_NAMESERVER   "8.8.8.8"
#define MG_INTERNAL   static
#define MG_INTERNAL_HEADER_INCLUDED
#define MG_MALLOC   malloc
#define MG_MAX_HOST_LEN   200

Referenced by mg_bind_opt(), and mg_connect_opt().

#define MG_MGR_EV_MGR   0 /* select() */
#define MG_REALLOC   realloc

Referenced by mg_connect_http().

#define MG_SET_PTRPTR (   _ptr,
  _v 
)
Value:
do { \
if (_ptr) *(_ptr) = _v; \
} while (0)
if(!(yy_init))
Definition: lexer-filter.c:653

Referenced by mg_bind_opt(), mg_connect_opt(), and mg_create_connection().

#define MG_TCP_RECV_BUFFER_SIZE   1024
#define MG_UDP_RECV_BUFFER_SIZE   1500
#define MG_VPRINTF_BUFFER_SIZE   100

Referenced by mg_vprintf().

#define MIME_ENTRY (   _ext,
  _type 
)    { _ext, sizeof(_ext) - 1, _type }
#define NUM_DIGITS   ('9' - '0' + 1)
#define NUM_LETTERS   (NUM_UPPERCASES * 2)
#define NUM_UPPERCASES   ('Z' - 'A' + 1)
#define R0 (   v,
  w,
  x,
  y,
  z,
 
)
Value:
z += ((w & (x ^ y)) ^ y) + blk0(block, i) + 0x5A827999 + rol(v, 5); \
w = rol(w, 30);
#define rol(value, bits)
Definition: mongoose.c:1306
ev_io w
Definition: teol0cli.c:23

Referenced by cs_sha1_transform().

#define R1 (   v,
  w,
  x,
  y,
  z,
 
)
Value:
z += ((w & (x ^ y)) ^ y) + blk(i) + 0x5A827999 + rol(v, 5); \
w = rol(w, 30);
#define rol(value, bits)
Definition: mongoose.c:1306
ev_io w
Definition: teol0cli.c:23
#define blk(i)
Definition: mongoose.c:1325

Referenced by cs_sha1_transform().

#define R2 (   v,
  w,
  x,
  y,
  z,
 
)
Value:
z += (w ^ x ^ y) + blk(i) + 0x6ED9EBA1 + rol(v, 5); \
w = rol(w, 30);
#define rol(value, bits)
Definition: mongoose.c:1306
ev_io w
Definition: teol0cli.c:23
#define blk(i)
Definition: mongoose.c:1325

Referenced by cs_sha1_transform().

#define R3 (   v,
  w,
  x,
  y,
  z,
 
)
Value:
z += (((w | x) & y) | (w & x)) + blk(i) + 0x8F1BBCDC + rol(v, 5); \
w = rol(w, 30);
#define rol(value, bits)
Definition: mongoose.c:1306
ev_io w
Definition: teol0cli.c:23
#define blk(i)
Definition: mongoose.c:1325

Referenced by cs_sha1_transform().

#define R4 (   v,
  w,
  x,
  y,
  z,
 
)
Value:
z += (w ^ x ^ y) + blk(i) + 0xCA62C1D6 + rol(v, 5); \
w = rol(w, 30);
#define rol(value, bits)
Definition: mongoose.c:1306
ev_io w
Definition: teol0cli.c:23
#define blk(i)
Definition: mongoose.c:1325

Referenced by cs_sha1_transform().

#define rol (   value,
  bits 
)    (((value) << (bits)) | ((value) >> (32 - (bits))))
#define SHA1HANDSOFF
#define TRY (   expr)    do { int _n = expr; if (_n < 0) return _n; } while (0)

Referenced by parse_json().

Enumeration Type Documentation

Enumerator
DATA_NONE 
DATA_FILE 
DATA_PUT 
DATA_CGI 

Function Documentation

int c_snprintf ( char *  buf,
size_t  buf_size,
const char *  fmt,
  ... 
)

References c_vsnprintf(), and result.

int c_vsnprintf ( char *  buf,
size_t  buf_size,
const char *  fmt,
va_list  ap 
)
int cs_base64_decode ( const unsigned char *  s,
int  len,
char *  dst 
)

Referenced by mg_base64_decode().

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

References BASE64_ENCODE_BODY.

Referenced by mg_base64_encode().

void cs_base64_init ( struct cs_base64_ctx ctx,
cs_base64_putc_t  b64_putc,
void *  user_data 
)
void cs_base64_update ( struct cs_base64_ctx ctx,
const char *  str,
size_t  len 
)
void cs_fprint_base64 ( FILE *  f,
const unsigned char *  src,
int  src_len 
)

References BASE64_ENCODE_BODY.

void cs_hmac_sha1 ( const unsigned char *  key,
size_t  keylen,
const unsigned char *  data,
size_t  datalen,
unsigned char  out[20] 
)
void cs_log_printf ( const char *  fmt,
  ... 
)
void cs_log_set_level ( enum cs_log_level  level)
char* cs_md5 ( char  buf[33],
  ... 
)
void cs_sha1_final ( unsigned char  digest[20],
cs_sha1_ctx context 
)
void cs_sha1_init ( cs_sha1_ctx context)

References cs_sha1_ctx::count, and cs_sha1_ctx::state.

Referenced by cs_hmac_sha1().

void cs_sha1_transform ( uint32_t  state[5],
const unsigned char  buffer[64] 
)

References R0, R1, R2, R3, and R4.

Referenced by cs_sha1_update().

void cs_sha1_update ( cs_sha1_ctx context,
const unsigned char *  data,
uint32_t  len 
)
void cs_to_hex ( char *  to,
const unsigned char *  p,
size_t  len 
)

Referenced by cs_md5().

MG_INTERNAL int find_index_file ( char *  path,
size_t  path_len,
const char *  list,
cs_stat_t stp 
)
struct json_token* find_json_token ( struct json_token toks,
const char *  path 
)
int json_emit ( char *  buf,
int  buf_len,
const char *  fmt,
  ... 
)
int json_emit_double ( char *  buf,
int  buf_len,
double  value 
)

Referenced by json_emit_va().

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

Referenced by json_emit_va().

int json_emit_quoted_str ( char *  s,
int  s_len,
const char *  str,
int  len 
)

References EMIT, and json_token::len.

Referenced by json_emit_va(), and mg_rpc_create_reply().

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

References json_token::len.

Referenced by json_emit_va(), and mg_rpc_create_reply().

int json_emit_va ( char *  s,
int  s_len,
const char *  fmt,
va_list  ap 
)
size_t mbuf_append ( struct mbuf a,
const void *  buf,
size_t  len 
)
void mbuf_free ( struct mbuf mbuf)

References mbuf::buf, MBUF_FREE, and mbuf_init().

Referenced by mg_send_dns_query().

void mbuf_init ( struct mbuf mbuf,
size_t  initial_size 
)
size_t mbuf_insert ( struct mbuf a,
size_t  off,
const void *  buf,
size_t  len 
)
void mbuf_remove ( struct mbuf mb,
size_t  n 
)
Examples:
teofossa.c.

References mbuf::buf, and mbuf::len.

Referenced by http_handler(), and mg_forward().

void mbuf_resize ( struct mbuf a,
size_t  new_size 
)

References mbuf::buf, mbuf::len, MBUF_REALLOC, and mbuf::size.

Referenced by mbuf_init(), and mbuf_trim().

void mbuf_trim ( struct mbuf mbuf)

References mbuf::len, and mbuf_resize().

void MD5_Final ( unsigned char  digest[16],
MD5_CTX ctx 
)

References MD5Context::bits, MD5Context::buf, and MD5Context::in.

Referenced by cs_md5().

void MD5_Init ( MD5_CTX ctx)

References MD5Context::bits, and MD5Context::buf.

Referenced by cs_md5().

void MD5_Update ( MD5_CTX ctx,
const unsigned char *  buf,
size_t  len 
)

References MD5Context::bits, MD5Context::buf, if(), and MD5Context::in.

Referenced by cs_md5().

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

References 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 
)
void mg_add_to_set ( sock_t  sock,
fd_set *  set,
sock_t max_fd 
)

References INVALID_SOCKET, and mg_connection::sock.

Referenced by mg_mgr_poll().

int mg_avprintf ( char **  buf,
size_t  size,
const char *  fmt,
va_list  ap 
)
int mg_base64_decode ( const unsigned char *  s,
int  len,
char *  dst 
)

References cs_base64_decode().

void mg_base64_encode ( const unsigned char *  src,
int  src_len,
char *  dst 
)
struct mg_connection* mg_bind ( struct mg_mgr srv,
const char *  address,
mg_event_handler_t  event_handler 
)

References mg_bind_opt().

void mg_broadcast ( struct mg_mgr mgr,
mg_event_handler_t  cb,
void *  data,
size_t  len 
)
int mg_casecmp ( const char *  s1,
const char *  s2 
)

References mg_ncasecmp().

int mg_check_ip_acl ( const char *  acl,
uint32_t  remote_ip 
)

References mg_next_comma_list_entry(), and mg_str::p.

Referenced by mg_send_http_file().

void mg_close_conn ( struct mg_connection conn)
struct mg_connection* mg_connect ( struct mg_mgr mgr,
const char *  address,
mg_event_handler_t  callback 
)
struct mg_connection* mg_connect_http ( struct mg_mgr mgr,
mg_event_handler_t  ev_handler,
const char *  url,
const char *  extra_headers,
const char *  post_data 
)
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_dns_insert_header ( struct mbuf io,
size_t  pos,
struct mg_dns_message msg 
)
struct mg_dns_resource_record* mg_dns_next_record ( struct mg_dns_message msg,
int  query,
struct mg_dns_resource_record prev 
)
size_t mg_dns_uncompress_name ( struct mg_dns_message msg,
struct mg_str name,
char *  dst,
int  dst_len 
)
void mg_ev_mgr_add_conn ( struct mg_connection nc)

Referenced by mg_add_conn().

void mg_ev_mgr_free ( struct mg_mgr mgr)

Referenced by mg_mgr_free().

void mg_ev_mgr_init ( struct mg_mgr mgr)

References mg_mgr::ctl, DBG, INVALID_SOCKET, and mg_socketpair().

Referenced by mg_mgr_init().

void mg_ev_mgr_remove_conn ( struct mg_connection nc)

Referenced by mg_remove_conn().

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

References ARRAY_SIZE, and MAX_PATH_SIZE.

void mg_forward ( struct mg_connection from,
struct mg_connection to 
)
struct mg_str* mg_get_http_header ( struct http_message hm,
const char *  name 
)
int mg_get_http_var ( const struct mg_str buf,
const char *  name,
char *  dst,
size_t  dst_len 
)

References mg_str::len, mg_ncasecmp(), and mg_str::p.

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

References mg_str::len.

Referenced by mg_hexdump_connection().

void mg_hexdump_connection ( struct mg_connection nc,
const char *  path,
int  num_bytes,
int  ev 
)
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 
)

References cs_md5().

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

References mg_str::len, and mg_str::p.

Referenced by mg_parse_multipart().

void mg_if_connect_cb ( struct mg_connection nc,
int  err 
)
void mg_if_connect_udp ( struct mg_connection nc)
int mg_if_listen_tcp ( struct mg_connection nc,
union socket_address sa 
)

Referenced by mg_bind_opt().

int mg_if_listen_udp ( struct mg_connection nc,
union socket_address sa 
)

Referenced by mg_bind_opt().

void mg_if_poll ( struct mg_connection nc,
time_t  now 
)

References mg_call(), and MG_EV_POLL.

Referenced by mg_mgr_handle_conn().

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

References mg_if_recved().

void mg_if_recved ( struct mg_connection nc,
size_t  len 
)
void mg_if_sent_cb ( struct mg_connection nc,
int  num_sent 
)
void mg_if_tcp_send ( struct mg_connection nc,
const void *  buf,
size_t  len 
)

References mbuf_append(), and mg_connection::send_mbuf.

Referenced by mg_send().

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

References DBG, mbuf::len, mbuf_append(), and mg_connection::send_mbuf.

Referenced by mg_send().

int mg_is_big_endian ( void  )
int mg_is_error ( int  n)

References DBG.

Referenced by mg_if_connect_tcp().

MG_INTERNAL int mg_is_not_modified ( struct http_message hm,
cs_stat_t st 
)
int mg_match_prefix ( const char *  pattern,
int  pattern_len,
const char *  str 
)

References mbuf::len, and mg_match_prefix().

Referenced by mg_match_prefix(), and mg_send_http_file().

void mg_mgr_init ( struct mg_mgr m,
void *  user_data 
)
void mg_mqtt_connack ( struct mg_connection nc,
uint8_t  return_code 
)

References MG_MQTT_CMD_CONNACK, and mg_send().

void mg_mqtt_disconnect ( struct mg_connection nc)
int mg_mqtt_next_subscribe_topic ( struct mg_mqtt_message msg,
struct mg_str topic,
uint8_t *  qos,
int  pos 
)
void mg_mqtt_ping ( struct mg_connection nc)

References MG_MQTT_CMD_PINGREQ.

void mg_mqtt_pong ( struct mg_connection nc)

References MG_MQTT_CMD_PINGRESP.

void mg_mqtt_puback ( struct mg_connection nc,
uint16_t  message_id 
)

References MG_MQTT_CMD_PUBACK.

void mg_mqtt_pubcomp ( struct mg_connection nc,
uint16_t  message_id 
)

References MG_MQTT_CMD_PUBCOMP.

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_pubrec ( struct mg_connection nc,
uint16_t  message_id 
)

References MG_MQTT_CMD_PUBREC.

void mg_mqtt_pubrel ( struct mg_connection nc,
uint16_t  message_id 
)

References MG_MQTT_CMD_PUBREL.

void mg_mqtt_suback ( struct mg_connection nc,
uint8_t *  qoss,
size_t  qoss_len,
uint16_t  message_id 
)
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_unsuback ( struct mg_connection nc,
uint16_t  message_id 
)

References MG_MQTT_CMD_UNSUBACK.

void mg_mqtt_unsubscribe ( struct mg_connection nc,
char **  topics,
size_t  topics_len,
uint16_t  message_id 
)
int mg_ncasecmp ( const char *  s1,
const char *  s2,
size_t  len 
)
struct mg_connection* mg_next ( struct mg_mgr s,
struct mg_connection conn 
)
const char* mg_next_comma_list_entry ( const char *  list,
struct mg_str val,
struct mg_str eq_val 
)

References mg_str::len, and mg_str::p.

Referenced by find_index_file(), and mg_check_ip_acl().

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

References ARRAY_SIZE, and MAX_PATH_SIZE.

MG_INTERNAL int mg_parse_address ( const char *  str,
union socket_address sa,
int *  proto,
char *  host,
size_t  host_len 
)
MG_INTERNAL time_t mg_parse_date_string ( const char *  datetime)

References result.

Referenced by mg_is_not_modified().

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 **  data,
size_t *  data_len 
)
int mg_printf ( struct mg_connection conn,
const char *  fmt,
  ... 
)
void mg_printf_html_escape ( struct mg_connection nc,
const char *  fmt,
  ... 
)
void mg_printf_http_chunk ( struct mg_connection nc,
const char *  fmt,
  ... 
)
void mg_printf_websocket_frame ( struct mg_connection nc,
int  op,
const char *  fmt,
  ... 
)
int mg_resolve ( const char *  host,
char *  buf,
size_t  n 
)
int mg_resolve_async ( struct mg_mgr mgr,
const char *  name,
int  query,
mg_resolve_callback_t  cb,
void *  data 
)

References mg_resolve_async_opt().

Referenced by mg_connect_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 
)
int mg_resolve_from_hosts_file ( const char *  name,
union socket_address usa 
)

References socket_address::sin.

Referenced by mg_parse_address().

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_reply ( char *  buf,
int  len,
const struct mg_rpc_request req,
const char *  result_fmt,
  ... 
)
int mg_rpc_create_request ( char *  buf,
int  len,
const char *  method,
const char *  id,
const char *  params_fmt,
  ... 
)

References json_emit(), and json_emit_va().

int mg_rpc_create_std_error ( char *  buf,
int  len,
struct mg_rpc_request req,
int  code 
)
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 
)
void mg_send_head ( struct mg_connection c,
int  status_code,
int64_t  content_length,
const char *  extra_headers 
)
void mg_send_http_chunk ( struct mg_connection nc,
const char *  buf,
size_t  len 
)

References mg_send().

Referenced by mg_printf_http_chunk().

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  opts 
)
void mg_send_response_line ( struct mg_connection nc,
int  status_code,
const char *  extra_headers 
)

References mg_printf().

Referenced by mg_send_head().

void mg_send_websocket_frame ( struct mg_connection nc,
int  op,
const void *  data,
size_t  len 
)
void mg_send_websocket_framev ( struct mg_connection nc,
int  op,
const struct mg_str strv,
int  strvcnt 
)
void mg_send_websocket_handshake ( struct mg_connection nc,
const char *  uri,
const char *  extra_headers 
)

References mg_base64_encode(), and mg_printf().

void mg_set_close_on_exec ( sock_t  sock)

Referenced by mg_socketpair().

void mg_set_non_blocking_mode ( sock_t  sock)

Referenced by mg_if_connect_tcp().

void mg_set_protocol_dns ( struct mg_connection nc)
void mg_set_protocol_http_websocket ( struct mg_connection nc)
void mg_set_protocol_mqtt ( struct mg_connection nc)
const char* mg_skip ( const char *  s,
const char *  end,
const char *  delims,
struct mg_str v 
)

References mg_str::len, and mg_str::p.

Referenced by mg_parse_http().

void mg_sock_addr_to_str ( const union socket_address sa,
char *  buf,
size_t  len,
int  flags 
)
void mg_sock_to_str ( sock_t  sock,
char *  buf,
size_t  len,
int  flags 
)
int mg_socketpair ( sock_t  sp[2],
int  sock_type 
)
int mg_stat ( const char *  path,
cs_stat_t st 
)

References ARRAY_SIZE, DBG, and MAX_PATH_SIZE.

Referenced by find_index_file(), and mg_send_http_file().

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

References mg_str::len, and mg_str::p.

Referenced by mg_send_http_file(), and mg_serve_http().

int mg_vprintf ( struct mg_connection nc,
const char *  fmt,
va_list  ap 
)
int parse_json ( const char *  s,
int  s_len,
struct json_token arr,
int  arr_len 
)

References TRY.

Referenced by mg_rpc_dispatch(), and mg_rpc_parse_reply().

struct json_token* parse_json2 ( const char *  s,
int  s_len 
)

References FROZEN_FREE.

size_t strnlen ( const char *  s,
size_t  maxlen 
)

Referenced by c_vsnprintf().

Variable Documentation

size_t ext_len
const char* extension
MG_INTERNAL char mg_dns_server[256]

Referenced by mg_resolve_async_opt().

const char* mime_type
enum cs_log_level s_cs_log_level
Initial value:
=
Definition: mongoose.h:280
void*(* test_calloc)(size_t, size_t)
void*(* test_malloc)(size_t)