Mercurial > pidgin.yaz
annotate src/protocols/msn/slplink.c @ 10107:65e7df286076
[gaim-migrate @ 11139]
msn crash fix from evands
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Sun, 17 Oct 2004 22:38:24 +0000 |
parents | 1843023b8189 |
children | ecf3ce2e2ab1 |
rev | line source |
---|---|
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
1 /** |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
2 * @file slplink.c MSNSLP Link support |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
3 * |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
4 * gaim |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
5 * |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
6 * Gaim is the legal property of its developers, whose names are too numerous |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
7 * to list here. Please refer to the COPYRIGHT file distributed with this |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
8 * source distribution. |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
9 * |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
10 * This program is free software; you can redistribute it and/or modify |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
11 * it under the terms of the GNU General Public License as published by |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
12 * the Free Software Foundation; either version 2 of the License, or |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
13 * (at your option) any later version. |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
14 * |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
15 * This program is distributed in the hope that it will be useful, |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
18 * GNU General Public License for more details. |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
19 * |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
20 * You should have received a copy of the GNU General Public License |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
21 * along with this program; if not, write to the Free Software |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
23 */ |
9193 | 24 #include "msn.h" |
25 #include "slplink.h" | |
26 | |
27 #include "switchboard.h" | |
28 #include "slp.h" | |
29 | |
30 void msn_slplink_send_msgpart(MsnSlpLink *slplink, MsnSlpMessage *slpmsg); | |
31 | |
32 #ifdef DEBUG_SLP_FILES | |
33 static int m_sc = 0; | |
34 static int m_rc = 0; | |
35 | |
36 static void | |
37 debug_msg_to_file(MsnMessage *msg, gboolean send) | |
38 { | |
39 char *tmp; | |
40 char *dir; | |
41 char *pload; | |
42 FILE *tf; | |
43 int c; | |
44 gsize pload_size; | |
45 | |
46 dir = send ? "send" : "recv"; | |
47 c = send ? m_sc++ : m_rc++; | |
48 tmp = g_strdup_printf("%s/msntest/%s/%03d", g_get_home_dir(), dir, c); | |
9219 | 49 tf = fopen(tmp, "wb"); |
9193 | 50 pload = msn_message_gen_payload(msg, &pload_size); |
51 fwrite(pload, 1, pload_size, tf); | |
52 fclose(tf); | |
53 g_free(tmp); | |
54 } | |
55 #endif | |
56 | |
57 MsnSlpLink * | |
58 msn_slplink_new(MsnSession *session, const char *username) | |
59 { | |
60 MsnSlpLink *slplink; | |
61 | |
62 slplink = g_new0(MsnSlpLink, 1); | |
63 | |
64 slplink->session = session; | |
65 slplink->slp_seq_id = rand() % 0xFFFFFF00 + 4; | |
66 | |
67 slplink->local_user = g_strdup(msn_user_get_passport(session->user)); | |
68 slplink->remote_user = g_strdup(username); | |
69 | |
70 slplink->slp_msg_queue = g_queue_new(); | |
71 | |
72 session->slplinks = | |
73 g_list_append(session->slplinks, slplink); | |
74 | |
75 return slplink; | |
76 } | |
77 | |
78 void | |
79 msn_slplink_destroy(MsnSlpLink *slplink) | |
80 { | |
81 MsnSession *session; | |
82 | |
83 session = slplink->session; | |
84 | |
85 if (slplink->local_user != NULL) | |
86 g_free(slplink->local_user); | |
87 | |
88 if (slplink->remote_user != NULL) | |
89 g_free(slplink->remote_user); | |
90 | |
91 if (slplink->directconn != NULL) | |
92 msn_directconn_destroy(slplink->directconn); | |
93 | |
94 session->slplinks = | |
95 g_list_remove(session->slplinks, slplink); | |
96 | |
97 g_free(slplink); | |
98 } | |
99 | |
100 MsnSlpLink * | |
101 msn_session_find_slplink(MsnSession *session, const char *who) | |
102 { | |
103 MsnSlpLink *slplink; | |
104 GList *l; | |
105 | |
106 for (l = session->slplinks; l != NULL; l = l->next) | |
107 { | |
108 slplink = l->data; | |
109 | |
110 if (!strcmp(slplink->remote_user, who)) | |
111 return slplink; | |
112 } | |
113 | |
114 return NULL; | |
115 } | |
116 | |
117 MsnSlpLink * | |
118 msn_session_get_slplink(MsnSession *session, const char *username) | |
119 { | |
120 MsnSlpLink *slplink; | |
121 | |
122 slplink = msn_session_find_slplink(session, username); | |
123 | |
124 if (slplink == NULL) | |
125 slplink = msn_slplink_new(session, username); | |
126 | |
127 return slplink; | |
128 } | |
129 | |
130 MsnSlpSession * | |
131 msn_slplink_find_slp_session(MsnSlpLink *slplink, long session_id) | |
132 { | |
133 GList *l; | |
134 MsnSlpSession *slpsession; | |
135 | |
136 for (l = slplink->slp_sessions; l != NULL; l = l->next) | |
137 { | |
138 slpsession = l->data; | |
139 | |
140 if (slpsession->id == session_id) | |
141 return slpsession; | |
142 } | |
143 | |
144 return NULL; | |
145 } | |
146 | |
147 MsnSlpCall * | |
148 msn_slplink_find_slp_call(MsnSlpLink *slplink, const char *id) | |
149 { | |
150 GList *l; | |
151 MsnSlpCall *slpcall; | |
152 | |
10107
65e7df286076
[gaim-migrate @ 11139]
Luke Schierer <lschiere@pidgin.im>
parents:
10092
diff
changeset
|
153 if (!id) |
65e7df286076
[gaim-migrate @ 11139]
Luke Schierer <lschiere@pidgin.im>
parents:
10092
diff
changeset
|
154 return NULL; |
65e7df286076
[gaim-migrate @ 11139]
Luke Schierer <lschiere@pidgin.im>
parents:
10092
diff
changeset
|
155 |
9193 | 156 for (l = slplink->slp_calls; l != NULL; l = l->next) |
157 { | |
158 slpcall = l->data; | |
159 | |
10107
65e7df286076
[gaim-migrate @ 11139]
Luke Schierer <lschiere@pidgin.im>
parents:
10092
diff
changeset
|
160 if (slpcall->id && !strcmp(slpcall->id, id)) |
9193 | 161 return slpcall; |
162 } | |
163 | |
164 return NULL; | |
165 } | |
166 | |
167 MsnSlpCall * | |
168 msn_slplink_find_slp_call_with_session_id(MsnSlpLink *slplink, long id) | |
169 { | |
170 GList *l; | |
171 MsnSlpCall *slpcall; | |
172 | |
173 for (l = slplink->slp_calls; l != NULL; l = l->next) | |
174 { | |
175 slpcall = l->data; | |
176 | |
177 if (slpcall->session_id == id) | |
178 return slpcall; | |
179 } | |
180 | |
181 return NULL; | |
182 } | |
183 | |
184 void | |
185 msn_slplink_send_msg(MsnSlpLink *slplink, MsnMessage *msg) | |
186 { | |
187 if (slplink->directconn != NULL) | |
188 { | |
189 msn_directconn_send_msg(slplink->directconn, msg); | |
190 } | |
191 else | |
192 { | |
193 MsnSwitchBoard *swboard; | |
194 | |
195 swboard = msn_session_get_swboard(slplink->session, slplink->remote_user); | |
196 | |
197 if (swboard == NULL) | |
198 return; | |
199 | |
200 if (!g_queue_is_empty(swboard->im_queue) || | |
201 !swboard->user_joined) | |
202 { | |
203 msn_switchboard_queue_msg(swboard, msg); | |
204 } | |
205 else | |
206 { | |
207 msn_switchboard_send_msg(swboard, msg); | |
208 } | |
209 } | |
210 } | |
211 | |
9571 | 212 static void |
213 t_ack(MsnCmdProc *cmdproc, MsnCommand *cmd) | |
9193 | 214 { |
215 MsnSlpMessage *slpmsg; | |
216 long long real_size; | |
217 | |
218 slpmsg = cmd->trans->data; | |
219 | |
220 real_size = (slpmsg->flags == 0x2) ? 0 : slpmsg->size; | |
221 | |
222 if (slpmsg->offset < real_size) | |
223 { | |
224 msn_slplink_send_msgpart(slpmsg->slplink, slpmsg); | |
225 } | |
226 else | |
227 { | |
228 /* The whole message has been sent */ | |
229 | |
9246
e20af87d8721
[gaim-migrate @ 10045]
Christian Hammond <chipx86@chipx86.com>
parents:
9231
diff
changeset
|
230 if (slpmsg->flags == 0x20 || slpmsg->flags == 0x1000030) |
9193 | 231 { |
9246
e20af87d8721
[gaim-migrate @ 10045]
Christian Hammond <chipx86@chipx86.com>
parents:
9231
diff
changeset
|
232 if ((slpmsg->slpcall != NULL) && |
e20af87d8721
[gaim-migrate @ 10045]
Christian Hammond <chipx86@chipx86.com>
parents:
9231
diff
changeset
|
233 (slpmsg->slpcall->cb != NULL)) |
e20af87d8721
[gaim-migrate @ 10045]
Christian Hammond <chipx86@chipx86.com>
parents:
9231
diff
changeset
|
234 { |
e20af87d8721
[gaim-migrate @ 10045]
Christian Hammond <chipx86@chipx86.com>
parents:
9231
diff
changeset
|
235 slpmsg->slpcall->cb(slpmsg->slpcall, NULL, 0); |
e20af87d8721
[gaim-migrate @ 10045]
Christian Hammond <chipx86@chipx86.com>
parents:
9231
diff
changeset
|
236 } |
9193 | 237 } |
238 | |
239 msn_slpmsg_destroy(slpmsg); | |
240 } | |
241 } | |
242 | |
243 void | |
244 msn_slplink_send_msgpart(MsnSlpLink *slplink, MsnSlpMessage *slpmsg) | |
245 { | |
246 MsnMessage *msg; | |
247 long long real_size; | |
248 size_t len = 0; | |
249 | |
250 msg = slpmsg->msg; | |
251 | |
252 real_size = (slpmsg->flags == 0x2) ? 0 : slpmsg->size; | |
253 | |
254 if (slpmsg->offset < real_size) | |
255 { | |
256 if (slpmsg->fp) | |
257 { | |
258 char data[1202]; | |
259 len = fread(data, 1, sizeof(data), slpmsg->fp); | |
260 msn_message_set_bin_data(msg, data, len); | |
261 } | |
262 else | |
263 { | |
264 len = slpmsg->size - slpmsg->offset; | |
265 | |
266 if (len > 1202) | |
267 len = 1202; | |
268 | |
269 msn_message_set_bin_data(msg, slpmsg->buffer + slpmsg->offset, len); | |
270 } | |
271 | |
272 msg->msnslp_header.offset = slpmsg->offset; | |
273 msg->msnslp_header.length = len; | |
274 } | |
275 | |
276 #ifdef DEBUG_SLP | |
277 msn_message_show_readable(msg, slpmsg->info, slpmsg->text_body); | |
278 #endif | |
279 | |
280 #ifdef DEBUG_SLP_FILES | |
281 debug_msg_to_file(msg, TRUE); | |
282 #endif | |
283 | |
284 msn_slplink_send_msg(slplink, msg); | |
285 | |
9226
7a00289f2ef1
[gaim-migrate @ 10022]
Christian Hammond <chipx86@chipx86.com>
parents:
9219
diff
changeset
|
286 if (slpmsg->flags == 0x20 || slpmsg->flags == 0x1000030) |
9193 | 287 { |
9226
7a00289f2ef1
[gaim-migrate @ 10022]
Christian Hammond <chipx86@chipx86.com>
parents:
9219
diff
changeset
|
288 if ((slpmsg->slpcall != NULL) && |
7a00289f2ef1
[gaim-migrate @ 10022]
Christian Hammond <chipx86@chipx86.com>
parents:
9219
diff
changeset
|
289 (slpmsg->slpcall->progress_cb != NULL)) |
7a00289f2ef1
[gaim-migrate @ 10022]
Christian Hammond <chipx86@chipx86.com>
parents:
9219
diff
changeset
|
290 { |
9231
ac8790437abe
[gaim-migrate @ 10027]
Christian Hammond <chipx86@chipx86.com>
parents:
9226
diff
changeset
|
291 slpmsg->slpcall->progress_cb(slpmsg->slpcall, slpmsg->size, |
ac8790437abe
[gaim-migrate @ 10027]
Christian Hammond <chipx86@chipx86.com>
parents:
9226
diff
changeset
|
292 len, slpmsg->offset); |
9226
7a00289f2ef1
[gaim-migrate @ 10022]
Christian Hammond <chipx86@chipx86.com>
parents:
9219
diff
changeset
|
293 } |
9193 | 294 } |
295 | |
296 slpmsg->offset += len; | |
297 } | |
298 | |
299 void | |
300 msn_slplink_release_msg(MsnSlpLink *slplink, MsnSlpMessage *slpmsg) | |
301 { | |
302 MsnMessage *msg; | |
303 | |
304 slpmsg->msg = msg = msn_message_new_msnslp(); | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
305 |
9193 | 306 if (slpmsg->flags == 0x0) |
307 { | |
308 msg->msnslp_header.session_id = slpmsg->session_id; | |
309 msg->msnslp_header.ack_id = rand() % 0xFFFFFF00; | |
310 } | |
311 else if (slpmsg->flags == 0x2) | |
312 { | |
313 msg->msnslp_header.session_id = slpmsg->session_id; | |
314 msg->msnslp_header.ack_id = slpmsg->ack_id; | |
315 msg->msnslp_header.ack_size = slpmsg->ack_size; | |
316 } | |
317 else if (slpmsg->flags == 0x20 || slpmsg->flags == 0x1000030) | |
318 { | |
319 MsnSlpSession *slpsession; | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
320 slpsession = slpmsg->slpsession; |
9193 | 321 |
322 g_return_if_fail(slpsession != NULL); | |
323 msg->msnslp_header.session_id = slpsession->id; | |
324 msg->msnslp_footer.value = slpsession->app_id; | |
325 msg->msnslp_header.ack_id = rand() % 0xFFFFFF00; | |
326 } | |
327 else if (slpmsg->flags == 0x100) | |
328 { | |
329 msg->msnslp_header.ack_id = slpmsg->ack_id; | |
330 msg->msnslp_header.ack_sub_id = slpmsg->ack_sub_id; | |
331 msg->msnslp_header.ack_size = slpmsg->ack_size; | |
332 } | |
333 | |
334 msg->msnslp_header.id = slpmsg->id; | |
335 msg->msnslp_header.flags = slpmsg->flags; | |
336 | |
337 msg->msnslp_header.total_size = slpmsg->size; | |
338 | |
339 msn_message_set_attr(msg, "P2P-Dest", slplink->remote_user); | |
340 | |
341 msg->ack_cb = t_ack; | |
342 msg->ack_data = slpmsg; | |
343 | |
344 msn_slplink_send_msgpart(slplink, slpmsg); | |
345 } | |
346 | |
347 void | |
348 msn_slplink_queue_slpmsg(MsnSlpLink *slplink, MsnSlpMessage *slpmsg) | |
349 { | |
350 slpmsg->id = slplink->slp_seq_id++; | |
351 | |
352 g_queue_push_head(slplink->slp_msg_queue, slpmsg); | |
353 } | |
354 | |
355 void | |
356 msn_slplink_send_slpmsg(MsnSlpLink *slplink, MsnSlpMessage *slpmsg) | |
357 { | |
358 slpmsg->id = slplink->slp_seq_id++; | |
359 | |
360 msn_slplink_release_msg(slplink, slpmsg); | |
361 } | |
362 | |
363 void | |
364 msn_slplink_unleash(MsnSlpLink *slplink) | |
365 { | |
366 MsnSlpMessage *slpmsg; | |
367 | |
368 /* Send the queued msgs in the order they came. */ | |
369 | |
370 while ((slpmsg = g_queue_pop_tail(slplink->slp_msg_queue)) != NULL) | |
371 msn_slplink_release_msg(slplink, slpmsg); | |
372 } | |
373 | |
374 void | |
375 msn_slplink_send_ack(MsnSlpLink *slplink, MsnMessage *msg) | |
376 { | |
377 MsnSlpMessage *slpmsg; | |
378 | |
379 slpmsg = msn_slpmsg_new(slplink); | |
380 | |
381 slpmsg->session_id = msg->msnslp_header.session_id; | |
382 slpmsg->size = msg->msnslp_header.total_size; | |
383 slpmsg->flags = 0x02; | |
384 slpmsg->ack_id = msg->msnslp_header.id; | |
385 slpmsg->ack_sub_id = msg->msnslp_header.ack_id; | |
386 slpmsg->ack_size = msg->msnslp_header.total_size; | |
387 | |
388 #ifdef DEBUG_SLP | |
389 slpmsg->info = "SLP ACK"; | |
390 #endif | |
391 | |
392 msn_slplink_send_slpmsg(slplink, slpmsg); | |
393 } | |
394 | |
9571 | 395 static void |
396 send_file_cb(MsnSlpSession *slpsession) | |
9193 | 397 { |
398 MsnSlpCall *slpcall; | |
399 MsnSlpMessage *slpmsg; | |
400 | |
401 slpcall = slpsession->slpcall; | |
402 slpmsg = msn_slpmsg_new(slpcall->slplink); | |
403 slpmsg->flags = 0x1000030; | |
404 slpmsg->slpsession = slpsession; | |
405 #ifdef DEBUG_SLP | |
406 slpmsg->info = "SLP FILE"; | |
407 #endif | |
408 slpmsg->slpcall = slpcall; | |
409 msn_slpmsg_open_file(slpmsg, gaim_xfer_get_local_filename(slpcall->xfer)); | |
410 | |
411 msn_slplink_send_slpmsg(slpcall->slplink, slpmsg); | |
412 } | |
413 | |
414 void | |
415 msn_slplink_process_msg(MsnSlpLink *slplink, MsnMessage *msg) | |
416 { | |
417 MsnSlpMessage *slpmsg; | |
418 const char *data; | |
419 gsize offset; | |
420 gsize len; | |
421 | |
422 #ifdef DEBUG_SLP | |
423 msn_slpmsg_show(msg); | |
424 #endif | |
425 | |
426 #ifdef DEBUG_SLP_FILES | |
427 debug_msg_to_file(msg, FALSE); | |
428 #endif | |
429 | |
430 if (msg->msnslp_header.total_size < msg->msnslp_header.length) | |
431 { | |
432 gaim_debug_error("msn", "This can't be good\n"); | |
433 g_return_if_reached(); | |
434 } | |
435 | |
436 slpmsg = NULL; | |
437 data = msn_message_get_bin_data(msg, &len); | |
438 | |
439 /* | |
440 OVERHEAD! | |
441 if (msg->msnslp_header.length < msg->msnslp_header.total_size) | |
442 */ | |
443 | |
444 offset = msg->msnslp_header.offset; | |
445 | |
446 if (offset == 0) | |
447 { | |
448 slpmsg = msn_slpmsg_new(slplink); | |
449 slpmsg->id = msg->msnslp_header.id; | |
450 slpmsg->session_id = msg->msnslp_header.session_id; | |
451 slpmsg->size = msg->msnslp_header.total_size; | |
452 slpmsg->flags = msg->msnslp_header.flags; | |
453 | |
454 if (slpmsg->session_id) | |
455 { | |
456 if (slpmsg->slpcall == NULL) | |
457 slpmsg->slpcall = msn_slplink_find_slp_call_with_session_id(slplink, slpmsg->session_id); | |
458 | |
459 if (slpmsg->slpcall != NULL) | |
460 { | |
9226
7a00289f2ef1
[gaim-migrate @ 10022]
Christian Hammond <chipx86@chipx86.com>
parents:
9219
diff
changeset
|
461 if (slpmsg->flags == 0x20 || slpmsg->flags == 0x1000030) |
7a00289f2ef1
[gaim-migrate @ 10022]
Christian Hammond <chipx86@chipx86.com>
parents:
9219
diff
changeset
|
462 { |
7a00289f2ef1
[gaim-migrate @ 10022]
Christian Hammond <chipx86@chipx86.com>
parents:
9219
diff
changeset
|
463 GaimXfer *xfer; |
9193 | 464 |
9226
7a00289f2ef1
[gaim-migrate @ 10022]
Christian Hammond <chipx86@chipx86.com>
parents:
9219
diff
changeset
|
465 xfer = slpmsg->slpcall->xfer; |
9193 | 466 |
9226
7a00289f2ef1
[gaim-migrate @ 10022]
Christian Hammond <chipx86@chipx86.com>
parents:
9219
diff
changeset
|
467 if (xfer != NULL) |
7a00289f2ef1
[gaim-migrate @ 10022]
Christian Hammond <chipx86@chipx86.com>
parents:
9219
diff
changeset
|
468 { |
7a00289f2ef1
[gaim-migrate @ 10022]
Christian Hammond <chipx86@chipx86.com>
parents:
9219
diff
changeset
|
469 slpmsg->fp = |
7a00289f2ef1
[gaim-migrate @ 10022]
Christian Hammond <chipx86@chipx86.com>
parents:
9219
diff
changeset
|
470 fopen(gaim_xfer_get_local_filename(slpmsg->slpcall->xfer), |
7a00289f2ef1
[gaim-migrate @ 10022]
Christian Hammond <chipx86@chipx86.com>
parents:
9219
diff
changeset
|
471 "wb"); |
7a00289f2ef1
[gaim-migrate @ 10022]
Christian Hammond <chipx86@chipx86.com>
parents:
9219
diff
changeset
|
472 } |
9193 | 473 } |
474 } | |
475 } | |
10092 | 476 if (!slpmsg->fp) |
477 { | |
478 slpmsg->buffer = g_try_malloc(slpmsg->size); | |
479 if (slpmsg->buffer == NULL) | |
480 { | |
481 gaim_debug_error("msn", "Failed to allocate buffer for slpmsg\n"); | |
482 return; | |
483 } | |
484 } | |
9193 | 485 } |
486 else | |
487 { | |
10092 | 488 slpmsg = msn_slplink_message_find(slplink, msg->msnslp_header.session_id, msg->msnslp_header.id); |
9193 | 489 } |
490 | |
491 if (slpmsg != NULL) | |
492 { | |
493 if (slpmsg->fp) | |
494 { | |
495 /* fseek(slpmsg->fp, offset, SEEK_SET); */ | |
496 len = fwrite(data, 1, len, slpmsg->fp); | |
497 } | |
498 else | |
499 { | |
10092 | 500 if ((offset + len) > slpmsg->size) |
501 { | |
502 gaim_debug_error("msn", "Oversized slpmsg\n"); | |
503 g_return_if_reached(); | |
504 } | |
505 else | |
506 memcpy(slpmsg->buffer + offset, data, len); | |
9193 | 507 } |
508 } | |
509 else | |
510 { | |
511 gaim_debug_error("msn", "Couldn't find slpmsg\n"); | |
512 g_return_if_reached(); | |
513 } | |
514 | |
9231
ac8790437abe
[gaim-migrate @ 10027]
Christian Hammond <chipx86@chipx86.com>
parents:
9226
diff
changeset
|
515 if (slpmsg->flags == 0x20 || slpmsg->flags == 0x1000030) |
9193 | 516 { |
9231
ac8790437abe
[gaim-migrate @ 10027]
Christian Hammond <chipx86@chipx86.com>
parents:
9226
diff
changeset
|
517 if ((slpmsg->slpcall != NULL) && |
ac8790437abe
[gaim-migrate @ 10027]
Christian Hammond <chipx86@chipx86.com>
parents:
9226
diff
changeset
|
518 (slpmsg->slpcall->progress_cb != NULL)) |
ac8790437abe
[gaim-migrate @ 10027]
Christian Hammond <chipx86@chipx86.com>
parents:
9226
diff
changeset
|
519 { |
ac8790437abe
[gaim-migrate @ 10027]
Christian Hammond <chipx86@chipx86.com>
parents:
9226
diff
changeset
|
520 slpmsg->slpcall->progress_cb(slpmsg->slpcall, slpmsg->size, |
ac8790437abe
[gaim-migrate @ 10027]
Christian Hammond <chipx86@chipx86.com>
parents:
9226
diff
changeset
|
521 len, offset); |
ac8790437abe
[gaim-migrate @ 10027]
Christian Hammond <chipx86@chipx86.com>
parents:
9226
diff
changeset
|
522 } |
9193 | 523 } |
524 | |
525 #if 0 | |
526 if (slpmsg->buffer == NULL) | |
527 return; | |
528 #endif | |
529 | |
530 if (msg->msnslp_header.offset + msg->msnslp_header.length | |
531 >= msg->msnslp_header.total_size) | |
532 { | |
533 /* All the pieces of the slpmsg have been received */ | |
534 MsnSlpCall *slpcall; | |
535 | |
536 slpcall = msn_slp_process_msg(slplink, slpmsg); | |
537 | |
538 if (slpmsg->flags == 0x100) | |
539 { | |
540 MsnDirectConn *directconn; | |
541 | |
542 directconn = slplink->directconn; | |
543 | |
544 if (!directconn->acked) | |
545 msn_directconn_send_handshake(directconn); | |
546 } | |
547 else if (slpmsg->flags == 0x0 || slpmsg->flags == 0x20 || | |
548 slpmsg->flags == 0x1000030) | |
549 { | |
550 /* Release all the messages and send the ACK */ | |
551 | |
552 msn_slplink_send_ack(slplink, msg); | |
553 msn_slplink_unleash(slplink); | |
554 } | |
555 | |
556 msn_slpmsg_destroy(slpmsg); | |
557 | |
558 if (slpcall != NULL && slpcall->wasted) | |
559 msn_slp_call_destroy(slpcall); | |
560 } | |
561 } | |
562 | |
563 MsnSlpMessage * | |
10092 | 564 msn_slplink_message_find(MsnSlpLink *slplink, long session_id, long id) |
9193 | 565 { |
566 GList *e; | |
567 | |
568 for (e = slplink->slp_msgs; e != NULL; e = e->next) | |
569 { | |
570 MsnSlpMessage *slpmsg = e->data; | |
571 | |
10092 | 572 if ((slpmsg->session_id == session_id) && (slpmsg->id == id)) |
9193 | 573 return slpmsg; |
574 } | |
575 | |
576 return NULL; | |
577 } | |
578 | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
579 typedef struct |
9193 | 580 { |
581 guint32 length; | |
582 guint32 unk1; | |
583 guint32 file_size; | |
584 guint32 unk2; | |
585 guint32 unk3; | |
586 } MsnContextHeader; | |
587 | |
588 #define MAX_FILE_NAME_LEN 0x226 | |
589 | |
9571 | 590 static char * |
10047 | 591 gen_context(const char *file_name, const char *file_path) |
9193 | 592 { |
593 struct stat st; | |
594 gsize size = 0; | |
595 MsnContextHeader header; | |
10047 | 596 gchar *u8 = NULL; |
9193 | 597 gchar *base, *n; |
10047 | 598 gunichar2 *uni = NULL; |
599 glong currentChar = 0; | |
600 glong uni_len = 0; | |
9193 | 601 gsize len; |
602 | |
10088 | 603 if (stat(file_path, &st) == 0) |
9193 | 604 size = st.st_size; |
605 | |
10047 | 606 if(!file_name) { |
607 u8 = gaim_utf8_try_convert(g_basename(file_path)); | |
608 file_name = u8; | |
609 } | |
610 | |
611 uni = g_utf8_to_utf16(file_name, -1, NULL, &uni_len, NULL); | |
612 | |
613 if(u8) { | |
614 g_free(u8); | |
615 file_name = NULL; | |
616 u8 = NULL; | |
617 } | |
9193 | 618 |
619 len = sizeof(MsnContextHeader) + MAX_FILE_NAME_LEN + 4; | |
620 | |
621 header.length = GUINT32_TO_LE(len); | |
622 header.unk1 = GUINT32_TO_LE(2); | |
623 header.file_size = GUINT32_TO_LE(size); | |
624 header.unk2 = GUINT32_TO_LE(0); | |
625 header.unk3 = GUINT32_TO_LE(0); | |
10047 | 626 |
627 base = g_malloc(len + 1); | |
628 n = base; | |
9193 | 629 |
630 memcpy(n, &header, sizeof(MsnContextHeader)); | |
631 n += sizeof(MsnContextHeader); | |
632 | |
633 memset(n, 0x00, MAX_FILE_NAME_LEN); | |
10047 | 634 for(currentChar = 0; currentChar < uni_len; currentChar++) { |
635 *((gunichar2 *)n + currentChar) = GUINT16_TO_LE(uni[currentChar]); | |
636 } | |
9193 | 637 n += MAX_FILE_NAME_LEN; |
638 | |
639 memset(n, 0xFF, 4); | |
640 n += 4; | |
10047 | 641 |
9193 | 642 g_free(uni); |
643 return gaim_base64_encode(base, len); | |
644 } | |
645 | |
646 void | |
647 msn_slplink_request_ft(MsnSlpLink *slplink, GaimXfer *xfer) | |
648 { | |
649 MsnSlpCall *slpcall; | |
650 char *context; | |
651 const char *fn; | |
10047 | 652 const char *fp; |
9193 | 653 |
10047 | 654 fn = gaim_xfer_get_filename(xfer); |
655 fp = gaim_xfer_get_local_filename(xfer); | |
9193 | 656 |
657 g_return_if_fail(slplink != NULL); | |
10047 | 658 g_return_if_fail(fp != NULL); |
9193 | 659 |
660 slpcall = msn_slp_call_new(slplink); | |
661 msn_slp_call_init(slpcall, MSN_SLPCALL_DC); | |
662 | |
9571 | 663 slpcall->session_init_cb = send_file_cb; |
9715
b030f83693da
[gaim-migrate @ 10576]
Christian Hammond <chipx86@chipx86.com>
parents:
9571
diff
changeset
|
664 slpcall->end_cb = msn_xfer_end_cb; |
9193 | 665 slpcall->progress_cb = msn_xfer_progress_cb; |
9259
f5f7482678d2
[gaim-migrate @ 10058]
Christian Hammond <chipx86@chipx86.com>
parents:
9246
diff
changeset
|
666 slpcall->cb = msn_xfer_completed_cb; |
9193 | 667 slpcall->xfer = xfer; |
668 | |
669 gaim_xfer_set_cancel_send_fnc(xfer, msn_xfer_cancel); | |
670 | |
671 xfer->data = slpcall; | |
672 | |
10047 | 673 context = gen_context(fn, fp); |
9193 | 674 |
675 msn_slp_call_invite(slpcall, "5D3E02AB-6190-11D3-BBBB-00C04F795683", 2, | |
676 context); | |
677 | |
678 g_free(context); | |
679 } | |
680 | |
681 void | |
682 msn_slplink_request_object(MsnSlpLink *slplink, | |
683 const char *info, | |
684 MsnSlpCb cb, | |
685 const MsnObject *obj) | |
686 { | |
687 MsnSlpCall *slpcall; | |
688 char *msnobj_data; | |
689 char *msnobj_base64; | |
690 | |
691 g_return_if_fail(slplink != NULL); | |
9861 | 692 g_return_if_fail(obj != NULL); |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
693 |
9193 | 694 msnobj_data = msn_object_to_string(obj); |
695 msnobj_base64 = gaim_base64_encode(msnobj_data, strlen(msnobj_data)); | |
696 g_free(msnobj_data); | |
697 | |
698 slpcall = msn_slp_call_new(slplink); | |
699 msn_slp_call_init(slpcall, MSN_SLPCALL_ANY); | |
700 | |
701 slpcall->data_info = g_strdup(info); | |
702 slpcall->cb = cb; | |
703 | |
704 msn_slp_call_invite(slpcall, "A4268EEC-FEC5-49E5-95C3-F126696BDBF6", 1, | |
705 msnobj_base64); | |
706 | |
707 g_free(msnobj_base64); | |
708 } |