Diff for /libaitmqtt/example/cmds.c between versions 1.3 and 1.3.12.2

version 1.3, 2012/06/28 11:06:17 version 1.3.12.2, 2022/09/16 04:14:03
Line 2 Line 2
 #include <stdlib.h>  #include <stdlib.h>
 #include <string.h>  #include <string.h>
 #include <sys/types.h>  #include <sys/types.h>
   #include <limits.h>
   #include <elwix.h>
 #include <aitmqtt.h>  #include <aitmqtt.h>
   
   
Line 18  main() Line 20  main()
         struct mqtthdr *hdr;          struct mqtthdr *hdr;
         u_char *qoses;          u_char *qoses;
   
         m = mqtt_msgAlloc(0);  
         /* conn* */          /* conn* */
        printf("connect=%d/%d\n", m->msg_len, mqtt_msgCONNECT(m, "MRYN", 0, "aaaaa", NULL, "bbb", NULL, 0, 0, 0));        m = mqtt_msgCONNECT("MRYN", 4, 0, "aaaaa", NULL, "bbb", NULL, 0, 0, 0);
         printf("connect=%d/%p\n", m->msg_len, m);
 //      for (i = 0; i < m->msg_len; i++)  //      for (i = 0; i < m->msg_len; i++)
 //              printf("%d\n", ((u_char*) m->msg_base)[i]);  //              printf("%d\n", ((u_char*) m->msg_base)[i]);
         t = msg = NULL;          t = msg = NULL;
