From 4879aece088fcf5204e2e72137298735ace8b8e5 Mon Sep 17 00:00:00 2001 From: Debarshi Ray Date: Sun, 21 Aug 2011 15:30:28 +0300 Subject: [PATCH 09/18] IdleDNSResolver: Not needed anymore Fixes: https://bugs.freedesktop.org/37145 --- src/Makefile.am | 2 - src/idle-dns-resolver.c | 204 ----------------------------------------------- src/idle-dns-resolver.h | 74 ----------------- 3 files changed, 0 insertions(+), 280 deletions(-) delete mode 100644 src/idle-dns-resolver.c delete mode 100644 src/idle-dns-resolver.h diff --git a/src/Makefile.am b/src/Makefile.am index 5cd1c0d..67be3e6 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -18,8 +18,6 @@ libidle_convenience_la_SOURCES = \ idle-ctcp.h \ idle-debug.c \ idle-debug.h \ - idle-dns-resolver.c \ - idle-dns-resolver.h \ idle-handles.c \ idle-handles.h \ idle-im-channel.c \ diff --git a/src/idle-dns-resolver.c b/src/idle-dns-resolver.c deleted file mode 100644 index 3985a85..0000000 --- a/src/idle-dns-resolver.c +++ /dev/null @@ -1,204 +0,0 @@ -/* - * This file is part of telepathy-idle - * - * Copyright (C) 2006-2007 Collabora Limited - * Copyright (C) 2006-2007 Nokia Corporation - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * version 2.1 as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ -#include "idle-dns-resolver.h" - -#include -#include -#include - -#define IDLE_DEBUG_FLAG IDLE_DEBUG_DNS -#include "idle-debug.h" - -typedef struct _IdleDNSResultReal IdleDNSResultReal; - -struct _IdleDNSResultReal { - IdleDNSResult result; - struct addrinfo *addrinfo; -}; - -#define idle_dns_result_real_new() \ - (g_slice_new(IdleDNSResultReal)) -#define idle_dns_result_real_new0() \ - (g_slice_new0(IdleDNSResultReal)) - -void idle_dns_result_destroy(IdleDNSResult *result) { - IdleDNSResultReal *real = (IdleDNSResultReal *)(result); - - if (result->ai_next) - idle_dns_result_destroy(result->ai_next); - - if (real->addrinfo) - freeaddrinfo(real->addrinfo); - - g_slice_free(IdleDNSResultReal, real); -} - -typedef struct _IdleDNSQueryData IdleDNSQueryData; - -struct _IdleDNSQueryData { - gchar *name; - guint port; - IdleDNSResultCallback cb; - gpointer user_data; - guint source_id; -}; - -#define idle_dns_query_data_new() \ - (g_slice_new(IdleDNSQueryData)) -#define idle_dns_query_data_new0() \ - (g_slice_new0(IdleDNSQueryData)) - -static void idle_dns_query_data_destroy(IdleDNSQueryData *data) { - g_free(data->name); - g_slice_free(IdleDNSQueryData, data); -} - -struct _IdleDNSResolver { - GHashTable *queries; - guint serial; -}; - -IdleDNSResolver *idle_dns_resolver_new() { - IdleDNSResolver *ret = g_slice_new(IdleDNSResolver); - - ret->queries = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, (GDestroyNotify)(idle_dns_query_data_destroy)); - ret->serial = 0; - - return ret; -} - -void idle_dns_resolver_destroy(IdleDNSResolver *res) { - g_hash_table_destroy(res->queries); - g_slice_free(IdleDNSResolver, res); -} - -struct _idle_helper { - IdleDNSResolver *res; - guint serial; -}; - -#define _idle_helper_new() \ - (g_slice_new(struct _idle_helper)) -#define _idle_helper_new0() \ - (g_slice_new0(struct _idle_helper)) - -static void _idle_helper_destroy(struct _idle_helper *helper) { - g_slice_free(struct _idle_helper, helper); -} - -static gboolean _resolve_idle_func(struct _idle_helper *helper) { - IdleDNSQueryData *data = g_hash_table_lookup(helper->res->queries, GUINT_TO_POINTER(helper->serial)); - struct addrinfo *info = NULL; - struct addrinfo *cur; - struct addrinfo hints; - int rc; - IdleDNSResultReal *results = NULL, *tail = NULL; - IdleDNSResultCallback cb; - gpointer user_data; - gchar *service = g_strdup_printf("%u", data->port); - - cb = data->cb; - user_data = data->user_data; - - memset(&hints, 0, sizeof(hints)); - hints.ai_socktype = SOCK_STREAM; - rc = getaddrinfo(data->name, service, &hints, &info); - - if (rc) { - IDLE_DEBUG("getaddrinfo(): %s", gai_strerror(rc)); - return FALSE; - } - - for (cur = info; cur != NULL; cur = cur->ai_next) { - IdleDNSResultReal *real = idle_dns_result_real_new(); - IdleDNSResult *result = &(real->result); - - result->ai_family = cur->ai_family; - result->ai_socktype = cur->ai_socktype; - result->ai_protocol = cur->ai_protocol; - result->ai_addr = cur->ai_addr; - result->ai_addrlen = cur->ai_addrlen; - result->ai_next = NULL; - - real->addrinfo = NULL; - - if (tail) - tail->result.ai_next = (IdleDNSResult *)(real); - - if (!results) { - results = real; - real->addrinfo = info; - } - - tail = real; - } - - g_hash_table_remove(helper->res->queries, GUINT_TO_POINTER(helper->serial)); - cb(helper->serial, (IdleDNSResult *)(results), user_data); - g_free(service); - - return FALSE; -} - -guint idle_dns_resolver_query(IdleDNSResolver *res, const gchar *name, guint port, IdleDNSResultCallback cb, gpointer user_data) { - IdleDNSQueryData *data; - struct _idle_helper *helper; - guint ret; - - g_assert (res != NULL); - g_assert (name != NULL); - g_assert (port != 0); - g_assert (cb != NULL); - - ret = res->serial++; - - helper = _idle_helper_new(); - helper->res = res; - helper->serial = ret; - - data = idle_dns_query_data_new(); - - data->name = g_strdup(name); - data->port = port; - data->cb = cb; - data->user_data = user_data; - data->source_id = g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, (GSourceFunc)(_resolve_idle_func), helper, (GDestroyNotify)(_idle_helper_destroy)); - - g_hash_table_insert(res->queries, GUINT_TO_POINTER(ret), data); - - return ret; -} - -void idle_dns_resolver_cancel_query(IdleDNSResolver *res, guint id) { - IdleDNSQueryData *data; - - g_assert(res); - - data = g_hash_table_lookup(res->queries, GUINT_TO_POINTER(id)); - - if (!data) { - IDLE_DEBUG("query %u not found!", id); - return; - } - - g_source_remove(data->source_id); - g_hash_table_remove(res->queries, GUINT_TO_POINTER(id)); -} - diff --git a/src/idle-dns-resolver.h b/src/idle-dns-resolver.h deleted file mode 100644 index 67f4997..0000000 --- a/src/idle-dns-resolver.h +++ /dev/null @@ -1,74 +0,0 @@ -/* - * This file is part of telepathy-idle - * - * Copyright (C) 2006-2007 Collabora Limited - * Copyright (C) 2006-2007 Nokia Corporation - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * version 2.1 as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include - -#ifndef __USE_POSIX -#define _IDLE_DNS_RESOLVER_H_UNDEF_USE_POSIX -#define __USE_POSIX -#endif - -#include -#include - -#ifdef _IDLE_DNS_RESOLVER_H_UNDEF_USE_POSIX -#undef __USE_POSIX -#endif - -G_BEGIN_DECLS - -typedef struct _IdleDNSResolver IdleDNSResolver; -typedef struct _IdleDNSResult IdleDNSResult; - -struct _IdleDNSResult { - /* as passed to socket() */ - int ai_family; - int ai_socktype; - int ai_protocol; - - /* as passed to connect() */ - struct sockaddr *ai_addr; - socklen_t ai_addrlen; - - /* pointer to the next list member or NULL if this is the last one */ - IdleDNSResult *ai_next; -}; - -void idle_dns_result_destroy(IdleDNSResult *result); - -/* - * id: the query identifier as returned by query() - * results: a linked list of _IdleDNSResult structs which should be freed with idle_dns_result_destroy - * user_data: the user_data pointer as passed to query() - */ - -typedef void (*IdleDNSResultCallback)(guint id, IdleDNSResult *results, gpointer user_data); - -IdleDNSResolver *idle_dns_resolver_new(); -void idle_dns_resolver_destroy(IdleDNSResolver *); - -/* - * returns: the ID of the query, which can be passed to cancel_query() - */ - -guint idle_dns_resolver_query(IdleDNSResolver *, const gchar *name, guint port, IdleDNSResultCallback callback, gpointer user_data); -void idle_dns_resolver_cancel_query(IdleDNSResolver *, guint id); - -G_END_DECLS -- 1.7.6.2