File main.c changed (mode: 100644) (index b7654ae..c9cfb04) |
... |
... |
int handle_frame(protocol_frame *frame) |
490 |
490 |
* It checks for basic inconsistiencies and allocates the |
* It checks for basic inconsistiencies and allocates the |
491 |
491 |
* protocol_frame structure. |
* protocol_frame structure. |
492 |
492 |
*/ |
*/ |
493 |
|
int parse_lossless_packet(Tox *tox, int32_t friendnumber, const uint8_t *data, uint32_t len, void *sender_uc) |
|
|
493 |
|
int parse_lossless_packet(Tox *tox, int32_t friendnumber, const uint8_t *data, uint32_t len, void *tmp) |
494 |
494 |
{ |
{ |
495 |
495 |
protocol_frame *frame = NULL; |
protocol_frame *frame = NULL; |
496 |
496 |
|
|
|
... |
... |
int parse_lossless_packet(Tox *tox, int32_t friendnumber, const uint8_t *data, u |
525 |
525 |
frame->connid = INT16_AT(data, 4); |
frame->connid = INT16_AT(data, 4); |
526 |
526 |
frame->data_length = INT16_AT(data, 6); |
frame->data_length = INT16_AT(data, 6); |
527 |
527 |
frame->data = (uint8_t *)(data + PROTOCOL_BUFFER_OFFSET); |
frame->data = (uint8_t *)(data + PROTOCOL_BUFFER_OFFSET); |
528 |
|
frame->friendnumber = *((uint32_t*)sender_uc); |
|
|
528 |
|
frame->friendnumber = friendnumber; |
529 |
529 |
log_printf(L_DEBUG, "Got protocol frame magic 0x%x type 0x%x from friend %d\n", frame->magic, frame->packet_type, frame->friendnumber); |
log_printf(L_DEBUG, "Got protocol frame magic 0x%x type 0x%x from friend %d\n", frame->magic, frame->packet_type, frame->friendnumber); |
530 |
530 |
|
|
531 |
531 |
if(len < frame->data_length + PROTOCOL_BUFFER_OFFSET) |
if(len < frame->data_length + PROTOCOL_BUFFER_OFFSET) |
|
... |
... |
void accept_friend_request(Tox *tox, const uint8_t *public_key, const uint8_t *d |
654 |
654 |
{ |
{ |
655 |
655 |
unsigned char tox_printable_id[TOX_FRIEND_ADDRESS_SIZE * 2 + 1]; |
unsigned char tox_printable_id[TOX_FRIEND_ADDRESS_SIZE * 2 + 1]; |
656 |
656 |
int32_t friendnumber; |
int32_t friendnumber; |
657 |
|
int32_t *friendnumber_ptr = NULL; |
|
658 |
657 |
|
|
659 |
658 |
log_printf(L_DEBUG, "Got friend request\n"); |
log_printf(L_DEBUG, "Got friend request\n"); |
660 |
659 |
|
|
|
... |
... |
void accept_friend_request(Tox *tox, const uint8_t *public_key, const uint8_t *d |
664 |
663 |
id_to_string(tox_printable_id, public_key); |
id_to_string(tox_printable_id, public_key); |
665 |
664 |
log_printf(L_INFO, "Accepted friend request from %s as %d\n", tox_printable_id, friendnumber); |
log_printf(L_INFO, "Accepted friend request from %s as %d\n", tox_printable_id, friendnumber); |
666 |
665 |
|
|
667 |
|
/* TODO: this is not freed right now, we're leaking 4 bytes per contact (OMG!) */ |
|
668 |
|
friendnumber_ptr = malloc(sizeof(int32_t)); |
|
669 |
|
if(!friendnumber_ptr) |
|
670 |
|
{ |
|
671 |
|
log_printf(L_ERROR, "Could not allocate memory for friendnumber_ptr\n"); |
|
672 |
|
return; |
|
673 |
|
} |
|
674 |
|
|
|
675 |
|
*friendnumber_ptr = friendnumber; |
|
676 |
|
|
|
677 |
|
tox_lossless_packet_registerhandler(tox, friendnumber, (PROTOCOL_MAGIC_V1)>>8, parse_lossless_packet, (void*)friendnumber_ptr); |
|
|
666 |
|
tox_lossless_packet_registerhandler(tox, friendnumber, (PROTOCOL_MAGIC_V1)>>8, parse_lossless_packet, NULL); |
678 |
667 |
} |
} |
679 |
668 |
|
|
680 |
669 |
void cleanup(int status, void *tmp) |
void cleanup(int status, void *tmp) |