--- libaitmqtt/src/pub.c 2012/04/26 12:33:14 1.1.1.1.2.2 +++ libaitmqtt/src/pub.c 2012/04/27 15:15:12 1.1.1.1.2.3 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: pub.c,v 1.1.1.1.2.2 2012/04/26 12:33:14 misho Exp $ +* $Id: pub.c,v 1.1.1.1.2.3 2012/04/27 15:15:12 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -209,9 +209,9 @@ mqtt_msgPUBCOMP(mqtt_msg_t * __restrict buf, u_short m * @msgID = MessageID * @pData = Data buffer * @datLen = Data buffer length, if *datLen == 0 allocate memory for pData - * return: NULL error or !=NULL MQTT fixed header + * return: NULL error or !=NULL MQTT data buffer */ -struct mqtthdr * +void * mqtt_readPUBLISH(mqtt_msg_t * __restrict buf, char * __restrict psTopic, int topicLen, u_short *msgID, void * __restrict pData, int *datLen) { @@ -221,7 +221,7 @@ mqtt_readPUBLISH(mqtt_msg_t * __restrict buf, char * _ mqtt_len_t *v; caddr_t pos; - if (!buf || !psTopic || !msgID || !pData) + if (!buf || !psTopic || !msgID) return NULL; hdr = _mqtt_readHEADER(buf, MQTT_TYPE_PUBLISH, &ret, &len); @@ -257,12 +257,14 @@ mqtt_readPUBLISH(mqtt_msg_t * __restrict buf, char * _ mqtt_SetErr(EINVAL, "Short message length %d", len); return NULL; } else { - if (!*datLen) { - if (!(pData = malloc(len))) { + if (!*datLen || !pData) { + if (!(pData = malloc(len + 1))) { LOGERR; return NULL; - } else + } else { *datLen = len; + ((char*) pData)[len] = 0; + } } memset(pData, 0, *datLen); @@ -271,7 +273,7 @@ mqtt_readPUBLISH(mqtt_msg_t * __restrict buf, char * _ memcpy(pData, pos, *datLen); } - return hdr; + return pData; } /*