MQTTPacket library (clone of https://os.mbed.com/teams/mqtt/code/MQTTPacket/)

Dependents:   MQTT_ON_AWS MQTT

Revision:
12:cd99ac9cb25a
Parent:
1:069ae45b7070
Child:
13:5e60cd1a52e7
diff -r b97b9873af52 -r cd99ac9cb25a MQTTConnectServer.c
--- a/MQTTConnectServer.c	Tue May 06 10:57:57 2014 +0100
+++ b/MQTTConnectServer.c	Fri Aug 01 13:03:52 2014 +0100
@@ -18,7 +18,7 @@
 #include "MQTTPacket.h"
 #include <string.h>
 
-#define min(a, b) ((a < b) ? 1 : 0)
+#define min(a, b) ((a < b) ? a : b)
 
 
 /**
@@ -32,12 +32,11 @@
 	int rc = 0;
 
 	if (version == 3 && memcmp(protocol->lenstring.data, "MQIdsp",
-			min(6, protocol->lenstring.len)))
+			min(6, protocol->lenstring.len)) == 0)
 		rc = 1;
-	else if (version == 3 && memcmp(protocol->lenstring.data, "MQTT",
-			min(4, protocol->lenstring.len)))
+	else if (version == 4 && memcmp(protocol->lenstring.data, "MQTT",
+			min(4, protocol->lenstring.len)) == 0)
 		rc = 1;
-
 	return rc;
 }
 
@@ -63,7 +62,7 @@
 	FUNC_ENTRY;
 	header.byte = readChar(&curdata);
 
-	curdata += (rc = MQTTPacket_decodeBuf(curdata, &mylen)); /* read remaining length */
+	curdata += MQTTPacket_decodeBuf(curdata, &mylen); /* read remaining length */
 
 	if (!readMQTTLenString(&Protocol, &curdata, enddata) ||
 		enddata - curdata < 0) /* do we have enough data to read the protocol version byte? */