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

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;
                     13:        u_short ka;
1.1.2.1   misho      14:        int i;
1.1.2.10  misho      15:        char cid[BUFSIZ], user[BUFSIZ], pass[BUFSIZ], topic[BUFSIZ], message[BUFSIZ];
1.1.2.1   misho      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]);
1.1.2.10  misho      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);
1.1.2.1   misho      32:        printf("connack=%d/%d\n", m->msg_len, mqtt_msgCONNACK(m, 1));
                     33:        for (i = 0; i < m->msg_len; i++)
                     34:                printf("%d\n", ((u_char*) m->msg_base)[i]);
1.1.2.11  misho      35:        printf("read connack=%d\n", mqtt_readCONNACK(m));
                     36:        getchar();
1.1.2.1   misho      37: 
                     38:        /* pub* */
1.1.2.4   misho      39:        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      40:        for (i = 0; i < m->msg_len; i++)
                     41:                printf("%d\n", ((u_char*) m->msg_base)[i]);
1.1.2.3   misho      42:        printf("puback=%d/%d\n", m->msg_len, mqtt_msgPUBACK(m, 10));
                     43:        for (i = 0; i < m->msg_len; i++)
                     44:                printf("%d\n", ((u_char*) m->msg_base)[i]);
1.1.2.13! misho      45:        printf("read puback=%d\n", mqtt_readPUBACK(m));
1.1.2.3   misho      46:        printf("pubrec=%d/%d\n", m->msg_len, mqtt_msgPUBREC(m, 11));
                     47:        for (i = 0; i < m->msg_len; i++)
                     48:                printf("%d\n", ((u_char*) m->msg_base)[i]);
1.1.2.13! misho      49:        printf("read pubrec=%d\n", mqtt_readPUBREC(m));
1.1.2.3   misho      50:        printf("pubrel=%d/%d\n", m->msg_len, mqtt_msgPUBREL(m, 12));
                     51:        for (i = 0; i < m->msg_len; i++)
                     52:                printf("%d\n", ((u_char*) m->msg_base)[i]);
1.1.2.13! misho      53:        printf("read pubrel=%d\n", mqtt_readPUBREL(m));
1.1.2.3   misho      54:        printf("pubcomp=%d/%d\n", m->msg_len, mqtt_msgPUBCOMP(m, 13));
                     55:        for (i = 0; i < m->msg_len; i++)
                     56:                printf("%d\n", ((u_char*) m->msg_base)[i]);
1.1.2.13! misho      57:        printf("read pubcomp=%d\n", mqtt_readPUBCOMP(m));
1.1.2.3   misho      58: 
                     59:        /* sub* */
1.1.2.5   misho      60:        memset(s, 0, sizeof s);
1.1.2.9   misho      61:        s[0].sub_topic._size = 3;
                     62:        s[0].sub_topic._base = "a/b";
                     63:        s[0].sub_ret = MQTT_QOS_ACK;
                     64:        s[1].sub_topic._size = 3;
                     65:        s[1].sub_topic._base = "c/d";
                     66:        s[1].sub_ret = MQTT_QOS_ONCE;
                     67:        s[2].sub_topic._size = 7;
                     68:        s[2].sub_topic._base = "x/y/z/Q";
                     69:        s[2].sub_ret = MQTT_QOS_EXACTLY;
1.1.2.5   misho      70:        printf("subscribe=%d/%d\n", m->msg_len, mqtt_msgSUBSCRIBE(m, s, 10, 0, 0));
                     71:        for (i = 0; i < m->msg_len; i++)
                     72:                printf("%d\n", ((u_char*) m->msg_base)[i]);
1.1.2.6   misho      73:        printf("suback=%d/%d\n", m->msg_len, mqtt_msgSUBACK(m, s, 10));
                     74:        for (i = 0; i < m->msg_len; i++)
                     75:                printf("%d\n", ((u_char*) m->msg_base)[i]);
1.1.2.7   misho      76:        printf("unsubscribe=%d/%d\n", m->msg_len, mqtt_msgUNSUBSCRIBE(m, s, 10, 0, 1));
                     77:        for (i = 0; i < m->msg_len; i++)
                     78:                printf("%d\n", ((u_char*) m->msg_base)[i]);
                     79:        printf("unsuback=%d/%d\n", m->msg_len, mqtt_msgUNSUBACK(m, 10));
                     80:        for (i = 0; i < m->msg_len; i++)
                     81:                printf("%d\n", ((u_char*) m->msg_base)[i]);
1.1.2.13! misho      82:        printf("read unsuback=%d\n", mqtt_readUNSUBACK(m));
1.1.2.1   misho      83: 
1.1.2.8   misho      84:        /* ping* */
                     85:        printf("pingreq=%d/%d\n", m->msg_len, mqtt_msgPINGREQ(m));
                     86:        for (i = 0; i < m->msg_len; i++)
                     87:                printf("%d\n", ((u_char*) m->msg_base)[i]);
1.1.2.12  misho      88:        printf("read pingreq=%d\n", mqtt_readPINGREQ(m));
1.1.2.8   misho      89:        printf("pingresp=%d/%d\n", m->msg_len, mqtt_msgPINGRESP(m));
                     90:        for (i = 0; i < m->msg_len; i++)
                     91:                printf("%d\n", ((u_char*) m->msg_base)[i]);
1.1.2.12  misho      92:        printf("read pingresp=%d\n", mqtt_readPINGRESP(m));
1.1.2.8   misho      93: 
                     94:        printf("disconnect=%d/%d\n", m->msg_len, mqtt_msgDISCONNECT(m));
                     95:        for (i = 0; i < m->msg_len; i++)
                     96:                printf("%d\n", ((u_char*) m->msg_base)[i]);
1.1.2.12  misho      97:        printf("read disconnect=%d\n", mqtt_readDISCONNECT(m));
1.1.2.8   misho      98: 
1.1.2.1   misho      99:        mqtt_msgFree(&m, 42);
                    100:        return 0;
                    101: }

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