MIDAS
Loading...
Searching...
No Matches
mongoose614.cxx File Reference
#include "mongoose614.h"
#include <string.h>
#include <stdarg.h>
#include <stdio.h>
#include <limits.h>
#include <stddef.h>
#include <sys/time.h>
#include <assert.h>
#include <ctype.h>
#include <stdlib.h>
#include <signal.h>
#include <reent.h>
#include <sys/stat.h>
#include <unistd.h>
#include <inc/hw_types.h>
#include <inc/hw_memmap.h>
#include <driverlib/prcm.h>
#include <driverlib/rom.h>
#include <driverlib/rom_map.h>
#include <driverlib/uart.h>
#include <driverlib/utils.h>
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Clock.h>
#include <errno.h>
#include <oslib/osi.h>
#include <stdint.h>
#include <lwip/init.h>
#include <lwip/pbuf.h>
#include <lwip/tcp.h>
#include <lwip/tcpip.h>
#include <lwip/tcp_impl.h>
#include <lwip/udp.h>
Include dependency graph for mongoose614.cxx:

Go to the source code of this file.

Classes

struct  ctl_msg
 
union  char64long16
 
struct  mg_q_msg
 
struct  mg_lwip_conn_state
 
struct  mg_lwip_if_connect_tcp_ctx
 
struct  mg_lwip_if_listen_ctx
 
struct  mg_lwip_tcp_write_ctx
 
struct  udp_sendto_ctx
 
struct  tcp_recved_ctx
 
struct  mg_ev_mgr_lwip_signal
 
struct  mg_ev_mgr_lwip_data
 

Macros

#define CS_MONGOOSE_SRC_INTERNAL_H_
 
#define MBUF_REALLOC   MG_REALLOC
 
#define MBUF_FREE   MG_FREE
 
#define MG_SET_PTRPTR(_ptr, _v)
 
#define MG_INTERNAL   static
 
#define MG_CTL_MSG_MESSAGE_SIZE   8192
 
#define MIN(a, b)   ((a) < (b) ? (a) : (b))
 
#define CS_COMMON_MG_MEM_H_
 
#define MG_MALLOC   malloc
 
#define MG_CALLOC   calloc
 
#define MG_REALLOC   realloc
 
#define MG_FREE   free
 
#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 CS_COMMON_CS_DBG_H_
 
#define CS_ENABLE_DEBUG   0
 
#define CS_LOG_PREFIX_LEN   24
 
#define CS_LOG_ENABLE_TS_DIFF   0
 
#define LOG(l, x)
 
#define DBG(x)
 
#define CS_COMMON_CS_DIRENT_H_
 
#define CS_COMMON_CS_ENDIAN_H_
 
#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_DISABLE_BUILTIN_SNPRINTF   0
 
#define C_SNPRINTF_APPEND_CHAR(ch)
 
#define C_SNPRINTF_FLAG_ZERO   1
 
#define MG_MAX_HOST_LEN   200
 
#define MG_TCP_IO_SIZE   1460
 
#define MG_UDP_IO_SIZE   1460
 
#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 CS_MONGOOSE_SRC_NET_IF_SOCKET_H_
 
#define MG_ENABLE_NET_IF_SOCKET   MG_NET_IF == MG_NET_IF_SOCKET
 
#define CS_MONGOOSE_SRC_NET_IF_SOCKS_H_
 
#define MG_NULL_IFACE_VTABLE
 
#define _MG_F_FD_CAN_READ   1
 
#define _MG_F_FD_CAN_WRITE   1 << 1
 
#define _MG_F_FD_ERROR   1 << 2
 
#define MG_SOCKET_IFACE_VTABLE
 
#define MAX(a, b)   ((a) > (b) ? (a) : (b))
 
#define CONSOLE_UART   UARTA0_BASE
 
#define CS_COMMON_PLATFORMS_SIMPLELINK_SL_FS_SLFS_H_
 
#define CS_COMMON_PLATFORMS_SIMPLELINK_SL_NET_IF_H_
 
#define MG_ENABLE_NET_IF_SIMPLELINK   MG_NET_IF == MG_NET_IF_SIMPLELINK
 
#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 MG_SL_IFACE_VTABLE
 
#define CS_COMMON_PLATFORMS_LWIP_MG_NET_IF_LWIP_H_
 
#define MG_ENABLE_NET_IF_LWIP_LOW_LEVEL   MG_NET_IF == MG_NET_IF_LWIP_LOW_LEVEL
 
#define ip_2_ip4(addr)   (addr)
 
#define TCP_NEW   tcp_new
 
#define TCP_BIND   tcp_bind
 
#define UDP_BIND   udp_bind
 
#define IPADDR_NTOA   ipaddr_ntoa
 
#define SET_ADDR(dst, src)   (dst)->sin.sin_addr.s_addr = ip_2_ip4(src)->addr
 
#define mgos_lock()
 
#define mgos_unlock()
 
#define MG_LWIP_IFACE_VTABLE
 
#define MG_SIG_QUEUE_LEN   32
 
#define CS_COMMON_PLATFORMS_PIC32_NET_IF_H_
 
#define MG_ENABLE_NET_IF_PIC32   MG_NET_IF == MG_NET_IF_PIC32
 
#define MG_PIC32_IFACE_VTABLE
 

Typedefs

typedef int cs_dirent_dummy
 

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  mg_q_msg_type { MG_Q_MSG_CB }
 
enum  mg_sig_type {
  MG_SIG_CONNECT_RESULT = 1 , MG_SIG_RECV = 2 , MG_SIG_CLOSE_CONN = 3 , MG_SIG_TOMBSTONE = 4 ,
  MG_SIG_ACCEPT = 5
}
 

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, void *user_data, int ev, void *ev_data)
 
void mg_forward (struct mg_connection *from, struct mg_connection *to)
 
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 struct mg_connectionmg_create_connection (struct mg_mgr *mgr, mg_event_handler_t callback, struct mg_add_sock_opts opts)
 
MG_INTERNAL int mg_get_errno (void)
 
MG_INTERNAL void mg_close_conn (struct mg_connection *conn)
 
static void cs_base64_emit_code (struct cs_base64_ctx *ctx, int v)
 
static void cs_base64_emit_chunk (struct cs_base64_ctx *ctx)
 
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)
 
static unsigned char from_b64 (unsigned char ch)
 
int cs_base64_decode (const unsigned char *s, int len, char *dst, int *dec_len)
 
void cs_log_set_level (enum cs_log_level level)
 
void cs_log_set_file_level (const char *file_level)
 
int cs_log_print_prefix (enum cs_log_level level, const char *fname, int line)
 
double cs_time (void) WEAK
 
double cs_timegm (const struct tm *tm)
 
static void byteReverse (unsigned char *buf, unsigned longs)
 
void cs_md5_init (cs_md5_ctx *ctx)
 
static void cs_md5_transform (uint32_t buf[4], uint32_t const in[16])
 
void cs_md5_update (cs_md5_ctx *ctx, const unsigned char *buf, size_t len)
 
void cs_md5_final (unsigned char digest[16], cs_md5_ctx *ctx)
 
static uint32_t blk0 (union char64long16 *block, int i)
 
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])
 
void mbuf_init (struct mbuf *mbuf, size_t initial_size) WEAK
 
void mbuf_free (struct mbuf *mbuf) WEAK
 
void mbuf_resize (struct mbuf *a, size_t new_size) WEAK
 
void mbuf_trim (struct mbuf *mbuf) WEAK
 
size_t mbuf_insert (struct mbuf *a, size_t off, const void *buf, size_t) WEAK
 
size_t mbuf_append (struct mbuf *a, const void *buf, size_t len) WEAK
 
size_t mbuf_append_and_free (struct mbuf *a, void *buf, size_t len) WEAK
 
void mbuf_remove (struct mbuf *mb, size_t n) WEAK
 
void mbuf_clear (struct mbuf *mb) WEAK
 
void mbuf_move (struct mbuf *from, struct mbuf *to) WEAK
 
int mg_ncasecmp (const char *s1, const char *s2, size_t len) WEAK
 
struct mg_str mg_mk_str (const char *s) WEAK
 
struct mg_str mg_mk_str_n (const char *s, size_t len) WEAK
 
int mg_vcmp (const struct mg_str *str1, const char *str2) WEAK
 
int mg_vcasecmp (const struct mg_str *str1, const char *str2) WEAK
 
static struct mg_str mg_strdup_common (const struct mg_str s, int nul_terminate)
 
struct mg_str mg_strdup (const struct mg_str s) WEAK
 
struct mg_str mg_strdup_nul (const struct mg_str s) WEAK
 
const charmg_strchr (const struct mg_str s, int c) WEAK
 
int mg_strcmp (const struct mg_str str1, const struct mg_str str2) WEAK
 
int mg_strncmp (const struct mg_str, const struct mg_str, size_t n) WEAK
 
void mg_strfree (struct mg_str *s) WEAK
 
const charmg_strstr (const struct mg_str haystack, const struct mg_str needle) WEAK
 
struct mg_str mg_strstrip (struct mg_str s) WEAK
 
int mg_str_starts_with (struct mg_str s, struct mg_str prefix) WEAK
 
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)
 
int c_vsnprintf (char *buf, size_t buf_size, const char *fmt, va_list ap) WEAK
 
int c_snprintf (char *buf, size_t buf_size, const char *fmt,...) WEAK
 
const charc_strnstr (const char *s, const char *find, size_t slen) WEAK
 
void cs_to_hex (char *to, const unsigned char *p, size_t len) WEAK
 
static int fourbit (int ch)
 
void cs_from_hex (char *to, const char *p, size_t len) WEAK
 
static int str_util_lowercase (const char *s)
 
int mg_casecmp (const char *s1, const char *s2) WEAK
 
int mg_asprintf (char **buf, size_t size, const char *fmt,...) WEAK
 
int mg_avprintf (char **buf, size_t size, const char *fmt, va_list ap) WEAK
 
const charmg_next_comma_list_entry (const char *, struct mg_str *, struct mg_str *) WEAK
 
struct mg_str mg_next_comma_list_entry_n (struct mg_str list, struct mg_str *val, struct mg_str *eq_val) WEAK
 
size_t mg_match_prefix_n (const struct mg_str, const struct mg_str) WEAK
 
size_t mg_match_prefix (const char *, int, const char *) WEAK
 
MG_INTERNAL void mg_timer (struct mg_connection *c, double now)
 
MG_INTERNAL size_t recv_avail_size (struct mg_connection *conn, size_t max)
 
static int mg_do_recv (struct mg_connection *nc)
 
int mg_if_poll (struct mg_connection *nc, double now)
 
void mg_destroy_conn (struct mg_connection *conn, int destroy_if)
 
void mg_mgr_init (struct mg_mgr *m, void *user_data)
 
void mg_mgr_init_opt (struct mg_mgr *m, void *user_data, struct mg_mgr_init_opts opts)
 
void mg_mgr_free (struct mg_mgr *m)
 
int mg_mgr_poll (struct mg_mgr *m, int timeout_ms)
 
int mg_vprintf (struct mg_connection *nc, const char *fmt, va_list ap)
 
int mg_printf (struct mg_connection *conn, const char *fmt,...)
 
MG_INTERNAL struct mg_connectionmg_create_connection_base (struct mg_mgr *mgr, mg_event_handler_t callback, struct mg_add_sock_opts opts)
 
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)
 
void mg_send (struct mg_connection *nc, const void *buf, int len)
 
static int mg_recv_tcp (struct mg_connection *nc, char *buf, size_t len)
 
static int mg_recv_udp (struct mg_connection *nc, char *buf, size_t len)
 
void mg_if_can_recv_cb (struct mg_connection *nc)
 
void mg_if_can_send_cb (struct mg_connection *nc)
 
void mg_if_connect_cb (struct mg_connection *nc, int err)
 
struct mg_connectionmg_connect (struct mg_mgr *mgr, const char *address, MG_CB(mg_event_handler_t callback, void *user_data))
 
struct mg_connectionmg_connect_opt (struct mg_mgr *mgr, const char *address, MG_CB(mg_event_handler_t callback, void *user_data), struct mg_connect_opts opts)
 
struct mg_connectionmg_bind (struct mg_mgr *srv, const char *address, MG_CB(mg_event_handler_t event_handler, void *user_data))
 
struct mg_connectionmg_bind_opt (struct mg_mgr *mgr, const char *address, MG_CB(mg_event_handler_t callback, void *user_data), struct mg_bind_opts opts)
 
struct mg_connectionmg_next (struct mg_mgr *s, struct mg_connection *conn)
 
static int isbyte (int n)
 
static int parse_net (const char *spec, uint32_t *net, uint32_t *mask)
 
int mg_check_ip_acl (const char *acl, uint32_t remote_ip)
 
double mg_set_timer (struct mg_connection *c, double timestamp)
 
void mg_sock_set (struct mg_connection *nc, sock_t sock)
 
void mg_if_get_conn_addr (struct mg_connection *nc, int remote, union socket_address *sa)
 
struct mg_connectionmg_add_sock_opt (struct mg_mgr *s, sock_t sock, MG_CB(mg_event_handler_t callback, void *user_data), struct mg_add_sock_opts opts)
 
struct mg_connectionmg_add_sock (struct mg_mgr *s, sock_t sock, MG_CB(mg_event_handler_t callback, void *user_data))
 
double mg_time (void)
 
struct mg_ifacemg_if_create_iface (const struct mg_iface_vtable *vtable, struct mg_mgr *mgr)
 
struct mg_ifacemg_find_iface (struct mg_mgr *mgr, const struct mg_iface_vtable *vtable, struct mg_iface *from)
 
double mg_mgr_min_timer (const struct mg_mgr *mgr)
 
static void mg_null_if_connect_tcp (struct mg_connection *c, const union socket_address *sa)
 
static void mg_null_if_connect_udp (struct mg_connection *c)
 
static int mg_null_if_listen_tcp (struct mg_connection *c, union socket_address *sa)
 
static int mg_null_if_listen_udp (struct mg_connection *c, union socket_address *sa)
 
static int mg_null_if_tcp_send (struct mg_connection *c, const void *buf, size_t len)
 
static int mg_null_if_udp_send (struct mg_connection *c, const void *buf, size_t len)
 
int mg_null_if_tcp_recv (struct mg_connection *c, void *buf, size_t len)
 
int mg_null_if_udp_recv (struct mg_connection *c, void *buf, size_t len, union socket_address *sa, size_t *sa_len)
 
static int mg_null_if_create_conn (struct mg_connection *c)
 
static void mg_null_if_destroy_conn (struct mg_connection *c)
 
static void mg_null_if_sock_set (struct mg_connection *c, sock_t sock)
 
static void mg_null_if_init (struct mg_iface *iface)
 
static void mg_null_if_free (struct mg_iface *iface)
 
static void mg_null_if_add_conn (struct mg_connection *c)
 
static void mg_null_if_remove_conn (struct mg_connection *c)
 
static time_t mg_null_if_poll (struct mg_iface *iface, int timeout_ms)
 
static void mg_null_if_get_conn_addr (struct mg_connection *c, int remote, union socket_address *sa)
 
static sock_t mg_open_listening_socket (union socket_address *sa, int type, int proto)
 
void mg_set_non_blocking_mode (sock_t sock)
 
static int mg_is_error (void)
 
void mg_socket_if_connect_tcp (struct mg_connection *nc, const union socket_address *sa)
 
void mg_socket_if_connect_udp (struct mg_connection *nc)
 
int mg_socket_if_listen_tcp (struct mg_connection *nc, union socket_address *sa)
 
static int mg_socket_if_listen_udp (struct mg_connection *nc, union socket_address *sa)
 
static int mg_socket_if_tcp_send (struct mg_connection *nc, const void *buf, size_t len)
 
static int mg_socket_if_udp_send (struct mg_connection *nc, const void *buf, size_t len)
 
static int mg_socket_if_tcp_recv (struct mg_connection *nc, void *buf, size_t len)
 
static int mg_socket_if_udp_recv (struct mg_connection *nc, void *buf, size_t len, union socket_address *sa, size_t *sa_len)
 
int mg_socket_if_create_conn (struct mg_connection *nc)
 
void mg_socket_if_destroy_conn (struct mg_connection *nc)
 
static int mg_accept_conn (struct mg_connection *lc)
 
void mg_mgr_handle_conn (struct mg_connection *nc, int fd_flags, double now)
 
void mg_socket_if_sock_set (struct mg_connection *nc, sock_t sock)
 
void mg_socket_if_init (struct mg_iface *iface)
 
void mg_socket_if_free (struct mg_iface *iface)
 
void mg_socket_if_add_conn (struct mg_connection *nc)
 
void mg_socket_if_remove_conn (struct mg_connection *nc)
 
void mg_add_to_set (sock_t sock, fd_set *set, sock_t *max_fd)
 
time_t mg_socket_if_poll (struct mg_iface *iface, int timeout_ms)
 
static void mg_sock_get_addr (sock_t sock, int remote, union socket_address *sa)
 
void mg_sock_to_str (sock_t sock, char *buf, size_t len, int flags)
 
void mg_socket_if_get_conn_addr (struct mg_connection *nc, int remote, union socket_address *sa)
 
static void parse_uri_component (const char **p, const char *end, const char *seps, struct mg_str *res)
 
int mg_parse_uri (const 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)
 
int mg_assemble_uri (const struct mg_str *scheme, const struct mg_str *user_info, const struct mg_str *host, unsigned int port, const struct mg_str *path, const struct mg_str *query, const struct mg_str *fragment, int normalize_path, struct mg_str *uri)
 
const charmg_skip (const char *s, const char *end, const char *delims, struct mg_str *v)
 
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)
 
int mg_sock_addr_to_str (const union socket_address *sa, char *buf, size_t len, int flags)
 
int mg_conn_addr_to_str (struct mg_connection *nc, char *buf, size_t len, int flags)
 
int mg_is_big_endian (void)
 
void mg_mbuf_append_base64_putc (char ch, void *user_data)
 
void mg_mbuf_append_base64 (struct mbuf *mbuf, const void *data, size_t len)
 
void mg_basic_auth_header (const struct mg_str user, const struct mg_str pass, struct mbuf *buf)
 
struct mg_str mg_url_encode_opt (const struct mg_str src, const struct mg_str safe, unsigned int flags)
 
struct mg_str mg_url_encode (const struct mg_str src)
 
void fprint_str (FILE *fp, const char *str)
 
void _exit (int status)
 
void _not_implemented (const char *what)
 
int _kill (int pid, int sig)
 
int _getpid ()
 
int _isatty (int fd)
 
int gettimeofday (struct timeval *tp, void *tzp)
 
const charinet_ntop (int af, const void *src, char *dst, socklen_t size)
 
charinet_ntoa (struct in_addr n)
 
int inet_pton (int af, const char *src, void *dst)
 
static void mg_task (void *arg)
 
bool mg_start_task (int priority, int stack_size, mg_init_cb mg_init)
 
void mg_run_in_task (void(*cb)(struct mg_mgr *mgr, void *arg), void *cb_arg)
 
static sock_t mg_open_listening_socket (struct mg_connection *nc, union socket_address *sa, int type, int proto)
 
static int mg_is_error (int n)
 
static void mg_sl_if_connect_tcp (struct mg_connection *nc, const union socket_address *sa)
 
static void mg_sl_if_connect_udp (struct mg_connection *nc)
 
static int mg_sl_if_listen_tcp (struct mg_connection *nc, union socket_address *sa)
 
static int mg_sl_if_listen_udp (struct mg_connection *nc, union socket_address *sa)
 
static int mg_sl_if_tcp_send (struct mg_connection *nc, const void *buf, size_t len)
 
static int mg_sl_if_udp_send (struct mg_connection *nc, const void *buf, size_t len)
 
static int mg_sl_if_tcp_recv (struct mg_connection *nc, void *buf, size_t len)
 
static int mg_sl_if_udp_recv (struct mg_connection *nc, void *buf, size_t len, union socket_address *sa, size_t *sa_len)
 
static int mg_sl_if_create_conn (struct mg_connection *nc)
 
void mg_sl_if_destroy_conn (struct mg_connection *nc)
 
void mg_sl_if_sock_set (struct mg_connection *nc, sock_t sock)
 
void mg_sl_if_init (struct mg_iface *iface)
 
void mg_sl_if_free (struct mg_iface *iface)
 
void mg_sl_if_add_conn (struct mg_connection *nc)
 
void mg_sl_if_remove_conn (struct mg_connection *nc)
 
time_t mg_sl_if_poll (struct mg_iface *iface, int timeout_ms)
 
void mg_sl_if_get_conn_addr (struct mg_connection *nc, int remote, union socket_address *sa)
 
void sl_restart_cb (struct mg_mgr *mgr)
 
void mg_lwip_post_signal (enum mg_sig_type sig, struct mg_connection *nc)
 
void mg_lwip_mgr_schedule_poll (struct mg_mgr *mgr)
 
void mg_lwip_if_init (struct mg_iface *iface)
 
void mg_lwip_if_free (struct mg_iface *iface)
 
void mg_lwip_if_add_conn (struct mg_connection *nc)
 
void mg_lwip_if_remove_conn (struct mg_connection *nc)
 
time_t mg_lwip_if_poll (struct mg_iface *iface, int timeout_ms)
 
static void mg_lwip_recv_common (struct mg_connection *nc, struct pbuf *p)
 
static err_t mg_lwip_tcp_conn_cb (void *arg, struct tcp_pcb *tpcb, err_t err)
 
static void mg_lwip_tcp_error_cb (void *arg, err_t err)
 
static err_t mg_lwip_tcp_recv_cb (void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err)
 
static err_t mg_lwip_tcp_sent_cb (void *arg, struct tcp_pcb *tpcb, u16_t num_sent)
 
static void mg_lwip_if_connect_tcp_tcpip (void *arg)
 
void mg_lwip_if_connect_tcp (struct mg_connection *nc, const union socket_address *sa)
 
static void mg_lwip_udp_recv_cb (void *arg, struct udp_pcb *pcb, struct pbuf *p, ip_addr_t *addr, u16_t port)
 
static int mg_lwip_if_udp_recv (struct mg_connection *nc, void *buf, size_t len, union socket_address *sa, size_t *sa_len)
 
static void mg_lwip_if_connect_udp_tcpip (void *arg)
 
void mg_lwip_if_connect_udp (struct mg_connection *nc)
 
static void tcp_close_tcpip (void *arg)
 
void mg_lwip_handle_accept (struct mg_connection *nc)
 
static err_t mg_lwip_accept_cb (void *arg, struct tcp_pcb *newtpcb, err_t err)
 
static void mg_lwip_if_listen_tcp_tcpip (void *arg)
 
int mg_lwip_if_listen_tcp (struct mg_connection *nc, union socket_address *sa)
 
static void mg_lwip_if_listen_udp_tcpip (void *arg)
 
int mg_lwip_if_listen_udp (struct mg_connection *nc, union socket_address *sa)
 
static void tcp_output_tcpip (void *arg)
 
static void mg_lwip_tcp_write_tcpip (void *arg)
 
int mg_lwip_if_tcp_send (struct mg_connection *nc, const void *buf, size_t len)
 
static void udp_sendto_tcpip (void *arg)
 
static int mg_lwip_if_udp_send (struct mg_connection *nc, const void *data, size_t len)
 
static int mg_lwip_if_can_send (struct mg_connection *nc, struct mg_lwip_conn_state *cs)
 
void tcp_recved_tcpip (void *arg)
 
static int mg_lwip_if_tcp_recv (struct mg_connection *nc, void *buf, size_t len)
 
int mg_lwip_if_create_conn (struct mg_connection *nc)
 
static void udp_remove_tcpip (void *arg)
 
void mg_lwip_if_destroy_conn (struct mg_connection *nc)
 
void mg_lwip_if_get_conn_addr (struct mg_connection *nc, int remote, union socket_address *sa)
 
void mg_lwip_if_sock_set (struct mg_connection *nc, sock_t sock)
 
void mg_ev_mgr_lwip_process_signals (struct mg_mgr *mgr)
 
int mg_pic32_if_create_conn (struct mg_connection *nc)
 
void mg_pic32_if_recved (struct mg_connection *nc, size_t len)
 
void mg_pic32_if_add_conn (struct mg_connection *nc)
 
void mg_pic32_if_init (struct mg_iface *iface)
 
void mg_pic32_if_free (struct mg_iface *iface)
 
void mg_pic32_if_remove_conn (struct mg_connection *nc)
 
void mg_pic32_if_destroy_conn (struct mg_connection *nc)
 
int mg_pic32_if_listen_udp (struct mg_connection *nc, union socket_address *sa)
 
void mg_pic32_if_udp_send (struct mg_connection *nc, const void *buf, size_t len)
 
void mg_pic32_if_tcp_send (struct mg_connection *nc, const void *buf, size_t len)
 
int mg_pic32_if_listen_tcp (struct mg_connection *nc, union socket_address *sa)
 
static void mg_handle_send (struct mg_connection *nc)
 
static void mg_handle_recv (struct mg_connection *nc)
 
time_t mg_pic32_if_poll (struct mg_iface *iface, int timeout_ms)
 
void mg_pic32_if_sock_set (struct mg_connection *nc, sock_t sock)
 
void mg_pic32_if_get_conn_addr (struct mg_connection *nc, int remote, union socket_address *sa)
 
void mg_pic32_if_connect_tcp (struct mg_connection *nc, const union socket_address *sa)
 
void mg_pic32_if_connect_udp (struct mg_connection *nc)
 

Variables

void *(* test_malloc )(size_t size)
 
void *(* test_calloc )(size_t count, size_t size)
 
enum cs_log_level cs_log_level
 
enum cs_log_level cs_log_level WEAK
 
const struct mg_iface_vtable mg_socket_iface_vtable = MG_SOCKET_IFACE_VTABLE
 
const struct mg_iface_vtable mg_default_iface_vtable = MG_NULL_IFACE_VTABLE
 
const struct mg_iface_vtablemg_ifaces []
 
int mg_num_ifaces = (int) (sizeof(mg_ifaces) / sizeof(mg_ifaces[0]))
 
const struct mg_iface_vtable mg_null_iface_vtable = MG_NULL_IFACE_VTABLE
 
static OsiMsgQ_t s_mg_q
 
const struct mg_iface_vtable mg_simplelink_iface_vtable = MG_SL_IFACE_VTABLE
 
const struct mg_iface_vtable mg_lwip_iface_vtable = MG_LWIP_IFACE_VTABLE
 
const struct mg_iface_vtable mg_pic32_iface_vtable = MG_PIC32_IFACE_VTABLE
 

Macro Definition Documentation

◆ _MG_ALLOWED_CONNECT_FLAGS_MASK

#define _MG_ALLOWED_CONNECT_FLAGS_MASK
Value:
#define MG_F_USER_6
Definition mongoose6.h:1298
#define MG_F_USER_2
Definition mongoose6.h:1294
#define MG_F_USER_4
Definition mongoose6.h:1296
#define MG_F_WEBSOCKET_NO_DEFRAG
Definition mongoose6.h:1290
#define MG_F_USER_1
Definition mongoose6.h:1293
#define MG_F_USER_5
Definition mongoose6.h:1297
#define MG_F_USER_3
Definition mongoose6.h:1295
#define MG_F_ENABLE_BROADCAST

Definition at line 2402 of file mongoose614.cxx.

◆ _MG_CALLBACK_MODIFIABLE_FLAGS_MASK

#define _MG_CALLBACK_MODIFIABLE_FLAGS_MASK
Value:

Definition at line 2406 of file mongoose614.cxx.

◆ _MG_F_FD_CAN_READ [1/2]

#define _MG_F_FD_CAN_READ   1

Definition at line 4034 of file mongoose614.cxx.

◆ _MG_F_FD_CAN_READ [2/2]

