summaryrefslogtreecommitdiffstats
path: root/avahi-common
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2005-08-12 21:01:28 +0000
committerLennart Poettering <lennart@poettering.net>2005-08-12 21:01:28 +0000
commit6e35536bddb52c8e6bc201265c77a846d879b5a3 (patch)
treef00a3475d91759f1fe3d36df2757cc8f230e9234 /avahi-common
parent5d047523c87ba11aad8c384f7ffde25b4dd746ed (diff)
* implement hashmap
* de-glib-ify rr.[ch], rrlist.[ch] git-svn-id: file:///home/lennart/svn/public/avahi/trunk@306 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe
Diffstat (limited to 'avahi-common')
-rw-r--r--avahi-common/domain-test.c2
-rw-r--r--avahi-common/domain.c55
-rw-r--r--avahi-common/domain.h20
-rw-r--r--avahi-common/malloc.c12
-rw-r--r--avahi-common/malloc.h5
5 files changed, 25 insertions, 69 deletions
diff --git a/avahi-common/domain-test.c b/avahi-common/domain-test.c
index 0113a8b..fc310c7 100644
--- a/avahi-common/domain-test.c
+++ b/avahi-common/domain-test.c
@@ -45,7 +45,7 @@ int main(int argc, char *argv[]) {
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;
}
diff --git a/avahi-common/domain.c b/avahi-common/domain.c
index b1e7cfe..5a51a39 100644
--- a/avahi-common/domain.c
+++ b/avahi-common/domain.c
@@ -227,32 +227,7 @@ int avahi_binary_domain_cmp(const char *a, const char *b) {
}
}
-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);
@@ -280,7 +255,7 @@ int avahi_valid_service_type(const char *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;
@@ -319,7 +294,7 @@ int avahi_valid_domain_name(const char *t) {
return 1;
}
-int avahi_valid_service_name(const char *t) {
+int avahi_is_valid_service_name(const char *t) {
assert(t);
if (*t == 0)
@@ -331,7 +306,7 @@ int avahi_valid_service_name(const char *t) {
return 1;
}
-int avahi_valid_host_name(const char *t) {
+int avahi_is_valid_host_name(const char *t) {
assert(t);
if (*t == 0)
@@ -345,25 +320,3 @@ int avahi_valid_host_name(const char *t) {
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;
-}
-
diff --git a/avahi-common/domain.h b/avahi-common/domain.h
index fc9d7fd..83a9332 100644
--- a/avahi-common/domain.h
+++ b/avahi-common/domain.h
@@ -53,29 +53,17 @@ 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);
-/** 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
diff --git a/avahi-common/malloc.c b/avahi-common/malloc.c
index 19e1e59..1883849 100644
--- a/avahi-common/malloc.c
+++ b/avahi-common/malloc.c
@@ -161,6 +161,8 @@ char *avahi_strdup_vprintf(const char *fmt, va_list ap) {
char *avahi_strdup_printf(const char *fmt, ... ) {
char *s;
va_list ap;
+
+ assert(fmt);
va_start(ap, fmt);
s = avahi_strdup_vprintf(fmt, ap);
@@ -169,3 +171,13 @@ char *avahi_strdup_printf(const char *fmt, ... ) {
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;
+}
diff --git a/avahi-common/malloc.h b/avahi-common/malloc.h
index 2dd740e..b658357 100644
--- a/avahi-common/malloc.h
+++ b/avahi-common/malloc.h
@@ -53,7 +53,10 @@ void *avahi_realloc(void *p, size_t size);
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;