mirror of
https://github.com/irssi/irssi.git
synced 2026-08-18 08:02:13 +02:00
Use GIOChannel instead of sockets directly. Helps porting to win32 :)
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@962 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
parent
e81fdd7307
commit
1c9f45b4a4
16 changed files with 223 additions and 202 deletions
|
|
@ -190,19 +190,20 @@ static void dcc_chat_input(DCC_REC *dcc)
|
|||
static void dcc_chat_listen(DCC_REC *dcc)
|
||||
{
|
||||
IPADDR ip;
|
||||
int handle, port;
|
||||
GIOChannel *handle;
|
||||
int port;
|
||||
|
||||
g_return_if_fail(dcc != NULL);
|
||||
|
||||
/* accept connection */
|
||||
handle = net_accept(dcc->handle, &ip, &port);
|
||||
if (handle == -1)
|
||||
if (handle == NULL)
|
||||
return;
|
||||
|
||||
/* TODO: add paranoia check - see dcc-files.c */
|
||||
|
||||
g_source_remove(dcc->tagconn);
|
||||
close(dcc->handle);
|
||||
net_disconnect(dcc->handle);
|
||||
|
||||
dcc->starttime = time(NULL);
|
||||
dcc->handle = handle;
|
||||
|
|
@ -243,14 +244,14 @@ static void dcc_chat_connect(DCC_REC *dcc)
|
|||
g_return_if_fail(dcc != NULL);
|
||||
|
||||
if (dcc->addrstr[0] == '\0' ||
|
||||
dcc->starttime != 0 || dcc->handle != -1) {
|
||||
dcc->starttime != 0 || dcc->handle != NULL) {
|
||||
/* already sent a chat request / already chatting */
|
||||
return;
|
||||
}
|
||||
|
||||
dcc->handle = net_connect_ip(&dcc->addr, dcc->port,
|
||||
source_host_ok ? source_host_ip : NULL);
|
||||
if (dcc->handle != -1) {
|
||||
if (dcc->handle != NULL) {
|
||||
dcc->tagconn = g_input_add(dcc->handle,
|
||||
G_INPUT_WRITE | G_INPUT_READ,
|
||||
(GInputFunction) sig_chat_connected, dcc);
|
||||
|
|
@ -267,8 +268,9 @@ static void cmd_dcc_chat(const char *data, IRC_SERVER_REC *server)
|
|||
void *free_arg;
|
||||
DCC_REC *dcc;
|
||||
IPADDR own_ip;
|
||||
GIOChannel *handle;
|
||||
char *nick, *str, host[MAX_IP_LEN];
|
||||
int port, handle;
|
||||
int port;
|
||||
|
||||
g_return_if_fail(data != NULL);
|
||||
|
||||
|
|
@ -288,12 +290,13 @@ static void cmd_dcc_chat(const char *data, IRC_SERVER_REC *server)
|
|||
if (server == NULL || !server->connected)
|
||||
cmd_param_error(CMDERR_NOT_CONNECTED);
|
||||
|
||||
if (net_getsockname(net_sendbuffer_handle(server->handle), &own_ip, NULL) == -1)
|
||||
if (net_getsockname(net_sendbuffer_handle(server->handle),
|
||||
&own_ip, NULL) == -1)
|
||||
cmd_param_error(CMDERR_ERRNO);
|
||||
|
||||
port = settings_get_int("dcc_port");
|
||||
handle = net_listen(&own_ip, &port);
|
||||
if (handle == -1)
|
||||
if (handle == NULL)
|
||||
cmd_param_error(CMDERR_ERRNO);
|
||||
|
||||
dcc = dcc_create(DCC_TYPE_CHAT, handle, nick, "chat", server, NULL);
|
||||
|
|
|
|||
|
|
@ -197,7 +197,7 @@ static void dcc_get_connect(DCC_REC *dcc)
|
|||
{
|
||||
dcc->handle = net_connect_ip(&dcc->addr, dcc->port,
|
||||
source_host_ok ? source_host_ip : NULL);
|
||||
if (dcc->handle != -1) {
|
||||
if (dcc->handle != NULL) {
|
||||
dcc->tagconn = g_input_add(dcc->handle,
|
||||
G_INPUT_WRITE | G_INPUT_READ,
|
||||
(GInputFunction) sig_dccget_connected, dcc);
|
||||
|
|
@ -209,7 +209,7 @@ static void dcc_get_connect(DCC_REC *dcc)
|
|||
}
|
||||
|
||||
#define dcc_is_unget(dcc) \
|
||||
((dcc)->type == DCC_TYPE_GET && (dcc)->handle == -1)
|
||||
((dcc)->type == DCC_TYPE_GET && (dcc)->handle == NULL)
|
||||
|
||||
/* SYNTAX: DCC GET <nick> [<file>] */
|
||||
static void cmd_dcc_get(const char *data)
|
||||
|
|
@ -268,7 +268,7 @@ static void dcc_resume_send(DCC_REC *dcc, int port)
|
|||
#define is_accept_ok(type, dcc) \
|
||||
(g_strcasecmp(type, "ACCEPT") != 0 || \
|
||||
((dcc)->type == DCC_TYPE_GET && \
|
||||
(dcc)->get_type == DCC_GET_RESUME && (dcc)->handle == -1))
|
||||
(dcc)->get_type == DCC_GET_RESUME && (dcc)->handle == NULL))
|
||||
|
||||
static void dcc_ctcp_msg(const char *data, IRC_SERVER_REC *server,
|
||||
const char *sender, const char *sendaddr,
|
||||
|
|
@ -453,14 +453,15 @@ static void dcc_send_read_size(DCC_REC *dcc)
|
|||
/* input function: DCC SEND - someone tried to connect to our socket */
|
||||
static void dcc_send_init(DCC_REC *dcc)
|
||||
{
|
||||
int handle, port;
|
||||
GIOChannel *handle;
|
||||
IPADDR addr;
|
||||
int port;
|
||||
|
||||
g_return_if_fail(dcc != NULL);
|
||||
|
||||
/* accept connection */
|
||||
handle = net_accept(dcc->handle, &addr, &port);
|
||||
if (handle == -1)
|
||||
if (handle == NULL)
|
||||
return;
|
||||
|
||||
/* TODO: some kind of paranoia check would be nice. it would check
|
||||
|
|
@ -468,7 +469,7 @@ static void dcc_send_init(DCC_REC *dcc)
|
|||
address who connected us. */
|
||||
|
||||
g_source_remove(dcc->tagconn);
|
||||
close(dcc->handle);
|
||||
net_disconnect(dcc->handle);
|
||||
|
||||
dcc->starttime = time(NULL);
|
||||
dcc->fastsend = settings_get_bool("dcc_fast_send");
|
||||
|
|
@ -501,10 +502,11 @@ static void cmd_dcc_send(const char *data, IRC_SERVER_REC *server, void *item)
|
|||
char *target, *fname, *str, *ptr;
|
||||
void *free_arg;
|
||||
char host[MAX_IP_LEN];
|
||||
int hfile, hlisten, port;
|
||||
int hfile, port;
|
||||
long fsize;
|
||||
DCC_REC *dcc, *chat;
|
||||
IPADDR own_ip;
|
||||
GIOChannel *handle, *hlisten;
|
||||
|
||||
g_return_if_fail(data != NULL);
|
||||
|
||||
|
|
@ -549,7 +551,9 @@ static void cmd_dcc_send(const char *data, IRC_SERVER_REC *server, void *item)
|
|||
lseek(hfile, 0, SEEK_SET);
|
||||
|
||||
/* get the IP address we use with IRC server */
|
||||
if (net_getsockname(chat != NULL ? chat->handle : net_sendbuffer_handle(server->handle), &own_ip, NULL) == -1) {
|
||||
handle = chat != NULL ? chat->handle :
|
||||
net_sendbuffer_handle(server->handle);
|
||||
if (net_getsockname(handle, &own_ip, NULL) == -1) {
|
||||
close(hfile);
|
||||
cmd_param_error(CMDERR_ERRNO);
|
||||
}
|
||||
|
|
@ -557,7 +561,7 @@ static void cmd_dcc_send(const char *data, IRC_SERVER_REC *server, void *item)
|
|||
/* start listening */
|
||||
port = settings_get_int("dcc_port");
|
||||
hlisten = net_listen(&own_ip, &port);
|
||||
if (hlisten == -1) {
|
||||
if (hlisten == NULL) {
|
||||
close(hfile);
|
||||
cmd_param_error(CMDERR_ERRNO);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ GSList *dcc_conns;
|
|||
static int dcc_timeouttag;
|
||||
|
||||
/* Create new DCC record */
|
||||
DCC_REC *dcc_create(int type, int handle, const char *nick, const char *arg,
|
||||
DCC_REC *dcc_create(int type, GIOChannel *handle, const char *nick, const char *arg,
|
||||
IRC_SERVER_REC *server, DCC_REC *chat)
|
||||
{
|
||||
DCC_REC *dcc;
|
||||
|
|
@ -110,7 +110,7 @@ void dcc_destroy(DCC_REC *dcc)
|
|||
signal_emit("dcc destroyed", 1, dcc);
|
||||
|
||||
if (dcc->fhandle != -1) close(dcc->fhandle);
|
||||
if (dcc->handle != -1) net_disconnect(dcc->handle);
|
||||
if (dcc->handle != NULL) net_disconnect(dcc->handle);
|
||||
if (dcc->tagconn != -1) g_source_remove(dcc->tagconn);
|
||||
if (dcc->tagread != -1) g_source_remove(dcc->tagread);
|
||||
if (dcc->tagwrite != -1) g_source_remove(dcc->tagwrite);
|
||||
|
|
@ -304,21 +304,21 @@ static void dcc_ctcp_msg(char *data, IRC_SERVER_REC *server, char *sender, char
|
|||
if (olddcc != NULL) {
|
||||
/* same DCC request offered again */
|
||||
if (olddcc->type == DCC_TYPE_CHAT &&
|
||||
olddcc->handle != -1 && olddcc->starttime == 0) {
|
||||
olddcc->handle != NULL && olddcc->starttime == 0) {
|
||||
/* we requested dcc chat, they requested
|
||||
dcc chat from us .. allow it. */
|
||||
dcc_destroy(olddcc);
|
||||
} else {
|
||||
/* if the connection isn't open, update the port,
|
||||
otherwise just ignore */
|
||||
if (olddcc->handle == -1)
|
||||
if (olddcc->handle == NULL)
|
||||
olddcc->port = port;
|
||||
cmd_params_free(free_arg);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
dcc = dcc_create(dcctype, -1, sender, arg, server, chat);
|
||||
dcc = dcc_create(dcctype, NULL, sender, arg, server, chat);
|
||||
dcc_get_address(addrstr, &dcc->addr);
|
||||
net_ip2host(&dcc->addr, dcc->addrstr);
|
||||
dcc->port = port;
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ typedef struct DCC_REC {
|
|||
int port; /* port we're connected in */
|
||||
|
||||
long size, transfd, skipped; /* file size / bytes transferred / skipped at start */
|
||||
int handle; /* socket handle */
|
||||
GIOChannel *handle; /* socket handle */
|
||||
void *sendbuf;
|
||||
int tagconn, tagread, tagwrite;
|
||||
int fhandle; /* file handle */
|
||||
|
|
@ -80,7 +80,7 @@ const char *dcc_type2str(int type);
|
|||
int dcc_str2type(const char *type);
|
||||
void dcc_make_address(IPADDR *ip, char *host);
|
||||
|
||||
DCC_REC *dcc_create(int type, int handle, const char *nick, const char *arg, IRC_SERVER_REC *server, DCC_REC *chat);
|
||||
DCC_REC *dcc_create(int type, GIOChannel *handle, const char *nick, const char *arg, IRC_SERVER_REC *server, DCC_REC *chat);
|
||||
void dcc_destroy(DCC_REC *dcc);
|
||||
|
||||
/* Send a CTCP message/notify to target. Send the CTCP via DCC chat if
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue