version 1.3.12.2, 2022/09/15 13:50:14
|
version 1.3.12.4, 2022/09/16 04:14:03
|
Line 51 SUCH DAMAGE.
|
Line 51 SUCH DAMAGE.
|
* |
* |
* @Topics = MQTT subscription topics |
* @Topics = MQTT subscription topics |
* @msgID = MessageID |
* @msgID = MessageID |
* @Dup = Duplicate message |
|
* @QOS = QoS |
|
* return: NULL error or allocated SUBSCRIBE message |
* return: NULL error or allocated SUBSCRIBE message |
*/ |
*/ |
mqtt_msg_t * |
mqtt_msg_t * |
mqtt_msgSUBSCRIBE(mqtt_subscr_t ** __restrict Topics, u_short msgID, | mqtt_msgSUBSCRIBE(mqtt_subscr_t * __restrict Topics, u_short msgID) |
u_char Dup, u_char QOS) | |
{ |
{ |
int len, siz; |
int len, siz; |
u_int n, *l; |
u_int n, *l; |
Line 65 mqtt_msgSUBSCRIBE(mqtt_subscr_t ** __restrict Topics,
|
Line 62 mqtt_msgSUBSCRIBE(mqtt_subscr_t ** __restrict Topics,
|
mqtthdr_var_t *topic; |
mqtthdr_var_t *topic; |
mqtt_len_t *mid; |
mqtt_len_t *mid; |
mqtt_subscr_t *t; |
mqtt_subscr_t *t; |
u_char *qos; |
|
void *data; |
void *data; |
mqtt_msg_t *msg = NULL; |
mqtt_msg_t *msg = NULL; |
|
|
if (!Topics || !*Topics) | if (!Topics) |
return NULL; |
return NULL; |
if (QOS > MQTT_QOS_EXACTLY) { | if (!msgID) { |
mqtt_SetErr(EINVAL, "Invalid QoS parameter"); | |
return NULL; | |
} | |
if (!msgID && QOS != MQTT_QOS_ONCE) { | |
mqtt_SetErr(EINVAL, "Invalid MessageID parameter must be >0"); |
mqtt_SetErr(EINVAL, "Invalid MessageID parameter must be >0"); |
return NULL; |
return NULL; |
} |
} |
|
|
/* calculate message size */ |
/* calculate message size */ |
len = sizeof(mqtt_len_t); /* msgid */ |
len = sizeof(mqtt_len_t); /* msgid */ |
for (t = *Topics; t && t->sub_topic.msg_base; t++) /* subscribes & qos */ | for (t = Topics; t && t->sub_topic.msg_base; t++) /* subscribes & qos */ |
len += sizeof(mqtt_len_t) + t->sub_topic.msg_len; | len += sizeof(mqtt_len_t) + t->sub_topic.msg_len + 1; |
|
|
/* calculate header size */ |
/* calculate header size */ |
siz = sizeof(struct mqtthdr); /* mqtt fixed header */ |
siz = sizeof(struct mqtthdr); /* mqtt fixed header */ |
Line 99 mqtt_msgSUBSCRIBE(mqtt_subscr_t ** __restrict Topics,
|
Line 91 mqtt_msgSUBSCRIBE(mqtt_subscr_t ** __restrict Topics,
|
|
|
/* fixed header */ |
/* fixed header */ |
hdr->mqtt_msg.type = MQTT_TYPE_SUBSCRIBE; |
hdr->mqtt_msg.type = MQTT_TYPE_SUBSCRIBE; |
hdr->mqtt_msg.qos = QOS; | hdr->mqtt_msg.qos = MQTT_QOS_ACK; |
hdr->mqtt_msg.dup = Dup ? 1 : 0; | |
hdr->mqtt_msg.retain = 0; | |
l = (u_int*) hdr->mqtt_len; |
l = (u_int*) hdr->mqtt_len; |
*l = n; |
*l = n; |
data += siz; |
data += siz; |
Line 112 mqtt_msgSUBSCRIBE(mqtt_subscr_t ** __restrict Topics,
|
Line 102 mqtt_msgSUBSCRIBE(mqtt_subscr_t ** __restrict Topics,
|
data += sizeof(mqtt_len_t); |
data += sizeof(mqtt_len_t); |
|
|
/* payload with subscriptions */ |
/* payload with subscriptions */ |
for (t = *Topics; t && t->sub_topic.msg_base; t++) { | for (t = Topics; t && t->sub_topic.msg_base; t++) { |
topic = (mqtthdr_var_t*) data; |
topic = (mqtthdr_var_t*) data; |
topic->var_sb.val = htons(t->sub_topic.msg_len); |
topic->var_sb.val = htons(t->sub_topic.msg_len); |
memcpy(topic->var_data, t->sub_topic.msg_base, ntohs(topic->var_sb.val)); |
memcpy(topic->var_data, t->sub_topic.msg_base, ntohs(topic->var_sb.val)); |
data += MQTTHDR_VAR_SIZEOF(topic); |
data += MQTTHDR_VAR_SIZEOF(topic); |
qos = data++; | *((char*) data) = t->sub_qos; |
*qos = t->sub_qos; | data++; |
} |
} |
|
|
return msg; |
return msg; |
Line 132 mqtt_msgSUBSCRIBE(mqtt_subscr_t ** __restrict Topics,
|
Line 122 mqtt_msgSUBSCRIBE(mqtt_subscr_t ** __restrict Topics,
|
* return: NULL error or allocated SUBACK message |
* return: NULL error or allocated SUBACK message |
*/ |
*/ |
mqtt_msg_t * |
mqtt_msg_t * |
mqtt_msgSUBACK(mqtt_subscr_t ** __restrict Topics, u_short msgID) | mqtt_msgSUBACK(mqtt_subscr_t * __restrict Topics, u_short msgID) |
{ |
{ |
int siz = 0; |
int siz = 0; |
struct mqtthdr *hdr; |
struct mqtthdr *hdr; |
Line 141 mqtt_msgSUBACK(mqtt_subscr_t ** __restrict Topics, u_s
|
Line 131 mqtt_msgSUBACK(mqtt_subscr_t ** __restrict Topics, u_s
|
u_char *qos; |
u_char *qos; |
mqtt_msg_t *msg = NULL; |
mqtt_msg_t *msg = NULL; |
|
|
if (!Topics || !*Topics) | if (!Topics) |
return NULL; |
return NULL; |
|
|
if (!(msg = mqtt_msgAlloc(MQTTMSG_MAX))) |
if (!(msg = mqtt_msgAlloc(MQTTMSG_MAX))) |
Line 157 mqtt_msgSUBACK(mqtt_subscr_t ** __restrict Topics, u_s
|
Line 147 mqtt_msgSUBACK(mqtt_subscr_t ** __restrict Topics, u_s
|
v->val = htons(msgID); |
v->val = htons(msgID); |
|
|
/* QoS payload from subscriptions */ |
/* QoS payload from subscriptions */ |
for (t = *Topics; t && t->sub_topic.msg_base; t++, siz++) { | for (t = Topics; t && t->sub_topic.msg_base; t++, siz++) { |
qos = (msg->msg_base + siz); |
qos = (msg->msg_base + siz); |
*qos = t->sub_qos; |
*qos = t->sub_qos; |
} |
} |
Line 179 mqtt_msgSUBACK(mqtt_subscr_t ** __restrict Topics, u_s
|
Line 169 mqtt_msgSUBACK(mqtt_subscr_t ** __restrict Topics, u_s
|
* return: NULL error or allocated UNSUBSCRIBE message |
* return: NULL error or allocated UNSUBSCRIBE message |
*/ |
*/ |
mqtt_msg_t * |
mqtt_msg_t * |
mqtt_msgUNSUBSCRIBE(mqtt_subscr_t ** __restrict Topics, u_short msgID, | mqtt_msgUNSUBSCRIBE(mqtt_subscr_t * __restrict Topics, u_short msgID, |
u_char Dup, u_char QOS) |
u_char Dup, u_char QOS) |
{ |
{ |
int len, siz = 0; |
int len, siz = 0; |
Line 191 mqtt_msgUNSUBSCRIBE(mqtt_subscr_t ** __restrict Topics
|
Line 181 mqtt_msgUNSUBSCRIBE(mqtt_subscr_t ** __restrict Topics
|
void *data; |
void *data; |
mqtt_msg_t *msg = NULL; |
mqtt_msg_t *msg = NULL; |
|
|
if (!Topics || !*Topics) | if (!Topics) |
return NULL; |
return NULL; |
if (QOS > MQTT_QOS_EXACTLY) { |
if (QOS > MQTT_QOS_EXACTLY) { |
mqtt_SetErr(EINVAL, "Invalid QoS parameter"); |
mqtt_SetErr(EINVAL, "Invalid QoS parameter"); |
Line 204 mqtt_msgUNSUBSCRIBE(mqtt_subscr_t ** __restrict Topics
|
Line 194 mqtt_msgUNSUBSCRIBE(mqtt_subscr_t ** __restrict Topics
|
|
|
/* calculate message size */ |
/* calculate message size */ |
len = sizeof(mqtt_len_t); /* msgid */ |
len = sizeof(mqtt_len_t); /* msgid */ |
for (t = *Topics; t && t->sub_topic.msg_base; t++) /* subscribes */ | for (t = Topics; t && t->sub_topic.msg_base; t++) /* subscribes */ |
len += sizeof(mqtt_len_t) + t->sub_topic.msg_len; |
len += sizeof(mqtt_len_t) + t->sub_topic.msg_len; |
|
|
/* calculate header size */ |
/* calculate header size */ |
Line 234 mqtt_msgUNSUBSCRIBE(mqtt_subscr_t ** __restrict Topics
|
Line 224 mqtt_msgUNSUBSCRIBE(mqtt_subscr_t ** __restrict Topics
|
data += sizeof(mqtt_len_t); |
data += sizeof(mqtt_len_t); |
|
|
/* payload with subscriptions */ |
/* payload with subscriptions */ |
for (t = *Topics; t && t->sub_topic.msg_base; t++) { | for (t = Topics; t && t->sub_topic.msg_base; t++) { |
topic = (mqtthdr_var_t*) data; |
topic = (mqtthdr_var_t*) data; |
topic->var_sb.val = htons(t->sub_topic.msg_len); |
topic->var_sb.val = htons(t->sub_topic.msg_len); |
memcpy(topic->var_data, t->sub_topic.msg_base, ntohs(topic->var_sb.val)); |
memcpy(topic->var_data, t->sub_topic.msg_base, ntohs(topic->var_sb.val)); |