Mercurial > pidgin
annotate src/protocols/msn/slp.c @ 10520:976c7b186789
[gaim-migrate @ 11835]
It turns out that Windows 2000 and ME will load icons with a greater color depth than 4 bits, but will only display them in 4-bit color. This is very ugly, so the new icons will only be used for Windows XP and newer.
committer: Tailor Script <tailor@pidgin.im>
author | Daniel Atallah <daniel.atallah@gmail.com> |
---|---|
date | Mon, 17 Jan 2005 01:35:42 +0000 |
parents | bec9130b24d2 |
children | 55e7d72fc09a |
rev | line source |
---|---|
9193 | 1 /** |
2 * @file msnslp.c MSNSLP support | |
3 * | |
4 * gaim | |
5 * | |
9198
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. |
9193 | 9 * |
10 * This program is free software; you can redistribute it and/or modify | |
11 * it under the terms of the GNU General Public License as published by | |
12 * the Free Software Foundation; either version 2 of the License, or | |
13 * (at your option) any later version. | |
14 * | |
15 * This program is distributed in the hope that it will be useful, | |
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 * GNU General Public License for more details. | |
19 * | |
20 * You should have received a copy of the GNU General Public License | |
21 * along with this program; if not, write to the Free Software | |
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
23 */ | |
24 #include "msn.h" | |
25 #include "slp.h" | |
26 #include "slpcall.h" | |
27 #include "slpmsg.h" | |
28 #include "slpsession.h" | |
29 | |
30 #include "object.h" | |
31 #include "user.h" | |
32 #include "switchboard.h" | |
33 | |
34 /* #include "slplink.h" */ | |
35 /* #include "directconn.h" */ | |
36 | |
37 static void send_ok(MsnSlpCall *slpcall, const char *branch, | |
38 const char *type, const char *content); | |
39 | |
40 static void send_decline(MsnSlpCall *slpcall, const char *branch, | |
41 const char *type, const char *content); | |
42 | |
9860 | 43 void msn_request_user_display(MsnUser *user); |
44 | |
9193 | 45 /************************************************************************** |
46 * Util | |
47 **************************************************************************/ | |
48 | |
49 char * | |
50 get_token(const char *str, const char *start, const char *end) | |
51 { | |
52 const char *c, *c2; | |
53 | |
54 if ((c = strstr(str, start)) == NULL) | |
55 return NULL; | |
56 | |
57 c += strlen(start); | |
58 | |
59 if (end != NULL) | |
60 { | |
61 if ((c2 = strstr(c, end)) == NULL) | |
62 return NULL; | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
63 |
9193 | 64 return g_strndup(c, c2 - c); |
65 } | |
66 else | |
67 { | |
68 /* This has to be changed */ | |
69 return g_strdup(c); | |
70 } | |
71 | |
72 } | |
73 | |
74 /************************************************************************** | |
75 * Xfer | |
76 **************************************************************************/ | |
77 | |
78 static void | |
79 msn_xfer_init(GaimXfer *xfer) | |
80 { | |
81 MsnSlpCall *slpcall; | |
82 /* MsnSlpLink *slplink; */ | |
83 char *content; | |
84 | |
85 gaim_debug_info("msn", "xfer_init\n"); | |
86 | |
87 slpcall = xfer->data; | |
88 | |
89 /* Send Ok */ | |
90 content = g_strdup_printf("SessionID: %lu\r\n\r\n", | |
91 slpcall->session_id); | |
92 | |
93 send_ok(slpcall, slpcall->branch, "application/x-msnmsgr-sessionreqbody", | |
94 content); | |
95 | |
96 g_free(content); | |
97 msn_slplink_unleash(slpcall->slplink); | |
98 } | |
99 | |
100 void | |
101 msn_xfer_cancel(GaimXfer *xfer) | |
102 { | |
103 MsnSlpCall *slpcall; | |
104 char *content; | |
105 | |
9788 | 106 g_return_if_fail(xfer != NULL); |
107 g_return_if_fail(xfer->data != NULL); | |
108 | |
9193 | 109 slpcall = xfer->data; |
110 | |
111 if (gaim_xfer_get_status(xfer) == GAIM_XFER_STATUS_CANCEL_LOCAL) | |
112 { | |
113 if (slpcall->started) | |
114 { | |
115 msn_slp_call_close(slpcall); | |
116 } | |
117 else | |
118 { | |
119 content = g_strdup_printf("SessionID: %lu\r\n\r\n", | |
120 slpcall->session_id); | |
121 | |
122 send_decline(slpcall, slpcall->branch, "application/x-msnmsgr-sessionreqbody", | |
123 content); | |
124 | |
125 g_free(content); | |
126 msn_slplink_unleash(slpcall->slplink); | |
127 } | |
128 } | |
129 } | |
130 | |
131 void | |
132 msn_xfer_progress_cb(MsnSlpCall *slpcall, gsize total_length, gsize len, gsize offset) | |
133 { | |
134 GaimXfer *xfer; | |
135 | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
136 xfer = slpcall->xfer; |
9193 | 137 |
9226
7a00289f2ef1
[gaim-migrate @ 10022]
Christian Hammond <chipx86@chipx86.com>
parents:
9198
diff
changeset
|
138 xfer->bytes_sent = (offset + len); |
7a00289f2ef1
[gaim-migrate @ 10022]
Christian Hammond <chipx86@chipx86.com>
parents:
9198
diff
changeset
|
139 xfer->bytes_remaining = total_length - (offset + len); |
9193 | 140 |
141 gaim_xfer_update_progress(xfer); | |
142 } | |
143 | |
144 void | |
9259
f5f7482678d2
[gaim-migrate @ 10058]
Christian Hammond <chipx86@chipx86.com>
parents:
9231
diff
changeset
|
145 msn_xfer_end_cb(MsnSlpCall *slpcall) |
9193 | 146 { |
10225 | 147 if ((gaim_xfer_get_status(slpcall->xfer) != GAIM_XFER_STATUS_DONE) && |
148 (gaim_xfer_get_status(slpcall->xfer) != GAIM_XFER_STATUS_CANCEL_REMOTE) && | |
149 (gaim_xfer_get_status(slpcall->xfer) != GAIM_XFER_STATUS_CANCEL_LOCAL)) | |
9226
7a00289f2ef1
[gaim-migrate @ 10022]
Christian Hammond <chipx86@chipx86.com>
parents:
9198
diff
changeset
|
150 { |
10226 | 151 gaim_xfer_cancel_remote(slpcall->xfer); |
9226
7a00289f2ef1
[gaim-migrate @ 10022]
Christian Hammond <chipx86@chipx86.com>
parents:
9198
diff
changeset
|
152 } |
9193 | 153 } |
154 | |
9259
f5f7482678d2
[gaim-migrate @ 10058]
Christian Hammond <chipx86@chipx86.com>
parents:
9231
diff
changeset
|
155 void |
f5f7482678d2
[gaim-migrate @ 10058]
Christian Hammond <chipx86@chipx86.com>
parents:
9231
diff
changeset
|
156 msn_xfer_completed_cb(MsnSlpCall *slpcall, const char *body, |
f5f7482678d2
[gaim-migrate @ 10058]
Christian Hammond <chipx86@chipx86.com>
parents:
9231
diff
changeset
|
157 long long size) |
f5f7482678d2
[gaim-migrate @ 10058]
Christian Hammond <chipx86@chipx86.com>
parents:
9231
diff
changeset
|
158 { |
f5f7482678d2
[gaim-migrate @ 10058]
Christian Hammond <chipx86@chipx86.com>
parents:
9231
diff
changeset
|
159 gaim_xfer_set_completed(slpcall->xfer, TRUE); |
f5f7482678d2
[gaim-migrate @ 10058]
Christian Hammond <chipx86@chipx86.com>
parents:
9231
diff
changeset
|
160 } |
f5f7482678d2
[gaim-migrate @ 10058]
Christian Hammond <chipx86@chipx86.com>
parents:
9231
diff
changeset
|
161 |
9193 | 162 /************************************************************************** |
163 * SLP Control | |
164 **************************************************************************/ | |
165 | |
166 #if 0 | |
167 static void | |
168 got_transresp(MsnSlpCall *slpcall, const char *nonce, | |
169 const char *ips_str, int port) | |
170 { | |
171 MsnDirectConn *directconn; | |
172 char **ip_addrs, **c; | |
173 | |
174 directconn = msn_directconn_new(slpcall->slplink); | |
175 | |
176 directconn->initial_call = slpcall; | |
177 | |
178 /* msn_directconn_parse_nonce(directconn, nonce); */ | |
179 directconn->nonce = g_strdup(nonce); | |
180 | |
181 ip_addrs = g_strsplit(ips_str, " ", -1); | |
182 | |
183 for (c = ip_addrs; *c != NULL; c++) | |
184 { | |
185 gaim_debug_info("msn", "ip_addr = %s\n", *c); | |
186 if (msn_directconn_connect(directconn, *c, port)) | |
187 break; | |
188 } | |
189 | |
190 g_strfreev(ip_addrs); | |
191 } | |
192 #endif | |
193 | |
194 static void | |
195 send_ok(MsnSlpCall *slpcall, const char *branch, | |
196 const char *type, const char *content) | |
197 { | |
198 MsnSlpLink *slplink; | |
199 MsnSlpMessage *slpmsg; | |
200 | |
201 slplink = slpcall->slplink; | |
202 | |
203 /* 200 OK */ | |
204 slpmsg = msn_slpmsg_sip_new(slpcall, 1, | |
205 "MSNSLP/1.0 200 OK", | |
206 branch, type, content); | |
207 | |
10345 | 208 #ifdef MSN_DEBUG_SLP |
9193 | 209 slpmsg->info = "SLP 200 OK"; |
210 slpmsg->text_body = TRUE; | |
211 #endif | |
212 | |
213 msn_slplink_queue_slpmsg(slplink, slpmsg); | |
214 | |
215 msn_slp_call_session_init(slpcall); | |
216 } | |
217 | |
218 static void | |
219 send_decline(MsnSlpCall *slpcall, const char *branch, | |
220 const char *type, const char *content) | |
221 { | |
222 MsnSlpLink *slplink; | |
223 MsnSlpMessage *slpmsg; | |
224 | |
225 slplink = slpcall->slplink; | |
226 | |
227 /* 603 Decline */ | |
228 slpmsg = msn_slpmsg_sip_new(slpcall, 1, | |
229 "MSNSLP/1.0 603 Decline", | |
230 branch, type, content); | |
231 | |
10345 | 232 #ifdef MSN_DEBUG_SLP |
9193 | 233 slpmsg->info = "SLP 603 Decline"; |
234 slpmsg->text_body = TRUE; | |
235 #endif | |
236 | |
237 msn_slplink_queue_slpmsg(slplink, slpmsg); | |
238 } | |
239 | |
10047 | 240 #define MAX_FILE_NAME_LEN 0x226 |
241 | |
9193 | 242 static void |
243 got_sessionreq(MsnSlpCall *slpcall, const char *branch, | |
244 const char *euf_guid, const char *context) | |
245 { | |
246 if (!strcmp(euf_guid, "A4268EEC-FEC5-49E5-95C3-F126696BDBF6")) | |
247 { | |
248 /* Emoticon or UserDisplay */ | |
249 MsnSlpSession *slpsession; | |
250 MsnSlpLink *slplink; | |
251 MsnSlpMessage *slpmsg; | |
252 MsnObject *obj; | |
253 char *msnobj_data; | |
254 const char *sha1c; | |
255 const char *file_name; | |
256 char *content; | |
10112 | 257 int len; |
9193 | 258 int type; |
259 | |
260 /* Send Ok */ | |
261 content = g_strdup_printf("SessionID: %lu\r\n\r\n", | |
262 slpcall->session_id); | |
263 | |
264 send_ok(slpcall, branch, "application/x-msnmsgr-sessionreqbody", | |
265 content); | |
266 | |
267 g_free(content); | |
268 | |
269 slplink = slpcall->slplink; | |
270 | |
271 gaim_base64_decode(context, &msnobj_data, &len); | |
272 obj = msn_object_new_from_string(msnobj_data); | |
273 type = msn_object_get_type(obj); | |
274 sha1c = msn_object_get_sha1c(obj); | |
275 g_free(msnobj_data); | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
276 |
9193 | 277 if (!(type == MSN_OBJECT_USERTILE)) |
278 { | |
279 gaim_debug_error("msn", "Wrong object?\n"); | |
280 msn_object_destroy(obj); | |
281 g_return_if_reached(); | |
282 } | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
283 |
9193 | 284 file_name = msn_object_get_real_location(obj); |
285 | |
9858 | 286 if (file_name == NULL) |
287 { | |
288 gaim_debug_error("msn", "Wrong object.\n"); | |
289 msn_object_destroy(obj); | |
290 g_return_if_reached(); | |
291 } | |
292 | |
10519 | 293 msn_object_destroy(obj); |
294 | |
9193 | 295 slpsession = msn_slplink_find_slp_session(slplink, |
9861 | 296 slpcall->session_id); |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
297 |
9193 | 298 /* DATA PREP */ |
299 slpmsg = msn_slpmsg_new(slplink); | |
10345 | 300 slpmsg->slpcall = slpcall; |
9193 | 301 slpmsg->slpsession = slpsession; |
302 slpmsg->session_id = slpsession->id; | |
303 msn_slpmsg_set_body(slpmsg, NULL, 4); | |
10345 | 304 #ifdef MSN_DEBUG_SLP |
9193 | 305 slpmsg->info = "SLP DATA PREP"; |
306 #endif | |
307 msn_slplink_queue_slpmsg(slplink, slpmsg); | |
308 | |
309 /* DATA */ | |
310 slpmsg = msn_slpmsg_new(slplink); | |
10345 | 311 slpmsg->slpcall = slpcall; |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
312 slpmsg->slpsession = slpsession; |
9193 | 313 slpmsg->flags = 0x20; |
10345 | 314 #ifdef MSN_DEBUG_SLP |
9193 | 315 slpmsg->info = "SLP DATA"; |
316 #endif | |
317 msn_slpmsg_open_file(slpmsg, file_name); | |
318 msn_slplink_queue_slpmsg(slplink, slpmsg); | |
319 } | |
320 else if (!strcmp(euf_guid, "5D3E02AB-6190-11D3-BBBB-00C04F795683")) | |
321 { | |
322 /* File Transfer */ | |
323 GaimAccount *account; | |
324 GaimXfer *xfer; | |
325 char *bin; | |
10112 | 326 int bin_len; |
9193 | 327 guint32 file_size; |
328 char *file_name; | |
10047 | 329 gunichar2 *uni_name; |
9193 | 330 |
331 account = slpcall->slplink->session->account; | |
332 | |
9259
f5f7482678d2
[gaim-migrate @ 10058]
Christian Hammond <chipx86@chipx86.com>
parents:
9231
diff
changeset
|
333 slpcall->cb = msn_xfer_completed_cb; |
f5f7482678d2
[gaim-migrate @ 10058]
Christian Hammond <chipx86@chipx86.com>
parents:
9231
diff
changeset
|
334 slpcall->end_cb = msn_xfer_end_cb; |
9193 | 335 slpcall->progress_cb = msn_xfer_progress_cb; |
336 slpcall->branch = g_strdup(branch); | |
337 | |
10296 | 338 slpcall->pending = TRUE; |
339 | |
9193 | 340 xfer = gaim_xfer_new(account, GAIM_XFER_RECEIVE, |
341 slpcall->slplink->remote_user); | |
342 | |
343 gaim_base64_decode(context, &bin, &bin_len); | |
9263
70153c759016
[gaim-migrate @ 10062]
Christian Hammond <chipx86@chipx86.com>
parents:
9259
diff
changeset
|
344 file_size = GUINT32_FROM_LE(*((gsize *)bin + 2)); |
10225 | 345 |
10047 | 346 uni_name = (gunichar2 *)(bin + 20); |
347 while(*uni_name != 0 && ((char *)uni_name - (bin + 20)) < MAX_FILE_NAME_LEN) { | |
348 *uni_name = GUINT16_FROM_LE(*uni_name); | |
349 uni_name++; | |
350 } | |
10225 | 351 |
9193 | 352 file_name = g_utf16_to_utf8((const gunichar2 *)(bin + 20), -1, |
353 NULL, NULL, NULL); | |
354 | |
355 g_free(bin); | |
356 | |
357 gaim_xfer_set_filename(xfer, file_name); | |
358 gaim_xfer_set_size(xfer, file_size); | |
359 gaim_xfer_set_init_fnc(xfer, msn_xfer_init); | |
360 gaim_xfer_set_request_denied_fnc(xfer, msn_xfer_cancel); | |
361 gaim_xfer_set_cancel_recv_fnc(xfer, msn_xfer_cancel); | |
362 | |
363 slpcall->xfer = xfer; | |
364 xfer->data = slpcall; | |
365 | |
366 gaim_xfer_request(xfer); | |
367 } | |
368 } | |
369 | |
370 void | |
371 send_bye(MsnSlpCall *slpcall, const char *type) | |
372 { | |
373 MsnSlpLink *slplink; | |
374 MsnSlpMessage *slpmsg; | |
375 char *header; | |
376 | |
377 slplink = slpcall->slplink; | |
378 | |
379 g_return_if_fail(slplink != NULL); | |
380 | |
381 header = g_strdup_printf("BYE MSNMSGR:%s MSNSLP/1.0", | |
382 slplink->local_user); | |
383 | |
384 slpmsg = msn_slpmsg_sip_new(slpcall, 0, header, | |
385 "A0D624A6-6C0C-4283-A9E0-BC97B4B46D32", | |
386 type, | |
387 "\r\n"); | |
388 g_free(header); | |
389 | |
10345 | 390 #ifdef MSN_DEBUG_SLP |
9193 | 391 slpmsg->info = "SLP BYE"; |
392 slpmsg->text_body = TRUE; | |
393 #endif | |
394 | |
395 msn_slplink_queue_slpmsg(slplink, slpmsg); | |
396 } | |
397 | |
398 static void | |
399 got_invite(MsnSlpCall *slpcall, | |
400 const char *branch, const char *type, const char *content) | |
401 { | |
402 MsnSlpLink *slplink; | |
403 | |
404 slplink = slpcall->slplink; | |
405 | |
406 if (!strcmp(type, "application/x-msnmsgr-sessionreqbody")) | |
407 { | |
408 char *euf_guid, *context; | |
409 char *temp; | |
410 | |
411 euf_guid = get_token(content, "EUF-GUID: {", "}\r\n"); | |
412 | |
413 temp = get_token(content, "SessionID: ", "\r\n"); | |
414 if (temp != NULL) | |
415 slpcall->session_id = atoi(temp); | |
416 g_free(temp); | |
417 | |
418 temp = get_token(content, "AppID: ", "\r\n"); | |
419 if (temp != NULL) | |
420 slpcall->app_id = atoi(temp); | |
421 g_free(temp); | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
422 |
9193 | 423 context = get_token(content, "Context: ", "\r\n"); |
424 | |
425 got_sessionreq(slpcall, branch, euf_guid, context); | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
426 |
9193 | 427 g_free(context); |
428 g_free(euf_guid); | |
429 } | |
430 else if (!strcmp(type, "application/x-msnmsgr-transreqbody")) | |
431 { | |
432 /* A direct connection? */ | |
433 | |
434 char *listening, *nonce; | |
435 char *content; | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
436 |
9193 | 437 if (FALSE) |
438 { | |
439 #if 0 | |
440 MsnDirectConn *directconn; | |
441 /* const char *ip_addr; */ | |
442 char *ip_port; | |
443 int port; | |
444 | |
445 /* ip_addr = gaim_prefs_get_string("/core/ft/public_ip"); */ | |
446 ip_port = "5190"; | |
447 listening = "true"; | |
448 nonce = rand_guid(); | |
449 | |
450 directconn = msn_directconn_new(slplink); | |
451 | |
452 /* msn_directconn_parse_nonce(directconn, nonce); */ | |
453 directconn->nonce = g_strdup(nonce); | |
454 | |
455 msn_directconn_listen(directconn); | |
456 | |
457 port = directconn->port; | |
458 | |
459 content = g_strdup_printf( | |
460 "Bridge: TCPv1\r\n" | |
461 "Listening: %s\r\n" | |
462 "Nonce: {%s}\r\n" | |
463 "Ipv4Internal-Addrs: 192.168.0.82\r\n" | |
464 "Ipv4Internal-Port: %d\r\n" | |
465 "\r\n", | |
466 listening, | |
467 nonce, | |
468 port); | |
469 #endif | |
470 } | |
471 else | |
472 { | |
473 listening = "false"; | |
474 nonce = g_strdup("00000000-0000-0000-0000-000000000000"); | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
475 |
9193 | 476 content = g_strdup_printf( |
477 "Bridge: TCPv1\r\n" | |
478 "Listening: %s\r\n" | |
479 "Nonce: {%s}\r\n" | |
480 "\r\n", | |
481 listening, | |
482 nonce); | |
483 } | |
484 | |
485 send_ok(slpcall, branch, | |
486 "application/x-msnmsgr-transrespbody", content); | |
487 | |
488 g_free(content); | |
489 g_free(nonce); | |
490 } | |
491 else if (!strcmp(type, "application/x-msnmsgr-transrespbody")) | |
492 { | |
493 #if 0 | |
494 char *ip_addrs; | |
495 char *temp; | |
496 char *nonce; | |
497 int port; | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
498 |
9193 | 499 nonce = get_token(content, "Nonce: {", "}\r\n"); |
500 ip_addrs = get_token(content, "IPv4Internal-Addrs: ", "\r\n"); | |
501 | |
502 temp = get_token(content, "IPv4Internal-Port: ", "\r\n"); | |
503 if (temp != NULL) | |
504 port = atoi(temp); | |
505 else | |
506 port = -1; | |
507 g_free(temp); | |
508 | |
509 if (ip_addrs == NULL) | |
510 return; | |
511 | |
512 if (port > 0) | |
513 got_transresp(slpcall, nonce, ip_addrs, port); | |
514 | |
515 g_free(nonce); | |
516 g_free(ip_addrs); | |
517 #endif | |
518 } | |
519 } | |
520 | |
521 static void | |
522 got_ok(MsnSlpCall *slpcall, | |
523 const char *type, const char *content) | |
524 { | |
525 g_return_if_fail(slpcall != NULL); | |
526 g_return_if_fail(type != NULL); | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
527 |
9193 | 528 if (!strcmp(type, "application/x-msnmsgr-sessionreqbody")) |
529 { | |
530 #if 0 | |
531 if (slpcall->type == MSN_SLPCALL_DC) | |
532 { | |
533 /* First let's try a DirectConnection. */ | |
534 | |
535 MsnSlpLink *slplink; | |
536 MsnSlpMessage *slpmsg; | |
537 char *header; | |
538 char *content; | |
539 char *branch; | |
540 | |
541 slplink = slpcall->slplink; | |
542 | |
543 branch = rand_guid(); | |
544 | |
545 content = g_strdup_printf( | |
546 "Bridges: TRUDPv1 TCPv1\r\n" | |
547 "NetID: 0\r\n" | |
548 "Conn-Type: Direct-Connect\r\n" | |
549 "UPnPNat: false\r\n" | |
550 "ICF: false\r\n" | |
551 ); | |
552 | |
553 header = g_strdup_printf("INVITE MSNMSGR:%s MSNSLP/1.0", | |
554 slplink->remote_user); | |
555 | |
556 slpmsg = msn_slp_sipmsg_new(slpcall, 0, header, branch, | |
557 "application/x-msnmsgr-transreqbody", | |
558 content); | |
559 | |
10345 | 560 #ifdef MSN_DEBUG_SLP |
9193 | 561 slpmsg->info = "SLP INVITE"; |
562 slpmsg->text_body = TRUE; | |
563 #endif | |
564 msn_slplink_send_slpmsg(slplink, slpmsg); | |
565 | |
566 g_free(header); | |
567 g_free(content); | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
568 |
9193 | 569 g_free(branch); |
570 } | |
571 else | |
572 { | |
573 msn_slp_call_session_init(slpcall); | |
574 } | |
575 #else | |
576 msn_slp_call_session_init(slpcall); | |
577 #endif | |
578 } | |
579 else if (!strcmp(type, "application/x-msnmsgr-transreqbody")) | |
580 { | |
581 /* Do we get this? */ | |
582 gaim_debug_info("msn", "OK with transreqbody\n"); | |
583 } | |
584 else if (!strcmp(type, "application/x-msnmsgr-transrespbody")) | |
585 { | |
586 #if 0 | |
587 char *ip_addrs; | |
588 char *temp; | |
589 char *nonce; | |
590 int port; | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
591 |
9193 | 592 nonce = get_token(content, "Nonce: {", "}\r\n"); |
593 ip_addrs = get_token(content, "IPv4Internal-Addrs: ", "\r\n"); | |
594 | |
595 temp = get_token(content, "IPv4Internal-Port: ", "\r\n"); | |
596 if (temp != NULL) | |
597 port = atoi(temp); | |
598 else | |
599 port = -1; | |
600 g_free(temp); | |
601 | |
602 if (ip_addrs == NULL) | |
603 return; | |
604 | |
605 if (port > 0) | |
606 got_transresp(slpcall, nonce, ip_addrs, port); | |
607 | |
608 g_free(nonce); | |
609 g_free(ip_addrs); | |
610 #endif | |
611 } | |
612 } | |
613 | |
614 MsnSlpCall * | |
615 msn_slp_sip_recv(MsnSlpLink *slplink, const char *body, gsize len) | |
616 { | |
617 MsnSlpCall *slpcall; | |
618 | |
619 if (!strncmp(body, "INVITE", strlen("INVITE"))) | |
620 { | |
621 char *branch; | |
622 char *content; | |
623 char *content_type; | |
624 | |
625 slpcall = msn_slp_call_new(slplink); | |
626 | |
627 /* From: <msnmsgr:buddy@hotmail.com> */ | |
628 #if 0 | |
629 slpcall->remote_user = get_token(body, "From: <msnmsgr:", ">\r\n"); | |
630 #endif | |
631 | |
632 branch = get_token(body, ";branch={", "}"); | |
633 | |
634 slpcall->id = get_token(body, "Call-ID: {", "}"); | |
635 | |
636 #if 0 | |
637 long content_len = -1; | |
638 | |
639 temp = get_token(body, "Content-Length: ", "\r\n"); | |
640 if (temp != NULL) | |
641 content_len = atoi(temp); | |
642 g_free(temp); | |
643 #endif | |
644 content_type = get_token(body, "Content-Type: ", "\r\n"); | |
645 | |
646 content = get_token(body, "\r\n\r\n", NULL); | |
647 | |
648 got_invite(slpcall, branch, content_type, content); | |
649 | |
10519 | 650 g_free(branch); |
9193 | 651 g_free(content_type); |
652 g_free(content); | |
653 } | |
654 else if (!strncmp(body, "MSNSLP/1.0 ", strlen("MSNSLP/1.0 "))) | |
655 { | |
656 char *content; | |
657 char *content_type; | |
658 /* Make sure this is "OK" */ | |
659 const char *status = body + strlen("MSNSLP/1.0 "); | |
660 char *call_id; | |
661 | |
662 call_id = get_token(body, "Call-ID: {", "}"); | |
663 slpcall = msn_slplink_find_slp_call(slplink, call_id); | |
664 g_free(call_id); | |
665 | |
9231
ac8790437abe
[gaim-migrate @ 10027]
Christian Hammond <chipx86@chipx86.com>
parents:
9226
diff
changeset
|
666 g_return_val_if_fail(slpcall != NULL, NULL); |
ac8790437abe
[gaim-migrate @ 10027]
Christian Hammond <chipx86@chipx86.com>
parents:
9226
diff
changeset
|
667 |
9193 | 668 if (strncmp(status, "200 OK", 6)) |
669 { | |
670 /* It's not valid. Kill this off. */ | |
671 char temp[32]; | |
672 const char *c; | |
673 | |
674 /* Eww */ | |
675 if ((c = strchr(status, '\r')) || (c = strchr(status, '\n')) || | |
676 (c = strchr(status, '\0'))) | |
677 { | |
9739 | 678 size_t offset = c - status; |
679 if (offset >= sizeof(temp)) | |
680 offset = sizeof(temp) - 1; | |
10225 | 681 |
9739 | 682 strncpy(temp, status, offset); |
683 temp[offset] = '\0'; | |
9193 | 684 } |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
685 |
9193 | 686 gaim_debug_error("msn", "Received non-OK result: %s\n", temp); |
687 | |
688 slpcall->wasted = TRUE; | |
689 | |
690 /* msn_slp_call_destroy(slpcall); */ | |
691 return slpcall; | |
692 } | |
693 | |
694 content_type = get_token(body, "Content-Type: ", "\r\n"); | |
695 | |
696 content = get_token(body, "\r\n\r\n", NULL); | |
697 | |
698 got_ok(slpcall, content_type, content); | |
699 | |
700 g_free(content_type); | |
701 g_free(content); | |
702 } | |
703 else if (!strncmp(body, "BYE", strlen("BYE"))) | |
704 { | |
705 char *call_id; | |
706 | |
707 call_id = get_token(body, "Call-ID: {", "}"); | |
708 slpcall = msn_slplink_find_slp_call(slplink, call_id); | |
709 g_free(call_id); | |
710 | |
711 if (slpcall != NULL) | |
712 slpcall->wasted = TRUE; | |
713 | |
714 /* msn_slp_call_destroy(slpcall); */ | |
715 } | |
716 else | |
717 slpcall = NULL; | |
718 | |
719 return slpcall; | |
720 } | |
721 | |
722 /************************************************************************** | |
723 * Msg Callbacks | |
724 **************************************************************************/ | |
725 | |
726 void | |
727 msn_p2p_msg(MsnCmdProc *cmdproc, MsnMessage *msg) | |
728 { | |
729 MsnSession *session; | |
730 MsnSlpLink *slplink; | |
731 | |
732 session = cmdproc->servconn->session; | |
733 slplink = msn_session_get_slplink(session, msg->remote_user); | |
734 | |
735 msn_slplink_process_msg(slplink, msg); | |
736 } | |
737 | |
738 void | |
739 got_emoticon(MsnSlpCall *slpcall, | |
740 const char *data, long long size) | |
741 { | |
742 gaim_debug_info("msn", "Got smiley: %s\n", slpcall->data_info); | |
743 | |
744 #if 0 | |
10403 | 745 serv_got_smiley(slpcall->slplink->session->account->gc, |
746 slpcall->slplink->remote_user, slpcall->data_info, data, size); | |
747 #endif | |
748 | |
749 #if 0 | |
9193 | 750 GaimConversation *conv; |
751 GaimConnection *gc = slpsession->swboard->servconn->session->account->gc; | |
752 serv_got_smiley(gc, info, data, size); | |
753 #endif | |
754 } | |
755 | |
756 void | |
757 msn_emoticon_msg(MsnCmdProc *cmdproc, MsnMessage *msg) | |
758 { | |
759 MsnSession *session; | |
760 MsnSlpLink *slplink; | |
761 MsnObject *obj; | |
762 char **tokens; | |
763 char *smile; | |
764 const char *who; | |
765 | |
766 session = cmdproc->servconn->session; | |
767 | |
768 tokens = g_strsplit(msg->body, "\t", 2); | |
769 | |
770 smile = tokens[0]; | |
771 obj = msn_object_new_from_string(gaim_url_decode(tokens[1])); | |
772 | |
773 who = msn_object_get_creator(obj); | |
774 | |
775 slplink = msn_session_get_slplink(session, who); | |
776 | |
10225 | 777 msn_slplink_request_object(slplink, smile, got_emoticon, NULL, obj); |
9193 | 778 |
779 g_strfreev(tokens); | |
780 } | |
781 | |
782 static gboolean | |
783 buddy_icon_cached(GaimConnection *gc, MsnObject *obj) | |
784 { | |
785 GaimAccount *account; | |
786 GaimBuddy *buddy; | |
787 GSList *sl; | |
788 const char *old; | |
789 const char *new; | |
790 | |
791 g_return_val_if_fail(obj != NULL, FALSE); | |
792 | |
793 account = gaim_connection_get_account(gc); | |
794 | |
795 sl = gaim_find_buddies(account, msn_object_get_creator(obj)); | |
796 | |
797 if (sl == NULL) | |
798 return FALSE; | |
799 | |
800 buddy = (GaimBuddy *)sl->data; | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
801 |
9193 | 802 old = gaim_blist_node_get_string((GaimBlistNode *)buddy, "icon_checksum"); |
803 new = msn_object_get_sha1c(obj); | |
804 | |
805 if (new == NULL) | |
806 return FALSE; | |
807 | |
808 if (old != NULL && !strcmp(old, new)) | |
809 return TRUE; | |
810 | |
811 return FALSE; | |
812 } | |
813 | |
814 void | |
9860 | 815 msn_release_buddy_icon_request(MsnUserList *userlist) |
9193 | 816 { |
817 MsnUser *user; | |
9860 | 818 |
10225 | 819 g_return_if_fail(userlist != NULL); |
820 | |
821 gaim_debug_info("msn", "Releasing buddy icon request\n"); | |
822 | |
9860 | 823 while (userlist->buddy_icon_window > 0) |
824 { | |
825 GQueue *queue; | |
826 GaimAccount *account; | |
827 const char *username; | |
828 | |
829 queue = userlist->buddy_icon_requests; | |
830 | |
831 if (g_queue_is_empty(userlist->buddy_icon_requests)) | |
832 break; | |
833 | |
834 user = g_queue_pop_head(queue); | |
9193 | 835 |
9860 | 836 account = userlist->session->account; |
837 username = user->passport; | |
9193 | 838 |
9860 | 839 msn_request_user_display(user); |
840 userlist->buddy_icon_window--; | |
10225 | 841 |
842 gaim_debug_info("msn", "buddy_icon_window=%d\n", | |
843 userlist->buddy_icon_window); | |
9860 | 844 } |
845 } | |
9193 | 846 |
9860 | 847 void |
848 msn_queue_buddy_icon_request(MsnUser *user) | |
849 { | |
850 GaimAccount *account; | |
851 MsnObject *obj; | |
852 GQueue *queue; | |
9193 | 853 |
10225 | 854 g_return_if_fail(user != NULL); |
855 | |
9860 | 856 account = user->userlist->session->account; |
9193 | 857 |
858 obj = msn_user_get_object(user); | |
859 | |
860 if (obj == NULL) | |
9860 | 861 { |
9193 | 862 /* It seems the user has not set a msnobject */ |
9860 | 863 GSList *sl; |
864 | |
865 /* TODO: I think we need better buddy icon core functions. */ | |
866 gaim_buddy_icons_set_for_user(account, user->passport, NULL, -1); | |
867 | |
868 sl = gaim_find_buddies(account, user->passport); | |
869 | |
870 for (; sl != NULL; sl = sl->next) | |
871 { | |
872 GaimBuddy *buddy = (GaimBuddy *)sl->data; | |
873 gaim_blist_node_remove_setting((GaimBlistNode*)buddy, "icon_checksum"); | |
874 } | |
875 | |
9193 | 876 return; |
9860 | 877 } |
878 | |
879 if (!buddy_icon_cached(account->gc, obj)) | |
880 { | |
881 MsnUserList *userlist; | |
882 | |
883 userlist = user->userlist; | |
884 queue = userlist->buddy_icon_requests; | |
885 | |
10225 | 886 gaim_debug_info("msn", "Queueing buddy icon request: %s\n", |
887 user->passport); | |
888 | |
9860 | 889 g_queue_push_tail(queue, user); |
890 | |
10225 | 891 gaim_debug_info("msn", "buddy_icon_window=%d\n", |
892 userlist->buddy_icon_window); | |
893 | |
9860 | 894 if (userlist->buddy_icon_window > 0) |
895 msn_release_buddy_icon_request(userlist); | |
896 } | |
897 } | |
898 | |
899 void | |
900 got_user_display(MsnSlpCall *slpcall, | |
901 const char *data, long long size) | |
902 { | |
10225 | 903 MsnUserList *userlist; |
9860 | 904 const char *info; |
905 GaimAccount *account; | |
906 GSList *sl; | |
907 | |
10225 | 908 g_return_if_fail(slpcall != NULL); |
909 | |
9860 | 910 info = slpcall->data_info; |
911 gaim_debug_info("msn", "Got User Display: %s\n", info); | |
912 | |
10225 | 913 userlist = slpcall->slplink->session->userlist; |
9860 | 914 account = slpcall->slplink->session->account; |
915 | |
916 /* TODO: I think we need better buddy icon core functions. */ | |
917 gaim_buddy_icons_set_for_user(account, slpcall->slplink->remote_user, | |
918 (void *)data, size); | |
919 | |
920 sl = gaim_find_buddies(account, slpcall->slplink->remote_user); | |
921 | |
922 for (; sl != NULL; sl = sl->next) | |
923 { | |
924 GaimBuddy *buddy = (GaimBuddy *)sl->data; | |
925 gaim_blist_node_set_string((GaimBlistNode*)buddy, "icon_checksum", info); | |
926 } | |
927 | |
10225 | 928 #if 0 |
929 /* Free one window slot */ | |
930 userlist->buddy_icon_window++; | |
931 | |
932 gaim_debug_info("msn", "buddy_icon_window=%d\n", | |
933 userlist->buddy_icon_window); | |
934 | |
935 msn_release_buddy_icon_request(userlist); | |
936 #endif | |
937 } | |
938 | |
939 void | |
940 end_user_display(MsnSlpCall *slpcall) | |
941 { | |
942 MsnUserList *userlist; | |
943 | |
944 g_return_if_fail(slpcall != NULL); | |
945 | |
946 gaim_debug_info("msn", "End User Display\n"); | |
947 | |
948 userlist = slpcall->slplink->session->userlist; | |
949 | |
10296 | 950 /* If the session is being destroyed we better stop doing anything. */ |
951 if (slpcall->slplink->session->destroying) | |
952 return; | |
953 | |
10225 | 954 /* Free one window slot */ |
955 userlist->buddy_icon_window++; | |
956 | |
957 gaim_debug_info("msn", "buddy_icon_window=%d\n", | |
958 userlist->buddy_icon_window); | |
959 | |
960 msn_release_buddy_icon_request(userlist); | |
9860 | 961 } |
962 | |
963 void | |
964 msn_request_user_display(MsnUser *user) | |
965 { | |
966 GaimAccount *account; | |
967 MsnSession *session; | |
968 MsnSlpLink *slplink; | |
969 MsnObject *obj; | |
970 const char *info; | |
971 | |
972 session = user->userlist->session; | |
973 account = session->account; | |
974 | |
975 slplink = msn_session_get_slplink(session, user->passport); | |
976 | |
977 obj = msn_user_get_object(user); | |
9193 | 978 |
979 info = msn_object_get_sha1c(obj); | |
980 | |
9860 | 981 if (g_ascii_strcasecmp(user->passport, |
982 gaim_account_get_username(account))) | |
983 { | |
10225 | 984 msn_slplink_request_object(slplink, info, got_user_display, |
985 end_user_display, obj); | |
9860 | 986 } |
987 else | |
988 { | |
10072
cf3454eadc22
[gaim-migrate @ 11051]
Luke Schierer <lschiere@pidgin.im>
parents:
10047
diff
changeset
|
989 MsnObject *my_obj = NULL; |
cf3454eadc22
[gaim-migrate @ 11051]
Luke Schierer <lschiere@pidgin.im>
parents:
10047
diff
changeset
|
990 const char *filename = NULL; |
cf3454eadc22
[gaim-migrate @ 11051]
Luke Schierer <lschiere@pidgin.im>
parents:
10047
diff
changeset
|
991 gchar *data = NULL; |
cf3454eadc22
[gaim-migrate @ 11051]
Luke Schierer <lschiere@pidgin.im>
parents:
10047
diff
changeset
|
992 gsize len = 0; |
cf3454eadc22
[gaim-migrate @ 11051]
Luke Schierer <lschiere@pidgin.im>
parents:
10047
diff
changeset
|
993 const char *my_info = NULL; |
cf3454eadc22
[gaim-migrate @ 11051]
Luke Schierer <lschiere@pidgin.im>
parents:
10047
diff
changeset
|
994 GSList *sl; |
cf3454eadc22
[gaim-migrate @ 11051]
Luke Schierer <lschiere@pidgin.im>
parents:
10047
diff
changeset
|
995 |
cf3454eadc22
[gaim-migrate @ 11051]
Luke Schierer <lschiere@pidgin.im>
parents:
10047
diff
changeset
|
996 gaim_debug_info("msn", "Requesting our own user display\n"); |
cf3454eadc22
[gaim-migrate @ 11051]
Luke Schierer <lschiere@pidgin.im>
parents:
10047
diff
changeset
|
997 |
cf3454eadc22
[gaim-migrate @ 11051]
Luke Schierer <lschiere@pidgin.im>
parents:
10047
diff
changeset
|
998 my_obj = msn_user_get_object(session->user); |
cf3454eadc22
[gaim-migrate @ 11051]
Luke Schierer <lschiere@pidgin.im>
parents:
10047
diff
changeset
|
999 |
cf3454eadc22
[gaim-migrate @ 11051]
Luke Schierer <lschiere@pidgin.im>
parents:
10047
diff
changeset
|
1000 if (my_obj != NULL) |
cf3454eadc22
[gaim-migrate @ 11051]
Luke Schierer <lschiere@pidgin.im>
parents:
10047
diff
changeset
|
1001 { |
cf3454eadc22
[gaim-migrate @ 11051]
Luke Schierer <lschiere@pidgin.im>
parents:
10047
diff
changeset
|
1002 filename = msn_object_get_real_location(my_obj); |
cf3454eadc22
[gaim-migrate @ 11051]
Luke Schierer <lschiere@pidgin.im>
parents:
10047
diff
changeset
|
1003 my_info = msn_object_get_sha1c(my_obj); |
cf3454eadc22
[gaim-migrate @ 11051]
Luke Schierer <lschiere@pidgin.im>
parents:
10047
diff
changeset
|
1004 } |
cf3454eadc22
[gaim-migrate @ 11051]
Luke Schierer <lschiere@pidgin.im>
parents:
10047
diff
changeset
|
1005 |
cf3454eadc22
[gaim-migrate @ 11051]
Luke Schierer <lschiere@pidgin.im>
parents:
10047
diff
changeset
|
1006 if (filename != NULL) |
cf3454eadc22
[gaim-migrate @ 11051]
Luke Schierer <lschiere@pidgin.im>
parents:
10047
diff
changeset
|
1007 g_file_get_contents(filename, &data, &len, NULL); |
cf3454eadc22
[gaim-migrate @ 11051]
Luke Schierer <lschiere@pidgin.im>
parents:
10047
diff
changeset
|
1008 |
cf3454eadc22
[gaim-migrate @ 11051]
Luke Schierer <lschiere@pidgin.im>
parents:
10047
diff
changeset
|
1009 /* TODO: I think we need better buddy icon core functions. */ |
cf3454eadc22
[gaim-migrate @ 11051]
Luke Schierer <lschiere@pidgin.im>
parents:
10047
diff
changeset
|
1010 gaim_buddy_icons_set_for_user(account, user->passport, (void *)data, len); |
10519 | 1011 g_free(data); |
10225 | 1012 |
10072
cf3454eadc22
[gaim-migrate @ 11051]
Luke Schierer <lschiere@pidgin.im>
parents:
10047
diff
changeset
|
1013 sl = gaim_find_buddies(account, user->passport); |
cf3454eadc22
[gaim-migrate @ 11051]
Luke Schierer <lschiere@pidgin.im>
parents:
10047
diff
changeset
|
1014 |
cf3454eadc22
[gaim-migrate @ 11051]
Luke Schierer <lschiere@pidgin.im>
parents:
10047
diff
changeset
|
1015 for (; sl != NULL; sl = sl->next) |
cf3454eadc22
[gaim-migrate @ 11051]
Luke Schierer <lschiere@pidgin.im>
parents:
10047
diff
changeset
|
1016 { |
cf3454eadc22
[gaim-migrate @ 11051]
Luke Schierer <lschiere@pidgin.im>
parents:
10047
diff
changeset
|
1017 GaimBuddy *buddy = (GaimBuddy *)sl->data; |
cf3454eadc22
[gaim-migrate @ 11051]
Luke Schierer <lschiere@pidgin.im>
parents:
10047
diff
changeset
|
1018 gaim_blist_node_set_string((GaimBlistNode*)buddy, "icon_checksum", info); |
cf3454eadc22
[gaim-migrate @ 11051]
Luke Schierer <lschiere@pidgin.im>
parents:
10047
diff
changeset
|
1019 } |
cf3454eadc22
[gaim-migrate @ 11051]
Luke Schierer <lschiere@pidgin.im>
parents:
10047
diff
changeset
|
1020 |
10225 | 1021 /* Free one window slot */ |
9860 | 1022 session->userlist->buddy_icon_window++; |
10225 | 1023 |
1024 gaim_debug_info("msn", "buddy_icon_window=%d\n", | |
1025 session->userlist->buddy_icon_window); | |
1026 | |
9860 | 1027 msn_release_buddy_icon_request(session->userlist); |
1028 } | |
9193 | 1029 } |