mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Change prototype for custom_packet_handler functions
Change the custom_packet_handler callback function interface to be consistent with other callback interfaces. The new interface takes the Messenger object calling as the first parameter, and moves the user data object to be the last parameter. This makes it comparable to the callbacks for file transfer and the like, and should simplify building interfaces. The new prototype is: int (*)(Messenger *m, int32_t friendnumber, const uint8_t *data, uint32_t len, void *object)
This commit is contained in:
parent
f1db6e7d6c
commit
8a56cb3b58
|
@ -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,13 @@ 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 +1490,13 @@ 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,7 @@ 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 +861,7 @@ 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,7 @@ 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 +527,7 @@ 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,7 @@ 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 +405,7 @@ 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