7 This file is part of avahi.
9 avahi is free software; you can redistribute it and/or modify it
10 under the terms of the GNU Lesser General Public License as
11 published by the Free Software Foundation; either version 2.1 of the
12 License, or (at your option) any later version.
14 avahi is distributed in the hope that it will be useful, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
17 Public License for more details.
19 You should have received a copy of the GNU Lesser General Public
20 License along with avahi; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
25 /** \file domain.h Domain name handling functions */
28 #include <sys/types.h>
30 #include <avahi-common/cdecl.h>
32 #ifndef DOXYGEN_SHOULD_SKIP_THIS
36 /** The maximum length of a a fully escaped domain name C string. This
37 * is calculated like this: RFC1034 mandates maximum length of FQDNs
38 * is 255. The maximum label length is 63. To minimize the number of
39 * (non-escaped) dots, we comprise our maximum-length domain name of
40 * four labels รก 63 characters plus three inner dots. Escaping the
41 * four labels quadruples their length at maximum. An escaped domain
42 * name has the therefore the maximum length of 63*4*4+3=1011. A
43 * trailing NUL and perhaps two unnecessary dots leading and trailing
44 * the string brings us to 1014. */
45 #define AVAHI_DOMAIN_NAME_MAX 1014
47 /** Maxium size of an unescaped label */
48 #define AVAHI_LABEL_MAX 64
50 /** Normalize a domain name into canonical form. This drops trailing
51 * dots and removes useless backslash escapes. */
52 char *avahi_normalize_name(const char *s, char *ret_s, size_t size);
54 /** Normalize a domain name into canonical form. This drops trailing
55 * dots and removes useless backslash escapes. avahi_free() the
57 char *avahi_normalize_name_strdup(const char *s);
59 /** Return the local host name. */
60 char *avahi_get_host_name(char *ret_s, size_t size);
62 /** Return the local host name. avahi_free() the result! */
63 char *avahi_get_host_name_strdup(void);
65 /** Return 1 when the specified domain names are equal, 0 otherwise */
66 int avahi_domain_equal(const char *a, const char *b);
68 /** Do a binary comparison of to specified domain names, return -1, 0, or 1, depending on the order. */
69 int avahi_binary_domain_cmp(const char *a, const char *b);
71 /** Read the first label from the textual domain name *name, unescape
72 * it and write it to dest, *name is changed to point to the next label*/
73 char *avahi_unescape_label(const char **name, char *dest, size_t size);
75 /** Escape the domain name in *src and write it to *ret_name */
76 char *avahi_escape_label(const char* src, size_t src_length, char **ret_name, size_t *ret_size);
78 /** Return 1 when the specified string contains a valid generic
79 * service type (i.e. a series of words starting with "_"), 0
81 int avahi_is_valid_service_type_generic(const char *t);
83 /** Return 1 when the specified string contains a valid strict service
84 * type (i.e. consisting of only two words, the latter being either
85 * _udp or _tcp), 0 otherwise */
86 int avahi_is_valid_service_type_strict(const char *t);
88 /** Return 1 when the specified string contains a valid service subtype, 0 otherwise */
89 int avahi_is_valid_service_subtype(const char *t);
91 /** Return a pointer to the type section of a subtype i.e. _foo._sub._bar._tcp => _bar._tcp */
92 const char *avahi_get_type_from_subtype(const char *t);
94 /** Return 1 when the specified string contains a valid domain name, 0 otherwise */
95 int avahi_is_valid_domain_name(const char *t);
97 /** Return 1 when the specified string contains a valid service name, 0 otherwise */
98 int avahi_is_valid_service_name(const char *t);
100 /** Return 1 when the specified string contains a valid non-FQDN host name (i.e. without dots), 0 otherwise */
101 int avahi_is_valid_host_name(const char *t);
103 /** Return some kind of hash value for the domain, useful for using domains as hash table keys. */
104 unsigned avahi_domain_hash(const char *name);
106 /** Returns 1 if the the end labels of domain are eqal to suffix */
107 int avahi_domain_ends_with(const char *domain, const char *suffix);
109 /** Construct a valid complete service name from a name, a type and a domain */
110 int avahi_service_name_join(char *p, size_t size, const char *name, const char *type, const char *domain);
112 /** Split a full service name into name, type and domain */
113 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);
115 #ifndef DOXYGEN_SHOULD_SKIP_THIS