Added different error codes for custom packet functions in Messenger.

This commit is contained in:
irungentoo 2015-02-26 13:13:26 -05:00
parent e61e2919a9
commit e5791ed9ef
No known key found for this signature in database
GPG Key ID: 10349DC9BED89E98
3 changed files with 37 additions and 15 deletions

View File

@ -428,13 +428,14 @@ int rtp_send_msg ( RTPSession *session, Messenger *messenger, const uint8_t *dat
if ( !msg ) return -1;
if ( -1 == send_custom_lossy_packet(messenger, session->dest, msg->data, msg->length) ) {
LOGGER_WARNING("Failed to send full packet (len: %d)! std error: %s", length, strerror(errno));
int ret = send_custom_lossy_packet(messenger, session->dest, msg->data, msg->length);
if ( 0 != ret) {
LOGGER_WARNING("Failed to send full packet (len: %d)! error: %i", length, ret);
rtp_free_msg ( session, msg );
return rtp_ErrorSending;
}
/* Set sequ number */
session->sequnum = session->sequnum >= MAX_SEQU_NUM ? 0 : session->sequnum + 1;
rtp_free_msg ( session, msg );

View File

@ -1379,11 +1379,24 @@ int send_custom_lossy_packet(const Messenger *m, int32_t friendnumber, const uin
if (friend_not_valid(m, friendnumber))
return -1;
if (m->friendlist[friendnumber].status != FRIEND_ONLINE)
return -1;
if (length == 0 || length > MAX_CRYPTO_DATA_SIZE)
return -2;
return send_lossy_cryptpacket(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c,
m->friendlist[friendnumber].friendcon_id), data, length);
if (data[0] < PACKET_ID_LOSSY_RANGE_START)
return -3;
if (data[0] >= (PACKET_ID_LOSSY_RANGE_START + PACKET_ID_LOSSY_RANGE_SIZE))
return -3;
if (m->friendlist[friendnumber].status != FRIEND_ONLINE)
return -4;
if (send_lossy_cryptpacket(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c,
m->friendlist[friendnumber].friendcon_id), data, length) == -1) {
return -5;
} else {
return 0;
}
}
static int handle_custom_lossless_packet(void *object, int friend_num, const uint8_t *packet, uint16_t length)
@ -1417,21 +1430,21 @@ int send_custom_lossless_packet(const Messenger *m, int32_t friendnumber, const
if (friend_not_valid(m, friendnumber))
return -1;
if (length == 0)
return -1;
if (length == 0 || length > MAX_CRYPTO_DATA_SIZE)
return -2;
if (data[0] < PACKET_ID_LOSSLESS_RANGE_START)
return -1;
return -3;
if (data[0] >= (PACKET_ID_LOSSLESS_RANGE_START + PACKET_ID_LOSSLESS_RANGE_SIZE))
return -1;
return -3;
if (m->friendlist[friendnumber].status != FRIEND_ONLINE)
return -1;
return -4;
if (write_cryptpacket(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c,
m->friendlist[friendnumber].friendcon_id), data, length, 1) == -1) {
return -1;
return -5;
} else {
return 0;
}

View File

@ -650,7 +650,11 @@ void custom_lossy_packet_registerhandler(Messenger *m, void (*packet_handler_cal
/* High level function to send custom lossy packets.
*
* return -1 on failure.
* return -1 if friend invalid.
* return -2 if length wrong.
* return -3 if first byte invalid.
* return -4 if friend offline.
* return -5 if packet failed to send because of other error.
* return 0 on success.
*/
int send_custom_lossy_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint32_t length);
@ -664,7 +668,11 @@ void custom_lossless_packet_registerhandler(Messenger *m, void (*packet_handler_
/* High level function to send custom lossless packets.
*
* return -1 on failure.
* return -1 if friend invalid.
* return -2 if length wrong.
* return -3 if first byte invalid.
* return -4 if friend offline.
* return -5 if packet failed to send because of other error.
* return 0 on success.
*/
int send_custom_lossless_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint32_t length);