1#ifndef foodomainhfoo
2#define foodomainhfoo
3
4/***
5  This file is part of avahi.
6
7  avahi is free software; you can redistribute it and/or modify it
8  under the terms of the GNU Lesser General Public License as
9  published by the Free Software Foundation; either version 2.1 of the
10  License, or (at your option) any later version.
11
12  avahi is distributed in the hope that it will be useful, but WITHOUT
13  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14  or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
15  Public License for more details.
16
17  You should have received a copy of the GNU Lesser General Public
18  License along with avahi; if not, write to the Free Software
19  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20  USA.
21***/
22
23/** \file domain.h Domain name handling functions */
24
25#include <inttypes.h>
26#include <sys/types.h>
27
28#include <avahi-common/cdecl.h>
29
30AVAHI_C_DECL_BEGIN
31
32/** The maximum length of a a fully escaped domain name C string. This
33 * is calculated like this: RFC1034 mandates maximum length of FQDNs
34 * is 255. The maximum label length is 63. To minimize the number of
35 * (non-escaped) dots, we comprise our maximum-length domain name of
36 * four labels � 63 characters plus three inner dots. Escaping the
37 * four labels quadruples their length at maximum. An escaped domain
38 * name has the therefore the maximum length of 63*4*4+3=1011. A
39 * trailing NUL and perhaps two unnecessary dots leading and trailing
40 * the string brings us to 1014. */
41#define AVAHI_DOMAIN_NAME_MAX 1014
42
43/** Maximum size of an unescaped label */
44#define AVAHI_LABEL_MAX 64
45
46/** @{ \name Normalization */
47
48/** Normalize a domain name into canonical form. This drops trailing
49 * dots and removes useless backslash escapes. */
50char *avahi_normalize_name(const char *s, char *ret_s, size_t size);
51
52/** Normalize a domain name into canonical form. This drops trailing
53 * dots and removes useless backslash escapes. avahi_free() the
54 * result! */
55char *avahi_normalize_name_strdup(const char *s);
56
57/** @} */
58
59/** @{ \name Comparison */
60
61/** Return 1 when the specified domain names are equal, 0 otherwise */
62int avahi_domain_equal(const char *a, const char *b);
63
64/** Return some kind of hash value for the domain, useful for using domains as hash table keys. */
65unsigned avahi_domain_hash(const char *name);
66
67/** @} */
68
69/** @{ \name Escaping */
70
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*/
73char *avahi_unescape_label(const char **name, char *dest, size_t size);
74
75/** Escape the domain name in *src and write it to *ret_name */
76char *avahi_escape_label(const char* src, size_t src_length, char **ret_name, size_t *ret_size);
77
78/** @} */
79
80/** @{ \name Validity Checks */
81
82/** Return 1 when the specified string contains a valid generic DNS-SD
83 * service type (i.e. a series of words starting with "_"), 0
84 * otherwise */
85int avahi_is_valid_service_type_generic(const char *t);
86
87/** Return 1 when the specified string contains a valid strict DNS-SD
88 * service type (i.e. consisting of only two words, the latter being
89 * either _udp or _tcp), 0 otherwise */
90int avahi_is_valid_service_type_strict(const char *t);
91
92/** Return 1 when the specified string contains a valid DNS-SD service
93 * subtype, 0 otherwise */
94int avahi_is_valid_service_subtype(const char *t);
95
96/** Return 1 when the specified string contains a valid domain name, 0 otherwise */
97int avahi_is_valid_domain_name(const char *t);
98
99/** Return 1 when the specified string contains a valid DNS-SD service name, 0 otherwise */
100int avahi_is_valid_service_name(const char *t);
101
102/** Return 1 when the specified string contains a valid non-FQDN host name (i.e. without dots), 0 otherwise */
103int avahi_is_valid_host_name(const char *t);
104
105/** 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 */
106int avahi_is_valid_fqdn(const char *t);
107
108/** @} */
109
110/** @{ \name DNS-SD service name handling */
111
112/** Construct a valid complete DNS-SD service name from a name, a type and a domain */
113int avahi_service_name_join(char *p, size_t size, const char *name, const char *type, const char *domain);
114
115/** Split a full service name into name, type and domain */
116int 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);
117
118/** @} */
119
120/** @{ \name DNS-SD Subtype handling */
121
122/** Return a pointer to the type section of a subtype i.e. _foo._sub._bar._tcp => _bar._tcp */
123const char *avahi_get_type_from_subtype(const char *t);
124
125/** @} */
126
127AVAHI_C_DECL_END
128
129#endif
130