summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2005-10-02 02:18:11 +0000
committerLennart Poettering <lennart@poettering.net>2005-10-02 02:18:11 +0000
commit7b7a022127d14b3a83d042c2aa52c76ec90554d2 (patch)
tree460d258950fbf20f8aa6005f9323e2260fd2078b
parentd3e893754d3158b72d488e515535dfcac980e1c3 (diff)
* add pthreads autoconf scripts
* add bonjour compatiblity layer (only browsing, resolving for now. the complicated stuff is done, missing parts will follow soon) git-svn-id: file:///home/lennart/svn/public/avahi/trunk@672 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe
-rw-r--r--Makefile.am3
-rw-r--r--common/acx_pthread.m4235
-rw-r--r--compat-bonjour/Makefile.am40
-rw-r--r--compat-bonjour/compat.c536
-rw-r--r--compat-bonjour/funcs.txt32
-rw-r--r--compat-bonjour/unsupported.c141
-rw-r--r--configure.ac4
7 files changed, 990 insertions, 1 deletions
diff --git a/Makefile.am b/Makefile.am
index 2d32ea6..14cf04a 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -59,7 +59,8 @@ SUBDIRS = \
examples \
man \
tests \
- service-type-database
+ service-type-database \
+ compat-bonjour
DX_INPUT = \
diff --git a/common/acx_pthread.m4 b/common/acx_pthread.m4
new file mode 100644
index 0000000..b7f692a
--- /dev/null
+++ b/common/acx_pthread.m4
@@ -0,0 +1,235 @@
+dnl @synopsis ACX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
+dnl
+dnl This macro figures out how to build C programs using POSIX threads.
+dnl It sets the PTHREAD_LIBS output variable to the threads library and
+dnl linker flags, and the PTHREAD_CFLAGS output variable to any special
+dnl C compiler flags that are needed. (The user can also force certain
+dnl compiler flags/libs to be tested by setting these environment
+dnl variables.)
+dnl
+dnl Also sets PTHREAD_CC to any special C compiler that is needed for
+dnl multi-threaded programs (defaults to the value of CC otherwise).
+dnl (This is necessary on AIX to use the special cc_r compiler alias.)
+dnl
+dnl NOTE: You are assumed to not only compile your program with these
+dnl flags, but also link it with them as well. e.g. you should link
+dnl with $PTHREAD_CC $CFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS
+dnl $LIBS
+dnl
+dnl If you are only building threads programs, you may wish to use
+dnl these variables in your default LIBS, CFLAGS, and CC:
+dnl
+dnl LIBS="$PTHREAD_LIBS $LIBS"
+dnl CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
+dnl CC="$PTHREAD_CC"
+dnl
+dnl In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute
+dnl constant has a nonstandard name, defines PTHREAD_CREATE_JOINABLE to
+dnl that name (e.g. PTHREAD_CREATE_UNDETACHED on AIX).
+dnl
+dnl ACTION-IF-FOUND is a list of shell commands to run if a threads
+dnl library is found, and ACTION-IF-NOT-FOUND is a list of commands to
+dnl run it if it is not found. If ACTION-IF-FOUND is not specified, the
+dnl default action will define HAVE_PTHREAD.
+dnl
+dnl Please let the authors know if this macro fails on any platform, or
+dnl if you have any other suggestions or comments. This macro was based
+dnl on work by SGJ on autoconf scripts for FFTW (www.fftw.org) (with
+dnl help from M. Frigo), as well as ac_pthread and hb_pthread macros
+dnl posted by Alejandro Forero Cuervo to the autoconf macro repository.
+dnl We are also grateful for the helpful feedback of numerous users.
+dnl
+dnl @category InstalledPackages
+dnl @author Steven G. Johnson <stevenj@alum.mit.edu>
+dnl @version 2005-01-14
+dnl @license GPLWithACException
+
+AC_DEFUN([ACX_PTHREAD], [
+AC_REQUIRE([AC_CANONICAL_HOST])
+AC_LANG_SAVE
+AC_LANG_C
+acx_pthread_ok=no
+
+# We used to check for pthread.h first, but this fails if pthread.h
+# requires special compiler flags (e.g. on True64 or Sequent).
+# It gets checked for in the link test anyway.
+
+# First of all, check if the user has set any of the PTHREAD_LIBS,
+# etcetera environment variables, and if threads linking works using
+# them:
+if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then
+ save_CFLAGS="$CFLAGS"
+ CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
+ save_LIBS="$LIBS"
+ LIBS="$PTHREAD_LIBS $LIBS"
+ AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS])
+ AC_TRY_LINK_FUNC(pthread_join, acx_pthread_ok=yes)
+ AC_MSG_RESULT($acx_pthread_ok)
+ if test x"$acx_pthread_ok" = xno; then
+ PTHREAD_LIBS=""
+ PTHREAD_CFLAGS=""
+ fi
+ LIBS="$save_LIBS"
+ CFLAGS="$save_CFLAGS"
+fi
+
+# We must check for the threads library under a number of different
+# names; the ordering is very important because some systems
+# (e.g. DEC) have both -lpthread and -lpthreads, where one of the
+# libraries is broken (non-POSIX).
+
+# Create a list of thread flags to try. Items starting with a "-" are
+# C compiler flags, and other items are library names, except for "none"
+# which indicates that we try without any flags at all, and "pthread-config"
+# which is a program returning the flags for the Pth emulation library.
+
+acx_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config"
+
+# The ordering *is* (sometimes) important. Some notes on the
+# individual items follow:
+
+# pthreads: AIX (must check this before -lpthread)
+# none: in case threads are in libc; should be tried before -Kthread and
+# other compiler flags to prevent continual compiler warnings
+# -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h)
+# -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able)
+# lthread: LinuxThreads port on FreeBSD (also preferred to -pthread)
+# -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads)
+# -pthreads: Solaris/gcc
+# -mthreads: Mingw32/gcc, Lynx/gcc
+# -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it
+# doesn't hurt to check since this sometimes defines pthreads too;
+# also defines -D_REENTRANT)
+# pthread: Linux, etcetera
+# --thread-safe: KAI C++
+# pthread-config: use pthread-config program (for GNU Pth library)
+
+case "${host_cpu}-${host_os}" in
+ *solaris*)
+
+ # On Solaris (at least, for some versions), libc contains stubbed
+ # (non-functional) versions of the pthreads routines, so link-based
+ # tests will erroneously succeed. (We need to link with -pthread or
+ # -lpthread.) (The stubs are missing pthread_cleanup_push, or rather
+ # a function called by this macro, so we could check for that, but
+ # who knows whether they'll stub that too in a future libc.) So,
+ # we'll just look for -pthreads and -lpthread first:
+
+ acx_pthread_flags="-pthread -pthreads pthread -mt $acx_pthread_flags"
+ ;;
+esac
+
+if test x"$acx_pthread_ok" = xno; then
+for flag in $acx_pthread_flags; do
+
+ case $flag in
+ none)
+ AC_MSG_CHECKING([whether pthreads work without any flags])
+ ;;
+
+ -*)
+ AC_MSG_CHECKING([whether pthreads work with $flag])
+ PTHREAD_CFLAGS="$flag"
+ ;;
+
+ pthread-config)
+ AC_CHECK_PROG(acx_pthread_config, pthread-config, yes, no)
+ if test x"$acx_pthread_config" = xno; then continue; fi
+ PTHREAD_CFLAGS="`pthread-config --cflags`"
+ PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`"
+ ;;
+
+ *)
+ AC_MSG_CHECKING([for the pthreads library -l$flag])
+ PTHREAD_LIBS="-l$flag"
+ ;;
+ esac
+
+ save_LIBS="$LIBS"
+ save_CFLAGS="$CFLAGS"
+ LIBS="$PTHREAD_LIBS $LIBS"
+ CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
+
+ # Check for various functions. We must include pthread.h,
+ # since some functions may be macros. (On the Sequent, we
+ # need a special flag -Kthread to make this header compile.)
+ # We check for pthread_join because it is in -lpthread on IRIX
+ # while pthread_create is in libc. We check for pthread_attr_init
+ # due to DEC craziness with -lpthreads. We check for
+ # pthread_cleanup_push because it is one of the few pthread
+ # functions on Solaris that doesn't have a non-functional libc stub.
+ # We try pthread_create on general principles.
+ AC_TRY_LINK([#include <pthread.h>],
+ [pthread_t th; pthread_join(th, 0);
+ pthread_attr_init(0); pthread_cleanup_push(0, 0);
+ pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
+ [acx_pthread_ok=yes])
+
+ LIBS="$save_LIBS"
+ CFLAGS="$save_CFLAGS"
+
+ AC_MSG_RESULT($acx_pthread_ok)
+ if test "x$acx_pthread_ok" = xyes; then
+ break;
+ fi
+
+ PTHREAD_LIBS=""
+ PTHREAD_CFLAGS=""
+done
+fi
+
+# Various other checks:
+if test "x$acx_pthread_ok" = xyes; then
+ save_LIBS="$LIBS"
+ LIBS="$PTHREAD_LIBS $LIBS"
+ save_CFLAGS="$CFLAGS"
+ CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
+
+ # Detect AIX lossage: JOINABLE attribute is called UNDETACHED.
+ AC_MSG_CHECKING([for joinable pthread attribute])
+ attr_name=unknown
+ for attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do
+ AC_TRY_LINK([#include <pthread.h>], [int attr=$attr;],
+ [attr_name=$attr; break])
+ done
+ AC_MSG_RESULT($attr_name)
+ if test "$attr_name" != PTHREAD_CREATE_JOINABLE; then
+ AC_DEFINE_UNQUOTED(PTHREAD_CREATE_JOINABLE, $attr_name,
+ [Define to necessary symbol if this constant
+ uses a non-standard name on your system.])
+ fi
+
+ AC_MSG_CHECKING([if more special flags are required for pthreads])
+ flag=no
+ case "${host_cpu}-${host_os}" in
+ *-aix* | *-freebsd* | *-darwin*) flag="-D_THREAD_SAFE";;
+ *solaris* | *-osf* | *-hpux*) flag="-D_REENTRANT";;
+ esac
+ AC_MSG_RESULT(${flag})
+ if test "x$flag" != xno; then
+ PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS"
+ fi
+
+ LIBS="$save_LIBS"
+ CFLAGS="$save_CFLAGS"
+
+ # More AIX lossage: must compile with cc_r
+ AC_CHECK_PROG(PTHREAD_CC, cc_r, cc_r, ${CC})
+else
+ PTHREAD_CC="$CC"
+fi
+
+AC_SUBST(PTHREAD_LIBS)
+AC_SUBST(PTHREAD_CFLAGS)
+AC_SUBST(PTHREAD_CC)
+
+# Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
+if test x"$acx_pthread_ok" = xyes; then
+ ifelse([$1],,AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.]),[$1])
+ :
+else
+ acx_pthread_ok=no
+ $2
+fi
+AC_LANG_RESTORE
+])dnl ACX_PTHREAD
diff --git a/compat-bonjour/Makefile.am b/compat-bonjour/Makefile.am
new file mode 100644
index 0000000..78decb7
--- /dev/null
+++ b/compat-bonjour/Makefile.am
@@ -0,0 +1,40 @@
+# $Id$
+
+# This file is part of avahi.
+#
+# avahi is free software; you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License as
+# published by the Free Software Foundation; either version 2 of the
+# License, or (at your option) any later version.
+#
+# avahi 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 Lesser General Public
+# License along with avahi; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+# USA.
+
+AM_CFLAGS=-I$(top_srcdir)
+
+# This cool debug trap works on i386/gcc only
+AM_CFLAGS+='-DDEBUG_TRAP=__asm__("int $$3")'
+
+avahi_compat_bonjourdir=$(includedir)/avahi-compat-bonjour
+
+avahi_compat_bonjour_HEADERS = \
+ dns_sd.h
+
+
+lib_LTLIBRARIES = \
+ libavahi-compat-bonjour.la
+
+libavahi_compat_bonjour_la_SOURCES = \
+ unsupported.c \
+ compat.c \
+ dns_sd.h
+
+libavahi_compat_bonjour_la_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
+libavahi_compat_bonjour_la_LDFLAGS = $(AM_LDFLAGS) -export-dynamic -version-info $(LIBAVAHI_COMPAT_BONJOUR_VERSION_INFO) $(PTHREAD_LIBS)
diff --git a/compat-bonjour/compat.c b/compat-bonjour/compat.c
new file mode 100644
index 0000000..6651845
--- /dev/null
+++ b/compat-bonjour/compat.c
@@ -0,0 +1,536 @@
+/* $Id$ */
+
+/***
+ This file is part of avahi.
+
+ avahi is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of the
+ License, or (at your option) any later version.
+
+ avahi 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 avahi; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <pthread.h>
+#include <assert.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <signal.h>
+#include <netinet/in.h>
+
+#include <avahi-common/simple-watch.h>
+#include <avahi-common/malloc.h>
+#include <avahi-common/error.h>
+#include <avahi-client/client.h>
+
+
+#include "dns_sd.h"
+
+enum {
+ COMMAND_POLL = 'P',
+ COMMAND_QUIT = 'Q',
+ COMMAND_POLLED = 'D'
+};
+
+struct _DNSServiceRef_t {
+ AvahiSimplePoll *simple_poll;
+
+ int thread_fd, main_fd;
+
+ pthread_t thread;
+ int thread_running;
+
+ pthread_mutex_t mutex;
+
+ void *context;
+ DNSServiceBrowseReply service_browser_callback;
+ DNSServiceResolveReply service_resolver_callback;
+
+ AvahiClient *client;
+ AvahiServiceBrowser *service_browser;
+ AvahiServiceResolver *service_resolver;
+};
+
+#define ASSERT_SUCCESS(r) { int __ret = (r); assert(__ret == 0); }
+
+static int read_command(int fd) {
+ ssize_t r;
+ char command;
+
+ assert(fd >= 0);
+
+ if ((r = read(fd, &command, 1)) != 1) {
+ fprintf(stderr, __FILE__": read() failed: %s\n", r < 0 ? strerror(errno) : "EOF");
+ return -1;
+ }
+
+ return command;
+}
+
+static int write_command(int fd, char reply) {
+ assert(fd >= 0);
+
+ if (write(fd, &reply, 1) != 1) {
+ fprintf(stderr, __FILE__": write() failed: %s\n", strerror(errno));
+ return -1;
+ }
+
+ return 0;
+}
+
+static int poll_func(struct pollfd *ufds, unsigned int nfds, int timeout, void *userdata) {
+ DNSServiceRef sdref = userdata;
+ int ret;
+
+ assert(sdref);
+
+ ASSERT_SUCCESS(pthread_mutex_unlock(&sdref->mutex));
+
+/* fprintf(stderr, "pre-syscall\n"); */
+ ret = poll(ufds, nfds, timeout);
+/* fprintf(stderr, "post-syscall\n"); */
+
+ ASSERT_SUCCESS(pthread_mutex_lock(&sdref->mutex));
+
+ return ret;
+}
+
+static void * thread_func(void *data) {
+ DNSServiceRef sdref = data;
+ sigset_t mask;
+
+ sigfillset(&mask);
+ pthread_sigmask(SIG_BLOCK, &mask, NULL);
+
+ sdref->thread = pthread_self();
+ sdref->thread_running = 1;
+
+ for (;;) {
+ char command;
+
+ if ((command = read_command(sdref->thread_fd)) < 0)
+ break;
+
+/* fprintf(stderr, "Command: %c\n", command); */
+
+ switch (command) {
+
+ case COMMAND_POLL:
+
+ ASSERT_SUCCESS(pthread_mutex_lock(&sdref->mutex));
+
+
+ if (avahi_simple_poll_run(sdref->simple_poll) < 0) {
+ fprintf(stderr, __FILE__": avahi_simple_poll_run() failed.\n");
+ ASSERT_SUCCESS(pthread_mutex_unlock(&sdref->mutex));
+ break;
+ }
+
+ if (write_command(sdref->thread_fd, COMMAND_POLLED) < 0) {
+ ASSERT_SUCCESS(pthread_mutex_unlock(&sdref->mutex));
+ break;
+ }
+
+ ASSERT_SUCCESS(pthread_mutex_unlock(&sdref->mutex));
+
+ break;
+
+ case COMMAND_QUIT:
+ return NULL;
+ }
+
+ }
+
+ return NULL;
+}
+
+static DNSServiceRef sdref_new(void) {
+ int fd[2] = { -1, -1 };
+ DNSServiceRef sdref = NULL;
+
+ if (socketpair(AF_UNIX, SOCK_STREAM, 0, fd) < 0)
+ goto fail;
+
+ if (!(sdref = avahi_new(struct _DNSServiceRef_t, 1)))
+ goto fail;
+
+ sdref->thread_fd = fd[0];
+ sdref->main_fd = fd[1];
+
+ sdref->client = NULL;
+ sdref->service_browser = NULL;
+ sdref->service_resolver = NULL;
+
+ pthread_mutex_init(&sdref->mutex, NULL);
+
+ sdref->thread_running = 0;
+
+ if (!(sdref->simple_poll = avahi_simple_poll_new()))
+ goto fail;
+
+ avahi_simple_poll_set_func(sdref->simple_poll, poll_func, sdref);
+
+ /* Start simple poll */
+ if (avahi_simple_poll_prepare(sdref->simple_poll, -1) < 0)
+ goto fail;
+
+ /* Queue a initiall POLL command for the thread */
+ if (write_command(sdref->main_fd, COMMAND_POLL) < 0)
+ goto fail;
+
+ if (pthread_create(&sdref->thread, NULL, thread_func, sdref) != 0)
+ goto fail;
+
+ sdref->thread_running = 1;
+
+ return sdref;
+
+fail:
+
+ if (sdref)
+ DNSServiceRefDeallocate(sdref);
+
+ return NULL;
+}
+
+int DNSSD_API DNSServiceRefSockFD(DNSServiceRef sdRef) {
+ assert(sdRef);
+
+ return sdRef->main_fd;
+}
+
+DNSServiceErrorType DNSSD_API DNSServiceProcessResult(DNSServiceRef sdref) {
+ DNSServiceErrorType ret = kDNSServiceErr_Unknown;
+
+ if (pthread_mutex_lock(&sdref->mutex) != 0)
+ return kDNSServiceErr_Unknown;
+
+ /* Cleanup notification socket */
+ if (read_command(sdref->main_fd) != COMMAND_POLLED)
+ goto finish;
+
+ if (avahi_simple_poll_dispatch(sdref->simple_poll) < 0)
+ goto finish;
+
+ if (avahi_simple_poll_prepare(sdref->simple_poll, -1) < 0)
+ goto finish;
+
+ /* Request the poll */
+ if (write_command(sdref->main_fd, COMMAND_POLL) < 0)
+ goto finish;
+
+ ret = kDNSServiceErr_NoError;
+
+finish:
+
+ pthread_mutex_unlock(&sdref->mutex);
+
+ return ret;
+}
+
+void DNSSD_API DNSServiceRefDeallocate(DNSServiceRef sdref) {
+ assert(sdref);
+
+ fprintf(stderr, "deallocating()\n");
+
+ if (sdref->thread_running) {
+ write_command(sdref->main_fd, COMMAND_QUIT);
+ avahi_simple_poll_wakeup(sdref->simple_poll);
+ pthread_join(sdref->thread, NULL);
+ }
+
+ if (sdref->client)
+ avahi_client_free(sdref->client);
+
+ if (sdref->thread_fd >= 0)
+ close(sdref->thread_fd);
+
+ if (sdref->main_fd >= 0)
+ close(sdref->main_fd);
+
+ if (sdref->simple_poll)
+ avahi_simple_poll_free(sdref->simple_poll);
+
+ pthread_mutex_destroy(&sdref->mutex);
+
+ avahi_free(sdref);
+}
+
+static DNSServiceErrorType map_error(int error) {
+ switch (error) {
+ case AVAHI_OK :
+ return kDNSServiceErr_NoError;
+
+ case AVAHI_ERR_BAD_STATE :
+ return kDNSServiceErr_BadState;
+
+ case AVAHI_ERR_INVALID_HOST_NAME:
+ case AVAHI_ERR_INVALID_DOMAIN_NAME:
+ case AVAHI_ERR_INVALID_TTL:
+ case AVAHI_ERR_IS_PATTERN:
+ case AVAHI_ERR_INVALID_RECORD:
+ case AVAHI_ERR_INVALID_SERVICE_NAME:
+ case AVAHI_ERR_INVALID_SERVICE_TYPE:
+ case AVAHI_ERR_INVALID_PORT:
+ case AVAHI_ERR_INVALID_KEY:
+ case AVAHI_ERR_INVALID_ADDRESS:
+ return kDNSServiceErr_BadParam;
+
+
+ case AVAHI_ERR_LOCAL_COLLISION:
+ return kDNSServiceErr_NameConflict;
+
+ case AVAHI_ERR_TOO_MANY_CLIENTS:
+ case AVAHI_ERR_TOO_MANY_OBJECTS:
+ case AVAHI_ERR_TOO_MANY_ENTRIES:
+ case AVAHI_ERR_ACCESS_DENIED:
+ return kDNSServiceErr_Refused;
+
+ case AVAHI_ERR_INVALID_OPERATION:
+ case AVAHI_ERR_INVALID_OBJECT:
+ return kDNSServiceErr_Invalid;
+
+ case AVAHI_ERR_NO_MEMORY:
+ return kDNSServiceErr_NoMemory;
+
+ case AVAHI_ERR_INVALID_INTERFACE:
+ case AVAHI_ERR_INVALID_PROTOCOL:
+ return kDNSServiceErr_BadInterfaceIndex;
+
+ case AVAHI_ERR_INVALID_FLAGS:
+ return kDNSServiceErr_BadFlags;
+
+ case AVAHI_ERR_NOT_FOUND:
+ return kDNSServiceErr_NoSuchName;
+
+ case AVAHI_ERR_VERSION_MISMATCH:
+ return kDNSServiceErr_Incompatible;
+
+ case AVAHI_ERR_NO_NETWORK:
+ case AVAHI_ERR_OS:
+ case AVAHI_ERR_INVALID_CONFIG:
+ case AVAHI_ERR_TIMEOUT:
+ case AVAHI_ERR_DBUS_ERROR:
+ case AVAHI_ERR_NOT_CONNECTED:
+ case AVAHI_ERR_NO_DAEMON:
+ break;
+
+ }
+
+ return kDNSServiceErr_Unknown;
+}
+
+static void service_browser_callback(
+ AvahiServiceBrowser *b,
+ AvahiIfIndex interface,
+ AvahiProtocol protocol,
+ AvahiBrowserEvent event,
+ const char *name,
+ const char *type,
+ const char *domain,
+ AvahiLookupResultFlags flags,
+ void *userdata) {
+
+ DNSServiceRef sdref = userdata;
+
+ assert(b);
+ assert(sdref);
+
+ switch (event) {
+ case AVAHI_BROWSER_NEW:
+ sdref->service_browser_callback(sdref, kDNSServiceFlagsAdd, interface, kDNSServiceErr_NoError, name, type, domain, sdref->context);
+ break;
+
+ case AVAHI_BROWSER_REMOVE:
+ sdref->service_browser_callback(sdref, 0, interface, kDNSServiceErr_NoError, name, type, domain, sdref->context);
+ break;
+
+ case AVAHI_BROWSER_FAILURE:
+ sdref->service_browser_callback(sdref, 0, interface, kDNSServiceErr_Unknown, name, type, domain, sdref->context);
+ break;
+
+ case AVAHI_BROWSER_NOT_FOUND:
+ sdref->service_browser_callback(sdref, 0, interface, kDNSServiceErr_NoSuchName, name, type, domain, sdref->context);
+ break;
+
+ case AVAHI_BROWSER_CACHE_EXHAUSTED:
+ case AVAHI_BROWSER_ALL_FOR_NOW:
+ break;
+ }
+}
+
+DNSServiceErrorType DNSSD_API DNSServiceBrowse(
+ DNSServiceRef *ret_sdref,
+ DNSServiceFlags flags,
+ uint32_t interface,
+ const char *regtype,
+ const char *domain,
+ DNSServiceBrowseReply callback,
+ void *context) {
+
+ DNSServiceErrorType ret = kDNSServiceErr_Unknown;
+ int error;
+ DNSServiceRef sdref = NULL;
+ AvahiIfIndex ifindex;
+
+ assert(ret_sdref);
+ assert(regtype);
+ assert(domain);
+ assert(callback);
+
+ if (interface == kDNSServiceInterfaceIndexLocalOnly || flags != 0)
+ return kDNSServiceErr_Unsupported;
+
+ if (!(sdref = sdref_new()))
+ return kDNSServiceErr_Unknown;
+
+ sdref->context = context;
+ sdref->service_browser_callback = callback;
+
+ ASSERT_SUCCESS(pthread_mutex_lock(&sdref->mutex));
+
+ if (!(sdref->client = avahi_client_new(avahi_simple_poll_get(sdref->simple_poll), NULL, NULL, &error))) {
+ ret = map_error(error);
+ goto finish;
+ }
+
+ ifindex = interface == kDNSServiceInterfaceIndexAny ? AVAHI_IF_UNSPEC : (AvahiIfIndex) interface;
+
+ if (!(sdref->service_browser = avahi_service_browser_new(sdref->client, ifindex, AVAHI_PROTO_UNSPEC, regtype, domain, 0, service_browser_callback, sdref))) {
+ ret = map_error(avahi_client_errno(sdref->client));
+ goto finish;
+ }
+
+
+ ret = kDNSServiceErr_NoError;
+ *ret_sdref = sdref;
+
+finish:
+
+ ASSERT_SUCCESS(pthread_mutex_unlock(&sdref->mutex));
+
+ if (ret != kDNSServiceErr_NoError)
+ DNSServiceRefDeallocate(sdref);
+
+ return ret;
+}
+
+static void service_resolver_callback(
+ AvahiServiceResolver *r,
+ AvahiIfIndex interface,
+ AvahiProtocol protocol,
+ AvahiResolverEvent event,
+ const char *name,
+ const char *type,
+ const char *domain,
+ const char *host_name,
+ const AvahiAddress *a,
+ uint16_t port,
+ AvahiStringList *txt,
+ AvahiLookupResultFlags flags,
+ void *userdata) {
+
+ DNSServiceRef sdref = userdata;
+
+ assert(r);
+ assert(sdref);
+
+ switch (event) {
+ case AVAHI_RESOLVER_FOUND: {
+
+ char *p = NULL;
+ size_t l = 0;
+
+ if ((p = avahi_new0(char, (l = avahi_string_list_serialize(txt, NULL, 0))+1)))
+ avahi_string_list_serialize(txt, p, l);
+
+ sdref->service_resolver_callback(sdref, 0, interface, kDNSServiceErr_NoError, "blaa", host_name, htons(port), l, p, sdref->context);
+
+ avahi_free(p);
+ break;
+ }
+
+ case AVAHI_RESOLVER_TIMEOUT:
+ case AVAHI_RESOLVER_NOT_FOUND:
+ sdref->service_resolver_callback(sdref, 0, interface, kDNSServiceErr_NoSuchName, NULL, NULL, 0, 0, NULL, sdref->context);
+ break;
+
+ case AVAHI_RESOLVER_FAILURE:
+ sdref->service_resolver_callback(sdref, 0, interface, kDNSServiceErr_Unknown, NULL, NULL, 0, 0, NULL, sdref->context);
+
+ }
+}
+
+
+DNSServiceErrorType DNSSD_API DNSServiceResolve(
+ DNSServiceRef *ret_sdref,
+ DNSServiceFlags flags,
+ uint32_t interface,
+ const char *name,
+ const char *regtype,
+ const char *domain,
+ DNSServiceResolveReply callback,
+ void *context) {
+
+ DNSServiceErrorType ret = kDNSServiceErr_Unknown;
+ int error;
+ DNSServiceRef sdref = NULL;
+ AvahiIfIndex ifindex;
+
+ assert(ret_sdref);
+ assert(name);
+ assert(regtype);
+ assert(domain);
+ assert(callback);
+
+ if (interface == kDNSServiceInterfaceIndexLocalOnly || flags != 0)
+ return kDNSServiceErr_Unsupported;
+
+ if (!(sdref = sdref_new()))
+ return kDNSServiceErr_Unknown;
+
+ sdref->context = context;
+ sdref->service_resolver_callback = callback;
+
+ ASSERT_SUCCESS(pthread_mutex_lock(&sdref->mutex));
+
+ if (!(sdref->client = avahi_client_new(avahi_simple_poll_get(sdref->simple_poll), NULL, NULL, &error))) {
+ ret = map_error(error);
+ goto finish;
+ }
+
+ ifindex = interface == kDNSServiceInterfaceIndexAny ? AVAHI_IF_UNSPEC : (AvahiIfIndex) interface;
+
+ if (!(sdref->service_resolver = avahi_service_resolver_new(sdref->client, ifindex, AVAHI_PROTO_UNSPEC, name, regtype, domain, AVAHI_PROTO_UNSPEC, 0, service_resolver_callback, sdref))) {
+ ret = map_error(avahi_client_errno(sdref->client));
+ goto finish;
+ }
+
+
+ ret = kDNSServiceErr_NoError;
+ *ret_sdref = sdref;
+
+finish:
+
+ ASSERT_SUCCESS(pthread_mutex_unlock(&sdref->mutex));
+
+ if (ret != kDNSServiceErr_NoError)
+ DNSServiceRefDeallocate(sdref);
+
+ return ret;
+}
+
diff --git a/compat-bonjour/funcs.txt b/compat-bonjour/funcs.txt
new file mode 100644
index 0000000..94104ad
--- /dev/null
+++ b/compat-bonjour/funcs.txt
@@ -0,0 +1,32 @@
+Yes:
+
+DNSServiceRefSockFD
+DNSServiceProcessResult
+DNSServiceRefDeallocate
+DNSServiceEnumerateDomains
+DNSServiceRegister
+DNSServiceBrowse
+DNSServiceResolve
+DNSServiceConstructFullName
+
+TXTRecordCreate
+TXTRecordDeallocate
+TXTRecordSetValue
+TXTRecordRemoveValue
+TXTRecordGetLength
+TXTRecordGetBytesPtr
+TXTRecordContainsKey
+TXTRecordGetValuePtr
+TXTRecordGetCount
+TXTRecordGetItemAtIndex
+
+No:
+
+DNSServiceRegisterRecord
+DNSServiceQueryRecord
+DNSServiceReconfirmRecord
+DNSServiceCreateConnection
+DNSServiceAddRecord
+DNSServiceUpdateRecord
+DNSServiceRemoveRecord
+DNSServiceSetDefaultDomainForUser
diff --git a/compat-bonjour/unsupported.c b/compat-bonjour/unsupported.c
new file mode 100644
index 0000000..d57d028
--- /dev/null
+++ b/compat-bonjour/unsupported.c
@@ -0,0 +1,141 @@
+/* $Id$ */
+
+/***
+ This file is part of avahi.
+
+ avahi is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of the
+ License, or (at your option) any later version.
+
+ avahi 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 avahi; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "dns_sd.h"
+
+DNSServiceErrorType DNSSD_API DNSServiceEnumerateDomains(
+ DNSServiceRef *sdRef,
+ DNSServiceFlags flags,
+ uint32_t interfaceIndex,
+ DNSServiceDomainEnumReply callBack,
+ void *context) {
+
+ return kDNSServiceErr_Unsupported;
+}
+
+DNSServiceErrorType DNSSD_API DNSServiceRegister (
+ DNSServiceRef *sdRef,
+ DNSServiceFlags flags,
+ uint32_t interfaceIndex,
+ const char *name,
+ const char *regtype,
+ const char *domain,
+ const char *host,
+ uint16_t port,
+ uint16_t txtLen,
+ const void *txtRecord,
+ DNSServiceRegisterReply callBack,
+ void *context) {
+
+ return kDNSServiceErr_Unsupported;
+}
+
+int DNSSD_API DNSServiceConstructFullName (
+ char *fullName,
+ const char *service,
+ const char *regtype,
+ const char *domain) {
+
+ return kDNSServiceErr_Unsupported;
+}
+
+DNSServiceErrorType DNSSD_API DNSServiceRegisterRecord (
+ DNSServiceRef sdRef,
+ DNSRecordRef *RecordRef,
+ DNSServiceFlags flags,
+ uint32_t interfaceIndex,
+ const char *fullname,
+ uint16_t rrtype,
+ uint16_t rrclass,
+ uint16_t rdlen,
+ const void *rdata,
+ uint32_t ttl,
+ DNSServiceRegisterRecordReply callBack,
+ void *context) {
+
+ return kDNSServiceErr_Unsupported;
+}
+
+DNSServiceErrorType DNSSD_API DNSServiceQueryRecord (
+ DNSServiceRef *sdRef,
+ DNSServiceFlags flags,
+ uint32_t interfaceIndex,
+ const char *fullname,
+ uint16_t rrtype,
+ uint16_t rrclass,
+ DNSServiceQueryRecordReply callBack,
+ void *context) {
+
+ return kDNSServiceErr_Unsupported;
+}
+
+void DNSSD_API DNSServiceReconfirmRecord (
+ DNSServiceFlags flags,
+ uint32_t interfaceIndex,
+ const char *fullname,
+ uint16_t rrtype,
+ uint16_t rrclass,
+ uint16_t rdlen,
+ const void *rdata) {
+
+ return;
+}
+
+DNSServiceErrorType DNSSD_API DNSServiceCreateConnection(DNSServiceRef *sdRef) {
+ return kDNSServiceErr_Unsupported;
+}
+
+DNSServiceErrorType DNSSD_API DNSServiceAddRecord(
+ DNSServiceRef sdRef,
+ DNSRecordRef *RecordRef,
+ DNSServiceFlags flags,
+ uint16_t rrtype,
+ uint16_t rdlen,
+ const void *rdata,
+ uint32_t ttl) {
+
+ return kDNSServiceErr_Unsupported;
+}
+
+DNSServiceErrorType DNSSD_API DNSServiceUpdateRecord(
+ DNSServiceRef sdRef,
+ DNSRecordRef RecordRef,
+ DNSServiceFlags flags,
+ uint16_t rdlen,
+ const void *rdata,
+ uint32_t ttl) {
+
+ return kDNSServiceErr_Unsupported;
+}
+
+DNSServiceErrorType DNSSD_API DNSServiceRemoveRecord(
+ DNSServiceRef sdRef,
+ DNSRecordRef RecordRef,
+ DNSServiceFlags flags) {
+
+ return kDNSServiceErr_Unsupported;
+}
+
+
diff --git a/configure.ac b/configure.ac
index d047e5c..c70ab2d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -34,6 +34,7 @@ AC_SUBST(LIBAVAHI_CLIENT_VERSION_INFO, [2:0:1])
AC_SUBST(LIBAVAHI_GLIB_VERSION_INFO, [0:1:0])
AC_SUBST(LIBAVAHI_QT3_VERSION_INFO, [0:0:0])
AC_SUBST(LIBAVAHI_QT4_VERSION_INFO, [0:0:0])
+AC_SUBST(LIBAVAHI_COMPAT_BONJOUR_VERSION_INFO, [0:0:0])
if type -p stow > /dev/null && test -d /usr/local/stow ; then
AC_MSG_NOTICE([*** Found /usr/local/stow: default install prefix set to /usr/local/stow/${PACKAGE_NAME}-${PACKAGE_VERSION} ***])
@@ -53,6 +54,8 @@ AC_PROG_GCC_TRADITIONAL
# libtool stuff
AC_PROG_LIBTOOL
+ACX_PTHREAD(,AC_MSG_ERROR([Missing POSIX Threads support]))
+
#
# Detecting the linux distribution for specific things like init scripts.
#
@@ -552,6 +555,7 @@ man/Makefile
tests/Makefile
service-type-database/Makefile
avahi-sharp/Makefile
+compat-bonjour/Makefile
])
AC_OUTPUT