Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More precise constness for topics in mosquitto_subscribe_multiple #3199

Open
wants to merge 1 commit into
base: fixes
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately C (unlike C++) also warns about converions from char** to const char* const*, even though the latter has lower requirements.


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