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
13G_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
22typedef struct SoupClientContext SoupClientContext;
23SOUP_AVAILABLE_IN_2_4
24GType soup_client_context_get_type (void);
25#define SOUP_TYPE_CLIENT_CONTEXT (soup_client_context_get_type ())
26
27typedef 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
33struct _SoupServer {
34 GObject parent;
35
36};
37
38typedef 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
58SOUP_AVAILABLE_IN_2_4
59GType soup_server_get_type (void);
60
61#define SOUP_SERVER_TLS_CERTIFICATE "tls-certificate"
62#define SOUP_SERVER_RAW_PATHS "raw-paths"
63#define SOUP_SERVER_SERVER_HEADER "server-header"
64#define SOUP_SERVER_HTTP_ALIASES "http-aliases"
65#define SOUP_SERVER_HTTPS_ALIASES "https-aliases"
66
67SOUP_AVAILABLE_IN_2_4
68SoupServer *soup_server_new (const char *optname1,
69 ...) G_GNUC_NULL_TERMINATED;
70
71SOUP_AVAILABLE_IN_2_48
72gboolean soup_server_set_ssl_cert_file (SoupServer *server,
73 const char *ssl_cert_file,
74 const char *ssl_key_file,
75 GError **error);
76SOUP_AVAILABLE_IN_2_4
77gboolean soup_server_is_https (SoupServer *server);
78
79SOUP_AVAILABLE_IN_2_48
80gboolean soup_server_listen (SoupServer *server,
81 GSocketAddress *address,
82 SoupServerListenOptions options,
83 GError **error);
84SOUP_AVAILABLE_IN_2_48
85gboolean soup_server_listen_all (SoupServer *server,
86 guint port,
87 SoupServerListenOptions options,
88 GError **error);
89SOUP_AVAILABLE_IN_2_48
90gboolean soup_server_listen_local (SoupServer *server,
91 guint port,
92 SoupServerListenOptions options,
93 GError **error);
94SOUP_AVAILABLE_IN_2_48
95gboolean soup_server_listen_socket (SoupServer *server,
96 GSocket *socket,
97 SoupServerListenOptions options,
98 GError **error);
99SOUP_AVAILABLE_IN_2_48
100gboolean soup_server_listen_fd (SoupServer *server,
101 int fd,
102 SoupServerListenOptions options,
103 GError **error);
104SOUP_AVAILABLE_IN_2_48
105GSList *soup_server_get_uris (SoupServer *server);
106SOUP_AVAILABLE_IN_2_48
107GSList *soup_server_get_listeners (SoupServer *server);
108
109SOUP_AVAILABLE_IN_2_4
110void soup_server_disconnect (SoupServer *server);
111
112SOUP_AVAILABLE_IN_2_50
113gboolean 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
121typedef void (*SoupServerCallback) (SoupServer *server,
122 SoupMessage *msg,
123 const char *path,
124 GHashTable *query,
125 SoupClientContext *client,
126 gpointer user_data);
127
128SOUP_AVAILABLE_IN_2_4
129void soup_server_add_handler (SoupServer *server,
130 const char *path,
131 SoupServerCallback callback,
132 gpointer user_data,
133 GDestroyNotify destroy);
134SOUP_AVAILABLE_IN_2_50
135void soup_server_add_early_handler (SoupServer *server,
136 const char *path,
137 SoupServerCallback callback,
138 gpointer user_data,
139 GDestroyNotify destroy);
140
141typedef void (*SoupServerWebsocketCallback) (SoupServer *server,
142 SoupWebsocketConnection *connection,
143 const char *path,
144 SoupClientContext *client,
145 gpointer user_data);
146SOUP_AVAILABLE_IN_2_50
147void 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
155SOUP_AVAILABLE_IN_2_4
156void soup_server_remove_handler (SoupServer *server,
157 const char *path);
158
159SOUP_AVAILABLE_IN_2_4
160void soup_server_add_auth_domain (SoupServer *server,
161 SoupAuthDomain *auth_domain);
162SOUP_AVAILABLE_IN_2_4
163void soup_server_remove_auth_domain (SoupServer *server,
164 SoupAuthDomain *auth_domain);
165
166/* I/O */
167SOUP_AVAILABLE_IN_2_4
168void soup_server_pause_message (SoupServer *server,
169 SoupMessage *msg);
170SOUP_AVAILABLE_IN_2_4
171void soup_server_unpause_message (SoupServer *server,
172 SoupMessage *msg);
173
174/* Client context */
175
176SOUP_AVAILABLE_IN_2_48
177GSocket *soup_client_context_get_gsocket (SoupClientContext *client);
178SOUP_AVAILABLE_IN_2_48
179GSocketAddress *soup_client_context_get_local_address (SoupClientContext *client);
180SOUP_AVAILABLE_IN_2_48
181GSocketAddress *soup_client_context_get_remote_address (SoupClientContext *client);
182SOUP_AVAILABLE_IN_2_4
183const char *soup_client_context_get_host (SoupClientContext *client);
184SOUP_AVAILABLE_IN_2_4
185SoupAuthDomain *soup_client_context_get_auth_domain (SoupClientContext *client);
186SOUP_AVAILABLE_IN_2_4
187const char *soup_client_context_get_auth_user (SoupClientContext *client);
188
189SOUP_AVAILABLE_IN_2_50
190GIOStream *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
200SOUP_AVAILABLE_IN_2_4
201SOUP_DEPRECATED_IN_2_48
202guint soup_server_get_port (SoupServer *server);
203
204SOUP_AVAILABLE_IN_2_4
205SOUP_DEPRECATED_IN_2_48
206SoupSocket *soup_server_get_listener (SoupServer *server);
207
208SOUP_AVAILABLE_IN_2_4
209SOUP_DEPRECATED_IN_2_48
210GMainContext *soup_server_get_async_context (SoupServer *server);
211
212SOUP_AVAILABLE_IN_2_4
213SOUP_DEPRECATED_IN_2_48
214void soup_server_run (SoupServer *server);
215SOUP_AVAILABLE_IN_2_4
216SOUP_DEPRECATED_IN_2_48
217void soup_server_run_async (SoupServer *server);
218SOUP_AVAILABLE_IN_2_4
219SOUP_DEPRECATED_IN_2_48
220void soup_server_quit (SoupServer *server);
221
222SOUP_AVAILABLE_IN_2_4
223SOUP_DEPRECATED_IN_2_48
224SoupAddress *soup_client_context_get_address (SoupClientContext *client);
225SOUP_AVAILABLE_IN_2_4
226SOUP_DEPRECATED_IN_2_48
227SoupSocket *soup_client_context_get_socket (SoupClientContext *client);
228
229G_END_DECLS
230
231#endif /* __SOUP_SERVER_H__ */
232