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