diff --git a/Makefile b/Makefile index 957f5e1a..40161d11 100644 --- a/Makefile +++ b/Makefile @@ -194,7 +194,7 @@ mongoose.c: Makefile $(wildcard src/*.c) $(wildcard src/tcpip/*.c) (cat src/license.h; echo; echo '#include "mongoose.h"' ; (for F in src/*.c src/tcpip/*.c ; do echo; echo '#ifdef MG_ENABLE_LINES'; echo "#line 1 \"$$F\""; echo '#endif'; cat $$F | sed -e 's,#include ".*,,'; done))> $@ mongoose.h: $(HDRS) Makefile - (cat src/license.h; echo; echo '#ifndef MONGOOSE_H'; echo '#define MONGOOSE_H'; echo; cat src/version.h ; echo; echo '#ifdef __cplusplus'; echo 'extern "C" {'; echo '#endif'; cat src/arch.h src/arch_*.h src/net_*.h src/config.h src/str.h src/queue.h src/fmt.h src/log.h src/timer.h src/fs.h src/util.h src/url.h src/iobuf.h src/base64.h src/md5.h src/sha1.h src/event.h src/net.h src/http.h src/ssi.h src/tls.h src/tls_mbed.h src/tls_openssl.h src/ws.h src/sntp.h src/mqtt.h src/dns.h src/json.h src/rpc.h src/tcpip/tcpip.h src/tcpip/driver_*.h | sed -e '/keep/! s,#include ".*,,' -e 's,^#pragma once,,'; echo; echo '#ifdef __cplusplus'; echo '}'; echo '#endif'; echo '#endif // MONGOOSE_H')> $@ + (cat src/license.h; echo; echo '#ifndef MONGOOSE_H'; echo '#define MONGOOSE_H'; echo; cat src/version.h ; echo; echo '#ifdef __cplusplus'; echo 'extern "C" {'; echo '#endif'; cat src/arch.h src/arch_*.h src/net_*.h src/config.h src/str.h src/queue.h src/fmt.h src/printf.h src/log.h src/timer.h src/fs.h src/util.h src/url.h src/iobuf.h src/base64.h src/md5.h src/sha1.h src/event.h src/net.h src/http.h src/ssi.h src/tls.h src/tls_mbed.h src/tls_openssl.h src/ws.h src/sntp.h src/mqtt.h src/dns.h src/json.h src/rpc.h src/tcpip/tcpip.h src/tcpip/driver_*.h | sed -e '/keep/! s,#include ".*,,' -e 's,^#pragma once,,'; echo; echo '#ifdef __cplusplus'; echo '}'; echo '#endif'; echo '#endif // MONGOOSE_H')> $@ clean: clean_examples clean_embedded diff --git a/mongoose.c b/mongoose.c index a4b283a2..2f463d05 100644 --- a/mongoose.c +++ b/mongoose.c @@ -117,6 +117,7 @@ int mg_base64_decode(const char *src, int n, char *dst) { + struct dns_data { struct dns_data *next; struct mg_connection *c; @@ -1305,6 +1306,7 @@ struct mg_fs mg_fs_posix = {p_stat, p_list, p_open, p_close, p_read, + // Chunk deletion marker is the MSB in the "processed" counter #define MG_DMARK ((size_t) 1 << (sizeof(size_t) * 8 - 1)) @@ -3243,6 +3245,7 @@ struct mg_connection *mg_mqtt_listen(struct mg_mgr *mgr, const char *url, + size_t mg_vprintf(struct mg_connection *c, const char *fmt, va_list *ap) { size_t old = c->send.len; mg_vxprintf(mg_pfn_iobuf, &c->send, fmt, ap); @@ -3491,7 +3494,6 @@ void mg_mgr_init(struct mg_mgr *mgr) { - size_t mg_queue_vprintf(struct mg_queue *q, const char *fmt, va_list *ap) { size_t len = mg_snprintf(NULL, 0, fmt, ap); char *buf; @@ -4103,6 +4105,7 @@ struct mg_connection *mg_sntp_connect(struct mg_mgr *mgr, const char *url, + #if MG_ENABLE_SOCKET #ifndef closesocket @@ -5775,6 +5778,7 @@ uint64_t mg_millis(void) { + struct ws_msg { uint8_t flags; size_t header_len; diff --git a/mongoose.h b/mongoose.h index 00f9910b..ee7e8287 100644 --- a/mongoose.h +++ b/mongoose.h @@ -862,14 +862,17 @@ void mg_queue_del(struct mg_queue *, size_t); // Delete oldest message - - typedef void (*mg_pfn_t)(char, void *); // Output function typedef size_t (*mg_pm_t)(mg_pfn_t, void *, va_list *); // %M printer size_t mg_vxprintf(void (*)(char, void *), void *, const char *fmt, va_list *); size_t mg_xprintf(void (*fn)(char, void *), void *, const char *fmt, ...); + + + + + // Convenience wrappers around mg_xprintf size_t mg_vsnprintf(char *buf, size_t len, const char *fmt, va_list *ap); size_t mg_snprintf(char *, size_t, const char *fmt, ...); @@ -989,7 +992,6 @@ bool mg_file_printf(struct mg_fs *fs, const char *path, const char *fmt, ...); - #if MG_ENABLE_ASSERT #include #elif !defined(assert) diff --git a/src/dns.c b/src/dns.c index f7c7851d..65745240 100644 --- a/src/dns.c +++ b/src/dns.c @@ -1,5 +1,6 @@ #include "dns.h" #include "log.h" +#include "printf.h" #include "str.h" #include "timer.h" #include "url.h" diff --git a/src/event.c b/src/event.c index fd5e2432..3d14767b 100644 --- a/src/event.c +++ b/src/event.c @@ -1,7 +1,7 @@ #include "event.h" -#include "fmt.h" #include "log.h" #include "net.h" +#include "printf.h" void mg_call(struct mg_connection *c, int ev, void *ev_data) { // Run user-defined handler first, in order to give it an ability diff --git a/src/fmt.c b/src/fmt.c index f8697084..7fb5fe69 100644 --- a/src/fmt.c +++ b/src/fmt.c @@ -1,5 +1,5 @@ #include "fmt.h" -#include "iobuf.h" +#include "printf.h" #include "util.h" static bool is_digit(int c) { return c >= '0' && c <= '9'; } diff --git a/src/fmt.h b/src/fmt.h index b9afee3c..b3030d27 100644 --- a/src/fmt.h +++ b/src/fmt.h @@ -1,30 +1,9 @@ #pragma once #include "arch.h" -#include "iobuf.h" -#include "queue.h" typedef void (*mg_pfn_t)(char, void *); // Output function typedef size_t (*mg_pm_t)(mg_pfn_t, void *, va_list *); // %M printer size_t mg_vxprintf(void (*)(char, void *), void *, const char *fmt, va_list *); size_t mg_xprintf(void (*fn)(char, void *), void *, const char *fmt, ...); - -// Convenience wrappers around mg_xprintf -size_t mg_vsnprintf(char *buf, size_t len, const char *fmt, va_list *ap); -size_t mg_snprintf(char *, size_t, const char *fmt, ...); -char *mg_vmprintf(const char *fmt, va_list *ap); -char *mg_mprintf(const char *fmt, ...); -size_t mg_queue_vprintf(struct mg_queue *, const char *fmt, va_list *); -size_t mg_queue_printf(struct mg_queue *, const char *fmt, ...); - -// %M print helper functions -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_ip4(void (*out)(char, void *), void *arg, va_list *ap); -size_t mg_print_ip6(void (*out)(char, void *), void *arg, va_list *ap); -size_t mg_print_mac(void (*out)(char, void *), void *arg, va_list *ap); - -// Various output functions -void mg_pfn_iobuf(char ch, void *param); // param: struct mg_iobuf * -void mg_pfn_stdout(char c, void *param); // param: ignored diff --git a/src/fs.c b/src/fs.c index df74754a..00eeb0ed 100644 --- a/src/fs.c +++ b/src/fs.c @@ -1,5 +1,5 @@ #include "fs.h" -#include "fmt.h" +#include "printf.h" struct mg_fd *mg_fs_open(struct mg_fs *fs, const char *path, int flags) { struct mg_fd *fd = (struct mg_fd *) calloc(1, sizeof(*fd)); diff --git a/src/fs_packed.c b/src/fs_packed.c index ef285e3b..70908193 100644 --- a/src/fs_packed.c +++ b/src/fs_packed.c @@ -1,5 +1,5 @@ -#include "fmt.h" #include "fs.h" +#include "printf.h" #include "str.h" struct packed_file { diff --git a/src/http.c b/src/http.c index e36ef25d..c63a051c 100644 --- a/src/http.c +++ b/src/http.c @@ -5,6 +5,7 @@ #include "json.h" #include "log.h" #include "net.h" +#include "printf.h" #include "ssi.h" #include "util.h" #include "version.h" diff --git a/src/net.c b/src/net.c index 82794dbb..285e46bf 100644 --- a/src/net.c +++ b/src/net.c @@ -2,6 +2,7 @@ #include "fmt.h" #include "log.h" #include "net.h" +#include "printf.h" #include "timer.h" #include "tls.h" diff --git a/src/printf.c b/src/printf.c index 5d0cd9c2..34e8fd37 100644 --- a/src/printf.c +++ b/src/printf.c @@ -1,6 +1,5 @@ #include "fmt.h" -#include "iobuf.h" -#include "queue.h" +#include "printf.h" #include "util.h" size_t mg_queue_vprintf(struct mg_queue *q, const char *fmt, va_list *ap) { diff --git a/src/printf.h b/src/printf.h new file mode 100644 index 00000000..cb29fcad --- /dev/null +++ b/src/printf.h @@ -0,0 +1,24 @@ +#pragma once + +#include "arch.h" +#include "iobuf.h" +#include "queue.h" + +// Convenience wrappers around mg_xprintf +size_t mg_vsnprintf(char *buf, size_t len, const char *fmt, va_list *ap); +size_t mg_snprintf(char *, size_t, const char *fmt, ...); +char *mg_vmprintf(const char *fmt, va_list *ap); +char *mg_mprintf(const char *fmt, ...); +size_t mg_queue_vprintf(struct mg_queue *, const char *fmt, va_list *); +size_t mg_queue_printf(struct mg_queue *, const char *fmt, ...); + +// %M print helper functions +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_ip4(void (*out)(char, void *), void *arg, va_list *ap); +size_t mg_print_ip6(void (*out)(char, void *), void *arg, va_list *ap); +size_t mg_print_mac(void (*out)(char, void *), void *arg, va_list *ap); + +// Various output functions +void mg_pfn_iobuf(char ch, void *param); // param: struct mg_iobuf * +void mg_pfn_stdout(char c, void *param); // param: ignored diff --git a/src/sock.c b/src/sock.c index c5088b92..1a8da89e 100644 --- a/src/sock.c +++ b/src/sock.c @@ -2,6 +2,7 @@ #include "event.h" #include "log.h" #include "net.h" +#include "printf.h" #include "str.h" #include "timer.h" #include "tls.h" diff --git a/src/ssi.c b/src/ssi.c index 928827b5..765a50de 100644 --- a/src/ssi.c +++ b/src/ssi.c @@ -1,6 +1,6 @@ -#include "ssi.h" -#include "fmt.h" #include "log.h" +#include "printf.h" +#include "ssi.h" #ifndef MG_MAX_SSI_DEPTH #define MG_MAX_SSI_DEPTH 5 diff --git a/src/tls_mbed.c b/src/tls_mbed.c index 218e93c9..5f3241cb 100644 --- a/src/tls_mbed.c +++ b/src/tls_mbed.c @@ -1,5 +1,5 @@ -#include "fmt.h" #include "fs.h" +#include "printf.h" #include "tls.h" #if MG_ENABLE_MBEDTLS diff --git a/src/tls_openssl.c b/src/tls_openssl.c index b6b3e2b0..cbc3cbc7 100644 --- a/src/tls_openssl.c +++ b/src/tls_openssl.c @@ -1,4 +1,4 @@ -#include "fmt.h" +#include "printf.h" #include "tls.h" #if MG_ENABLE_OPENSSL diff --git a/src/util.h b/src/util.h index ccce7d9b..60c4fc0b 100644 --- a/src/util.h +++ b/src/util.h @@ -2,7 +2,6 @@ #include "arch.h" #include "config.h" -#include "fmt.h" #include "net.h" #include "str.h" diff --git a/src/ws.c b/src/ws.c index f836cc7f..5c57fed2 100644 --- a/src/ws.c +++ b/src/ws.c @@ -4,6 +4,7 @@ #include "fmt.h" #include "http.h" #include "log.h" +#include "printf.h" #include "sha1.h" #include "url.h" #include "util.h"