Annotation of mqtt/src/sub.c, revision 1.1.2.4
1.1.2.1 misho 1: #include "global.h"
2:
3:
4: /* ------------------------------------------------------------------- */
5:
1.1.2.2 misho 6: int
7: mqtt_msgSUBSCRIBE(mqtt_msg_t * __restrict buf, const char *csTopic, u_short msgID,
1.1.2.3 misho 8: u_char Dup, u_char QOS)
1.1.2.2 misho 9: {
1.1.2.3 misho 10: int siz = 0;
11: struct mqtthdr *hdr;
12: mqtthdr_var_t *topic;
13: mqtt_v_t *mid;
14:
15: if (!buf || !csTopic)
16: return -1;
17: if (QOS > MQTT_QOS_EXACTLY) {
18: mqtt_SetErr(EINVAL, "Error:: invalid QoS parameter");
19: return -1;
20: }
21: if (!msgID && QOS != MQTT_QOS_ONCE) {
22: mqtt_SetErr(EINVAL, "Error:: invalid MessageID parameter must be >0");
23: return -1;
24: }
25:
26: if (mqtt_msgRealloc(buf, MQTTMSG_MAX) == -1)
27: return -1;
28: else {
29: hdr = (struct mqtthdr *) (buf->msg_base + siz);
30: siz += sizeof(struct mqtthdr);
31: }
32:
33: /* variable header */
34:
1.1.2.4 ! misho 35: mid = (mqtt_v_t*) (buf->msg_base + siz);
! 36: mid->val = htons(msgID);
! 37: siz += sizeof(mqtt_v_t);
! 38:
1.1.2.3 misho 39: topic = (mqtthdr_var_t*) (buf->msg_base + siz);
40: topic->var_sb.val = htons(strlen(csTopic));
41: memcpy(topic->var_data, csTopic, ntohs(topic->var_sb.val));
42: siz += MQTTHDR_VAR_SIZEOF(topic);
43:
44: /* fixed header */
45:
1.1.2.4 ! misho 46: hdr->mqtt_msg.type = MQTT_TYPE_SUBSCRIBE;
1.1.2.3 misho 47: hdr->mqtt_msg.qos = QOS;
48: hdr->mqtt_msg.dup = Dup ? 1 : 0;
1.1.2.4 ! misho 49: hdr->mqtt_msg.retain = 0;
1.1.2.3 misho 50: *hdr->mqtt_len = mqtt_encodeLen(siz - sizeof(struct mqtthdr));
51:
52: mqtt_msgRealloc(buf, siz);
53: return siz;
1.1.2.2 misho 54: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>