Skip to content

Commit

Permalink
Fix subscribe_multiple datatypes.
Browse files Browse the repository at this point in the history
  • Loading branch information
ralight committed Nov 13, 2018
1 parent 353990e commit 098a1c8
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion client/sub_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -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; i<cfg->unsub_topic_count; i++){
mosquitto_unsubscribe(mosq, NULL, cfg->unsub_topics[i]);
Expand Down
4 changes: 2 additions & 2 deletions lib/actions.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 5 additions & 1 deletion lib/mosquitto.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/send_mosq.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/handle_connack.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ int handle__connack(struct mosquitto_db *db, struct mosquitto *context)
}
for(i=0; i<context->bridge->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{
Expand Down

0 comments on commit 098a1c8

Please sign in to comment.