summaryrefslogtreecommitdiff
path: root/toxcore
diff options
context:
space:
mode:
Diffstat (limited to 'toxcore')
-rw-r--r--toxcore/tox.c97
1 files changed, 97 insertions, 0 deletions
diff --git a/toxcore/tox.c b/toxcore/tox.c
index 6b16a8d4..e95bbefb 100644
--- a/toxcore/tox.c
+++ b/toxcore/tox.c
@@ -809,3 +809,100 @@ void tox_callback_friend_action(Tox *tox, tox_friend_action_cb *function, void *
809 m_callback_action(m, function, user_data); 809 m_callback_action(m, function, user_data);
810} 810}
811 811
812static void set_custom_packet_error(int ret, TOX_ERR_SEND_CUSTOM_PACKET *error)
813{
814 switch (ret) {
815 case 0:
816 SET_ERROR_PARAMETER(error, TOX_ERR_SEND_CUSTOM_PACKET_OK);
817 break;
818
819 case -1:
820 SET_ERROR_PARAMETER(error, TOX_ERR_SEND_CUSTOM_PACKET_FRIEND_NOT_FOUND);
821 break;
822
823 case -2:
824 SET_ERROR_PARAMETER(error, TOX_ERR_SEND_CUSTOM_PACKET_TOO_LONG);
825 break;
826
827 case -3:
828 SET_ERROR_PARAMETER(error, TOX_ERR_SEND_CUSTOM_PACKET_INVALID);
829 break;
830
831 case -4:
832 SET_ERROR_PARAMETER(error, TOX_ERR_SEND_CUSTOM_PACKET_FRIEND_NOT_CONNECTED);
833 break;
834
835 case -5:
836 SET_ERROR_PARAMETER(error, TOX_ERR_SEND_CUSTOM_PACKET_SENDQ);
837 break;
838 }
839}
840
841bool tox_send_lossy_packet(Tox *tox, uint32_t friend_number, const uint8_t *data, size_t length,
842 TOX_ERR_SEND_CUSTOM_PACKET *error)
843{
844 if (!data) {
845 SET_ERROR_PARAMETER(error, TOX_ERR_SEND_CUSTOM_PACKET_NULL);
846 return 0;
847 }
848
849 Messenger *m = tox;
850
851 if (length == 0) {
852 SET_ERROR_PARAMETER(error, TOX_ERR_SEND_CUSTOM_PACKET_EMPTY);
853 return 0;
854 }
855
856 if (data[0] < (PACKET_ID_LOSSY_RANGE_START + PACKET_LOSSY_AV_RESERVED)) {
857 SET_ERROR_PARAMETER(error, TOX_ERR_SEND_CUSTOM_PACKET_INVALID);
858 return 0;
859 }
860
861 int ret = send_custom_lossy_packet(m, friend_number, data, length);
862
863 set_custom_packet_error(ret, error);
864
865 if (ret == 0) {
866 return 1;
867 } else {
868 return 0;
869 }
870}
871
872void tox_callback_friend_lossy_packet(Tox *tox, tox_friend_lossy_packet_cb *function, void *user_data)
873{
874 Messenger *m = tox;
875 custom_lossy_packet_registerhandler(m, function, user_data);
876}
877
878bool tox_send_lossless_packet(Tox *tox, uint32_t friend_number, const uint8_t *data, size_t length,
879 TOX_ERR_SEND_CUSTOM_PACKET *error)
880{
881 if (!data) {
882 SET_ERROR_PARAMETER(error, TOX_ERR_SEND_CUSTOM_PACKET_NULL);
883 return 0;
884 }
885
886 Messenger *m = tox;
887
888 if (length == 0) {
889 SET_ERROR_PARAMETER(error, TOX_ERR_SEND_CUSTOM_PACKET_EMPTY);
890 return 0;
891 }
892
893 int ret = send_custom_lossless_packet(m, friend_number, data, length);
894
895 set_custom_packet_error(ret, error);
896
897 if (ret == 0) {
898 return 1;
899 } else {
900 return 0;
901 }
902}
903
904void tox_callback_friend_lossless_packet(Tox *tox, tox_friend_lossless_packet_cb *function, void *user_data)
905{
906 Messenger *m = tox;
907 custom_lossless_packet_registerhandler(m, function, user_data);
908}