1: #include <stdio.h>
2: #include <string.h>
3: #include <sys/types.h>
4: #include <aitmqtt.h>
5:
6:
7: int
8: main()
9: {
10: mqtt_msg_t *m;
11: mqtt_subscr_t s[4];
12: mqtthdr_connflgs_t flg;
13: u_short ka;
14: int i;
15: char cid[BUFSIZ], user[BUFSIZ], pass[BUFSIZ], topic[BUFSIZ], message[BUFSIZ];
16:
17: m = mqtt_msgAlloc(0);
18: /* conn* */
19: printf("connect=%d/%d\n", m->msg_len, mqtt_msgCONNECT(m, "MRYN", "aaaaa", NULL, "bbb", NULL, 0, 0, 0));
20: for (i = 0; i < m->msg_len; i++)
21: printf("%d\n", ((u_char*) m->msg_base)[i]);
22: flg = mqtt_readCONNECT(m, &ka, cid, sizeof cid, user, sizeof user, pass, sizeof pass,
23: topic, sizeof topic, message, sizeof message);
24: printf("read connect flags:: clean=%d will=%d qos=%d retain=%d pass=%d user=%d\n",
25: flg.clean_sess, flg.will_flg, flg.will_qos, flg.will_retain, flg.password, flg.username);
26: if (flg.reserved) {
27: printf("Error:: mqtt_readCONNECT() #%d - %s\n", mqtt_GetErrno(), mqtt_GetError());
28: return 1;
29: }
30: printf("++> KA=%d sec, ConnID=%s User=%s Pass=%s Will_Topic=%s Will_Message=%s\n", ka,
31: cid, user, pass, topic, message);
32: getchar();
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]);
36:
37: /* pub* */
38: printf("publish=%d/%d\n", m->msg_len, mqtt_msgPUBLISH(m, "AAA/bbb/CCC/ddd", 7, 0, 2, 0, "OLE!!!", 7));
39: for (i = 0; i < m->msg_len; i++)
40: printf("%d\n", ((u_char*) m->msg_base)[i]);
41: printf("puback=%d/%d\n", m->msg_len, mqtt_msgPUBACK(m, 10));
42: for (i = 0; i < m->msg_len; i++)
43: printf("%d\n", ((u_char*) m->msg_base)[i]);
44: printf("pubrec=%d/%d\n", m->msg_len, mqtt_msgPUBREC(m, 11));
45: for (i = 0; i < m->msg_len; i++)
46: printf("%d\n", ((u_char*) m->msg_base)[i]);
47: printf("pubrel=%d/%d\n", m->msg_len, mqtt_msgPUBREL(m, 12));
48: for (i = 0; i < m->msg_len; i++)
49: printf("%d\n", ((u_char*) m->msg_base)[i]);
50: printf("pubcomp=%d/%d\n", m->msg_len, mqtt_msgPUBCOMP(m, 13));
51: for (i = 0; i < m->msg_len; i++)
52: printf("%d\n", ((u_char*) m->msg_base)[i]);
53:
54: /* sub* */
55: memset(s, 0, sizeof s);
56: s[0].sub_topic._size = 3;
57: s[0].sub_topic._base = "a/b";
58: s[0].sub_ret = MQTT_QOS_ACK;
59: s[1].sub_topic._size = 3;
60: s[1].sub_topic._base = "c/d";
61: s[1].sub_ret = MQTT_QOS_ONCE;
62: s[2].sub_topic._size = 7;
63: s[2].sub_topic._base = "x/y/z/Q";
64: s[2].sub_ret = MQTT_QOS_EXACTLY;
65: printf("subscribe=%d/%d\n", m->msg_len, mqtt_msgSUBSCRIBE(m, s, 10, 0, 0));
66: for (i = 0; i < m->msg_len; i++)
67: printf("%d\n", ((u_char*) m->msg_base)[i]);
68: printf("suback=%d/%d\n", m->msg_len, mqtt_msgSUBACK(m, s, 10));
69: for (i = 0; i < m->msg_len; i++)
70: printf("%d\n", ((u_char*) m->msg_base)[i]);
71: printf("unsubscribe=%d/%d\n", m->msg_len, mqtt_msgUNSUBSCRIBE(m, s, 10, 0, 1));
72: for (i = 0; i < m->msg_len; i++)
73: printf("%d\n", ((u_char*) m->msg_base)[i]);
74: printf("unsuback=%d/%d\n", m->msg_len, mqtt_msgUNSUBACK(m, 10));
75: for (i = 0; i < m->msg_len; i++)
76: printf("%d\n", ((u_char*) m->msg_base)[i]);
77:
78: /* ping* */
79: printf("pingreq=%d/%d\n", m->msg_len, mqtt_msgPINGREQ(m));
80: for (i = 0; i < m->msg_len; i++)
81: printf("%d\n", ((u_char*) m->msg_base)[i]);
82: printf("pingresp=%d/%d\n", m->msg_len, mqtt_msgPINGRESP(m));
83: for (i = 0; i < m->msg_len; i++)
84: printf("%d\n", ((u_char*) m->msg_base)[i]);
85:
86: printf("disconnect=%d/%d\n", m->msg_len, mqtt_msgDISCONNECT(m));
87: for (i = 0; i < m->msg_len; i++)
88: printf("%d\n", ((u_char*) m->msg_base)[i]);
89:
90: mqtt_msgFree(&m, 42);
91: return 0;
92: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>