#define _MG_F_FD_CAN_READ   1

Definition at line 4034 of file mongoose614.cxx.

◆ _MG_F_FD_CAN_WRITE [1/2]

#define _MG_F_FD_CAN_WRITE   1 << 1

Definition at line 4035 of file mongoose614.cxx.

◆ _MG_F_FD_CAN_WRITE [2/2]

#define _MG_F_FD_CAN_WRITE   1 << 1

Definition at line 4035 of file mongoose614.cxx.

◆ _MG_F_FD_ERROR [1/2]

#define _MG_F_FD_ERROR   1 << 2

Definition at line 4036 of file mongoose614.cxx.

◆ _MG_F_FD_ERROR [2/2]

#define _MG_F_FD_ERROR   1 << 2

Definition at line 4036 of file mongoose614.cxx.

◆ BASE64_ENCODE_BODY

#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('='); \
} \
INT i
Definition mdump.cxx:32
INT j
Definition odbhist.cxx:40
TH1X EXPRT * h1_book(const char *name, const char *title, int bins, double min, double max)
Definition rmidas.h:24
char c
Definition system.cxx:1310

Definition at line 311 of file mongoose614.cxx.

316 { \
317 a = src[i]; \
318 b = i + 1 >= src_len ? 0 : src[i + 1]; \
319 c = i + 2 >= src_len ? 0 : src[i + 2]; \
320 \
321 BASE64_OUT(b64[a >> 2]); \
322 BASE64_OUT(b64[((a & 3) << 4) | (b >> 4)]); \
323 if (i + 1 < src_len) { \
324 BASE64_OUT(b64[(b & 15) << 2 | (c >> 6)]); \
325 } \
326 if (i + 2 < src_len) { \
327 BASE64_OUT(b64[c & 63]); \
328 } \
329 } \
330 \
331 while (j % 4 != 0) { \
332 BASE64_OUT('='); \
333 } \

◆ BASE64_FLUSH

#define BASE64_FLUSH ( )
Value:
do { \
dst[j++] = '\0'; \
} while (0)

Definition at line 341 of file mongoose614.cxx.

342 { \
343 dst[j++] = '\0'; \
344 } while (0)

◆ BASE64_OUT

#define BASE64_OUT (   ch)
Value:
do { \
dst[j++] = (ch); \
} while (0)

Definition at line 336 of file mongoose614.cxx.

337 { \
338 dst[j++] = (ch); \
339 } while (0)

◆ blk

#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 at line 1294 of file mongoose614.cxx.

◆ C_DISABLE_BUILTIN_SNPRINTF

#define C_DISABLE_BUILTIN_SNPRINTF   0

Definition at line 1854 of file mongoose614.cxx.

◆ C_SNPRINTF_APPEND_CHAR

#define C_SNPRINTF_APPEND_CHAR (   ch)
Value:
do { \
if (i < (int) buf_size) buf[i] = ch; \
i++; \
} while (0)

Definition at line 1867 of file mongoose614.cxx.

1868 { \
1869 if (i < (int) buf_size) buf[i] = ch; \
1870 i++; \
1871 } while (0)

◆ C_SNPRINTF_FLAG_ZERO

#define C_SNPRINTF_FLAG_ZERO   1

Definition at line 1873 of file mongoose614.cxx.

◆ CONSOLE_UART

#define CONSOLE_UART   UARTA0_BASE

Definition at line 13352 of file mongoose614.cxx.

◆ CS_COMMON_CS_DBG_H_

#define CS_COMMON_CS_DBG_H_

Definition at line 453 of file mongoose614.cxx.

◆ CS_COMMON_CS_DIRENT_H_

#define CS_COMMON_CS_DIRENT_H_

Definition at line 750 of file mongoose614.cxx.

◆ CS_COMMON_CS_ENDIAN_H_

#define CS_COMMON_CS_ENDIAN_H_

Definition at line 1013 of file mongoose614.cxx.

◆ CS_COMMON_MG_MEM_H_

#define CS_COMMON_MG_MEM_H_

Definition at line 185 of file mongoose614.cxx.

◆ CS_COMMON_PLATFORMS_LWIP_MG_NET_IF_LWIP_H_

#define CS_COMMON_PLATFORMS_LWIP_MG_NET_IF_LWIP_H_

Definition at line 15141 of file mongoose614.cxx.

◆ CS_COMMON_PLATFORMS_PIC32_NET_IF_H_

#define CS_COMMON_PLATFORMS_PIC32_NET_IF_H_

Definition at line 16191 of file mongoose614.cxx.

◆ CS_COMMON_PLATFORMS_SIMPLELINK_SL_FS_SLFS_H_

#define CS_COMMON_PLATFORMS_SIMPLELINK_SL_FS_SLFS_H_

Definition at line 13512 of file mongoose614.cxx.

◆ CS_COMMON_PLATFORMS_SIMPLELINK_SL_NET_IF_H_

#define CS_COMMON_PLATFORMS_SIMPLELINK_SL_NET_IF_H_

Definition at line 14412 of file mongoose614.cxx.

◆ CS_ENABLE_DEBUG

#define CS_ENABLE_DEBUG   0

Definition at line 462 of file mongoose614.cxx.

◆ CS_LOG_ENABLE_TS_DIFF

#define CS_LOG_ENABLE_TS_DIFF   0

Definition at line 470 of file mongoose614.cxx.

◆ CS_LOG_PREFIX_LEN

#define CS_LOG_PREFIX_LEN   24

Definition at line 466 of file mongoose614.cxx.

◆ CS_MONGOOSE_SRC_INTERNAL_H_

#define CS_MONGOOSE_SRC_INTERNAL_H_

Definition at line 11 of file mongoose614.cxx.

◆ CS_MONGOOSE_SRC_NET_IF_SOCKET_H_

#define CS_MONGOOSE_SRC_NET_IF_SOCKET_H_

Definition at line 3575 of file mongoose614.cxx.

◆ CS_MONGOOSE_SRC_NET_IF_SOCKS_H_

#define CS_MONGOOSE_SRC_NET_IF_SOCKS_H_

Definition at line 3603 of file mongoose614.cxx.

◆ DBG

#define DBG (   x)

Definition at line 574 of file mongoose614.cxx.

◆ F1

#define F1 (   x,
  y,
  z 
)    (z ^ (x & (y ^ z)))

Definition at line 1082 of file mongoose614.cxx.

◆ F2

#define F2 (   x,
  y,
  z 
)    F1(z, x, y)

Definition at line 1083 of file mongoose614.cxx.

◆ F3

#define F3 (   x,
  y,
  z 
)    (x ^ y ^ z)

Definition at line 1084 of file mongoose614.cxx.

◆ F4

#define F4 (   x,
  y,
  z 
)    (y ^ (x | ~z))

Definition at line 1085 of file mongoose614.cxx.

◆ intptr_t

#define intptr_t   long

Definition at line 2412 of file mongoose614.cxx.

◆ ip_2_ip4

#define ip_2_ip4 (   addr)    (addr)

Definition at line 15233 of file mongoose614.cxx.

◆ IPADDR_NTOA

#define IPADDR_NTOA   ipaddr_ntoa

Definition at line 15253 of file mongoose614.cxx.

◆ LOG

#define LOG (   l,
 
)

Definition at line 573 of file mongoose614.cxx.

◆ MAX

#define MAX (   a,
 
)    ((a) > (b) ? (a) : (b))

Definition at line 10465 of file mongoose614.cxx.

◆ MBUF_FREE

#define MBUF_FREE   MG_FREE

Definition at line 20 of file mongoose614.cxx.

◆ MBUF_REALLOC

#define MBUF_REALLOC   MG_REALLOC

Definition at line 16 of file mongoose614.cxx.

◆ MD5STEP

#define MD5STEP (   f,
  w,
  x,
  y,
  z,
  data,
 
)     (w += f(x, y, z) + data, w = w << s | w >> (32 - s), w += x)

Definition at line 1087 of file mongoose614.cxx.

◆ MG_CALLOC

#define MG_CALLOC   calloc

Definition at line 196 of file mongoose614.cxx.

◆ MG_COPY_COMMON_CONNECTION_OPTIONS

#define MG_COPY_COMMON_CONNECTION_OPTIONS (   dst,
  src 
)     memcpy(dst, src, sizeof(*dst));

Definition at line 2398 of file mongoose614.cxx.

◆ MG_CTL_MSG_MESSAGE_SIZE

#define MG_CTL_MSG_MESSAGE_SIZE   8192

Definition at line 42 of file mongoose614.cxx.

◆ MG_ENABLE_NET_IF_LWIP_LOW_LEVEL

#define MG_ENABLE_NET_IF_LWIP_LOW_LEVEL   MG_NET_IF == MG_NET_IF_LWIP_LOW_LEVEL

Definition at line 15144 of file mongoose614.cxx.

◆ MG_ENABLE_NET_IF_PIC32

#define MG_ENABLE_NET_IF_PIC32   MG_NET_IF == MG_NET_IF_PIC32

Definition at line 16200 of file mongoose614.cxx.

◆ MG_ENABLE_NET_IF_SIMPLELINK

#define MG_ENABLE_NET_IF_SIMPLELINK   MG_NET_IF == MG_NET_IF_SIMPLELINK

Definition at line 14421 of file mongoose614.cxx.

◆ MG_ENABLE_NET_IF_SOCKET

#define MG_ENABLE_NET_IF_SOCKET   MG_NET_IF == MG_NET_IF_SOCKET

Definition at line 3584 of file mongoose614.cxx.

◆ MG_FREE

#define MG_FREE   free

Definition at line 204 of file mongoose614.cxx.

◆ MG_INTERNAL

#define MG_INTERNAL   static

Definition at line 29 of file mongoose614.cxx.

◆ MG_LWIP_IFACE_VTABLE

#define MG_LWIP_IFACE_VTABLE
Value:
{ \
}
void mg_lwip_if_connect_udp(struct mg_connection *nc)
void mg_lwip_if_destroy_conn(struct mg_connection *nc)
void mg_lwip_if_add_conn(struct mg_connection *nc)
int mg_lwip_if_create_conn(struct mg_connection *nc)
time_t mg_lwip_if_poll(struct mg_iface *iface, int timeout_ms)
void mg_lwip_if_get_conn_addr(struct mg_connection *nc, int remote, union socket_address *sa)
void mg_lwip_if_free(struct mg_iface *iface)
static int mg_lwip_if_udp_send(struct mg_connection *nc, const void *data, size_t len)
void mg_lwip_if_remove_conn(struct mg_connection *nc)
void mg_lwip_if_init(struct mg_iface *iface)
static int mg_lwip_if_udp_recv(struct mg_connection *nc, void *buf, size_t len, union socket_address *sa, size_t *sa_len)
void mg_lwip_if_sock_set(struct mg_connection *nc, sock_t sock)
static int mg_lwip_if_tcp_recv(struct mg_connection *nc, void *buf, size_t len)
int mg_lwip_if_listen_tcp(struct mg_connection *nc, union socket_address *sa)
int mg_lwip_if_listen_udp(struct mg_connection *nc, union socket_address *sa)
int mg_lwip_if_tcp_send(struct mg_connection *nc, const void *buf, size_t len)
void mg_lwip_if_connect_tcp(struct mg_connection *nc, const union socket_address *sa)

Definition at line 15881 of file mongoose614.cxx.

◆ MG_MALLOC

#define MG_MALLOC   malloc

Definition at line 192 of file mongoose614.cxx.

◆ MG_MAX_HOST_LEN

#define MG_MAX_HOST_LEN   200

Definition at line 2389 of file mongoose614.cxx.

◆ MG_NULL_IFACE_VTABLE

#define MG_NULL_IFACE_VTABLE
Value:
{ \
}
static void mg_null_if_add_conn(struct mg_connection *c)
int mg_null_if_tcp_recv(struct mg_connection *c, void *buf, size_t len)
static void mg_null_if_get_conn_addr(struct mg_connection *c, int remote, union socket_address *sa)
static void mg_null_if_free(struct mg_iface *iface)
static time_t mg_null_if_poll(struct mg_iface *iface, int timeout_ms)
static void mg_null_if_init(struct mg_iface *iface)
static void mg_null_if_destroy_conn(struct mg_connection *c)
static int mg_null_if_create_conn(struct mg_connection *c)
static void mg_null_if_sock_set(struct mg_connection *c, sock_t sock)
static void mg_null_if_connect_udp(struct mg_connection *c)
static int mg_null_if_listen_tcp(struct mg_connection *c, union socket_address *sa)
static int mg_null_if_tcp_send(struct mg_connection *c, const void *buf, size_t len)
static int mg_null_if_udp_send(struct mg_connection *c, const void *buf, size_t len)
int mg_null_if_udp_recv(struct mg_connection *c, void *buf, size_t len, union socket_address *sa, size_t *sa_len)
static void mg_null_if_remove_conn(struct mg_connection *c)
static void mg_null_if_connect_tcp(struct mg_connection *c, const union socket_address *sa)
static int mg_null_if_listen_udp(struct mg_connection *c, union socket_address *sa)

Definition at line 3804 of file mongoose614.cxx.

◆ MG_PIC32_IFACE_VTABLE

#define MG_PIC32_IFACE_VTABLE
Value:
{ \
}
int mg_pic32_if_listen_udp(struct mg_connection *nc, union socket_address *sa)
void mg_pic32_if_udp_send(struct mg_connection *nc, const void *buf, size_t len)
int mg_pic32_if_listen_tcp(struct mg_connection *nc, union socket_address *sa)
void mg_pic32_if_tcp_send(struct mg_connection *nc, const void *buf, size_t len)
time_t mg_pic32_if_poll(struct mg_iface *iface, int timeout_ms)
void mg_pic32_if_recved(struct mg_connection *nc, size_t len)
void mg_pic32_if_add_conn(struct mg_connection *nc)
void mg_pic32_if_init(struct mg_iface *iface)
void mg_pic32_if_connect_udp(struct mg_connection *nc)
void mg_pic32_if_free(struct mg_iface *iface)
void mg_pic32_if_destroy_conn(struct mg_connection *nc)
int mg_pic32_if_create_conn(struct mg_connection *nc)
void mg_pic32_if_get_conn_addr(struct mg_connection *nc, int remote, union socket_address *sa)
void mg_pic32_if_sock_set(struct mg_connection *nc, sock_t sock)
void mg_pic32_if_connect_tcp(struct mg_connection *nc, const union socket_address *sa)
void mg_pic32_if_remove_conn(struct mg_connection *nc)

Definition at line 16490 of file mongoose614.cxx.

◆ MG_REALLOC

#define MG_REALLOC   realloc

Definition at line 200 of file mongoose614.cxx.

◆ MG_SET_PTRPTR

#define MG_SET_PTRPTR (   _ptr,
  _v 
)
Value:
do { \
if (_ptr) *(_ptr) = _v; \
} while (0)

Definition at line 23 of file mongoose614.cxx.

24 { \
25 if (_ptr) *(_ptr) = _v; \
26 } while (0)

◆ MG_SIG_QUEUE_LEN

#define MG_SIG_QUEUE_LEN   32

Definition at line 15932 of file mongoose614.cxx.

◆ MG_SL_IFACE_VTABLE

#define MG_SL_IFACE_VTABLE
Value:
{ \
}
static int mg_sl_if_listen_tcp(struct mg_connection *nc, union socket_address *sa)
void mg_sl_if_sock_set(struct mg_connection *nc, sock_t sock)
static int mg_sl_if_udp_recv(struct mg_connection *nc, void *buf, size_t len, union socket_address *sa, size_t *sa_len)
static int mg_sl_if_create_conn(struct mg_connection *nc)
static void mg_sl_if_connect_tcp(struct mg_connection *nc, const union socket_address *sa)
void mg_sl_if_add_conn(struct mg_connection *nc)
void mg_sl_if_remove_conn(struct mg_connection *nc)
static int mg_sl_if_listen_udp(struct mg_connection *nc, union socket_address *sa)
static void mg_sl_if_connect_udp(struct mg_connection *nc)
static int mg_sl_if_tcp_recv(struct mg_connection *nc, void *buf, size_t len)
void mg_sl_if_get_conn_addr(struct mg_connection *nc, int remote, union socket_address *sa)
void mg_sl_if_destroy_conn(struct mg_connection *nc)
void mg_sl_if_init(struct mg_iface *iface)
void mg_sl_if_free(struct mg_iface *iface)
static int mg_sl_if_tcp_send(struct mg_connection *nc, const void *buf, size_t len)
static int mg_sl_if_udp_send(struct mg_connection *nc, const void *buf, size_t len)
time_t mg_sl_if_poll(struct mg_iface *iface, int timeout_ms)

Definition at line 14838 of file mongoose614.cxx.

◆ MG_SOCKET_IFACE_VTABLE

#define MG_SOCKET_IFACE_VTABLE
Value:
{ \
}
void mg_socket_if_sock_set(struct mg_connection *nc, sock_t sock)
void mg_socket_if_connect_udp(struct mg_connection *nc)
static int mg_socket_if_tcp_send(struct mg_connection *nc, const void *buf, size_t len)
static int mg_socket_if_udp_recv(struct mg_connection *nc, void *buf, size_t len, union socket_address *sa, size_t *sa_len)
void mg_socket_if_add_conn(struct mg_connection *nc)
void mg_socket_if_get_conn_addr(struct mg_connection *nc, int remote, union socket_address *sa)
void mg_socket_if_init(struct mg_iface *iface)
void mg_socket_if_connect_tcp(struct mg_connection *nc, const union socket_address *sa)
void mg_socket_if_remove_conn(struct mg_connection *nc)
static int mg_socket_if_udp_send(struct mg_connection *nc, const void *buf, size_t len)
static int mg_socket_if_listen_udp(struct mg_connection *nc, union socket_address *sa)
static int mg_socket_if_tcp_recv(struct mg_connection *nc, void *buf, size_t len)
int mg_socket_if_listen_tcp(struct mg_connection *nc, union socket_address *sa)
void mg_socket_if_free(struct mg_iface *iface)
int mg_socket_if_create_conn(struct mg_connection *nc)
void mg_socket_if_destroy_conn(struct mg_connection *nc)
time_t mg_socket_if_poll(struct mg_iface *iface, int timeout_ms)

Definition at line 4376 of file mongoose614.cxx.

◆ MG_TCP_IO_SIZE

#define MG_TCP_IO_SIZE   1460

Definition at line 2392 of file mongoose614.cxx.

◆ MG_TCP_RECV_BUFFER_SIZE

#define MG_TCP_RECV_BUFFER_SIZE   1024

Definition at line 14458 of file mongoose614.cxx.

◆ MG_UDP_IO_SIZE

#define MG_UDP_IO_SIZE   1460

Definition at line 2395 of file mongoose614.cxx.

◆ MG_UDP_RECV_BUFFER_SIZE

#define MG_UDP_RECV_BUFFER_SIZE   1500

Definition at line 14459 of file mongoose614.cxx.

◆ mgos_lock

#define mgos_lock ( )

Definition at line 15272 of file mongoose614.cxx.

◆ mgos_unlock

#define mgos_unlock ( )

Definition at line 15273 of file mongoose614.cxx.

◆ MIN

#define MIN (   a,
 
)    ((a) < (b) ? (a) : (b))

Definition at line 85 of file mongoose614.cxx.

◆ NUM_DIGITS

#define NUM_DIGITS   ('9' - '0' + 1)

Definition at line 244 of file mongoose614.cxx.

◆ NUM_LETTERS

#define NUM_LETTERS   (NUM_UPPERCASES * 2)

Definition at line 243 of file mongoose614.cxx.

◆ NUM_UPPERCASES

#define NUM_UPPERCASES   ('Z' - 'A' + 1)

Definition at line 242 of file mongoose614.cxx.

◆ R0

#define R0 (   v,
  w,
  x,
  y,
  z,
  i 
)
Value:
z += ((w & (x ^ y)) ^ y) + blk0(block, i) + 0x5A827999 + rol(v, 5); \
w = rol(w, 30);
static uint32_t blk0(union char64long16 *block, int i)

Definition at line 1298 of file mongoose614.cxx.

◆ R1

#define R1 (   v,
  w,
  x,
  y,
  z,
  i 
)
Value:
z += ((w & (x ^ y)) ^ y) + blk(i) + 0x5A827999 + rol(v, 5); \
w = rol(w, 30);
#define blk(i)

Definition at line 1301 of file mongoose614.cxx.

◆ R2

#define R2 (   v,
  w,
  x,
  y,
  z,
  i 
)
Value:
z += (w ^ x ^ y) + blk(i) + 0x6ED9EBA1 + rol(v, 5); \
w = rol(w, 30);

Definition at line 1304 of file mongoose614.cxx.

◆ R3

#define R3 (   v,
  w,
  x,
  y,
  z,
  i 
)
Value:
z += (((w | x) & y) | (w & x)) + blk(i) + 0x8F1BBCDC + rol(v, 5); \
w = rol(w, 30);

Definition at line 1307 of file mongoose614.cxx.

◆ R4

#define R4 (   v,
  w,
  x,
  y,
  z,
  i 
)
Value:
z += (w ^ x ^ y) + blk(i) + 0xCA62C1D6 + rol(v, 5); \
w = rol(w, 30);

Definition at line 1310 of file mongoose614.cxx.

◆ rol

#define rol (   value,
  bits 
)    (((value) << (bits)) | ((value) >> (32 - (bits))))

Definition at line 1275 of file mongoose614.cxx.

◆ SET_ADDR

#define SET_ADDR (   dst,
  src 
)    (dst)->sin.sin_addr.s_addr = ip_2_ip4(src)->addr

Definition at line 15254 of file mongoose614.cxx.

◆ SHA1HANDSOFF

#define SHA1HANDSOFF

Definition at line 1265 of file mongoose614.cxx.

◆ TCP_BIND

#define TCP_BIND   tcp_bind

Definition at line 15251 of file mongoose614.cxx.

◆ TCP_NEW

#define TCP_NEW   tcp_new

Definition at line 15250 of file mongoose614.cxx.

◆ UDP_BIND

#define UDP_BIND   udp_bind

Definition at line 15252 of file mongoose614.cxx.

Typedef Documentation

◆ cs_dirent_dummy

Definition at line 893 of file mongoose614.cxx.

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 480 of file mongoose614.cxx.

480 {
481 LL_NONE = -1,
482 LL_ERROR = 0,
483 LL_WARN = 1,
484 LL_INFO = 2,
485 LL_DEBUG = 3,
487
488 _LL_MIN = -2,
489 _LL_MAX = 5,
490};
@ LL_INFO
@ LL_DEBUG
@ LL_ERROR
@ LL_NONE
@ _LL_MAX
@ LL_WARN
@ LL_VERBOSE_DEBUG
@ _LL_MIN

◆ mg_q_msg_type

Enumerator
MG_Q_MSG_CB 

Definition at line 14345 of file mongoose614.cxx.

14345 {
14347};
@ MG_Q_MSG_CB

◆ mg_sig_type

Enumerator
MG_SIG_CONNECT_RESULT 
MG_SIG_RECV 
MG_SIG_CLOSE_CONN 
MG_SIG_TOMBSTONE 
MG_SIG_ACCEPT 

Definition at line 15172 of file mongoose614.cxx.

15172 {
15174 MG_SIG_RECV = 2,
15176 MG_SIG_TOMBSTONE = 4,
15177 MG_SIG_ACCEPT = 5,
15178};
@ MG_SIG_CLOSE_CONN
@ MG_SIG_RECV
@ MG_SIG_TOMBSTONE
@ MG_SIG_ACCEPT
@ MG_SIG_CONNECT_RESULT

Function Documentation

◆ _exit()

void _exit ( int  status)

Definition at line 13397 of file mongoose614.cxx.

13397 {
13398 fprint_str(stderr, "_exit\n");
13399 /* cause an unaligned access exception, that will drop you into gdb */
13400 *(int *) 1 = status;
13401 while (1)
13402 ; /* avoid gcc warning because stdlib abort() has noreturn attribute */
13403}
void fprint_str(FILE *fp, const char *str)
DWORD status
Definition odbhist.cxx:39
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _getpid()

int _getpid ( )

Definition at line 13418 of file mongoose614.cxx.

13418 {
13419 fprint_str(stderr, "_getpid is not implemented\n");
13420 return 42;
13421}
Here is the call graph for this function:

◆ _isatty()

int _isatty ( int  fd)

Definition at line 13423 of file mongoose614.cxx.

13423 {
13424 /* 0, 1 and 2 are TTYs. */
13425 return fd < 2;
13426}

◆ _kill()

int _kill ( int  pid,
int  sig 
)

Definition at line 13411 of file mongoose614.cxx.

13411 {
13412 (void) pid;
13413 (void) sig;
13414 _not_implemented("_kill");
13415 return -1;
13416}
void _not_implemented(const char *what)
Here is the call graph for this function:

◆ _not_implemented()

void _not_implemented ( const char what)

Definition at line 13405 of file mongoose614.cxx.

13405 {
13406 fprint_str(stderr, what);
13407 fprint_str(stderr, " is not implemented\n");
13408 _exit(42);
13409}
void _exit(int status)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ blk0()

static uint32_t blk0 ( union char64long16 block,
int  i 
)
static

Definition at line 1277 of file mongoose614.cxx.

1277 {
1278/* Forrest: SHA expect BIG_ENDIAN, swap if LITTLE_ENDIAN */
1279#if BYTE_ORDER == LITTLE_ENDIAN
1280 block->l[i] =
1281 (rol(block->l[i], 24) & 0xFF00FF00) | (rol(block->l[i], 8) & 0x00FF00FF);
1282#endif
1283 return block->l[i];
1284}
Here is the call graph for this function:

◆ byteReverse()

static void byteReverse ( unsigned char buf,
unsigned  longs 
)
static

Definition at line 1067 of file mongoose614.cxx.

1067 {
1068/* Forrest: MD5 expect LITTLE_ENDIAN, swap if BIG_ENDIAN */
1069#if BYTE_ORDER == BIG_ENDIAN
1070 do {
1071 uint32_t t = (uint32_t)((unsigned) buf[3] << 8 | buf[2]) << 16 |
1072 ((unsigned) buf[1] << 8 | buf[0]);
1073 *(uint32_t *) buf = t;
1074 buf += 4;
1075 } while (--longs);
1076#else
1077 (void) buf;
1078 (void) longs;
1079#endif
1080}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ c_itoa()

static int c_itoa ( char buf,
size_t  buf_size,
int64_t  num,
int  base,
int  flags,
int  field_width 
)
static

Definition at line 1881 of file mongoose614.cxx.

1882 {
1883 char tmp[40];
1884 int i = 0, k = 0, neg = 0;
1885
1886 if (num < 0) {
1887 neg++;
1888 num = -num;
1889 }
1890
1891 /* Print into temporary buffer - in reverse order */
1892 do {
1893 int rem = num % base;
1894 if (rem < 10) {
1895 tmp[k++] = '0' + rem;
1896 } else {
1897 tmp[k++] = 'a' + (rem - 10);
1898 }
1899 num /= base;
1900 } while (num > 0);
1901
1902 /* Zero padding */
1903 if (flags && C_SNPRINTF_FLAG_ZERO) {
1904 while (k < field_width && k < (int) sizeof(tmp) - 1) {
1905 tmp[k++] = '0';
1906 }
1907 }
1908
1909 /* And sign */
1910 if (neg) {
1911 tmp[k++] = '-';
1912 }
1913
1914 /* Now output */
1915 while (--k >= 0) {
1917 }
1918
1919 return i;
1920}
#define C_SNPRINTF_FLAG_ZERO
#define C_SNPRINTF_APPEND_CHAR(ch)
INT k
Definition odbhist.cxx:40
static te_expr * base(state *s)
Definition tinyexpr.c:357
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cs_base64_decode()

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

