Add initial TLS (SSL) support to gio
[platform/upstream/glib.git] / gio / gtlsconnection.h
1 /* GIO - GLib Input, Output and Streaming Library
2  *
3  * Copyright (C) 2010 Red Hat, Inc.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General
16  * Public License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20
21 #if !defined (__GIO_GIO_H_INSIDE__) && !defined (GIO_COMPILATION)
22 #error "Only <gio/gio.h> can be included directly."
23 #endif
24
25 #ifndef __G_TLS_CONNECTION_H__
26 #define __G_TLS_CONNECTION_H__
27
28 #include <gio/giostream.h>
29
30 G_BEGIN_DECLS
31
32 #define G_TYPE_TLS_CONNECTION            (g_tls_connection_get_type ())
33 #define G_TLS_CONNECTION(inst)           (G_TYPE_CHECK_INSTANCE_CAST ((inst), G_TYPE_TLS_CONNECTION, GTlsConnection))
34 #define G_TLS_CONNECTION_CLASS(class)    (G_TYPE_CHECK_CLASS_CAST ((class), G_TYPE_TLS_CONNECTION, GTlsConnectionClass))
35 #define G_IS_TLS_CONNECTION(inst)        (G_TYPE_CHECK_INSTANCE_TYPE ((inst), G_TYPE_TLS_CONNECTION))
36 #define G_IS_TLS_CONNECTION_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE ((class), G_TYPE_TLS_CONNECTION))
37 #define G_TLS_CONNECTION_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), G_TYPE_TLS_CONNECTION, GTlsConnectionClass))
38
39 /**
40  * GTlsConnection:
41  *
42  * TLS connection. This is an abstract type that will be subclassed by
43  * a TLS-library-specific subtype.
44  *
45  * Since: 2.28
46  */
47 typedef struct _GTlsConnectionClass   GTlsConnectionClass;
48 typedef struct _GTlsConnectionPrivate GTlsConnectionPrivate;
49
50 struct _GTlsConnection {
51   GIOStream parent_instance;
52
53   GTlsConnectionPrivate *priv;
54 };
55
56 struct _GTlsConnectionClass
57 {
58   GIOStreamClass parent_class;
59
60   /* signals */
61   GTlsCertificate * ( *need_certificate)   (GTlsConnection       *connection);
62
63   gboolean          ( *accept_certificate) (GTlsConnection       *connection,
64                                             GTlsCertificate      *peer_cert,
65                                             GTlsCertificateFlags  errors);
66
67   /* methods */
68   gboolean ( *handshake )        (GTlsConnection       *conn,
69                                   GCancellable         *cancellable,
70                                   GError              **error);
71
72   void     ( *handshake_async )  (GTlsConnection       *conn,
73                                   int                   io_priority,
74                                   GCancellable         *cancellable,
75                                   GAsyncReadyCallback   callback,
76                                   gpointer              user_data);
77   gboolean ( *handshake_finish ) (GTlsConnection       *conn,
78                                   GAsyncResult         *result,
79                                   GError              **error);
80
81   /*< private >*/
82   /* Padding for future expansion */
83   gpointer padding[8];
84 };
85
86 GType                g_tls_connection_get_type                 (void) G_GNUC_CONST;
87
88 void                 g_tls_connection_set_certificate          (GTlsConnection       *conn,
89                                                                 GTlsCertificate      *certificate);
90 GTlsCertificate     *g_tls_connection_get_certificate          (GTlsConnection       *conn);
91
92 GTlsCertificate     *g_tls_connection_get_peer_certificate     (GTlsConnection       *conn);
93
94 void                 g_tls_connection_set_require_close_notify (GTlsConnection       *conn,
95                                                                 gboolean              require_close_notify);
96 gboolean             g_tls_connection_get_require_close_notify (GTlsConnection       *conn);
97
98 void                 g_tls_connection_set_rehandshake_mode     (GTlsConnection       *conn,
99                                                                 GTlsRehandshakeMode   mode);
100 GTlsRehandshakeMode  g_tls_connection_get_rehandshake_mode     (GTlsConnection       *conn);
101
102 gboolean             g_tls_connection_handshake                (GTlsConnection       *conn,
103                                                                 GCancellable         *cancellable,
104                                                                 GError              **error);
105
106 void                 g_tls_connection_handshake_async          (GTlsConnection       *conn,
107                                                                 int                   io_priority,
108                                                                 GCancellable         *cancellable,
109                                                                 GAsyncReadyCallback   callback,
110                                                                 gpointer              user_data);
111 gboolean             g_tls_connection_handshake_finish         (GTlsConnection       *conn,
112                                                                 GAsyncResult         *result,
113                                                                 GError              **error);
114
115 /**
116  * G_TLS_ERROR:
117  *
118  * Error domain for TLS. Errors in this domain will be from the
119  * #GTlsError enumeration. See #GError for more information on error
120  * domains.
121  */
122 #define G_TLS_ERROR (g_tls_error_quark ())
123 GQuark g_tls_error_quark (void);
124
125
126 /*< protected >*/
127 GTlsCertificate     *g_tls_connection_emit_need_certificate    (GTlsConnection       *conn);
128 gboolean             g_tls_connection_emit_accept_certificate  (GTlsConnection       *conn,
129                                                                 GTlsCertificate      *peer_cert,
130                                                                 GTlsCertificateFlags  errors);
131
132 void                 g_tls_connection_set_peer_certificate     (GTlsConnection       *conn,
133                                                                 GTlsCertificate      *certificate);
134
135 G_END_DECLS
136
137 #endif /* __G_TLS_CONNECTION_H__ */