printf("%i\n", avahi_domain_equal("a", "aaa"));
- printf("%u = %u\n", avahi_domain_hash("\\Aaaab\\\\."), avahi_domain_hash("aaaa\\b\\\\"));
+/* printf("%u = %u\n", avahi_domain_hash("\\Aaaab\\\\."), avahi_domain_hash("aaaa\\b\\\\")); */
return 0;
}
}
}
-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) {
+int avahi_is_valid_service_type(const char *t) {
const char *p;
assert(t);
return 1;
}
-int avahi_valid_domain_name(const char *t) {
+int avahi_is_valid_domain_name(const char *t) {
const char *p, *dp;
int dot = 0;
return 1;
}
-int avahi_valid_service_name(const char *t) {
+int avahi_is_valid_service_name(const char *t) {
assert(t);
if (*t == 0)
return 1;
}
-int avahi_valid_host_name(const char *t) {
+int avahi_is_valid_host_name(const char *t) {
assert(t);
if (*t == 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;
-}
-
/** 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);
-/** Return some kind of hash value for a string */
-unsigned avahi_strhash(const char *p);
-
-/** Return some kind of hash value for a domain */
-unsigned avahi_domain_hash(const char *s);
-
/** Return 1 when the specified string contains a valid service type, 0 otherwise */
-int avahi_valid_service_type(const char *t);
+int avahi_is_valid_service_type(const char *t);
/** Return 1 when the specified string contains a valid domain name, 0 otherwise */
-int avahi_valid_domain_name(const char *t);
+int avahi_is_valid_domain_name(const char *t);
/** Return 1 when the specified string contains a valid service name, 0 otherwise */
-int avahi_valid_service_name(const char *t);
+int avahi_is_valid_service_name(const char *t);
/** Return 1 when the specified string contains a valid non-FQDN host name (i.e. without dots), 0 otherwise */
-int avahi_valid_host_name(const char *t);
-
-/** Change every character in the string to upper case (ASCII), return a pointer to the string */
-char *avahi_strup(char *s);
-
-/** Change every character in the string to lower case (ASCII), return a pointer to the string */
-char *avahi_strdown(char *s);
+int avahi_is_valid_host_name(const char *t);
AVAHI_C_DECL_END
char *avahi_strdup_printf(const char *fmt, ... ) {
char *s;
va_list ap;
+
+ assert(fmt);
va_start(ap, fmt);
s = avahi_strdup_vprintf(fmt, ap);
return s;
}
+void *avahi_memdup(const void *s, size_t l) {
+ void *p;
+ assert(s);
+
+ if (!(p = avahi_malloc(l)))
+ return NULL;
+
+ memcpy(p, s, l);
+ return p;
+}
char *avahi_strdup(const char *s);
/** Just like libc's strndup() */
-char *avahi_strndup(const char *s, size_t l);
+char *avahi_strndup(const char *s, size_t l);
+
+/** Duplicate the given memory block into a new one allocated with avahi_malloc() */
+void *avahi_memdup(const void *s, size_t l);
/** Wraps allocator functions */
typedef struct AvahiAllocator AvahiAllocator;
conformance-test \
avahi-reflector \
dns-test \
- timeeventq-test
+ timeeventq-test \
+ hashmap-test
libavahi_core_la_SOURCES = \
timeeventq.c timeeventq.h\
log.c log.h \
browse-dns-server.c \
fdutil.h fdutil.c \
- util.c util.h
+ util.c util.h \
+ hashmap.c hashmap.h
libavahi_core_la_CFLAGS = $(AM_CFLAGS)
libavahi_core_la_LIBADD = $(AM_LDADD) $(COMMON_LDADD)
dns-test.c \
log.c log.h \
util.c util.h \
- rr.c rr.h
+ rr.c rr.h \
+ hashmap.c hashmap.h
dns_test_CFLAGS = $(AM_CFLAGS)
dns_test_LDADD = $(AM_LDADD) $(COMMON_LDADD)
timeeventq_test_CFLAGS = $(AM_CFLAGS)
timeeventq_test_LDADD = $(AM_LDADD) $(COMMON_LDADD)
+hashmap_test_SOURCES = \
+ hashmap-test.c \
+ hashmap.h hashmap.c \
+ util.h util.c
+hashmap_test_CFLAGS = $(AM_CFLAGS)
+hashmap_test_LDADD = $(AM_LDADD) $(COMMON_LDADD)
+
valgrind: avahi-test
libtool --mode=execute valgrind ./avahi-test
g_assert(callback);
g_assert(type == AVAHI_DNS_SERVER_RESOLVE || type == AVAHI_DNS_SERVER_UPDATE);
- if (domain && !avahi_valid_domain_name(domain)) {
+ if (domain && !avahi_is_valid_domain_name(domain)) {
avahi_server_set_errno(server, AVAHI_ERR_INVALID_DOMAIN_NAME);
return NULL;
}
g_assert(callback);
g_assert(type >= AVAHI_DOMAIN_BROWSER_BROWSE && type <= AVAHI_DOMAIN_BROWSER_BROWSE_LEGACY);
- if (domain && !avahi_valid_domain_name(domain)) {
+ if (domain && !avahi_is_valid_domain_name(domain)) {
avahi_server_set_errno(server, AVAHI_ERR_INVALID_DOMAIN_NAME);
return NULL;
}
g_assert(server);
g_assert(callback);
- if (domain && !avahi_valid_domain_name(domain)) {
+ if (domain && !avahi_is_valid_domain_name(domain)) {
avahi_server_set_errno(server, AVAHI_ERR_INVALID_DOMAIN_NAME);
return NULL;
}
g_assert(callback);
g_assert(service_type);
- if (!avahi_valid_service_type(service_type)) {
+ if (!avahi_is_valid_service_type(service_type)) {
avahi_server_set_errno(server, AVAHI_ERR_INVALID_SERVICE_TYPE);
return NULL;
}
- if (domain && !avahi_valid_domain_name(domain)) {
+ if (domain && !avahi_is_valid_domain_name(domain)) {
avahi_server_set_errno(server, AVAHI_ERR_INVALID_DOMAIN_NAME);
return NULL;
}
return NULL;
}
- if (!avahi_key_valid(key)) {
+ if (!avahi_key_is_valid(key)) {
avahi_server_set_errno(server, AVAHI_ERR_INVALID_KEY);
return NULL;
}
--- /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 <avahi-common/domain.h>
+#include <avahi-common/malloc.h>
+
+#include "hashmap.h"
+#include "util.h"
+
+int main(int argc, 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
+/* $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 <string.h>
+
+#include <avahi-common/llist.h>
+#include <avahi-common/domain.h>
+#include <avahi-common/malloc.h>
+
+#include "hashmap.h"
+#include "util.h"
+
+#define HASH_MAP_SIZE 123
+
+typedef struct Entry Entry;
+struct Entry {
+ AvahiHashmap *hashmap;
+ void *key;
+ void *value;
+
+ AVAHI_LLIST_FIELDS(Entry, bucket);
+ AVAHI_LLIST_FIELDS(Entry, entries);
+};
+
+struct AvahiHashmap {
+ AvahiHashFunc hash_func;
+ AvahiEqualFunc equal_func;
+ AvahiFreeFunc key_free_func, value_free_func;
+
+ Entry *entries[HASH_MAP_SIZE];
+ AVAHI_LLIST_HEAD(Entry, entries_list);
+};
+
+static Entry* entry_get(AvahiHashmap *m, const void *key) {
+ unsigned idx;
+ Entry *e;
+
+ idx = m->hash_func(key) % HASH_MAP_SIZE;
+
+ for (e = m->entries[idx]; e; e = e->bucket_next)
+ if (m->equal_func(key, e->key))
+ return e;
+
+ return NULL;
+}
+
+static void entry_free(AvahiHashmap *m, Entry *e, int stolen) {
+ unsigned idx;
+ assert(e);
+
+ idx = m->hash_func(e->key) % HASH_MAP_SIZE;
+
+ AVAHI_LLIST_REMOVE(Entry, bucket, m->entries[idx], e);
+ AVAHI_LLIST_REMOVE(Entry, entries, m->entries_list, e);
+
+ if (m->key_free_func)
+ m->key_free_func(e->key);
+ if (m->value_free_func && !stolen)
+ m->value_free_func(e->value);
+
+ avahi_free(e);
+}
+
+AvahiHashmap* avahi_hashmap_new(AvahiHashFunc hash_func, AvahiEqualFunc equal_func, AvahiFreeFunc key_free_func, AvahiFreeFunc value_free_func) {
+ AvahiHashmap *m;
+
+ assert(hash_func);
+ assert(equal_func);
+
+ if (!(m = avahi_new(AvahiHashmap, 1)))
+ return NULL;
+
+ m->hash_func = hash_func;
+ m->equal_func = equal_func;
+ m->key_free_func = key_free_func;
+ m->value_free_func = value_free_func;
+
+ memset(m->entries, 0, sizeof(m->entries));
+
+ AVAHI_LLIST_HEAD_INIT(Entry, m->entries_list);
+
+ return m;
+}
+
+void avahi_hashmap_free(AvahiHashmap *m) {
+ assert(m);
+
+ while (m->entries_list)
+ entry_free(m, m->entries_list, 0);
+
+ avahi_free(m);
+}
+
+void* avahi_hashmap_lookup(AvahiHashmap *m, const void *key) {
+ Entry *e;
+
+ assert(m);
+
+ if (!(e = entry_get(m, key)))
+ return NULL;
+
+ return e->value;
+}
+
+void* avahi_hashmap_steal(AvahiHashmap *m, const void *key) {
+ Entry *e;
+ void *v;
+
+ assert(m);
+
+ if (!(e = entry_get(m, key)))
+ return NULL;
+
+ v = e->value;
+ entry_free(m, e, 1);
+ return v;
+}
+
+int avahi_hashmap_insert(AvahiHashmap *m, void *key, void *value) {
+ unsigned idx;
+ Entry *e;
+
+ assert(m);
+
+ if ((e = entry_get(m, key))) {
+ if (m->key_free_func)
+ m->key_free_func(key);
+ if (m->value_free_func)
+ m->value_free_func(value);
+
+ return 1;
+ }
+
+ if (!(e = avahi_new(Entry, 1)))
+ return -1;
+
+ e->hashmap = m;
+ e->key = key;
+ e->value = value;
+
+ AVAHI_LLIST_PREPEND(Entry, entries, m->entries_list, e);
+
+ idx = m->hash_func(key) % HASH_MAP_SIZE;
+ AVAHI_LLIST_PREPEND(Entry, bucket, m->entries[idx], e);
+
+ return 0;
+}
+
+
+int avahi_hashmap_replace(AvahiHashmap *m, void *key, void *value) {
+ unsigned idx;
+ Entry *e;
+
+ assert(m);
+
+ if ((e = entry_get(m, key))) {
+ if (m->key_free_func)
+ m->key_free_func(e->key);
+ if (m->value_free_func)
+ m->value_free_func(e->value);
+
+ e->key = key;
+ e->value = value;
+
+ return 1;
+ }
+
+ if (!(e = avahi_new(Entry, 1)))
+ return -1;
+
+ e->hashmap = m;
+ e->key = key;
+ e->value = value;
+
+ AVAHI_LLIST_PREPEND(Entry, entries, m->entries_list, e);
+
+ idx = m->hash_func(key) % HASH_MAP_SIZE;
+ AVAHI_LLIST_PREPEND(Entry, bucket, m->entries[idx], e);
+
+ return 0;
+}
+
+
+void avahi_hashmap_remove(AvahiHashmap *m, const void *key) {
+ Entry *e;
+
+ assert(m);
+
+ if (!(e = entry_get(m, key)))
+ return;
+
+ entry_free(m, e, 0);
+}
+
+unsigned avahi_string_hash(const void *data) {
+ const char *p = data;
+ unsigned hash = 0;
+
+ for (; *p; p++)
+ hash = 31 * hash + *p;
+
+ return hash;
+}
+
+int avahi_string_equal(const void *a, const void *b) {
+ const char *p = a, *q = b;
+
+ return strcmp(p, q) == 0;
+}
+
+unsigned avahi_domain_hash(const void *data) {
+ unsigned hash = 0;
+ const char *s;
+
+ for (;;) {
+ char c[65];
+
+ if (!avahi_unescape_label(&s, c, sizeof(c)))
+ return hash;
+
+ if (!c[0])
+ continue;
+
+ hash += avahi_string_hash(avahi_strdown(c));
+ }
+}
--- /dev/null
+#ifndef foohashmaphfoo
+#define foohashmaphfoo
+
+/* $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
+
+typedef struct AvahiHashmap AvahiHashmap;
+
+typedef unsigned (*AvahiHashFunc)(const void *data);
+typedef int (*AvahiEqualFunc)(const void *a, const void *b);
+typedef void (*AvahiFreeFunc)(void *p);
+
+AvahiHashmap* avahi_hashmap_new(AvahiHashFunc hash_func, AvahiEqualFunc equal_func, AvahiFreeFunc key_free_func, AvahiFreeFunc value_free_func);
+
+void avahi_hashmap_free(AvahiHashmap *m);
+void* avahi_hashmap_lookup(AvahiHashmap *m, const void *key);
+void* avahi_hashmap_steal(AvahiHashmap *m, const void *key);
+int avahi_hashmap_insert(AvahiHashmap *m, void *key, void *data);
+int avahi_hashmap_replace(AvahiHashmap *m, void *key, void *data);
+void avahi_hashmap_remove(AvahiHashmap *m, const void *key);
+
+unsigned avahi_string_hash(const void *data);
+int avahi_string_equal(const void *a, const void *b);
+
+unsigned avahi_domain_hash(const void *data);
+
+AVAHI_C_DECL_END
+
+#endif
g_assert(aprotocol == AVAHI_PROTO_UNSPEC || aprotocol == AVAHI_PROTO_INET || aprotocol == AVAHI_PROTO_INET6);
- if (!avahi_valid_domain_name(host_name)) {
+ if (!avahi_is_valid_domain_name(host_name)) {
avahi_server_set_errno(server, AVAHI_ERR_INVALID_HOST_NAME);
return NULL;
}
g_assert(aprotocol == AVAHI_PROTO_UNSPEC || aprotocol == AVAHI_PROTO_INET || aprotocol == AVAHI_PROTO_INET6);
- if (!avahi_valid_service_name(name)) {
+ if (!avahi_is_valid_service_name(name)) {
avahi_server_set_errno(server, AVAHI_ERR_INVALID_SERVICE_NAME);
return NULL;
}
- if (!avahi_valid_service_type(type)) {
+ if (!avahi_is_valid_service_type(type)) {
avahi_server_set_errno(server, AVAHI_ERR_INVALID_SERVICE_TYPE);
return NULL;
}
- if (!avahi_valid_domain_name(domain)) {
+ if (!avahi_is_valid_domain_name(domain)) {
avahi_server_set_errno(server, AVAHI_ERR_INVALID_DOMAIN_NAME);
return NULL;
}
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
+#include <assert.h>
#include <avahi-common/domain.h>
+#include <avahi-common/malloc.h>
+
#include "rr.h"
+#include "log.h"
+#include "util.h"
-AvahiKey *avahi_key_new(const gchar *name, guint16 class, guint16 type) {
+AvahiKey *avahi_key_new(const char *name, uint16_t class, uint16_t type) {
AvahiKey *k;
- g_assert(name);
+ assert(name);
- k = g_new(AvahiKey, 1);
+ if (!(k = avahi_new(AvahiKey, 1))) {
+ avahi_log_error("avahi_new() failed.");
+ return NULL;
+ }
+
+ if (!(k->name = avahi_normalize_name(name))) {
+ avahi_log_error("avahi_normalize_name() failed.");
+ avahi_free(k);
+ return NULL;
+ }
+
k->ref = 1;
- k->name = avahi_normalize_name(name);
k->clazz = class;
k->type = type;
-/* g_message("%p %% ref=1", k); */
-
return k;
}
AvahiKey *avahi_key_ref(AvahiKey *k) {
- g_assert(k);
- g_assert(k->ref >= 1);
+ assert(k);
+ assert(k->ref >= 1);
k->ref++;
-/* g_message("%p ++ ref=%i", k, k->ref); */
-
return k;
}
void avahi_key_unref(AvahiKey *k) {
- g_assert(k);
- g_assert(k->ref >= 1);
-
-/* g_message("%p -- ref=%i", k, k->ref-1); */
+ assert(k);
+ assert(k->ref >= 1);
if ((--k->ref) <= 0) {
- g_free(k->name);
- g_free(k);
+ avahi_free(k->name);
+ avahi_free(k);
}
}
-AvahiRecord *avahi_record_new(AvahiKey *k, guint32 ttl) {
+AvahiRecord *avahi_record_new(AvahiKey *k, uint32_t ttl) {
AvahiRecord *r;
- g_assert(k);
+ assert(k);
- r = g_new(AvahiRecord, 1);
+ if (!(r = avahi_new(AvahiRecord, 1))) {
+ avahi_log_error("avahi_new() failed.");
+ return NULL;
+ }
+
r->ref = 1;
r->key = avahi_key_ref(k);
memset(&r->data, 0, sizeof(r->data));
- r->ttl = ttl != (guint32) -1 ? ttl : AVAHI_DEFAULT_TTL;
+ r->ttl = ttl != (uint32_t) -1 ? ttl : AVAHI_DEFAULT_TTL;
return r;
}
-AvahiRecord *avahi_record_new_full(const gchar *name, guint16 class, guint16 type, guint32 ttl) {
+AvahiRecord *avahi_record_new_full(const char *name, uint16_t class, uint16_t type, uint32_t ttl) {
AvahiRecord *r;
AvahiKey *k;
- g_assert(name);
+ assert(name);
- k = avahi_key_new(name, class, type);
+ if (!(k = avahi_key_new(name, class, type))) {
+ avahi_log_error("avahi_key_new() failed.");
+ return NULL;
+ }
+
r = avahi_record_new(k, ttl);
avahi_key_unref(k);
+ if (!r) {
+ avahi_log_error("avahi_record_new() failed.");
+ return NULL;
+ }
+
return r;
}
AvahiRecord *avahi_record_ref(AvahiRecord *r) {
- g_assert(r);
- g_assert(r->ref >= 1);
+ assert(r);
+ assert(r->ref >= 1);
r->ref++;
return r;
}
void avahi_record_unref(AvahiRecord *r) {
- g_assert(r);
- g_assert(r->ref >= 1);
+ assert(r);
+ assert(r->ref >= 1);
if ((--r->ref) <= 0) {
switch (r->key->type) {
case AVAHI_DNS_TYPE_SRV:
- g_free(r->data.srv.name);
+ avahi_free(r->data.srv.name);
break;
case AVAHI_DNS_TYPE_PTR:
case AVAHI_DNS_TYPE_CNAME:
- g_free(r->data.ptr.name);
+ avahi_free(r->data.ptr.name);
break;
case AVAHI_DNS_TYPE_HINFO:
- g_free(r->data.hinfo.cpu);
- g_free(r->data.hinfo.os);
+ avahi_free(r->data.hinfo.cpu);
+ avahi_free(r->data.hinfo.os);
break;
case AVAHI_DNS_TYPE_TXT:
break;
default:
- g_free(r->data.generic.data);
+ avahi_free(r->data.generic.data);
}
avahi_key_unref(r->key);
- g_free(r);
+ avahi_free(r);
}
}
-const gchar *avahi_dns_class_to_string(guint16 class) {
+const char *avahi_dns_class_to_string(uint16_t class) {
if (class & AVAHI_DNS_CACHE_FLUSH)
return "FLUSH";
}
}
-const gchar *avahi_dns_type_to_string(guint16 type) {
+const char *avahi_dns_type_to_string(uint16_t type) {
switch (type) {
case AVAHI_DNS_TYPE_CNAME:
return "CNAME";
}
}
-gchar *avahi_key_to_string(const AvahiKey *k) {
- g_assert(k);
- g_assert(k->ref >= 1);
+char *avahi_key_to_string(const AvahiKey *k) {
+ assert(k);
+ assert(k->ref >= 1);
- return g_strdup_printf("%s\t%s\t%s",
- k->name,
- avahi_dns_class_to_string(k->clazz),
- avahi_dns_type_to_string(k->type));
+ return avahi_strdup_printf("%s\t%s\t%s",
+ k->name,
+ avahi_dns_class_to_string(k->clazz),
+ avahi_dns_type_to_string(k->type));
}
-gchar *avahi_record_to_string(const AvahiRecord *r) {
- gchar *p, *s;
+char *avahi_record_to_string(const AvahiRecord *r) {
+ char *p, *s;
char buf[257], *t = NULL, *d = NULL;
- g_assert(r);
- g_assert(r->ref >= 1);
+ assert(r);
+ assert(r->ref >= 1);
switch (r->key->type) {
case AVAHI_DNS_TYPE_A:
}
p = avahi_key_to_string(r->key);
- s = g_strdup_printf("%s %s ; ttl=%u", p, t ? t : "<unparsable>", r->ttl);
- g_free(p);
- g_free(d);
+ s = avahi_strdup_printf("%s %s ; ttl=%u", p, t ? t : "<unparsable>", r->ttl);
+ avahi_free(p);
+ avahi_free(d);
return s;
}
gboolean avahi_key_equal(const AvahiKey *a, const AvahiKey *b) {
- g_assert(a);
- g_assert(b);
+ assert(a);
+ assert(b);
if (a == b)
return TRUE;
}
gboolean avahi_key_pattern_match(const AvahiKey *pattern, const AvahiKey *k) {
- g_assert(pattern);
- g_assert(k);
+ assert(pattern);
+ assert(k);
/* g_message("equal: %p %p", a, b); */
- g_assert(!avahi_key_is_pattern(k));
+ assert(!avahi_key_is_pattern(k));
if (pattern == k)
return TRUE;
}
gboolean avahi_key_is_pattern(const AvahiKey *k) {
- g_assert(k);
+ assert(k);
return
k->type == AVAHI_DNS_TYPE_ANY ||
}
guint avahi_key_hash(const AvahiKey *k) {
- g_assert(k);
+ assert(k);
return
avahi_domain_hash(k->name) +
}
static gboolean rdata_equal(const AvahiRecord *a, const AvahiRecord *b) {
- g_assert(a);
- g_assert(b);
- g_assert(a->key->type == b->key->type);
+ assert(a);
+ assert(b);
+ assert(a->key->type == b->key->type);
/* t = avahi_record_to_string(a); */
/* g_message("comparing %s", t); */
-/* g_free(t); */
+/* avahi_free(t); */
/* t = avahi_record_to_string(b); */
/* g_message("and %s", t); */
-/* g_free(t); */
+/* avahi_free(t); */
switch (a->key->type) {
}
gboolean avahi_record_equal_no_ttl(const AvahiRecord *a, const AvahiRecord *b) {
- g_assert(a);
- g_assert(b);
+ assert(a);
+ assert(b);
if (a == b)
return TRUE;
AvahiRecord *avahi_record_copy(AvahiRecord *r) {
AvahiRecord *copy;
- copy = g_new(AvahiRecord, 1);
+ if (!(copy = avahi_new(AvahiRecord, 1))) {
+ avahi_log_error("avahi_new() failed.");
+ return NULL;
+ }
+
copy->ref = 1;
copy->key = avahi_key_ref(r->key);
copy->ttl = r->ttl;
switch (r->key->type) {
case AVAHI_DNS_TYPE_PTR:
case AVAHI_DNS_TYPE_CNAME:
- copy->data.ptr.name = g_strdup(r->data.ptr.name);
+ if (!(copy->data.ptr.name = avahi_strdup(r->data.ptr.name)))
+ goto fail;
break;
case AVAHI_DNS_TYPE_SRV:
copy->data.srv.priority = r->data.srv.priority;
copy->data.srv.weight = r->data.srv.weight;
copy->data.srv.port = r->data.srv.port;
- copy->data.srv.name = g_strdup(r->data.srv.name);
+ if (!(copy->data.srv.name = avahi_strdup(r->data.srv.name)))
+ goto fail;
break;
case AVAHI_DNS_TYPE_HINFO:
- copy->data.hinfo.os = g_strdup(r->data.hinfo.os);
- copy->data.hinfo.cpu = g_strdup(r->data.hinfo.cpu);
+ if (!(copy->data.hinfo.os = avahi_strdup(r->data.hinfo.os)))
+ goto fail;
+
+ if (!(copy->data.hinfo.cpu = avahi_strdup(r->data.hinfo.cpu))) {
+ avahi_free(r->data.hinfo.os);
+ goto fail;
+ }
break;
case AVAHI_DNS_TYPE_TXT:
break;
default:
- copy->data.generic.data = g_memdup(r->data.generic.data, r->data.generic.size);
+ if (!(copy->data.generic.data = avahi_memdup(r->data.generic.data, r->data.generic.size)))
+ goto fail;
copy->data.generic.size = r->data.generic.size;
break;
}
return copy;
+
+fail:
+ avahi_log_error("Failed to allocate memory");
+
+ avahi_key_unref(copy->key);
+ avahi_free(copy);
+
+ return NULL;
}
-guint avahi_key_get_estimate_size(AvahiKey *k) {
- g_assert(k);
+size_t avahi_key_get_estimate_size(AvahiKey *k) {
+ assert(k);
return strlen(k->name)+1+4;
}
-guint avahi_record_get_estimate_size(AvahiRecord *r) {
+size_t avahi_record_get_estimate_size(AvahiRecord *r) {
guint n;
- g_assert(r);
+ assert(r);
n = avahi_key_get_estimate_size(r->key) + 4 + 2;
return n;
}
-static gint lexicographical_memcmp(gconstpointer a, size_t al, gconstpointer b, size_t bl) {
+static int lexicographical_memcmp(const void* a, size_t al, const void* b, size_t bl) {
size_t c;
- gint ret;
+ int ret;
- g_assert(a);
- g_assert(b);
+ assert(a);
+ assert(b);
c = al < bl ? al : bl;
if ((ret = memcmp(a, b, c)))
return al == c ? 1 : -1;
}
-static gint uint16_cmp(guint16 a, guint16 b) {
+static int uint16_cmp(uint16_t a, uint16_t b) {
return a == b ? 0 : (a < b ? -1 : 1);
}
-gint avahi_record_lexicographical_compare(AvahiRecord *a, AvahiRecord *b) {
- gint r;
-/* gchar *t1, *t2; */
+int avahi_record_lexicographical_compare(AvahiRecord *a, AvahiRecord *b) {
+ int r;
+/* char *t1, *t2; */
- g_assert(a);
- g_assert(b);
+ assert(a);
+ assert(b);
/* t1 = avahi_record_to_string(a); */
/* t2 = avahi_record_to_string(b); */
/* g_message("lexicocmp: %s %s", t1, t2); */
-/* g_free(t1); */
-/* g_free(t2); */
+/* avahi_free(t1); */
+/* avahi_free(t2); */
if (a == b)
return 0;
guint8 *ma, *mb;
guint asize, bsize;
- ma = g_new(guint8, asize = avahi_string_list_serialize(a->data.txt.string_list, NULL, 0));
- mb = g_new(guint8, bsize = avahi_string_list_serialize(b->data.txt.string_list, NULL, 0));
+ if (!(ma = avahi_new(guint8, asize = avahi_string_list_serialize(a->data.txt.string_list, NULL, 0))))
+ goto fail;
+ if (!(mb = g_new(guint8, bsize = avahi_string_list_serialize(b->data.txt.string_list, NULL, 0)))) {
+ avahi_free(ma);
+ goto fail;
+ }
+
avahi_string_list_serialize(a->data.txt.string_list, ma, asize);
avahi_string_list_serialize(b->data.txt.string_list, mb, bsize);
else
r = 0;
- g_free(ma);
- g_free(mb);
+ avahi_free(ma);
+ avahi_free(mb);
return r;
}
return lexicographical_memcmp(a->data.generic.data, a->data.generic.size,
b->data.generic.data, b->data.generic.size);
}
+
+fail:
+ avahi_log_error("Out of memory");
+ return -1; /* or whatever ... */
}
-gboolean avahi_record_is_goodbye(AvahiRecord *r) {
- g_assert(r);
+int avahi_record_is_goodbye(AvahiRecord *r) {
+ assert(r);
return r->ttl == 0;
}
-gboolean avahi_key_valid(AvahiKey *k) {
- g_assert(k);
+int avahi_key_is_valid(AvahiKey *k) {
+ assert(k);
- if (!avahi_valid_domain_name(k->name))
+ if (!avahi_is_valid_domain_name(k->name))
return FALSE;
return TRUE;
}
-gboolean avahi_record_valid(AvahiRecord *r) {
- g_assert(r);
+int avahi_record_is_valid(AvahiRecord *r) {
+ assert(r);
- if (!avahi_key_valid(r->key))
- return FALSE;
+ if (!avahi_key_is_valid(r->key))
+ return 0;
switch (r->key->type) {
case AVAHI_DNS_TYPE_PTR:
case AVAHI_DNS_TYPE_CNAME:
- return avahi_valid_domain_name(r->data.ptr.name);
+ return avahi_is_valid_domain_name(r->data.ptr.name);
case AVAHI_DNS_TYPE_SRV:
- return avahi_valid_domain_name(r->data.srv.name);
+ return avahi_is_valid_domain_name(r->data.srv.name);
case AVAHI_DNS_TYPE_HINFO:
return
for (strlst = r->data.txt.string_list; strlst; strlst = strlst->next)
if (strlst->size > 255)
- return FALSE;
+ return 0;
- return TRUE;
+ return 1;
}
}
- return TRUE;
+ return 1;
}
USA.
***/
-#include <glib.h>
+/** \file rr.h Functions and definitions for manipulating DNS resource record (RR) data. */
#include <avahi-common/strlst.h>
#include <avahi-common/address.h>
#include <avahi-common/cdecl.h>
-/** \file rr.h Functions and definitions for manipulating DNS resource record (RR) data. */
+#include <inttypes.h>
+#include <sys/types.h>
AVAHI_C_DECL_BEGIN
reference counter. The structure is intended to be treated as "immutable", no
changes should be imposed after creation */
typedef struct {
- guint ref; /**< Reference counter */
- gchar *name; /**< Record name */
- guint16 clazz; /**< Record class, one of the AVAHI_DNS_CLASS_xxx constants */
- guint16 type; /**< Record type, one of the AVAHI_DNS_TYPE_xxx constants */
+ int ref; /**< Reference counter */
+ char *name; /**< Record name */
+ uint16_t clazz; /**< Record class, one of the AVAHI_DNS_CLASS_xxx constants */
+ uint16_t type; /**< Record type, one of the AVAHI_DNS_TYPE_xxx constants */
} AvahiKey;
/** Encapsulates a DNS resource record. The structure is intended to
* be treated as "immutable", no changes should be imposed after
* creation. */
typedef struct {
- guint ref; /**< Reference counter */
+ int ref; /**< Reference counter */
AvahiKey *key; /**< Reference to the query key of thsi record */
- guint32 ttl; /**< DNS TTL of this record */
+ uint32_t ttl; /**< DNS TTL of this record */
union {
struct {
- gpointer data;
- guint16 size;
+ void* data;
+ uint16_t size;
} generic; /**< Generic record data for unknown types */
struct {
- guint16 priority;
- guint16 weight;
- guint16 port;
- gchar *name;
+ uint16_t priority;
+ uint16_t weight;
+ uint16_t port;
+ char *name;
} srv; /**< Data for SRV records */
struct {
- gchar *name;
+ char *name;
} ptr; /**< Data for PTR an CNAME records */
struct {
- gchar *cpu;
- gchar *os;
+ char *cpu;
+ char *os;
} hinfo; /**< Data for HINFO records */
struct {
} AvahiRecord;
/** Create a new AvahiKey object. The reference counter will be set to 1. */
-AvahiKey *avahi_key_new(const gchar *name, guint16 clazz, guint16 type);
+AvahiKey *avahi_key_new(const char *name, uint16_t clazz, uint16_t type);
/** Increase the reference counter of an AvahiKey object by one */
AvahiKey *avahi_key_ref(AvahiKey *k);
/** Check whether two AvahiKey object contain the same
* data. AVAHI_DNS_CLASS_ANY/AVAHI_DNS_TYPE_ANY are treated like any
* other class/type. */
-gboolean avahi_key_equal(const AvahiKey *a, const AvahiKey *b);
+int avahi_key_equal(const AvahiKey *a, const AvahiKey *b);
/** Match a key to a key pattern. The pattern has a type of
AVAHI_DNS_CLASS_ANY, the classes are taken to be equal. Same for the
type. If the pattern has neither class nor type with ANY constants,
this function is identical to avahi_key_equal(). In contrast to
avahi_equal() this function is not commutative. */
-gboolean avahi_key_pattern_match(const AvahiKey *pattern, const AvahiKey *k);
+int avahi_key_pattern_match(const AvahiKey *pattern, const AvahiKey *k);
/** Check whether a key is a pattern key, i.e. the class/type has a
* value of AVAHI_DNS_CLASS_ANY/AVAHI_DNS_TYPE_ANY */
-gboolean avahi_key_is_pattern(const AvahiKey *k);
+int avahi_key_is_pattern(const AvahiKey *k);
/** Return a numeric hash value for a key for usage in hash tables. */
-guint avahi_key_hash(const AvahiKey *k);
+unsigned avahi_key_hash(const AvahiKey *k);
/** Create a new record object. Record data should be filled in right after creation. The reference counter is set to 1. */
-AvahiRecord *avahi_record_new(AvahiKey *k, guint32 ttl);
+AvahiRecord *avahi_record_new(AvahiKey *k, uint32_t ttl);
/** Create a new record object. Record data should be filled in right after creation. The reference counter is set to 1. */
-AvahiRecord *avahi_record_new_full(const gchar *name, guint16 clazz, guint16 type, guint32 ttl);
+AvahiRecord *avahi_record_new_full(const char *name, uint16_t clazz, uint16_t type, uint32_t ttl);
/** Increase the reference counter of an AvahiRecord by one. */
AvahiRecord *avahi_record_ref(AvahiRecord *r);
/** Return a textual representation of the specified DNS class. The
* returned pointer points to a read only internal string. */
-const gchar *avahi_dns_class_to_string(guint16 clazz);
+const char *avahi_dns_class_to_string(uint16_t clazz);
/** Return a textual representation of the specified DNS class. The
* returned pointer points to a read only internal string. */
-const gchar *avahi_dns_type_to_string(guint16 type);
+const char *avahi_dns_type_to_string(uint16_t type);
/** Create a textual representation of the specified key. g_free() the
* result! */
-gchar *avahi_key_to_string(const AvahiKey *k);
+char *avahi_key_to_string(const AvahiKey *k);
/** Create a textual representation of the specified record, similar
* in style to BIND zone file data. g_free() the result! */
-gchar *avahi_record_to_string(const AvahiRecord *r);
+char *avahi_record_to_string(const AvahiRecord *r);
/** Check whether two records are equal (regardless of the TTL */
-gboolean avahi_record_equal_no_ttl(const AvahiRecord *a, const AvahiRecord *b);
+int avahi_record_equal_no_ttl(const AvahiRecord *a, const AvahiRecord *b);
/** Make a deep copy of an AvahiRecord object */
AvahiRecord *avahi_record_copy(AvahiRecord *r);
/** Returns a maximum estimate for the space that is needed to store
* this key in a DNS packet. */
-guint avahi_key_get_estimate_size(AvahiKey *k);
+size_t avahi_key_get_estimate_size(AvahiKey *k);
/** Returns a maximum estimate for the space that is needed to store
* the record in a DNS packet. */
-guint avahi_record_get_estimate_size(AvahiRecord *r);
+size_t avahi_record_get_estimate_size(AvahiRecord *r);
/** Do a mDNS spec conforming lexicographical comparison of the two
* records. Return a negative value if a < b, a positive if a > b,
* zero if equal. */
-gint avahi_record_lexicographical_compare(AvahiRecord *a, AvahiRecord *b);
+int avahi_record_lexicographical_compare(AvahiRecord *a, AvahiRecord *b);
/** Return TRUE if the specified record is an mDNS goodbye record. i.e. TTL is zero. */
-gboolean avahi_record_is_goodbye(AvahiRecord *r);
+int avahi_record_is_goodbye(AvahiRecord *r);
/** Check whether the specified key is valid */
-gboolean avahi_key_valid(AvahiKey *k);
+int avahi_key_is_valid(AvahiKey *k);
/** Check whether the specified record is valid */
-gboolean avahi_record_valid(AvahiRecord *r);
+int avahi_record_is_valid(AvahiRecord *r);
AVAHI_C_DECL_END
USA.
***/
+#include <assert.h>
+
#include <avahi-common/llist.h>
+#include <avahi-common/malloc.h>
+
#include "rrlist.h"
+#include "log.h"
typedef struct AvahiRecordListItem AvahiRecordListItem;
struct AvahiRecordListItem {
- gboolean read;
+ int read;
AvahiRecord *record;
- gboolean unicast_response;
- gboolean flush_cache;
- gboolean auxiliary;
+ int unicast_response;
+ int flush_cache;
+ int auxiliary;
AVAHI_LLIST_FIELDS(AvahiRecordListItem, items);
};
};
AvahiRecordList *avahi_record_list_new(void) {
- AvahiRecordList *l = g_new(AvahiRecordList, 1);
+ AvahiRecordList *l;
+
+ if (!(l = avahi_new(AvahiRecordList, 1))) {
+ avahi_log_error("avahi_new() failed.");
+ return NULL;
+ }
+
AVAHI_LLIST_HEAD_INIT(AvahiRecordListItem, l->read);
AVAHI_LLIST_HEAD_INIT(AvahiRecordListItem, l->unread);
return l;
}
void avahi_record_list_free(AvahiRecordList *l) {
- g_assert(l);
+ assert(l);
avahi_record_list_flush(l);
- g_free(l);
+ avahi_free(l);
}
static void item_free(AvahiRecordList *l, AvahiRecordListItem *i) {
- g_assert(l);
- g_assert(i);
+ assert(l);
+ assert(i);
if (i->read)
AVAHI_LLIST_REMOVE(AvahiRecordListItem, items, l->read, i);
AVAHI_LLIST_REMOVE(AvahiRecordListItem, items, l->unread, i);
avahi_record_unref(i->record);
- g_free(i);
+ avahi_free(i);
}
void avahi_record_list_flush(AvahiRecordList *l) {
- g_assert(l);
+ assert(l);
while (l->read)
item_free(l, l->read);
item_free(l, l->unread);
}
-AvahiRecord* avahi_record_list_next(AvahiRecordList *l, gboolean *flush_cache, gboolean *unicast_response, gboolean *auxiliary) {
+AvahiRecord* avahi_record_list_next(AvahiRecordList *l, int *flush_cache, int *unicast_response, int *auxiliary) {
AvahiRecord *r;
AvahiRecordListItem *i;
if (!(i = l->unread))
return NULL;
- g_assert(!i->read);
+ assert(!i->read);
r = avahi_record_ref(i->record);
if (unicast_response)
static AvahiRecordListItem *get(AvahiRecordList *l, AvahiRecord *r) {
AvahiRecordListItem *i;
- g_assert(l);
- g_assert(r);
+ assert(l);
+ assert(r);
for (i = l->read; i; i = i->items_next)
if (avahi_record_equal_no_ttl(i->record, r))
return NULL;
}
-void avahi_record_list_push(AvahiRecordList *l, AvahiRecord *r, gboolean flush_cache, gboolean unicast_response, gboolean auxiliary) {
+void avahi_record_list_push(AvahiRecordList *l, AvahiRecord *r, int flush_cache, int unicast_response, int auxiliary) {
AvahiRecordListItem *i;
- g_assert(l);
- g_assert(r);
+ assert(l);
+ assert(r);
if (get(l, r))
return;
- i = g_new(AvahiRecordListItem, 1);
+ if (!(i = avahi_new(AvahiRecordListItem, 1))) {
+ avahi_log_error("avahi_new() failed.");
+ return;
+ }
+
i->unicast_response = unicast_response;
i->flush_cache = flush_cache;
i->auxiliary = auxiliary;
void avahi_record_list_drop(AvahiRecordList *l, AvahiRecord *r) {
AvahiRecordListItem *i;
- g_assert(l);
- g_assert(r);
+ assert(l);
+ assert(r);
if (!(i = get(l, r)))
return;
item_free(l, i);
}
-gboolean avahi_record_list_empty(AvahiRecordList *l) {
- g_assert(l);
+int avahi_record_list_is_empty(AvahiRecordList *l) {
+ assert(l);
return !l->unread && !l->read;
}
void avahi_record_list_free(AvahiRecordList *l);
void avahi_record_list_flush(AvahiRecordList *l);
-AvahiRecord* avahi_record_list_next(AvahiRecordList *l, gboolean *flush_cache, gboolean *unicast_response, gboolean *auxiliary);
-void avahi_record_list_push(AvahiRecordList *l, AvahiRecord *r, gboolean flush_cache, gboolean unicast_response, gboolean auxiliary);
+AvahiRecord* avahi_record_list_next(AvahiRecordList *l, int *flush_cache, int *unicast_response, int *auxiliary);
+void avahi_record_list_push(AvahiRecordList *l, AvahiRecord *r, int flush_cache, int unicast_response, int auxiliary);
void avahi_record_list_drop(AvahiRecordList *l, AvahiRecord *r);
-gboolean avahi_record_list_empty(AvahiRecordList *l);
+int avahi_record_list_is_empty(AvahiRecordList *l);
#endif
/* avahi_log_debug("query"); */
- g_assert(avahi_record_list_empty(s->record_list));
+ g_assert(avahi_record_list_is_empty(s->record_list));
is_probe = avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_NSCOUNT) > 0;
avahi_record_unref(record);
}
- if (!avahi_record_list_empty(s->record_list))
+ if (!avahi_record_list_is_empty(s->record_list))
avahi_server_generate_response(s, i, p, a, port, legacy_unicast, is_probe);
return;
/* If the incoming response contained a conflicting record, some
records have been scheduling for sending. We need to flush them
here. */
- if (!avahi_record_list_empty(s->record_list))
+ if (!avahi_record_list_is_empty(s->record_list))
avahi_server_generate_response(s, i, NULL, NULL, 0, FALSE, TRUE);
}
g_assert(s);
g_assert(host_name);
- if (host_name && !avahi_valid_host_name(host_name))
+ if (host_name && !avahi_is_valid_host_name(host_name))
return avahi_server_set_errno(s, AVAHI_ERR_INVALID_HOST_NAME);
withdraw_host_rrs(s);
g_assert(s);
g_assert(domain_name);
- if (domain_name && !avahi_valid_domain_name(domain_name))
+ if (domain_name && !avahi_is_valid_domain_name(domain_name))
return avahi_server_set_errno(s, AVAHI_ERR_INVALID_DOMAIN_NAME);
withdraw_host_rrs(s);
static gint valid_server_config(const AvahiServerConfig *sc) {
- if (sc->host_name && !avahi_valid_host_name(sc->host_name))
+ if (sc->host_name && !avahi_is_valid_host_name(sc->host_name))
return AVAHI_ERR_INVALID_HOST_NAME;
- if (sc->domain_name && !avahi_valid_domain_name(sc->domain_name))
+ if (sc->domain_name && !avahi_is_valid_domain_name(sc->domain_name))
return AVAHI_ERR_INVALID_DOMAIN_NAME;
return AVAHI_OK;
if (avahi_key_is_pattern(r->key))
return avahi_server_set_errno(s, AVAHI_ERR_IS_PATTERN);
- if (!avahi_record_valid(r))
+ if (!avahi_record_is_valid(r))
return avahi_server_set_errno(s, AVAHI_ERR_INVALID_RECORD);
if (check_record_conflict(s, interface, protocol, r, flags) < 0)
name = name ? (n = avahi_normalize_name(name)) : s->host_name_fqdn;
- if (!avahi_valid_domain_name(name)) {
+ if (!avahi_is_valid_domain_name(name)) {
avahi_server_set_errno(s, AVAHI_ERR_INVALID_HOST_NAME);
goto fail;
}
g_assert(type);
g_assert(name);
- if (!avahi_valid_service_name(name))
+ if (!avahi_is_valid_service_name(name))
return avahi_server_set_errno(s, AVAHI_ERR_INVALID_SERVICE_NAME);
- if (!avahi_valid_service_type(type))
+ if (!avahi_is_valid_service_type(type))
return avahi_server_set_errno(s, AVAHI_ERR_INVALID_SERVICE_TYPE);
- if (domain && !avahi_valid_domain_name(domain))
+ if (domain && !avahi_is_valid_domain_name(domain))
return avahi_server_set_errno(s, AVAHI_ERR_INVALID_DOMAIN_NAME);
- if (host && !avahi_valid_domain_name(host))
+ if (host && !avahi_is_valid_domain_name(host))
return avahi_server_set_errno(s, AVAHI_ERR_INVALID_HOST_NAME);
if (port == 0)
g_assert(type == AVAHI_DNS_SERVER_UPDATE || type == AVAHI_DNS_SERVER_RESOLVE);
g_assert(address->family == AVAHI_PROTO_INET || address->family == AVAHI_PROTO_INET6);
- if (domain && !avahi_valid_domain_name(domain))
+ if (domain && !avahi_is_valid_domain_name(domain))
return avahi_server_set_errno(s, AVAHI_ERR_INVALID_DOMAIN_NAME);
if (port == 0)
g_assert(name);
g_assert(type == AVAHI_DNS_SERVER_UPDATE || type == AVAHI_DNS_SERVER_RESOLVE);
- if (domain && !avahi_valid_domain_name(domain))
+ if (domain && !avahi_is_valid_domain_name(domain))
return avahi_server_set_errno(s, AVAHI_ERR_INVALID_DOMAIN_NAME);
if (port == 0)
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
+#include <ctype.h>
#include <glib.h>
return r;
}
+
+
+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;
+}
+
char *avahi_format_mac_address(const uint8_t* mac, size_t size);
+/** Change every character in the string to upper case (ASCII), return a pointer to the string */
+char *avahi_strup(char *s);
+
+/** Change every character in the string to lower case (ASCII), return a pointer to the string */
+char *avahi_strdown(char *s);
+
AVAHI_C_DECL_END
#endif