Mercurial > pidgin
annotate src/protocols/msn/slp.c @ 9262:572e4658492c
[gaim-migrate @ 10061]
Patch by Justin Wood. He says:
"User icon would set wrong status There is a small window, that if you set
a user icon, you'll set the wrong status for the next update.
Thought this over, and it shouldn't have any nasty side effects.. but there
are potential problems, if a status change message is lost. Things should
be ok though, that said"
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Fri, 11 Jun 2004 00:16:36 +0000 |
parents | f5f7482678d2 |
children | 70153c759016 |
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 | |
43 /************************************************************************** | |
44 * Util | |
45 **************************************************************************/ | |
46 | |
47 char * | |
48 get_token(const char *str, const char *start, const char *end) | |
49 { | |
50 const char *c, *c2; | |
51 | |
52 if ((c = strstr(str, start)) == NULL) | |
53 return NULL; | |
54 | |
55 c += strlen(start); | |
56 | |
57 if (end != NULL) | |
58 { | |
59 if ((c2 = strstr(c, end)) == NULL) | |
60 return NULL; | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
61 |
9193 | 62 return g_strndup(c, c2 - c); |
63 } | |
64 else | |
65 { | |
66 /* This has to be changed */ | |
67 return g_strdup(c); | |
68 } | |
69 | |
70 } | |
71 | |
72 /************************************************************************** | |
73 * Xfer | |
74 **************************************************************************/ | |
75 | |
76 static void | |
77 msn_xfer_init(GaimXfer *xfer) | |
78 { | |
79 MsnSlpCall *slpcall; | |
80 /* MsnSlpLink *slplink; */ | |
81 char *content; | |
82 | |
83 gaim_debug_info("msn", "xfer_init\n"); | |
84 | |
85 slpcall = xfer->data; | |
86 | |
87 /* Send Ok */ | |
88 content = g_strdup_printf("SessionID: %lu\r\n\r\n", | |
89 slpcall->session_id); | |
90 | |
91 send_ok(slpcall, slpcall->branch, "application/x-msnmsgr-sessionreqbody", | |
92 content); | |
93 | |
94 g_free(content); | |
95 gaim_xfer_add(xfer); | |
96 msn_slplink_unleash(slpcall->slplink); | |
97 } | |
98 | |
99 void | |
100 msn_xfer_cancel(GaimXfer *xfer) | |
101 { | |
102 MsnSlpCall *slpcall; | |
103 char *content; | |
104 | |
105 slpcall = xfer->data; | |
106 | |
107 if (gaim_xfer_get_status(xfer) == GAIM_XFER_STATUS_CANCEL_LOCAL) | |
108 { | |
109 if (slpcall->started) | |
110 { | |
111 msn_slp_call_close(slpcall); | |
112 } | |
113 else | |
114 { | |
115 content = g_strdup_printf("SessionID: %lu\r\n\r\n", | |
116 slpcall->session_id); | |
117 | |
118 send_decline(slpcall, slpcall->branch, "application/x-msnmsgr-sessionreqbody", | |
119 content); | |
120 | |
121 g_free(content); | |
122 msn_slplink_unleash(slpcall->slplink); | |
123 } | |
124 } | |
125 } | |
126 | |
127 void | |
128 msn_xfer_progress_cb(MsnSlpCall *slpcall, gsize total_length, gsize len, gsize offset) | |
129 { | |
130 GaimXfer *xfer; | |
131 | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
132 xfer = slpcall->xfer; |
9193 | 133 |
9226
7a00289f2ef1
[gaim-migrate @ 10022]
Christian Hammond <chipx86@chipx86.com>
parents:
9198
diff
changeset
|
134 xfer->bytes_sent = (offset + len); |
7a00289f2ef1
[gaim-migrate @ 10022]
Christian Hammond <chipx86@chipx86.com>
parents:
9198
diff
changeset
|
135 xfer->bytes_remaining = total_length - (offset + len); |
9193 | 136 |
137 gaim_xfer_update_progress(xfer); | |
138 } | |
139 | |
140 void | |
9259
f5f7482678d2
[gaim-migrate @ 10058]
Christian Hammond <chipx86@chipx86.com>
parents:
9231
diff
changeset
|
141 msn_xfer_end_cb(MsnSlpCall *slpcall) |
9193 | 142 { |
9226
7a00289f2ef1
[gaim-migrate @ 10022]
Christian Hammond <chipx86@chipx86.com>
parents:
9198
diff
changeset
|
143 if (gaim_xfer_get_status(slpcall->xfer) != GAIM_XFER_STATUS_DONE) |
7a00289f2ef1
[gaim-migrate @ 10022]
Christian Hammond <chipx86@chipx86.com>
parents:
9198
diff
changeset
|
144 { |
9259
f5f7482678d2
[gaim-migrate @ 10058]
Christian Hammond <chipx86@chipx86.com>
parents:
9231
diff
changeset
|
145 gaim_xfer_cancel_remote(slpcall->xfer); |
9226
7a00289f2ef1
[gaim-migrate @ 10022]
Christian Hammond <chipx86@chipx86.com>
parents:
9198
diff
changeset
|
146 } |
9193 | 147 } |
148 | |
9259
f5f7482678d2
[gaim-migrate @ 10058]
Christian Hammond <chipx86@chipx86.com>
parents:
9231
diff
changeset
|
149 void |
f5f7482678d2
[gaim-migrate @ 10058]
Christian Hammond <chipx86@chipx86.com>
parents:
9231
diff
changeset
|
150 msn_xfer_completed_cb(MsnSlpCall *slpcall, const char *body, |
f5f7482678d2
[gaim-migrate @ 10058]
Christian Hammond <chipx86@chipx86.com>
parents:
9231
diff
changeset
|
151 long long size) |
f5f7482678d2
[gaim-migrate @ 10058]
Christian Hammond <chipx86@chipx86.com>
parents:
9231
diff
changeset
|
152 { |
f5f7482678d2
[gaim-migrate @ 10058]
Christian Hammond <chipx86@chipx86.com>
parents:
9231
diff
changeset
|
153 gaim_xfer_set_completed(slpcall->xfer, TRUE); |
f5f7482678d2
[gaim-migrate @ 10058]
Christian Hammond <chipx86@chipx86.com>
parents:
9231
diff
changeset
|
154 } |
f5f7482678d2
[gaim-migrate @ 10058]
Christian Hammond <chipx86@chipx86.com>
parents:
9231
diff
changeset
|
155 |
9193 | 156 /************************************************************************** |
157 * SLP Control | |
158 **************************************************************************/ | |
159 | |
160 #if 0 | |
161 static void | |
162 got_transresp(MsnSlpCall *slpcall, const char *nonce, | |
163 const char *ips_str, int port) | |
164 { | |
165 MsnDirectConn *directconn; | |
166 char **ip_addrs, **c; | |
167 | |
168 directconn = msn_directconn_new(slpcall->slplink); | |
169 | |
170 directconn->initial_call = slpcall; | |
171 | |
172 /* msn_directconn_parse_nonce(directconn, nonce); */ | |
173 directconn->nonce = g_strdup(nonce); | |
174 | |
175 ip_addrs = g_strsplit(ips_str, " ", -1); | |
176 | |
177 for (c = ip_addrs; *c != NULL; c++) | |
178 { | |
179 gaim_debug_info("msn", "ip_addr = %s\n", *c); | |
180 if (msn_directconn_connect(directconn, *c, port)) | |
181 break; | |
182 } | |
183 | |
184 g_strfreev(ip_addrs); | |
185 } | |
186 #endif | |
187 | |
188 static void | |
189 send_ok(MsnSlpCall *slpcall, const char *branch, | |
190 const char *type, const char *content) | |
191 { | |
192 MsnSlpLink *slplink; | |
193 MsnSlpMessage *slpmsg; | |
194 | |
195 slplink = slpcall->slplink; | |
196 | |
197 /* 200 OK */ | |
198 slpmsg = msn_slpmsg_sip_new(slpcall, 1, | |
199 "MSNSLP/1.0 200 OK", | |
200 branch, type, content); | |
201 | |
202 #ifdef DEBUG_SLP | |
203 slpmsg->info = "SLP 200 OK"; | |
204 slpmsg->text_body = TRUE; | |
205 #endif | |
206 | |
207 msn_slplink_queue_slpmsg(slplink, slpmsg); | |
208 | |
209 msn_slp_call_session_init(slpcall); | |
210 } | |
211 | |
212 static void | |
213 send_decline(MsnSlpCall *slpcall, const char *branch, | |
214 const char *type, const char *content) | |
215 { | |
216 MsnSlpLink *slplink; | |
217 MsnSlpMessage *slpmsg; | |
218 | |
219 slplink = slpcall->slplink; | |
220 | |
221 /* 603 Decline */ | |
222 slpmsg = msn_slpmsg_sip_new(slpcall, 1, | |
223 "MSNSLP/1.0 603 Decline", | |
224 branch, type, content); | |
225 | |
226 #ifdef DEBUG_SLP | |
227 slpmsg->info = "SLP 603 Decline"; | |
228 slpmsg->text_body = TRUE; | |
229 #endif | |
230 | |
231 msn_slplink_queue_slpmsg(slplink, slpmsg); | |
232 } | |
233 | |
234 static void | |
235 got_sessionreq(MsnSlpCall *slpcall, const char *branch, | |
236 const char *euf_guid, const char *context) | |
237 { | |
238 if (!strcmp(euf_guid, "A4268EEC-FEC5-49E5-95C3-F126696BDBF6")) | |
239 { | |
240 /* Emoticon or UserDisplay */ | |
241 MsnSlpSession *slpsession; | |
242 MsnSlpLink *slplink; | |
243 MsnSlpMessage *slpmsg; | |
244 MsnObject *obj; | |
245 char *msnobj_data; | |
246 const char *sha1c; | |
247 const char *file_name; | |
248 char *content; | |
249 gsize len; | |
250 int type; | |
251 | |
252 /* Send Ok */ | |
253 content = g_strdup_printf("SessionID: %lu\r\n\r\n", | |
254 slpcall->session_id); | |
255 | |
256 send_ok(slpcall, branch, "application/x-msnmsgr-sessionreqbody", | |
257 content); | |
258 | |
259 g_free(content); | |
260 | |
261 slplink = slpcall->slplink; | |
262 | |
263 gaim_base64_decode(context, &msnobj_data, &len); | |
264 obj = msn_object_new_from_string(msnobj_data); | |
265 type = msn_object_get_type(obj); | |
266 sha1c = msn_object_get_sha1c(obj); | |
267 g_free(msnobj_data); | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
268 |
9193 | 269 if (!(type == MSN_OBJECT_USERTILE)) |
270 { | |
271 gaim_debug_error("msn", "Wrong object?\n"); | |
272 msn_object_destroy(obj); | |
273 g_return_if_reached(); | |
274 } | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
275 |
9193 | 276 file_name = msn_object_get_real_location(obj); |
277 | |
278 slpsession = msn_slplink_find_slp_session(slplink, | |
279 slpcall->session_id); | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
280 |
9193 | 281 /* DATA PREP */ |
282 slpmsg = msn_slpmsg_new(slplink); | |
283 slpmsg->slpsession = slpsession; | |
284 slpmsg->session_id = slpsession->id; | |
285 msn_slpmsg_set_body(slpmsg, NULL, 4); | |
286 #ifdef DEBUG_SLP | |
287 slpmsg->info = "SLP DATA PREP"; | |
288 #endif | |
289 msn_slplink_queue_slpmsg(slplink, slpmsg); | |
290 | |
291 /* DATA */ | |
292 slpmsg = msn_slpmsg_new(slplink); | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
293 slpmsg->slpsession = slpsession; |
9193 | 294 slpmsg->flags = 0x20; |
295 #ifdef DEBUG_SLP | |
296 slpmsg->info = "SLP DATA"; | |
297 #endif | |
298 msn_slpmsg_open_file(slpmsg, file_name); | |
299 msn_slplink_queue_slpmsg(slplink, slpmsg); | |
300 } | |
301 else if (!strcmp(euf_guid, "5D3E02AB-6190-11D3-BBBB-00C04F795683")) | |
302 { | |
303 /* File Transfer */ | |
304 GaimAccount *account; | |
305 GaimXfer *xfer; | |
306 char *bin; | |
307 gsize bin_len; | |
308 guint32 file_size; | |
309 char *file_name; | |
310 | |
311 account = slpcall->slplink->session->account; | |
312 | |
9259
f5f7482678d2
[gaim-migrate @ 10058]
Christian Hammond <chipx86@chipx86.com>
parents:
9231
diff
changeset
|
313 slpcall->cb = msn_xfer_completed_cb; |
f5f7482678d2
[gaim-migrate @ 10058]
Christian Hammond <chipx86@chipx86.com>
parents:
9231
diff
changeset
|
314 slpcall->end_cb = msn_xfer_end_cb; |
9193 | 315 slpcall->progress_cb = msn_xfer_progress_cb; |
316 slpcall->branch = g_strdup(branch); | |
317 | |
318 xfer = gaim_xfer_new(account, GAIM_XFER_RECEIVE, | |
319 slpcall->slplink->remote_user); | |
320 | |
321 gaim_base64_decode(context, &bin, &bin_len); | |
322 file_size = *((gsize *)bin + 2); | |
323 file_name = g_utf16_to_utf8((const gunichar2 *)(bin + 20), -1, | |
324 NULL, NULL, NULL); | |
325 | |
326 g_free(bin); | |
327 | |
328 gaim_xfer_set_filename(xfer, file_name); | |
329 gaim_xfer_set_size(xfer, file_size); | |
330 gaim_xfer_set_init_fnc(xfer, msn_xfer_init); | |
331 gaim_xfer_set_request_denied_fnc(xfer, msn_xfer_cancel); | |
332 gaim_xfer_set_cancel_recv_fnc(xfer, msn_xfer_cancel); | |
333 | |
334 slpcall->xfer = xfer; | |
335 xfer->data = slpcall; | |
336 | |
337 gaim_xfer_request(xfer); | |
338 } | |
339 } | |
340 | |
341 void | |
342 send_bye(MsnSlpCall *slpcall, const char *type) | |
343 { | |
344 MsnSlpLink *slplink; | |
345 MsnSlpMessage *slpmsg; | |
346 char *header; | |
347 | |
348 slplink = slpcall->slplink; | |
349 | |
350 g_return_if_fail(slplink != NULL); | |
351 | |
352 header = g_strdup_printf("BYE MSNMSGR:%s MSNSLP/1.0", | |
353 slplink->local_user); | |
354 | |
355 slpmsg = msn_slpmsg_sip_new(slpcall, 0, header, | |
356 "A0D624A6-6C0C-4283-A9E0-BC97B4B46D32", | |
357 type, | |
358 "\r\n"); | |
359 g_free(header); | |
360 | |
361 #ifdef DEBUG_SLP | |
362 slpmsg->info = "SLP BYE"; | |
363 slpmsg->text_body = TRUE; | |
364 #endif | |
365 | |
366 msn_slplink_queue_slpmsg(slplink, slpmsg); | |
367 } | |
368 | |
369 static void | |
370 got_invite(MsnSlpCall *slpcall, | |
371 const char *branch, const char *type, const char *content) | |
372 { | |
373 MsnSlpLink *slplink; | |
374 | |
375 slplink = slpcall->slplink; | |
376 | |
377 if (!strcmp(type, "application/x-msnmsgr-sessionreqbody")) | |
378 { | |
379 char *euf_guid, *context; | |
380 char *temp; | |
381 | |
382 euf_guid = get_token(content, "EUF-GUID: {", "}\r\n"); | |
383 | |
384 temp = get_token(content, "SessionID: ", "\r\n"); | |
385 if (temp != NULL) | |
386 slpcall->session_id = atoi(temp); | |
387 g_free(temp); | |
388 | |
389 temp = get_token(content, "AppID: ", "\r\n"); | |
390 if (temp != NULL) | |
391 slpcall->app_id = atoi(temp); | |
392 g_free(temp); | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
393 |
9193 | 394 context = get_token(content, "Context: ", "\r\n"); |
395 | |
396 got_sessionreq(slpcall, branch, euf_guid, context); | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
397 |
9193 | 398 g_free(context); |
399 g_free(euf_guid); | |
400 } | |
401 else if (!strcmp(type, "application/x-msnmsgr-transreqbody")) | |
402 { | |
403 /* A direct connection? */ | |
404 | |
405 char *listening, *nonce; | |
406 char *content; | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
407 |
9193 | 408 if (FALSE) |
409 { | |
410 #if 0 | |
411 MsnDirectConn *directconn; | |
412 /* const char *ip_addr; */ | |
413 char *ip_port; | |
414 int port; | |
415 | |
416 /* ip_addr = gaim_prefs_get_string("/core/ft/public_ip"); */ | |
417 ip_port = "5190"; | |
418 listening = "true"; | |
419 nonce = rand_guid(); | |
420 | |
421 directconn = msn_directconn_new(slplink); | |
422 | |
423 /* msn_directconn_parse_nonce(directconn, nonce); */ | |
424 directconn->nonce = g_strdup(nonce); | |
425 | |
426 msn_directconn_listen(directconn); | |
427 | |
428 port = directconn->port; | |
429 | |
430 content = g_strdup_printf( | |
431 "Bridge: TCPv1\r\n" | |
432 "Listening: %s\r\n" | |
433 "Nonce: {%s}\r\n" | |
434 "Ipv4Internal-Addrs: 192.168.0.82\r\n" | |
435 "Ipv4Internal-Port: %d\r\n" | |
436 "\r\n", | |
437 listening, | |
438 nonce, | |
439 port); | |
440 #endif | |
441 } | |
442 else | |
443 { | |
444 listening = "false"; | |
445 nonce = g_strdup("00000000-0000-0000-0000-000000000000"); | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
446 |
9193 | 447 content = g_strdup_printf( |
448 "Bridge: TCPv1\r\n" | |
449 "Listening: %s\r\n" | |
450 "Nonce: {%s}\r\n" | |
451 "\r\n", | |
452 listening, | |
453 nonce); | |
454 } | |
455 | |
456 send_ok(slpcall, branch, | |
457 "application/x-msnmsgr-transrespbody", content); | |
458 | |
459 g_free(content); | |
460 g_free(nonce); | |
461 } | |
462 else if (!strcmp(type, "application/x-msnmsgr-transrespbody")) | |
463 { | |
464 #if 0 | |
465 char *ip_addrs; | |
466 char *temp; | |
467 char *nonce; | |
468 int port; | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
469 |
9193 | 470 nonce = get_token(content, "Nonce: {", "}\r\n"); |
471 ip_addrs = get_token(content, "IPv4Internal-Addrs: ", "\r\n"); | |
472 | |
473 temp = get_token(content, "IPv4Internal-Port: ", "\r\n"); | |
474 if (temp != NULL) | |
475 port = atoi(temp); | |
476 else | |
477 port = -1; | |
478 g_free(temp); | |
479 | |
480 if (ip_addrs == NULL) | |
481 return; | |
482 | |
483 if (port > 0) | |
484 got_transresp(slpcall, nonce, ip_addrs, port); | |
485 | |
486 g_free(nonce); | |
487 g_free(ip_addrs); | |
488 #endif | |
489 } | |
490 } | |
491 | |
492 static void | |
493 got_ok(MsnSlpCall *slpcall, | |
494 const char *type, const char *content) | |
495 { | |
496 g_return_if_fail(slpcall != NULL); | |
497 g_return_if_fail(type != NULL); | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
498 |
9193 | 499 if (!strcmp(type, "application/x-msnmsgr-sessionreqbody")) |
500 { | |
501 #if 0 | |
502 if (slpcall->type == MSN_SLPCALL_DC) | |
503 { | |
504 /* First let's try a DirectConnection. */ | |
505 | |
506 MsnSlpLink *slplink; | |
507 MsnSlpMessage *slpmsg; | |
508 char *header; | |
509 char *content; | |
510 char *branch; | |
511 | |
512 slplink = slpcall->slplink; | |
513 | |
514 branch = rand_guid(); | |
515 | |
516 content = g_strdup_printf( | |
517 "Bridges: TRUDPv1 TCPv1\r\n" | |
518 "NetID: 0\r\n" | |
519 "Conn-Type: Direct-Connect\r\n" | |
520 "UPnPNat: false\r\n" | |
521 "ICF: false\r\n" | |
522 ); | |
523 | |
524 header = g_strdup_printf("INVITE MSNMSGR:%s MSNSLP/1.0", | |
525 slplink->remote_user); | |
526 | |
527 slpmsg = msn_slp_sipmsg_new(slpcall, 0, header, branch, | |
528 "application/x-msnmsgr-transreqbody", | |
529 content); | |
530 | |
531 #ifdef DEBUG_SLP | |
532 slpmsg->info = "SLP INVITE"; | |
533 slpmsg->text_body = TRUE; | |
534 #endif | |
535 msn_slplink_send_slpmsg(slplink, slpmsg); | |
536 | |
537 g_free(header); | |
538 g_free(content); | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
539 |
9193 | 540 g_free(branch); |
541 } | |
542 else | |
543 { | |
544 msn_slp_call_session_init(slpcall); | |
545 } | |
546 #else | |
547 msn_slp_call_session_init(slpcall); | |
548 #endif | |
549 } | |
550 else if (!strcmp(type, "application/x-msnmsgr-transreqbody")) | |
551 { | |
552 /* Do we get this? */ | |
553 gaim_debug_info("msn", "OK with transreqbody\n"); | |
554 } | |
555 else if (!strcmp(type, "application/x-msnmsgr-transrespbody")) | |
556 { | |
557 #if 0 | |
558 char *ip_addrs; | |
559 char *temp; | |
560 char *nonce; | |
561 int port; | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
562 |
9193 | 563 nonce = get_token(content, "Nonce: {", "}\r\n"); |
564 ip_addrs = get_token(content, "IPv4Internal-Addrs: ", "\r\n"); | |
565 | |
566 temp = get_token(content, "IPv4Internal-Port: ", "\r\n"); | |
567 if (temp != NULL) | |
568 port = atoi(temp); | |
569 else | |
570 port = -1; | |
571 g_free(temp); | |
572 | |
573 if (ip_addrs == NULL) | |
574 return; | |
575 | |
576 if (port > 0) | |
577 got_transresp(slpcall, nonce, ip_addrs, port); | |
578 | |
579 g_free(nonce); | |
580 g_free(ip_addrs); | |
581 #endif | |
582 } | |
583 } | |
584 | |
585 MsnSlpCall * | |
586 msn_slp_sip_recv(MsnSlpLink *slplink, const char *body, gsize len) | |
587 { | |
588 MsnSlpCall *slpcall; | |
589 | |
590 if (!strncmp(body, "INVITE", strlen("INVITE"))) | |
591 { | |
592 char *branch; | |
593 char *content; | |
594 char *content_type; | |
595 | |
596 slpcall = msn_slp_call_new(slplink); | |
597 | |
598 /* From: <msnmsgr:buddy@hotmail.com> */ | |
599 #if 0 | |
600 slpcall->remote_user = get_token(body, "From: <msnmsgr:", ">\r\n"); | |
601 #endif | |
602 | |
603 branch = get_token(body, ";branch={", "}"); | |
604 | |
605 slpcall->id = get_token(body, "Call-ID: {", "}"); | |
606 | |
607 #if 0 | |
608 long content_len = -1; | |
609 | |
610 temp = get_token(body, "Content-Length: ", "\r\n"); | |
611 if (temp != NULL) | |
612 content_len = atoi(temp); | |
613 g_free(temp); | |
614 #endif | |
615 content_type = get_token(body, "Content-Type: ", "\r\n"); | |
616 | |
617 content = get_token(body, "\r\n\r\n", NULL); | |
618 | |
619 got_invite(slpcall, branch, content_type, content); | |
620 | |
621 g_free(content_type); | |
622 g_free(content); | |
623 } | |
624 else if (!strncmp(body, "MSNSLP/1.0 ", strlen("MSNSLP/1.0 "))) | |
625 { | |
626 char *content; | |
627 char *content_type; | |
628 /* Make sure this is "OK" */ | |
629 const char *status = body + strlen("MSNSLP/1.0 "); | |
630 char *call_id; | |
631 | |
632 call_id = get_token(body, "Call-ID: {", "}"); | |
633 slpcall = msn_slplink_find_slp_call(slplink, call_id); | |
634 g_free(call_id); | |
635 | |
9231
ac8790437abe
[gaim-migrate @ 10027]
Christian Hammond <chipx86@chipx86.com>
parents:
9226
diff
changeset
|
636 g_return_val_if_fail(slpcall != NULL, NULL); |
ac8790437abe
[gaim-migrate @ 10027]
Christian Hammond <chipx86@chipx86.com>
parents:
9226
diff
changeset
|
637 |
9193 | 638 if (strncmp(status, "200 OK", 6)) |
639 { | |
640 /* It's not valid. Kill this off. */ | |
641 char temp[32]; | |
642 const char *c; | |
643 | |
644 /* Eww */ | |
645 if ((c = strchr(status, '\r')) || (c = strchr(status, '\n')) || | |
646 (c = strchr(status, '\0'))) | |
647 { | |
648 strncpy(temp, status, c - status); | |
649 temp[c - status] = '\0'; | |
650 } | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
651 |
9193 | 652 gaim_debug_error("msn", "Received non-OK result: %s\n", temp); |
653 | |
654 slpcall->wasted = TRUE; | |
655 | |
656 /* msn_slp_call_destroy(slpcall); */ | |
657 return slpcall; | |
658 } | |
659 | |
660 content_type = get_token(body, "Content-Type: ", "\r\n"); | |
661 | |
662 content = get_token(body, "\r\n\r\n", NULL); | |
663 | |
664 got_ok(slpcall, content_type, content); | |
665 | |
666 g_free(content_type); | |
667 g_free(content); | |
668 } | |
669 else if (!strncmp(body, "BYE", strlen("BYE"))) | |
670 { | |
671 char *call_id; | |
672 | |
673 call_id = get_token(body, "Call-ID: {", "}"); | |
674 slpcall = msn_slplink_find_slp_call(slplink, call_id); | |
675 g_free(call_id); | |
676 | |
677 if (slpcall != NULL) | |
678 slpcall->wasted = TRUE; | |
679 | |
680 /* msn_slp_call_destroy(slpcall); */ | |
681 } | |
682 else | |
683 slpcall = NULL; | |
684 | |
685 return slpcall; | |
686 } | |
687 | |
688 /************************************************************************** | |
689 * Msg Callbacks | |
690 **************************************************************************/ | |
691 | |
692 void | |
693 msn_p2p_msg(MsnCmdProc *cmdproc, MsnMessage *msg) | |
694 { | |
695 MsnSession *session; | |
696 MsnSlpLink *slplink; | |
697 | |
698 session = cmdproc->servconn->session; | |
699 slplink = msn_session_get_slplink(session, msg->remote_user); | |
700 | |
701 msn_slplink_process_msg(slplink, msg); | |
702 } | |
703 | |
704 void | |
705 got_emoticon(MsnSlpCall *slpcall, | |
706 const char *data, long long size) | |
707 { | |
708 gaim_debug_info("msn", "Got smiley: %s\n", slpcall->data_info); | |
709 | |
710 #if 0 | |
711 GaimConversation *conv; | |
712 GaimConnection *gc = slpsession->swboard->servconn->session->account->gc; | |
713 serv_got_smiley(gc, info, data, size); | |
714 #endif | |
715 } | |
716 | |
717 void | |
718 msn_emoticon_msg(MsnCmdProc *cmdproc, MsnMessage *msg) | |
719 { | |
720 MsnSession *session; | |
721 MsnSlpLink *slplink; | |
722 MsnObject *obj; | |
723 char **tokens; | |
724 char *smile; | |
725 const char *who; | |
726 | |
727 session = cmdproc->servconn->session; | |
728 | |
729 tokens = g_strsplit(msg->body, "\t", 2); | |
730 | |
731 smile = tokens[0]; | |
732 obj = msn_object_new_from_string(gaim_url_decode(tokens[1])); | |
733 | |
734 who = msn_object_get_creator(obj); | |
735 | |
736 slplink = msn_session_get_slplink(session, who); | |
737 | |
738 msn_slplink_request_object(slplink, smile, got_emoticon, obj); | |
739 | |
740 g_strfreev(tokens); | |
741 } | |
742 | |
743 void | |
744 got_user_display(MsnSlpCall *slpcall, | |
745 const char *data, long long size) | |
746 { | |
747 const char *info; | |
748 GaimAccount *account; | |
749 GSList *sl; | |
750 | |
751 info = slpcall->data_info; | |
752 gaim_debug_info("msn", "Got User Display: %s\n", info); | |
753 | |
754 account = slpcall->slplink->session->account; | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
755 |
9193 | 756 /* TODO: I think we need better buddy icon core functions. */ |
757 gaim_buddy_icons_set_for_user(account, slpcall->slplink->remote_user, | |
758 (void *)data, size); | |
759 | |
760 sl = gaim_find_buddies(account, slpcall->slplink->remote_user); | |
761 | |
762 for (; sl != NULL; sl = sl->next) | |
763 { | |
764 GaimBuddy *buddy = (GaimBuddy *)sl->data; | |
765 gaim_blist_node_set_string((GaimBlistNode*)buddy, "icon_checksum", info); | |
766 gaim_blist_save(); | |
767 } | |
768 } | |
769 | |
770 static gboolean | |
771 buddy_icon_cached(GaimConnection *gc, MsnObject *obj) | |
772 { | |
773 GaimAccount *account; | |
774 GaimBuddy *buddy; | |
775 GSList *sl; | |
776 const char *old; | |
777 const char *new; | |
778 | |
779 g_return_val_if_fail(obj != NULL, FALSE); | |
780 | |
781 account = gaim_connection_get_account(gc); | |
782 | |
783 sl = gaim_find_buddies(account, msn_object_get_creator(obj)); | |
784 | |
785 if (sl == NULL) | |
786 { | |
787 return FALSE; | |
788 } | |
789 | |
790 buddy = (GaimBuddy *)sl->data; | |
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
791 |
9193 | 792 old = gaim_blist_node_get_string((GaimBlistNode *)buddy, "icon_checksum"); |
793 new = msn_object_get_sha1c(obj); | |
794 | |
795 if (new == NULL) | |
796 { | |
797 return FALSE; | |
798 } | |
799 | |
800 if (old != NULL && !strcmp(old, new)) | |
801 return TRUE; | |
802 | |
803 return FALSE; | |
804 } | |
805 | |
806 void | |
807 msn_request_buddy_icon(GaimConnection *gc, const char *passport) | |
808 { | |
809 MsnSession *session; | |
810 MsnSlpLink *slplink; | |
811 MsnUser *user; | |
812 MsnObject *obj; | |
813 const char *info; | |
814 | |
815 session = gc->proto_data; | |
816 | |
817 g_return_if_fail(session->protocol_ver == 9); | |
818 | |
819 slplink = msn_session_get_slplink(session, passport); | |
820 | |
821 user = msn_userlist_find_user(session->userlist, passport); | |
822 | |
823 obj = msn_user_get_object(user); | |
824 | |
825 if (obj == NULL) | |
826 /* It seems the user has not set a msnobject */ | |
827 return; | |
828 | |
829 info = msn_object_get_sha1c(obj); | |
830 | |
831 if (!buddy_icon_cached(gc, obj)) | |
832 msn_slplink_request_object(slplink, info, got_user_display, obj); | |
833 } |