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