From 4586d4466ffd0b8913f04b63c5dbfd261fc88017 Mon Sep 17 00:00:00 2001 From: Federico Lucifredi Date: Sun, 20 Jan 2008 20:59:53 +0000 Subject: adding avahi_c_to_canonical_string() and avahi_count_canonical_labels() to domain-util.c. Utility functions to compose RRSIG packet. git-svn-id: file:///home/lennart/svn/public/avahi/branches/federico2@1731 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe --- avahi-core/domain-util.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ avahi-core/domain-util.h | 6 ++++++ 2 files changed, 56 insertions(+) (limited to 'avahi-core') diff --git a/avahi-core/domain-util.c b/avahi-core/domain-util.c index 777a064..0d6ba14 100644 --- a/avahi-core/domain-util.c +++ b/avahi-core/domain-util.c @@ -188,3 +188,53 @@ int avahi_domain_ends_with(const char *domain, const char *suffix) { } } +/*todo: revise location of this function in this file vs domain.c (and.h) */ +unsigned char * avahi_c_to_canonical_string(const char* input) + { + char *label = avahi_malloc(AVAHI_LABEL_MAX); + char *retval = avahi_malloc(AVAHI_DOMAIN_NAME_MAX); + char *result = retval; + + /* printf("invoked with: -%s-\n", input); */ + + for(;;) + { + avahi_unescape_label(&input, label, AVAHI_LABEL_MAX); + + if(!(*label)) + break; + + *result = (char)strlen(label); + /* printf("label length: -%d-\n", *result); */ + + result++; + + /*printf("label: -%s-\n", label); */ + + strcpy(result, label); + result += (char)strlen(label); + + /* printf("intermediate result: -%s-\n", retval); */ + } + + /* printf("result: -%s-\n", retval); + printf("result length: -%d-\n", (char)strlen(retval)); */ + + avahi_free(label); + return retval; + } + +uint8_t avahi_count_canonical_labels(const char* input){ + char *p; + uint8_t count; + + p = input; + count = 0; + + while (*p != 0){ + count++; + p += *p; + } + + return count; +} \ No newline at end of file diff --git a/avahi-core/domain-util.h b/avahi-core/domain-util.h index 01233d8..c3e3579 100644 --- a/avahi-core/domain-util.h +++ b/avahi-core/domain-util.h @@ -42,6 +42,12 @@ int avahi_binary_domain_cmp(const char *a, const char *b); /** Returns 1 if the the end labels of domain are eqal to suffix */ int avahi_domain_ends_with(const char *domain, const char *suffix); +/** returns canonical DNS representation of C string representing a domain */ +unsigned char * avahi_c_to_canonical_string(const char* input); + +/** returns the number of labels in a canonical DNS domain */ +uint8_t avahi_count_canonical_labels(const char* input); + AVAHI_C_DECL_END #endif -- cgit