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 SOUP_SERVER_SERVER_HEADER "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 #define SOUP_SERVER_ADD_WEBSOCKET_EXTENSION "add-websocket-extension" 142 #define SOUP_SERVER_REMOVE_WEBSOCKET_EXTENSION "remove-websocket-extension" 143 144 typedef void (*SoupServerWebsocketCallback) (SoupServer *server, 145 SoupWebsocketConnection *connection, 146 const char *path, 147 SoupClientContext *client, 148 gpointer user_data); 149 SOUP_AVAILABLE_IN_2_50 150 void soup_server_add_websocket_handler (SoupServer *server, 151 const char *path, 152 const char *origin, 153 char **protocols, 154 SoupServerWebsocketCallback callback, 155 gpointer user_data, 156 GDestroyNotify destroy); 157 SOUP_AVAILABLE_IN_2_68 158 void soup_server_add_websocket_extension (SoupServer *server, 159 GType extension_type); 160 SOUP_AVAILABLE_IN_2_68 161 void soup_server_remove_websocket_extension (SoupServer *server, 162 GType extension_type); 163 164 SOUP_AVAILABLE_IN_2_4 165 void soup_server_remove_handler (SoupServer *server, 166 const char *path); 167 168 SOUP_AVAILABLE_IN_2_4 169 void soup_server_add_auth_domain (SoupServer *server, 170 SoupAuthDomain *auth_domain); 171 SOUP_AVAILABLE_IN_2_4 172 void soup_server_remove_auth_domain (SoupServer *server, 173 SoupAuthDomain *auth_domain); 174 175 /* I/O */ 176 SOUP_AVAILABLE_IN_2_4 177 void soup_server_pause_message (SoupServer *server, 178 SoupMessage *msg); 179 SOUP_AVAILABLE_IN_2_4 180 void soup_server_unpause_message (SoupServer *server, 181 SoupMessage *msg); 182 183 /* Client context */ 184 185 SOUP_AVAILABLE_IN_2_48 186 GSocket *soup_client_context_get_gsocket (SoupClientContext *client); 187 SOUP_AVAILABLE_IN_2_48 188 GSocketAddress *soup_client_context_get_local_address (SoupClientContext *client); 189 SOUP_AVAILABLE_IN_2_48 190 GSocketAddress *soup_client_context_get_remote_address (SoupClientContext *client); 191 SOUP_AVAILABLE_IN_2_4 192 const char *soup_client_context_get_host (SoupClientContext *client); 193 SOUP_AVAILABLE_IN_2_4 194 SoupAuthDomain *soup_client_context_get_auth_domain (SoupClientContext *client); 195 SOUP_AVAILABLE_IN_2_4 196 const char *soup_client_context_get_auth_user (SoupClientContext *client); 197 198 SOUP_AVAILABLE_IN_2_50 199 GIOStream *soup_client_context_steal_connection (SoupClientContext *client); 200 201 /* Legacy API */ 202 203 #define SOUP_SERVER_PORT "port" 204 #define SOUP_SERVER_INTERFACE "interface" 205 #define SOUP_SERVER_ASYNC_CONTEXT "async-context" 206 #define SOUP_SERVER_SSL_CERT_FILE "ssl-cert-file" 207 #define SOUP_SERVER_SSL_KEY_FILE "ssl-key-file" 208 209 SOUP_AVAILABLE_IN_2_4 210 SOUP_DEPRECATED_IN_2_48 211 guint soup_server_get_port (SoupServer *server); 212 213 SOUP_AVAILABLE_IN_2_4 214 SOUP_DEPRECATED_IN_2_48 215 SoupSocket *soup_server_get_listener (SoupServer *server); 216 217 SOUP_AVAILABLE_IN_2_4 218 SOUP_DEPRECATED_IN_2_48 219 GMainContext *soup_server_get_async_context (SoupServer *server); 220 221 SOUP_AVAILABLE_IN_2_4 222 SOUP_DEPRECATED_IN_2_48 223 void soup_server_run (SoupServer *server); 224 SOUP_AVAILABLE_IN_2_4 225 SOUP_DEPRECATED_IN_2_48 226 void soup_server_run_async (SoupServer *server); 227 SOUP_AVAILABLE_IN_2_4 228 SOUP_DEPRECATED_IN_2_48 229 void soup_server_quit (SoupServer *server); 230 231 SOUP_AVAILABLE_IN_2_4 232 SOUP_DEPRECATED_IN_2_48 233 SoupAddress *soup_client_context_get_address (SoupClientContext *client); 234 SOUP_AVAILABLE_IN_2_4 235 SOUP_DEPRECATED_IN_2_48 236 SoupSocket *soup_client_context_get_socket (SoupClientContext *client); 237 238 G_END_DECLS 239 240 #endif /* __SOUP_SERVER_H__ */ 241