glib-2.0: add unichar.to_string method
[vala-lang.git] / vapi / avahi-gobject.vapi
blob9703e5030eef11b02f9466d799ed50f45cd2f8ee
1 /* avahi.vala
2  *
3  * Copyright (C) 2009  Sebastian Noack
4  *
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.
9  *
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.
14  *
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
18  *
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.
22  *
23  * Author:
24  *  Sebastian Noack <sebastian.noack@gmail.com>
25  */
27 [CCode(cprefix="Ga", lower_case_cprefix="ga_")]
28 namespace Avahi {
29         /* Error handling */
31         [CCode(cheader_filename="avahi-gobject/ga-error.h", cprefix="AVAHI_ERR_")]
32         public errordomain Error {
33                 FAILURE,
34                 BAD_STATE,
35                 INVALID_HOST_NAME,
36                 INVALID_DOMAIN_NAME,
37                 NO_NETWORK,
38                 INVALID_TTL,
39                 IS_PATTERN,
40                 COLLISION,
41                 INVALID_RECORD,
43                 INVALID_SERVICE_NAME,
44                 INVALID_SERVICE_TYPE,
45                 INVALID_PORT,
46                 INVALID_KEY,
47                 INVALID_ADDRESS,
48                 TIMEOUT,
49                 TOO_MANY_CLIENTS,
50                 TOO_MANY_OBJECTS,
51                 TOO_MANY_ENTRIES,
52                 OS,
54                 ACCESS_DENIED,
55                 INVALID_OPERATION,
56                 DBUS_ERROR,
57                 DISCONNECTED,
58                 NO_MEMORY,
59                 INVALID_OBJECT,
60                 NO_DAEMON,
61                 INVALID_INTERFACE,
62                 INVALID_PROTOCOL,
63                 INVALID_FLAGS,
65                 NOT_FOUND,
66                 INVALID_CONFIG,
67                 VERSION_MISMATCH,
68                 INVALID_SERVICE_SUBTYPE,
69                 INVALID_PACKET,
70                 INVALID_DNS_ERROR,
71                 DNS_FORMERR,
72                 DNS_SERVFAIL,
73                 DNS_NXDOMAIN,
74                 DNS_NOTIMP,
76                 DNS_REFUSED,
77                 DNS_YXDOMAIN,
78                 DNS_YXRRSET,
79                 DNS_NXRRSET,
80                 DNS_NOTAUTH,
81                 DNS_NOTZONE,
82                 INVALID_RDATA,
83                 INVALID_DNS_CLASS,
84                 INVALID_DNS_TYPE,
85                 NOT_SUPPORTED,
87                 NOT_PERMITTED,
88                 INVALID_ARGUMENT,
89                 IS_EMPTY,
90                 NO_CHANGE
91         }
93         [CCode(cheader_filename="avahi-gobject/ga-error.h", cname="avahi_strerror")]
94         public unowned string strerror(int errno);
97         /* Network addresses */
99         [SimpleType]
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();
113                 public int to_af();
114                 [CCode(cname="AVAHI_PROTO_VALID")]
115                 public bool is_valid();
116         }
118         [SimpleType]
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();
126         }
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);
141         }
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;
149         [Compact]
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")]
154                 public char[] text;
156                 public StringList(string? txt=null, ...);
157                 public StringList.from_array(string[] array);
159                 [ReturnsModifiedPointer()]
160                 public void add(string text);
161                 [ReturnsModifiedPointer()]
162                 [PrintfFormat]
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);
192                         return dest;
193                 }
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 {
199                         StringList dest;
201                         int errno = _parse(data, out dest);
202                         if (errno < 0) {
203                                 var err = new Error.FAILURE(strerror(errno));
204                                 err.code = errno;
205                                 throw err;
206                         }
208                         return dest;
209                 }
210         }
213         /* Domain name utility functions */
215         [CCode(cheader_filename="avahi-common/domain.h", lower_case_cprefix="avahi_")]
216         namespace Domain {
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);
236                 }
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);
245                         if (errno < 0) {
246                                 var err = new Error.FAILURE(strerror(errno));
247                                 err.code = errno;
248                                 throw err;
249                         }
251                         return (string) dest;
252                 }
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);
267                         if (errno < 0) {
268                                 var err = new Error.FAILURE(strerror(errno));
269                                 err.code = errno;
270                                 throw err;
271                         }
272                 }
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]);
284         }
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);
290         }
293         /* Lookup flags */
295         [CCode(cheader_filename="avahi-gobject/ga-enums.h", cprefix="GA_LOOKUP_RESULT_")]
296         public enum LookupResultFlags {
297                 CACHED,
298                 WIDE_AREA,
299                 MULTICAST,
300                 LOCAL,
301                 OUR_OWN,
302                 STATIC
303         }
305         [Flags]
306         [CCode(cheader_filename="avahi-gobject/ga-enums.h", cprefix="GA_LOOKUP_")]
307         public enum LookupFlags {
308                 NO_FLAGS,
309                 USE_WIDE_AREA,
310                 USE_MULTICAST,
311                 NO_TXT,
312                 NO_ADDRESS
313         }
316         /* Client */
318         [CCode(cheader_filename="avahi-gobject/ga-client.h")]
319         public enum ClientState {
320                 NOT_STARTED,
321                 S_REGISTERING,
322                 S_RUNNING,
323                 S_COLLISION,
324                 FAILURE,
325                 CONNECTING
326         }
328         [Flags]
329         [CCode(cheader_filename="avahi-gobject/ga-client.h", cprefix="GA_CLIENT_FLAG_")]
330         public enum ClientFlags {
331                 NO_FLAGS,
332                 IGNORE_USER_CONFIG,
333                 NO_FAIL
334         }
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;
342                 [NoAccessorMethod]
343                 public ClientState state { get; }
344                 [NoAccessorMethod]
345                 public ClientFlags flags { get; construct; }
347                 public signal void state_changed(ClientState state);
348         }
351         /* Record browser */
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;
360                 [NoAccessorMethod]
361                 public Protocol protocol { get; set; }
362                 [NoAccessorMethod]
363                 public Interface interface { get; set; }
364                 [NoAccessorMethod]
365                 public string name { owned get; set; }
366                 [NoAccessorMethod]
367                 public uint16 type { get; set; }
368                 [NoAccessorMethod]
369                 public uint16 class { get; set; }
370                 [NoAccessorMethod]
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);
378         }
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;
390                 [NoAccessorMethod]
391                 public Protocol protocol { get; set; }
392                 [NoAccessorMethod]
393                 public Protocol aprotocol { get; set; }
394                 [NoAccessorMethod]
395                 public Interface interface { get; set; }
396                 [NoAccessorMethod]
397                 public string type { owned get; set; }
398                 [NoAccessorMethod]
399                 public string? domain { owned get; set; }
400                 [NoAccessorMethod]
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);
408         }
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);
420                 [NoAccessorMethod]
421                 public Protocol protocol { get; set; }
422                 [NoAccessorMethod]
423                 public Protocol aprotocol { get; set; }
424                 [NoAccessorMethod]
425                 public Interface interface { get; set; }
426                 [NoAccessorMethod]
427                 public string name { owned get; set; }
428                 [NoAccessorMethod]
429                 public string type { owned get; set; }
430                 [NoAccessorMethod]
431                 public string domain { owned get; set; }
432                 [NoAccessorMethod]
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);
437         }
440         /* Entry group */
442         [Flags]
443         [CCode(cheader_filename="avahi-common/defs.h", cname="AvahiPublishFlags", cfrefix="AVAHI_PUBLISH_")]
444         public enum PublishFlags {
445                 UNIQUE,
446                 NO_PROBE,
447                 NO_ANNOUNCE,
448                 ALLOW_MULTIPLE,
449                 NO_REVERSE,
450                 NO_COOKIE,
451                 UPDATE,
452                 USE_WIDE_AREA,
453                 USE_MULTICAST
454         }
456         [CCode(cheader_filename="avahi-gobject/ga-entry-group.h")]
457         public enum EntryGroupState {
458                 UNCOMMITED,
459                 REGISTERING,
460                 ESTABLISHED,
461                 COLLISION,
462                 FAILURE
463         }
465         [Compact]
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;
471                 public string name;
472                 public string type;
473                 public string domain;
474                 public string host;
475                 public uint16 port;
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;
482         }
484         [CCode(cheader_filename="avahi-gobject/ga-entry-group.h")]
485         public class EntryGroup : GLib.Object {
486                 public EntryGroup();
488                 public void attach(Client client) throws Error;
489                 [CCode(sentinel="")]
490                 public EntryGroupService add_service_strlist(string name, string type, uint16 port, ...) throws Error;
491                 [CCode(sentinel="")]
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;
500                 [NoAccessorMethod]
501                 public EntryGroupState state { get; }
503                 public signal void state_changed(EntryGroupState state);
504         }