Mercurial > pidgin
annotate src/protocols/msn/ft.c @ 5547:90a67ea697f7
[gaim-migrate @ 5948]
Some more convertination.
committer: Tailor Script <tailor@pidgin.im>
| author | Christian Hammond <chipx86@chipx86.com> |
|---|---|
| date | Thu, 29 May 2003 19:48:13 +0000 |
| parents | abe4d103e300 |
| children | 187c740f2a4e |
| rev | line source |
|---|---|
| 4542 | 1 /** |
| 2 * @file msn.c The MSN protocol plugin | |
| 3 * | |
| 4 * gaim | |
| 5 * | |
| 6 * Copyright (C) 2003, Christian Hammond <chipx86@gnupdate.org> | |
| 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 "msn.h" | |
| 24 | |
|
4546
a951bb590857
[gaim-migrate @ 4825]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4542
diff
changeset
|
25 #ifdef _WIN32 |
|
a951bb590857
[gaim-migrate @ 4825]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4542
diff
changeset
|
26 #include "win32dep.h" |
|
a951bb590857
[gaim-migrate @ 4825]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4542
diff
changeset
|
27 #endif |
|
a951bb590857
[gaim-migrate @ 4825]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
4542
diff
changeset
|
28 |
| 4542 | 29 G_MODULE_IMPORT GSList *connections; |
| 30 | |
| 31 static struct gaim_xfer * | |
| 32 find_xfer_by_cookie(struct gaim_connection *gc, unsigned long cookie) | |
| 33 { | |
| 34 GSList *g; | |
| 35 struct msn_data *md = (struct msn_data *)gc->proto_data; | |
| 36 struct gaim_xfer *xfer = NULL; | |
| 37 struct msn_xfer_data *xfer_data; | |
| 38 | |
| 39 for (g = md->file_transfers; g != NULL; g = g->next) { | |
| 40 xfer = (struct gaim_xfer *)g->data; | |
| 41 xfer_data = (struct msn_xfer_data *)xfer->data; | |
| 42 | |
| 43 if (xfer_data->cookie == cookie) | |
| 44 break; | |
| 45 | |
| 46 xfer = NULL; | |
| 47 } | |
| 48 | |
| 49 return xfer; | |
| 50 } | |
| 51 | |
| 52 static void | |
| 53 msn_xfer_init(struct gaim_xfer *xfer) | |
| 54 { | |
| 55 struct gaim_account *account; | |
| 56 struct msn_xfer_data *xfer_data; | |
| 57 struct msn_switchboard *ms; | |
| 58 char header[MSN_BUF_LEN]; | |
| 59 char buf[MSN_BUF_LEN]; | |
| 60 | |
| 61 account = gaim_xfer_get_account(xfer); | |
| 62 | |
| 63 ms = msn_find_switch(account->gc, xfer->who); | |
| 64 | |
| 65 xfer_data = (struct msn_xfer_data *)xfer->data; | |
| 66 | |
| 67 if (gaim_xfer_get_type(xfer) == GAIM_XFER_RECEIVE) { | |
| 68 /* | |
| 69 * NOTE: We actually have to wait for the next Invitation message | |
| 70 * before the transfer starts. We handle that in | |
| 71 * msn_xfer_start(). | |
| 72 */ | |
| 73 | |
| 74 g_snprintf(header, sizeof(header), | |
| 75 "MIME-Version: 1.0\r\n" | |
| 76 "Content-Type: text/x-msmsgsinvite; charset=UTF-8\r\n\r\n" | |
| 77 "Invitation-Command: ACCEPT\r\n" | |
| 78 "Invitation-Cookie: %lu\r\n" | |
| 79 "Launch-Application: FALSE\r\n" | |
| 80 "Request-Data: IP-Address:\r\n", | |
| 81 (unsigned long)xfer_data->cookie); | |
| 82 | |
| 83 g_snprintf(buf, sizeof(buf), "MSG %u N %d\r\n%s\r\n\r\n", | |
| 84 ++ms->trId, strlen(header) + strlen("\r\n\r\n"), | |
| 85 header); | |
| 86 | |
| 87 if (msn_write(ms->fd, buf, strlen(buf)) < 0) { | |
| 88 msn_kill_switch(ms); | |
| 89 gaim_xfer_destroy(xfer); | |
| 90 | |
| 91 return; | |
| 92 } | |
| 93 } | |
| 94 } | |
| 95 | |
| 96 static void | |
| 97 msn_xfer_start(struct gaim_xfer *xfer) | |
| 98 { | |
| 99 struct msn_xfer_data *xfer_data; | |
| 100 | |
| 101 xfer_data = (struct msn_xfer_data *)xfer->data; | |
| 102 | |
| 103 xfer_data->transferring = TRUE; | |
| 104 | |
| 105 if (gaim_xfer_get_type(xfer) == GAIM_XFER_RECEIVE) { | |
| 106 char sendbuf[MSN_BUF_LEN]; | |
| 107 | |
| 108 /* Send the TFR string to request the start of a transfer. */ | |
| 109 g_snprintf(sendbuf, sizeof(sendbuf), "TFR\r\n"); | |
| 110 | |
| 111 if (msn_write(xfer->fd, sendbuf, strlen(sendbuf)) < 0) { | |
|
4675
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
112 gaim_xfer_cancel_remote(xfer); |
| 4542 | 113 } |
| 114 } | |
| 115 } | |
| 116 | |
| 117 static void | |
| 118 msn_xfer_end(struct gaim_xfer *xfer) | |
| 119 { | |
| 120 struct gaim_account *account; | |
| 121 struct msn_xfer_data *xfer_data; | |
| 122 struct msn_data *md; | |
| 123 | |
| 124 account = gaim_xfer_get_account(xfer); | |
| 125 xfer_data = (struct msn_xfer_data *)xfer->data; | |
| 126 md = (struct msn_data *)account->gc->proto_data; | |
| 127 | |
| 128 if (gaim_xfer_get_type(xfer) == GAIM_XFER_RECEIVE) { | |
| 129 char sendbuf[MSN_BUF_LEN]; | |
| 130 | |
| 131 g_snprintf(sendbuf, sizeof(sendbuf), "BYE 16777989\r\n"); | |
| 132 | |
| 133 msn_write(xfer->fd, sendbuf, strlen(sendbuf)); | |
| 134 | |
| 135 md->file_transfers = g_slist_remove(md->file_transfers, xfer); | |
| 136 | |
| 137 g_free(xfer_data); | |
| 138 xfer->data = NULL; | |
| 139 } | |
| 140 } | |
| 141 | |
| 142 static void | |
|
4675
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
143 msn_xfer_cancel_send(struct gaim_xfer *xfer) |
|
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
144 { |
|
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
145 struct gaim_account *account; |
|
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
146 struct msn_xfer_data *xfer_data; |
|
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
147 struct msn_data *md; |
|
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
148 |
|
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
149 xfer_data = (struct msn_xfer_data *)xfer->data; |
|
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
150 |
|
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
151 xfer_data->do_cancel = TRUE; |
|
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
152 |
|
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
153 account = gaim_xfer_get_account(xfer); |
|
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
154 md = (struct msn_data *)account->gc->proto_data; |
|
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
155 |
|
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
156 md->file_transfers = g_slist_remove(md->file_transfers, xfer); |
|
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
157 |
|
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
158 g_free(xfer_data); |
|
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
159 xfer->data = NULL; |
|
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
160 } |
|
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
161 |
|
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
162 static void |
|
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
163 msn_xfer_cancel_recv(struct gaim_xfer *xfer) |
| 4542 | 164 { |
| 165 struct gaim_account *account; | |
| 166 struct msn_xfer_data *xfer_data; | |
| 167 struct msn_data *md; | |
| 168 | |
| 169 account = gaim_xfer_get_account(xfer); | |
| 170 xfer_data = (struct msn_xfer_data *)xfer->data; | |
| 171 md = (struct msn_data *)account->gc->proto_data; | |
| 172 | |
|
4675
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
173 md->file_transfers = g_slist_remove(md->file_transfers, xfer); |
| 4542 | 174 |
|
4675
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
175 g_free(xfer_data); |
|
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
176 xfer->data = NULL; |
| 4542 | 177 } |
| 178 | |
| 179 static size_t | |
| 180 msn_xfer_read(char **buffer, struct gaim_xfer *xfer) | |
| 181 { | |
|
4675
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
182 struct msn_xfer_data *xfer_data; |
| 4542 | 183 unsigned char header[3]; |
| 184 size_t len, size; | |
| 185 | |
|
4675
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
186 xfer_data = (struct msn_xfer_data *)xfer->data; |
|
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
187 |
|
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
188 if (xfer_data->do_cancel) |
|
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
189 { |
|
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
190 write(xfer->fd, "CCL\n", 4); |
|
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
191 |
|
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
192 return 0; |
|
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
193 } |
|
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
194 |
| 4542 | 195 if (read(xfer->fd, header, sizeof(header)) < 3) { |
| 196 gaim_xfer_set_completed(xfer, TRUE); | |
| 197 return 0; | |
| 198 } | |
| 199 | |
| 200 if (header[0] != 0) { | |
|
5221
abe4d103e300
[gaim-migrate @ 5591]
Christian Hammond <chipx86@chipx86.com>
parents:
4793
diff
changeset
|
201 gaim_debug(GAIM_DEBUG_ERROR, "msn", |
|
abe4d103e300
[gaim-migrate @ 5591]
Christian Hammond <chipx86@chipx86.com>
parents:
4793
diff
changeset
|
202 "MSNFTP: Invalid header[0]: %d. Aborting.\n", |
|
abe4d103e300
[gaim-migrate @ 5591]
Christian Hammond <chipx86@chipx86.com>
parents:
4793
diff
changeset
|
203 header[0]); |
| 4542 | 204 return 0; |
| 205 } | |
| 206 | |
| 207 size = header[1] | (header[2] << 8); | |
| 208 | |
| 209 *buffer = g_new0(char, size); | |
| 210 | |
| 211 for (len = 0; | |
| 212 len < size; | |
| 213 len += read(xfer->fd, *buffer + len, size - len)) | |
| 214 ; | |
| 215 | |
| 216 if (len == 0) | |
| 217 gaim_xfer_set_completed(xfer, TRUE); | |
| 218 | |
| 219 return len; | |
| 220 } | |
| 221 | |
| 222 static size_t | |
| 223 msn_xfer_write(const char *buffer, size_t size, struct gaim_xfer *xfer) | |
| 224 { | |
|
4675
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
225 struct gaim_account *account; |
|
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
226 struct msn_xfer_data *xfer_data; |
|
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
227 struct msn_data *md; |
|
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
228 unsigned char header[3]; |
|
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
229 |
|
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
230 xfer_data = (struct msn_xfer_data *)xfer->data; |
|
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
231 account = gaim_xfer_get_account(xfer); |
|
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
232 md = (struct msn_data *)account->gc->proto_data; |
|
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
233 |
|
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
234 if (xfer_data->do_cancel) |
|
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
235 { |
|
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
236 header[0] = 1; |
|
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
237 header[1] = 0; |
|
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
238 header[2] = 0; |
|
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
239 |
|
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
240 if (write(xfer->fd, header, sizeof(header)) < 3) { |
|
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
241 gaim_xfer_cancel_remote(xfer); |
|
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
242 return 0; |
|
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
243 } |
|
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
244 } |
|
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
245 else |
|
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
246 { |
|
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
247 /* Not implemented yet. */ |
|
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
248 } |
|
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
249 |
| 4542 | 250 return 0; |
| 251 } | |
| 252 | |
| 253 static int | |
| 254 msn_process_msnftp(struct gaim_xfer *xfer, gint source, const char *buf) | |
| 255 { | |
| 256 struct msn_xfer_data *xfer_data; | |
| 257 struct gaim_account *account; | |
| 258 char sendbuf[MSN_BUF_LEN]; | |
| 259 | |
| 260 xfer_data = (struct msn_xfer_data *)xfer->data; | |
| 261 account = gaim_xfer_get_account(xfer); | |
| 262 | |
| 4793 | 263 if (!g_ascii_strncasecmp(buf, "VER MSNFTP", 10)) { |
| 4542 | 264 /* Send the USR string */ |
| 265 g_snprintf(sendbuf, sizeof(sendbuf), "USR %s %lu\r\n", | |
| 266 account->gc->username, | |
| 267 (unsigned long)xfer_data->authcookie); | |
| 268 | |
| 269 if (msn_write(source, sendbuf, strlen(sendbuf)) < 0) { | |
|
4675
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
270 gaim_xfer_cancel_remote(xfer); /* ? */ |
| 4542 | 271 |
| 272 return 0; | |
| 273 } | |
| 274 } | |
| 4793 | 275 else if (!g_ascii_strncasecmp(buf, "FIL", 3)) { |
| 4542 | 276 gaim_input_remove(xfer_data->inpa); |
| 277 xfer_data->inpa = 0; | |
| 278 | |
| 279 gaim_xfer_start(xfer, source, NULL, 0); | |
| 280 } | |
| 281 #if 0 | |
| 282 char *tmp = buf; | |
| 283 | |
| 284 /* | |
| 285 * This data is the size, but we already have | |
| 286 * the size, so who cares. | |
| 287 */ | |
| 288 GET_NEXT(tmp); | |
| 289 | |
| 290 /* Send the TFR string to request the start of a transfer. */ | |
| 291 g_snprintf(sendbuf, sizeof(sendbuf), "TFR\r\n"); | |
| 292 | |
| 293 | |
| 294 if (msn_write(source, sendbuf, strlen(sendbuf)) < 0) { | |
| 295 gaim_xfer_cancel(xfer); | |
| 296 | |
| 297 return 0; | |
| 298 } | |
| 299 #endif | |
| 300 | |
| 301 return 1; | |
| 302 } | |
| 303 | |
| 304 static void | |
| 305 msn_msnftp_cb(gpointer data, gint source, GaimInputCondition cond) | |
| 306 { | |
| 307 struct gaim_xfer *xfer; | |
| 308 struct msn_xfer_data *xfer_data; | |
| 309 char buf[MSN_BUF_LEN]; | |
| 310 gboolean cont = TRUE; | |
| 311 size_t len; | |
| 312 | |
| 313 xfer = (struct gaim_xfer *)data; | |
| 314 xfer_data = (struct msn_xfer_data *)xfer->data; | |
| 315 | |
| 316 len = read(source, buf, sizeof(buf)); | |
| 317 | |
| 318 if (len <= 0) { | |
|
4675
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
319 gaim_xfer_cancel_remote(xfer); |
| 4542 | 320 return; |
| 321 } | |
| 322 | |
| 323 xfer_data->rxqueue = g_realloc(xfer_data->rxqueue, | |
| 324 len + xfer_data->rxlen); | |
| 325 memcpy(xfer_data->rxqueue + xfer_data->rxlen, buf, len); | |
| 326 xfer_data->rxlen += len; | |
| 327 | |
| 328 while (cont) { | |
| 329 char *end = xfer_data->rxqueue; | |
| 330 char *cmd; | |
| 331 int cmdlen; | |
| 332 int i = 0; | |
| 333 | |
| 334 if (!xfer_data->rxlen) | |
| 335 return; | |
| 336 | |
| 337 for (i = 0; i < xfer_data->rxlen - 1; end++, i++) { | |
| 338 if (*end == '\r' && *(end + 1) == '\n') | |
| 339 break; | |
| 340 } | |
| 341 | |
| 342 if (i == xfer_data->rxlen - 1) | |
| 343 return; | |
| 344 | |
| 345 cmdlen = end - xfer_data->rxqueue + 2; | |
| 346 cmd = xfer_data->rxqueue; | |
| 347 | |
| 348 xfer_data->rxlen -= cmdlen; | |
| 349 | |
| 350 if (xfer_data->rxlen) | |
| 351 xfer_data->rxqueue = g_memdup(cmd + cmdlen, xfer_data->rxlen); | |
| 352 else { | |
| 353 xfer_data->rxqueue = NULL; | |
| 354 cmd = g_realloc(cmd, cmdlen + 1); | |
| 355 } | |
| 356 | |
| 357 cmd[cmdlen] = '\0'; | |
| 358 | |
| 359 g_strchomp(cmd); | |
| 360 | |
| 361 cont = msn_process_msnftp(xfer, source, cmd); | |
| 362 | |
| 363 g_free(cmd); | |
| 364 } | |
| 365 } | |
| 366 | |
| 367 static void | |
| 368 msn_msnftp_connect(gpointer data, gint source, GaimInputCondition cond) | |
| 369 { | |
| 370 struct gaim_account *account; | |
| 371 struct gaim_xfer *xfer; | |
| 372 struct msn_xfer_data *xfer_data; | |
| 373 char buf[MSN_BUF_LEN]; | |
| 374 | |
| 375 xfer = (struct gaim_xfer *)data; | |
| 376 account = gaim_xfer_get_account(xfer); | |
| 377 xfer_data = (struct msn_xfer_data *)xfer->data; | |
| 378 | |
| 379 if (source == -1 || !g_slist_find(connections, account->gc)) { | |
|
5221
abe4d103e300
[gaim-migrate @ 5591]
Christian Hammond <chipx86@chipx86.com>
parents:
4793
diff
changeset
|
380 gaim_debug(GAIM_DEBUG_ERROR, "msn", |
|
abe4d103e300
[gaim-migrate @ 5591]
Christian Hammond <chipx86@chipx86.com>
parents:
4793
diff
changeset
|
381 "MSNFTP: Error establishing connection\n"); |
| 4542 | 382 close(source); |
| 383 | |
|
4675
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
384 gaim_xfer_cancel_remote(xfer); |
| 4542 | 385 |
| 386 return; | |
| 387 } | |
| 388 | |
| 389 g_snprintf(buf, sizeof(buf), "VER MSNFTP\r\n"); | |
| 390 | |
| 391 if (msn_write(source, buf, strlen(buf)) < 0) { | |
|
4675
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
392 gaim_xfer_cancel_remote(xfer); |
| 4542 | 393 return; |
| 394 } | |
| 395 | |
| 396 xfer_data->inpa = gaim_input_add(source, GAIM_INPUT_READ, | |
| 397 msn_msnftp_cb, xfer); | |
| 398 } | |
| 399 | |
| 400 void | |
| 401 msn_process_ft_msg(struct msn_switchboard *ms, char *msg) | |
| 402 { | |
| 403 struct gaim_xfer *xfer; | |
| 404 struct msn_xfer_data *xfer_data; | |
| 405 struct msn_data *md = ms->gc->proto_data; | |
| 406 char *tmp = msg; | |
| 407 | |
| 408 if (strstr(msg, "Application-GUID: " MSN_FT_GUID) && | |
| 409 strstr(msg, "Invitation-Command: INVITE")) { | |
| 410 | |
| 411 /* | |
| 412 * First invitation message, requesting an ACCEPT or CANCEL from | |
| 413 * the recipient. Used in incoming file transfers. | |
| 414 */ | |
| 415 | |
| 416 char *filename; | |
| 417 char *cookie_s, *filesize_s; | |
| 418 | |
| 419 tmp = strstr(msg, "Invitation-Cookie"); | |
| 420 GET_NEXT(tmp); | |
| 421 cookie_s = tmp; | |
| 422 GET_NEXT(tmp); | |
| 423 GET_NEXT(tmp); | |
| 424 filename = tmp; | |
| 425 | |
| 426 /* Needed for filenames with spaces */ | |
| 427 tmp = strchr(tmp, '\r'); | |
| 428 *tmp = '\0'; | |
| 429 tmp += 2; | |
| 430 | |
| 431 GET_NEXT(tmp); | |
| 432 filesize_s = tmp; | |
| 433 GET_NEXT(tmp); | |
| 434 | |
| 435 /* Setup the MSN-specific file transfer data */ | |
| 436 xfer_data = g_new0(struct msn_xfer_data, 1); | |
| 437 xfer_data->cookie = atoi(cookie_s); | |
| 438 xfer_data->transferring = FALSE; | |
| 439 | |
| 440 /* Build the file transfer handle. */ | |
| 441 xfer = gaim_xfer_new(ms->gc->account, GAIM_XFER_RECEIVE, ms->msguser); | |
| 442 xfer->data = xfer_data; | |
| 443 | |
| 444 /* Set the info about the incoming file. */ | |
| 445 gaim_xfer_set_filename(xfer, filename); | |
| 446 gaim_xfer_set_size(xfer, atoi(filesize_s)); | |
| 447 | |
| 448 /* Setup our I/O op functions */ | |
|
4675
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
449 gaim_xfer_set_init_fnc(xfer, msn_xfer_init); |
|
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
450 gaim_xfer_set_start_fnc(xfer, msn_xfer_start); |
|
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
451 gaim_xfer_set_end_fnc(xfer, msn_xfer_end); |
|
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
452 gaim_xfer_set_cancel_send_fnc(xfer, msn_xfer_cancel_send); |
|
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
453 gaim_xfer_set_cancel_recv_fnc(xfer, msn_xfer_cancel_recv); |
|
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
454 gaim_xfer_set_read_fnc(xfer, msn_xfer_read); |
|
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
455 gaim_xfer_set_write_fnc(xfer, msn_xfer_write); |
| 4542 | 456 |
| 457 /* Keep track of this transfer for later. */ | |
| 458 md->file_transfers = g_slist_append(md->file_transfers, xfer); | |
| 459 | |
| 460 /* Now perform the request */ | |
| 461 gaim_xfer_request(xfer); | |
| 462 } | |
| 463 else if (strstr(msg, "Invitation-Command: ACCEPT")) { | |
| 464 | |
| 465 /* | |
| 466 * XXX I hope these checks don't return false positives, but they | |
| 467 * seem like they should work. The only issue is alternative | |
| 468 * protocols, *maybe*. | |
| 469 */ | |
| 470 | |
| 471 if (strstr(msg, "AuthCookie:")) { | |
| 472 | |
| 473 /* | |
| 474 * Second invitation request, sent after the recipient accepts | |
| 475 * the request. Used in incoming file transfers. | |
| 476 */ | |
| 477 char *cookie_s, *ip, *port_s, *authcookie_s; | |
| 478 char ip_s[16]; | |
| 479 | |
| 480 tmp = strstr(msg, "Invitation-Cookie"); | |
| 481 GET_NEXT(tmp); | |
| 482 cookie_s = tmp; | |
| 483 GET_NEXT(tmp); | |
| 484 GET_NEXT(tmp); | |
| 485 ip = tmp; | |
| 486 GET_NEXT(tmp); | |
| 487 GET_NEXT(tmp); | |
| 488 port_s = tmp; | |
| 489 GET_NEXT(tmp); | |
| 490 GET_NEXT(tmp); | |
| 491 authcookie_s = tmp; | |
| 492 GET_NEXT(tmp); | |
| 493 | |
| 494 xfer = find_xfer_by_cookie(ms->gc, atoi(cookie_s)); | |
| 495 | |
| 496 if (xfer == NULL) | |
| 497 { | |
|
5221
abe4d103e300
[gaim-migrate @ 5591]
Christian Hammond <chipx86@chipx86.com>
parents:
4793
diff
changeset
|
498 gaim_debug(GAIM_DEBUG_ERROR, "msn", |
|
abe4d103e300
[gaim-migrate @ 5591]
Christian Hammond <chipx86@chipx86.com>
parents:
4793
diff
changeset
|
499 "MSNFTP : Cookie not found. " |
|
abe4d103e300
[gaim-migrate @ 5591]
Christian Hammond <chipx86@chipx86.com>
parents:
4793
diff
changeset
|
500 "File transfer aborted.\n"); |
| 4542 | 501 return; |
| 502 } | |
| 503 | |
| 504 xfer_data = (struct msn_xfer_data *)xfer->data; | |
| 505 xfer_data->authcookie = atol(authcookie_s); | |
| 506 | |
| 507 strncpy(ip_s, ip, sizeof(ip_s)); | |
| 508 | |
| 4634 | 509 if (proxy_connect(xfer->account, ip_s, atoi(port_s), |
| 4542 | 510 msn_msnftp_connect, xfer) != 0) { |
| 511 | |
|
4675
3145c5c45877
[gaim-migrate @ 4986]
Christian Hammond <chipx86@chipx86.com>
parents:
4634
diff
changeset
|
512 gaim_xfer_cancel_remote(xfer); |
| 4542 | 513 |
| 514 return; | |
| 515 } | |
| 516 } | |
| 517 else | |
| 518 { | |
| 519 /* | |
| 520 * An accept message from the recipient. Used in outgoing | |
| 521 * file transfers. | |
| 522 */ | |
| 523 } | |
| 524 } | |
| 525 } | |
| 526 |
