diff mbox series

[2/2] mongoose: API adjustments

Message ID 20230124181645.16241-3-daniel@braunwarth.dev
State Accepted
Delegated to: Stefano Babic
Headers show
Series mongoose: update to version 7.9 | expand

Commit Message

Daniel Braunwarth Jan. 24, 2023, 6:16 p.m. UTC
Version 7.9 introduced the following API changes we need to follow:

1. mg_connection::label renamed to ::data

   See https://github.com/cesanta/mongoose/pull/1956

2. mg_straddr removed

   See https://github.com/cesanta/mongoose/pull/1897

Signed-off-by: Daniel Braunwarth <daniel@braunwarth.dev>
---
 mongoose/mongoose_interface.c | 16 ++++++++--------
 mongoose/mongoose_multipart.c |  6 +++---
 2 files changed, 11 insertions(+), 11 deletions(-)
diff mbox series

Patch

diff --git a/mongoose/mongoose_interface.c b/mongoose/mongoose_interface.c
index 465bd51..2f269cf 100644
--- a/mongoose/mongoose_interface.c
+++ b/mongoose/mongoose_interface.c
@@ -362,7 +362,7 @@  static void broadcast_callback(struct mg_connection *nc, int ev,
 	if (ev == MG_EV_READ) {
 		struct mg_connection *t;
 		for (t = nc->mgr->conns; t != NULL; t = t->next) {
-			if (t->label[0] != 'W') continue;
+			if (t->data[0] != 'W') continue;
 			mg_ws_send(t,(char *)nc->recv.buf, nc->recv.len, WEBSOCKET_OP_TEXT);
 		}
 		mg_iobuf_del(&nc->recv, 0, nc->recv.len);
@@ -670,12 +670,12 @@  static void websocket_handler(struct mg_connection *nc, void *ev_data)
 {
 	struct mg_http_message *hm = (struct mg_http_message *) ev_data;
 	mg_ws_upgrade(nc, hm, NULL);
-	nc->label[0] = 'W';
+	nc->data[0] = 'W';
 }
 
 static void ev_handler(struct mg_connection *nc, int ev, void *ev_data, void *fn_data)
 {
-	if (nc->label[0] != 'M' && ev == MG_EV_HTTP_MSG) {
+	if (nc->data[0] != 'M' && ev == MG_EV_HTTP_MSG) {
 		struct mg_http_message *hm = (struct mg_http_message *) ev_data;
 		if (!mg_http_is_authorized(hm, global_auth_domain, global_auth_file))
 			mg_http_send_digest_auth_request(nc, global_auth_domain);
@@ -685,7 +685,7 @@  static void ev_handler(struct mg_connection *nc, int ev, void *ev_data, void *fn
 			restart_handler(nc, ev_data);
 		else
 			mg_http_serve_dir(nc, ev_data, &s_http_server_opts);
-	} else if (nc->label[0] != 'M' && ev == MG_EV_READ) {
+	} else if (nc->data[0] != 'M' && ev == MG_EV_READ) {
 		struct mg_http_message hm;
 		int hlen = mg_http_parse((char *) nc->recv.buf, nc->recv.len, &hm);
 		if (hlen > 0) {
@@ -702,7 +702,7 @@  static void ev_handler(struct mg_connection *nc, int ev, void *ev_data, void *fn
 				}
 			}
 		}
-	} else if (nc->label[0] == 'M' && (ev == MG_EV_READ || ev == MG_EV_POLL || ev == MG_EV_CLOSE)) {
+	} else if (nc->data[0] == 'M' && (ev == MG_EV_READ || ev == MG_EV_POLL || ev == MG_EV_CLOSE)) {
 		if (nc->recv.len >= MG_MAX_RECV_SIZE && ev == MG_EV_READ)
 			nc->is_full = true;
 		multipart_upload_handler(nc, ev, ev_data, fn_data);
@@ -804,7 +804,7 @@  int start_mongoose(const char *cfgfname, int argc, char *argv[])
 	struct mg_mgr mgr;
 	struct mg_connection *nc;
 	char *url = NULL;
-	char buf[50];
+	char buf[50] = "\0";
 	int choice;
 
 #if MG_ENABLE_SSL
@@ -927,9 +927,9 @@  int start_mongoose(const char *cfgfname, int argc, char *argv[])
 	start_thread(broadcast_message_thread, NULL);
 	start_thread(broadcast_progress_thread, NULL);
 
+	mg_snprintf(buf, sizeof(buf), "%I", 4, &nc->loc);
 	INFO("Mongoose web server version %s with pid %d started on [%s] with web root [%s]",
-		MG_VERSION, getpid(), mg_straddr(&nc->loc, buf, sizeof(buf)),
-		s_http_server_opts.root_dir);
+		MG_VERSION, getpid(), buf, s_http_server_opts.root_dir);
 
 	while (s_signo == 0)
 		mg_mgr_poll(&mgr, 100);
diff --git a/mongoose/mongoose_multipart.c b/mongoose/mongoose_multipart.c
index dabfe31..b1741c9 100644
--- a/mongoose/mongoose_multipart.c
+++ b/mongoose/mongoose_multipart.c
@@ -140,7 +140,7 @@  static void mg_http_multipart_finalize(struct mg_connection *c) {
 	mg_http_free_proto_data_mp_stream(mp_stream);
 	mp_stream->state = MPS_FINISHED;
 	free(mp_stream);
-	c->label[0] = '\0';
+	c->data[0] = '\0';
 }
 
 static int mg_http_multipart_wait_for_boundary(struct mg_connection *c) {
@@ -335,11 +335,11 @@  void multipart_upload_handler(struct mg_connection *c, int ev, void *ev_data,
 		s = mg_http_get_header(hm, "Content-Type");
 		if (s != NULL && s->len >= 9 && strncmp(s->ptr, "multipart", 9) == 0) {
 			/* New request - new proto data */
-			c->label[0] = 'M';
+			c->data[0] = 'M';
 
 			mg_http_multipart_begin(c, hm);
 			mg_http_multipart_continue(c);
 			return;
 		}
 	}
-}
\ No newline at end of file
+}