version 1.1.1.1.2.9, 2011/11/22 13:00:33
|
version 1.1.1.1.2.11, 2011/11/28 10:17:12
|
Line 238 mqtt_str2sub(const char **csStr, u_short strnum, u_cha
|
Line 238 mqtt_str2sub(const char **csStr, u_short strnum, u_cha
|
memset(v, 0, (items + 1) * sizeof(mqtt_subscr_t)); |
memset(v, 0, (items + 1) * sizeof(mqtt_subscr_t)); |
|
|
for (i = 0; i < items; i++) { |
for (i = 0; i < items; i++) { |
v[i].sub_sb.val = htons(strlen(csStr[i])); | v[i].sub_topic._size = strlen(csStr[i]); |
v[i].sub_data = strdup(csStr[i]); | v[i].sub_topic._base = strdup(csStr[i]); |
if (qoses && qoses[i] < MQTT_QOS_RESERVED) |
if (qoses && qoses[i] < MQTT_QOS_RESERVED) |
v[i].sub_qos = qoses[i]; | v[i].sub_ret = qoses[i]; |
} |
} |
|
|
return v; |
return v; |
Line 251 mqtt_str2sub(const char **csStr, u_short strnum, u_cha
|
Line 251 mqtt_str2sub(const char **csStr, u_short strnum, u_cha
|
* mqtt_subFree() Free array from subscribe variables |
* mqtt_subFree() Free array from subscribe variables |
* |
* |
* @subs = Subscribe variables |
* @subs = Subscribe variables |
* @all = if !=0 free and subs pointer |
|
* return: none |
* return: none |
*/ |
*/ |
inline void |
inline void |
mqtt_subFree(mqtt_subscr_t ** __restrict subs, int all) | mqtt_subFree(mqtt_subscr_t ** __restrict subs) |
{ |
{ |
mqtt_subscr_t *v; |
mqtt_subscr_t *v; |
|
|
if (!subs) |
if (!subs) |
return; |
return; |
|
|
for (v = *subs; v->sub_data; v++) { | for (v = *subs; v->sub_topic._base; v++) { |
free(v->sub_data); | free(v->sub_topic._base); |
v->sub_data = NULL; | v->sub_topic._base = NULL; |
| v->sub_topic._size = 0; |
} |
} |
|
|
if (all) { | free(*subs); |
free(*subs); | *subs = NULL; |
*subs = NULL; | |
} | |
} |
} |
|
|
/* |
/* |
* mqtt_subAlloc() Create array from subscribe variables |
* mqtt_subAlloc() Create array from subscribe variables |
* |
* |
* @num = Number of elements |
* @num = Number of elements |
* return: NULL error or subscribe array, after use must call mqtt_subFree() with all!=0 | * return: NULL error or subscribe array, after use must call mqtt_subFree() |
*/ |
*/ |
inline mqtt_subscr_t * |
inline mqtt_subscr_t * |
mqtt_subAlloc(u_short num) |
mqtt_subAlloc(u_short num) |
Line 293 mqtt_subAlloc(u_short num)
|
Line 291 mqtt_subAlloc(u_short num)
|
memset(s, 0, (num + 1) * sizeof(mqtt_subscr_t)); |
memset(s, 0, (num + 1) * sizeof(mqtt_subscr_t)); |
|
|
for (i = 0; i < num; i++) |
for (i = 0; i < num; i++) |
if (!(s[i].sub_data = malloc(0))) { | if (!(s[i].sub_topic._base = malloc(0))) { |
LOGERR; |
LOGERR; |
break; |
break; |
} |
} |