Default to TLS for https connections, and fall back to SSLv3 on failure
[platform/upstream/libsoup.git] / libsoup / soup-socket.h
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
11 G_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
20 struct _SoupSocket {
21         GObject parent;
22
23 };
24
25 typedef struct {
26         GObjectClass parent_class;
27
28         /* signals */
29         void (*readable)       (SoupSocket *);
30         void (*writable)       (SoupSocket *);
31         void (*disconnected)   (SoupSocket *);
32
33         void (*new_connection) (SoupSocket *, SoupSocket *);
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_TIMEOUT             "timeout"
52 #define SOUP_SOCKET_TLS_CERTIFICATE     "tls-certificate"
53 #define SOUP_SOCKET_TLS_ERRORS          "tls-errors"
54
55 typedef void (*SoupSocketCallback)            (SoupSocket         *sock,
56                                                guint               status,
57                                                gpointer            user_data);
58
59 GType soup_socket_get_type (void);
60
61 SoupSocket    *soup_socket_new                (const char         *optname1,
62                                                ...) G_GNUC_NULL_TERMINATED;
63
64 void           soup_socket_connect_async      (SoupSocket         *sock,
65                                                GCancellable       *cancellable,
66                                                SoupSocketCallback  callback,
67                                                gpointer            user_data);
68 guint          soup_socket_connect_sync       (SoupSocket         *sock,
69                                                GCancellable       *cancellable);
70 int            soup_socket_get_fd             (SoupSocket         *sock);
71
72 gboolean       soup_socket_listen             (SoupSocket         *sock);
73
74 gboolean       soup_socket_start_ssl          (SoupSocket         *sock,
75                                                GCancellable       *cancellable);
76 gboolean       soup_socket_start_proxy_ssl    (SoupSocket         *sock,
77                                                const char         *ssl_host,
78                                                GCancellable       *cancellable);
79 gboolean       soup_socket_is_ssl             (SoupSocket         *sock);
80
81 void           soup_socket_disconnect         (SoupSocket         *sock);
82 gboolean       soup_socket_is_connected       (SoupSocket         *sock);
83
84 SoupAddress   *soup_socket_get_local_address  (SoupSocket         *sock);
85 SoupAddress   *soup_socket_get_remote_address (SoupSocket         *sock);
86
87
88 typedef enum {
89         SOUP_SOCKET_OK,
90         SOUP_SOCKET_WOULD_BLOCK,
91         SOUP_SOCKET_EOF,
92         SOUP_SOCKET_ERROR
93 } SoupSocketIOStatus;
94
95 SoupSocketIOStatus  soup_socket_read       (SoupSocket         *sock,
96                                             gpointer            buffer,
97                                             gsize               len,
98                                             gsize              *nread,
99                                             GCancellable       *cancellable,
100                                             GError            **error);
101 SoupSocketIOStatus  soup_socket_read_until (SoupSocket         *sock,
102                                             gpointer            buffer,
103                                             gsize               len,
104                                             gconstpointer       boundary,
105                                             gsize               boundary_len,
106                                             gsize              *nread,
107                                             gboolean           *got_boundary,
108                                             GCancellable       *cancellable,
109                                             GError            **error);
110
111 SoupSocketIOStatus  soup_socket_write      (SoupSocket         *sock,
112                                             gconstpointer       buffer,
113                                             gsize               len,
114                                             gsize              *nwrote,
115                                             GCancellable       *cancellable,
116                                             GError            **error);
117
118 G_END_DECLS
119
120 #endif /* SOUP_SOCKET_H */