diff options
author | irungentoo <irungentoo@gmail.com> | 2015-02-26 13:13:26 -0500 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2015-02-26 13:13:26 -0500 |
commit | e5791ed9ef59ee5786016b39686b3d9aacf940c0 (patch) | |
tree | 33a15cfe0e37a40ae1b8b8aac5b357036ed7574e /toxcore | |
parent | e61e2919a92ca76e554c9fdc135d0a6ea5d6aedb (diff) |
Added different error codes for custom packet functions in Messenger.
Diffstat (limited to 'toxcore')
-rw-r--r-- | toxcore/Messenger.c | 31 | ||||
-rw-r--r-- | toxcore/Messenger.h | 12 |
2 files changed, 32 insertions, 11 deletions
diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index 33d087de..aa7b05bc 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c | |||
@@ -1379,11 +1379,24 @@ int send_custom_lossy_packet(const Messenger *m, int32_t friendnumber, const uin | |||
1379 | if (friend_not_valid(m, friendnumber)) | 1379 | if (friend_not_valid(m, friendnumber)) |
1380 | return -1; | 1380 | return -1; |
1381 | 1381 | ||
1382 | if (length == 0 || length > MAX_CRYPTO_DATA_SIZE) | ||
1383 | return -2; | ||
1384 | |||
1385 | if (data[0] < PACKET_ID_LOSSY_RANGE_START) | ||
1386 | return -3; | ||
1387 | |||
1388 | if (data[0] >= (PACKET_ID_LOSSY_RANGE_START + PACKET_ID_LOSSY_RANGE_SIZE)) | ||
1389 | return -3; | ||
1390 | |||
1382 | if (m->friendlist[friendnumber].status != FRIEND_ONLINE) | 1391 | if (m->friendlist[friendnumber].status != FRIEND_ONLINE) |
1383 | return -1; | 1392 | return -4; |
1384 | 1393 | ||
1385 | return send_lossy_cryptpacket(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c, | 1394 | if (send_lossy_cryptpacket(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c, |
1386 | m->friendlist[friendnumber].friendcon_id), data, length); | 1395 | m->friendlist[friendnumber].friendcon_id), data, length) == -1) { |
1396 | return -5; | ||
1397 | } else { | ||
1398 | return 0; | ||
1399 | } | ||
1387 | } | 1400 | } |
1388 | 1401 | ||
1389 | static int handle_custom_lossless_packet(void *object, int friend_num, const uint8_t *packet, uint16_t length) | 1402 | 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 | |||
1417 | if (friend_not_valid(m, friendnumber)) | 1430 | if (friend_not_valid(m, friendnumber)) |
1418 | return -1; | 1431 | return -1; |
1419 | 1432 | ||
1420 | if (length == 0) | 1433 | if (length == 0 || length > MAX_CRYPTO_DATA_SIZE) |
1421 | return -1; | 1434 | return -2; |
1422 | 1435 | ||
1423 | if (data[0] < PACKET_ID_LOSSLESS_RANGE_START) | 1436 | if (data[0] < PACKET_ID_LOSSLESS_RANGE_START) |
1424 | return -1; | 1437 | return -3; |
1425 | 1438 | ||
1426 | if (data[0] >= (PACKET_ID_LOSSLESS_RANGE_START + PACKET_ID_LOSSLESS_RANGE_SIZE)) | 1439 | if (data[0] >= (PACKET_ID_LOSSLESS_RANGE_START + PACKET_ID_LOSSLESS_RANGE_SIZE)) |
1427 | return -1; | 1440 | return -3; |
1428 | 1441 | ||
1429 | if (m->friendlist[friendnumber].status != FRIEND_ONLINE) | 1442 | if (m->friendlist[friendnumber].status != FRIEND_ONLINE) |
1430 | return -1; | 1443 | return -4; |
1431 | 1444 | ||
1432 | if (write_cryptpacket(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c, | 1445 | if (write_cryptpacket(m->net_crypto, friend_connection_crypt_connection_id(m->fr_c, |
1433 | m->friendlist[friendnumber].friendcon_id), data, length, 1) == -1) { | 1446 | m->friendlist[friendnumber].friendcon_id), data, length, 1) == -1) { |
1434 | return -1; | 1447 | return -5; |
1435 | } else { | 1448 | } else { |
1436 | return 0; | 1449 | return 0; |
1437 | } | 1450 | } |
diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h index 5d5e5879..f4046f2e 100644 --- a/toxcore/Messenger.h +++ b/toxcore/Messenger.h | |||
@@ -650,7 +650,11 @@ void custom_lossy_packet_registerhandler(Messenger *m, void (*packet_handler_cal | |||
650 | 650 | ||
651 | /* High level function to send custom lossy packets. | 651 | /* High level function to send custom lossy packets. |
652 | * | 652 | * |
653 | * return -1 on failure. | 653 | * return -1 if friend invalid. |
654 | * return -2 if length wrong. | ||
655 | * return -3 if first byte invalid. | ||
656 | * return -4 if friend offline. | ||
657 | * return -5 if packet failed to send because of other error. | ||
654 | * return 0 on success. | 658 | * return 0 on success. |
655 | */ | 659 | */ |
656 | int send_custom_lossy_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint32_t length); | 660 | 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_ | |||
664 | 668 | ||
665 | /* High level function to send custom lossless packets. | 669 | /* High level function to send custom lossless packets. |
666 | * | 670 | * |
667 | * return -1 on failure. | 671 | * return -1 if friend invalid. |
672 | * return -2 if length wrong. | ||
673 | * return -3 if first byte invalid. | ||
674 | * return -4 if friend offline. | ||
675 | * return -5 if packet failed to send because of other error. | ||
668 | * return 0 on success. | 676 | * return 0 on success. |
669 | */ | 677 | */ |
670 | int send_custom_lossless_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint32_t length); | 678 | int send_custom_lossless_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data, uint32_t length); |