--- libaitmqtt/example/cmds.c 2012/01/26 13:07:33 1.1 +++ libaitmqtt/example/cmds.c 2012/06/20 15:02:23 1.2 @@ -14,7 +14,7 @@ main() mqtthdr_connack_t cack; u_short ka, msgID; int i, len; - char cid[BUFSIZ], user[BUFSIZ], pass[BUFSIZ], topic[BUFSIZ], message[BUFSIZ], *t, *msg; + char cid[BUFSIZ], user[BUFSIZ], pass[BUFSIZ], topic[BUFSIZ], *t, *msg, *pub; struct mqtthdr *hdr; u_char *qoses; @@ -48,14 +48,13 @@ main() printf("publish=%d/%d\n", m->msg_len, mqtt_msgPUBLISH(m, "AAA/bbb/CCC/ddd", 7, 0, 2, 0, "OLE!!!", 7)); for (i = 0; i < m->msg_len; i++) printf("%d\n", ((u_char*) m->msg_base)[i]); - len = sizeof message; - hdr = mqtt_readPUBLISH(m, topic, sizeof topic, &msgID, message, &len); - if (!hdr) { + if (!(len = mqtt_readPUBLISH(m, topic, sizeof topic, &msgID, (void**) &pub))) { printf("Error:: mqtt_readPUBLISH() #%d - %s\n", mqtt_GetErrno(), mqtt_GetError()); return 2; } 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, message); + printf("++> topic=%s MessageID=%d DATA=(%d)%s\n", topic, msgID, len, pub); + free(pub); printf("puback=%d/%d\n", m->msg_len, mqtt_msgPUBACK(m, 10)); for (i = 0; i < m->msg_len; i++) printf("%d\n", ((u_char*) m->msg_base)[i]); @@ -88,8 +87,7 @@ main() printf("subscribe=%d/%d\n", m->msg_len, mqtt_msgSUBSCRIBE(m, s, 10, 0, 0)); for (i = 0; i < m->msg_len; i++) printf("%d\n", ((u_char*) m->msg_base)[i]); - hdr = mqtt_readSUBSCRIBE(m, &msgID, &ss); - if (!hdr) { + if (mqtt_readSUBSCRIBE(m, &msgID, &ss) == -1) { printf("Error:: mqtt_readSUBSCRIBE() #%d - %s\n", mqtt_GetErrno(), mqtt_GetError()); return 3; } @@ -109,8 +107,7 @@ main() printf("unsubscribe=%d/%d\n", m->msg_len, mqtt_msgUNSUBSCRIBE(m, s, 10, 0, 1)); for (i = 0; i < m->msg_len; i++) printf("%d\n", ((u_char*) m->msg_base)[i]); - hdr = mqtt_readUNSUBSCRIBE(m, &msgID, &ss); - if (!hdr) { + if (mqtt_readUNSUBSCRIBE(m, &msgID, &ss) == -1) { printf("Error:: mqtt_readUNSUBSCRIBE() #%d - %s\n", mqtt_GetErrno(), mqtt_GetError()); return 3; }