This commit is contained in:
ailin-nemui 2026-01-27 09:04:00 +01:00 committed by GitHub
commit 0937b40104
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
23 changed files with 357 additions and 337 deletions

View file

@ -19,6 +19,7 @@
*/ */
#include "module.h" #include "module.h"
#include <irssi/src/core/net-sendbuffer.h>
#include <irssi/src/core/network.h> #include <irssi/src/core/network.h>
#include <sys/select.h> #include <sys/select.h>
@ -31,7 +32,7 @@
typedef struct { typedef struct {
time_t created; time_t created;
GIOChannel *handle; GIOChannel *channel;
int tag; int tag;
} NET_DISCONNECT_REC; } NET_DISCONNECT_REC;
@ -39,12 +40,18 @@ static GSList *disconnects;
static int timeout_tag; static int timeout_tag;
void net_disconnect_any(NET_DISCONNECT_REC *rec)
{
if (rec->channel != NULL)
net_disconnect_channel(rec->channel);
}
static void net_disconnect_remove(NET_DISCONNECT_REC *rec) static void net_disconnect_remove(NET_DISCONNECT_REC *rec)
{ {
disconnects = g_slist_remove(disconnects, rec); disconnects = g_slist_remove(disconnects, rec);
g_source_remove(rec->tag); g_source_remove(rec->tag);
net_disconnect(rec->handle); net_disconnect_any(rec);
g_free(rec); g_free(rec);
} }
@ -57,7 +64,7 @@ static void sig_disconnect(NET_DISCONNECT_REC *rec)
if server just keeps sending us stuff we won't get stuck */ if server just keeps sending us stuff we won't get stuck */
count = 0; count = 0;
do { do {
ret = net_receive(rec->handle, buf, sizeof(buf)); ret = net_receive_channel(rec->channel, buf, sizeof(buf));
if (ret == -1) { if (ret == -1) {
/* socket was closed */ /* socket was closed */
net_disconnect_remove(rec); net_disconnect_remove(rec);
@ -92,15 +99,17 @@ static int sig_timeout_disconnect(void)
/* Try to let the other side close the connection, if it still isn't /* Try to let the other side close the connection, if it still isn't
disconnected after certain amount of time, close it ourself */ disconnected after certain amount of time, close it ourself */
void net_disconnect_later(GIOChannel *handle) void net_disconnect_later(NET_SENDBUF_REC *handle)
{ {
NET_DISCONNECT_REC *rec; NET_DISCONNECT_REC *rec;
rec = g_new(NET_DISCONNECT_REC, 1); rec = g_new(NET_DISCONNECT_REC, 1);
rec->created = time(NULL); rec->created = time(NULL);
rec->handle = handle; if (handle->channel != NULL) {
rec->tag = i_input_add(handle, I_INPUT_READ, (GInputFunction) sig_disconnect, rec); rec->channel = handle->channel;
rec->tag =
i_input_add(rec->channel, I_INPUT_READ, (GInputFunction) sig_disconnect, rec);
}
if (timeout_tag == -1) { if (timeout_tag == -1) {
timeout_tag = g_timeout_add(10000, (GSourceFunc) timeout_tag = g_timeout_add(10000, (GSourceFunc)
sig_timeout_disconnect, NULL); sig_timeout_disconnect, NULL);
@ -136,15 +145,16 @@ void net_disconnect_deinit(void)
continue; continue;
} }
fd = g_io_channel_unix_get_fd(rec->handle); if (rec->channel != NULL) {
FD_ZERO(&set); fd = g_io_channel_unix_get_fd(rec->channel);
FD_SET(fd, &set); FD_ZERO(&set);
tv.tv_sec = first ? 0 : max-now; FD_SET(fd, &set);
tv.tv_usec = first ? 100000 : 0; tv.tv_sec = first ? 0 : max - now;
if (select(fd+1, &set, NULL, NULL, &tv) > 0 && tv.tv_usec = first ? 100000 : 0;
FD_ISSET(fd, &set)) { if (select(fd + 1, &set, NULL, NULL, &tv) > 0 && FD_ISSET(fd, &set)) {
/* data coming .. check if we can close the handle */ /* data coming .. check if we can close the handle */
sig_disconnect(rec); sig_disconnect(rec);
}
} else if (first) { } else if (first) {
/* Display the text when we have already waited /* Display the text when we have already waited
for a while */ for a while */

View file

@ -1,9 +1,11 @@
#ifndef IRSSI_CORE_NET_DISCONNECT_H #ifndef IRSSI_CORE_NET_DISCONNECT_H
#define IRSSI_CORE_NET_DISCONNECT_H #define IRSSI_CORE_NET_DISCONNECT_H
#include <irssi/src/common.h>
/* Try to let the other side close the connection, if it still isn't /* Try to let the other side close the connection, if it still isn't
disconnected after certain amount of time, close it ourself */ disconnected after certain amount of time, close it ourself */
void net_disconnect_later(GIOChannel *handle); void net_disconnect_later(NET_SENDBUF_REC *handle);
void net_disconnect_init(void); void net_disconnect_init(void);
void net_disconnect_deinit(void); void net_disconnect_deinit(void);

View file

@ -26,15 +26,15 @@
/* Create new buffer - if `bufsize' is zero or less, DEFAULT_BUFFER_SIZE /* Create new buffer - if `bufsize' is zero or less, DEFAULT_BUFFER_SIZE
is used */ is used */
NET_SENDBUF_REC *net_sendbuffer_create(GIOChannel *handle, int bufsize) NET_SENDBUF_REC *net_sendbuffer_create_channel(GIOChannel *channel, int bufsize)
{ {
NET_SENDBUF_REC *rec; NET_SENDBUF_REC *rec;
g_return_val_if_fail(handle != NULL, NULL); g_return_val_if_fail(channel != NULL, NULL);
rec = g_new0(NET_SENDBUF_REC, 1); rec = g_new0(NET_SENDBUF_REC, 1);
rec->send_tag = -1; rec->send_tag = -1;
rec->handle = handle; rec->channel = channel;
rec->bufsize = bufsize > 0 ? bufsize : DEFAULT_BUFFER_SIZE; rec->bufsize = bufsize > 0 ? bufsize : DEFAULT_BUFFER_SIZE;
rec->def_bufsize = rec->bufsize; rec->def_bufsize = rec->bufsize;
@ -45,7 +45,10 @@ NET_SENDBUF_REC *net_sendbuffer_create(GIOChannel *handle, int bufsize)
void net_sendbuffer_destroy(NET_SENDBUF_REC *rec, int close) void net_sendbuffer_destroy(NET_SENDBUF_REC *rec, int close)
{ {
if (rec->send_tag != -1) g_source_remove(rec->send_tag); if (rec->send_tag != -1) g_source_remove(rec->send_tag);
if (close) net_disconnect(rec->handle); if (close) {
if (rec->channel != NULL)
net_disconnect_channel(rec->channel);
}
if (rec->readbuffer != NULL) line_split_free(rec->readbuffer); if (rec->readbuffer != NULL) line_split_free(rec->readbuffer);
g_free_not_null(rec->buffer); g_free_not_null(rec->buffer);
g_free(rec); g_free(rec);
@ -56,7 +59,7 @@ static int buffer_send(NET_SENDBUF_REC *rec)
{ {
int ret; int ret;
ret = net_transmit(rec->handle, rec->buffer, rec->bufpos); ret = net_transmit_channel(rec->channel, rec->buffer, rec->bufpos);
if (ret < 0 || rec->bufpos == ret) { if (ret < 0 || rec->bufpos == ret) {
/* error/all sent - don't try to send it anymore */ /* error/all sent - don't try to send it anymore */
rec->bufsize = rec->def_bufsize; rec->bufsize = rec->def_bufsize;
@ -102,7 +105,7 @@ static int buffer_add(NET_SENDBUF_REC *rec, const void *data, int size)
rec->buffer = g_realloc(rec->buffer, rec->bufsize); rec->buffer = g_realloc(rec->buffer, rec->bufsize);
} }
memcpy(rec->buffer+rec->bufpos, data, size); memcpy(rec->buffer + rec->bufpos, data, size);
rec->bufpos += size; rec->bufpos += size;
return TRUE; return TRUE;
} }
@ -112,7 +115,7 @@ static int buffer_add(NET_SENDBUF_REC *rec, const void *data, int size)
occurred. */ occurred. */
int net_sendbuffer_send(NET_SENDBUF_REC *rec, const void *data, int size) int net_sendbuffer_send(NET_SENDBUF_REC *rec, const void *data, int size)
{ {
int ret; int ret = 0;
g_return_val_if_fail(rec != NULL, -1); g_return_val_if_fail(rec != NULL, -1);
g_return_val_if_fail(data != NULL, -1); g_return_val_if_fail(data != NULL, -1);
@ -120,7 +123,8 @@ int net_sendbuffer_send(NET_SENDBUF_REC *rec, const void *data, int size)
if (rec->buffer == NULL || rec->bufpos == 0) { if (rec->buffer == NULL || rec->bufpos == 0) {
/* nothing in buffer - transmit immediately */ /* nothing in buffer - transmit immediately */
ret = net_transmit(rec->handle, data, size); if (rec->channel != NULL)
ret = net_transmit_channel(rec->channel, data, size);
if (ret < 0) return -1; if (ret < 0) return -1;
size -= ret; size -= ret;
data = ((const char *) data) + ret; data = ((const char *) data) + ret;
@ -131,8 +135,10 @@ int net_sendbuffer_send(NET_SENDBUF_REC *rec, const void *data, int size)
/* everything couldn't be sent. */ /* everything couldn't be sent. */
if (rec->send_tag == -1) { if (rec->send_tag == -1) {
rec->send_tag = if (rec->channel != NULL) {
i_input_add(rec->handle, I_INPUT_WRITE, (GInputFunction) sig_sendbuffer, rec); rec->send_tag = i_input_add(rec->channel, I_INPUT_WRITE,
(GInputFunction) sig_sendbuffer, rec);
}
} }
return buffer_add(rec, data, size) ? 0 : -1; return buffer_add(rec, data, size) ? 0 : -1;
@ -143,8 +149,10 @@ int net_sendbuffer_receive_line(NET_SENDBUF_REC *rec, char **str, int read_socke
char tmpbuf[2048]; char tmpbuf[2048];
int recvlen = 0; int recvlen = 0;
if (read_socket) if (read_socket) {
recvlen = net_receive(rec->handle, tmpbuf, sizeof(tmpbuf)); if (rec->channel != NULL)
recvlen = net_receive_channel(rec->channel, tmpbuf, sizeof(tmpbuf));
}
return line_split(tmpbuf, recvlen, str, &rec->readbuffer); return line_split(tmpbuf, recvlen, str, &rec->readbuffer);
} }
@ -158,16 +166,16 @@ void net_sendbuffer_flush(NET_SENDBUF_REC *rec)
return; return;
/* set the socket blocking while doing this */ /* set the socket blocking while doing this */
handle = g_io_channel_unix_get_fd(rec->handle); handle = g_io_channel_unix_get_fd(rec->channel);
fcntl(handle, F_SETFL, 0); fcntl(handle, F_SETFL, 0);
while (!buffer_send(rec)) ; while (!buffer_send(rec)) ;
fcntl(handle, F_SETFL, O_NONBLOCK); fcntl(handle, F_SETFL, O_NONBLOCK);
} }
/* Returns the socket handle */ /* Returns the socket handle */
GIOChannel *net_sendbuffer_handle(NET_SENDBUF_REC *rec) GIOChannel *net_sendbuffer_channel(NET_SENDBUF_REC *rec)
{ {
g_return_val_if_fail(rec != NULL, NULL); g_return_val_if_fail(rec != NULL, NULL);
return rec->handle; return rec->channel;
} }

View file

@ -1,24 +1,26 @@
#ifndef IRSSI_CORE_NET_SENDBUFFER_H #ifndef IRSSI_CORE_NET_SENDBUFFER_H
#define IRSSI_CORE_NET_SENDBUFFER_H #define IRSSI_CORE_NET_SENDBUFFER_H
#include <irssi/src/common.h>
#define DEFAULT_BUFFER_SIZE 8192 #define DEFAULT_BUFFER_SIZE 8192
#define MAX_BUFFER_SIZE 1048576 #define MAX_BUFFER_SIZE 1048576
struct _NET_SENDBUF_REC { struct _NET_SENDBUF_REC {
GIOChannel *handle; GIOChannel *channel;
LINEBUF_REC *readbuffer; /* receive buffer */ LINEBUF_REC *readbuffer; /* receive buffer */
int send_tag; int send_tag;
int bufsize; int bufsize;
int bufpos; int bufpos;
char *buffer; /* Buffer is NULL until it's actually needed. */ char *buffer; /* Buffer is NULL until it's actually needed. */
int def_bufsize; int def_bufsize;
unsigned int dead:1; unsigned int dead : 1;
}; };
/* Create new buffer - if `bufsize' is zero or less, DEFAULT_BUFFER_SIZE /* Create new buffer - if `bufsize' is zero or less, DEFAULT_BUFFER_SIZE
is used */ is used */
NET_SENDBUF_REC *net_sendbuffer_create(GIOChannel *handle, int bufsize); NET_SENDBUF_REC *net_sendbuffer_create_channel(GIOChannel *channel, int bufsize);
/* Destroy the buffer. `close' specifies if socket handle should be closed. */ /* Destroy the buffer. `close' specifies if socket handle should be closed. */
void net_sendbuffer_destroy(NET_SENDBUF_REC *rec, int close); void net_sendbuffer_destroy(NET_SENDBUF_REC *rec, int close);
@ -33,6 +35,6 @@ int net_sendbuffer_receive_line(NET_SENDBUF_REC *rec, char **str, int read_socke
void net_sendbuffer_flush(NET_SENDBUF_REC *rec); void net_sendbuffer_flush(NET_SENDBUF_REC *rec);
/* Returns the socket handle */ /* Returns the socket handle */
GIOChannel *net_sendbuffer_handle(NET_SENDBUF_REC *rec); GIOChannel *net_sendbuffer_channel(NET_SENDBUF_REC *rec);
#endif #endif

View file

@ -82,9 +82,9 @@ static int ssl_inited = FALSE;
static X509_STORE *store = NULL; static X509_STORE *store = NULL;
#endif #endif
static void irssi_ssl_free(GIOChannel *handle) static void irssi_ssl_free(GIOChannel *channel)
{ {
GIOSSLChannel *chan = (GIOSSLChannel *)handle; GIOSSLChannel *chan = (GIOSSLChannel *) channel;
g_io_channel_unref(chan->giochan); g_io_channel_unref(chan->giochan);
SSL_free(chan->ssl); SSL_free(chan->ssl);
SSL_CTX_free(chan->ctx); SSL_CTX_free(chan->ctx);
@ -247,9 +247,10 @@ static gboolean irssi_ssl_verify(SSL *ssl, SSL_CTX *ctx, const char* hostname, i
return TRUE; return TRUE;
} }
static GIOStatus irssi_ssl_read(GIOChannel *handle, gchar *buf, gsize len, gsize *ret, GError **gerr) static GIOStatus irssi_ssl_read(GIOChannel *channel, gchar *buf, gsize len, gsize *ret,
GError **gerr)
{ {
GIOSSLChannel *chan = (GIOSSLChannel *)handle; GIOSSLChannel *chan = (GIOSSLChannel *) channel;
gint ret1, err; gint ret1, err;
const char *errstr; const char *errstr;
gchar *errmsg; gchar *errmsg;
@ -293,9 +294,10 @@ static GIOStatus irssi_ssl_read(GIOChannel *handle, gchar *buf, gsize len, gsize
return G_IO_STATUS_ERROR; return G_IO_STATUS_ERROR;
} }
static GIOStatus irssi_ssl_write(GIOChannel *handle, const gchar *buf, gsize len, gsize *ret, GError **gerr) static GIOStatus irssi_ssl_write(GIOChannel *channel, const gchar *buf, gsize len, gsize *ret,
GError **gerr)
{ {
GIOSSLChannel *chan = (GIOSSLChannel *)handle; GIOSSLChannel *chan = (GIOSSLChannel *) channel;
gint ret1, err; gint ret1, err;
const char *errstr; const char *errstr;
gchar *errmsg; gchar *errmsg;
@ -339,39 +341,39 @@ static GIOStatus irssi_ssl_write(GIOChannel *handle, const gchar *buf, gsize len
return G_IO_STATUS_ERROR; return G_IO_STATUS_ERROR;
} }
static GIOStatus irssi_ssl_seek(GIOChannel *handle, gint64 offset, GSeekType type, GError **gerr) static GIOStatus irssi_ssl_seek(GIOChannel *channel, gint64 offset, GSeekType type, GError **gerr)
{ {
GIOSSLChannel *chan = (GIOSSLChannel *)handle; GIOSSLChannel *chan = (GIOSSLChannel *) channel;
return chan->giochan->funcs->io_seek(handle, offset, type, gerr); return chan->giochan->funcs->io_seek(channel, offset, type, gerr);
} }
static GIOStatus irssi_ssl_close(GIOChannel *handle, GError **gerr) static GIOStatus irssi_ssl_close(GIOChannel *channel, GError **gerr)
{ {
GIOSSLChannel *chan = (GIOSSLChannel *)handle; GIOSSLChannel *chan = (GIOSSLChannel *) channel;
return chan->giochan->funcs->io_close(handle, gerr); return chan->giochan->funcs->io_close(channel, gerr);
} }
static GSource *irssi_ssl_create_watch(GIOChannel *handle, GIOCondition cond) static GSource *irssi_ssl_create_watch(GIOChannel *channel, GIOCondition cond)
{ {
GIOSSLChannel *chan = (GIOSSLChannel *)handle; GIOSSLChannel *chan = (GIOSSLChannel *) channel;
return chan->giochan->funcs->io_create_watch(handle, cond); return chan->giochan->funcs->io_create_watch(channel, cond);
} }
static GIOStatus irssi_ssl_set_flags(GIOChannel *handle, GIOFlags flags, GError **gerr) static GIOStatus irssi_ssl_set_flags(GIOChannel *channel, GIOFlags flags, GError **gerr)
{ {
GIOSSLChannel *chan = (GIOSSLChannel *)handle; GIOSSLChannel *chan = (GIOSSLChannel *) channel;
return chan->giochan->funcs->io_set_flags(handle, flags, gerr); return chan->giochan->funcs->io_set_flags(channel, flags, gerr);
} }
static GIOFlags irssi_ssl_get_flags(GIOChannel *handle) static GIOFlags irssi_ssl_get_flags(GIOChannel *channel)
{ {
GIOSSLChannel *chan = (GIOSSLChannel *)handle; GIOSSLChannel *chan = (GIOSSLChannel *) channel;
return chan->giochan->funcs->io_get_flags(handle); return chan->giochan->funcs->io_get_flags(channel);
} }
static GIOFuncs irssi_ssl_channel_funcs = { static GIOFuncs irssi_ssl_channel_funcs = {
@ -441,7 +443,7 @@ static int get_pem_password_callback(char *buffer, int max_length, int rwflag, v
return length; return length;
} }
static GIOChannel *irssi_ssl_get_iochannel(GIOChannel *handle, int port, SERVER_REC *server) static GIOChannel *irssi_ssl_get_iochannel(GIOChannel *channel, int port, SERVER_REC *server)
{ {
GIOSSLChannel *chan; GIOSSLChannel *chan;
GIOChannel *gchan; GIOChannel *gchan;
@ -457,12 +459,12 @@ static GIOChannel *irssi_ssl_get_iochannel(GIOChannel *handle, int port, SERVER_
const char *ciphers = server->connrec->tls_ciphers; const char *ciphers = server->connrec->tls_ciphers;
gboolean verify = server->connrec->tls_verify; gboolean verify = server->connrec->tls_verify;
g_return_val_if_fail(handle != NULL, NULL); g_return_val_if_fail(channel != NULL, NULL);
if(!ssl_inited && !irssi_ssl_init()) if(!ssl_inited && !irssi_ssl_init())
return NULL; return NULL;
if(!(fd = g_io_channel_unix_get_fd(handle))) if (!(fd = g_io_channel_unix_get_fd(channel)))
return NULL; return NULL;
ERR_clear_error(); ERR_clear_error();
@ -575,7 +577,7 @@ static GIOChannel *irssi_ssl_get_iochannel(GIOChannel *handle, int port, SERVER_
chan = g_new0(GIOSSLChannel, 1); chan = g_new0(GIOSSLChannel, 1);
chan->fd = fd; chan->fd = fd;
chan->giochan = handle; chan->giochan = channel;
chan->ssl = ssl; chan->ssl = ssl;
chan->ctx = ctx; chan->ctx = ctx;
chan->server = server; chan->server = server;
@ -802,37 +804,36 @@ static void set_server_temporary_key_info(TLS_REC *tls, SSL *ssl)
#endif /* SSL_get_server_tmp_key. */ #endif /* SSL_get_server_tmp_key. */
} }
GIOChannel *net_connect_ip_ssl(IPADDR *ip, int port, IPADDR *my_ip, SERVER_REC *server) GIOChannel *net_connect_ip_ssl_channel(IPADDR *ip, int port, IPADDR *my_ip, SERVER_REC *server)
{ {
GIOChannel *handle, *ssl_handle; GIOChannel *channel, *ssl_channel;
handle = net_connect_ip(ip, port, my_ip); channel = net_connect_ip_channel(ip, port, my_ip);
if (handle == NULL) if (channel == NULL)
return NULL; return NULL;
ssl_handle = irssi_ssl_get_iochannel(handle, port, server); ssl_channel = irssi_ssl_get_iochannel(channel, port, server);
if (ssl_handle == NULL) if (ssl_channel == NULL)
g_io_channel_unref(handle); g_io_channel_unref(channel);
return ssl_handle; return ssl_channel;
} }
GIOChannel *net_start_ssl(SERVER_REC *server) GIOChannel *net_start_ssl_channel(SERVER_REC *server)
{ {
GIOChannel *handle, *ssl_handle; GIOChannel *channel, *ssl_channel;
g_return_val_if_fail(server != NULL, NULL); g_return_val_if_fail(server != NULL, NULL);
handle = net_sendbuffer_handle(server->handle); channel = net_sendbuffer_channel(server->handle);
if (handle == NULL) if (channel == NULL)
return NULL; return NULL;
ssl_handle = irssi_ssl_get_iochannel(handle, server->connrec->port, server); ssl_channel = irssi_ssl_get_iochannel(channel, server->connrec->port, server);
return ssl_handle; return ssl_channel;
} }
int irssi_ssl_handshake_channel(GIOChannel *channel)
int irssi_ssl_handshake(GIOChannel *handle)
{ {
GIOSSLChannel *chan = (GIOSSLChannel *)handle; GIOSSLChannel *chan = (GIOSSLChannel *) channel;
int ret, err; int ret, err;
const char *errstr = NULL; const char *errstr = NULL;
X509 *cert = NULL; X509 *cert = NULL;

View file

@ -182,7 +182,7 @@ int net_connect_ip_handle(const IPADDR *ip, int port, const IPADDR *my_ip)
} }
/* Connect to socket with ip address */ /* Connect to socket with ip address */
GIOChannel *net_connect_ip(IPADDR *ip, int port, IPADDR *my_ip) GIOChannel *net_connect_ip_channel(IPADDR *ip, int port, IPADDR *my_ip)
{ {
int handle = -1; int handle = -1;
@ -202,7 +202,7 @@ GIOChannel *net_connect_ip(IPADDR *ip, int port, IPADDR *my_ip)
} }
/* Connect to named UNIX socket */ /* Connect to named UNIX socket */
GIOChannel *net_connect_unix(const char *path) GIOChannel *net_connect_unix_channel(const char *path)
{ {
struct sockaddr_un sa; struct sockaddr_un sa;
int handle, ret; int handle, ret;
@ -233,17 +233,17 @@ GIOChannel *net_connect_unix(const char *path)
} }
/* Disconnect socket */ /* Disconnect socket */
void net_disconnect(GIOChannel *handle) void net_disconnect_channel(GIOChannel *channel)
{ {
g_return_if_fail(handle != NULL); g_return_if_fail(channel != NULL);
g_io_channel_shutdown(handle, TRUE, NULL); g_io_channel_shutdown(channel, TRUE, NULL);
g_io_channel_unref(handle); g_io_channel_unref(channel);
} }
/* Listen for connections on a socket. if `my_ip' is NULL, listen in any /* Listen for connections on a socket. if `my_ip' is NULL, listen in any
address. */ address. */
GIOChannel *net_listen(IPADDR *my_ip, int *port) GIOChannel *net_listen_channel(IPADDR *my_ip, int *port)
{ {
union sockaddr_union so; union sockaddr_union so;
int ret, handle, opt = 1; int ret, handle, opt = 1;
@ -296,16 +296,16 @@ GIOChannel *net_listen(IPADDR *my_ip, int *port)
} }
/* Accept a connection on a socket */ /* Accept a connection on a socket */
GIOChannel *net_accept(GIOChannel *handle, IPADDR *addr, int *port) GIOChannel *net_accept_channel(GIOChannel *channel, IPADDR *addr, int *port)
{ {
union sockaddr_union so; union sockaddr_union so;
int ret; int ret;
socklen_t addrlen; socklen_t addrlen;
g_return_val_if_fail(handle != NULL, NULL); g_return_val_if_fail(channel != NULL, NULL);
addrlen = sizeof(so); addrlen = sizeof(so);
ret = accept(g_io_channel_unix_get_fd(handle), &so.sa, &addrlen); ret = accept(g_io_channel_unix_get_fd(channel), &so.sa, &addrlen);
if (ret < 0) if (ret < 0)
return NULL; return NULL;
@ -318,16 +318,16 @@ GIOChannel *net_accept(GIOChannel *handle, IPADDR *addr, int *port)
} }
/* Read data from socket, return number of bytes read, -1 = error */ /* Read data from socket, return number of bytes read, -1 = error */
int net_receive(GIOChannel *handle, char *buf, int len) int net_receive_channel(GIOChannel *channel, char *buf, int len)
{ {
gsize ret; gsize ret;
GIOStatus status; GIOStatus status;
GError *err = NULL; GError *err = NULL;
g_return_val_if_fail(handle != NULL, -1); g_return_val_if_fail(channel != NULL, -1);
g_return_val_if_fail(buf != NULL, -1); g_return_val_if_fail(buf != NULL, -1);
status = g_io_channel_read_chars(handle, buf, len, &ret, &err); status = g_io_channel_read_chars(channel, buf, len, &ret, &err);
if (err != NULL) { if (err != NULL) {
g_warning("%s", err->message); g_warning("%s", err->message);
g_error_free(err); g_error_free(err);
@ -339,16 +339,16 @@ int net_receive(GIOChannel *handle, char *buf, int len)
} }
/* Transmit data, return number of bytes sent, -1 = error */ /* Transmit data, return number of bytes sent, -1 = error */
int net_transmit(GIOChannel *handle, const char *data, int len) int net_transmit_channel(GIOChannel *channel, const char *data, int len)
{ {
gsize ret; gsize ret;
GIOStatus status; GIOStatus status;
GError *err = NULL; GError *err = NULL;
g_return_val_if_fail(handle != NULL, -1); g_return_val_if_fail(channel != NULL, -1);
g_return_val_if_fail(data != NULL, -1); g_return_val_if_fail(data != NULL, -1);
status = g_io_channel_write_chars(handle, (char *) data, len, &ret, &err); status = g_io_channel_write_chars(channel, (char *) data, len, &ret, &err);
if (err != NULL) { if (err != NULL) {
g_warning("%s", err->message); g_warning("%s", err->message);
g_error_free(err); g_error_free(err);
@ -360,17 +360,16 @@ int net_transmit(GIOChannel *handle, const char *data, int len)
} }
/* Get socket address/port */ /* Get socket address/port */
int net_getsockname(GIOChannel *handle, IPADDR *addr, int *port) int net_getsockname_channel(GIOChannel *channel, IPADDR *addr, int *port)
{ {
union sockaddr_union so; union sockaddr_union so;
socklen_t addrlen; socklen_t addrlen;
g_return_val_if_fail(handle != NULL, -1); g_return_val_if_fail(channel != NULL, -1);
g_return_val_if_fail(addr != NULL, -1); g_return_val_if_fail(addr != NULL, -1);
addrlen = sizeof(so); addrlen = sizeof(so);
if (getsockname(g_io_channel_unix_get_fd(handle), if (getsockname(g_io_channel_unix_get_fd(channel), (struct sockaddr *) &so, &addrlen) == -1)
(struct sockaddr *) &so, &addrlen) == -1)
return -1; return -1;
sin_get_ip(&so, addr); sin_get_ip(&so, addr);
@ -518,13 +517,13 @@ int net_host2ip(const char *host, IPADDR *ip)
} }
/* Get socket error */ /* Get socket error */
int net_geterror(GIOChannel *handle) int net_geterror_channel(GIOChannel *channel)
{ {
int data; int data;
socklen_t len = sizeof(data); socklen_t len = sizeof(data);
if (getsockopt(g_io_channel_unix_get_fd(handle), if (getsockopt(g_io_channel_unix_get_fd(channel), SOL_SOCKET, SO_ERROR, (void *) &data,
SOL_SOCKET, SO_ERROR, (void *) &data, &len) == -1) &len) == -1)
return -1; return -1;
return data; return data;

View file

@ -57,34 +57,34 @@ int i_io_channel_read_block(GIOChannel *channel, void *data, int len);
int net_connect_ip_handle(const IPADDR *ip, int port, const IPADDR *my_ip); int net_connect_ip_handle(const IPADDR *ip, int port, const IPADDR *my_ip);
/* Connect to socket with ip address and SSL*/ /* Connect to socket with ip address and SSL*/
GIOChannel *net_connect_ip_ssl(IPADDR *ip, int port, IPADDR *my_ip, SERVER_REC *server); GIOChannel *net_connect_ip_ssl_channel(IPADDR *ip, int port, IPADDR *my_ip, SERVER_REC *server);
/* Start TLS */ /* Start TLS */
GIOChannel *net_start_ssl(SERVER_REC *server); GIOChannel *net_start_ssl_channel(SERVER_REC *server);
int irssi_ssl_handshake(GIOChannel *handle); int irssi_ssl_handshake_channel(GIOChannel *channel);
/* Connect to socket with ip address */ /* Connect to socket with ip address */
GIOChannel *net_connect_ip(IPADDR *ip, int port, IPADDR *my_ip); GIOChannel *net_connect_ip_channel(IPADDR *ip, int port, IPADDR *my_ip);
/* Connect to named UNIX socket */ /* Connect to named UNIX socket */
GIOChannel *net_connect_unix(const char *path); GIOChannel *net_connect_unix_channel(const char *path);
/* Disconnect socket */ /* Disconnect socket */
void net_disconnect(GIOChannel *handle); void net_disconnect_channel(GIOChannel *channel);
/* Listen for connections on a socket */ /* Listen for connections on a socket */
GIOChannel *net_listen(IPADDR *my_ip, int *port); GIOChannel *net_listen_channel(IPADDR *my_ip, int *port);
/* Accept a connection on a socket */ /* Accept a connection on a socket */
GIOChannel *net_accept(GIOChannel *handle, IPADDR *addr, int *port); GIOChannel *net_accept_channel(GIOChannel *channel, IPADDR *addr, int *port);
/* Read data from socket, return number of bytes read, -1 = error */ /* Read data from socket, return number of bytes read, -1 = error */
int net_receive(GIOChannel *handle, char *buf, int len); int net_receive_channel(GIOChannel *channel, char *buf, int len);
/* Transmit data, return number of bytes sent, -1 = error */ /* Transmit data, return number of bytes sent, -1 = error */
int net_transmit(GIOChannel *handle, const char *data, int len); int net_transmit_channel(GIOChannel *channel, const char *data, int len);
/* Get the first IP address for host, both IPv4 and IPv6 if possible. */ /* Get the first IP address for host, both IPv4 and IPv6 if possible. */
int net_gethostbyname_first_ips(const char *addr, GResolverNameLookupFlags flags, IPADDR *ip4, int net_gethostbyname_first_ips(const char *addr, GResolverNameLookupFlags flags, IPADDR *ip4,
IPADDR *ip6); IPADDR *ip6);
/* Get socket address/port */ /* Get socket address/port */
int net_getsockname(GIOChannel *handle, IPADDR *addr, int *port); int net_getsockname_channel(GIOChannel *channel, IPADDR *addr, int *port);
/* IPADDR -> char* translation. `host' must be at least MAX_IP_LEN bytes */ /* IPADDR -> char* translation. `host' must be at least MAX_IP_LEN bytes */
int net_ip2host(IPADDR *ip, char *host); int net_ip2host(IPADDR *ip, char *host);
@ -92,7 +92,7 @@ int net_ip2host(IPADDR *ip, char *host);
int net_host2ip(const char *host, IPADDR *ip); int net_host2ip(const char *host, IPADDR *ip);
/* Get socket error */ /* Get socket error */
int net_geterror(GIOChannel *handle); int net_geterror_channel(GIOChannel *channel);
/* Get name of TCP service */ /* Get name of TCP service */
char *net_getservbyport(int port); char *net_getservbyport(int port);

View file

@ -34,7 +34,7 @@ char *tls_ciphers;
char *tls_pinned_cert; char *tls_pinned_cert;
char *tls_pinned_pubkey; char *tls_pinned_pubkey;
GIOChannel *connect_handle; /* connect using this handle */ GIOChannel *connect_channel; /* connect using this handle */
/* when reconnecting, the old server status */ /* when reconnecting, the old server status */
unsigned int reconnection:1; /* we're trying to reconnect a connected server */ unsigned int reconnection:1; /* we're trying to reconnect a connected server */

View file

@ -143,13 +143,13 @@ void server_connect_finished(SERVER_REC *server)
signal_emit("server connected", 1, server); signal_emit("server connected", 1, server);
} }
static void server_connect_callback_init(SERVER_REC *server, GIOChannel *handle) static void server_connect_callback_init_channel(SERVER_REC *server, GIOChannel *channel)
{ {
int error; int error;
g_return_if_fail(IS_SERVER(server)); g_return_if_fail(IS_SERVER(server));
error = net_geterror(handle); error = net_geterror_channel(channel);
if (error != 0) { if (error != 0) {
server->connection_lost = TRUE; server->connection_lost = TRUE;
server->connrec->last_failed = server->connrec->last_connected; server->connrec->last_failed = server->connrec->last_connected;
@ -164,13 +164,13 @@ static void server_connect_callback_init(SERVER_REC *server, GIOChannel *handle)
server_connect_finished(server); server_connect_finished(server);
} }
static void server_connect_callback_init_ssl(SERVER_REC *server, GIOChannel *handle) static void server_connect_callback_init_ssl_channel(SERVER_REC *server, GIOChannel *channel)
{ {
int error; int error;
g_return_if_fail(IS_SERVER(server)); g_return_if_fail(IS_SERVER(server));
error = irssi_ssl_handshake(handle); error = irssi_ssl_handshake_channel(channel);
if (error == -1) { if (error == -1) {
server->connection_lost = TRUE; server->connection_lost = TRUE;
server->connrec->last_failed = server->connrec->last_connected; server->connrec->last_failed = server->connrec->last_connected;
@ -181,8 +181,8 @@ static void server_connect_callback_init_ssl(SERVER_REC *server, GIOChannel *han
if (server->connect_tag != -1) if (server->connect_tag != -1)
g_source_remove(server->connect_tag); g_source_remove(server->connect_tag);
server->connect_tag = server->connect_tag =
i_input_add(handle, error == 1 ? I_INPUT_READ : I_INPUT_WRITE, i_input_add(channel, error == 1 ? I_INPUT_READ : I_INPUT_WRITE,
(GInputFunction) server_connect_callback_init_ssl, server); (GInputFunction) server_connect_callback_init_ssl_channel, server);
return; return;
} }
@ -195,17 +195,17 @@ static void server_connect_callback_init_ssl(SERVER_REC *server, GIOChannel *han
server_connect_finished(server); server_connect_finished(server);
} }
static void server_real_connect(SERVER_REC *server, IPADDR *ip, static void server_real_connect(SERVER_REC *server, IPADDR *ip, const char *unix_socket,
const char *unix_socket) const char *host)
{ {
GIOChannel *handle; GIOChannel *channel;
IPADDR *own_ip = NULL;
const char *errmsg; const char *errmsg;
char *errmsg2; char *errmsg2;
IPADDR *own_ip = NULL;
char ipaddr[MAX_IP_LEN]; char ipaddr[MAX_IP_LEN];
int port = 0; int port = 0;
g_return_if_fail(ip != NULL || unix_socket != NULL); g_return_if_fail(ip != NULL || unix_socket != NULL || host != NULL);
if (ip != NULL) { if (ip != NULL) {
server->connrec->chosen_family = ip->family; server->connrec->chosen_family = ip->family;
@ -213,7 +213,7 @@ static void server_real_connect(SERVER_REC *server, IPADDR *ip,
server->connrec->ipaddr = g_strdup(ipaddr); server->connrec->ipaddr = g_strdup(ipaddr);
} }
signal_emit("server connecting", 2, server, ip); signal_emit("server connecting", 3, server, ip, ip != NULL ? ipaddr : host);
if (server->connrec->no_connect) if (server->connrec->no_connect)
return; return;
@ -222,23 +222,23 @@ static void server_real_connect(SERVER_REC *server, IPADDR *ip,
own_ip = IPADDR_IS_V6(ip) ? server->connrec->own_ip6 : server->connrec->own_ip4; own_ip = IPADDR_IS_V6(ip) ? server->connrec->own_ip6 : server->connrec->own_ip4;
port = server->connrec->proxy != NULL ? port = server->connrec->proxy != NULL ?
server->connrec->proxy_port : server->connrec->port; server->connrec->proxy_port : server->connrec->port;
handle = net_connect_ip(ip, port, own_ip); channel = net_connect_ip_channel(ip, port, own_ip);
} else { } else {
handle = net_connect_unix(unix_socket); channel = net_connect_unix_channel(unix_socket);
} }
if (server->connrec->use_tls && handle != NULL) { if (server->connrec->use_tls && channel != NULL) {
server->handle = net_sendbuffer_create(handle, 0); server->handle = net_sendbuffer_create_channel(channel, 0);
handle = net_start_ssl(server); channel = net_start_ssl_channel(server);
if (handle == NULL) { if (channel == NULL) {
net_sendbuffer_destroy(server->handle, TRUE); net_sendbuffer_destroy(server->handle, TRUE);
server->handle = NULL; server->handle = NULL;
} else { } else {
server->handle->handle = handle; server->handle->channel = channel;
} }
} }
if (handle == NULL) { if (channel == NULL) {
/* failed */ /* failed */
errmsg = g_strerror(errno); errmsg = g_strerror(errno);
errmsg2 = NULL; errmsg2 = NULL;
@ -262,13 +262,13 @@ static void server_real_connect(SERVER_REC *server, IPADDR *ip,
} else { } else {
server->connrec->last_failed = 0; server->connrec->last_failed = 0;
if (!server->connrec->use_tls) if (!server->connrec->use_tls)
server->handle = net_sendbuffer_create(handle, 0); server->handle = net_sendbuffer_create_channel(channel, 0);
if (server->connrec->use_tls) if (server->connrec->use_tls)
server_connect_callback_init_ssl(server, handle); server_connect_callback_init_ssl_channel(server, channel);
else else
server->connect_tag = server->connect_tag = i_input_add(
i_input_add(handle, I_INPUT_WRITE | I_INPUT_READ, channel, I_INPUT_WRITE | I_INPUT_READ,
(GInputFunction) server_connect_callback_init, server); (GInputFunction) server_connect_callback_init_channel, server);
} }
} }
@ -318,7 +318,7 @@ static void server_connect_use_resolved(SERVER_REC *server)
if (ip != NULL) { if (ip != NULL) {
/* host lookup ok */ /* host lookup ok */
server_real_connect(server, ip, NULL); server_real_connect(server, ip, NULL, NULL);
errormsg = NULL; errormsg = NULL;
} else { } else {
if (iprec->error->code == G_RESOLVER_ERROR_NOT_FOUND) { if (iprec->error->code == G_RESOLVER_ERROR_NOT_FOUND) {
@ -441,16 +441,16 @@ int server_start_connect(SERVER_REC *server)
server->rawlog = rawlog_create(); server->rawlog = rawlog_create();
if (server->connrec->connect_handle != NULL) { if (server->connrec->connect_channel != NULL) {
/* already connected */ /* already connected */
GIOChannel *handle = server->connrec->connect_handle; GIOChannel *channel = server->connrec->connect_channel;
server->connrec->connect_handle = NULL; server->connrec->connect_channel = NULL;
server->handle = net_sendbuffer_create(handle, 0); server->handle = net_sendbuffer_create_channel(channel, 0);
server_connect_finished(server); server_connect_finished(server);
} else if (server->connrec->unix_socket) { } else if (server->connrec->unix_socket) {
/* connect with unix socket */ /* connect with unix socket */
server_real_connect(server, NULL, server->connrec->address); server_real_connect(server, NULL, server->connrec->address, NULL);
} else { } else {
int already_resolved; int already_resolved;
/* resolve host name */ /* resolve host name */
@ -564,7 +564,7 @@ int server_unref(SERVER_REC *server)
/* we were on some channels, try to let the server /* we were on some channels, try to let the server
disconnect so that our quit message is guaranteed disconnect so that our quit message is guaranteed
to get displayed */ to get displayed */
net_disconnect_later(net_sendbuffer_handle(server->handle)); net_disconnect_later(server->handle);
net_sendbuffer_destroy(server->handle, FALSE); net_sendbuffer_destroy(server->handle, FALSE);
} }
server->handle = NULL; server->handle = NULL;
@ -654,8 +654,8 @@ void server_connect_unref(SERVER_CONNECT_REC *conn)
CHAT_PROTOCOL(conn)->destroy_server_connect(conn); CHAT_PROTOCOL(conn)->destroy_server_connect(conn);
if (conn->connect_handle != NULL) if (conn->connect_channel != NULL)
net_disconnect(conn->connect_handle); net_disconnect_channel(conn->connect_channel);
g_free_not_null(conn->proxy); g_free_not_null(conn->proxy);
g_free_not_null(conn->proxy_string); g_free_not_null(conn->proxy_string);

View file

@ -175,13 +175,13 @@ static void session_save_server(SERVER_REC *server, CONFIG_REC *config,
config_node_set_str(config, node, "tls_pinned_cert", server->connrec->tls_pinned_cert); config_node_set_str(config, node, "tls_pinned_cert", server->connrec->tls_pinned_cert);
config_node_set_str(config, node, "tls_pinned_pubkey", server->connrec->tls_pinned_pubkey); config_node_set_str(config, node, "tls_pinned_pubkey", server->connrec->tls_pinned_pubkey);
handle = g_io_channel_unix_get_fd(net_sendbuffer_handle(server->handle)); handle = g_io_channel_unix_get_fd(net_sendbuffer_channel(server->handle));
config_node_set_int(config, node, "handle", handle); config_node_set_int(config, node, "handle", handle);
signal_emit("session save server", 3, server, config, node); signal_emit("session save server", 3, server, config, node);
/* fake the server disconnection */ /* fake the server disconnection */
g_io_channel_unref(net_sendbuffer_handle(server->handle)); g_io_channel_unref(net_sendbuffer_channel(server->handle));
net_sendbuffer_destroy(server->handle, FALSE); net_sendbuffer_destroy(server->handle, FALSE);
server->handle = NULL; server->handle = NULL;
@ -282,7 +282,7 @@ static void session_restore_server(CONFIG_NODE *node)
conn->tls_pinned_pubkey = g_strdup(config_node_get_str(node, "tls_pinned_pubkey", NULL)); conn->tls_pinned_pubkey = g_strdup(config_node_get_str(node, "tls_pinned_pubkey", NULL));
conn->reconnection = TRUE; conn->reconnection = TRUE;
conn->connect_handle = i_io_channel_new(handle); conn->connect_channel = i_io_channel_new(handle);
server = proto->server_init_connect(conn); server = proto->server_init_connect(conn);
server->version = g_strdup(config_node_get_str(node, "version", NULL)); server->version = g_strdup(config_node_get_str(node, "version", NULL));

View file

@ -305,9 +305,9 @@ static void process_exec(PROCESS_REC *rec, const char *cmd)
GIOChannel *outio = i_io_channel_new(in[1]); GIOChannel *outio = i_io_channel_new(in[1]);
rec->in = i_io_channel_new(out[0]); rec->in = i_io_channel_new(out[0]);
rec->out = net_sendbuffer_create(outio, 0); rec->out = net_sendbuffer_create_channel(outio, 0);
close(out[1]); close(out[1]);
close(in[0]); close(in[0]);
pidwait_add(rec->pid); pidwait_add(rec->pid);
return; return;
@ -360,7 +360,7 @@ static void sig_exec_input_reader(PROCESS_REC *rec)
g_return_if_fail(rec != NULL); g_return_if_fail(rec != NULL);
recvlen = net_receive(rec->in, tmpbuf, sizeof(tmpbuf)); recvlen = net_receive_channel(rec->in, tmpbuf, sizeof(tmpbuf));
do { do {
ret = line_split(tmpbuf, recvlen, &str, &rec->databuf); ret = line_split(tmpbuf, recvlen, &str, &rec->databuf);
if (ret == -1) { if (ret == -1) {

View file

@ -83,7 +83,7 @@ void event_connected(IRC_SERVER_REC *server, const char *data, const char *from)
server->real_connect_time = time(NULL); server->real_connect_time = time(NULL);
/* let the queue send now that we are identified */ /* let the queue send now that we are identified */
g_get_current_time(&server->wait_cmd); server->wait_cmd = g_get_real_time();
if (server->connrec->usermode != NULL) { if (server->connrec->usermode != NULL) {
/* Send the user mode, before the autosendcmd. /* Send the user mode, before the autosendcmd.
@ -124,7 +124,7 @@ void test_server() {
server->session_reconnect = TRUE; server->session_reconnect = TRUE;
g_free(server->tag); g_free(server->tag);
server->tag = g_strdup("testserver"); server->tag = g_strdup("testserver");
server->handle = net_sendbuffer_create(handle, 0); server->handle = net_sendbuffer_create_channel(handle, 0);
/* we skip some initialisations that would try to send data */ /* we skip some initialisations that would try to send data */
/* irc_servers_deinit(); */ /* irc_servers_deinit(); */

View file

@ -323,7 +323,7 @@ static void server_init_1(IRC_SERVER_REC *server)
server_init_2(server); server_init_2(server);
} }
static void init_ssl_loop(IRC_SERVER_REC *server, GIOChannel *handle) static void init_ssl_loop_channel(IRC_SERVER_REC *server, GIOChannel *channel)
{ {
int error; int error;
server->connrec->starttls = 1; server->connrec->starttls = 1;
@ -333,7 +333,7 @@ static void init_ssl_loop(IRC_SERVER_REC *server, GIOChannel *handle)
server->starttls_tag = 0; server->starttls_tag = 0;
} }
error = irssi_ssl_handshake(handle); error = irssi_ssl_handshake_channel(channel);
if (error == -1) { if (error == -1) {
server->connection_lost = TRUE; server->connection_lost = TRUE;
server_disconnect((SERVER_REC *) server); server_disconnect((SERVER_REC *) server);
@ -341,8 +341,8 @@ static void init_ssl_loop(IRC_SERVER_REC *server, GIOChannel *handle)
} }
if (error & 1) { /* wait */ if (error & 1) { /* wait */
server->starttls_tag = server->starttls_tag =
i_input_add(handle, error == 1 ? I_INPUT_READ : I_INPUT_WRITE, i_input_add(channel, error == 1 ? I_INPUT_READ : I_INPUT_WRITE,
(GInputFunction) init_ssl_loop, server); (GInputFunction) init_ssl_loop_channel, server);
return; return;
} }
/* continue */ /* continue */
@ -375,7 +375,7 @@ void irc_server_send_starttls(IRC_SERVER_REC *server)
static void event_starttls(IRC_SERVER_REC *server, const char *data) static void event_starttls(IRC_SERVER_REC *server, const char *data)
{ {
GIOChannel *ssl_handle; GIOChannel *ssl_channel;
g_return_if_fail(server != NULL); g_return_if_fail(server != NULL);
@ -387,12 +387,12 @@ static void event_starttls(IRC_SERVER_REC *server, const char *data)
char *str; char *str;
line_split("", -1, &str, &server->handle->readbuffer); line_split("", -1, &str, &server->handle->readbuffer);
} }
ssl_handle = net_start_ssl((SERVER_REC *) server); ssl_channel = net_start_ssl_channel((SERVER_REC *) server);
if (ssl_handle != NULL) { if (ssl_channel != NULL) {
g_source_remove(server->readtag); g_source_remove(server->readtag);
server->readtag = -1; server->readtag = -1;
server->handle->handle = ssl_handle; server->handle->channel = ssl_channel;
init_ssl_loop(server, server->handle->handle); init_ssl_loop_channel(server, server->handle->channel);
} else { } else {
g_warning("net_start_ssl failed"); g_warning("net_start_ssl failed");
} }
@ -485,7 +485,7 @@ void irc_server_connect(SERVER_REC *server)
{ {
g_return_if_fail(server != NULL); g_return_if_fail(server != NULL);
if (server->connrec->connect_handle != NULL) { if (server->connrec->connect_channel != NULL) {
/* an existing handle from upgrade */ /* an existing handle from upgrade */
IRC_SERVER_CONNECT_REC *conn; IRC_SERVER_CONNECT_REC *conn;
int tls_disconnect; int tls_disconnect;
@ -495,8 +495,8 @@ void irc_server_connect(SERVER_REC *server)
if (tls_disconnect) { if (tls_disconnect) {
/* we cannot use it, it is encrypted. force a reconnect */ /* we cannot use it, it is encrypted. force a reconnect */
g_io_channel_unref(conn->connect_handle); g_io_channel_unref(conn->connect_channel);
conn->connect_handle = NULL; conn->connect_channel = NULL;
server->session_reconnect = FALSE; server->session_reconnect = FALSE;
server_connect_ref((SERVER_CONNECT_REC *) conn); server_connect_ref((SERVER_CONNECT_REC *) conn);
server_disconnect(server); server_disconnect(server);
@ -695,23 +695,24 @@ void irc_server_send_away(IRC_SERVER_REC *server, const char *reason)
void irc_server_send_data(IRC_SERVER_REC *server, const char *data, int len) void irc_server_send_data(IRC_SERVER_REC *server, const char *data, int len)
{ {
if (net_sendbuffer_send(server->handle, data, len) == -1) { if (server->handle != NULL) {
/* something bad happened */ if (net_sendbuffer_send(server->handle, data, len) == -1) {
server->connection_lost = TRUE; /* something bad happened */
return; server->connection_lost = TRUE;
} return;
}
server->last_cmd = g_get_real_time();
server->last_cmd = g_get_real_time(); /* A bit kludgy way to do the flood protection. In ircnet, there
actually is 1sec / 100 bytes penalty, but we rather want to deal
/* A bit kludgy way to do the flood protection. In ircnet, there with the max. 1000 bytes input buffer problem. If we send more
actually is 1sec / 100 bytes penalty, but we rather want to deal than that with the burst, we'll get excess flooded. */
with the max. 1000 bytes input buffer problem. If we send more if (len < 100 || server->cmd_queue_speed <= 10)
than that with the burst, we'll get excess flooded. */ server->wait_cmd = 0;
if (len < 100 || server->cmd_queue_speed <= 10) else {
server->wait_cmd = 0; server->wait_cmd = server->last_cmd;
else { server->wait_cmd += (2 + len / 100) * G_USEC_PER_SEC;
server->wait_cmd = server->last_cmd; }
server->wait_cmd += (2 + len / 100) * G_USEC_PER_SEC;
} }
} }

View file

@ -579,8 +579,10 @@ static void irc_init_server(IRC_SERVER_REC *server)
if (!IS_IRC_SERVER(server)) if (!IS_IRC_SERVER(server))
return; return;
server->readtag = i_input_add(net_sendbuffer_handle(server->handle), I_INPUT_READ, if (server->handle->channel != NULL) {
(GInputFunction) irc_parse_incoming, server); server->readtag = i_input_add(net_sendbuffer_channel(server->handle), I_INPUT_READ,
(GInputFunction) irc_parse_incoming, server);
}
} }
void irc_irc_init(void) void irc_irc_init(void)

View file

@ -337,29 +337,29 @@ void dcc_chat_input(CHAT_DCC_REC *dcc)
static void dcc_chat_listen(CHAT_DCC_REC *dcc) static void dcc_chat_listen(CHAT_DCC_REC *dcc)
{ {
IPADDR ip; IPADDR ip;
GIOChannel *handle; GIOChannel *channel;
int port; int port;
g_return_if_fail(IS_DCC_CHAT(dcc)); g_return_if_fail(IS_DCC_CHAT(dcc));
/* accept connection */ /* accept connection */
handle = net_accept(dcc->handle, &ip, &port); channel = net_accept_channel(dcc->channel, &ip, &port);
if (handle == NULL) if (channel == NULL)
return; return;
/* TODO: add paranoia check - see dcc-files.c */ /* TODO: add paranoia check - see dcc-files.c */
net_disconnect(dcc->handle); net_disconnect_channel(dcc->channel);
g_source_remove(dcc->tagconn); g_source_remove(dcc->tagconn);
dcc->tagconn = -1; dcc->tagconn = -1;
dcc->starttime = time(NULL); dcc->starttime = time(NULL);
dcc->handle = handle; dcc->channel = channel;
dcc->sendbuf = net_sendbuffer_create(handle, 0); dcc->sendbuf = net_sendbuffer_create_channel(channel, 0);
memcpy(&dcc->addr, &ip, sizeof(IPADDR)); memcpy(&dcc->addr, &ip, sizeof(IPADDR));
net_ip2host(&dcc->addr, dcc->addrstr); net_ip2host(&dcc->addr, dcc->addrstr);
dcc->port = port; dcc->port = port;
dcc->tagread = i_input_add(handle, I_INPUT_READ, (GInputFunction) dcc_chat_input, dcc); dcc->tagread = i_input_add(channel, I_INPUT_READ, (GInputFunction) dcc_chat_input, dcc);
signal_emit("dcc connected", 1, dcc); signal_emit("dcc connected", 1, dcc);
} }
@ -369,7 +369,7 @@ static void sig_chat_connected(CHAT_DCC_REC *dcc)
{ {
g_return_if_fail(IS_DCC_CHAT(dcc)); g_return_if_fail(IS_DCC_CHAT(dcc));
if (net_geterror(dcc->handle) != 0) { if (net_geterror_channel(dcc->channel) != 0) {
/* error connecting */ /* error connecting */
signal_emit("dcc error connect", 1, dcc); signal_emit("dcc error connect", 1, dcc);
dcc_destroy(DCC(dcc)); dcc_destroy(DCC(dcc));
@ -381,8 +381,9 @@ static void sig_chat_connected(CHAT_DCC_REC *dcc)
dcc->tagconn = -1; dcc->tagconn = -1;
dcc->starttime = time(NULL); dcc->starttime = time(NULL);
dcc->sendbuf = net_sendbuffer_create(dcc->handle, 0); dcc->sendbuf = net_sendbuffer_create_channel(dcc->channel, 0);
dcc->tagread = i_input_add(dcc->handle, I_INPUT_READ, (GInputFunction) dcc_chat_input, dcc); dcc->tagread =
i_input_add(dcc->channel, I_INPUT_READ, (GInputFunction) dcc_chat_input, dcc);
signal_emit("dcc connected", 1, dcc); signal_emit("dcc connected", 1, dcc);
} }
@ -391,15 +392,14 @@ static void dcc_chat_connect(CHAT_DCC_REC *dcc)
{ {
g_return_if_fail(IS_DCC_CHAT(dcc)); g_return_if_fail(IS_DCC_CHAT(dcc));
if (dcc->addrstr[0] == '\0' || if (dcc->addrstr[0] == '\0' || dcc->starttime != 0 || dcc->channel != NULL) {
dcc->starttime != 0 || dcc->handle != NULL) {
/* already sent a chat request / already chatting */ /* already sent a chat request / already chatting */
return; return;
} }
dcc->handle = dcc_connect_ip(&dcc->addr, dcc->port); dcc->channel = dcc_connect_ip_channel(&dcc->addr, dcc->port);
if (dcc->handle != NULL) { if (dcc->channel != NULL) {
dcc->tagconn = i_input_add(dcc->handle, I_INPUT_WRITE | I_INPUT_READ, dcc->tagconn = i_input_add(dcc->channel, I_INPUT_WRITE | I_INPUT_READ,
(GInputFunction) sig_chat_connected, dcc); (GInputFunction) sig_chat_connected, dcc);
} else { } else {
/* error connecting */ /* error connecting */
@ -412,25 +412,23 @@ static void dcc_chat_passive(CHAT_DCC_REC *dcc)
{ {
IPADDR own_ip; IPADDR own_ip;
int port; int port;
GIOChannel *handle; GIOChannel *channel;
char host[MAX_IP_LEN]; char host[MAX_IP_LEN];
g_return_if_fail(IS_DCC_CHAT(dcc)); g_return_if_fail(IS_DCC_CHAT(dcc));
if (dcc->addrstr[0] == '\0' || if (dcc->addrstr[0] == '\0' || dcc->starttime != 0 || dcc->channel != NULL) {
dcc->starttime != 0 || dcc->handle != NULL) {
/* already sent a chat request / already chatting */ /* already sent a chat request / already chatting */
return; return;
} }
handle = dcc_listen(net_sendbuffer_handle(dcc->server->handle), channel = dcc_listen_channel(net_sendbuffer_channel(dcc->server->handle), &own_ip, &port);
&own_ip, &port); if (channel == NULL)
if (handle == NULL)
cmd_return_error(CMDERR_ERRNO); cmd_return_error(CMDERR_ERRNO);
dcc->handle = handle; dcc->channel = channel;
dcc->tagconn = dcc->tagconn =
i_input_add(dcc->handle, I_INPUT_READ, (GInputFunction) dcc_chat_listen, dcc); i_input_add(dcc->channel, I_INPUT_READ, (GInputFunction) dcc_chat_listen, dcc);
/* Let's send the reply to the other client! */ /* Let's send the reply to the other client! */
dcc_ip2str(&own_ip, host); dcc_ip2str(&own_ip, host);
@ -445,7 +443,7 @@ static void cmd_dcc_chat(const char *data, IRC_SERVER_REC *server)
void *free_arg; void *free_arg;
CHAT_DCC_REC *dcc; CHAT_DCC_REC *dcc;
IPADDR own_ip; IPADDR own_ip;
GIOChannel *handle; GIOChannel *channel;
GHashTable *optlist; GHashTable *optlist;
int p_id; int p_id;
char *nick, host[MAX_IP_LEN]; char *nick, host[MAX_IP_LEN];
@ -470,7 +468,7 @@ static void cmd_dcc_chat(const char *data, IRC_SERVER_REC *server)
} }
dcc = dcc_chat_find_id(nick); dcc = dcc_chat_find_id(nick);
if (dcc != NULL && dcc_is_waiting_user(dcc)) { if (dcc != NULL && dcc_is_waiting_user_channel(dcc)) {
if (!dcc_is_passive(dcc)) { if (!dcc_is_passive(dcc)) {
/* found from dcc chat requests, /* found from dcc chat requests,
we're the connecting side */ we're the connecting side */
@ -483,8 +481,7 @@ static void cmd_dcc_chat(const char *data, IRC_SERVER_REC *server)
return; return;
} }
if (dcc != NULL && dcc_is_listening(dcc) && if (dcc != NULL && dcc_is_listening_channel(dcc) && dcc->server == server) {
dcc->server == server) {
/* sending request again even while old request is /* sending request again even while old request is
still waiting, remove it. */ still waiting, remove it. */
dcc_destroy(DCC(dcc)); dcc_destroy(DCC(dcc));
@ -502,14 +499,14 @@ static void cmd_dcc_chat(const char *data, IRC_SERVER_REC *server)
if (g_hash_table_lookup(optlist, "passive") == NULL) { if (g_hash_table_lookup(optlist, "passive") == NULL) {
/* Standard DCC CHAT... let's listen for incoming connections */ /* Standard DCC CHAT... let's listen for incoming connections */
handle = dcc_listen(net_sendbuffer_handle(server->handle), channel =
&own_ip, &port); dcc_listen_channel(net_sendbuffer_channel(server->handle), &own_ip, &port);
if (handle == NULL) if (channel == NULL)
cmd_param_error(CMDERR_ERRNO); cmd_param_error(CMDERR_ERRNO);
dcc->handle = handle; dcc->channel = channel;
dcc->tagconn = dcc->tagconn =
i_input_add(dcc->handle, I_INPUT_READ, (GInputFunction) dcc_chat_listen, dcc); i_input_add(dcc->channel, I_INPUT_READ, (GInputFunction) dcc_chat_listen, dcc);
/* send the chat request */ /* send the chat request */
signal_emit("dcc request send", 1, dcc); signal_emit("dcc request send", 1, dcc);
@ -645,7 +642,7 @@ static void ctcp_msg_dcc_chat(IRC_SERVER_REC *server, const char *data,
dcc = DCC_CHAT(dcc_find_request(DCC_CHAT_TYPE, nick, NULL)); dcc = DCC_CHAT(dcc_find_request(DCC_CHAT_TYPE, nick, NULL));
if (dcc != NULL) { if (dcc != NULL) {
if (dcc_is_listening(dcc)) { if (dcc_is_listening_channel(dcc)) {
/* we requested dcc chat, they requested /* we requested dcc chat, they requested
dcc chat from us .. allow it. */ dcc chat from us .. allow it. */
dcc_destroy(DCC(dcc)); dcc_destroy(DCC(dcc));

View file

@ -102,8 +102,7 @@ void dcc_get_send_received(GET_DCC_REC *dcc)
memcpy(dcc->count_buf, &recd, 4); memcpy(dcc->count_buf, &recd, 4);
dcc->count_pos = dcc->count_pos =
net_transmit(dcc->handle, dcc->count_buf+dcc->count_pos, net_transmit_channel(dcc->channel, dcc->count_buf + dcc->count_pos, 4 - dcc->count_pos);
4-dcc->count_pos);
if (dcc->count_pos == 4) dcc->count_pos = 0; if (dcc->count_pos == 4) dcc->count_pos = 0;
/* count_pos might be -1 here. if this happens, the /* count_pos might be -1 here. if this happens, the
@ -112,7 +111,7 @@ void dcc_get_send_received(GET_DCC_REC *dcc)
never, but I just want to do it right.. :) */ never, but I just want to do it right.. :) */
if (dcc->tagwrite == -1) { if (dcc->tagwrite == -1) {
dcc->tagwrite = dcc->tagwrite =
i_input_add(dcc->handle, I_INPUT_WRITE, (GInputFunction) sig_dccget_send, dcc); i_input_add(dcc->channel, I_INPUT_WRITE, (GInputFunction) sig_dccget_send, dcc);
} }
} }
@ -123,8 +122,8 @@ static void sig_dccget_send(GET_DCC_REC *dcc)
int ret; int ret;
if (dcc->count_pos != 0) { if (dcc->count_pos != 0) {
ret = net_transmit(dcc->handle, dcc->count_buf+dcc->count_pos, ret = net_transmit_channel(dcc->channel, dcc->count_buf + dcc->count_pos,
4-dcc->count_pos); 4 - dcc->count_pos);
if (dcc->count_pos <= 0) if (dcc->count_pos <= 0)
dcc->count_pos = ret; dcc->count_pos = ret;
@ -157,8 +156,8 @@ static void sig_dccget_receive(GET_DCC_REC *dcc)
} }
for (;;) { for (;;) {
ret = net_receive(dcc->handle, dcc_get_recv_buffer, ret = net_receive_channel(dcc->channel, dcc_get_recv_buffer,
DCC_GET_RECV_BUFFER_SIZE); DCC_GET_RECV_BUFFER_SIZE);
if (ret == 0) break; if (ret == 0) break;
if (ret < 0) { if (ret < 0) {
@ -194,7 +193,7 @@ void sig_dccget_connected(GET_DCC_REC *dcc)
int ret, ret_errno, temphandle, old_umask; int ret, ret_errno, temphandle, old_umask;
if (!dcc->from_dccserver) { if (!dcc->from_dccserver) {
if (net_geterror(dcc->handle) != 0) { if (net_geterror_channel(dcc->channel) != 0) {
/* error connecting */ /* error connecting */
signal_emit("dcc error connect", 1, dcc); signal_emit("dcc error connect", 1, dcc);
dcc_destroy(DCC(dcc)); dcc_destroy(DCC(dcc));
@ -285,13 +284,13 @@ void sig_dccget_connected(GET_DCC_REC *dcc)
return; return;
} }
dcc->tagread = dcc->tagread =
i_input_add(dcc->handle, I_INPUT_READ, (GInputFunction) sig_dccget_receive, dcc); i_input_add(dcc->channel, I_INPUT_READ, (GInputFunction) sig_dccget_receive, dcc);
signal_emit("dcc connected", 1, dcc); signal_emit("dcc connected", 1, dcc);
if (dcc->from_dccserver) { if (dcc->from_dccserver) {
str = g_strdup_printf("121 %s %d\n", str = g_strdup_printf("121 %s %d\n",
dcc->server ? dcc->server->nick : "??", 0); dcc->server ? dcc->server->nick : "??", 0);
net_transmit(dcc->handle, str, strlen(str)); net_transmit_channel(dcc->channel, str, strlen(str));
} }
} }
@ -307,10 +306,10 @@ void dcc_get_connect(GET_DCC_REC *dcc)
return; return;
} }
dcc->handle = dcc_connect_ip(&dcc->addr, dcc->port); dcc->channel = dcc_connect_ip_channel(&dcc->addr, dcc->port);
if (dcc->handle != NULL) { if (dcc->channel != NULL) {
dcc->tagconn = i_input_add(dcc->handle, I_INPUT_WRITE | I_INPUT_READ, dcc->tagconn = i_input_add(dcc->channel, I_INPUT_WRITE | I_INPUT_READ,
(GInputFunction) sig_dccget_connected, dcc); (GInputFunction) sig_dccget_connected, dcc);
} else { } else {
/* error connecting */ /* error connecting */
@ -321,43 +320,43 @@ void dcc_get_connect(GET_DCC_REC *dcc)
static void dcc_get_listen(GET_DCC_REC *dcc) static void dcc_get_listen(GET_DCC_REC *dcc)
{ {
GIOChannel *handle; GIOChannel *channel;
IPADDR addr; IPADDR addr;
int port; int port;
/* accept connection */ /* accept connection */
handle = net_accept(dcc->handle, &addr, &port); channel = net_accept_channel(dcc->channel, &addr, &port);
if (handle == NULL) if (channel == NULL)
return; return;
net_disconnect(dcc->handle); net_disconnect_channel(dcc->channel);
g_source_remove(dcc->tagconn); g_source_remove(dcc->tagconn);
dcc->tagconn = -1; dcc->tagconn = -1;
dcc->starttime = time(NULL); dcc->starttime = time(NULL);
dcc->handle = handle; dcc->channel = channel;
memcpy(&dcc->addr, &addr, sizeof(IPADDR)); memcpy(&dcc->addr, &addr, sizeof(IPADDR));
net_ip2host(&dcc->addr, dcc->addrstr); net_ip2host(&dcc->addr, dcc->addrstr);
dcc->port = port; dcc->port = port;
dcc->tagconn = i_input_add(handle, I_INPUT_READ | I_INPUT_WRITE, dcc->tagconn = i_input_add(channel, I_INPUT_READ | I_INPUT_WRITE,
(GInputFunction) sig_dccget_connected, dcc); (GInputFunction) sig_dccget_connected, dcc);
} }
void dcc_get_passive(GET_DCC_REC *dcc) void dcc_get_passive(GET_DCC_REC *dcc)
{ {
GIOChannel *handle; GIOChannel *channel;
IPADDR own_ip; IPADDR own_ip;
int port; int port;
char host[MAX_IP_LEN]; char host[MAX_IP_LEN];
handle = dcc_listen(net_sendbuffer_handle(dcc->server->handle), channel = dcc_listen_channel(net_sendbuffer_channel(dcc->server->handle), &own_ip, &port);
&own_ip, &port); if (channel == NULL)
if (handle == NULL)
cmd_return_error(CMDERR_ERRNO); cmd_return_error(CMDERR_ERRNO);
dcc->handle = handle; dcc->channel = channel;
dcc->tagconn = i_input_add(dcc->handle, I_INPUT_READ, (GInputFunction) dcc_get_listen, dcc); dcc->tagconn =
i_input_add(dcc->channel, I_INPUT_READ, (GInputFunction) dcc_get_listen, dcc);
/* Let's send the reply to the other client! */ /* Let's send the reply to the other client! */
dcc_ip2str(&own_ip, host); dcc_ip2str(&own_ip, host);
@ -581,7 +580,7 @@ void cmd_dcc_receive(const char *data, DCC_GET_FUNC accept_func,
next = tmp->next; next = tmp->next;
if (IS_DCC_GET(dcc) && g_ascii_strcasecmp(dcc->nick, nick) == 0 && if (IS_DCC_GET(dcc) && g_ascii_strcasecmp(dcc->nick, nick) == 0 &&
(dcc_is_waiting_user(dcc) || dcc->from_dccserver) && (dcc_is_waiting_user_channel(dcc) || dcc->from_dccserver) &&
(*fname == '\0' || g_strcmp0(dcc->arg, fname) == 0)) { (*fname == '\0' || g_strcmp0(dcc->arg, fname) == 0)) {
found = TRUE; found = TRUE;
if (!dcc_is_passive(dcc)) if (!dcc_is_passive(dcc))

View file

@ -15,7 +15,7 @@ IPADDR addr; /* address we're connected in */
char addrstr[MAX_IP_LEN]; /* in readable form */ char addrstr[MAX_IP_LEN]; /* in readable form */
int port; /* port we're connected in */ int port; /* port we're connected in */
GIOChannel *handle; /* socket handle */ GIOChannel *channel; /* socket handle */
int tagconn, tagread, tagwrite; int tagconn, tagread, tagwrite;
time_t starttime; /* transfer start time */ time_t starttime; /* transfer start time */
uoff_t transfd; /* bytes transferred */ uoff_t transfd; /* bytes transferred */

View file

@ -272,7 +272,7 @@ static void dcc_send_data(SEND_DCC_REC *dcc)
return; return;
} }
ret = net_transmit(dcc->handle, buffer, ret); ret = net_transmit_channel(dcc->channel, buffer, ret);
if (ret > 0) dcc->transfd += ret; if (ret > 0) dcc->transfd += ret;
dcc->gotalldata = FALSE; dcc->gotalldata = FALSE;
@ -287,8 +287,8 @@ static void dcc_send_read_size(SEND_DCC_REC *dcc)
guint32 bytes; guint32 bytes;
int ret; int ret;
ret = net_receive(dcc->handle, dcc->count_buf+dcc->count_pos, ret =
4-dcc->count_pos); net_receive_channel(dcc->channel, dcc->count_buf + dcc->count_pos, 4 - dcc->count_pos);
if (ret == -1) { if (ret == -1) {
dcc_close(DCC(dcc)); dcc_close(DCC(dcc));
return; return;
@ -313,31 +313,31 @@ static void dcc_send_read_size(SEND_DCC_REC *dcc)
/* input function: DCC SEND - someone tried to connect to our socket */ /* input function: DCC SEND - someone tried to connect to our socket */
static void dcc_send_connected(SEND_DCC_REC *dcc) static void dcc_send_connected(SEND_DCC_REC *dcc)
{ {
GIOChannel *handle; GIOChannel *channel;
IPADDR addr; IPADDR addr;
int port; int port;
/* accept connection */ /* accept connection */
handle = net_accept(dcc->handle, &addr, &port); channel = net_accept_channel(dcc->channel, &addr, &port);
if (handle == NULL) if (channel == NULL)
return; return;
/* TODO: some kind of paranoia check would be nice. it would check /* TODO: some kind of paranoia check would be nice. it would check
that the host of the nick who we sent the request matches the that the host of the nick who we sent the request matches the
address who connected us. */ address who connected us. */
net_disconnect(dcc->handle); net_disconnect_channel(dcc->channel);
g_source_remove(dcc->tagconn); g_source_remove(dcc->tagconn);
dcc->tagconn = -1; dcc->tagconn = -1;
dcc->starttime = time(NULL); dcc->starttime = time(NULL);
dcc->handle = handle; dcc->channel = channel;
memcpy(&dcc->addr, &addr, sizeof(IPADDR)); memcpy(&dcc->addr, &addr, sizeof(IPADDR));
net_ip2host(&dcc->addr, dcc->addrstr); net_ip2host(&dcc->addr, dcc->addrstr);
dcc->port = port; dcc->port = port;
dcc->tagread = i_input_add(handle, I_INPUT_READ, (GInputFunction) dcc_send_read_size, dcc); dcc->tagread = i_input_add(channel, I_INPUT_READ, (GInputFunction) dcc_send_read_size, dcc);
dcc->tagwrite = i_input_add(handle, I_INPUT_WRITE, (GInputFunction) dcc_send_data, dcc); dcc->tagwrite = i_input_add(channel, I_INPUT_WRITE, (GInputFunction) dcc_send_data, dcc);
signal_emit("dcc connected", 1, dcc); signal_emit("dcc connected", 1, dcc);
} }
@ -345,15 +345,15 @@ static void dcc_send_connected(SEND_DCC_REC *dcc)
/* input function: DCC SEND - connect to the receiver (passive protocol) */ /* input function: DCC SEND - connect to the receiver (passive protocol) */
static void dcc_send_connect(SEND_DCC_REC *dcc) static void dcc_send_connect(SEND_DCC_REC *dcc)
{ {
dcc->handle = dcc_connect_ip(&dcc->addr, dcc->port); dcc->channel = dcc_connect_ip_channel(&dcc->addr, dcc->port);
if (dcc->handle != NULL) { if (dcc->channel != NULL) {
dcc->starttime = time(NULL); dcc->starttime = time(NULL);
dcc->tagread = i_input_add(dcc->handle, I_INPUT_READ, dcc->tagread = i_input_add(dcc->channel, I_INPUT_READ,
(GInputFunction) dcc_send_read_size, dcc); (GInputFunction) dcc_send_read_size, dcc);
dcc->tagwrite = dcc->tagwrite =
i_input_add(dcc->handle, I_INPUT_WRITE, (GInputFunction) dcc_send_data, dcc); i_input_add(dcc->channel, I_INPUT_WRITE, (GInputFunction) dcc_send_data, dcc);
signal_emit("dcc connected", 1, dcc); signal_emit("dcc connected", 1, dcc);
} else { } else {
/* error connecting */ /* error connecting */
@ -372,7 +372,7 @@ static int dcc_send_one_file(int queue, const char *target, const char *fname,
int hfile, port = 0; int hfile, port = 0;
SEND_DCC_REC *dcc; SEND_DCC_REC *dcc;
IPADDR own_ip; IPADDR own_ip;
GIOChannel *handle; GIOChannel *channel;
if (dcc_find_request(DCC_SEND_TYPE, target, fname)) { if (dcc_find_request(DCC_SEND_TYPE, target, fname)) {
signal_emit("dcc error send exists", 2, target, fname); signal_emit("dcc error send exists", 2, target, fname);
@ -398,16 +398,16 @@ static int dcc_send_one_file(int queue, const char *target, const char *fname,
/* start listening (only if passive == FALSE )*/ /* start listening (only if passive == FALSE )*/
if (passive == FALSE) { if (passive == FALSE) {
handle = dcc_listen(chat != NULL ? chat->handle : channel = dcc_listen_channel(chat != NULL ? chat->channel :
net_sendbuffer_handle(server->handle), net_sendbuffer_channel(server->handle),
&own_ip, &port); &own_ip, &port);
if (handle == NULL) { if (channel == NULL) {
close(hfile); close(hfile);
g_warning("dcc_listen() failed: %s", strerror(errno)); g_warning("dcc_listen() failed: %s", strerror(errno));
return FALSE; return FALSE;
} }
} else { } else {
handle = NULL; channel = NULL;
} }
str = g_path_get_basename(fname); str = g_path_get_basename(fname);
@ -425,7 +425,7 @@ static int dcc_send_one_file(int queue, const char *target, const char *fname,
return FALSE; return FALSE;
} }
dcc->handle = handle; dcc->channel = channel;
dcc->port = port; dcc->port = port;
dcc->size = st.st_size; dcc->size = st.st_size;
dcc->fhandle = hfile; dcc->fhandle = hfile;
@ -433,7 +433,7 @@ static int dcc_send_one_file(int queue, const char *target, const char *fname,
dcc->file_quoted = strchr(fname, ' ') != NULL; dcc->file_quoted = strchr(fname, ' ') != NULL;
if (!passive) { if (!passive) {
dcc->tagconn = dcc->tagconn =
i_input_add(handle, I_INPUT_READ, (GInputFunction) dcc_send_connected, dcc); i_input_add(channel, I_INPUT_READ, (GInputFunction) dcc_send_connected, dcc);
} }
/* Generate an ID for this send if using passive protocol */ /* Generate an ID for this send if using passive protocol */

View file

@ -49,15 +49,15 @@ static void sig_dcc_destroyed(SERVER_DCC_REC *dcc)
} }
/* Start listening for incoming connections */ /* Start listening for incoming connections */
static GIOChannel *dcc_listen_port(GIOChannel *iface, IPADDR *ip, int port) static GIOChannel *dcc_listen_port_channel(GIOChannel *iface, IPADDR *ip, int port)
{ {
if (net_getsockname(iface, ip, NULL) == -1) if (net_getsockname_channel(iface, ip, NULL) == -1)
return NULL; return NULL;
if (IPADDR_IS_V6(ip)) if (IPADDR_IS_V6(ip))
return net_listen(NULL, &port); return net_listen_channel(NULL, &port);
else else
return net_listen(&ip4_any, &port); return net_listen_channel(&ip4_any, &port);
} }
/* input function: DCC SERVER received some data.. */ /* input function: DCC SERVER received some data.. */
@ -85,7 +85,7 @@ static void dcc_server_input(SERVER_DCC_REC *dcc)
if (dcc->connection_established) { if (dcc->connection_established) {
/* We set handle to NULL first because the new (chat/get) is using the same */ /* We set handle to NULL first because the new (chat/get) is using the same */
/* handle and we don't want dcc_close to disconnect it.*/ /* handle and we don't want dcc_close to disconnect it.*/
dcc->handle = NULL; dcc->channel = NULL;
dcc_close(DCC(dcc)); dcc_close(DCC(dcc));
break; break;
} }
@ -164,27 +164,27 @@ static void dcc_server_listen(SERVER_DCC_REC *dcc)
{ {
SERVER_DCC_REC *newdcc; SERVER_DCC_REC *newdcc;
IPADDR ip; IPADDR ip;
GIOChannel *handle; GIOChannel *channel;
int port; int port;
g_return_if_fail(IS_DCC_SERVER(dcc)); g_return_if_fail(IS_DCC_SERVER(dcc));
/* accept connection */ /* accept connection */
handle = net_accept(dcc->handle, &ip, &port); channel = net_accept_channel(dcc->channel, &ip, &port);
if (handle == NULL) if (channel == NULL)
return; return;
/* Create a new DCC SERVER to handle this connection */ /* Create a new DCC SERVER to handle this connection */
newdcc = dcc_server_clone(dcc); newdcc = dcc_server_clone(dcc);
newdcc->starttime = time(NULL); newdcc->starttime = time(NULL);
newdcc->handle = handle; newdcc->channel = channel;
newdcc->sendbuf = net_sendbuffer_create(handle, 0); newdcc->sendbuf = net_sendbuffer_create_channel(channel, 0);
memcpy(&newdcc->addr, &ip, sizeof(IPADDR)); memcpy(&newdcc->addr, &ip, sizeof(IPADDR));
net_ip2host(&newdcc->addr, newdcc->addrstr); net_ip2host(&newdcc->addr, newdcc->addrstr);
newdcc->port = port; newdcc->port = port;
newdcc->tagread = newdcc->tagread =
i_input_add(handle, I_INPUT_READ, (GInputFunction) dcc_server_input, newdcc); i_input_add(channel, I_INPUT_READ, (GInputFunction) dcc_server_input, newdcc);
signal_emit("dcc connected", 1, newdcc); signal_emit("dcc connected", 1, newdcc);
} }
@ -205,12 +205,12 @@ static void dcc_server_msg(SERVER_DCC_REC *dcc, const char *msg)
CHAT_DCC_REC *dccchat = dcc_chat_create(dcc->server, NULL, msg, "chat"); CHAT_DCC_REC *dccchat = dcc_chat_create(dcc->server, NULL, msg, "chat");
dccchat->starttime = time(NULL); dccchat->starttime = time(NULL);
dccchat->handle = dcc->handle; dccchat->channel = dcc->channel;
dccchat->sendbuf = net_sendbuffer_create(dccchat->handle, 0); dccchat->sendbuf = net_sendbuffer_create_channel(dccchat->channel, 0);
memcpy(&dccchat->addr, &dcc->addr, sizeof(IPADDR)); memcpy(&dccchat->addr, &dcc->addr, sizeof(IPADDR));
net_ip2host(&dccchat->addr, dccchat->addrstr); net_ip2host(&dccchat->addr, dccchat->addrstr);
dccchat->port = dcc->port; dccchat->port = dcc->port;
dccchat->tagread = i_input_add(dccchat->handle, I_INPUT_READ, dccchat->tagread = i_input_add(dccchat->channel, I_INPUT_READ,
(GInputFunction) dcc_chat_input, dccchat); (GInputFunction) dcc_chat_input, dccchat);
dcc->connection_established = 1; dcc->connection_established = 1;
@ -266,7 +266,7 @@ static void dcc_server_msg(SERVER_DCC_REC *dcc, const char *msg)
} }
dccget = dcc_get_create(dcc->server, NULL, nick, fname); dccget = dcc_get_create(dcc->server, NULL, nick, fname);
dccget->handle = dcc->handle; dccget->channel = dcc->channel;
dccget->target = g_strdup(dcc->server ? dcc->server->nick : "??"); dccget->target = g_strdup(dcc->server ? dcc->server->nick : "??");
memcpy(&dccget->addr, &dcc->addr, sizeof(dcc->addr)); memcpy(&dccget->addr, &dcc->addr, sizeof(dcc->addr));
if (dccget->addr.family == AF_INET) { if (dccget->addr.family == AF_INET) {
@ -314,7 +314,7 @@ SERVER_DCC_REC *dcc_server_find_port(const char *port_str)
static void cmd_dcc_server(const char *data, IRC_SERVER_REC *server) static void cmd_dcc_server(const char *data, IRC_SERVER_REC *server)
{ {
void *free_arg; void *free_arg;
GIOChannel *handle; GIOChannel *channel;
SERVER_DCC_REC *dcc; SERVER_DCC_REC *dcc;
IPADDR own_ip; IPADDR own_ip;
char *flags, *port; char *flags, *port;
@ -337,18 +337,18 @@ static void cmd_dcc_server(const char *data, IRC_SERVER_REC *server)
cmd_param_error(CMDERR_NOT_CONNECTED); cmd_param_error(CMDERR_NOT_CONNECTED);
} }
handle = dcc_listen_port(net_sendbuffer_handle(server->handle), channel =
&own_ip, atoi(port)); dcc_listen_port_channel(net_sendbuffer_channel(server->handle), &own_ip, atoi(port));
if (handle == NULL) { if (channel == NULL) {
cmd_param_error(CMDERR_ERRNO); cmd_param_error(CMDERR_ERRNO);
} }
dcc = dcc_server_create(server, flags); dcc = dcc_server_create(server, flags);
dcc->handle = handle; dcc->channel = channel;
dcc->port = atoi(port); dcc->port = atoi(port);
dcc->tagconn = dcc->tagconn =
i_input_add(dcc->handle, I_INPUT_READ, (GInputFunction) dcc_server_listen, dcc); i_input_add(dcc->channel, I_INPUT_READ, (GInputFunction) dcc_server_listen, dcc);
signal_emit("dcc server started", 1, dcc); signal_emit("dcc server started", 1, dcc);

View file

@ -109,7 +109,8 @@ void dcc_destroy(DCC_REC *dcc)
dcc->destroyed = TRUE; dcc->destroyed = TRUE;
signal_emit("dcc destroyed", 1, dcc); signal_emit("dcc destroyed", 1, dcc);
if (dcc->handle != NULL) net_disconnect(dcc->handle); if (dcc->channel != NULL)
net_disconnect_channel(dcc->channel);
if (dcc->tagconn != -1) g_source_remove(dcc->tagconn); if (dcc->tagconn != -1) g_source_remove(dcc->tagconn);
if (dcc->tagread != -1) g_source_remove(dcc->tagread); if (dcc->tagread != -1) g_source_remove(dcc->tagread);
if (dcc->tagwrite != -1) g_source_remove(dcc->tagwrite); if (dcc->tagwrite != -1) g_source_remove(dcc->tagwrite);
@ -132,7 +133,7 @@ DCC_REC *dcc_find_request_latest(int type)
for (tmp = dcc_conns; tmp != NULL; tmp = tmp->next) { for (tmp = dcc_conns; tmp != NULL; tmp = tmp->next) {
DCC_REC *dcc = tmp->data; DCC_REC *dcc = tmp->data;
if (dcc->type == type && dcc_is_waiting_user(dcc)) if (dcc->type == type && dcc_is_waiting_user_channel(dcc))
latest = dcc; latest = dcc;
} }
@ -195,14 +196,14 @@ void dcc_str2ip(const char *str, IPADDR *ip)
} }
/* Start listening for incoming connections */ /* Start listening for incoming connections */
GIOChannel *dcc_listen(GIOChannel *iface, IPADDR *ip, int *port) GIOChannel *dcc_listen_channel(GIOChannel *iface, IPADDR *ip, int *port)
{ {
GIOChannel *handle; GIOChannel *channel;
IPADDR *listen_ip = NULL; IPADDR *listen_ip = NULL;
const char *dcc_port, *p, *own_ip; const char *dcc_port, *p, *own_ip;
int first, last; int first, last;
if (net_getsockname(iface, ip, NULL) == -1) if (net_getsockname_channel(iface, ip, NULL) == -1)
return NULL; return NULL;
/* figure out if we want to listen in IPv4 address or in "any" address, /* figure out if we want to listen in IPv4 address or in "any" address,
@ -222,7 +223,7 @@ GIOChannel *dcc_listen(GIOChannel *iface, IPADDR *ip, int *port)
if (first == 0) { if (first == 0) {
/* random port */ /* random port */
*port = 0; *port = 0;
return net_listen(listen_ip, port); return net_listen_channel(listen_ip, port);
} }
/* get last port */ /* get last port */
@ -240,20 +241,20 @@ GIOChannel *dcc_listen(GIOChannel *iface, IPADDR *ip, int *port)
/* use the first available port */ /* use the first available port */
for (*port = first; *port <= last; (*port)++) { for (*port = first; *port <= last; (*port)++) {
handle = net_listen(listen_ip, port); channel = net_listen_channel(listen_ip, port);
if (handle != NULL) if (channel != NULL)
return handle; return channel;
} }
return NULL; return NULL;
} }
/* Connect to specified IP address using the correct own_ip. */ /* Connect to specified IP address using the correct own_ip. */
GIOChannel *dcc_connect_ip(IPADDR *ip, int port) GIOChannel *dcc_connect_ip_channel(IPADDR *ip, int port)
{ {
IPADDR *own_ip, temp_ip; IPADDR *own_ip, temp_ip;
const char *own_ip_str; const char *own_ip_str;
GIOChannel *handle; GIOChannel *channel;
own_ip_str = settings_get_str("dcc_own_ip"); own_ip_str = settings_get_str("dcc_own_ip");
own_ip = NULL; own_ip = NULL;
@ -267,13 +268,13 @@ GIOChannel *dcc_connect_ip(IPADDR *ip, int port)
if (own_ip == NULL) if (own_ip == NULL)
own_ip = IPADDR_IS_V6(ip) ? source_host_ip6 : source_host_ip4; own_ip = IPADDR_IS_V6(ip) ? source_host_ip6 : source_host_ip4;
handle = net_connect_ip(ip, port, own_ip); channel = net_connect_ip_channel(ip, port, own_ip);
if (handle == NULL && errno == EADDRNOTAVAIL && own_ip != NULL) { if (channel == NULL && errno == EADDRNOTAVAIL && own_ip != NULL) {
/* dcc_own_ip is external address */ /* dcc_own_ip is external address */
own_ip = IPADDR_IS_V6(ip) ? source_host_ip6 : source_host_ip4; own_ip = IPADDR_IS_V6(ip) ? source_host_ip6 : source_host_ip4;
handle = net_connect_ip(ip, port, own_ip); channel = net_connect_ip_channel(ip, port, own_ip);
} }
return handle; return channel;
} }
/* Server connected - update server for DCC records that have /* Server connected - update server for DCC records that have

View file

@ -17,12 +17,10 @@ typedef struct {
((dcc)->starttime != 0) ((dcc)->starttime != 0)
/* not connected, we're waiting for other side to connect */ /* not connected, we're waiting for other side to connect */
#define dcc_is_listening(dcc) \ #define dcc_is_listening_channel(dcc) ((dcc)->channel != NULL && (dcc)->starttime == 0)
((dcc)->handle != NULL && (dcc)->starttime == 0)
/* not connected, waiting for user to accept it */ /* not connected, waiting for user to accept it */
#define dcc_is_waiting_user(dcc) \ #define dcc_is_waiting_user_channel(dcc) ((dcc)->channel == NULL)
((dcc)->handle == NULL)
/* passive DCC */ /* passive DCC */
#define dcc_is_passive(dcc) \ #define dcc_is_passive(dcc) \
@ -52,9 +50,9 @@ void dcc_ip2str(IPADDR *ip, char *str);
void dcc_str2ip(const char *str, IPADDR *ip); void dcc_str2ip(const char *str, IPADDR *ip);
/* Start listening for incoming connections */ /* Start listening for incoming connections */
GIOChannel *dcc_listen(GIOChannel *iface, IPADDR *ip, int *port); GIOChannel *dcc_listen_channel(GIOChannel *iface, IPADDR *ip, int *port);
/* Connect to specified IP address using the correct own_ip. */ /* Connect to specified IP address using the correct own_ip. */
GIOChannel *dcc_connect_ip(IPADDR *ip, int port); GIOChannel *dcc_connect_ip_channel(IPADDR *ip, int port);
/* Close DCC - sends "dcc closed" signal and calls dcc_destroy() */ /* Close DCC - sends "dcc closed" signal and calls dcc_destroy() */
void dcc_close(DCC_REC *dcc); void dcc_close(DCC_REC *dcc);

View file

@ -47,7 +47,7 @@ static int is_all_digits(const char *s)
return strspn(s, "0123456789") == strlen(s); return strspn(s, "0123456789") == strlen(s);
} }
static GIOChannel *net_listen_unix(const char *path) static GIOChannel *net_listen_unix_channel(const char *path)
{ {
struct sockaddr_un sa; struct sockaddr_un sa;
int saved_errno, handle; int saved_errno, handle;
@ -84,16 +84,16 @@ error_close:
return NULL; return NULL;
} }
static GIOChannel *net_accept_unix(GIOChannel *handle) static GIOChannel *net_accept_unix_channel(GIOChannel *channel)
{ {
struct sockaddr_un sa; struct sockaddr_un sa;
int ret; int ret;
socklen_t addrlen; socklen_t addrlen;
g_return_val_if_fail(handle != NULL, NULL); g_return_val_if_fail(channel != NULL, NULL);
addrlen = sizeof sa; addrlen = sizeof sa;
ret = accept(g_io_channel_unix_get_fd(handle), (struct sockaddr *)&sa, &addrlen); ret = accept(g_io_channel_unix_get_fd(channel), (struct sockaddr *) &sa, &addrlen);
if (ret < 0) if (ret < 0)
return NULL; return NULL;
@ -431,7 +431,7 @@ static void sig_listen(LISTEN_REC *listen)
CLIENT_REC *rec; CLIENT_REC *rec;
IPADDR ip; IPADDR ip;
NET_SENDBUF_REC *sendbuf; NET_SENDBUF_REC *sendbuf;
GIOChannel *handle; GIOChannel *channel;
char host[MAX_IP_LEN]; char host[MAX_IP_LEN];
int port; int port;
char *addr; char *addr;
@ -440,20 +440,20 @@ static void sig_listen(LISTEN_REC *listen)
/* accept connection */ /* accept connection */
if (listen->port) { if (listen->port) {
handle = net_accept(listen->handle, &ip, &port); channel = net_accept_channel(listen->channel, &ip, &port);
if (handle == NULL) if (channel == NULL)
return; return;
net_ip2host(&ip, host); net_ip2host(&ip, host);
addr = g_strdup_printf("%s:%d", host, port); addr = g_strdup_printf("%s:%d", host, port);
} else { } else {
/* no port => this is a unix socket */ /* no port => this is a unix socket */
handle = net_accept_unix(listen->handle); channel = net_accept_unix_channel(listen->channel);
if (handle == NULL) if (channel == NULL)
return; return;
addr = g_strdup("(local)"); addr = g_strdup("(local)");
} }
sendbuf = net_sendbuffer_create(handle, 0); sendbuf = net_sendbuffer_create_channel(channel, 0);
rec = g_new0(CLIENT_REC, 1); rec = g_new0(CLIENT_REC, 1);
rec->listen = listen; rec->listen = listen;
rec->handle = sendbuf; rec->handle = sendbuf;
@ -470,7 +470,7 @@ static void sig_listen(LISTEN_REC *listen)
rec->server = servers == NULL ? NULL : rec->server = servers == NULL ? NULL :
IRC_SERVER(server_find_chatnet(listen->ircnet)); IRC_SERVER(server_find_chatnet(listen->ircnet));
} }
rec->recv_tag = i_input_add(handle, I_INPUT_READ, (GInputFunction) sig_listen_client, rec); rec->recv_tag = i_input_add(channel, I_INPUT_READ, (GInputFunction) sig_listen_client, rec);
proxy_clients = g_slist_prepend(proxy_clients, rec); proxy_clients = g_slist_prepend(proxy_clients, rec);
listen->clients = g_slist_prepend(listen->clients, rec); listen->clients = g_slist_prepend(listen->clients, rec);
@ -699,14 +699,14 @@ static void add_listen(const char *ircnet, int port, const char *port_or_path)
{ {
LISTEN_REC *rec; LISTEN_REC *rec;
IPADDR ip4, ip6, *my_ip; IPADDR ip4, ip6, *my_ip;
GIOChannel *handle; GIOChannel *channel;
if (*port_or_path == '\0' || port < 0 || *ircnet == '\0') if (*port_or_path == '\0' || port < 0 || *ircnet == '\0')
return; return;
if (port == 0) { if (port == 0) {
/* listening on a unix socket */ /* listening on a unix socket */
handle = net_listen_unix(port_or_path); channel = net_listen_unix_channel(port_or_path);
} else { } else {
/* bind to specific host/ip? */ /* bind to specific host/ip? */
my_ip = NULL; my_ip = NULL;
@ -725,10 +725,10 @@ static void add_listen(const char *ircnet, int port, const char *port_or_path)
&ip6 : &ip6 :
&ip4; &ip4;
} }
handle = net_listen(my_ip, &port); channel = net_listen_channel(my_ip, &port);
} }
if (handle == NULL) { if (channel == NULL) {
printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, printtext(NULL, NULL, MSGLEVEL_CLIENTERROR,
"Proxy: Listen in port %s failed: %s", "Proxy: Listen in port %s failed: %s",
port_or_path, g_strerror(errno)); port_or_path, g_strerror(errno));
@ -736,12 +736,12 @@ static void add_listen(const char *ircnet, int port, const char *port_or_path)
} }
rec = g_new0(LISTEN_REC, 1); rec = g_new0(LISTEN_REC, 1);
rec->handle = handle; rec->channel = channel;
rec->ircnet = g_strdup(ircnet); rec->ircnet = g_strdup(ircnet);
rec->port = port; rec->port = port;
rec->port_or_path = g_strdup(port_or_path); rec->port_or_path = g_strdup(port_or_path);
rec->tag = i_input_add(rec->handle, I_INPUT_READ, (GInputFunction) sig_listen, rec); rec->tag = i_input_add(rec->channel, I_INPUT_READ, (GInputFunction) sig_listen, rec);
proxy_listens = g_slist_append(proxy_listens, rec); proxy_listens = g_slist_append(proxy_listens, rec);
} }
@ -757,7 +757,7 @@ static void remove_listen(LISTEN_REC *rec)
if (rec->port == 0) if (rec->port == 0)
unlink(rec->port_or_path); unlink(rec->port_or_path);
net_disconnect(rec->handle); net_disconnect_channel(rec->channel);
g_source_remove(rec->tag); g_source_remove(rec->tag);
g_free(rec->port_or_path); g_free(rec->port_or_path);
g_free(rec->ircnet); g_free(rec->ircnet);

View file

@ -13,7 +13,7 @@ typedef struct {
char *ircnet; char *ircnet;
int tag; int tag;
GIOChannel *handle; GIOChannel *channel;
GSList *clients; GSList *clients;