-intltool-extract.in
-intltool-merge.in
-intltool-update.in
*.tar.gz
doxygen
Makefile
*.la
.deps/
.libs/
-ABOUT-NLS
-ChangeLog
aclocal.m4
*.cache
compile
config.h
config.h.in
config.log
-config.rpath
config.status
config.sub
configure
libtool
ltmain.sh
missing
-py-compile
stamp-h1
.*.swp
test-driver
SUBDIRS = \
common \
avahi \
+ tests \
examples
DX_INPUT = \
+++ /dev/null
-*.o
-*.lo
-*.la
-Makefile
-Makefile.in
-.deps
-.libs
-alternative-test
-domain-test
-strlst-test
-timeval-test
-utf8-test
-watch-test
-watch-test-thread
-avahi-reflector
-avahi-test
-conformance-test
-dns-spin-test
-dns-test
-hashmap-test
-prioq-test
-querier-test
-timeeventq-test
-update-test
-*-test.log
-*-test.trs
-test-suite.log
# This cool debug trap works on i386/gcc only
AM_CFLAGS+='-DDEBUG_TRAP=__asm__("int $$3")'
-avahiincludedir=$(includedir)/src
+avahiincludedir = $(top_srcdir)/avahi
avahiinclude_HEADERS = \
strlst.h \
lib_LTLIBRARIES = libavahi.la
-if ENABLE_TESTS
-noinst_PROGRAMS = \
- strlst-test \
- domain-test \
- alternative-test \
- timeval-test \
- watch-test \
- watch-test-thread \
- utf8-test \
- prioq-test \
- avahi-test \
- conformance-test \
- avahi-reflector \
- dns-test \
- dns-spin-test \
- timeeventq-test \
- hashmap-test \
- querier-test \
- update-test
-
-TESTS = \
- dns-spin-test \
- dns-test \
- hashmap-test
-endif
-
libavahi_la_SOURCES = \
malloc.c malloc.h \
address.c address.h \
libavahi_la_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS) -DAVAHI_LOCALEDIR=\"$(avahilocaledir)\"
libavahi_la_LIBADD = $(AM_LDADD) $(PTHREAD_CFLAGS) $(PTHREAD_LIBS) $(INTLLIBS)
libavahi_la_LDFLAGS = $(AM_LDFLAGS) -version-info $(LIBAVAHI_VERSION_INFO)
-
-strlst_test_SOURCES = strlst-test.c
-strlst_test_CFLAGS = $(AM_CFLAGS)
-strlst_test_LDADD = $(AM_LDADD) libavahi.la
-
-alternative_test_SOURCES = alternative-test.c
-alternative_test_CFLAGS = $(AM_CFLAGS)
-alternative_test_LDADD = $(AM_LDADD) libavahi.la
-
-domain_test_SOURCES = domain-test.c
-domain_test_CFLAGS = $(AM_CFLAGS)
-domain_test_LDADD = $(AM_LDADD) libavahi.la
-
-watch_test_SOURCES = watch-test.c
-watch_test_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
-watch_test_LDADD = $(AM_LDADD) $(PTHREAD_LIBS) $(PTHREAD_CFLAGS) libavahi.la
-
-watch_test_thread_SOURCES = $(watch_test_SOURCES)
-watch_test_thread_CFLAGS = $(watch_test_CFLAGS) -DUSE_THREAD
-watch_test_thread_LDADD = $(watch_test_LDADD) libavahi.la
-
-timeval_test_SOURCES = timeval-test.c
-timeval_test_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
-timeval_test_LDADD = $(AM_LDADD) $(PTHREAD_LIBS) $(PTHREAD_CFLAGS) libavahi.la
-
-utf8_test_SOURCES = utf8-test.c
-utf8_test_CFLAGS = $(AM_CFLAGS)
-utf8_test_LDADD = $(AM_LDADD) libavahi.la
-
-prioq_test_SOURCES = prioq-test.c
-prioq_test_CFLAGS = $(AM_CFLAGS)
-prioq_test_LDADD = $(AM_LDADD) libavahi.la
-
-avahi_test_SOURCES = avahi-test.c
-avahi_test_CFLAGS = $(AM_CFLAGS)
-avahi_test_LDADD = $(AM_LDADD) libavahi.la
-
-update_test_SOURCES = update-test.c
-update_test_CFLAGS = $(AM_CFLAGS)
-update_test_LDADD = $(AM_LDADD) libavahi.la
-
-querier_test_SOURCES = querier-test.c
-querier_test_CFLAGS = $(AM_CFLAGS)
-querier_test_LDADD = $(AM_LDADD) libavahi.la
-
-conformance_test_SOURCES = conformance-test.c
-conformance_test_CFLAGS = $(AM_CFLAGS)
-conformance_test_LDADD = $(AM_LDADD) libavahi.la
-
-avahi_reflector_SOURCES = avahi-reflector.c
-avahi_reflector_CFLAGS = $(AM_CFLAGS)
-avahi_reflector_LDADD = $(AM_LDADD) libavahi.la
-
-dns_test_SOURCES = dns-test.c
-dns_test_CFLAGS = $(AM_CFLAGS)
-dns_test_LDADD = $(AM_LDADD) libavahi.la
-
-dns_spin_test_SOURCES = dns-spin-test.c
-dns_spin_test_CFLAGS = $(AM_CFLAGS)
-dns_spin_test_LDADD = $(AM_LDADD) libavahi.la
-
-timeeventq_test_SOURCES = timeeventq-test.c
-timeeventq_test_CFLAGS = $(AM_CFLAGS)
-timeeventq_test_LDADD = $(AM_LDADD) libavahi.la
-
-hashmap_test_SOURCES = hashmap-test.c
-hashmap_test_CFLAGS = $(AM_CFLAGS)
-hashmap_test_LDADD = $(AM_LDADD) libavahi.la
-
-valgrind: avahi-test
- libtool --mode=execute valgrind ./avahi-test
-
-gdb: avahi-test
- libtool --mode=execute gdb ./avahi-test
+++ /dev/null
-/***
- This file is part of avahi.
-
- avahi is free software; you can redistribute it and/or modify it
- under the terms of the GNU Lesser General Public License as
- published by the Free Software Foundation; either version 2.1 of the
- License, or (at your option) any later version.
-
- avahi is distributed in the hope that it will be useful, but WITHOUT
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
- Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with avahi; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- USA.
-***/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdio.h>
-
-#include "alternative.h"
-#include "malloc.h"
-#include "domain.h"
-
-int main(AVAHI_GCC_UNUSED int argc, AVAHI_GCC_UNUSED char *argv[]) {
- const char* const test_strings[] = {
- "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
- "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXüüüüüüü",
- "gurke",
- "-",
- " #",
- "1",
- "#0",
- " #0",
- " #1",
- "#-1",
- " #-1",
- "-0",
- "--0",
- "-1",
- "--1",
- "-2",
- "gurke1",
- "gurke0",
- "gurke-2",
- "gurke #0",
- "gurke #1",
- "gurke #",
- "gurke#1",
- "gurke-",
- "gurke---",
- "gurke #",
- "gurke ###",
- NULL
- };
-
- char *r = NULL;
- int i, j, k;
-
- for (k = 0; test_strings[k]; k++) {
-
- printf(">>>>>%s<<<<\n", test_strings[k]);
-
- for (j = 0; j < 2; j++) {
-
- for (i = 0; i <= 100; i++) {
- char *n;
-
- n = i == 0 ? avahi_strdup(test_strings[k]) : (j ? avahi_alternative_service_name(r) : avahi_alternative_host_name(r));
- avahi_free(r);
- r = n;
-
- if (j)
- assert(avahi_is_valid_service_name(n));
- else
- assert(avahi_is_valid_host_name(n));
-
- printf("%s\n", r);
- }
- }
- }
-
- avahi_free(r);
- return 0;
-}
+++ /dev/null
-/***
- This file is part of avahi.
-
- avahi is free software; you can redistribute it and/or modify it
- under the terms of the GNU Lesser General Public License as
- published by the Free Software Foundation; either version 2.1 of the
- License, or (at your option) any later version.
-
- avahi is distributed in the hope that it will be useful, but WITHOUT
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
- Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with avahi; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- USA.
-***/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdlib.h>
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-
-#include <avahi/simple-watch.h>
-#include <avahi/core.h>
-
-int main(AVAHI_GCC_UNUSED int argc, AVAHI_GCC_UNUSED char*argv[]) {
- AvahiServer *server;
- AvahiServerConfig config;
- int error;
- AvahiSimplePoll *simple_poll;
-
- simple_poll = avahi_simple_poll_new();
-
- avahi_server_config_init(&config);
- config.publish_hinfo = 0;
- config.publish_addresses = 0;
- config.publish_workstation = 0;
- config.publish_domain = 0;
- config.use_ipv6 = 0;
- config.enable_reflector = 1;
-
- server = avahi_server_new(avahi_simple_poll_get(simple_poll), &config, NULL, NULL, &error);
- avahi_server_config_free(&config);
-
- for (;;)
- if (avahi_simple_poll_iterate(simple_poll, -1) != 0)
- break;
-
- avahi_server_free(server);
- avahi_simple_poll_free(simple_poll);
-
- return 0;
-}
+++ /dev/null
-/***
- This file is part of avahi.
-
- avahi is free software; you can redistribute it and/or modify it
- under the terms of the GNU Lesser General Public License as
- published by the Free Software Foundation; either version 2.1 of the
- License, or (at your option) any later version.
-
- avahi is distributed in the hope that it will be useful, but WITHOUT
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
- Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with avahi; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- USA.
-***/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <assert.h>
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-
-#include <avahi/malloc.h>
-#include <avahi/simple-watch.h>
-#include <avahi/alternative.h>
-#include <avahi/timeval.h>
-
-#include <avahi/core.h>
-#include <avahi/log.h>
-#include <avahi/publish.h>
-#include <avahi/lookup.h>
-#include <avahi/dns-srv-rr.h>
-
-static AvahiSEntryGroup *group = NULL;
-static AvahiServer *server = NULL;
-static char *service_name = NULL;
-
-static const AvahiPoll *poll_api;
-
-static void quit_timeout_callback(AVAHI_GCC_UNUSED AvahiTimeout *timeout, void* userdata) {
- AvahiSimplePoll *simple_poll = userdata;
-
- avahi_simple_poll_quit(simple_poll);
-}
-
-static void dump_line(const char *text, AVAHI_GCC_UNUSED void* userdata) {
- printf("%s\n", text);
-}
-
-static void dump_timeout_callback(AvahiTimeout *timeout, void* userdata) {
- struct timeval tv;
-
- AvahiServer *avahi = userdata;
- avahi_server_dump(avahi, dump_line, NULL);
-
- avahi_elapse_time(&tv, 5000, 0);
- poll_api->timeout_update(timeout, &tv);
-}
-
-static const char *browser_event_to_string(AvahiBrowserEvent event) {
- switch (event) {
- case AVAHI_BROWSER_NEW : return "NEW";
- case AVAHI_BROWSER_REMOVE : return "REMOVE";
- case AVAHI_BROWSER_CACHE_EXHAUSTED : return "CACHE_EXHAUSTED";
- case AVAHI_BROWSER_ALL_FOR_NOW : return "ALL_FOR_NOW";
- case AVAHI_BROWSER_FAILURE : return "FAILURE";
- }
-
- abort();
-}
-
-static const char *resolver_event_to_string(AvahiResolverEvent event) {
- switch (event) {
- case AVAHI_RESOLVER_FOUND: return "FOUND";
- case AVAHI_RESOLVER_FAILURE: return "FAILURE";
- }
- abort();
-}
-
-static void record_browser_callback(
- AvahiSRecordBrowser *r,
- AvahiIfIndex interface,
- AvahiProtocol protocol,
- AvahiBrowserEvent event,
- AvahiRecord *record,
- AVAHI_GCC_UNUSED AvahiLookupResultFlags flags,
- AVAHI_GCC_UNUSED void* userdata) {
- char *t;
-
- assert(r);
-
- if (record) {
- avahi_log_debug("RB: record [%s] on %i.%i is %s", t = avahi_record_to_string(record), interface, protocol, browser_event_to_string(event));
- avahi_free(t);
- } else
- avahi_log_debug("RB: [%s]", browser_event_to_string(event));
-
-}
-
-static void remove_entries(void);
-static void create_entries(int new_name);
-
-static void entry_group_callback(AVAHI_GCC_UNUSED AvahiServer *s, AVAHI_GCC_UNUSED AvahiSEntryGroup *g, AvahiEntryGroupState state, AVAHI_GCC_UNUSED void* userdata) {
- avahi_log_debug("entry group state: %i", state);
-
- if (state == AVAHI_ENTRY_GROUP_COLLISION) {
- remove_entries();
- create_entries(1);
- avahi_log_debug("Service name conflict, retrying with <%s>", service_name);
- } else if (state == AVAHI_ENTRY_GROUP_ESTABLISHED) {
- avahi_log_debug("Service established under name <%s>", service_name);
- }
-}
-
-static void server_callback(AvahiServer *s, AvahiServerState state, AVAHI_GCC_UNUSED void* userdata) {
-
- server = s;
- avahi_log_debug("server state: %i", state);
-
- if (state == AVAHI_SERVER_RUNNING) {
- avahi_log_debug("Server startup complete. Host name is <%s>. Service cookie is %u", avahi_server_get_host_name_fqdn(s), avahi_server_get_local_service_cookie(s));
- create_entries(0);
- } else if (state == AVAHI_SERVER_COLLISION) {
- char *n;
- remove_entries();
-
- n = avahi_alternative_host_name(avahi_server_get_host_name(s));
-
- avahi_log_debug("Host name conflict, retrying with <%s>", n);
- avahi_server_set_host_name(s, n);
- avahi_free(n);
- }
-}
-
-static void remove_entries(void) {
- if (group)
- avahi_s_entry_group_reset(group);
-}
-
-static void create_entries(int new_name) {
- AvahiAddress a;
- AvahiRecord *r;
-
- remove_entries();
-
- if (!group)
- group = avahi_s_entry_group_new(server, entry_group_callback, NULL);
-
- assert(avahi_s_entry_group_is_empty(group));
-
- if (!service_name)
- service_name = avahi_strdup("Test Service");
- else if (new_name) {
- char *n = avahi_alternative_service_name(service_name);
- avahi_free(service_name);
- service_name = n;
- }
-
- if (avahi_server_add_service(server, group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, service_name, "_http._tcp", NULL, NULL, 80, "foo", NULL) < 0) {
- avahi_log_error("Failed to add HTTP service");
- goto fail;
- }
-
- if (avahi_server_add_service(server, group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, service_name, "_ftp._tcp", NULL, NULL, 21, "foo", NULL) < 0) {
- avahi_log_error("Failed to add FTP service");
- goto fail;
- }
-
- if (avahi_server_add_service(server, group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0,service_name, "_webdav._tcp", NULL, NULL, 80, "foo", NULL) < 0) {
- avahi_log_error("Failed to add WEBDAV service");
- goto fail;
- }
-
- if (avahi_server_add_dns_server_address(server, group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, NULL, AVAHI_DNS_SERVER_RESOLVE, avahi_address_parse("192.168.50.1", AVAHI_PROTO_UNSPEC, &a), 53) < 0) {
- avahi_log_error("Failed to add new DNS Server address");
- goto fail;
- }
-
- r = avahi_record_new_full("cname.local", AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_CNAME, AVAHI_DEFAULT_TTL);
- r->data.cname.name = avahi_strdup("cocaine.local");
-
- if (avahi_server_add(server, group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, r) < 0) {
- avahi_record_unref(r);
- avahi_log_error("Failed to add CNAME record");
- goto fail;
- }
- avahi_record_unref(r);
-
- avahi_s_entry_group_commit(group);
- return;
-
-fail:
- if (group)
- avahi_s_entry_group_free(group);
-
- group = NULL;
-}
-
-static void hnr_callback(
- AVAHI_GCC_UNUSED AvahiSHostNameResolver *r,
- AvahiIfIndex iface,
- AvahiProtocol protocol,
- AvahiResolverEvent event,
- const char *hostname,
- const AvahiAddress *a,
- AVAHI_GCC_UNUSED AvahiLookupResultFlags flags,
- AVAHI_GCC_UNUSED void* userdata) {
- char t[AVAHI_ADDRESS_STR_MAX];
-
- if (a)
- avahi_address_snprint(t, sizeof(t), a);
-
- avahi_log_debug("HNR: (%i.%i) <%s> -> %s [%s]", iface, protocol, hostname, a ? t : "n/a", resolver_event_to_string(event));
-}
-
-static void ar_callback(
- AVAHI_GCC_UNUSED AvahiSAddressResolver *r,
- AvahiIfIndex iface,
- AvahiProtocol protocol,
- AvahiResolverEvent event,
- const AvahiAddress *a,
- const char *hostname,
- AVAHI_GCC_UNUSED AvahiLookupResultFlags flags,
- AVAHI_GCC_UNUSED void* userdata) {
- char t[AVAHI_ADDRESS_STR_MAX];
-
- avahi_address_snprint(t, sizeof(t), a);
-
- avahi_log_debug("AR: (%i.%i) %s -> <%s> [%s]", iface, protocol, t, hostname ? hostname : "n/a", resolver_event_to_string(event));
-}
-
-static void db_callback(
- AVAHI_GCC_UNUSED AvahiSDomainBrowser *b,
- AvahiIfIndex iface,
- AvahiProtocol protocol,
- AvahiBrowserEvent event,
- const char *domain,
- AVAHI_GCC_UNUSED AvahiLookupResultFlags flags,
- AVAHI_GCC_UNUSED void* userdata) {
-
- avahi_log_debug("DB: (%i.%i) <%s> [%s]", iface, protocol, domain ? domain : "NULL", browser_event_to_string(event));
-}
-
-static void stb_callback(
- AVAHI_GCC_UNUSED AvahiSServiceTypeBrowser *b,
- AvahiIfIndex iface,
- AvahiProtocol protocol,
- AvahiBrowserEvent event,
- const char *service_type,
- const char *domain,
- AVAHI_GCC_UNUSED AvahiLookupResultFlags flags,
- AVAHI_GCC_UNUSED void* userdata) {
-
- avahi_log_debug("STB: (%i.%i) %s in <%s> [%s]", iface, protocol, service_type ? service_type : "NULL", domain ? domain : "NULL", browser_event_to_string(event));
-}
-
-static void sb_callback(
- AVAHI_GCC_UNUSED AvahiSServiceBrowser *b,
- AvahiIfIndex iface,
- AvahiProtocol protocol,
- AvahiBrowserEvent event,
- const char *name,
- const char *service_type,
- const char *domain,
- AVAHI_GCC_UNUSED AvahiLookupResultFlags flags,
- AVAHI_GCC_UNUSED void* userdata) {
- avahi_log_debug("SB: (%i.%i) <%s> as %s in <%s> [%s]", iface, protocol, name ? name : "NULL", service_type ? service_type : "NULL", domain ? domain : "NULL", browser_event_to_string(event));
-}
-
-static void sr_callback(
- AVAHI_GCC_UNUSED AvahiSServiceResolver *r,
- AvahiIfIndex iface,
- AvahiProtocol protocol,
- AvahiResolverEvent event,
- const char *name,
- const char*service_type,
- const char*domain_name,
- const char*hostname,
- const AvahiAddress *a,
- uint16_t port,
- AvahiStringList *txt,
- AVAHI_GCC_UNUSED AvahiLookupResultFlags flags,
- AVAHI_GCC_UNUSED void* userdata) {
-
- if (event != AVAHI_RESOLVER_FOUND)
- avahi_log_debug("SR: (%i.%i) <%s> as %s in <%s> [%s]", iface, protocol, name, service_type, domain_name, resolver_event_to_string(event));
- else {
- char t[AVAHI_ADDRESS_STR_MAX], *s;
-
- avahi_address_snprint(t, sizeof(t), a);
-
- s = avahi_string_list_to_string(txt);
- avahi_log_debug("SR: (%i.%i) <%s> as %s in <%s>: %s/%s:%i (%s) [%s]", iface, protocol, name, service_type, domain_name, hostname, t, port, s, resolver_event_to_string(event));
- avahi_free(s);
- }
-}
-
-static void dsb_callback(
- AVAHI_GCC_UNUSED AvahiSDNSServerBrowser *b,
- AvahiIfIndex iface,
- AvahiProtocol protocol,
- AvahiBrowserEvent event,
- const char*hostname,
- const AvahiAddress *a,
- uint16_t port,
- AVAHI_GCC_UNUSED AvahiLookupResultFlags flags,
- AVAHI_GCC_UNUSED void* userdata) {
-
- char t[AVAHI_ADDRESS_STR_MAX] = "n/a";
-
- if (a)
- avahi_address_snprint(t, sizeof(t), a);
-
- avahi_log_debug("DSB: (%i.%i): %s/%s:%i [%s]", iface, protocol, hostname ? hostname : "NULL", t, port, browser_event_to_string(event));
-}
-
-int main(AVAHI_GCC_UNUSED int argc, AVAHI_GCC_UNUSED char *argv[]) {
- AvahiSRecordBrowser *r;
- AvahiSHostNameResolver *hnr;
- AvahiSAddressResolver *ar;
- AvahiKey *k;
- AvahiServerConfig config;
- AvahiAddress a;
- AvahiSDomainBrowser *db;
- AvahiSServiceTypeBrowser *stb;
- AvahiSServiceBrowser *sb;
- AvahiSServiceResolver *sr;
- AvahiSDNSServerBrowser *dsb;
- AvahiSimplePoll *simple_poll;
- int error;
- struct timeval tv;
-
- simple_poll = avahi_simple_poll_new();
- poll_api = avahi_simple_poll_get(simple_poll);
-
- avahi_server_config_init(&config);
-
- avahi_address_parse("192.168.50.1", AVAHI_PROTO_UNSPEC, &config.wide_area_servers[0]);
- config.n_wide_area_servers = 1;
- config.enable_wide_area = 1;
-
- server = avahi_server_new(poll_api, &config, server_callback, NULL, &error);
- avahi_server_config_free(&config);
-
- k = avahi_key_new("_http._tcp.0pointer.de", AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_PTR);
- r = avahi_s_record_browser_new(server, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, k, 0, record_browser_callback, NULL);
- avahi_key_unref(k);
-
- hnr = avahi_s_host_name_resolver_new(server, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, "cname.local", AVAHI_PROTO_UNSPEC, 0, hnr_callback, NULL);
-
- ar = avahi_s_address_resolver_new(server, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, avahi_address_parse("192.168.50.1", AVAHI_PROTO_INET, &a), 0, ar_callback, NULL);
-
- db = avahi_s_domain_browser_new(server, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, NULL, AVAHI_DOMAIN_BROWSER_BROWSE, 0, db_callback, NULL);
-
- stb = avahi_s_service_type_browser_new(server, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, NULL, 0, stb_callback, NULL);
-
- sb = avahi_s_service_browser_new(server, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, "_http._tcp", NULL, 0, sb_callback, NULL);
-
- sr = avahi_s_service_resolver_new(server, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, "Ecstasy HTTP", "_http._tcp", "local", AVAHI_PROTO_UNSPEC, 0, sr_callback, NULL);
-
- dsb = avahi_s_dns_server_browser_new(server, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, "local", AVAHI_DNS_SERVER_RESOLVE, AVAHI_PROTO_UNSPEC, 0, dsb_callback, NULL);
-
- avahi_elapse_time(&tv, 1000*5, 0);
- poll_api->timeout_new(poll_api, &tv, dump_timeout_callback, server);
-
- avahi_elapse_time(&tv, 1000*60, 0);
- poll_api->timeout_new(poll_api, &tv, quit_timeout_callback, simple_poll);
-
- avahi_simple_poll_loop(simple_poll);
-
- avahi_s_record_browser_free(r);
- avahi_s_host_name_resolver_free(hnr);
- avahi_s_address_resolver_free(ar);
- avahi_s_domain_browser_free(db);
- avahi_s_service_type_browser_free(stb);
- avahi_s_service_browser_free(sb);
- avahi_s_service_resolver_free(sr);
- avahi_s_dns_server_browser_free(dsb);
-
- if (group)
- avahi_s_entry_group_free(group);
-
- if (server)
- avahi_server_free(server);
-
- if (simple_poll)
- avahi_simple_poll_free(simple_poll);
-
- avahi_free(service_name);
-
- return 0;
-}
+++ /dev/null
-/***
- This file is part of avahi.
-
- avahi is free software; you can redistribute it and/or modify it
- under the terms of the GNU Lesser General Public License as
- published by the Free Software Foundation; either version 2.1 of the
- License, or (at your option) any later version.
-
- avahi is distributed in the hope that it will be useful, but WITHOUT
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
- Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with avahi; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- USA.
-***/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdlib.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <assert.h>
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-
-#include <avahi/alternative.h>
-#include <avahi/malloc.h>
-#include <avahi/simple-watch.h>
-#include <avahi/timeval.h>
-
-#include <avahi/core.h>
-#include <avahi/log.h>
-#include <avahi/lookup.h>
-#include <avahi/publish.h>
-
-static char *name = NULL;
-static AvahiSEntryGroup *group = NULL;
-static int try = 0;
-static AvahiServer *avahi = NULL;
-static const AvahiPoll *poll_api;
-
-static void dump_line(const char *text, AVAHI_GCC_UNUSED void* userdata) {
- printf("%s\n", text);
-}
-
-static void dump_timeout_callback(AvahiTimeout *timeout, AVAHI_GCC_UNUSED void* userdata) {
- struct timeval tv;
-
- avahi_server_dump(avahi, dump_line, NULL);
-
- avahi_elapse_time(&tv, 5000, 0);
- poll_api->timeout_update(timeout, &tv);
-}
-
-static void entry_group_callback(AvahiServer *s, AvahiSEntryGroup *g, AvahiEntryGroupState state, void* userdata);
-
-static void create_service(const char *t) {
- char *n;
-
- assert(t || name);
-
- n = t ? avahi_strdup(t) : avahi_alternative_service_name(name);
- avahi_free(name);
- name = n;
-
- if (group)
- avahi_s_entry_group_reset(group);
- else
- group = avahi_s_entry_group_new(avahi, entry_group_callback, NULL);
-
- avahi_server_add_service(avahi, group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, name, "_http._tcp", NULL, NULL, 80, "foo", NULL);
- avahi_s_entry_group_commit(group);
-
- try++;
-}
-
-static void rename_timeout_callback(AvahiTimeout *timeout, AVAHI_GCC_UNUSED void *userdata) {
- struct timeval tv;
-
- if (access("flag", F_OK) == 0) {
- create_service("New - Bonjour Service Name");
- return;
- }
-
- avahi_elapse_time(&tv, 5000, 0);
- poll_api->timeout_update(timeout, &tv);
-}
-
-static void entry_group_callback(AVAHI_GCC_UNUSED AvahiServer *s, AVAHI_GCC_UNUSED AvahiSEntryGroup *g, AvahiEntryGroupState state, AVAHI_GCC_UNUSED void* userdata) {
- if (state == AVAHI_ENTRY_GROUP_COLLISION)
- create_service(NULL);
- else if (state == AVAHI_ENTRY_GROUP_ESTABLISHED) {
- avahi_log_debug("ESTABLISHED !!!!");
- try = 0;
- }
-}
-
-static void server_callback(AvahiServer *s, AvahiServerState state, AVAHI_GCC_UNUSED void* userdata) {
- avahi_log_debug("server state: %i", state);
-
- if (state == AVAHI_SERVER_RUNNING) {
- avahi_server_dump(avahi, dump_line, NULL);
- } else if (state == AVAHI_SERVER_COLLISION) {
- char *n;
-
- 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);
- avahi_free(n);
-
- }
-}
-
-int main(AVAHI_GCC_UNUSED int argc, AVAHI_GCC_UNUSED char *argv[]) {
- int error;
- AvahiSimplePoll *simple_poll;
- struct timeval tv;
- struct AvahiServerConfig config;
-
- simple_poll = avahi_simple_poll_new();
- poll_api = avahi_simple_poll_get(simple_poll);
-
- avahi_server_config_init(&config);
- config.publish_workstation = 0;
- config.use_ipv6 = 0;
- config.publish_domain = 0;
- config.publish_hinfo = 0;
- avahi = avahi_server_new(poll_api, &config, server_callback, NULL, &error);
- avahi_server_config_free(&config);
-
- avahi_elapse_time(&tv, 5000, 0);
- poll_api->timeout_new(poll_api, &tv, dump_timeout_callback, avahi);
-
- avahi_elapse_time(&tv, 5000, 0);
- poll_api->timeout_new(poll_api, &tv, rename_timeout_callback, avahi);
-
- /* Evil, but the conformace test requires that*/
- create_service("gurke");
-
-
- avahi_simple_poll_loop(simple_poll);
-
- if (group)
- avahi_s_entry_group_free(group);
- avahi_server_free(avahi);
-
- avahi_simple_poll_free(simple_poll);
-
- return 0;
-}
+++ /dev/null
-/***
- 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.
-***/
-
-/* Regression test for Avahi bug #84.
- * This program tests whether the avahi_dns_packet_consume_name function
- * returns (rather than spinning forever). For a function as simple as
- * avahi_dns_packet_consume_name, we assume that 1 second of CPU time ≈ forever
- */
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#include <string.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <signal.h>
-#include <sys/time.h>
-
-#include "dns.h"
-
-#define MAX_CPU_SECONDS 1
-
-#define TEST_NAME "dns-spin-test"
-
-static void fail(const char *fmt, ...) __attribute__((format(printf, 1, 2), noreturn));
-static void unresolved(const char *fmt, ...) __attribute__((format(printf, 1, 2), noreturn));
-static void stdlib_fail(const char *msg) __attribute__((noreturn));
-static void handle(int sig) __attribute__((noreturn));
-
-void stdlib_fail(const char *msg) {
- perror(msg);
-
- printf("UNRESOLVED: " TEST_NAME " (stdlib failure)\n");
-
- exit(77);
-}
-
-void unresolved(const char *fmt, ...) {
- va_list ap;
-
- printf("UNRESOLVED: " TEST_NAME ": ");
- va_start(ap, fmt);
- vprintf(fmt, ap);
- va_end(ap);
- printf("\n");
-
- exit(77);
-}
-
-void fail(const char *fmt, ...) {
- va_list ap;
-
- va_start(ap, fmt);
- vprintf(fmt, ap);
- va_end(ap);
- printf("\n");
-
- exit(EXIT_FAILURE);
-}
-
-void handle(AVAHI_GCC_UNUSED int sig) {
- fail("Interrupted after %d second of CPU time", MAX_CPU_SECONDS);
-}
-
-#define TRY_EXCEPT(cmd, badresult) \
- do { \
- if ((cmd) == (badresult)) \
- unresolved("%s returned %s", #cmd, #badresult); \
- } while (0)
-
-int main(AVAHI_GCC_UNUSED int argc, AVAHI_GCC_UNUSED char *argv[]) {
- struct itimerval itval;
- AvahiDnsPacket *packet;
- char name[512];
- int ret;
- uint8_t badrr[] = {
- 0xC0, AVAHI_DNS_PACKET_HEADER_SIZE, /* self-referential QNAME pointer */
- 0, 1, /* QTYPE A (host addr) */
- 0, 1, /* QCLASS IN (internet/ipv4) */
- };
-
- if (signal(SIGVTALRM, handle) == SIG_ERR)
- stdlib_fail("signal(SIGVTALRM)");
-
- memset(&itval, 0, sizeof(itval));
- itval.it_value.tv_sec = MAX_CPU_SECONDS;
-
- if (setitimer(ITIMER_VIRTUAL, &itval, NULL) == -1)
- stdlib_fail("setitimer()");
-
- TRY_EXCEPT(packet = avahi_dns_packet_new_query(512), NULL);
- TRY_EXCEPT(avahi_dns_packet_append_bytes(packet, badrr, sizeof(badrr)), NULL);
-
- /* This is expected to fail (if it returns) */
- ret = avahi_dns_packet_consume_name(packet, name, sizeof(name));
-
- if (ret != -1)
- fail("avahi_dns_packet_consume_name() returned %d; -1 was expected", ret);
-
- return EXIT_SUCCESS;
-}
-
-/* vim:ts=4:sw=4:et
- */
+++ /dev/null
-/***
- This file is part of avahi.
-
- avahi is free software; you can redistribute it and/or modify it
- under the terms of the GNU Lesser General Public License as
- published by the Free Software Foundation; either version 2.1 of the
- License, or (at your option) any later version.
-
- avahi is distributed in the hope that it will be useful, but WITHOUT
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
- Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with avahi; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- USA.
-***/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <assert.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-
-#include <avahi/domain.h>
-#include <avahi/defs.h>
-#include <avahi/malloc.h>
-
-#include "dns.h"
-#include "log.h"
-#include "util.h"
-
-int main(AVAHI_GCC_UNUSED int argc, AVAHI_GCC_UNUSED char *argv[]) {
- char t[AVAHI_DOMAIN_NAME_MAX], *m;
- const char *a, *b, *c, *d;
- AvahiDnsPacket *p;
- AvahiRecord *r, *r2;
- uint8_t rdata[AVAHI_DNS_RDATA_MAX];
- size_t l;
-
- p = avahi_dns_packet_new(0);
-
- assert(avahi_dns_packet_append_name(p, a = "Ahello.hello.hello.de."));
- assert(avahi_dns_packet_append_name(p, b = "Bthis is a test.hello.de."));
- assert(avahi_dns_packet_append_name(p, c = "Cthis\\.is\\.a\\.test\\.with\\.dots.hello.de."));
- assert(avahi_dns_packet_append_name(p, d = "Dthis\\\\is another test.hello.de."));
-
- avahi_hexdump(AVAHI_DNS_PACKET_DATA(p), p->size);
-
- assert(avahi_dns_packet_consume_name(p, t, sizeof(t)) == 0);
- avahi_log_debug(">%s<", t);
- assert(avahi_domain_equal(a, t));
-
- assert(avahi_dns_packet_consume_name(p, t, sizeof(t)) == 0);
- avahi_log_debug(">%s<", t);
- assert(avahi_domain_equal(b, t));
-
- assert(avahi_dns_packet_consume_name(p, t, sizeof(t)) == 0);
- avahi_log_debug(">%s<", t);
- assert(avahi_domain_equal(c, t));
-
- assert(avahi_dns_packet_consume_name(p, t, sizeof(t)) == 0);
- avahi_log_debug(">%s<", t);
- assert(avahi_domain_equal(d, t));
-
- avahi_dns_packet_free(p);
-
- /* RDATA PARSING AND SERIALIZATION */
-
- /* Create an AvahiRecord with some usful data */
- r = avahi_record_new_full("foobar.local", AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_HINFO, AVAHI_DEFAULT_TTL);
- assert(r);
- r->data.hinfo.cpu = avahi_strdup("FOO");
- r->data.hinfo.os = avahi_strdup("BAR");
-
- /* Serialize it into a blob */
- assert((l = avahi_rdata_serialize(r, rdata, sizeof(rdata))) != (size_t) -1);
-
- /* Print it */
- avahi_hexdump(rdata, l);
-
- /* Create a new record and fill in the data from the blob */
- r2 = avahi_record_new(r->key, AVAHI_DEFAULT_TTL);
- assert(r2);
- assert(avahi_rdata_parse(r2, rdata, l) >= 0);
-
- /* Compare both versions */
- assert(avahi_record_equal_no_ttl(r, r2));
-
- /* Free the records */
- avahi_record_unref(r);
- avahi_record_unref(r2);
-
- r = avahi_record_new_full("foobar", 77, 77, AVAHI_DEFAULT_TTL);
- assert(r);
-
- assert(r->data.generic.data = avahi_memdup("HALLO", r->data.generic.size = 5));
-
- m = avahi_record_to_string(r);
- assert(m);
-
- avahi_log_debug(">%s<", m);
-
- avahi_free(m);
- avahi_record_unref(r);
-
- return 0;
-}
+++ /dev/null
-/***
- This file is part of avahi.
-
- avahi is free software; you can redistribute it and/or modify it
- under the terms of the GNU Lesser General Public License as
- published by the Free Software Foundation; either version 2.1 of the
- License, or (at your option) any later version.
-
- avahi is distributed in the hope that it will be useful, but WITHOUT
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
- Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with avahi; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- USA.
-***/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdio.h>
-#include <string.h>
-#include <assert.h>
-
-#include "domain.h"
-#include "malloc.h"
-
-int main(AVAHI_GCC_UNUSED int argc, AVAHI_GCC_UNUSED char *argv[]) {
- char *s;
- char t[256], r[256];
- const char *p;
- size_t size;
- char name[64], type[AVAHI_DOMAIN_NAME_MAX], domain[AVAHI_DOMAIN_NAME_MAX];
-
- printf("%s\n", s = avahi_normalize_name_strdup("foo.foo\\046."));
- avahi_free(s);
-
- printf("%s\n", s = avahi_normalize_name_strdup("foo.foo\\.foo."));
- avahi_free(s);
-
-
- printf("%s\n", s = avahi_normalize_name_strdup("fo\\\\o\\..f oo."));
- avahi_free(s);
-
- printf("%i\n", avahi_domain_equal("\\065aa bbb\\.\\046cc.cc\\\\.dee.fff.", "Aaa BBB\\.\\.cc.cc\\\\.dee.fff"));
- printf("%i\n", avahi_domain_equal("A", "a"));
-
- printf("%i\n", avahi_domain_equal("a", "aaa"));
-
- printf("%u = %u\n", avahi_domain_hash("ccc\\065aa.aa\\.b\\\\."), avahi_domain_hash("cccAaa.aa\\.b\\\\"));
-
-
- avahi_service_name_join(t, sizeof(t), "foo.foo.foo \\.", "_http._tcp", "test.local");
- printf("<%s>\n", t);
-
- avahi_service_name_split(t, name, sizeof(name), type, sizeof(type), domain, sizeof(domain));
- printf("name: <%s>; type: <%s>; domain <%s>\n", name, type, domain);
-
- avahi_service_name_join(t, sizeof(t), NULL, "_http._tcp", "one.two\\. .local");
- printf("<%s>\n", t);
-
- avahi_service_name_split(t, NULL, 0, type, sizeof(type), domain, sizeof(domain));
- printf("name: <>; type: <%s>; domain <%s>\n", type, domain);
-
-
- p = "--:---\\\\\\123\\065_äöü\\064\\.\\\\sjöödfhh.sdfjhskjdf";
- printf("unescaped: <%s>, rest: %s\n", avahi_unescape_label(&p, t, sizeof(t)), p);
-
- size = sizeof(r);
- s = r;
-
- printf("escaped: <%s>\n", avahi_escape_label(t, strlen(t), &s, &size));
-
- p = r;
- printf("unescaped: <%s>\n", avahi_unescape_label(&p, t, sizeof(t)));
-
- assert(avahi_is_valid_service_type_generic("_foo._bar._waldo"));
- assert(!avahi_is_valid_service_type_strict("_foo._bar._waldo"));
- assert(!avahi_is_valid_service_subtype("_foo._bar._waldo"));
-
- assert(avahi_is_valid_service_type_generic("_foo._tcp"));
- assert(avahi_is_valid_service_type_strict("_foo._tcp"));
- assert(!avahi_is_valid_service_subtype("_foo._tcp"));
-
- assert(!avahi_is_valid_service_type_generic("_foo._bar.waldo"));
- assert(!avahi_is_valid_service_type_strict("_foo._bar.waldo"));
- assert(!avahi_is_valid_service_subtype("_foo._bar.waldo"));
-
- assert(!avahi_is_valid_service_type_generic(""));
- assert(!avahi_is_valid_service_type_strict(""));
- assert(!avahi_is_valid_service_subtype(""));
-
- assert(avahi_is_valid_service_type_generic("_foo._sub._bar._tcp"));
- assert(!avahi_is_valid_service_type_strict("_foo._sub._bar._tcp"));
- assert(avahi_is_valid_service_subtype("_foo._sub._bar._tcp"));
-
- printf("%s\n", avahi_get_type_from_subtype("_foo._sub._bar._tcp"));
-
- assert(!avahi_is_valid_host_name("sf.ooo."));
- assert(avahi_is_valid_host_name("sfooo."));
- assert(avahi_is_valid_host_name("sfooo"));
-
- assert(avahi_is_valid_domain_name("."));
- assert(avahi_is_valid_domain_name(""));
-
- assert(avahi_normalize_name(".", t, sizeof(t)));
- assert(avahi_normalize_name("", t, sizeof(t)));
-
- assert(!avahi_is_valid_fqdn("."));
- assert(!avahi_is_valid_fqdn(""));
- assert(!avahi_is_valid_fqdn("foo"));
- assert(avahi_is_valid_fqdn("foo.bar"));
- assert(avahi_is_valid_fqdn("foo.bar."));
- assert(avahi_is_valid_fqdn("gnurz.foo.bar."));
- assert(!avahi_is_valid_fqdn("192.168.50.1"));
- assert(!avahi_is_valid_fqdn("::1"));
- assert(!avahi_is_valid_fqdn(".192.168.50.1."));
-
- return 0;
-}
+++ /dev/null
-/***
- This file is part of avahi.
-
- avahi is free software; you can redistribute it and/or modify it
- under the terms of the GNU Lesser General Public License as
- published by the Free Software Foundation; either version 2.1 of the
- License, or (at your option) any later version.
-
- avahi is distributed in the hope that it will be useful, but WITHOUT
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
- Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with avahi; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- USA.
-***/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdio.h>
-
-#include <avahi/domain.h>
-#include <avahi/malloc.h>
-
-#include "hashmap.h"
-#include "util.h"
-
-int main(AVAHI_GCC_UNUSED int argc, AVAHI_GCC_UNUSED char *argv[]) {
- unsigned n;
- AvahiHashmap *m;
- const char *t;
-
- m = avahi_hashmap_new(avahi_string_hash, avahi_string_equal, avahi_free, avahi_free);
-
- avahi_hashmap_insert(m, avahi_strdup("bla"), avahi_strdup("#1"));
- avahi_hashmap_insert(m, avahi_strdup("bla2"), avahi_strdup("asdf"));
- avahi_hashmap_insert(m, avahi_strdup("gurke"), avahi_strdup("ffsdf"));
- avahi_hashmap_insert(m, avahi_strdup("blubb"), avahi_strdup("sadfsd"));
- avahi_hashmap_insert(m, avahi_strdup("bla"), avahi_strdup("#2"));
-
- for (n = 0; n < 1000; n ++)
- avahi_hashmap_insert(m, avahi_strdup_printf("key %u", n), avahi_strdup_printf("value %u", n));
-
- printf("%s\n", (const char*) avahi_hashmap_lookup(m, "bla"));
-
- avahi_hashmap_replace(m, avahi_strdup("bla"), avahi_strdup("#3"));
-
- printf("%s\n", (const char*) avahi_hashmap_lookup(m, "bla"));
-
- avahi_hashmap_remove(m, "bla");
-
- t = (const char*) avahi_hashmap_lookup(m, "bla");
- printf("%s\n", t ? t : "(null)");
-
- avahi_hashmap_free(m);
-
- return 0;
-}
+++ /dev/null
-/***
- This file is part of avahi.
-
- avahi is free software; you can redistribute it and/or modify it
- under the terms of the GNU Lesser General Public License as
- published by the Free Software Foundation; either version 2.1 of the
- License, or (at your option) any later version.
-
- avahi is distributed in the hope that it will be useful, but WITHOUT
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
- Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with avahi; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- USA.
-***/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <time.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <assert.h>
-
-#include <avahi/gccmacro.h>
-
-#include "prioq.h"
-
-#define POINTER_TO_INT(p) ((int) (long) (p))
-#define INT_TO_POINTER(i) ((void*) (long) (i))
-
-static int compare_int(const void* a, const void* b) {
- int i = POINTER_TO_INT(a), j = POINTER_TO_INT(b);
-
- return i < j ? -1 : (i > j ? 1 : 0);
-}
-
-static int compare_ptr(const void* a, const void* b) {
- return a < b ? -1 : (a > b ? 1 : 0);
-}
-
-static void rec(AvahiPrioQueueNode *n) {
- if (!n)
- return;
-
- if (n->left)
- assert(n->left->parent == n);
-
- if (n->right)
- assert(n->right->parent == n);
-
- if (n->parent) {
- assert(n->parent->left == n || n->parent->right == n);
-
- if (n->parent->left == n)
- assert(n->next == n->parent->right);
- }
-
- if (!n->next) {
- assert(n->queue->last == n);
-
- if (n->parent && n->parent->left == n)
- assert(n->parent->right == NULL);
- }
-
-
- if (n->parent) {
- int a = POINTER_TO_INT(n->parent->data), b = POINTER_TO_INT(n->data);
- if (a > b) {
- printf("%i <= %i: NO\n", a, b);
- abort();
- }
- }
-
- rec(n->left);
- rec(n->right);
-}
-
-int main(AVAHI_GCC_UNUSED int argc, AVAHI_GCC_UNUSED char *argv[]) {
- AvahiPrioQueue *q, *q2;
- int i;
-
- q = avahi_prio_queue_new(compare_int);
- q2 = avahi_prio_queue_new(compare_ptr);
-
- srand(time(NULL));
-
- for (i = 0; i < 10000; i++)
- avahi_prio_queue_put(q2, avahi_prio_queue_put(q, INT_TO_POINTER(random() & 0xFFFF)));
-
- while (q2->root) {
- rec(q->root);
- rec(q2->root);
-
- assert(q->n_nodes == q2->n_nodes);
-
- printf("%i\n", POINTER_TO_INT(((AvahiPrioQueueNode*)q2->root->data)->data));
-
- avahi_prio_queue_remove(q, q2->root->data);
- avahi_prio_queue_remove(q2, q2->root);
- }
-
-
-/* prev = 0; */
-/* while (q->root) { */
-/* int v = GPOINTER_TO_INT(q->root->data); */
-/* rec(q->root); */
-/* printf("%i\n", v); */
-/* avahi_prio_queue_remove(q, q->root); */
-/* assert(v >= prev); */
-/* prev = v; */
-/* } */
-
- avahi_prio_queue_free(q);
- return 0;
-}
+++ /dev/null
-/***
- This file is part of avahi.
-
- avahi is free software; you can redistribute it and/or modify it
- under the terms of the GNU Lesser General Public License as
- published by the Free Software Foundation; either version 2.1 of the
- License, or (at your option) any later version.
-
- avahi is distributed in the hope that it will be useful, but WITHOUT
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
- Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with avahi; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- USA.
-***/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdlib.h>
-#include <assert.h>
-
-#include <avahi/malloc.h>
-#include <avahi/simple-watch.h>
-#include <avahi/alternative.h>
-#include <avahi/timeval.h>
-
-#include <avahi/core.h>
-#include <avahi/log.h>
-#include <avahi/publish.h>
-#include <avahi/lookup.h>
-
-#define DOMAIN NULL
-#define SERVICE_TYPE "_http._tcp"
-
-static AvahiSServiceBrowser *service_browser1 = NULL, *service_browser2 = NULL;
-static const AvahiPoll * poll_api = NULL;
-static AvahiServer *server = NULL;
-static AvahiSimplePoll *simple_poll;
-
-static const char *browser_event_to_string(AvahiBrowserEvent event) {
- switch (event) {
- case AVAHI_BROWSER_NEW : return "NEW";
- case AVAHI_BROWSER_REMOVE : return "REMOVE";
- case AVAHI_BROWSER_CACHE_EXHAUSTED : return "CACHE_EXHAUSTED";
- case AVAHI_BROWSER_ALL_FOR_NOW : return "ALL_FOR_NOW";
- case AVAHI_BROWSER_FAILURE : return "FAILURE";
- }
-
- abort();
-}
-
-static void sb_callback(
- AvahiSServiceBrowser *b,
- AvahiIfIndex iface,
- AvahiProtocol protocol,
- AvahiBrowserEvent event,
- const char *name,
- const char *service_type,
- const char *domain,
- AvahiLookupResultFlags flags,
- AVAHI_GCC_UNUSED void* userdata) {
- avahi_log_debug("SB%i: (%i.%s) <%s> as <%s> in <%s> [%s] cached=%i", b == service_browser1 ? 1 : 2, iface, avahi_proto_to_string(protocol), name, service_type, domain, browser_event_to_string(event), !!(flags & AVAHI_LOOKUP_RESULT_CACHED));
-}
-
-static void create_second_service_browser(AvahiTimeout *timeout, AVAHI_GCC_UNUSED void* userdata) {
-
- service_browser2 = avahi_s_service_browser_new(server, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, SERVICE_TYPE, DOMAIN, 0, sb_callback, NULL);
- assert(service_browser2);
-
- poll_api->timeout_free(timeout);
-}
-
-static void quit(AVAHI_GCC_UNUSED AvahiTimeout *timeout, AVAHI_GCC_UNUSED void *userdata) {
- avahi_simple_poll_quit(simple_poll);
-}
-
-int main(AVAHI_GCC_UNUSED int argc, AVAHI_GCC_UNUSED char *argv[]) {
- struct timeval tv;
- AvahiServerConfig config;
-
- simple_poll = avahi_simple_poll_new();
- assert(simple_poll);
-
- poll_api = avahi_simple_poll_get(simple_poll);
- assert(poll_api);
-
- avahi_server_config_init(&config);
- config.publish_hinfo = 0;
- config.publish_addresses = 0;
- config.publish_workstation = 0;
- config.publish_domain = 0;
-
- avahi_address_parse("192.168.50.1", AVAHI_PROTO_UNSPEC, &config.wide_area_servers[0]);
- config.n_wide_area_servers = 1;
- config.enable_wide_area = 1;
-
- server = avahi_server_new(poll_api, &config, NULL, NULL, NULL);
- assert(server);
- avahi_server_config_free(&config);
-
- service_browser1 = avahi_s_service_browser_new(server, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, SERVICE_TYPE, DOMAIN, 0, sb_callback, NULL);
- assert(service_browser1);
-
- poll_api->timeout_new(poll_api, avahi_elapse_time(&tv, 10000, 0), create_second_service_browser, NULL);
-
- poll_api->timeout_new(poll_api, avahi_elapse_time(&tv, 60000, 0), quit, NULL);
-
-
- for (;;)
- if (avahi_simple_poll_iterate(simple_poll, -1) != 0)
- break;
-
- avahi_server_free(server);
- avahi_simple_poll_free(simple_poll);
-
- return 0;
-}
+++ /dev/null
-/***
- This file is part of avahi.
-
- avahi is free software; you can redistribute it and/or modify it
- under the terms of the GNU Lesser General Public License as
- published by the Free Software Foundation; either version 2.1 of the
- License, or (at your option) any later version.
-
- avahi is distributed in the hope that it will be useful, but WITHOUT
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
- Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with avahi; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- USA.
-***/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdio.h>
-#include <assert.h>
-
-#include "strlst.h"
-#include "malloc.h"
-
-int main(AVAHI_GCC_UNUSED int argc, AVAHI_GCC_UNUSED char *argv[]) {
- char *t, *v;
- uint8_t data[1024];
- AvahiStringList *a = NULL, *b, *p;
- size_t size, n;
- int r;
-
- a = avahi_string_list_new("prefix", "a", "b", NULL);
-
- a = avahi_string_list_add(a, "start");
- a = avahi_string_list_add(a, "foo=99");
- a = avahi_string_list_add(a, "bar");
- a = avahi_string_list_add(a, "");
- a = avahi_string_list_add(a, "");
- a = avahi_string_list_add(a, "quux");
- a = avahi_string_list_add(a, "");
- a = avahi_string_list_add_arbitrary(a, (const uint8_t*) "null\0null", 9);
- a = avahi_string_list_add_printf(a, "seven=%i %c", 7, 'x');
- a = avahi_string_list_add_pair(a, "blubb", "blaa");
- a = avahi_string_list_add_pair(a, "uxknurz", NULL);
- a = avahi_string_list_add_pair_arbitrary(a, "uxknurz2", (const uint8_t*) "blafasel\0oerks", 14);
-
- a = avahi_string_list_add(a, "end");
-
- t = avahi_string_list_to_string(a);
- printf("--%s--\n", t);
- avahi_free(t);
-
- n = avahi_string_list_serialize(a, NULL, 0);
- size = avahi_string_list_serialize(a, data, sizeof(data));
- assert(size == n);
-
- printf("%zu\n", size);
-
- for (t = (char*) data, n = 0; n < size; n++, t++) {
- if (*t <= 32)
- printf("(%u)", *t);
- else
- printf("%c", *t);
- }
-
- printf("\n");
-
- assert(avahi_string_list_parse(data, size, &b) == 0);
-
- printf("equal: %i\n", avahi_string_list_equal(a, b));
-
- t = avahi_string_list_to_string(b);
- printf("--%s--\n", t);
- avahi_free(t);
-
- avahi_string_list_free(b);
-
- b = avahi_string_list_copy(a);
-
- assert(avahi_string_list_equal(a, b));
-
- t = avahi_string_list_to_string(b);
- printf("--%s--\n", t);
- avahi_free(t);
-
- p = avahi_string_list_find(a, "seven");
- assert(p);
-
- r = avahi_string_list_get_pair(p, &t, &v, NULL);
- assert(r >= 0);
- assert(t);
- assert(v);
-
- printf("<%s>=<%s>\n", t, v);
- avahi_free(t);
- avahi_free(v);
-
- p = avahi_string_list_find(a, "quux");
- assert(p);
-
- r = avahi_string_list_get_pair(p, &t, &v, NULL);
- assert(r >= 0);
- assert(t);
- assert(!v);
-
- printf("<%s>=<%s>\n", t, v);
- avahi_free(t);
- avahi_free(v);
-
- avahi_string_list_free(a);
- avahi_string_list_free(b);
-
- n = avahi_string_list_serialize(NULL, NULL, 0);
- size = avahi_string_list_serialize(NULL, data, sizeof(data));
- assert(size == 1);
- assert(size == n);
-
- assert(avahi_string_list_parse(data, size, &a) == 0);
- assert(!a);
-
- return 0;
-}
+++ /dev/null
-/***
- This file is part of avahi.
-
- avahi is free software; you can redistribute it and/or modify it
- under the terms of the GNU Lesser General Public License as
- published by the Free Software Foundation; either version 2.1 of the
- License, or (at your option) any later version.
-
- avahi is distributed in the hope that it will be useful, but WITHOUT
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
- Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with avahi; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- USA.
-***/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <assert.h>
-#include <stdlib.h>
-
-#include <avahi/timeval.h>
-#include <avahi/simple-watch.h>
-
-#include "timeeventq.h"
-#include "log.h"
-
-#define POINTER_TO_INT(p) ((int) (long) (p))
-#define INT_TO_POINTER(i) ((void*) (long) (i))
-
-static AvahiTimeEventQueue *q = NULL;
-
-static void callback(AvahiTimeEvent*e, void* userdata) {
- struct timeval tv = {0, 0};
- assert(e);
- avahi_log_info("callback(%i)", POINTER_TO_INT(userdata));
- avahi_elapse_time(&tv, 1000, 100);
- avahi_time_event_update(e, &tv);
-}
-
-int main(AVAHI_GCC_UNUSED int argc, AVAHI_GCC_UNUSED char *argv[]) {
- struct timeval tv;
- AvahiSimplePoll *s;
-
- s = avahi_simple_poll_new();
-
- q = avahi_time_event_queue_new(avahi_simple_poll_get(s));
-
- avahi_time_event_new(q, avahi_elapse_time(&tv, 5000, 100), callback, INT_TO_POINTER(1));
- avahi_time_event_new(q, avahi_elapse_time(&tv, 5000, 100), callback, INT_TO_POINTER(2));
-
- avahi_log_info("starting");
-
- for (;;)
- if (avahi_simple_poll_iterate(s, -1) != 0)
- break;
-
- avahi_time_event_queue_free(q);
- avahi_simple_poll_free(s);
-
- return 0;
-}
+++ /dev/null
-/***
- This file is part of avahi.
-
- avahi is free software; you can redistribute it and/or modify it
- under the terms of the GNU Lesser General Public License as
- published by the Free Software Foundation; either version 2.1 of the
- License, or (at your option) any later version.
-
- avahi is distributed in the hope that it will be useful, but WITHOUT
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
- Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with avahi; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- USA.
-***/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdio.h>
-
-#include "gccmacro.h"
-#include "timeval.h"
-
-int main(AVAHI_GCC_UNUSED int argc, AVAHI_GCC_UNUSED char *argv[]) {
-
- struct timeval a = { 5, 5 }, b;
-
- b = a;
-
- printf("%li.%li\n", a.tv_sec, a.tv_usec);
- avahi_timeval_add(&a, -50);
-
- printf("%li.%li\n", a.tv_sec, a.tv_usec);
-
- printf("%lli\n", (long long) avahi_timeval_diff(&a, &b));
-
- return 0;
-}
+++ /dev/null
-/***
- This file is part of avahi.
-
- avahi is free software; you can redistribute it and/or modify it
- under the terms of the GNU Lesser General Public License as
- published by the Free Software Foundation; either version 2.1 of the
- License, or (at your option) any later version.
-
- avahi is distributed in the hope that it will be useful, but WITHOUT
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
- Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with avahi; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- USA.
-***/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <assert.h>
-#include <stdlib.h>
-
-#include <avahi/error.h>
-#include <avahi/watch.h>
-#include <avahi/simple-watch.h>
-#include <avahi/malloc.h>
-#include <avahi/alternative.h>
-#include <avahi/timeval.h>
-
-#include <avahi/core.h>
-#include <avahi/log.h>
-#include <avahi/publish.h>
-#include <avahi/lookup.h>
-
-static AvahiSEntryGroup *group = NULL;
-
-static void server_callback(AvahiServer *s, AvahiServerState state, AVAHI_GCC_UNUSED void* userdata) {
-
- avahi_log_debug("server state: %i", state);
-
- if (state == AVAHI_SERVER_RUNNING) {
- int ret;
-
- group = avahi_s_entry_group_new(s, NULL, NULL);
- assert(group);
-
- ret = avahi_server_add_service(s, group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, "foo", "_http._tcp", NULL, NULL, 80, "test1", NULL);
- assert(ret == AVAHI_OK);
-
- avahi_s_entry_group_commit(group);
- }
-}
-
-static void modify_txt_callback(AVAHI_GCC_UNUSED AvahiTimeout *e, void *userdata) {
- int ret;
- AvahiServer *s = userdata;
-
- avahi_log_debug("modifying");
-
- ret = avahi_server_update_service_txt(s, group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, "foo", "_http._tcp", NULL, "test2", NULL);
- assert(ret == AVAHI_OK);
-}
-
-int main(AVAHI_GCC_UNUSED int argc, AVAHI_GCC_UNUSED char *argv[]) {
- AvahiSimplePoll *simple_poll;
- const AvahiPoll *poll_api;
- AvahiServer *server;
- struct timeval tv;
- AvahiServerConfig config;
-
- simple_poll = avahi_simple_poll_new();
- assert(simple_poll);
-
- poll_api = avahi_simple_poll_get(simple_poll);
- assert(poll_api);
-
- avahi_server_config_init(&config);
- config.publish_domain = config.publish_workstation = config.use_ipv6 = config.publish_hinfo = 0;
- server = avahi_server_new(poll_api, &config, server_callback, NULL, NULL);
- assert(server);
- avahi_server_config_free(&config);
-
- poll_api->timeout_new(poll_api, avahi_elapse_time(&tv, 1000*10, 0), modify_txt_callback, server);
-
- avahi_simple_poll_loop(simple_poll);
- return 0;
-}
+++ /dev/null
-/***
- This file is part of avahi.
-
- avahi is free software; you can redistribute it and/or modify it
- under the terms of the GNU Lesser General Public License as
- published by the Free Software Foundation; either version 2.1 of the
- License, or (at your option) any later version.
-
- avahi is distributed in the hope that it will be useful, but WITHOUT
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
- Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with avahi; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- USA.
-***/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <assert.h>
-
-#include <avahi/gccmacro.h>
-
-#include "utf8.h"
-
-int main(AVAHI_GCC_UNUSED int argc, AVAHI_GCC_UNUSED char *argv[]) {
-
- assert(avahi_utf8_valid("hallo"));
- assert(!avahi_utf8_valid("üxknürz"));
- assert(avahi_utf8_valid("üxknürz"));
-
- return 0;
-}
+++ /dev/null
-/***
- This file is part of avahi.
-
- avahi is free software; you can redistribute it and/or modify it
- under the terms of the GNU Lesser General Public License as
- published by the Free Software Foundation; either version 2.1 of the
- License, or (at your option) any later version.
-
- avahi is distributed in the hope that it will be useful, but WITHOUT
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
- Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with avahi; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- USA.
-***/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdio.h>
-#include <unistd.h>
-#include <assert.h>
-#include <errno.h>
-#include <string.h>
-
-#include "watch.h"
-#include "timeval.h"
-#include "gccmacro.h"
-
-static const AvahiPoll *api = NULL;
-
-#ifndef USE_THREAD
-#include "simple-watch.h"
-static AvahiSimplePoll *simple_poll = NULL;
-#else
-#include "thread-watch.h"
-static AvahiThreadedPoll *threaded_poll = NULL;
-#endif
-
-static void callback(AvahiWatch *w, int fd, AvahiWatchEvent event, AVAHI_GCC_UNUSED void *userdata) {
-
- if (event & AVAHI_WATCH_IN) {
- ssize_t r;
- char c;
-
- if ((r = read(fd, &c, 1)) <= 0) {
- fprintf(stderr, "read() failed: %s\n", r < 0 ? strerror(errno) : "EOF");
- api->watch_free(w);
- return;
- }
-
- printf("Read: %c\n", c >= 32 && c < 127 ? c : '.');
- }
-}
-
-static void wakeup(AvahiTimeout *t, AVAHI_GCC_UNUSED void *userdata) {
- static int i = 0;
- struct timeval tv;
-
- printf("Wakeup #%i\n", i++);
-
- if (i > 10) {
-#ifndef USE_THREAD
- avahi_simple_poll_quit(simple_poll);
-#else
- avahi_threaded_poll_quit(threaded_poll);
-#endif
- } else {
- avahi_elapse_time(&tv, 1000, 0);
- api->timeout_update(t, &tv);
- }
-}
-
-int main(AVAHI_GCC_UNUSED int argc, AVAHI_GCC_UNUSED char *argv[]) {
- struct timeval tv;
-
-#ifndef USE_THREAD
- simple_poll = avahi_simple_poll_new();
- assert(simple_poll);
- api = avahi_simple_poll_get(simple_poll);
- assert(api);
-#else
- threaded_poll = avahi_threaded_poll_new();
- assert(threaded_poll);
- api = avahi_threaded_poll_get(threaded_poll);
- assert(api);
-#endif
-
- api->watch_new(api, 0, AVAHI_WATCH_IN, callback, NULL);
-
- avahi_elapse_time(&tv, 1000, 0);
- api->timeout_new(api, &tv, wakeup, NULL);
-
-#ifndef USE_THREAD
- /* Our main loop */
- avahi_simple_poll_loop(simple_poll);
- avahi_simple_poll_free(simple_poll);
-
-#else
- avahi_threaded_poll_start(threaded_poll);
-
- fprintf(stderr, "Now doing some stupid stuff ...\n");
- sleep(20);
- fprintf(stderr, "... stupid stuff is done.\n");
-
- avahi_threaded_poll_free(threaded_poll);
-
-#endif
-
- return 0;
-}
AC_CONFIG_FILES([
Makefile
avahi/Makefile
+tests/Makefile
examples/Makefile
common/Makefile
])
-*.o
-*.lo
-*.la
-Makefile
-Makefile.in
-.deps
-.libs
-client-browse-services
-client-publish-service
core-browse-services
core-publish-service
-glib-integration
--- /dev/null
+alternative-test
+domain-test
+strlst-test
+timeval-test
+utf8-test
+watch-test
+watch-test-thread
+avahi-reflector
+avahi-test
+conformance-test
+dns-spin-test
+dns-test
+hashmap-test
+prioq-test
+querier-test
+timeeventq-test
+update-test
+*-test.log
+*-test.trs
+test-suite.log
--- /dev/null
+# This file is part of avahi.
+#
+# avahi is free software; you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License as
+# published by the Free Software Foundation; either version 2 of the
+# License, or (at your option) any later version.
+#
+# avahi is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+# License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with avahi; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+# USA.
+
+AM_CFLAGS=-I$(top_srcdir)
+AM_LDADD=$(top_srcdir)/avahi/libavahi.la
+
+# This cool debug trap works on i386/gcc only
+AM_CFLAGS+='-DDEBUG_TRAP=__asm__("int $$3")'
+
+if ENABLE_TESTS
+noinst_PROGRAMS = \
+ strlst-test \
+ domain-test \
+ alternative-test \
+ timeval-test \
+ watch-test \
+ watch-test-thread \
+ utf8-test \
+ prioq-test \
+ avahi-test \
+ conformance-test \
+ avahi-reflector \
+ dns-test \
+ dns-spin-test \
+ timeeventq-test \
+ hashmap-test \
+ querier-test \
+ update-test
+
+TESTS = \
+ dns-spin-test \
+ dns-test \
+ hashmap-test
+endif
+
+
+strlst_test_SOURCES = strlst-test.c
+strlst_test_CFLAGS = $(AM_CFLAGS)
+strlst_test_LDADD = $(AM_LDADD)
+
+alternative_test_SOURCES = alternative-test.c
+alternative_test_CFLAGS = $(AM_CFLAGS)
+alternative_test_LDADD = $(AM_LDADD)
+
+domain_test_SOURCES = domain-test.c
+domain_test_CFLAGS = $(AM_CFLAGS)
+domain_test_LDADD = $(AM_LDADD)
+
+watch_test_SOURCES = watch-test.c
+watch_test_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
+watch_test_LDADD = $(AM_LDADD) $(PTHREAD_LIBS) $(PTHREAD_CFLAGS)
+
+watch_test_thread_SOURCES = $(watch_test_SOURCES)
+watch_test_thread_CFLAGS = $(watch_test_CFLAGS) -DUSE_THREAD
+watch_test_thread_LDADD = $(watch_test_LDADD)
+
+timeval_test_SOURCES = timeval-test.c
+timeval_test_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS)
+timeval_test_LDADD = $(AM_LDADD) $(PTHREAD_LIBS) $(PTHREAD_CFLAGS)
+
+utf8_test_SOURCES = utf8-test.c
+utf8_test_CFLAGS = $(AM_CFLAGS)
+utf8_test_LDADD = $(AM_LDADD)
+
+prioq_test_SOURCES = prioq-test.c
+prioq_test_CFLAGS = $(AM_CFLAGS)
+prioq_test_LDADD = $(AM_LDADD)
+
+avahi_test_SOURCES = avahi-test.c
+avahi_test_CFLAGS = $(AM_CFLAGS)
+avahi_test_LDADD = $(AM_LDADD)
+
+update_test_SOURCES = update-test.c
+update_test_CFLAGS = $(AM_CFLAGS)
+update_test_LDADD = $(AM_LDADD)
+
+querier_test_SOURCES = querier-test.c
+querier_test_CFLAGS = $(AM_CFLAGS)
+querier_test_LDADD = $(AM_LDADD)
+
+conformance_test_SOURCES = conformance-test.c
+conformance_test_CFLAGS = $(AM_CFLAGS)
+conformance_test_LDADD = $(AM_LDADD)
+
+avahi_reflector_SOURCES = avahi-reflector.c
+avahi_reflector_CFLAGS = $(AM_CFLAGS)
+avahi_reflector_LDADD = $(AM_LDADD)
+
+dns_test_SOURCES = dns-test.c
+dns_test_CFLAGS = $(AM_CFLAGS)
+dns_test_LDADD = $(AM_LDADD)
+
+dns_spin_test_SOURCES = dns-spin-test.c
+dns_spin_test_CFLAGS = $(AM_CFLAGS)
+dns_spin_test_LDADD = $(AM_LDADD)
+
+timeeventq_test_SOURCES = timeeventq-test.c
+timeeventq_test_CFLAGS = $(AM_CFLAGS)
+timeeventq_test_LDADD = $(AM_LDADD)
+
+hashmap_test_SOURCES = hashmap-test.c
+hashmap_test_CFLAGS = $(AM_CFLAGS)
+hashmap_test_LDADD = $(AM_LDADD)
+
+valgrind: avahi-test
+ libtool --mode=execute valgrind ./avahi-test
+
+gdb: avahi-test
+ libtool --mode=execute gdb ./avahi-test
--- /dev/null
+/***
+ This file is part of avahi.
+
+ avahi is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of the
+ License, or (at your option) any later version.
+
+ avahi is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
+ Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with avahi; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+
+#include <avahi/alternative.h>
+#include <avahi/malloc.h>
+#include <avahi/domain.h>
+
+int main(AVAHI_GCC_UNUSED int argc, AVAHI_GCC_UNUSED char *argv[]) {
+ const char* const test_strings[] = {
+ "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
+ "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXüüüüüüü",
+ "gurke",
+ "-",
+ " #",
+ "1",
+ "#0",
+ " #0",
+ " #1",
+ "#-1",
+ " #-1",
+ "-0",
+ "--0",
+ "-1",
+ "--1",
+ "-2",
+ "gurke1",
+ "gurke0",
+ "gurke-2",
+ "gurke #0",
+ "gurke #1",
+ "gurke #",
+ "gurke#1",
+ "gurke-",
+ "gurke---",
+ "gurke #",
+ "gurke ###",
+ NULL
+ };
+
+ char *r = NULL;
+ int i, j, k;
+
+ for (k = 0; test_strings[k]; k++) {
+
+ printf(">>>>>%s<<<<\n", test_strings[k]);
+
+ for (j = 0; j < 2; j++) {
+
+ for (i = 0; i <= 100; i++) {
+ char *n;
+
+ n = i == 0 ? avahi_strdup(test_strings[k]) : (j ? avahi_alternative_service_name(r) : avahi_alternative_host_name(r));
+ avahi_free(r);
+ r = n;
+
+ if (j)
+ assert(avahi_is_valid_service_name(n));
+ else
+ assert(avahi_is_valid_host_name(n));
+
+ printf("%s\n", r);
+ }
+ }
+ }
+
+ avahi_free(r);
+ return 0;
+}
--- /dev/null
+/***
+ This file is part of avahi.
+
+ avahi is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of the
+ License, or (at your option) any later version.
+
+ avahi is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
+ Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with avahi; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdlib.h>
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#include <avahi/simple-watch.h>
+#include <avahi/core.h>
+
+int main(AVAHI_GCC_UNUSED int argc, AVAHI_GCC_UNUSED char*argv[]) {
+ AvahiServer *server;
+ AvahiServerConfig config;
+ int error;
+ AvahiSimplePoll *simple_poll;
+
+ simple_poll = avahi_simple_poll_new();
+
+ avahi_server_config_init(&config);
+ config.publish_hinfo = 0;
+ config.publish_addresses = 0;
+ config.publish_workstation = 0;
+ config.publish_domain = 0;
+ config.use_ipv6 = 0;
+ config.enable_reflector = 1;
+
+ server = avahi_server_new(avahi_simple_poll_get(simple_poll), &config, NULL, NULL, &error);
+ avahi_server_config_free(&config);
+
+ for (;;)
+ if (avahi_simple_poll_iterate(simple_poll, -1) != 0)
+ break;
+
+ avahi_server_free(server);
+ avahi_simple_poll_free(simple_poll);
+
+ return 0;
+}
--- /dev/null
+/***
+ This file is part of avahi.
+
+ avahi is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of the
+ License, or (at your option) any later version.
+
+ avahi is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
+ Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with avahi; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <assert.h>
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#include <avahi/malloc.h>
+#include <avahi/simple-watch.h>
+#include <avahi/alternative.h>
+#include <avahi/timeval.h>
+
+#include <avahi/core.h>
+#include <avahi/log.h>
+#include <avahi/publish.h>
+#include <avahi/lookup.h>
+#include <avahi/dns-srv-rr.h>
+
+static AvahiSEntryGroup *group = NULL;
+static AvahiServer *server = NULL;
+static char *service_name = NULL;
+
+static const AvahiPoll *poll_api;
+
+static void quit_timeout_callback(AVAHI_GCC_UNUSED AvahiTimeout *timeout, void* userdata) {
+ AvahiSimplePoll *simple_poll = userdata;
+
+ avahi_simple_poll_quit(simple_poll);
+}
+
+static void dump_line(const char *text, AVAHI_GCC_UNUSED void* userdata) {
+ printf("%s\n", text);
+}
+
+static void dump_timeout_callback(AvahiTimeout *timeout, void* userdata) {
+ struct timeval tv;
+
+ AvahiServer *avahi = userdata;
+ avahi_server_dump(avahi, dump_line, NULL);
+
+ avahi_elapse_time(&tv, 5000, 0);
+ poll_api->timeout_update(timeout, &tv);
+}
+
+static const char *browser_event_to_string(AvahiBrowserEvent event) {
+ switch (event) {
+ case AVAHI_BROWSER_NEW : return "NEW";
+ case AVAHI_BROWSER_REMOVE : return "REMOVE";
+ case AVAHI_BROWSER_CACHE_EXHAUSTED : return "CACHE_EXHAUSTED";
+ case AVAHI_BROWSER_ALL_FOR_NOW : return "ALL_FOR_NOW";
+ case AVAHI_BROWSER_FAILURE : return "FAILURE";
+ }
+
+ abort();
+}
+
+static const char *resolver_event_to_string(AvahiResolverEvent event) {
+ switch (event) {
+ case AVAHI_RESOLVER_FOUND: return "FOUND";
+ case AVAHI_RESOLVER_FAILURE: return "FAILURE";
+ }
+ abort();
+}
+
+static void record_browser_callback(
+ AvahiSRecordBrowser *r,
+ AvahiIfIndex interface,
+ AvahiProtocol protocol,
+ AvahiBrowserEvent event,
+ AvahiRecord *record,
+ AVAHI_GCC_UNUSED AvahiLookupResultFlags flags,
+ AVAHI_GCC_UNUSED void* userdata) {
+ char *t;
+
+ assert(r);
+
+ if (record) {
+ avahi_log_debug("RB: record [%s] on %i.%i is %s", t = avahi_record_to_string(record), interface, protocol, browser_event_to_string(event));
+ avahi_free(t);
+ } else
+ avahi_log_debug("RB: [%s]", browser_event_to_string(event));
+
+}
+
+static void remove_entries(void);
+static void create_entries(int new_name);
+
+static void entry_group_callback(AVAHI_GCC_UNUSED AvahiServer *s, AVAHI_GCC_UNUSED AvahiSEntryGroup *g, AvahiEntryGroupState state, AVAHI_GCC_UNUSED void* userdata) {
+ avahi_log_debug("entry group state: %i", state);
+
+ if (state == AVAHI_ENTRY_GROUP_COLLISION) {
+ remove_entries();
+ create_entries(1);
+ avahi_log_debug("Service name conflict, retrying with <%s>", service_name);
+ } else if (state == AVAHI_ENTRY_GROUP_ESTABLISHED) {
+ avahi_log_debug("Service established under name <%s>", service_name);
+ }
+}
+
+static void server_callback(AvahiServer *s, AvahiServerState state, AVAHI_GCC_UNUSED void* userdata) {
+
+ server = s;
+ avahi_log_debug("server state: %i", state);
+
+ if (state == AVAHI_SERVER_RUNNING) {
+ avahi_log_debug("Server startup complete. Host name is <%s>. Service cookie is %u", avahi_server_get_host_name_fqdn(s), avahi_server_get_local_service_cookie(s));
+ create_entries(0);
+ } else if (state == AVAHI_SERVER_COLLISION) {
+ char *n;
+ remove_entries();
+
+ n = avahi_alternative_host_name(avahi_server_get_host_name(s));
+
+ avahi_log_debug("Host name conflict, retrying with <%s>", n);
+ avahi_server_set_host_name(s, n);
+ avahi_free(n);
+ }
+}
+
+static void remove_entries(void) {
+ if (group)
+ avahi_s_entry_group_reset(group);
+}
+
+static void create_entries(int new_name) {
+ AvahiAddress a;
+ AvahiRecord *r;
+
+ remove_entries();
+
+ if (!group)
+ group = avahi_s_entry_group_new(server, entry_group_callback, NULL);
+
+ assert(avahi_s_entry_group_is_empty(group));
+
+ if (!service_name)
+ service_name = avahi_strdup("Test Service");
+ else if (new_name) {
+ char *n = avahi_alternative_service_name(service_name);
+ avahi_free(service_name);
+ service_name = n;
+ }
+
+ if (avahi_server_add_service(server, group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, service_name, "_http._tcp", NULL, NULL, 80, "foo", NULL) < 0) {
+ avahi_log_error("Failed to add HTTP service");
+ goto fail;
+ }
+
+ if (avahi_server_add_service(server, group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, service_name, "_ftp._tcp", NULL, NULL, 21, "foo", NULL) < 0) {
+ avahi_log_error("Failed to add FTP service");
+ goto fail;
+ }
+
+ if (avahi_server_add_service(server, group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0,service_name, "_webdav._tcp", NULL, NULL, 80, "foo", NULL) < 0) {
+ avahi_log_error("Failed to add WEBDAV service");
+ goto fail;
+ }
+
+ if (avahi_server_add_dns_server_address(server, group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, NULL, AVAHI_DNS_SERVER_RESOLVE, avahi_address_parse("192.168.50.1", AVAHI_PROTO_UNSPEC, &a), 53) < 0) {
+ avahi_log_error("Failed to add new DNS Server address");
+ goto fail;
+ }
+
+ r = avahi_record_new_full("cname.local", AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_CNAME, AVAHI_DEFAULT_TTL);
+ r->data.cname.name = avahi_strdup("cocaine.local");
+
+ if (avahi_server_add(server, group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, r) < 0) {
+ avahi_record_unref(r);
+ avahi_log_error("Failed to add CNAME record");
+ goto fail;
+ }
+ avahi_record_unref(r);
+
+ avahi_s_entry_group_commit(group);
+ return;
+
+fail:
+ if (group)
+ avahi_s_entry_group_free(group);
+
+ group = NULL;
+}
+
+static void hnr_callback(
+ AVAHI_GCC_UNUSED AvahiSHostNameResolver *r,
+ AvahiIfIndex iface,
+ AvahiProtocol protocol,
+ AvahiResolverEvent event,
+ const char *hostname,
+ const AvahiAddress *a,
+ AVAHI_GCC_UNUSED AvahiLookupResultFlags flags,
+ AVAHI_GCC_UNUSED void* userdata) {
+ char t[AVAHI_ADDRESS_STR_MAX];
+
+ if (a)
+ avahi_address_snprint(t, sizeof(t), a);
+
+ avahi_log_debug("HNR: (%i.%i) <%s> -> %s [%s]", iface, protocol, hostname, a ? t : "n/a", resolver_event_to_string(event));
+}
+
+static void ar_callback(
+ AVAHI_GCC_UNUSED AvahiSAddressResolver *r,
+ AvahiIfIndex iface,
+ AvahiProtocol protocol,
+ AvahiResolverEvent event,
+ const AvahiAddress *a,
+ const char *hostname,
+ AVAHI_GCC_UNUSED AvahiLookupResultFlags flags,
+ AVAHI_GCC_UNUSED void* userdata) {
+ char t[AVAHI_ADDRESS_STR_MAX];
+
+ avahi_address_snprint(t, sizeof(t), a);
+
+ avahi_log_debug("AR: (%i.%i) %s -> <%s> [%s]", iface, protocol, t, hostname ? hostname : "n/a", resolver_event_to_string(event));
+}
+
+static void db_callback(
+ AVAHI_GCC_UNUSED AvahiSDomainBrowser *b,
+ AvahiIfIndex iface,
+ AvahiProtocol protocol,
+ AvahiBrowserEvent event,
+ const char *domain,
+ AVAHI_GCC_UNUSED AvahiLookupResultFlags flags,
+ AVAHI_GCC_UNUSED void* userdata) {
+
+ avahi_log_debug("DB: (%i.%i) <%s> [%s]", iface, protocol, domain ? domain : "NULL", browser_event_to_string(event));
+}
+
+static void stb_callback(
+ AVAHI_GCC_UNUSED AvahiSServiceTypeBrowser *b,
+ AvahiIfIndex iface,
+ AvahiProtocol protocol,
+ AvahiBrowserEvent event,
+ const char *service_type,
+ const char *domain,
+ AVAHI_GCC_UNUSED AvahiLookupResultFlags flags,
+ AVAHI_GCC_UNUSED void* userdata) {
+
+ avahi_log_debug("STB: (%i.%i) %s in <%s> [%s]", iface, protocol, service_type ? service_type : "NULL", domain ? domain : "NULL", browser_event_to_string(event));
+}
+
+static void sb_callback(
+ AVAHI_GCC_UNUSED AvahiSServiceBrowser *b,
+ AvahiIfIndex iface,
+ AvahiProtocol protocol,
+ AvahiBrowserEvent event,
+ const char *name,
+ const char *service_type,
+ const char *domain,
+ AVAHI_GCC_UNUSED AvahiLookupResultFlags flags,
+ AVAHI_GCC_UNUSED void* userdata) {
+ avahi_log_debug("SB: (%i.%i) <%s> as %s in <%s> [%s]", iface, protocol, name ? name : "NULL", service_type ? service_type : "NULL", domain ? domain : "NULL", browser_event_to_string(event));
+}
+
+static void sr_callback(
+ AVAHI_GCC_UNUSED AvahiSServiceResolver *r,
+ AvahiIfIndex iface,
+ AvahiProtocol protocol,
+ AvahiResolverEvent event,
+ const char *name,
+ const char*service_type,
+ const char*domain_name,
+ const char*hostname,
+ const AvahiAddress *a,
+ uint16_t port,
+ AvahiStringList *txt,
+ AVAHI_GCC_UNUSED AvahiLookupResultFlags flags,
+ AVAHI_GCC_UNUSED void* userdata) {
+
+ if (event != AVAHI_RESOLVER_FOUND)
+ avahi_log_debug("SR: (%i.%i) <%s> as %s in <%s> [%s]", iface, protocol, name, service_type, domain_name, resolver_event_to_string(event));
+ else {
+ char t[AVAHI_ADDRESS_STR_MAX], *s;
+
+ avahi_address_snprint(t, sizeof(t), a);
+
+ s = avahi_string_list_to_string(txt);
+ avahi_log_debug("SR: (%i.%i) <%s> as %s in <%s>: %s/%s:%i (%s) [%s]", iface, protocol, name, service_type, domain_name, hostname, t, port, s, resolver_event_to_string(event));
+ avahi_free(s);
+ }
+}
+
+static void dsb_callback(
+ AVAHI_GCC_UNUSED AvahiSDNSServerBrowser *b,
+ AvahiIfIndex iface,
+ AvahiProtocol protocol,
+ AvahiBrowserEvent event,
+ const char*hostname,
+ const AvahiAddress *a,
+ uint16_t port,
+ AVAHI_GCC_UNUSED AvahiLookupResultFlags flags,
+ AVAHI_GCC_UNUSED void* userdata) {
+
+ char t[AVAHI_ADDRESS_STR_MAX] = "n/a";
+
+ if (a)
+ avahi_address_snprint(t, sizeof(t), a);
+
+ avahi_log_debug("DSB: (%i.%i): %s/%s:%i [%s]", iface, protocol, hostname ? hostname : "NULL", t, port, browser_event_to_string(event));
+}
+
+int main(AVAHI_GCC_UNUSED int argc, AVAHI_GCC_UNUSED char *argv[]) {
+ AvahiSRecordBrowser *r;
+ AvahiSHostNameResolver *hnr;
+ AvahiSAddressResolver *ar;
+ AvahiKey *k;
+ AvahiServerConfig config;
+ AvahiAddress a;
+ AvahiSDomainBrowser *db;
+ AvahiSServiceTypeBrowser *stb;
+ AvahiSServiceBrowser *sb;
+ AvahiSServiceResolver *sr;
+ AvahiSDNSServerBrowser *dsb;
+ AvahiSimplePoll *simple_poll;
+ int error;
+ struct timeval tv;
+
+ simple_poll = avahi_simple_poll_new();
+ poll_api = avahi_simple_poll_get(simple_poll);
+
+ avahi_server_config_init(&config);
+
+ avahi_address_parse("192.168.50.1", AVAHI_PROTO_UNSPEC, &config.wide_area_servers[0]);
+ config.n_wide_area_servers = 1;
+ config.enable_wide_area = 1;
+
+ server = avahi_server_new(poll_api, &config, server_callback, NULL, &error);
+ avahi_server_config_free(&config);
+
+ k = avahi_key_new("_http._tcp.0pointer.de", AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_PTR);
+ r = avahi_s_record_browser_new(server, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, k, 0, record_browser_callback, NULL);
+ avahi_key_unref(k);
+
+ hnr = avahi_s_host_name_resolver_new(server, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, "cname.local", AVAHI_PROTO_UNSPEC, 0, hnr_callback, NULL);
+
+ ar = avahi_s_address_resolver_new(server, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, avahi_address_parse("192.168.50.1", AVAHI_PROTO_INET, &a), 0, ar_callback, NULL);
+
+ db = avahi_s_domain_browser_new(server, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, NULL, AVAHI_DOMAIN_BROWSER_BROWSE, 0, db_callback, NULL);
+
+ stb = avahi_s_service_type_browser_new(server, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, NULL, 0, stb_callback, NULL);
+
+ sb = avahi_s_service_browser_new(server, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, "_http._tcp", NULL, 0, sb_callback, NULL);
+
+ sr = avahi_s_service_resolver_new(server, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, "Ecstasy HTTP", "_http._tcp", "local", AVAHI_PROTO_UNSPEC, 0, sr_callback, NULL);
+
+ dsb = avahi_s_dns_server_browser_new(server, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, "local", AVAHI_DNS_SERVER_RESOLVE, AVAHI_PROTO_UNSPEC, 0, dsb_callback, NULL);
+
+ avahi_elapse_time(&tv, 1000*5, 0);
+ poll_api->timeout_new(poll_api, &tv, dump_timeout_callback, server);
+
+ avahi_elapse_time(&tv, 1000*60, 0);
+ poll_api->timeout_new(poll_api, &tv, quit_timeout_callback, simple_poll);
+
+ avahi_simple_poll_loop(simple_poll);
+
+ avahi_s_record_browser_free(r);
+ avahi_s_host_name_resolver_free(hnr);
+ avahi_s_address_resolver_free(ar);
+ avahi_s_domain_browser_free(db);
+ avahi_s_service_type_browser_free(stb);
+ avahi_s_service_browser_free(sb);
+ avahi_s_service_resolver_free(sr);
+ avahi_s_dns_server_browser_free(dsb);
+
+ if (group)
+ avahi_s_entry_group_free(group);
+
+ if (server)
+ avahi_server_free(server);
+
+ if (simple_poll)
+ avahi_simple_poll_free(simple_poll);
+
+ avahi_free(service_name);
+
+ return 0;
+}
--- /dev/null
+/***
+ This file is part of avahi.
+
+ avahi is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of the
+ License, or (at your option) any later version.
+
+ avahi is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
+ Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with avahi; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <assert.h>
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#include <avahi/alternative.h>
+#include <avahi/malloc.h>
+#include <avahi/simple-watch.h>
+#include <avahi/timeval.h>
+
+#include <avahi/core.h>
+#include <avahi/log.h>
+#include <avahi/lookup.h>
+#include <avahi/publish.h>
+
+static char *name = NULL;
+static AvahiSEntryGroup *group = NULL;
+static int try = 0;
+static AvahiServer *avahi = NULL;
+static const AvahiPoll *poll_api;
+
+static void dump_line(const char *text, AVAHI_GCC_UNUSED void* userdata) {
+ printf("%s\n", text);
+}
+
+static void dump_timeout_callback(AvahiTimeout *timeout, AVAHI_GCC_UNUSED void* userdata) {
+ struct timeval tv;
+
+ avahi_server_dump(avahi, dump_line, NULL);
+
+ avahi_elapse_time(&tv, 5000, 0);
+ poll_api->timeout_update(timeout, &tv);
+}
+
+static void entry_group_callback(AvahiServer *s, AvahiSEntryGroup *g, AvahiEntryGroupState state, void* userdata);
+
+static void create_service(const char *t) {
+ char *n;
+
+ assert(t || name);
+
+ n = t ? avahi_strdup(t) : avahi_alternative_service_name(name);
+ avahi_free(name);
+ name = n;
+
+ if (group)
+ avahi_s_entry_group_reset(group);
+ else
+ group = avahi_s_entry_group_new(avahi, entry_group_callback, NULL);
+
+ avahi_server_add_service(avahi, group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, name, "_http._tcp", NULL, NULL, 80, "foo", NULL);
+ avahi_s_entry_group_commit(group);
+
+ try++;
+}
+
+static void rename_timeout_callback(AvahiTimeout *timeout, AVAHI_GCC_UNUSED void *userdata) {
+ struct timeval tv;
+
+ if (access("flag", F_OK) == 0) {
+ create_service("New - Bonjour Service Name");
+ return;
+ }
+
+ avahi_elapse_time(&tv, 5000, 0);
+ poll_api->timeout_update(timeout, &tv);
+}
+
+static void entry_group_callback(AVAHI_GCC_UNUSED AvahiServer *s, AVAHI_GCC_UNUSED AvahiSEntryGroup *g, AvahiEntryGroupState state, AVAHI_GCC_UNUSED void* userdata) {
+ if (state == AVAHI_ENTRY_GROUP_COLLISION)
+ create_service(NULL);
+ else if (state == AVAHI_ENTRY_GROUP_ESTABLISHED) {
+ avahi_log_debug("ESTABLISHED !!!!");
+ try = 0;
+ }
+}
+
+static void server_callback(AvahiServer *s, AvahiServerState state, AVAHI_GCC_UNUSED void* userdata) {
+ avahi_log_debug("server state: %i", state);
+
+ if (state == AVAHI_SERVER_RUNNING) {
+ avahi_server_dump(avahi, dump_line, NULL);
+ } else if (state == AVAHI_SERVER_COLLISION) {
+ char *n;
+
+ 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);
+ avahi_free(n);
+
+ }
+}
+
+int main(AVAHI_GCC_UNUSED int argc, AVAHI_GCC_UNUSED char *argv[]) {
+ int error;
+ AvahiSimplePoll *simple_poll;
+ struct timeval tv;
+ struct AvahiServerConfig config;
+
+ simple_poll = avahi_simple_poll_new();
+ poll_api = avahi_simple_poll_get(simple_poll);
+
+ avahi_server_config_init(&config);
+ config.publish_workstation = 0;
+ config.use_ipv6 = 0;
+ config.publish_domain = 0;
+ config.publish_hinfo = 0;
+ avahi = avahi_server_new(poll_api, &config, server_callback, NULL, &error);
+ avahi_server_config_free(&config);
+
+ avahi_elapse_time(&tv, 5000, 0);
+ poll_api->timeout_new(poll_api, &tv, dump_timeout_callback, avahi);
+
+ avahi_elapse_time(&tv, 5000, 0);
+ poll_api->timeout_new(poll_api, &tv, rename_timeout_callback, avahi);
+
+ /* Evil, but the conformace test requires that*/
+ create_service("gurke");
+
+
+ avahi_simple_poll_loop(simple_poll);
+
+ if (group)
+ avahi_s_entry_group_free(group);
+ avahi_server_free(avahi);
+
+ avahi_simple_poll_free(simple_poll);
+
+ return 0;
+}
--- /dev/null
+/***
+ 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.
+***/
+
+/* Regression test for Avahi bug #84.
+ * This program tests whether the avahi_dns_packet_consume_name function
+ * returns (rather than spinning forever). For a function as simple as
+ * avahi_dns_packet_consume_name, we assume that 1 second of CPU time ≈ forever
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <string.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <sys/time.h>
+
+#include <avahi/dns.h>
+
+#define MAX_CPU_SECONDS 1
+
+#define TEST_NAME "dns-spin-test"
+
+static void fail(const char *fmt, ...) __attribute__((format(printf, 1, 2), noreturn));
+static void unresolved(const char *fmt, ...) __attribute__((format(printf, 1, 2), noreturn));
+static void stdlib_fail(const char *msg) __attribute__((noreturn));
+static void handle(int sig) __attribute__((noreturn));
+
+void stdlib_fail(const char *msg) {
+ perror(msg);
+
+ printf("UNRESOLVED: " TEST_NAME " (stdlib failure)\n");
+
+ exit(77);
+}
+
+void unresolved(const char *fmt, ...) {
+ va_list ap;
+
+ printf("UNRESOLVED: " TEST_NAME ": ");
+ va_start(ap, fmt);
+ vprintf(fmt, ap);
+ va_end(ap);
+ printf("\n");
+
+ exit(77);
+}
+
+void fail(const char *fmt, ...) {
+ va_list ap;
+
+ va_start(ap, fmt);
+ vprintf(fmt, ap);
+ va_end(ap);
+ printf("\n");
+
+ exit(EXIT_FAILURE);
+}
+
+void handle(AVAHI_GCC_UNUSED int sig) {
+ fail("Interrupted after %d second of CPU time", MAX_CPU_SECONDS);
+}
+
+#define TRY_EXCEPT(cmd, badresult) \
+ do { \
+ if ((cmd) == (badresult)) \
+ unresolved("%s returned %s", #cmd, #badresult); \
+ } while (0)
+
+int main(AVAHI_GCC_UNUSED int argc, AVAHI_GCC_UNUSED char *argv[]) {
+ struct itimerval itval;
+ AvahiDnsPacket *packet;
+ char name[512];
+ int ret;
+ uint8_t badrr[] = {
+ 0xC0, AVAHI_DNS_PACKET_HEADER_SIZE, /* self-referential QNAME pointer */
+ 0, 1, /* QTYPE A (host addr) */
+ 0, 1, /* QCLASS IN (internet/ipv4) */
+ };
+
+ if (signal(SIGVTALRM, handle) == SIG_ERR)
+ stdlib_fail("signal(SIGVTALRM)");
+
+ memset(&itval, 0, sizeof(itval));
+ itval.it_value.tv_sec = MAX_CPU_SECONDS;
+
+ if (setitimer(ITIMER_VIRTUAL, &itval, NULL) == -1)
+ stdlib_fail("setitimer()");
+
+ TRY_EXCEPT(packet = avahi_dns_packet_new_query(512), NULL);
+ TRY_EXCEPT(avahi_dns_packet_append_bytes(packet, badrr, sizeof(badrr)), NULL);
+
+ /* This is expected to fail (if it returns) */
+ ret = avahi_dns_packet_consume_name(packet, name, sizeof(name));
+
+ if (ret != -1)
+ fail("avahi_dns_packet_consume_name() returned %d; -1 was expected", ret);
+
+ return EXIT_SUCCESS;
+}
+
+/* vim:ts=4:sw=4:et
+ */
--- /dev/null
+/***
+ This file is part of avahi.
+
+ avahi is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of the
+ License, or (at your option) any later version.
+
+ avahi is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
+ Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with avahi; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <assert.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#include <avahi/domain.h>
+#include <avahi/defs.h>
+#include <avahi/malloc.h>
+
+#include <avahi/dns.h>
+#include <avahi/log.h>
+#include <avahi/util.h>
+
+int main(AVAHI_GCC_UNUSED int argc, AVAHI_GCC_UNUSED char *argv[]) {
+ char t[AVAHI_DOMAIN_NAME_MAX], *m;
+ const char *a, *b, *c, *d;
+ AvahiDnsPacket *p;
+ AvahiRecord *r, *r2;
+ uint8_t rdata[AVAHI_DNS_RDATA_MAX];
+ size_t l;
+
+ p = avahi_dns_packet_new(0);
+
+ assert(avahi_dns_packet_append_name(p, a = "Ahello.hello.hello.de."));
+ assert(avahi_dns_packet_append_name(p, b = "Bthis is a test.hello.de."));
+ assert(avahi_dns_packet_append_name(p, c = "Cthis\\.is\\.a\\.test\\.with\\.dots.hello.de."));
+ assert(avahi_dns_packet_append_name(p, d = "Dthis\\\\is another test.hello.de."));
+
+ avahi_hexdump(AVAHI_DNS_PACKET_DATA(p), p->size);
+
+ assert(avahi_dns_packet_consume_name(p, t, sizeof(t)) == 0);
+ avahi_log_debug(">%s<", t);
+ assert(avahi_domain_equal(a, t));
+
+ assert(avahi_dns_packet_consume_name(p, t, sizeof(t)) == 0);
+ avahi_log_debug(">%s<", t);
+ assert(avahi_domain_equal(b, t));
+
+ assert(avahi_dns_packet_consume_name(p, t, sizeof(t)) == 0);
+ avahi_log_debug(">%s<", t);
+ assert(avahi_domain_equal(c, t));
+
+ assert(avahi_dns_packet_consume_name(p, t, sizeof(t)) == 0);
+ avahi_log_debug(">%s<", t);
+ assert(avahi_domain_equal(d, t));
+
+ avahi_dns_packet_free(p);
+
+ /* RDATA PARSING AND SERIALIZATION */
+
+ /* Create an AvahiRecord with some usful data */
+ r = avahi_record_new_full("foobar.local", AVAHI_DNS_CLASS_IN, AVAHI_DNS_TYPE_HINFO, AVAHI_DEFAULT_TTL);
+ assert(r);
+ r->data.hinfo.cpu = avahi_strdup("FOO");
+ r->data.hinfo.os = avahi_strdup("BAR");
+
+ /* Serialize it into a blob */
+ assert((l = avahi_rdata_serialize(r, rdata, sizeof(rdata))) != (size_t) -1);
+
+ /* Print it */
+ avahi_hexdump(rdata, l);
+
+ /* Create a new record and fill in the data from the blob */
+ r2 = avahi_record_new(r->key, AVAHI_DEFAULT_TTL);
+ assert(r2);
+ assert(avahi_rdata_parse(r2, rdata, l) >= 0);
+
+ /* Compare both versions */
+ assert(avahi_record_equal_no_ttl(r, r2));
+
+ /* Free the records */
+ avahi_record_unref(r);
+ avahi_record_unref(r2);
+
+ r = avahi_record_new_full("foobar", 77, 77, AVAHI_DEFAULT_TTL);
+ assert(r);
+
+ assert(r->data.generic.data = avahi_memdup("HALLO", r->data.generic.size = 5));
+
+ m = avahi_record_to_string(r);
+ assert(m);
+
+ avahi_log_debug(">%s<", m);
+
+ avahi_free(m);
+ avahi_record_unref(r);
+
+ return 0;
+}
--- /dev/null
+/***
+ This file is part of avahi.
+
+ avahi is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of the
+ License, or (at your option) any later version.
+
+ avahi is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
+ Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with avahi; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <string.h>
+#include <assert.h>
+
+#include <avahi/domain.h>
+#include <avahi/malloc.h>
+
+int main(AVAHI_GCC_UNUSED int argc, AVAHI_GCC_UNUSED char *argv[]) {
+ char *s;
+ char t[256], r[256];
+ const char *p;
+ size_t size;
+ char name[64], type[AVAHI_DOMAIN_NAME_MAX], domain[AVAHI_DOMAIN_NAME_MAX];
+
+ printf("%s\n", s = avahi_normalize_name_strdup("foo.foo\\046."));
+ avahi_free(s);
+
+ printf("%s\n", s = avahi_normalize_name_strdup("foo.foo\\.foo."));
+ avahi_free(s);
+
+
+ printf("%s\n", s = avahi_normalize_name_strdup("fo\\\\o\\..f oo."));
+ avahi_free(s);
+
+ printf("%i\n", avahi_domain_equal("\\065aa bbb\\.\\046cc.cc\\\\.dee.fff.", "Aaa BBB\\.\\.cc.cc\\\\.dee.fff"));
+ printf("%i\n", avahi_domain_equal("A", "a"));
+
+ printf("%i\n", avahi_domain_equal("a", "aaa"));
+
+ printf("%u = %u\n", avahi_domain_hash("ccc\\065aa.aa\\.b\\\\."), avahi_domain_hash("cccAaa.aa\\.b\\\\"));
+
+
+ avahi_service_name_join(t, sizeof(t), "foo.foo.foo \\.", "_http._tcp", "test.local");
+ printf("<%s>\n", t);
+
+ avahi_service_name_split(t, name, sizeof(name), type, sizeof(type), domain, sizeof(domain));
+ printf("name: <%s>; type: <%s>; domain <%s>\n", name, type, domain);
+
+ avahi_service_name_join(t, sizeof(t), NULL, "_http._tcp", "one.two\\. .local");
+ printf("<%s>\n", t);
+
+ avahi_service_name_split(t, NULL, 0, type, sizeof(type), domain, sizeof(domain));
+ printf("name: <>; type: <%s>; domain <%s>\n", type, domain);
+
+
+ p = "--:---\\\\\\123\\065_äöü\\064\\.\\\\sjöödfhh.sdfjhskjdf";
+ printf("unescaped: <%s>, rest: %s\n", avahi_unescape_label(&p, t, sizeof(t)), p);
+
+ size = sizeof(r);
+ s = r;
+
+ printf("escaped: <%s>\n", avahi_escape_label(t, strlen(t), &s, &size));
+
+ p = r;
+ printf("unescaped: <%s>\n", avahi_unescape_label(&p, t, sizeof(t)));
+
+ assert(avahi_is_valid_service_type_generic("_foo._bar._waldo"));
+ assert(!avahi_is_valid_service_type_strict("_foo._bar._waldo"));
+ assert(!avahi_is_valid_service_subtype("_foo._bar._waldo"));
+
+ assert(avahi_is_valid_service_type_generic("_foo._tcp"));
+ assert(avahi_is_valid_service_type_strict("_foo._tcp"));
+ assert(!avahi_is_valid_service_subtype("_foo._tcp"));
+
+ assert(!avahi_is_valid_service_type_generic("_foo._bar.waldo"));
+ assert(!avahi_is_valid_service_type_strict("_foo._bar.waldo"));
+ assert(!avahi_is_valid_service_subtype("_foo._bar.waldo"));
+
+ assert(!avahi_is_valid_service_type_generic(""));
+ assert(!avahi_is_valid_service_type_strict(""));
+ assert(!avahi_is_valid_service_subtype(""));
+
+ assert(avahi_is_valid_service_type_generic("_foo._sub._bar._tcp"));
+ assert(!avahi_is_valid_service_type_strict("_foo._sub._bar._tcp"));
+ assert(avahi_is_valid_service_subtype("_foo._sub._bar._tcp"));
+
+ printf("%s\n", avahi_get_type_from_subtype("_foo._sub._bar._tcp"));
+
+ assert(!avahi_is_valid_host_name("sf.ooo."));
+ assert(avahi_is_valid_host_name("sfooo."));
+ assert(avahi_is_valid_host_name("sfooo"));
+
+ assert(avahi_is_valid_domain_name("."));
+ assert(avahi_is_valid_domain_name(""));
+
+ assert(avahi_normalize_name(".", t, sizeof(t)));
+ assert(avahi_normalize_name("", t, sizeof(t)));
+
+ assert(!avahi_is_valid_fqdn("."));
+ assert(!avahi_is_valid_fqdn(""));
+ assert(!avahi_is_valid_fqdn("foo"));
+ assert(avahi_is_valid_fqdn("foo.bar"));
+ assert(avahi_is_valid_fqdn("foo.bar."));
+ assert(avahi_is_valid_fqdn("gnurz.foo.bar."));
+ assert(!avahi_is_valid_fqdn("192.168.50.1"));
+ assert(!avahi_is_valid_fqdn("::1"));
+ assert(!avahi_is_valid_fqdn(".192.168.50.1."));
+
+ return 0;
+}
--- /dev/null
+/***
+ This file is part of avahi.
+
+ avahi is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of the
+ License, or (at your option) any later version.
+
+ avahi is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
+ Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with avahi; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+
+#include <avahi/domain.h>
+#include <avahi/malloc.h>
+
+#include <avahi/hashmap.h>
+#include <avahi/util.h>
+
+int main(AVAHI_GCC_UNUSED int argc, AVAHI_GCC_UNUSED char *argv[]) {
+ unsigned n;
+ AvahiHashmap *m;
+ const char *t;
+
+ m = avahi_hashmap_new(avahi_string_hash, avahi_string_equal, avahi_free, avahi_free);
+
+ avahi_hashmap_insert(m, avahi_strdup("bla"), avahi_strdup("#1"));
+ avahi_hashmap_insert(m, avahi_strdup("bla2"), avahi_strdup("asdf"));
+ avahi_hashmap_insert(m, avahi_strdup("gurke"), avahi_strdup("ffsdf"));
+ avahi_hashmap_insert(m, avahi_strdup("blubb"), avahi_strdup("sadfsd"));
+ avahi_hashmap_insert(m, avahi_strdup("bla"), avahi_strdup("#2"));
+
+ for (n = 0; n < 1000; n ++)
+ avahi_hashmap_insert(m, avahi_strdup_printf("key %u", n), avahi_strdup_printf("value %u", n));
+
+ printf("%s\n", (const char*) avahi_hashmap_lookup(m, "bla"));
+
+ avahi_hashmap_replace(m, avahi_strdup("bla"), avahi_strdup("#3"));
+
+ printf("%s\n", (const char*) avahi_hashmap_lookup(m, "bla"));
+
+ avahi_hashmap_remove(m, "bla");
+
+ t = (const char*) avahi_hashmap_lookup(m, "bla");
+ printf("%s\n", t ? t : "(null)");
+
+ avahi_hashmap_free(m);
+
+ return 0;
+}
--- /dev/null
+/***
+ This file is part of avahi.
+
+ avahi is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of the
+ License, or (at your option) any later version.
+
+ avahi is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
+ Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with avahi; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <time.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <assert.h>
+
+#include <avahi/gccmacro.h>
+
+#include <avahi/prioq.h>
+
+#define POINTER_TO_INT(p) ((int) (long) (p))
+#define INT_TO_POINTER(i) ((void*) (long) (i))
+
+static int compare_int(const void* a, const void* b) {
+ int i = POINTER_TO_INT(a), j = POINTER_TO_INT(b);
+
+ return i < j ? -1 : (i > j ? 1 : 0);
+}
+
+static int compare_ptr(const void* a, const void* b) {
+ return a < b ? -1 : (a > b ? 1 : 0);
+}
+
+static void rec(AvahiPrioQueueNode *n) {
+ if (!n)
+ return;
+
+ if (n->left)
+ assert(n->left->parent == n);
+
+ if (n->right)
+ assert(n->right->parent == n);
+
+ if (n->parent) {
+ assert(n->parent->left == n || n->parent->right == n);
+
+ if (n->parent->left == n)
+ assert(n->next == n->parent->right);
+ }
+
+ if (!n->next) {
+ assert(n->queue->last == n);
+
+ if (n->parent && n->parent->left == n)
+ assert(n->parent->right == NULL);
+ }
+
+
+ if (n->parent) {
+ int a = POINTER_TO_INT(n->parent->data), b = POINTER_TO_INT(n->data);
+ if (a > b) {
+ printf("%i <= %i: NO\n", a, b);
+ abort();
+ }
+ }
+
+ rec(n->left);
+ rec(n->right);
+}
+
+int main(AVAHI_GCC_UNUSED int argc, AVAHI_GCC_UNUSED char *argv[]) {
+ AvahiPrioQueue *q, *q2;
+ int i;
+
+ q = avahi_prio_queue_new(compare_int);
+ q2 = avahi_prio_queue_new(compare_ptr);
+
+ srand(time(NULL));
+
+ for (i = 0; i < 10000; i++)
+ avahi_prio_queue_put(q2, avahi_prio_queue_put(q, INT_TO_POINTER(random() & 0xFFFF)));
+
+ while (q2->root) {
+ rec(q->root);
+ rec(q2->root);
+
+ assert(q->n_nodes == q2->n_nodes);
+
+ printf("%i\n", POINTER_TO_INT(((AvahiPrioQueueNode*)q2->root->data)->data));
+
+ avahi_prio_queue_remove(q, q2->root->data);
+ avahi_prio_queue_remove(q2, q2->root);
+ }
+
+
+/* prev = 0; */
+/* while (q->root) { */
+/* int v = GPOINTER_TO_INT(q->root->data); */
+/* rec(q->root); */
+/* printf("%i\n", v); */
+/* avahi_prio_queue_remove(q, q->root); */
+/* assert(v >= prev); */
+/* prev = v; */
+/* } */
+
+ avahi_prio_queue_free(q);
+ return 0;
+}
--- /dev/null
+/***
+ This file is part of avahi.
+
+ avahi is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of the
+ License, or (at your option) any later version.
+
+ avahi is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
+ Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with avahi; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <assert.h>
+
+#include <avahi/malloc.h>
+#include <avahi/simple-watch.h>
+#include <avahi/alternative.h>
+#include <avahi/timeval.h>
+
+#include <avahi/core.h>
+#include <avahi/log.h>
+#include <avahi/publish.h>
+#include <avahi/lookup.h>
+
+#define DOMAIN NULL
+#define SERVICE_TYPE "_http._tcp"
+
+static AvahiSServiceBrowser *service_browser1 = NULL, *service_browser2 = NULL;
+static const AvahiPoll * poll_api = NULL;
+static AvahiServer *server = NULL;
+static AvahiSimplePoll *simple_poll;
+
+static const char *browser_event_to_string(AvahiBrowserEvent event) {
+ switch (event) {
+ case AVAHI_BROWSER_NEW : return "NEW";
+ case AVAHI_BROWSER_REMOVE : return "REMOVE";
+ case AVAHI_BROWSER_CACHE_EXHAUSTED : return "CACHE_EXHAUSTED";
+ case AVAHI_BROWSER_ALL_FOR_NOW : return "ALL_FOR_NOW";
+ case AVAHI_BROWSER_FAILURE : return "FAILURE";
+ }
+
+ abort();
+}
+
+static void sb_callback(
+ AvahiSServiceBrowser *b,
+ AvahiIfIndex iface,
+ AvahiProtocol protocol,
+ AvahiBrowserEvent event,
+ const char *name,
+ const char *service_type,
+ const char *domain,
+ AvahiLookupResultFlags flags,
+ AVAHI_GCC_UNUSED void* userdata) {
+ avahi_log_debug("SB%i: (%i.%s) <%s> as <%s> in <%s> [%s] cached=%i", b == service_browser1 ? 1 : 2, iface, avahi_proto_to_string(protocol), name, service_type, domain, browser_event_to_string(event), !!(flags & AVAHI_LOOKUP_RESULT_CACHED));
+}
+
+static void create_second_service_browser(AvahiTimeout *timeout, AVAHI_GCC_UNUSED void* userdata) {
+
+ service_browser2 = avahi_s_service_browser_new(server, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, SERVICE_TYPE, DOMAIN, 0, sb_callback, NULL);
+ assert(service_browser2);
+
+ poll_api->timeout_free(timeout);
+}
+
+static void quit(AVAHI_GCC_UNUSED AvahiTimeout *timeout, AVAHI_GCC_UNUSED void *userdata) {
+ avahi_simple_poll_quit(simple_poll);
+}
+
+int main(AVAHI_GCC_UNUSED int argc, AVAHI_GCC_UNUSED char *argv[]) {
+ struct timeval tv;
+ AvahiServerConfig config;
+
+ simple_poll = avahi_simple_poll_new();
+ assert(simple_poll);
+
+ poll_api = avahi_simple_poll_get(simple_poll);
+ assert(poll_api);
+
+ avahi_server_config_init(&config);
+ config.publish_hinfo = 0;
+ config.publish_addresses = 0;
+ config.publish_workstation = 0;
+ config.publish_domain = 0;
+
+ avahi_address_parse("192.168.50.1", AVAHI_PROTO_UNSPEC, &config.wide_area_servers[0]);
+ config.n_wide_area_servers = 1;
+ config.enable_wide_area = 1;
+
+ server = avahi_server_new(poll_api, &config, NULL, NULL, NULL);
+ assert(server);
+ avahi_server_config_free(&config);
+
+ service_browser1 = avahi_s_service_browser_new(server, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, SERVICE_TYPE, DOMAIN, 0, sb_callback, NULL);
+ assert(service_browser1);
+
+ poll_api->timeout_new(poll_api, avahi_elapse_time(&tv, 10000, 0), create_second_service_browser, NULL);
+
+ poll_api->timeout_new(poll_api, avahi_elapse_time(&tv, 60000, 0), quit, NULL);
+
+
+ for (;;)
+ if (avahi_simple_poll_iterate(simple_poll, -1) != 0)
+ break;
+
+ avahi_server_free(server);
+ avahi_simple_poll_free(simple_poll);
+
+ return 0;
+}
--- /dev/null
+/***
+ This file is part of avahi.
+
+ avahi is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of the
+ License, or (at your option) any later version.
+
+ avahi is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
+ Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with avahi; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <assert.h>
+
+#include <avahi/strlst.h>
+#include <avahi/malloc.h>
+
+int main(AVAHI_GCC_UNUSED int argc, AVAHI_GCC_UNUSED char *argv[]) {
+ char *t, *v;
+ uint8_t data[1024];
+ AvahiStringList *a = NULL, *b, *p;
+ size_t size, n;
+ int r;
+
+ a = avahi_string_list_new("prefix", "a", "b", NULL);
+
+ a = avahi_string_list_add(a, "start");
+ a = avahi_string_list_add(a, "foo=99");
+ a = avahi_string_list_add(a, "bar");
+ a = avahi_string_list_add(a, "");
+ a = avahi_string_list_add(a, "");
+ a = avahi_string_list_add(a, "quux");
+ a = avahi_string_list_add(a, "");
+ a = avahi_string_list_add_arbitrary(a, (const uint8_t*) "null\0null", 9);
+ a = avahi_string_list_add_printf(a, "seven=%i %c", 7, 'x');
+ a = avahi_string_list_add_pair(a, "blubb", "blaa");
+ a = avahi_string_list_add_pair(a, "uxknurz", NULL);
+ a = avahi_string_list_add_pair_arbitrary(a, "uxknurz2", (const uint8_t*) "blafasel\0oerks", 14);
+
+ a = avahi_string_list_add(a, "end");
+
+ t = avahi_string_list_to_string(a);
+ printf("--%s--\n", t);
+ avahi_free(t);
+
+ n = avahi_string_list_serialize(a, NULL, 0);
+ size = avahi_string_list_serialize(a, data, sizeof(data));
+ assert(size == n);
+
+ printf("%zu\n", size);
+
+ for (t = (char*) data, n = 0; n < size; n++, t++) {
+ if (*t <= 32)
+ printf("(%u)", *t);
+ else
+ printf("%c", *t);
+ }
+
+ printf("\n");
+
+ assert(avahi_string_list_parse(data, size, &b) == 0);
+
+ printf("equal: %i\n", avahi_string_list_equal(a, b));
+
+ t = avahi_string_list_to_string(b);
+ printf("--%s--\n", t);
+ avahi_free(t);
+
+ avahi_string_list_free(b);
+
+ b = avahi_string_list_copy(a);
+
+ assert(avahi_string_list_equal(a, b));
+
+ t = avahi_string_list_to_string(b);
+ printf("--%s--\n", t);
+ avahi_free(t);
+
+ p = avahi_string_list_find(a, "seven");
+ assert(p);
+
+ r = avahi_string_list_get_pair(p, &t, &v, NULL);
+ assert(r >= 0);
+ assert(t);
+ assert(v);
+
+ printf("<%s>=<%s>\n", t, v);
+ avahi_free(t);
+ avahi_free(v);
+
+ p = avahi_string_list_find(a, "quux");
+ assert(p);
+
+ r = avahi_string_list_get_pair(p, &t, &v, NULL);
+ assert(r >= 0);
+ assert(t);
+ assert(!v);
+
+ printf("<%s>=<%s>\n", t, v);
+ avahi_free(t);
+ avahi_free(v);
+
+ avahi_string_list_free(a);
+ avahi_string_list_free(b);
+
+ n = avahi_string_list_serialize(NULL, NULL, 0);
+ size = avahi_string_list_serialize(NULL, data, sizeof(data));
+ assert(size == 1);
+ assert(size == n);
+
+ assert(avahi_string_list_parse(data, size, &a) == 0);
+ assert(!a);
+
+ return 0;
+}
--- /dev/null
+/***
+ This file is part of avahi.
+
+ avahi is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of the
+ License, or (at your option) any later version.
+
+ avahi is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
+ Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with avahi; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <assert.h>
+#include <stdlib.h>
+
+#include <avahi/timeval.h>
+#include <avahi/simple-watch.h>
+
+#include <avahi/timeeventq.h>
+#include <avahi/log.h>
+
+#define POINTER_TO_INT(p) ((int) (long) (p))
+#define INT_TO_POINTER(i) ((void*) (long) (i))
+
+static AvahiTimeEventQueue *q = NULL;
+
+static void callback(AvahiTimeEvent*e, void* userdata) {
+ struct timeval tv = {0, 0};
+ assert(e);
+ avahi_log_info("callback(%i)", POINTER_TO_INT(userdata));
+ avahi_elapse_time(&tv, 1000, 100);
+ avahi_time_event_update(e, &tv);
+}
+
+int main(AVAHI_GCC_UNUSED int argc, AVAHI_GCC_UNUSED char *argv[]) {
+ struct timeval tv;
+ AvahiSimplePoll *s;
+
+ s = avahi_simple_poll_new();
+
+ q = avahi_time_event_queue_new(avahi_simple_poll_get(s));
+
+ avahi_time_event_new(q, avahi_elapse_time(&tv, 5000, 100), callback, INT_TO_POINTER(1));
+ avahi_time_event_new(q, avahi_elapse_time(&tv, 5000, 100), callback, INT_TO_POINTER(2));
+
+ avahi_log_info("starting");
+
+ for (;;)
+ if (avahi_simple_poll_iterate(s, -1) != 0)
+ break;
+
+ avahi_time_event_queue_free(q);
+ avahi_simple_poll_free(s);
+
+ return 0;
+}
--- /dev/null
+/***
+ This file is part of avahi.
+
+ avahi is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of the
+ License, or (at your option) any later version.
+
+ avahi is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
+ Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with avahi; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+
+#include <avahi/gccmacro.h>
+#include <avahi/timeval.h>
+
+int main(AVAHI_GCC_UNUSED int argc, AVAHI_GCC_UNUSED char *argv[]) {
+
+ struct timeval a = { 5, 5 }, b;
+
+ b = a;
+
+ printf("%li.%li\n", a.tv_sec, a.tv_usec);
+ avahi_timeval_add(&a, -50);
+
+ printf("%li.%li\n", a.tv_sec, a.tv_usec);
+
+ printf("%lli\n", (long long) avahi_timeval_diff(&a, &b));
+
+ return 0;
+}
--- /dev/null
+/***
+ This file is part of avahi.
+
+ avahi is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of the
+ License, or (at your option) any later version.
+
+ avahi is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
+ Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with avahi; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <assert.h>
+#include <stdlib.h>
+
+#include <avahi/error.h>
+#include <avahi/watch.h>
+#include <avahi/simple-watch.h>
+#include <avahi/malloc.h>
+#include <avahi/alternative.h>
+#include <avahi/timeval.h>
+
+#include <avahi/core.h>
+#include <avahi/log.h>
+#include <avahi/publish.h>
+#include <avahi/lookup.h>
+
+static AvahiSEntryGroup *group = NULL;
+
+static void server_callback(AvahiServer *s, AvahiServerState state, AVAHI_GCC_UNUSED void* userdata) {
+
+ avahi_log_debug("server state: %i", state);
+
+ if (state == AVAHI_SERVER_RUNNING) {
+ int ret;
+
+ group = avahi_s_entry_group_new(s, NULL, NULL);
+ assert(group);
+
+ ret = avahi_server_add_service(s, group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, "foo", "_http._tcp", NULL, NULL, 80, "test1", NULL);
+ assert(ret == AVAHI_OK);
+
+ avahi_s_entry_group_commit(group);
+ }
+}
+
+static void modify_txt_callback(AVAHI_GCC_UNUSED AvahiTimeout *e, void *userdata) {
+ int ret;
+ AvahiServer *s = userdata;
+
+ avahi_log_debug("modifying");
+
+ ret = avahi_server_update_service_txt(s, group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, "foo", "_http._tcp", NULL, "test2", NULL);
+ assert(ret == AVAHI_OK);
+}
+
+int main(AVAHI_GCC_UNUSED int argc, AVAHI_GCC_UNUSED char *argv[]) {
+ AvahiSimplePoll *simple_poll;
+ const AvahiPoll *poll_api;
+ AvahiServer *server;
+ struct timeval tv;
+ AvahiServerConfig config;
+
+ simple_poll = avahi_simple_poll_new();
+ assert(simple_poll);
+
+ poll_api = avahi_simple_poll_get(simple_poll);
+ assert(poll_api);
+
+ avahi_server_config_init(&config);
+ config.publish_domain = config.publish_workstation = config.use_ipv6 = config.publish_hinfo = 0;
+ server = avahi_server_new(poll_api, &config, server_callback, NULL, NULL);
+ assert(server);
+ avahi_server_config_free(&config);
+
+ poll_api->timeout_new(poll_api, avahi_elapse_time(&tv, 1000*10, 0), modify_txt_callback, server);
+
+ avahi_simple_poll_loop(simple_poll);
+ return 0;
+}
--- /dev/null
+/***
+ This file is part of avahi.
+
+ avahi is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of the
+ License, or (at your option) any later version.
+
+ avahi is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
+ Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with avahi; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <assert.h>
+
+#include <avahi/gccmacro.h>
+
+#include <avahi/utf8.h>
+
+int main(AVAHI_GCC_UNUSED int argc, AVAHI_GCC_UNUSED char *argv[]) {
+
+ assert(avahi_utf8_valid("hallo"));
+ assert(!avahi_utf8_valid("üxknürz"));
+ assert(avahi_utf8_valid("üxknürz"));
+
+ return 0;
+}
--- /dev/null
+/***
+ This file is part of avahi.
+
+ avahi is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of the
+ License, or (at your option) any later version.
+
+ avahi is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
+ Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with avahi; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <unistd.h>
+#include <assert.h>
+#include <errno.h>
+#include <string.h>
+
+#include <avahi/watch.h>
+#include <avahi/timeval.h>
+#include <avahi/gccmacro.h>
+
+static const AvahiPoll *api = NULL;
+
+#ifndef USE_THREAD
+#include <avahi/simple-watch.h>
+static AvahiSimplePoll *simple_poll = NULL;
+#else
+#include <avahi/thread-watch.h>
+static AvahiThreadedPoll *threaded_poll = NULL;
+#endif
+
+static void callback(AvahiWatch *w, int fd, AvahiWatchEvent event, AVAHI_GCC_UNUSED void *userdata) {
+
+ if (event & AVAHI_WATCH_IN) {
+ ssize_t r;
+ char c;
+
+ if ((r = read(fd, &c, 1)) <= 0) {
+ fprintf(stderr, "read() failed: %s\n", r < 0 ? strerror(errno) : "EOF");
+ api->watch_free(w);
+ return;
+ }
+
+ printf("Read: %c\n", c >= 32 && c < 127 ? c : '.');
+ }
+}
+
+static void wakeup(AvahiTimeout *t, AVAHI_GCC_UNUSED void *userdata) {
+ static int i = 0;
+ struct timeval tv;
+
+ printf("Wakeup #%i\n", i++);
+
+ if (i > 10) {
+#ifndef USE_THREAD
+ avahi_simple_poll_quit(simple_poll);
+#else
+ avahi_threaded_poll_quit(threaded_poll);
+#endif
+ } else {
+ avahi_elapse_time(&tv, 1000, 0);
+ api->timeout_update(t, &tv);
+ }
+}
+
+int main(AVAHI_GCC_UNUSED int argc, AVAHI_GCC_UNUSED char *argv[]) {
+ struct timeval tv;
+
+#ifndef USE_THREAD
+ simple_poll = avahi_simple_poll_new();
+ assert(simple_poll);
+ api = avahi_simple_poll_get(simple_poll);
+ assert(api);
+#else
+ threaded_poll = avahi_threaded_poll_new();
+ assert(threaded_poll);
+ api = avahi_threaded_poll_get(threaded_poll);
+ assert(api);
+#endif
+
+ api->watch_new(api, 0, AVAHI_WATCH_IN, callback, NULL);
+
+ avahi_elapse_time(&tv, 1000, 0);
+ api->timeout_new(api, &tv, wakeup, NULL);
+
+#ifndef USE_THREAD
+ /* Our main loop */
+ avahi_simple_poll_loop(simple_poll);
+ avahi_simple_poll_free(simple_poll);
+
+#else
+ avahi_threaded_poll_start(threaded_poll);
+
+ fprintf(stderr, "Now doing some stupid stuff ...\n");
+ sleep(20);
+ fprintf(stderr, "... stupid stuff is done.\n");
+
+ avahi_threaded_poll_free(threaded_poll);
+
+#endif
+
+ return 0;
+}