AM_CFLAGS=-I$(top_srcdir)
-# DBUS
-AM_CFLAGS+=$(DBUS_CFLAGS)
-AM_LDADD=$(DBUS_LIBS)
-
# This cool debug trap works on i386/gcc only
AM_CFLAGS+='-DDEBUG_TRAP=__asm__("int $$3")'
noinst_HEADERS = \
internal.h
- dbus-watch-glue.h
noinst_PROGRAMS = \
client-test
libavahi_client_la_SOURCES = \
client.c client.h \
entrygroup.c \
- browser.c \
- dbus-watch-glue.c
+ browser.c
-libavahi_client_la_CFLAGS = $(AM_CFLAGS)
-libavahi_client_la_LIBADD = $(AM_LDADD)
+libavahi_client_la_CFLAGS = $(AM_CFLAGS) $(DBUS_CFLAGS)
+libavahi_client_la_LIBADD = $(AM_LDADD) $(DBUS_LIBS) ../avahi-common/libdbus-watch-glue.a
client_test_SOURCES = \
client-test.c
-client_test_CFLAGS = $(AM_CFLAGS)
-client_test_LDADD = $(AM_LDADD) libavahi-client.la ../avahi-common/libavahi-common.la ../avahi-glib/libavahi-glib.la
+
+client_test_CFLAGS = $(AM_CFLAGS) $(GLIB20_CFLAGS)
+client_test_LDADD = $(AM_LDADD) $(GLIB20_LIBS) libavahi-client.la ../avahi-common/libavahi-common.la ../avahi-glib/libavahi-glib.la
endif
#include <string.h>
#include <dbus/dbus.h>
-#include <dbus/dbus-glib-lowlevel.h>
#include <avahi-client/client.h>
#include <avahi-common/dbus.h>
#include <avahi-common/llist.h>
#include <avahi-common/error.h>
#include <avahi-common/malloc.h>
+#include <avahi-common/dbus-watch-glue.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
-#include "dbus-watch-glue.h"
#include "client.h"
#include "internal.h"
+++ /dev/null
-/* $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.
-***/
-
-#include <assert.h>
-
-#include <avahi-common/malloc.h>
-
-#include "dbus-watch-glue.h"
-
-static AvahiWatchEvent translate_dbus_to_avahi(unsigned int f) {
- AvahiWatchEvent e = 0;
-
- if (f & DBUS_WATCH_READABLE)
- e |= AVAHI_WATCH_IN;
- if (f & DBUS_WATCH_WRITABLE)
- e |= AVAHI_WATCH_OUT;
- if (f & DBUS_WATCH_ERROR)
- e |= AVAHI_WATCH_ERR;
- if (f & DBUS_WATCH_HANGUP)
- e |= AVAHI_WATCH_HUP;
-
- return e;
-}
-
-static unsigned int translate_avahi_to_dbus(AvahiWatchEvent e) {
- unsigned int f = 0;
-
- if (e & AVAHI_WATCH_IN)
- f |= DBUS_WATCH_READABLE;
- if (e & AVAHI_WATCH_OUT)
- f |= DBUS_WATCH_WRITABLE;
- if (e & AVAHI_WATCH_ERR)
- f |= DBUS_WATCH_ERROR;
- if (e & AVAHI_WATCH_HUP)
- f |= DBUS_WATCH_HANGUP;
-
- return f;
-}
-
-static void watch_callback(AvahiWatch *avahi_watch, int fd, AvahiWatchEvent events, void *userdata) {
- DBusWatch *dbus_watch = userdata;
- assert(avahi_watch);
- assert(dbus_watch);
-
- dbus_watch_handle(dbus_watch, translate_avahi_to_dbus(events));
- /* Ignore the return value */
-}
-
-static dbus_bool_t update_watch(const AvahiPoll *poll_api, DBusWatch *dbus_watch) {
- AvahiWatch *avahi_watch;
- dbus_bool_t b;
-
- assert(dbus_watch);
-
- avahi_watch = dbus_watch_get_data(dbus_watch);
-
- b = dbus_watch_get_enabled(dbus_watch);
-
- if (b && !avahi_watch) {
-
- if (!(avahi_watch = poll_api->watch_new(
- poll_api,
- dbus_watch_get_fd(dbus_watch),
- translate_dbus_to_avahi(dbus_watch_get_flags(dbus_watch)),
- watch_callback,
- dbus_watch)))
- return FALSE;
-
- dbus_watch_set_data(dbus_watch, avahi_watch, (DBusFreeFunction) poll_api->watch_free);
-
- } else if (!b && avahi_watch) {
-
- poll_api->watch_free(avahi_watch);
- dbus_watch_set_data(dbus_watch, NULL, NULL);
-
- } else if (avahi_watch) {
-
- /* Update flags */
- poll_api->watch_update(avahi_watch, dbus_watch_get_flags(dbus_watch));
- }
-
- return TRUE;
-}
-
-static dbus_bool_t add_watch(DBusWatch *dbus_watch, void *userdata) {
- const AvahiPoll *poll_api = (const AvahiPoll*) userdata;
-
- assert(dbus_watch);
- assert(poll_api);
-
- return update_watch(poll_api, dbus_watch);
-}
-
-static void remove_watch(DBusWatch *dbus_watch, void *userdata) {
- const AvahiPoll *poll_api = (const AvahiPoll*) userdata;
- AvahiWatch *avahi_watch;
-
- assert(dbus_watch);
- assert(poll_api);
-
- avahi_watch = dbus_watch_get_data(dbus_watch);
- poll_api->watch_free(avahi_watch);
- dbus_watch_set_data(dbus_watch, NULL, NULL);
-}
-
-static void watch_toggled(DBusWatch *dbus_watch, void *userdata) {
- const AvahiPoll *poll_api = (const AvahiPoll*) userdata;
-
- assert(dbus_watch);
- assert(poll_api);
-
- update_watch(poll_api, dbus_watch);
-}
-
-typedef struct TimeoutData {
- const AvahiPoll *poll_api;
- AvahiTimeout *avahi_timeout;
- DBusTimeout *dbus_timeout;
-} TimeoutData;
-
-static void update_timeout(TimeoutData *timeout) {
- assert(timeout);
-
- if (dbus_timeout_get_enabled(timeout->dbus_timeout)) {
- struct timeval tv;
- avahi_elapse_time(&tv, dbus_timeout_get_interval(timeout->dbus_timeout), 0);
- timeout->poll_api->timeout_update(timeout->
- avahi_timeout, &tv);
- } else
- timeout->poll_api->timeout_update(timeout->avahi_timeout, NULL);
-
-}
-
-static void timeout_callback(AvahiTimeout *avahi_timeout, void *userdata) {
- TimeoutData *timeout = userdata;
-
- assert(avahi_timeout);
- assert(timeout);
-
- dbus_timeout_handle(timeout->dbus_timeout);
- /* Ignore the return value */
-
- update_timeout(timeout);
-}
-
-static dbus_bool_t add_timeout(DBusTimeout *dbus_timeout, void *userdata) {
- TimeoutData *timeout;
- const AvahiPoll *poll_api = (const AvahiPoll*) userdata;
- struct timeval tv;
- dbus_bool_t b;
-
- assert(dbus_timeout);
- assert(poll_api);
-
- if (!(timeout = avahi_new(TimeoutData, 1)))
- return FALSE;
-
- timeout->dbus_timeout = dbus_timeout;
- timeout->poll_api = poll_api;
-
- if ((b = dbus_timeout_get_enabled(dbus_timeout)))
- avahi_elapse_time(&tv, dbus_timeout_get_interval(dbus_timeout), 0);
-
- if (!(timeout->avahi_timeout = poll_api->timeout_new(
- poll_api,
- b ? &tv : NULL,
- timeout_callback,
- dbus_timeout))) {
- avahi_free(timeout);
- return FALSE;
- }
-
- dbus_timeout_set_data(dbus_timeout, timeout, NULL);
- return TRUE;
-}
-
-static void remove_timeout(DBusTimeout *dbus_timeout, void *userdata) {
- TimeoutData *timeout;
- const AvahiPoll *poll_api = (const AvahiPoll*) userdata;
-
- assert(dbus_timeout);
- assert(poll_api);
-
- timeout = dbus_timeout_get_data(dbus_timeout);
- assert(timeout);
-
- poll_api->timeout_free(timeout->avahi_timeout);
- avahi_free(timeout);
- dbus_timeout_set_data(dbus_timeout, NULL, NULL);
-}
-
-static void timeout_toggled(DBusTimeout *dbus_timeout, void *userdata) {
- TimeoutData *timeout;
- const AvahiPoll *poll_api = (const AvahiPoll*) userdata;
-
- assert(dbus_timeout);
- assert(poll_api);
-
- timeout = dbus_timeout_get_data(dbus_timeout);
- assert(timeout);
-
- update_timeout(timeout);
-}
-
-int avahi_dbus_connection_glue(DBusConnection *c, const AvahiPoll *poll_api) {
- assert(c);
- assert(poll_api);
-
- if (!(dbus_connection_set_watch_functions(c, add_watch, remove_watch, watch_toggled, (void*) poll_api, NULL)))
- return -1;
-
- if (!(dbus_connection_set_timeout_functions(c, add_timeout, remove_timeout, timeout_toggled, (void*) poll_api, NULL)))
- return -1;
-
- return 0;
-}
+++ /dev/null
-#ifndef foodbuswatchgluehfoo
-#define foodbuswatchgluehfoo
-
-/* $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.
-***/
-
-#include <dbus/dbus.h>
-
-#include <avahi-common/watch.h>
-
-int avahi_dbus_connection_glue(DBusConnection *c, const AvahiPoll *poll_api);
-
-#endif
simple-watch.h \
gccmacro.h
-noinst_HEADERS = llist.h
-
-if ENABLE_DBUS
-noinst_HEADERS += dbus.h
-endif
+noinst_HEADERS = \
+ llist.h
noinst_PROGRAMS = \
strlst-test \
timeval_test_LDADD = $(AM_LDADD)
+
+if ENABLE_DBUS
+noinst_HEADERS += \
+ dbus.h \
+ dbus-watch-glue.h
+
+noinst_LIBRARIES = \
+ libdbus-watch-glue.a
+
+libdbus_watch_glue_a_SOURCES = \
+ dbus-watch-glue.h dbus-watch-glue.c
+
+libdbus_watch_glue_a_CFLAGS = $(AM_CFLAGS) $(DBUS_CFLAGS)
+
+endif
+
--- /dev/null
+/* $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.
+***/
+
+#include <assert.h>
+
+#include <avahi-common/malloc.h>
+
+#include "dbus-watch-glue.h"
+
+static AvahiWatchEvent translate_dbus_to_avahi(unsigned int f) {
+ AvahiWatchEvent e = 0;
+
+ if (f & DBUS_WATCH_READABLE)
+ e |= AVAHI_WATCH_IN;
+ if (f & DBUS_WATCH_WRITABLE)
+ e |= AVAHI_WATCH_OUT;
+ if (f & DBUS_WATCH_ERROR)
+ e |= AVAHI_WATCH_ERR;
+ if (f & DBUS_WATCH_HANGUP)
+ e |= AVAHI_WATCH_HUP;
+
+ return e;
+}
+
+static unsigned int translate_avahi_to_dbus(AvahiWatchEvent e) {
+ unsigned int f = 0;
+
+ if (e & AVAHI_WATCH_IN)
+ f |= DBUS_WATCH_READABLE;
+ if (e & AVAHI_WATCH_OUT)
+ f |= DBUS_WATCH_WRITABLE;
+ if (e & AVAHI_WATCH_ERR)
+ f |= DBUS_WATCH_ERROR;
+ if (e & AVAHI_WATCH_HUP)
+ f |= DBUS_WATCH_HANGUP;
+
+ return f;
+}
+
+static void watch_callback(AvahiWatch *avahi_watch, int fd, AvahiWatchEvent events, void *userdata) {
+ DBusWatch *dbus_watch = userdata;
+ assert(avahi_watch);
+ assert(dbus_watch);
+
+ dbus_watch_handle(dbus_watch, translate_avahi_to_dbus(events));
+ /* Ignore the return value */
+}
+
+static dbus_bool_t update_watch(const AvahiPoll *poll_api, DBusWatch *dbus_watch) {
+ AvahiWatch *avahi_watch;
+ dbus_bool_t b;
+
+ assert(dbus_watch);
+
+ avahi_watch = dbus_watch_get_data(dbus_watch);
+
+ b = dbus_watch_get_enabled(dbus_watch);
+
+ if (b && !avahi_watch) {
+
+ if (!(avahi_watch = poll_api->watch_new(
+ poll_api,
+ dbus_watch_get_fd(dbus_watch),
+ translate_dbus_to_avahi(dbus_watch_get_flags(dbus_watch)),
+ watch_callback,
+ dbus_watch)))
+ return FALSE;
+
+ dbus_watch_set_data(dbus_watch, avahi_watch, NULL);
+
+ } else if (!b && avahi_watch) {
+
+ poll_api->watch_free(avahi_watch);
+ dbus_watch_set_data(dbus_watch, NULL, NULL);
+
+ } else if (avahi_watch) {
+
+ /* Update flags */
+ poll_api->watch_update(avahi_watch, dbus_watch_get_flags(dbus_watch));
+ }
+
+ return TRUE;
+}
+
+static dbus_bool_t add_watch(DBusWatch *dbus_watch, void *userdata) {
+ const AvahiPoll *poll_api = (const AvahiPoll*) userdata;
+
+ assert(dbus_watch);
+ assert(poll_api);
+
+ return update_watch(poll_api, dbus_watch);
+}
+
+static void remove_watch(DBusWatch *dbus_watch, void *userdata) {
+ const AvahiPoll *poll_api = (const AvahiPoll*) userdata;
+ AvahiWatch *avahi_watch;
+
+ assert(dbus_watch);
+ assert(poll_api);
+
+ if ((avahi_watch = dbus_watch_get_data(dbus_watch))) {
+ poll_api->watch_free(avahi_watch);
+ dbus_watch_set_data(dbus_watch, NULL, NULL);
+ }
+}
+
+static void watch_toggled(DBusWatch *dbus_watch, void *userdata) {
+ const AvahiPoll *poll_api = (const AvahiPoll*) userdata;
+
+ assert(dbus_watch);
+ assert(poll_api);
+
+ update_watch(poll_api, dbus_watch);
+}
+
+typedef struct TimeoutData {
+ const AvahiPoll *poll_api;
+ AvahiTimeout *avahi_timeout;
+ DBusTimeout *dbus_timeout;
+} TimeoutData;
+
+static void update_timeout(TimeoutData *timeout) {
+ assert(timeout);
+
+ if (dbus_timeout_get_enabled(timeout->dbus_timeout)) {
+ struct timeval tv;
+ avahi_elapse_time(&tv, dbus_timeout_get_interval(timeout->dbus_timeout), 0);
+ timeout->poll_api->timeout_update(timeout->
+ avahi_timeout, &tv);
+ } else
+ timeout->poll_api->timeout_update(timeout->avahi_timeout, NULL);
+
+}
+
+static void timeout_callback(AvahiTimeout *avahi_timeout, void *userdata) {
+ TimeoutData *timeout = userdata;
+
+ assert(avahi_timeout);
+ assert(timeout);
+
+ dbus_timeout_handle(timeout->dbus_timeout);
+ /* Ignore the return value */
+
+ update_timeout(timeout);
+}
+
+static dbus_bool_t add_timeout(DBusTimeout *dbus_timeout, void *userdata) {
+ TimeoutData *timeout;
+ const AvahiPoll *poll_api = (const AvahiPoll*) userdata;
+ struct timeval tv;
+ dbus_bool_t b;
+
+ assert(dbus_timeout);
+ assert(poll_api);
+
+ if (!(timeout = avahi_new(TimeoutData, 1)))
+ return FALSE;
+
+ timeout->dbus_timeout = dbus_timeout;
+ timeout->poll_api = poll_api;
+
+ if ((b = dbus_timeout_get_enabled(dbus_timeout)))
+ avahi_elapse_time(&tv, dbus_timeout_get_interval(dbus_timeout), 0);
+
+ if (!(timeout->avahi_timeout = poll_api->timeout_new(
+ poll_api,
+ b ? &tv : NULL,
+ timeout_callback,
+ dbus_timeout))) {
+ avahi_free(timeout);
+ return FALSE;
+ }
+
+ dbus_timeout_set_data(dbus_timeout, timeout, NULL);
+ return TRUE;
+}
+
+static void remove_timeout(DBusTimeout *dbus_timeout, void *userdata) {
+ TimeoutData *timeout;
+ const AvahiPoll *poll_api = (const AvahiPoll*) userdata;
+
+ assert(dbus_timeout);
+ assert(poll_api);
+
+ timeout = dbus_timeout_get_data(dbus_timeout);
+ assert(timeout);
+
+ poll_api->timeout_free(timeout->avahi_timeout);
+ avahi_free(timeout);
+ dbus_timeout_set_data(dbus_timeout, NULL, NULL);
+}
+
+static void timeout_toggled(DBusTimeout *dbus_timeout, void *userdata) {
+ TimeoutData *timeout;
+ const AvahiPoll *poll_api = (const AvahiPoll*) userdata;
+
+ assert(dbus_timeout);
+ assert(poll_api);
+
+ timeout = dbus_timeout_get_data(dbus_timeout);
+ assert(timeout);
+
+ update_timeout(timeout);
+}
+
+int avahi_dbus_connection_glue(DBusConnection *c, const AvahiPoll *poll_api) {
+ assert(c);
+ assert(poll_api);
+
+ if (!(dbus_connection_set_watch_functions(c, add_watch, remove_watch, watch_toggled, (void*) poll_api, NULL)))
+ return -1;
+
+ if (!(dbus_connection_set_timeout_functions(c, add_timeout, remove_timeout, timeout_toggled, (void*) poll_api, NULL)))
+ return -1;
+
+ return 0;
+}
--- /dev/null
+#ifndef foodbuswatchgluehfoo
+#define foodbuswatchgluehfoo
+
+/* $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.
+***/
+
+#include <dbus/dbus.h>
+
+#include <avahi-common/watch.h>
+
+int avahi_dbus_connection_glue(DBusConnection *c, const AvahiPoll *poll_api);
+
+#endif
void *avahi_realloc(void *p, size_t size);
/** Allocate n new structures of the specified type. */
-#define avahi_new(type, n) (type*) avahi_malloc(n*sizeof(type))
+#define avahi_new(type, n) ((type*) avahi_malloc((n)*sizeof(type)))
/** Same as avahi_new() but set the memory to zero */
-#define avahi_new0(type, n) (type*) avahi_malloc0(n*sizeof(type))
+#define avahi_new0(type, n) ((type*) avahi_malloc0((n)*sizeof(type)))
/** Just like libc's strdup() */
char *avahi_strdup(const char *s);
static void watch_free(AvahiWatch *w) {
assert(w);
+
assert(!w->dead);
remove_pollfd(w);
AM_LDADD=-lexpat
-# GLIB 2.0
-AM_CFLAGS+=$(GLIB20_CFLAGS)
-AM_LDADD+=$(GLIB20_LIBS)
-
# libdaemon
AM_CFLAGS+=$(LIBDAEMON_CFLAGS)
AM_LDADD+=$(LIBDAEMON_LIBS)
if ENABLE_DBUS
-# DBUS
AM_CFLAGS+=$(DBUS_CFLAGS)
AM_LDADD+=$(DBUS_LIBS)
endif
sbin_PROGRAMS = \
avahi-daemon
+noinst_PROGRAMS = \
+ ini-file-parser-test
+
avahi_daemon_SOURCES = \
main.c main.h \
simple-protocol.c simple-protocol.h \
- static-services.c static-services.h
+ static-services.c static-services.h \
+ ini-file-parser.c ini-file-parser.h
+
+avahi_daemon_CFLAGS = $(AM_CFLAGS)
+avahi_daemon_LDADD = $(AM_LDADD) ../avahi-common/libavahi-common.la ../avahi-core/libavahi-core.la
+
+ini_file_parser_test_SOURCES = \
+ ini-file-parser.c ini-file-parser.h \
+ ini-file-parser-test.c
+
+ini_file_parser_test_CFLAGS = $(AM_CFLAGS)
+ini_file_parser_test_LDADD = $(AM_LDADD) ../avahi-common/libavahi-common.la ../avahi-core/libavahi-core.la
pkgsysconf_DATA = \
avahi-daemon.conf
introspect.xsl
if ENABLE_DBUS
-avahi_daemon_SOURCES += dbus-protocol.c dbus-protocol.h
+avahi_daemon_SOURCES += \
+ dbus-protocol.c \
+ dbus-protocol.h
+
+avahi_daemon_LDADD += \
+ ../avahi-common/libdbus-watch-glue.a
dbusservice_DATA = avahi-dbus.conf
endif
-avahi_daemon_CFLAGS = $(AM_CFLAGS)
-avahi_daemon_LDADD = $(AM_LDADD) ../avahi-common/libavahi-common.la ../avahi-glib/libavahi-glib.la ../avahi-core/libavahi-core.la
+
xmllint:
xmllint --noout --valid example.service
#include <net/if.h>
#include <errno.h>
#include <unistd.h>
-#include <glib.h>
+#include <assert.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <signal.h>
#include <dbus/dbus.h>
-#include <dbus/dbus-glib-lowlevel.h>
#include <avahi-common/llist.h>
+#include <avahi-common/malloc.h>
+#include <avahi-common/dbus.h>
+#include <avahi-common/dbus-watch-glue.h>
#include <avahi-core/log.h>
#include <avahi-core/core.h>
-#include <avahi-common/dbus.h>
#include "dbus-protocol.h"
#include "main.h"
/* #define VALGRIND_WORKAROUND */
struct EntryGroupInfo {
- guint id;
+ unsigned id;
Client *client;
AvahiSEntryGroup *entry_group;
- gchar *path;
+ char *path;
- gint n_entries;
+ int n_entries;
AVAHI_LLIST_FIELDS(EntryGroupInfo, entry_groups);
};
};
struct DomainBrowserInfo {
- guint id;
+ unsigned id;
Client *client;
AvahiSDomainBrowser *domain_browser;
- gchar *path;
+ char *path;
AVAHI_LLIST_FIELDS(DomainBrowserInfo, domain_browsers);
};
struct ServiceTypeBrowserInfo {
- guint id;
+ unsigned id;
Client *client;
AvahiSServiceTypeBrowser *service_type_browser;
- gchar *path;
+ char *path;
AVAHI_LLIST_FIELDS(ServiceTypeBrowserInfo, service_type_browsers);
};
struct ServiceBrowserInfo {
- guint id;
+ unsigned id;
Client *client;
AvahiSServiceBrowser *service_browser;
- gchar *path;
+ char *path;
AVAHI_LLIST_FIELDS(ServiceBrowserInfo, service_browsers);
};
};
struct Client {
- guint id;
- gchar *name;
- guint current_id;
- gint n_objects;
+ unsigned id;
+ char *name;
+ unsigned current_id;
+ int n_objects;
AVAHI_LLIST_FIELDS(Client, clients);
AVAHI_LLIST_HEAD(EntryGroupInfo, entry_groups);
struct Server {
DBusConnection *bus;
AVAHI_LLIST_HEAD(Client, clients);
- gint n_clients;
- guint current_id;
+ int n_clients;
+ unsigned current_id;
};
static Server *server = NULL;
static void entry_group_free(EntryGroupInfo *i) {
- g_assert(i);
+ assert(i);
if (i->entry_group)
avahi_s_entry_group_free(i->entry_group);
dbus_connection_unregister_object_path(server->bus, i->path);
- g_free(i->path);
+ avahi_free(i->path);
AVAHI_LLIST_REMOVE(EntryGroupInfo, entry_groups, i->client->entry_groups, i);
i->client->n_objects--;
- g_assert(i->client->n_objects >= 0);
+ assert(i->client->n_objects >= 0);
- g_free(i);
+ avahi_free(i);
}
static void host_name_resolver_free(HostNameResolverInfo *i) {
- g_assert(i);
+ assert(i);
if (i->host_name_resolver)
avahi_s_host_name_resolver_free(i->host_name_resolver);
AVAHI_LLIST_REMOVE(HostNameResolverInfo, host_name_resolvers, i->client->host_name_resolvers, i);
i->client->n_objects--;
- g_assert(i->client->n_objects >= 0);
+ assert(i->client->n_objects >= 0);
- g_free(i);
+ avahi_free(i);
}
static void address_resolver_free(AddressResolverInfo *i) {
- g_assert(i);
+ assert(i);
if (i->address_resolver)
avahi_s_address_resolver_free(i->address_resolver);
AVAHI_LLIST_REMOVE(AddressResolverInfo, address_resolvers, i->client->address_resolvers, i);
i->client->n_objects--;
- g_assert(i->client->n_objects >= 0);
+ assert(i->client->n_objects >= 0);
- g_free(i);
+ avahi_free(i);
}
static void domain_browser_free(DomainBrowserInfo *i) {
- g_assert(i);
+ assert(i);
if (i->domain_browser)
avahi_s_domain_browser_free(i->domain_browser);
dbus_connection_unregister_object_path(server->bus, i->path);
- g_free(i->path);
+ avahi_free(i->path);
AVAHI_LLIST_REMOVE(DomainBrowserInfo, domain_browsers, i->client->domain_browsers, i);
i->client->n_objects--;
- g_assert(i->client->n_objects >= 0);
+ assert(i->client->n_objects >= 0);
- g_free(i);
+ avahi_free(i);
}
static void service_type_browser_free(ServiceTypeBrowserInfo *i) {
- g_assert(i);
+ assert(i);
if (i->service_type_browser)
avahi_s_service_type_browser_free(i->service_type_browser);
dbus_connection_unregister_object_path(server->bus, i->path);
- g_free(i->path);
+ avahi_free(i->path);
AVAHI_LLIST_REMOVE(ServiceTypeBrowserInfo, service_type_browsers, i->client->service_type_browsers, i);
i->client->n_objects--;
- g_assert(i->client->n_objects >= 0);
+ assert(i->client->n_objects >= 0);
- g_free(i);
+ avahi_free(i);
}
static void service_browser_free(ServiceBrowserInfo *i) {
- g_assert(i);
+ assert(i);
if (i->service_browser)
avahi_s_service_browser_free(i->service_browser);
dbus_connection_unregister_object_path(server->bus, i->path);
- g_free(i->path);
+ avahi_free(i->path);
AVAHI_LLIST_REMOVE(ServiceBrowserInfo, service_browsers, i->client->service_browsers, i);
i->client->n_objects--;
- g_assert(i->client->n_objects >= 0);
+ assert(i->client->n_objects >= 0);
- g_free(i);
+ avahi_free(i);
}
static void service_resolver_free(ServiceResolverInfo *i) {
- g_assert(i);
+ assert(i);
if (i->service_resolver)
avahi_s_service_resolver_free(i->service_resolver);
AVAHI_LLIST_REMOVE(ServiceResolverInfo, service_resolvers, i->client->service_resolvers, i);
i->client->n_objects--;
- g_assert(i->client->n_objects >= 0);
+ assert(i->client->n_objects >= 0);
- g_free(i);
+ avahi_free(i);
}
static void client_free(Client *c) {
- g_assert(server);
- g_assert(c);
+ assert(server);
+ assert(c);
while (c->entry_groups)
entry_group_free(c->entry_groups);
while (c->service_resolvers)
service_resolver_free(c->service_resolvers);
- g_assert(c->n_objects == 0);
+ assert(c->n_objects == 0);
- g_free(c->name);
+ avahi_free(c->name);
AVAHI_LLIST_REMOVE(Client, clients, server->clients, c);
- g_free(c);
+ avahi_free(c);
server->n_clients --;
- g_assert(server->n_clients >= 0);
+ assert(server->n_clients >= 0);
}
-static Client *client_get(const gchar *name, gboolean create) {
+static Client *client_get(const char *name, int create) {
Client *client;
- g_assert(server);
- g_assert(name);
+ assert(server);
+ assert(name);
for (client = server->clients; client; client = client->clients_next)
if (!strcmp(name, client->name))
return NULL;
/* If not existant yet, create a new entry */
- client = g_new(Client, 1);
+ client = avahi_new(Client, 1);
client->id = server->current_id++;
- client->name = g_strdup(name);
+ client->name = avahi_strdup(name);
client->current_id = 0;
client->n_objects = 0;
AVAHI_LLIST_HEAD_INIT(EntryGroupInfo, client->entry_groups);
AVAHI_LLIST_PREPEND(Client, clients, server->clients, client);
server->n_clients++;
- g_assert(server->n_clients > 0);
+ assert(server->n_clients > 0);
return client;
}
-static DBusHandlerResult respond_error(DBusConnection *c, DBusMessage *m, gint error, const gchar *text) {
+static DBusHandlerResult respond_error(DBusConnection *c, DBusMessage *m, int error, const char *text) {
DBusMessage *reply;
- const gchar * const table[- AVAHI_ERR_MAX] = {
+ const char * const table[- AVAHI_ERR_MAX] = {
NULL, /* OK */
AVAHI_DBUS_ERR_FAILURE,
AVAHI_DBUS_ERR_BAD_STATE,
AVAHI_DBUS_ERR_INVALID_OBJECT
};
- g_assert(-error > -AVAHI_OK);
- g_assert(-error < -AVAHI_ERR_MAX);
+ assert(-error > -AVAHI_OK);
+ assert(-error < -AVAHI_ERR_MAX);
reply = dbus_message_new_error(m, table[-error], text ? text : avahi_strerror(error));
dbus_connection_send(c, reply, NULL);
return DBUS_HANDLER_RESULT_HANDLED;
}
-static DBusHandlerResult respond_string(DBusConnection *c, DBusMessage *m, const gchar *text) {
+static DBusHandlerResult respond_string(DBusConnection *c, DBusMessage *m, const char *text) {
DBusMessage *reply;
reply = dbus_message_new_method_return(m);
return DBUS_HANDLER_RESULT_HANDLED;
}
-static DBusHandlerResult respond_int32(DBusConnection *c, DBusMessage *m, gint32 i) {
+static DBusHandlerResult respond_int32(DBusConnection *c, DBusMessage *m, int32_t i) {
DBusMessage *reply;
reply = dbus_message_new_method_return(m);
return DBUS_HANDLER_RESULT_HANDLED;
}
-static DBusHandlerResult respond_path(DBusConnection *c, DBusMessage *m, const gchar *path) {
+static DBusHandlerResult respond_path(DBusConnection *c, DBusMessage *m, const char *path) {
DBusMessage *reply;
reply = dbus_message_new_method_return(m);
return DBUS_HANDLER_RESULT_HANDLED;
}
-static DBusHandlerResult handle_introspect(DBusConnection *c, DBusMessage *m, const gchar *fname) {
- gchar *path = NULL;
- gchar *contents;
- GError *gerror = NULL;
+static char *file_get_contents(char *fname) {
+ int fd = -1;
+ struct stat st;
+ ssize_t size;
+ char *buf = NULL;
+
+ assert(fname);
+
+ if (!(fd = open(fname, O_RDONLY))) {
+ avahi_log_error("Failed to open %s: %s", fname, strerror(errno));
+ goto fail;
+ }
+
+ if (fstat(fd, &st) < 0) {
+ avahi_log_error("stat(%s) failed: %s", fname, strerror(errno));
+ goto fail;
+ }
+
+ if (!(S_ISREG(st.st_mode))) {
+ avahi_log_error("Invalid file %s", fname);
+ goto fail;
+ }
+
+ if (st.st_size > 1024*1024) { /** 1MB */
+ avahi_log_error("File too large %s", fname);
+ goto fail;
+ }
+
+ buf = avahi_new(char, st.st_size+1);
+
+ if ((size = read(fd, buf, st.st_size)) < 0) {
+ avahi_log_error("read() failed: %s\n", strerror(errno));
+ goto fail;
+ }
+
+ buf[size] = 0;
+
+ close(fd);
+ return buf;
+
+fail:
+ if (fd >= 0)
+ close(fd);
+
+ if (buf)
+ avahi_free(buf);
+
+ return NULL;
+
+}
+
+static DBusHandlerResult handle_introspect(DBusConnection *c, DBusMessage *m, const char *fname) {
+ char *path, *contents;
DBusError error;
- g_assert(c);
- g_assert(m);
- g_assert(fname);
+ assert(c);
+ assert(m);
+ assert(fname);
dbus_error_init(&error);
if (!dbus_message_get_args(m, &error, DBUS_TYPE_INVALID)) {
- avahi_log_warn("Error parsing Introspect message: %s", error.message);
+ avahi_log_error("Error parsing Introspect message: %s", error.message);
goto fail;
}
- path = g_strdup_printf("%s/%s", AVAHI_DBUS_INTROSPECTION_DIR, fname);
-
- if (!(g_file_get_contents(path, &contents, NULL, &gerror))) {
- avahi_log_warn("Failed to load introspection data: %s", gerror->message);
- g_error_free(gerror);
- g_free(path);
+ path = avahi_strdup_printf("%s/%s", AVAHI_DBUS_INTROSPECTION_DIR, fname);
+ contents = file_get_contents(path);
+ avahi_free(path);
+
+ if (!contents) {
+ avahi_log_error("Failed to load introspection data.");
goto fail;
}
-
- g_free(path);
respond_string(c, m, contents);
- g_free(contents);
+ avahi_free(contents);
return DBUS_HANDLER_RESULT_HANDLED;
}
static DBusHandlerResult msg_signal_filter_impl(DBusConnection *c, DBusMessage *m, void *userdata) {
- GMainLoop *loop = userdata;
DBusError error;
dbus_error_init(&error);
/* No, we shouldn't quit, but until we get somewhere
* usefull such that we can restore our state, we will */
avahi_log_warn("Disconnnected from d-bus, terminating...");
- g_main_loop_quit (loop);
+
+ raise(SIGQUIT); /* The signal handler will catch this and terminate the process cleanly*/
+
return DBUS_HANDLER_RESULT_HANDLED;
} else if (dbus_message_is_signal(m, DBUS_INTERFACE_DBUS, "NameAcquired")) {
- gchar *name;
+ char *name;
if (!dbus_message_get_args(m, &error, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID)) {
avahi_log_warn("Error parsing NameAcquired message");
return DBUS_HANDLER_RESULT_HANDLED;
} else if (dbus_message_is_signal(m, DBUS_INTERFACE_DBUS, "NameOwnerChanged")) {
- gchar *name, *old, *new;
+ char *name, *old, *new;
if (!dbus_message_get_args(m, &error, DBUS_TYPE_STRING, &name, DBUS_TYPE_STRING, &old, DBUS_TYPE_STRING, &new, DBUS_TYPE_INVALID)) {
avahi_log_warn("Error parsing NameOwnerChanged message");
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
-static void entry_group_callback(AvahiServer *s, AvahiSEntryGroup *g, AvahiEntryGroupState state, gpointer userdata) {
+static void entry_group_callback(AvahiServer *s, AvahiSEntryGroup *g, AvahiEntryGroupState state, void* userdata) {
EntryGroupInfo *i = userdata;
DBusMessage *m;
- gint32 t;
+ int32_t t;
- g_assert(s);
- g_assert(g);
- g_assert(i);
+ assert(s);
+ assert(g);
+ assert(i);
m = dbus_message_new_signal(i->path, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "StateChanged");
- t = (gint32) state;
+ t = (int32_t) state;
dbus_message_append_args(m, DBUS_TYPE_INT32, &t, DBUS_TYPE_INVALID);
dbus_message_set_destination(m, i->client->name);
dbus_connection_send(server->bus, m, NULL);
DBusError error;
EntryGroupInfo *i = userdata;
- g_assert(c);
- g_assert(m);
- g_assert(i);
+ assert(c);
+ assert(m);
+ assert(i);
dbus_error_init(&error);
} else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "IsEmpty")) {
DBusMessage *reply;
- gboolean b;
+ int b;
if (!dbus_message_get_args(m, &error, DBUS_TYPE_INVALID)) {
avahi_log_warn("Error parsing EntryGroup::IsEmpty message");
}
state = avahi_s_entry_group_get_state(i->entry_group);
- return respond_int32(c, m, (gint32) state);
+ return respond_int32(c, m, (int32_t) state);
} else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "AddService")) {
- gint32 interface, protocol;
- gchar *type, *name, *domain, *host;
- guint16 port;
+ int32_t interface, protocol;
+ char *type, *name, *domain, *host;
+ uint16_t port;
AvahiStringList *strlst;
DBusMessageIter iter, sub;
int j;
for (;;) {
DBusMessageIter sub2;
int at, n;
- guint8 *k;
+ uint8_t *k;
if ((at = dbus_message_iter_get_arg_type(&sub)) == DBUS_TYPE_INVALID)
break;
- g_assert(at == DBUS_TYPE_ARRAY);
+ assert(at == DBUS_TYPE_ARRAY);
if (dbus_message_iter_get_element_type(&sub) != DBUS_TYPE_BYTE) {
avahi_log_warn("Error parsing EntryGroup::AddService message");
return respond_ok(c, m);
} else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_ENTRY_GROUP, "AddAddress")) {
- gint32 interface, protocol;
- gchar *name, *address;
+ int32_t interface, protocol;
+ char *name, *address;
AvahiAddress a;
if (!dbus_message_get_args(
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
-static void host_name_resolver_callback(AvahiSHostNameResolver *r, AvahiIfIndex interface, AvahiProtocol protocol, AvahiResolverEvent event, const gchar *host_name, const AvahiAddress *a, gpointer userdata) {
+static void host_name_resolver_callback(AvahiSHostNameResolver *r, AvahiIfIndex interface, AvahiProtocol protocol, AvahiResolverEvent event, const char *host_name, const AvahiAddress *a, void* userdata) {
HostNameResolverInfo *i = userdata;
- g_assert(r);
- g_assert(host_name);
- g_assert(i);
+ assert(r);
+ assert(host_name);
+ assert(i);
if (event == AVAHI_RESOLVER_FOUND) {
char t[256], *pt = t;
- gint32 i_interface, i_protocol, i_aprotocol;
+ int32_t i_interface, i_protocol, i_aprotocol;
DBusMessage *reply;
- g_assert(a);
+ assert(a);
avahi_address_snprint(t, sizeof(t), a);
- i_interface = (gint32) interface;
- i_protocol = (gint32) protocol;
- i_aprotocol = (gint32) a->family;
+ i_interface = (int32_t) interface;
+ i_protocol = (int32_t) protocol;
+ i_aprotocol = (int32_t) a->family;
reply = dbus_message_new_method_return(i->message);
dbus_message_append_args(
dbus_connection_send(server->bus, reply, NULL);
dbus_message_unref(reply);
} else {
- g_assert(event == AVAHI_RESOLVER_TIMEOUT);
+ assert(event == AVAHI_RESOLVER_TIMEOUT);
respond_error(server->bus, i->message, AVAHI_ERR_TIMEOUT, NULL);
}
host_name_resolver_free(i);
}
-static void address_resolver_callback(AvahiSAddressResolver *r, AvahiIfIndex interface, AvahiProtocol protocol, AvahiResolverEvent event, const AvahiAddress *address, const gchar *host_name, gpointer userdata) {
+static void address_resolver_callback(AvahiSAddressResolver *r, AvahiIfIndex interface, AvahiProtocol protocol, AvahiResolverEvent event, const AvahiAddress *address, const char *host_name, void* userdata) {
AddressResolverInfo *i = userdata;
- g_assert(r);
- g_assert(address);
- g_assert(i);
+ assert(r);
+ assert(address);
+ assert(i);
if (event == AVAHI_RESOLVER_FOUND) {
char t[256], *pt = t;
- gint32 i_interface, i_protocol, i_aprotocol;
+ int32_t i_interface, i_protocol, i_aprotocol;
DBusMessage *reply;
- g_assert(host_name);
+ assert(host_name);
avahi_address_snprint(t, sizeof(t), address);
- i_interface = (gint32) interface;
- i_protocol = (gint32) protocol;
- i_aprotocol = (gint32) address->family;
+ i_interface = (int32_t) interface;
+ i_protocol = (int32_t) protocol;
+ i_aprotocol = (int32_t) address->family;
reply = dbus_message_new_method_return(i->message);
dbus_message_append_args(
dbus_connection_send(server->bus, reply, NULL);
dbus_message_unref(reply);
} else {
- g_assert(event == AVAHI_RESOLVER_TIMEOUT);
+ assert(event == AVAHI_RESOLVER_TIMEOUT);
respond_error(server->bus, i->message, AVAHI_ERR_TIMEOUT, NULL);
}
DBusError error;
DomainBrowserInfo *i = userdata;
- g_assert(c);
- g_assert(m);
- g_assert(i);
+ assert(c);
+ assert(m);
+ assert(i);
dbus_error_init(&error);
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
-static void domain_browser_callback(AvahiSDomainBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, const gchar *domain, gpointer userdata) {
+static void domain_browser_callback(AvahiSDomainBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, const char *domain, void* userdata) {
DomainBrowserInfo *i = userdata;
DBusMessage *m;
- gint32 i_interface, i_protocol;
+ int32_t i_interface, i_protocol;
- g_assert(b);
- g_assert(domain);
- g_assert(i);
+ assert(b);
+ assert(domain);
+ assert(i);
- i_interface = (gint32) interface;
- i_protocol = (gint32) protocol;
+ i_interface = (int32_t) interface;
+ i_protocol = (int32_t) protocol;
m = dbus_message_new_signal(i->path, AVAHI_DBUS_INTERFACE_DOMAIN_BROWSER, event == AVAHI_BROWSER_NEW ? "ItemNew" : "ItemRemove");
dbus_message_append_args(
DBusError error;
ServiceTypeBrowserInfo *i = userdata;
- g_assert(c);
- g_assert(m);
- g_assert(i);
+ assert(c);
+ assert(m);
+ assert(i);
dbus_error_init(&error);
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
-static void service_type_browser_callback(AvahiSServiceTypeBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, const gchar *type, const gchar *domain, gpointer userdata) {
+static void service_type_browser_callback(AvahiSServiceTypeBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, const char *type, const char *domain, void* userdata) {
ServiceTypeBrowserInfo *i = userdata;
DBusMessage *m;
- gint32 i_interface, i_protocol;
+ int32_t i_interface, i_protocol;
- g_assert(b);
- g_assert(type);
- g_assert(domain);
- g_assert(i);
+ assert(b);
+ assert(type);
+ assert(domain);
+ assert(i);
- i_interface = (gint32) interface;
- i_protocol = (gint32) protocol;
+ i_interface = (int32_t) interface;
+ i_protocol = (int32_t) protocol;
m = dbus_message_new_signal(i->path, AVAHI_DBUS_INTERFACE_SERVICE_TYPE_BROWSER, event == AVAHI_BROWSER_NEW ? "ItemNew" : "ItemRemove");
dbus_message_append_args(
DBusError error;
ServiceBrowserInfo *i = userdata;
- g_assert(c);
- g_assert(m);
- g_assert(i);
+ assert(c);
+ assert(m);
+ assert(i);
dbus_error_init(&error);
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
-static void service_browser_callback(AvahiSServiceBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, const gchar *name, const gchar *type, const gchar *domain, gpointer userdata) {
+static void service_browser_callback(AvahiSServiceBrowser *b, AvahiIfIndex interface, AvahiProtocol protocol, AvahiBrowserEvent event, const char *name, const char *type, const char *domain, void* userdata) {
ServiceBrowserInfo *i = userdata;
DBusMessage *m;
- gint32 i_interface, i_protocol;
+ int32_t i_interface, i_protocol;
- g_assert(b);
- g_assert(name);
- g_assert(type);
- g_assert(domain);
- g_assert(i);
+ assert(b);
+ assert(name);
+ assert(type);
+ assert(domain);
+ assert(i);
- i_interface = (gint32) interface;
- i_protocol = (gint32) protocol;
+ i_interface = (int32_t) interface;
+ i_protocol = (int32_t) protocol;
m = dbus_message_new_signal(i->path, AVAHI_DBUS_INTERFACE_SERVICE_BROWSER, event == AVAHI_BROWSER_NEW ? "ItemNew" : "ItemRemove");
dbus_message_append_args(
AvahiIfIndex interface,
AvahiProtocol protocol,
AvahiResolverEvent event,
- const gchar *name,
- const gchar *type,
- const gchar *domain,
- const gchar *host_name,
+ const char *name,
+ const char *type,
+ const char *domain,
+ const char *host_name,
const AvahiAddress *a,
- guint16 port,
+ uint16_t port,
AvahiStringList *txt,
- gpointer userdata) {
+ void* userdata) {
ServiceResolverInfo *i = userdata;
- g_assert(r);
- g_assert(i);
+ assert(r);
+ assert(i);
if (event == AVAHI_RESOLVER_FOUND) {
char t[256], *pt = t;
- gint32 i_interface, i_protocol, i_aprotocol;
- guint n, j;
+ int32_t i_interface, i_protocol, i_aprotocol;
+ unsigned n, j;
AvahiStringList *p;
DBusMessage *reply;
DBusMessageIter iter, sub;
- g_assert(host_name);
+ assert(host_name);
- g_assert(a);
+ assert(a);
avahi_address_snprint(t, sizeof(t), a);
- i_interface = (gint32) interface;
- i_protocol = (gint32) protocol;
- i_aprotocol = (gint32) a->family;
+ i_interface = (int32_t) interface;
+ i_protocol = (int32_t) protocol;
+ i_aprotocol = (int32_t) a->family;
reply = dbus_message_new_method_return(i->message);
dbus_message_append_args(
for (p = txt, j = n-1; p; p = p->next, j--) {
DBusMessageIter sub2;
- const guint8 *data = p->text;
+ const uint8_t *data = p->text;
dbus_message_iter_open_container(&sub, DBUS_TYPE_ARRAY, "y", &sub2);
dbus_message_iter_append_fixed_array(&sub2, DBUS_TYPE_BYTE, &data, p->size);
dbus_connection_send(server->bus, reply, NULL);
dbus_message_unref(reply);
} else {
- g_assert(event == AVAHI_RESOLVER_TIMEOUT);
+ assert(event == AVAHI_RESOLVER_TIMEOUT);
respond_error(server->bus, i->message, AVAHI_ERR_TIMEOUT, NULL);
}
}
state = avahi_server_get_state(avahi_server);
- return respond_int32(c, m, (gint32) state);
+ return respond_int32(c, m, (int32_t) state);
} else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "GetNetworkInterfaceNameByIndex")) {
- gint32 idx;
+ int32_t idx;
int fd;
struct ifreq ifr;
#else
if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
- gchar txt[256];
- g_snprintf(txt, sizeof(txt), "OS Error: %s", strerror(errno));
+ char txt[256];
+ snprintf(txt, sizeof(txt), "OS Error: %s", strerror(errno));
return respond_error(c, m, AVAHI_ERR_OS, txt);
}
ifr.ifr_ifindex = idx;
if (ioctl(fd, SIOCGIFNAME, &ifr) < 0) {
- gchar txt[256];
- g_snprintf(txt, sizeof(txt), "OS Error: %s", strerror(errno));
+ char txt[256];
+ snprintf(txt, sizeof(txt), "OS Error: %s", strerror(errno));
close(fd);
return respond_error(c, m, AVAHI_ERR_OS, txt);
}
#endif
} else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "GetNetworkInterfaceIndexByName")) {
- gchar *n;
+ char *n;
int fd;
struct ifreq ifr;
return respond_int32(c, m, 1);
#else
if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
- gchar txt[256];
- g_snprintf(txt, sizeof(txt), "OS Error: %s", strerror(errno));
+ char txt[256];
+ snprintf(txt, sizeof(txt), "OS Error: %s", strerror(errno));
return respond_error(c, m, AVAHI_ERR_OS, txt);
}
memset(&ifr, 0, sizeof(ifr));
- g_snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%s", n);
+ snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%s", n);
if (ioctl(fd, SIOCGIFINDEX, &ifr) < 0) {
- gchar txt[256];
- g_snprintf(txt, sizeof(txt), "OS Error: %s", strerror(errno));
+ char txt[256];
+ snprintf(txt, sizeof(txt), "OS Error: %s", strerror(errno));
close(fd);
return respond_error(c, m, AVAHI_ERR_OS, txt);
}
#endif
} else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "GetAlternativeHostName")) {
- gchar *n, * t;
+ char *n, * t;
if (!(dbus_message_get_args(m, &error, DBUS_TYPE_STRING, &n, DBUS_TYPE_INVALID)) || !n) {
avahi_log_warn("Error parsing Server::GetAlternativeHostName message");
t = avahi_alternative_host_name(n);
respond_string(c, m, t);
- g_free(t);
+ avahi_free(t);
return DBUS_HANDLER_RESULT_HANDLED;
} else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "GetAlternativeServiceName")) {
- gchar *n, *t;
+ char *n, *t;
if (!(dbus_message_get_args(m, &error, DBUS_TYPE_STRING, &n, DBUS_TYPE_INVALID)) || !n) {
avahi_log_warn("Error parsing Server::GetAlternativeServiceName message");
t = avahi_alternative_service_name(n);
respond_string(c, m, t);
- g_free(t);
+ avahi_free(t);
return DBUS_HANDLER_RESULT_HANDLED;
return respond_error(c, m, AVAHI_ERR_TOO_MANY_OBJECTS, NULL);
}
- i = g_new(EntryGroupInfo, 1);
+ i = avahi_new(EntryGroupInfo, 1);
i->id = ++client->current_id;
i->client = client;
- i->path = g_strdup_printf("/Client%u/EntryGroup%u", client->id, i->id);
+ i->path = avahi_strdup_printf("/Client%u/EntryGroup%u", client->id, i->id);
i->n_entries = 0;
AVAHI_LLIST_PREPEND(EntryGroupInfo, entry_groups, client->entry_groups, i);
client->n_objects++;
} else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "ResolveHostName")) {
Client *client;
- gint32 interface, protocol, aprotocol;
- gchar *name;
+ int32_t interface, protocol, aprotocol;
+ char *name;
HostNameResolverInfo *i;
if (!dbus_message_get_args(
return respond_error(c, m, AVAHI_ERR_TOO_MANY_OBJECTS, NULL);
}
- i = g_new(HostNameResolverInfo, 1);
+ i = avahi_new(HostNameResolverInfo, 1);
i->client = client;
i->message = dbus_message_ref(m);
AVAHI_LLIST_PREPEND(HostNameResolverInfo, host_name_resolvers, client->host_name_resolvers, i);
} else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "ResolveAddress")) {
Client *client;
- gint32 interface, protocol;
- gchar *address;
+ int32_t interface, protocol;
+ char *address;
AddressResolverInfo *i;
AvahiAddress a;
return respond_error(c, m, AVAHI_ERR_TOO_MANY_OBJECTS, NULL);
}
- i = g_new(AddressResolverInfo, 1);
+ i = avahi_new(AddressResolverInfo, 1);
i->client = client;
i->message = dbus_message_ref(m);
AVAHI_LLIST_PREPEND(AddressResolverInfo, address_resolvers, client->address_resolvers, i);
NULL,
NULL
};
- gint32 interface, protocol, type;
- gchar *domain;
+ int32_t interface, protocol, type;
+ char *domain;
if (!dbus_message_get_args(
if (!*domain)
domain = NULL;
- i = g_new(DomainBrowserInfo, 1);
+ i = avahi_new(DomainBrowserInfo, 1);
i->id = ++client->current_id;
i->client = client;
- i->path = g_strdup_printf("/Client%u/DomainBrowser%u", client->id, i->id);
+ i->path = avahi_strdup_printf("/Client%u/DomainBrowser%u", client->id, i->id);
AVAHI_LLIST_PREPEND(DomainBrowserInfo, domain_browsers, client->domain_browsers, i);
client->n_objects++;
NULL,
NULL
};
- gint32 interface, protocol;
- gchar *domain;
+ int32_t interface, protocol;
+ char *domain;
if (!dbus_message_get_args(
m, &error,
if (!*domain)
domain = NULL;
- i = g_new(ServiceTypeBrowserInfo, 1);
+ i = avahi_new(ServiceTypeBrowserInfo, 1);
i->id = ++client->current_id;
i->client = client;
- i->path = g_strdup_printf("/Client%u/ServiceTypeBrowser%u", client->id, i->id);
+ i->path = avahi_strdup_printf("/Client%u/ServiceTypeBrowser%u", client->id, i->id);
AVAHI_LLIST_PREPEND(ServiceTypeBrowserInfo, service_type_browsers, client->service_type_browsers, i);
client->n_objects++;
NULL,
NULL
};
- gint32 interface, protocol;
- gchar *domain, *type;
+ int32_t interface, protocol;
+ char *domain, *type;
if (!dbus_message_get_args(
m, &error,
if (!*domain)
domain = NULL;
- i = g_new(ServiceBrowserInfo, 1);
+ i = avahi_new(ServiceBrowserInfo, 1);
i->id = ++client->current_id;
i->client = client;
- i->path = g_strdup_printf("/Client%u/ServiceBrowser%u", client->id, i->id);
+ i->path = avahi_strdup_printf("/Client%u/ServiceBrowser%u", client->id, i->id);
AVAHI_LLIST_PREPEND(ServiceBrowserInfo, service_browsers, client->service_browsers, i);
client->n_objects++;
} else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "ResolveService")) {
Client *client;
- gint32 interface, protocol, aprotocol;
- gchar *name, *type, *domain;
+ int32_t interface, protocol, aprotocol;
+ char *name, *type, *domain;
ServiceResolverInfo *i;
if (!dbus_message_get_args(
if (!*domain)
domain = NULL;
- i = g_new(ServiceResolverInfo, 1);
+ i = avahi_new(ServiceResolverInfo, 1);
i->client = client;
i->message = dbus_message_ref(m);
AVAHI_LLIST_PREPEND(ServiceResolverInfo, service_resolvers, client->service_resolvers, i);
void dbus_protocol_server_state_changed(AvahiServerState state) {
DBusMessage *m;
- gint32 t;
+ int32_t t;
if (!server)
return;
m = dbus_message_new_signal(AVAHI_DBUS_PATH_SERVER, AVAHI_DBUS_INTERFACE_SERVER, "StateChanged");
- t = (gint32) state;
+ t = (int32_t) state;
dbus_message_append_args(m, DBUS_TYPE_INT32, &t, DBUS_TYPE_INVALID);
dbus_connection_send(server->bus, m, NULL);
dbus_message_unref(m);
}
-int dbus_protocol_setup(GMainLoop *loop) {
+int dbus_protocol_setup(const AvahiPoll *poll_api) {
DBusError error;
static const DBusObjectPathVTable server_vtable = {
NULL
};
+
dbus_error_init(&error);
- server = g_malloc(sizeof(Server));
- server->clients = NULL;
+ server = avahi_new(Server, 1);
+ AVAHI_LLIST_HEAD_INIT(Clients, server->clients);
server->current_id = 0;
server->n_clients = 0;
goto fail;
}
- dbus_connection_setup_with_g_main(server->bus, NULL);
- dbus_connection_set_exit_on_disconnect(server->bus, TRUE);
+ avahi_dbus_connection_glue(server->bus, poll_api);
dbus_bus_request_name(server->bus, AVAHI_DBUS_NAME, 0, &error);
if (dbus_error_is_set(&error)) {
dbus_bus_add_match(server->bus, "type='signal',""interface='" DBUS_INTERFACE_DBUS "'", &error);
- dbus_connection_add_filter(server->bus, msg_signal_filter_impl, loop, NULL);
+ dbus_connection_add_filter(server->bus, msg_signal_filter_impl, (void*) poll_api, NULL);
dbus_connection_register_object_path(server->bus, AVAHI_DBUS_PATH_SERVER, &server_vtable, NULL);
return 0;
}
dbus_error_free (&error);
- g_free(server);
+ avahi_free(server);
server = NULL;
return -1;
}
while (server->clients)
client_free(server->clients);
- g_assert(server->n_clients == 0);
+ assert(server->n_clients == 0);
if (server->bus) {
dbus_connection_disconnect(server->bus);
dbus_connection_unref(server->bus);
}
- g_free(server);
+ avahi_free(server);
server = NULL;
}
}
USA.
***/
-#include <glib.h>
-
-int dbus_protocol_setup(GMainLoop *loop);
+int dbus_protocol_setup(const AvahiPoll *poll_api);
void dbus_protocol_shutdown(void);
void dbus_protocol_server_state_changed(AvahiServerState state);
--- /dev/null
+/* $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.
+***/
+
+#include <stdio.h>
+
+#include <avahi-common/malloc.h>
+
+#include "ini-file-parser.h"
+
+int main(int argc, char *argv[]) {
+
+ AvahiIniFile *f;
+ AvahiIniFileGroup *g;
+
+ if (!(f = avahi_ini_file_load("avahi-daemon.conf"))) {
+ return 1;
+ }
+
+ printf("%u groups\n", f->n_groups);
+
+ for (g = f->groups; g; g = g->groups_next) {
+ AvahiIniFilePair *p;
+ printf("<%s> (%u pairs)\n", g->name, g->n_pairs);
+
+ for (p = g->pairs; p; p = p->pairs_next) {
+ char **split, **i;
+
+ printf("\t<%s> = ", p->key);
+ split = avahi_split_csv(p->value);
+
+ for (i = split; *i; i++)
+ printf("<%s> ", *i);
+
+ avahi_strfreev(split);
+
+ printf("\n");
+ }
+ }
+
+ avahi_ini_file_free(f);
+}
--- /dev/null
+/* $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.
+***/
+
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+
+#include <avahi-common/malloc.h>
+#include <avahi-core/log.h>
+
+#include "ini-file-parser.h"
+
+AvahiIniFile* avahi_ini_file_load(const char *fname) {
+ AvahiIniFile *f;
+ FILE *fo;
+ AvahiIniFileGroup *group = NULL;
+ unsigned line;
+
+ assert(fname);
+
+ if (!(fo = fopen(fname, "r"))) {
+ avahi_log_error("Failed to open file '%s': %s", fname, strerror(errno));
+ return NULL;
+ }
+
+ f = avahi_new(AvahiIniFile, 1);
+ AVAHI_LLIST_HEAD_INIT(AvahiIniFileGroup, f->groups);
+ f->n_groups = 0;
+
+ line = 0;
+ while (!feof(fo)) {
+ char ln[256], *s, *e;
+ AvahiIniFilePair *pair;
+
+ if (!(fgets(ln, sizeof(ln), fo)))
+ break;
+
+ line++;
+
+ s = ln + strspn(ln, " \t");
+ s[strcspn(s, "\r\n")] = 0;
+
+ /* Skip comments and empty lines */
+ if (*s == '#' || *s == '%' || *s == 0)
+ continue;
+
+ if (*s == '[') {
+ /* new group */
+
+ if (!(e = strchr(s, ']'))) {
+ avahi_log_error("Unclosed group header in %s:%u: <%s>", fname, line, s);
+ goto fail;
+ }
+
+ *e = 0;
+
+ group = avahi_new(AvahiIniFileGroup, 1);
+ group->name = avahi_strdup(s+1);
+ group->n_pairs = 0;
+ AVAHI_LLIST_HEAD_INIT(AvahiIniFilePair, group->pairs);
+
+ AVAHI_LLIST_PREPEND(AvahiIniFileGroup, groups, f->groups, group);
+ f->n_groups++;
+ } else {
+
+ /* Normal assignment */
+ if (!(e = strchr(s, '='))) {
+ avahi_log_error("Missing assignment in %s:%u: <%s>", fname, line, s);
+ goto fail;
+ }
+
+ if (!group) {
+ avahi_log_error("Assignment outside group in %s:%u <%s>", fname, line, s);
+ goto fail;
+ }
+
+ /* Split the key and the value */
+ *(e++) = 0;
+
+ pair = avahi_new(AvahiIniFilePair, 1);
+ pair->key = avahi_strdup(s);
+ pair->value = avahi_strdup(e);
+
+ AVAHI_LLIST_PREPEND(AvahiIniFilePair, pairs, group->pairs, pair);
+ group->n_pairs++;
+ }
+ }
+
+ fclose(fo);
+
+ return f;
+
+fail:
+
+ if (fo)
+ fclose(fo);
+
+ if (f)
+ avahi_ini_file_free(f);
+
+ return NULL;
+}
+
+void avahi_ini_file_free(AvahiIniFile *f) {
+ AvahiIniFileGroup *g;
+ assert(f);
+
+ while ((g = f->groups)) {
+ AvahiIniFilePair *p;
+
+ while ((p = g->pairs)) {
+ avahi_free(p->key);
+ avahi_free(p->value);
+
+ AVAHI_LLIST_REMOVE(AvahiIniFilePair, pairs, g->pairs, p);
+ avahi_free(p);
+ }
+
+ avahi_free(g->name);
+
+ AVAHI_LLIST_REMOVE(AvahiIniFileGroup, groups, f->groups, g);
+ avahi_free(g);
+ }
+
+ avahi_free(f);
+}
+
+char** avahi_split_csv(const char *t) {
+ unsigned n_comma = 0;
+ const char *p;
+ char **r, **i;
+
+ for (p = t; *p; p++)
+ if (*p == ',')
+ n_comma++;
+
+ i = r = avahi_new(char*, n_comma+2);
+
+ for (;;) {
+ size_t l = strcspn(t, ",");
+
+ *(i++) = avahi_strndup(t, l);
+
+ t += l;
+
+ if (*t == 0)
+ break;
+
+ assert(*t == ',');
+ t++;
+ }
+
+ *i = NULL;
+
+ return r;
+}
+
+void avahi_strfreev(char **p) {
+ char **i;
+
+ if (!p)
+ return;
+
+ for (i = p; *i; i++)
+ avahi_free(*i);
+
+ avahi_free(p);
+}
--- /dev/null
+#ifndef fooinifileparserhfoo
+#define fooinifileparserhfoo
+
+/* $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.
+***/
+
+#include <avahi-common/llist.h>
+
+typedef struct AvahiIniFile AvahiIniFile;
+typedef struct AvahiIniFilePair AvahiIniFilePair;
+typedef struct AvahiIniFileGroup AvahiIniFileGroup;
+
+struct AvahiIniFilePair {
+ AVAHI_LLIST_FIELDS(AvahiIniFilePair, pairs);
+ char *key, *value;
+};
+
+struct AvahiIniFileGroup {
+ AVAHI_LLIST_FIELDS(AvahiIniFileGroup, groups);
+ char *name;
+
+ AVAHI_LLIST_HEAD(AvahiIniFilePair, pairs);
+ unsigned n_pairs;
+};
+
+struct AvahiIniFile {
+ AVAHI_LLIST_HEAD(AvahiIniFileGroup, groups);
+ unsigned n_groups;
+};
+
+
+AvahiIniFile* avahi_ini_file_load(const char *fname);
+void avahi_ini_file_free(AvahiIniFile *f);
+
+char** avahi_split_csv(const char *t);
+
+void avahi_strfreev(char **);
+
+#endif
#include <config.h>
#endif
+#include <assert.h>
#include <getopt.h>
#include <string.h>
#include <signal.h>
#include <libdaemon/dlog.h>
#include <libdaemon/dpid.h>
+#include <avahi-common/malloc.h>
+#include <avahi-common/simple-watch.h>
#include <avahi-core/core.h>
#include <avahi-core/log.h>
-#include <avahi-glib/glib-malloc.h>
-#include <avahi-glib/glib-watch.h>
#include "main.h"
#include "simple-protocol.h"
#include "dbus-protocol.h"
#include "static-services.h"
+#include "ini-file-parser.h"
AvahiServer *avahi_server = NULL;
typedef struct {
AvahiServerConfig server_config;
DaemonCommand command;
- gboolean daemonize;
- gboolean use_syslog;
- gchar *config_file;
- gboolean enable_dbus;
- gboolean drop_root;
- gboolean publish_resolv_conf;
- gchar ** publish_dns_servers;
- gboolean no_rlimits;
- gboolean debug;
-
- gboolean rlimit_as_set, rlimit_core_set, rlimit_data_set, rlimit_fsize_set, rlimit_nofile_set, rlimit_stack_set;
+ int daemonize;
+ int use_syslog;
+ char *config_file;
+ int enable_dbus;
+ int drop_root;
+ int publish_resolv_conf;
+ char ** publish_dns_servers;
+ int no_rlimits;
+ int debug;
+
+ int rlimit_as_set, rlimit_core_set, rlimit_data_set, rlimit_fsize_set, rlimit_nofile_set, rlimit_stack_set;
rlim_t rlimit_as, rlimit_core, rlimit_data, rlimit_fsize, rlimit_nofile, rlimit_stack;
#ifdef RLIMIT_NPROC
- gboolean rlimit_nproc_set;
+ int rlimit_nproc_set;
rlim_t rlimit_nproc;
#endif
} DaemonConfig;
static AvahiSEntryGroup *dns_servers_entry_group = NULL;
static AvahiSEntryGroup *resolv_conf_entry_group = NULL;
-static gchar **resolv_conf = NULL;
+static char **resolv_conf = NULL;
static DaemonConfig config;
#define MAX_NAME_SERVERS 10
-static gint load_resolv_conf(const DaemonConfig *c) {
- gint ret = -1;
+static int has_prefix(const char *s, const char *prefix) {
+ size_t l;
+
+ l = strlen(prefix);
+
+ return strlen(s) >= l && strncmp(s, prefix, l) == 0;
+}
+
+static int load_resolv_conf(const DaemonConfig *c) {
+ int ret = -1;
FILE *f;
- gint i = 0;
+ int i = 0;
- g_strfreev(resolv_conf);
+ avahi_strfreev(resolv_conf);
resolv_conf = NULL;
if (!c->publish_resolv_conf)
goto finish;
}
- resolv_conf = g_new0(gchar*, MAX_NAME_SERVERS+1);
+ resolv_conf = avahi_new0(char*, MAX_NAME_SERVERS+1);
while (!feof(f) && i < MAX_NAME_SERVERS) {
char ln[128];
- gchar *p;
+ char *p;
if (!(fgets(ln, sizeof(ln), f)))
break;
ln[strcspn(ln, "\r\n#")] = 0;
p = ln + strspn(ln, "\t ");
- if (g_str_has_prefix(p, "nameserver")) {
+ if (has_prefix(p, "nameserver")) {
p += 10;
p += strspn(p, "\t ");
p[strcspn(p, "\t ")] = 0;
- resolv_conf[i++] = strdup(p);
+ resolv_conf[i++] = avahi_strdup(p);
}
}
finish:
if (ret != 0) {
- g_strfreev(resolv_conf);
+ avahi_strfreev(resolv_conf);
resolv_conf = NULL;
}
return ret;
}
-static AvahiSEntryGroup* add_dns_servers(AvahiServer *s, AvahiSEntryGroup* g, gchar **l) {
- gchar **p;
+static AvahiSEntryGroup* add_dns_servers(AvahiServer *s, AvahiSEntryGroup* g, char **l) {
+ char **p;
- g_assert(s);
- g_assert(l);
+ assert(s);
+ assert(l);
if (!g)
g = avahi_s_entry_group_new(s, NULL, NULL);
- g_assert(avahi_s_entry_group_is_empty(g));
+ assert(avahi_s_entry_group_is_empty(g));
for (p = l; *p; p++) {
AvahiAddress a;
static void server_callback(AvahiServer *s, AvahiServerState state, void *userdata) {
DaemonConfig *c = userdata;
- g_assert(s);
- g_assert(c);
+ assert(s);
+ assert(c);
/** This function is possibly called before the global variable
* avahi_server has been set, therefore we do it explicitly */
simple_protocol_restart_queries();
} else if (state == AVAHI_SERVER_COLLISION) {
- gchar *n;
+ char *n;
static_service_remove_from_server();
n = avahi_alternative_host_name(avahi_server_get_host_name(s));
avahi_log_warn("Host name conflict, retrying with <%s>", n);
avahi_server_set_host_name(s, n);
- g_free(n);
+ avahi_free(n);
}
}
-static void help(FILE *f, const gchar *argv0) {
+static void help(FILE *f, const char *argv0) {
fprintf(f,
"%s [options]\n"
" -h --help Show this help\n"
}
-static gint parse_command_line(DaemonConfig *c, int argc, char *argv[]) {
- gint o;
+static int parse_command_line(DaemonConfig *c, int argc, char *argv[]) {
+ int o;
enum {
OPTION_NO_RLIMITS = 256,
{ NULL, 0, NULL, 0 }
};
- g_assert(c);
+ assert(c);
opterr = 0;
while ((o = getopt_long(argc, argv, "hDkVf:rcs", long_options, NULL)) >= 0) {
switch(o) {
case 's':
- c->use_syslog = TRUE;
+ c->use_syslog = 1;
break;
case 'h':
c->command = DAEMON_HELP;
break;
case 'D':
- c->daemonize = TRUE;
+ c->daemonize = 1;
break;
case 'k':
c->command = DAEMON_KILL;
c->command = DAEMON_VERSION;
break;
case 'f':
- g_free(c->config_file);
- c->config_file = g_strdup(optarg);
+ avahi_free(c->config_file);
+ c->config_file = avahi_strdup(optarg);
break;
case 'r':
c->command = DAEMON_RELOAD;
c->command = DAEMON_CHECK;
break;
case OPTION_NO_RLIMITS:
- c->no_rlimits = TRUE;
+ c->no_rlimits = 1;
break;
case OPTION_NO_DROP_ROOT:
- c->drop_root = FALSE;
+ c->drop_root = 0;
break;
case OPTION_DEBUG:
- c->debug = TRUE;
+ c->debug = 1;
break;
default:
fprintf(stderr, "Invalid command line argument: %c\n", o);
return 0;
}
-static gboolean is_yes(const gchar *s) {
- g_assert(s);
+static int is_yes(const char *s) {
+ assert(s);
return *s == 'y' || *s == 'Y';
}
-static gint load_config_file(DaemonConfig *c) {
+static int load_config_file(DaemonConfig *c) {
int r = -1;
- GKeyFile *f = NULL;
- GError *err = NULL;
- gchar **groups = NULL, **g, **keys = NULL, *v = NULL;
+ AvahiIniFile *f;
+ AvahiIniFileGroup *g;
- g_assert(c);
-
- f = g_key_file_new();
- g_key_file_set_list_separator(f, ',');
-
- if (!g_key_file_load_from_file(f, c->config_file ? c->config_file : AVAHI_CONFIG_FILE, G_KEY_FILE_NONE, &err)) {
- fprintf(stderr, "Unable to read config file: %s\n", err->message);
- goto finish;
- }
-
- groups = g_key_file_get_groups(f, NULL);
-
- for (g = groups; *g; g++) {
- if (g_strcasecmp(*g, "server") == 0) {
- gchar **k;
-
- keys = g_key_file_get_keys(f, *g, NULL, NULL);
-
- for (k = keys; *k; k++) {
+ assert(c);
- v = g_key_file_get_value(f, *g, *k, NULL);
-
- if (g_strcasecmp(*k, "host-name") == 0) {
- g_free(c->server_config.host_name);
- c->server_config.host_name = v;
- v = NULL;
- } else if (g_strcasecmp(*k, "domain-name") == 0) {
- g_free(c->server_config.domain_name);
- c->server_config.domain_name = v;
- v = NULL;
- } else if (g_strcasecmp(*k, "use-ipv4") == 0)
- c->server_config.use_ipv4 = is_yes(v);
- else if (g_strcasecmp(*k, "use-ipv6") == 0)
- c->server_config.use_ipv6 = is_yes(v);
- else if (g_strcasecmp(*k, "check-response-ttl") == 0)
- c->server_config.check_response_ttl = is_yes(v);
- else if (g_strcasecmp(*k, "use-iff-running") == 0)
- c->server_config.use_iff_running = is_yes(v);
- else if (g_strcasecmp(*k, "enable-dbus") == 0)
- c->enable_dbus = is_yes(v);
- else if (g_strcasecmp(*k, "drop-root") == 0)
- c->drop_root = is_yes(v);
+ if (!(f = avahi_ini_file_load(c->config_file ? c->config_file : AVAHI_CONFIG_FILE)))
+ goto finish;
+
+ for (g = f->groups; g; g = g->groups_next) {
+
+ if (strcasecmp(g->name, "server") == 0) {
+ AvahiIniFilePair *p;
+
+ for (p = g->pairs; p; p = p->pairs_next) {
+
+ if (strcasecmp(p->key, "host-name") == 0) {
+ avahi_free(c->server_config.host_name);
+ c->server_config.host_name = avahi_strdup(p->value);
+ } else if (strcasecmp(p->key, "domain-name") == 0) {
+ avahi_free(c->server_config.domain_name);
+ c->server_config.domain_name = avahi_strdup(p->value);
+ } else if (strcasecmp(p->key, "use-ipv4") == 0)
+ c->server_config.use_ipv4 = is_yes(p->value);
+ else if (strcasecmp(p->key, "use-ipv6") == 0)
+ c->server_config.use_ipv6 = is_yes(p->value);
+ else if (strcasecmp(p->key, "check-response-ttl") == 0)
+ c->server_config.check_response_ttl = is_yes(p->value);
+ else if (strcasecmp(p->key, "use-iff-running") == 0)
+ c->server_config.use_iff_running = is_yes(p->value);
+ else if (strcasecmp(p->key, "enable-dbus") == 0)
+ c->enable_dbus = is_yes(p->value);
+ else if (strcasecmp(p->key, "drop-root") == 0)
+ c->drop_root = is_yes(p->value);
else {
- fprintf(stderr, "Invalid configuration key \"%s\" in group \"%s\"\n", *k, *g);
+ avahi_log_error("Invalid configuration key \"%s\" in group \"%s\"\n", p->key, g->name);
goto finish;
}
-
- g_free(v);
- v = NULL;
}
-
- g_strfreev(keys);
- keys = NULL;
-
- } else if (g_strcasecmp(*g, "publish") == 0) {
- gchar **k;
- keys = g_key_file_get_keys(f, *g, NULL, NULL);
+ } else if (strcasecmp(g->name, "publish") == 0) {
+ AvahiIniFilePair *p;
- for (k = keys; *k; k++) {
-
- v = g_key_file_get_string(f, *g, *k, NULL);
+ for (p = g->pairs; p; p = p->pairs_next) {
- if (g_strcasecmp(*k, "publish-addresses") == 0)
- c->server_config.publish_addresses = is_yes(v);
- else if (g_strcasecmp(*k, "publish-hinfo") == 0)
- c->server_config.publish_hinfo = is_yes(v);
- else if (g_strcasecmp(*k, "publish-workstation") == 0)
- c->server_config.publish_workstation = is_yes(v);
- else if (g_strcasecmp(*k, "publish-domain") == 0)
- c->server_config.publish_domain = is_yes(v);
- else if (g_strcasecmp(*k, "publish-resolv-conf-dns-servers") == 0)
- c->publish_resolv_conf = is_yes(v);
- else if (g_strcasecmp(*k, "publish-dns-servers") == 0) {
- g_strfreev(c->publish_dns_servers);
- c->publish_dns_servers = g_key_file_get_string_list(f, *g, *k, NULL, NULL);
+ if (strcasecmp(p->key, "publish-addresses") == 0)
+ c->server_config.publish_addresses = is_yes(p->value);
+ else if (strcasecmp(p->key, "publish-hinfo") == 0)
+ c->server_config.publish_hinfo = is_yes(p->value);
+ else if (strcasecmp(p->key, "publish-workstation") == 0)
+ c->server_config.publish_workstation = is_yes(p->value);
+ else if (strcasecmp(p->key, "publish-domain") == 0)
+ c->server_config.publish_domain = is_yes(p->value);
+ else if (strcasecmp(p->key, "publish-resolv-conf-dns-servers") == 0)
+ c->publish_resolv_conf = is_yes(p->value);
+ else if (strcasecmp(p->key, "publish-dns-servers") == 0) {
+ avahi_strfreev(c->publish_dns_servers);
+ c->publish_dns_servers = avahi_split_csv(p->value);
} else {
- fprintf(stderr, "Invalid configuration key \"%s\" in group \"%s\"\n", *k, *g);
+ avahi_log_error("Invalid configuration key \"%s\" in group \"%s\"\n", p->key, g->name);
goto finish;
}
-
- g_free(v);
- v = NULL;
}
- g_strfreev(keys);
- keys = NULL;
-
- } else if (g_strcasecmp(*g, "reflector") == 0) {
- gchar **k;
-
- keys = g_key_file_get_keys(f, *g, NULL, NULL);
-
- for (k = keys; *k; k++) {
+ } else if (strcasecmp(g->name, "reflector") == 0) {
+ AvahiIniFilePair *p;
- v = g_key_file_get_string(f, *g, *k, NULL);
+ for (p = g->pairs; p; p = p->pairs_next) {
- if (g_strcasecmp(*k, "enable-reflector") == 0)
- c->server_config.enable_reflector = is_yes(v);
- else if (g_strcasecmp(*k, "reflect-ipv") == 0)
- c->server_config.reflect_ipv = is_yes(v);
+ if (strcasecmp(p->key, "enable-reflector") == 0)
+ c->server_config.enable_reflector = is_yes(p->value);
+ else if (strcasecmp(p->key, "reflect-ipv") == 0)
+ c->server_config.reflect_ipv = is_yes(p->value);
else {
- fprintf(stderr, "Invalid configuration key \"%s\" in group \"%s\"\n", *k, *g);
+ avahi_log_error("Invalid configuration key \"%s\" in group \"%s\"\n", p->key, g->name);
goto finish;
}
-
- g_free(v);
- v = NULL;
}
-
- g_strfreev(keys);
- keys = NULL;
-
- } else if (g_strcasecmp(*g, "rlimits") == 0) {
- gchar **k;
- keys = g_key_file_get_keys(f, *g, NULL, NULL);
-
- for (k = keys; *k; k++) {
+ } else if (strcasecmp(g->name, "rlimits") == 0) {
+ AvahiIniFilePair *p;
- v = g_key_file_get_string(f, *g, *k, NULL);
+ for (p = g->pairs; p; p = p->pairs_next) {
- if (g_strcasecmp(*k, "rlimit-as") == 0) {
- c->rlimit_as_set = TRUE;
- c->rlimit_as = atoi(v);
- } else if (g_strcasecmp(*k, "rlimit-core") == 0) {
- c->rlimit_core_set = TRUE;
- c->rlimit_core = atoi(v);
- } else if (g_strcasecmp(*k, "rlimit-data") == 0) {
- c->rlimit_data_set = TRUE;
- c->rlimit_data = atoi(v);
- } else if (g_strcasecmp(*k, "rlimit-fsize") == 0) {
- c->rlimit_fsize_set = TRUE;
- c->rlimit_fsize = atoi(v);
- } else if (g_strcasecmp(*k, "rlimit-nofile") == 0) {
- c->rlimit_nofile_set = TRUE;
- c->rlimit_nofile = atoi(v);
- } else if (g_strcasecmp(*k, "rlimit-stack") == 0) {
- c->rlimit_stack_set = TRUE;
- c->rlimit_stack = atoi(v);
+ if (strcasecmp(p->key, "rlimit-as") == 0) {
+ c->rlimit_as_set = 1;
+ c->rlimit_as = atoi(p->value);
+ } else if (strcasecmp(p->key, "rlimit-core") == 0) {
+ c->rlimit_core_set = 1;
+ c->rlimit_core = atoi(p->value);
+ } else if (strcasecmp(p->key, "rlimit-data") == 0) {
+ c->rlimit_data_set = 1;
+ c->rlimit_data = atoi(p->value);
+ } else if (strcasecmp(p->key, "rlimit-fsize") == 0) {
+ c->rlimit_fsize_set = 1;
+ c->rlimit_fsize = atoi(p->value);
+ } else if (strcasecmp(p->key, "rlimit-nofile") == 0) {
+ c->rlimit_nofile_set = 1;
+ c->rlimit_nofile = atoi(p->value);
+ } else if (strcasecmp(p->key, "rlimit-stack") == 0) {
+ c->rlimit_stack_set = 1;
+ c->rlimit_stack = atoi(p->value);
#ifdef RLIMIT_NPROC
- } else if (g_strcasecmp(*k, "rlimit-nproc") == 0) {
- c->rlimit_nproc_set = TRUE;
- c->rlimit_nproc = atoi(v);
+ } else if (strcasecmp(p->key, "rlimit-nproc") == 0) {
+ c->rlimit_nproc_set = 1;
+ c->rlimit_nproc = atoi(p->value);
#endif
} else {
- fprintf(stderr, "Invalid configuration key \"%s\" in group \"%s\"\n", *k, *g);
+ avahi_log_error("Invalid configuration key \"%s\" in group \"%s\"\n", p->key, g->name);
goto finish;
}
- g_free(v);
- v = NULL;
}
-
- g_strfreev(keys);
- keys = NULL;
} else {
- fprintf(stderr, "Invalid configuration file group \"%s\".\n", *g);
+ avahi_log_error("Invalid configuration file group \"%s\".\n", g->name);
goto finish;
}
}
finish:
- g_strfreev(groups);
- g_strfreev(keys);
- g_free(v);
-
- if (err)
- g_error_free (err);
-
if (f)
- g_key_file_free(f);
+ avahi_ini_file_free(f);
return r;
}
-static void log_function(AvahiLogLevel level, const gchar *txt) {
+static void log_function(AvahiLogLevel level, const char *txt) {
static const int const log_level_map[] = {
LOG_ERR,
LOG_DEBUG
};
- g_assert(level < AVAHI_LOG_LEVEL_MAX);
- g_assert(txt);
+ assert(level < AVAHI_LOG_LEVEL_MAX);
+ assert(txt);
if (!config.debug && level == AVAHI_LOG_DEBUG)
return;
daemon_log(log_level_map[level], "%s", txt);
}
-static void dump(const gchar *text, gpointer userdata) {
+static void dump(const char *text, void* userdata) {
avahi_log_info("%s", text);
}
-static gboolean signal_callback(GIOChannel *source, GIOCondition condition, gpointer data) {
- gint sig;
- GMainLoop *loop = data;
+static void signal_callback(AvahiWatch *watch, int fd, AvahiWatchEvent event, void *userdata) {
+ int sig;
+ AvahiSimplePoll *simple_poll_api = userdata;
+ const AvahiPoll *poll_api;
- g_assert(source);
- g_assert(loop);
+ assert(watch);
+ assert(simple_poll_api);
+
+ poll_api = avahi_simple_poll_get(simple_poll_api);
if ((sig = daemon_signal_next()) <= 0) {
avahi_log_error("daemon_signal_next() failed");
- return FALSE;
+ poll_api->watch_free(watch);
+ return;
}
switch (sig) {
"Got %s, quitting.",
sig == SIGINT ? "SIGINT" :
(sig == SIGQUIT ? "SIGQUIT" : "SIGTERM"));
- g_main_loop_quit(loop);
+ avahi_simple_poll_quit(simple_poll_api);
break;
case SIGHUP:
avahi_log_warn("Got spurious signal, ignoring.");
break;
}
-
- return TRUE;
}
-static gint run_server(DaemonConfig *c) {
- GMainLoop *loop = NULL;
- gint r = -1;
- GIOChannel *io = NULL;
- guint watch_id = (guint) -1;
- gint error;
- AvahiGLibPoll *poll_api;
+static int run_server(DaemonConfig *c) {
+ int r = -1;
+ int error;
+ AvahiSimplePoll *simple_poll_api;
+ const AvahiPoll *poll_api;
+ AvahiWatch *sig_watch;
+
+ assert(c);
- g_assert(c);
+ if (!(simple_poll_api = avahi_simple_poll_new())) {
+ avahi_log_error("Failed to create main loop object.");
+ goto finish;
+ }
- poll_api = avahi_glib_poll_new(NULL, G_PRIORITY_DEFAULT);
- loop = g_main_loop_new(NULL, FALSE);
+ poll_api = avahi_simple_poll_get(simple_poll_api);
if (daemon_signal_init(SIGINT, SIGQUIT, SIGHUP, SIGTERM, SIGUSR1, 0) < 0) {
avahi_log_error("Could not register signal handlers (%s).", strerror(errno));
goto finish;
}
- if (!(io = g_io_channel_unix_new(daemon_signal_fd()))) {
- avahi_log_error( "Failed to create signal io channel.");
+ if (!(sig_watch = poll_api->watch_new(poll_api, daemon_signal_fd(), AVAHI_WATCH_IN, signal_callback, simple_poll_api))) {
+ avahi_log_error( "Failed to create signal watcher");
goto finish;
}
- g_io_channel_set_close_on_unref(io, FALSE);
- watch_id = g_io_add_watch(io, G_IO_IN, signal_callback, loop);
-
- if (simple_protocol_setup(NULL) < 0)
+ if (simple_protocol_setup(poll_api) < 0)
goto finish;
#ifdef ENABLE_DBUS
if (c->enable_dbus)
- if (dbus_protocol_setup(loop) < 0)
+ if (dbus_protocol_setup(poll_api) < 0)
goto finish;
#endif
load_resolv_conf(c);
static_service_load();
- if (!(avahi_server = avahi_server_new(avahi_glib_poll_get(poll_api), &c->server_config, server_callback, c, &error))) {
+ if (!(avahi_server = avahi_server_new(poll_api, &c->server_config, server_callback, c, &error))) {
avahi_log_error("Failed to create server: %s", avahi_strerror(error));
goto finish;
}
if (c->daemonize)
daemon_retval_send(0);
- r = 0;
+ for (;;) {
+ if ((r = avahi_simple_poll_iterate(simple_poll_api, -1)) < 0) {
- g_main_loop_run(loop);
+ /* We handle signals through an FD, so let's continue */
+ if (errno == EINTR)
+ continue;
+
+ avahi_log_error("poll(): %s", strerror(errno));
+ goto finish;
+ } else if (r > 0)
+ /* Quit */
+ break;
+ }
+
finish:
daemon_signal_done();
- if (watch_id != (guint) -1)
- g_source_remove(watch_id);
-
- if (io)
- g_io_channel_unref(io);
+ if (sig_watch)
+ poll_api->watch_free(sig_watch);
- if (poll_api)
- avahi_glib_poll_free(poll_api);
+ if (simple_poll_api)
+ avahi_simple_poll_free(simple_poll_api);
- if (loop)
- g_main_loop_unref(loop);
-
if (r != 0 && c->daemonize)
daemon_retval_send(1);
return r;
}
-static gint drop_root(void) {
+#define set_env(key, value) putenv(avahi_strdup_printf("%s=%s", (key), (value)))
+
+static int drop_root(void) {
struct passwd *pw;
struct group * gr;
- gint r;
+ int r;
if (!(pw = getpwnam(AVAHI_USER))) {
avahi_log_error( "Failed to find user '"AVAHI_USER"'.");
return -1;
}
- g_setenv("USER", pw->pw_name, 1);
- g_setenv("LOGNAME", pw->pw_name, 1);
- g_setenv("HOME", pw->pw_dir, 1);
+ set_env("USER", pw->pw_name);
+ set_env("LOGNAME", pw->pw_name);
+ set_env("HOME", pw->pw_dir);
avahi_log_info("Successfully dropped root privileges.");
return AVAHI_DAEMON_RUNTIME_DIR"/pid";
}
-static gint make_runtime_dir(void) {
- gint r = -1;
+static int make_runtime_dir(void) {
+ int r = -1;
mode_t u;
- gboolean reset_umask = FALSE;
+ int reset_umask = 0;
struct passwd *pw;
struct group * gr;
struct stat st;
}
u = umask(0000);
- reset_umask = TRUE;
+ reset_umask = 1;
if (mkdir(AVAHI_DAEMON_RUNTIME_DIR, 0755) < 0 && errno != EEXIST) {
avahi_log_error("mkdir(\""AVAHI_DAEMON_RUNTIME_DIR"\"): %s", strerror(errno));
return r;
}
-static void set_one_rlimit(int resource, rlim_t limit, const gchar *name) {
+static void set_one_rlimit(int resource, rlim_t limit, const char *name) {
struct rlimit rl;
rl.rlim_cur = rl.rlim_max = limit;
}
int main(int argc, char *argv[]) {
- gint r = 255;
- const gchar *argv0;
- gboolean wrote_pid_file = FALSE;
+ int r = 255;
+ const char *argv0;
+ int wrote_pid_file = 0;
avahi_set_log_function(log_function);
- avahi_set_allocator(avahi_glib_allocator());
init_rand_seed();
avahi_server_config_init(&config.server_config);
config.command = DAEMON_RUN;
- config.daemonize = FALSE;
+ config.daemonize = 0;
config.config_file = NULL;
- config.enable_dbus = TRUE;
- config.drop_root = TRUE;
+ config.enable_dbus = 1;
+ config.drop_root = 1;
config.publish_dns_servers = NULL;
- config.publish_resolv_conf = FALSE;
- config.use_syslog = FALSE;
- config.no_rlimits = FALSE;
- config.debug = FALSE;
+ config.publish_resolv_conf = 0;
+ config.use_syslog = 0;
+ config.no_rlimits = 0;
+ config.debug = 0;
- config.rlimit_as_set = FALSE;
- config.rlimit_core_set = FALSE;
- config.rlimit_data_set = FALSE;
- config.rlimit_fsize_set = FALSE;
- config.rlimit_nofile_set = FALSE;
- config.rlimit_stack_set = FALSE;
+ config.rlimit_as_set = 0;
+ config.rlimit_core_set = 0;
+ config.rlimit_data_set = 0;
+ config.rlimit_fsize_set = 0;
+ config.rlimit_nofile_set = 0;
+ config.rlimit_stack_set = 0;
#ifdef RLIMIT_NPROC
- config.rlimit_nproc_set = FALSE;
+ config.rlimit_nproc_set = 0;
#endif
if ((argv0 = strrchr(argv[0], '/')))
daemon_retval_send(1);
goto finish;
} else
- wrote_pid_file = TRUE;
+ wrote_pid_file = 1;
if (!config.no_rlimits)
enforce_rlimits();
daemon_retval_done();
avahi_server_config_free(&config.server_config);
- g_free(config.config_file);
- g_strfreev(config.publish_dns_servers);
- g_strfreev(resolv_conf);
+ avahi_free(config.config_file);
+ avahi_strfreev(config.publish_dns_servers);
+ avahi_strfreev(resolv_conf);
if (wrote_pid_file)
daemon_pid_file_remove();
#include <config.h>
#endif
+#include <assert.h>
#include <string.h>
#include <sys/socket.h>
#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
-#include <glib.h>
-
#include <avahi-common/llist.h>
+#include <avahi-common/malloc.h>
#include <avahi-core/log.h>
#include "simple-protocol.h"
ClientState state;
- gint fd;
- GPollFD poll_fd;
+ int fd;
+ AvahiWatch *watch;
- gchar inbuf[BUFFER_SIZE], outbuf[BUFFER_SIZE];
- guint inbuf_length, outbuf_length;
+ char inbuf[BUFFER_SIZE], outbuf[BUFFER_SIZE];
+ size_t inbuf_length, outbuf_length;
AvahiSHostNameResolver *host_name_resolver;
AvahiSAddressResolver *address_resolver;
};
struct Server {
- GSource source;
- GMainContext *context;
- GPollFD poll_fd;
- gint fd;
+ const AvahiPoll *poll_api;
+ int fd;
+ AvahiWatch *watch;
AVAHI_LLIST_HEAD(Client, clients);
- guint n_clients;
- gboolean bind_successful;
+ unsigned n_clients;
+ int bind_successful;
};
static Server *server = NULL;
+static void client_work(AvahiWatch *watch, int fd, AvahiWatchEvent events, void *userdata);
+
static void client_free(Client *c) {
- g_assert(c);
+ assert(c);
- g_assert(c->server->n_clients >= 1);
+ assert(c->server->n_clients >= 1);
c->server->n_clients--;
if (c->host_name_resolver)
if (c->dns_server_browser)
avahi_s_dns_server_browser_free(c->dns_server_browser);
-
- g_source_remove_poll(&c->server->source, &c->poll_fd);
+
+ c->server->poll_api->watch_free(c->watch);
close(c->fd);
+
AVAHI_LLIST_REMOVE(Client, clients, c->server->clients, c);
- g_free(c);
+ avahi_free(c);
}
static void client_new(Server *s, int fd) {
Client *c;
- g_assert(fd >= 0);
+ assert(fd >= 0);
- c = g_new(Client, 1);
+ c = avahi_new(Client, 1);
c->server = s;
c->fd = fd;
c->state = CLIENT_IDLE;
c->address_resolver = NULL;
c->dns_server_browser = NULL;
- memset(&c->poll_fd, 0, sizeof(GPollFD));
- c->poll_fd.fd = fd;
- c->poll_fd.events = G_IO_IN|G_IO_ERR|G_IO_HUP;
- g_source_add_poll(&s->source, &c->poll_fd);
+ c->watch = s->poll_api->watch_new(s->poll_api, fd, AVAHI_WATCH_IN, client_work, c);
AVAHI_LLIST_PREPEND(Client, clients, s->clients, c);
s->n_clients++;
}
-static void client_output(Client *c, const guint8*data, guint size) {
- guint k, m;
+static void client_output(Client *c, const uint8_t*data, size_t size) {
+ size_t k, m;
- g_assert(c);
- g_assert(data);
+ assert(c);
+ assert(data);
if (!size)
return;
memcpy(c->outbuf + c->outbuf_length, data, m);
c->outbuf_length += m;
- c->poll_fd.events |= G_IO_OUT;
+ server->poll_api->watch_update(c->watch, AVAHI_WATCH_OUT);
}
-static void client_output_printf(Client *c, const gchar *format, ...) {
- gchar *t;
+static void client_output_printf(Client *c, const char *format, ...) {
+ char *t;
va_list ap;
va_start(ap, format);
- t = g_strdup_vprintf(format, ap);
+ t = avahi_strdup_vprintf(format, ap);
va_end(ap);
- client_output(c, (guint8*) t, strlen(t));
- g_free(t);
+ client_output(c, (uint8_t*) t, strlen(t));
+ avahi_free(t);
}
Client *c = userdata;
- g_assert(c);
+ assert(c);
if (event == AVAHI_RESOLVER_TIMEOUT)
client_output_printf(c, "%+i Query timed out\n", AVAHI_ERR_TIMEOUT);
else {
- gchar t[64];
+ char t[64];
avahi_address_snprint(t, sizeof(t), a);
client_output_printf(c, "+ %i %u %s %s\n", iface, protocol, hostname, t);
}
Client *c = userdata;
- g_assert(c);
+ assert(c);
if (event == AVAHI_RESOLVER_TIMEOUT)
client_output_printf(c, "%+i Query timed out\n", AVAHI_ERR_TIMEOUT);
void* userdata) {
Client *c = userdata;
- gchar t[64];
+ char t[64];
- g_assert(c);
+ assert(c);
if (!a)
return;
client_output_printf(c, "%c %i %u %s %u\n", event == AVAHI_BROWSER_NEW ? '>' : '<', interface, protocol, t, port);
}
-static void handle_line(Client *c, const gchar *s) {
- gchar cmd[64], arg[64];
- gint n_args;
+static void handle_line(Client *c, const char *s) {
+ char cmd[64], arg[64];
+ int n_args;
- g_assert(c);
- g_assert(s);
+ assert(c);
+ assert(s);
if (c->state != CLIENT_IDLE)
return;
}
static void handle_input(Client *c) {
- g_assert(c);
+ assert(c);
for (;;) {
- gchar *e;
- guint k;
+ char *e;
+ size_t k;
if (!(e = memchr(c->inbuf, '\n', c->inbuf_length)))
break;
- k = e - (gchar*) c->inbuf;
+ k = e - (char*) c->inbuf;
*e = 0;
handle_line(c, c->inbuf);
}
}
-static void client_work(Client *c) {
- g_assert(c);
+static void client_work(AvahiWatch *watch, int fd, AvahiWatchEvent events, void *userdata) {
+ Client *c = userdata;
+
+ assert(c);
- if ((c->poll_fd.revents & G_IO_IN) && c->inbuf_length < sizeof(c->inbuf)) {
+ if ((events & AVAHI_WATCH_IN) && c->inbuf_length < sizeof(c->inbuf)) {
ssize_t r;
if ((r = read(c->fd, c->inbuf + c->inbuf_length, sizeof(c->inbuf) - c->inbuf_length)) <= 0) {
}
c->inbuf_length += r;
- g_assert(c->inbuf_length <= sizeof(c->inbuf));
+ assert(c->inbuf_length <= sizeof(c->inbuf));
handle_input(c);
}
- if ((c->poll_fd.revents & G_IO_OUT) && c->outbuf_length > 0) {
+ if ((events & AVAHI_WATCH_OUT) && c->outbuf_length > 0) {
ssize_t r;
if ((r = write(c->fd, c->outbuf, c->outbuf_length)) < 0) {
return;
}
- g_assert((guint) r <= c->outbuf_length);
+ assert((size_t) r <= c->outbuf_length);
c->outbuf_length -= r;
if (c->outbuf_length)
}
}
- c->poll_fd.events =
- G_IO_ERR |
- G_IO_HUP |
- (c->outbuf_length > 0 ? G_IO_OUT : 0) |
- (c->inbuf_length < sizeof(c->inbuf) ? G_IO_IN : 0);
+ c->server->poll_api->watch_update(
+ watch,
+ (c->outbuf_length > 0 ? AVAHI_WATCH_OUT : 0) |
+ (c->inbuf_length < sizeof(c->inbuf) ? AVAHI_WATCH_IN : 0));
}
-static gboolean prepare_func(GSource *source, gint *timeout) {
- g_assert(source);
- g_assert(timeout);
-
- *timeout = -1;
- return FALSE;
-}
-
-static gboolean check_func(GSource *source) {
- Server *s = (Server*) source;
- Client *c;
-
- g_assert(s);
-
- if (s->poll_fd.revents)
- return TRUE;
-
- for (c = s->clients; c; c = c->clients_next)
- if (c->poll_fd.revents)
- return TRUE;
-
- return FALSE;
-}
+static void server_work(AvahiWatch *watch, int fd, AvahiWatchEvent events, void *userdata) {
+ Server *s = userdata;
-static gboolean dispatch_func(GSource *source, GSourceFunc callback, gpointer user_data) {
- Server *s = (Server*) source;
- Client *c, *n;
-
- g_assert(s);
+ assert(s);
- if (s->poll_fd.revents & G_IO_IN) {
- gint fd;
+ if (events & AVAHI_WATCH_IN) {
+ int cfd;
- if ((fd = accept(s->fd, NULL, NULL)) < 0)
- avahi_log_warn("accept(): %s", strerror(errno));
+ if ((cfd = accept(fd, NULL, NULL)) < 0)
+ avahi_log_error("accept(): %s", strerror(errno));
else
- client_new(s, fd);
- } else if (s->poll_fd.revents)
- g_error("Invalid revents");
-
- for (c = s->clients; c; c = n) {
- n = c->clients_next;
- if (c->poll_fd.revents)
- client_work(c);
+ client_new(s, cfd);
}
-
- return TRUE;
}
-
-int simple_protocol_setup(GMainContext *c) {
+
+int simple_protocol_setup(const AvahiPoll *poll_api) {
struct sockaddr_un sa;
mode_t u;
- static GSourceFuncs source_funcs = {
- prepare_func,
- check_func,
- dispatch_func,
- NULL,
- NULL,
- NULL
- };
-
- g_assert(!server);
+ assert(!server);
- server = (Server*) g_source_new(&source_funcs, sizeof(Server));
- server->bind_successful = FALSE;
+ server = avahi_new(Server, 1);
+ server->poll_api = poll_api;
+ server->bind_successful = 0;
server->fd = -1;
AVAHI_LLIST_HEAD_INIT(Client, server->clients);
- g_main_context_ref(server->context = (c ? c : g_main_context_default()));
- server->clients = NULL;
-
+ server->watch = NULL;
+
u = umask(0000);
if ((server->fd = socket(PF_LOCAL, SOCK_STREAM, 0)) < 0) {
goto fail;
}
- server->bind_successful = TRUE;
+ server->bind_successful = 1;
if (listen(server->fd, 2) < 0) {
avahi_log_warn("listen(): %s", strerror(errno));
umask(u);
- memset(&server->poll_fd, 0, sizeof(GPollFD));
- server->poll_fd.fd = server->fd;
- server->poll_fd.events = G_IO_IN|G_IO_ERR;
- g_source_add_poll(&server->source, &server->poll_fd);
-
- g_source_attach(&server->source, server->context);
+ server->watch = poll_api->watch_new(poll_api, server->fd, AVAHI_WATCH_IN, server_work, server);
return 0;
if (server) {
+ if (server->bind_successful)
+ unlink(AVAHI_SOCKET);
+
while (server->clients)
client_free(server->clients);
- if (server->bind_successful)
- unlink(AVAHI_SOCKET);
+ if (server->watch)
+ server->poll_api->watch_free(server->watch);
if (server->fd >= 0)
close(server->fd);
- g_main_context_unref(server->context);
+ avahi_free(server);
- g_source_destroy(&server->source);
- g_source_unref(&server->source);
-
server = NULL;
}
}
/* Restart queries in case of local domain name changes */
- g_assert(server);
+ assert(server);
for (c = server->clients; c; c = c->clients_next)
if (c->state == CLIENT_BROWSE_DNS_SERVERS && c->dns_server_browser) {
USA.
***/
-int simple_protocol_setup(GMainContext *c);
+#include <avahi-common/watch.h>
+
+int simple_protocol_setup(const AvahiPoll *poll_api);
void simple_protocol_shutdown(void);
void simple_protocol_restart_queries(void);
#include <fcntl.h>
#include <unistd.h>
-#include <glib.h>
#include <expat.h>
#include <avahi-common/llist.h>
+#include <avahi-common/malloc.h>
#include <avahi-core/log.h>
#include "main.h"
struct StaticService {
StaticServiceGroup *group;
- gchar *type;
- gchar *domain_name;
- gchar *host_name;
- guint16 port;
+ char *type;
+ char *domain_name;
+ char *host_name;
+ uint16_t port;
AvahiStringList *txt_records;
};
struct StaticServiceGroup {
- gchar *filename;
+ char *filename;
time_t mtime;
- gchar *name, *chosen_name;
- gboolean replace_wildcards;
+ char *name, *chosen_name;
+ int replace_wildcards;
AvahiSEntryGroup *entry_group;
AVAHI_LLIST_HEAD(StaticService, services);
static AVAHI_LLIST_HEAD(StaticServiceGroup, groups) = NULL;
-static gchar *replacestr(const gchar *pattern, const gchar *a, const gchar *b) {
- gchar *r = NULL, *e, *n;
+static char *replacestr(const char *pattern, const char *a, const char *b) {
+ char *r = NULL, *e, *n;
while ((e = strstr(pattern, a))) {
- gchar *k;
+ char *k;
- k = g_strndup(pattern, e - pattern);
+ k = avahi_strndup(pattern, e - pattern);
if (r)
- n = g_strconcat(r, k, b, NULL);
+ n = avahi_strdup_printf("%s%s%s", r, k, b);
else
- n = g_strconcat(k, b, NULL);
+ n = avahi_strdup_printf("%s%s", k, b);
- g_free(k);
- g_free(r);
+ avahi_free(k);
+ avahi_free(r);
r = n;
pattern = e + strlen(a);
}
if (!r)
- return g_strdup(pattern);
+ return avahi_strdup(pattern);
- n = g_strconcat(r, pattern, NULL);
- g_free(r);
+ n = avahi_strdup_printf("%s%s", r, pattern);
+ avahi_free(r);
return n;
}
static StaticService *static_service_new(StaticServiceGroup *group) {
StaticService *s;
- g_assert(group);
- s = g_new(StaticService, 1);
+ assert(group);
+ s = avahi_new(StaticService, 1);
s->group = group;
s->type = s->host_name = s->domain_name = NULL;
return s;
}
-static StaticServiceGroup *static_service_group_new(gchar *filename) {
+static StaticServiceGroup *static_service_group_new(char *filename) {
StaticServiceGroup *g;
- g_assert(filename);
+ assert(filename);
- g = g_new(StaticServiceGroup, 1);
- g->filename = g_strdup(filename);
+ g = avahi_new(StaticServiceGroup, 1);
+ g->filename = avahi_strdup(filename);
g->mtime = 0;
g->name = g->chosen_name = NULL;
- g->replace_wildcards = FALSE;
+ g->replace_wildcards = 0;
g->entry_group = NULL;
AVAHI_LLIST_HEAD_INIT(StaticService, g->services);
}
static void static_service_free(StaticService *s) {
- g_assert(s);
+ assert(s);
AVAHI_LLIST_REMOVE(StaticService, services, s->group->services, s);
- g_free(s->type);
- g_free(s->host_name);
- g_free(s->domain_name);
+ avahi_free(s->type);
+ avahi_free(s->host_name);
+ avahi_free(s->domain_name);
avahi_string_list_free(s->txt_records);
- g_free(s);
+ avahi_free(s);
}
static void static_service_group_free(StaticServiceGroup *g) {
- g_assert(g);
+ assert(g);
if (g->entry_group)
avahi_s_entry_group_free(g->entry_group);
AVAHI_LLIST_REMOVE(StaticServiceGroup, groups, groups, g);
- g_free(g->filename);
- g_free(g->name);
- g_free(g->chosen_name);
- g_free(g);
+ avahi_free(g->filename);
+ avahi_free(g->name);
+ avahi_free(g->chosen_name);
+ avahi_free(g);
}
-static void entry_group_callback(AvahiServer *s, AvahiSEntryGroup *eg, AvahiEntryGroupState state, gpointer userdata) {
+static void entry_group_callback(AvahiServer *s, AvahiSEntryGroup *eg, AvahiEntryGroupState state, void* userdata) {
StaticServiceGroup *g = userdata;
- g_assert(s);
- g_assert(g);
+ assert(s);
+ assert(g);
if (state == AVAHI_ENTRY_GROUP_COLLISION) {
- gchar *n;
+ char *n;
remove_static_service_group_from_server(g);
n = avahi_alternative_service_name(g->chosen_name);
- g_free(g->chosen_name);
+ avahi_free(g->chosen_name);
g->chosen_name = n;
avahi_log_notice("Service name conflict for \"%s\" (%s), retrying with \"%s\".", g->name, g->filename, g->chosen_name);
static void add_static_service_group_to_server(StaticServiceGroup *g) {
StaticService *s;
- g_assert(g);
+ assert(g);
if (g->chosen_name)
- g_free(g->chosen_name);
+ avahi_free(g->chosen_name);
if (g->replace_wildcards)
g->chosen_name = replacestr(g->name, "%h", avahi_server_get_host_name(avahi_server));
else
- g->chosen_name = g_strdup(g->name);
+ g->chosen_name = avahi_strdup(g->name);
if (!g->entry_group)
g->entry_group = avahi_s_entry_group_new(avahi_server, entry_group_callback, g);
- g_assert(avahi_s_entry_group_is_empty(g->entry_group));
+ assert(avahi_s_entry_group_is_empty(g->entry_group));
for (s = g->services; s; s = s->services_next) {
}
static void remove_static_service_group_from_server(StaticServiceGroup *g) {
- g_assert(g);
+ assert(g);
if (g->entry_group)
avahi_s_entry_group_reset(g->entry_group);
StaticServiceGroup *group;
StaticService *service;
xml_tag_name current_tag;
- gboolean failed;
- gchar *buf;
+ int failed;
+ char *buf;
};
static void XMLCALL xml_start(void *data, const char *el, const char *attr[]) {
struct xml_userdata *u = data;
- g_assert(u);
+ assert(u);
if (u->failed)
return;
if (attr[0])
goto invalid_attr;
- g_assert(!u->service);
+ assert(!u->service);
u->service = static_service_new(u->group);
u->current_tag = XML_TAG_SERVICE;
u->current_tag = XML_TAG_TXT_RECORD;
} else {
avahi_log_error("%s: parse failure: didn't expect element <%s>.", u->group->filename, el);
- u->failed = TRUE;
+ u->failed = 1;
}
return;
invalid_attr:
avahi_log_error("%s: parse failure: invalid attribute for element <%s>.", u->group->filename, el);
- u->failed = TRUE;
+ u->failed = 1;
return;
}
static void XMLCALL xml_end(void *data, const char *el) {
struct xml_userdata *u = data;
- g_assert(u);
+ assert(u);
if (u->failed)
return;
if (!u->group->name || !u->group->services) {
avahi_log_error("%s: parse failure: service group incomplete.", u->group->filename);
- u->failed = TRUE;
+ u->failed = 1;
return;
}
if (!u->service->type) {
avahi_log_error("%s: parse failure: service incomplete.", u->group->filename);
- u->failed = TRUE;
+ u->failed = 1;
return;
}
case XML_TAG_PORT: {
int p;
- g_assert(u->service);
+ assert(u->service);
p = u->buf ? atoi(u->buf) : 0;
if (p < 0 || p > 0xFFFF) {
avahi_log_error("%s: parse failure: invalid port specification \"%s\".", u->group->filename, u->buf);
- u->failed = TRUE;
+ u->failed = 1;
return;
}
- u->service->port = (guint16) p;
+ u->service->port = (uint16_t) p;
u->current_tag = XML_TAG_SERVICE;
break;
}
case XML_TAG_TXT_RECORD: {
- g_assert(u->service);
+ assert(u->service);
u->service->txt_records = avahi_string_list_add(u->service->txt_records, u->buf ? u->buf : "");
u->current_tag = XML_TAG_SERVICE;
;
}
- g_free(u->buf);
+ avahi_free(u->buf);
u->buf = NULL;
}
-static gchar *append_cdata(gchar *t, const gchar *n, int length) {
- gchar *r, *k;
+static char *append_cdata(char *t, const char *n, int length) {
+ char *r, *k;
if (!length)
return t;
- k = g_strndup(n, length);
+ k = avahi_strndup(n, length);
if (t) {
- r = g_strconcat(t, k, NULL);
- g_free(k);
- g_free(t);
+ r = avahi_strdup_printf("%s%s", t, k);
+ avahi_free(k);
+ avahi_free(t);
} else
r = k;
static void XMLCALL xml_cdata(void *data, const XML_Char *s, int len) {
struct xml_userdata *u = data;
- g_assert(u);
+ assert(u);
if (u->failed)
return;
break;
case XML_TAG_TYPE:
- g_assert(u->service);
+ assert(u->service);
u->service->type = append_cdata(u->service->type, s, len);
break;
case XML_TAG_DOMAIN_NAME:
- g_assert(u->service);
+ assert(u->service);
u->service->domain_name = append_cdata(u->service->domain_name, s, len);
break;
case XML_TAG_HOST_NAME:
- g_assert(u->service);
+ assert(u->service);
u->service->host_name = append_cdata(u->service->host_name, s, len);
break;
}
}
-static gint static_service_group_load(StaticServiceGroup *g) {
+static int static_service_group_load(StaticServiceGroup *g) {
XML_Parser parser = NULL;
- gint fd = -1;
+ int fd = -1;
struct xml_userdata u;
- gint r = -1;
+ int r = -1;
struct stat st;
ssize_t n;
- g_assert(g);
+ assert(g);
u.buf = NULL;
u.group = g;
u.service = NULL;
u.current_tag = XML_TAG_INVALID;
- u.failed = FALSE;
+ u.failed = 0;
/* Cleanup old data in this service group, if available */
remove_static_service_group_from_server(g);
while (g->services)
static_service_free(g->services);
- g_free(g->name);
- g_free(g->chosen_name);
+ avahi_free(g->name);
+ avahi_free(g->chosen_name);
g->name = g->chosen_name = NULL;
- g->replace_wildcards = FALSE;
+ g->replace_wildcards = 0;
if (!(parser = XML_ParserCreate(NULL))) {
avahi_log_error("XML_ParserCreate() failed.");
if (parser)
XML_ParserFree(parser);
- g_free(u.buf);
+ avahi_free(u.buf);
return r;
}
-static void load_file(gchar *n) {
+static void load_file(char *n) {
StaticServiceGroup *g;
- g_assert(n);
+ assert(n);
for (g = groups; g; g = g->groups_next)
if (strcmp(g->filename, n) == 0)
void static_service_load(void) {
StaticServiceGroup *g, *n;
glob_t globbuf;
- gchar **p;
+ char **p;
for (g = groups; g; g = n) {
struct stat st;
if test "x$ENABLE_DBUS" = "xyes"; then
AC_DEFINE(ENABLE_DBUS, 1, [Whether to use DBUS or not])
- PKG_CHECK_MODULES(DBUS, [ dbus-glib-1 >= 0.30])
+ PKG_CHECK_MODULES(DBUS, [ dbus-1 >= 0.30])
AC_ARG_WITH(dbus-sys, AS_HELP_STRING([--with-dbus-sys=<dir>], [where D-BUS system.d directory is]))