Line 30  main() Line 32  main()
                         flg.clean_sess, flg.will_flg, flg.will_qos, flg.will_retain, flg.password, flg.username);                          flg.clean_sess, flg.will_flg, flg.will_qos, flg.will_retain, flg.password, flg.username);
         if (flg.reserved) {          if (flg.reserved) {
                 printf("Error:: mqtt_readCONNECT() #%d - %s\n", mqtt_GetErrno(), mqtt_GetError());                  printf("Error:: mqtt_readCONNECT() #%d - %s\n", mqtt_GetErrno(), mqtt_GetError());
                   mqtt_msgFree(&m, 0);
                 return 1;                  return 1;
         }          }
         printf("++> KA=%d sec, ConnID=%s User=%s Pass=%s Will_Topic=%s Will_Message=%s\n", ka,           printf("++> KA=%d sec, ConnID=%s User=%s Pass=%s Will_Topic=%s Will_Message=%s\n", ka, 
                         cid, user, pass, t, msg);                          cid, user, pass, t, msg);
         if (t)          if (t)
                free(t);                e_free(t);
         if (msg)          if (msg)
                free(msg);                e_free(msg);
        printf("connack=%d/%d\n", m->msg_len, mqtt_msgCONNACK(m, 1));        mqtt_msgFree(&m, 0);
 
         m = mqtt_msgCONNACK(1);
         printf("connack=%d/%p\n", m->msg_len, m);
 //      for (i = 0; i < m->msg_len; i++)  //      for (i = 0; i < m->msg_len; i++)
 //              printf("%d\n", ((u_char*) m->msg_base)[i]);  //              printf("%d\n", ((u_char*) m->msg_base)[i]);
         printf("read connack=%d\n", mqtt_readCONNACK(m));          printf("read connack=%d\n", mqtt_readCONNACK(m));
           mqtt_msgFree(&m, 0);
         getchar();          getchar();
   
         /* pub* */          /* pub* */
        printf("publish=%d/%d\n", m->msg_len, mqtt_msgPUBLISH(m, "AAA/bbb/CCC/ddd", 7, 0, 2, 0, "OLE!!!", 7));        m = mqtt_msgPUBLISH("AAA/bbb/CCC/ddd", 7, 0, 2, 0, "OLE!!!", 7);
         printf("publish=%d/%p\n", m->msg_len, m);
 //      for (i = 0; i < m->msg_len; i++)  //      for (i = 0; i < m->msg_len; i++)
 //              printf("%d\n", ((u_char*) m->msg_base)[i]);  //              printf("%d\n", ((u_char*) m->msg_base)[i]);
         if (!(len = mqtt_readPUBLISH(m, topic, sizeof topic, &msgID, (void**) &pub))) {          if (!(len = mqtt_readPUBLISH(m, topic, sizeof topic, &msgID, (void**) &pub))) {
                 printf("Error:: mqtt_readPUBLISH() #%d - %s\n", mqtt_GetErrno(), mqtt_GetError());                  printf("Error:: mqtt_readPUBLISH() #%d - %s\n", mqtt_GetErrno(), mqtt_GetError());
                   mqtt_msgFree(&m, 0);
                 return 2;                  return 2;
         } else          } else
                 hdr = (struct mqtthdr*) m->msg_base;                  hdr = (struct mqtthdr*) m->msg_base;
         printf("read publish: dup=%d qos=%d retain=%d\n", hdr->mqtt_msg.dup, hdr->mqtt_msg.qos, hdr->mqtt_msg.retain);          printf("read publish: dup=%d qos=%d retain=%d\n", hdr->mqtt_msg.dup, hdr->mqtt_msg.qos, hdr->mqtt_msg.retain);
         printf("++> topic=%s MessageID=%d DATA=(%d)%s\n", topic, msgID, len, pub);          printf("++> topic=%s MessageID=%d DATA=(%d)%s\n", topic, msgID, len, pub);
        free(pub);        mqtt_msgFree(&m, 0);
        printf("puback=%d/%d\n", m->msg_len, mqtt_msgPUBACK(m, 10));        e_free(pub);
 
         m = mqtt_msgPUBACK(10);
         printf("puback=%d/%p\n", m->msg_len, m);
 //      for (i = 0; i < m->msg_len; i++)  //      for (i = 0; i < m->msg_len; i++)
 //              printf("%d\n", ((u_char*) m->msg_base)[i]);  //              printf("%d\n", ((u_char*) m->msg_base)[i]);
         printf("read puback=%d\n", mqtt_readPUBACK(m));          printf("read puback=%d\n", mqtt_readPUBACK(m));
        printf("pubrec=%d/%d\n", m->msg_len, mqtt_msgPUBREC(m, 11));        mqtt_msgFree(&m, 0);
 
         m = mqtt_msgPUBREC(11);
         printf("pubrec=%d/%p\n", m->msg_len, m);
 //      for (i = 0; i < m->msg_len; i++)  //      for (i = 0; i < m->msg_len; i++)
 //              printf("%d\n", ((u_char*) m->msg_base)[i]);  //              printf("%d\n", ((u_char*) m->msg_base)[i]);
         printf("read pubrec=%d\n", mqtt_readPUBREC(m));          printf("read pubrec=%d\n", mqtt_readPUBREC(m));
        printf("pubrel=%d/%d\n", m->msg_len, mqtt_msgPUBREL(m, 12));        mqtt_msgFree(&m, 0);
 
         m = mqtt_msgPUBREL(12);
         printf("pubrel=%d/%p\n", m->msg_len, m);
 //      for (i = 0; i < m->msg_len; i++)  //      for (i = 0; i < m->msg_len; i++)
 //              printf("%d\n", ((u_char*) m->msg_base)[i]);  //              printf("%d\n", ((u_char*) m->msg_base)[i]);
         printf("read pubrel=%d\n", mqtt_readPUBREL(m));          printf("read pubrel=%d\n", mqtt_readPUBREL(m));
        printf("pubcomp=%d/%d\n", m->msg_len, mqtt_msgPUBCOMP(m, 13));        mqtt_msgFree(&m, 0);
 
         m = mqtt_msgPUBCOMP(13);
         printf("pubcomp=%d/%p\n", m->msg_len, m);
 //      for (i = 0; i < m->msg_len; i++)  //      for (i = 0; i < m->msg_len; i++)
 //              printf("%d\n", ((u_char*) m->msg_base)[i]);  //              printf("%d\n", ((u_char*) m->msg_base)[i]);
         printf("read pubcomp=%d\n", mqtt_readPUBCOMP(m));          printf("read pubcomp=%d\n", mqtt_readPUBCOMP(m));
           mqtt_msgFree(&m, 0);
         getchar();          getchar();
   
         /* sub* */          /* sub* */
         memset(s, 0, sizeof s);          memset(s, 0, sizeof s);
         s[0].sub_topic.msg_len = 3;          s[0].sub_topic.msg_len = 3;
         s[0].sub_topic.msg_base = "a/b";          s[0].sub_topic.msg_base = "a/b";
        s[0].sub_ret = MQTT_QOS_ACK;        s[0].sub_qos = MQTT_QOS_ACK;
         s[1].sub_topic.msg_len = 3;          s[1].sub_topic.msg_len = 3;
         s[1].sub_topic.msg_base = "c/d";          s[1].sub_topic.msg_base = "c/d";
        s[1].sub_ret = MQTT_QOS_ONCE;        s[1].sub_qos = MQTT_QOS_ONCE;
         s[2].sub_topic.msg_len = 7;          s[2].sub_topic.msg_len = 7;
         s[2].sub_topic.msg_base = "x/y/z/Q";          s[2].sub_topic.msg_base = "x/y/z/Q";
        s[2].sub_ret = MQTT_QOS_EXACTLY;        s[2].sub_qos = MQTT_QOS_EXACTLY;
        printf("subscribe=%d/%d\n", m->msg_len, mqtt_msgSUBSCRIBE(m, s, 10, 0, 0));        m = mqtt_msgSUBSCRIBE(s, 10);
         printf("subscribe=%d/%p\n", m->msg_len, m);
         /*
         for (i = 0; i < m->msg_len; i++)          for (i = 0; i < m->msg_len; i++)
                 printf("%d\n", ((u_char*) m->msg_base)[i]);                  printf("%d\n", ((u_char*) m->msg_base)[i]);
                   */
         if (mqtt_readSUBSCRIBE(m, &msgID, &ss) == -1) {          if (mqtt_readSUBSCRIBE(m, &msgID, &ss) == -1) {
                 printf("Error:: mqtt_readSUBSCRIBE() #%d - %s\n", mqtt_GetErrno(), mqtt_GetError());                  printf("Error:: mqtt_readSUBSCRIBE() #%d - %s\n", mqtt_GetErrno(), mqtt_GetError());
                   mqtt_msgFree(&m, 0);
                 return 3;                  return 3;
         }          }
         printf("read subscribe: dup=%d qos=%d retain=%d\n", hdr->mqtt_msg.dup, hdr->mqtt_msg.qos, hdr->mqtt_msg.retain);          printf("read subscribe: dup=%d qos=%d retain=%d\n", hdr->mqtt_msg.dup, hdr->mqtt_msg.qos, hdr->mqtt_msg.retain);
         printf("++> MessageID=%d\n", msgID);          printf("++> MessageID=%d\n", msgID);
         for (i = 0; ss[i].sub_topic.msg_base; i++)          for (i = 0; ss[i].sub_topic.msg_base; i++)
                printf(" >>> QoS=%d Topic(%d)=%s\n", ss[i].sub_ret, ss[i].sub_topic.msg_len,                 printf(" >>> QoS=%d Topic(%d)=%s\n", ss[i].sub_qos, ss[i].sub_topic.msg_len, 
                                 (char*) ss[i].sub_topic.msg_base);                                  (char*) ss[i].sub_topic.msg_base);
           mqtt_msgFree(&m, 0);
         mqtt_subFree(&ss);          mqtt_subFree(&ss);
        printf("suback=%d/%d\n", m->msg_len, mqtt_msgSUBACK(m, s, 10));
         m = mqtt_msgSUBACK(s, 10);
         printf("suback=%d/%p\n", m->msg_len, m);
 //      for (i = 0; i < m->msg_len; i++)  //      for (i = 0; i < m->msg_len; i++)
 //              printf("%d\n", ((u_char*) m->msg_base)[i]);  //              printf("%d\n", ((u_char*) m->msg_base)[i]);
         printf("read suback=%d\n", (len = mqtt_readSUBACK(m, &msgID, &qoses)));          printf("read suback=%d\n", (len = mqtt_readSUBACK(m, &msgID, &qoses)));
         for (i = 0; i < len; i++)          for (i = 0; i < len; i++)
                 printf(" >>> QoS=%d\n", qoses[i]);                  printf(" >>> QoS=%d\n", qoses[i]);
        free(qoses);        mqtt_msgFree(&m, 0);
        printf("unsubscribe=%d/%d\n", m->msg_len, mqtt_msgUNSUBSCRIBE(m, s, 10, 0, 1));        e_free(qoses);
 
         m = mqtt_msgUNSUBSCRIBE(s, 10, 0, 1);
         printf("unsubscribe=%d/%p\n", m->msg_len, m);
 //      for (i = 0; i < m->msg_len; i++)  //      for (i = 0; i < m->msg_len; i++)
 //              printf("%d\n", ((u_char*) m->msg_base)[i]);  //              printf("%d\n", ((u_char*) m->msg_base)[i]);
         if (mqtt_readUNSUBSCRIBE(m, &msgID, &ss) == -1) {          if (mqtt_readUNSUBSCRIBE(m, &msgID, &ss) == -1) {
                 printf("Error:: mqtt_readUNSUBSCRIBE() #%d - %s\n", mqtt_GetErrno(), mqtt_GetError());                  printf("Error:: mqtt_readUNSUBSCRIBE() #%d - %s\n", mqtt_GetErrno(), mqtt_GetError());
                   mqtt_msgFree(&m, 0);
                 return 3;                  return 3;
         }          }
         printf("read unsubscribe: dup=%d qos=%d retain=%d\n", hdr->mqtt_msg.dup, hdr->mqtt_msg.qos, hdr->mqtt_msg.retain);          printf("read unsubscribe: dup=%d qos=%d retain=%d\n", hdr->mqtt_msg.dup, hdr->mqtt_msg.qos, hdr->mqtt_msg.retain);
         printf("++> MessageID=%d\n", msgID);          printf("++> MessageID=%d\n", msgID);
         for (i = 0; ss[i].sub_topic.msg_base; i++)          for (i = 0; ss[i].sub_topic.msg_base; i++)
                 printf(" >>> Topic(%d)=%s\n", ss[i].sub_topic.msg_len, (char*) ss[i].sub_topic.msg_base);                  printf(" >>> Topic(%d)=%s\n", ss[i].sub_topic.msg_len, (char*) ss[i].sub_topic.msg_base);
           mqtt_msgFree(&m, 0);
         mqtt_subFree(&ss);          mqtt_subFree(&ss);
        printf("unsuback=%d/%d\n", m->msg_len, mqtt_msgUNSUBACK(m, 10));
         m = mqtt_msgUNSUBACK(10);
         printf("unsuback=%d/%p\n", m->msg_len, m);
 //      for (i = 0; i < m->msg_len; i++)  //      for (i = 0; i < m->msg_len; i++)
 //              printf("%d\n", ((u_char*) m->msg_base)[i]);  //              printf("%d\n", ((u_char*) m->msg_base)[i]);
         printf("read unsuback=%d\n", mqtt_readUNSUBACK(m));          printf("read unsuback=%d\n", mqtt_readUNSUBACK(m));
           mqtt_msgFree(&m, 0);
         getchar();          getchar();
   
         /* ping* */          /* ping* */
        printf("pingreq=%d/%d\n", m->msg_len, mqtt_msgPINGREQ(m));        m = mqtt_msgPINGREQ();
         printf("pingreq=%d/%p\n", m->msg_len, m);
 //      for (i = 0; i < m->msg_len; i++)  //      for (i = 0; i < m->msg_len; i++)
 //              printf("%d\n", ((u_char*) m->msg_base)[i]);  //              printf("%d\n", ((u_char*) m->msg_base)[i]);
         printf("read pingreq=%d\n", mqtt_readPINGREQ(m));          printf("read pingreq=%d\n", mqtt_readPINGREQ(m));
        printf("pingresp=%d/%d\n", m->msg_len, mqtt_msgPINGRESP(m));        mqtt_msgFree(&m, 0);
         m = mqtt_msgPINGRESP();
         printf("pingresp=%d/%p\n", m->msg_len, m);
 //      for (i = 0; i < m->msg_len; i++)  //      for (i = 0; i < m->msg_len; i++)
 //              printf("%d\n", ((u_char*) m->msg_base)[i]);  //              printf("%d\n", ((u_char*) m->msg_base)[i]);
         printf("read pingresp=%d\n", mqtt_readPINGRESP(m));          printf("read pingresp=%d\n", mqtt_readPINGRESP(m));
           mqtt_msgFree(&m, 0);
   
        printf("disconnect=%d/%d\n", m->msg_len, mqtt_msgDISCONNECT(m));        m = mqtt_msgDISCONNECT();
         printf("disconnect=%d/%p\n", m->msg_len, m);
 //      for (i = 0; i < m->msg_len; i++)  //      for (i = 0; i < m->msg_len; i++)
 //              printf("%d\n", ((u_char*) m->msg_base)[i]);  //              printf("%d\n", ((u_char*) m->msg_base)[i]);
         printf("read disconnect=%d\n", mqtt_readDISCONNECT(m));          printf("read disconnect=%d\n", mqtt_readDISCONNECT(m));
        mqtt_msgFree(&m, 0);
        mqtt_msgFree(&m, 42); 
         return 0;          return 0;
 }  }

Removed from v.1.3  
changed lines
  Added in v.1.3.12.2


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