version 1.1.2.6, 2011/12/05 14:11:47
|
version 1.1.2.11, 2011/12/09 09:55:27
|
Line 32 mqtt_msgCONNECT(mqtt_msg_t * __restrict buf, const cha
|
Line 32 mqtt_msgCONNECT(mqtt_msg_t * __restrict buf, const cha
|
|
|
if (!buf || !csConnID) |
if (!buf || !csConnID) |
return -1; |
return -1; |
if (strlen(csConnID) > 23) { | if (strlen(csConnID) > 24) { |
mqtt_SetErr(EINVAL, "Error:: invalid argument ConnID is too long (max 23 bytes)"); |
mqtt_SetErr(EINVAL, "Error:: invalid argument ConnID is too long (max 23 bytes)"); |
return -1; |
return -1; |
} |
} |
if (csUser && strlen(csUser) > 12) { | if (csUser && strlen(csUser) > 13) { |
mqtt_SetErr(EINVAL, "Error:: invalid argument Username is too long (max 12 bytes)"); |
mqtt_SetErr(EINVAL, "Error:: invalid argument Username is too long (max 12 bytes)"); |
return -1; |
return -1; |
} |
} |
if (csPass && strlen(csPass) > 12) { | if (csPass && strlen(csPass) > 13) { |
mqtt_SetErr(EINVAL, "Error:: invalid argument Password is too long (max 12 bytes)"); |
mqtt_SetErr(EINVAL, "Error:: invalid argument Password is too long (max 12 bytes)"); |
return -1; |
return -1; |
} |
} |
Line 253 mqtt_msgDISCONNECT(mqtt_msg_t * __restrict buf)
|
Line 253 mqtt_msgDISCONNECT(mqtt_msg_t * __restrict buf)
|
* @userLen = Username length |
* @userLen = Username length |
* @psPass = Password for Username, only if csUser is set |
* @psPass = Password for Username, only if csUser is set |
* @passLen = Password length |
* @passLen = Password length |
* @psWillTopic = Will Topic if !=NULL Will Flags set into message | * @psWillTopic = Will Topic if !=NULL Will Flags set into message and must be free() |
* @topicLen = Will Topic length | * @psWillMessage = Will Message, may be NULL if !NULL must be free() after use! |
* @psWillMessage = Will Message, may be NULL | |
* @msgLen = Will Message length | |
* return: .reserved == 1 is error or == 0 connection flags & msg ok |
* return: .reserved == 1 is error or == 0 connection flags & msg ok |
*/ |
*/ |
mqtthdr_connflgs_t |
mqtthdr_connflgs_t |
mqtt_readCONNECT(mqtt_msg_t * __restrict buf, u_short *kasec, char * __restrict psConnID, int connLen, |
mqtt_readCONNECT(mqtt_msg_t * __restrict buf, u_short *kasec, char * __restrict psConnID, int connLen, |
char * __restrict psUser, int userLen, char * __restrict psPass, int passLen, |
char * __restrict psUser, int userLen, char * __restrict psPass, int passLen, |
char * __restrict psWillTopic, int topicLen, char * __restrict psWillMessage, int msgLen) | char ** __restrict psWillTopic, char ** __restrict psWillMessage) |
{ |
{ |
mqtthdr_connflgs_t flg = MQTT_CONNFLGS_INIT; |
mqtthdr_connflgs_t flg = MQTT_CONNFLGS_INIT; |
struct mqtthdr *hdr; |
struct mqtthdr *hdr; |
Line 275 mqtt_readCONNECT(mqtt_msg_t * __restrict buf, u_short
|
Line 273 mqtt_readCONNECT(mqtt_msg_t * __restrict buf, u_short
|
if (!buf || !buf->msg_base || !buf->msg_len || !psConnID || !connLen) |
if (!buf || !buf->msg_base || !buf->msg_len || !psConnID || !connLen) |
return flg; |
return flg; |
|
|
hdr = (struct mqtthdr*) buf->msg_base; | hdr = _mqtt_readHEADER(buf, MQTT_TYPE_CONNECT, &ret, &len); |
if (hdr->mqtt_msg.type != MQTT_TYPE_CONNECT) { | if (!hdr) |
mqtt_SetErr(EINVAL, "Error:: wrong command #%d", hdr->mqtt_msg.type); | |
return flg; |
return flg; |
} else |
|
len = mqtt_decodeLen(hdr->mqtt_len, &ret); |
|
if (len < 12) { |
if (len < 12) { |
mqtt_SetErr(EINVAL, "Error:: short message length %d", len); |
mqtt_SetErr(EINVAL, "Error:: short message length %d", len); |
return flg; |
return flg; |
Line 332 mqtt_readCONNECT(mqtt_msg_t * __restrict buf, u_short
|
Line 327 mqtt_readCONNECT(mqtt_msg_t * __restrict buf, u_short
|
flg.reserved = 1; |
flg.reserved = 1; |
return flg; |
return flg; |
} else { |
} else { |
if (psWillTopic && topicLen) { | if (psWillTopic) { |
memset(psWillTopic, 0, topicLen--); | *psWillTopic = malloc(ntohs(var->var_sb.val) + 1); |
memcpy(psWillTopic, var->var_data, | if (!*psWillTopic) { |
ntohs(var->var_sb.val) > topicLen ? topicLen : ntohs(var->var_sb.val)); | LOGERR; |
| flg.reserved = 1; |
| return flg; |
| } else |
| memset(*psWillTopic, 0, ntohs(var->var_sb.val) + 1); |
| memcpy(*psWillTopic, var->var_data, ntohs(var->var_sb.val)); |
} |
} |
pos += MQTTHDR_VAR_SIZEOF(var); |
pos += MQTTHDR_VAR_SIZEOF(var); |
} |
} |
Line 347 mqtt_readCONNECT(mqtt_msg_t * __restrict buf, u_short
|
Line 347 mqtt_readCONNECT(mqtt_msg_t * __restrict buf, u_short
|
flg.reserved = 1; |
flg.reserved = 1; |
return flg; |
return flg; |
} else { |
} else { |
if (psWillMessage && msgLen) { | if (psWillMessage) { |
memset(psWillMessage, 0, msgLen--); | *psWillMessage = malloc(ntohs(var->var_sb.val) + 1); |
memcpy(psWillMessage, var->var_data, | if (!*psWillMessage) { |
ntohs(var->var_sb.val) > msgLen ? msgLen : ntohs(var->var_sb.val)); | LOGERR; |
| flg.reserved = 1; |
| return flg; |
| } else |
| memset(*psWillMessage, 0, ntohs(var->var_sb.val) + 1); |
| memcpy(*psWillMessage, var->var_data, ntohs(var->var_sb.val)); |
} |
} |
pos += MQTTHDR_VAR_SIZEOF(var); |
pos += MQTTHDR_VAR_SIZEOF(var); |
} |
} |
Line 391 mqtt_readCONNECT(mqtt_msg_t * __restrict buf, u_short
|
Line 396 mqtt_readCONNECT(mqtt_msg_t * __restrict buf, u_short
|
} |
} |
|
|
return flg; |
return flg; |
|
} |
|
|
|
/* |
|
* mqtt_readCONNACK() Read CONNACK message |
|
* |
|
* @buf = Message buffer |
|
* return: -1 error or >-1 CONNECT message return code |
|
*/ |
|
u_char |
|
mqtt_readCONNACK(mqtt_msg_t * __restrict buf) |
|
{ |
|
int len, ret; |
|
struct mqtthdr *hdr; |
|
mqtthdr_connack_t *ack; |
|
caddr_t pos; |
|
|
|
if (!buf || !buf->msg_base || !buf->msg_len) |
|
return (u_char) -1; |
|
|
|
hdr = _mqtt_readHEADER(buf, MQTT_TYPE_CONNACK, &ret, &len); |
|
if (!hdr) |
|
return (u_char) -1; |
|
if (len < sizeof(mqtthdr_connack_t)) { |
|
mqtt_SetErr(EINVAL, "Error:: short message length %d", len); |
|
return (u_char) -1; |
|
} else { |
|
pos = buf->msg_base + ret + 1; |
|
ack = (mqtthdr_connack_t*) pos; |
|
} |
|
|
|
if (ack->retcode > MQTT_RETCODE_DENIED) { |
|
mqtt_SetErr(EINVAL, "Error:: invalid retcode %u", ack->retcode); |
|
return (u_char) -1; |
|
} |
|
|
|
return ack->retcode; |
|
} |
|
|
|
/* |
|
* mqtt_readDISCONNECT() Read DISCONNECT message |
|
* |
|
* @buf = Message buffer |
|
* return: -1 error, 0 ok, >0 undefined result |
|
*/ |
|
int |
|
mqtt_readDISCONNECT(mqtt_msg_t * __restrict buf) |
|
{ |
|
int len, ret; |
|
struct mqtthdr *hdr; |
|
|
|
hdr = _mqtt_readHEADER(buf, MQTT_TYPE_DISCONNECT, &ret, &len); |
|
if (!hdr || ret != 1) |
|
return -1; |
|
|
|
return len; |
|
} |
|
|
|
/* |
|
* mqtt_readPINGREQ() Read PINGREQ message |
|
* |
|
* @buf = Message buffer |
|
* return: -1 error, 0 ok, >0 undefined result |
|
*/ |
|
int |
|
mqtt_readPINGREQ(mqtt_msg_t * __restrict buf) |
|
{ |
|
int len, ret; |
|
struct mqtthdr *hdr; |
|
|
|
hdr = _mqtt_readHEADER(buf, MQTT_TYPE_PINGREQ, &ret, &len); |
|
if (!hdr || ret != 1) |
|
return -1; |
|
|
|
return len; |
|
} |
|
|
|
/* |
|
* mqtt_readPINGRESP() Read PINGRESP message |
|
* |
|
* @buf = Message buffer |
|
* return: -1 error, 0 ok, >0 undefined result |
|
*/ |
|
int |
|
mqtt_readPINGRESP(mqtt_msg_t * __restrict buf) |
|
{ |
|
int len, ret; |
|
struct mqtthdr *hdr; |
|
|
|
hdr = _mqtt_readHEADER(buf, MQTT_TYPE_PINGRESP, &ret, &len); |
|
if (!hdr || ret != 1) |
|
return -1; |
|
|
|
return len; |
} |
} |