version 1.1.1.1.2.11, 2011/11/28 10:17:12
|
version 1.1.1.1.2.14, 2011/12/05 16:55:40
|
Line 39 mqtt_SetErr(int eno, char *estr, ...)
|
Line 39 mqtt_SetErr(int eno, char *estr, ...)
|
va_end(lst); |
va_end(lst); |
} |
} |
|
|
|
#pragma GCC visibility push(hidden) |
|
// _mqtt_readHEADER() read fixed header from MQTT message |
|
inline struct mqtthdr * |
|
_mqtt_readHEADER(mqtt_msg_t * __restrict buf, u_char cmd, int *bytes, int *len) |
|
{ |
|
struct mqtthdr *hdr; |
|
|
|
if (!buf || !buf->msg_base || !buf->msg_len) |
|
return NULL; |
|
|
|
hdr = (struct mqtthdr*) buf->msg_base; |
|
if (hdr->mqtt_msg.type != cmd) { |
|
mqtt_SetErr(EINVAL, "Error:: wrong command #%d should be %d", |
|
hdr->mqtt_msg.type, cmd); |
|
return NULL; |
|
} |
|
|
|
*len = mqtt_decodeLen(hdr->mqtt_len, bytes); |
|
return hdr; |
|
} |
|
#pragma GCC visibility pop |
|
|
// ---------------------------------------------------------- |
// ---------------------------------------------------------- |
|
|
/* |
/* |
Line 158 mqtt_encodeLen(u_int num)
|
Line 180 mqtt_encodeLen(u_int num)
|
/* |
/* |
* mqtt_decodeLen() Decode length from MQTT packet |
* mqtt_decodeLen() Decode length from MQTT packet |
* |
* |
* @len = length | * @len = length from MQTT header |
* @n = sizeof bytes, if !=NULL |
* @n = sizeof bytes, if !=NULL |
* return: -1 error, >-1 length of message |
* return: -1 error, >-1 length of message |
*/ |
*/ |
inline u_int |
inline u_int |
mqtt_decodeLen(u_int len, char *n) | mqtt_decodeLen(void * __restrict len, int * __restrict n) |
{ |
{ |
register u_int i, dig, mul; |
register u_int i, dig, mul; |
u_int ret = 0; |
u_int ret = 0; |
u_char *p = (u_char*) &len; | u_char *p = (u_char*) len; |
|
|
if (len > 0xffffff7f) | if (!len) |
return (u_int) -1; |
return (u_int) -1; |
|
|
for (mul = 1, i = 0; i < sizeof ret; i++, mul *= 0x80) { |
for (mul = 1, i = 0; i < sizeof ret; i++, mul *= 0x80) { |
Line 265 mqtt_subFree(mqtt_subscr_t ** __restrict subs)
|
Line 287 mqtt_subFree(mqtt_subscr_t ** __restrict subs)
|
free(v->sub_topic._base); |
free(v->sub_topic._base); |
v->sub_topic._base = NULL; |
v->sub_topic._base = NULL; |
v->sub_topic._size = 0; |
v->sub_topic._size = 0; |
|
|
|
if (v->sub_value._base) { |
|
free(v->sub_value._base); |
|
v->sub_value._base = NULL; |
|
v->sub_value._size = 0; |
|
} |
} |
} |
|
|
free(*subs); |
free(*subs); |
Line 281 inline mqtt_subscr_t *
|
Line 309 inline mqtt_subscr_t *
|
mqtt_subAlloc(u_short num) |
mqtt_subAlloc(u_short num) |
{ |
{ |
mqtt_subscr_t *s = NULL; |
mqtt_subscr_t *s = NULL; |
register int i; |
|
|
|
s = malloc((num + 1) * sizeof(mqtt_subscr_t)); |
s = malloc((num + 1) * sizeof(mqtt_subscr_t)); |
if (!s) { |
if (!s) { |
Line 289 mqtt_subAlloc(u_short num)
|
Line 316 mqtt_subAlloc(u_short num)
|
return NULL; |
return NULL; |
} else |
} else |
memset(s, 0, (num + 1) * sizeof(mqtt_subscr_t)); |
memset(s, 0, (num + 1) * sizeof(mqtt_subscr_t)); |
|
|
for (i = 0; i < num; i++) |
|
if (!(s[i].sub_topic._base = malloc(0))) { |
|
LOGERR; |
|
break; |
|
} |
|
|
|
return s; |
return s; |
} |
} |