annotate src/protocols/irc/dcc_send.c @ 13837:1a095ac881ce

[gaim-migrate @ 16286] When the /quit command is used on IRC, we disconnect the account. This avoids having Gaim think the server kicked us offline. And it avoids Gaim auto-reconnecting. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Mon, 19 Jun 2006 06:27:18 +0000
parents 5ddde4ad1ca2
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8351
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1 /**
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
2 * @file dcc_send.c Functions used in sending files with DCC SEND
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
3 *
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
4 * gaim
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
5 *
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
6 * Copyright (C) 2004, Timothy T Ringenbach <omarvo@hotmail.com>
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
7 * Copyright (C) 2003, Robbert Haarman <gaim@inglorion.net>
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
8 *
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
9 * This program is free software; you can redistribute it and/or modify
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
10 * it under the terms of the GNU General Public License as published by
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
11 * the Free Software Foundation; either version 2 of the License, or
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
12 * (at your option) any later version.
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
13 *
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
14 * This program is distributed in the hope that it will be useful,
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
17 * GNU General Public License for more details.
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
18 *
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
19 * You should have received a copy of the GNU General Public License
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
20 * along with this program; if not, write to the Free Software
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
22 */
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
23
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
24 #include "internal.h"
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
25 #include "irc.h"
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
26 #include "debug.h"
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
27 #include "ft.h"
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
28 #include "notify.h"
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
29 #include "network.h"
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
30
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
31 /***************************************************************************
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
32 * Functions related to receiving files via DCC SEND
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
33 ***************************************************************************/
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
34
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
35 struct irc_xfer_rx_data {
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
36 gchar *ip;
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
37 };
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
38
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
39 static void irc_dccsend_recv_destroy(GaimXfer *xfer)
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
40 {
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
41 struct irc_xfer_rx_data *xd = xfer->data;
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
42
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
43 if (xd->ip != NULL)
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
44 g_free(xd->ip);
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
45
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
46 g_free(xd);
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
47 }
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
48
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
49 /*
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
50 * This function is called whenever data is received.
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
51 * It sends the acknowledgement (in the form of a total byte count as an
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
52 * unsigned 4 byte integer in network byte order)
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
53 */
11159
bd8ac1d4b2f2 [gaim-migrate @ 13246]
Mark Doliner <mark@kingant.net>
parents: 10654
diff changeset
54 static void irc_dccsend_recv_ack(GaimXfer *xfer, const guchar *data, size_t size) {
8351
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
55 unsigned long l;
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
56
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
57 l = htonl(xfer->bytes_sent);
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
58 write(xfer->fd, &l, sizeof(l));
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
59 }
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
60
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
61 static void irc_dccsend_recv_init(GaimXfer *xfer) {
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
62 struct irc_xfer_rx_data *xd = xfer->data;
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
63
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
64 gaim_xfer_start(xfer, -1, xd->ip, xfer->remote_port);
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
65 g_free(xd->ip);
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
66 xd->ip = NULL;
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
67 }
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
68
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
69 /* This function makes the necessary arrangements for receiving files */
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
70 void irc_dccsend_recv(struct irc_conn *irc, const char *from, const char *msg) {
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
71 GaimXfer *xfer;
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
72 struct irc_xfer_rx_data *xd;
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
73 gchar **token;
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
74 struct in_addr addr;
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
75 GString *filename;
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
76 int i = 0;
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
77 guint32 nip;
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
78
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
79 token = g_strsplit(msg, " ", 0);
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
80 if (!token[0] || !token[1] || !token[2]) {
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
81 g_strfreev(token);
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
82 return;
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
83 }
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
84
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
85 filename = g_string_new("");
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
86 if (token[0][0] == '"') {
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
87 if (!strchr(&(token[0][1]), '"')) {
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
88 g_string_append(filename, &(token[0][1]));
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
89 for (i = 1; token[i]; i++)
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
90 if (!strchr(token[i], '"')) {
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
91 g_string_append_printf(filename, " %s", token[i]);
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
92 } else {
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
93 g_string_append_len(filename, token[i], strlen(token[i]) - 1);
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
94 break;
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
95 }
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
96 } else {
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
97 g_string_append_len(filename, &(token[0][1]), strlen(&(token[0][1])) - 1);
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
98 }
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
99 } else {
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
100 g_string_append(filename, token[0]);
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
101 }
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
102
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
103 if (!token[i] || !token[i+1] || !token[i+2]) {
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
104 g_strfreev(token);
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
105 g_string_free(filename, TRUE);
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
106 return;
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
107 }
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
108 i++;
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
109
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
110 xfer = gaim_xfer_new(irc->account, GAIM_XFER_RECEIVE, from);
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
111 xd = g_new0(struct irc_xfer_rx_data, 1);
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
112 xfer->data = xd;
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
113
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
114 gaim_xfer_set_filename(xfer, filename->str);
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
115 xfer->remote_port = atoi(token[i+1]);
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
116
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
117 nip = strtoul(token[i], NULL, 10);
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
118 if (nip) {
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
119 addr.s_addr = htonl(nip);
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
120 xd->ip = g_strdup(inet_ntoa(addr));
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
121 } else {
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
122 xd->ip = g_strdup(token[i]);
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
123 }
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
124 gaim_debug(GAIM_DEBUG_INFO, "irc", "Receiving file from %s\n",
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
125 xd->ip);
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
126 gaim_xfer_set_size(xfer, token[i+2] ? atoi(token[i+2]) : 0);
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
127
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
128 gaim_xfer_set_init_fnc(xfer, irc_dccsend_recv_init);
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
129 gaim_xfer_set_ack_fnc(xfer, irc_dccsend_recv_ack);
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
130
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
131 gaim_xfer_set_end_fnc(xfer, irc_dccsend_recv_destroy);
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
132 gaim_xfer_set_request_denied_fnc(xfer, irc_dccsend_recv_destroy);
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
133 gaim_xfer_set_cancel_send_fnc(xfer, irc_dccsend_recv_destroy);
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
134
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
135 gaim_xfer_request(xfer);
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
136 g_strfreev(token);
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
137 g_string_free(filename, TRUE);
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
138 }
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
139
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
140 /*******************************************************************
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
141 * Functions related to sending files via DCC SEND
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
142 *******************************************************************/
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
143
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
144 struct irc_xfer_send_data {
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
145 gint inpa;
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
146 int fd;
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
147 guchar *rxqueue;
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
148 guint rxlen;
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
149 };
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
150
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
151 static void irc_dccsend_send_destroy(GaimXfer *xfer)
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
152 {
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
153 struct irc_xfer_send_data *xd = xfer->data;
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
154
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
155 if (xd == NULL)
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
156 return;
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
157
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
158 if (xd->inpa > 0)
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
159 gaim_input_remove(xd->inpa);
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
160 if (xd->fd != -1)
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
161 close(xd->fd);
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
162
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
163 if (xd->rxqueue)
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
164 g_free(xd->rxqueue);
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
165
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
166 g_free(xd);
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
167 }
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
168
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
169 /* just in case you were wondering, this is why DCC is gay */
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
170 static void irc_dccsend_send_read(gpointer data, int source, GaimInputCondition cond)
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
171 {
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
172 GaimXfer *xfer = data;
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
173 struct irc_xfer_send_data *xd = xfer->data;
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
174 char *buffer[16];
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
175 int len;
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
176
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12909
diff changeset
177 len = read(source, buffer, sizeof(buffer));
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12909
diff changeset
178
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12909
diff changeset
179 if (len < 0 && errno == EAGAIN)
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12909
diff changeset
180 return;
13786
5ddde4ad1ca2 [gaim-migrate @ 16198]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13200
diff changeset
181 else if (len <= 0) {
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12909
diff changeset
182 /* XXX: Shouldn't this be canceling the transfer? */
8351
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
183 gaim_input_remove(xd->inpa);
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
184 xd->inpa = 0;
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
185 return;
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
186 }
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
187
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
188 xd->rxqueue = g_realloc(xd->rxqueue, len + xd->rxlen);
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
189 memcpy(xd->rxqueue + xd->rxlen, buffer, len);
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
190 xd->rxlen += len;
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
191
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
192 while (1) {
11318
519dc2186438 [gaim-migrate @ 13521]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11159
diff changeset
193 size_t acked;
8351
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
194
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
195 if (xd->rxlen < 4)
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
196 break;
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
197
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
198 acked = ntohl(*((gint32 *)xd->rxqueue));
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
199
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
200 xd->rxlen -= 4;
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
201 if (xd->rxlen) {
10388
088633feb846 [gaim-migrate @ 11615]
Nathan Walp <nwalp@pidgin.im>
parents: 10112
diff changeset
202 unsigned char *tmp = g_memdup(xd->rxqueue + 4, xd->rxlen);
8351
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
203 g_free(xd->rxqueue);
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
204 xd->rxqueue = tmp;
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
205 } else {
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
206 g_free(xd->rxqueue);
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
207 xd->rxqueue = NULL;
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
208 }
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
209
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
210 if (acked >= gaim_xfer_get_size(xfer)) {
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
211 gaim_input_remove(xd->inpa);
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
212 xd->inpa = 0;
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
213 gaim_xfer_set_completed(xfer, TRUE);
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
214 gaim_xfer_end(xfer);
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
215 return;
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
216 }
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
217 }
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
218 }
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
219
12323
fc464a0abccc [gaim-migrate @ 14627]
Richard Laager <rlaager@wiktel.com>
parents: 12151
diff changeset
220 static gssize irc_dccsend_send_write(const guchar *buffer, size_t size, GaimXfer *xfer)
8351
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
221 {
12151
de798f2f4bf1 [gaim-migrate @ 14452]
Richard Laager <rlaager@wiktel.com>
parents: 12143
diff changeset
222 gssize s;
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12909
diff changeset
223 int ret;
8351
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
224
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
225 s = MIN(gaim_xfer_get_bytes_remaining(xfer), size);
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
226 if (!s)
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
227 return 0;
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
228
13200
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12909
diff changeset
229 ret = write(xfer->fd, buffer, s);
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12909
diff changeset
230
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12909
diff changeset
231 if (ret < 0 && errno == EAGAIN)
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12909
diff changeset
232 ret = 0;
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12909
diff changeset
233
33bef17125c2 [gaim-migrate @ 15563]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12909
diff changeset
234 return ret;
8351
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
235 }
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
236
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
237 static void irc_dccsend_send_connected(gpointer data, int source, GaimInputCondition cond) {
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
238 GaimXfer *xfer = (GaimXfer *) data;
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
239 struct irc_xfer_send_data *xd = xfer->data;
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
240 int conn;
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
241
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
242 conn = accept(xd->fd, NULL, 0);
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
243 if (conn == -1) {
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
244 /* Accepting the connection failed. This could just be related
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
245 * to the nonblocking nature of the listening socket, so we'll
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
246 * just try again next time */
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
247 /* Let's print an error message anyway */
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
248 gaim_debug_warning("irc", "accept: %s\n", strerror(errno));
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
249 return;
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
250 }
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
251
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
252 gaim_input_remove(xfer->watcher);
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
253 xfer->watcher = 0;
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
254 close(xd->fd);
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
255 xd->fd = -1;
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
256
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
257 xd->inpa = gaim_input_add(conn, GAIM_INPUT_READ, irc_dccsend_send_read, xfer);
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
258 /* Start the transfer */
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
259 gaim_xfer_start(xfer, conn, NULL, 0);
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
260 }
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
261
12909
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
262 static void
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
263 irc_dccsend_network_listen_cb(int sock, gpointer data)
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
264 {
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
265 GaimXfer *xfer = data;
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
266 struct irc_xfer_send_data *xd;
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
267 GaimConnection *gc;
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
268 struct irc_conn *irc;
8351
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
269 const char *arg[2];
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
270 char *tmp;
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
271 struct in_addr addr;
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
272 unsigned short int port;
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
273
12909
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
274 if (gaim_xfer_get_status(xfer) == GAIM_XFER_STATUS_CANCEL_LOCAL
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
275 || gaim_xfer_get_status(xfer) == GAIM_XFER_STATUS_CANCEL_REMOTE) {
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
276 gaim_xfer_unref(xfer);
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
277 return;
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
278 }
8351
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
279
12909
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
280 xd = xfer->data;
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
281 gc = gaim_account_get_connection(gaim_xfer_get_account(xfer));
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
282 irc = gc->proto_data;
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
283
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
284 gaim_xfer_unref(xfer);
8351
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
285
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
286 if (sock < 0) {
10654
f2e86683cafc [gaim-migrate @ 12182]
Mark Doliner <mark@kingant.net>
parents: 10555
diff changeset
287 gaim_notify_error(gc, NULL, _("File Transfer Failed"),
8351
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
288 _("Gaim could not open a listening port."));
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
289 gaim_xfer_cancel_local(xfer);
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
290 return;
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
291 }
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
292
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
293 xd->fd = sock;
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
294
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
295 port = gaim_network_get_port_from_fd(sock);
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
296 gaim_debug_misc("irc", "port is %hu\n", port);
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
297 /* Monitor the listening socket */
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
298 xfer->watcher = gaim_input_add(sock, GAIM_INPUT_READ,
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
299 irc_dccsend_send_connected, xfer);
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
300
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
301 /* Send the intended recipient the DCC request */
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
302 arg[0] = xfer->who;
8838
518455386538 [gaim-migrate @ 9604]
Mark Doliner <mark@kingant.net>
parents: 8351
diff changeset
303 inet_aton(gaim_network_get_my_ip(irc->fd), &addr);
11656
f9c5480ad0ce [gaim-migrate @ 13940]
Richard Laager <rlaager@wiktel.com>
parents: 11318
diff changeset
304 arg[1] = tmp = g_strdup_printf("\001DCC SEND \"%s\" %u %hu %" G_GSIZE_FORMAT "\001",
8351
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
305 xfer->filename, ntohl(addr.s_addr),
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
306 port, xfer->size);
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
307
10555
761822c6f7ca [gaim-migrate @ 11932]
Nathan Walp <nwalp@pidgin.im>
parents: 10388
diff changeset
308 irc_cmd_privmsg(gc->proto_data, "msg", NULL, arg);
8351
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
309 g_free(tmp);
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
310 }
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
311
12909
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
312 /*
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
313 * This function is called after the user has selected a file to send.
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
314 */
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
315 static void irc_dccsend_send_init(GaimXfer *xfer) {
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
316 GaimConnection *gc = gaim_account_get_connection(gaim_xfer_get_account(xfer));
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
317
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
318 xfer->filename = g_path_get_basename(xfer->local_filename);
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
319
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
320 gaim_xfer_ref(xfer);
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
321
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
322 /* Create a listening socket */
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
323 if (!gaim_network_listen_range(0, 0, SOCK_STREAM,
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
324 irc_dccsend_network_listen_cb, xfer)) {
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
325 gaim_xfer_unref(xfer);
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
326 gaim_notify_error(gc, NULL, _("File Transfer Failed"),
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
327 _("Gaim could not open a listening port."));
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
328 gaim_xfer_cancel_local(xfer);
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
329 }
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
330
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
331 }
8e3b85fe4a55 [gaim-migrate @ 15262]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 12730
diff changeset
332
12143
cbebda5f019c [gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents: 11656
diff changeset
333 GaimXfer *irc_dccsend_new_xfer(GaimConnection *gc, const char *who) {
8351
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
334 GaimXfer *xfer;
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
335 struct irc_xfer_send_data *xd;
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
336
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
337 /* Build the file transfer handle */
9466
d27156c9c876 [gaim-migrate @ 10291]
Luke Schierer <lschiere@pidgin.im>
parents: 8838
diff changeset
338 xfer = gaim_xfer_new(gaim_connection_get_account(gc), GAIM_XFER_SEND, who);
8351
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
339
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
340 xd = g_new0(struct irc_xfer_send_data, 1);
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
341 xd->fd = -1;
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
342 xfer->data = xd;
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
343
12143
cbebda5f019c [gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents: 11656
diff changeset
344 /* Setup our I/O op functions */
8351
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
345 gaim_xfer_set_init_fnc(xfer, irc_dccsend_send_init);
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
346 gaim_xfer_set_write_fnc(xfer, irc_dccsend_send_write);
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
347 gaim_xfer_set_end_fnc(xfer, irc_dccsend_send_destroy);
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
348 gaim_xfer_set_request_denied_fnc(xfer, irc_dccsend_send_destroy);
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
349 gaim_xfer_set_cancel_send_fnc(xfer, irc_dccsend_send_destroy);
12143
cbebda5f019c [gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents: 11656
diff changeset
350
cbebda5f019c [gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents: 11656
diff changeset
351 return xfer;
cbebda5f019c [gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents: 11656
diff changeset
352 }
cbebda5f019c [gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents: 11656
diff changeset
353
cbebda5f019c [gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents: 11656
diff changeset
354 /**
cbebda5f019c [gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents: 11656
diff changeset
355 * Gaim calls this function when the user selects Send File from the
cbebda5f019c [gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents: 11656
diff changeset
356 * buddy menu
cbebda5f019c [gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents: 11656
diff changeset
357 * It sets up the GaimXfer struct and tells Gaim to go ahead
cbebda5f019c [gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents: 11656
diff changeset
358 */
cbebda5f019c [gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents: 11656
diff changeset
359 void irc_dccsend_send_file(GaimConnection *gc, const char *who, const char *file) {
cbebda5f019c [gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents: 11656
diff changeset
360 GaimXfer *xfer = irc_dccsend_new_xfer(gc, who);
cbebda5f019c [gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents: 11656
diff changeset
361
cbebda5f019c [gaim-migrate @ 14444]
Richard Laager <rlaager@wiktel.com>
parents: 11656
diff changeset
362 /* Perform the request */
9466
d27156c9c876 [gaim-migrate @ 10291]
Luke Schierer <lschiere@pidgin.im>
parents: 8838
diff changeset
363 if (file)
d27156c9c876 [gaim-migrate @ 10291]
Luke Schierer <lschiere@pidgin.im>
parents: 8838
diff changeset
364 gaim_xfer_request_accepted(xfer, file);
d27156c9c876 [gaim-migrate @ 10291]
Luke Schierer <lschiere@pidgin.im>
parents: 8838
diff changeset
365 else
d27156c9c876 [gaim-migrate @ 10291]
Luke Schierer <lschiere@pidgin.im>
parents: 8838
diff changeset
366 gaim_xfer_request(xfer);
8351
ffa642240fc1 [gaim-migrate @ 9075]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
367 }