--- mqtt/example/Attic/cmds.c 2011/12/06 09:04:55 1.1.2.14 +++ mqtt/example/Attic/cmds.c 2011/12/06 12:36:45 1.1.2.16 @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -8,12 +9,13 @@ int main() { mqtt_msg_t *m; - mqtt_subscr_t s[4]; + mqtt_subscr_t s[4], *ss; mqtthdr_connflgs_t flg; u_short ka, msgID; int i, len; char cid[BUFSIZ], user[BUFSIZ], pass[BUFSIZ], topic[BUFSIZ], message[BUFSIZ]; struct mqtthdr *hdr; + u_char *qoses; m = mqtt_msgAlloc(0); /* conn* */ @@ -80,12 +82,36 @@ 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) { + printf("Error:: mqtt_readSUBSCRIBE() #%d - %s\n", mqtt_GetErrno(), mqtt_GetError()); + 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("++> MessageID=%d\n", msgID); + for (i = 0; ss[i].sub_topic._base; i++) + printf(" >>> QoS=%d Topic(%d)=%s\n", ss[i].sub_ret, ss[i].sub_topic._size, ss[i].sub_topic._base); + mqtt_subFree(&ss); printf("suback=%d/%d\n", m->msg_len, mqtt_msgSUBACK(m, s, 10)); for (i = 0; i < m->msg_len; i++) printf("%d\n", ((u_char*) m->msg_base)[i]); + printf("read suback=%d\n", (len = mqtt_readSUBACK(m, &msgID, &qoses))); + for (i = 0; i < len; i++) + printf(" >>> QoS=%d\n", qoses[i]); + free(qoses); 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) { + printf("Error:: mqtt_readUNSUBSCRIBE() #%d - %s\n", mqtt_GetErrno(), mqtt_GetError()); + 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("++> MessageID=%d\n", msgID); + for (i = 0; ss[i].sub_topic._base; i++) + printf(" >>> Topic(%d)=%s\n", ss[i].sub_topic._size, ss[i].sub_topic._base); + mqtt_subFree(&ss); printf("unsuback=%d/%d\n", m->msg_len, mqtt_msgUNSUBACK(m, 10)); for (i = 0; i < m->msg_len; i++) printf("%d\n", ((u_char*) m->msg_base)[i]);