summaryrefslogtreecommitdiff
path: root/src/irc/dcc/dcc-send.c
diff options
context:
space:
mode:
authorTimo Sirainen <cras@irssi.org>2002-11-21 17:48:40 +0000
committercras <cras@dbcabf3a-b0e7-0310-adc4-f8d773084564>2002-11-21 17:48:40 +0000
commitdc8bd638e395eada4cdea03c5f1a1c28d506f003 (patch)
tree88d2a16cb750ef08c02975f41db3ea0bd149cd6d /src/irc/dcc/dcc-send.c
parentdc7efcb45bc7298a786bc8392adb488b3c704718 (diff)
downloadirssi-dc8bd638e395eada4cdea03c5f1a1c28d506f003.zip
Irssi now uses 64bit file offets if it's only supported by system. Also did
a few changes to DCC so that it should be possible to send >4GB files. DCC protocol uses 32bit "n bytes transferred" notifications, so I had to bend the protocol a bit to allow 64bit files by truncating the value to lowest 32bits. I'm not sure how other clients handle those notifications, but irssi uses it only to figure out when the DCC SEND transfer is complete, so it's quite safe to assume that if we've managed to write() all the bytes and we receive the last 32bit of file size, it means the total file size instead of the total - (n+1)*4GB. git-svn-id: http://svn.irssi.org/repos/irssi/trunk@3018 dbcabf3a-b0e7-0310-adc4-f8d773084564
Diffstat (limited to 'src/irc/dcc/dcc-send.c')
-rw-r--r--src/irc/dcc/dcc-send.c27
1 files changed, 14 insertions, 13 deletions
diff --git a/src/irc/dcc/dcc-send.c b/src/irc/dcc/dcc-send.c
index a75984ac..46e1dd4e 100644
--- a/src/irc/dcc/dcc-send.c
+++ b/src/irc/dcc/dcc-send.c
@@ -254,7 +254,6 @@ static void dcc_send_read_size(SEND_DCC_REC *dcc)
guint32 bytes;
int ret;
- /* we need to get 4 bytes.. */
ret = net_receive(dcc->handle, dcc->count_buf+dcc->count_pos,
4-dcc->count_pos);
if (ret == -1) {
@@ -267,14 +266,12 @@ static void dcc_send_read_size(SEND_DCC_REC *dcc)
if (dcc->count_pos != 4)
return;
- memcpy(&bytes, dcc->count_buf, 4);
- bytes = (guint32) ntohl(bytes);
-
- dcc->gotalldata = (unsigned long) bytes == dcc->transfd;
+ bytes = ntohl(*((guint32 *) dcc->count_buf));
dcc->count_pos = 0;
- if (dcc->waitforend && dcc->gotalldata) {
+ if (dcc->waitforend && bytes == (dcc->transfd & 0xffffffff)) {
/* file is sent */
+ dcc->gotalldata = TRUE;
dcc_close(DCC(dcc));
}
}
@@ -334,10 +331,10 @@ static char *dcc_send_get_file(const char *fname)
static int dcc_send_one_file(int queue, const char *target, const char *fname,
IRC_SERVER_REC *server, CHAT_DCC_REC *chat)
{
+ struct stat st;
char *str;
char host[MAX_IP_LEN];
int hfile, port;
- long fsize;
SEND_DCC_REC *dcc;
IPADDR own_ip;
GIOChannel *handle;
@@ -356,8 +353,12 @@ static int dcc_send_one_file(int queue, const char *target, const char *fname,
GINT_TO_POINTER(errno));
return FALSE;
}
- fsize = lseek(hfile, 0, SEEK_END);
- lseek(hfile, 0, SEEK_SET);
+
+ if (fstat(hfile, &st) < 0) {
+ g_warning("fstat() failed: %s", strerror(errno));
+ close(hfile);
+ return FALSE;
+ }
/* start listening */
handle = dcc_listen(chat != NULL ? chat->handle :
@@ -386,7 +387,7 @@ static int dcc_send_one_file(int queue, const char *target, const char *fname,
dcc->handle = handle;
dcc->port = port;
- dcc->size = fsize;
+ dcc->size = st.st_size;
dcc->fhandle = hfile;
dcc->queue = queue;
dcc->file_quoted = strchr(fname, ' ') != NULL;
@@ -398,9 +399,9 @@ static int dcc_send_one_file(int queue, const char *target, const char *fname,
dcc_ip2str(&own_ip, host);
str = g_strdup_printf(dcc->file_quoted ?
- "DCC SEND \"%s\" %s %d %lu" :
- "DCC SEND %s %s %d %lu",
- dcc->arg, host, port, fsize);
+ "DCC SEND \"%s\" %s %d %"PRIuUOFF_T :
+ "DCC SEND %s %s %d %"PRIuUOFF_T,
+ dcc->arg, host, port, dcc->size);
dcc_ctcp_message(server, target, chat, FALSE, str);
g_free(str);