3 * Copyright (C) 2009 Michael B. Trausch <mike@trausch.us>
4 * License: GNU LGPL v2.1 as published by the Free Software Foundation.
6 * Part of the Vala compiler system.
8 * Note that as of GLib 2.22, gnet-2.0 will be deprecated, so software using
9 * gnet-2.0 will not be forward compatible to GLib 3.0. Also, the async
10 * methods are mostly unimplemented in these bindings, and these bindings are
11 * currently untested. Please improve them.
13 * There are nearly certainly bound to be bugs in here. What I did was just
14 * read the header files for glib-2.0 and re-create as much of them as I could
15 * here. However, some things (such as when a "gchar *" in the header means
16 * a char[] over a string) may be incorrect. Someone who has used the gnet-2.0
17 * libraries and who is familiar with Vala ought to review these bindings.
19 [CCode(cprefix = "G", lower_case_cprefix = "gnet_",
20 cheader_filename = "gnet.h")]
22 public static void init();
25 [CCode(free_function = "gnet_inetaddr_delete",
26 ref_function = "gnet_inetaddr_ref",
27 unref_function = "gnet_inetaddr_unref")]
28 public class InetAddr {
29 [CCode(cname = "GNET_INETADDR_MAX_LEN")]
30 public static const uint8 MAX_BYTES;
32 [CCode(cname = "gnet_inetaddr_new_list")]
33 public static GLib.List<InetAddr> new_list(string hostname, int port);
34 [CCode(cname = "gnet_inetaddr_delete_list")]
35 public static void delete_list(GLib.List<InetAddr> list);
37 [CCode(cname = "gnet_inetaddr_is_canonical")]
38 public static bool is_canonical(string hostname);
40 [CCode(cname = "gnet_inetaddr_equal")]
41 public static bool equal(InetAddr a1, InetAddr a2);
42 [CCode(cname = "gnet_inetaddr_noport_equal")]
43 public static bool noport_equal(InetAddr a1, InetAddr a2);
45 [CCode(cname = "gnet_inetaddr_hash")]
46 public static uint hash(InetAddr a);
48 [CCode(cname = "gnet_inetaddr_get_host_name")]
49 public static string get_host_name();
50 [CCode(cname = "gnet_inetaddr_get_host_addr")]
51 public static InetAddr get_host_addr();
53 [CCode(cname = "gnet_inetaddr_autodetect_internet_interface")]
54 public static InetAddr autodetect_internet_interface();
55 [CCode(cname = "gnet_inetaddr_get_internet_interface")]
56 public static InetAddr get_internet_interface();
57 [CCode(cname = "gnet_inetaddr_get_interface_to")]
58 public static InetAddr get_interface_to(InetAddr dest);
60 [CCode(cname = "gnet_inetaddr_is_internet_domainname")]
61 public static bool is_internet_domainname(string domain);
63 [CCode(cname = "gnet_inetaddr_list_interfaces")]
64 public static GLib.List<InetAddr> list_interfaces();
66 [CCode(cname = "gnet_inetaddr_new")]
67 public InetAddr(string hostname, int port);
68 [CCode(cname = "gnet_inetaddr_new_nonblock")]
69 public InetAddr.nonblock(string hostname, int port);
70 [CCode(cname = "gnet_inetaddr_new_bytes")]
71 public InetAddr.bytes(char[] bytes);
73 [CCode(cname = "gnet_inetaddr_clone")]
74 public InetAddr clone();
76 [CCode(cname = "gnet_inetaddr_get_name")]
77 public string get_name();
78 [CCode(cname = "gnet_inetaddr_get_name_nonblock")]
79 public string get_name_nonblock();
81 [CCode(cname = "gnet_inetaddr_get_length")]
82 public int get_length();
84 [CCode(cname = "gnet_inetaddr_get_bytes")]
85 public void get_bytes(out string buffer);
86 [CCode(cname = "gnet_inetaddr_set_bytes")]
87 public void set_bytes(char[] bytes);
89 [CCode(cname = "gnet_inetaddr_get_canonical_name")]
90 public string get_canonical_name();
92 // Can these be bound as a "port" property?
93 [CCode(cname = "gnet_inetaddr_get_port")]
94 public int get_port();
95 [CCode(cname = "gnet_inetaddr_set_port")]
96 public void set_port(int port);
98 [CCode(cname = "gnet_inetaddr_is_internet")]
99 public bool is_internet();
100 [CCode(cname = "gnet_inetaddr_is_private")]
101 public bool is_private();
102 [CCode(cname = "gnet_inetaddr_is_reserved")]
103 public bool is_reserved();
104 [CCode(cname = "gnet_inetaddr_is_loopback")]
105 public bool is_loopback();
106 [CCode(cname = "gnet_inetaddr_is_multicast")]
107 public bool is_multicast();
108 [CCode(cname = "gnet_inetaddr_is_broadcast")]
109 public bool is_broadcast();
111 [CCode(cname = "gnet_inetaddr_is_ipv4")]
112 public bool is_ipv4();
113 [CCode(cname = "gnet_inetaddr_is_ipv6")]
114 public bool is_ipv6();
117 public static class IOChannel {
118 [CCode(name = "gnet_io_channel_writen")]
119 public static GLib.IOError writen(GLib.IOChannel chan, string buf,
120 size_t len, out size_t bytes_written);
122 [CCode(name = "gnet_io_channel_readn")]
123 public static GLib.IOError readn(GLib.IOChannel chan, string buf,
124 size_t len, out size_t bytes_read);
125 [CCode(name = "gnet_io_channel_readline")]
126 public static GLib.IOError readline(GLib.IOChannel chan, string buf,
127 size_t len, out size_t bytes_read);
128 [CCode(name = "gnet_io_channel_readline_strdup")]
129 public static GLib.IOError readline_strdup(GLib.IOChannel chan,
135 [CCode(free_function = "gnet_udp_socket_delete",
136 ref_function = "gnet_udp_socket_ref",
137 unref_function = "gnet_udp_socket_unref")]
138 public class UdpSocket {
139 [CCode(cname = "gnet_udp_socket_new")]
141 [CCode(cname = "gnet_udp_socket_new_with_port")]
142 public UdpSocket.with_port(int port);
143 [CCode(cname = "gnet_udp_socket_new_full")]
144 public UdpSocket.full(InetAddr iface, int port);
146 [CCode(cname = "gnet_udp_socket_get_io_channel")]
147 public GLib.IOChannel get_io_channel();
148 [CCode(cname = "gnet_udp_socket_get_local_inetaddr")]
149 public InetAddr get_local_inetaddr();
151 [CCode(cname = "gnet_udp_socket_send")]
152 public int send(string buf, int len, InetAddr dest);
153 [CCode(cname = "gnet_udp_socket_receive")]
154 public int receive(string buf, int len, InetAddr src);
155 [CCode(cname = "gnet_udp_socket_has_packet")]
156 public bool has_packet();
158 [CCode(cname = "gnet_udp_socket_get_ttl")]
159 public int get_ttl();
160 [CCode(cname = "gnet_udp_socket_set_ttl")]
161 public int set_ttl(int ttl);
173 [CCode(free_function = "gnet_tcp_socket_delete",
174 ref_function = "gnet_tcp_socket_ref",
175 unref_function = "gnet_tcp_socket_unref")]
176 public class TcpSocket {
177 [CCode(cname = "gnet_tcp_socket_connect")]
178 public static TcpSocket connect(string hostname, int port);
180 [CCode(cname = "gnet_tcp_socket_new")]
181 public TcpSocket(InetAddr addr);
182 [CCode(cname = "gnet_tcp_socket_new_direct")]
183 public TcpSocket.direct(InetAddr addr);
185 [CCode(cname = "gnet_tcp_socket_get_io_channel")]
186 public GLib.IOChannel get_io_channel();
187 [CCode(cname = "gnet_tcp_socket_get_remote_inetaddr")]
188 public InetAddr get_remote_inetaddr();
189 [CCode(cname = "gnet_tcp_socket_get_local_inetaddr")]
190 public InetAddr get_local_inetaddr();
194 [CCode(free_function = "gnet_tcp_socket_delete",
195 ref_function = "gnet_tcp_socket_ref",
196 unref_function = "gnet_tcp_socket_unref",
197 cname = "GTcpSocket*")]
198 public class TcpServerSocket {
199 [CCode(cname = "gnet_tcp_socket_server_new")]
200 public TcpServerSocket();
201 [CCode(cname = "gnet_tcp_socket_server_new_with_port")]
202 public TcpServerSocket.with_port(int port);
203 [CCode(cname = "gnet_tcp_socket_server_new_full")]
204 public TcpServerSocket.full(InetAddr iface, int port);
206 [CCode(cname = "gnet_tcp_socket_server_accept")]
207 public TcpSocket accept();
208 [CCode(cname = "gnet_tcp_socket_server_accept_nonblock")]
209 public TcpSocket accept_nonblock();
211 [CCode(cname = "gnet_tcp_socket_get_port")]
212 public int get_port();
216 [CCode(free_function = "gnet_mcast_socket_delete",
217 ref_function = "gnet_mcast_socket_ref",
218 unref_function = "gnet_mcast_socket_unref",
219 cname = "GMcastSocket*")]
220 public class MulticastSocket {
221 [CCode(cname = "gnet_mcast_socket_new")]
222 public MulticastSocket();
223 [CCode(cname = "gnet_mcast_socket_new_with_port")]
224 public MulticastSocket.with_port(int port);
225 [CCode(cname = "gnet_mcast_socket_new_full")]
226 public MulticastSocket.full(InetAddr iface, int port);
228 [CCode(cname = "gnet_mcast_socket_get_io_channel")]
229 public GLib.IOChannel get_io_channel();
230 [CCode(cname = "gnet_mcast_socket_get_local_inetaddr")]
231 public GLib.IOChannel get_local_inetaddr();
233 [CCode(cname = "gnet_mcast_socket_join_group")]
234 public int join_group(InetAddr addr);
235 [CCode(cname = "gnet_mcast_socket_leave_group")]
236 public int leave_group(InetAddr addr);
238 [CCode(cname = "gnet_mcast_socket_get_ttl")]
239 public int get_ttl();
240 [CCode(cname = "gnet_mcast_socket_set_ttl")]
241 public int set_ttl(int ttl);
243 [CCode(cname = "gnet_mcast_socket_is_loopback")]
244 public int is_loopback();
245 [CCode(cname = "gnet_mcast_socket_set_loopback")]
246 public int set_loopback(bool enable);
248 [CCode(cname = "gnet_mcast_socket_send")]
249 public int send(string buf, int len, InetAddr dst);
250 [CCode(cname = "gnet_mcast_socket_receive")]
251 public int receive(string buf, int len, InetAddr src);
252 [CCode(cname = "gnet_mcast_socket_has_packet")]
253 public bool has_packet();
255 [CCode(cname = "gnet_mcast_socket_to_udp_socket")]
256 public UdpSocket to_udp_socket();
259 #if GNET_EXPERIMENTAL
260 public static class Socks {
261 [CCode(cname = "GNET_SOCKS_PORT")]
262 public static const int SOCKS_PORT;
264 [CCode(cname = "GNET_SOCKS_VERSION")]
265 public static const int SOCKS_VERSION;
267 [CCode(cname = "gnet_socks_get_enabled")]
268 public static bool get_enabled();
269 [CCode(cname = "gnet_socks_set_enabled")]
270 public static void set_enabled();
272 [CCode(cname = "gnet_socks_get_server")]
273 public static InetAddr get_server();
274 [CCode(cname = "gnet_socks_set_server")]
275 public static void set_server(InetAddr inetaddr);
277 [CCode(cname = "gnet_socks_get_version")]
278 public static int get_version();
279 [CCode(cname = "gnet_socks_set_version")]
280 public static void set_version(int version);
284 public static class Pack {
285 [CCode(cname = "gnet_pack")]
287 public static int pack(string format, string buf, int len, ...);
288 [CCode(cname = "gnet_pack_strdup")]
290 public static int pack_strdup(string format, out string buf, ...);
292 [CCode(cname = "gnet_calcsize")]
294 public static int calcsize(string format, ...);
296 [CCode(cname = "gnet_unpack")]
297 public static int unpack(string format, string buf, int len, ...);
301 [CCode(free_function = "gnet_uri_delete",
302 ref_function = "g_object_ref",
303 unref_function = "g_object_unref")]
305 public string scheme;
306 public string userinfo;
307 public string hostname;
311 public string fragment;
313 [CCode(cname = "gnet_uri_equal")]
314 public static bool equal(URI u1, URI u2);
315 [CCode(cname = "gnet_uri_hash")]
316 public static uint hash(URI u);
318 // If I understand this right, u should be allocated, but not setup.
319 [CCode(cname = "gnet_uri_parse_inplace")]
320 public static bool parse_inplace(URI* u,
321 string uri, string hostname, int len);
323 [CCode(cname = "gnet_uri_new")]
324 public URI(string uri);
325 [CCode(cname = "gnet_uri_new_fields")]
326 public URI.fields(string scheme, string hostname, int port,
328 [CCode(cname = "gnet_uri_new_fields_all")]
329 public URI.fields_all(string scheme, string userinfo, string hostname,
330 int port, string path, string query,
333 [CCode(cname = "gnet_uri_clone")]
336 [CCode(cname = "gnet_uri_escape")]
337 public void escape();
338 [CCode(cname = "gnet_uri_unescape")]
339 public void unescape();
341 [CCode(cname = "gnet_uri_get_string")]
342 public string get_string();
343 [CCode(cname = "gnet_uri_get_string")]
344 public string to_string();
346 [CCode(cname = "gnet_uri_set_scheme")]
347 public void set_scheme(string scheme);
348 [CCode(cname = "gnet_uri_set_userinfo")]
349 public void set_userinfo(string userinfo);
350 [CCode(cname = "gnet_uri_set_hostname")]
351 public void set_hostname(string hostname);
352 [CCode(cname = "gnet_uri_set_port")]
353 public void set_port(int port);
354 [CCode(cname = "gnet_uri_set_path")]
355 public void set_path(string path);
356 [CCode(cname = "gnet_uri_set_query")]
357 public void set_query(string query);
358 [CCode(cname = "gnet_uri_set_fragment")]
359 public void set_fragment(string fragment);
362 public enum ConnHttpHeaderFlags {
363 [CCode(cname = "GNET_CONN_HTTP_FLAG_SKIP_HEADER_CHECK")]
364 SKIP_HEADER_CHECK = 1
367 public enum ConnHttpMethod {
372 [CCode(cname = "GConnHttpError",
373 cprefix = "GNET_CONN_HTTP_ERROR_")]
374 public errordomain HttpError {
376 PROTOCOL_UNSUPPORTED,
380 [CCode(cname = "GConnHttpEventType", cprefix="GNET_CONN_HTTP_")]
381 public enum HttpEventType {
392 public struct ConnHttpEvent {
393 public HttpEventType type;
396 public struct ConnHttpEventResolved {
400 public struct ConnHttpEventRedirect {
401 public uint num_redirects;
402 public uint max_redirects;
403 public string new_location;
404 public bool auto_redirect;
407 public struct ConnHttpEventResponse {
408 public uint response_code;
409 public string[] header_fields;
410 public string[] header_values;
413 public struct ConnHttpEventData {
414 public uint64 content_length;
415 public uint64 data_received;
417 public size_t buf_len;
420 public struct ConnHttpEventError {
421 public HttpError code;
422 public string message;
425 public delegate void ConnHttpFunc(ConnHttp c, ConnHttpEvent event);
428 [Ccode(free_function = "gnet_conn_http_delete",
429 ref_function = "g_object_ref",
430 unref_function = "g_object_unref")]
431 public class ConnHttp {
432 [CCode(cname = "gnet_http_get")]
433 public static bool do_get(string url, out string buf, out size_t len,
436 [CCode(cname = "gnet_conn_http_new")]
439 [CCode(cname = "gnet_conn_http_set_uri")]
440 public bool set_uri(string uri);
441 [CCode(cname = "gnet_conn_http_set_escaped_uri")]
442 public bool set_escaped_uri(string uri);
444 [CCode(cname = "gnet_conn_http_set_header")]
445 public bool set_header(string field, string value,
446 ConnHttpHeaderFlags flags);
448 [CCode(cname = "gnet_conn_http_set_max_redirects")]
449 public void set_max_redirects(uint num);
451 [CCode(cname = "gnet_conn_http_set_timeout")]
452 public void set_timeout(uint timeout);
454 [CCode(cname = "gnet_conn_http_set_user_agent")]
455 public bool set_user_agent(string agent);
457 [CCode(cname = "gnet_conn_http_set_method")]
458 public bool set_method(ConnHttpMethod method, string post_data,
459 size_t post_data_len);
461 [CCode(cname = "gnet_conn_http_set_main_context")]
462 public bool set_main_context(GLib.MainContext ctx);
464 [CCode(cname = "gnet_conn_http_run")]
465 public bool run(ConnHttpFunc f);
467 [CCode(cname = "gnet_conn_http_steal_buffer")]
468 public bool steal_buffer(out string buf, out size_t len);
470 [CCode(cname = "gnet_conn_http_cancel")]
471 public void cancel();
474 [CCode(cname = "GConnEventType", cprefix="GNET_CONN_")]
475 public enum ConnEventType {
486 public struct ConnEvent {
487 public ConnEventType type;
488 public string buffer;
492 public delegate void ConnFunc(Conn c, ConnEvent evt);
495 [CCode(free_function = "gnet_conn_delete",
496 ref_function = "gnet_conn_ref",
497 unref_function = "gnet_conn_unref")]
499 [CCode(cname = "gnet_conn_new")]
500 public Conn(string hostname, int port, ConnFunc cf);
501 [CCode(cname = "gnet_conn_new_inetaddr")]
502 public Conn.inetaddr(InetAddr inetaddr, ConnFunc cf);
503 [CCode(cname = "gnet_conn_new_socket")]
504 public Conn.socket(TcpSocket s, ConnFunc cf);
506 [CCode(cname = "gnet_conn_set_callback")]
507 public void set_callback(ConnFunc cf);
508 [CCode(cname = "gnet_conn_set_callback")]
509 public void set_delegate(ConnFunc cf);
511 [CCode(cname = "gnet_conn_set_main_context")]
512 public bool set_main_context(GLib.MainContext ctx);
514 [CCode(cname = "gnet_conn_connect")]
515 public void connect();
516 [CCode(cname = "gnet_conn_disconnect")]
517 public void disconnect();
518 [CCode(cname = "gnet_conn_is_connected")]
519 public bool is_connected();
521 [CCode(cname = "gnet_conn_read")]
523 [CCode(cname = "gnet_conn_readn")]
524 public void readn(int len);
525 [CCode(cname = "gnet_conn_readline")]
526 public void readline();
528 [CCode(cname = "gnet_conn_write")]
529 public void write(string buf, int len);
530 [CCode(cname = "gnet_conn_write_direct")]
531 public void write_direct(string buf, int len,
532 GLib.DestroyNotify buffer_destroy_cb);
534 [CCode(cname = "gnet_conn_set_watch_readable")]
535 public void set_watch_readable(bool enable);
536 [CCode(cname = "gnet_conn_set_watch_writable")]
537 public void set_watch_writable(bool enable);
538 [CCode(cname = "gnet_conn_set_watch_error")]
539 public void set_watch_error(bool enable);
541 [CCode(cname = "gnet_conn_timeout")]
542 public void timeout(uint timeout);
545 public delegate void ServerFunc(Server s, Conn c);
548 [CCode(free_function = "gnet_server_delete",
549 ref_function = "gnet_server_ref",
550 unref_function = "gnet_server_unref")]
551 public class Server {
552 public InetAddr iface;
554 public TcpSocket socket;
555 public uint ref_count;
556 public ServerFunc func;
557 public void* user_data;
559 [CCode(cname = "gnet_server_new")]
560 public Server(InetAddr iface, int port, ServerFunc f);
564 [CCode(free_function = "gnet_md5_delete",
565 ref_function = "g_object_ref",
566 unref_function = "g_object_unref")]
568 [CCode(cname = "GNET_MD5_HASH_LENGTH")]
569 public static const int HASH_LENGTH;
571 [CCode(cname = "gnet_md5_equal")]
572 public static bool equal(MD5 m1, MD5 m2);
573 [CCode(cname = "gnet_md5_hash")]
574 public static uint hash(MD5 m);
576 [CCode(cname = "gnet_md5_new_incremental")]
578 [CCode(cname = "gnet_md5_new")]
579 public MD5.buf(char[] buf);
580 [CCode(cname = "gnet_md5_new_string")]
581 public MD5.str(string buf);
583 [CCode(cname = "gnet_md5_clone")]
586 [CCode(cname = "gnet_md5_update")]
587 public void update(char[] buf);
588 [CCode(cname = "gnet_md5_final")]
591 [CCode(cname = "gnet_md5_get_digest")]
592 public string get_digest();
593 [CCode(cname = "gnet_md5_get_string")]
594 public string get_string();
596 [CCode(cname = "gnet_md5_copy_string")]
597 public void copy_string(string buf);
601 [CCode(free_function = "gnet_sha_delete",
602 ref_function = "g_object_ref",
603 unref_function = "g_object_unref")]
605 [CCode(cname = "GNET_SHA_HASH_LENGTH")]
606 public static const int HASH_LENGTH;
608 [CCode(cname = "gnet_sha_equal")]
609 public static bool equal(SHA s1, SHA s2);
610 [CCode(cname = "gnet_sha_hash")]
611 public static uint hash(SHA s);
613 [CCode(cname = "gnet_sha_new_incremental")]
615 [CCode(cname = "gnet_sha_new")]
616 public SHA.buf(char[] buf);
617 [CCode(cname = "gnet_sha_new_string")]
618 public SHA.str(string buf);
620 [CCode(cname = "gnet_sha_update")]
621 public void update(char[] buf);
622 [CCode(cname = "gnet_sha_final")]
625 [CCode(cname = "gnet_sha_clone")]
628 [CCode(cname = "gnet_sha_get_digest")]
629 public string get_digest();
630 [CCode(cname = "gnet_sha_get_string")]
631 public string get_string();
633 [CCode(cname = "gnet_sha_copy_string")]
634 public void copy_string(string buf);
637 [CCode(cname = "GIPv6Policy", cprefix = "GIPV6_POLICY_")]
638 public enum IPv6Policy {
645 public static class IPv6 {
646 [CCode(cname = "gnet_ipv6_get_policy")]
647 public static IPv6Policy get_policy();
649 [CCode(cname = "gnet_ipv6_set_policy")]
650 public static void set_policy(IPv6Policy policy);
653 public static class Base64 {
654 [CCode(cname = "gnet_base64_encode")]
655 public static string encode(char[] src, out int dstlen, bool strict);
656 [CCode(cname = "gnet_base64_decode")]
657 public static string decode(char[] src, out int dstlen);