Definition at line 410 of file mongoose614.cxx.

410 {
411 unsigned char a, b, c, d;
412 int orig_len = len;
413 char *orig_dst = dst;
414 while (len >= 4 && (a = from_b64(s[0])) != 255 &&
415 (b = from_b64(s[1])) != 255 && (c = from_b64(s[2])) != 255 &&
416 (d = from_b64(s[3])) != 255) {
417 s += 4;
418 len -= 4;
419 if (a == 200 || b == 200) break; /* '=' can't be there */
420 *dst++ = a << 2 | b >> 4;
421 if (c == 200) break;
422 *dst++ = b << 4 | c >> 2;
423 if (d == 200) break;
424 *dst++ = c << 6 | d;
425 }
426 *dst = 0;
427 if (dec_len != NULL) *dec_len = (dst - orig_dst);
428 return orig_len - len;
429}
static unsigned char from_b64(unsigned char ch)
double d
Definition system.cxx:1311
Here is the caller graph for this function:

◆ cs_base64_emit_chunk()

static void cs_base64_emit_chunk ( struct cs_base64_ctx ctx)
static

Definition at line 264 of file mongoose614.cxx.

264 {
265 int a, b, c;
266
267 a = ctx->chunk[0];
268 b = ctx->chunk[1];
269 c = ctx->chunk[2];
270
271 cs_base64_emit_code(ctx, a >> 2);
272 cs_base64_emit_code(ctx, ((a & 3) << 4) | (b >> 4));
273 if (ctx->chunk_size > 1) {
274 cs_base64_emit_code(ctx, (b & 15) << 2 | (c >> 6));
275 }
276 if (ctx->chunk_size > 2) {
277 cs_base64_emit_code(ctx, c & 63);
278 }
279}
unsigned char chunk[3]
Definition mongoose6.h:982
static void cs_base64_emit_code(struct cs_base64_ctx *ctx, int v)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cs_base64_emit_code()

static void cs_base64_emit_code ( struct cs_base64_ctx ctx,
int  v 
)
static

Definition at line 251 of file mongoose614.cxx.

251 {
252 if (v < NUM_UPPERCASES) {
253 ctx->b64_putc(v + 'A', ctx->user_data);
254 } else if (v < (NUM_LETTERS)) {
255 ctx->b64_putc(v - NUM_UPPERCASES + 'a', ctx->user_data);
256 } else if (v < (NUM_LETTERS + NUM_DIGITS)) {
257 ctx->b64_putc(v - NUM_LETTERS + '0', ctx->user_data);
258 } else {
259 ctx->b64_putc(v - NUM_LETTERS - NUM_DIGITS == 0 ? '+' : '/',
260 ctx->user_data);
261 }
262}
void * user_data
Definition mongoose6.h:984
cs_base64_putc_t b64_putc
Definition mongoose6.h:981
#define NUM_DIGITS
#define NUM_UPPERCASES
#define NUM_LETTERS
Here is the caller graph for this function:

◆ cs_from_hex()

void cs_from_hex ( char to,
const char p,
size_t  len 
)

Definition at line 2154 of file mongoose614.cxx.

2154 {
2155 size_t i;
2156
2157 for (i = 0; i < len; i += 2) {
2158 *to++ = (fourbit(p[i]) << 4) + fourbit(p[i + 1]);
2159 }
2160 *to = '\0';
2161}
static int fourbit(int ch)

◆ cs_log_print_prefix()

int cs_log_print_prefix ( enum cs_log_level  level,
const char fname,
int  line 
)

◆ cs_log_set_file_level()

void cs_log_set_file_level ( const char file_level)

Definition at line 716 of file mongoose614.cxx.

716 {
718}
Here is the call graph for this function:

◆ cs_md5_final()

void cs_md5_final ( unsigned char  digest[16],
cs_md5_ctx ctx 
)

Definition at line 1221 of file mongoose614.cxx.

1221 {
1222 unsigned count;
1223 unsigned char *p;
1224 uint32_t *a;
1225
1226 count = (ctx->bits[0] >> 3) & 0x3F;
1227
1228 p = ctx->in + count;
1229 *p++ = 0x80;
1230 count = 64 - 1 - count;
1231 if (count < 8) {
1232 memset(p, 0, count);
1233 byteReverse(ctx->in, 16);
1234 cs_md5_transform(ctx->buf, (uint32_t *) ctx->in);
1235 memset(ctx->in, 0, 56);
1236 } else {
1237 memset(p, 0, count - 8);
1238 }
1239 byteReverse(ctx->in, 14);
1240
1241 a = (uint32_t *) ctx->in;
1242 a[14] = ctx->bits[0];
1243 a[15] = ctx->bits[1];
1244
1245 cs_md5_transform(ctx->buf, (uint32_t *) ctx->in);
1246 byteReverse((unsigned char *) ctx->buf, 4);
1247 memcpy(digest, ctx->buf, 16);
1248 memset((char *) ctx, 0, sizeof(*ctx));
1249}
double count
Definition mdump.cxx:33
static void cs_md5_transform(uint32_t buf[4], uint32_t const in[16])
static void byteReverse(unsigned char *buf, unsigned longs)
unsigned char in[64]
uint32_t bits[2]
uint32_t buf[4]
Here is the call graph for this function:

◆ cs_md5_init()

void cs_md5_init ( cs_md5_ctx ctx)

Definition at line 1094 of file mongoose614.cxx.

1094 {
1095 ctx->buf[0] = 0x67452301;
1096 ctx->buf[1] = 0xefcdab89;
1097 ctx->buf[2] = 0x98badcfe;
1098 ctx->buf[3] = 0x10325476;
1099
1100 ctx->bits[0] = 0;
1101 ctx->bits[1] = 0;
1102}

◆ cs_md5_transform()

static void cs_md5_transform ( uint32_t  buf[4],
uint32_t const  in[16] 
)
static

Definition at line 1104 of file mongoose614.cxx.

1104 {
1105 register uint32_t a, b, c, d;
1106
1107 a = buf[0];
1108 b = buf[1];
1109 c = buf[2];
1110 d = buf[3];
1111
1112 MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
1113 MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
1114 MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);
1115 MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
1116 MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
1117 MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);
1118 MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);
1119 MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);
1120 MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);
1121 MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
1122 MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
1123 MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
1124 MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
1125 MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
1126 MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
1127 MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);
1128
1129 MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
1130 MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);
1131 MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
1132 MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
1133 MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);
1134 MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
1135 MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
1136 MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
1137 MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
1138 MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
1139 MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
1140 MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);
1141 MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
1142 MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
1143 MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
1144 MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
1145
1146 MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
1147 MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);
1148 MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
1149 MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
1150 MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);
1151 MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
1152 MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
1153 MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
1154 MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
1155 MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
1156 MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
1157 MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);
1158 MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
1159 MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
1160 MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
1161 MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
1162
1163 MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);
1164 MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);
1165 MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
1166 MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);
1167 MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
1168 MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
1169 MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
1170 MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);
1171 MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
1172 MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
1173 MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);
1174 MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
1175 MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);
1176 MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
1177 MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
1178 MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);
1179
1180 buf[0] += a;
1181 buf[1] += b;
1182 buf[2] += c;
1183 buf[3] += d;
1184}
#define MD5STEP(f, w, x, y, z, data, s)
#define F1(x, y, z)
#define F4(x, y, z)
#define F3(x, y, z)
#define F2(x, y, z)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cs_md5_update()

void cs_md5_update ( cs_md5_ctx ctx,
const unsigned char buf,
size_t  len 
)

Definition at line 1186 of file mongoose614.cxx.

1186 {
1187 uint32_t t;
1188
1189 t = ctx->bits[0];
1190 if ((ctx->bits[0] = t + ((uint32_t) len << 3)) < t) ctx->bits[1]++;
1191 ctx->bits[1] += (uint32_t) len >> 29;
1192
1193 t = (t >> 3) & 0x3f;
1194
1195 if (t) {
1196 unsigned char *p = (unsigned char *) ctx->in + t;
1197
1198 t = 64 - t;
1199 if (len < t) {
1200 memcpy(p, buf, len);
1201 return;
1202 }
1203 memcpy(p, buf, t);
1204 byteReverse(ctx->in, 16);
1205 cs_md5_transform(ctx->buf, (uint32_t *) ctx->in);
1206 buf += t;
1207 len -= t;
1208 }
1209
1210 while (len >= 64) {
1211 memcpy(ctx->in, buf, 64);
1212 byteReverse(ctx->in, 16);
1213 cs_md5_transform(ctx->buf, (uint32_t *) ctx->in);
1214 buf += 64;
1215 len -= 64;
1216 }
1217
1218 memcpy(ctx->in, buf, len);
1219}

◆ cs_sha1_transform()

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

Definition at line 1314 of file mongoose614.cxx.

1314 {
1315 uint32_t a, b, c, d, e;
1316 union char64long16 block[1];
1317
1318 memcpy(block, buffer, 64);
1319 a = state[0];
1320 b = state[1];
1321 c = state[2];
1322 d = state[3];
1323 e = state[4];
1324 R0(a, b, c, d, e, 0);
1325 R0(e, a, b, c, d, 1);
1326 R0(d, e, a, b, c, 2);
1327 R0(c, d, e, a, b, 3);
1328 R0(b, c, d, e, a, 4);
1329 R0(a, b, c, d, e, 5);
1330 R0(e, a, b, c, d, 6);
1331 R0(d, e, a, b, c, 7);
1332 R0(c, d, e, a, b, 8);
1333 R0(b, c, d, e, a, 9);
1334 R0(a, b, c, d, e, 10);
1335 R0(e, a, b, c, d, 11);
1336 R0(d, e, a, b, c, 12);
1337 R0(c, d, e, a, b, 13);
1338 R0(b, c, d, e, a, 14);
1339 R0(a, b, c, d, e, 15);
1340 R1(e, a, b, c, d, 16);
1341 R1(d, e, a, b, c, 17);
1342 R1(c, d, e, a, b, 18);
1343 R1(b, c, d, e, a, 19);
1344 R2(a, b, c, d, e, 20);
1345 R2(e, a, b, c, d, 21);
1346 R2(d, e, a, b, c, 22);
1347 R2(c, d, e, a, b, 23);
1348 R2(b, c, d, e, a, 24);
1349 R2(a, b, c, d, e, 25);
1350 R2(e, a, b, c, d, 26);
1351 R2(d, e, a, b, c, 27);
1352 R2(c, d, e, a, b, 28);
1353 R2(b, c, d, e, a, 29);
1354 R2(a, b, c, d, e, 30);
1355 R2(e, a, b, c, d, 31);
1356 R2(d, e, a, b, c, 32);
1357 R2(c, d, e, a, b, 33);
1358 R2(b, c, d, e, a, 34);
1359 R2(a, b, c, d, e, 35);
1360 R2(e, a, b, c, d, 36);
1361 R2(d, e, a, b, c, 37);
1362 R2(c, d, e, a, b, 38);
1363 R2(b, c, d, e, a, 39);
1364 R3(a, b, c, d, e, 40);
1365 R3(e, a, b, c, d, 41);
1366 R3(d, e, a, b, c, 42);
1367 R3(c, d, e, a, b, 43);
1368 R3(b, c, d, e, a, 44);
1369 R3(a, b, c, d, e, 45);
1370 R3(e, a, b, c, d, 46);
1371 R3(d, e, a, b, c, 47);
1372 R3(c, d, e, a, b, 48);
1373 R3(b, c, d, e, a, 49);
1374 R3(a, b, c, d, e, 50);
1375 R3(e, a, b, c, d, 51);
1376 R3(d, e, a, b, c, 52);
1377 R3(c, d, e, a, b, 53);
1378 R3(b, c, d, e, a, 54);
1379 R3(a, b, c, d, e, 55);
1380 R3(e, a, b, c, d, 56);
1381 R3(d, e, a, b, c, 57);
1382 R3(c, d, e, a, b, 58);
1383 R3(b, c, d, e, a, 59);
1384 R4(a, b, c, d, e, 60);
1385 R4(e, a, b, c, d, 61);
1386 R4(d, e, a, b, c, 62);
1387 R4(c, d, e, a, b, 63);
1388 R4(b, c, d, e, a, 64);
1389 R4(a, b, c, d, e, 65);
1390 R4(e, a, b, c, d, 66);
1391 R4(d, e, a, b, c, 67);
1392 R4(c, d, e, a, b, 68);
1393 R4(b, c, d, e, a, 69);
1394 R4(a, b, c, d, e, 70);
1395 R4(e, a, b, c, d, 71);
1396 R4(d, e, a, b, c, 72);
1397 R4(c, d, e, a, b, 73);
1398 R4(b, c, d, e, a, 74);
1399 R4(a, b, c, d, e, 75);
1400 R4(e, a, b, c, d, 76);
1401 R4(d, e, a, b, c, 77);
1402 R4(c, d, e, a, b, 78);
1403 R4(b, c, d, e, a, 79);
1404 state[0] += a;
1405 state[1] += b;
1406 state[2] += c;
1407 state[3] += d;
1408 state[4] += e;
1409 /* Erase working structures. The order of operations is important,
1410 * used to ensure that compiler doesn't optimize those out. */
1411 memset(block, 0, sizeof(block));
1412 a = b = c = d = e = 0;
1413 (void) a;
1414 (void) b;
1415 (void) c;
1416 (void) d;
1417 (void) e;
1418}
#define R1(v, w, x, y, z, i)
#define R2(v, w, x, y, z, i)
#define R0(v, w, x, y, z, i)
#define R3(v, w, x, y, z, i)
#define R4(v, w, x, y, z, i)
static double e(void)
Definition tinyexpr.c:136
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cs_timegm()

double cs_timegm ( const struct tm tm)

Definition at line 958 of file mongoose614.cxx.

958 {
959 /* Month-to-day offset for non-leap-years. */
960 static const int month_day[12] = {0, 31, 59, 90, 120, 151,
961 181, 212, 243, 273, 304, 334};
962
963 /* Most of the calculation is easy; leap years are the main difficulty. */
964 int month = tm->tm_mon % 12;
965 int year = tm->tm_year + tm->tm_mon / 12;
966 int year_for_leap;
967 int64_t rt;
968
969 if (month < 0) { /* Negative values % 12 are still negative. */
970 month += 12;
971 --year;
972 }
973
974 /* This is the number of Februaries since 1900. */
975 year_for_leap = (month > 1) ? year + 1 : year;
976
977 rt =
978 tm->tm_sec /* Seconds */
979 +
980 60 *
981 (tm->tm_min /* Minute = 60 seconds */
982 +
983 60 * (tm->tm_hour /* Hour = 60 minutes */
984 +
985 24 * (month_day[month] + tm->tm_mday - 1 /* Day = 24 hours */
986 + 365 * (year - 70) /* Year = 365 days */
987 + (year_for_leap - 69) / 4 /* Every 4 years is leap... */
988 - (year_for_leap - 1) / 100 /* Except centuries... */
989 + (year_for_leap + 299) / 400))); /* Except 400s. */
990 return rt < 0 ? -1 : (double) rt;
991}
MUTEX_T * tm
Definition odbedit.cxx:39

◆ fourbit()

static int fourbit ( int  ch)
static

Definition at line 2142 of file mongoose614.cxx.

2142 {
2143 if (ch >= '0' && ch <= '9') {
2144 return ch - '0';
2145 } else if (ch >= 'a' && ch <= 'f') {
2146 return ch - 'a' + 10;
2147 } else if (ch >= 'A' && ch <= 'F') {
2148 return ch - 'A' + 10;
2149 }
2150 return 0;
2151}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fprint_str()

void fprint_str ( FILE fp,
const char str 
)

Definition at line 13390 of file mongoose614.cxx.

13390 {
13391 while (*str != '\0') {
13392 if (*str == '\n') MAP_UARTCharPut(CONSOLE_UART, '\r');
13394 }
13395}
#define CONSOLE_UART
char str[256]
Definition odbhist.cxx:33
Here is the call graph for this function:
Here is the caller graph for this function:

◆ from_b64()

static unsigned char from_b64 ( unsigned char  ch)
static

Definition at line 371 of file mongoose614.cxx.

371 {
372 /* Inverse lookup map */
373 static const unsigned char tab[128] = {
374 255, 255, 255, 255,
375 255, 255, 255, 255, /* 0 */
376 255, 255, 255, 255,
377 255, 255, 255, 255, /* 8 */
378 255, 255, 255, 255,
379 255, 255, 255, 255, /* 16 */
380 255, 255, 255, 255,
381 255, 255, 255, 255, /* 24 */
382 255, 255, 255, 255,
383 255, 255, 255, 255, /* 32 */
384 255, 255, 255, 62,
385 255, 255, 255, 63, /* 40 */
386 52, 53, 54, 55,
387 56, 57, 58, 59, /* 48 */
388 60, 61, 255, 255,
389 255, 200, 255, 255, /* 56 '=' is 200, on index 61 */
390 255, 0, 1, 2,
391 3, 4, 5, 6, /* 64 */
392 7, 8, 9, 10,
393 11, 12, 13, 14, /* 72 */
394 15, 16, 17, 18,
395 19, 20, 21, 22, /* 80 */
396 23, 24, 25, 255,
397 255, 255, 255, 255, /* 88 */
398 255, 26, 27, 28,
399 29, 30, 31, 32, /* 96 */
400 33, 34, 35, 36,
401 37, 38, 39, 40, /* 104 */
402 41, 42, 43, 44,
403 45, 46, 47, 48, /* 112 */
404 49, 50, 51, 255,
405 255, 255, 255, 255, /* 120 */
406 };
407 return tab[ch & 127];
408}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ gettimeofday()

int gettimeofday ( struct timeval tp,
void tzp 
)

Definition at line 13454 of file mongoose614.cxx.

13454 {
13456 tp->tv_sec = ticks / 1000;
13457 tp->tv_usec = (ticks % 1000) * 1000;
13458 return 0;
13459}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ inet_ntoa()

char * inet_ntoa ( struct in_addr  n)

Definition at line 14313 of file mongoose614.cxx.

14313 {
14314 static char a[16];
14315 return (char *) inet_ntop(AF_INET, &n, a, sizeof(a));
14316}
DWORD n[4]
Definition mana.cxx:247
const char * inet_ntop(int af, const void *src, char *dst, socklen_t size)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ inet_ntop()

const char * inet_ntop ( int  af,
const void src,
char dst,
socklen_t  size 
)

Definition at line 14300 of file mongoose614.cxx.

14300 {
14301 int res;
14302 struct in_addr *in = (struct in_addr *) src;
14303 if (af != AF_INET) {
14304 errno = ENOTSUP;
14305 return NULL;
14306 }
14307 res = snprintf(dst, size, "%lu.%lu.%lu.%lu", SL_IPV4_BYTE(in->s_addr, 0),
14308 SL_IPV4_BYTE(in->s_addr, 1), SL_IPV4_BYTE(in->s_addr, 2),
14309 SL_IPV4_BYTE(in->s_addr, 3));
14310 return res > 0 ? dst : NULL;
14311}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ inet_pton()

int inet_pton ( int  af,
const char src,
void dst 
)

Definition at line 14318 of file mongoose614.cxx.

14318 {
14319 uint32_t a0, a1, a2, a3;
14320 uint8_t *db = (uint8_t *) dst;
14321 if (af != AF_INET) {
14322 errno = ENOTSUP;
14323 return 0;
14324 }
14325 if (sscanf(src, "%lu.%lu.%lu.%lu", &a0, &a1, &a2, &a3) != 4) {
14326 return 0;
14327 }
14328 *db = a3;
14329 *(db + 1) = a2;
14330 *(db + 2) = a1;
14331 *(db + 3) = a0;
14332 return 1;
14333}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ isbyte()

static int isbyte ( int  n)
static

Definition at line 3462 of file mongoose614.cxx.

3462 {
3463 return n >= 0 && n <= 255;
3464}
Here is the caller graph for this function:

◆ mbuf_append_and_free()

size_t mbuf_append_and_free ( struct mbuf a,
void buf,
size_t  len 
)

Definition at line 1628 of file mongoose614.cxx.

1628 {
1629 size_t ret;
1630 /* Optimization: if the buffer is currently empty,
1631 * take over the user-provided buffer. */
1632 if (a->len == 0) {
1633 if (a->buf != NULL) free(a->buf);
1634 a->buf = (char *) data;
1635 a->len = a->size = len;
1636 return len;
1637 }
1638 ret = mbuf_insert(a, a->len, data, len);
1639 free(data);
1640 return ret;
1641}
size_t mbuf_insert(struct mbuf *a, size_t off, const void *buf, size_t) WEAK
size_t len
Definition mongoose6.h:835
char * buf
Definition mongoose6.h:834
size_t size
Definition mongoose6.h:836
void * data
Definition mana.cxx:268

◆ mbuf_clear()

void mbuf_clear ( struct mbuf mb)

Definition at line 1652 of file mongoose614.cxx.

1652 {
1653 mb->len = 0;
1654}

◆ mbuf_move()

void mbuf_move ( struct mbuf from,
struct mbuf to 
)

Definition at line 1657 of file mongoose614.cxx.

1657 {
1658 memcpy(to, from, sizeof(*to));
1659 memset(from, 0, sizeof(*from));
1660}

◆ mg_accept_conn()

static int mg_accept_conn ( struct mg_connection lc)
static

Definition at line 3963 of file mongoose614.cxx.

3963 {
3964 struct mg_connection *nc;
3965 union socket_address sa;
3966 socklen_t sa_len = sizeof(sa);
3967 /* NOTE(lsm): on Windows, sock is always > FD_SETSIZE */
3968 sock_t sock = accept(lc->sock, &sa.sa, &sa_len);
3969 if (sock == INVALID_SOCKET) {
3970 if (mg_is_error()) {
3971 DBG(("%p: failed to accept: %d", lc, mg_get_errno()));
3972 }
3973 return 0;
3974 }
3975 nc = mg_if_accept_new_conn(lc);
3976 if (nc == NULL) {
3977 closesocket(sock);
3978 return 0;
3979 }
3980 DBG(("%p conn from %s:%d", nc, inet_ntoa(sa.sin.sin_addr),
3981 ntohs(sa.sin.sin_port)));
3982 mg_sock_set(nc, sock);
3984 return 1;
3985}
void mg_if_accept_tcp_cb(struct mg_connection *nc, union socket_address *sa, size_t sa_len)
struct mg_connection * mg_if_accept_new_conn(struct mg_connection *lc)
void mg_sock_set(struct mg_connection *nc, sock_t sock)
struct sockaddr sa
Definition mongoose6.h:1195
#define closesocket(s)
Definition melog.cxx:29
#define INVALID_SOCKET
#define DBG(x)
MG_INTERNAL int mg_get_errno(void)
char * inet_ntoa(struct in_addr n)
static int mg_is_error(void)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_add_conn()

MG_INTERNAL void mg_add_conn ( struct mg_mgr mgr,
struct mg_connection c 
)

Definition at line 2415 of file mongoose614.cxx.

2415 {
2416 DBG(("%p %p", mgr, c));
2417 c->mgr = mgr;
2418 c->next = mgr->active_connections;
2419 mgr->active_connections = c;
2420 c->prev = NULL;
2421 if (c->next != NULL) c->next->prev = c;
2422 if (c->sock != INVALID_SOCKET) {
2423 c->iface->vtable->add_conn(c);
2424 }
2425}
struct mg_connection * active_connections
Definition mongoose6.h:1231
struct mg_connection * next
Definition mongoose6.h:1247
struct mg_connection * prev
Definition mongoose6.h:1247
struct mg_iface * iface
void(* add_conn)(struct mg_connection *nc)
const struct mg_iface_vtable * vtable
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_CB(mg_event_handler_t callback, void *user_data)   
)

Definition at line 3555 of file mongoose614.cxx.

3557 {
3558 struct mg_add_sock_opts opts;
3559 memset(&opts, 0, sizeof(opts));
3560 return mg_add_sock_opt(s, sock, MG_CB(callback, user_data), opts);
3561}
struct mg_connection * mg_add_sock_opt(struct mg_mgr *s, sock_t sock, MG_CB(mg_event_handler_t callback, void *user_data), struct mg_add_sock_opts opts)
#define MG_CB(cb, ud)
struct callback_addr callback
Definition mserver.cxx:22
Here is the call graph for this function:

◆ mg_add_sock_opt()

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

Definition at line 3539 of file mongoose614.cxx.

3542 {
3543#if MG_ENABLE_CALLBACK_USERDATA
3544 opts.user_data = user_data;
3545#endif
3546
3548 if (nc != NULL) {
3549 mg_sock_set(nc, sock);
3550 mg_add_conn(nc->mgr, nc);
3551 }
3552 return nc;
3553}
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_add_to_set()

void mg_add_to_set ( sock_t  sock,
fd_set set,
sock_t max_fd 
)

Definition at line 4146 of file mongoose614.cxx.

4146 {
4147 if (sock != INVALID_SOCKET
4149 && sock < (sock_t) FD_SETSIZE
4150#endif
4151 ) {
4152 FD_SET(sock, set);
4153 if (*max_fd == INVALID_SOCKET || sock > *max_fd) {
4154 *max_fd = sock;
4155 }
4156 }
4157}
#define FD_SETSIZE
Definition msystem.h:199
#define set(var, value)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_asprintf()

int mg_asprintf ( char **  buf,
size_t  size,
const char fmt,
  ... 
)

Definition at line 2203 of file mongoose614.cxx.

2203 {
2204 int ret;
2205 va_list ap;
2206 va_start(ap, fmt);
2207 ret = mg_avprintf(buf, size, fmt, ap);
2208 va_end(ap);
2209 return ret;
2210}
int mg_avprintf(char **buf, size_t size, const char *fmt, va_list ap) WEAK

◆ mg_assemble_uri()

int mg_assemble_uri ( const struct mg_str scheme,
const struct mg_str user_info,
const struct mg_str host,
unsigned int  port,
const struct mg_str path,
const struct mg_str query,
const struct mg_str fragment,
int  normalize_path,
struct mg_str uri 
)

Definition at line 5751 of file mongoose614.cxx.

5755 {
5756 int result = -1;
5757 struct mbuf out;
5758 mbuf_init(&out, 0);
5759
5760 if (scheme != NULL && scheme->len > 0) {
5761 mbuf_append(&out, scheme->p, scheme->len);
5762 mbuf_append(&out, "://", 3);
5763 }
5764
5765 if (user_info != NULL && user_info->len > 0) {
5766 mbuf_append(&out, user_info->p, user_info->len);
5767 mbuf_append(&out, "@", 1);
5768 }
5769
5770 if (host != NULL && host->len > 0) {
5771 mbuf_append(&out, host->p, host->len);
5772 }
5773
5774 if (port != 0) {
5775 char port_str[20];
5776 int port_str_len = sprintf(port_str, ":%u", port);
5778 }
5779
5780 if (path != NULL && path->len > 0) {
5781 if (normalize_path) {
5782 struct mg_str npath = mg_strdup(*path);
5783 if (npath.len != path->len) goto out;
5784 if (!mg_normalize_uri_path(path, &npath)) {
5785 free((void *) npath.p);
5786 goto out;
5787 }
5788 mbuf_append(&out, npath.p, npath.len);
5789 free((void *) npath.p);
5790 } else {
5791 mbuf_append(&out, path->p, path->len);
5792 }
5793 } else if (normalize_path) {
5794 mbuf_append(&out, "/", 1);
5795 }
5796
5797 if (query != NULL && query->len > 0) {
5798 mbuf_append(&out, "?", 1);
5799 mbuf_append(&out, query->p, query->len);
5800 }
5801
5802 if (fragment != NULL && fragment->len > 0) {
5803 mbuf_append(&out, "#", 1);
5804 mbuf_append(&out, fragment->p, fragment->len);
5805 }
5806
5807 result = 0;
5808
5809out:
5810 if (result == 0) {
5811 uri->p = out.buf;
5812 uri->len = out.len;
5813 } else {
5814 mbuf_free(&out);
5815 uri->p = NULL;
5816 uri->len = 0;
5817 }
5818 return result;
5819}
int mg_normalize_uri_path(const struct mg_str *in, struct mg_str *out)
void mbuf_free(struct mbuf *mbuf) WEAK
size_t len
Definition mongoose6.h:1207
void mbuf_init(struct mbuf *mbuf, size_t initial_size) WEAK
size_t mbuf_append(struct mbuf *a, const void *buf, size_t len) WEAK
const char * p
Definition mongoose6.h:1206
struct mg_str mg_strdup(const struct mg_str s) WEAK

