From 996b79872ec9dbb68a53219ddc36f2e62e7048b3 Mon Sep 17 00:00:00 2001 From: Ian Craggs Date: Fri, 1 Aug 2014 11:44:58 +0100 Subject: [PATCH] Change boolean types to char size --- samples/pub0sub1.c | 14 +++++++------- samples/qos0pub.c | 3 ++- samples/qos1pub.c | 3 +-- src/MQTTSNConnect.h | 14 +++++++------- src/MQTTSNConnectClient.c | 6 +++--- src/MQTTSNConnectServer.c | 6 +++--- src/MQTTSNDeserializePublish.c | 2 +- src/MQTTSNPacket.c | 4 ++-- src/MQTTSNPacket.h | 6 ++---- src/MQTTSNPublish.h | 4 ++-- src/MQTTSNSerializePublish.c | 2 +- src/MQTTSNSubscribe.h | 4 ++-- src/MQTTSNSubscribeClient.c | 3 ++- src/MQTTSNSubscribeServer.c | 2 +- test/test1.c | 15 ++++++++------- test/test2.c | 2 +- 16 files changed, 45 insertions(+), 45 deletions(-) diff --git a/samples/pub0sub1.c b/samples/pub0sub1.c index a33b663..de35ce0 100644 --- a/samples/pub0sub1.c +++ b/samples/pub0sub1.c @@ -16,8 +16,6 @@ #include "MQTTSNPacket.h" -#include - #if !defined(SOCKET_ERROR) /** error in socket operation */ #define SOCKET_ERROR -1 @@ -108,7 +106,7 @@ int mysock = 0; char *host = "127.0.0.1"; int port = 1884; -int getdata(unsigned char* buf, size_t count) +int getdata(unsigned char* buf, int count) { int rc = recvfrom(mysock, buf, count, 0, NULL, NULL); printf("received %d bytes count %d\n", rc, (int)count); @@ -125,9 +123,10 @@ int main(int argc, char** argv) unsigned char* payload = (unsigned char*)"mypayload"; int payloadlen = strlen((char*)payload); int len = 0; - int dup = 0; + unsigned char dup = 0; int qos = 1; - int retained = 0, packetid = 1; + unsigned char retained = 0; + short packetid = 1; char *topicname = "a long topic name"; MQTTSNPacket_connectData options = MQTTSNPacket_connectData_initializer; unsigned short topicid; @@ -168,7 +167,7 @@ int main(int argc, char** argv) /* subscribe */ printf("Subscribing\n"); topic.type = MQTTSN_TOPIC_TYPE_NORMAL; - topic.data.long_.name = "substopic"; + topic.data.long_.name = topicname; topic.data.long_.len = strlen(topic.data.long_.name); len = MQTTSNSerialize_subscribe(buf, buflen, 0, 2, /*msgid*/ 1, &topic); rc = sendPacketBuffer(mysock, host, port, buf, len); @@ -217,8 +216,9 @@ int main(int argc, char** argv) if (MQTTSNPacket_read(buf, buflen, getdata) == MQTTSN_PUBLISH) { unsigned short packet_id; - int dup, qos, retained, payloadlen; + int qos, payloadlen; unsigned char* payload; + unsigned char dup, retained; MQTTSN_topicid pubtopic; if (MQTTSNDeserialize_publish(&dup, &qos, &retained, &packet_id, &pubtopic, diff --git a/samples/qos0pub.c b/samples/qos0pub.c index d40b238..ecd2622 100644 --- a/samples/qos0pub.c +++ b/samples/qos0pub.c @@ -141,10 +141,11 @@ int main(int argc, char** argv) topic.type = MQTTSN_TOPIC_TYPE_NORMAL; topic.data.long_.name = topicname; topic.data.long_.len = strlen(topicname); - len = MQTTSNSerialize_publish(buf, buflen - len, dup, qos, retained, packetid, + len = MQTTSNSerialize_publish(buf, buflen, dup, qos, retained, packetid, topic, payload, payloadlen); rc = sendPacketBuffer(mysock, host, port, buf, len); + printf("rc %d from send packet for publish length %d\n", rc, len); rc = shutdown(mysock, SHUT_WR); rc = close(mysock); diff --git a/samples/qos1pub.c b/samples/qos1pub.c index c62d0eb..f3d3455 100644 --- a/samples/qos1pub.c +++ b/samples/qos1pub.c @@ -108,7 +108,7 @@ int mysock = 0; char *host = "127.0.0.1"; int port = 1884; -int getdata(unsigned char* buf, size_t count) +int getdata(unsigned char* buf, int count) { int rc = recvfrom(mysock, buf, count, 0, NULL, NULL); //printf("received %d bytes count %d\n", rc, (int)count); @@ -128,7 +128,6 @@ int main(int argc, char** argv) int dup = 0; int qos = 1; int retained = 0, packetid = 1; - char *topicname = "a long topic name"; MQTTSNPacket_connectData options = MQTTSNPacket_connectData_initializer; if (argc > 1) diff --git a/src/MQTTSNConnect.h b/src/MQTTSNConnect.h index 5814754..2695985 100644 --- a/src/MQTTSNConnect.h +++ b/src/MQTTSNConnect.h @@ -25,9 +25,9 @@ typedef struct */ int struct_version; MQTTSNString clientID; - int duration; - int cleansession; - int willFlag; + unsigned short duration; + unsigned char cleansession; + unsigned char willFlag; } MQTTSNPacket_connectData; #define MQTTSNPacket_connectData_initializer { {'M', 'Q', 'S', 'C'}, 0, {NULL, {0, NULL}}, 10, 1, 0 } @@ -59,14 +59,14 @@ int MQTTSNDeserialize_willmsgupd(MQTTSNString* willMsg, unsigned char* buf, int int MQTTSNSerialize_willmsgresp(unsigned char* buf, int buflen, int resp_rc); int MQTTSNDeserialize_willmsgresp(int* resp_rc, unsigned char* buf, int buflen); -int MQTTSNSerialize_willtopic(unsigned char* buf, int buflen, int willQoS, int willRetain, MQTTSNString willTopic); -int MQTTSNDeserialize_willtopic(int *willQoS, int *willRetain, MQTTSNString* willTopic, unsigned char* buf, int buflen); +int MQTTSNSerialize_willtopic(unsigned char* buf, int buflen, int willQoS, unsigned char willRetain, MQTTSNString willTopic); +int MQTTSNDeserialize_willtopic(int* willQoS, unsigned char* willRetain, MQTTSNString* willTopic, unsigned char* buf, int buflen); int MQTTSNSerialize_willtopicreq(unsigned char* buf, int buflen); int MQTTSNDeserialize_willtopicreq(unsigned char* buf, int buflen); -int MQTTSNSerialize_willtopicupd(unsigned char* buf, int buflen, int willQoS, int willRetain, MQTTSNString willTopic); -int MQTTSNDeserialize_willtopicupd(int *willQoS, int *willRetain, MQTTSNString* willTopic, unsigned char* buf, int buflen); +int MQTTSNSerialize_willtopicupd(unsigned char* buf, int buflen, int willQoS, unsigned char willRetain, MQTTSNString willTopic); +int MQTTSNDeserialize_willtopicupd(int *willQoS, unsigned char *willRetain, MQTTSNString* willTopic, unsigned char* buf, int buflen); int MQTTSNSerialize_willtopicresp(unsigned char* buf, int buflen, int resp_rc); int MQTTSNDeserialize_willtopicresp(int* resp_rc, unsigned char* buf, int buflen); diff --git a/src/MQTTSNConnectClient.c b/src/MQTTSNConnectClient.c index f5f9926..d7f1489 100644 --- a/src/MQTTSNConnectClient.c +++ b/src/MQTTSNConnectClient.c @@ -222,7 +222,7 @@ exit: * @param willTopic the topic of the will message * @return serialized length, or error if 0 */ -int MQTTSNSerialize_willtopic1(unsigned char* buf, int buflen, int willQoS, int willRetain, MQTTSNString willTopic, +int MQTTSNSerialize_willtopic1(unsigned char* buf, int buflen, int willQoS, unsigned char willRetain, MQTTSNString willTopic, enum MQTTSN_msgTypes packet_type) { unsigned char *ptr = buf; @@ -263,7 +263,7 @@ exit: * @param willTopic the topic of the will message * @return serialized length, or error if 0 */ -int MQTTSNSerialize_willtopicupd(unsigned char* buf, int buflen, int willQoS, int willRetain, MQTTSNString willTopic) +int MQTTSNSerialize_willtopicupd(unsigned char* buf, int buflen, int willQoS, unsigned char willRetain, MQTTSNString willTopic) { return MQTTSNSerialize_willtopic1(buf, buflen, willQoS, willRetain, willTopic, MQTTSN_WILLTOPICUPD); } @@ -278,7 +278,7 @@ int MQTTSNSerialize_willtopicupd(unsigned char* buf, int buflen, int willQoS, in * @param willTopic the topic of the will message * @return serialized length, or error if 0 */ -int MQTTSNSerialize_willtopic(unsigned char* buf, int buflen, int willQoS, int willRetain, MQTTSNString willTopic) +int MQTTSNSerialize_willtopic(unsigned char* buf, int buflen, int willQoS, unsigned char willRetain, MQTTSNString willTopic) { return MQTTSNSerialize_willtopic1(buf, buflen, willQoS, willRetain, willTopic, MQTTSN_WILLTOPIC); } diff --git a/src/MQTTSNConnectServer.c b/src/MQTTSNConnectServer.c index 20db5de..5dc24a9 100644 --- a/src/MQTTSNConnectServer.c +++ b/src/MQTTSNConnectServer.c @@ -255,7 +255,7 @@ exit: * @param len the length in bytes of the data in the supplied buffer * @return error code. 1 is success, 0 is failure */ -int MQTTSNDeserialize_willtopic1(int *willQoS, int *willRetain, MQTTSNString* willTopic, unsigned char* buf, int len, +int MQTTSNDeserialize_willtopic1(int *willQoS, unsigned char *willRetain, MQTTSNString* willTopic, unsigned char* buf, int len, enum MQTTSN_msgTypes packet_type) { MQTTSNFlags flags; @@ -294,7 +294,7 @@ exit: * @param len the length in bytes of the data in the supplied buffer * @return error code. 1 is success, 0 is failure */ -int MQTTSNDeserialize_willtopic(int *willQoS, int *willRetain, MQTTSNString* willTopic, unsigned char* buf, int len) +int MQTTSNDeserialize_willtopic(int *willQoS, unsigned char *willRetain, MQTTSNString* willTopic, unsigned char* buf, int len) { return MQTTSNDeserialize_willtopic1(willQoS, willRetain, willTopic, buf, len, MQTTSN_WILLTOPIC); } @@ -306,7 +306,7 @@ int MQTTSNDeserialize_willtopic(int *willQoS, int *willRetain, MQTTSNString* wil * @param len the length in bytes of the data in the supplied buffer * @return error code. 1 is success, 0 is failure */ -int MQTTSNDeserialize_willtopicupd(int *willQoS, int *willRetain, MQTTSNString* willTopic, unsigned char* buf, int len) +int MQTTSNDeserialize_willtopicupd(int *willQoS, unsigned char *willRetain, MQTTSNString* willTopic, unsigned char* buf, int len) { return MQTTSNDeserialize_willtopic1(willQoS, willRetain, willTopic, buf, len, MQTTSN_WILLTOPICUPD); } diff --git a/src/MQTTSNDeserializePublish.c b/src/MQTTSNDeserializePublish.c index d1da741..dbf1bdc 100644 --- a/src/MQTTSNDeserializePublish.c +++ b/src/MQTTSNDeserializePublish.c @@ -33,7 +33,7 @@ * @param buflen the length in bytes of the data in the supplied buffer * @return error code. 1 is success */ -int MQTTSNDeserialize_publish(int* dup, int* qos, int* retained, unsigned short* packetid, MQTTSN_topicid* topic, +int MQTTSNDeserialize_publish(unsigned char* dup, int* qos, unsigned char* retained, unsigned short* packetid, MQTTSN_topicid* topic, unsigned char** payload, int* payloadlen, unsigned char* buf, int buflen) { MQTTSNFlags flags; diff --git a/src/MQTTSNPacket.c b/src/MQTTSNPacket.c index ef1cc64..4f98b6a 100644 --- a/src/MQTTSNPacket.c +++ b/src/MQTTSNPacket.c @@ -83,7 +83,7 @@ int MQTTSNPacket_encode(unsigned char* buf, int length) * @param value the decoded length returned * @return the number of bytes read from the socket */ -int MQTTSNPacket_decode(unsigned char* buf, size_t buflen, int* value) +int MQTTSNPacket_decode(unsigned char* buf, int buflen, int* value) { int len = MQTTSNPACKET_READ_ERROR; #define MAX_NO_OF_LENGTH_BYTES 3 @@ -246,7 +246,7 @@ int MQTTSNstrlen(MQTTSNString MQTTSNString) * @param getfn pointer to a function which will read any number of bytes from the needed source * @return integer MQTT packet type, or MQTTSNPACKET_READ_ERROR on error */ -int MQTTSNPacket_read(unsigned char* buf, int buflen, int (*getfn)(unsigned char*, size_t)) +int MQTTSNPacket_read(unsigned char* buf, int buflen, int (*getfn)(unsigned char*, int)) { int rc = MQTTSNPACKET_READ_ERROR; const int MQTTSN_MIN_PACKET_LENGTH = 3; diff --git a/src/MQTTSNPacket.h b/src/MQTTSNPacket.h index f696a92..974619f 100644 --- a/src/MQTTSNPacket.h +++ b/src/MQTTSNPacket.h @@ -126,13 +126,11 @@ int MQTTSNstrlen(MQTTSNString mqttsnstring); #include "MQTTSNUnsubscribe.h" #include "MQTTSNSearch.h" -#include - char* MQTTSNPacket_name(int ptype); int MQTTSNPacket_len(int length); int MQTTSNPacket_encode(unsigned char* buf, int length); -int MQTTSNPacket_decode(unsigned char* buf, size_t buflen, int* value); +int MQTTSNPacket_decode(unsigned char* buf, int buflen, int* value); int readInt(unsigned char** pptr); char readChar(unsigned char** pptr); @@ -142,7 +140,7 @@ int readMQTTSNString(MQTTSNString* mqttstring, unsigned char** pptr, unsigned ch void writeCString(unsigned char** pptr, char* string); void writeMQTTSNString(unsigned char** pptr, MQTTSNString mqttstring); -int MQTTSNPacket_read(unsigned char* buf, int buflen, int (*getfn)(unsigned char*, size_t)); +int MQTTSNPacket_read(unsigned char* buf, int buflen, int (*getfn)(unsigned char*, int)); #ifdef __cplusplus /* If this is a C++ compiler, use C linkage */ } diff --git a/src/MQTTSNPublish.h b/src/MQTTSNPublish.h index 792dcd8..937817b 100644 --- a/src/MQTTSNPublish.h +++ b/src/MQTTSNPublish.h @@ -17,9 +17,9 @@ #if !defined(MQTTSNPUBLISH_H_) #define MQTTSNPUBLISH_H_ -int MQTTSNSerialize_publish(unsigned char* buf, int buflen, int dup, int qos, int retained, unsigned short packetid, +int MQTTSNSerialize_publish(unsigned char* buf, int buflen, unsigned char dup, int qos, unsigned char retained, unsigned short packetid, MQTTSN_topicid topic, unsigned char* payload, int payloadlen); -int MQTTSNDeserialize_publish(int* dup, int* qos, int* retained, unsigned short* packetid, +int MQTTSNDeserialize_publish(unsigned char* dup, int* qos, unsigned char* retained, unsigned short* packetid, MQTTSN_topicid* topic, unsigned char** payload, int* payloadlen, unsigned char* buf, int len); int MQTTSNSerialize_puback(unsigned char* buf, int buflen, unsigned short topicid, unsigned short packetid, diff --git a/src/MQTTSNSerializePublish.c b/src/MQTTSNSerializePublish.c index e495f76..f34db32 100644 --- a/src/MQTTSNSerializePublish.c +++ b/src/MQTTSNSerializePublish.c @@ -51,7 +51,7 @@ int MQTTSNSerialize_publishLength(int payloadlen, MQTTSN_topicid topic, int qos) * @param payloadlen integer - the length of the MQTT payload * @return the length of the serialized data. <= 0 indicates error */ -int MQTTSNSerialize_publish(unsigned char* buf, int buflen, int dup, int qos, int retained, unsigned short packetid, +int MQTTSNSerialize_publish(unsigned char* buf, int buflen, unsigned char dup, int qos, unsigned char retained, unsigned short packetid, MQTTSN_topicid topic, unsigned char* payload, int payloadlen) { unsigned char *ptr = buf; diff --git a/src/MQTTSNSubscribe.h b/src/MQTTSNSubscribe.h index c8b8a78..6232553 100644 --- a/src/MQTTSNSubscribe.h +++ b/src/MQTTSNSubscribe.h @@ -17,9 +17,9 @@ #if !defined(MQTTSNSUBSCRIBE_H_) #define MQTTSNSUBSCRIBE_H_ -int MQTTSNSerialize_subscribe(unsigned char* buf, int buflen, int dup, int qos, unsigned short packetid, +int MQTTSNSerialize_subscribe(unsigned char* buf, int buflen, unsigned char dup, int qos, unsigned short packetid, MQTTSN_topicid* topicFilter); -int MQTTSNDeserialize_subscribe(int* dup, int* qos, unsigned short* packetid, +int MQTTSNDeserialize_subscribe(unsigned char* dup, int* qos, unsigned short* packetid, MQTTSN_topicid* topicFilter, unsigned char* buf, int buflen); int MQTTSNSerialize_suback(unsigned char* buf, int buflen, int qos, unsigned short topicid, unsigned short packetid, diff --git a/src/MQTTSNSubscribeClient.c b/src/MQTTSNSubscribeClient.c index cbe5074..42a34df 100644 --- a/src/MQTTSNSubscribeClient.c +++ b/src/MQTTSNSubscribeClient.c @@ -48,7 +48,8 @@ int MQTTSNSerialize_subscribeLength(MQTTSN_topicid* topicFilter) * @param topic MQTTSN_topicid - the MQTT-SN topic in the subscribe * @return the length of the serialized data. <= 0 indicates error */ -int MQTTSNSerialize_subscribe(unsigned char* buf, int buflen, int dup, int qos, unsigned short packetid, MQTTSN_topicid* topicFilter) +int MQTTSNSerialize_subscribe(unsigned char* buf, int buflen, unsigned char dup, int qos, unsigned short packetid, + MQTTSN_topicid* topicFilter) { unsigned char *ptr = buf; MQTTSNFlags flags; diff --git a/src/MQTTSNSubscribeServer.c b/src/MQTTSNSubscribeServer.c index c49cdbb..d16f80a 100644 --- a/src/MQTTSNSubscribeServer.c +++ b/src/MQTTSNSubscribeServer.c @@ -29,7 +29,7 @@ * @param buflen the length in bytes of the data in the supplied buffer * @return error code. 1 is success */ -int MQTTSNDeserialize_subscribe(int* dup, int* qos, unsigned short* packetid, +int MQTTSNDeserialize_subscribe(unsigned char* dup, int* qos, unsigned short* packetid, MQTTSN_topicid* topicFilter, unsigned char* buf, int buflen) { MQTTSNFlags flags; diff --git a/test/test1.c b/test/test1.c index 15da41b..42fa445 100644 --- a/test/test1.c +++ b/test/test1.c @@ -412,17 +412,17 @@ int test2(struct Options options) unsigned char buf[100]; int buflen = sizeof(buf); - int dup = 0; + unsigned char dup = 0; int qos = 2; - int retained = 0; + unsigned char retained = 0; unsigned short msgid = 23; MQTTSN_topicid topic; unsigned char *payload = (unsigned char*)"kkhkhkjkj jkjjk jk jk "; int payloadlen = strlen((char*)payload); - int dup2 = 1; + unsigned char dup2 = 1; int qos2 = 1; - int retained2 = 1; + unsigned char retained2 = 1; unsigned short msgid2 = 3243; MQTTSN_topicid topic2; unsigned char *payload2 = NULL; @@ -511,7 +511,8 @@ int test3(struct Options options) assert("good rc from deserialize willmsgreq", rc == 1, "rc was %d\n", rc); memset(buf, '\0', sizeof(buf)); - int willQoS = 1, willRetain = 1, willQoS1 = 0, willRetain1 = 0; + int willQoS = 1, willQoS1 = 0; + unsigned char willRetain = 1, willRetain1 = 0; MQTTSNString willTopic = MQTTSNString_initializer, willTopic1 = MQTTSNString_initializer; willTopic.cstring = "a will topic"; rc = MQTTSNSerialize_willtopic(buf, buflen, willQoS, willRetain, willTopic); @@ -591,12 +592,12 @@ int test4(struct Options options) unsigned char buf[100]; size_t buflen = sizeof(buf); - int dup = 0; + unsigned char dup = 0; unsigned short packetid = 23; MQTTSN_topicid topicFilter; int req_qos = 2; - int dup2 = 1; + unsigned char dup2 = 1; unsigned short packetid2 = 2223; MQTTSN_topicid topicFilter2; int req_qos2 = 0; diff --git a/test/test2.c b/test/test2.c index d815bb5..1b3d013 100644 --- a/test/test2.c +++ b/test/test2.c @@ -289,7 +289,7 @@ int sendPacketBuffer(int asocket, char* host, int port, unsigned char* buf, int int mysock = 0; -int getdata(unsigned char* buf, size_t count) +int getdata(unsigned char* buf, int count) { int rc = recvfrom(mysock, buf, count, 0, NULL, NULL); //printf("received %d bytes count %d\n", rc, (int)count);