strlst.h \
address.h \
alternative.h \
- util.h \
+ domain.h \
cdecl.h \
defs.h \
malloc.h
noinst_PROGRAMS = \
strlst-test \
domain-test \
- alternative-test \
- timeval-test
+ alternative-test
lib_LTLIBRARIES = \
libavahi-common.la
alternative.c alternative.h \
error.c error.h \
strlst.c strlst.h \
- util.c util.h
+ domain.c domain.h
libavahi_common_la_CFLAGS = $(AM_CFLAGS)
libavahi_common_la_LIBADD = $(AM_LDADD)
alternative_test_SOURCES = \
alternative.c alternative.h \
malloc.c malloc.h \
- util.c util.h \
+ domain.c domain.h \
alternative-test.c
alternative_test_CFLAGS = $(AM_CFLAGS)
alternative_test_LDADD = $(AM_LDADD)
domain_test_SOURCES = \
- util.c util.h \
+ domain.c domain.h \
malloc.c malloc.h \
domain-test.c
domain_test_CFLAGS = $(AM_CFLAGS)
domain_test_LDADD = $(AM_LDADD)
-timeval_test_SOURCES = \
- util.c util.h \
- malloc.c malloc.h \
- timeval-test.c
-timeval_test_CFLAGS = $(AM_CFLAGS)
-timeval_test_LDADD = $(AM_LDADD)
-
#include <assert.h>
#include "address.h"
-#include "util.h"
#include "malloc.h"
size_t avahi_address_get_size(const AvahiAddress *a) {
#include "alternative.h"
#include "malloc.h"
-#include "util.h"
char * avahi_alternative_host_name(const char *s) {
const char *p, *e;
#include <stdio.h>
-#include "util.h"
+#include "domain.h"
#include "malloc.h"
int main(int argc, char *argv[]) {
--- /dev/null
+/* $Id$ */
+
+/***
+ This file is part of avahi.
+
+ avahi is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of the
+ License, or (at your option) any later version.
+
+ avahi is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
+ Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with avahi; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <string.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <limits.h>
+#include <stdio.h>
+#include <ctype.h>
+#include <stdlib.h>
+#include <assert.h>
+
+#include "domain.h"
+#include "malloc.h"
+
+char *avahi_get_host_name(void) {
+#ifdef HOST_NAME_MAX
+ char t[HOST_NAME_MAX];
+#else
+ char t[256];
+#endif
+ gethostname(t, sizeof(t));
+ t[sizeof(t)-1] = 0;
+ return avahi_normalize_name(t);
+}
+
+static char *unescape_uneeded(const char *src, char *ret_dest, size_t size) {
+ int escaped = 0;
+
+ assert(src);
+ assert(ret_dest);
+ assert(size > 0);
+
+ for (; *src; src++) {
+
+ if (!escaped && *src == '\\')
+ escaped = 1;
+ else if (escaped && (*src == '.' || *src == '\\')) {
+
+ if ((size -= 2) <= 1) break;
+
+ *(ret_dest++) = '\\';
+ *(ret_dest++) = *src;
+ escaped = 0;
+ } else {
+ if (--size <= 1) break;
+
+ *(ret_dest++) = *src;
+ escaped = 0;
+ }
+
+ }
+
+ *ret_dest = 0;
+
+ return ret_dest;
+}
+
+char *avahi_normalize_name(const char *s) {
+ char tmp[256];
+ size_t l;
+
+ assert(s);
+
+ unescape_uneeded(s, tmp, sizeof(tmp));
+
+ l = strlen(tmp);
+
+ while (l > 0 && tmp[l-1] == '.')
+ tmp[--l] = 0;
+
+ return avahi_strdup(tmp);
+}
+
+
+/* Read the first label from string *name, unescape "\" and write it to dest */
+char *avahi_unescape_label(const char **name, char *dest, size_t size) {
+ unsigned i = 0;
+ char *d;
+
+ assert(dest);
+ assert(size > 0);
+ assert(name);
+
+ if (!**name)
+ return NULL;
+
+ d = dest;
+
+ for (;;) {
+ if (i >= size)
+ return NULL;
+
+ if (**name == '.') {
+ (*name)++;
+ break;
+ }
+
+ if (**name == 0)
+ break;
+
+ if (**name == '\\') {
+ (*name) ++;
+
+ if (**name == 0)
+ break;
+ }
+
+ *(d++) = *((*name) ++);
+ i++;
+ }
+
+ assert(i < size);
+
+ *d = 0;
+
+ return dest;
+}
+
+/* Escape "\" and ".", append \0 */
+char *avahi_escape_label(const uint8_t* src, size_t src_length, char **ret_name, size_t *ret_size) {
+ char *r;
+
+ assert(src);
+ assert(ret_name);
+ assert(*ret_name);
+ assert(ret_size);
+ assert(*ret_size > 0);
+
+ r = *ret_name;
+
+ while (src_length > 0) {
+ if (*src == '.' || *src == '\\') {
+ if (*ret_size < 3)
+ return NULL;
+
+ *((*ret_name) ++) = '\\';
+ (*ret_size) --;
+ }
+
+ if (*ret_size < 2)
+ return NULL;
+
+ *((*ret_name)++) = *src;
+ (*ret_size) --;
+
+ src_length --;
+ src++;
+ }
+
+ **ret_name = 0;
+
+ return r;
+}
+
+int avahi_domain_equal(const char *a, const char *b) {
+ assert(a);
+ assert(b);
+
+ if (a == b)
+ return 1;
+
+ for (;;) {
+ char ca[65], cb[65], *pa, *pb;
+
+ pa = avahi_unescape_label(&a, ca, sizeof(ca));
+ pb = avahi_unescape_label(&b, cb, sizeof(cb));
+
+ if (!pa && !pb)
+ return 1;
+ else if ((pa && !pb) || (!pa && pb))
+ return 0;
+
+ if (strcasecmp(pa, pb))
+ return 0;
+ }
+
+ return 1;
+}
+
+int avahi_binary_domain_cmp(const char *a, const char *b) {
+ assert(a);
+ assert(b);
+
+ if (a == b)
+ return 0;
+
+ for (;;) {
+ char ca[65], cb[65], *pa, *pb;
+ int r;
+
+ pa = avahi_unescape_label(&a, ca, sizeof(ca));
+ pb = avahi_unescape_label(&b, cb, sizeof(cb));
+
+ if (!pa && !pb)
+ return 0;
+ else if (pa && !pb)
+ return 1;
+ else if (!pa && pb)
+ return -1;
+
+ if ((r = strcmp(pa, pb)))
+ return r;
+ }
+}
+
+unsigned avahi_strhash(const char *p) {
+ unsigned hash = 0;
+
+ for (; *p; p++)
+ hash = 31 * hash + *p;
+
+ return hash;
+}
+
+unsigned avahi_domain_hash(const char *s) {
+ unsigned hash = 0;
+
+ for (;;) {
+ char c[65];
+
+ if (!avahi_unescape_label(&s, c, sizeof(c)))
+ return hash;
+
+ if (!c[0])
+ continue;
+
+ hash += avahi_strhash(avahi_strdown(c));
+ }
+}
+
+int avahi_valid_service_type(const char *t) {
+ const char *p;
+ assert(t);
+
+ if (strlen(t) < 5)
+ return 0;
+
+ if (*t != '_')
+ return 0;
+
+ if (!(p = strchr(t, '.')))
+ return 0;
+
+ if (p - t > 63 || p - t < 2)
+ return 0;
+
+ if (*(++p) != '_')
+ return 0;
+
+ if (strchr(p, '.'))
+ return 0;
+
+ if (strlen(p) > 63 || strlen(p) < 2)
+ return 0;
+
+ return 1;
+}
+
+int avahi_valid_domain_name(const char *t) {
+ const char *p, *dp;
+ int dot = 0;
+
+ assert(t);
+
+ if (*t == 0)
+ return 0;
+
+ /* Domains may not start with a dot */
+ if (*t == '.')
+ return 0;
+
+ dp = t;
+
+ for (p = t; *p; p++) {
+
+ if (*p == '.') {
+ if (dot) /* Two subsequent dots */
+ return 0;
+
+ if (p - dp > 63)
+ return 0;
+
+ dot = 1;
+ dp = p + 1;
+ } else
+ dot = 0;
+
+ }
+
+ if (p - dp > 63)
+ return 0;
+
+ /* A trailing dot IS allowed */
+
+ return 1;
+}
+
+int avahi_valid_service_name(const char *t) {
+ assert(t);
+
+ if (*t == 0)
+ return 0;
+
+ if (strlen(t) > 63)
+ return 0;
+
+ return 1;
+}
+
+int avahi_valid_host_name(const char *t) {
+ assert(t);
+
+ if (*t == 0)
+ return 0;
+
+ if (strlen(t) > 63)
+ return 0;
+
+ if (strchr(t, '.'))
+ return 0;
+
+ return 1;
+}
+
+char *avahi_strdown(char *s) {
+ char *c;
+
+ assert(s);
+
+ for (c = s; *c; c++)
+ *c = (char) tolower(*c);
+
+ return s;
+}
+
+char *avahi_strup(char *s) {
+ char *c;
+ assert(s);
+
+ for (c = s; *c; c++)
+ *c = (char) toupper(*c);
+
+ return s;
+}
+
--- /dev/null
+#ifndef foodomainhfoo
+#define foodimainhfoo
+
+/* $Id$ */
+
+/***
+ This file is part of avahi.
+
+ avahi is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of the
+ License, or (at your option) any later version.
+
+ avahi is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
+ Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with avahi; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+#include <inttypes.h>
+#include <sys/types.h>
+
+#include <avahi-common/cdecl.h>
+
+AVAHI_C_DECL_BEGIN
+
+char *avahi_normalize_name(const char *s); /* avahi_free() the result! */
+char *avahi_get_host_name(void); /* avahi_free() the result! */
+
+int avahi_domain_equal(const char *a, const char *b);
+int avahi_binary_domain_cmp(const char *a, const char *b);
+
+/* Read the first label from the textual domain name *name, unescape
+ * it and write it to dest, *name is changed to point to the next label*/
+char *avahi_unescape_label(const char **name, char *dest, size_t size);
+
+/* Escape the domain name in *src and write it to *ret_name */
+char *avahi_escape_label(const uint8_t* src, size_t src_length, char **ret_name, size_t *ret_size);
+
+unsigned avahi_strhash(const char *p);
+unsigned avahi_domain_hash(const char *s);
+
+int avahi_valid_service_type(const char *t);
+int avahi_valid_domain_name(const char *t);
+int avahi_valid_service_name(const char *t);
+int avahi_valid_host_name(const char *t);
+
+char *avahi_strup(char *s);
+char *avahi_strdown(char *s);
+
+AVAHI_C_DECL_END
+
+#endif
+++ /dev/null
-/* $Id$ */
-
-/***
- This file is part of avahi.
-
- avahi is free software; you can redistribute it and/or modify it
- under the terms of the GNU Lesser General Public License as
- published by the Free Software Foundation; either version 2.1 of the
- License, or (at your option) any later version.
-
- avahi is distributed in the hope that it will be useful, but WITHOUT
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
- Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with avahi; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- USA.
-***/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdio.h>
-#include "util.h"
-
-int main(int argc, 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", avahi_timeval_diff(&a, &b));
-}
+++ /dev/null
-/* $Id$ */
-
-/***
- This file is part of avahi.
-
- avahi is free software; you can redistribute it and/or modify it
- under the terms of the GNU Lesser General Public License as
- published by the Free Software Foundation; either version 2.1 of the
- License, or (at your option) any later version.
-
- avahi is distributed in the hope that it will be useful, but WITHOUT
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
- Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with avahi; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- USA.
-***/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <string.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <limits.h>
-#include <stdio.h>
-#include <ctype.h>
-#include <stdlib.h>
-#include <assert.h>
-
-#include "util.h"
-#include "malloc.h"
-
-char *avahi_get_host_name(void) {
-#ifdef HOST_NAME_MAX
- char t[HOST_NAME_MAX];
-#else
- char t[256];
-#endif
- gethostname(t, sizeof(t));
- t[sizeof(t)-1] = 0;
- return avahi_normalize_name(t);
-}
-
-static char *unescape_uneeded(const char *src, char *ret_dest, size_t size) {
- int escaped = 0;
-
- assert(src);
- assert(ret_dest);
- assert(size > 0);
-
- for (; *src; src++) {
-
- if (!escaped && *src == '\\')
- escaped = 1;
- else if (escaped && (*src == '.' || *src == '\\')) {
-
- if ((size -= 2) <= 1) break;
-
- *(ret_dest++) = '\\';
- *(ret_dest++) = *src;
- escaped = 0;
- } else {
- if (--size <= 1) break;
-
- *(ret_dest++) = *src;
- escaped = 0;
- }
-
- }
-
- *ret_dest = 0;
-
- return ret_dest;
-}
-
-char *avahi_normalize_name(const char *s) {
- char tmp[256];
- size_t l;
-
- assert(s);
-
- unescape_uneeded(s, tmp, sizeof(tmp));
-
- l = strlen(tmp);
-
- while (l > 0 && tmp[l-1] == '.')
- tmp[--l] = 0;
-
- return avahi_strdup(tmp);
-}
-
-int avahi_timeval_compare(const struct timeval *a, const struct timeval *b) {
- assert(a);
- assert(b);
-
- if (a->tv_sec < b->tv_sec)
- return -1;
-
- if (a->tv_sec > b->tv_sec)
- return 1;
-
- if (a->tv_usec < b->tv_usec)
- return -1;
-
- if (a->tv_usec > b->tv_usec)
- return 1;
-
- return 0;
-}
-
-AvahiUsec avahi_timeval_diff(const struct timeval *a, const struct timeval *b) {
- assert(a);
- assert(b);
-
- if (avahi_timeval_compare(a, b) < 0)
- return - avahi_timeval_diff(b, a);
-
- return ((AvahiUsec) a->tv_sec - b->tv_sec)*1000000 + a->tv_usec - b->tv_usec;
-}
-
-struct timeval* avahi_timeval_add(struct timeval *a, AvahiUsec usec) {
- AvahiUsec u;
- assert(a);
-
- u = usec + a->tv_usec;
-
- if (u < 0) {
- a->tv_usec = (long) (1000000 + (u % 1000000));
- a->tv_sec += (long) (-1 + (u / 1000000));
- } else {
- a->tv_usec = (long) (u % 1000000);
- a->tv_sec += (long) (u / 1000000);
- }
-
- return a;
-}
-
-AvahiUsec avahi_age(const struct timeval *a) {
- struct timeval now;
-
- assert(a);
-
- gettimeofday(&now, NULL);
-
- return avahi_timeval_diff(&now, a);
-}
-
-
-struct timeval *avahi_elapse_time(struct timeval *tv, unsigned msec, unsigned jitter) {
- assert(tv);
-
- gettimeofday(tv, NULL);
-
- if (msec)
- avahi_timeval_add(tv, (AvahiUsec) msec*1000);
-
- if (jitter)
- avahi_timeval_add(tv, (AvahiUsec) (jitter*1000.0*rand()/(RAND_MAX+1.0)));
-
- return tv;
-}
-
-int avahi_set_cloexec(int fd) {
- int n;
-
- assert(fd >= 0);
-
- if ((n = fcntl(fd, F_GETFD)) < 0)
- return -1;
-
- if (n & FD_CLOEXEC)
- return 0;
-
- return fcntl(fd, F_SETFD, n|FD_CLOEXEC);
-}
-
-int avahi_set_nonblock(int fd) {
- int n;
-
- assert(fd >= 0);
-
- if ((n = fcntl(fd, F_GETFL)) < 0)
- return -1;
-
- if (n & O_NONBLOCK)
- return 0;
-
- return fcntl(fd, F_SETFL, n|O_NONBLOCK);
-}
-
-int avahi_wait_for_write(int fd) {
- fd_set fds;
- int r;
-
- FD_ZERO(&fds);
- FD_SET(fd, &fds);
-
- if ((r = select(fd+1, NULL, &fds, NULL, NULL)) < 0)
- return -1;
-
- assert(r > 0);
-
- return 0;
-}
-
-/* Read the first label from string *name, unescape "\" and write it to dest */
-char *avahi_unescape_label(const char **name, char *dest, size_t size) {
- unsigned i = 0;
- char *d;
-
- assert(dest);
- assert(size > 0);
- assert(name);
-
- if (!**name)
- return NULL;
-
- d = dest;
-
- for (;;) {
- if (i >= size)
- return NULL;
-
- if (**name == '.') {
- (*name)++;
- break;
- }
-
- if (**name == 0)
- break;
-
- if (**name == '\\') {
- (*name) ++;
-
- if (**name == 0)
- break;
- }
-
- *(d++) = *((*name) ++);
- i++;
- }
-
- assert(i < size);
-
- *d = 0;
-
- return dest;
-}
-
-/* Escape "\" and ".", append \0 */
-char *avahi_escape_label(const uint8_t* src, size_t src_length, char **ret_name, size_t *ret_size) {
- char *r;
-
- assert(src);
- assert(ret_name);
- assert(*ret_name);
- assert(ret_size);
- assert(*ret_size > 0);
-
- r = *ret_name;
-
- while (src_length > 0) {
- if (*src == '.' || *src == '\\') {
- if (*ret_size < 3)
- return NULL;
-
- *((*ret_name) ++) = '\\';
- (*ret_size) --;
- }
-
- if (*ret_size < 2)
- return NULL;
-
- *((*ret_name)++) = *src;
- (*ret_size) --;
-
- src_length --;
- src++;
- }
-
- **ret_name = 0;
-
- return r;
-}
-
-int avahi_domain_equal(const char *a, const char *b) {
- assert(a);
- assert(b);
-
- if (a == b)
- return 1;
-
- for (;;) {
- char ca[65], cb[65], *pa, *pb;
-
- pa = avahi_unescape_label(&a, ca, sizeof(ca));
- pb = avahi_unescape_label(&b, cb, sizeof(cb));
-
- if (!pa && !pb)
- return 1;
- else if ((pa && !pb) || (!pa && pb))
- return 0;
-
- if (strcasecmp(pa, pb))
- return 0;
- }
-
- return 1;
-}
-
-int avahi_binary_domain_cmp(const char *a, const char *b) {
- assert(a);
- assert(b);
-
- if (a == b)
- return 0;
-
- for (;;) {
- char ca[65], cb[65], *pa, *pb;
- int r;
-
- pa = avahi_unescape_label(&a, ca, sizeof(ca));
- pb = avahi_unescape_label(&b, cb, sizeof(cb));
-
- if (!pa && !pb)
- return 0;
- else if (pa && !pb)
- return 1;
- else if (!pa && pb)
- return -1;
-
- if ((r = strcmp(pa, pb)))
- return r;
- }
-}
-
-void avahi_hexdump(const void* p, size_t size) {
- const uint8_t *c = p;
- assert(p);
-
- printf("Dumping %u bytes from %p:\n", size, p);
-
- while (size > 0) {
- unsigned i;
-
- for (i = 0; i < 16; i++) {
- if (i < size)
- printf("%02x ", c[i]);
- else
- printf(" ");
- }
-
- for (i = 0; i < 16; i++) {
- if (i < size)
- printf("%c", c[i] >= 32 && c[i] < 127 ? c[i] : '.');
- else
- printf(" ");
- }
-
- printf("\n");
-
- c += 16;
-
- if (size <= 16)
- break;
-
- size -= 16;
- }
-}
-
-unsigned avahi_strhash(const char *p) {
- unsigned hash = 0;
-
- for (; *p; p++)
- hash = 31 * hash + *p;
-
- return hash;
-}
-
-unsigned avahi_domain_hash(const char *s) {
- unsigned hash = 0;
-
- for (;;) {
- char c[65];
-
- if (!avahi_unescape_label(&s, c, sizeof(c)))
- return hash;
-
- if (!c[0])
- continue;
-
- hash += avahi_strhash(avahi_strdown(c));
- }
-}
-
-char *avahi_format_mac_address(const uint8_t* mac, size_t size) {
- char *r, *t;
- unsigned i;
- static const char hex[] = "0123456789abcdef";
-
- t = r = avahi_new(char, size > 0 ? size*3 : 1);
-
- if (size <= 0) {
- *r = 0;
- return r;
- }
-
- for (i = 0; i < size; i++) {
- *(t++) = hex[*mac >> 4];
- *(t++) = hex[*mac & 0xF];
- *(t++) = ':';
-
- mac++;
- }
-
- *(--t) = 0;
- return r;
-}
-
-int avahi_valid_service_type(const char *t) {
- const char *p;
- assert(t);
-
- if (strlen(t) < 5)
- return 0;
-
- if (*t != '_')
- return 0;
-
- if (!(p = strchr(t, '.')))
- return 0;
-
- if (p - t > 63 || p - t < 2)
- return 0;
-
- if (*(++p) != '_')
- return 0;
-
- if (strchr(p, '.'))
- return 0;
-
- if (strlen(p) > 63 || strlen(p) < 2)
- return 0;
-
- return 1;
-}
-
-int avahi_valid_domain_name(const char *t) {
- const char *p, *dp;
- int dot = 0;
-
- assert(t);
-
- if (*t == 0)
- return 0;
-
- /* Domains may not start with a dot */
- if (*t == '.')
- return 0;
-
- dp = t;
-
- for (p = t; *p; p++) {
-
- if (*p == '.') {
- if (dot) /* Two subsequent dots */
- return 0;
-
- if (p - dp > 63)
- return 0;
-
- dot = 1;
- dp = p + 1;
- } else
- dot = 0;
-
- }
-
- if (p - dp > 63)
- return 0;
-
- /* A trailing dot IS allowed */
-
- return 1;
-}
-
-int avahi_valid_service_name(const char *t) {
- assert(t);
-
- if (*t == 0)
- return 0;
-
- if (strlen(t) > 63)
- return 0;
-
- return 1;
-}
-
-int avahi_valid_host_name(const char *t) {
- assert(t);
-
- if (*t == 0)
- return 0;
-
- if (strlen(t) > 63)
- return 0;
-
- if (strchr(t, '.'))
- return 0;
-
- return 1;
-}
-
-char *avahi_strdown(char *s) {
- char *c;
-
- assert(s);
-
- for (c = s; *c; c++)
- *c = (char) tolower(*c);
-
- return s;
-}
-
-char *avahi_strup(char *s) {
- char *c;
- assert(s);
-
- for (c = s; *c; c++)
- *c = (char) toupper(*c);
-
- return s;
-}
-
+++ /dev/null
-#ifndef fooutilhfoo
-#define fooutilhfoo
-
-/* $Id$ */
-
-/***
- This file is part of avahi.
-
- avahi is free software; you can redistribute it and/or modify it
- under the terms of the GNU Lesser General Public License as
- published by the Free Software Foundation; either version 2.1 of the
- License, or (at your option) any later version.
-
- avahi is distributed in the hope that it will be useful, but WITHOUT
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
- Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with avahi; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- USA.
-***/
-
-#include <inttypes.h>
-#include <stdarg.h>
-#include <sys/time.h>
-
-#include <avahi-common/cdecl.h>
-
-AVAHI_C_DECL_BEGIN
-
-typedef int64_t AvahiUsec;
-
-char *avahi_normalize_name(const char *s); /* avahi_free() the result! */
-char *avahi_get_host_name(void); /* avahi_free() the result! */
-
-int avahi_timeval_compare(const struct timeval *a, const struct timeval *b);
-AvahiUsec avahi_timeval_diff(const struct timeval *a, const struct timeval *b);
-struct timeval* avahi_timeval_add(struct timeval *a, AvahiUsec usec);
-
-AvahiUsec avahi_age(const struct timeval *a);
-struct timeval *avahi_elapse_time(struct timeval *tv, unsigned msec, unsigned jitter);
-
-int avahi_set_cloexec(int fd);
-int avahi_set_nonblock(int fd);
-int avahi_wait_for_write(int fd);
-
-int avahi_domain_equal(const char *a, const char *b);
-int avahi_binary_domain_cmp(const char *a, const char *b);
-
-void avahi_hexdump(const void *p, size_t size);
-
-/* Read the first label from the textual domain name *name, unescape
- * it and write it to dest, *name is changed to point to the next label*/
-char *avahi_unescape_label(const char **name, char *dest, size_t size);
-
-/* Escape the domain name in *src and write it to *ret_name */
-char *avahi_escape_label(const uint8_t* src, size_t src_length, char **ret_name, size_t *ret_size);
-
-unsigned avahi_strhash(const char *p);
-unsigned avahi_domain_hash(const char *s);
-
-char *avahi_format_mac_address(const uint8_t* mac, size_t size);
-
-int avahi_valid_service_type(const char *t);
-int avahi_valid_domain_name(const char *t);
-int avahi_valid_service_name(const char *t);
-int avahi_valid_host_name(const char *t);
-
-char *avahi_strdown(char *s);
-char *avahi_strup(char *s);
-
-AVAHI_C_DECL_END
-
-#endif
conformance-test \
avahi-reflector \
dns-test \
- timeeventq-test
+ timeeventq-test \
+ timeval-test
libavahi_core_la_SOURCES = \
timeeventq.c timeeventq.h\
rr.c rr.h \
core.h \
log.c log.h \
- browse-dns-server.c
+ browse-dns-server.c \
+ fdutil.h fdutil.c \
+ timeval.h timeval.c \
+ util.c util.h
libavahi_core_la_CFLAGS = $(AM_CFLAGS)
libavahi_core_la_LIBADD = $(AM_LDADD) $(COMMON_LDADD)
dns.c dns.h \
dns-test.c \
log.c log.h \
+ util.c util.h \
rr.c rr.h
dns_test_CFLAGS = $(AM_CFLAGS)
dns_test_LDADD = $(AM_LDADD) $(COMMON_LDADD)
timeeventq_test_SOURCES = \
timeeventq-test.c \
timeeventq.h timeeventq.c \
+ timeval.c timeval.h \
prioq.h prioq.c
timeeventq_test_CFLAGS = $(AM_CFLAGS)
timeeventq_test_LDADD = $(AM_LDADD) $(COMMON_LDADD)
+timeval_test_SOURCES = \
+ timeval.c timeval.h \
+ timeval-test.c
+timeval_test_CFLAGS = $(AM_CFLAGS)
+timeval_test_LDADD = $(AM_LDADD)
+
valgrind: avahi-test
libtool --mode=execute valgrind ./avahi-test
#endif
#include "announce.h"
-#include "util.h"
+#include "timeval.h"
#define AVAHI_ANNOUNCEMENT_JITTER_MSEC 250
#define AVAHI_PROBE_JITTER_MSEC 250
#include <string.h>
+#include <avahi-common/domain.h>
#include "browse.h"
-#include "util.h"
#include "log.h"
#include "rr.h"
#include <config.h>
#endif
+#include <avahi-common/domain.h>
#include "browse.h"
-#include "util.h"
struct AvahiDomainBrowser {
AvahiServer *server;
#include <string.h>
+#include <avahi-common/domain.h>
#include "browse.h"
-#include "util.h"
#include "log.h"
struct AvahiServiceTypeBrowser {
#include <string.h>
+#include <avahi-common/domain.h>
#include "browse.h"
-#include "util.h"
#include "log.h"
struct AvahiServiceBrowser {
#endif
#include "browse.h"
-#include "util.h"
+#include "timeval.h"
#include "log.h"
struct AvahiRecordBrowser {
#include <string.h>
-#include "util.h"
+#include "timeval.h"
#include "cache.h"
#include "log.h"
#include <stdio.h>
#include "core.h"
-#include "util.h"
#include "alternative.h"
#include "log.h"
#include <config.h>
#endif
+#include <avahi-common/domain.h>
#include "dns.h"
-#include "util.h"
#include "log.h"
+#include "util.h"
int main(int argc, char *argv[]) {
gchar t[256];
#include <string.h>
#include <stdio.h>
+#include <avahi-common/domain.h>
#include "dns.h"
-#include "util.h"
AvahiDnsPacket* avahi_dns_packet_new(guint mtu) {
AvahiDnsPacket *p;
--- /dev/null
+/* $Id$ */
+
+/***
+ This file is part of avahi.
+
+ avahi is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of the
+ License, or (at your option) any later version.
+
+ avahi is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
+ Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with avahi; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <unistd.h>
+#include <fcntl.h>
+#include <assert.h>
+
+#include "fdutil.h"
+
+int avahi_set_cloexec(int fd) {
+ int n;
+
+ assert(fd >= 0);
+
+ if ((n = fcntl(fd, F_GETFD)) < 0)
+ return -1;
+
+ if (n & FD_CLOEXEC)
+ return 0;
+
+ return fcntl(fd, F_SETFD, n|FD_CLOEXEC);
+}
+
+int avahi_set_nonblock(int fd) {
+ int n;
+
+ assert(fd >= 0);
+
+ if ((n = fcntl(fd, F_GETFL)) < 0)
+ return -1;
+
+ if (n & O_NONBLOCK)
+ return 0;
+
+ return fcntl(fd, F_SETFL, n|O_NONBLOCK);
+}
+
+int avahi_wait_for_write(int fd) {
+ fd_set fds;
+ int r;
+
+ FD_ZERO(&fds);
+ FD_SET(fd, &fds);
+
+ if ((r = select(fd+1, NULL, &fds, NULL, NULL)) < 0)
+ return -1;
+
+ assert(r > 0);
+
+ return 0;
+}
--- /dev/null
+#ifndef foofdutilhfoo
+#define foofdutilhfoo
+
+/* $Id$ */
+
+/***
+ This file is part of avahi.
+
+ avahi is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of the
+ License, or (at your option) any later version.
+
+ avahi is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
+ Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with avahi; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+#include <avahi-common/cdecl.h>
+
+AVAHI_C_DECL_BEGIN
+
+int avahi_set_cloexec(int fd);
+int avahi_set_nonblock(int fd);
+int avahi_wait_for_write(int fd);
+
+AVAHI_C_DECL_END
+
+#endif
#include <config.h>
#endif
+#include <avahi-common/domain.h>
+
#include "probe-sched.h"
-#include "util.h"
+#include "timeval.h"
#include "log.h"
#define AVAHI_PROBE_HISTORY_MSEC 150
#endif
#include "query-sched.h"
-#include "util.h"
+#include "timeval.h"
#define AVAHI_QUERY_HISTORY_MSEC 100
#define AVAHI_QUERY_DEFER_MSEC 100
#endif
#include "browse.h"
-#include "util.h"
+#include "timeval.h"
struct AvahiAddressResolver {
AvahiServer *server;
#include <config.h>
#endif
+#include <avahi-common/domain.h>
+#include "timeval.h"
#include "browse.h"
-#include "util.h"
struct AvahiHostNameResolver {
AvahiServer *server;
#include <string.h>
+#include <avahi-common/domain.h>
#include "browse.h"
-#include "util.h"
+#include "timeval.h"
struct AvahiServiceResolver {
AvahiServer *server;
#endif
#include "response-sched.h"
-#include "util.h"
+#include "timeval.h"
#include "log.h"
#define AVAHI_RESPONSE_HISTORY_MSEC 500
#include <sys/socket.h>
#include <arpa/inet.h>
-#include "util.h"
+#include <avahi-common/domain.h>
#include "rr.h"
AvahiKey *avahi_key_new(const gchar *name, guint16 class, guint16 type) {
#include <errno.h>
#include <stdio.h>
+#include <avahi-common/domain.h>
+
#include "server.h"
-#include "util.h"
+#include "timeval.h"
#include "iface.h"
#include "socket.h"
#include "browse.h"
#include <sys/ioctl.h>
#include "dns.h"
-#include "util.h"
+#include "fdutil.h"
#include "socket.h"
#include "log.h"
#include <glib.h>
-#include "util.h"
#include "timeeventq.h"
+#include "timeval.h"
static AvahiTimeEventQueue *q = NULL;
#endif
#include "timeeventq.h"
-#include "util.h"
+#include "timeval.h"
static gint compare(gconstpointer _a, gconstpointer _b) {
const AvahiTimeEvent *a = _a, *b = _b;
--- /dev/null
+/* $Id$ */
+
+/***
+ This file is part of avahi.
+
+ avahi is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of the
+ License, or (at your option) any later version.
+
+ avahi is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
+ Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with avahi; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include "timeval.h"
+
+int main(int argc, 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", avahi_timeval_diff(&a, &b));
+}
--- /dev/null
+/* $Id$ */
+
+/***
+ This file is part of avahi.
+
+ avahi is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of the
+ License, or (at your option) any later version.
+
+ avahi is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
+ Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with avahi; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <assert.h>
+
+#include "timeval.h"
+
+int avahi_timeval_compare(const struct timeval *a, const struct timeval *b) {
+ assert(a);
+ assert(b);
+
+ if (a->tv_sec < b->tv_sec)
+ return -1;
+
+ if (a->tv_sec > b->tv_sec)
+ return 1;
+
+ if (a->tv_usec < b->tv_usec)
+ return -1;
+
+ if (a->tv_usec > b->tv_usec)
+ return 1;
+
+ return 0;
+}
+
+AvahiUsec avahi_timeval_diff(const struct timeval *a, const struct timeval *b) {
+ assert(a);
+ assert(b);
+
+ if (avahi_timeval_compare(a, b) < 0)
+ return - avahi_timeval_diff(b, a);
+
+ return ((AvahiUsec) a->tv_sec - b->tv_sec)*1000000 + a->tv_usec - b->tv_usec;
+}
+
+struct timeval* avahi_timeval_add(struct timeval *a, AvahiUsec usec) {
+ AvahiUsec u;
+ assert(a);
+
+ u = usec + a->tv_usec;
+
+ if (u < 0) {
+ a->tv_usec = (long) (1000000 + (u % 1000000));
+ a->tv_sec += (long) (-1 + (u / 1000000));
+ } else {
+ a->tv_usec = (long) (u % 1000000);
+ a->tv_sec += (long) (u / 1000000);
+ }
+
+ return a;
+}
+
+AvahiUsec avahi_age(const struct timeval *a) {
+ struct timeval now;
+
+ assert(a);
+
+ gettimeofday(&now, NULL);
+
+ return avahi_timeval_diff(&now, a);
+}
+
+
+struct timeval *avahi_elapse_time(struct timeval *tv, unsigned msec, unsigned jitter) {
+ assert(tv);
+
+ gettimeofday(tv, NULL);
+
+ if (msec)
+ avahi_timeval_add(tv, (AvahiUsec) msec*1000);
+
+ if (jitter)
+ avahi_timeval_add(tv, (AvahiUsec) (jitter*1000.0*rand()/(RAND_MAX+1.0)));
+
+ return tv;
+}
+
--- /dev/null
+#ifndef footimevalhfoo
+#define footimevalhfoo
+
+/* $Id$ */
+
+/***
+ This file is part of avahi.
+
+ avahi is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of the
+ License, or (at your option) any later version.
+
+ avahi is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
+ Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with avahi; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+#include <inttypes.h>
+#include <sys/time.h>
+
+#include <avahi-common/cdecl.h>
+
+AVAHI_C_DECL_BEGIN
+
+typedef int64_t AvahiUsec;
+
+int avahi_timeval_compare(const struct timeval *a, const struct timeval *b);
+AvahiUsec avahi_timeval_diff(const struct timeval *a, const struct timeval *b);
+struct timeval* avahi_timeval_add(struct timeval *a, AvahiUsec usec);
+
+AvahiUsec avahi_age(const struct timeval *a);
+struct timeval *avahi_elapse_time(struct timeval *tv, unsigned msec, unsigned jitter);
+
+AVAHI_C_DECL_END
+
+#endif
--- /dev/null
+/* $Id$ */
+
+/***
+ This file is part of avahi.
+
+ avahi is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of the
+ License, or (at your option) any later version.
+
+ avahi is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
+ Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with avahi; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+
+#include <glib.h>
+
+#include "util.h"
+
+void avahi_hexdump(const void* p, size_t size) {
+ const uint8_t *c = p;
+ assert(p);
+
+ printf("Dumping %u bytes from %p:\n", size, p);
+
+ while (size > 0) {
+ unsigned i;
+
+ for (i = 0; i < 16; i++) {
+ if (i < size)
+ printf("%02x ", c[i]);
+ else
+ printf(" ");
+ }
+
+ for (i = 0; i < 16; i++) {
+ if (i < size)
+ printf("%c", c[i] >= 32 && c[i] < 127 ? c[i] : '.');
+ else
+ printf(" ");
+ }
+
+ printf("\n");
+
+ c += 16;
+
+ if (size <= 16)
+ break;
+
+ size -= 16;
+ }
+}
+
+
+char *avahi_format_mac_address(const uint8_t* mac, size_t size) {
+ char *r, *t;
+ unsigned i;
+ static const char hex[] = "0123456789abcdef";
+
+ t = r = g_new(char, size > 0 ? size*3 : 1);
+
+ if (size <= 0) {
+ *r = 0;
+ return r;
+ }
+
+ for (i = 0; i < size; i++) {
+ *(t++) = hex[*mac >> 4];
+ *(t++) = hex[*mac & 0xF];
+ *(t++) = ':';
+
+ mac++;
+ }
+
+ *(--t) = 0;
+ return r;
+}
+
--- /dev/null
+#ifndef fooutilhfoo
+#define fooutilhfoo
+
+/* $Id$ */
+
+/***
+ This file is part of avahi.
+
+ avahi is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of the
+ License, or (at your option) any later version.
+
+ avahi is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
+ Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with avahi; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ USA.
+***/
+
+#include <inttypes.h>
+
+#include <avahi-common/cdecl.h>
+
+AVAHI_C_DECL_BEGIN
+
+void avahi_hexdump(const void *p, size_t size);
+
+char *avahi_format_mac_address(const uint8_t* mac, size_t size);
+
+AVAHI_C_DECL_END
+
+#endif
gint32 interface, protocol;
gchar *type, *name, *domain, *host;
guint16 port;
- gchar **txt = NULL;
- gint txt_len;
AvahiStringList *strlst;
DBusMessageIter iter, sub;
int j;
#include <glib.h>
-#include <avahi-common/util.h>
#include <avahi-common/llist.h>
#include <libdaemon/dfork.h>