◆ mg_basic_auth_header()

void mg_basic_auth_header ( const struct mg_str  user,
const struct mg_str  pass,
struct mbuf buf 
)

Definition at line 10750 of file mongoose614.cxx.

10751 {
10752 const char *header_prefix = "Authorization: Basic ";
10753 const char *header_suffix = "\r\n";
10754
10755 struct cs_base64_ctx ctx;
10757
10759
10760 cs_base64_update(&ctx, user.p, user.len);
10761 if (pass.len > 0) {
10762 cs_base64_update(&ctx, ":", 1);
10763 cs_base64_update(&ctx, pass.p, pass.len);
10764 }
10765 cs_base64_finish(&ctx);
10767}
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_init(struct cs_base64_ctx *ctx, cs_base64_putc_t b64_putc, void *user_data)
void mg_mbuf_append_base64_putc(char ch, void *user_data)

◆ mg_bind()

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

Definition at line 3346 of file mongoose614.cxx.

3348 {
3349 struct mg_bind_opts opts;
3350 memset(&opts, 0, sizeof(opts));
3351 return mg_bind_opt(srv, address, MG_CB(event_handler, user_data), opts);
3352}
void * user_data
Definition mongoose6.h:1396
struct mg_connection * mg_bind_opt(struct mg_mgr *mgr, const char *address, MG_CB(mg_event_handler_t callback, void *user_data), 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_CB(mg_event_handler_t callback, void *user_data)  ,
struct mg_bind_opts  opts 
)

Definition at line 3354 of file mongoose614.cxx.

3357 {
3358 union socket_address sa;
3359 struct mg_connection *nc = NULL;
3360 int proto, rc;
3362 char host[MG_MAX_HOST_LEN];
3363
3364#if MG_ENABLE_CALLBACK_USERDATA
3366#endif
3367
3368 if (callback == NULL) {
3369 MG_SET_PTRPTR(opts.error_string, "handler is required");
3370 return NULL;
3371 }
3372
3374
3375 if (mg_parse_address(address, &sa, &proto, host, sizeof(host)) <= 0) {
3376 MG_SET_PTRPTR(opts.error_string, "cannot parse address");
3377 return NULL;
3378 }
3379
3381 if (nc == NULL) {
3382 return NULL;
3383 }
3384
3385 nc->sa = sa;
3386 nc->flags |= MG_F_LISTENING;
3387 if (proto == SOCK_DGRAM) nc->flags |= MG_F_UDP;
3388
3389#if MG_ENABLE_SSL
3390 DBG(("%p %s %s,%s,%s", nc, address, (opts.ssl_cert ? opts.ssl_cert : "-"),
3391 (opts.ssl_key ? opts.ssl_key : "-"),
3392 (opts.ssl_ca_cert ? opts.ssl_ca_cert : "-")));
3393
3394 if (opts.ssl_cert != NULL || opts.ssl_ca_cert != NULL) {
3395 const char *err_msg = NULL;
3396 struct mg_ssl_if_conn_params params;
3397 if (nc->flags & MG_F_UDP) {
3398 MG_SET_PTRPTR(opts.error_string, "SSL for UDP is not supported");
3399 mg_destroy_conn(nc, 1 /* destroy_if */);
3400 return NULL;
3401 }
3402 memset(&params, 0, sizeof(params));
3403 params.cert = opts.ssl_cert;
3404 params.key = opts.ssl_key;
3405 params.ca_cert = opts.ssl_ca_cert;
3406 params.cipher_suites = opts.ssl_cipher_suites;
3407 if (mg_ssl_if_conn_init(nc, &params, &err_msg) != MG_SSL_OK) {
3408 MG_SET_PTRPTR(opts.error_string, err_msg);
3409 mg_destroy_conn(nc, 1 /* destroy_if */);
3410 return NULL;
3411 }
3412 nc->flags |= MG_F_SSL;
3413 }
3414#endif /* MG_ENABLE_SSL */
3415
3416 if (nc->flags & MG_F_UDP) {
3417 rc = nc->iface->vtable->listen_udp(nc, &nc->sa);
3418 } else {
3419 rc = nc->iface->vtable->listen_tcp(nc, &nc->sa);
3420 }
3421 if (rc != 0) {
3422 DBG(("Failed to open listener: %d", rc));
3423 MG_SET_PTRPTR(opts.error_string, "failed to open listener");
3424 mg_destroy_conn(nc, 1 /* destroy_if */);
3425 return NULL;
3426 }
3427 mg_add_conn(nc->mgr, nc);
3428
3429 return nc;
3430}
union socket_address sa
Definition mongoose6.h:1253
#define MG_F_LISTENING
Definition mongoose6.h:1278
#define MG_F_UDP
Definition mongoose6.h:1279
unsigned long flags
Definition mongoose6.h:1276
#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)
#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)
void mg_destroy_conn(struct mg_connection *conn, int destroy_if)
#define MG_F_SSL
int(* listen_tcp)(struct mg_connection *nc, union socket_address *sa)
int(* listen_udp)(struct mg_connection *nc, union socket_address *sa)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_call()

MG_INTERNAL void mg_call ( struct mg_connection nc,
mg_event_handler_t  ev_handler,
void user_data,
int  ev,
void ev_data 
)

Definition at line 2435 of file mongoose614.cxx.

2437 {
2438 if (ev_handler == NULL) {
2439 /*
2440 * If protocol handler is specified, call it. Otherwise, call user-specified
2441 * event handler.
2442 */
2444 }
2445 if (ev != MG_EV_POLL) {
2446 DBG(("%p %s ev=%d ev_data=%p flags=0x%lx rmbl=%d smbl=%d", nc,
2447 ev_handler == nc->handler ? "user" : "proto", ev, ev_data, nc->flags,
2448 (int) nc->recv_mbuf.len, (int) nc->send_mbuf.len));
2449 }
2450
2451#if !defined(NO_LIBC) && MG_ENABLE_HEXDUMP
2452 if (nc->mgr->hexdump_file != NULL && ev != MG_EV_POLL && ev != MG_EV_RECV &&
2453 ev != MG_EV_SEND /* handled separately */) {
2455 }
2456#endif
2457 if (ev_handler != NULL) {
2458 unsigned long flags_before = nc->flags;
2459 ev_handler(nc, ev, ev_data MG_UD_ARG(user_data));
2460 /* Prevent user handler from fiddling with system flags. */
2461 if (ev_handler == nc->handler && nc->flags != flags_before) {
2464 }
2465 }
2466 if (ev != MG_EV_POLL) nc->mgr->num_calls++;
2467 if (ev != MG_EV_POLL) {
2468 DBG(("%p after %s flags=0x%lx rmbl=%d smbl=%d", nc,
2469 ev_handler == nc->handler ? "user" : "proto", nc->flags,
2470 (int) nc->recv_mbuf.len, (int) nc->send_mbuf.len));
2471 }
2472#if !MG_ENABLE_CALLBACK_USERDATA
2473 (void) user_data;
2474#endif
2475}
const char * hexdump_file
Definition mongoose6.h:1232
mg_event_handler_t handler
Definition mongoose6.h:1264
#define MG_EV_RECV
Definition mongoose6.h:1222
void mg_hexdump_connection(struct mg_connection *nc, const char *path, const void *buf, int num_bytes, int ev)
#define MG_EV_POLL
Definition mongoose6.h:1219
#define MG_EV_SEND
Definition mongoose6.h:1223
mg_event_handler_t proto_handler
Definition mongoose6.h:1261
#define _MG_CALLBACK_MODIFIABLE_FLAGS_MASK
#define MG_UD_ARG(ud)
int num_calls
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_connect()

struct mg_connection * mg_connect ( struct mg_mgr mgr,
const char address,
MG_CB(mg_event_handler_t callback, void *user_data)   
)

Definition at line 3236 of file mongoose614.cxx.

3238 {
3239 struct mg_connect_opts opts;
3240 memset(&opts, 0, sizeof(opts));
3241 return mg_connect_opt(mgr, address, MG_CB(callback, user_data), opts);
3242}
struct mg_connection * mg_connect_opt(struct mg_mgr *mgr, const char *address, MG_CB(mg_event_handler_t callback, void *user_data), struct mg_connect_opts opts)
Here is the call graph for this function:

◆ mg_connect_opt()

struct mg_connection * mg_connect_opt ( struct mg_mgr mgr,
const char address,
MG_CB(mg_event_handler_t callback, void *user_data)  ,
struct mg_connect_opts  opts 
)

Definition at line 3244 of file mongoose614.cxx.

3247 {
3248 struct mg_connection *nc = NULL;
3249 int proto, rc;
3251 char host[MG_MAX_HOST_LEN];
3252
3254
3255 if ((nc = mg_create_connection(mgr, callback, add_sock_opts)) == NULL) {
3256 return NULL;
3257 }
3258
3259 if ((rc = mg_parse_address(address, &nc->sa, &proto, host, sizeof(host))) <
3260 0) {
3261 /* Address is malformed */
3262 MG_SET_PTRPTR(opts.error_string, "cannot parse address");
3263 mg_destroy_conn(nc, 1 /* destroy_if */);
3264 return NULL;
3265 }
3266
3268 nc->flags |= (proto == SOCK_DGRAM) ? MG_F_UDP : 0;
3269#if MG_ENABLE_CALLBACK_USERDATA
3270 nc->user_data = user_data;
3271#else
3272 nc->user_data = opts.user_data;
3273#endif
3274
3275#if MG_ENABLE_SSL
3276 LOG(LL_DEBUG,
3277 ("%p %s %s,%s,%s", nc, address, (opts.ssl_cert ? opts.ssl_cert : "-"),
3278 (opts.ssl_key ? opts.ssl_key : "-"),
3279 (opts.ssl_ca_cert ? opts.ssl_ca_cert : "-")));
3280
3281 if (opts.ssl_cert != NULL || opts.ssl_ca_cert != NULL ||
3282 opts.ssl_psk_identity != NULL) {
3283 const char *err_msg = NULL;
3284 struct mg_ssl_if_conn_params params;
3285 if (nc->flags & MG_F_UDP) {
3286 MG_SET_PTRPTR(opts.error_string, "SSL for UDP is not supported");
3287 mg_destroy_conn(nc, 1 /* destroy_if */);
3288 return NULL;
3289 }
3290 memset(&params, 0, sizeof(params));
3291 params.cert = opts.ssl_cert;
3292 params.key = opts.ssl_key;
3293 params.ca_cert = opts.ssl_ca_cert;
3294 params.cipher_suites = opts.ssl_cipher_suites;
3295 params.psk_identity = opts.ssl_psk_identity;
3296 params.psk_key = opts.ssl_psk_key;
3297 if (opts.ssl_ca_cert != NULL) {
3298 if (opts.ssl_server_name != NULL) {
3299 if (strcmp(opts.ssl_server_name, "*") != 0) {
3300 params.server_name = opts.ssl_server_name;
3301 }
3302 } else if (rc == 0) { /* If it's a DNS name, use host. */
3303 params.server_name = host;
3304 }
3305 }
3306 if (mg_ssl_if_conn_init(nc, &params, &err_msg) != MG_SSL_OK) {
3307 MG_SET_PTRPTR(opts.error_string, err_msg);
3308 mg_destroy_conn(nc, 1 /* destroy_if */);
3309 return NULL;
3310 }
3311 nc->flags |= MG_F_SSL;
3312 }
3313#endif /* MG_ENABLE_SSL */
3314
3315 if (rc == 0) {
3316#if MG_ENABLE_ASYNC_RESOLVER
3317 /*
3318 * DNS resolution is required for host.
3319 * mg_parse_address() fills port in nc->sa, which we pass to resolve_cb()
3320 */
3321 struct mg_connection *dns_conn = NULL;
3322 struct mg_resolve_async_opts o;
3323 memset(&o, 0, sizeof(o));
3324 o.dns_conn = &dns_conn;
3325 o.nameserver = opts.nameserver;
3327 o) != 0) {
3328 MG_SET_PTRPTR(opts.error_string, "cannot schedule DNS lookup");
3329 mg_destroy_conn(nc, 1 /* destroy_if */);
3330 return NULL;
3331 }
3332 nc->priv_2 = dns_conn;
3333 nc->flags |= MG_F_RESOLVING;
3334 return nc;
3335#else
3336 MG_SET_PTRPTR(opts.error_string, "Resolver is disabled");
3337 mg_destroy_conn(nc, 1 /* destroy_if */);
3338 return NULL;
3339#endif
3340 } else {
3341 /* Address is parsed and resolved to IP. proceed with connect() */
3342 return mg_do_connect(nc, proto, &nc->sa);
3343 }
3344}
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
#define LOG(l, x)
#define _MG_ALLOWED_CONNECT_FLAGS_MASK
MG_INTERNAL struct mg_connection * mg_do_connect(struct mg_connection *nc, int proto, union socket_address *sa)
static void resolve_cb(struct mg_dns_message *msg, void *data, enum mg_resolve_err e)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_create_connection()

MG_INTERNAL struct mg_connection * mg_create_connection ( struct mg_mgr mgr,
mg_event_handler_t  callback,
struct mg_add_sock_opts  opts 
)

Definition at line 2758 of file mongoose614.cxx.

2760 {
2762
2763 if (conn != NULL && !conn->iface->vtable->create_conn(conn)) {
2764 MG_FREE(conn);
2765 conn = NULL;
2766 }
2767 if (conn == NULL) {
2768 MG_SET_PTRPTR(opts.error_string, "failed to init connection");
2769 }
2770
2771 return conn;
2772}
#define MG_FREE
int(* create_conn)(struct mg_connection *nc)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_create_connection_base()

MG_INTERNAL struct mg_connection * mg_create_connection_base ( struct mg_mgr mgr,
mg_event_handler_t  callback,
struct mg_add_sock_opts  opts 
)

Definition at line 2731 of file mongoose614.cxx.

2733 {
2734 struct mg_connection *conn;
2735
2736 if ((conn = (struct mg_connection *) MG_CALLOC(1, sizeof(*conn))) != NULL) {
2737 conn->sock = INVALID_SOCKET;
2738 conn->handler = callback;
2739 conn->mgr = mgr;
2740 conn->last_io_time = (time_t) mg_time();
2741 conn->iface =
2742 (opts.iface != NULL ? opts.iface : mgr->ifaces[MG_MAIN_IFACE]);
2744 conn->user_data = opts.user_data;
2745 /*
2746 * SIZE_MAX is defined as a long long constant in
2747 * system headers on some platforms and so it
2748 * doesn't compile with pedantic ansi flags.
2749 */
2750 conn->recv_mbuf_limit = ~0;
2751 } else {
2752 MG_SET_PTRPTR(opts.error_string, "failed to create connection");
2753 }
2754
2755 return conn;
2756}
double mg_time(void)
time_t last_io_time
Definition mongoose6.h:1259
size_t recv_mbuf_limit
Definition mongoose6.h:1254
#define MG_CALLOC
#define MG_MAIN_IFACE
struct mg_iface ** ifaces
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_destroy_conn()

void mg_destroy_conn ( struct mg_connection conn,
int  destroy_if 
)

Definition at line 2528 of file mongoose614.cxx.

2528 {
2529 if (conn->sock != INVALID_SOCKET) { /* Don't print timer-only conns */
2530 LOG(LL_DEBUG, ("%p 0x%lx %d", conn, conn->flags, destroy_if));
2531 }
2532 if (destroy_if) conn->iface->vtable->destroy_conn(conn);
2533 if (conn->proto_data != NULL && conn->proto_data_destructor != NULL) {
2534 conn->proto_data_destructor(conn->proto_data);
2535 }
2536#if MG_ENABLE_SSL
2537 mg_ssl_if_conn_free(conn);
2538#endif
2539 mbuf_free(&conn->recv_mbuf);
2540 mbuf_free(&conn->send_mbuf);
2541
2542 memset(conn, 0, sizeof(*conn));
2543 MG_FREE(conn);
2544}
void(* proto_data_destructor)(void *proto_data)
Definition mongoose6.h:1263
void * proto_data
Definition mongoose6.h:1262
struct mbuf send_mbuf
Definition mongoose6.h:1256
struct mbuf recv_mbuf
Definition mongoose6.h:1255
void(* destroy_conn)(struct mg_connection *nc)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_do_connect()

MG_INTERNAL struct mg_connection * mg_do_connect ( struct mg_connection nc,
int  proto,
union socket_address sa 
)

Definition at line 3155 of file mongoose614.cxx.

3157 {
3158 LOG(LL_DEBUG, ("%p %s://%s:%hu", nc, proto == SOCK_DGRAM ? "udp" : "tcp",
3159 inet_ntoa(sa->sin.sin_addr), ntohs(sa->sin.sin_port)));
3160
3161 nc->flags |= MG_F_CONNECTING;
3162 if (proto == SOCK_DGRAM) {
3163 nc->iface->vtable->connect_udp(nc);
3164 } else {
3165 nc->iface->vtable->connect_tcp(nc, sa);
3166 }
3167 mg_add_conn(nc->mgr, nc);
3168 return nc;
3169}
#define MG_F_CONNECTING
Definition mongoose6.h:1281
void(* connect_tcp)(struct mg_connection *nc, const union socket_address *sa)
void(* connect_udp)(struct mg_connection *nc)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_do_recv()

static int mg_do_recv ( struct mg_connection nc)
static

Definition at line 2940 of file mongoose614.cxx.

2940 {
2941 int res = 0;
2942 char *buf = NULL;
2943 size_t len = (nc->flags & MG_F_UDP ? MG_UDP_IO_SIZE : MG_TCP_IO_SIZE);
2945 ((nc->flags & MG_F_LISTENING) && !(nc->flags & MG_F_UDP))) {
2946 return -1;
2947 }
2948 do {
2949 len = recv_avail_size(nc, len);
2950 if (len == 0) {
2951 res = -2;
2952 break;
2953 }
2954 if (nc->recv_mbuf.size < nc->recv_mbuf.len + len) {
2955 mbuf_resize(&nc->recv_mbuf, nc->recv_mbuf.len + len);
2956 }
2957 buf = nc->recv_mbuf.buf + nc->recv_mbuf.len;
2958 len = nc->recv_mbuf.size - nc->recv_mbuf.len;
2959 if (nc->flags & MG_F_UDP) {
2960 res = mg_recv_udp(nc, buf, len);
2961 } else {
2962 res = mg_recv_tcp(nc, buf, len);
2963 }
2964 } while (res > 0 && !(nc->flags & (MG_F_CLOSE_IMMEDIATELY | MG_F_UDP)));
2965 return res;
2966}
void mbuf_resize(struct mbuf *a, size_t new_size) WEAK
#define MG_UDP_IO_SIZE
MG_INTERNAL size_t recv_avail_size(struct mg_connection *conn, size_t max)
static int mg_recv_tcp(struct mg_connection *nc, char *buf, size_t len)
#define MG_TCP_IO_SIZE
static int mg_recv_udp(struct mg_connection *nc, char *buf, size_t len)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_ev_mgr_lwip_process_signals()

void mg_ev_mgr_lwip_process_signals ( struct mg_mgr mgr)

Definition at line 15962 of file mongoose614.cxx.

15962 {
15963 struct mg_ev_mgr_lwip_data *md =
15964 (struct mg_ev_mgr_lwip_data *) mgr->ifaces[MG_MAIN_IFACE]->data;
15965 while (md->sig_queue_len > 0) {
15966 mgos_lock();
15967 int i = md->start_index;
15968 int sig = md->sig_queue[i].sig;
15969 struct mg_connection *nc = md->sig_queue[i].nc;
15970 struct mg_lwip_conn_state *cs = (struct mg_lwip_conn_state *) nc->sock;
15971 md->start_index = (i + 1) % MG_SIG_QUEUE_LEN;
15972 md->sig_queue_len--;
15973 mgos_unlock();
15974 if (nc->iface == NULL || nc->mgr == NULL) continue;
15975 switch (sig) {
15976 case MG_SIG_CONNECT_RESULT: {
15978 break;
15979 }
15980 case MG_SIG_CLOSE_CONN: {
15982 break;
15983 }
15984 case MG_SIG_RECV: {
15985 cs->recv_pending = 0;
15988 break;
15989 }
15990 case MG_SIG_TOMBSTONE: {
15991 break;
15992 }
15993 case MG_SIG_ACCEPT: {
15995 break;
15996 }
15997 }
15998 }
15999}
void mg_if_connect_cb(struct mg_connection *nc, int err)
void mbuf_trim(struct mbuf *mbuf) WEAK
MG_INTERNAL void mg_close_conn(struct mg_connection *conn)
void mg_lwip_handle_accept(struct mg_connection *nc)
void mg_if_can_recv_cb(struct mg_connection *nc)
#define MG_SIG_QUEUE_LEN
#define mgos_lock()
#define mgos_unlock()
void * data
struct mg_connection * nc
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_find_iface()

struct mg_iface * mg_find_iface ( struct mg_mgr mgr,
const struct mg_iface_vtable vtable,
struct mg_iface from 
)

Definition at line 3643 of file mongoose614.cxx.

3645 {
3646 int i = 0;
3647 if (from != NULL) {
3648 for (i = 0; i < mgr->num_ifaces; i++) {
3649 if (mgr->ifaces[i] == from) {
3650 i++;
3651 break;
3652 }
3653 }
3654 }
3655
3656 for (; i < mgr->num_ifaces; i++) {
3657 if (mgr->ifaces[i]->vtable == vtable) {
3658 return mgr->ifaces[i];
3659 }
3660 }
3661 return NULL;
3662}
int num_ifaces

◆ mg_forward()

void mg_forward ( struct mg_connection from,
struct mg_connection to 
)

Definition at line 3507 of file mongoose614.cxx.

3507 {
3508 mg_send(to, from->recv_mbuf.buf, from->recv_mbuf.len);
3509 mbuf_remove(&from->recv_mbuf, from->recv_mbuf.len);
3510}
void mbuf_remove(struct mbuf *mb, size_t n) WEAK
void mg_send(struct mg_connection *nc, const void *buf, int len)
Here is the call graph for this function:

◆ mg_get_errno()

DO_NOT_WARN_UNUSED MG_INTERNAL int mg_get_errno ( void  )

Definition at line 10729 of file mongoose614.cxx.

10729 {
10730#ifndef WINCE
10731 return errno;
10732#else
10733 /* TODO(alashkin): translate error codes? */
10734 return GetLastError();
10735#endif
10736}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_handle_recv()

static void mg_handle_recv ( struct mg_connection nc)
static

Definition at line 16386 of file mongoose614.cxx.

16386 {
16387 uint16_t bytes_read = 0;
16388 uint8_t *buf = NULL;
16389 if (nc->flags & MG_F_UDP) {
16390 bytes_read = TCPIP_UDP_GetIsReady((UDP_SOCKET) nc->sock);
16391 if (bytes_read != 0 &&
16392 (nc->recv_mbuf_limit == -1 ||
16393 nc->recv_mbuf.len + bytes_read < nc->recv_mbuf_limit)) {
16394 buf = (uint8_t *) MG_MALLOC(bytes_read);
16395 if (TCPIP_UDP_ArrayGet((UDP_SOCKET) nc->sock, buf, bytes_read) !=
16396 bytes_read) {
16398 bytes_read = 0;
16399 MG_FREE(buf);
16400 }
16401 }
16402 } else {
16403 bytes_read = TCPIP_TCP_GetIsReady((TCP_SOCKET) nc->sock);
16404 if (bytes_read != 0) {
16405 if (nc->recv_mbuf_limit != -1 &&
16406 nc->recv_mbuf_limit - nc->recv_mbuf.len > bytes_read) {
16407 bytes_read = nc->recv_mbuf_limit - nc->recv_mbuf.len;
16408 }
16409 buf = (uint8_t *) MG_MALLOC(bytes_read);
16410 if (TCPIP_TCP_ArrayGet((TCP_SOCKET) nc->sock, buf, bytes_read) !=
16411 bytes_read) {
16413 MG_FREE(buf);
16414 bytes_read = 0;
16415 }
16416 }
16417 }
16418
16419 if (bytes_read != 0) {
16420 mg_if_recv_tcp_cb(nc, buf, bytes_read, 1 /* own */);
16421 }
16422}
void mg_if_recv_tcp_cb(struct mg_connection *nc, void *buf, int len)
#define MG_MALLOC
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_handle_send()

static void mg_handle_send ( struct mg_connection nc)
static

Definition at line 16348 of file mongoose614.cxx.

16348 {
16349 uint16_t bytes_written = 0;
16350 if (nc->flags & MG_F_UDP) {
16352 (UDP_SOCKET) nc->sock,
16353 nc->sa.sin.sin_family == AF_INET ? IP_ADDRESS_TYPE_IPV4
16355 ntohs(nc->sa.sin.sin_port), (IP_MULTI_ADDRESS *) &nc->sa.sin)) {
16357 return;
16358 }
16359 bytes_written = TCPIP_UDP_TxPutIsReady((UDP_SOCKET) nc->sock, 0);
16360 if (bytes_written >= nc->send_mbuf.len) {
16362 (uint8_t *) nc->send_mbuf.buf,
16363 nc->send_mbuf.len) != nc->send_mbuf.len) {
16365 bytes_written = 0;
16366 }
16367 }
16368 } else {
16369 bytes_written = TCPIP_TCP_FifoTxFreeGet((TCP_SOCKET) nc->sock);
16370 if (bytes_written != 0) {
16371 if (bytes_written > nc->send_mbuf.len) {
16372 bytes_written = nc->send_mbuf.len;
16373 }
16375 (uint8_t *) nc->send_mbuf.buf,
16376 bytes_written) != bytes_written) {
16378 bytes_written = 0;
16379 }
16380 }
16381 }
16382
16383 mg_if_sent_cb(nc, bytes_written);
16384}
void mg_if_sent_cb(struct mg_connection *nc, int num_sent)
struct sockaddr_in sin
Definition mongoose6.h:1196
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_if_can_recv_cb()

void mg_if_can_recv_cb ( struct mg_connection nc)

Definition at line 2968 of file mongoose614.cxx.

2968 {
2969 mg_do_recv(nc);
2970}
static int mg_do_recv(struct mg_connection *nc)
Here is the caller graph for this function:

◆ mg_if_can_send_cb()

void mg_if_can_send_cb ( struct mg_connection nc)

Definition at line 3091 of file mongoose614.cxx.

