sslconn.h

Go to the documentation of this file.
00001 
00006 /* purple
00007  *
00008  * Purple is the legal property of its developers, whose names are too numerous
00009  * to list here.  Please refer to the COPYRIGHT file distributed with this
00010  * source distribution.
00011  *
00012  * This program is free software; you can redistribute it and/or modify
00013  * it under the terms of the GNU General Public License as published by
00014  * the Free Software Foundation; either version 2 of the License, or
00015  * (at your option) any later version.
00016  *
00017  * This program is distributed in the hope that it will be useful,
00018  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00019  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020  * GNU General Public License for more details.
00021  *
00022  * You should have received a copy of the GNU General Public License
00023  * along with this program; if not, write to the Free Software
00024  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
00025  */
00026 #ifndef _PURPLE_SSLCONN_H_
00027 #define _PURPLE_SSLCONN_H_
00028 
00029 #include "certificate.h"
00030 #include "proxy.h"
00031 
00032 #define PURPLE_SSL_DEFAULT_PORT 443
00033 
00034 typedef enum
00035 {
00036     PURPLE_SSL_HANDSHAKE_FAILED = 1,
00037     PURPLE_SSL_CONNECT_FAILED = 2,
00038     PURPLE_SSL_CERTIFICATE_INVALID = 3
00039 } PurpleSslErrorType;
00040 
00041 typedef struct _PurpleSslConnection PurpleSslConnection;
00042 
00043 typedef void (*PurpleSslInputFunction)(gpointer, PurpleSslConnection *,
00044                                      PurpleInputCondition);
00045 typedef void (*PurpleSslErrorFunction)(PurpleSslConnection *, PurpleSslErrorType,
00046                                      gpointer);
00047 
00048 struct _PurpleSslConnection
00049 {
00051     char *host;
00053     int port;
00055     void *connect_cb_data;
00057     PurpleSslInputFunction connect_cb;
00059     PurpleSslErrorFunction error_cb;
00061     void *recv_cb_data;
00063     PurpleSslInputFunction recv_cb;
00064 
00066     int fd;
00069     int inpa;
00071     PurpleProxyConnectData *connect_data;
00072 
00074     void *private_data;
00075 
00077     PurpleCertificateVerifier *verifier;
00078 };
00079 
00086 typedef struct
00087 {
00091     gboolean (*init)(void);
00093     void (*uninit)(void);
00096     void (*connectfunc)(PurpleSslConnection *gsc);
00101     void (*close)(PurpleSslConnection *gsc);
00108     size_t (*read)(PurpleSslConnection *gsc, void *data, size_t len);
00115     size_t (*write)(PurpleSslConnection *gsc, const void *data, size_t len);
00125     GList * (* get_peer_certificates)(PurpleSslConnection * gsc);
00126     
00127     void (*_purple_reserved2)(void);
00128     void (*_purple_reserved3)(void);
00129     void (*_purple_reserved4)(void);
00130 } PurpleSslOps;
00131 
00132 #ifdef __cplusplus
00133 extern "C" {
00134 #endif
00135 
00136 /**************************************************************************/
00138 /**************************************************************************/
00146 gboolean purple_ssl_is_supported(void);
00147 
00154 const gchar * purple_ssl_strerror(PurpleSslErrorType error);
00155 
00173 PurpleSslConnection *purple_ssl_connect(PurpleAccount *account, const char *host,
00174                                     int port, PurpleSslInputFunction func,
00175                                     PurpleSslErrorFunction error_func,
00176                                     void *data);
00177 
00190 PurpleSslConnection *purple_ssl_connect_fd(PurpleAccount *account, int fd,
00191                                        PurpleSslInputFunction func,
00192                                        PurpleSslErrorFunction error_func,
00193                                        void *data);
00194 
00207 PurpleSslConnection *purple_ssl_connect_with_host_fd(PurpleAccount *account, int fd,
00208                                            PurpleSslInputFunction func,
00209                                            PurpleSslErrorFunction error_func,
00210                                            const char *host,
00211                                            void *data);
00212 
00221 void purple_ssl_input_add(PurpleSslConnection *gsc, PurpleSslInputFunction func,
00222                         void *data);
00223 
00229 void purple_ssl_close(PurpleSslConnection *gsc);
00230 
00240 size_t purple_ssl_read(PurpleSslConnection *gsc, void *buffer, size_t len);
00241 
00251 size_t purple_ssl_write(PurpleSslConnection *gsc, const void *buffer, size_t len);
00252 
00261 GList * purple_ssl_get_peer_certificates(PurpleSslConnection *gsc);
00262 
00265 /**************************************************************************/
00267 /**************************************************************************/
00275 void purple_ssl_set_ops(PurpleSslOps *ops);
00276 
00282 PurpleSslOps *purple_ssl_get_ops(void);
00283 
00287 void purple_ssl_init(void);
00288 
00292 void purple_ssl_uninit(void);
00293 
00296 #ifdef __cplusplus
00297 }
00298 #endif
00299 
00300 #endif /* _PURPLE_SSLCONN_H_ */