Mercurial > pidgin
annotate src/protocols/msn/slplink.c @ 10248:e7c0a9e0c276
[gaim-migrate @ 11388]
Remove a timeout in the gtkstatusselector when all accounts sign off
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Tue, 23 Nov 2004 06:25:14 +0000 |
parents | ecf3ce2e2ab1 |
children | f776e117c17b |
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 GList *l; | |
104 | |
105 for (l = session->slplinks; l != NULL; l = l->next) | |
106 { | |
10225 | 107 MsnSlpLink *slplink; |
108 | |
9193 | 109 slplink = l->data; |
110 | |
111 if (!strcmp(slplink->remote_user, who)) | |
112 return slplink; | |
113 } | |
114 | |
115 return NULL; | |
116 } | |
117 | |
118 MsnSlpLink * | |
119 msn_session_get_slplink(MsnSession *session, const char *username) | |
120 { | |
121 MsnSlpLink *slplink; | |
122 | |
123 slplink = msn_session_find_slplink(session, username); | |
124 | |
125 if (slplink == NULL) | |
126 slplink = msn_slplink_new(session, username); | |
127 | |
128 return slplink; | |
129 } | |
130 | |
131 MsnSlpSession * | |
132 msn_slplink_find_slp_session(MsnSlpLink *slplink, long session_id) | |
133 { | |
134 GList *l; | |
135 MsnSlpSession *slpsession; | |
136 | |
137 for (l = slplink->slp_sessions; l != NULL; l = l->next) | |
138 { | |
139 slpsession = l->data; | |
140 | |
141 if (slpsession->id == session_id) | |
142 return slpsession; | |
143 } | |
144 | |
145 return NULL; | |
146 } | |
147 | |
148 MsnSlpCall * | |
149 msn_slplink_find_slp_call(MsnSlpLink *slplink, const char *id) | |
150 { | |
151 GList *l; | |
152 MsnSlpCall *slpcall; | |
153 | |
10107
65e7df286076
[gaim-migrate @ 11139]
Luke Schierer <lschiere@pidgin.im>
parents:
10092
diff
changeset
|
154 if (!id) |
65e7df286076
[gaim-migrate @ 11139]
Luke Schierer <lschiere@pidgin.im>
parents:
10092
diff
changeset
|
155 return NULL; |
65e7df286076
[gaim-migrate @ 11139]
Luke Schierer <lschiere@pidgin.im>
parents:
10092
diff
changeset
|
156 |
9193 | 157 for (l = slplink->slp_calls; l != NULL; l = l->next) |
158 { | |
159 slpcall = l->data; | |
160 | |
10107
65e7df286076
[gaim-migrate @ 11139]
Luke Schierer <lschiere@pidgin.im>
parents:
10092
diff
changeset
|
161 if (slpcall->id && !strcmp(slpcall->id, id)) |
9193 | 162 return slpcall; |
163 } | |
164 | |
165 return NULL; | |
166 } | |
167 | |
168 MsnSlpCall * | |
169 msn_slplink_find_slp_call_with_session_id(MsnSlpLink *slplink, long id) | |
170 { | |
171 GList *l; | |
172 MsnSlpCall *slpcall; | |
173 | |
174 for (l = slplink->slp_calls; l != NULL; l = l->next) | |
175 { | |
176 slpcall = l->data; | |
177 | |
178 if (slpcall->session_id == id) | |
179 return slpcall; | |
180 } | |
181 | |
182 return NULL; | |
183 } | |
184 | |
185 void | |
186 msn_slplink_send_msg(MsnSlpLink *slplink, MsnMessage *msg) | |
187 { | |
188 if (slplink->directconn != NULL) | |
189 { | |
190 msn_directconn_send_msg(slplink->directconn, msg); | |
191 } | |
192 else | |
193 { | |
194 MsnSwitchBoard *swboard; | |
195 | |
10225 | 196 swboard = msn_session_get_swboard(slplink->session, |
197 slplink->remote_user); | |
9193 | 198 |
199 if (swboard == NULL) | |
200 return; | |
201 | |
202 if (!g_queue_is_empty(swboard->im_queue) || | |
203 !swboard->user_joined) | |
204 { | |
205 msn_switchboard_queue_msg(swboard, msg); | |
206 } | |
207 else | |
208 { | |
209 msn_switchboard_send_msg(swboard, msg); | |
210 } | |
211 } | |
212 } | |
213 | |
10225 | 214 /* We have received the message receive ack */ |
9571 | 215 static void |
10225 | 216 msg_ack(void *data) |
9193 | 217 { |
218 MsnSlpMessage *slpmsg; | |
219 long long real_size; | |
220 | |
10225 | 221 slpmsg = data; |
9193 | 222 |
223 real_size = (slpmsg->flags == 0x2) ? 0 : slpmsg->size; | |
224 | |
225 if (slpmsg->offset < real_size) | |
226 { | |
227 msn_slplink_send_msgpart(slpmsg->slplink, slpmsg); | |
228 } | |
229 else | |
230 { | |
231 /* The whole message has been sent */ | |
232 | |
9246
e20af87d8721
[gaim-migrate @ 10045]
Christian Hammond <chipx86@chipx86.com>
parents:
9231
diff
changeset
|
233 if (slpmsg->flags == 0x20 || slpmsg->flags == 0x1000030) |
9193 | 234 { |
9246
e20af87d8721
[gaim-migrate @ 10045]
Christian Hammond <chipx86@chipx86.com>
parents:
9231
diff
changeset
|
235 if ((slpmsg->slpcall != NULL) && |
e20af87d8721
[gaim-migrate @ 10045]
Christian Hammond <chipx86@chipx86.com>
parents:
9231
diff
changeset
|
236 (slpmsg->slpcall->cb != NULL)) |
e20af87d8721
[gaim-migrate @ 10045]
Christian Hammond <chipx86@chipx86.com>
parents:
9231
diff
changeset
|
237 { |
e20af87d8721
[gaim-migrate @ 10045]
Christian Hammond <chipx86@chipx86.com>
parents:
9231
diff
changeset
|
238 slpmsg->slpcall->cb(slpmsg->slpcall, NULL, 0); |
e20af87d8721
[gaim-migrate @ 10045]
Christian Hammond <chipx86@chipx86.com>
parents:
9231
diff
changeset
|
239 } |
9193 | 240 } |
241 | |
242 msn_slpmsg_destroy(slpmsg); | |
243 } | |
244 } | |
245 | |
246 void | |
247 msn_slplink_send_msgpart(MsnSlpLink *slplink, MsnSlpMessage *slpmsg) | |
248 { | |
249 MsnMessage *msg; | |
250 long long real_size; | |
251 size_t len = 0; | |
252 | |
253 msg = slpmsg->msg; | |
254 | |
255 real_size = (slpmsg->flags == 0x2) ? 0 : slpmsg->size; | |
256 | |
257 if (slpmsg->offset < real_size) | |
258 { | |
259 if (slpmsg->fp) | |
260 { | |
261 char data[1202]; | |
262 len = fread(data, 1, sizeof(data), slpmsg->fp); | |
263 msn_message_set_bin_data(msg, data, len); | |
264 } | |
265 else | |
266 { | |
267 len = slpmsg->size - slpmsg->offset; | |
268 | |
269 if (len > 1202) | |
270 len = 1202; | |
271 | |
272 msn_message_set_bin_data(msg, slpmsg->buffer + slpmsg->offset, len); | |
273 } | |
274 | |
275 msg->msnslp_header.offset = slpmsg->offset; | |
276 msg->msnslp_header.length = len; | |
277 } | |
278 | |
279 #ifdef DEBUG_SLP | |
280 msn_message_show_readable(msg, slpmsg->info, slpmsg->text_body); | |
281 #endif | |
282 | |
283 #ifdef DEBUG_SLP_FILES | |
284 debug_msg_to_file(msg, TRUE); | |
285 #endif | |
286 | |
287 msn_slplink_send_msg(slplink, msg); | |
288 | |
10225 | 289 if ((slpmsg->flags == 0x20 || slpmsg->flags == 0x1000030) && (slpmsg->slpcall != NULL)) |
9193 | 290 { |
10225 | 291 if (slpmsg->slpcall->timer) |
292 { | |
293 gaim_timeout_remove(slpmsg->slpcall->timer); | |
294 slpmsg->slpcall->timer = gaim_timeout_add(MSN_SLPCALL_TIMEOUT, | |
295 msn_slp_call_timeout, slpmsg->slpcall); | |
296 } | |
297 | |
298 if (slpmsg->slpcall->progress_cb != NULL) | |
9226
7a00289f2ef1
[gaim-migrate @ 10022]
Christian Hammond <chipx86@chipx86.com>
parents:
9219
diff
changeset
|
299 { |
9231
ac8790437abe
[gaim-migrate @ 10027]
Christian Hammond <chipx86@chipx86.com>
parents:
9226
diff
changeset
|
300 slpmsg->slpcall->progress_cb(slpmsg->slpcall, slpmsg->size, |
ac8790437abe
[gaim-migrate @ 10027]
Christian Hammond <chipx86@chipx86.com>
parents:
9226
diff
changeset
|
301 len, slpmsg->offset); |
9226
7a00289f2ef1
[gaim-migrate @ 10022]
Christian Hammond <chipx86@chipx86.com>
parents:
9219
diff
changeset
|
302 } |
9193 | 303 } |
304 | |
305 slpmsg->offset += len; | |
306 } | |
307 | |
308 void | |
309 msn_slplink_release_msg(MsnSlpLink *slplink, MsnSlpMessage *slpmsg) | |
310 { | |
311 MsnMessage *msg; | |
312 | |
313 slpmsg->msg = msg = msn_message_new_msnslp(); | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
314 |
9193 | 315 if (slpmsg->flags == 0x0) |
316 { | |
317 msg->msnslp_header.session_id = slpmsg->session_id; | |
318 msg->msnslp_header.ack_id = rand() % 0xFFFFFF00; | |
319 } | |
320 else if (slpmsg->flags == 0x2) | |
321 { | |
322 msg->msnslp_header.session_id = slpmsg->session_id; | |
323 msg->msnslp_header.ack_id = slpmsg->ack_id; | |
324 msg->msnslp_header.ack_size = slpmsg->ack_size; | |
325 } | |
326 else if (slpmsg->flags == 0x20 || slpmsg->flags == 0x1000030) | |
327 { | |
328 MsnSlpSession *slpsession; | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
329 slpsession = slpmsg->slpsession; |
9193 | 330 |
331 g_return_if_fail(slpsession != NULL); | |
332 msg->msnslp_header.session_id = slpsession->id; | |
333 msg->msnslp_footer.value = slpsession->app_id; | |
334 msg->msnslp_header.ack_id = rand() % 0xFFFFFF00; | |
335 } | |
336 else if (slpmsg->flags == 0x100) | |
337 { | |
338 msg->msnslp_header.ack_id = slpmsg->ack_id; | |
339 msg->msnslp_header.ack_sub_id = slpmsg->ack_sub_id; | |
340 msg->msnslp_header.ack_size = slpmsg->ack_size; | |
341 } | |
342 | |
343 msg->msnslp_header.id = slpmsg->id; | |
344 msg->msnslp_header.flags = slpmsg->flags; | |
345 | |
346 msg->msnslp_header.total_size = slpmsg->size; | |
347 | |
348 msn_message_set_attr(msg, "P2P-Dest", slplink->remote_user); | |
349 | |
10225 | 350 msg->ack_cb = msg_ack; |
9193 | 351 msg->ack_data = slpmsg; |
352 | |
353 msn_slplink_send_msgpart(slplink, slpmsg); | |
354 } | |
355 | |
356 void | |
357 msn_slplink_queue_slpmsg(MsnSlpLink *slplink, MsnSlpMessage *slpmsg) | |
358 { | |
359 slpmsg->id = slplink->slp_seq_id++; | |
360 | |
361 g_queue_push_head(slplink->slp_msg_queue, slpmsg); | |
362 } | |
363 | |
364 void | |
365 msn_slplink_send_slpmsg(MsnSlpLink *slplink, MsnSlpMessage *slpmsg) | |
366 { | |
367 slpmsg->id = slplink->slp_seq_id++; | |
368 | |
369 msn_slplink_release_msg(slplink, slpmsg); | |
370 } | |
371 | |
372 void | |
373 msn_slplink_unleash(MsnSlpLink *slplink) | |
374 { | |
375 MsnSlpMessage *slpmsg; | |
376 | |
377 /* Send the queued msgs in the order they came. */ | |
378 | |
379 while ((slpmsg = g_queue_pop_tail(slplink->slp_msg_queue)) != NULL) | |
380 msn_slplink_release_msg(slplink, slpmsg); | |
381 } | |
382 | |
383 void | |
384 msn_slplink_send_ack(MsnSlpLink *slplink, MsnMessage *msg) | |
385 { | |
386 MsnSlpMessage *slpmsg; | |
387 | |
388 slpmsg = msn_slpmsg_new(slplink); | |
389 | |
390 slpmsg->session_id = msg->msnslp_header.session_id; | |
391 slpmsg->size = msg->msnslp_header.total_size; | |
392 slpmsg->flags = 0x02; | |
393 slpmsg->ack_id = msg->msnslp_header.id; | |
394 slpmsg->ack_sub_id = msg->msnslp_header.ack_id; | |
395 slpmsg->ack_size = msg->msnslp_header.total_size; | |
396 | |
397 #ifdef DEBUG_SLP | |
398 slpmsg->info = "SLP ACK"; | |
399 #endif | |
400 | |
401 msn_slplink_send_slpmsg(slplink, slpmsg); | |
402 } | |
403 | |
9571 | 404 static void |
405 send_file_cb(MsnSlpSession *slpsession) | |
9193 | 406 { |
407 MsnSlpCall *slpcall; | |
408 MsnSlpMessage *slpmsg; | |
409 | |
410 slpcall = slpsession->slpcall; | |
411 slpmsg = msn_slpmsg_new(slpcall->slplink); | |
412 slpmsg->flags = 0x1000030; | |
413 slpmsg->slpsession = slpsession; | |
414 #ifdef DEBUG_SLP | |
415 slpmsg->info = "SLP FILE"; | |
416 #endif | |
417 slpmsg->slpcall = slpcall; | |
418 msn_slpmsg_open_file(slpmsg, gaim_xfer_get_local_filename(slpcall->xfer)); | |
419 | |
420 msn_slplink_send_slpmsg(slpcall->slplink, slpmsg); | |
421 } | |
422 | |
423 void | |
424 msn_slplink_process_msg(MsnSlpLink *slplink, MsnMessage *msg) | |
425 { | |
426 MsnSlpMessage *slpmsg; | |
427 const char *data; | |
428 gsize offset; | |
429 gsize len; | |
430 | |
431 #ifdef DEBUG_SLP | |
432 msn_slpmsg_show(msg); | |
433 #endif | |
434 | |
435 #ifdef DEBUG_SLP_FILES | |
436 debug_msg_to_file(msg, FALSE); | |
437 #endif | |
438 | |
439 if (msg->msnslp_header.total_size < msg->msnslp_header.length) | |
440 { | |
441 gaim_debug_error("msn", "This can't be good\n"); | |
442 g_return_if_reached(); | |
443 } | |
444 | |
445 slpmsg = NULL; | |
446 data = msn_message_get_bin_data(msg, &len); | |
447 | |
448 /* | |
449 OVERHEAD! | |
450 if (msg->msnslp_header.length < msg->msnslp_header.total_size) | |
451 */ | |
452 | |
453 offset = msg->msnslp_header.offset; | |
454 | |
455 if (offset == 0) | |
456 { | |
457 slpmsg = msn_slpmsg_new(slplink); | |
458 slpmsg->id = msg->msnslp_header.id; | |
459 slpmsg->session_id = msg->msnslp_header.session_id; | |
460 slpmsg->size = msg->msnslp_header.total_size; | |
461 slpmsg->flags = msg->msnslp_header.flags; | |
462 | |
463 if (slpmsg->session_id) | |
464 { | |
465 if (slpmsg->slpcall == NULL) | |
466 slpmsg->slpcall = msn_slplink_find_slp_call_with_session_id(slplink, slpmsg->session_id); | |
467 | |
468 if (slpmsg->slpcall != NULL) | |
469 { | |
9226
7a00289f2ef1
[gaim-migrate @ 10022]
Christian Hammond <chipx86@chipx86.com>
parents:
9219
diff
changeset
|
470 if (slpmsg->flags == 0x20 || slpmsg->flags == 0x1000030) |
7a00289f2ef1
[gaim-migrate @ 10022]
Christian Hammond <chipx86@chipx86.com>
parents:
9219
diff
changeset
|
471 { |
7a00289f2ef1
[gaim-migrate @ 10022]
Christian Hammond <chipx86@chipx86.com>
parents:
9219
diff
changeset
|
472 GaimXfer *xfer; |
9193 | 473 |
9226
7a00289f2ef1
[gaim-migrate @ 10022]
Christian Hammond <chipx86@chipx86.com>
parents:
9219
diff
changeset
|
474 xfer = slpmsg->slpcall->xfer; |
9193 | 475 |
9226
7a00289f2ef1
[gaim-migrate @ 10022]
Christian Hammond <chipx86@chipx86.com>
parents:
9219
diff
changeset
|
476 if (xfer != NULL) |
7a00289f2ef1
[gaim-migrate @ 10022]
Christian Hammond <chipx86@chipx86.com>
parents:
9219
diff
changeset
|
477 { |
7a00289f2ef1
[gaim-migrate @ 10022]
Christian Hammond <chipx86@chipx86.com>
parents:
9219
diff
changeset
|
478 slpmsg->fp = |
7a00289f2ef1
[gaim-migrate @ 10022]
Christian Hammond <chipx86@chipx86.com>
parents:
9219
diff
changeset
|
479 fopen(gaim_xfer_get_local_filename(slpmsg->slpcall->xfer), |
7a00289f2ef1
[gaim-migrate @ 10022]
Christian Hammond <chipx86@chipx86.com>
parents:
9219
diff
changeset
|
480 "wb"); |
7a00289f2ef1
[gaim-migrate @ 10022]
Christian Hammond <chipx86@chipx86.com>
parents:
9219
diff
changeset
|
481 } |
9193 | 482 } |
483 } | |
484 } | |
10225 | 485 if (!slpmsg->fp && slpmsg->size) |
10092 | 486 { |
487 slpmsg->buffer = g_try_malloc(slpmsg->size); | |
488 if (slpmsg->buffer == NULL) | |
489 { | |
490 gaim_debug_error("msn", "Failed to allocate buffer for slpmsg\n"); | |
491 return; | |
492 } | |
493 } | |
9193 | 494 } |
495 else | |
496 { | |
10092 | 497 slpmsg = msn_slplink_message_find(slplink, msg->msnslp_header.session_id, msg->msnslp_header.id); |
9193 | 498 } |
499 | |
500 if (slpmsg != NULL) | |
501 { | |
502 if (slpmsg->fp) | |
503 { | |
504 /* fseek(slpmsg->fp, offset, SEEK_SET); */ | |
505 len = fwrite(data, 1, len, slpmsg->fp); | |
506 } | |
10225 | 507 else if (slpmsg->size) |
9193 | 508 { |
10092 | 509 if ((offset + len) > slpmsg->size) |
510 { | |
511 gaim_debug_error("msn", "Oversized slpmsg\n"); | |
512 g_return_if_reached(); | |
513 } | |
514 else | |
515 memcpy(slpmsg->buffer + offset, data, len); | |
9193 | 516 } |
517 } | |
518 else | |
519 { | |
520 gaim_debug_error("msn", "Couldn't find slpmsg\n"); | |
521 g_return_if_reached(); | |
522 } | |
523 | |
10225 | 524 if ((slpmsg->flags == 0x20 || slpmsg->flags == 0x1000030) && (slpmsg->slpcall != NULL)) |
9193 | 525 { |
10225 | 526 if (slpmsg->slpcall->timer) |
527 { | |
528 gaim_timeout_remove(slpmsg->slpcall->timer); | |
529 slpmsg->slpcall->timer = gaim_timeout_add(MSN_SLPCALL_TIMEOUT, | |
530 msn_slp_call_timeout, slpmsg->slpcall); | |
531 } | |
532 | |
533 if (slpmsg->slpcall->progress_cb != NULL) | |
9231
ac8790437abe
[gaim-migrate @ 10027]
Christian Hammond <chipx86@chipx86.com>
parents:
9226
diff
changeset
|
534 { |
ac8790437abe
[gaim-migrate @ 10027]
Christian Hammond <chipx86@chipx86.com>
parents:
9226
diff
changeset
|
535 slpmsg->slpcall->progress_cb(slpmsg->slpcall, slpmsg->size, |
ac8790437abe
[gaim-migrate @ 10027]
Christian Hammond <chipx86@chipx86.com>
parents:
9226
diff
changeset
|
536 len, offset); |
ac8790437abe
[gaim-migrate @ 10027]
Christian Hammond <chipx86@chipx86.com>
parents:
9226
diff
changeset
|
537 } |
9193 | 538 } |
539 | |
540 #if 0 | |
541 if (slpmsg->buffer == NULL) | |
542 return; | |
543 #endif | |
544 | |
545 if (msg->msnslp_header.offset + msg->msnslp_header.length | |
546 >= msg->msnslp_header.total_size) | |
547 { | |
548 /* All the pieces of the slpmsg have been received */ | |
549 MsnSlpCall *slpcall; | |
550 | |
551 slpcall = msn_slp_process_msg(slplink, slpmsg); | |
552 | |
553 if (slpmsg->flags == 0x100) | |
554 { | |
555 MsnDirectConn *directconn; | |
556 | |
557 directconn = slplink->directconn; | |
558 | |
559 if (!directconn->acked) | |
560 msn_directconn_send_handshake(directconn); | |
561 } | |
562 else if (slpmsg->flags == 0x0 || slpmsg->flags == 0x20 || | |
563 slpmsg->flags == 0x1000030) | |
564 { | |
565 /* Release all the messages and send the ACK */ | |
566 | |
567 msn_slplink_send_ack(slplink, msg); | |
568 msn_slplink_unleash(slplink); | |
569 } | |
570 | |
571 msn_slpmsg_destroy(slpmsg); | |
572 | |
573 if (slpcall != NULL && slpcall->wasted) | |
574 msn_slp_call_destroy(slpcall); | |
575 } | |
576 } | |
577 | |
578 MsnSlpMessage * | |
10092 | 579 msn_slplink_message_find(MsnSlpLink *slplink, long session_id, long id) |
9193 | 580 { |
581 GList *e; | |
582 | |
583 for (e = slplink->slp_msgs; e != NULL; e = e->next) | |
584 { | |
585 MsnSlpMessage *slpmsg = e->data; | |
586 | |
10092 | 587 if ((slpmsg->session_id == session_id) && (slpmsg->id == id)) |
9193 | 588 return slpmsg; |
589 } | |
590 | |
591 return NULL; | |
592 } | |
593 | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
594 typedef struct |
9193 | 595 { |
596 guint32 length; | |
597 guint32 unk1; | |
598 guint32 file_size; | |
599 guint32 unk2; | |
600 guint32 unk3; | |
601 } MsnContextHeader; | |
602 | |
603 #define MAX_FILE_NAME_LEN 0x226 | |
604 | |
9571 | 605 static char * |
10047 | 606 gen_context(const char *file_name, const char *file_path) |
9193 | 607 { |
608 struct stat st; | |
609 gsize size = 0; | |
610 MsnContextHeader header; | |
10047 | 611 gchar *u8 = NULL; |
9193 | 612 gchar *base, *n; |
10047 | 613 gunichar2 *uni = NULL; |
614 glong currentChar = 0; | |
615 glong uni_len = 0; | |
9193 | 616 gsize len; |
617 | |
10088 | 618 if (stat(file_path, &st) == 0) |
9193 | 619 size = st.st_size; |
620 | |
10047 | 621 if(!file_name) { |
622 u8 = gaim_utf8_try_convert(g_basename(file_path)); | |
623 file_name = u8; | |
624 } | |
625 | |
626 uni = g_utf8_to_utf16(file_name, -1, NULL, &uni_len, NULL); | |
627 | |
628 if(u8) { | |
629 g_free(u8); | |
630 file_name = NULL; | |
631 u8 = NULL; | |
632 } | |
9193 | 633 |
634 len = sizeof(MsnContextHeader) + MAX_FILE_NAME_LEN + 4; | |
635 | |
636 header.length = GUINT32_TO_LE(len); | |
637 header.unk1 = GUINT32_TO_LE(2); | |
638 header.file_size = GUINT32_TO_LE(size); | |
639 header.unk2 = GUINT32_TO_LE(0); | |
640 header.unk3 = GUINT32_TO_LE(0); | |
10225 | 641 |
10047 | 642 base = g_malloc(len + 1); |
643 n = base; | |
9193 | 644 |
645 memcpy(n, &header, sizeof(MsnContextHeader)); | |
646 n += sizeof(MsnContextHeader); | |
647 | |
648 memset(n, 0x00, MAX_FILE_NAME_LEN); | |
10047 | 649 for(currentChar = 0; currentChar < uni_len; currentChar++) { |
650 *((gunichar2 *)n + currentChar) = GUINT16_TO_LE(uni[currentChar]); | |
651 } | |
9193 | 652 n += MAX_FILE_NAME_LEN; |
653 | |
654 memset(n, 0xFF, 4); | |
655 n += 4; | |
10225 | 656 |
9193 | 657 g_free(uni); |
658 return gaim_base64_encode(base, len); | |
659 } | |
660 | |
661 void | |
662 msn_slplink_request_ft(MsnSlpLink *slplink, GaimXfer *xfer) | |
663 { | |
664 MsnSlpCall *slpcall; | |
665 char *context; | |
666 const char *fn; | |
10047 | 667 const char *fp; |
9193 | 668 |
10047 | 669 fn = gaim_xfer_get_filename(xfer); |
670 fp = gaim_xfer_get_local_filename(xfer); | |
9193 | 671 |
672 g_return_if_fail(slplink != NULL); | |
10047 | 673 g_return_if_fail(fp != NULL); |
9193 | 674 |
675 slpcall = msn_slp_call_new(slplink); | |
676 msn_slp_call_init(slpcall, MSN_SLPCALL_DC); | |
677 | |
9571 | 678 slpcall->session_init_cb = send_file_cb; |
9715
b030f83693da
[gaim-migrate @ 10576]
Christian Hammond <chipx86@chipx86.com>
parents:
9571
diff
changeset
|
679 slpcall->end_cb = msn_xfer_end_cb; |
9193 | 680 slpcall->progress_cb = msn_xfer_progress_cb; |
9259
f5f7482678d2
[gaim-migrate @ 10058]
Christian Hammond <chipx86@chipx86.com>
parents:
9246
diff
changeset
|
681 slpcall->cb = msn_xfer_completed_cb; |
9193 | 682 slpcall->xfer = xfer; |
683 | |
684 gaim_xfer_set_cancel_send_fnc(xfer, msn_xfer_cancel); | |
685 | |
686 xfer->data = slpcall; | |
687 | |
10047 | 688 context = gen_context(fn, fp); |
9193 | 689 |
690 msn_slp_call_invite(slpcall, "5D3E02AB-6190-11D3-BBBB-00C04F795683", 2, | |
691 context); | |
692 | |
693 g_free(context); | |
694 } | |
695 | |
696 void | |
697 msn_slplink_request_object(MsnSlpLink *slplink, | |
698 const char *info, | |
699 MsnSlpCb cb, | |
10225 | 700 MsnSlpEndCb end_cb, |
9193 | 701 const MsnObject *obj) |
702 { | |
703 MsnSlpCall *slpcall; | |
704 char *msnobj_data; | |
705 char *msnobj_base64; | |
706 | |
707 g_return_if_fail(slplink != NULL); | |
9861 | 708 g_return_if_fail(obj != NULL); |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
709 |
9193 | 710 msnobj_data = msn_object_to_string(obj); |
711 msnobj_base64 = gaim_base64_encode(msnobj_data, strlen(msnobj_data)); | |
712 g_free(msnobj_data); | |
713 | |
714 slpcall = msn_slp_call_new(slplink); | |
715 msn_slp_call_init(slpcall, MSN_SLPCALL_ANY); | |
716 | |
717 slpcall->data_info = g_strdup(info); | |
718 slpcall->cb = cb; | |
10225 | 719 slpcall->end_cb = end_cb; |
9193 | 720 |
721 msn_slp_call_invite(slpcall, "A4268EEC-FEC5-49E5-95C3-F126696BDBF6", 1, | |
722 msnobj_base64); | |
723 | |
724 g_free(msnobj_base64); | |
725 } |