3091 {
3092 int n = 0;
3093 const char *buf = nc->send_mbuf.buf;
3094 size_t len = nc->send_mbuf.len;
3095
3097 return;
3098 }
3099 if (!(nc->flags & MG_F_UDP)) {
3100 if (nc->flags & MG_F_LISTENING) return;
3101 if (len > MG_TCP_IO_SIZE) len = MG_TCP_IO_SIZE;
3102 }
3103#if MG_ENABLE_SSL
3104 if (nc->flags & MG_F_SSL) {
3105 if (nc->flags & MG_F_SSL_HANDSHAKE_DONE) {
3106 if (len > 0) {
3107 n = mg_ssl_if_write(nc, buf, len);
3108 DBG(("%p -> %d bytes (SSL)", nc, n));
3109 }
3110 if (n < 0) {
3111 if (n == MG_SSL_WANT_WRITE) {
3112 nc->flags |= MG_F_WANT_WRITE;
3113 n = 0;
3114 } else {
3116 }
3117 } else {
3118 nc->flags &= ~MG_F_WANT_WRITE;
3119 }
3120 } else {
3121 mg_ssl_handshake(nc);
3122 }
3123 } else
3124#endif
3125 if (len > 0) {
3126 if (nc->flags & MG_F_UDP) {
3127 n = nc->iface->vtable->udp_send(nc, buf, len);
3128 } else {
3129 n = nc->iface->vtable->tcp_send(nc, buf, len);
3130 }
3131 DBG(("%p -> %d bytes", nc, n));
3132 }
3133
3134#if !defined(NO_LIBC) && MG_ENABLE_HEXDUMP
3135 if (n > 0 && nc->mgr && nc->mgr->hexdump_file != NULL) {
3137 }
3138#endif
3139 if (n < 0) {
3141 } else if (n > 0) {
3142 nc->last_io_time = (time_t) mg_time();
3143 mbuf_remove(&nc->send_mbuf, n);
3144 mbuf_trim(&nc->send_mbuf);
3145 }
3146 if (n != 0) mg_call(nc, NULL, nc->user_data, MG_EV_SEND, &n);
3147}
#define MG_F_SSL_HANDSHAKE_DONE
Definition mongoose6.h:1282
#define MG_F_WANT_WRITE
Definition mongoose6.h:1284
MG_INTERNAL void mg_call(struct mg_connection *nc, mg_event_handler_t ev_handler, void *user_data, int ev, void *ev_data)
int(* udp_send)(struct mg_connection *nc, const void *buf, size_t len)
int(* tcp_send)(struct mg_connection *nc, const void *buf, size_t len)
Here is the caller graph for this function:

◆ mg_if_create_iface()

struct mg_iface * mg_if_create_iface ( const struct mg_iface_vtable vtable,
struct mg_mgr mgr 
)

Definition at line 3634 of file mongoose614.cxx.

3635 {
3636 struct mg_iface *iface = (struct mg_iface *) MG_CALLOC(1, sizeof(*iface));
3637 iface->mgr = mgr;
3638 iface->data = NULL;
3639 iface->vtable = vtable;
3640 return iface;
3641}
struct mg_mgr * mgr
Here is the caller graph for this function:

◆ mg_if_poll()

int mg_if_poll ( struct mg_connection nc,
double  now 
)

Definition at line 2494 of file mongoose614.cxx.

2494 {
2495 if (nc->flags & MG_F_CLOSE_IMMEDIATELY) {
2496 mg_close_conn(nc);
2497 return 0;
2498 } else if (nc->flags & MG_F_SEND_AND_CLOSE) {
2499 if (nc->send_mbuf.len == 0) {
2501 mg_close_conn(nc);
2502 return 0;
2503 }
2504 } else if (nc->flags & MG_F_RECV_AND_CLOSE) {
2505 mg_close_conn(nc);
2506 return 0;
2507 }
2508#if MG_ENABLE_SSL
2509 if ((nc->flags & (MG_F_SSL | MG_F_LISTENING | MG_F_CONNECTING)) == MG_F_SSL) {
2510 /* SSL library may have data to be delivered to the app in its buffers,
2511 * drain them. */
2512 int recved = 0;
2513 do {
2514 if (nc->flags & (MG_F_WANT_READ | MG_F_WANT_WRITE)) break;
2515 if (recv_avail_size(nc, MG_TCP_IO_SIZE) <= 0) break;
2516 recved = mg_do_recv(nc);
2517 } while (recved > 0);
2518 }
2519#endif /* MG_ENABLE_SSL */
2520 mg_timer(nc, now);
2521 {
2522 time_t now_t = (time_t) now;
2523 mg_call(nc, NULL, nc->user_data, MG_EV_POLL, &now_t);
2524 }
2525 return 1;
2526}
#define MG_F_WANT_READ
Definition mongoose6.h:1283
MG_INTERNAL void mg_timer(struct mg_connection *c, double now)
#define MG_F_RECV_AND_CLOSE
Here is the caller graph for this function:

◆ mg_is_error() [1/2]

static int mg_is_error ( int  n)
static

Definition at line 14475 of file mongoose614.cxx.

14475 {
14476 return (n < 0 && n != SL_ERROR_BSD_EALREADY && n != SL_ERROR_BSD_EAGAIN);
14477}
Here is the call graph for this function:

◆ mg_is_error() [2/2]

static int mg_is_error ( void  )
static

Definition at line 3846 of file mongoose614.cxx.

3846 {
3847 int err = mg_get_errno();
3848 return err != EINPROGRESS && err != EWOULDBLOCK
3849#ifndef WINCE
3850 && err != EAGAIN && err != EINTR
3851#endif
3852#ifdef _WIN32
3854#endif
3855 ;
3856}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_lwip_accept_cb()

static err_t mg_lwip_accept_cb ( void arg,
struct tcp_pcb newtpcb,
err_t  err 
)
static

Definition at line 15547 of file mongoose614.cxx.

15547 {
15548 struct mg_connection *lc = (struct mg_connection *) arg, *nc;
15549 struct mg_lwip_conn_state *lcs, *cs;
15550 struct tcp_pcb_listen *lpcb;
15551 LOG(LL_DEBUG,
15552 ("%p conn %p from %s:%u", lc, newtpcb,
15553 IPADDR_NTOA(ipX_2_ip(&newtpcb->remote_ip)), newtpcb->remote_port));
15554 if (lc == NULL) {
15556 return ERR_ABRT;
15557 }
15558 lcs = (struct mg_lwip_conn_state *) lc->sock;
15559 lpcb = (struct tcp_pcb_listen *) lcs->pcb.tcp;
15560#if TCP_LISTEN_BACKLOG
15562#endif
15563 nc = mg_if_accept_new_conn(lc);
15564 if (nc == NULL) {
15566 return ERR_ABRT;
15567 }
15568 cs = (struct mg_lwip_conn_state *) nc->sock;
15569 cs->lc = lc;
15570 cs->pcb.tcp = newtpcb;
15571 /* We need to set up callbacks before returning because data may start
15572 * arriving immediately. */
15573 tcp_arg(newtpcb, nc);
15576 tcp_recv(newtpcb, mg_lwip_tcp_recv_cb);
15577#if LWIP_TCP_KEEPALIVE
15578 mg_lwip_set_keepalive_params(nc, 60, 10, 6);
15579#endif
15581 (void) err;
15582 (void) lpcb;
15583 return ERR_OK;
15584}
#define IPADDR_NTOA
static void mg_lwip_tcp_error_cb(void *arg, err_t err)
static err_t mg_lwip_tcp_sent_cb(void *arg, struct tcp_pcb *tpcb, u16_t num_sent)
static err_t mg_lwip_tcp_recv_cb(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err)
void mg_lwip_post_signal(enum mg_sig_type sig, struct mg_connection *nc)
struct mg_connection * lc
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_lwip_handle_accept()

void mg_lwip_handle_accept ( struct mg_connection nc)

Definition at line 15537 of file mongoose614.cxx.

15537 {
15538 struct mg_lwip_conn_state *cs = (struct mg_lwip_conn_state *) nc->sock;
15539 if (cs->pcb.tcp == NULL) return;
15540 union socket_address sa;
15541 struct tcp_pcb *tpcb = cs->pcb.tcp;
15542 SET_ADDR(&sa, &tpcb->remote_ip);
15543 sa.sin.sin_port = htons(tpcb->remote_port);
15544 mg_if_accept_tcp_cb(nc, &sa, sizeof(sa.sin));
15545}
#define SET_ADDR(dst, src)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_lwip_if_add_conn()

void mg_lwip_if_add_conn ( struct mg_connection nc)

Definition at line 16012 of file mongoose614.cxx.

16012 {
16013 (void) nc;
16014}
Here is the call graph for this function:

◆ mg_lwip_if_can_send()

static int mg_lwip_if_can_send ( struct mg_connection nc,
struct mg_lwip_conn_state cs 
)
static

Definition at line 15748 of file mongoose614.cxx.

15749 {
15750 int can_send = 0;
15751 if (nc->send_mbuf.len > 0 || (nc->flags & MG_F_WANT_WRITE)) {
15752 /* We have stuff to send, but can we? */
15753 if (nc->flags & MG_F_UDP) {
15754 /* UDP is always ready for sending. */
15755 can_send = (cs->pcb.udp != NULL);
15756 } else {
15757 can_send = (cs->pcb.tcp != NULL && cs->pcb.tcp->snd_buf > 0);
15758/* See comment above. */
15759#if CS_PLATFORM == CS_P_ESP8266
15760 if (cs->pcb.tcp->unacked != NULL) can_send = 0;
15761#endif
15762 }
15763 }
15764 return can_send;
15765}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_lwip_if_connect_tcp()

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

Definition at line 15434 of file mongoose614.cxx.

15435 {
15436 struct mg_lwip_if_connect_tcp_ctx ctx = {.nc = nc, .sa = sa};
15438}
static void mg_lwip_if_connect_tcp_tcpip(void *arg)
const union socket_address * sa
struct mg_connection * nc
Here is the call graph for this function:

◆ mg_lwip_if_connect_tcp_tcpip()

static void mg_lwip_if_connect_tcp_tcpip ( void arg)
static

Definition at line 15405 of file mongoose614.cxx.

15405 {
15406 struct mg_lwip_if_connect_tcp_ctx *ctx =
15407 (struct mg_lwip_if_connect_tcp_ctx *) arg;
15408 struct mg_connection *nc = ctx->nc;
15409 const union socket_address *sa = ctx->sa;
15410
15411 struct mg_lwip_conn_state *cs = (struct mg_lwip_conn_state *) nc->sock;
15412 struct tcp_pcb *tpcb = TCP_NEW();
15413 cs->pcb.tcp = tpcb;
15414 ip_addr_t *ip = (ip_addr_t *) &sa->sin.sin_addr.s_addr;
15415 u16_t port = ntohs(sa->sin.sin_port);
15416 tcp_arg(tpcb, nc);
15419 tcp_recv(tpcb, mg_lwip_tcp_recv_cb);
15420 cs->err = TCP_BIND(tpcb, IP_ADDR_ANY, 0 /* any port */);
15421 DBG(("%p tcp_bind = %d", nc, cs->err));
15422 if (cs->err != ERR_OK) {
15424 return;
15425 }
15426 cs->err = tcp_connect(tpcb, ip, port, mg_lwip_tcp_conn_cb);
15427 DBG(("%p tcp_connect %p = %d", nc, tpcb, cs->err));
15428 if (cs->err != ERR_OK) {
15430 return;
15431 }
15432}
#define TCP_NEW
static err_t mg_lwip_tcp_conn_cb(void *arg, struct tcp_pcb *tpcb, err_t err)
#define TCP_BIND
struct mg_context * ctx
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_lwip_if_connect_udp()

void mg_lwip_if_connect_udp ( struct mg_connection nc)

Definition at line 15529 of file mongoose614.cxx.

15529 {
15531}
static void mg_lwip_if_connect_udp_tcpip(void *arg)
Here is the call graph for this function:

◆ mg_lwip_if_connect_udp_tcpip()

static void mg_lwip_if_connect_udp_tcpip ( void arg)
static

Definition at line 15514 of file mongoose614.cxx.

15514 {
15515 struct mg_connection *nc = (struct mg_connection *) arg;
15516 struct mg_lwip_conn_state *cs = (struct mg_lwip_conn_state *) nc->sock;
15517 struct udp_pcb *upcb = udp_new();
15518 cs->err = UDP_BIND(upcb, IP_ADDR_ANY, 0 /* any port */);
15519 DBG(("%p udp_bind %p = %d", nc, upcb, cs->err));
15520 if (cs->err == ERR_OK) {
15521 udp_recv(upcb, mg_lwip_udp_recv_cb, nc);
15522 cs->pcb.udp = upcb;
15523 } else {
15524 udp_remove(upcb);
15525 }
15527}
#define UDP_BIND
static void mg_lwip_udp_recv_cb(void *arg, struct udp_pcb *pcb, struct pbuf *p, ip_addr_t *addr, u16_t port)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_lwip_if_create_conn()

int mg_lwip_if_create_conn ( struct mg_connection nc)

Definition at line 15808 of file mongoose614.cxx.

15808 {
15809 struct mg_lwip_conn_state *cs =
15810 (struct mg_lwip_conn_state *) MG_CALLOC(1, sizeof(*cs));
15811 if (cs == NULL) return 0;
15812 cs->nc = nc;
15813 nc->sock = (intptr_t) cs;
15814 return 1;
15815}
#define intptr_t
Here is the call graph for this function:

◆ mg_lwip_if_destroy_conn()

void mg_lwip_if_destroy_conn ( struct mg_connection nc)

Definition at line 15821 of file mongoose614.cxx.

15821 {
15822 if (nc->sock == INVALID_SOCKET) return;
15823 struct mg_lwip_conn_state *cs = (struct mg_lwip_conn_state *) nc->sock;
15824 if (!(nc->flags & MG_F_UDP)) {
15825 struct tcp_pcb *tpcb = cs->pcb.tcp;
15826 if (tpcb != NULL) {
15827 tcp_arg(tpcb, NULL);
15828 DBG(("%p tcp_close %p", nc, tpcb));
15829 tcp_arg(tpcb, NULL);
15831 }
15832 while (cs->rx_chain != NULL) {
15833 struct pbuf *seg = cs->rx_chain;
15834 cs->rx_chain = pbuf_dechain(cs->rx_chain);
15835 pbuf_free(seg);
15836 }
15837 memset(cs, 0, sizeof(*cs));
15838 MG_FREE(cs);
15839 } else if (nc->listener == NULL) {
15840 /* Only close outgoing UDP pcb or listeners. */
15841 struct udp_pcb *upcb = cs->pcb.udp;
15842 if (upcb != NULL) {
15843 DBG(("%p udp_remove %p", nc, upcb));
15845 }
15846 memset(cs, 0, sizeof(*cs));
15847 MG_FREE(cs);
15848 }
15849 nc->sock = INVALID_SOCKET;
15850}
struct mg_connection * listener
Definition mongoose6.h:1248
static void tcp_close_tcpip(void *arg)
static void udp_remove_tcpip(void *arg)
Here is the call graph for this function:

◆ mg_lwip_if_free()

void mg_lwip_if_free ( struct mg_iface iface)

Definition at line 16007 of file mongoose614.cxx.

16007 {
16008 MG_FREE(iface->data);
16009 iface->data = NULL;
16010}
Here is the call graph for this function:

◆ mg_lwip_if_get_conn_addr()

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

Definition at line 15852 of file mongoose614.cxx.

15853 {
15854 memset(sa, 0, sizeof(*sa));
15855 if (nc == NULL || nc->sock == INVALID_SOCKET) return;
15856 struct mg_lwip_conn_state *cs = (struct mg_lwip_conn_state *) nc->sock;
15857 if (nc->flags & MG_F_UDP) {
15858 struct udp_pcb *upcb = cs->pcb.udp;
15859 if (remote) {
15860 memcpy(sa, &nc->sa, sizeof(*sa));
15861 } else if (upcb != NULL) {
15862 sa->sin.sin_port = htons(upcb->local_port);
15863 SET_ADDR(sa, &upcb->local_ip);
15864 }
15865 } else {
15866 struct tcp_pcb *tpcb = cs->pcb.tcp;
15867 if (remote) {
15868 memcpy(sa, &nc->sa, sizeof(*sa));
15869 } else if (tpcb != NULL) {
15870 sa->sin.sin_port = htons(tpcb->local_port);
15871 SET_ADDR(sa, &tpcb->local_ip);
15872 }
15873 }
15874}
Here is the call graph for this function:

◆ mg_lwip_if_init()

void mg_lwip_if_init ( struct mg_iface iface)

Definition at line 16001 of file mongoose614.cxx.

