From ec81d19dd18fb4fce9b0fcbe9db73200585ec2f0 Mon Sep 17 00:00:00 2001 From: Thadeu Lima de Souza Cascardo Date: Wed, 9 Oct 2013 18:49:56 -0300 Subject: [PATCH] Compare response address with friend address. --- friend.c | 15 ++++++++++++++- friend.h | 2 ++ message.c | 5 +++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/friend.c b/friend.c index f749b4d..7386f83 100644 --- a/friend.c +++ b/friend.c @@ -60,9 +60,22 @@ struct cache { GList *friends; }; +static struct cache *ucache; + +struct friend *friend_get_by_address(GInetAddress *address) +{ + GList *l; + for (l = g_list_first(ucache->friends); l != NULL; l = g_list_next(l)) { + struct friend *friend = l->data; + if (g_inet_address_equal(g_inet_socket_address_get_address(friend->saddr), address)) + return friend; + } + return NULL; +} + int create_cache(struct cache **cache) { - *cache = g_slice_new0(struct cache); + ucache = *cache = g_slice_new0(struct cache); (*cache)->friends = NULL; return 0; } diff --git a/friend.h b/friend.h index b120fa1..c92814d 100644 --- a/friend.h +++ b/friend.h @@ -21,6 +21,7 @@ #include #include +#include int sock_init(void); @@ -33,5 +34,6 @@ int load_cache(struct cache *cache, char *fname); int store_cache(struct cache *cache, char *fname); int friend_send_message(struct friend *friend, char *buffer, size_t len); +struct friend *friend_get_by_address(GInetAddress *address); #endif diff --git a/message.c b/message.c index 1a66892..35b5d1c 100644 --- a/message.c +++ b/message.c @@ -52,6 +52,11 @@ gboolean message_incoming(GIOChannel *channel, GIOCondition cond, gpointer data) iaddress = g_inet_socket_address_get_address(G_INET_SOCKET_ADDRESS(address)); if (g_inet_address_get_is_loopback(iaddress)) { command(buffer, len); + } else { + struct friend *friend; + friend = friend_get_by_address(iaddress); + if (friend); + g_source_remove_by_user_data(friend); } g_object_unref(address); g_free(buffer); -- 2.20.1