From 04001b2ec36f5492e441fb68f3ff74e1507c6f26 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Fri, 21 Mar 2014 19:27:17 -0400 Subject: [PATCH] Friends client id is now removed from the request received list when he is deleted. --- toxcore/Messenger.c | 1 + toxcore/friend_requests.c | 19 +++++++++++++++++++ toxcore/friend_requests.h | 7 +++++++ 3 files changed, 27 insertions(+) diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index e1c2763c..6e103036 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c @@ -346,6 +346,7 @@ int m_delfriend(Messenger *m, int32_t friendnumber) onion_delfriend(m->onion_c, m->friendlist[friendnumber].onion_friendnum); crypto_kill(m->net_crypto, m->friendlist[friendnumber].crypt_connection_id); free(m->friendlist[friendnumber].statusmessage); + remove_request_received(&(m->fr), m->friendlist[friendnumber].client_id); memset(&(m->friendlist[friendnumber]), 0, sizeof(Friend)); uint32_t i; diff --git a/toxcore/friend_requests.c b/toxcore/friend_requests.c index 7574a881..469ab02d 100644 --- a/toxcore/friend_requests.c +++ b/toxcore/friend_requests.c @@ -113,6 +113,25 @@ static int request_received(Friend_Requests *fr, uint8_t *client_id) return 0; } +/* Remove client id from received_requests list. + * + * return 0 if it removed it successfully. + * return -1 if it didn't find it. + */ +int remove_request_received(Friend_Requests *fr, uint8_t *client_id) +{ + uint32_t i; + + for (i = 0; i < MAX_RECEIVED_STORED; ++i) { + if (id_equal(fr->received_requests[i], client_id)) { + memset(fr->received_requests[i], 0, crypto_box_PUBLICKEYBYTES); + return 0; + } + } + + return -1; +} + static int friendreq_handlepacket(void *object, uint8_t *source_pubkey, uint8_t *packet, uint32_t length) { diff --git a/toxcore/friend_requests.h b/toxcore/friend_requests.h index 722c7431..eab359f0 100644 --- a/toxcore/friend_requests.h +++ b/toxcore/friend_requests.h @@ -55,6 +55,13 @@ int send_friendrequest(Onion_Client *onion_c, uint8_t *public_key, uint32_t nosp void set_nospam(Friend_Requests *fr, uint32_t num); uint32_t get_nospam(Friend_Requests *fr); +/* Remove client id from received_requests list. + * + * return 0 if it removed it successfully. + * return -1 if it didn't find it. + */ +int remove_request_received(Friend_Requests *fr, uint8_t *client_id); + /* Set the function that will be executed when a friend request for us is received. * Function format is function(uint8_t * public_key, uint8_t * data, uint16_t length, void * userdata) */