16001 {
16002 LOG(LL_INFO, ("Mongoose %s, LwIP %u.%u.%u", MG_VERSION, LWIP_VERSION_MAJOR,
16004 iface->data = MG_CALLOC(1, sizeof(struct mg_ev_mgr_lwip_data));
16005}
#define MG_VERSION
Definition mongoose6.h:26
Here is the call graph for this function:

◆ mg_lwip_if_listen_tcp()

int mg_lwip_if_listen_tcp ( struct mg_connection nc,
union socket_address sa 
)

Definition at line 15614 of file mongoose614.cxx.

15614 {
15615 struct mg_lwip_if_listen_ctx ctx = {.nc = nc, .sa = sa};
15617 return ctx.ret;
15618}
static void mg_lwip_if_listen_tcp_tcpip(void *arg)
struct mg_connection * nc
union socket_address * sa
Here is the call graph for this function:

◆ mg_lwip_if_listen_tcp_tcpip()

static void mg_lwip_if_listen_tcp_tcpip ( void arg)
static

Definition at line 15592 of file mongoose614.cxx.

15592 {
15593 struct mg_lwip_if_listen_ctx *ctx = (struct mg_lwip_if_listen_ctx *) arg;
15594 struct mg_connection *nc = ctx->nc;
15595 union socket_address *sa = ctx->sa;
15596 struct mg_lwip_conn_state *cs = (struct mg_lwip_conn_state *) nc->sock;
15597 struct tcp_pcb *tpcb = TCP_NEW();
15598 ip_addr_t *ip = (ip_addr_t *) &sa->sin.sin_addr.s_addr;
15599 u16_t port = ntohs(sa->sin.sin_port);
15600 cs->err = TCP_BIND(tpcb, ip, port);
15601 DBG(("%p tcp_bind(%s:%u) = %d", nc, IPADDR_NTOA(ip), port, cs->err));
15602 if (cs->err != ERR_OK) {
15603 tcp_close(tpcb);
15604 ctx->ret = -1;
15605 return;
15606 }
15607 tcp_arg(tpcb, nc);
15608 tpcb = tcp_listen(tpcb);
15609 cs->pcb.tcp = tpcb;
15611 ctx->ret = 0;
15612}
static err_t mg_lwip_accept_cb(void *arg, struct tcp_pcb *newtpcb, err_t err)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_lwip_if_listen_udp()

int mg_lwip_if_listen_udp ( struct mg_connection nc,
union socket_address sa 
)

Definition at line 15640 of file mongoose614.cxx.

15640 {
15641 struct mg_lwip_if_listen_ctx ctx = {.nc = nc, .sa = sa};
15643 return ctx.ret;
15644}
static void mg_lwip_if_listen_udp_tcpip(void *arg)
Here is the call graph for this function:

◆ mg_lwip_if_listen_udp_tcpip()

static void mg_lwip_if_listen_udp_tcpip ( void arg)
static

Definition at line 15620 of file mongoose614.cxx.

15620 {
15621 struct mg_lwip_if_listen_ctx *ctx = (struct mg_lwip_if_listen_ctx *) arg;
15622 struct mg_connection *nc = ctx->nc;
15623 union socket_address *sa = ctx->sa;
15624 struct mg_lwip_conn_state *cs = (struct mg_lwip_conn_state *) nc->sock;
15625 struct udp_pcb *upcb = udp_new();
15626 ip_addr_t *ip = (ip_addr_t *) &sa->sin.sin_addr.s_addr;
15627 u16_t port = ntohs(sa->sin.sin_port);
15628 cs->err = UDP_BIND(upcb, ip, port);
15629 DBG(("%p udb_bind(%s:%u) = %d", nc, IPADDR_NTOA(ip), port, cs->err));
15630 if (cs->err != ERR_OK) {
15631 udp_remove(upcb);
15632 ctx->ret = -1;
15633 } else {
15634 udp_recv(upcb, mg_lwip_udp_recv_cb, nc);
15635 cs->pcb.udp = upcb;
15636 ctx->ret = 0;
15637 }
15638}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_lwip_if_poll()

time_t mg_lwip_if_poll ( struct mg_iface iface,
int  timeout_ms 
)

Definition at line 16027 of file mongoose614.cxx.

16027 {
16028 struct mg_mgr *mgr = iface->mgr;
16029 int n = 0;
16030 double now = mg_time();
16031 struct mg_connection *nc, *tmp;
16032 double min_timer = 0;
16033 int num_timers = 0;
16034#if 0
16035 DBG(("begin poll @%u", (unsigned int) (now * 1000)));
16036#endif
16038 for (nc = mgr->active_connections; nc != NULL; nc = tmp) {
16039 struct mg_lwip_conn_state *cs = (struct mg_lwip_conn_state *) nc->sock;
16040 tmp = nc->next;
16041 n++;
16042 if (!mg_if_poll(nc, now)) continue;
16043 if (nc->sock != INVALID_SOCKET &&
16044 !(nc->flags & (MG_F_UDP | MG_F_LISTENING)) && cs->pcb.tcp != NULL &&
16045 cs->pcb.tcp->unsent != NULL) {
16047 }
16048 if (nc->ev_timer_time > 0) {
16049 if (num_timers == 0 || nc->ev_timer_time < min_timer) {
16051 }
16052 num_timers++;
16053 }
16054
16055 if (nc->sock != INVALID_SOCKET) {
16056 if (mg_lwip_if_can_send(nc, cs)) {
16059 }
16060 if (cs->rx_chain != NULL) {
16062 } else if (cs->draining_rx_chain) {
16063 /*
16064 * If the connection is about to close, and rx_chain is finally empty,
16065 * send the MG_SIG_CLOSE_CONN signal
16066 */
16068 }
16069 }
16070 }
16071#if 0
16072 DBG(("end poll @%u, %d conns, %d timers (min %u), next in %d ms",
16073 (unsigned int) (now * 1000), n, num_timers,
16074 (unsigned int) (min_timer * 1000), timeout_ms));
16075#endif
16076 (void) timeout_ms;
16077 return now;
16078}
double ev_timer_time
Definition mongoose6.h:1260
static void tcp_output_tcpip(void *arg)
int mg_if_poll(struct mg_connection *nc, double now)
static int mg_lwip_if_can_send(struct mg_connection *nc, struct mg_lwip_conn_state *cs)
void mg_ev_mgr_lwip_process_signals(struct mg_mgr *mgr)
void mg_if_can_send_cb(struct mg_connection *nc)
Here is the call graph for this function:

◆ mg_lwip_if_remove_conn()

void mg_lwip_if_remove_conn ( struct mg_connection nc)

Definition at line 16016 of file mongoose614.cxx.

16016 {
16017 struct mg_ev_mgr_lwip_data *md =
16018 (struct mg_ev_mgr_lwip_data *) nc->iface->data;
16019 /* Walk the queue and null-out further signals for this conn. */
16020 for (int i = 0; i < MG_SIG_QUEUE_LEN; i++) {
16021 if (md->sig_queue[i].nc == nc) {
16022 md->sig_queue[i].sig = MG_SIG_TOMBSTONE;
16023 }
16024 }
16025}
Here is the call graph for this function:

◆ mg_lwip_if_sock_set()

void mg_lwip_if_sock_set ( struct mg_connection nc,
sock_t  sock 
)

Definition at line 15876 of file mongoose614.cxx.

15876 {
15877 nc->sock = sock;
15878}

◆ mg_lwip_if_tcp_recv()

static int mg_lwip_if_tcp_recv ( struct mg_connection nc,
void buf,
size_t  len 
)
static

Definition at line 15777 of file mongoose614.cxx.

15778 {
15779 int res = 0;
15780 char *bufp = buf;
15781 struct mg_lwip_conn_state *cs = (struct mg_lwip_conn_state *) nc->sock;
15782 if (nc->sock == INVALID_SOCKET) return -1;
15783 mgos_lock();
15784 while (cs->rx_chain != NULL && len > 0) {
15785 struct pbuf *seg = cs->rx_chain;
15786 size_t seg_len = (seg->len - cs->rx_offset);
15787 size_t copy_len = MIN(len, seg_len);
15788
15789 pbuf_copy_partial(seg, bufp, copy_len, cs->rx_offset);
15790 len -= copy_len;
15791 res += copy_len;
15792 bufp += copy_len;
15793 cs->rx_offset += copy_len;
15794 if (cs->rx_offset == cs->rx_chain->len) {
15795 cs->rx_chain = pbuf_dechain(cs->rx_chain);
15796 pbuf_free(seg);
15797 cs->rx_offset = 0;
15798 }
15799 }
15800 mgos_unlock();
15801 if (res > 0) {
15802 struct tcp_recved_ctx ctx = {.tpcb = cs->pcb.tcp, .len = res};
15804 }
15805 return res;
15806}
#define MIN(a, b)
void tcp_recved_tcpip(void *arg)
struct tcp_pcb * tpcb
Here is the call graph for this function:

◆ mg_lwip_if_tcp_send()

int mg_lwip_if_tcp_send ( struct mg_connection nc,
const void buf,
size_t  len 
)

Definition at line 15703 of file mongoose614.cxx.

15703 {
15704 struct mg_lwip_tcp_write_ctx ctx = {.nc = nc, .data = buf, .len = len};
15705 struct mg_lwip_conn_state *cs = (struct mg_lwip_conn_state *) nc->sock;
15706 if (nc->sock == INVALID_SOCKET) return -1;
15707 struct tcp_pcb *tpcb = cs->pcb.tcp;
15708 if (tpcb == NULL) return -1;
15709 if (tpcb->snd_buf <= 0) return 0;
15711 return ctx.ret;
15712}
static void mg_lwip_tcp_write_tcpip(void *arg)
struct mg_connection * nc
Here is the call graph for this function:

◆ mg_lwip_if_udp_recv()

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

Definition at line 15490 of file mongoose614.cxx.

15491 {
15492 /*
15493 * For UDP, RX chain consists of interleaved address and packet bufs:
15494 * Address pbuf followed by exactly one data pbuf (recv_cb took care of that).
15495 */
15496 int res = 0;
15497 struct mg_lwip_conn_state *cs = (struct mg_lwip_conn_state *) nc->sock;
15498 if (nc->sock == INVALID_SOCKET) return -1;
15499 mgos_lock();
15500 if (cs->rx_chain != NULL) {
15501 struct pbuf *ap = cs->rx_chain;
15502 struct pbuf *dp = ap->next;
15503 cs->rx_chain = pbuf_dechain(dp);
15504 res = MIN(dp->len, len);
15505 pbuf_copy_partial(dp, buf, res, 0);
15506 pbuf_free(dp);
15507 pbuf_copy_partial(ap, sa, MIN(*sa_len, ap->len), 0);
15508 pbuf_free(ap);
15509 }
15510 mgos_unlock();
15511 return res;
15512}
Here is the call graph for this function:

◆ mg_lwip_if_udp_send()

static int mg_lwip_if_udp_send ( struct mg_connection nc,
const void data,
size_t  len 
)
static

Definition at line 15727 of file mongoose614.cxx.

15728 {
15729 struct mg_lwip_conn_state *cs = (struct mg_lwip_conn_state *) nc->sock;
15730 if (nc->sock == INVALID_SOCKET || cs->pcb.udp == NULL) return -1;
15731 struct udp_pcb *upcb = cs->pcb.udp;
15732 struct pbuf *p = pbuf_alloc(PBUF_TRANSPORT, len, PBUF_RAM);
15733#if defined(LWIP_IPV4) && LWIP_IPV4 && defined(LWIP_IPV6) && LWIP_IPV6
15734 ip_addr_t ip = {.u_addr.ip4.addr = nc->sa.sin.sin_addr.s_addr, .type = 0};
15735#else
15736 ip_addr_t ip = {.addr = nc->sa.sin.sin_addr.s_addr};
15737#endif
15738 u16_t port = ntohs(nc->sa.sin.sin_port);
15739 if (p == NULL) return 0;
15740 memcpy(p->payload, data, len);
15741 struct udp_sendto_ctx ctx = {.upcb = upcb, .p = p, .ip = &ip, .port = port};
15743 cs->err = ctx.ret;
15744 pbuf_free(p);
15745 return (cs->err == ERR_OK ? (int) len : -2);
15746}
static void udp_sendto_tcpip(void *arg)
struct pbuf * p
struct udp_pcb * upcb
Here is the call graph for this function:

◆ mg_lwip_mgr_schedule_poll()

void mg_lwip_mgr_schedule_poll ( struct mg_mgr mgr)
Here is the caller graph for this function:

◆ mg_lwip_post_signal()

void mg_lwip_post_signal ( enum mg_sig_type  sig,
struct mg_connection nc 
)

Definition at line 15946 of file mongoose614.cxx.

15946 {
15947 struct mg_ev_mgr_lwip_data *md =
15948 (struct mg_ev_mgr_lwip_data *) nc->iface->data;
15949 mgos_lock();
15950 if (md->sig_queue_len >= MG_SIG_QUEUE_LEN) {
15951 mgos_unlock();
15952 return;
15953 }
15954 int end_index = (md->start_index + md->sig_queue_len) % MG_SIG_QUEUE_LEN;
15955 md->sig_queue[end_index].sig = sig;
15956 md->sig_queue[end_index].nc = nc;
15957 md->sig_queue_len++;
15959 mgos_unlock();
15960}
void mg_lwip_mgr_schedule_poll(struct mg_mgr *mgr)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_lwip_recv_common()

static void mg_lwip_recv_common ( struct mg_connection nc,
struct pbuf p 
)
static

Definition at line 15477 of file mongoose614.cxx.

15477 {
15478 struct mg_lwip_conn_state *cs = (struct mg_lwip_conn_state *) nc->sock;
15479 if (cs->rx_chain == NULL) {
15480 cs->rx_chain = p;
15481 } else {
15482 pbuf_chain(cs->rx_chain, p);
15483 }
15484 if (!cs->recv_pending) {
15485 cs->recv_pending = 1;
15487 }
15488}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_lwip_tcp_conn_cb()

static err_t mg_lwip_tcp_conn_cb ( void arg,
struct tcp_pcb tpcb,
err_t  err 
)
static

Definition at line 15299 of file mongoose614.cxx.

15299 {
15300 struct mg_connection *nc = (struct mg_connection *) arg;
15301 DBG(("%p connect to %s:%u = %d", nc, IPADDR_NTOA(ipX_2_ip(&tpcb->remote_ip)),
15302 tpcb->remote_port, err));
15303 if (nc == NULL) {
15304 tcp_abort(tpcb);
15305 return ERR_ARG;
15306 }
15307 struct mg_lwip_conn_state *cs = (struct mg_lwip_conn_state *) nc->sock;
15308 cs->err = err;
15309#if LWIP_TCP_KEEPALIVE
15310 if (err == 0) mg_lwip_set_keepalive_params(nc, 60, 10, 6);
15311#endif
15313 return ERR_OK;
15314}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_lwip_tcp_error_cb()

static void mg_lwip_tcp_error_cb ( void arg,
err_t  err 
)
static

Definition at line 15316 of file mongoose614.cxx.

15316 {
15317 struct mg_connection *nc = (struct mg_connection *) arg;
15318 DBG(("%p conn error %d", nc, err));
15319 if (nc == NULL || (nc->flags & MG_F_CLOSE_IMMEDIATELY)) return;
15320 struct mg_lwip_conn_state *cs = (struct mg_lwip_conn_state *) nc->sock;
15321 cs->pcb.tcp = NULL; /* Has already been deallocated */
15322 if (nc->flags & MG_F_CONNECTING) {
15323 cs->err = err;
15325 } else {
15327 }
15328}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_lwip_tcp_recv_cb()

static err_t mg_lwip_tcp_recv_cb ( void arg,
struct tcp_pcb tpcb,
struct pbuf p,
err_t  err 
)
static

Definition at line 15330 of file mongoose614.cxx.

15331 {
15332 struct mg_connection *nc = (struct mg_connection *) arg;
15333 struct mg_lwip_conn_state *cs =
15334 (nc ? (struct mg_lwip_conn_state *) nc->sock : NULL);
15335 DBG(("%p %p %p %p %u %d", nc, cs, tpcb, p, (p != NULL ? p->tot_len : 0),
15336 err));
15337 if (p == NULL) {
15338 if (nc != NULL && !(nc->flags & MG_F_CLOSE_IMMEDIATELY)) {
15339 if (cs->rx_chain != NULL) {
15340 /*
15341 * rx_chain still contains non-consumed data, don't close the
15342 * connection
15343 */
15344 cs->draining_rx_chain = 1;
15345 } else {
15347 }
15348 } else {
15349 /* Tombstoned connection, do nothing. */
15350 }
15351 return ERR_OK;
15352 } else if (nc == NULL) {
15353 tcp_abort(tpcb);
15354 return ERR_ARG;
15355 }
15356 /*
15357 * If we get a chain of more than one segment at once, we need to bump
15358 * refcount on the subsequent bufs to make them independent.
15359 */
15360 if (p->next != NULL) {
15361 struct pbuf *q = p->next;
15362 for (; q != NULL; q = q->next) pbuf_ref(q);
15363 }
15364 mgos_lock();
15365 if (cs->rx_chain == NULL) {
15366 cs->rx_offset = 0;
15367 } else if (pbuf_clen(cs->rx_chain) >= 4) {
15368 /* ESP SDK has a limited pool of 5 pbufs. We must not hog them all or RX
15369 * will be completely blocked. We already have at least 4 in the chain,
15370 * this one is the last, so we have to make a copy and release this one. */
15371 struct pbuf *np = pbuf_alloc(PBUF_RAW, p->tot_len, PBUF_RAM);
15372 if (np != NULL) {
15373 pbuf_copy(np, p);
15374 pbuf_free(p);
15375 p = np;
15376 }
15377 }
15378 mg_lwip_recv_common(nc, p);
15379 mgos_unlock();
15380 (void) err;
15381 return ERR_OK;
15382}
static std::string q(const char *s)
static void mg_lwip_recv_common(struct mg_connection *nc, struct pbuf *p)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_lwip_tcp_sent_cb()

static err_t mg_lwip_tcp_sent_cb ( void arg,
struct tcp_pcb tpcb,
u16_t  num_sent 
)
static

Definition at line 15384 of file mongoose614.cxx.

15385 {
15386 struct mg_connection *nc = (struct mg_connection *) arg;
15387 DBG(("%p %p %u %p %p", nc, tpcb, num_sent, tpcb->unsent, tpcb->unacked));
15388 if (nc == NULL) return ERR_OK;
15389 if ((nc->flags & MG_F_SEND_AND_CLOSE) && !(nc->flags & MG_F_WANT_WRITE) &&
15390 nc->send_mbuf.len == 0 && tpcb->unsent == NULL && tpcb->unacked == NULL) {
15392 }
15393 if (nc->send_mbuf.len > 0 || (nc->flags & MG_F_WANT_WRITE)) {
15395 }
15396 (void) num_sent;
15397 return ERR_OK;
15398}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_lwip_tcp_write_tcpip()

static void mg_lwip_tcp_write_tcpip ( void arg)
static

Definition at line 15657 of file mongoose614.cxx.

15657 {
15658 struct mg_lwip_tcp_write_ctx *ctx = (struct mg_lwip_tcp_write_ctx *) arg;
15659 struct mg_connection *nc = ctx->nc;
15660 struct mg_lwip_conn_state *cs = (struct mg_lwip_conn_state *) nc->sock;
15661 struct tcp_pcb *tpcb = cs->pcb.tcp;
15662 size_t len = MIN(tpcb->mss, MIN(ctx->len, tpcb->snd_buf));
15663 size_t unsent, unacked;
15664 if (len == 0) {
15665 DBG(("%p no buf avail %u %u %p %p", tpcb, tpcb->snd_buf, tpcb->snd_queuelen,
15666 tpcb->unsent, tpcb->unacked));
15668 ctx->ret = 0;
15669 return;
15670 }
15671 unsent = (tpcb->unsent != NULL ? tpcb->unsent->len : 0);
15672 unacked = (tpcb->unacked != NULL ? tpcb->unacked->len : 0);
15673/*
15674 * On ESP8266 we only allow one TCP segment in flight at any given time.
15675 * This may increase latency and reduce efficiency of tcp windowing,
15676 * but memory is scarce and precious on that platform so we do this to
15677 * reduce footprint.
15678 */
15679#if CS_PLATFORM == CS_P_ESP8266
15680 if (unacked > 0) {
15681 ctx->ret = 0;
15682 return;
15683 }
15684 len = MIN(len, (TCP_MSS - unsent));
15685#endif
15686 cs->err = tcp_write(tpcb, ctx->data, len, TCP_WRITE_FLAG_COPY);
15687 unsent = (tpcb->unsent != NULL ? tpcb->unsent->len : 0);
15688 unacked = (tpcb->unacked != NULL ? tpcb->unacked->len : 0);
15689 DBG(("%p tcp_write %u = %d, %u %u", tpcb, len, cs->err, unsent, unacked));
15690 if (cs->err != ERR_OK) {
15691 /*
15692 * We ignore ERR_MEM because memory will be freed up when the data is sent
15693 * and we'll retry.
15694 */
15695 ctx->ret = (cs->err == ERR_MEM ? 0 : -1);
15696 return;
15697 }
15698 ctx->ret = len;
15699 (void) unsent;
15700 (void) unacked;
15701}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_lwip_udp_recv_cb()

static void mg_lwip_udp_recv_cb ( void arg,
struct udp_pcb pcb,
struct pbuf p,
ip_addr_t addr,
u16_t  port 
)
static

Definition at line 15448 of file mongoose614.cxx.

15451{
15452 struct mg_connection *nc = (struct mg_connection *) arg;
15453 DBG(("%p %s:%u %p %u %u", nc, IPADDR_NTOA(addr), port, p, p->ref, p->len));
15454 /* Put address in a separate pbuf and tack it onto the packet. */
15455 struct pbuf *sap =
15456 pbuf_alloc(PBUF_RAW, sizeof(union socket_address), PBUF_RAM);
15457 if (sap == NULL) {
15458 pbuf_free(p);
15459 return;
15460 }
15461 union socket_address *sa = (union socket_address *) sap->payload;
15462#if ((LWIP_VERSION_MAJOR << 8) | LWIP_VERSION_MINOR) >= 0x0105
15463 sa->sin.sin_addr.s_addr = ip_2_ip4(addr)->addr;
15464#else
15465 sa->sin.sin_addr.s_addr = addr->addr;
15466#endif
15467 sa->sin.sin_port = htons(port);
15468 /* Logic in the recv handler requires that there be exactly one data pbuf. */
15469 p = pbuf_coalesce(p, PBUF_RAW);
15470 pbuf_chain(sap, p);
15471 mgos_lock();
15473 mgos_unlock();
15474 (void) pcb;
15475}
char addr[128]
Definition mcnaf.cxx:104
#define ip_2_ip4(addr)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_mbuf_append_base64()

void mg_mbuf_append_base64 ( struct mbuf mbuf,
const void data,
size_t  len 
)

Definition at line 10743 of file mongoose614.cxx.

10743 {
10744 struct cs_base64_ctx ctx;
10746 cs_base64_update(&ctx, (const char *) data, len);
10747 cs_base64_finish(&ctx);
10748}

◆ mg_mbuf_append_base64_putc()

void mg_mbuf_append_base64_putc ( char  ch,
void user_data 
)

Definition at line 10738 of file mongoose614.cxx.

10738 {
10739 struct mbuf *mbuf = (struct mbuf *) user_data;
10740 mbuf_append(mbuf, &ch, sizeof(ch));
10741}
Here is the caller graph for this function:

◆ mg_mgr_handle_conn()

void mg_mgr_handle_conn ( struct mg_connection nc,
int  fd_flags,
double  now 
)

Definition at line 4038 of file mongoose614.cxx.

4038 {
4039 int worth_logging =
4040 fd_flags != 0 || (nc->flags & (MG_F_WANT_READ | MG_F_WANT_WRITE));
4041 if (worth_logging) {
4042 DBG(("%p fd=%d fd_flags=%d nc_flags=0x%lx rmbl=%d smbl=%d", nc, nc->sock,
4043 fd_flags, nc->flags, (int) nc->recv_mbuf.len,
4044 (int) nc->send_mbuf.len));
4045 }
4046
4047 if (!mg_if_poll(nc, now)) return;
4048
4049 if (nc->flags & MG_F_CONNECTING) {
4050 if (fd_flags != 0) {
4051 int err = 0;
4052#if !defined(MG_ESP8266)
4053 if (!(nc->flags & MG_F_UDP)) {
4054 socklen_t len = sizeof(err);
4055 int ret =
4056 getsockopt(nc->sock, SOL_SOCKET, SO_ERROR, (char *) &err, &len);
4057 if (ret != 0) {
4058 err = 1;
4059 } else if (err == EAGAIN || err == EWOULDBLOCK) {
4060 err = 0;
4061 }
4062 }
4063#else
4064 /*
4065 * On ESP8266 we use blocking connect.
4066 */
4067 err = nc->err;
4068#endif
4069 mg_if_connect_cb(nc, err);
4070 } else if (nc->err != 0) {
4071 mg_if_connect_cb(nc, nc->err);
4072 }
4073 }
4074
4076 if (nc->flags & MG_F_UDP) {
4078 } else {
4079 if (nc->flags & MG_F_LISTENING) {
4080 /*
4081 * We're not looping here, and accepting just one connection at
4082 * a time. The reason is that eCos does not respect non-blocking
4083 * flag on a listening socket and hangs in a loop.
4084 */
4085 mg_accept_conn(nc);
4086 } else {
4088 }
4089 }
4090 }
4091
4093
4094 if (worth_logging) {
4095 DBG(("%p after fd=%d nc_flags=0x%lx rmbl=%d smbl=%d", nc, nc->sock,
4096 nc->flags, (int) nc->recv_mbuf.len, (int) nc->send_mbuf.len));
4097 }
4098}
static int mg_accept_conn(struct mg_connection *lc)
#define _MG_F_FD_CAN_READ
#define _MG_F_FD_CAN_WRITE
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_mgr_init_opt()

void mg_mgr_init_opt ( struct mg_mgr m,
void user_data,
struct mg_mgr_init_opts  opts 
)

Definition at line 2576 of file mongoose614.cxx.

2577 {
2578 memset(m, 0, sizeof(*m));
2579#if MG_ENABLE_BROADCAST
2580 m->ctl[0] = m->ctl[1] = INVALID_SOCKET;
2581#endif
2582 m->user_data = user_data;
2583
2584#ifdef _WIN32
2585 {
2586 WSADATA data;
2587 WSAStartup(MAKEWORD(2, 2), &data);
2588 }
2589#elif defined(__unix__)
2590 /* Ignore SIGPIPE signal, so if client cancels the request, it
2591 * won't kill the whole process. */
2593#endif
2594
2595 {
2596 int i;
2597 if (opts.num_ifaces == 0) {
2598 opts.num_ifaces = mg_num_ifaces;
2599 opts.ifaces = mg_ifaces;
2600 }
2601 if (opts.main_iface != NULL) {
2602 opts.ifaces[MG_MAIN_IFACE] = opts.main_iface;
2603 }
2604 m->num_ifaces = opts.num_ifaces;
2605 m->ifaces =
2606 (struct mg_iface **) MG_MALLOC(sizeof(*m->ifaces) * opts.num_ifaces);
2607 for (i = 0; i < opts.num_ifaces; i++) {
2608 m->ifaces[i] = mg_if_create_iface(opts.ifaces[i], m);
2609 m->ifaces[i]->vtable->init(m->ifaces[i]);
2610 }
2611 }
2612 if (opts.nameserver != NULL) {
2613 m->nameserver = strdup(opts.nameserver);
2614 }
2615 DBG(("=================================="));
2616 DBG(("init mgr=%p", m));
2617#if MG_ENABLE_SSL
2618 {
2619 static int init_done;
2620 if (!init_done) {
2622 init_done++;
2623 }
2624 }
2625#endif
2626}
sock_t ctl[2]
Definition mongoose6.h:1234
void * user_data
Definition mongoose6.h:1236
const struct mg_iface_vtable * mg_ifaces[]
int mg_num_ifaces
struct mg_iface * mg_if_create_iface(const struct mg_iface_vtable *vtable, struct mg_mgr *mgr)
void(* init)(struct mg_iface *iface)
const char * nameserver
Here is the caller graph for this function:

◆ mg_mgr_min_timer()

double mg_mgr_min_timer ( const struct mg_mgr mgr)

Definition at line 3664 of file mongoose614.cxx.

3664 {
3665 double min_timer = 0;
3666 struct mg_connection *nc;
3667 for (nc = mgr->active_connections; nc != NULL; nc = nc->next) {
3668 if (nc->ev_timer_time <= 0) continue;
3669 if (min_timer == 0 || nc->ev_timer_time < min_timer) {
3671 }
3672 }
3673 return min_timer;
3674}

◆ mg_mk_str_n()

struct mg_str mg_mk_str_n ( const char s,
size_t  len 
)

Definition at line 1701 of file mongoose614.cxx.

1701 {
1702 struct mg_str ret = {s, len};
1703 return ret;
1704}
Here is the caller graph for this function:

◆ mg_next_comma_list_entry_n()

struct mg_str mg_next_comma_list_entry_n ( struct mg_str  list,
struct mg_str val,
struct mg_str eq_val 
)

Definition at line 2271 of file mongoose614.cxx.

2272 {
2273 if (list.len == 0) {
2274 /* End of the list */
2275 list = mg_mk_str(NULL);
2276 } else {
2277 const char *chr = NULL;
2278 *val = list;
2279
2280 if ((chr = mg_strchr(*val, ',')) != NULL) {
2281 /* Comma found. Store length and shift the list ptr */
2282 val->len = chr - val->p;
2283 chr++;
2284 list.len -= (chr - list.p);
2285 list.p = chr;
2286 } else {
2287 /* This value is the last one */
2288 list = mg_mk_str_n(list.p + list.len, 0);
2289 }
2290
2291 if (eq_val != NULL) {
2292 /* Value has form "x=y", adjust pointers and lengths */
2293 /* so that val points to "x", and eq_val points to "y". */
2294 eq_val->len = 0;
2295 eq_val->p = (const char *) memchr(val->p, '=', val->len);
2296 if (eq_val->p != NULL) {
2297 eq_val->p++; /* Skip over '=' character */
2298 eq_val->len = val->p + val->len - eq_val->p;
2299 val->len = (eq_val->p - val->p) - 1;
2300 }
2301 }
2302 }
2303
2304 return list;
2305}
struct mg_str mg_mk_str(const char *s) WEAK
const char * mg_strchr(const struct mg_str s, int c) WEAK
struct mg_str mg_mk_str_n(const char *s, size_t len) WEAK
static te_expr * list(state *s)
Definition tinyexpr.c:567
Here is the caller graph for this function:

◆ mg_null_if_add_conn()

static void mg_null_if_add_conn ( struct mg_connection c)
static

Definition at line 3775 of file mongoose614.cxx.

3775 {
3776 c->sock = INVALID_SOCKET;
3777 c->flags |= MG_F_CLOSE_IMMEDIATELY;
3778}

◆ mg_null_if_connect_tcp()

static void mg_null_if_connect_tcp ( struct mg_connection c,
const union socket_address sa 
)
static

Definition at line 3696 of file mongoose614.cxx.

3697 {
3698 c->flags |= MG_F_CLOSE_IMMEDIATELY;
3699 (void) sa;
3700}
Here is the call graph for this function:

◆ mg_null_if_connect_udp()

static void mg_null_if_connect_udp ( struct mg_connection c)
static

Definition at line 3702 of file mongoose614.cxx.

3702 {
3703 c->flags |= MG_F_CLOSE_IMMEDIATELY;
3704}

◆ mg_null_if_create_conn()

static int mg_null_if_create_conn ( struct mg_connection c)
static

Definition at line 3753 of file mongoose614.cxx.

3753 {
3754 (void) c;
3755 return 1;
3756}
Here is the call graph for this function:

◆ mg_null_if_destroy_conn()

static void mg_null_if_destroy_conn ( struct mg_connection c)
static

Definition at line 3758 of file mongoose614.cxx.

3758 {
3759 (void) c;
3760}
Here is the call graph for this function:

◆ mg_null_if_free()

static void mg_null_if_free ( struct mg_iface iface)
static

Definition at line 3771 of file mongoose614.cxx.

3771 {
3772 (void) iface;
3773}
Here is the call graph for this function:

◆ mg_null_if_get_conn_addr()

static void mg_null_if_get_conn_addr ( struct mg_connection c,
int  remote,
union socket_address sa 
)
static

Definition at line 3797 of file mongoose614.cxx.

3798 {
3799 (void) c;
3800 (void) remote;
3801 (void) sa;
3802}
Here is the call graph for this function:

◆ mg_null_if_init()

static void mg_null_if_init ( struct mg_iface iface)
static

Definition at line 3767 of file mongoose614.cxx.

3767 {
3768 (void) iface;
3769}
Here is the call graph for this function:

◆ mg_null_if_listen_tcp()

static int mg_null_if_listen_tcp ( struct mg_connection c,
union socket_address sa 
)
static

Definition at line 3706 of file mongoose614.cxx.

3707 {
3708 (void) c;
3709 (void) sa;
3710 return -1;
3711}
Here is the call graph for this function:

◆ mg_null_if_listen_udp()

static int mg_null_if_listen_udp ( struct mg_connection c,
union socket_address sa 
)
static

Definition at line 3713 of file mongoose614.cxx.

3714 {
3715 (void) c;
3716 (void) sa;
3717 return -1;
3718}
Here is the call graph for this function:

◆ mg_null_if_poll()

static time_t mg_null_if_poll ( struct mg_iface iface,
int  timeout_ms 
)
static

Definition at line 3784 of file mongoose614.cxx.

3784 {
3785 struct mg_mgr *mgr = iface->mgr;
3786 struct mg_connection *nc, *tmp;
3787 double now = mg_time();
3788 /* We basically just run timers and poll. */
3789 for (nc = mgr->active_connections; nc != NULL; nc = tmp) {
3790 tmp = nc->next;
3791 mg_if_poll(nc, now);
3792 }
3793 (void) timeout_ms;
3794 return (time_t) now;
3795}
Here is the call graph for this function:

◆ mg_null_if_remove_conn()

static void mg_null_if_remove_conn ( struct mg_connection c)
static

Definition at line 3780 of file mongoose614.cxx.

3780 {
3781 (void) c;
3782}
Here is the call graph for this function:

◆ mg_null_if_sock_set()

static void mg_null_if_sock_set ( struct mg_connection c,
sock_t  sock 
)
static

Definition at line 3762 of file mongoose614.cxx.

3762 {
3763 (void) c;
3764 (void) sock;
3765}
Here is the call graph for this function:

◆ mg_null_if_tcp_recv()

int mg_null_if_tcp_recv ( struct mg_connection c,
void buf,
size_t  len 
)

Definition at line 3736 of file mongoose614.cxx.

3736 {
3737 (void) c;
3738 (void) buf;
3739 (void) len;
3740 return -1;
3741}
Here is the call graph for this function:

◆ mg_null_if_tcp_send()

static int mg_null_if_tcp_send ( struct mg_connection c,
const void buf,
size_t  len 
)
static

Definition at line 3720 of file mongoose614.cxx.

3721 {
3722 (void) c;
3723 (void) buf;
3724 (void) len;
3725 return -1;
3726}
Here is the call graph for this function:

◆ mg_null_if_udp_recv()

int mg_null_if_udp_recv ( struct mg_connection c,
void buf,
size_t  len,
union socket_address sa,
size_t sa_len 
)

Definition at line 3743 of file mongoose614.cxx.

3744 {
3745 (void) c;
3746 (void) buf;
3747 (void) len;
3748 (void) sa;
3749 (void) sa_len;
3750 return -1;
3751}
Here is the call graph for this function:

◆ mg_null_if_udp_send()

static int mg_null_if_udp_send ( struct mg_connection c,
const void buf,
size_t  len 
)
static

Definition at line 3728 of file mongoose614.cxx.

3729 {
3730 (void) c;
3731 (void) buf;
3732 (void) len;
3733 return -1;
3734}
Here is the call graph for this function:

◆ mg_open_listening_socket() [1/2]

static sock_t mg_open_listening_socket ( struct mg_connection nc,
union socket_address sa,
int  type,
int  proto 
)
static

Definition at line 14600 of file mongoose614.cxx.

14602 {
14603 int r;
14605 (sa->sa.sa_family == AF_INET) ? sizeof(sa->sin) : sizeof(sa->sin6);
14606 sock_t sock = sl_Socket(sa->sa.sa_family, type, proto);
14607 if (sock < 0) return sock;
14608#if MG_ENABLE_SSL && MG_SSL_IF == MG_SSL_IF_SIMPLELINK
14609 if ((r = sl_set_ssl_opts(sock, nc)) < 0) goto clean;
14610#endif
14611 if ((r = sl_Bind(sock, &sa->sa, sa_len)) < 0) goto clean;
14612 if (type != SOCK_DGRAM) {
14613 if ((r = sl_Listen(sock, SOMAXCONN)) < 0) goto clean;
14614 }
14616clean:
14617 if (r < 0) {
14618 sl_Close(sock);
14619 sock = r;
14620 }
14621 return sock;
14622}
struct sockaddr sin6
Definition mongoose6.h:1200
INT type
Definition mana.cxx:269
#define SOMAXCONN
void mg_set_non_blocking_mode(sock_t sock)
Here is the call graph for this function:

◆ mg_open_listening_socket() [2/2]

static sock_t mg_open_listening_socket ( union socket_address sa,
int  type,
int  proto 
)
static

Definition at line 3988 of file mongoose614.cxx.

3989 {
3991 (sa->sa.sa_family == AF_INET) ? sizeof(sa->sin) : sizeof(sa->sin6);
3992 sock_t sock = INVALID_SOCKET;
3993#if !MG_LWIP
3994 int on = 1;
3995#endif
3996
3997 if ((sock = socket(sa->sa.sa_family, type, proto)) != INVALID_SOCKET &&
3998#if !MG_LWIP /* LWIP doesn't support either */
4000 /* "Using SO_REUSEADDR and SO_EXCLUSIVEADDRUSE" http://goo.gl/RmrFTm */
4001 !setsockopt(sock, SOL_SOCKET, SO_EXCLUSIVEADDRUSE, (void *) &on,
4002 sizeof(on)) &&
4003#endif
4004
4005#if !defined(_WIN32) || !defined(SO_EXCLUSIVEADDRUSE)
4006 /*
4007 * SO_RESUSEADDR is not enabled on Windows because the semantics of
4008 * SO_REUSEADDR on UNIX and Windows is different. On Windows,
4009 * SO_REUSEADDR allows to bind a socket to a port without error even if
4010 * the port is already open by another program. This is not the behavior
4011 * SO_REUSEADDR was designed for, and leads to hard-to-track failure
4012 * scenarios. Therefore, SO_REUSEADDR was disabled on Windows unless
4013 * SO_EXCLUSIVEADDRUSE is supported and set on a socket.
4014 */
4015 !setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void *) &on, sizeof(on)) &&
4016#endif
4017#endif /* !MG_LWIP */
4018
4019 !bind(sock, &sa->sa, sa_len) &&
4020 (type == SOCK_DGRAM || listen(sock, SOMAXCONN) == 0)) {
4021#if !MG_LWIP
4023 /* In case port was set to 0, get the real port number */
4024 (void) getsockname(sock, &sa->sa, &sa_len);
4025#endif
4026 } else if (sock != INVALID_SOCKET) {
4027 closesocket(sock);
4028 sock = INVALID_SOCKET;
4029 }
4030
4031 return sock;
4032}
#define MG_LWIP
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_parse_address()

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

