Mercurial > pidgin
annotate src/protocols/msn/slp.c @ 10082:51e9c4f27a62
[gaim-migrate @ 11073]
an update was provided for this as well
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Wed, 06 Oct 2004 11:22:18 +0000 |
parents | cf3454eadc22 |
children | 1a91e814e9d8 |
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 { |
9226
7a00289f2ef1
[gaim-migrate @ 10022]
Christian Hammond <chipx86@chipx86.com>
parents:
9198
diff
changeset
|
147 if (gaim_xfer_get_status(slpcall->xfer) != GAIM_XFER_STATUS_DONE) |
7a00289f2ef1
[gaim-migrate @ 10022]
Christian Hammond <chipx86@chipx86.com>
parents:
9198
diff
changeset
|
148 { |
9259
f5f7482678d2
[gaim-migrate @ 10058]
Christian Hammond <chipx86@chipx86.com>
parents:
9231
diff
changeset
|
149 gaim_xfer_cancel_remote(slpcall->xfer); |
9226
7a00289f2ef1
[gaim-migrate @ 10022]
Christian Hammond <chipx86@chipx86.com>
parents:
9198
diff
changeset
|
150 } |
9193 | 151 } |
152 | |
9259
f5f7482678d2
[gaim-migrate @ 10058]
Christian Hammond <chipx86@chipx86.com>
parents:
9231
diff
changeset
|
153 void |
f5f7482678d2
[gaim-migrate @ 10058]
Christian Hammond <chipx86@chipx86.com>
parents:
9231
diff
changeset
|
154 msn_xfer_completed_cb(MsnSlpCall *slpcall, const char *body, |
f5f7482678d2
[gaim-migrate @ 10058]
Christian Hammond <chipx86@chipx86.com>
parents:
9231
diff
changeset
|
155 long long size) |
f5f7482678d2
[gaim-migrate @ 10058]
Christian Hammond <chipx86@chipx86.com>
parents:
9231
diff
changeset
|
156 { |
f5f7482678d2
[gaim-migrate @ 10058]
Christian Hammond <chipx86@chipx86.com>
parents:
9231
diff
changeset
|
157 gaim_xfer_set_completed(slpcall->xfer, TRUE); |
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 |
9193 | 160 /************************************************************************** |
161 * SLP Control | |
162 **************************************************************************/ | |
163 | |
164 #if 0 | |
165 static void | |
166 got_transresp(MsnSlpCall *slpcall, const char *nonce, | |
167 const char *ips_str, int port) | |
168 { | |
169 MsnDirectConn *directconn; | |
170 char **ip_addrs, **c; | |
171 | |
172 directconn = msn_directconn_new(slpcall->slplink); | |
173 | |
174 directconn->initial_call = slpcall; | |
175 | |
176 /* msn_directconn_parse_nonce(directconn, nonce); */ | |
177 directconn->nonce = g_strdup(nonce); | |
178 | |
179 ip_addrs = g_strsplit(ips_str, " ", -1); | |
180 | |
181 for (c = ip_addrs; *c != NULL; c++) | |
182 { | |
183 gaim_debug_info("msn", "ip_addr = %s\n", *c); | |
184 if (msn_directconn_connect(directconn, *c, port)) | |
185 break; | |
186 } | |
187 | |
188 g_strfreev(ip_addrs); | |
189 } | |
190 #endif | |
191 | |
192 static void | |
193 send_ok(MsnSlpCall *slpcall, const char *branch, | |
194 const char *type, const char *content) | |
195 { | |
196 MsnSlpLink *slplink; | |
197 MsnSlpMessage *slpmsg; | |
198 | |
199 slplink = slpcall->slplink; | |
200 | |
201 /* 200 OK */ | |
202 slpmsg = msn_slpmsg_sip_new(slpcall, 1, | |
203 "MSNSLP/1.0 200 OK", | |
204 branch, type, content); | |
205 | |
206 #ifdef DEBUG_SLP | |
207 slpmsg->info = "SLP 200 OK"; | |
208 slpmsg->text_body = TRUE; | |
209 #endif | |
210 | |
211 msn_slplink_queue_slpmsg(slplink, slpmsg); | |
212 | |
213 msn_slp_call_session_init(slpcall); | |
214 } | |
215 | |
216 static void | |
217 send_decline(MsnSlpCall *slpcall, const char *branch, | |
218 const char *type, const char *content) | |
219 { | |
220 MsnSlpLink *slplink; | |
221 MsnSlpMessage *slpmsg; | |
222 | |
223 slplink = slpcall->slplink; | |
224 | |
225 /* 603 Decline */ | |
226 slpmsg = msn_slpmsg_sip_new(slpcall, 1, | |
227 "MSNSLP/1.0 603 Decline", | |
228 branch, type, content); | |
229 | |
230 #ifdef DEBUG_SLP | |
231 slpmsg->info = "SLP 603 Decline"; | |
232 slpmsg->text_body = TRUE; | |
233 #endif | |
234 | |
235 msn_slplink_queue_slpmsg(slplink, slpmsg); | |
236 } | |
237 | |
10047 | 238 #define MAX_FILE_NAME_LEN 0x226 |
239 | |
9193 | 240 static void |
241 got_sessionreq(MsnSlpCall *slpcall, const char *branch, | |
242 const char *euf_guid, const char *context) | |
243 { | |
244 if (!strcmp(euf_guid, "A4268EEC-FEC5-49E5-95C3-F126696BDBF6")) | |
245 { | |
246 /* Emoticon or UserDisplay */ | |
247 MsnSlpSession *slpsession; | |
248 MsnSlpLink *slplink; | |
249 MsnSlpMessage *slpmsg; | |
250 MsnObject *obj; | |
251 char *msnobj_data; | |
252 const char *sha1c; | |
253 const char *file_name; | |
254 char *content; | |
255 gsize len; | |
256 int type; | |
257 | |
258 /* Send Ok */ | |
259 content = g_strdup_printf("SessionID: %lu\r\n\r\n", | |
260 slpcall->session_id); | |
261 | |
262 send_ok(slpcall, branch, "application/x-msnmsgr-sessionreqbody", | |
263 content); | |
264 | |
265 g_free(content); | |
266 | |
267 slplink = slpcall->slplink; | |
268 | |
269 gaim_base64_decode(context, &msnobj_data, &len); | |
270 obj = msn_object_new_from_string(msnobj_data); | |
271 type = msn_object_get_type(obj); | |
272 sha1c = msn_object_get_sha1c(obj); | |
273 g_free(msnobj_data); | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
274 |
9193 | 275 if (!(type == MSN_OBJECT_USERTILE)) |
276 { | |
277 gaim_debug_error("msn", "Wrong object?\n"); | |
278 msn_object_destroy(obj); | |
279 g_return_if_reached(); | |
280 } | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
281 |
9193 | 282 file_name = msn_object_get_real_location(obj); |
283 | |
9858 | 284 if (file_name == NULL) |
285 { | |
286 gaim_debug_error("msn", "Wrong object.\n"); | |
287 msn_object_destroy(obj); | |
288 g_return_if_reached(); | |
289 } | |
290 | |
9193 | 291 slpsession = msn_slplink_find_slp_session(slplink, |
9861 | 292 slpcall->session_id); |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
293 |
9193 | 294 /* DATA PREP */ |
295 slpmsg = msn_slpmsg_new(slplink); | |
296 slpmsg->slpsession = slpsession; | |
297 slpmsg->session_id = slpsession->id; | |
298 msn_slpmsg_set_body(slpmsg, NULL, 4); | |
299 #ifdef DEBUG_SLP | |
300 slpmsg->info = "SLP DATA PREP"; | |
301 #endif | |
302 msn_slplink_queue_slpmsg(slplink, slpmsg); | |
303 | |
304 /* DATA */ | |
305 slpmsg = msn_slpmsg_new(slplink); | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
306 slpmsg->slpsession = slpsession; |
9193 | 307 slpmsg->flags = 0x20; |
308 #ifdef DEBUG_SLP | |
309 slpmsg->info = "SLP DATA"; | |
310 #endif | |
311 msn_slpmsg_open_file(slpmsg, file_name); | |
312 msn_slplink_queue_slpmsg(slplink, slpmsg); | |
313 } | |
314 else if (!strcmp(euf_guid, "5D3E02AB-6190-11D3-BBBB-00C04F795683")) | |
315 { | |
316 /* File Transfer */ | |
317 GaimAccount *account; | |
318 GaimXfer *xfer; | |
319 char *bin; | |
320 gsize bin_len; | |
321 guint32 file_size; | |
322 char *file_name; | |
10047 | 323 gunichar2 *uni_name; |
9193 | 324 |
325 account = slpcall->slplink->session->account; | |
326 | |
9259
f5f7482678d2
[gaim-migrate @ 10058]
Christian Hammond <chipx86@chipx86.com>
parents:
9231
diff
changeset
|
327 slpcall->cb = msn_xfer_completed_cb; |
f5f7482678d2
[gaim-migrate @ 10058]
Christian Hammond <chipx86@chipx86.com>
parents:
9231
diff
changeset
|
328 slpcall->end_cb = msn_xfer_end_cb; |
9193 | 329 slpcall->progress_cb = msn_xfer_progress_cb; |
330 slpcall->branch = g_strdup(branch); | |
331 | |
332 xfer = gaim_xfer_new(account, GAIM_XFER_RECEIVE, | |
333 slpcall->slplink->remote_user); | |
334 | |
335 gaim_base64_decode(context, &bin, &bin_len); | |
9263
70153c759016
[gaim-migrate @ 10062]
Christian Hammond <chipx86@chipx86.com>
parents:
9259
diff
changeset
|
336 file_size = GUINT32_FROM_LE(*((gsize *)bin + 2)); |
10047 | 337 |
338 uni_name = (gunichar2 *)(bin + 20); | |
339 while(*uni_name != 0 && ((char *)uni_name - (bin + 20)) < MAX_FILE_NAME_LEN) { | |
340 *uni_name = GUINT16_FROM_LE(*uni_name); | |
341 uni_name++; | |
342 } | |
343 | |
9193 | 344 file_name = g_utf16_to_utf8((const gunichar2 *)(bin + 20), -1, |
345 NULL, NULL, NULL); | |
346 | |
347 g_free(bin); | |
348 | |
349 gaim_xfer_set_filename(xfer, file_name); | |
350 gaim_xfer_set_size(xfer, file_size); | |
351 gaim_xfer_set_init_fnc(xfer, msn_xfer_init); | |
352 gaim_xfer_set_request_denied_fnc(xfer, msn_xfer_cancel); | |
353 gaim_xfer_set_cancel_recv_fnc(xfer, msn_xfer_cancel); | |
354 | |
355 slpcall->xfer = xfer; | |
356 xfer->data = slpcall; | |
357 | |
358 gaim_xfer_request(xfer); | |
359 } | |
360 } | |
361 | |
362 void | |
363 send_bye(MsnSlpCall *slpcall, const char *type) | |
364 { | |
365 MsnSlpLink *slplink; | |
366 MsnSlpMessage *slpmsg; | |
367 char *header; | |
368 | |
369 slplink = slpcall->slplink; | |
370 | |
371 g_return_if_fail(slplink != NULL); | |
372 | |
373 header = g_strdup_printf("BYE MSNMSGR:%s MSNSLP/1.0", | |
374 slplink->local_user); | |
375 | |
376 slpmsg = msn_slpmsg_sip_new(slpcall, 0, header, | |
377 "A0D624A6-6C0C-4283-A9E0-BC97B4B46D32", | |
378 type, | |
379 "\r\n"); | |
380 g_free(header); | |
381 | |
382 #ifdef DEBUG_SLP | |
383 slpmsg->info = "SLP BYE"; | |
384 slpmsg->text_body = TRUE; | |
385 #endif | |
386 | |
387 msn_slplink_queue_slpmsg(slplink, slpmsg); | |
388 } | |
389 | |
390 static void | |
391 got_invite(MsnSlpCall *slpcall, | |
392 const char *branch, const char *type, const char *content) | |
393 { | |
394 MsnSlpLink *slplink; | |
395 | |
396 slplink = slpcall->slplink; | |
397 | |
398 if (!strcmp(type, "application/x-msnmsgr-sessionreqbody")) | |
399 { | |
400 char *euf_guid, *context; | |
401 char *temp; | |
402 | |
403 euf_guid = get_token(content, "EUF-GUID: {", "}\r\n"); | |
404 | |
405 temp = get_token(content, "SessionID: ", "\r\n"); | |
406 if (temp != NULL) | |
407 slpcall->session_id = atoi(temp); | |
408 g_free(temp); | |
409 | |
410 temp = get_token(content, "AppID: ", "\r\n"); | |
411 if (temp != NULL) | |
412 slpcall->app_id = atoi(temp); | |
413 g_free(temp); | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
414 |
9193 | 415 context = get_token(content, "Context: ", "\r\n"); |
416 | |
417 got_sessionreq(slpcall, branch, euf_guid, context); | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
418 |
9193 | 419 g_free(context); |
420 g_free(euf_guid); | |
421 } | |
422 else if (!strcmp(type, "application/x-msnmsgr-transreqbody")) | |
423 { | |
424 /* A direct connection? */ | |
425 | |
426 char *listening, *nonce; | |
427 char *content; | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
428 |
9193 | 429 if (FALSE) |
430 { | |
431 #if 0 | |
432 MsnDirectConn *directconn; | |
433 /* const char *ip_addr; */ | |
434 char *ip_port; | |
435 int port; | |
436 | |
437 /* ip_addr = gaim_prefs_get_string("/core/ft/public_ip"); */ | |
438 ip_port = "5190"; | |
439 listening = "true"; | |
440 nonce = rand_guid(); | |
441 | |
442 directconn = msn_directconn_new(slplink); | |
443 | |
444 /* msn_directconn_parse_nonce(directconn, nonce); */ | |
445 directconn->nonce = g_strdup(nonce); | |
446 | |
447 msn_directconn_listen(directconn); | |
448 | |
449 port = directconn->port; | |
450 | |
451 content = g_strdup_printf( | |
452 "Bridge: TCPv1\r\n" | |
453 "Listening: %s\r\n" | |
454 "Nonce: {%s}\r\n" | |
455 "Ipv4Internal-Addrs: 192.168.0.82\r\n" | |
456 "Ipv4Internal-Port: %d\r\n" | |
457 "\r\n", | |
458 listening, | |
459 nonce, | |
460 port); | |
461 #endif | |
462 } | |
463 else | |
464 { | |
465 listening = "false"; | |
466 nonce = g_strdup("00000000-0000-0000-0000-000000000000"); | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
467 |
9193 | 468 content = g_strdup_printf( |
469 "Bridge: TCPv1\r\n" | |
470 "Listening: %s\r\n" | |
471 "Nonce: {%s}\r\n" | |
472 "\r\n", | |
473 listening, | |
474 nonce); | |
475 } | |
476 | |
477 send_ok(slpcall, branch, | |
478 "application/x-msnmsgr-transrespbody", content); | |
479 | |
480 g_free(content); | |
481 g_free(nonce); | |
482 } | |
483 else if (!strcmp(type, "application/x-msnmsgr-transrespbody")) | |
484 { | |
485 #if 0 | |
486 char *ip_addrs; | |
487 char *temp; | |
488 char *nonce; | |
489 int port; | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
490 |
9193 | 491 nonce = get_token(content, "Nonce: {", "}\r\n"); |
492 ip_addrs = get_token(content, "IPv4Internal-Addrs: ", "\r\n"); | |
493 | |
494 temp = get_token(content, "IPv4Internal-Port: ", "\r\n"); | |
495 if (temp != NULL) | |
496 port = atoi(temp); | |
497 else | |
498 port = -1; | |
499 g_free(temp); | |
500 | |
501 if (ip_addrs == NULL) | |
502 return; | |
503 | |
504 if (port > 0) | |
505 got_transresp(slpcall, nonce, ip_addrs, port); | |
506 | |
507 g_free(nonce); | |
508 g_free(ip_addrs); | |
509 #endif | |
510 } | |
511 } | |
512 | |
513 static void | |
514 got_ok(MsnSlpCall *slpcall, | |
515 const char *type, const char *content) | |
516 { | |
517 g_return_if_fail(slpcall != NULL); | |
518 g_return_if_fail(type != NULL); | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
519 |
9193 | 520 if (!strcmp(type, "application/x-msnmsgr-sessionreqbody")) |
521 { | |
522 #if 0 | |
523 if (slpcall->type == MSN_SLPCALL_DC) | |
524 { | |
525 /* First let's try a DirectConnection. */ | |
526 | |
527 MsnSlpLink *slplink; | |
528 MsnSlpMessage *slpmsg; | |
529 char *header; | |
530 char *content; | |
531 char *branch; | |
532 | |
533 slplink = slpcall->slplink; | |
534 | |
535 branch = rand_guid(); | |
536 | |
537 content = g_strdup_printf( | |
538 "Bridges: TRUDPv1 TCPv1\r\n" | |
539 "NetID: 0\r\n" | |
540 "Conn-Type: Direct-Connect\r\n" | |
541 "UPnPNat: false\r\n" | |
542 "ICF: false\r\n" | |
543 ); | |
544 | |
545 header = g_strdup_printf("INVITE MSNMSGR:%s MSNSLP/1.0", | |
546 slplink->remote_user); | |
547 | |
548 slpmsg = msn_slp_sipmsg_new(slpcall, 0, header, branch, | |
549 "application/x-msnmsgr-transreqbody", | |
550 content); | |
551 | |
552 #ifdef DEBUG_SLP | |
553 slpmsg->info = "SLP INVITE"; | |
554 slpmsg->text_body = TRUE; | |
555 #endif | |
556 msn_slplink_send_slpmsg(slplink, slpmsg); | |
557 | |
558 g_free(header); | |
559 g_free(content); | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
560 |
9193 | 561 g_free(branch); |
562 } | |
563 else | |
564 { | |
565 msn_slp_call_session_init(slpcall); | |
566 } | |
567 #else | |
568 msn_slp_call_session_init(slpcall); | |
569 #endif | |
570 } | |
571 else if (!strcmp(type, "application/x-msnmsgr-transreqbody")) | |
572 { | |
573 /* Do we get this? */ | |
574 gaim_debug_info("msn", "OK with transreqbody\n"); | |
575 } | |
576 else if (!strcmp(type, "application/x-msnmsgr-transrespbody")) | |
577 { | |
578 #if 0 | |
579 char *ip_addrs; | |
580 char *temp; | |
581 char *nonce; | |
582 int port; | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
583 |
9193 | 584 nonce = get_token(content, "Nonce: {", "}\r\n"); |
585 ip_addrs = get_token(content, "IPv4Internal-Addrs: ", "\r\n"); | |
586 | |
587 temp = get_token(content, "IPv4Internal-Port: ", "\r\n"); | |
588 if (temp != NULL) | |
589 port = atoi(temp); | |
590 else | |
591 port = -1; | |
592 g_free(temp); | |
593 | |
594 if (ip_addrs == NULL) | |
595 return; | |
596 | |
597 if (port > 0) | |
598 got_transresp(slpcall, nonce, ip_addrs, port); | |
599 | |
600 g_free(nonce); | |
601 g_free(ip_addrs); | |
602 #endif | |
603 } | |
604 } | |
605 | |
606 MsnSlpCall * | |
607 msn_slp_sip_recv(MsnSlpLink *slplink, const char *body, gsize len) | |
608 { | |
609 MsnSlpCall *slpcall; | |
610 | |
611 if (!strncmp(body, "INVITE", strlen("INVITE"))) | |
612 { | |
613 char *branch; | |
614 char *content; | |
615 char *content_type; | |
616 | |
617 slpcall = msn_slp_call_new(slplink); | |
618 | |
619 /* From: <msnmsgr:buddy@hotmail.com> */ | |
620 #if 0 | |
621 slpcall->remote_user = get_token(body, "From: <msnmsgr:", ">\r\n"); | |
622 #endif | |
623 | |
624 branch = get_token(body, ";branch={", "}"); | |
625 | |
626 slpcall->id = get_token(body, "Call-ID: {", "}"); | |
627 | |
628 #if 0 | |
629 long content_len = -1; | |
630 | |
631 temp = get_token(body, "Content-Length: ", "\r\n"); | |
632 if (temp != NULL) | |
633 content_len = atoi(temp); | |
634 g_free(temp); | |
635 #endif | |
636 content_type = get_token(body, "Content-Type: ", "\r\n"); | |
637 | |
638 content = get_token(body, "\r\n\r\n", NULL); | |
639 | |
640 got_invite(slpcall, branch, content_type, content); | |
641 | |
642 g_free(content_type); | |
643 g_free(content); | |
644 } | |
645 else if (!strncmp(body, "MSNSLP/1.0 ", strlen("MSNSLP/1.0 "))) | |
646 { | |
647 char *content; | |
648 char *content_type; | |
649 /* Make sure this is "OK" */ | |
650 const char *status = body + strlen("MSNSLP/1.0 "); | |
651 char *call_id; | |
652 | |
653 call_id = get_token(body, "Call-ID: {", "}"); | |
654 slpcall = msn_slplink_find_slp_call(slplink, call_id); | |
655 g_free(call_id); | |
656 | |
9231
ac8790437abe
[gaim-migrate @ 10027]
Christian Hammond <chipx86@chipx86.com>
parents:
9226
diff
changeset
|
657 g_return_val_if_fail(slpcall != NULL, NULL); |
ac8790437abe
[gaim-migrate @ 10027]
Christian Hammond <chipx86@chipx86.com>
parents:
9226
diff
changeset
|
658 |
9193 | 659 if (strncmp(status, "200 OK", 6)) |
660 { | |
661 /* It's not valid. Kill this off. */ | |
662 char temp[32]; | |
663 const char *c; | |
664 | |
665 /* Eww */ | |
666 if ((c = strchr(status, '\r')) || (c = strchr(status, '\n')) || | |
667 (c = strchr(status, '\0'))) | |
668 { | |
9739 | 669 size_t offset = c - status; |
670 if (offset >= sizeof(temp)) | |
671 offset = sizeof(temp) - 1; | |
672 | |
673 strncpy(temp, status, offset); | |
674 temp[offset] = '\0'; | |
9193 | 675 } |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
676 |
9193 | 677 gaim_debug_error("msn", "Received non-OK result: %s\n", temp); |
678 | |
679 slpcall->wasted = TRUE; | |
680 | |
681 /* msn_slp_call_destroy(slpcall); */ | |
682 return slpcall; | |
683 } | |
684 | |
685 content_type = get_token(body, "Content-Type: ", "\r\n"); | |
686 | |
687 content = get_token(body, "\r\n\r\n", NULL); | |
688 | |
689 got_ok(slpcall, content_type, content); | |
690 | |
691 g_free(content_type); | |
692 g_free(content); | |
693 } | |
694 else if (!strncmp(body, "BYE", strlen("BYE"))) | |
695 { | |
696 char *call_id; | |
697 | |
698 call_id = get_token(body, "Call-ID: {", "}"); | |
699 slpcall = msn_slplink_find_slp_call(slplink, call_id); | |
700 g_free(call_id); | |
701 | |
702 if (slpcall != NULL) | |
703 slpcall->wasted = TRUE; | |
704 | |
705 /* msn_slp_call_destroy(slpcall); */ | |
706 } | |
707 else | |
708 slpcall = NULL; | |
709 | |
710 return slpcall; | |
711 } | |
712 | |
713 /************************************************************************** | |
714 * Msg Callbacks | |
715 **************************************************************************/ | |
716 | |
717 void | |
718 msn_p2p_msg(MsnCmdProc *cmdproc, MsnMessage *msg) | |
719 { | |
720 MsnSession *session; | |
721 MsnSlpLink *slplink; | |
722 | |
723 session = cmdproc->servconn->session; | |
724 slplink = msn_session_get_slplink(session, msg->remote_user); | |
725 | |
726 msn_slplink_process_msg(slplink, msg); | |
727 } | |
728 | |
729 void | |
730 got_emoticon(MsnSlpCall *slpcall, | |
731 const char *data, long long size) | |
732 { | |
733 gaim_debug_info("msn", "Got smiley: %s\n", slpcall->data_info); | |
734 | |
735 #if 0 | |
736 GaimConversation *conv; | |
737 GaimConnection *gc = slpsession->swboard->servconn->session->account->gc; | |
738 serv_got_smiley(gc, info, data, size); | |
739 #endif | |
740 } | |
741 | |
742 void | |
743 msn_emoticon_msg(MsnCmdProc *cmdproc, MsnMessage *msg) | |
744 { | |
745 MsnSession *session; | |
746 MsnSlpLink *slplink; | |
747 MsnObject *obj; | |
748 char **tokens; | |
749 char *smile; | |
750 const char *who; | |
751 | |
752 session = cmdproc->servconn->session; | |
753 | |
754 tokens = g_strsplit(msg->body, "\t", 2); | |
755 | |
756 smile = tokens[0]; | |
757 obj = msn_object_new_from_string(gaim_url_decode(tokens[1])); | |
758 | |
759 who = msn_object_get_creator(obj); | |
760 | |
761 slplink = msn_session_get_slplink(session, who); | |
762 | |
763 msn_slplink_request_object(slplink, smile, got_emoticon, obj); | |
764 | |
765 g_strfreev(tokens); | |
766 } | |
767 | |
768 static gboolean | |
769 buddy_icon_cached(GaimConnection *gc, MsnObject *obj) | |
770 { | |
771 GaimAccount *account; | |
772 GaimBuddy *buddy; | |
773 GSList *sl; | |
774 const char *old; | |
775 const char *new; | |
776 | |
777 g_return_val_if_fail(obj != NULL, FALSE); | |
778 | |
779 account = gaim_connection_get_account(gc); | |
780 | |
781 sl = gaim_find_buddies(account, msn_object_get_creator(obj)); | |
782 | |
783 if (sl == NULL) | |
784 return FALSE; | |
785 | |
786 buddy = (GaimBuddy *)sl->data; | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
787 |
9193 | 788 old = gaim_blist_node_get_string((GaimBlistNode *)buddy, "icon_checksum"); |
789 new = msn_object_get_sha1c(obj); | |
790 | |
791 if (new == NULL) | |
792 return FALSE; | |
793 | |
794 if (old != NULL && !strcmp(old, new)) | |
795 return TRUE; | |
796 | |
797 return FALSE; | |
798 } | |
799 | |
800 void | |
9860 | 801 msn_release_buddy_icon_request(MsnUserList *userlist) |
9193 | 802 { |
803 MsnUser *user; | |
9860 | 804 |
805 while (userlist->buddy_icon_window > 0) | |
806 { | |
807 GQueue *queue; | |
808 GaimAccount *account; | |
809 const char *username; | |
810 | |
811 queue = userlist->buddy_icon_requests; | |
812 | |
813 if (g_queue_is_empty(userlist->buddy_icon_requests)) | |
814 break; | |
815 | |
816 user = g_queue_pop_head(queue); | |
9193 | 817 |
9860 | 818 account = userlist->session->account; |
819 username = user->passport; | |
9193 | 820 |
9860 | 821 msn_request_user_display(user); |
822 userlist->buddy_icon_window--; | |
823 } | |
824 } | |
9193 | 825 |
9860 | 826 void |
827 msn_queue_buddy_icon_request(MsnUser *user) | |
828 { | |
829 GaimAccount *account; | |
830 MsnObject *obj; | |
831 GQueue *queue; | |
9193 | 832 |
9860 | 833 account = user->userlist->session->account; |
9193 | 834 |
835 obj = msn_user_get_object(user); | |
836 | |
837 if (obj == NULL) | |
9860 | 838 { |
9193 | 839 /* It seems the user has not set a msnobject */ |
9860 | 840 GSList *sl; |
841 | |
842 /* TODO: I think we need better buddy icon core functions. */ | |
843 gaim_buddy_icons_set_for_user(account, user->passport, NULL, -1); | |
844 | |
845 sl = gaim_find_buddies(account, user->passport); | |
846 | |
847 for (; sl != NULL; sl = sl->next) | |
848 { | |
849 GaimBuddy *buddy = (GaimBuddy *)sl->data; | |
850 gaim_blist_node_remove_setting((GaimBlistNode*)buddy, "icon_checksum"); | |
851 } | |
852 | |
9193 | 853 return; |
9860 | 854 } |
855 | |
856 if (!buddy_icon_cached(account->gc, obj)) | |
857 { | |
858 MsnUserList *userlist; | |
859 | |
860 userlist = user->userlist; | |
861 queue = userlist->buddy_icon_requests; | |
862 | |
863 g_queue_push_tail(queue, user); | |
864 | |
865 if (userlist->buddy_icon_window > 0) | |
866 msn_release_buddy_icon_request(userlist); | |
867 } | |
868 } | |
869 | |
870 void | |
871 got_user_display(MsnSlpCall *slpcall, | |
872 const char *data, long long size) | |
873 { | |
874 const char *info; | |
875 GaimAccount *account; | |
876 GSList *sl; | |
877 | |
878 info = slpcall->data_info; | |
879 gaim_debug_info("msn", "Got User Display: %s\n", info); | |
880 | |
881 account = slpcall->slplink->session->account; | |
882 | |
883 /* TODO: I think we need better buddy icon core functions. */ | |
884 gaim_buddy_icons_set_for_user(account, slpcall->slplink->remote_user, | |
885 (void *)data, size); | |
886 | |
887 sl = gaim_find_buddies(account, slpcall->slplink->remote_user); | |
888 | |
889 for (; sl != NULL; sl = sl->next) | |
890 { | |
891 GaimBuddy *buddy = (GaimBuddy *)sl->data; | |
892 gaim_blist_node_set_string((GaimBlistNode*)buddy, "icon_checksum", info); | |
893 } | |
894 | |
895 slpcall->slplink->session->userlist->buddy_icon_window++; | |
896 msn_release_buddy_icon_request(slpcall->slplink->session->userlist); | |
897 } | |
898 | |
899 void | |
900 msn_request_user_display(MsnUser *user) | |
901 { | |
902 GaimAccount *account; | |
903 MsnSession *session; | |
904 MsnSlpLink *slplink; | |
905 MsnObject *obj; | |
906 const char *info; | |
907 | |
908 session = user->userlist->session; | |
909 account = session->account; | |
910 | |
911 slplink = msn_session_get_slplink(session, user->passport); | |
912 | |
913 obj = msn_user_get_object(user); | |
9193 | 914 |
915 info = msn_object_get_sha1c(obj); | |
916 | |
9860 | 917 if (g_ascii_strcasecmp(user->passport, |
918 gaim_account_get_username(account))) | |
919 { | |
9193 | 920 msn_slplink_request_object(slplink, info, got_user_display, obj); |
9860 | 921 } |
922 else | |
923 { | |
10072
cf3454eadc22
[gaim-migrate @ 11051]
Luke Schierer <lschiere@pidgin.im>
parents:
10047
diff
changeset
|
924 MsnObject *my_obj = NULL; |
cf3454eadc22
[gaim-migrate @ 11051]
Luke Schierer <lschiere@pidgin.im>
parents:
10047
diff
changeset
|
925 const char *filename = NULL; |
cf3454eadc22
[gaim-migrate @ 11051]
Luke Schierer <lschiere@pidgin.im>
parents:
10047
diff
changeset
|
926 gchar *data = NULL; |
cf3454eadc22
[gaim-migrate @ 11051]
Luke Schierer <lschiere@pidgin.im>
parents:
10047
diff
changeset
|
927 gsize len = 0; |
cf3454eadc22
[gaim-migrate @ 11051]
Luke Schierer <lschiere@pidgin.im>
parents:
10047
diff
changeset
|
928 const char *my_info = NULL; |
cf3454eadc22
[gaim-migrate @ 11051]
Luke Schierer <lschiere@pidgin.im>
parents:
10047
diff
changeset
|
929 GSList *sl; |
cf3454eadc22
[gaim-migrate @ 11051]
Luke Schierer <lschiere@pidgin.im>
parents:
10047
diff
changeset
|
930 |
cf3454eadc22
[gaim-migrate @ 11051]
Luke Schierer <lschiere@pidgin.im>
parents:
10047
diff
changeset
|
931 gaim_debug_info("msn", "Requesting our own user display\n"); |
cf3454eadc22
[gaim-migrate @ 11051]
Luke Schierer <lschiere@pidgin.im>
parents:
10047
diff
changeset
|
932 |
cf3454eadc22
[gaim-migrate @ 11051]
Luke Schierer <lschiere@pidgin.im>
parents:
10047
diff
changeset
|
933 my_obj = msn_user_get_object(session->user); |
cf3454eadc22
[gaim-migrate @ 11051]
Luke Schierer <lschiere@pidgin.im>
parents:
10047
diff
changeset
|
934 |
cf3454eadc22
[gaim-migrate @ 11051]
Luke Schierer <lschiere@pidgin.im>
parents:
10047
diff
changeset
|
935 if (my_obj != NULL) |
cf3454eadc22
[gaim-migrate @ 11051]
Luke Schierer <lschiere@pidgin.im>
parents:
10047
diff
changeset
|
936 { |
cf3454eadc22
[gaim-migrate @ 11051]
Luke Schierer <lschiere@pidgin.im>
parents:
10047
diff
changeset
|
937 filename = msn_object_get_real_location(my_obj); |
cf3454eadc22
[gaim-migrate @ 11051]
Luke Schierer <lschiere@pidgin.im>
parents:
10047
diff
changeset
|
938 my_info = msn_object_get_sha1c(my_obj); |
cf3454eadc22
[gaim-migrate @ 11051]
Luke Schierer <lschiere@pidgin.im>
parents:
10047
diff
changeset
|
939 } |
cf3454eadc22
[gaim-migrate @ 11051]
Luke Schierer <lschiere@pidgin.im>
parents:
10047
diff
changeset
|
940 |
cf3454eadc22
[gaim-migrate @ 11051]
Luke Schierer <lschiere@pidgin.im>
parents:
10047
diff
changeset
|
941 if (filename != NULL) |
cf3454eadc22
[gaim-migrate @ 11051]
Luke Schierer <lschiere@pidgin.im>
parents:
10047
diff
changeset
|
942 g_file_get_contents(filename, &data, &len, NULL); |
cf3454eadc22
[gaim-migrate @ 11051]
Luke Schierer <lschiere@pidgin.im>
parents:
10047
diff
changeset
|
943 |
cf3454eadc22
[gaim-migrate @ 11051]
Luke Schierer <lschiere@pidgin.im>
parents:
10047
diff
changeset
|
944 /* TODO: I think we need better buddy icon core functions. */ |
cf3454eadc22
[gaim-migrate @ 11051]
Luke Schierer <lschiere@pidgin.im>
parents:
10047
diff
changeset
|
945 gaim_buddy_icons_set_for_user(account, user->passport, (void *)data, len); |
cf3454eadc22
[gaim-migrate @ 11051]
Luke Schierer <lschiere@pidgin.im>
parents:
10047
diff
changeset
|
946 |
cf3454eadc22
[gaim-migrate @ 11051]
Luke Schierer <lschiere@pidgin.im>
parents:
10047
diff
changeset
|
947 sl = gaim_find_buddies(account, user->passport); |
cf3454eadc22
[gaim-migrate @ 11051]
Luke Schierer <lschiere@pidgin.im>
parents:
10047
diff
changeset
|
948 |
cf3454eadc22
[gaim-migrate @ 11051]
Luke Schierer <lschiere@pidgin.im>
parents:
10047
diff
changeset
|
949 for (; sl != NULL; sl = sl->next) |
cf3454eadc22
[gaim-migrate @ 11051]
Luke Schierer <lschiere@pidgin.im>
parents:
10047
diff
changeset
|
950 { |
cf3454eadc22
[gaim-migrate @ 11051]
Luke Schierer <lschiere@pidgin.im>
parents:
10047
diff
changeset
|
951 GaimBuddy *buddy = (GaimBuddy *)sl->data; |
cf3454eadc22
[gaim-migrate @ 11051]
Luke Schierer <lschiere@pidgin.im>
parents:
10047
diff
changeset
|
952 gaim_blist_node_set_string((GaimBlistNode*)buddy, "icon_checksum", info); |
cf3454eadc22
[gaim-migrate @ 11051]
Luke Schierer <lschiere@pidgin.im>
parents:
10047
diff
changeset
|
953 } |
cf3454eadc22
[gaim-migrate @ 11051]
Luke Schierer <lschiere@pidgin.im>
parents:
10047
diff
changeset
|
954 |
9860 | 955 session->userlist->buddy_icon_window++; |
956 msn_release_buddy_icon_request(session->userlist); | |
957 } | |
9193 | 958 } |