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