Thu, 20 Jul 2006 08:11:54 +0000
[gaim-migrate @ 16525]
A bunch of little things
* Use GAIM_CONNECTION_IS_VALID(gc) in a lot of places where
we were doing g_list_find(gaim_connections_get_all(), gc)
* Get rid of a lot of places where we were doing
g_list_find(gaim_connections_get_all(), gc). The handle used
by the request API ensures that the ok and cancel callback
functions won't be called if the gc is destroyed. However,
GAIM_CONNECTION_IS_VALID(gc) is still very important for
callback functions where we can't cancel the request.
For example, gaim_proxy_connect() callback functions.
* "Added" a function to Yahoo! that should help us notice
when our buddies change their buddy icon/display picture
* Some comments in a few places
* Changed GAIM_CONNECTION_IS_VALID(gc) to only look through
the list of "all" connections and not the list of
"connecting" connections. Some time ago we changed how
this was done so that the list of "all" connections now
includes the "connection" connections.
| 7651 | 1 | /* |
| 2 | * @file yahoo_filexfer.c Yahoo Filetransfer | |
| 3 | * | |
| 8046 | 4 | * Gaim is the legal property of its developers, whose names are too numerous |
| 5 | * to list here. Please refer to the COPYRIGHT file distributed with this | |
| 6 | * source distribution. | |
| 7651 | 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify | |
| 9 | * it under the terms of the GNU General Public License as published by | |
| 10 | * the Free Software Foundation; either version 2 of the License, or | |
| 11 | * (at your option) any later version. | |
| 12 | * | |
| 13 | * This program is distributed in the hope that it will be useful, | |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 16 | * GNU General Public License for more details. | |
| 17 | * | |
| 18 | * You should have received a copy of the GNU General Public License | |
| 19 | * along with this program; if not, write to the Free Software | |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 21 | */ | |
| 22 | ||
| 23 | #include "prpl.h" | |
| 24 | #include "internal.h" | |
| 25 | #include "util.h" | |
| 26 | #include "debug.h" | |
| 27 | #include "notify.h" | |
| 28 | #include "proxy.h" | |
| 29 | #include "ft.h" | |
| 30 | #include "yahoo.h" | |
| 10392 | 31 | #include "yahoo_packet.h" |
| 7651 | 32 | #include "yahoo_filexfer.h" |
|
11475
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
33 | #include "yahoo_doodle.h" |
| 7651 | 34 | |
| 35 | struct yahoo_xfer_data { | |
| 36 | gchar *host; | |
| 37 | gchar *path; | |
| 38 | int port; | |
| 39 | GaimConnection *gc; | |
| 40 | long expires; | |
| 41 | gboolean started; | |
|
13272
fd4f3356640f
[gaim-migrate @ 15637]
Daniel Atallah <datallah@pidgin.im>
parents:
13201
diff
changeset
|
42 | gchar *txbuf; |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
43 | gsize txbuflen; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
44 | gsize txbuf_written; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
45 | guint tx_handler; |
| 7651 | 46 | gchar *rxqueue; |
| 47 | guint rxlen; | |
| 48 | }; | |
| 49 | ||
| 50 | static void yahoo_xfer_data_free(struct yahoo_xfer_data *xd) | |
| 51 | { | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
52 | g_free(xd->host); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
53 | g_free(xd->path); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
54 | g_free(xd->txbuf); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
55 | if (xd->tx_handler) |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
56 | gaim_input_remove(xd->tx_handler); |
| 7651 | 57 | g_free(xd); |
| 58 | } | |
| 59 | ||
| 60 | static void yahoo_receivefile_connected(gpointer data, gint source, GaimInputCondition condition) | |
| 61 | { | |
| 62 | GaimXfer *xfer; | |
| 63 | struct yahoo_xfer_data *xd; | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
64 | int total_len, written; |
| 7651 | 65 | |
| 66 | gaim_debug(GAIM_DEBUG_INFO, "yahoo", | |
| 67 | "AAA - in yahoo_receivefile_connected\n"); | |
| 68 | if (!(xfer = data)) | |
| 69 | return; | |
| 70 | if (!(xd = xfer->data)) | |
| 71 | return; | |
|
13144
e8c3eafab5f8
[gaim-migrate @ 15506]
Evan Schoenberg <evands@pidgin.im>
parents:
12412
diff
changeset
|
72 | if ((source < 0) || (xd->path == NULL) || (xd->host == NULL)) { |
|
10654
b2dd3be1b087
[gaim-migrate @ 12182]
Richard Laager <rlaager@pidgin.im>
parents:
10651
diff
changeset
|
73 | gaim_xfer_error(GAIM_XFER_RECEIVE, gaim_xfer_get_account(xfer), |
|
b2dd3be1b087
[gaim-migrate @ 12182]
Richard Laager <rlaager@pidgin.im>
parents:
10651
diff
changeset
|
74 | xfer->who, _("Unable to connect.")); |
| 7805 | 75 | gaim_xfer_cancel_remote(xfer); |
| 7651 | 76 | return; |
| 77 | } | |
| 78 | ||
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
79 | /* The first time we get here, assemble the tx buffer */ |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
80 | if (xd->txbuflen == 0) { |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
81 | xd->txbuf = g_strdup_printf("GET /%s HTTP/1.0\r\nHost: %s\r\n\r\n", |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
82 | xd->path, xd->host); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
83 | xd->txbuflen = strlen(xd->txbuf); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
84 | xd->txbuf_written = 0; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
85 | } |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
86 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
87 | total_len = xd->txbuflen - xd->txbuf_written; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
88 | |
| 7651 | 89 | xfer->fd = source; |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
90 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
91 | written = write(xfer->fd, xd->txbuf + xd->txbuf_written, total_len); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
92 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
93 | if (written < 0 && errno == EAGAIN) |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
94 | written = 0; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
95 | else if (written <= 0) { |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
96 | gaim_debug_error("yahoo", "Unable to write in order to start ft errno = %d\n", errno); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
97 | gaim_xfer_cancel_remote(xfer); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
98 | return; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
99 | } |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
100 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
101 | if (written < total_len) { |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
102 | if (!xd->tx_handler) |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
103 | xd->tx_handler = gaim_input_add(source, GAIM_INPUT_WRITE, |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
104 | yahoo_receivefile_connected, xfer); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
105 | xd->txbuf_written += written; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
106 | return; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
107 | } |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
108 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
109 | if (xd->tx_handler) |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
110 | gaim_input_remove(xd->tx_handler); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
111 | xd->tx_handler = 0; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
112 | g_free(xd->txbuf); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
113 | xd->txbuf = NULL; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
114 | xd->txbuflen = 0; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
115 | |
| 7651 | 116 | gaim_xfer_start(xfer, source, NULL, 0); |
| 117 | ||
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
118 | } |
| 7651 | 119 | |
| 120 | ||
| 121 | static void yahoo_sendfile_connected(gpointer data, gint source, GaimInputCondition condition) | |
| 122 | { | |
| 123 | GaimXfer *xfer; | |
| 124 | struct yahoo_xfer_data *xd; | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
125 | int written, total_len; |
| 7651 | 126 | |
| 127 | gaim_debug(GAIM_DEBUG_INFO, "yahoo", | |
| 128 | "AAA - in yahoo_sendfile_connected\n"); | |
| 129 | if (!(xfer = data)) | |
| 130 | return; | |
| 131 | if (!(xd = xfer->data)) | |
| 132 | return; | |
| 133 | ||
| 134 | ||
| 135 | if (source < 0) { | |
|
10654
b2dd3be1b087
[gaim-migrate @ 12182]
Richard Laager <rlaager@pidgin.im>
parents:
10651
diff
changeset
|
136 | gaim_xfer_error(GAIM_XFER_RECEIVE, gaim_xfer_get_account(xfer), |
|
b2dd3be1b087
[gaim-migrate @ 12182]
Richard Laager <rlaager@pidgin.im>
parents:
10651
diff
changeset
|
137 | xfer->who, _("Unable to connect.")); |
| 7805 | 138 | gaim_xfer_cancel_remote(xfer); |
| 7651 | 139 | return; |
| 140 | } | |
| 141 | ||
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
142 | /* The first time we get here, assemble the tx buffer */ |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
143 | if (xd->txbuflen == 0) { |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
144 | struct yahoo_packet *pkt; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
145 | gchar *size, *filename, *encoded_filename, *header; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
146 | guchar *pkt_buf; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
147 | const char *host; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
148 | int port; |
|
13277
c8a85dd74704
[gaim-migrate @ 15642]
Richard Laager <rlaager@pidgin.im>
parents:
13272
diff
changeset
|
149 | size_t content_length, header_len, pkt_buf_len; |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
150 | GaimConnection *gc; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
151 | GaimAccount *account; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
152 | struct yahoo_data *yd; |
| 7651 | 153 | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
154 | gc = xd->gc; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
155 | account = gaim_connection_get_account(gc); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
156 | yd = gc->proto_data; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
157 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
158 | pkt = yahoo_packet_new(YAHOO_SERVICE_FILETRANSFER, |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
159 | YAHOO_STATUS_AVAILABLE, yd->session_id); |
| 7651 | 160 | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
161 | size = g_strdup_printf("%" G_GSIZE_FORMAT, gaim_xfer_get_size(xfer)); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
162 | filename = g_path_get_basename(gaim_xfer_get_local_filename(xfer)); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
163 | encoded_filename = yahoo_string_encode(gc, filename, NULL); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
164 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
165 | yahoo_packet_hash(pkt, "sssss", 0, gaim_connection_get_display_name(gc), |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
166 | 5, xfer->who, 14, "", 27, encoded_filename, 28, size); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
167 | g_free(size); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
168 | g_free(encoded_filename); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
169 | g_free(filename); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
170 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
171 | content_length = YAHOO_PACKET_HDRLEN + yahoo_packet_length(pkt); |
|
11644
939411169d01
[gaim-migrate @ 13922]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11475
diff
changeset
|
172 | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
173 | pkt_buf_len = yahoo_packet_build(pkt, 8, FALSE, &pkt_buf); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
174 | yahoo_packet_free(pkt); |
| 7651 | 175 | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
176 | host = gaim_account_get_string(account, "xfer_host", YAHOO_XFER_HOST); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
177 | port = gaim_account_get_int(account, "xfer_port", YAHOO_XFER_PORT); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
178 | header = g_strdup_printf( |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
179 | "POST http://%s:%d/notifyft HTTP/1.0\r\n" |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
180 | "Content-length: %" G_GSIZE_FORMAT "\r\n" |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
181 | "Host: %s:%d\r\n" |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
182 | "Cookie: Y=%s; T=%s\r\n" |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
183 | "\r\n", |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
184 | host, port, content_length + 4 + gaim_xfer_get_size(xfer), |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
185 | host, port, yd->cookie_y, yd->cookie_t); |
| 7651 | 186 | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
187 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
188 | header_len = strlen(header); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
189 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
190 | xd->txbuflen = header_len + pkt_buf_len + 4; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
191 | xd->txbuf = g_malloc(xd->txbuflen); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
192 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
193 | memcpy(xd->txbuf, header, header_len); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
194 | g_free(header); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
195 | memcpy(xd->txbuf + header_len, pkt_buf, pkt_buf_len); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
196 | g_free(pkt_buf); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
197 | memcpy(xd->txbuf + header_len + pkt_buf_len, "29\xc0\x80", 4); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
198 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
199 | xd->txbuf_written = 0; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
200 | } |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
201 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
202 | total_len = xd->txbuflen - xd->txbuf_written; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
203 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
204 | xfer->fd = source; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
205 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
206 | written = write(xfer->fd, xd->txbuf + xd->txbuf_written, total_len); |
| 7651 | 207 | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
208 | if (written < 0 && errno == EAGAIN) |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
209 | written = 0; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
210 | else if (written <= 0) { |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
211 | gaim_debug_error("yahoo", "Unable to write in order to start ft errno = %d\n", errno); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
212 | gaim_xfer_cancel_remote(xfer); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
213 | return; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
214 | } |
| 7651 | 215 | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
216 | if (written < total_len) { |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
217 | if (!xd->tx_handler) |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
218 | xd->tx_handler = gaim_input_add(source, GAIM_INPUT_WRITE, |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
219 | yahoo_sendfile_connected, xfer); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
220 | xd->txbuf_written += written; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
221 | return; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
222 | } |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
223 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
224 | if (xd->tx_handler) |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
225 | gaim_input_remove(xd->tx_handler); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
226 | xd->tx_handler = 0; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
227 | g_free(xd->txbuf); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
228 | xd->txbuf = NULL; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
229 | xd->txbuflen = 0; |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
230 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
13144
diff
changeset
|
231 | gaim_xfer_start(xfer, source, NULL, 0); |
| 7651 | 232 | } |
| 233 | ||
| 234 | static void yahoo_xfer_init(GaimXfer *xfer) | |
| 235 | { | |
| 236 | struct yahoo_xfer_data *xfer_data; | |
| 237 | GaimConnection *gc; | |
| 238 | GaimAccount *account; | |
| 7827 | 239 | struct yahoo_data *yd; |
| 7651 | 240 | |
| 241 | xfer_data = xfer->data; | |
| 242 | gc = xfer_data->gc; | |
| 7827 | 243 | yd = gc->proto_data; |
| 7651 | 244 | account = gaim_connection_get_account(gc); |
| 245 | ||
| 246 | if (gaim_xfer_get_type(xfer) == GAIM_XFER_SEND) { | |
|
10937
1753f4709889
[gaim-migrate @ 12721]
Peter Lawler <pidgin@bleeter.id.au>
parents:
10654
diff
changeset
|
247 | if (yd->jp) { |
|
1753f4709889
[gaim-migrate @ 12721]
Peter Lawler <pidgin@bleeter.id.au>
parents:
10654
diff
changeset
|
248 | if (gaim_proxy_connect(account, gaim_account_get_string(account, "xferjp_host", YAHOOJP_XFER_HOST), |
|
1753f4709889
[gaim-migrate @ 12721]
Peter Lawler <pidgin@bleeter.id.au>
parents:
10654
diff
changeset
|
249 | gaim_account_get_int(account, "xfer_port", YAHOO_XFER_PORT), |
|
1753f4709889
[gaim-migrate @ 12721]
Peter Lawler <pidgin@bleeter.id.au>
parents:
10654
diff
changeset
|
250 | yahoo_sendfile_connected, xfer) == -1) |
|
1753f4709889
[gaim-migrate @ 12721]
Peter Lawler <pidgin@bleeter.id.au>
parents:
10654
diff
changeset
|
251 | { |
|
1753f4709889
[gaim-migrate @ 12721]
Peter Lawler <pidgin@bleeter.id.au>
parents:
10654
diff
changeset
|
252 | gaim_notify_error(gc, NULL, _("File Transfer Failed"), |
|
1753f4709889
[gaim-migrate @ 12721]
Peter Lawler <pidgin@bleeter.id.au>
parents:
10654
diff
changeset
|
253 | _("Unable to establish file descriptor.")); |
|
1753f4709889
[gaim-migrate @ 12721]
Peter Lawler <pidgin@bleeter.id.au>
parents:
10654
diff
changeset
|
254 | gaim_xfer_cancel_remote(xfer); |
|
1753f4709889
[gaim-migrate @ 12721]
Peter Lawler <pidgin@bleeter.id.au>
parents:
10654
diff
changeset
|
255 | } |
| 8282 | 256 | } else { |
|
10937
1753f4709889
[gaim-migrate @ 12721]
Peter Lawler <pidgin@bleeter.id.au>
parents:
10654
diff
changeset
|
257 | if (gaim_proxy_connect(account, gaim_account_get_string(account, "xfer_host", YAHOO_XFER_HOST), |
|
1753f4709889
[gaim-migrate @ 12721]
Peter Lawler <pidgin@bleeter.id.au>
parents:
10654
diff
changeset
|
258 | gaim_account_get_int(account, "xfer_port", YAHOO_XFER_PORT), |
|
1753f4709889
[gaim-migrate @ 12721]
Peter Lawler <pidgin@bleeter.id.au>
parents:
10654
diff
changeset
|
259 | yahoo_sendfile_connected, xfer) == -1) |
|
1753f4709889
[gaim-migrate @ 12721]
Peter Lawler <pidgin@bleeter.id.au>
parents:
10654
diff
changeset
|
260 | { |
|
1753f4709889
[gaim-migrate @ 12721]
Peter Lawler <pidgin@bleeter.id.au>
parents:
10654
diff
changeset
|
261 | gaim_notify_error(gc, NULL, _("File Transfer Failed"), |
|
1753f4709889
[gaim-migrate @ 12721]
Peter Lawler <pidgin@bleeter.id.au>
parents:
10654
diff
changeset
|
262 | _("Unable to establish file descriptor.")); |
|
1753f4709889
[gaim-migrate @ 12721]
Peter Lawler <pidgin@bleeter.id.au>
parents:
10654
diff
changeset
|
263 | gaim_xfer_cancel_remote(xfer); |
| 8282 | 264 | } |
| 7651 | 265 | } |
| 266 | } else { | |
| 267 | xfer->fd = gaim_proxy_connect(account, xfer_data->host, xfer_data->port, | |
| 268 | yahoo_receivefile_connected, xfer); | |
| 269 | if (xfer->fd == -1) { | |
|
10654
b2dd3be1b087
[gaim-migrate @ 12182]
Richard Laager <rlaager@pidgin.im>
parents:
10651
diff
changeset
|
270 | gaim_notify_error(gc, NULL, _("File Transfer Failed"), |
| 7651 | 271 | _("Unable to establish file descriptor.")); |
| 272 | gaim_xfer_cancel_remote(xfer); | |
| 273 | } | |
| 274 | } | |
| 275 | } | |
| 276 | ||
| 277 | static void yahoo_xfer_start(GaimXfer *xfer) | |
| 278 | { | |
| 279 | /* We don't need to do anything here, do we? */ | |
| 280 | } | |
| 281 | ||
| 282 | static void yahoo_xfer_end(GaimXfer *xfer) | |
| 283 | { | |
| 284 | struct yahoo_xfer_data *xfer_data; | |
| 285 | ||
| 286 | xfer_data = xfer->data; | |
| 287 | ||
| 288 | if (xfer_data) | |
| 289 | yahoo_xfer_data_free(xfer_data); | |
| 290 | xfer->data = NULL; | |
| 291 | ||
| 292 | } | |
| 293 | ||
|
11897
10853b830964
[gaim-migrate @ 14188]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11801
diff
changeset
|
294 | static guint calculate_length(const gchar *l, size_t len) |
| 7651 | 295 | { |
| 296 | int i; | |
| 297 | ||
| 298 | for (i = 0; i < len; i++) { | |
| 299 | if (!g_ascii_isdigit(l[i])) | |
| 300 | continue; | |
| 301 | return strtol(l + i, NULL, 10); | |
| 302 | } | |
| 303 | return 0; | |
| 304 | } | |
| 305 | ||
|
12412
8abe3226695e
[gaim-migrate @ 14719]
Richard Laager <rlaager@pidgin.im>
parents:
12151
diff
changeset
|
306 | static gssize yahoo_xfer_read(guchar **buffer, GaimXfer *xfer) |
| 7651 | 307 | { |
| 7710 | 308 | gchar buf[4096]; |
|
12151
8002bb57756b
[gaim-migrate @ 14452]
Richard Laager <rlaager@pidgin.im>
parents:
12143
diff
changeset
|
309 | gssize len; |
| 7651 | 310 | gchar *start = NULL; |
| 311 | gchar *length; | |
| 312 | gchar *end; | |
| 7710 | 313 | int filelen; |
| 7651 | 314 | struct yahoo_xfer_data *xd = xfer->data; |
| 315 | ||
| 316 | if (gaim_xfer_get_type(xfer) != GAIM_XFER_RECEIVE) { | |
| 317 | return 0; | |
| 318 | } | |
| 319 | ||
| 320 | len = read(xfer->fd, buf, sizeof(buf)); | |
| 321 | ||
| 7682 | 322 | if (len <= 0) { |
| 7710 | 323 | if ((gaim_xfer_get_size(xfer) > 0) && |
| 9798 | 324 | (gaim_xfer_get_bytes_sent(xfer) >= gaim_xfer_get_size(xfer))) { |
| 7682 | 325 | gaim_xfer_set_completed(xfer, TRUE); |
| 9798 | 326 | return 0; |
| 327 | } else | |
| 328 | return -1; | |
| 7651 | 329 | } |
| 330 | ||
| 331 | if (!xd->started) { | |
| 332 | xd->rxqueue = g_realloc(xd->rxqueue, len + xd->rxlen); | |
| 333 | memcpy(xd->rxqueue + xd->rxlen, buf, len); | |
| 334 | xd->rxlen += len; | |
| 335 | ||
| 336 | length = g_strstr_len(xd->rxqueue, len, "Content-length:"); | |
|
10579
f4576b2e0956
[gaim-migrate @ 11976]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10576
diff
changeset
|
337 | /* some proxies re-write this header, changing the capitalization :( |
|
f4576b2e0956
[gaim-migrate @ 11976]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10576
diff
changeset
|
338 | * technically that's allowed since headers are case-insensitive |
|
f4576b2e0956
[gaim-migrate @ 11976]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10576
diff
changeset
|
339 | * [RFC 2616, section 4.2] */ |
|
f4576b2e0956
[gaim-migrate @ 11976]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10576
diff
changeset
|
340 | if (length == NULL) |
|
f4576b2e0956
[gaim-migrate @ 11976]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
10576
diff
changeset
|
341 | length = g_strstr_len(xd->rxqueue, len, "Content-Length:"); |
| 7651 | 342 | if (length) { |
| 343 | end = g_strstr_len(length, length - xd->rxqueue, "\r\n"); | |
| 344 | if (!end) | |
| 345 | return 0; | |
| 7710 | 346 | if ((filelen = calculate_length(length, len - (length - xd->rxqueue)))) |
| 347 | gaim_xfer_set_size(xfer, filelen); | |
| 7651 | 348 | } |
| 349 | start = g_strstr_len(xd->rxqueue, len, "\r\n\r\n"); | |
| 350 | if (start) | |
| 351 | start += 4; | |
| 352 | if (!start || start > (xd->rxqueue + len)) | |
| 353 | return 0; | |
| 354 | xd->started = TRUE; | |
| 355 | ||
| 356 | len -= (start - xd->rxqueue); | |
| 357 | ||
| 358 | *buffer = g_malloc(len); | |
| 359 | memcpy(*buffer, start, len); | |
| 360 | g_free(xd->rxqueue); | |
| 361 | xd->rxqueue = NULL; | |
| 362 | xd->rxlen = 0; | |
| 363 | } else { | |
| 364 | *buffer = g_malloc(len); | |
| 365 | memcpy(*buffer, buf, len); | |
| 366 | } | |
| 367 | ||
| 368 | return len; | |
| 369 | } | |
| 370 | ||
|
12412
8abe3226695e
[gaim-migrate @ 14719]
Richard Laager <rlaager@pidgin.im>
parents:
12151
diff
changeset
|
371 | static gssize yahoo_xfer_write(const guchar *buffer, size_t size, GaimXfer *xfer) |
| 7651 | 372 | { |
|
12151
8002bb57756b
[gaim-migrate @ 14452]
Richard Laager <rlaager@pidgin.im>
parents:
12143
diff
changeset
|
373 | gssize len; |
| 7651 | 374 | struct yahoo_xfer_data *xd = xfer->data; |
| 375 | ||
| 376 | if (!xd) | |
| 9798 | 377 | return -1; |
| 7651 | 378 | |
| 379 | if (gaim_xfer_get_type(xfer) != GAIM_XFER_SEND) { | |
| 9798 | 380 | return -1; |
| 7651 | 381 | } |
| 382 | ||
| 383 | len = write(xfer->fd, buffer, size); | |
| 384 | ||
| 7710 | 385 | if (len == -1) { |
| 386 | if (gaim_xfer_get_bytes_sent(xfer) >= gaim_xfer_get_size(xfer)) | |
| 387 | gaim_xfer_set_completed(xfer, TRUE); | |
| 388 | if ((errno != EAGAIN) && (errno != EINTR)) | |
| 9798 | 389 | return -1; |
| 7710 | 390 | return 0; |
| 391 | } | |
| 392 | ||
| 393 | if ((gaim_xfer_get_bytes_sent(xfer) + len) >= gaim_xfer_get_size(xfer)) | |
| 7651 | 394 | gaim_xfer_set_completed(xfer, TRUE); |
| 395 | ||
| 396 | return len; | |
| 397 | } | |
| 398 | ||
| 399 | static void yahoo_xfer_cancel_send(GaimXfer *xfer) | |
| 400 | { | |
| 401 | struct yahoo_xfer_data *xfer_data; | |
| 402 | ||
| 403 | xfer_data = xfer->data; | |
| 404 | ||
| 405 | if (xfer_data) | |
| 406 | yahoo_xfer_data_free(xfer_data); | |
| 407 | xfer->data = NULL; | |
| 408 | } | |
| 409 | ||
| 410 | static void yahoo_xfer_cancel_recv(GaimXfer *xfer) | |
| 411 | { | |
| 412 | struct yahoo_xfer_data *xfer_data; | |
| 413 | ||
| 414 | xfer_data = xfer->data; | |
| 415 | ||
| 416 | if (xfer_data) | |
| 417 | yahoo_xfer_data_free(xfer_data); | |
| 418 | xfer->data = NULL; | |
| 419 | } | |
| 420 | ||
|
11914
81ac838f3824
[gaim-migrate @ 14205]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11897
diff
changeset
|
421 | void yahoo_process_p2pfilexfer(GaimConnection *gc, struct yahoo_packet *pkt) |
|
11475
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
422 | { |
|
11914
81ac838f3824
[gaim-migrate @ 14205]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11897
diff
changeset
|
423 | GSList *l = pkt->hash; |
|
11644
939411169d01
[gaim-migrate @ 13922]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11475
diff
changeset
|
424 | |
|
11914
81ac838f3824
[gaim-migrate @ 14205]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11897
diff
changeset
|
425 | char *me = NULL; |
|
81ac838f3824
[gaim-migrate @ 14205]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11897
diff
changeset
|
426 | char *from = NULL; |
|
81ac838f3824
[gaim-migrate @ 14205]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11897
diff
changeset
|
427 | char *service = NULL; |
|
81ac838f3824
[gaim-migrate @ 14205]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11897
diff
changeset
|
428 | char *message = NULL; |
|
81ac838f3824
[gaim-migrate @ 14205]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11897
diff
changeset
|
429 | char *command = NULL; |
|
81ac838f3824
[gaim-migrate @ 14205]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11897
diff
changeset
|
430 | char *imv = NULL; |
|
81ac838f3824
[gaim-migrate @ 14205]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11897
diff
changeset
|
431 | char *unknown = NULL; |
|
11644
939411169d01
[gaim-migrate @ 13922]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11475
diff
changeset
|
432 | |
|
11801
c19b37ac661b
[gaim-migrate @ 14092]
Gary Kramlich <grim@reaperworld.com>
parents:
11644
diff
changeset
|
433 | /* Get all the necessary values from this new packet */ |
|
11914
81ac838f3824
[gaim-migrate @ 14205]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11897
diff
changeset
|
434 | while(l != NULL) |
|
11475
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
435 | { |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
436 | struct yahoo_pair *pair = l->data; |
|
11644
939411169d01
[gaim-migrate @ 13922]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11475
diff
changeset
|
437 | |
|
11914
81ac838f3824
[gaim-migrate @ 14205]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11897
diff
changeset
|
438 | if(pair->key == 5) /* Get who the packet is for */ |
|
11475
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
439 | me = pair->value; |
|
11644
939411169d01
[gaim-migrate @ 13922]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11475
diff
changeset
|
440 | |
|
11914
81ac838f3824
[gaim-migrate @ 14205]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11897
diff
changeset
|
441 | if(pair->key == 4) /* Get who the packet is from */ |
|
11475
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
442 | from = pair->value; |
|
11644
939411169d01
[gaim-migrate @ 13922]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11475
diff
changeset
|
443 | |
|
11914
81ac838f3824
[gaim-migrate @ 14205]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11897
diff
changeset
|
444 | if(pair->key == 49) /* Get the type of service */ |
|
11475
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
445 | service = pair->value; |
|
11644
939411169d01
[gaim-migrate @ 13922]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11475
diff
changeset
|
446 | |
|
11914
81ac838f3824
[gaim-migrate @ 14205]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11897
diff
changeset
|
447 | if(pair->key == 14) /* Get the 'message' of the packet */ |
|
11475
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
448 | message = pair->value; |
|
11644
939411169d01
[gaim-migrate @ 13922]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11475
diff
changeset
|
449 | |
|
11914
81ac838f3824
[gaim-migrate @ 14205]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11897
diff
changeset
|
450 | if(pair->key == 13) /* Get the command associated with this packet */ |
|
11475
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
451 | command = pair->value; |
|
11644
939411169d01
[gaim-migrate @ 13922]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11475
diff
changeset
|
452 | |
|
11914
81ac838f3824
[gaim-migrate @ 14205]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11897
diff
changeset
|
453 | if(pair->key == 63) /* IMVironment name and version */ |
|
11475
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
454 | imv = pair->value; |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
455 | |
|
11914
81ac838f3824
[gaim-migrate @ 14205]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11897
diff
changeset
|
456 | if(pair->key == 64) /* Not sure, but it does vary with initialization of Doodle */ |
|
81ac838f3824
[gaim-migrate @ 14205]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11897
diff
changeset
|
457 | unknown = pair->value; /* So, I'll keep it (for a little while atleast) */ |
|
11644
939411169d01
[gaim-migrate @ 13922]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11475
diff
changeset
|
458 | |
|
11475
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
459 | l = l->next; |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
460 | } |
|
11644
939411169d01
[gaim-migrate @ 13922]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11475
diff
changeset
|
461 | |
|
11801
c19b37ac661b
[gaim-migrate @ 14092]
Gary Kramlich <grim@reaperworld.com>
parents:
11644
diff
changeset
|
462 | /* If this packet is an IMVIRONMENT, handle it accordingly */ |
|
13459
c20f00df92e5
[gaim-migrate @ 15833]
Daniel Atallah <datallah@pidgin.im>
parents:
13277
diff
changeset
|
463 | if(service != NULL && imv != NULL && !strcmp(service, "IMVIRONMENT")) |
|
11475
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
464 | { |
|
11801
c19b37ac661b
[gaim-migrate @ 14092]
Gary Kramlich <grim@reaperworld.com>
parents:
11644
diff
changeset
|
465 | /* Check for a Doodle packet and handle it accordingly */ |
|
11914
81ac838f3824
[gaim-migrate @ 14205]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11897
diff
changeset
|
466 | if(!strcmp(imv, "doodle;11")) |
|
81ac838f3824
[gaim-migrate @ 14205]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11897
diff
changeset
|
467 | yahoo_doodle_process(gc, me, from, command, message); |
|
11644
939411169d01
[gaim-migrate @ 13922]
Peter Lawler <pidgin@bleeter.id.au>
parents:
11475
diff
changeset
|
468 | |
|
11801
c19b37ac661b
[gaim-migrate @ 14092]
Gary Kramlich <grim@reaperworld.com>
parents:
11644
diff
changeset
|
469 | /* If an IMVIRONMENT packet comes without a specific imviroment name */ |
|
11914
81ac838f3824
[gaim-migrate @ 14205]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11897
diff
changeset
|
470 | if(!strcmp(imv, ";0")) |
|
11475
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
471 | { |
|
11914
81ac838f3824
[gaim-migrate @ 14205]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11897
diff
changeset
|
472 | /* It is unfortunately time to close all IMVironments with the remote client */ |
|
81ac838f3824
[gaim-migrate @ 14205]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11897
diff
changeset
|
473 | yahoo_doodle_command_got_shutdown(gc, from); |
|
11475
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
474 | } |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
475 | } |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
476 | } |
|
1e222e6e52a0
[gaim-migrate @ 13717]
Gary Kramlich <grim@reaperworld.com>
parents:
11159
diff
changeset
|
477 | |
| 7651 | 478 | void yahoo_process_filetransfer(GaimConnection *gc, struct yahoo_packet *pkt) |
| 479 | { | |
| 480 | char *from = NULL; | |
| 481 | char *to = NULL; | |
| 482 | char *msg = NULL; | |
| 483 | char *url = NULL; | |
|
13851
27bc39ea07f8
[gaim-migrate @ 16306]
Mark Doliner <markdoliner@pidgin.im>
parents:
13713
diff
changeset
|
484 | char *imv = NULL; |
| 7651 | 485 | long expires = 0; |
| 486 | GaimXfer *xfer; | |
|
13851
27bc39ea07f8
[gaim-migrate @ 16306]
Mark Doliner <markdoliner@pidgin.im>
parents:
13713
diff
changeset
|
487 | struct yahoo_data *yd; |
| 7651 | 488 | struct yahoo_xfer_data *xfer_data; |
| 489 | char *service = NULL; | |
| 490 | char *filename = NULL; | |
| 491 | unsigned long filesize = 0L; | |
| 492 | GSList *l; | |
| 493 | ||
|
13851
27bc39ea07f8
[gaim-migrate @ 16306]
Mark Doliner <markdoliner@pidgin.im>
parents:
13713
diff
changeset
|
494 | yd = gc->proto_data; |
|
27bc39ea07f8
[gaim-migrate @ 16306]
Mark Doliner <markdoliner@pidgin.im>
parents:
13713
diff
changeset
|
495 | |
| 7651 | 496 | for (l = pkt->hash; l; l = l->next) { |
| 497 | struct yahoo_pair *pair = l->data; | |
| 498 | ||
| 499 | if (pair->key == 4) | |
| 500 | from = pair->value; | |
| 501 | if (pair->key == 5) | |
| 502 | to = pair->value; | |
| 503 | if (pair->key == 14) | |
| 504 | msg = pair->value; | |
| 505 | if (pair->key == 20) | |
| 506 | url = pair->value; | |
| 507 | if (pair->key == 38) | |
| 508 | expires = strtol(pair->value, NULL, 10); | |
| 509 | if (pair->key == 27) | |
| 510 | filename = pair->value; | |
| 511 | if (pair->key == 28) | |
| 512 | filesize = atol(pair->value); | |
| 513 | if (pair->key == 49) | |
| 514 | service = pair->value; | |
|
13851
27bc39ea07f8
[gaim-migrate @ 16306]
Mark Doliner <markdoliner@pidgin.im>
parents:
13713
diff
changeset
|
515 | if (pair->key == 63) |
|
27bc39ea07f8
[gaim-migrate @ 16306]
Mark Doliner <markdoliner@pidgin.im>
parents:
13713
diff
changeset
|
516 | imv = pair->value; |
|
27bc39ea07f8
[gaim-migrate @ 16306]
Mark Doliner <markdoliner@pidgin.im>
parents:
13713
diff
changeset
|
517 | } |
|
27bc39ea07f8
[gaim-migrate @ 16306]
Mark Doliner <markdoliner@pidgin.im>
parents:
13713
diff
changeset
|
518 | |
|
27bc39ea07f8
[gaim-migrate @ 16306]
Mark Doliner <markdoliner@pidgin.im>
parents:
13713
diff
changeset
|
519 | /* |
|
27bc39ea07f8
[gaim-migrate @ 16306]
Mark Doliner <markdoliner@pidgin.im>
parents:
13713
diff
changeset
|
520 | * The remote user has changed their IMVironment. We |
|
27bc39ea07f8
[gaim-migrate @ 16306]
Mark Doliner <markdoliner@pidgin.im>
parents:
13713
diff
changeset
|
521 | * record it for later use. |
|
27bc39ea07f8
[gaim-migrate @ 16306]
Mark Doliner <markdoliner@pidgin.im>
parents:
13713
diff
changeset
|
522 | */ |
|
27bc39ea07f8
[gaim-migrate @ 16306]
Mark Doliner <markdoliner@pidgin.im>
parents:
13713
diff
changeset
|
523 | if (from && imv && service && (strcmp("IMVIRONMENT", service) == 0)) { |
|
27bc39ea07f8
[gaim-migrate @ 16306]
Mark Doliner <markdoliner@pidgin.im>
parents:
13713
diff
changeset
|
524 | g_hash_table_replace(yd->imvironments, g_strdup(from), g_strdup(imv)); |
|
27bc39ea07f8
[gaim-migrate @ 16306]
Mark Doliner <markdoliner@pidgin.im>
parents:
13713
diff
changeset
|
525 | return; |
| 7651 | 526 | } |
| 527 | ||
| 528 | if (pkt->service == YAHOO_SERVICE_P2PFILEXFER) { | |
| 10261 | 529 | if (service && (strcmp("FILEXFER", service) != 0)) { |
|
13467
f86303a455ae
[gaim-migrate @ 15841]
Richard Laager <rlaager@pidgin.im>
parents:
13459
diff
changeset
|
530 | gaim_debug_misc("yahoo", "unhandled service 0x%02x\n", pkt->service); |
| 7651 | 531 | return; |
| 532 | } | |
| 533 | } | |
| 534 | ||
| 535 | if (msg) { | |
| 536 | char *tmp; | |
| 537 | tmp = strchr(msg, '\006'); | |
| 538 | if (tmp) | |
| 539 | *tmp = '\0'; | |
| 540 | } | |
| 541 | ||
| 542 | if (!url || !from) | |
| 543 | return; | |
| 544 | ||
| 545 | /* Setup the Yahoo-specific file transfer data */ | |
| 546 | xfer_data = g_new0(struct yahoo_xfer_data, 1); | |
| 547 | xfer_data->gc = gc; | |
| 9227 | 548 | if (!gaim_url_parse(url, &(xfer_data->host), &(xfer_data->port), &(xfer_data->path), NULL, NULL)) { |
| 7651 | 549 | g_free(xfer_data); |
| 550 | return; | |
| 551 | } | |
| 552 | ||
| 553 | gaim_debug_misc("yahoo_filexfer", "Host is %s, port is %d, path is %s, and the full url was %s.\n", | |
| 554 | xfer_data->host, xfer_data->port, xfer_data->path, url); | |
| 555 | ||
| 556 | /* Build the file transfer handle. */ | |
| 557 | xfer = gaim_xfer_new(gc->account, GAIM_XFER_RECEIVE, from); | |
| 558 | xfer->data = xfer_data; | |
| 559 | ||
| 560 | /* Set the info about the incoming file. */ | |
|
10976
96153d16e808
[gaim-migrate @ 12802]
Daniel Atallah <datallah@pidgin.im>
parents:
10937
diff
changeset
|
561 | if (filename) { |
|
96153d16e808
[gaim-migrate @ 12802]
Daniel Atallah <datallah@pidgin.im>
parents:
10937
diff
changeset
|
562 | char *utf8_filename = yahoo_string_decode(gc, filename, TRUE); |
|
96153d16e808
[gaim-migrate @ 12802]
Daniel Atallah <datallah@pidgin.im>
parents:
10937
diff
changeset
|
563 | gaim_xfer_set_filename(xfer, utf8_filename); |
|
96153d16e808
[gaim-migrate @ 12802]
Daniel Atallah <datallah@pidgin.im>
parents:
10937
diff
changeset
|
564 | g_free(utf8_filename); |
|
96153d16e808
[gaim-migrate @ 12802]
Daniel Atallah <datallah@pidgin.im>
parents:
10937
diff
changeset
|
565 | } else { |
| 7651 | 566 | gchar *start, *end; |
| 567 | start = g_strrstr(xfer_data->path, "/"); | |
| 568 | if (start) | |
| 569 | start++; | |
| 570 | end = g_strrstr(xfer_data->path, "?"); | |
| 571 | if (start && *start && end) { | |
|
10976
96153d16e808
[gaim-migrate @ 12802]
Daniel Atallah <datallah@pidgin.im>
parents:
10937
diff
changeset
|
572 | char *utf8_filename; |
| 7651 | 573 | filename = g_strndup(start, end - start); |
|
10976
96153d16e808
[gaim-migrate @ 12802]
Daniel Atallah <datallah@pidgin.im>
parents:
10937
diff
changeset
|
574 | utf8_filename = yahoo_string_decode(gc, filename, TRUE); |
| 7651 | 575 | g_free(filename); |
|
10976
96153d16e808
[gaim-migrate @ 12802]
Daniel Atallah <datallah@pidgin.im>
parents:
10937
diff
changeset
|
576 | gaim_xfer_set_filename(xfer, utf8_filename); |
|
96153d16e808
[gaim-migrate @ 12802]
Daniel Atallah <datallah@pidgin.im>
parents:
10937
diff
changeset
|
577 | g_free(utf8_filename); |
| 7651 | 578 | filename = NULL; |
| 579 | } | |
| 580 | } | |
| 581 | ||
| 582 | gaim_xfer_set_size(xfer, filesize); | |
| 583 | ||
| 584 | /* Setup our I/O op functions */ | |
| 585 | gaim_xfer_set_init_fnc(xfer, yahoo_xfer_init); | |
| 586 | gaim_xfer_set_start_fnc(xfer, yahoo_xfer_start); | |
| 587 | gaim_xfer_set_end_fnc(xfer, yahoo_xfer_end); | |
| 588 | gaim_xfer_set_cancel_send_fnc(xfer, yahoo_xfer_cancel_send); | |
| 589 | gaim_xfer_set_cancel_recv_fnc(xfer, yahoo_xfer_cancel_recv); | |
| 590 | gaim_xfer_set_read_fnc(xfer, yahoo_xfer_read); | |
| 591 | gaim_xfer_set_write_fnc(xfer, yahoo_xfer_write); | |
| 592 | ||
| 593 | /* Now perform the request */ | |
| 594 | gaim_xfer_request(xfer); | |
| 595 | } | |
| 596 | ||
|
12143
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11914
diff
changeset
|
597 | GaimXfer *yahoo_new_xfer(GaimConnection *gc, const char *who) |
| 7651 | 598 | { |
| 599 | GaimXfer *xfer; | |
| 600 | struct yahoo_xfer_data *xfer_data; | |
|
12143
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11914
diff
changeset
|
601 | |
|
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11914
diff
changeset
|
602 | g_return_val_if_fail(who != NULL, NULL); |
|
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11914
diff
changeset
|
603 | |
| 7651 | 604 | xfer_data = g_new0(struct yahoo_xfer_data, 1); |
| 605 | xfer_data->gc = gc; | |
|
12143
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11914
diff
changeset
|
606 | |
| 7651 | 607 | /* Build the file transfer handle. */ |
| 608 | xfer = gaim_xfer_new(gc->account, GAIM_XFER_SEND, who); | |
| 609 | xfer->data = xfer_data; | |
|
12143
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11914
diff
changeset
|
610 | |
| 7651 | 611 | /* Setup our I/O op functions */ |
| 612 | gaim_xfer_set_init_fnc(xfer, yahoo_xfer_init); | |
| 613 | gaim_xfer_set_start_fnc(xfer, yahoo_xfer_start); | |
| 614 | gaim_xfer_set_end_fnc(xfer, yahoo_xfer_end); | |
| 615 | gaim_xfer_set_cancel_send_fnc(xfer, yahoo_xfer_cancel_send); | |
| 616 | gaim_xfer_set_cancel_recv_fnc(xfer, yahoo_xfer_cancel_recv); | |
| 617 | gaim_xfer_set_read_fnc(xfer, yahoo_xfer_read); | |
| 618 | gaim_xfer_set_write_fnc(xfer, yahoo_xfer_write); | |
| 619 | ||
|
12143
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11914
diff
changeset
|
620 | return xfer; |
|
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11914
diff
changeset
|
621 | } |
|
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11914
diff
changeset
|
622 | |
|
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11914
diff
changeset
|
623 | void yahoo_send_file(GaimConnection *gc, const char *who, const char *file) |
|
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11914
diff
changeset
|
624 | { |
|
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11914
diff
changeset
|
625 | GaimXfer *xfer = yahoo_new_xfer(gc, who); |
|
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11914
diff
changeset
|
626 | |
|
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11914
diff
changeset
|
627 | g_return_if_fail(xfer != NULL); |
|
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11914
diff
changeset
|
628 | |
| 7651 | 629 | /* Now perform the request */ |
|
11914
81ac838f3824
[gaim-migrate @ 14205]
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents:
11897
diff
changeset
|
630 | if (file) |
|
9466
b6425eab60ca
[gaim-migrate @ 10291]
Daniel Atallah <datallah@pidgin.im>
parents:
9306
diff
changeset
|
631 | gaim_xfer_request_accepted(xfer, file); |
|
b6425eab60ca
[gaim-migrate @ 10291]
Daniel Atallah <datallah@pidgin.im>
parents:
9306
diff
changeset
|
632 | else |
|
b6425eab60ca
[gaim-migrate @ 10291]
Daniel Atallah <datallah@pidgin.im>
parents:
9306
diff
changeset
|
633 | gaim_xfer_request(xfer); |
| 7651 | 634 | } |