1/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2/*
3 * Copyright (C) 2000-2003, Ximian, Inc.
4 */
5
6#ifndef __SOUP_SOCKET_H__
7#define __SOUP_SOCKET_H__ 1
8
9#include <libsoup/soup-types.h>
10
11G_BEGIN_DECLS
12
13#define SOUP_TYPE_SOCKET (soup_socket_get_type ())
14#define SOUP_SOCKET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SOUP_TYPE_SOCKET, SoupSocket))
15#define SOUP_SOCKET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SOUP_TYPE_SOCKET, SoupSocketClass))
16#define SOUP_IS_SOCKET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SOUP_TYPE_SOCKET))
17#define SOUP_IS_SOCKET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), SOUP_TYPE_SOCKET))
18#define SOUP_SOCKET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SOUP_TYPE_SOCKET, SoupSocketClass))
19
20struct _SoupSocket {
21 GObject parent;
22
23};
24
25typedef struct {
26 GObjectClass parent_class;
27
28 /* signals */
29 void (*readable) (SoupSocket *sock);
30 void (*writable) (SoupSocket *sock);
31 void (*disconnected) (SoupSocket *sock);
32
33 void (*new_connection) (SoupSocket *listener, SoupSocket *new_sock);
34
35 /* Padding for future expansion */
36 void (*_libsoup_reserved1) (void);
37 void (*_libsoup_reserved2) (void);
38 void (*_libsoup_reserved3) (void);
39 void (*_libsoup_reserved4) (void);
40} SoupSocketClass;
41
42#define SOUP_SOCKET_LOCAL_ADDRESS "local-address"
43#define SOUP_SOCKET_REMOTE_ADDRESS "remote-address"
44#define SOUP_SOCKET_FLAG_NONBLOCKING "non-blocking"
45#define SOUP_SOCKET_IS_SERVER "is-server"
46#define SOUP_SOCKET_SSL_CREDENTIALS "ssl-creds"
47#define SOUP_SOCKET_SSL_STRICT "ssl-strict"
48#define SOUP_SOCKET_SSL_FALLBACK "ssl-fallback"
49#define SOUP_SOCKET_TRUSTED_CERTIFICATE "trusted-certificate"
50#define SOUP_SOCKET_ASYNC_CONTEXT "async-context"
51#define SOUP_SOCKET_USE_THREAD_CONTEXT "use-thread-context"
52#define SOUP_SOCKET_TIMEOUT "timeout"
53#define SOUP_SOCKET_TLS_CERTIFICATE "tls-certificate"
54#define SOUP_SOCKET_TLS_ERRORS "tls-errors"
55
56typedef void (*SoupSocketCallback) (SoupSocket *sock,
57 guint status,
58 gpointer user_data);
59
60SOUP_AVAILABLE_IN_2_4
61GType soup_socket_get_type (void);
62
63SOUP_AVAILABLE_IN_2_4
64SoupSocket *soup_socket_new (const char *optname1,
65 ...) G_GNUC_NULL_TERMINATED;
66
67SOUP_AVAILABLE_IN_2_4
68void soup_socket_connect_async (SoupSocket *sock,
69 GCancellable *cancellable,
70 SoupSocketCallback callback,
71 gpointer user_data);
72SOUP_AVAILABLE_IN_2_4
73guint soup_socket_connect_sync (SoupSocket *sock,
74 GCancellable *cancellable);
75SOUP_AVAILABLE_IN_2_4
76int soup_socket_get_fd (SoupSocket *sock);
77
78SOUP_AVAILABLE_IN_2_4
79gboolean soup_socket_listen (SoupSocket *sock);
80
81SOUP_AVAILABLE_IN_2_4
82gboolean soup_socket_start_ssl (SoupSocket *sock,
83 GCancellable *cancellable);
84SOUP_AVAILABLE_IN_2_4
85gboolean soup_socket_start_proxy_ssl (SoupSocket *sock,
86 const char *ssl_host,
87 GCancellable *cancellable);
88SOUP_AVAILABLE_IN_2_4
89gboolean soup_socket_is_ssl (SoupSocket *sock);
90
91SOUP_AVAILABLE_IN_2_4
92void soup_socket_disconnect (SoupSocket *sock);
93SOUP_AVAILABLE_IN_2_4
94gboolean soup_socket_is_connected (SoupSocket *sock);
95
96SOUP_AVAILABLE_IN_2_4
97SoupAddress *soup_socket_get_local_address (SoupSocket *sock);
98SOUP_AVAILABLE_IN_2_4
99SoupAddress *soup_socket_get_remote_address (SoupSocket *sock);
100
101typedef enum {
102 SOUP_SOCKET_OK,
103 SOUP_SOCKET_WOULD_BLOCK,
104 SOUP_SOCKET_EOF,
105 SOUP_SOCKET_ERROR
106} SoupSocketIOStatus;
107
108SOUP_AVAILABLE_IN_2_4
109SoupSocketIOStatus soup_socket_read (SoupSocket *sock,
110 gpointer buffer,
111 gsize len,
112 gsize *nread,
113 GCancellable *cancellable,
114 GError **error);
115SOUP_AVAILABLE_IN_2_4
116SoupSocketIOStatus soup_socket_read_until (SoupSocket *sock,
117 gpointer buffer,
118 gsize len,
119 gconstpointer boundary,
120 gsize boundary_len,
121 gsize *nread,
122 gboolean *got_boundary,
123 GCancellable *cancellable,
124 GError **error);
125
126SOUP_AVAILABLE_IN_2_4
127SoupSocketIOStatus soup_socket_write (SoupSocket *sock,
128 gconstpointer buffer,
129 gsize len,
130 gsize *nwrote,
131 GCancellable *cancellable,
132 GError **error);
133
134G_END_DECLS
135
136#endif /* __SOUP_SOCKET_H__ */
137