Definition at line 2787 of file mongoose614.cxx.

2788 {
2789 unsigned int a, b, c, d, port = 0;
2790 int ch, len = 0;
2791#if MG_ENABLE_IPV6
2792 char buf[100];
2793#endif
2794
2795 /*
2796 * MacOS needs that. If we do not zero it, subsequent bind() will fail.
2797 * Also, all-zeroes in the socket address means binding to all addresses
2798 * for both IPv4 and IPv6 (INADDR_ANY and IN6ADDR_ANY_INIT).
2799 */
2800 memset(sa, 0, sizeof(*sa));
2801 sa->sin.sin_family = AF_INET;
2802
2803 *proto = SOCK_STREAM;
2804
2805 if (strncmp(str, "udp://", 6) == 0) {
2806 str += 6;
2807 *proto = SOCK_DGRAM;
2808 } else if (strncmp(str, "tcp://", 6) == 0) {
2809 str += 6;
2810 }
2811
2812 if (sscanf(str, "%u.%u.%u.%u:%u%n", &a, &b, &c, &d, &port, &len) == 5) {
2813 /* Bind to a specific IPv4 address, e.g. 192.168.1.5:8080 */
2814 sa->sin.sin_addr.s_addr =
2815 htonl(((uint32_t) a << 24) | ((uint32_t) b << 16) | c << 8 | d);
2816 sa->sin.sin_port = htons((uint16_t) port);
2817#if MG_ENABLE_IPV6
2818 } else if (sscanf(str, "[%99[^]]]:%u%n", buf, &port, &len) == 2 &&
2819 inet_pton(AF_INET6, buf, &sa->sin6.sin6_addr)) {
2820 /* IPv6 address, e.g. [3ffe:2a00:100:7031::1]:8080 */
2821 sa->sin6.sin6_family = AF_INET6;
2822 sa->sin.sin_port = htons((uint16_t) port);
2823#endif
2824#if MG_ENABLE_ASYNC_RESOLVER
2825 } else if (strlen(str) < host_len &&
2826 sscanf(str, "%[^ :]:%u%n", host, &port, &len) == 2) {
2827 sa->sin.sin_port = htons((uint16_t) port);
2828 if (mg_resolve_from_hosts_file(host, sa) != 0) {
2829 /*
2830 * if resolving from hosts file failed and the host
2831 * we are trying to resolve is `localhost` - we should
2832 * try to resolve it using `gethostbyname` and do not try
2833 * to resolve it via DNS server if gethostbyname has failed too
2834 */
2835 if (mg_ncasecmp(host, "localhost", 9) != 0) {
2836 return 0;
2837 }
2838
2839#if MG_ENABLE_SYNC_RESOLVER
2840 if (!mg_resolve2(host, &sa->sin.sin_addr)) {
2841 return -1;
2842 }
2843#else
2844 return -1;
2845#endif
2846 }
2847#endif
2848 } else if (sscanf(str, ":%u%n", &port, &len) == 1 ||
2849 sscanf(str, "%u%n", &port, &len) == 1) {
2850 /* If only port is specified, bind to IPv4, INADDR_ANY */
2851 sa->sin.sin_port = htons((uint16_t) port);
2852 } else {
2853 return -1;
2854 }
2855
2856 /* Required for MG_ENABLE_ASYNC_RESOLVER=0 */
2857 (void) host;
2858 (void) host_len;
2859
2860 ch = str[len]; /* Character that follows the address */
2861 return port < 0xffffUL && (ch == '\0' || ch == ',' || isspace(ch)) ? len : -1;
2862}
int mg_resolve_from_hosts_file(const char *host, union socket_address *usa)
int mg_ncasecmp(const char *s1, const char *s2, size_t len) WEAK
int inet_pton(int af, const char *src, void *dst)
static int mg_resolve2(const char *host, struct in_addr *ina)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_pic32_if_add_conn()

void mg_pic32_if_add_conn ( struct mg_connection nc)

Definition at line 16242 of file mongoose614.cxx.

16242 {
16243 (void) nc;
16244}
Here is the call graph for this function:

◆ mg_pic32_if_connect_tcp()

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

Definition at line 16475 of file mongoose614.cxx.

16476 {
16478 sa->sin.sin_family == AF_INET ? IP_ADDRESS_TYPE_IPV4
16480 ntohs(sa->sin.sin_port), (IP_MULTI_ADDRESS *) &sa->sin);
16481 nc->err = (nc->sock == INVALID_SOCKET) ? -1 : 0;
16482}
Here is the call graph for this function:

◆ mg_pic32_if_connect_udp()

void mg_pic32_if_connect_udp ( struct mg_connection nc)

Definition at line 16484 of file mongoose614.cxx.

16484 {
16486 nc->err = (nc->sock == INVALID_SOCKET) ? -1 : 0;
16487}
Here is the call graph for this function:

◆ mg_pic32_if_create_conn()

int mg_pic32_if_create_conn ( struct mg_connection nc)

Definition at line 16232 of file mongoose614.cxx.

16232 {
16233 (void) nc;
16234 return 1;
16235}
Here is the call graph for this function:

◆ mg_pic32_if_destroy_conn()

void mg_pic32_if_destroy_conn ( struct mg_connection nc)

Definition at line 16259 of file mongoose614.cxx.

16259 {
16260 if (nc->sock == INVALID_SOCKET) return;
16261 /* For UDP, only close outgoing sockets or listeners. */
16262 if (!(nc->flags & MG_F_UDP)) {
16263 /* Close TCP */
16265 } else if (nc->listener == NULL) {
16266 /* Only close outgoing UDP or listeners. */
16268 }
16269
16270 nc->sock = INVALID_SOCKET;
16271}
Here is the call graph for this function:

◆ mg_pic32_if_free()

void mg_pic32_if_free ( struct mg_iface iface)

Definition at line 16251 of file mongoose614.cxx.

16251 {
16252 (void) iface;
16253}
Here is the call graph for this function:

◆ mg_pic32_if_get_conn_addr()

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

Definition at line 16470 of file mongoose614.cxx.

16471 {
16472 /* TODO(alaskin): not implemented yet */
16473}

◆ mg_pic32_if_init()

void mg_pic32_if_init ( struct mg_iface iface)

Definition at line 16246 of file mongoose614.cxx.

16246 {
16247 (void) iface;
16248 (void) mg_get_errno(); /* Shutup compiler */
16249}
Here is the call graph for this function:

◆ mg_pic32_if_listen_tcp()

int mg_pic32_if_listen_tcp ( struct mg_connection nc,
union socket_address sa 
)

Definition at line 16295 of file mongoose614.cxx.

16295 {
16297 sa->sin.sin_family == AF_INET ? IP_ADDRESS_TYPE_IPV4
16299 ntohs(sa->sin.sin_port),
16300 sa->sin.sin_addr.s_addr == 0 ? 0 : (IP_MULTI_ADDRESS *) &sa->sin);
16301 memcpy(&nc->sa, sa, sizeof(*sa));
16302 if (nc->sock == INVALID_SOCKET) {
16303 return -1;
16304 }
16305 return 0;
16306}
Here is the call graph for this function:

◆ mg_pic32_if_listen_udp()

int mg_pic32_if_listen_udp ( struct mg_connection nc,
union socket_address sa 
)

Definition at line 16273 of file mongoose614.cxx.

16273 {
16275 sa->sin.sin_family == AF_INET ? IP_ADDRESS_TYPE_IPV4
16277 ntohs(sa->sin.sin_port),
16278 sa->sin.sin_addr.s_addr == 0 ? 0 : (IP_MULTI_ADDRESS *) &sa->sin);
16279 if (nc->sock == INVALID_SOCKET) {
16280 return -1;
16281 }
16282 return 0;
16283}
Here is the call graph for this function:

◆ mg_pic32_if_poll()

time_t mg_pic32_if_poll ( struct mg_iface iface,
int  timeout_ms 
)

Definition at line 16424 of file mongoose614.cxx.

16424 {
16425 struct mg_mgr *mgr = iface->mgr;
16426 double now = mg_time();
16427 struct mg_connection *nc, *tmp;
16428
16429 for (nc = mgr->active_connections; nc != NULL; nc = tmp) {
16430 tmp = nc->next;
16431
16432 if (nc->flags & MG_F_CONNECTING) {
16433 /* processing connections */
16434 if (nc->flags & MG_F_UDP ||
16436 mg_if_connect_cb(nc, 0);
16437 }
16438 } else if (nc->flags & MG_F_LISTENING) {
16440 /* accept new connections */
16441 mg_accept_conn(nc);
16442 }
16443 } else {
16444 if (nc->send_mbuf.len != 0) {
16445 mg_handle_send(nc);
16446 }
16447
16448 if (nc->recv_mbuf_limit == -1 ||
16449 nc->recv_mbuf.len < nc->recv_mbuf_limit) {
16450 mg_handle_recv(nc);
16451 }
16452 }
16453 }
16454
16455 for (nc = mgr->active_connections; nc != NULL; nc = tmp) {
16456 tmp = nc->next;
16457 if ((nc->flags & MG_F_CLOSE_IMMEDIATELY) ||
16458 (nc->send_mbuf.len == 0 && (nc->flags & MG_F_SEND_AND_CLOSE))) {
16459 mg_close_conn(nc);
16460 }
16461 }
16462
16463 return now;
16464}
static void mg_handle_recv(struct mg_connection *nc)
static void mg_handle_send(struct mg_connection *nc)
Here is the call graph for this function:

◆ mg_pic32_if_recved()

void mg_pic32_if_recved ( struct mg_connection nc,
size_t  len 
)

Definition at line 16237 of file mongoose614.cxx.

16237 {
16238 (void) nc;
16239 (void) len;
16240}
Here is the call graph for this function:

◆ mg_pic32_if_remove_conn()

void mg_pic32_if_remove_conn ( struct mg_connection nc)

Definition at line 16255 of file mongoose614.cxx.

16255 {
16256 (void) nc;
16257}
Here is the call graph for this function:

◆ mg_pic32_if_sock_set()

void mg_pic32_if_sock_set ( struct mg_connection nc,
sock_t  sock 
)

Definition at line 16466 of file mongoose614.cxx.

16466 {
16467 nc->sock = sock;
16468}

◆ mg_pic32_if_tcp_send()

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

Definition at line 16290 of file mongoose614.cxx.

16291 {
16292 mbuf_append(&nc->send_mbuf, buf, len);
16293}
Here is the call graph for this function:

◆ mg_pic32_if_udp_send()

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

Definition at line 16285 of file mongoose614.cxx.

16286 {
16287 mbuf_append(&nc->send_mbuf, buf, len);
16288}
Here is the call graph for this function:

◆ mg_recv_tcp()

static int mg_recv_tcp ( struct mg_connection nc,
char buf,
size_t  len 
)
static

Definition at line 2972 of file mongoose614.cxx.

2972 {
2973 int n = 0;
2974#if MG_ENABLE_SSL
2975 if (nc->flags & MG_F_SSL) {
2976 if (nc->flags & MG_F_SSL_HANDSHAKE_DONE) {
2977 n = mg_ssl_if_read(nc, buf, len);
2978 DBG(("%p <- %d bytes (SSL)", nc, n));
2979 if (n < 0) {
2980 if (n == MG_SSL_WANT_READ) {
2981 nc->flags |= MG_F_WANT_READ;
2982 n = 0;
2983 } else {
2985 }
2986 } else if (n > 0) {
2987 nc->flags &= ~MG_F_WANT_READ;
2988 }
2989 } else {
2990 mg_ssl_handshake(nc);
2991 }
2992 } else
2993#endif
2994 {
2995 n = nc->iface->vtable->tcp_recv(nc, buf, len);
2996 DBG(("%p <- %d bytes", nc, n));
2997 }
2998 if (n > 0) {
2999 nc->recv_mbuf.len += n;
3000 nc->last_io_time = (time_t) mg_time();
3001#if !defined(NO_LIBC) && MG_ENABLE_HEXDUMP
3002 if (nc->mgr && nc->mgr->hexdump_file != NULL) {
3004 }
3005#endif
3006 mbuf_trim(&nc->recv_mbuf);
3007 mg_call(nc, NULL, nc->user_data, MG_EV_RECV, &n);
3008 } else if (n < 0) {
3010 }
3011 mbuf_trim(&nc->recv_mbuf);
3012 return n;
3013}
int(* tcp_recv)(struct mg_connection *nc, void *buf, size_t len)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_recv_udp()

static int mg_recv_udp ( struct mg_connection nc,
char buf,
size_t  len 
)
static

Definition at line 3015 of file mongoose614.cxx.

3015 {
3016 int n = 0;
3017 struct mg_connection *lc = nc;
3018 union socket_address sa;
3019 size_t sa_len = sizeof(sa);
3020 n = nc->iface->vtable->udp_recv(lc, buf, len, &sa, &sa_len);
3021 if (n < 0) {
3023 goto out;
3024 }
3025 if (nc->flags & MG_F_LISTENING) {
3026 /*
3027 * Do we have an existing connection for this source?
3028 * This is very inefficient for long connection lists.
3029 */
3030 lc = nc;
3031 for (nc = mg_next(lc->mgr, NULL); nc != NULL; nc = mg_next(lc->mgr, nc)) {
3032 if (memcmp(&nc->sa.sa, &sa.sa, sa_len) == 0 && nc->listener == lc) {
3033 break;
3034 }
3035 }
3036 if (nc == NULL) {
3037 struct mg_add_sock_opts opts;
3038 memset(&opts, 0, sizeof(opts));
3039 /* Create fake connection w/out sock initialization */
3040 nc = mg_create_connection_base(lc->mgr, lc->handler, opts);
3041 if (nc != NULL) {
3042 nc->sock = lc->sock;
3043 nc->listener = lc;
3044 nc->sa = sa;
3045 nc->proto_handler = lc->proto_handler;
3046 nc->user_data = lc->user_data;
3048 nc->flags = MG_F_UDP;
3049 /*
3050 * Long-lived UDP "connections" i.e. interactions that involve more
3051 * than one request and response are rare, most are transactional:
3052 * response is sent and the "connection" is closed. Or - should be.
3053 * But users (including ourselves) tend to forget about that part,
3054 * because UDP is connectionless and one does not think about
3055 * processing a UDP request as handling a connection that needs to be
3056 * closed. Thus, we begin with SEND_AND_CLOSE flag set, which should
3057 * be a reasonable default for most use cases, but it is possible to
3058 * turn it off the connection should be kept alive after processing.
3059 */
3061 mg_add_conn(lc->mgr, nc);
3062 mg_call(nc, NULL, nc->user_data, MG_EV_ACCEPT, &nc->sa);
3063 }
3064 }
3065 }
3066 if (nc != NULL) {
3067 DBG(("%p <- %d bytes from %s:%d", nc, n, inet_ntoa(nc->sa.sin.sin_addr),
3068 ntohs(nc->sa.sin.sin_port)));
3069 if (nc == lc) {
3070 nc->recv_mbuf.len += n;
3071 } else {
3072 mbuf_append(&nc->recv_mbuf, buf, n);
3073 }
3074 mbuf_trim(&lc->recv_mbuf);
3075 lc->last_io_time = nc->last_io_time = (time_t) mg_time();
3076#if !defined(NO_LIBC) && MG_ENABLE_HEXDUMP
3077 if (nc->mgr && nc->mgr->hexdump_file != NULL) {
3079 }
3080#endif
3081 if (n != 0) {
3082 mg_call(nc, NULL, nc->user_data, MG_EV_RECV, &n);
3083 }
3084 }
3085
3086out:
3087 mbuf_free(&lc->recv_mbuf);
3088 return n;
3089}
struct mg_connection * mg_next(struct mg_mgr *s, struct mg_connection *conn)
#define MG_EV_ACCEPT
Definition mongoose6.h:1220
int(* udp_recv)(struct mg_connection *nc, void *buf, size_t len, union socket_address *sa, size_t *sa_len)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_remove_conn()

MG_INTERNAL void mg_remove_conn ( struct mg_connection c)

Definition at line 2427 of file mongoose614.cxx.

2427 {
2428 if (conn->prev == NULL) conn->mgr->active_connections = conn->next;
2429 if (conn->prev) conn->prev->next = conn->next;
2430 if (conn->next) conn->next->prev = conn->prev;
2431 conn->prev = conn->next = NULL;
2432 conn->iface->vtable->remove_conn(conn);
2433}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_run_in_task()

void mg_run_in_task ( void(*)(struct mg_mgr *mgr, void *arg)  cb,
void cb_arg 
)

Definition at line 14384 of file mongoose614.cxx.

14384 {
14385 struct mg_q_msg msg = {MG_Q_MSG_CB, cb, cb_arg};
14387}
static OsiMsgQ_t s_mg_q
void(* cb)(struct mg_mgr *mgr, void *arg)
Here is the call graph for this function:

◆ mg_set_non_blocking_mode()

void mg_set_non_blocking_mode ( sock_t  sock)

Definition at line 3836 of file mongoose614.cxx.

3836 {
3837#ifdef _WIN32
3838 unsigned long on = 1;
3839 ioctlsocket(sock, FIONBIO, &on);
3840#else
3841 int flags = fcntl(sock, F_GETFL, 0);
3842 fcntl(sock, F_SETFL, flags | O_NONBLOCK);
3843#endif
3844}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_sl_if_add_conn()

void mg_sl_if_add_conn ( struct mg_connection nc)

Definition at line 14700 of file mongoose614.cxx.

14700 {
14701 (void) nc;
14702}
Here is the call graph for this function:

◆ mg_sl_if_connect_tcp()

static void mg_sl_if_connect_tcp ( struct mg_connection nc,
const union socket_address sa 
)
static

Definition at line 14479 of file mongoose614.cxx.

14480 {
14481 int proto = 0;
14482#if MG_ENABLE_SSL && MG_SSL_IF == MG_SSL_IF_SIMPLELINK
14483 if (nc->flags & MG_F_SSL) proto = SL_SEC_SOCKET;
14484#endif
14485 sock_t sock = sl_Socket(AF_INET, SOCK_STREAM, proto);
14486 if (sock < 0) {
14487 nc->err = sock;
14488 goto out;
14489 }
14490 mg_sock_set(nc, sock);
14491#if MG_ENABLE_SSL && MG_SSL_IF == MG_SSL_IF_SIMPLELINK
14492 nc->err = sl_set_ssl_opts(sock, nc);
14493 if (nc->err != 0) goto out;
14494#endif
14495 nc->err = sl_Connect(sock, &sa->sa, sizeof(sa->sin));
14496out:
14497 DBG(("%p to %s:%d sock %d %d err %d", nc, inet_ntoa(sa->sin.sin_addr),
14498 ntohs(sa->sin.sin_port), nc->sock, proto, nc->err));
14499}
Here is the call graph for this function:

◆ mg_sl_if_connect_udp()

static void mg_sl_if_connect_udp ( struct mg_connection nc)
static

Definition at line 14501 of file mongoose614.cxx.

14501 {
14502 sock_t sock = sl_Socket(AF_INET, SOCK_DGRAM, 0);
14503 if (sock < 0) {
14504 nc->err = sock;
14505 return;
14506 }
14507 mg_sock_set(nc, sock);
14508 nc->err = 0;
14509}
Here is the call graph for this function:

◆ mg_sl_if_create_conn()

static int mg_sl_if_create_conn ( struct mg_connection nc)
static

Definition at line 14564 of file mongoose614.cxx.

14564 {
14565 (void) nc;
14566 return 1;
14567}
Here is the call graph for this function:

◆ mg_sl_if_destroy_conn()

void mg_sl_if_destroy_conn ( struct mg_connection nc)

Definition at line 14569 of file mongoose614.cxx.

14569 {
14570 if (nc->sock == INVALID_SOCKET) return;
14571 /* For UDP, only close outgoing sockets or listeners. */
14572 if (!(nc->flags & MG_F_UDP) || nc->listener == NULL) {
14573 sl_Close(nc->sock);
14574 }
14575 nc->sock = INVALID_SOCKET;
14576}
Here is the call graph for this function:

◆ mg_sl_if_free()

void mg_sl_if_free ( struct mg_iface iface)

Definition at line 14696 of file mongoose614.cxx.

14696 {
14697 (void) iface;
14698}
Here is the call graph for this function:

◆ mg_sl_if_get_conn_addr()

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

Definition at line 14804 of file mongoose614.cxx.

14805 {
14806 /* SimpleLink does not provide a way to get socket's peer address after
14807 * accept or connect. Address should have been preserved in the connection,
14808 * so we do our best here by using it. */
14809 if (remote) memcpy(sa, &nc->sa, sizeof(*sa));
14810}
Here is the call graph for this function:

◆ mg_sl_if_init()

void mg_sl_if_init ( struct mg_iface iface)

Definition at line 14691 of file mongoose614.cxx.

14691 {
14692 (void) iface;
14693 DBG(("%p using sl_Select()", iface->mgr));
14694}
Here is the call graph for this function:

◆ mg_sl_if_listen_tcp()

static int mg_sl_if_listen_tcp ( struct mg_connection nc,
union socket_address sa 
)
static

Definition at line 14511 of file mongoose614.cxx.

14512 {
14513 int proto = 0;
14514 if (nc->flags & MG_F_SSL) proto = SL_SEC_SOCKET;
14515 sock_t sock = mg_open_listening_socket(nc, sa, SOCK_STREAM, proto);
14516 if (sock < 0) return sock;
14517 mg_sock_set(nc, sock);
14518 return 0;
14519}
static sock_t mg_open_listening_socket(union socket_address *sa, int type, int proto)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_sl_if_listen_udp()

static int mg_sl_if_listen_udp ( struct mg_connection nc,
union socket_address sa 
)
static

Definition at line 14521 of file mongoose614.cxx.

14522 {
14523 sock_t sock = mg_open_listening_socket(nc, sa, SOCK_DGRAM, 0);
14524 if (sock == INVALID_SOCKET) return (errno ? errno : 1);
14525 mg_sock_set(nc, sock);
14526 return 0;
14527}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_sl_if_poll()

time_t mg_sl_if_poll ( struct mg_iface iface,
int  timeout_ms 
)

Definition at line 14708 of file mongoose614.cxx.

14708 {
14709 struct mg_mgr *mgr = iface->mgr;
14710 double now = mg_time();
14711 double min_timer;
14712 struct mg_connection *nc, *tmp;
14713 struct SlTimeval_t tv;
14716 int num_fds, num_ev = 0, num_timers = 0;
14717
14721
14722 /*
14723 * Note: it is ok to have connections with sock == INVALID_SOCKET in the list,
14724 * e.g. timer-only "connections".
14725 */
14726 min_timer = 0;
14727 for (nc = mgr->active_connections, num_fds = 0; nc != NULL; nc = tmp) {
14728 tmp = nc->next;
14729
14730 if (nc->sock != INVALID_SOCKET) {
14731 num_fds++;
14732
14733 if (!(nc->flags & MG_F_WANT_WRITE) &&
14734 nc->recv_mbuf.len < nc->recv_mbuf_limit &&
14735 (!(nc->flags & MG_F_UDP) || nc->listener == NULL)) {
14737 if (max_fd == INVALID_SOCKET || nc->sock > max_fd) max_fd = nc->sock;
14738 }
14739
14740 if (((nc->flags & MG_F_CONNECTING) && !(nc->flags & MG_F_WANT_READ)) ||
14741 (nc->send_mbuf.len > 0 && !(nc->flags & MG_F_CONNECTING))) {
14744 if (max_fd == INVALID_SOCKET || nc->sock > max_fd) max_fd = nc->sock;
14745 }
14746 }
14747
14748 if (nc->ev_timer_time > 0) {
14749 if (num_timers == 0 || nc->ev_timer_time < min_timer) {
14751 }
14752 num_timers++;
14753 }
14754 }
14755
14756 /*
14757 * If there is a timer to be fired earlier than the requested timeout,
14758 * adjust the timeout.
14759 */
14760 if (num_timers > 0) {
14761 double timer_timeout_ms = (min_timer - mg_time()) * 1000 + 1 /* rounding */;
14764 }
14765 }
14766 if (timeout_ms < 0) timeout_ms = 0;
14767
14768 tv.tv_sec = timeout_ms / 1000;
14769 tv.tv_usec = (timeout_ms % 1000) * 1000;
14770
14771 if (num_fds > 0) {
14772 num_ev = sl_Select((int) max_fd + 1, &read_set, &write_set, &err_set, &tv);
14773 }
14774
14775 now = mg_time();
14776 DBG(("sl_Select @ %ld num_ev=%d of %d, timeout=%d", (long) now, num_ev,
14778
14779 for (nc = mgr->active_connections; nc != NULL; nc = tmp) {
14780 int fd_flags = 0;
14781 if (nc->sock != INVALID_SOCKET) {
14782 if (num_ev > 0) {
14783 fd_flags =
14785 (!(nc->flags & MG_F_UDP) || nc->listener == NULL)
14787 : 0) |
14789 : 0) |
14791 }
14792 /* SimpleLink does not report UDP sockets as writable. */
14793 if (nc->flags & MG_F_UDP && nc->send_mbuf.len > 0) {
14795 }
14796 }
14797 tmp = nc->next;
14799 }
14800
14801 return now;
14802}
#define _MG_F_FD_ERROR
void mg_mgr_handle_conn(struct mg_connection *nc, int fd_flags, double now)
timeval tv
Definition msysmon.cxx:1095
Here is the call graph for this function:

◆ mg_sl_if_remove_conn()

void mg_sl_if_remove_conn ( struct mg_connection nc)

Definition at line 14704 of file mongoose614.cxx.

14704 {
14705 (void) nc;
14706}
Here is the call graph for this function:

◆ mg_sl_if_sock_set()

void mg_sl_if_sock_set ( struct mg_connection nc,
sock_t  sock 
)

Definition at line 14685 of file mongoose614.cxx.

14685 {
14687 nc->sock = sock;
14688 DBG(("%p %d", nc, sock));
14689}
Here is the call graph for this function:

◆ mg_sl_if_tcp_recv()

static int mg_sl_if_tcp_recv ( struct mg_connection nc,
void buf,
size_t  len 
)
static

Definition at line 14543 of file mongoose614.cxx.

14543 {
14544 int n = sl_Recv(nc->sock, buf, len, 0);
14545 if (n == 0) {
14546 /* Orderly shutdown of the socket, try flushing output. */
14548 } else if (n < 0 && !mg_is_error(n)) {
14549 n = 0;
14550 }
14551 return n;
14552}
Here is the call graph for this function:

◆ mg_sl_if_tcp_send()

static int mg_sl_if_tcp_send ( struct mg_connection nc,
const void buf,
size_t  len 
)
static

Definition at line 14529 of file mongoose614.cxx.

14530 {
14531 int n = (int) sl_Send(nc->sock, buf, len, 0);
14532 if (n < 0 && !mg_is_error(n)) n = 0;
14533 return n;
14534}
Here is the call graph for this function:

◆ mg_sl_if_udp_recv()

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

Definition at line 14554 of file mongoose614.cxx.

14555 {
14557 int n = sl_RecvFrom(nc->sock, buf, MG_UDP_RECV_BUFFER_SIZE, 0,
14558 (SlSockAddr_t *) sa, &sa_len_t);
14559 *sa_len = sa_len_t;
14560 if (n < 0 && !mg_is_error(n)) n = 0;
14561 return n;
14562}
#define MG_UDP_RECV_BUFFER_SIZE
Here is the call graph for this function:

◆ mg_sl_if_udp_send()

static int mg_sl_if_udp_send ( struct mg_connection nc,
const void buf,
size_t  len 
)
static

