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_SERVER_H__ |
7 | #define __SOUP_SERVER_H__ 1 |
8 | |
9 | #include <libsoup/soup-types.h> |
10 | #include <libsoup/soup-uri.h> |
11 | #include <libsoup/soup-websocket-connection.h> |
12 | |
13 | G_BEGIN_DECLS |
14 | |
15 | #define SOUP_TYPE_SERVER (soup_server_get_type ()) |
16 | #define SOUP_SERVER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SOUP_TYPE_SERVER, SoupServer)) |
17 | #define SOUP_SERVER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SOUP_TYPE_SERVER, SoupServerClass)) |
18 | #define SOUP_IS_SERVER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SOUP_TYPE_SERVER)) |
19 | #define SOUP_IS_SERVER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), SOUP_TYPE_SERVER)) |
20 | #define SOUP_SERVER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SOUP_TYPE_SERVER, SoupServerClass)) |
21 | |
22 | typedef struct SoupClientContext SoupClientContext; |
23 | SOUP_AVAILABLE_IN_2_4 |
24 | GType soup_client_context_get_type (void); |
25 | #define SOUP_TYPE_CLIENT_CONTEXT (soup_client_context_get_type ()) |
26 | |
27 | typedef enum { |
28 | SOUP_SERVER_LISTEN_HTTPS = (1 << 0), |
29 | SOUP_SERVER_LISTEN_IPV4_ONLY = (1 << 1), |
30 | SOUP_SERVER_LISTEN_IPV6_ONLY = (1 << 2) |
31 | } SoupServerListenOptions; |
32 | |
33 | struct _SoupServer { |
34 | GObject parent; |
35 | |
36 | }; |
37 | |
38 | typedef struct { |
39 | GObjectClass parent_class; |
40 | |
41 | /* signals */ |
42 | void (*request_started) (SoupServer *server, SoupMessage *msg, |
43 | SoupClientContext *client); |
44 | void (*request_read) (SoupServer *server, SoupMessage *msg, |
45 | SoupClientContext *client); |
46 | void (*request_finished) (SoupServer *server, SoupMessage *msg, |
47 | SoupClientContext *client); |
48 | void (*request_aborted) (SoupServer *server, SoupMessage *msg, |
49 | SoupClientContext *client); |
50 | |
51 | /* Padding for future expansion */ |
52 | void (*_libsoup_reserved1) (void); |
53 | void (*_libsoup_reserved2) (void); |
54 | void (*_libsoup_reserved3) (void); |
55 | void (*_libsoup_reserved4) (void); |
56 | } SoupServerClass; |
57 | |
58 | SOUP_AVAILABLE_IN_2_4 |
59 | GType soup_server_get_type (void); |
60 | |
61 | #define SOUP_SERVER_TLS_CERTIFICATE "tls-certificate" |
62 | #define SOUP_SERVER_RAW_PATHS "raw-paths" |
63 | #define "server-header" |
64 | #define SOUP_SERVER_HTTP_ALIASES "http-aliases" |
65 | #define SOUP_SERVER_HTTPS_ALIASES "https-aliases" |
66 | |
67 | SOUP_AVAILABLE_IN_2_4 |
68 | SoupServer *soup_server_new (const char *optname1, |
69 | ...) G_GNUC_NULL_TERMINATED; |
70 | |
71 | SOUP_AVAILABLE_IN_2_48 |
72 | gboolean soup_server_set_ssl_cert_file (SoupServer *server, |
73 | const char *ssl_cert_file, |
74 | const char *ssl_key_file, |
75 | GError **error); |
76 | SOUP_AVAILABLE_IN_2_4 |
77 | gboolean soup_server_is_https (SoupServer *server); |
78 | |
79 | SOUP_AVAILABLE_IN_2_48 |
80 | gboolean soup_server_listen (SoupServer *server, |
81 | GSocketAddress *address, |
82 | SoupServerListenOptions options, |
83 | GError **error); |
84 | SOUP_AVAILABLE_IN_2_48 |
85 | gboolean soup_server_listen_all (SoupServer *server, |
86 | guint port, |
87 | SoupServerListenOptions options, |
88 | GError **error); |
89 | SOUP_AVAILABLE_IN_2_48 |
90 | gboolean soup_server_listen_local (SoupServer *server, |
91 | guint port, |
92 | SoupServerListenOptions options, |
93 | GError **error); |
94 | SOUP_AVAILABLE_IN_2_48 |
95 | gboolean soup_server_listen_socket (SoupServer *server, |
96 | GSocket *socket, |
97 | SoupServerListenOptions options, |
98 | GError **error); |
99 | SOUP_AVAILABLE_IN_2_48 |
100 | gboolean soup_server_listen_fd (SoupServer *server, |
101 | int fd, |
102 | SoupServerListenOptions options, |
103 | GError **error); |
104 | SOUP_AVAILABLE_IN_2_48 |
105 | GSList *soup_server_get_uris (SoupServer *server); |
106 | SOUP_AVAILABLE_IN_2_48 |
107 | GSList *soup_server_get_listeners (SoupServer *server); |
108 | |
109 | SOUP_AVAILABLE_IN_2_4 |
110 | void soup_server_disconnect (SoupServer *server); |
111 | |
112 | SOUP_AVAILABLE_IN_2_50 |
113 | gboolean soup_server_accept_iostream (SoupServer *server, |
114 | GIOStream *stream, |
115 | GSocketAddress *local_addr, |
116 | GSocketAddress *remote_addr, |
117 | GError **error); |
118 | |
119 | /* Handlers and auth */ |
120 | |
121 | typedef void (*SoupServerCallback) (SoupServer *server, |
122 | SoupMessage *msg, |
123 | const char *path, |
124 | GHashTable *query, |
125 | SoupClientContext *client, |
126 | gpointer user_data); |
127 | |
128 | SOUP_AVAILABLE_IN_2_4 |
129 | void soup_server_add_handler (SoupServer *server, |
130 | const char *path, |
131 | SoupServerCallback callback, |
132 | gpointer user_data, |
133 | GDestroyNotify destroy); |
134 | SOUP_AVAILABLE_IN_2_50 |
135 | void soup_server_add_early_handler (SoupServer *server, |
136 | const char *path, |
137 | SoupServerCallback callback, |
138 | gpointer user_data, |
139 | GDestroyNotify destroy); |
140 | |
141 | typedef void (*SoupServerWebsocketCallback) (SoupServer *server, |
142 | SoupWebsocketConnection *connection, |
143 | const char *path, |
144 | SoupClientContext *client, |
145 | gpointer user_data); |
146 | SOUP_AVAILABLE_IN_2_50 |
147 | void soup_server_add_websocket_handler (SoupServer *server, |
148 | const char *path, |
149 | const char *origin, |
150 | char **protocols, |
151 | SoupServerWebsocketCallback callback, |
152 | gpointer user_data, |
153 | GDestroyNotify destroy); |
154 | |
155 | SOUP_AVAILABLE_IN_2_4 |
156 | void soup_server_remove_handler (SoupServer *server, |
157 | const char *path); |
158 | |
159 | SOUP_AVAILABLE_IN_2_4 |
160 | void soup_server_add_auth_domain (SoupServer *server, |
161 | SoupAuthDomain *auth_domain); |
162 | SOUP_AVAILABLE_IN_2_4 |
163 | void soup_server_remove_auth_domain (SoupServer *server, |
164 | SoupAuthDomain *auth_domain); |
165 | |
166 | /* I/O */ |
167 | SOUP_AVAILABLE_IN_2_4 |
168 | void soup_server_pause_message (SoupServer *server, |
169 | SoupMessage *msg); |
170 | SOUP_AVAILABLE_IN_2_4 |
171 | void soup_server_unpause_message (SoupServer *server, |
172 | SoupMessage *msg); |
173 | |
174 | /* Client context */ |
175 | |
176 | SOUP_AVAILABLE_IN_2_48 |
177 | GSocket *soup_client_context_get_gsocket (SoupClientContext *client); |
178 | SOUP_AVAILABLE_IN_2_48 |
179 | GSocketAddress *soup_client_context_get_local_address (SoupClientContext *client); |
180 | SOUP_AVAILABLE_IN_2_48 |
181 | GSocketAddress *soup_client_context_get_remote_address (SoupClientContext *client); |
182 | SOUP_AVAILABLE_IN_2_4 |
183 | const char *soup_client_context_get_host (SoupClientContext *client); |
184 | SOUP_AVAILABLE_IN_2_4 |
185 | SoupAuthDomain *soup_client_context_get_auth_domain (SoupClientContext *client); |
186 | SOUP_AVAILABLE_IN_2_4 |
187 | const char *soup_client_context_get_auth_user (SoupClientContext *client); |
188 | |
189 | SOUP_AVAILABLE_IN_2_50 |
190 | GIOStream *soup_client_context_steal_connection (SoupClientContext *client); |
191 | |
192 | /* Legacy API */ |
193 | |
194 | #define SOUP_SERVER_PORT "port" |
195 | #define SOUP_SERVER_INTERFACE "interface" |
196 | #define SOUP_SERVER_ASYNC_CONTEXT "async-context" |
197 | #define SOUP_SERVER_SSL_CERT_FILE "ssl-cert-file" |
198 | #define SOUP_SERVER_SSL_KEY_FILE "ssl-key-file" |
199 | |
200 | SOUP_AVAILABLE_IN_2_4 |
201 | SOUP_DEPRECATED_IN_2_48 |
202 | guint soup_server_get_port (SoupServer *server); |
203 | |
204 | SOUP_AVAILABLE_IN_2_4 |
205 | SOUP_DEPRECATED_IN_2_48 |
206 | SoupSocket *soup_server_get_listener (SoupServer *server); |
207 | |
208 | SOUP_AVAILABLE_IN_2_4 |
209 | SOUP_DEPRECATED_IN_2_48 |
210 | GMainContext *soup_server_get_async_context (SoupServer *server); |
211 | |
212 | SOUP_AVAILABLE_IN_2_4 |
213 | SOUP_DEPRECATED_IN_2_48 |
214 | void soup_server_run (SoupServer *server); |
215 | SOUP_AVAILABLE_IN_2_4 |
216 | SOUP_DEPRECATED_IN_2_48 |
217 | void soup_server_run_async (SoupServer *server); |
218 | SOUP_AVAILABLE_IN_2_4 |
219 | SOUP_DEPRECATED_IN_2_48 |
220 | void soup_server_quit (SoupServer *server); |
221 | |
222 | SOUP_AVAILABLE_IN_2_4 |
223 | SOUP_DEPRECATED_IN_2_48 |
224 | SoupAddress *soup_client_context_get_address (SoupClientContext *client); |
225 | SOUP_AVAILABLE_IN_2_4 |
226 | SOUP_DEPRECATED_IN_2_48 |
227 | SoupSocket *soup_client_context_get_socket (SoupClientContext *client); |
228 | |
229 | G_END_DECLS |
230 | |
231 | #endif /* __SOUP_SERVER_H__ */ |
232 | |