Mercurial > pidgin
annotate src/protocols/msn/slp.c @ 9739:35f22ba01bd7
[gaim-migrate @ 10603]
bug fix.
committer: Tailor Script <tailor@pidgin.im>
| author | Sean Egan <seanegan@gmail.com> |
|---|---|
| date | Wed, 11 Aug 2004 18:05:10 +0000 |
| parents | 7a8aa87164ae |
| children | 1e9ecca6c97e |
| 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); | |
|
9263
70153c759016
[gaim-migrate @ 10062]
Christian Hammond <chipx86@chipx86.com>
parents:
9259
diff
changeset
|
322 file_size = GUINT32_FROM_LE(*((gsize *)bin + 2)); |
| 9193 | 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 { | |
| 9739 | 648 size_t offset = c - status; |
| 649 if (offset >= sizeof(temp)) | |
| 650 offset = sizeof(temp) - 1; | |
| 651 | |
| 652 strncpy(temp, status, offset); | |
| 653 temp[offset] = '\0'; | |
| 9193 | 654 } |
|
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
655 |
| 9193 | 656 gaim_debug_error("msn", "Received non-OK result: %s\n", temp); |
| 657 | |
| 658 slpcall->wasted = TRUE; | |
| 659 | |
| 660 /* msn_slp_call_destroy(slpcall); */ | |
| 661 return slpcall; | |
| 662 } | |
| 663 | |
| 664 content_type = get_token(body, "Content-Type: ", "\r\n"); | |
| 665 | |
| 666 content = get_token(body, "\r\n\r\n", NULL); | |
| 667 | |
| 668 got_ok(slpcall, content_type, content); | |
| 669 | |
| 670 g_free(content_type); | |
| 671 g_free(content); | |
| 672 } | |
| 673 else if (!strncmp(body, "BYE", strlen("BYE"))) | |
| 674 { | |
| 675 char *call_id; | |
| 676 | |
| 677 call_id = get_token(body, "Call-ID: {", "}"); | |
| 678 slpcall = msn_slplink_find_slp_call(slplink, call_id); | |
| 679 g_free(call_id); | |
| 680 | |
| 681 if (slpcall != NULL) | |
| 682 slpcall->wasted = TRUE; | |
| 683 | |
| 684 /* msn_slp_call_destroy(slpcall); */ | |
| 685 } | |
| 686 else | |
| 687 slpcall = NULL; | |
| 688 | |
| 689 return slpcall; | |
| 690 } | |
| 691 | |
| 692 /************************************************************************** | |
| 693 * Msg Callbacks | |
| 694 **************************************************************************/ | |
| 695 | |
| 696 void | |
| 697 msn_p2p_msg(MsnCmdProc *cmdproc, MsnMessage *msg) | |
| 698 { | |
| 699 MsnSession *session; | |
| 700 MsnSlpLink *slplink; | |
| 701 | |
| 702 session = cmdproc->servconn->session; | |
| 703 slplink = msn_session_get_slplink(session, msg->remote_user); | |
| 704 | |
| 705 msn_slplink_process_msg(slplink, msg); | |
| 706 } | |
| 707 | |
| 708 void | |
| 709 got_emoticon(MsnSlpCall *slpcall, | |
| 710 const char *data, long long size) | |
| 711 { | |
| 712 gaim_debug_info("msn", "Got smiley: %s\n", slpcall->data_info); | |
| 713 | |
| 714 #if 0 | |
| 715 GaimConversation *conv; | |
| 716 GaimConnection *gc = slpsession->swboard->servconn->session->account->gc; | |
| 717 serv_got_smiley(gc, info, data, size); | |
| 718 #endif | |
| 719 } | |
| 720 | |
| 721 void | |
| 722 msn_emoticon_msg(MsnCmdProc *cmdproc, MsnMessage *msg) | |
| 723 { | |
| 724 MsnSession *session; | |
| 725 MsnSlpLink *slplink; | |
| 726 MsnObject *obj; | |
| 727 char **tokens; | |
| 728 char *smile; | |
| 729 const char *who; | |
| 730 | |
| 731 session = cmdproc->servconn->session; | |
| 732 | |
| 733 tokens = g_strsplit(msg->body, "\t", 2); | |
| 734 | |
| 735 smile = tokens[0]; | |
| 736 obj = msn_object_new_from_string(gaim_url_decode(tokens[1])); | |
| 737 | |
| 738 who = msn_object_get_creator(obj); | |
| 739 | |
| 740 slplink = msn_session_get_slplink(session, who); | |
| 741 | |
| 742 msn_slplink_request_object(slplink, smile, got_emoticon, obj); | |
| 743 | |
| 744 g_strfreev(tokens); | |
| 745 } | |
| 746 | |
| 747 void | |
| 748 got_user_display(MsnSlpCall *slpcall, | |
| 749 const char *data, long long size) | |
| 750 { | |
| 751 const char *info; | |
| 752 GaimAccount *account; | |
| 753 GSList *sl; | |
| 754 | |
| 755 info = slpcall->data_info; | |
| 756 gaim_debug_info("msn", "Got User Display: %s\n", info); | |
| 757 | |
| 758 account = slpcall->slplink->session->account; | |
|
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
759 |
| 9193 | 760 /* TODO: I think we need better buddy icon core functions. */ |
| 761 gaim_buddy_icons_set_for_user(account, slpcall->slplink->remote_user, | |
| 762 (void *)data, size); | |
| 763 | |
| 764 sl = gaim_find_buddies(account, slpcall->slplink->remote_user); | |
| 765 | |
| 766 for (; sl != NULL; sl = sl->next) | |
| 767 { | |
| 768 GaimBuddy *buddy = (GaimBuddy *)sl->data; | |
| 769 gaim_blist_node_set_string((GaimBlistNode*)buddy, "icon_checksum", info); | |
| 770 } | |
| 771 } | |
| 772 | |
| 773 static gboolean | |
| 774 buddy_icon_cached(GaimConnection *gc, MsnObject *obj) | |
| 775 { | |
| 776 GaimAccount *account; | |
| 777 GaimBuddy *buddy; | |
| 778 GSList *sl; | |
| 779 const char *old; | |
| 780 const char *new; | |
| 781 | |
| 782 g_return_val_if_fail(obj != NULL, FALSE); | |
| 783 | |
| 784 account = gaim_connection_get_account(gc); | |
| 785 | |
| 786 sl = gaim_find_buddies(account, msn_object_get_creator(obj)); | |
| 787 | |
| 788 if (sl == NULL) | |
| 789 { | |
| 790 return FALSE; | |
| 791 } | |
| 792 | |
| 793 buddy = (GaimBuddy *)sl->data; | |
|
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
794 |
| 9193 | 795 old = gaim_blist_node_get_string((GaimBlistNode *)buddy, "icon_checksum"); |
| 796 new = msn_object_get_sha1c(obj); | |
| 797 | |
| 798 if (new == NULL) | |
| 799 { | |
| 800 return FALSE; | |
| 801 } | |
| 802 | |
| 803 if (old != NULL && !strcmp(old, new)) | |
| 804 return TRUE; | |
| 805 | |
| 806 return FALSE; | |
| 807 } | |
| 808 | |
| 809 void | |
| 810 msn_request_buddy_icon(GaimConnection *gc, const char *passport) | |
| 811 { | |
| 812 MsnSession *session; | |
| 813 MsnSlpLink *slplink; | |
| 814 MsnUser *user; | |
| 815 MsnObject *obj; | |
| 816 const char *info; | |
| 817 | |
| 818 session = gc->proto_data; | |
| 819 | |
| 820 g_return_if_fail(session->protocol_ver == 9); | |
| 821 | |
| 822 slplink = msn_session_get_slplink(session, passport); | |
| 823 | |
| 824 user = msn_userlist_find_user(session->userlist, passport); | |
| 825 | |
| 826 obj = msn_user_get_object(user); | |
| 827 | |
| 828 if (obj == NULL) | |
| 829 /* It seems the user has not set a msnobject */ | |
| 830 return; | |
| 831 | |
| 832 info = msn_object_get_sha1c(obj); | |
| 833 | |
| 834 if (!buddy_icon_cached(gc, obj)) | |
| 835 msn_slplink_request_object(slplink, info, got_user_display, obj); | |
| 836 } |
