3 * Copyright (C) 2009 Sebastian Noack
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 * As a special exception, if you use inline functions from this file, this
20 * file does not by itself cause the resulting executable to be covered by
21 * the GNU Lesser General Public License.
24 * Sebastian Noack <sebastian.noack@gmail.com>
27 [CCode(cprefix="Ga", lower_case_cprefix="ga_")]
31 [CCode(cheader_filename="avahi-gobject/ga-error.h", cprefix="AVAHI_ERR_")]
32 public errordomain Error {
68 INVALID_SERVICE_SUBTYPE,
93 [CCode(cheader_filename="avahi-gobject/ga-error.h", cname="avahi_strerror")]
94 public unowned string strerror(int errno);
97 /* Network addresses */
100 [CCode(cheader_filename="avahi-common/address.h", cname="AvahiProtocol", cprefix="avahi_proto_")]
101 public struct Protocol {
102 [CCode(cname="AVAHI_PROTO_INET")]
103 public static Protocol INET;
104 [CCode(cname="AVAHI_PROTO_INET6")]
105 public static Protocol INET6;
106 [CCode(cname="AVAHI_PROTO_UNSPEC")]
107 public static Protocol UNSPEC;
109 [CCode(cname="avahi_af_to_proto")]
110 public Protocol.from_af(int af);
112 public unowned string to_string();
114 [CCode(cname="AVAHI_PROTO_VALID")]
115 public bool is_valid();
119 [CCode(cheader_filename="avahi-common/address.h", cname="AvahiIfIndex")]
120 public struct Interface {
121 [CCode(cname="AVAHI_IF_UNSPEC")]
122 public static Interface UNSPEC;
124 [CCode(cname="AVAHI_IF_VALID")]
125 public bool is_valid();
128 [CCode(cheader_filename="avahi-common/address.h", cname="AvahiAddress", cprefix="avahi_address_")]
129 public struct Address {
130 public Protocol proto;
132 [CCode(cname="AVAHI_ADDRESS_STR_MAX")]
133 public static size_t STR_MAX;
135 [CCode(cname="avahi_address_parse", instance_pos=-1)]
136 public Address.parse(string s, Protocol proto=Protocol.UNSPEC);
138 [CCode(cname="avahi_address_snprint", instance_pos=-1)]
139 public unowned string to_string(char[] dest=new char[STR_MAX]);
140 public int cmp(Address other);
144 /* Linked list of strings used for DNS TXT record data */
146 [CCode(cheader_filename="avahi-common/defs.h", cname="AVAHI_SERVICE_COOKIE_INVALID")]
147 public const uint32 SERVICE_COOKIE_INVALID;
150 [CCode(cheader_filename="avahi-common/strlst.h", cname="AvahiStringList", cprefix="avahi_string_list_", dup_function="avahi_string_list_copy", free_function="avahi_string_list_free")]
151 public class StringList {
152 public StringList next;
153 [CCode(array_length_cname="size")]
156 public StringList(string? txt=null, ...);
157 public StringList.from_array(string[] array);
159 [ReturnsModifiedPointer()]
160 public void add(string text);
161 [ReturnsModifiedPointer()]
163 public void add_printf(string format, ...);
164 [ReturnsModifiedPointer()]
165 public void add_arbitrary(char[] text);
166 [ReturnsModifiedPointer()]
167 public void add_anonymous(size_t size);
168 [ReturnsModifiedPointer()]
169 public void add_many(...);
171 public string to_string();
172 public int equal(StringList other);
173 public StringList copy();
174 [ReturnsModifiedPointer()]
175 public void reverse();
176 public uint length();
178 public unowned StringList find(string key);
179 public bool get_pair(out string key, out char[] value);
180 [ReturnsModifiedPointer()]
181 public void add_pair(string key, string? value);
182 [ReturnsModifiedPointer()]
183 public void add_pair_arbitrary(string key, char[] value);
184 public uint32 get_service_cookie();
186 [CCode(cname="avahi_string_list_serialize")]
187 private size_t _serialize(char[] dest);
188 [CCode(cname="avahi_string_list_serialize_dup")]
189 public char[] serialize() {
190 char[] dest = new char[this.length() * 256];
191 dest.length = (int) _serialize(dest);
195 [CCode(cname="avahi_string_list_parse")]
196 private static int _parse(char[] data, out StringList dest);
197 [CCode(cname="avahi_string_list_parse_dup")]
198 public static StringList parse(char[] data) throws Error {
201 int errno = _parse(data, out dest);
203 var err = new Error.FAILURE(strerror(errno));
213 /* Domain name utility functions */
215 [CCode(cheader_filename="avahi-common/domain.h", lower_case_cprefix="avahi_")]
217 public const size_t DOMAIN_NAME_MAX;
218 public const size_t LABEL_MAX;
220 [CCode(cname="avahi_normalize_name_strdup")]
221 public string normalize_name(string s);
222 [CCode(cname="avahi_domain_equal")]
223 public bool equal(string a, string b);
224 [CCode(cname="avahi_domain_hash")]
225 public uint hash(string name);
226 public unowned string? get_type_from_subtype(string s);
227 public unowned string? unescape_label(ref unowned string name, char[] dest=new char[LABEL_MAX]);
229 [CCode(cname="avahi_escape_label")]
230 private string? _escape_label(char* src, size_t src_len, ref char* dest, ref size_t dest_len);
231 [CCode(cname="avahi_escape_label_dup")]
232 public string? escape_label(string s) {
233 size_t len = LABEL_MAX * 4;
234 char* dest = new char[len];
235 return _escape_label(s, s.size(), ref dest, ref len);
238 [CCode(cname="avahi_service_name_join")]
239 private int _service_name_join(char* dest, size_t dest_len, string name, string type, string domain);
240 [CCode(cname="avahi_service_name_join_dup")]
241 public string service_name_join(string name, string type, string domain) throws Error {
242 char* dest = new char[DOMAIN_NAME_MAX];
244 int errno = _service_name_join(dest, DOMAIN_NAME_MAX, name, type, domain);
246 var err = new Error.FAILURE(strerror(errno));
251 return (string) dest;
254 [CCode(cname="avahi_service_name_split")]
255 private int _service_name_split(string src, char* name, size_t name_len,
256 char* type, size_t type_len,
257 char* domain, size_t domain_len);
258 [CCode(cname="avahi_service_name_split_dup")]
259 public void service_name_split(string src, out string name, out string type, out string domain) throws Error {
260 name = (string) new char[LABEL_MAX];
261 type = (string) new char[DOMAIN_NAME_MAX];
262 domain = (string) new char[DOMAIN_NAME_MAX];
264 int errno = _service_name_split(src, name, LABEL_MAX,
265 type, DOMAIN_NAME_MAX,
266 domain, DOMAIN_NAME_MAX);
268 var err = new Error.FAILURE(strerror(errno));
274 public bool is_valid_service_type_generic(string s);
275 public bool is_valid_service_type_strict(string s);
276 public bool is_valid_service_subtype(string s);
277 public bool is_valid_domain_name(string s);
278 public bool is_valid_service_name(string s);
279 public bool is_valid_host_name(string s);
280 public bool is_valid_fqdn(string s);
282 [CCode(cheader_filename="avahi-common/address.h")]
283 public unowned string reverse_lookup_name(Address addr, char[] dest=new char[DOMAIN_NAME_MAX]);
286 [CCode(cheader_filename="avahi-common/alternative.h", lower_case_cprefix="avahi_alternative_")]
287 namespace Alternative {
288 public string host_name(string s);
289 public string service_name(string s);
295 [CCode(cheader_filename="avahi-gobject/ga-enums.h", cprefix="GA_LOOKUP_RESULT_")]
296 public enum LookupResultFlags {
306 [CCode(cheader_filename="avahi-gobject/ga-enums.h", cprefix="GA_LOOKUP_")]
307 public enum LookupFlags {
318 [CCode(cheader_filename="avahi-gobject/ga-client.h")]
319 public enum ClientState {
329 [CCode(cheader_filename="avahi-gobject/ga-client.h", cprefix="GA_CLIENT_FLAG_")]
330 public enum ClientFlags {
336 [CCode(cheader_filename="avahi-gobject/ga-client.h")]
337 public class Client : GLib.Object {
338 public Client(ClientFlags flags=ClientFlags.NO_FLAGS);
340 public void start() throws Error;
343 public ClientState state { get; }
345 public ClientFlags flags { get; construct; }
347 public signal void state_changed(ClientState state);
353 [CCode(cheader_filename="avahi-gobject/ga-record-browser.h")]
354 public class RecordBrowser : GLib.Object {
355 public RecordBrowser(string name, uint16 type);
356 public RecordBrowser.full(Interface interface, Protocol protocol, string name, uint16 class, uint16 type, LookupFlags flags=LookupFlags.NO_FLAGS);
358 public void attach(Client client) throws Error;
361 public Protocol protocol { get; set; }
363 public Interface interface { get; set; }
365 public string name { owned get; set; }
367 public uint16 type { get; set; }
369 public uint16 class { get; set; }
371 public LookupFlags flags { get; set; }
373 public signal void new_record(Interface interface, Protocol protocol, string name, uint16 class, uint16 type, char[] data, LookupResultFlags flags);
374 public signal void removed_record(Interface interface, Protocol protocol, string name, uint16 class, uint16 type, char[] data, LookupResultFlags flags);
375 public signal void all_for_now();
376 public signal void cache_exhausted();
377 public signal void failure(GLib.Error error);
381 /* Service browser */
383 [CCode(cheader_filename="avahi-gobject/ga-service-browser.h")]
384 public class ServiceBrowser : GLib.Object {
385 public ServiceBrowser(string type);
386 public ServiceBrowser.full(Interface interface, Protocol protocol, string type, string? domain=null, LookupFlags flags=LookupFlags.NO_FLAGS);
388 public void attach(Client client) throws Error;
391 public Protocol protocol { get; set; }
393 public Protocol aprotocol { get; set; }
395 public Interface interface { get; set; }
397 public string type { owned get; set; }
399 public string? domain { owned get; set; }
401 public LookupFlags flags { get; set; }
403 public signal void new_service(Interface interface, Protocol protocol, string name, string type, string domain, LookupResultFlags flags);
404 public signal void removed_service(Interface interface, Protocol protocol, string name, string type, string domain, LookupResultFlags flags);
405 public signal void all_for_now();
406 public signal void cache_exhausted();
407 public signal void failure(GLib.Error error);
411 /* Service resolver */
413 [CCode(cheader_filename="avahi-gobject/ga-service-resolver.h")]
414 public class ServiceResolver : GLib.Object {
415 public ServiceResolver(Interface interface, Protocol protocol, string name, string type, string domain, Protocol address_protocol, LookupFlags flags=LookupFlags.NO_FLAGS);
417 public void attach(Client client) throws Error;
418 public bool get_address(out Address address, out uint16 port);
421 public Protocol protocol { get; set; }
423 public Protocol aprotocol { get; set; }
425 public Interface interface { get; set; }
427 public string name { owned get; set; }
429 public string type { owned get; set; }
431 public string domain { owned get; set; }
433 public LookupFlags flags { get; set; }
435 public signal void found(Interface interface, Protocol protocol, string name, string type, string domain, string hostname, Address? address, uint16 port, StringList? txt, LookupResultFlags flags);
436 public signal void failure(GLib.Error error);
443 [CCode(cheader_filename="avahi-common/defs.h", cname="AvahiPublishFlags", cfrefix="AVAHI_PUBLISH_")]
444 public enum PublishFlags {
456 [CCode(cheader_filename="avahi-gobject/ga-entry-group.h")]
457 public enum EntryGroupState {
466 [CCode(cheader_filename="avahi-gobject/ga-entry-group.h", ref_function="", unref_function="")]
467 public class EntryGroupService {
468 public Interface interface;
469 public Protocol protocol;
470 public PublishFlags flags;
473 public string domain;
477 public void freeze();
478 public void set(string key, string value) throws Error;
479 public void set_arbitrary(string key, char[] value) throws Error;
480 public void remove_key(string key) throws Error;
481 public void thaw() throws Error;
484 [CCode(cheader_filename="avahi-gobject/ga-entry-group.h")]
485 public class EntryGroup : GLib.Object {
488 public void attach(Client client) throws Error;
490 public EntryGroupService add_service_strlist(string name, string type, uint16 port, ...) throws Error;
492 public EntryGroupService add_service_full_strlist(Interface interface, Protocol protocol, PublishFlags flags, string name, string type, string domain, string host, uint16 port, ...) throws Error;
493 public EntryGroupService add_service(string name, string type, ...) throws Error;
494 public EntryGroupService add_service_full(Interface interface, Protocol protocol, PublishFlags flags, string name, string type, string domain, string host, uint16 port, ...) throws Error;
495 public void add_record(PublishFlags flags, string name, uint16 type, uint32 ttl, char[] data) throws Error;
496 public void add_record_full(Interface interface, Protocol protocol, PublishFlags flags, string name, uint16 class, uint16 type, uint32 ttl, char[] data) throws Error;
497 public void commit() throws Error;
498 public void reset() throws Error;
501 public EntryGroupState state { get; }
503 public signal void state_changed(EntryGroupState state);