Initial irssiproxy SSL support

Patch by "Christian Sachs" from FS#645, rebased to current head.

http://bugs.irssi.org/index.php?do=details&task_id=645
This commit is contained in:
dequis 2015-06-27 11:33:55 -03:00
commit 3c351ba018
5 changed files with 167 additions and 10 deletions

View file

@ -29,6 +29,42 @@
#include "irc-channels.h"
#include "irc-nicklist.h"
#include "modes.h"
#include "line-split.h"
void proxy_send(CLIENT_REC *client, char *d, int l)
{
#ifdef HAVE_OPENSSL
if(client->listen->use_ssl) {
SSL_write(client->ssl, d, l);
} else
#endif
net_sendbuffer_send(client->handle, d, l);
}
int proxy_readline(CLIENT_REC *client, char **str)
{
#ifdef HAVE_OPENSSL
if(client->listen->use_ssl) {
char tmpbuf[2048];
int recvlen = 0;
recvlen = SSL_read(client->ssl, tmpbuf, sizeof(tmpbuf));
if(recvlen > 0) {
return line_split(tmpbuf, recvlen, str, &client->handle->readbuffer);
} else {
int err;
err = SSL_get_error(client->ssl, recvlen);
/* READ/WRITE are not really errors, they just indicate that atm
OpenSSL is waiting for more data */
if(err == SSL_ERROR_WANT_READ || err == SSL_ERROR_WANT_WRITE) {
return line_split(tmpbuf, 0, str, &client->handle->readbuffer);
}
return recvlen; /* if any other error occurs, this will quit the connection */
}
} else
#endif
return net_sendbuffer_receive_line(client->handle, str, 1);
}
void proxy_outdata(CLIENT_REC *client, const char *data, ...)
{
@ -41,7 +77,7 @@ void proxy_outdata(CLIENT_REC *client, const char *data, ...)
va_start(args, data);
str = g_strdup_vprintf(data, args);
net_sendbuffer_send(client->handle, str, strlen(str));
proxy_send(client, str, strlen(str));
g_free(str);
va_end(args);
@ -65,7 +101,7 @@ void proxy_outdata_all(IRC_SERVER_REC *server, const char *data, ...)
CLIENT_REC *rec = tmp->data;
if (rec->connected && rec->server == server)
net_sendbuffer_send(rec->handle, str, len);
proxy_send(rec, str, len);
}
g_free(str);