Definition at line 14536 of file mongoose614.cxx.

14537 {
14538 int n = sl_SendTo(nc->sock, buf, len, 0, &nc->sa.sa, sizeof(nc->sa.sin));
14539 if (n < 0 && !mg_is_error(n)) n = 0;
14540 return n;
14541}
Here is the call graph for this function:

◆ mg_sock_get_addr()

static void mg_sock_get_addr ( sock_t  sock,
int  remote,
union socket_address sa 
)
static

Definition at line 4349 of file mongoose614.cxx.

4350 {
4351 socklen_t slen = sizeof(*sa);
4352 memset(sa, 0, slen);
4353 if (remote) {
4354 getpeername(sock, &sa->sa, &slen);
4355 } else {
4356 getsockname(sock, &sa->sa, &slen);
4357 }
4358}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_socket_if_add_conn()

void mg_socket_if_add_conn ( struct mg_connection nc)

Definition at line 4138 of file mongoose614.cxx.

4138 {
4139 (void) nc;
4140}
Here is the call graph for this function:

◆ mg_socket_if_connect_tcp()

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

Definition at line 3858 of file mongoose614.cxx.

3859 {
3860 int rc, proto = 0;
3861 nc->sock = socket(AF_INET, SOCK_STREAM, proto);
3862 if (nc->sock == INVALID_SOCKET) {
3863 nc->err = mg_get_errno() ? mg_get_errno() : 1;
3864 return;
3865 }
3866#if !defined(MG_ESP8266)
3868#endif
3869 rc = connect(nc->sock, &sa->sa, sizeof(sa->sin));
3870 nc->err = rc < 0 && mg_is_error() ? mg_get_errno() : 0;
3871 DBG(("%p sock %d rc %d errno %d err %d", nc, nc->sock, rc, mg_get_errno(),
3872 nc->err));
3873}
Here is the call graph for this function:

◆ mg_socket_if_connect_udp()

void mg_socket_if_connect_udp ( struct mg_connection nc)

Definition at line 3875 of file mongoose614.cxx.

3875 {
3876 nc->sock = socket(AF_INET, SOCK_DGRAM, 0);
3877 if (nc->sock == INVALID_SOCKET) {
3878 nc->err = mg_get_errno() ? mg_get_errno() : 1;
3879 return;
3880 }
3881 if (nc->flags & MG_F_ENABLE_BROADCAST) {
3882 int optval = 1;
3883 if (setsockopt(nc->sock, SOL_SOCKET, SO_BROADCAST, (const char *) &optval,
3884 sizeof(optval)) < 0) {
3885 nc->err = mg_get_errno() ? mg_get_errno() : 1;
3886 return;
3887 }
3888 }
3889 nc->err = 0;
3890}
Here is the call graph for this function:

◆ mg_socket_if_create_conn()

int mg_socket_if_create_conn ( struct mg_connection nc)

Definition at line 3947 of file mongoose614.cxx.

3947 {
3948 (void) nc;
3949 return 1;
3950}
Here is the call graph for this function:

◆ mg_socket_if_destroy_conn()

void mg_socket_if_destroy_conn ( struct mg_connection nc)

Definition at line 3952 of file mongoose614.cxx.

3952 {
3953 if (nc->sock == INVALID_SOCKET) return;
3954 if (!(nc->flags & MG_F_UDP)) {
3955 closesocket(nc->sock);
3956 } else {
3957 /* Only close outgoing UDP sockets or listeners. */
3958 if (nc->listener == NULL) closesocket(nc->sock);
3959 }
3960 nc->sock = INVALID_SOCKET;
3961}
Here is the call graph for this function:

◆ mg_socket_if_free()

void mg_socket_if_free ( struct mg_iface iface)

Definition at line 4134 of file mongoose614.cxx.

4134 {
4135 (void) iface;
4136}
Here is the call graph for this function:

◆ mg_socket_if_get_conn_addr()

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

Definition at line 4366 of file mongoose614.cxx.

4367 {
4368 if ((nc->flags & MG_F_UDP) && remote) {
4369 memcpy(sa, &nc->sa, sizeof(*sa));
4370 return;
4371 }
4372 mg_sock_get_addr(nc->sock, remote, sa);
4373}
static void mg_sock_get_addr(sock_t sock, int remote, union socket_address *sa)
Here is the call graph for this function:

◆ mg_socket_if_init()

void mg_socket_if_init ( struct mg_iface iface)

Definition at line 4126 of file mongoose614.cxx.

4126 {
4127 (void) iface;
4128 DBG(("%p using select()", iface->mgr));
4129#if MG_ENABLE_BROADCAST
4130 mg_socketpair(iface->mgr->ctl, SOCK_DGRAM);
4131#endif
4132}
int mg_socketpair(sock_t[2], int sock_type)
Here is the call graph for this function:

◆ mg_socket_if_listen_tcp()

int mg_socket_if_listen_tcp ( struct mg_connection nc,
union socket_address sa 
)

Definition at line 3892 of file mongoose614.cxx.

3893 {
3894 int proto = 0;
3895 sock_t sock = mg_open_listening_socket(sa, SOCK_STREAM, proto);
3896 if (sock == INVALID_SOCKET) {
3897 return (mg_get_errno() ? mg_get_errno() : 1);
3898 }
3899 mg_sock_set(nc, sock);
3900 return 0;
3901}
Here is the call graph for this function:

◆ mg_socket_if_listen_udp()

static int mg_socket_if_listen_udp ( struct mg_connection nc,
union socket_address sa 
)
static

Definition at line 3903 of file mongoose614.cxx.

3904 {
3906 if (sock == INVALID_SOCKET) return (mg_get_errno() ? mg_get_errno() : 1);
3907 mg_sock_set(nc, sock);
3908 return 0;
3909}
Here is the call graph for this function:

◆ mg_socket_if_poll()

time_t mg_socket_if_poll ( struct mg_iface iface,
int  timeout_ms 
)

Definition at line 4159 of file mongoose614.cxx.

4159 {
4160 struct mg_mgr *mgr = iface->mgr;
4161 double now = mg_time();
4162 double min_timer;
4163 struct mg_connection *nc, *tmp;
4164 struct timeval tv;
4167 int num_fds, num_ev, num_timers = 0;
4168#ifdef __unix__
4169 int try_dup = 1;
4170#endif
4171
4172 FD_ZERO(&read_set);
4174 FD_ZERO(&err_set);
4175#if MG_ENABLE_BROADCAST
4176 mg_add_to_set(mgr->ctl[1], &read_set, &max_fd);
4177#endif
4178
4179 /*
4180 * Note: it is ok to have connections with sock == INVALID_SOCKET in the list,
4181 * e.g. timer-only "connections".
4182 */
4183 min_timer = 0;
4184 for (nc = mgr->active_connections, num_fds = 0; nc != NULL; nc = tmp) {
4185 tmp = nc->next;
4186
4187 if (nc->sock != INVALID_SOCKET) {
4188 num_fds++;
4189
4190#ifdef __unix__
4191 /* A hack to make sure all our file descriptos fit into FD_SETSIZE. */
4192 if (nc->sock >= (sock_t) FD_SETSIZE && try_dup) {
4193 int new_sock = dup(nc->sock);
4194 if (new_sock >= 0) {
4195 if (new_sock < (sock_t) FD_SETSIZE) {
4196 closesocket(nc->sock);
4197 DBG(("new sock %d -> %d", nc->sock, new_sock));
4198 nc->sock = new_sock;
4199 } else {
4201 DBG(("new sock is still larger than FD_SETSIZE, disregard"));
4202 try_dup = 0;
4203 }
4204 } else {
4205 try_dup = 0;
4206 }
4207 }
4208#endif
4209
4210 if (nc->recv_mbuf.len < nc->recv_mbuf_limit &&
4211 (!(nc->flags & MG_F_UDP) || nc->listener == NULL)) {
4213 }
4214
4215 if (((nc->flags & MG_F_CONNECTING) && !(nc->flags & MG_F_WANT_READ)) ||
4216 (nc->send_mbuf.len > 0 && !(nc->flags & MG_F_CONNECTING))) {
4219 }
4220 }
4221
4222 if (nc->ev_timer_time > 0) {
4223 if (num_timers == 0 || nc->ev_timer_time < min_timer) {
4225 }
4226 num_timers++;
4227 }
4228 }
4229
4230 /*
4231 * If there is a timer to be fired earlier than the requested timeout,
4232 * adjust the timeout.
4233 */
4234 if (num_timers > 0) {
4235 double timer_timeout_ms = (min_timer - mg_time()) * 1000 + 1 /* rounding */;
4238 }
4239 }
4240 if (timeout_ms < 0) timeout_ms = 0;
4241
4242 tv.tv_sec = timeout_ms / 1000;
4243 tv.tv_usec = (timeout_ms % 1000) * 1000;
4244
4245 num_ev = select((int) max_fd + 1, &read_set, &write_set, &err_set, &tv);
4246 now = mg_time();
4247#if 0
4248 DBG(("select @ %ld num_ev=%d of %d, timeout=%d", (long) now, num_ev, num_fds,
4249 timeout_ms));
4250#endif
4251
4252#if MG_ENABLE_BROADCAST
4253 if (num_ev > 0 && mgr->ctl[1] != INVALID_SOCKET &&
4254 FD_ISSET(mgr->ctl[1], &read_set)) {
4256 }
4257#endif
4258
4259 for (nc = mgr->active_connections; nc != NULL; nc = tmp) {
4260 int fd_flags = 0;
4261 if (nc->sock != INVALID_SOCKET) {
4262 if (num_ev > 0) {
4263 fd_flags = (FD_ISSET(nc->sock, &read_set) &&
4264 (!(nc->flags & MG_F_UDP) || nc->listener == NULL)
4266 : 0) |
4267 (FD_ISSET(nc->sock, &write_set) ? _MG_F_FD_CAN_WRITE : 0) |
4268 (FD_ISSET(nc->sock, &err_set) ? _MG_F_FD_ERROR : 0);
4269 }
4270#if MG_LWIP
4271 /* With LWIP socket emulation layer, we don't get write events for UDP */
4272 if ((nc->flags & MG_F_UDP) && nc->listener == NULL) {
4274 }
4275#endif
4276 }
4277 tmp = nc->next;
4279 }
4280
4281 return (time_t) now;
4282}
void mg_add_to_set(sock_t sock, fd_set *set, sock_t *max_fd)
static void mg_mgr_handle_ctl_sock(struct mg_mgr *mgr)
Here is the call graph for this function:

◆ mg_socket_if_remove_conn()

void mg_socket_if_remove_conn ( struct mg_connection nc)

Definition at line 4142 of file mongoose614.cxx.

4142 {
4143 (void) nc;
4144}
Here is the call graph for this function:

◆ mg_socket_if_sock_set()

void mg_socket_if_sock_set ( struct mg_connection nc,
sock_t  sock 
)

Definition at line 4119 of file mongoose614.cxx.

4119 {
4122 nc->sock = sock;
4123 DBG(("%p %d", nc, sock));
4124}
void mg_set_close_on_exec(sock_t sock)
Here is the call graph for this function:

◆ mg_socket_if_tcp_recv()

static int mg_socket_if_tcp_recv ( struct mg_connection nc,
void buf,
size_t  len 
)
static

Definition at line 3925 of file mongoose614.cxx.

3926 {
3927 int n = (int) MG_RECV_FUNC(nc->sock, buf, len, 0);
3928 if (n == 0) {
3929 /* Orderly shutdown of the socket, try flushing output. */
3931 } else if (n < 0 && !mg_is_error()) {
3932 n = 0;
3933 }
3934 return n;
3935}
#define MG_RECV_FUNC(s, b, l, f)
Definition mongoose6.h:1186
Here is the call graph for this function:

◆ mg_socket_if_tcp_send()

static int mg_socket_if_tcp_send ( struct mg_connection nc,
const void buf,
size_t  len 
)
static

Definition at line 3911 of file mongoose614.cxx.

3912 {
3913 int n = (int) MG_SEND_FUNC(nc->sock, buf, len, 0);
3914 if (n < 0 && !mg_is_error()) n = 0;
3915 return n;
3916}
#define MG_SEND_FUNC(s, b, l, f)
Definition mongoose6.h:1187
Here is the call graph for this function:

◆ mg_socket_if_udp_recv()

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

Definition at line 3937 of file mongoose614.cxx.

3939 {
3941 int n = recvfrom(nc->sock, buf, len, 0, &sa->sa, &sa_len_st);
3942 *sa_len = sa_len_st;
3943 if (n < 0 && !mg_is_error()) n = 0;
3944 return n;
3945}
Here is the call graph for this function:

◆ mg_socket_if_udp_send()

static int mg_socket_if_udp_send ( struct mg_connection nc,
const void buf,
size_t  len 
)
static

Definition at line 3918 of file mongoose614.cxx.

3919 {
3920 int n = sendto(nc->sock, buf, len, 0, &nc->sa.sa, sizeof(nc->sa.sin));
3921 if (n < 0 && !mg_is_error()) n = 0;
3922 return n;
3923}
Here is the call graph for this function:

◆ mg_start_task()

bool mg_start_task ( int  priority,
int  stack_size,
mg_init_cb  mg_init 
)

Definition at line 14356 of file mongoose614.cxx.

14356 {
14357 if (osi_MsgQCreate(&s_mg_q, "MG", sizeof(struct mg_q_msg), 16) != OSI_OK) {
14358 return false;
14359 }
14360 if (osi_TaskCreate(mg_task, (const signed char *) "MG", stack_size,
14361 (void *) mg_init, priority, NULL) != OSI_OK) {
14362 return false;
14363 }
14364 return true;
14365}
static void mg_task(void *arg)
Here is the call graph for this function:

◆ mg_str_starts_with()

int mg_str_starts_with ( struct mg_str  s,
struct mg_str  prefix 
)

Definition at line 1822 of file mongoose614.cxx.

1822 {
1823 const struct mg_str sp = MG_MK_STR_N(s.p, prefix.len);
1824 if (s.len < prefix.len) return 0;
1825 return (mg_strcmp(sp, prefix) == 0);
1826}
int mg_strcmp(const struct mg_str str1, const struct mg_str str2) WEAK
#define MG_MK_STR_N(str_literal, len)

◆ mg_strchr()

const char * mg_strchr ( const struct mg_str  s,
int  c 
)

Definition at line 1752 of file mongoose614.cxx.

1752 {
1753 size_t i;
1754 for (i = 0; i < s.len; i++) {
1755 if (s.p[i] == c) return &s.p[i];
1756 }
1757 return NULL;
1758}
Here is the caller graph for this function:

◆ mg_strcmp()

int mg_strcmp ( const struct mg_str  str1,
const struct mg_str  str2 
)

Definition at line 1761 of file mongoose614.cxx.

1761 {
1762 size_t i = 0;
1763 while (i < str1.len && i < str2.len) {
1764 if (str1.p[i] < str2.p[i]) return -1;
1765 if (str1.p[i] > str2.p[i]) return 1;
1766 i++;
1767 }
1768 if (i < str1.len) return 1;
1769 if (i < str2.len) return -1;
1770 return 0;
1771}
Here is the caller graph for this function:

◆ mg_strdup()

struct mg_str mg_strdup ( const struct mg_str  s)

Definition at line 1742 of file mongoose614.cxx.

1742 {
1743 return mg_strdup_common(s, 0 /* NUL-terminate */);
1744}
static struct mg_str mg_strdup_common(const struct mg_str s, int nul_terminate)
Here is the caller graph for this function:

◆ mg_strdup_common()

static struct mg_str mg_strdup_common ( const struct mg_str  s,
int  nul_terminate 
)
static

Definition at line 1726 of file mongoose614.cxx.

1727 {
1728 struct mg_str r = {NULL, 0};
1729 if (s.len > 0 && s.p != NULL) {
1730 char *sc = (char *) MG_MALLOC(s.len + (nul_terminate ? 1 : 0));
1731 if (sc != NULL) {
1732 memcpy(sc, s.p, s.len);
1733 if (nul_terminate) sc[s.len] = '\0';
1734 r.p = sc;
1735 r.len = s.len;
1736 }
1737 }
1738 return r;
1739}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_strdup_nul()

struct mg_str mg_strdup_nul ( const struct mg_str  s)

Definition at line 1747 of file mongoose614.cxx.

1747 {
1748 return mg_strdup_common(s, 1 /* NUL-terminate */);
1749}

◆ mg_strfree()

void mg_strfree ( struct mg_str s)

Definition at line 1788 of file mongoose614.cxx.

1788 {
1789 char *sp = (char *) s->p;
1790 s->p = NULL;
1791 s->len = 0;
1792 if (sp != NULL) free(sp);
1793}

◆ mg_strncmp()

int mg_strncmp ( const struct mg_str  str1,
const struct mg_str  str2,
size_t  n 
)

Definition at line 1774 of file mongoose614.cxx.

1774 {
1775 struct mg_str s1 = str1;
1776 struct mg_str s2 = str2;
1777
1778 if (s1.len > n) {
1779 s1.len = n;
1780 }
1781 if (s2.len > n) {
1782 s2.len = n;
1783 }
1784 return mg_strcmp(s1, s2);
1785}

◆ mg_strstr()

const char * mg_strstr ( const struct mg_str  haystack,
const struct mg_str  needle 
)

Definition at line 1797 of file mongoose614.cxx.

1798 {
1799 size_t i;
1800 if (needle.len > haystack.len) return NULL;
1801 for (i = 0; i <= haystack.len - needle.len; i++) {
1802 if (memcmp(haystack.p + i, needle.p, needle.len) == 0) {
1803 return haystack.p + i;
1804 }
1805 }
1806 return NULL;
1807}

◆ mg_strstrip()

struct mg_str mg_strstrip ( struct mg_str  s)

Definition at line 1810 of file mongoose614.cxx.

1810 {
1811 while (s.len > 0 && isspace((int) *s.p)) {
1812 s.p++;
1813 s.len--;
1814 }
1815 while (s.len > 0 && isspace((int) *(s.p + s.len - 1))) {
1816 s.len--;
1817 }
1818 return s;
1819}

◆ mg_task()

static void mg_task ( void arg)
static

Definition at line 14367 of file mongoose614.cxx.

14367 {
14368 struct mg_mgr mgr;
14370 mg_mgr_init(&mgr, NULL);
14371 mg_init(&mgr);
14372 while (1) {
14373 struct mg_q_msg msg;
14374 mg_mgr_poll(&mgr, 1);
14375 if (osi_MsgQRead(&s_mg_q, &msg, 1) != OSI_OK) continue;
14376 switch (msg.type) {
14377 case MG_Q_MSG_CB: {
14378 msg.cb(&mgr, msg.arg);
14379 }
14380 }
14381 }
14382}
int mg_mgr_poll(struct mg_mgr *m, int timeout_ms)
void mg_mgr_init(struct mg_mgr *m, void *user_data)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mg_timer()

MG_INTERNAL void mg_timer ( struct mg_connection c,
double  now 
)

Definition at line 2477 of file mongoose614.cxx.

2477 {
2478 if (c->ev_timer_time > 0 && now >= c->ev_timer_time) {
2479 double old_value = c->ev_timer_time;
2480 c->ev_timer_time = 0;
2481 mg_call(c, NULL, c->user_data, MG_EV_TIMER, &old_value);
2482 }
2483}
#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_url_encode()

struct mg_str mg_url_encode ( const struct mg_str  src)

Definition at line 10795 of file mongoose614.cxx.

10795 {
10796 return mg_url_encode_opt(src, mg_mk_str("._-$,;~()/"), 0);
10797}
struct mg_str mg_url_encode_opt(const struct mg_str src, const struct mg_str safe, unsigned int flags)

◆ mg_url_encode_opt()

struct mg_str mg_url_encode_opt ( const struct mg_str  src,
const struct mg_str  safe,
unsigned int  flags 
)

Definition at line 10769 of file mongoose614.cxx.

10770 {
10771 const char *hex =
10772 (flags & MG_URL_ENCODE_F_UPPERCASE_HEX ? "0123456789ABCDEF"
10773 : "0123456789abcdef");
10774 size_t i = 0;
10775 struct mbuf mb;
10776 mbuf_init(&mb, src.len);
10777
10778 for (i = 0; i < src.len; i++) {
10779 const unsigned char c = *((const unsigned char *) src.p + i);
10780 if (isalnum(c) || mg_strchr(safe, c) != NULL) {
10781 mbuf_append(&mb, &c, 1);
10782 } else if (c == ' ' && (flags & MG_URL_ENCODE_F_SPACE_AS_PLUS)) {
10783 mbuf_append(&mb, "+", 1);
10784 } else {
10785 mbuf_append(&mb, "%", 1);
10786 mbuf_append(&mb, &hex[c >> 4], 1);
10787 mbuf_append(&mb, &hex[c & 15], 1);
10788 }
10789 }
10790 mbuf_append(&mb, "", 1);
10791 mbuf_trim(&mb);
10792 return mg_mk_str_n(mb.buf, mb.len - 1);
10793}
#define MG_URL_ENCODE_F_UPPERCASE_HEX
#define MG_URL_ENCODE_F_SPACE_AS_PLUS

◆ parse_net()

static int parse_net ( const char spec,
uint32_t net,
uint32_t mask 
)
static

Definition at line 3466 of file mongoose614.cxx.

3466 {
3467 int n, a, b, c, d, slash = 32, len = 0;
3468
3469 if ((sscanf(spec, "%d.%d.%d.%d/%d%n", &a, &b, &c, &d, &slash, &n) == 5 ||
3470 sscanf(spec, "%d.%d.%d.%d%n", &a, &b, &c, &d, &n) == 4) &&
3471 isbyte(a) && isbyte(b) && isbyte(c) && isbyte(d) && slash >= 0 &&
3472 slash < 33) {
3473 len = n;
3474 *net =
3475 ((uint32_t) a << 24) | ((uint32_t) b << 16) | ((uint32_t) c << 8) | d;
3476 *mask = slash ? 0xffffffffU << (32 - slash) : 0;
3477 }
3478
3479 return len;
3480}
#define mask(slot)
Definition midas_macro.h:54
static int isbyte(int n)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ parse_uri_component()

static void parse_uri_component ( const char **  p,
const char end,
const char seps,
struct mg_str res 
)
static

Definition at line 5573 of file mongoose614.cxx.

5574 {
5575 const char *q;
5576 res->p = *p;
5577 for (; *p < end; (*p)++) {
5578 for (q = seps; *q != '\0'; q++) {
5579 if (**p == *q) break;
5580 }
5581 if (*q != '\0') break;
5582 }
5583 res->len = (*p) - res->p;
5584 if (*p < end) (*p)++;
5585}
#define end
Here is the call graph for this function:
Here is the caller graph for this function:

◆ recv_avail_size()

MG_INTERNAL size_t recv_avail_size ( struct mg_connection conn,
size_t  max 
)

Definition at line 2485 of file mongoose614.cxx.

2485 {
2486 size_t avail;
2487 if (conn->recv_mbuf_limit < conn->recv_mbuf.len) return 0;
2488 avail = conn->recv_mbuf_limit - conn->recv_mbuf.len;
2489 return avail > max ? max : avail;
2490}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sl_restart_cb()

void sl_restart_cb ( struct mg_mgr mgr)

Definition at line 14812 of file mongoose614.cxx.

14812 {
14813 /*
14814 * SimpleLink has been restarted, meaning all sockets have been invalidated.
14815 * We try our best - we'll restart the listeners, but for outgoing
14816 * connections we have no option but to terminate.
14817 */
14818 struct mg_connection *nc;
14819 for (nc = mg_next(mgr, NULL); nc != NULL; nc = mg_next(mgr, nc)) {
14820 if (nc->sock == INVALID_SOCKET) continue; /* Could be a timer */
14821 if (nc->flags & MG_F_LISTENING) {
14822 DBG(("restarting %p %s:%d", nc, inet_ntoa(nc->sa.sin.sin_addr),
14823 ntohs(nc->sa.sin.sin_port)));
14824 int res = (nc->flags & MG_F_UDP ? mg_sl_if_listen_udp(nc, &nc->sa)
14825 : mg_sl_if_listen_tcp(nc, &nc->sa));
14826 if (res == 0) continue;
14827 /* Well, we tried and failed. Fall through to closing. */
14828 }
14829 nc->sock = INVALID_SOCKET;
14830 DBG(("terminating %p %s:%d", nc, inet_ntoa(nc->sa.sin.sin_addr),
14831 ntohs(nc->sa.sin.sin_port)));
14832 /* TODO(rojer): Outgoing UDP? */
14834 }
14835}
Here is the call graph for this function:

◆ str_util_lowercase()

static int str_util_lowercase ( const char s)
static

Definition at line 2182 of file mongoose614.cxx.

2182 {
2183 return tolower(*(const unsigned char *) s);
2184}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tcp_close_tcpip()

static void tcp_close_tcpip ( void arg)
static

Definition at line 15533 of file mongoose614.cxx.

15533 {
15534 tcp_close((struct tcp_pcb *) arg);
15535}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tcp_output_tcpip()

static void tcp_output_tcpip ( void arg)
static

Definition at line 15653 of file mongoose614.cxx.

15653 {
15654 tcp_output((struct tcp_pcb *) arg);
15655}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ tcp_recved_tcpip()

void tcp_recved_tcpip ( void arg)

Definition at line 15772 of file mongoose614.cxx.

15772 {
15773 struct tcp_recved_ctx *ctx = (struct tcp_recved_ctx *) arg;
15774 if (ctx->tpcb != NULL) tcp_recved(ctx->tpcb, ctx->len);
15775}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ udp_remove_tcpip()

static void udp_remove_tcpip ( void arg)
static

Definition at line 15817 of file mongoose614.cxx.

15817 {
15818 udp_remove((struct udp_pcb *) arg);
15819}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ udp_sendto_tcpip()

static void udp_sendto_tcpip ( void arg)
static

Definition at line 15722 of file mongoose614.cxx.

15722 {
15723 struct udp_sendto_ctx *ctx = (struct udp_sendto_ctx *) arg;
15724 ctx->ret = udp_sendto(ctx->upcb, ctx->p, ctx->ip, ctx->port);
15725}
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ mg_default_iface_vtable

const struct mg_iface_vtable mg_default_iface_vtable = MG_NULL_IFACE_VTABLE

Definition at line 3817 of file mongoose614.cxx.

◆ mg_ifaces

Initial value:
= {
}
const struct mg_iface_vtable mg_default_iface_vtable

Definition at line 3628 of file mongoose614.cxx.

3628 {
3630};

◆ mg_lwip_iface_vtable

Definition at line 15903 of file mongoose614.cxx.

◆ mg_null_iface_vtable

Definition at line 3814 of file mongoose614.cxx.

◆ mg_num_ifaces

int mg_num_ifaces = (int) (sizeof(mg_ifaces) / sizeof(mg_ifaces[0]))

Definition at line 3632 of file mongoose614.cxx.

◆ mg_pic32_iface_vtable

Definition at line 16511 of file mongoose614.cxx.

◆ mg_simplelink_iface_vtable

const struct mg_iface_vtable mg_simplelink_iface_vtable = MG_SL_IFACE_VTABLE

Definition at line 14860 of file mongoose614.cxx.

◆ mg_socket_iface_vtable

Definition at line 4398 of file mongoose614.cxx.

◆ s_mg_q

OsiMsgQ_t s_mg_q
static

Definition at line 14353 of file mongoose614.cxx.

◆ test_calloc

void *(* test_calloc) (size_t count, size_t size) ( size_t  count,
size_t  size 
)
extern

◆ test_malloc

void *(* test_malloc) (size_t size) ( size_t  size)
extern

◆ WEAK

Initial value:

Definition at line 612 of file mongoose614.cxx.