|
|
|
@ -30,13 +30,13 @@ Contributors:
|
|
|
|
|
#include "util_mosq.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int send__subscribe(struct mosquitto *mosq, int *mid, const char *topic, uint8_t topic_qos)
|
|
|
|
|
int send__subscribe(struct mosquitto *mosq, int *mid, int topic_count, const char **topic, int topic_qos)
|
|
|
|
|
{
|
|
|
|
|
/* FIXME - only deals with a single topic */
|
|
|
|
|
struct mosquitto__packet *packet = NULL;
|
|
|
|
|
uint32_t packetlen;
|
|
|
|
|
uint16_t local_mid;
|
|
|
|
|
int rc;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
assert(mosq);
|
|
|
|
|
assert(topic);
|
|
|
|
@ -44,7 +44,10 @@ int send__subscribe(struct mosquitto *mosq, int *mid, const char *topic, uint8_t
|
|
|
|
|
packet = mosquitto__calloc(1, sizeof(struct mosquitto__packet));
|
|
|
|
|
if(!packet) return MOSQ_ERR_NOMEM;
|
|
|
|
|
|
|
|
|
|
packetlen = 2 + 2+strlen(topic) + 1;
|
|
|
|
|
packetlen = 2;
|
|
|
|
|
for(i=0; i<topic_count; i++){
|
|
|
|
|
packetlen += 2+strlen(topic[i]) + 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
packet->command = 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; i<topic_count; i++){
|
|
|
|
|
packet__write_string(packet, topic[i], strlen(topic[i]));
|
|
|
|
|
packet__write_byte(packet, topic_qos);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef WITH_BROKER
|
|
|
|
|
# ifdef WITH_BRIDGE
|
|
|
|
|
log__printf(mosq, MOSQ_LOG_DEBUG, "Bridge %s sending SUBSCRIBE (Mid: %d, Topic: %s, QoS: %d)", mosq->id, 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; i<topic_count; i++){
|
|
|
|
|
log__printf(mosq, MOSQ_LOG_DEBUG, "Client %s sending SUBSCRIBE (Mid: %d, Topic: %s, QoS: %d)", mosq->id, local_mid, topic[i], topic_qos);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return packet__queue(mosq, packet);
|
|
|
|
|