]> git.meshlink.io Git - catta/blob - avahi-common/domain.h
1ed6fce54aee707c0d6bcd5c59a5af442c57fef7
[catta] / avahi-common / domain.h
1 #ifndef foodomainhfoo
2 #define foodomainhfoo
3
4 /* $Id$ */
5
6 /***
7   This file is part of avahi.
8
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.
13
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.
18
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
22   USA.
23 ***/
24
25 /** \file domain.h Domain name handling functions */
26
27 #include <inttypes.h>
28 #include <sys/types.h>
29
30 #include <avahi-common/cdecl.h>
31
32 AVAHI_C_DECL_BEGIN
33
34 /** The maximum length of a a fully escaped domain name C string. This
35  * is calculated like this: RFC1034 mandates maximum length of FQDNs
36  * is 255. The maximum label length is 63. To minimize the number of
37  * (non-escaped) dots, we comprise our maximum-length domain name of
38  * four labels รก 63 characters plus three inner dots. Escaping the
39  * four labels quadruples their length at maximum. An escaped domain
40  * name has the therefore the maximum length of 63*4*4+3=1011. A
41  * trailing NUL and perhaps two unnecessary dots leading and trailing
42  * the string brings us to 1014. */
43 #define AVAHI_DOMAIN_NAME_MAX 1014
44
45 /** Maximum size of an unescaped label */
46 #define AVAHI_LABEL_MAX 64
47
48 /** @{ \name Normalization */
49
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);
53
54 /** Normalize a domain name into canonical form. This drops trailing
55  * dots and removes useless backslash escapes. avahi_free() the
56  * result! */
57 char *avahi_normalize_name_strdup(const char *s);
58
59 /** @} */
60
61 /** @{ \name Comparison */
62
63 /** Return 1 when the specified domain names are equal, 0 otherwise */
64 int avahi_domain_equal(const char *a, const char *b);
65
66 /** Return some kind of hash value for the domain, useful for using domains as hash table keys. */
67 unsigned avahi_domain_hash(const char *name);
68
69 /** @} */
70
71 /** @{ \name Escaping */
72
73 /** Read the first label from the textual domain name *name, unescape
74  * it and write it to dest, *name is changed to point to the next label*/
75 char *avahi_unescape_label(const char **name, char *dest, size_t size);
76
77 /** Escape the domain name in *src and write it to *ret_name */
78 char *avahi_escape_label(const char* src, size_t src_length, char **ret_name, size_t *ret_size);
79
80 /** @} */
81
82 /** @{ \name Validity Checks */
83
84 /** Return 1 when the specified string contains a valid generic DNS-SD
85  * service type (i.e. a series of words starting with "_"), 0
86  * otherwise */
87 int avahi_is_valid_service_type_generic(const char *t);
88
89 /** Return 1 when the specified string contains a valid strict DNS-SD
90  * service type (i.e. consisting of only two words, the latter being
91  * either _udp or _tcp), 0 otherwise */
92 int avahi_is_valid_service_type_strict(const char *t);
93
94 /** Return 1 when the specified string contains a valid DNS-SD service
95  * subtype, 0 otherwise */
96 int avahi_is_valid_service_subtype(const char *t);
97
98 /** Return 1 when the specified string contains a valid domain name, 0 otherwise */
99 int avahi_is_valid_domain_name(const char *t);
100
101 /** Return 1 when the specified string contains a valid DNS-SD service name, 0 otherwise */
102 int avahi_is_valid_service_name(const char *t);
103
104 /** Return 1 when the specified string contains a valid non-FQDN host name (i.e. without dots), 0 otherwise */
105 int avahi_is_valid_host_name(const char *t);
106
107 /** Return 1 when the specified string contains a valid FQDN host name (i.e. with more than one label and non-numerical), 0 otherwise. \since 0.6.9 */
108 int avahi_is_valid_fqdn(const char *t);
109
110 /** @} */
111
112 /** @{ \name DNS-SD service name handling */
113
114 /** Construct a valid complete DNS-SD service name from a name, a type and a domain */
115 int avahi_service_name_join(char *p, size_t size, const char *name, const char *type, const char *domain);
116
117 /** Split a full service name into name, type and domain */
118 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);
119
120 /** @} */
121
122 /** @{ \name DNS-SD Subtype handling */
123
124 /** Return a pointer to the type section of a subtype i.e. _foo._sub._bar._tcp => _bar._tcp */
125 const char *avahi_get_type_from_subtype(const char *t);
126
127 /** @} */
128
129 AVAHI_C_DECL_END
130
131 #endif