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;
}
#include <sys/types.h>
#include <stdint.h>
+#include <gio/gio.h>
int sock_init(void);
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
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);