diff options
Diffstat (limited to 'core/Messenger.c')
-rw-r--r-- | core/Messenger.c | 40 |
1 files changed, 24 insertions, 16 deletions
diff --git a/core/Messenger.c b/core/Messenger.c index a6189941..ebde5a78 100644 --- a/core/Messenger.c +++ b/core/Messenger.c | |||
@@ -395,52 +395,59 @@ void m_set_sends_receipts(Messenger *m, int friendnumber, int yesno) | |||
395 | /* static void (*friend_request)(uint8_t *, uint8_t *, uint16_t); | 395 | /* static void (*friend_request)(uint8_t *, uint8_t *, uint16_t); |
396 | static uint8_t friend_request_isset = 0; */ | 396 | static uint8_t friend_request_isset = 0; */ |
397 | /* set the function that will be executed when a friend request is received. */ | 397 | /* set the function that will be executed when a friend request is received. */ |
398 | void m_callback_friendrequest(Messenger *m, void (*function)(uint8_t *, uint8_t *, uint16_t)) | 398 | void m_callback_friendrequest(Messenger *m, void (*function)(uint8_t *, uint8_t *, uint16_t, void*), void* userdata) |
399 | { | 399 | { |
400 | callback_friendrequest(function); | 400 | callback_friendrequest(function, userdata); |
401 | } | 401 | } |
402 | 402 | ||
403 | /* set the function that will be executed when a message from a friend is received. */ | 403 | /* set the function that will be executed when a message from a friend is received. */ |
404 | void m_callback_friendmessage(Messenger *m, void (*function)(Messenger *m, int, uint8_t *, uint16_t)) | 404 | void m_callback_friendmessage(Messenger *m, void (*function)(Messenger *m, int, uint8_t *, uint16_t, void*), void* userdata) |
405 | { | 405 | { |
406 | m->friend_message = function; | 406 | m->friend_message = function; |
407 | m->friend_message_isset = 1; | 407 | m->friend_message_isset = 1; |
408 | m->friend_message_userdata = userdata; | ||
408 | } | 409 | } |
409 | 410 | ||
410 | void m_callback_action(Messenger *m, void (*function)(Messenger *m, int, uint8_t *, uint16_t)) | 411 | void m_callback_action(Messenger *m, void (*function)(Messenger *m, int, uint8_t *, uint16_t, void*), void* userdata) |
411 | { | 412 | { |
412 | m->friend_action = function; | 413 | m->friend_action = function; |
413 | m->friend_action_isset = 1; | 414 | m->friend_action_isset = 1; |
415 | m->friend_action_userdata = userdata; | ||
414 | } | 416 | } |
415 | 417 | ||
416 | void m_callback_namechange(Messenger *m, void (*function)(Messenger *m, int, uint8_t *, uint16_t)) | 418 | void m_callback_namechange(Messenger *m, void (*function)(Messenger *m, int, uint8_t *, uint16_t, void*), void* userdata) |
417 | { | 419 | { |
418 | m->friend_namechange = function; | 420 | m->friend_namechange = function; |
419 | m->friend_namechange_isset = 1; | 421 | m->friend_namechange_isset = 1; |
422 | m->friend_namechange_userdata = userdata; | ||
420 | } | 423 | } |
421 | 424 | ||
422 | void m_callback_statusmessage(Messenger *m, void (*function)(Messenger *m, int, uint8_t *, uint16_t)) | 425 | void m_callback_statusmessage(Messenger *m, void (*function)(Messenger *m, int, uint8_t *, uint16_t, void*), void* userdata) |
423 | { | 426 | { |
424 | m->friend_statusmessagechange = function; | 427 | m->friend_statusmessagechange = function; |
425 | m->friend_statusmessagechange_isset = 1; | 428 | m->friend_statusmessagechange_isset = 1; |
429 | m->friend_statuschange_userdata = userdata; | ||
426 | } | 430 | } |
427 | 431 | ||
428 | void m_callback_userstatus(Messenger *m, void (*function)(Messenger *m, int, USERSTATUS)) | 432 | void m_callback_userstatus(Messenger *m, void (*function)(Messenger *m, int, USERSTATUS, void*), void* userdata) |
429 | { | 433 | { |
430 | m->friend_userstatuschange = function; | 434 | m->friend_userstatuschange = function; |
431 | m->friend_userstatuschange_isset = 1; | 435 | m->friend_userstatuschange_isset = 1; |
436 | m->friend_userstatuschange_userdata = userdata; | ||
432 | } | 437 | } |
433 | 438 | ||
434 | void m_callback_read_receipt(Messenger *m, void (*function)(Messenger *m, int, uint32_t)) | 439 | void m_callback_read_receipt(Messenger *m, void (*function)(Messenger *m, int, uint32_t, void*), void* userdata) |
435 | { | 440 | { |
436 | m->read_receipt = function; | 441 | m->read_receipt = function; |
437 | m->read_receipt_isset = 1; | 442 | m->read_receipt_isset = 1; |
443 | m->read_receipt_userdata = userdata; | ||
438 | } | 444 | } |
439 | 445 | ||
440 | void m_callback_connectionstatus(Messenger *m, void (*function)(Messenger *m, int, uint8_t)) | 446 | void m_callback_connectionstatus(Messenger *m, void (*function)(Messenger *m, int, uint8_t, void*), void* userdata) |
441 | { | 447 | { |
442 | m->friend_connectionstatuschange = function; | 448 | m->friend_connectionstatuschange = function; |
443 | m->friend_connectionstatuschange_isset = 1; | 449 | m->friend_connectionstatuschange_isset = 1; |
450 | m->friend_connectionstatuschange_userdata = userdata; | ||
444 | } | 451 | } |
445 | 452 | ||
446 | static void check_friend_connectionstatus(Messenger *m, int friendnumber, uint8_t status) | 453 | static void check_friend_connectionstatus(Messenger *m, int friendnumber, uint8_t status) |
@@ -452,7 +459,7 @@ static void check_friend_connectionstatus(Messenger *m, int friendnumber, uint8_ | |||
452 | const uint8_t was_connected = m->friendlist[friendnumber].status == FRIEND_ONLINE; | 459 | const uint8_t was_connected = m->friendlist[friendnumber].status == FRIEND_ONLINE; |
453 | const uint8_t is_connected = status == FRIEND_ONLINE; | 460 | const uint8_t is_connected = status == FRIEND_ONLINE; |
454 | if (is_connected != was_connected) | 461 | if (is_connected != was_connected) |
455 | m->friend_connectionstatuschange(m, friendnumber, is_connected); | 462 | m->friend_connectionstatuschange(m, friendnumber, is_connected, m->friend_connectionstatuschange_userdata); |
456 | } | 463 | } |
457 | 464 | ||
458 | void set_friend_status(Messenger *m, int friendnumber, uint8_t status) | 465 | void set_friend_status(Messenger *m, int friendnumber, uint8_t status) |
@@ -569,7 +576,7 @@ void doFriends(Messenger *m) | |||
569 | if (data_length >= MAX_NAME_LENGTH || data_length == 0) | 576 | if (data_length >= MAX_NAME_LENGTH || data_length == 0) |
570 | break; | 577 | break; |
571 | if(m->friend_namechange_isset) | 578 | if(m->friend_namechange_isset) |
572 | m->friend_namechange(m, i, data, data_length); | 579 | m->friend_namechange(m, i, data, data_length, m->friend_namechange_userdata); |
573 | memcpy(m->friendlist[i].name, data, data_length); | 580 | memcpy(m->friendlist[i].name, data, data_length); |
574 | m->friendlist[i].name[data_length - 1] = 0; /* make sure the NULL terminator is present. */ | 581 | m->friendlist[i].name[data_length - 1] = 0; /* make sure the NULL terminator is present. */ |
575 | break; | 582 | break; |
@@ -580,7 +587,8 @@ void doFriends(Messenger *m) | |||
580 | uint8_t *status = calloc(MIN(data_length, MAX_STATUSMESSAGE_LENGTH), 1); | 587 | uint8_t *status = calloc(MIN(data_length, MAX_STATUSMESSAGE_LENGTH), 1); |
581 | memcpy(status, data, MIN(data_length, MAX_STATUSMESSAGE_LENGTH)); | 588 | memcpy(status, data, MIN(data_length, MAX_STATUSMESSAGE_LENGTH)); |
582 | if (m->friend_statusmessagechange_isset) | 589 | if (m->friend_statusmessagechange_isset) |
583 | m->friend_statusmessagechange(m, i, status, MIN(data_length, MAX_STATUSMESSAGE_LENGTH)); | 590 | m->friend_statusmessagechange(m, i, status, MIN(data_length, MAX_STATUSMESSAGE_LENGTH), |
591 | m->friend_statuschange_userdata); | ||
584 | set_friend_statusmessage(m, i, status, MIN(data_length, MAX_STATUSMESSAGE_LENGTH)); | 592 | set_friend_statusmessage(m, i, status, MIN(data_length, MAX_STATUSMESSAGE_LENGTH)); |
585 | free(status); | 593 | free(status); |
586 | break; | 594 | break; |
@@ -590,7 +598,7 @@ void doFriends(Messenger *m) | |||
590 | break; | 598 | break; |
591 | USERSTATUS status = data[0]; | 599 | USERSTATUS status = data[0]; |
592 | if (m->friend_userstatuschange_isset) | 600 | if (m->friend_userstatuschange_isset) |
593 | m->friend_userstatuschange(m, i, status); | 601 | m->friend_userstatuschange(m, i, status, m->friend_userstatuschange_userdata); |
594 | set_friend_userstatus(m, i, status); | 602 | set_friend_userstatus(m, i, status); |
595 | break; | 603 | break; |
596 | } | 604 | } |
@@ -603,12 +611,12 @@ void doFriends(Messenger *m) | |||
603 | write_cryptpacket_id(m, i, PACKET_ID_RECEIPT, message_id, message_id_length); | 611 | write_cryptpacket_id(m, i, PACKET_ID_RECEIPT, message_id, message_id_length); |
604 | } | 612 | } |
605 | if (m->friend_message_isset) | 613 | if (m->friend_message_isset) |
606 | (*m->friend_message)(m, i, message, message_length); | 614 | (*m->friend_message)(m, i, message, message_length, m->friend_message_userdata); |
607 | break; | 615 | break; |
608 | } | 616 | } |
609 | case PACKET_ID_ACTION: { | 617 | case PACKET_ID_ACTION: { |
610 | if (m->friend_action_isset) | 618 | if (m->friend_action_isset) |
611 | (*m->friend_action)(m, i, data, data_length); | 619 | (*m->friend_action)(m, i, data, data_length, m->friend_action_userdata); |
612 | break; | 620 | break; |
613 | } | 621 | } |
614 | case PACKET_ID_RECEIPT: { | 622 | case PACKET_ID_RECEIPT: { |
@@ -618,7 +626,7 @@ void doFriends(Messenger *m) | |||
618 | memcpy(&msgid, data, sizeof(msgid)); | 626 | memcpy(&msgid, data, sizeof(msgid)); |
619 | msgid = ntohl(msgid); | 627 | msgid = ntohl(msgid); |
620 | if (m->read_receipt_isset) | 628 | if (m->read_receipt_isset) |
621 | (*m->read_receipt)(m, i, msgid); | 629 | (*m->read_receipt)(m, i, msgid, m->read_receipt_userdata); |
622 | break; | 630 | break; |
623 | } | 631 | } |
624 | } | 632 | } |