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

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]);
                     45:        printf("pubrec=%d/%d\n", m->msg_len, mqtt_msgPUBREC(m, 11));
                     46:        for (i = 0; i < m->msg_len; i++)
                     47:                printf("%d\n", ((u_char*) m->msg_base)[i]);
                     48:        printf("pubrel=%d/%d\n", m->msg_len, mqtt_msgPUBREL(m, 12));
                     49:        for (i = 0; i < m->msg_len; i++)
                     50:                printf("%d\n", ((u_char*) m->msg_base)[i]);
                     51:        printf("pubcomp=%d/%d\n", m->msg_len, mqtt_msgPUBCOMP(m, 13));
                     52:        for (i = 0; i < m->msg_len; i++)
                     53:                printf("%d\n", ((u_char*) m->msg_base)[i]);
                     54: 
                     55:        /* sub* */
1.1.2.5   misho      56:        memset(s, 0, sizeof s);
1.1.2.9   misho      57:        s[0].sub_topic._size = 3;
                     58:        s[0].sub_topic._base = "a/b";
                     59:        s[0].sub_ret = MQTT_QOS_ACK;
                     60:        s[1].sub_topic._size = 3;
                     61:        s[1].sub_topic._base = "c/d";
                     62:        s[1].sub_ret = MQTT_QOS_ONCE;
                     63:        s[2].sub_topic._size = 7;
                     64:        s[2].sub_topic._base = "x/y/z/Q";
                     65:        s[2].sub_ret = MQTT_QOS_EXACTLY;
1.1.2.5   misho      66:        printf("subscribe=%d/%d\n", m->msg_len, mqtt_msgSUBSCRIBE(m, s, 10, 0, 0));
                     67:        for (i = 0; i < m->msg_len; i++)
                     68:                printf("%d\n", ((u_char*) m->msg_base)[i]);
1.1.2.6   misho      69:        printf("suback=%d/%d\n", m->msg_len, mqtt_msgSUBACK(m, s, 10));
                     70:        for (i = 0; i < m->msg_len; i++)
                     71:                printf("%d\n", ((u_char*) m->msg_base)[i]);
1.1.2.7   misho      72:        printf("unsubscribe=%d/%d\n", m->msg_len, mqtt_msgUNSUBSCRIBE(m, s, 10, 0, 1));
                     73:        for (i = 0; i < m->msg_len; i++)
                     74:                printf("%d\n", ((u_char*) m->msg_base)[i]);
                     75:        printf("unsuback=%d/%d\n", m->msg_len, mqtt_msgUNSUBACK(m, 10));
                     76:        for (i = 0; i < m->msg_len; i++)
                     77:                printf("%d\n", ((u_char*) m->msg_base)[i]);
1.1.2.1   misho      78: 
1.1.2.8   misho      79:        /* ping* */
                     80:        printf("pingreq=%d/%d\n", m->msg_len, mqtt_msgPINGREQ(m));
                     81:        for (i = 0; i < m->msg_len; i++)
                     82:                printf("%d\n", ((u_char*) m->msg_base)[i]);
                     83:        printf("pingresp=%d/%d\n", m->msg_len, mqtt_msgPINGRESP(m));
                     84:        for (i = 0; i < m->msg_len; i++)
                     85:                printf("%d\n", ((u_char*) m->msg_base)[i]);
                     86: 
                     87:        printf("disconnect=%d/%d\n", m->msg_len, mqtt_msgDISCONNECT(m));
                     88:        for (i = 0; i < m->msg_len; i++)
                     89:                printf("%d\n", ((u_char*) m->msg_base)[i]);
                     90: 
1.1.2.1   misho      91:        mqtt_msgFree(&m, 42);
                     92:        return 0;
                     93: }

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