From d7a0757764bf59836acb8371e5c37ae63727f20b Mon Sep 17 00:00:00 2001 From: Simon Goldschmidt Date: Thu, 4 Mar 2021 20:14:46 +0100 Subject: [PATCH] mqtt: allow calling mqtt_set_inpub_callback before mqtt_client_connect See also patch #10037 --- src/apps/mqtt/mqtt.c | 12 +++++++++++- src/include/lwip/apps/mqtt.h | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/apps/mqtt/mqtt.c b/src/apps/mqtt/mqtt.c index 153cf746..8e5c206a 100644 --- a/src/apps/mqtt/mqtt.c +++ b/src/apps/mqtt/mqtt.c @@ -1295,6 +1295,9 @@ mqtt_client_connect(mqtt_client_t *client, const ip_addr_t *ip_addr, u16_t port, u16_t remaining_length = 2 + 4 + 1 + 1 + 2; u8_t flags = 0, will_topic_len = 0, will_msg_len = 0; u16_t client_user_len = 0, client_pass_len = 0; + mqtt_incoming_data_cb_t data_cb; + mqtt_incoming_publish_cb_t pub_cb; + void *inpub_arg; LWIP_ASSERT_CORE_LOCKED(); LWIP_ASSERT("mqtt_client_connect: client != NULL", client != NULL); @@ -1307,8 +1310,15 @@ mqtt_client_connect(mqtt_client_t *client, const ip_addr_t *ip_addr, u16_t port, return ERR_ISCONN; } - /* Wipe clean */ + /* Wipe clean, but keep callbacks */ + data_cb = client->data_cb; + pub_cb = client->pub_cb; + inpub_arg = client->inpub_arg; memset(client, 0, sizeof(mqtt_client_t)); + client->data_cb = data_cb; + client->pub_cb = pub_cb; + client->inpub_arg = inpub_arg; + client->connect_arg = arg; client->connect_cb = cb; client->keep_alive = client_info->keep_alive; diff --git a/src/include/lwip/apps/mqtt.h b/src/include/lwip/apps/mqtt.h index f099812d..bece4005 100644 --- a/src/include/lwip/apps/mqtt.h +++ b/src/include/lwip/apps/mqtt.h @@ -183,7 +183,7 @@ void mqtt_client_free(mqtt_client_t* client); u8_t mqtt_client_is_connected(mqtt_client_t *client); -void mqtt_set_inpub_callback(mqtt_client_t *client, mqtt_incoming_publish_cb_t, +void mqtt_set_inpub_callback(mqtt_client_t *client, mqtt_incoming_publish_cb_t pub_cb, mqtt_incoming_data_cb_t data_cb, void *arg); err_t mqtt_sub_unsub(mqtt_client_t *client, const char *topic, u8_t qos, mqtt_request_cb_t cb, void *arg, u8_t sub);