Annotation of mqtt/example/cmds.c, revision 1.1.2.16

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>