--- libaitmqtt/src/aitmqtt.c 2012/05/05 13:10:24 1.1.1.1.2.14 +++ libaitmqtt/src/aitmqtt.c 2012/06/11 08:37:41 1.1.1.1.2.15 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: aitmqtt.c,v 1.1.1.1.2.14 2012/05/05 13:10:24 misho Exp $ +* $Id: aitmqtt.c,v 1.1.1.1.2.15 2012/06/11 08:37:41 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -188,6 +188,38 @@ mqtt_msgRealloc(mqtt_msg_t * __restrict msg, u_short l msg->msg_base = p; return ret; +} + +/* + * mqtt_msgDup() - Duplicate message buffer + * + * @msg = Message + * return: NULL error or !=NULL duplicated message, after use must call mqtt_msgFree() with all!=0 + */ +inline mqtt_msg_t * +mqtt_msgDup(mqtt_msg_t * __restrict msg) +{ + mqtt_msg_t *m = NULL; + + m = malloc(sizeof(mqtt_msg_t)); + if (!m) { + LOGERR; + return NULL; + } else + memset(m, 0, sizeof(mqtt_msg_t)); + + if (msg->msg_len) { + m->msg_len = msg->msg_len; + m->msg_base = malloc(m->msg_len); + if (!m->msg_base) { + LOGERR; + free(m); + return NULL; + } else + memcpy(m->msg_base, msg->msg_base, m->msg_len); + } + + return m; } /*