/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
- * soup-socket.c: ronous Callback-based HTTP Request Queue.
- *
- * Authors:
- * David Helder (dhelder@umich.edu)
- * Alex Graveley (alex@ximian.com)
- *
- * Original code compliments of David Helder's GNET Networking Library.
- *
- * Copyright (C) 2000-2002, Ximian, Inc.
+ * Copyright (C) 2000-2003, Ximian, Inc.
*/
#ifndef SOUP_SOCKET_H
#define SOUP_SOCKET_H 1
-#include <glib.h>
-#include <libsoup/soup-address.h>
+#include <libsoup/soup-types.h>
-typedef struct _SoupSocket SoupSocket;
+G_BEGIN_DECLS
-typedef gpointer SoupSocketConnectId;
+#define SOUP_TYPE_SOCKET (soup_socket_get_type ())
+#define SOUP_SOCKET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SOUP_TYPE_SOCKET, SoupSocket))
+#define SOUP_SOCKET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SOUP_TYPE_SOCKET, SoupSocketClass))
+#define SOUP_IS_SOCKET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SOUP_TYPE_SOCKET))
+#define SOUP_IS_SOCKET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), SOUP_TYPE_SOCKET))
+#define SOUP_SOCKET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SOUP_TYPE_SOCKET, SoupSocketClass))
-typedef enum {
- SOUP_SOCKET_CONNECT_ERROR_NONE,
- SOUP_SOCKET_CONNECT_ERROR_ADDR_RESOLVE,
- SOUP_SOCKET_CONNECT_ERROR_NETWORK
-} SoupSocketConnectStatus;
-
-typedef void (*SoupSocketConnectFn) (SoupSocket *socket,
- SoupSocketConnectStatus status,
- gpointer data);
-
-SoupSocketConnectId soup_socket_connect (const gchar* hostname,
- const gint port,
- SoupSocketConnectFn func,
- gpointer data);
+struct _SoupSocket {
+ GObject parent;
-void soup_socket_connect_cancel (SoupSocketConnectId id);
+};
-SoupSocket *soup_socket_connect_sync (const gchar *hostname,
- const gint port);
+typedef struct {
+ GObjectClass parent_class;
+ /* signals */
+ void (*readable) (SoupSocket *);
+ void (*writable) (SoupSocket *);
+ void (*disconnected) (SoupSocket *);
-typedef gpointer SoupSocketNewId;
-
-typedef enum {
- SOUP_SOCKET_NEW_STATUS_OK,
- SOUP_SOCKET_NEW_STATUS_ERROR
-} SoupSocketNewStatus;
+ void (*new_connection) (SoupSocket *, SoupSocket *);
-typedef void (*SoupSocketNewFn) (SoupSocket* socket,
- SoupSocketNewStatus status,
- gpointer data);
+ /* Padding for future expansion */
+ void (*_libsoup_reserved1) (void);
+ void (*_libsoup_reserved2) (void);
+ void (*_libsoup_reserved3) (void);
+ void (*_libsoup_reserved4) (void);
+} SoupSocketClass;
-SoupSocketNewId soup_socket_new (SoupAddress *addr,
- guint port,
- SoupSocketNewFn func,
- gpointer data);
+#define SOUP_SOCKET_LOCAL_ADDRESS "local-address"
+#define SOUP_SOCKET_REMOTE_ADDRESS "remote-address"
+#define SOUP_SOCKET_FLAG_NONBLOCKING "non-blocking"
+#define SOUP_SOCKET_IS_SERVER "is-server"
+#define SOUP_SOCKET_SSL_CREDENTIALS "ssl-creds"
+#define SOUP_SOCKET_SSL_STRICT "ssl-strict"
+#define SOUP_SOCKET_SSL_FALLBACK "ssl-fallback"
+#define SOUP_SOCKET_TRUSTED_CERTIFICATE "trusted-certificate"
+#define SOUP_SOCKET_ASYNC_CONTEXT "async-context"
+#define SOUP_SOCKET_USE_THREAD_CONTEXT "use-thread-context"
+#define SOUP_SOCKET_TIMEOUT "timeout"
+#define SOUP_SOCKET_TLS_CERTIFICATE "tls-certificate"
+#define SOUP_SOCKET_TLS_ERRORS "tls-errors"
-void soup_socket_new_cancel (SoupSocketNewId id);
+typedef void (*SoupSocketCallback) (SoupSocket *sock,
+ guint status,
+ gpointer user_data);
-SoupSocket *soup_socket_new_sync (SoupAddress *addr,
- guint port);
+GType soup_socket_get_type (void);
+SoupSocket *soup_socket_new (const char *optname1,
+ ...) G_GNUC_NULL_TERMINATED;
-void soup_socket_ref (SoupSocket* s);
+void soup_socket_connect_async (SoupSocket *sock,
+ GCancellable *cancellable,
+ SoupSocketCallback callback,
+ gpointer user_data);
+guint soup_socket_connect_sync (SoupSocket *sock,
+ GCancellable *cancellable);
+int soup_socket_get_fd (SoupSocket *sock);
-void soup_socket_unref (SoupSocket* s);
+gboolean soup_socket_listen (SoupSocket *sock);
-GIOChannel *soup_socket_get_iochannel (SoupSocket* socket);
+gboolean soup_socket_start_ssl (SoupSocket *sock,
+ GCancellable *cancellable);
+gboolean soup_socket_start_proxy_ssl (SoupSocket *sock,
+ const char *ssl_host,
+ GCancellable *cancellable);
+gboolean soup_socket_is_ssl (SoupSocket *sock);
-SoupAddress *soup_socket_get_address (const SoupSocket* socket);
+void soup_socket_disconnect (SoupSocket *sock);
+gboolean soup_socket_is_connected (SoupSocket *sock);
-gint soup_socket_get_port (const SoupSocket* socket);
+SoupAddress *soup_socket_get_local_address (SoupSocket *sock);
+SoupAddress *soup_socket_get_remote_address (SoupSocket *sock);
+GInputStream *soup_socket_get_input_stream (SoupSocket *sock);
+GOutputStream *soup_socket_get_output_stream (SoupSocket *sock);
-#define SOUP_SERVER_ANY_PORT 0
-
-SoupSocket *soup_socket_server_new (SoupAddress *local_addr,
- guint local_port);
-
-SoupSocket *soup_socket_server_accept (SoupSocket *socket);
-
-SoupSocket *soup_socket_server_try_accept (SoupSocket *socket);
+typedef enum {
+ SOUP_SOCKET_OK,
+ SOUP_SOCKET_WOULD_BLOCK,
+ SOUP_SOCKET_EOF,
+ SOUP_SOCKET_ERROR
+} SoupSocketIOStatus;
+
+SoupSocketIOStatus soup_socket_read (SoupSocket *sock,
+ gpointer buffer,
+ gsize len,
+ gsize *nread,
+ GCancellable *cancellable,
+ GError **error);
+SoupSocketIOStatus soup_socket_read_until (SoupSocket *sock,
+ gpointer buffer,
+ gsize len,
+ gconstpointer boundary,
+ gsize boundary_len,
+ gsize *nread,
+ gboolean *got_boundary,
+ GCancellable *cancellable,
+ GError **error);
+
+SoupSocketIOStatus soup_socket_write (SoupSocket *sock,
+ gconstpointer buffer,
+ gsize len,
+ gsize *nwrote,
+ GCancellable *cancellable,
+ GError **error);
+
+G_END_DECLS
#endif /* SOUP_SOCKET_H */