Skip to content

Commit

Permalink
More precise constness for topics in mosquitto_subscribe_multiple
Browse files Browse the repository at this point in the history
mosquitto_subscribe_multiple and mosquitto_unsubscribe_multiple do not
need to change the characters in the list of topics. Make the signature
more precise to reflect that.

Now works without cast array of const char*, particularly useful for C++
or Rust bindings.

Signed-off-by: Niklas Fiekas <niklas.fiekas@backscattering.de>
  • Loading branch information
niklasf committed Jan 11, 2025
1 parent ba2b98d commit 393d7db
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion client/sub_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ static void my_connect_callback(struct mosquitto *mosq, void *obj, int result, i

connack_result = result;
if(!result){
mosquitto_subscribe_multiple(mosq, NULL, cfg.topic_count, cfg.topics, cfg.qos, cfg.sub_opts, cfg.subscribe_props);
mosquitto_subscribe_multiple(mosq, NULL, cfg.topic_count, (const char* const*)cfg.topics, cfg.qos, cfg.sub_opts, cfg.subscribe_props);

for(i=0; i<cfg.unsub_topic_count; i++){
mosquitto_unsubscribe_v5(mosq, NULL, cfg.unsub_topics[i], cfg.unsubscribe_props);
Expand Down
4 changes: 2 additions & 2 deletions include/mosquitto.h
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,7 @@ libmosq_EXPORT int mosquitto_subscribe_v5(struct mosquitto *mosq, int *mid, cons
* MOSQ_ERR_OVERSIZE_PACKET - if the resulting packet would be larger than
* supported by the broker.
*/
libmosq_EXPORT int mosquitto_subscribe_multiple(struct mosquitto *mosq, int *mid, int sub_count, char *const *const sub, int qos, int options, const mosquitto_property *properties);
libmosq_EXPORT int mosquitto_subscribe_multiple(struct mosquitto *mosq, int *mid, int sub_count, const char* const *sub, int qos, int options, const mosquitto_property *properties);

/*
* Function: mosquitto_unsubscribe
Expand Down Expand Up @@ -1135,7 +1135,7 @@ libmosq_EXPORT int mosquitto_unsubscribe_v5(struct mosquitto *mosq, int *mid, co
* MOSQ_ERR_OVERSIZE_PACKET - if the resulting packet would be larger than
* supported by the broker.
*/
libmosq_EXPORT int mosquitto_unsubscribe_multiple(struct mosquitto *mosq, int *mid, int sub_count, char *const *const sub, const mosquitto_property *properties);
libmosq_EXPORT int mosquitto_unsubscribe_multiple(struct mosquitto *mosq, int *mid, int sub_count, const char* const *sub, const mosquitto_property *properties);


/* ======================================================================
Expand Down
12 changes: 6 additions & 6 deletions lib/actions.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,17 +166,17 @@ int mosquitto_publish_v5(struct mosquitto *mosq, int *mid, const char *topic, in

int mosquitto_subscribe(struct mosquitto *mosq, int *mid, const char *sub, int qos)
{
return mosquitto_subscribe_multiple(mosq, mid, 1, (char *const *const)&sub, qos, 0, NULL);
return mosquitto_subscribe_multiple(mosq, mid, 1, &sub, qos, 0, NULL);
}


int mosquitto_subscribe_v5(struct mosquitto *mosq, int *mid, const char *sub, int qos, int options, const mosquitto_property *properties)
{
return mosquitto_subscribe_multiple(mosq, mid, 1, (char *const *const)&sub, qos, options, properties);
return mosquitto_subscribe_multiple(mosq, mid, 1, &sub, qos, options, properties);
}


int mosquitto_subscribe_multiple(struct mosquitto *mosq, int *mid, int sub_count, char *const *const sub, int qos, int options, const mosquitto_property *properties)
int mosquitto_subscribe_multiple(struct mosquitto *mosq, int *mid, int sub_count, const char* const *sub, int qos, int options, const mosquitto_property *properties)
{
const mosquitto_property *outgoing_properties = NULL;
mosquitto_property local_property;
Expand Down Expand Up @@ -227,15 +227,15 @@ int mosquitto_subscribe_multiple(struct mosquitto *mosq, int *mid, int sub_count

int mosquitto_unsubscribe(struct mosquitto *mosq, int *mid, const char *sub)
{
return mosquitto_unsubscribe_multiple(mosq, mid, 1, (char *const *const)&sub, NULL);
return mosquitto_unsubscribe_multiple(mosq, mid, 1, &sub, NULL);
}

int mosquitto_unsubscribe_v5(struct mosquitto *mosq, int *mid, const char *sub, const mosquitto_property *properties)
{
return mosquitto_unsubscribe_multiple(mosq, mid, 1, (char *const *const)&sub, properties);
return mosquitto_unsubscribe_multiple(mosq, mid, 1, &sub, properties);
}

int mosquitto_unsubscribe_multiple(struct mosquitto *mosq, int *mid, int sub_count, char *const *const sub, const mosquitto_property *properties)
int mosquitto_unsubscribe_multiple(struct mosquitto *mosq, int *mid, int sub_count, const char* const *sub, const mosquitto_property *properties)
{
const mosquitto_property *outgoing_properties = NULL;
mosquitto_property local_property;
Expand Down
4 changes: 2 additions & 2 deletions lib/send_mosq.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ int send__pubcomp(struct mosquitto *mosq, uint16_t mid, const mosquitto_property
int send__publish(struct mosquitto *mosq, uint16_t mid, const char *topic, uint32_t payloadlen, const void *payload, uint8_t qos, bool retain, bool dup, const mosquitto_property *cmsg_props, const mosquitto_property *store_props, uint32_t expiry_interval);
int send__pubrec(struct mosquitto *mosq, uint16_t mid, uint8_t reason_code, const mosquitto_property *properties);
int send__pubrel(struct mosquitto *mosq, uint16_t mid, const mosquitto_property *properties);
int send__subscribe(struct mosquitto *mosq, int *mid, int topic_count, char *const *const topic, int topic_qos, const mosquitto_property *properties);
int send__unsubscribe(struct mosquitto *mosq, int *mid, int topic_count, char *const *const topic, const mosquitto_property *properties);
int send__subscribe(struct mosquitto *mosq, int *mid, int topic_count, const char* const *topic, int topic_qos, const mosquitto_property *properties);
int send__unsubscribe(struct mosquitto *mosq, int *mid, int topic_count, const char* const *topic, const mosquitto_property *properties);

#endif
2 changes: 1 addition & 1 deletion lib/send_subscribe.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
#include "util_mosq.h"


int send__subscribe(struct mosquitto *mosq, int *mid, int topic_count, char *const *const topic, int topic_qos, const mosquitto_property *properties)
int send__subscribe(struct mosquitto *mosq, int *mid, int topic_count, const char* const *topic, int topic_qos, const mosquitto_property *properties)
{
struct mosquitto__packet *packet = NULL;
uint32_t packetlen;
Expand Down
2 changes: 1 addition & 1 deletion lib/send_unsubscribe.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
#include "util_mosq.h"


int send__unsubscribe(struct mosquitto *mosq, int *mid, int topic_count, char *const *const topic, const mosquitto_property *properties)
int send__unsubscribe(struct mosquitto *mosq, int *mid, int topic_count, const char* const *topic, const mosquitto_property *properties)
{
struct mosquitto__packet *packet = NULL;
uint32_t packetlen;
Expand Down
4 changes: 2 additions & 2 deletions src/bridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -546,12 +546,12 @@ int bridge__on_connect(struct mosquitto *context)
| MQTT_SUB_OPT_RETAIN_AS_PUBLISHED
| MQTT_SUB_OPT_SEND_RETAIN_ALWAYS;
}
if(send__subscribe(context, NULL, 1, &context->bridge->topics[i].remote_topic, sub_opts, NULL)){
if(send__subscribe(context, NULL, 1, (const char* const*)&context->bridge->topics[i].remote_topic, sub_opts, NULL)){
return 1;
}
}else{
if(context->bridge->attempt_unsubscribe){
if(send__unsubscribe(context, NULL, 1, &context->bridge->topics[i].remote_topic, NULL)){
if(send__unsubscribe(context, NULL, 1, (const char* const*)&context->bridge->topics[i].remote_topic, NULL)){
/* direction = inwards only. This means we should not be subscribed
* to the topic. It is possible that we used to be subscribed to
* this topic so unsubscribe. */
Expand Down

0 comments on commit 393d7db

Please sign in to comment.