mirror of
https://github.com/cesanta/mongoose.git
synced 2025-01-15 02:08:08 +08:00
commit
4dd51cc889
50
mongoose.c
50
mongoose.c
@ -3517,25 +3517,6 @@ struct mg_timer *mg_timer_add(struct mg_mgr *mgr, uint64_t milliseconds,
|
|||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t mg_print_ip(void (*out)(char, void *), void *arg, va_list *ap) {
|
|
||||||
struct mg_addr *addr = va_arg(*ap, struct mg_addr *);
|
|
||||||
if (addr->is_ip6) {
|
|
||||||
uint16_t *p = (uint16_t *) addr->ip6;
|
|
||||||
return mg_xprintf(out, arg, "[%x:%x:%x:%x:%x:%x:%x:%x]", mg_htons(p[0]),
|
|
||||||
mg_htons(p[1]), mg_htons(p[2]), mg_htons(p[3]),
|
|
||||||
mg_htons(p[4]), mg_htons(p[5]), mg_htons(p[6]),
|
|
||||||
mg_htons(p[7]));
|
|
||||||
} else {
|
|
||||||
uint8_t *p = (uint8_t *) &addr->ip;
|
|
||||||
return mg_xprintf(out, arg, "%d.%d.%d.%d", p[0], p[1], p[2], p[3]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t mg_print_ip_port(void (*out)(char, void *), void *arg, va_list *ap) {
|
|
||||||
struct mg_addr *a = va_arg(*ap, struct mg_addr *);
|
|
||||||
return mg_xprintf(out, arg, "%M:%hu", mg_print_ip, a, mg_ntohs(a->port));
|
|
||||||
}
|
|
||||||
|
|
||||||
void mg_mgr_free(struct mg_mgr *mgr) {
|
void mg_mgr_free(struct mg_mgr *mgr) {
|
||||||
struct mg_connection *c;
|
struct mg_connection *c;
|
||||||
struct mg_timer *tmp, *t = mgr->timers;
|
struct mg_timer *tmp, *t = mgr->timers;
|
||||||
@ -5352,6 +5333,7 @@ void mg_tls_init(struct mg_connection *c, const struct mg_tls_opts *opts) {
|
|||||||
if (opts->srvname.len > 0) {
|
if (opts->srvname.len > 0) {
|
||||||
char *s = mg_mprintf("%.*s", (int) opts->srvname.len, opts->srvname.ptr);
|
char *s = mg_mprintf("%.*s", (int) opts->srvname.len, opts->srvname.ptr);
|
||||||
SSL_set1_host(tls->ssl, s);
|
SSL_set1_host(tls->ssl, s);
|
||||||
|
SSL_set_tlsext_host_name(tls->ssl, s);
|
||||||
free(s);
|
free(s);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -5595,6 +5577,31 @@ int mg_check_ip_acl(struct mg_str acl, uint32_t remote_ip) {
|
|||||||
return allowed == '+';
|
return allowed == '+';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t mg_print_ip(void (*out)(char, void *), void *arg, va_list *ap) {
|
||||||
|
struct mg_addr *addr = va_arg(*ap, struct mg_addr *);
|
||||||
|
if (addr->is_ip6) {
|
||||||
|
uint16_t *p = (uint16_t *) addr->ip6;
|
||||||
|
return mg_xprintf(out, arg, "[%x:%x:%x:%x:%x:%x:%x:%x]", mg_ntohs(p[0]),
|
||||||
|
mg_ntohs(p[1]), mg_ntohs(p[2]), mg_ntohs(p[3]),
|
||||||
|
mg_ntohs(p[4]), mg_ntohs(p[5]), mg_ntohs(p[6]),
|
||||||
|
mg_ntohs(p[7]));
|
||||||
|
} else {
|
||||||
|
uint8_t *p = (uint8_t *) &addr->ip;
|
||||||
|
return mg_xprintf(out, arg, "%d.%d.%d.%d", p[0], p[1], p[2], p[3]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t mg_print_ip_port(void (*out)(char, void *), void *arg, va_list *ap) {
|
||||||
|
struct mg_addr *a = va_arg(*ap, struct mg_addr *);
|
||||||
|
return mg_xprintf(out, arg, "%M:%hu", mg_print_ip, a, mg_ntohs(a->port));
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t mg_print_mac(void (*out)(char, void *), void *arg, va_list *ap) {
|
||||||
|
uint8_t *p = va_arg(*ap, uint8_t *);
|
||||||
|
return mg_xprintf(out, arg, "%02x:%02x:%02x:%02x:%02x:%02x", p[0], p[1], p[2],
|
||||||
|
p[3], p[4], p[5]);
|
||||||
|
}
|
||||||
|
|
||||||
#if MG_ENABLE_CUSTOM_MILLIS
|
#if MG_ENABLE_CUSTOM_MILLIS
|
||||||
#else
|
#else
|
||||||
uint64_t mg_millis(void) {
|
uint64_t mg_millis(void) {
|
||||||
@ -6110,7 +6117,6 @@ static size_t mip_driver_stm32_tx(const void *buf, size_t len, struct mip_if *if
|
|||||||
s_txdesc[s_txno][0] = BIT(20) | BIT(28) | BIT(29) | BIT(30); // Chain,FS,LS
|
s_txdesc[s_txno][0] = BIT(20) | BIT(28) | BIT(29) | BIT(30); // Chain,FS,LS
|
||||||
s_txdesc[s_txno][0] |= BIT(31); // Set OWN bit - let DMA take over
|
s_txdesc[s_txno][0] |= BIT(31); // Set OWN bit - let DMA take over
|
||||||
if (++s_txno >= ETH_DESC_CNT) s_txno = 0;
|
if (++s_txno >= ETH_DESC_CNT) s_txno = 0;
|
||||||
printf("sent\n");
|
|
||||||
}
|
}
|
||||||
ETH->DMASR = BIT(2) | BIT(5); // Clear any prior TBUS/TUS
|
ETH->DMASR = BIT(2) | BIT(5); // Clear any prior TBUS/TUS
|
||||||
ETH->DMATPDR = 0; // and resume
|
ETH->DMATPDR = 0; // and resume
|
||||||
@ -6124,11 +6130,9 @@ static bool mip_driver_stm32_up(struct mip_if *ifp) {
|
|||||||
return bsr & BIT(2) ? 1 : 0;
|
return bsr & BIT(2) ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t s_rxno;
|
|
||||||
void ETH_IRQHandler(void);
|
void ETH_IRQHandler(void);
|
||||||
|
static uint32_t s_rxno;
|
||||||
void ETH_IRQHandler(void) {
|
void ETH_IRQHandler(void) {
|
||||||
static int cnt;
|
|
||||||
printf("--> %d\n", cnt++);
|
|
||||||
qp_mark(QP_IRQTRIGGERED, 0);
|
qp_mark(QP_IRQTRIGGERED, 0);
|
||||||
if (ETH->DMASR & BIT(6)) { // Frame received, loop
|
if (ETH->DMASR & BIT(6)) { // Frame received, loop
|
||||||
ETH->DMASR = BIT(16) | BIT(6); // Clear flag
|
ETH->DMASR = BIT(16) | BIT(6); // Clear flag
|
||||||
|
@ -886,6 +886,8 @@ bool mg_file_printf(struct mg_fs *fs, const char *path, const char *fmt, ...);
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void mg_random(void *buf, size_t len);
|
void mg_random(void *buf, size_t len);
|
||||||
char *mg_random_str(char *buf, size_t len);
|
char *mg_random_str(char *buf, size_t len);
|
||||||
uint16_t mg_ntohs(uint16_t net);
|
uint16_t mg_ntohs(uint16_t net);
|
||||||
@ -905,6 +907,10 @@ uint64_t mg_millis(void);
|
|||||||
#define MG_IPADDR_PARTS(ADDR) \
|
#define MG_IPADDR_PARTS(ADDR) \
|
||||||
MG_U8P(ADDR)[0], MG_U8P(ADDR)[1], MG_U8P(ADDR)[2], MG_U8P(ADDR)[3]
|
MG_U8P(ADDR)[0], MG_U8P(ADDR)[1], MG_U8P(ADDR)[2], MG_U8P(ADDR)[3]
|
||||||
|
|
||||||
|
size_t mg_print_ip(void (*out)(char, void *), void *arg, va_list *ap);
|
||||||
|
size_t mg_print_ip_port(void (*out)(char, void *), void *arg, va_list *ap);
|
||||||
|
size_t mg_print_mac(void (*out)(char, void *), void *arg, va_list *ap);
|
||||||
|
|
||||||
// Linked list management macros
|
// Linked list management macros
|
||||||
#define LIST_ADD_HEAD(type_, head_, elem_) \
|
#define LIST_ADD_HEAD(type_, head_, elem_) \
|
||||||
do { \
|
do { \
|
||||||
@ -1111,8 +1117,6 @@ bool mg_open_listener(struct mg_connection *c, const char *url);
|
|||||||
// Utility functions
|
// Utility functions
|
||||||
struct mg_timer *mg_timer_add(struct mg_mgr *mgr, uint64_t milliseconds,
|
struct mg_timer *mg_timer_add(struct mg_mgr *mgr, uint64_t milliseconds,
|
||||||
unsigned flags, void (*fn)(void *), void *arg);
|
unsigned flags, void (*fn)(void *), void *arg);
|
||||||
size_t mg_print_ip(void (*out)(char, void *), void *ptr, va_list *ap);
|
|
||||||
size_t mg_print_ip_port(void (*out)(char, void *), void *ptr, va_list *ap);
|
|
||||||
|
|
||||||
// Low-level IO primives used by TLS layer
|
// Low-level IO primives used by TLS layer
|
||||||
enum { MG_IO_ERR = -1, MG_IO_WAIT = -2, MG_IO_RESET = -3 };
|
enum { MG_IO_ERR = -1, MG_IO_WAIT = -2, MG_IO_RESET = -3 };
|
||||||
|
19
src/net.c
19
src/net.c
@ -207,25 +207,6 @@ struct mg_timer *mg_timer_add(struct mg_mgr *mgr, uint64_t milliseconds,
|
|||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t mg_print_ip(void (*out)(char, void *), void *arg, va_list *ap) {
|
|
||||||
struct mg_addr *addr = va_arg(*ap, struct mg_addr *);
|
|
||||||
if (addr->is_ip6) {
|
|
||||||
uint16_t *p = (uint16_t *) addr->ip6;
|
|
||||||
return mg_xprintf(out, arg, "[%x:%x:%x:%x:%x:%x:%x:%x]", mg_htons(p[0]),
|
|
||||||
mg_htons(p[1]), mg_htons(p[2]), mg_htons(p[3]),
|
|
||||||
mg_htons(p[4]), mg_htons(p[5]), mg_htons(p[6]),
|
|
||||||
mg_htons(p[7]));
|
|
||||||
} else {
|
|
||||||
uint8_t *p = (uint8_t *) &addr->ip;
|
|
||||||
return mg_xprintf(out, arg, "%d.%d.%d.%d", p[0], p[1], p[2], p[3]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t mg_print_ip_port(void (*out)(char, void *), void *arg, va_list *ap) {
|
|
||||||
struct mg_addr *a = va_arg(*ap, struct mg_addr *);
|
|
||||||
return mg_xprintf(out, arg, "%M:%hu", mg_print_ip, a, mg_ntohs(a->port));
|
|
||||||
}
|
|
||||||
|
|
||||||
void mg_mgr_free(struct mg_mgr *mgr) {
|
void mg_mgr_free(struct mg_mgr *mgr) {
|
||||||
struct mg_connection *c;
|
struct mg_connection *c;
|
||||||
struct mg_timer *tmp, *t = mgr->timers;
|
struct mg_timer *tmp, *t = mgr->timers;
|
||||||
|
@ -98,8 +98,6 @@ bool mg_open_listener(struct mg_connection *c, const char *url);
|
|||||||
// Utility functions
|
// Utility functions
|
||||||
struct mg_timer *mg_timer_add(struct mg_mgr *mgr, uint64_t milliseconds,
|
struct mg_timer *mg_timer_add(struct mg_mgr *mgr, uint64_t milliseconds,
|
||||||
unsigned flags, void (*fn)(void *), void *arg);
|
unsigned flags, void (*fn)(void *), void *arg);
|
||||||
size_t mg_print_ip(void (*out)(char, void *), void *ptr, va_list *ap);
|
|
||||||
size_t mg_print_ip_port(void (*out)(char, void *), void *ptr, va_list *ap);
|
|
||||||
|
|
||||||
// Low-level IO primives used by TLS layer
|
// Low-level IO primives used by TLS layer
|
||||||
enum { MG_IO_ERR = -1, MG_IO_WAIT = -2, MG_IO_RESET = -3 };
|
enum { MG_IO_ERR = -1, MG_IO_WAIT = -2, MG_IO_RESET = -3 };
|
||||||
|
25
src/util.c
25
src/util.c
@ -87,6 +87,31 @@ int mg_check_ip_acl(struct mg_str acl, uint32_t remote_ip) {
|
|||||||
return allowed == '+';
|
return allowed == '+';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t mg_print_ip(void (*out)(char, void *), void *arg, va_list *ap) {
|
||||||
|
struct mg_addr *addr = va_arg(*ap, struct mg_addr *);
|
||||||
|
if (addr->is_ip6) {
|
||||||
|
uint16_t *p = (uint16_t *) addr->ip6;
|
||||||
|
return mg_xprintf(out, arg, "[%x:%x:%x:%x:%x:%x:%x:%x]", mg_ntohs(p[0]),
|
||||||
|
mg_ntohs(p[1]), mg_ntohs(p[2]), mg_ntohs(p[3]),
|
||||||
|
mg_ntohs(p[4]), mg_ntohs(p[5]), mg_ntohs(p[6]),
|
||||||
|
mg_ntohs(p[7]));
|
||||||
|
} else {
|
||||||
|
uint8_t *p = (uint8_t *) &addr->ip;
|
||||||
|
return mg_xprintf(out, arg, "%d.%d.%d.%d", p[0], p[1], p[2], p[3]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t mg_print_ip_port(void (*out)(char, void *), void *arg, va_list *ap) {
|
||||||
|
struct mg_addr *a = va_arg(*ap, struct mg_addr *);
|
||||||
|
return mg_xprintf(out, arg, "%M:%hu", mg_print_ip, a, mg_ntohs(a->port));
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t mg_print_mac(void (*out)(char, void *), void *arg, va_list *ap) {
|
||||||
|
uint8_t *p = va_arg(*ap, uint8_t *);
|
||||||
|
return mg_xprintf(out, arg, "%02x:%02x:%02x:%02x:%02x:%02x", p[0], p[1], p[2],
|
||||||
|
p[3], p[4], p[5]);
|
||||||
|
}
|
||||||
|
|
||||||
#if MG_ENABLE_CUSTOM_MILLIS
|
#if MG_ENABLE_CUSTOM_MILLIS
|
||||||
#else
|
#else
|
||||||
uint64_t mg_millis(void) {
|
uint64_t mg_millis(void) {
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
#include "arch.h"
|
#include "arch.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include "fmt.h"
|
||||||
|
#include "net.h"
|
||||||
#include "str.h"
|
#include "str.h"
|
||||||
|
|
||||||
void mg_random(void *buf, size_t len);
|
void mg_random(void *buf, size_t len);
|
||||||
@ -23,6 +25,10 @@ uint64_t mg_millis(void);
|
|||||||
#define MG_IPADDR_PARTS(ADDR) \
|
#define MG_IPADDR_PARTS(ADDR) \
|
||||||
MG_U8P(ADDR)[0], MG_U8P(ADDR)[1], MG_U8P(ADDR)[2], MG_U8P(ADDR)[3]
|
MG_U8P(ADDR)[0], MG_U8P(ADDR)[1], MG_U8P(ADDR)[2], MG_U8P(ADDR)[3]
|
||||||
|
|
||||||
|
size_t mg_print_ip(void (*out)(char, void *), void *arg, va_list *ap);
|
||||||
|
size_t mg_print_ip_port(void (*out)(char, void *), void *arg, va_list *ap);
|
||||||
|
size_t mg_print_mac(void (*out)(char, void *), void *arg, va_list *ap);
|
||||||
|
|
||||||
// Linked list management macros
|
// Linked list management macros
|
||||||
#define LIST_ADD_HEAD(type_, head_, elem_) \
|
#define LIST_ADD_HEAD(type_, head_, elem_) \
|
||||||
do { \
|
do { \
|
||||||
|
Loading…
x
Reference in New Issue
Block a user