From c839a61fead44555df13b4b67d36febc7ee7b00a Mon Sep 17 00:00:00 2001 From: NickCis Date: Fri, 15 May 2015 16:20:33 -0300 Subject: [PATCH] Adding mg_vprintf and mg_vprintf_data in order to use va_list like functions --- mongoose.c | 26 +++++++++++++++++++++----- mongoose.h | 2 ++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/mongoose.c b/mongoose.c index d7e5246d..dd721b92 100644 --- a/mongoose.c +++ b/mongoose.c @@ -1951,13 +1951,21 @@ static void write_chunk(struct connection *conn, const char *buf, int len) { } size_t mg_printf(struct mg_connection *conn, const char *fmt, ...) { - struct connection *c = MG_CONN_2_CONN(conn); va_list ap; + int ret; va_start(ap, fmt); - ns_vprintf(c->ns_conn, fmt, ap); + ret = mg_vprintf(conn, fmt, ap); va_end(ap); + return ret; +} + +size_t mg_vprintf(struct mg_connection *conn, const char *fmt, va_list ap) { + struct connection *c = MG_CONN_2_CONN(conn); + + ns_vprintf(c->ns_conn, fmt, ap); + return c->ns_conn->send_iobuf.len; } @@ -2790,16 +2798,24 @@ size_t mg_send_data(struct mg_connection *c, const void *data, int data_len) { } size_t mg_printf_data(struct mg_connection *c, const char *fmt, ...) { - struct connection *conn = MG_CONN_2_CONN(c); va_list ap; + int ret; + + va_start(ap, fmt); + ret = mg_vprintf_data(c, fmt, ap); + va_end(ap); + + return ret; +} + +size_t mg_vprintf_data(struct mg_connection *c, const char *fmt, va_list ap) { + struct connection *conn = MG_CONN_2_CONN(c); int len; char mem[IOBUF_SIZE], *buf = mem; terminate_headers(c); - va_start(ap, fmt); len = ns_avprintf(&buf, sizeof(mem), fmt, ap); - va_end(ap); if (len >= 0) { write_chunk((struct connection *) conn, buf, len); diff --git a/mongoose.h b/mongoose.h index 522e92ad..3258e3f4 100644 --- a/mongoose.h +++ b/mongoose.h @@ -104,8 +104,10 @@ void mg_send_status(struct mg_connection *, int status_code); void mg_send_header(struct mg_connection *, const char *name, const char *val); size_t mg_send_data(struct mg_connection *, const void *data, int data_len); size_t mg_printf_data(struct mg_connection *, const char *format, ...); +size_t mg_vprintf_data(struct mg_connection *, const char *format, va_list ap); size_t mg_write(struct mg_connection *, const void *buf, size_t len); size_t mg_printf(struct mg_connection *conn, const char *fmt, ...); +size_t mg_vprintf(struct mg_connection *conn, const char *fmt, va_list ap); size_t mg_websocket_write(struct mg_connection *, int opcode, const char *data, size_t data_len);