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_", lower_case_cprefix="avahi_proto_")]
101 public enum Protocol {
106 [CCode(cname="avahi_af_to_proto")]
107 public static Protocol from_af(int af);
109 public unowned string to_string();
112 [CCode(cname="AVAHI_PROTO_VALID")]
113 public bool is_valid();
117 [CCode(cheader_filename="avahi-common/address.h", cname="AvahiIfIndex")]
118 public struct Interface {
119 [CCode(cname="AVAHI_IF_UNSPEC")]
120 public static Interface UNSPEC;
122 [CCode(cname="AVAHI_IF_VALID")]
123 public bool is_valid();
126 [CCode(cheader_filename="avahi-common/address.h", cname="AvahiAddress", cprefix="avahi_address_")]
127 public struct Address {
128 public Protocol proto;
130 [CCode(cname="AVAHI_ADDRESS_STR_MAX")]
131 public static size_t STR_MAX;
133 [CCode(cname="avahi_address_parse", instance_pos=-1)]
134 public Address.parse(string s, Protocol proto=Protocol.UNSPEC);
136 [CCode(cname="avahi_address_snprint", instance_pos=-1)]
137 public unowned string to_string(char[] dest=new char[STR_MAX]);
138 public int cmp(Address other);
142 /* Linked list of strings used for DNS TXT record data */
144 [CCode(cheader_filename="avahi-common/defs.h", cname="AVAHI_SERVICE_COOKIE_INVALID")]
145 public const uint32 SERVICE_COOKIE_INVALID;
148 [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")]
149 public class StringList {
150 public StringList next;
151 [CCode(array_length_cname="size")]
154 public StringList(string? txt=null, ...);
155 public StringList.from_array(string[] array);
157 [ReturnsModifiedPointer()]
158 public void add(string text);
159 [ReturnsModifiedPointer()]
161 public void add_printf(string format, ...);
162 [ReturnsModifiedPointer()]
163 public void add_arbitrary(char[] text);
164 [ReturnsModifiedPointer()]
165 public void add_anonymous(size_t size);
166 [ReturnsModifiedPointer()]
167 public void add_many(...);
169 public string to_string();
170 public int equal(StringList other);
171 public StringList copy();
172 [ReturnsModifiedPointer()]
173 public void reverse();
174 public uint length();
176 public unowned StringList find(string key);
177 public bool get_pair(out string key, out char[] value);
178 [ReturnsModifiedPointer()]
179 public void add_pair(string key, string? value);
180 [ReturnsModifiedPointer()]
181 public void add_pair_arbitrary(string key, char[] value);
182 public uint32 get_service_cookie();
184 [CCode(cname="avahi_string_list_serialize")]
185 private size_t _serialize(char[] dest);
186 [CCode(cname="avahi_string_list_serialize_dup")]
187 public char[] serialize() {
188 char[] dest = new char[this.length() * 256];
189 dest.length = (int) _serialize(dest);
193 [CCode(cname="avahi_string_list_parse")]
194 private static int _parse(char[] data, out StringList dest);
195 [CCode(cname="avahi_string_list_parse_dup")]
196 public static StringList parse(char[] data) throws Error {
199 int errno = _parse(data, out dest);
201 var err = new Error.FAILURE(strerror(errno));
211 /* Domain name utility functions */
213 [CCode(cheader_filename="avahi-common/domain.h", lower_case_cprefix="avahi_")]
215 public const size_t DOMAIN_NAME_MAX;
216 public const size_t LABEL_MAX;
218 [CCode(cname="avahi_normalize_name_strdup")]
219 public string normalize_name(string s);
220 [CCode(cname="avahi_domain_equal")]
221 public bool equal(string a, string b);
222 [CCode(cname="avahi_domain_hash")]
223 public uint hash(string name);
224 public unowned string? get_type_from_subtype(string s);
225 public unowned string? unescape_label(ref unowned string name, char[] dest=new char[LABEL_MAX]);
227 [CCode(cname="avahi_escape_label")]
228 private string? _escape_label(char* src, size_t src_len, ref char* dest, ref size_t dest_len);
229 [CCode(cname="avahi_escape_label_dup")]
230 public string? escape_label(string s) {
231 size_t len = LABEL_MAX * 4;
232 char* dest = new char[len];
233 return _escape_label(s, s.size(), ref dest, ref len);
236 [CCode(cname="avahi_service_name_join")]
237 private int _service_name_join(char* dest, size_t dest_len, string name, string type, string domain);
238 [CCode(cname="avahi_service_name_join_dup")]
239 public string service_name_join(string name, string type, string domain) throws Error {
240 char* dest = new char[DOMAIN_NAME_MAX];
242 int errno = _service_name_join(dest, DOMAIN_NAME_MAX, name, type, domain);
244 var err = new Error.FAILURE(strerror(errno));
249 return (string) dest;
252 [CCode(cname="avahi_service_name_split")]
253 private int _service_name_split(string src, char* name, size_t name_len,
254 char* type, size_t type_len,
255 char* domain, size_t domain_len);
256 [CCode(cname="avahi_service_name_split_dup")]
257 public void service_name_split(string src, out string name, out string type, out string domain) throws Error {
258 name = (string) new char[LABEL_MAX];
259 type = (string) new char[DOMAIN_NAME_MAX];
260 domain = (string) new char[DOMAIN_NAME_MAX];
262 int errno = _service_name_split(src, name, LABEL_MAX,
263 type, DOMAIN_NAME_MAX,
264 domain, DOMAIN_NAME_MAX);
266 var err = new Error.FAILURE(strerror(errno));
272 public bool is_valid_service_type_generic(string s);
273 public bool is_valid_service_type_strict(string s);
274 public bool is_valid_service_subtype(string s);
275 public bool is_valid_domain_name(string s);
276 public bool is_valid_service_name(string s);
277 public bool is_valid_host_name(string s);
278 public bool is_valid_fqdn(string s);
280 [CCode(cheader_filename="avahi-common/address.h")]
281 public unowned string reverse_lookup_name(Address addr, char[] dest=new char[DOMAIN_NAME_MAX]);
284 [CCode(cheader_filename="avahi-common/alternative.h", lower_case_cprefix="avahi_alternative_")]
285 namespace Alternative {
286 public string host_name(string s);
287 public string service_name(string s);
293 [CCode(cheader_filename="avahi-gobject/ga-enums.h", cprefix="GA_LOOKUP_RESULT_")]
294 public enum LookupResultFlags {
304 [CCode(cheader_filename="avahi-gobject/ga-enums.h", cprefix="GA_LOOKUP_")]
305 public enum LookupFlags {
316 [CCode(cheader_filename="avahi-gobject/ga-client.h")]
317 public enum ClientState {
327 [CCode(cheader_filename="avahi-gobject/ga-client.h", cprefix="GA_CLIENT_FLAG_")]
328 public enum ClientFlags {
334 [CCode(cheader_filename="avahi-gobject/ga-client.h")]
335 public class Client : GLib.Object {
336 public Client(ClientFlags flags=ClientFlags.NO_FLAGS);
338 public void start() throws Error;
341 public ClientState state { get; }
343 public ClientFlags flags { get; construct; }
345 public signal void state_changed(ClientState state);
351 [CCode(cheader_filename="avahi-gobject/ga-record-browser.h")]
352 public class RecordBrowser : GLib.Object {
353 public RecordBrowser(string name, uint16 type);
354 public RecordBrowser.full(Interface interface, Protocol protocol, string name, uint16 class, uint16 type, LookupFlags flags=LookupFlags.NO_FLAGS);
356 public void attach(Client client) throws Error;
359 public Protocol protocol { get; set; }
361 public Interface interface { get; set; }
363 public string name { owned get; set; }
365 public uint16 type { get; set; }
367 public uint16 class { get; set; }
369 public LookupFlags flags { get; set; }
371 public signal void new_record(Interface interface, Protocol protocol, string name, uint16 class, uint16 type, char[] data, LookupResultFlags flags);
372 public signal void removed_record(Interface interface, Protocol protocol, string name, uint16 class, uint16 type, char[] data, LookupResultFlags flags);
373 public signal void all_for_now();
374 public signal void cache_exhausted();
375 public signal void failure(GLib.Error error);
379 /* Service browser */
381 [CCode(cheader_filename="avahi-gobject/ga-service-browser.h")]
382 public class ServiceBrowser : GLib.Object {
383 public ServiceBrowser(string type);
384 public ServiceBrowser.full(Interface interface, Protocol protocol, string type, string? domain=null, LookupFlags flags=LookupFlags.NO_FLAGS);
386 public void attach(Client client) throws Error;
389 public Protocol protocol { get; set; }
391 public Protocol aprotocol { get; set; }
393 public Interface interface { get; set; }
395 public string type { owned get; set; }
397 public string? domain { owned get; set; }
399 public LookupFlags flags { get; set; }
401 public signal void new_service(Interface interface, Protocol protocol, string name, string type, string domain, LookupResultFlags flags);
402 public signal void removed_service(Interface interface, Protocol protocol, string name, string type, string domain, LookupResultFlags flags);
403 public signal void all_for_now();
404 public signal void cache_exhausted();
405 public signal void failure(GLib.Error error);
409 /* Service resolver */
411 [CCode(cheader_filename="avahi-gobject/ga-service-resolver.h")]
412 public class ServiceResolver : GLib.Object {
413 public ServiceResolver(Interface interface, Protocol protocol, string name, string type, string domain, Protocol address_protocol, LookupFlags flags=LookupFlags.NO_FLAGS);
415 public void attach(Client client) throws Error;
416 public bool get_address(out Address address, out uint16 port);
419 public Protocol protocol { get; set; }
421 public Protocol aprotocol { get; set; }
423 public Interface interface { get; set; }
425 public string name { owned get; set; }
427 public string type { owned get; set; }
429 public string domain { owned get; set; }
431 public LookupFlags flags { get; set; }
433 public signal void found(Interface interface, Protocol protocol, string name, string type, string domain, string hostname, Address? address, uint16 port, StringList? txt, LookupResultFlags flags);
434 public signal void failure(GLib.Error error);
441 [CCode(cheader_filename="avahi-common/defs.h", cname="AvahiPublishFlags", cfrefix="AVAHI_PUBLISH_")]
442 public enum PublishFlags {
454 [CCode(cheader_filename="avahi-gobject/ga-entry-group.h")]
455 public enum EntryGroupState {
464 [CCode(cheader_filename="avahi-gobject/ga-entry-group.h", ref_function="", unref_function="")]
465 public class EntryGroupService {
466 public Interface interface;
467 public Protocol protocol;
468 public PublishFlags flags;
471 public string domain;
475 public void freeze();
476 public void set(string key, string value) throws Error;
477 public void set_arbitrary(string key, char[] value) throws Error;
478 public void remove_key(string key) throws Error;
479 public void thaw() throws Error;
482 [CCode(cheader_filename="avahi-gobject/ga-entry-group.h")]
483 public class EntryGroup : GLib.Object {
486 public void attach(Client client) throws Error;
488 public EntryGroupService add_service_strlist(string name, string type, uint16 port, ...) throws Error;
490 public EntryGroupService add_service_full_strlist(Interface interface, Protocol protocol, PublishFlags flags, string name, string type, string domain, string host, uint16 port, ...) throws Error;
491 public EntryGroupService add_service(string name, string type, ...) throws Error;
492 public EntryGroupService add_service_full(Interface interface, Protocol protocol, PublishFlags flags, string name, string type, string domain, string host, uint16 port, ...) throws Error;
493 public void add_record(PublishFlags flags, string name, uint16 type, uint32 ttl, char[] data) throws Error;
494 public void add_record_full(Interface interface, Protocol protocol, PublishFlags flags, string name, uint16 class, uint16 type, uint32 ttl, char[] data) throws Error;
495 public void commit() throws Error;
496 public void reset() throws Error;
499 public EntryGroupState state { get; }
501 public signal void state_changed(EntryGroupState state);