version 1.1.1.1.2.7, 2012/04/26 15:26:37
|
version 1.1.1.1.2.11, 2012/04/27 16:17:11
|
Line 287 mqtt_str2subs(const char **csStr, u_short strnum, u_ch
|
Line 287 mqtt_str2subs(const char **csStr, u_short strnum, u_ch
|
|
|
if (!csStr) |
if (!csStr) |
return NULL; |
return NULL; |
for (items = 0, strs = csStr; *strs; items++, strs++) |
|
if (strnum && items >= strnum) { |
|
items = strnum; |
|
break; |
|
} |
|
|
|
|
for (items = 0, strs = csStr; |
|
(!strnum || (strnum && items < strnum)) && *strs; |
|
items++, strs++); |
|
|
if (!(v = malloc((items + 1) * sizeof(mqtt_subscr_t)))) { |
if (!(v = malloc((items + 1) * sizeof(mqtt_subscr_t)))) { |
LOGERR; |
LOGERR; |
return NULL; |
return NULL; |
Line 368 mqtt_subAlloc(u_short num)
|
Line 367 mqtt_subAlloc(u_short num)
|
* return: NULL error or subscribe array, after use must call mqtt_subFree() |
* return: NULL error or subscribe array, after use must call mqtt_subFree() |
*/ |
*/ |
inline mqtt_subscr_t * |
inline mqtt_subscr_t * |
mqtt_subRealloc(mqtt_subscr_t * __restrict subs, u_short num) | mqtt_subRealloc(mqtt_subscr_t ** __restrict subs, u_short num) |
{ |
{ |
mqtt_subscr_t *s = NULL; |
mqtt_subscr_t *s = NULL; |
|
|
s = realloc(subs, (num + 1) * sizeof(mqtt_subscr_t)); | if (!subs) |
| return NULL; |
| |
| s = realloc(*subs, (num + 1) * sizeof(mqtt_subscr_t)); |
if (!s) { |
if (!s) { |
LOGERR; |
LOGERR; |
return NULL; |
return NULL; |
|
} else { |
|
memset(s + num, 0, sizeof(mqtt_subscr_t)); |
|
*subs = s; |
} |
} |
|
|
return s; | return *subs; |
} |
} |
|
|
|
/* |
|
* mqtt_subCopy() - Copy subscription structure to another one |
|
* |
|
* @dst = destination subscription |
|
* @src = source subscription |
|
* return: =NULL error or !=NULL successful copied a structure |
|
*/ |
|
inline mqtt_subscr_t * |
|
mqtt_subCopy(mqtt_subscr_t * __restrict dst, mqtt_subscr_t * __restrict src) |
|
{ |
|
if (!dst || !src) |
|
return NULL; |
|
|
|
if (src->sub_topic.msg_base) { |
|
dst->sub_topic.msg_base = malloc(src->sub_topic.msg_len + 1); |
|
if (!dst->sub_topic.msg_base) { |
|
LOGERR; |
|
memset(dst, 0, sizeof(mqtt_subscr_t)); |
|
return NULL; |
|
} else { |
|
dst->sub_topic.msg_len = src->sub_topic.msg_len; |
|
((char*) dst->sub_topic.msg_base)[dst->sub_topic.msg_len] = 0; |
|
memcpy(dst->sub_topic.msg_base, src->sub_topic.msg_base, |
|
dst->sub_topic.msg_len); |
|
} |
|
} |
|
if (src->sub_value.msg_base) { |
|
dst->sub_value.msg_base = malloc(src->sub_value.msg_len + 1); |
|
if (!dst->sub_value.msg_base) { |
|
LOGERR; |
|
if (dst->sub_topic.msg_base) |
|
free(dst->sub_topic.msg_base); |
|
memset(dst, 0, sizeof(mqtt_subscr_t)); |
|
return NULL; |
|
} else { |
|
dst->sub_value.msg_len = src->sub_value.msg_len; |
|
((char*) dst->sub_value.msg_base)[dst->sub_value.msg_len] = 0; |
|
memcpy(dst->sub_value.msg_base, src->sub_value.msg_base, |
|
dst->sub_value.msg_len); |
|
} |
|
} |
|
|
|
dst->sub_ret = src->sub_ret; |
|
return dst; |
|
} |
|
|
|
|
/* |
/* |
* mqtt_expandTopic() - Expanding topic to regular expression |
* mqtt_expandTopic() - Expanding topic to regular expression |