From cf9a72d8dbe463c0b87a448fc5843b0891154bd3 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Thu, 27 Sep 2018 22:05:15 +0100 Subject: [PATCH] Add mosquitto_subscribe_multiple. --- lib/actions.c | 19 ++++++++++++++++++- lib/linker.version | 5 +++++ lib/mosquitto.h | 24 ++++++++++++++++++++++++ lib/send_mosq.h | 2 +- lib/send_subscribe.c | 21 ++++++++++++++------- src/handle_connack.c | 2 +- 6 files changed, 63 insertions(+), 10 deletions(-) diff --git a/lib/actions.c b/lib/actions.c index 5e50dbe5..5883fc70 100644 --- a/lib/actions.c +++ b/lib/actions.c @@ -105,7 +105,24 @@ int mosquitto_subscribe(struct mosquitto *mosq, int *mid, const char *sub, int q if(mosquitto_sub_topic_check(sub)) return MOSQ_ERR_INVAL; if(mosquitto_validate_utf8(sub, strlen(sub))) return MOSQ_ERR_MALFORMED_UTF8; - return send__subscribe(mosq, mid, sub, qos); + return send__subscribe(mosq, mid, 1, &sub, qos); +} + + +int mosquitto_subscribe_multiple(struct mosquitto *mosq, int *mid, int sub_count, const char **sub, int qos) +{ + int i; + + if(!mosq || !sub_count || !sub) return MOSQ_ERR_INVAL; + if(qos < 0 || qos > 2) return MOSQ_ERR_INVAL; + if(mosq->sock == INVALID_SOCKET) return MOSQ_ERR_NO_CONN; + + for(i=0; icommand = SUBSCRIBE | (1<<1); packet->remaining_length = packetlen; @@ -60,15 +63,19 @@ int send__subscribe(struct mosquitto *mosq, int *mid, const char *topic, uint8_t packet__write_uint16(packet, local_mid); /* Payload */ - packet__write_string(packet, topic, strlen(topic)); - packet__write_byte(packet, topic_qos); + for(i=0; iid, local_mid, topic, topic_qos); + log__printf(mosq, MOSQ_LOG_DEBUG, "Bridge %s sending SUBSCRIBE (Mid: %d, Topic: %s, QoS: %d)", mosq->id, local_mid, topic[0], topic_qos); # endif #else - log__printf(mosq, MOSQ_LOG_DEBUG, "Client %s sending SUBSCRIBE (Mid: %d, Topic: %s, QoS: %d)", mosq->id, local_mid, topic, topic_qos); + for(i=0; iid, local_mid, topic[i], topic_qos); + } #endif return packet__queue(mosq, packet); diff --git a/src/handle_connack.c b/src/handle_connack.c index 14b053eb..3194a61a 100644 --- a/src/handle_connack.c +++ b/src/handle_connack.c @@ -75,7 +75,7 @@ int handle__connack(struct mosquitto_db *db, struct mosquitto *context) } for(i=0; ibridge->topic_count; i++){ if(context->bridge->topics[i].direction == bd_in || context->bridge->topics[i].direction == bd_both){ - if(send__subscribe(context, NULL, context->bridge->topics[i].remote_topic, context->bridge->topics[i].qos)){ + if(send__subscribe(context, NULL, 1, &context->bridge->topics[i].remote_topic, &context->bridge->topics[i].qos)){ return 1; } }else{