mirror of
https://github.com/irssi/irssi.git
synced 2026-08-18 08:02:13 +02:00
Farewell glib-1.
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@4509 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
parent
cb1287ab63
commit
afa4292466
13 changed files with 9 additions and 507 deletions
|
|
@ -94,146 +94,6 @@ static gboolean irssi_ssl_verify(SSL *ssl, SSL_CTX *ctx, X509 *cert)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
#if GLIB_MAJOR_VERSION < 2
|
||||
|
||||
static GIOError ssl_errno(gint e)
|
||||
{
|
||||
switch(e)
|
||||
{
|
||||
case EINVAL:
|
||||
return G_IO_ERROR_INVAL;
|
||||
case EINTR:
|
||||
case EAGAIN:
|
||||
return G_IO_ERROR_AGAIN;
|
||||
default:
|
||||
return G_IO_ERROR_INVAL;
|
||||
}
|
||||
/*UNREACH*/
|
||||
return G_IO_ERROR_INVAL;
|
||||
}
|
||||
|
||||
static GIOError irssi_ssl_cert_step(GIOSSLChannel *chan)
|
||||
{
|
||||
X509 *cert;
|
||||
gint err;
|
||||
switch(err = SSL_do_handshake(chan->ssl))
|
||||
{
|
||||
case 1:
|
||||
if(!(cert = SSL_get_peer_certificate(chan->ssl)))
|
||||
{
|
||||
g_warning("SSL server supplied no certificate");
|
||||
return G_IO_ERROR_INVAL;
|
||||
}
|
||||
if (chan->verify && ! irssi_ssl_verify(chan->ssl, chan->ctx, cert)) {
|
||||
X509_free(cert);
|
||||
return G_IO_ERROR_INVAL;
|
||||
}
|
||||
X509_free(cert);
|
||||
return G_IO_ERROR_NONE;
|
||||
default:
|
||||
if(SSL_get_error(chan->ssl, err) == SSL_ERROR_WANT_READ)
|
||||
return G_IO_ERROR_AGAIN;
|
||||
return ssl_errno(errno);
|
||||
}
|
||||
/*UNREACH*/
|
||||
return G_IO_ERROR_INVAL;
|
||||
}
|
||||
|
||||
static GIOError irssi_ssl_read(GIOChannel *handle, gchar *buf, guint len, guint *ret)
|
||||
{
|
||||
GIOSSLChannel *chan = (GIOSSLChannel *)handle;
|
||||
gint err;
|
||||
|
||||
if(! chan->got_cert)
|
||||
{
|
||||
gint cert_err = irssi_ssl_cert_step(chan);
|
||||
if(cert_err != G_IO_ERROR_NONE)
|
||||
return cert_err;
|
||||
}
|
||||
|
||||
err = SSL_read(chan->ssl, buf, len);
|
||||
if(err < 0)
|
||||
{
|
||||
*ret = 0;
|
||||
if(SSL_get_error(chan->ssl, err) == SSL_ERROR_WANT_READ)
|
||||
return G_IO_ERROR_AGAIN;
|
||||
return ssl_errno(errno);
|
||||
}
|
||||
else
|
||||
{
|
||||
*ret = err;
|
||||
return G_IO_ERROR_NONE;
|
||||
}
|
||||
/*UNREACH*/
|
||||
return -1;
|
||||
}
|
||||
|
||||
static GIOError irssi_ssl_write(GIOChannel *handle, gchar *buf, guint len, guint *ret)
|
||||
{
|
||||
GIOSSLChannel *chan = (GIOSSLChannel *)handle;
|
||||
gint err;
|
||||
|
||||
if(chan->got_cert)
|
||||
{
|
||||
gint cert_err = irssi_ssl_cert_step(chan);
|
||||
if(cert_err != G_IO_ERROR_NONE)
|
||||
return cert_err;
|
||||
}
|
||||
|
||||
|
||||
err = SSL_write(chan->ssl, (const char *)buf, len);
|
||||
if(err < 0)
|
||||
{
|
||||
*ret = 0;
|
||||
if(SSL_get_error(chan->ssl, err) == SSL_ERROR_WANT_READ)
|
||||
return G_IO_ERROR_AGAIN;
|
||||
return ssl_errno(errno);
|
||||
}
|
||||
else
|
||||
{
|
||||
*ret = err;
|
||||
return G_IO_ERROR_NONE;
|
||||
}
|
||||
/*UNREACH*/
|
||||
return G_IO_ERROR_INVAL;
|
||||
}
|
||||
|
||||
static GIOError irssi_ssl_seek(GIOChannel *handle, gint offset, GSeekType type)
|
||||
{
|
||||
GIOSSLChannel *chan = (GIOSSLChannel *)handle;
|
||||
GIOError e;
|
||||
e = g_io_channel_seek(chan->giochan, offset, type);
|
||||
return (e == G_IO_ERROR_NONE) ? G_IO_ERROR_NONE : G_IO_ERROR_INVAL;
|
||||
}
|
||||
|
||||
static void irssi_ssl_close(GIOChannel *handle)
|
||||
{
|
||||
GIOSSLChannel *chan = (GIOSSLChannel *)handle;
|
||||
g_io_channel_close(chan->giochan);
|
||||
}
|
||||
|
||||
static guint irssi_ssl_create_watch(GIOChannel *handle, gint priority, GIOCondition cond,
|
||||
GIOFunc func, gpointer data, GDestroyNotify notify)
|
||||
{
|
||||
GIOSSLChannel *chan = (GIOSSLChannel *)handle;
|
||||
|
||||
return chan->giochan->funcs->io_add_watch(handle, priority, cond, func, data, notify);
|
||||
}
|
||||
|
||||
/* ssl function pointers */
|
||||
static GIOFuncs irssi_ssl_channel_funcs =
|
||||
{
|
||||
irssi_ssl_read,
|
||||
irssi_ssl_write,
|
||||
irssi_ssl_seek,
|
||||
irssi_ssl_close,
|
||||
irssi_ssl_create_watch,
|
||||
irssi_ssl_free
|
||||
};
|
||||
|
||||
#else /* GLIB_MAJOR_VERSION < 2 */
|
||||
|
||||
static GIOStatus ssl_errno(gint e)
|
||||
{
|
||||
switch(e)
|
||||
|
|
@ -383,8 +243,6 @@ static GIOFuncs irssi_ssl_channel_funcs = {
|
|||
irssi_ssl_get_flags
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
static gboolean irssi_ssl_init(void)
|
||||
{
|
||||
SSL_library_init();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue