From f8ed4ed7f8c048234d87140f5a3811043b1dab9e Mon Sep 17 00:00:00 2001 From: Stefan Becker Date: Sun, 26 Aug 2012 21:39:40 +0300 Subject: [PATCH] telepathy: implement sipe_backend_dnsquery_* The code uses GResolver & friends from gio-2.0 which were added in 2.22.0. Update configure.ac and RPM spec accordingly. RPM build now supports "--without telepathy" for older distros. --- configure.ac | 3 + contrib/rpm/pidgin-sipe.spec | 35 ++++++--- pixmaps/Makefile.common.am | 11 ++- src/telepathy/Makefile.am | 1 + src/telepathy/telepathy-dnsquery.c | 150 +++++++++++++++++++++++++++++++++++++ src/telepathy/telepathy-stubs.c | 15 ---- 6 files changed, 188 insertions(+), 27 deletions(-) create mode 100644 src/telepathy/telepathy-dnsquery.c diff --git a/configure.ac b/configure.ac index 001f0b01..c03ee399 100644 --- a/configure.ac +++ b/configure.ac @@ -385,6 +385,9 @@ AS_IF([test "x$enable_telepathy" != xno], dnl telepathy is based on GObject PKG_CHECK_MODULES(GOBJECT, [gobject-2.0]) + + dnl telepathy uses GResolver from gio + PKG_CHECK_MODULES(GIO, [gio-2.0 >= 2.22.0]) ], [enable_telepathy=no])]) AM_CONDITIONAL(SIPE_INCLUDE_TELEPATHY, [test "x$enable_telepathy" != xno]) diff --git a/contrib/rpm/pidgin-sipe.spec b/contrib/rpm/pidgin-sipe.spec index c89edde2..a992d85c 100644 --- a/contrib/rpm/pidgin-sipe.spec +++ b/contrib/rpm/pidgin-sipe.spec @@ -1,6 +1,6 @@ # # Example SPEC file to generate a RPM for pidgin-sipe. -# It should work out-of-the-box on Fedora 10/11 and RHEL5. +# It should work out-of-the-box on Fedora 10+ or RHEL5+. # %if 0%{?_with_git:1} #------------------------------- BUILD FROM GIT ------------------------------- @@ -10,7 +10,7 @@ # # Run "./git-snapshot.sh ." in your local repository. # Then update the following line from the generated archive name -%define git 20120824git1788cfd +%define git 20120826gite7aaa07 # Increment when you generate several RPMs on the same day... %define gitcount 0 #------------------------------- BUILD FROM GIT ------------------------------- @@ -56,8 +56,13 @@ BuildRequires: glib2-devel >= 2.28.0 BuildRequires: libnice-devel >= 0.1.0 BuildRequires: gstreamer-devel %endif +# Use "--without telepathy" to disable telepathy +%if !0%{?_without_telepathy:1} +BuildRequires: glib2-devel >= 2.22.0 +%endif # Configurable components +# Use "--without kerberos" to disable krb5 %if !0%{?_without_kerberos:1} BuildRequires: krb5-devel %endif @@ -98,6 +103,7 @@ It implements the extended version of SIP/SIMPLE used by various products: This package provides the protocol plugin for libpurple clients. +%if !0%{?_without_telepathy:1} %package -n %{empathy_files} Summary: Telepathy communication manager to connect to MS Office Communicator Group: %{pkg_group} @@ -132,6 +138,7 @@ SIP/SIMPLE used by various products: * Reuters Messaging This package provides the protocol support for Telepathy clients. +%endif %package -n %{common_files} @@ -160,7 +167,11 @@ This package provides common files for the SIPE protocol plugins: %endif %configure \ --enable-purple \ +%if !0%{?_without_telepathy:1} --enable-telepathy +%else + --disable-telepathy +%endif make %{_smp_mflags} make %{_smp_mflags} check @@ -185,13 +196,7 @@ rm -rf %{buildroot} %{_libdir}/purple-2/libsipe.so -%files -n %{telepathy_plugin} -%defattr(-,root,root,-) -%doc AUTHORS ChangeLog COPYING NEWS README TODO -%{_datadir}/dbus-1/services/*.sipe.service -%{_libexecdir}/telepathy-sipe - - +%if !0%{?_without_telepathy:1} %files -n %{empathy_files} %defattr(-,root,root,-) %doc AUTHORS COPYING @@ -199,6 +204,14 @@ rm -rf %{buildroot} %{_datadir}/empathy/icons/hicolor/*/apps/im-sipe.svg +%files -n %{telepathy_plugin} +%defattr(-,root,root,-) +%doc AUTHORS ChangeLog COPYING NEWS README TODO +%{_datadir}/dbus-1/services/*.sipe.service +%{_libexecdir}/telepathy-sipe +%endif + + %files -n %{common_files} -f %{name}.lang %defattr(-,root,root,-) @@ -211,6 +224,10 @@ rm -rf %{buildroot} %changelog +* Sun Aug 26 2012 J. D. User 1.13.3-*git* +- telepathy now requires glib-2.0 >= 2.22.0 +- use "--without telepathy" to disable telepathy packages + * Fri Aug 24 2012 J. D. User 1.13.3-*git* - add empathy-sipe package diff --git a/pixmaps/Makefile.common.am b/pixmaps/Makefile.common.am index f755e4e1..212c5cba 100644 --- a/pixmaps/Makefile.common.am +++ b/pixmaps/Makefile.common.am @@ -1,11 +1,16 @@ MAINTAINERCLEANFILES = Makefile.in -DISTCLEANFILES = im-sipe.$(pixmapext) EXTRA_DIST = sipe.$(pixmapext) -empathyappsiconsdir = $(datadir)/empathy/icons/hicolor/$(pixmapsize)/apps -empathyappsicons_DATA = im-sipe.$(pixmapext) +if SIPE_INCLUDE_PURPLE pidginprotocolpixdir = $(datadir)/pixmaps/pidgin/protocols/$(pixmapsize) pidginprotocolpix_DATA = sipe.$(pixmapext) +endif + +if SIPE_INCLUDE_TELEPATHY +empathyappsiconsdir = $(datadir)/empathy/icons/hicolor/$(pixmapsize)/apps +empathyappsicons_DATA = im-sipe.$(pixmapext) +DISTCLEANFILES = im-sipe.$(pixmapext) im-sipe.$(pixmapext): $(srcdir)/sipe.$(pixmapext) cp $< $@ +endif diff --git a/src/telepathy/Makefile.am b/src/telepathy/Makefile.am index fa54d123..19fc0783 100644 --- a/src/telepathy/Makefile.am +++ b/src/telepathy/Makefile.am @@ -8,6 +8,7 @@ libexec_PROGRAMS = telepathy-sipe telepathy_sipe_SOURCES = \ telepathy-connection.c \ telepathy-debug.c \ + telepathy-dnsquery.c \ telepathy-main.c \ telepathy-private.h \ telepathy-protocol.c \ diff --git a/src/telepathy/telepathy-dnsquery.c b/src/telepathy/telepathy-dnsquery.c new file mode 100644 index 00000000..0744de51 --- /dev/null +++ b/src/telepathy/telepathy-dnsquery.c @@ -0,0 +1,150 @@ +/** + * @file telepathy-dnsquery.c + * + * pidgin-sipe + * + * Copyright (C) 2012 SIPE Project + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include + +#include "sipe-backend.h" +#include "sipe-common.h" +#include "sipe-core.h" + +struct sipe_dns_query { + sipe_dns_resolved_cb callback; + gpointer extradata; + guint port; + GCancellable *cancel; +}; + +static void dns_srv_response(GObject *resolver, + GAsyncResult *result, + gpointer data) +{ + GError *error = NULL; + GList *targets = g_resolver_lookup_service_finish(G_RESOLVER(resolver), + result, + &error); + struct sipe_dns_query *query = data; + + if (targets) { + GSrvTarget *target = targets->data; + query->callback(query->extradata, + g_srv_target_get_hostname(target), + g_srv_target_get_port(target)); + g_resolver_free_targets(targets); + } else { + SIPE_DEBUG_INFO("dns_srv_response: failed: %s", + error ? error->message : "UNKNOWN"); + query->callback(query->extradata, NULL, 0); + } + g_object_unref(query->cancel); + g_free(query); +} + +struct sipe_dns_query *sipe_backend_dns_query_srv(SIPE_UNUSED_PARAMETER struct sipe_core_public *sipe_public, + const gchar *protocol, + const gchar *transport, + const gchar *domain, + sipe_dns_resolved_cb callback, + gpointer data) +{ + struct sipe_dns_query *query = g_new0(struct sipe_dns_query, 1); + GResolver *resolver = g_resolver_get_default(); + + SIPE_DEBUG_INFO("sipe_backend_dns_query_srv: %s/%s/%s", + protocol, transport, domain); + + query->callback = callback; + query->extradata = data; + query->cancel = g_cancellable_new(); + g_resolver_lookup_service_async(resolver, + protocol, transport, domain, + query->cancel, + dns_srv_response, + query); + + g_object_unref(resolver); + return(query); +} + +static void dns_a_response(GObject *resolver, + GAsyncResult *result, + gpointer data) +{ + GError *error = NULL; + GList *addresses = g_resolver_lookup_by_name_finish(G_RESOLVER(resolver), + result, + &error); + struct sipe_dns_query *query = data; + + if (addresses) { + GInetAddress *address = addresses->data; + gchar *ipstr = g_inet_address_to_string(address); + query->callback(query->extradata, ipstr, query->port); + g_free(ipstr); + g_resolver_free_addresses(addresses); + } else { + SIPE_DEBUG_INFO("dns_a_response: failed: %s", + error ? error->message : "UNKNOWN"); + query->callback(query->extradata, NULL, 0); + } + g_object_unref(query->cancel); + g_free(query); +} + +struct sipe_dns_query *sipe_backend_dns_query_a(SIPE_UNUSED_PARAMETER struct sipe_core_public *sipe_public, + const gchar *hostname, + int port, + sipe_dns_resolved_cb callback, + gpointer data) +{ + struct sipe_dns_query *query = g_new0(struct sipe_dns_query, 1); + GResolver *resolver = g_resolver_get_default(); + + SIPE_DEBUG_INFO("sipe_backend_dns_query_a: %s", hostname); + + query->callback = callback; + query->extradata = data; + query->port = port; + query->cancel = g_cancellable_new(); + g_resolver_lookup_by_name_async(resolver, + hostname, + query->cancel, + dns_a_response, + query); + + g_object_unref(resolver); + return(query); +} + +void sipe_backend_dns_query_cancel(struct sipe_dns_query *query) +{ + g_cancellable_cancel(query->cancel); +} + +/* + Local Variables: + mode: c + c-file-style: "bsd" + indent-tabs-mode: t + tab-width: 8 + End: +*/ diff --git a/src/telepathy/telepathy-stubs.c b/src/telepathy/telepathy-stubs.c index 4022972c..07f4cf5e 100644 --- a/src/telepathy/telepathy-stubs.c +++ b/src/telepathy/telepathy-stubs.c @@ -174,21 +174,6 @@ void sipe_backend_connection_error(SIPE_UNUSED_PARAMETER struct sipe_core_public gboolean sipe_backend_connection_is_disconnecting(SIPE_UNUSED_PARAMETER struct sipe_core_public *sipe_public) { return(FALSE); } gboolean sipe_backend_connection_is_valid(SIPE_UNUSED_PARAMETER SIPE_UNUSED_PARAMETER struct sipe_core_public *sipe_public) { return(TRUE); } -/** DNS QUERY ****************************************************************/ - -struct sipe_dns_query *sipe_backend_dns_query_srv(SIPE_UNUSED_PARAMETER struct sipe_core_public *sipe_public, - SIPE_UNUSED_PARAMETER const gchar *protocol, - SIPE_UNUSED_PARAMETER const gchar *transport, - SIPE_UNUSED_PARAMETER const gchar *domain, - SIPE_UNUSED_PARAMETER sipe_dns_resolved_cb callback, - SIPE_UNUSED_PARAMETER gpointer data) { return(NULL); } -struct sipe_dns_query *sipe_backend_dns_query_a(SIPE_UNUSED_PARAMETER struct sipe_core_public *sipe_public, - SIPE_UNUSED_PARAMETER const gchar *hostname, - SIPE_UNUSED_PARAMETER int port, - SIPE_UNUSED_PARAMETER sipe_dns_resolved_cb callback, - SIPE_UNUSED_PARAMETER gpointer data) { return(NULL); } -void sipe_backend_dns_query_cancel(SIPE_UNUSED_PARAMETER struct sipe_dns_query *query) {} - /** FILE TRANSFER ************************************************************/ void sipe_backend_ft_error(SIPE_UNUSED_PARAMETER struct sipe_file_transfer *ft, -- 2.11.4.GIT