Skip to content

Commit

Permalink
* Compile tests only when --enable-tests was specified on the configu…
Browse files Browse the repository at this point in the history
…re command line

* Build compat layers only when --enable-compat-{howl,libdns_sd} was passed to configure
* drop avahi_strlcpy() to reduce our code/API size
* replace getifname() with if_indextoname in avahi-dnsconfd
* declare environ if needed in avahi-dnsconfd
* drop some useless definitions like  AVAHI_PUBLISH_NULL = 0


git-svn-id: file:///home/lennart/svn/public/avahi/trunk@819 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe
  • Loading branch information
poettering committed Oct 19, 2005
1 parent d266407 commit 16d9e30
Show file tree
Hide file tree
Showing 18 changed files with 132 additions and 57 deletions.
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ SUBDIRS = \
tests \
service-type-database \
avahi-compat-libdns_sd \
avahi-compat-howl
avahi-compat-howl


DX_INPUT = \
Expand Down
4 changes: 4 additions & 0 deletions avahi-client/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ avahi_clientinclude_HEADERS = client.h

noinst_HEADERS = internal.h

if ENABLE_TESTS

noinst_PROGRAMS = \
client-test \
srv-test

endif

lib_LTLIBRARIES = libavahi-client.la

libavahi_client_la_SOURCES = \
Expand Down
2 changes: 2 additions & 0 deletions avahi-common/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@ avahi_commoninclude_HEADERS = \
llist.h \
rlist.h

if ENABLE_TESTS
noinst_PROGRAMS = \
strlst-test \
domain-test \
alternative-test \
timeval-test \
watch-test
endif

