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