From 098a1c8ecfa9f2dd3042bf8cdac2ed3bb434ff30 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Thu, 4 Oct 2018 09:46:51 +0100 Subject: [PATCH] Fix subscribe_multiple datatypes. --- client/sub_client.c | 2 +- lib/actions.c | 4 ++-- lib/mosquitto.h | 6 +++++- lib/send_mosq.h | 2 +- src/handle_connack.c | 2 +- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/client/sub_client.c b/client/sub_client.c index 9ed88735c5..95120cd0ce 100644 --- a/client/sub_client.c +++ b/client/sub_client.c @@ -96,7 +96,7 @@ void my_connect_callback(struct mosquitto *mosq, void *obj, int result, int flag cfg = (struct mosq_config *)obj; if(!result){ - mosquitto_subscribe_multiple(mosq, NULL, cfg->topic_count, (const char **)cfg->topics, cfg->qos); + mosquitto_subscribe_multiple(mosq, NULL, cfg->topic_count, cfg->topics, cfg->qos); for(i=0; iunsub_topic_count; i++){ mosquitto_unsubscribe(mosq, NULL, cfg->unsub_topics[i]); diff --git a/lib/actions.c b/lib/actions.c index 5883fc7048..f994c6a9d1 100644 --- a/lib/actions.c +++ b/lib/actions.c @@ -105,11 +105,11 @@ 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, 1, &sub, qos); + return send__subscribe(mosq, mid, 1, (char *const *const)&sub, qos); } -int mosquitto_subscribe_multiple(struct mosquitto *mosq, int *mid, int sub_count, const char **sub, int qos) +int mosquitto_subscribe_multiple(struct mosquitto *mosq, int *mid, int sub_count, char *const *const sub, int qos) { int i; diff --git a/lib/mosquitto.h b/lib/mosquitto.h index 98ccef14c5..521cfa07be 100644 --- a/lib/mosquitto.h +++ b/lib/mosquitto.h @@ -645,6 +645,10 @@ libmosq_EXPORT int mosquitto_subscribe(struct mosquitto *mosq, int *mid, const c * sent. * sub_count - the count of subscriptions to be made * sub - array of sub_count pointers, each pointing to a subscription string. + * The "char *const *const" datatype ensures that neither the array of + * pointers nor the strings that they point to are mutable. If you aren't + * familiar with this, just think of it as a safer "char **", + * equivalent to "const char *" for a simple string pointer. * qos - the requested Quality of Service for each subscription. * * Returns: @@ -654,7 +658,7 @@ libmosq_EXPORT int mosquitto_subscribe(struct mosquitto *mosq, int *mid, const c * MOSQ_ERR_NO_CONN - if the client isn't connected to a broker. * MOSQ_ERR_MALFORMED_UTF8 - if a topic is not valid UTF-8 */ -int mosquitto_subscribe_multiple(struct mosquitto *mosq, int *mid, int sub_count, const char **sub, int qos); +int mosquitto_subscribe_multiple(struct mosquitto *mosq, int *mid, int sub_count, char *const *const sub, int qos); /* * Function: mosquitto_unsubscribe diff --git a/lib/send_mosq.h b/lib/send_mosq.h index c04f3c3f78..35645952dd 100644 --- a/lib/send_mosq.h +++ b/lib/send_mosq.h @@ -31,7 +31,7 @@ int send__pubcomp(struct mosquitto *mosq, uint16_t mid); int send__publish(struct mosquitto *mosq, uint16_t mid, const char *topic, uint32_t payloadlen, const void *payload, int qos, bool retain, bool dup); int send__pubrec(struct mosquitto *mosq, uint16_t mid); int send__pubrel(struct mosquitto *mosq, uint16_t mid); -int send__subscribe(struct mosquitto *mosq, int *mid, int topic_count, const char **topic, int topic_qos); +int send__subscribe(struct mosquitto *mosq, int *mid, int topic_count, char *const *const topic, int topic_qos); int send__unsubscribe(struct mosquitto *mosq, int *mid, const char *topic); #endif diff --git a/src/handle_connack.c b/src/handle_connack.c index de45a40908..3257ea4414 100644 --- a/src/handle_connack.c +++ b/src/handle_connack.c @@ -76,7 +76,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, 1, &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{