Annotation of mqtt/example/cmds.c, revision 1.1.2.14
1.1.2.1 misho 1: #include <stdio.h>
1.1.2.5 misho 2: #include <string.h>
1.1.2.1 misho 3: #include <sys/types.h>
4: #include <aitmqtt.h>
5:
6:
7: int
8: main()
9: {
10: mqtt_msg_t *m;
1.1.2.5 misho 11: mqtt_subscr_t s[4];
1.1.2.10 misho 12: mqtthdr_connflgs_t flg;
1.1.2.14! misho 13: u_short ka, msgID;
! 14: int i, len;
1.1.2.10 misho 15: char cid[BUFSIZ], user[BUFSIZ], pass[BUFSIZ], topic[BUFSIZ], message[BUFSIZ];
1.1.2.14! misho 16: struct mqtthdr *hdr;
1.1.2.1 misho 17:
18: m = mqtt_msgAlloc(0);
19: /* conn* */
20: printf("connect=%d/%d\n", m->msg_len, mqtt_msgCONNECT(m, "MRYN", "aaaaa", NULL, "bbb", NULL, 0, 0, 0));
21: for (i = 0; i < m->msg_len; i++)
22: printf("%d\n", ((u_char*) m->msg_base)[i]);
1.1.2.10 misho 23: flg = mqtt_readCONNECT(m, &ka, cid, sizeof cid, user, sizeof user, pass, sizeof pass,
24: topic, sizeof topic, message, sizeof message);
25: printf("read connect flags:: clean=%d will=%d qos=%d retain=%d pass=%d user=%d\n",
26: flg.clean_sess, flg.will_flg, flg.will_qos, flg.will_retain, flg.password, flg.username);
27: if (flg.reserved) {
28: printf("Error:: mqtt_readCONNECT() #%d - %s\n", mqtt_GetErrno(), mqtt_GetError());
29: return 1;
30: }
31: printf("++> KA=%d sec, ConnID=%s User=%s Pass=%s Will_Topic=%s Will_Message=%s\n", ka,
32: cid, user, pass, topic, message);
1.1.2.1 misho 33: printf("connack=%d/%d\n", m->msg_len, mqtt_msgCONNACK(m, 1));
34: for (i = 0; i < m->msg_len; i++)
35: printf("%d\n", ((u_char*) m->msg_base)[i]);
1.1.2.11 misho 36: printf("read connack=%d\n", mqtt_readCONNACK(m));
37: getchar();
1.1.2.1 misho 38:
39: /* pub* */
1.1.2.4 misho 40: printf("publish=%d/%d\n", m->msg_len, mqtt_msgPUBLISH(m, "AAA/bbb/CCC/ddd", 7, 0, 2, 0, "OLE!!!", 7));
1.1.2.1 misho 41: for (i = 0; i < m->msg_len; i++)
42: printf("%d\n", ((u_char*) m->msg_base)[i]);
1.1.2.14! misho 43: len = sizeof message;
! 44: hdr = mqtt_readPUBLISH(m, topic, sizeof topic, &msgID, message, &len);
! 45: if (!hdr) {
! 46: printf("Error:: mqtt_readPUBLISH() #%d - %s\n", mqtt_GetErrno(), mqtt_GetError());
! 47: return 2;
! 48: }
! 49: printf("read publish: dup=%d qos=%d retain=%d\n", hdr->mqtt_msg.dup, hdr->mqtt_msg.qos, hdr->mqtt_msg.retain);
! 50: printf("++> topic=%s MessageID=%d DATA=(%d)%s\n", topic, msgID, len, message);
1.1.2.3 misho 51: printf("puback=%d/%d\n", m->msg_len, mqtt_msgPUBACK(m, 10));
52: for (i = 0; i < m->msg_len; i++)
53: printf("%d\n", ((u_char*) m->msg_base)[i]);
1.1.2.13 misho 54: printf("read puback=%d\n", mqtt_readPUBACK(m));
1.1.2.3 misho 55: printf("pubrec=%d/%d\n", m->msg_len, mqtt_msgPUBREC(m, 11));
56: for (i = 0; i < m->msg_len; i++)
57: printf("%d\n", ((u_char*) m->msg_base)[i]);
1.1.2.13 misho 58: printf("read pubrec=%d\n", mqtt_readPUBREC(m));
1.1.2.3 misho 59: printf("pubrel=%d/%d\n", m->msg_len, mqtt_msgPUBREL(m, 12));
60: for (i = 0; i < m->msg_len; i++)
61: printf("%d\n", ((u_char*) m->msg_base)[i]);
1.1.2.13 misho 62: printf("read pubrel=%d\n", mqtt_readPUBREL(m));
1.1.2.3 misho 63: printf("pubcomp=%d/%d\n", m->msg_len, mqtt_msgPUBCOMP(m, 13));
64: for (i = 0; i < m->msg_len; i++)
65: printf("%d\n", ((u_char*) m->msg_base)[i]);
1.1.2.13 misho 66: printf("read pubcomp=%d\n", mqtt_readPUBCOMP(m));
1.1.2.14! misho 67: getchar();
1.1.2.3 misho 68:
69: /* sub* */
1.1.2.5 misho 70: memset(s, 0, sizeof s);
1.1.2.9 misho 71: s[0].sub_topic._size = 3;
72: s[0].sub_topic._base = "a/b";
73: s[0].sub_ret = MQTT_QOS_ACK;
74: s[1].sub_topic._size = 3;
75: s[1].sub_topic._base = "c/d";
76: s[1].sub_ret = MQTT_QOS_ONCE;
77: s[2].sub_topic._size = 7;
78: s[2].sub_topic._base = "x/y/z/Q";
79: s[2].sub_ret = MQTT_QOS_EXACTLY;
1.1.2.5 misho 80: printf("subscribe=%d/%d\n", m->msg_len, mqtt_msgSUBSCRIBE(m, s, 10, 0, 0));
81: for (i = 0; i < m->msg_len; i++)
82: printf("%d\n", ((u_char*) m->msg_base)[i]);
1.1.2.6 misho 83: printf("suback=%d/%d\n", m->msg_len, mqtt_msgSUBACK(m, s, 10));
84: for (i = 0; i < m->msg_len; i++)
85: printf("%d\n", ((u_char*) m->msg_base)[i]);
1.1.2.7 misho 86: printf("unsubscribe=%d/%d\n", m->msg_len, mqtt_msgUNSUBSCRIBE(m, s, 10, 0, 1));
87: for (i = 0; i < m->msg_len; i++)
88: printf("%d\n", ((u_char*) m->msg_base)[i]);
89: printf("unsuback=%d/%d\n", m->msg_len, mqtt_msgUNSUBACK(m, 10));
90: for (i = 0; i < m->msg_len; i++)
91: printf("%d\n", ((u_char*) m->msg_base)[i]);
1.1.2.13 misho 92: printf("read unsuback=%d\n", mqtt_readUNSUBACK(m));
1.1.2.14! misho 93: getchar();
1.1.2.1 misho 94:
1.1.2.8 misho 95: /* ping* */
96: printf("pingreq=%d/%d\n", m->msg_len, mqtt_msgPINGREQ(m));
97: for (i = 0; i < m->msg_len; i++)
98: printf("%d\n", ((u_char*) m->msg_base)[i]);
1.1.2.12 misho 99: printf("read pingreq=%d\n", mqtt_readPINGREQ(m));
1.1.2.8 misho 100: printf("pingresp=%d/%d\n", m->msg_len, mqtt_msgPINGRESP(m));
101: for (i = 0; i < m->msg_len; i++)
102: printf("%d\n", ((u_char*) m->msg_base)[i]);
1.1.2.12 misho 103: printf("read pingresp=%d\n", mqtt_readPINGRESP(m));
1.1.2.8 misho 104:
105: printf("disconnect=%d/%d\n", m->msg_len, mqtt_msgDISCONNECT(m));
106: for (i = 0; i < m->msg_len; i++)
107: printf("%d\n", ((u_char*) m->msg_base)[i]);
1.1.2.12 misho 108: printf("read disconnect=%d\n", mqtt_readDISCONNECT(m));
1.1.2.8 misho 109:
1.1.2.1 misho 110: mqtt_msgFree(&m, 42);
111: return 0;
112: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>