lib_LTLIBRARIES = \
libavahi-common.la
Expand Down
3 changes: 0 additions & 3 deletions avahi-common/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ typedef enum {

/** Some flags for publishing functions */
typedef enum {
AVAHI_PUBLISH_NULL = 0,
AVAHI_PUBLISH_UNIQUE = 1, /**< For raw records: The RRset is intended to be unique */
AVAHI_PUBLISH_NO_PROBE = 2, /**< For raw records: Though the RRset is intended to be unique no probes shall be sent */
AVAHI_PUBLISH_NO_ANNOUNCE = 4, /**< For raw records: Do not announce this RR to other hosts */
Expand All @@ -166,7 +165,6 @@ typedef enum {

/** Some flags for lookup functions */
typedef enum {
AVAHI_LOOKUP_NULL = 0,
AVAHI_LOOKUP_USE_WIDE_AREA = 1, /**< Force lookup via wide area DNS */
AVAHI_LOOKUP_USE_MULTICAST = 2, /**< Force lookup via multicast DNS */
AVAHI_LOOKUP_NO_TXT = 4, /**< When doing service resolving, don't lookup TXT record */
Expand All @@ -175,7 +173,6 @@ typedef enum {

/** Some flags for lookup callback functions */
typedef enum {
AVAHI_LOOKUP_RESULT_NULL = 0,
AVAHI_LOOKUP_RESULT_CACHED = 1, /**< This response originates from the cache */
AVAHI_LOOKUP_RESULT_WIDE_AREA = 2, /**< This response originates from wide area DNS */
AVAHI_LOOKUP_RESULT_MULTICAST = 4, /**< This response originates from multicast DNS */
Expand Down
21 changes: 12 additions & 9 deletions avahi-common/domain.c
Original file line number Diff line number Diff line change
Expand Up @@ -530,19 +530,22 @@ int avahi_service_name_join(char *p, size_t size, const char *name, const char *
return AVAHI_OK;
}

#ifndef HAVE_STRLCPY

char *avahi_strlcpy(char *dest, const char *src, size_t n) {
static size_t strlcpy(char *dest, const char *src, size_t n) {
assert(dest);
assert(src);

if (n == 0)
return dest;

strncpy(dest, src, n-1);
dest[n-1] = 0;
return dest;
if (n > 0) {
strncpy(dest, src, n-1);
dest[n-1] = 0;
}

return strlen(src);
}

#endif

int avahi_service_name_split(const char *p, char *name, size_t name_size, char *type, size_t type_size, char *domain, size_t domain_size) {
enum {
NAME,
Expand Down Expand Up @@ -574,7 +577,7 @@ int avahi_service_name_split(const char *p, char *name, size_t name_size, char *

switch (state) {
case NAME:
avahi_strlcpy(name, buf, name_size);
strlcpy(name, buf, name_size);
state = TYPE;
break;

Expand Down
4 changes: 4 additions & 0 deletions avahi-compat-howl/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ AM_CFLAGS+='-DDEBUG_TRAP=__asm__("int $$3")'
SUBDIRS = . samples

if HAVE_DBUS
if ENABLE_COMPAT_HOWL

avahi_compat_howldir=$(includedir)/avahi-compat-howl
avahi_compat_howl_rendezvousdir=$(avahi_compat_howldir)/rendezvous
Expand Down Expand Up @@ -70,7 +71,9 @@ HOWLHEADERS = \

lib_LTLIBRARIES = libavahi-compat-howl.la

if ENABLE_TESTS
noinst_PROGRAMS = address-test text-test browse-domain-test
endif

libavahi_compat_howl_la_SOURCES = \
$(HOWLHEADERS) \
Expand Down Expand Up @@ -105,3 +108,4 @@ browse_domain_test_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS) -I $(srcdir)/include
browse_domain_test_LDADD = $(AM_LDADD) libavahi-compat-howl.la

endif
endif
4 changes: 4 additions & 0 deletions avahi-compat-howl/samples/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ AM_CFLAGS=-I$(top_srcdir) -I$(top_srcdir)/avahi-compat-howl/include
AM_CFLAGS+='-DDEBUG_TRAP=__asm__("int $$3")'

if HAVE_DBUS
if ENABLE_COMPAT_HOWL

if ENABLE_TESTS
noinst_PROGRAMS = browse resolve publish query
endif

browse_SOURCES = \
browse.c
Expand All @@ -47,3 +50,4 @@ query_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS) -I $(srcdir)/include
query_LDADD = $(AM_LDADD) ../libavahi-compat-howl.la

endif
endif
18 changes: 17 additions & 1 deletion avahi-compat-howl/text.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,22 @@ struct _sw_text_record {
int buffer_valid;
};

#ifndef HAVE_STRLCPY

static size_t strlcpy(char *dest, const char *src, size_t n) {
assert(dest);
assert(src);

if (n > 0) {
strncpy(dest, src, n-1);
dest[n-1] = 0;
}

return strlen(src);
}

#endif

sw_result sw_text_record_init(sw_text_record *self) {
assert(self);

Expand Down Expand Up @@ -223,7 +239,7 @@ sw_result sw_text_record_iterator_next(
if (avahi_string_list_get_pair(self->index, &mkey, &mvalue, &msize) < 0)
return SW_E_UNKNOWN;

avahi_strlcpy(key, mkey, SW_TEXT_RECORD_MAX_LEN);
strlcpy(key, mkey, SW_TEXT_RECORD_MAX_LEN);
memset(val, 0, SW_TEXT_RECORD_MAX_LEN);
memcpy(val, mvalue, msize);
*val_len = msize;
Expand Down
4 changes: 4 additions & 0 deletions avahi-compat-libdns_sd/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,17 @@ AM_CFLAGS=-I$(top_srcdir)
AM_CFLAGS+='-DDEBUG_TRAP=__asm__("int $$3")'

if HAVE_DBUS
if ENABLE_COMPAT_LIBDNS_SD

avahi_compat_libdns_sddir=$(includedir)/avahi-compat-libdns_sd

avahi_compat_libdns_sd_HEADERS = dns_sd.h

lib_LTLIBRARIES = libavahi-compat-libdns_sd.la

if ENABLE_TESTS
noinst_PROGRAMS = txt-test
endif

libavahi_compat_libdns_sd_la_SOURCES = \
dns_sd.h \
Expand Down Expand Up @@ -61,3 +64,4 @@ libdns_sd-test: libdns_sd-test.c libavahi-compat-libdns_sd.la
CLEANFILES = libdns_sd-test.o libdns_sd-test

endif
endif
2 changes: 2 additions & 0 deletions avahi-core/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ avahiinclude_HEADERS = \
lib_LTLIBRARIES = \
libavahi-core.la

if ENABLE_TESTS
noinst_PROGRAMS = \
prioq-test \
avahi-test \
Expand All @@ -44,6 +45,7 @@ noinst_PROGRAMS = \
hashmap-test \
querier-test \
update-test
endif

libavahi_core_la_SOURCES = \
timeeventq.c timeeventq.h\
Expand Down
2 changes: 1 addition & 1 deletion avahi-core/entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ int avahi_server_add_dns_server_name(
r->data.srv.weight = 0;
r->data.srv.port = port;
r->data.srv.name = n;
ret = avahi_server_add(s, g, interface, protocol, AVAHI_PUBLISH_NULL, r);
ret = avahi_server_add(s, g, interface, protocol, 0, r);
avahi_record_unref(r);

return ret;
Expand Down
2 changes: 2 additions & 0 deletions avahi-daemon/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ AM_CFLAGS+= \
sbin_PROGRAMS = \
avahi-daemon

if ENABLE_TESTS
noinst_PROGRAMS = \
ini-file-parser-test
endif

avahi_daemon_SOURCES = \
main.c main.h \
Expand Down
42 changes: 7 additions & 35 deletions avahi-dnsconfd/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ static enum {
BROWSING
} state = ACKWAIT;

static int quit = 0;

static enum {
DAEMON_RUN,
DAEMON_KILL,
Expand All @@ -72,8 +70,13 @@ static enum {
DAEMON_CHECK
} command = DAEMON_RUN;

static int quit = 0;
static int daemonize = 0;

#if !HAVE_DECL_ENVIRON
extern char **environ;
#endif

typedef struct DNSServerInfo DNSServerInfo;

struct DNSServerInfo {
Expand Down Expand Up @@ -213,37 +216,6 @@ static char *concat_dns_servers(AvahiIfIndex interface) {
return r;
}

static char *getifname(AvahiIfIndex interface, char *name, size_t len) {
int fd = -1;
char *ret = NULL;
struct ifreq ifr;

assert(interface >= 0);

if ((fd = socket(PF_INET, SOCK_DGRAM, 0)) < 0) {
daemon_log(LOG_ERR, "socket(): %s", strerror(errno));
goto finish;
}

memset(&ifr, 0, sizeof(ifr));
ifr.ifr_ifindex = (int) interface;

if (ioctl(fd, SIOCGIFNAME, &ifr) < 0) {
daemon_log(LOG_ERR, "SIOCGIFNAME: %s\n", strerror(errno));
goto finish;
}

strncpy(name, ifr.ifr_name, len-1);
name[len-1] = 0;
ret = name;

finish:
if (fd >= 0)
close(fd);

return ret;
}

static void set_env(const char *name, const char *value) {
char **e;
size_t l;
Expand Down Expand Up @@ -274,11 +246,11 @@ static void run_script(int new, AvahiIfIndex interface, AvahiProtocol protocol,
char *p;
int ret;
char ia[16], pa[16];
char name[IFNAMSIZ+1];
char name[IF_NAMESIZE];

assert(interface > 0);

if (!getifname(interface, name, sizeof(name)))
if (!if_indextoname(interface, name))
return;

p = concat_dns_servers(interface);
Expand Down
4 changes: 4 additions & 0 deletions avahi-glib/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,13 @@ avahiinclude_HEADERS = \
lib_LTLIBRARIES = \
libavahi-glib.la

if ENABLE_TESTS

noinst_PROGRAMS = \
glib-watch-test

endif

libavahi_glib_la_SOURCES = \
glib-watch.c glib-watch.h \
glib-malloc.h glib-malloc.c
Expand Down

0 comments on commit 16d9e30

Please sign in to comment.