mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Merge branch 'more_consistent_custom_packet_handlers' of https://github.com/wrouesnel/toxcore
This commit is contained in:
commit
7d27893f1a
|
@ -70,7 +70,8 @@ void print_typingchange(Tox *m, int friendnumber, uint8_t typing, void *userdata
|
|||
|
||||
uint32_t custom_packet;
|
||||
|
||||
int handle_custom_packet(void *object, const uint8_t *data, uint32_t len)
|
||||
int handle_custom_packet(Tox *m, uint32_t friend_num, const uint8_t *data,
|
||||
uint32_t len, void *object)
|
||||
{
|
||||
uint8_t number = *((uint32_t *)object);
|
||||
|
||||
|
|
|
@ -341,7 +341,7 @@ RTPMessage *msg_parse ( const uint8_t *data, int length )
|
|||
/**
|
||||
* Callback for networking core.
|
||||
*/
|
||||
int rtp_handle_packet ( void *object, const uint8_t *data, uint32_t length )
|
||||
int rtp_handle_packet ( Messenger *m, int32_t friendnumber, const uint8_t *data, uint32_t length, void *object )
|
||||
{
|
||||
RTPSession *session = object;
|
||||
RTPMessage *msg;
|
||||
|
|
|
@ -1441,13 +1441,15 @@ static int handle_custom_lossy_packet(void *object, int friend_num, const uint8_
|
|||
|
||||
if (m->friendlist[friend_num].lossy_packethandlers[packet[0] % PACKET_ID_LOSSY_RANGE_SIZE].function)
|
||||
return m->friendlist[friend_num].lossy_packethandlers[packet[0] % PACKET_ID_LOSSY_RANGE_SIZE].function(
|
||||
m->friendlist[friend_num].lossy_packethandlers[packet[0] % PACKET_ID_LOSSY_RANGE_SIZE].object, packet, length);
|
||||
m, friend_num, packet, length, m->friendlist[friend_num].lossy_packethandlers[packet[0] %
|
||||
PACKET_ID_LOSSY_RANGE_SIZE].object);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int custom_lossy_packet_registerhandler(Messenger *m, int32_t friendnumber, uint8_t byte,
|
||||
int (*packet_handler_callback)(void *object, const uint8_t *data, uint32_t len), void *object)
|
||||
int (*packet_handler_callback)(Messenger *m, int32_t friendnumber, const uint8_t *data, uint32_t len, void *object),
|
||||
void *object)
|
||||
{
|
||||
if (friend_not_valid(m, friendnumber))
|
||||
return -1;
|
||||
|
@ -1490,13 +1492,15 @@ static int handle_custom_lossless_packet(void *object, int friend_num, const uin
|
|||
|
||||
if (m->friendlist[friend_num].lossless_packethandlers[packet[0] % PACKET_ID_LOSSLESS_RANGE_SIZE].function)
|
||||
return m->friendlist[friend_num].lossless_packethandlers[packet[0] % PACKET_ID_LOSSLESS_RANGE_SIZE].function(
|
||||
m->friendlist[friend_num].lossless_packethandlers[packet[0] % PACKET_ID_LOSSLESS_RANGE_SIZE].object, packet, length);
|
||||
m, friend_num, packet, length, m->friendlist[friend_num].lossless_packethandlers[packet[0] %
|
||||
PACKET_ID_LOSSLESS_RANGE_SIZE].object);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int custom_lossless_packet_registerhandler(Messenger *m, int32_t friendnumber, uint8_t byte,
|
||||
int (*packet_handler_callback)(void *object, const uint8_t *data, uint32_t len), void *object)
|
||||
int (*packet_handler_callback)(Messenger *m, int32_t friendnumber, const uint8_t *data, uint32_t len, void *object),
|
||||
void *object)
|
||||
{
|
||||
if (friend_not_valid(m, friendnumber))
|
||||
return -1;
|
||||
|
|
|
@ -189,6 +189,8 @@ enum {
|
|||
FILECONTROL_RESUME_BROKEN
|
||||
};
|
||||
|
||||
typedef struct Messenger Messenger;
|
||||
|
||||
typedef struct {
|
||||
uint8_t client_id[crypto_box_PUBLICKEYBYTES];
|
||||
int friendcon_id;
|
||||
|
@ -222,18 +224,18 @@ typedef struct {
|
|||
AVATAR_RECEIVEDATA *avatar_recv_data; // We are receiving avatar data from this friend.
|
||||
|
||||
struct {
|
||||
int (*function)(void *object, const uint8_t *data, uint32_t len);
|
||||
int (*function)(Messenger *m, int32_t friendnumber, const uint8_t *data, uint32_t len, void *object);
|
||||
void *object;
|
||||
} lossy_packethandlers[PACKET_ID_LOSSY_RANGE_SIZE];
|
||||
|
||||
struct {
|
||||
int (*function)(void *object, const uint8_t *data, uint32_t len);
|
||||
int (*function)(Messenger *m, int32_t friendnumber, const uint8_t *data, uint32_t len, void *object);
|
||||
void *object;
|
||||
} lossless_packethandlers[PACKET_ID_LOSSLESS_RANGE_SIZE];
|
||||
} Friend;
|
||||
|
||||
|
||||
typedef struct Messenger {
|
||||
struct Messenger {
|
||||
|
||||
Networking_Core *net;
|
||||
Net_Crypto *net_crypto;
|
||||
|
@ -310,7 +312,7 @@ typedef struct Messenger {
|
|||
void *msi_packet_userdata;
|
||||
|
||||
Messenger_Options options;
|
||||
} Messenger;
|
||||
};
|
||||
|
||||
/* Format: [client_id (32 bytes)][nospam number (4 bytes)][checksum (2 bytes)]
|
||||
*
|
||||
|
@ -841,7 +843,8 @@ int m_msi_packet(const Messenger *m, int32_t friendnumber, const uint8_t *data,
|
|||
* return 0 on success.
|
||||
*/
|
||||
int custom_lossy_packet_registerhandler(Messenger *m, int32_t friendnumber, uint8_t byte,
|
||||
int (*packet_handler_callback)(void *object, const uint8_t *data, uint32_t len), void *object);
|
||||
int (*packet_handler_callback)(Messenger *m, int32_t friendnumber, const uint8_t *data, uint32_t len, void *object),
|
||||
void *object);
|
||||
|
||||
/* High level function to send custom lossy packets.
|
||||
*
|
||||
|
@ -859,7 +862,8 @@ int send_custom_lossy_packet(const Messenger *m, int32_t friendnumber, const uin
|
|||
* return 0 on success.
|
||||
*/
|
||||
int custom_lossless_packet_registerhandler(Messenger *m, int32_t friendnumber, uint8_t byte,
|
||||
int (*packet_handler_callback)(void *object, const uint8_t *data, uint32_t len), void *object);
|
||||
int (*packet_handler_callback)(Messenger *m, int32_t friendnumber, const uint8_t *data, uint32_t len, void *object),
|
||||
void *object);
|
||||
|
||||
/* High level function to send custom lossless packets.
|
||||
*
|
||||
|
|
|
@ -490,7 +490,8 @@ void tox_get_keys(Tox *tox, uint8_t *public_key, uint8_t *secret_key)
|
|||
* return 0 on success.
|
||||
*/
|
||||
int tox_lossy_packet_registerhandler(Tox *tox, int32_t friendnumber, uint8_t byte,
|
||||
int (*packet_handler_callback)(void *object, const uint8_t *data, uint32_t len), void *object)
|
||||
int (*packet_handler_callback)(Messenger *tox, int32_t friendnumber, const uint8_t *data, uint32_t len, void *object),
|
||||
void *object)
|
||||
{
|
||||
Messenger *m = tox;
|
||||
|
||||
|
@ -527,7 +528,8 @@ int tox_send_lossy_packet(const Tox *tox, int32_t friendnumber, const uint8_t *d
|
|||
* return 0 on success.
|
||||
*/
|
||||
int tox_lossless_packet_registerhandler(Tox *tox, int32_t friendnumber, uint8_t byte,
|
||||
int (*packet_handler_callback)(void *object, const uint8_t *data, uint32_t len), void *object)
|
||||
int (*packet_handler_callback)(Messenger *tox, int32_t friendnumber, const uint8_t *data, uint32_t len, void *object),
|
||||
void *object)
|
||||
{
|
||||
Messenger *m = tox;
|
||||
|
||||
|
|
|
@ -385,7 +385,8 @@ void tox_get_keys(Tox *tox, uint8_t *public_key, uint8_t *secret_key);
|
|||
* return 0 on success.
|
||||
*/
|
||||
int tox_lossy_packet_registerhandler(Tox *tox, int32_t friendnumber, uint8_t byte,
|
||||
int (*packet_handler_callback)(void *object, const uint8_t *data, uint32_t len), void *object);
|
||||
int (*packet_handler_callback)(Tox *tox, int32_t friendnumber, const uint8_t *data, uint32_t len, void *object),
|
||||
void *object);
|
||||
|
||||
/* Function to send custom lossy packets.
|
||||
* First byte of data must be in the range: 200-254.
|
||||
|
@ -405,7 +406,8 @@ int tox_send_lossy_packet(const Tox *tox, int32_t friendnumber, const uint8_t *d
|
|||
* return 0 on success.
|
||||
*/
|
||||
int tox_lossless_packet_registerhandler(Tox *tox, int32_t friendnumber, uint8_t byte,
|
||||
int (*packet_handler_callback)(void *object, const uint8_t *data, uint32_t len), void *object);
|
||||
int (*packet_handler_callback)(Tox *tox, int32_t friendnumber, const uint8_t *data, uint32_t len, void *object),
|
||||
void *object);
|
||||
|
||||
/* Function to send custom lossless packets.
|
||||
* First byte of data must be in the range: 160-191.
|
||||
|
|
Loading…
Reference in New Issue
Block a user