Mercurial > pidgin.yaz
annotate src/protocols/msn/slplink.c @ 10774:d83f745c997b
[gaim-migrate @ 12383]
Some escaping stuff, all over the place.
Various escaping fixes in the IRC prpl.
The core and plugins only need to escape text if it's going to be shown in
a gtkimhtml or equivalent - such as writing to a conversation window, or
gaim_notify_{formatted,userinfo}
The primary and secondary text for all notify and request API functions
do NOT need to be escaped by the core or plugins, because whether html-like
markup is required for these is UI dependent. Now we always escape these
in the Gtk UI request & notify ops.
Should I backport any of the above to oldstatus?
I also removed gaim_chat_get_display_name() - it was almost a duplicate of
gaim_chat_get_name(), and it leaked.
committer: Tailor Script <tailor@pidgin.im>
author | Stu Tomlinson <stu@nosnilmot.com> |
---|---|
date | Sat, 02 Apr 2005 17:18:43 +0000 |
parents | 888d4c328be5 |
children | 93663df88ec4 |
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 | |
10345 | 32 #ifdef MSN_DEBUG_SLP_FILES |
9193 | 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); | |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10481
diff
changeset
|
49 tf = g_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 | |
10602 | 57 /************************************************************************** |
58 * Main | |
59 **************************************************************************/ | |
60 | |
9193 | 61 MsnSlpLink * |
62 msn_slplink_new(MsnSession *session, const char *username) | |
63 { | |
64 MsnSlpLink *slplink; | |
65 | |
10296 | 66 g_return_val_if_fail(session != NULL, NULL); |
67 | |
9193 | 68 slplink = g_new0(MsnSlpLink, 1); |
69 | |
10773 | 70 #ifdef MSN_DEBUG_SLPLINK |
71 gaim_debug_info("msn", "slplink_new: slplink(%p)\n", slplink); | |
72 #endif | |
73 | |
9193 | 74 slplink->session = session; |
75 slplink->slp_seq_id = rand() % 0xFFFFFF00 + 4; | |
76 | |
77 slplink->local_user = g_strdup(msn_user_get_passport(session->user)); | |
78 slplink->remote_user = g_strdup(username); | |
79 | |
80 slplink->slp_msg_queue = g_queue_new(); | |
81 | |
82 session->slplinks = | |
83 g_list_append(session->slplinks, slplink); | |
84 | |
85 return slplink; | |
86 } | |
87 | |
88 void | |
89 msn_slplink_destroy(MsnSlpLink *slplink) | |
90 { | |
91 MsnSession *session; | |
92 | |
10773 | 93 #ifdef MSN_DEBUG_SLPLINK |
94 gaim_debug_info("msn", "slplink_destroy: slplink(%p)\n", slplink); | |
95 #endif | |
96 | |
10296 | 97 g_return_if_fail(slplink != NULL); |
98 | |
10345 | 99 if (slplink->swboard != NULL) |
100 slplink->swboard->slplink = NULL; | |
101 | |
9193 | 102 session = slplink->session; |
103 | |
104 if (slplink->local_user != NULL) | |
105 g_free(slplink->local_user); | |
106 | |
107 if (slplink->remote_user != NULL) | |
108 g_free(slplink->remote_user); | |
109 | |
110 if (slplink->directconn != NULL) | |
111 msn_directconn_destroy(slplink->directconn); | |
112 | |
10296 | 113 while (slplink->slp_calls != NULL) |
114 msn_slp_call_destroy(slplink->slp_calls->data); | |
115 | |
9193 | 116 session->slplinks = |
117 g_list_remove(session->slplinks, slplink); | |
118 | |
119 g_free(slplink); | |
120 } | |
121 | |
122 MsnSlpLink * | |
123 msn_session_find_slplink(MsnSession *session, const char *who) | |
124 { | |
125 GList *l; | |
126 | |
127 for (l = session->slplinks; l != NULL; l = l->next) | |
128 { | |
10225 | 129 MsnSlpLink *slplink; |
130 | |
9193 | 131 slplink = l->data; |
132 | |
133 if (!strcmp(slplink->remote_user, who)) | |
134 return slplink; | |
135 } | |
136 | |
137 return NULL; | |
138 } | |
139 | |
140 MsnSlpLink * | |
141 msn_session_get_slplink(MsnSession *session, const char *username) | |
142 { | |
143 MsnSlpLink *slplink; | |
144 | |
145 slplink = msn_session_find_slplink(session, username); | |
146 | |
147 if (slplink == NULL) | |
148 slplink = msn_slplink_new(session, username); | |
149 | |
150 return slplink; | |
151 } | |
152 | |
153 MsnSlpSession * | |
154 msn_slplink_find_slp_session(MsnSlpLink *slplink, long session_id) | |
155 { | |
156 GList *l; | |
157 MsnSlpSession *slpsession; | |
158 | |
159 for (l = slplink->slp_sessions; l != NULL; l = l->next) | |
160 { | |
161 slpsession = l->data; | |
162 | |
163 if (slpsession->id == session_id) | |
164 return slpsession; | |
165 } | |
166 | |
167 return NULL; | |
168 } | |
169 | |
10602 | 170 void |
171 msn_slplink_add_slpcall(MsnSlpLink *slplink, MsnSlpCall *slpcall) | |
172 { | |
10621 | 173 if (slplink->swboard != NULL) |
174 slplink->swboard->flag |= MSN_SB_FLAG_FT; | |
10602 | 175 |
176 slplink->slp_calls = g_list_append(slplink->slp_calls, slpcall); | |
177 } | |
178 | |
179 void | |
180 msn_slplink_remove_slpcall(MsnSlpLink *slplink, MsnSlpCall *slpcall) | |
181 { | |
182 slplink->slp_calls = g_list_remove(slplink->slp_calls, slpcall); | |
183 | |
10773 | 184 /* The slplink has no slpcalls in it. If no one is using it, we might |
185 * destroy the switchboard, but we should be careful not to use the slplink | |
186 * again. */ | |
10602 | 187 if (slplink->slp_calls == NULL) |
188 { | |
189 if (slplink->swboard != NULL) | |
10773 | 190 { |
191 if (msn_switchboard_release(slplink->swboard, MSN_SB_FLAG_FT)) | |
192 /* I'm not sure this is the best thing to do, but it's better | |
193 * than nothing. */ | |
194 slpcall->slplink = NULL; | |
195 } | |
10602 | 196 } |
197 } | |
198 | |
9193 | 199 MsnSlpCall * |
200 msn_slplink_find_slp_call(MsnSlpLink *slplink, const char *id) | |
201 { | |
202 GList *l; | |
203 MsnSlpCall *slpcall; | |
204 | |
10107
65e7df286076
[gaim-migrate @ 11139]
Luke Schierer <lschiere@pidgin.im>
parents:
10092
diff
changeset
|
205 if (!id) |
65e7df286076
[gaim-migrate @ 11139]
Luke Schierer <lschiere@pidgin.im>
parents:
10092
diff
changeset
|
206 return NULL; |
65e7df286076
[gaim-migrate @ 11139]
Luke Schierer <lschiere@pidgin.im>
parents:
10092
diff
changeset
|
207 |
9193 | 208 for (l = slplink->slp_calls; l != NULL; l = l->next) |
209 { | |
210 slpcall = l->data; | |
211 | |
10107
65e7df286076
[gaim-migrate @ 11139]
Luke Schierer <lschiere@pidgin.im>
parents:
10092
diff
changeset
|
212 if (slpcall->id && !strcmp(slpcall->id, id)) |
9193 | 213 return slpcall; |
214 } | |
215 | |
216 return NULL; | |
217 } | |
218 | |
219 MsnSlpCall * | |
220 msn_slplink_find_slp_call_with_session_id(MsnSlpLink *slplink, long id) | |
221 { | |
222 GList *l; | |
223 MsnSlpCall *slpcall; | |
224 | |
225 for (l = slplink->slp_calls; l != NULL; l = l->next) | |
226 { | |
227 slpcall = l->data; | |
228 | |
229 if (slpcall->session_id == id) | |
230 return slpcall; | |
231 } | |
232 | |
233 return NULL; | |
234 } | |
235 | |
236 void | |
237 msn_slplink_send_msg(MsnSlpLink *slplink, MsnMessage *msg) | |
238 { | |
239 if (slplink->directconn != NULL) | |
240 { | |
241 msn_directconn_send_msg(slplink->directconn, msg); | |
242 } | |
243 else | |
244 { | |
10345 | 245 if (slplink->swboard == NULL) |
246 { | |
247 slplink->swboard = msn_session_get_swboard(slplink->session, | |
10773 | 248 slplink->remote_user, MSN_SB_FLAG_FT); |
9193 | 249 |
10345 | 250 if (slplink->swboard == NULL) |
251 return; | |
9193 | 252 |
10346 | 253 /* If swboard is destroyed we will be too */ |
10345 | 254 slplink->swboard->slplink = slplink; |
255 } | |
9193 | 256 |
10481 | 257 msn_switchboard_send_msg(slplink->swboard, msg, TRUE); |
9193 | 258 } |
259 } | |
260 | |
10345 | 261 /* We have received the message ack */ |
9571 | 262 static void |
10345 | 263 msg_ack(MsnMessage *msg, void *data) |
9193 | 264 { |
265 MsnSlpMessage *slpmsg; | |
266 long long real_size; | |
267 | |
10225 | 268 slpmsg = data; |
9193 | 269 |
270 real_size = (slpmsg->flags == 0x2) ? 0 : slpmsg->size; | |
271 | |
10345 | 272 slpmsg->offset += msg->msnslp_header.length; |
273 | |
9193 | 274 if (slpmsg->offset < real_size) |
275 { | |
276 msn_slplink_send_msgpart(slpmsg->slplink, slpmsg); | |
277 } | |
278 else | |
279 { | |
280 /* The whole message has been sent */ | |
281 | |
9246
e20af87d8721
[gaim-migrate @ 10045]
Christian Hammond <chipx86@chipx86.com>
parents:
9231
diff
changeset
|
282 if (slpmsg->flags == 0x20 || slpmsg->flags == 0x1000030) |
9193 | 283 { |
9246
e20af87d8721
[gaim-migrate @ 10045]
Christian Hammond <chipx86@chipx86.com>
parents:
9231
diff
changeset
|
284 if ((slpmsg->slpcall != NULL) && |
e20af87d8721
[gaim-migrate @ 10045]
Christian Hammond <chipx86@chipx86.com>
parents:
9231
diff
changeset
|
285 (slpmsg->slpcall->cb != NULL)) |
e20af87d8721
[gaim-migrate @ 10045]
Christian Hammond <chipx86@chipx86.com>
parents:
9231
diff
changeset
|
286 { |
e20af87d8721
[gaim-migrate @ 10045]
Christian Hammond <chipx86@chipx86.com>
parents:
9231
diff
changeset
|
287 slpmsg->slpcall->cb(slpmsg->slpcall, NULL, 0); |
e20af87d8721
[gaim-migrate @ 10045]
Christian Hammond <chipx86@chipx86.com>
parents:
9231
diff
changeset
|
288 } |
9193 | 289 } |
10345 | 290 } |
9193 | 291 |
10345 | 292 slpmsg->msgs = g_list_remove(slpmsg->msgs, msg); |
293 } | |
294 | |
295 /* We have received the message nak. */ | |
296 static void | |
297 msg_nak(MsnMessage *msg, void *data) | |
298 { | |
299 MsnSlpMessage *slpmsg; | |
300 | |
301 slpmsg = data; | |
302 | |
303 msn_slplink_send_msgpart(slpmsg->slplink, slpmsg); | |
304 | |
305 slpmsg->msgs = g_list_remove(slpmsg->msgs, msg); | |
9193 | 306 } |
307 | |
308 void | |
309 msn_slplink_send_msgpart(MsnSlpLink *slplink, MsnSlpMessage *slpmsg) | |
310 { | |
311 MsnMessage *msg; | |
312 long long real_size; | |
313 size_t len = 0; | |
314 | |
10345 | 315 /* Maybe we will want to create a new msg for this slpmsg instead of |
316 * reusing the same one all the time. */ | |
9193 | 317 msg = slpmsg->msg; |
318 | |
319 real_size = (slpmsg->flags == 0x2) ? 0 : slpmsg->size; | |
320 | |
321 if (slpmsg->offset < real_size) | |
322 { | |
323 if (slpmsg->fp) | |
324 { | |
325 char data[1202]; | |
326 len = fread(data, 1, sizeof(data), slpmsg->fp); | |
327 msn_message_set_bin_data(msg, data, len); | |
328 } | |
329 else | |
330 { | |
331 len = slpmsg->size - slpmsg->offset; | |
332 | |
333 if (len > 1202) | |
334 len = 1202; | |
335 | |
336 msn_message_set_bin_data(msg, slpmsg->buffer + slpmsg->offset, len); | |
337 } | |
338 | |
339 msg->msnslp_header.offset = slpmsg->offset; | |
340 msg->msnslp_header.length = len; | |
341 } | |
342 | |
10345 | 343 #ifdef MSN_DEBUG_SLP |
9193 | 344 msn_message_show_readable(msg, slpmsg->info, slpmsg->text_body); |
345 #endif | |
346 | |
10345 | 347 #ifdef MSN_DEBUG_SLP_FILES |
9193 | 348 debug_msg_to_file(msg, TRUE); |
349 #endif | |
350 | |
10345 | 351 slpmsg->msgs = |
352 g_list_append(slpmsg->msgs, msg); | |
9193 | 353 msn_slplink_send_msg(slplink, msg); |
354 | |
10345 | 355 if ((slpmsg->flags == 0x20 || slpmsg->flags == 0x1000030) && |
356 (slpmsg->slpcall != NULL)) | |
9193 | 357 { |
10296 | 358 slpmsg->slpcall->progress = TRUE; |
10225 | 359 |
360 if (slpmsg->slpcall->progress_cb != NULL) | |
9226
7a00289f2ef1
[gaim-migrate @ 10022]
Christian Hammond <chipx86@chipx86.com>
parents:
9219
diff
changeset
|
361 { |
9231
ac8790437abe
[gaim-migrate @ 10027]
Christian Hammond <chipx86@chipx86.com>
parents:
9226
diff
changeset
|
362 slpmsg->slpcall->progress_cb(slpmsg->slpcall, slpmsg->size, |
ac8790437abe
[gaim-migrate @ 10027]
Christian Hammond <chipx86@chipx86.com>
parents:
9226
diff
changeset
|
363 len, slpmsg->offset); |
9226
7a00289f2ef1
[gaim-migrate @ 10022]
Christian Hammond <chipx86@chipx86.com>
parents:
9219
diff
changeset
|
364 } |
9193 | 365 } |
366 | |
10345 | 367 /* slpmsg->offset += len; */ |
9193 | 368 } |
369 | |
370 void | |
10345 | 371 msn_slplink_release_slpmsg(MsnSlpLink *slplink, MsnSlpMessage *slpmsg) |
9193 | 372 { |
373 MsnMessage *msg; | |
374 | |
375 slpmsg->msg = msg = msn_message_new_msnslp(); | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
376 |
9193 | 377 if (slpmsg->flags == 0x0) |
378 { | |
379 msg->msnslp_header.session_id = slpmsg->session_id; | |
380 msg->msnslp_header.ack_id = rand() % 0xFFFFFF00; | |
381 } | |
382 else if (slpmsg->flags == 0x2) | |
383 { | |
384 msg->msnslp_header.session_id = slpmsg->session_id; | |
385 msg->msnslp_header.ack_id = slpmsg->ack_id; | |
386 msg->msnslp_header.ack_size = slpmsg->ack_size; | |
387 } | |
388 else if (slpmsg->flags == 0x20 || slpmsg->flags == 0x1000030) | |
389 { | |
390 MsnSlpSession *slpsession; | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
391 slpsession = slpmsg->slpsession; |
9193 | 392 |
393 g_return_if_fail(slpsession != NULL); | |
394 msg->msnslp_header.session_id = slpsession->id; | |
395 msg->msnslp_footer.value = slpsession->app_id; | |
396 msg->msnslp_header.ack_id = rand() % 0xFFFFFF00; | |
397 } | |
398 else if (slpmsg->flags == 0x100) | |
399 { | |
400 msg->msnslp_header.ack_id = slpmsg->ack_id; | |
401 msg->msnslp_header.ack_sub_id = slpmsg->ack_sub_id; | |
402 msg->msnslp_header.ack_size = slpmsg->ack_size; | |
403 } | |
404 | |
405 msg->msnslp_header.id = slpmsg->id; | |
406 msg->msnslp_header.flags = slpmsg->flags; | |
407 | |
408 msg->msnslp_header.total_size = slpmsg->size; | |
409 | |
410 msn_message_set_attr(msg, "P2P-Dest", slplink->remote_user); | |
411 | |
10225 | 412 msg->ack_cb = msg_ack; |
10345 | 413 msg->nak_cb = msg_nak; |
9193 | 414 msg->ack_data = slpmsg; |
415 | |
416 msn_slplink_send_msgpart(slplink, slpmsg); | |
10284 | 417 |
418 msn_message_destroy(msg); | |
9193 | 419 } |
420 | |
421 void | |
422 msn_slplink_queue_slpmsg(MsnSlpLink *slplink, MsnSlpMessage *slpmsg) | |
423 { | |
424 slpmsg->id = slplink->slp_seq_id++; | |
425 | |
426 g_queue_push_head(slplink->slp_msg_queue, slpmsg); | |
427 } | |
428 | |
429 void | |
430 msn_slplink_send_slpmsg(MsnSlpLink *slplink, MsnSlpMessage *slpmsg) | |
431 { | |
432 slpmsg->id = slplink->slp_seq_id++; | |
433 | |
10345 | 434 msn_slplink_release_slpmsg(slplink, slpmsg); |
9193 | 435 } |
436 | |
437 void | |
438 msn_slplink_unleash(MsnSlpLink *slplink) | |
439 { | |
440 MsnSlpMessage *slpmsg; | |
441 | |
442 /* Send the queued msgs in the order they came. */ | |
443 | |
444 while ((slpmsg = g_queue_pop_tail(slplink->slp_msg_queue)) != NULL) | |
10345 | 445 { |
446 msn_slplink_release_slpmsg(slplink, slpmsg); | |
447 } | |
9193 | 448 } |
449 | |
450 void | |
451 msn_slplink_send_ack(MsnSlpLink *slplink, MsnMessage *msg) | |
452 { | |
453 MsnSlpMessage *slpmsg; | |
454 | |
455 slpmsg = msn_slpmsg_new(slplink); | |
456 | |
457 slpmsg->session_id = msg->msnslp_header.session_id; | |
458 slpmsg->size = msg->msnslp_header.total_size; | |
459 slpmsg->flags = 0x02; | |
460 slpmsg->ack_id = msg->msnslp_header.id; | |
461 slpmsg->ack_sub_id = msg->msnslp_header.ack_id; | |
462 slpmsg->ack_size = msg->msnslp_header.total_size; | |
463 | |
10345 | 464 #ifdef MSN_DEBUG_SLP |
9193 | 465 slpmsg->info = "SLP ACK"; |
466 #endif | |
467 | |
468 msn_slplink_send_slpmsg(slplink, slpmsg); | |
469 } | |
470 | |
9571 | 471 static void |
472 send_file_cb(MsnSlpSession *slpsession) | |
9193 | 473 { |
474 MsnSlpCall *slpcall; | |
475 MsnSlpMessage *slpmsg; | |
476 | |
477 slpcall = slpsession->slpcall; | |
478 slpmsg = msn_slpmsg_new(slpcall->slplink); | |
10345 | 479 slpmsg->slpcall = slpcall; |
9193 | 480 slpmsg->flags = 0x1000030; |
481 slpmsg->slpsession = slpsession; | |
10345 | 482 #ifdef MSN_DEBUG_SLP |
9193 | 483 slpmsg->info = "SLP FILE"; |
484 #endif | |
485 msn_slpmsg_open_file(slpmsg, gaim_xfer_get_local_filename(slpcall->xfer)); | |
486 | |
487 msn_slplink_send_slpmsg(slpcall->slplink, slpmsg); | |
488 } | |
489 | |
490 void | |
491 msn_slplink_process_msg(MsnSlpLink *slplink, MsnMessage *msg) | |
492 { | |
493 MsnSlpMessage *slpmsg; | |
494 const char *data; | |
495 gsize offset; | |
496 gsize len; | |
497 | |
10345 | 498 #ifdef MSN_DEBUG_SLP |
9193 | 499 msn_slpmsg_show(msg); |
500 #endif | |
501 | |
10345 | 502 #ifdef MSN_DEBUG_SLP_FILES |
9193 | 503 debug_msg_to_file(msg, FALSE); |
504 #endif | |
505 | |
506 if (msg->msnslp_header.total_size < msg->msnslp_header.length) | |
507 { | |
508 gaim_debug_error("msn", "This can't be good\n"); | |
509 g_return_if_reached(); | |
510 } | |
511 | |
512 slpmsg = NULL; | |
513 data = msn_message_get_bin_data(msg, &len); | |
514 | |
515 /* | |
516 OVERHEAD! | |
517 if (msg->msnslp_header.length < msg->msnslp_header.total_size) | |
518 */ | |
519 | |
520 offset = msg->msnslp_header.offset; | |
521 | |
522 if (offset == 0) | |
523 { | |
524 slpmsg = msn_slpmsg_new(slplink); | |
525 slpmsg->id = msg->msnslp_header.id; | |
526 slpmsg->session_id = msg->msnslp_header.session_id; | |
527 slpmsg->size = msg->msnslp_header.total_size; | |
528 slpmsg->flags = msg->msnslp_header.flags; | |
529 | |
530 if (slpmsg->session_id) | |
531 { | |
532 if (slpmsg->slpcall == NULL) | |
533 slpmsg->slpcall = msn_slplink_find_slp_call_with_session_id(slplink, slpmsg->session_id); | |
534 | |
535 if (slpmsg->slpcall != NULL) | |
536 { | |
9226
7a00289f2ef1
[gaim-migrate @ 10022]
Christian Hammond <chipx86@chipx86.com>
parents:
9219
diff
changeset
|
537 if (slpmsg->flags == 0x20 || slpmsg->flags == 0x1000030) |
7a00289f2ef1
[gaim-migrate @ 10022]
Christian Hammond <chipx86@chipx86.com>
parents:
9219
diff
changeset
|
538 { |
7a00289f2ef1
[gaim-migrate @ 10022]
Christian Hammond <chipx86@chipx86.com>
parents:
9219
diff
changeset
|
539 GaimXfer *xfer; |
9193 | 540 |
9226
7a00289f2ef1
[gaim-migrate @ 10022]
Christian Hammond <chipx86@chipx86.com>
parents:
9219
diff
changeset
|
541 xfer = slpmsg->slpcall->xfer; |
9193 | 542 |
9226
7a00289f2ef1
[gaim-migrate @ 10022]
Christian Hammond <chipx86@chipx86.com>
parents:
9219
diff
changeset
|
543 if (xfer != NULL) |
7a00289f2ef1
[gaim-migrate @ 10022]
Christian Hammond <chipx86@chipx86.com>
parents:
9219
diff
changeset
|
544 { |
7a00289f2ef1
[gaim-migrate @ 10022]
Christian Hammond <chipx86@chipx86.com>
parents:
9219
diff
changeset
|
545 slpmsg->fp = |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10481
diff
changeset
|
546 g_fopen(gaim_xfer_get_local_filename(slpmsg->slpcall->xfer), |
9226
7a00289f2ef1
[gaim-migrate @ 10022]
Christian Hammond <chipx86@chipx86.com>
parents:
9219
diff
changeset
|
547 "wb"); |
7a00289f2ef1
[gaim-migrate @ 10022]
Christian Hammond <chipx86@chipx86.com>
parents:
9219
diff
changeset
|
548 } |
9193 | 549 } |
550 } | |
551 } | |
10225 | 552 if (!slpmsg->fp && slpmsg->size) |
10092 | 553 { |
554 slpmsg->buffer = g_try_malloc(slpmsg->size); | |
555 if (slpmsg->buffer == NULL) | |
556 { | |
557 gaim_debug_error("msn", "Failed to allocate buffer for slpmsg\n"); | |
558 return; | |
559 } | |
560 } | |
9193 | 561 } |
562 else | |
563 { | |
10092 | 564 slpmsg = msn_slplink_message_find(slplink, msg->msnslp_header.session_id, msg->msnslp_header.id); |
9193 | 565 } |
566 | |
10345 | 567 if (slpmsg == NULL) |
9193 | 568 { |
10345 | 569 /* Probably the transfer was canceled */ |
9193 | 570 gaim_debug_error("msn", "Couldn't find slpmsg\n"); |
10345 | 571 return; |
9193 | 572 } |
573 | |
10345 | 574 if (slpmsg->fp) |
575 { | |
576 /* fseek(slpmsg->fp, offset, SEEK_SET); */ | |
577 len = fwrite(data, 1, len, slpmsg->fp); | |
578 } | |
579 else if (slpmsg->size) | |
580 { | |
581 if ((offset + len) > slpmsg->size) | |
582 { | |
583 gaim_debug_error("msn", "Oversized slpmsg\n"); | |
584 g_return_if_reached(); | |
585 } | |
586 else | |
587 memcpy(slpmsg->buffer + offset, data, len); | |
588 } | |
589 | |
590 if ((slpmsg->flags == 0x20 || slpmsg->flags == 0x1000030) && | |
591 (slpmsg->slpcall != NULL)) | |
9193 | 592 { |
10296 | 593 slpmsg->slpcall->progress = TRUE; |
10225 | 594 |
595 if (slpmsg->slpcall->progress_cb != NULL) | |
9231
ac8790437abe
[gaim-migrate @ 10027]
Christian Hammond <chipx86@chipx86.com>
parents:
9226
diff
changeset
|
596 { |
ac8790437abe
[gaim-migrate @ 10027]
Christian Hammond <chipx86@chipx86.com>
parents:
9226
diff
changeset
|
597 slpmsg->slpcall->progress_cb(slpmsg->slpcall, slpmsg->size, |
ac8790437abe
[gaim-migrate @ 10027]
Christian Hammond <chipx86@chipx86.com>
parents:
9226
diff
changeset
|
598 len, offset); |
ac8790437abe
[gaim-migrate @ 10027]
Christian Hammond <chipx86@chipx86.com>
parents:
9226
diff
changeset
|
599 } |
9193 | 600 } |
601 | |
602 #if 0 | |
603 if (slpmsg->buffer == NULL) | |
604 return; | |
605 #endif | |
606 | |
607 if (msg->msnslp_header.offset + msg->msnslp_header.length | |
608 >= msg->msnslp_header.total_size) | |
609 { | |
610 /* All the pieces of the slpmsg have been received */ | |
611 MsnSlpCall *slpcall; | |
612 | |
613 slpcall = msn_slp_process_msg(slplink, slpmsg); | |
614 | |
615 if (slpmsg->flags == 0x100) | |
616 { | |
617 MsnDirectConn *directconn; | |
618 | |
619 directconn = slplink->directconn; | |
620 | |
621 if (!directconn->acked) | |
622 msn_directconn_send_handshake(directconn); | |
623 } | |
624 else if (slpmsg->flags == 0x0 || slpmsg->flags == 0x20 || | |
625 slpmsg->flags == 0x1000030) | |
626 { | |
627 /* Release all the messages and send the ACK */ | |
628 | |
629 msn_slplink_send_ack(slplink, msg); | |
630 msn_slplink_unleash(slplink); | |
631 } | |
632 | |
633 msn_slpmsg_destroy(slpmsg); | |
634 | |
635 if (slpcall != NULL && slpcall->wasted) | |
636 msn_slp_call_destroy(slpcall); | |
637 } | |
638 } | |
639 | |
640 MsnSlpMessage * | |
10092 | 641 msn_slplink_message_find(MsnSlpLink *slplink, long session_id, long id) |
9193 | 642 { |
643 GList *e; | |
644 | |
645 for (e = slplink->slp_msgs; e != NULL; e = e->next) | |
646 { | |
647 MsnSlpMessage *slpmsg = e->data; | |
648 | |
10092 | 649 if ((slpmsg->session_id == session_id) && (slpmsg->id == id)) |
9193 | 650 return slpmsg; |
651 } | |
652 | |
653 return NULL; | |
654 } | |
655 | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
656 typedef struct |
9193 | 657 { |
658 guint32 length; | |
659 guint32 unk1; | |
660 guint32 file_size; | |
661 guint32 unk2; | |
662 guint32 unk3; | |
663 } MsnContextHeader; | |
664 | |
665 #define MAX_FILE_NAME_LEN 0x226 | |
666 | |
10388 | 667 static unsigned char * |
10047 | 668 gen_context(const char *file_name, const char *file_path) |
9193 | 669 { |
670 struct stat st; | |
671 gsize size = 0; | |
672 MsnContextHeader header; | |
10047 | 673 gchar *u8 = NULL; |
10388 | 674 guchar *base, *n; |
10047 | 675 gunichar2 *uni = NULL; |
676 glong currentChar = 0; | |
677 glong uni_len = 0; | |
9193 | 678 gsize len; |
679 | |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10481
diff
changeset
|
680 if (g_stat(file_path, &st) == 0) |
9193 | 681 size = st.st_size; |
682 | |
10047 | 683 if(!file_name) { |
684 u8 = gaim_utf8_try_convert(g_basename(file_path)); | |
685 file_name = u8; | |
686 } | |
687 | |
688 uni = g_utf8_to_utf16(file_name, -1, NULL, &uni_len, NULL); | |
689 | |
690 if(u8) { | |
691 g_free(u8); | |
692 file_name = NULL; | |
693 u8 = NULL; | |
694 } | |
9193 | 695 |
696 len = sizeof(MsnContextHeader) + MAX_FILE_NAME_LEN + 4; | |
697 | |
698 header.length = GUINT32_TO_LE(len); | |
699 header.unk1 = GUINT32_TO_LE(2); | |
700 header.file_size = GUINT32_TO_LE(size); | |
701 header.unk2 = GUINT32_TO_LE(0); | |
702 header.unk3 = GUINT32_TO_LE(0); | |
10225 | 703 |
10047 | 704 base = g_malloc(len + 1); |
705 n = base; | |
9193 | 706 |
707 memcpy(n, &header, sizeof(MsnContextHeader)); | |
708 n += sizeof(MsnContextHeader); | |
709 | |
710 memset(n, 0x00, MAX_FILE_NAME_LEN); | |
10047 | 711 for(currentChar = 0; currentChar < uni_len; currentChar++) { |
712 *((gunichar2 *)n + currentChar) = GUINT16_TO_LE(uni[currentChar]); | |
713 } | |
9193 | 714 n += MAX_FILE_NAME_LEN; |
715 | |
716 memset(n, 0xFF, 4); | |
717 n += 4; | |
10225 | 718 |
9193 | 719 g_free(uni); |
720 return gaim_base64_encode(base, len); | |
721 } | |
722 | |
723 void | |
724 msn_slplink_request_ft(MsnSlpLink *slplink, GaimXfer *xfer) | |
725 { | |
726 MsnSlpCall *slpcall; | |
727 char *context; | |
728 const char *fn; | |
10047 | 729 const char *fp; |
9193 | 730 |
10047 | 731 fn = gaim_xfer_get_filename(xfer); |
732 fp = gaim_xfer_get_local_filename(xfer); | |
9193 | 733 |
734 g_return_if_fail(slplink != NULL); | |
10047 | 735 g_return_if_fail(fp != NULL); |
9193 | 736 |
737 slpcall = msn_slp_call_new(slplink); | |
738 msn_slp_call_init(slpcall, MSN_SLPCALL_DC); | |
739 | |
9571 | 740 slpcall->session_init_cb = send_file_cb; |
9715
b030f83693da
[gaim-migrate @ 10576]
Christian Hammond <chipx86@chipx86.com>
parents:
9571
diff
changeset
|
741 slpcall->end_cb = msn_xfer_end_cb; |
9193 | 742 slpcall->progress_cb = msn_xfer_progress_cb; |
9259
f5f7482678d2
[gaim-migrate @ 10058]
Christian Hammond <chipx86@chipx86.com>
parents:
9246
diff
changeset
|
743 slpcall->cb = msn_xfer_completed_cb; |
9193 | 744 slpcall->xfer = xfer; |
745 | |
10296 | 746 slpcall->pending = TRUE; |
747 | |
9193 | 748 gaim_xfer_set_cancel_send_fnc(xfer, msn_xfer_cancel); |
749 | |
750 xfer->data = slpcall; | |
751 | |
10047 | 752 context = gen_context(fn, fp); |
9193 | 753 |
754 msn_slp_call_invite(slpcall, "5D3E02AB-6190-11D3-BBBB-00C04F795683", 2, | |
755 context); | |
756 | |
757 g_free(context); | |
758 } | |
759 | |
760 void | |
761 msn_slplink_request_object(MsnSlpLink *slplink, | |
762 const char *info, | |
763 MsnSlpCb cb, | |
10225 | 764 MsnSlpEndCb end_cb, |
9193 | 765 const MsnObject *obj) |
766 { | |
767 MsnSlpCall *slpcall; | |
10388 | 768 unsigned char *msnobj_data; |
769 unsigned char *msnobj_base64; | |
9193 | 770 |
771 g_return_if_fail(slplink != NULL); | |
9861 | 772 g_return_if_fail(obj != NULL); |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
773 |
9193 | 774 msnobj_data = msn_object_to_string(obj); |
775 msnobj_base64 = gaim_base64_encode(msnobj_data, strlen(msnobj_data)); | |
776 g_free(msnobj_data); | |
777 | |
778 slpcall = msn_slp_call_new(slplink); | |
779 msn_slp_call_init(slpcall, MSN_SLPCALL_ANY); | |
780 | |
781 slpcall->data_info = g_strdup(info); | |
782 slpcall->cb = cb; | |
10225 | 783 slpcall->end_cb = end_cb; |
9193 | 784 |
785 msn_slp_call_invite(slpcall, "A4268EEC-FEC5-49E5-95C3-F126696BDBF6", 1, | |
786 msnobj_base64); | |
787 | |
788 g_free(msnobj_base64); | |
789 } |