Mercurial > pidgin
annotate src/protocols/msn/notification.c @ 5312:89948fedf782
[gaim-migrate @ 5684]
A patch from Phroggie to let this compile in Windows.
I normally do not accept Windows patches, as I leave it to Herman, but I'm
making an exception in this case.
committer: Tailor Script <tailor@pidgin.im>
| author | Christian Hammond <chipx86@chipx86.com> |
|---|---|
| date | Tue, 06 May 2003 04:45:26 +0000 |
| parents | e2e53316a21d |
| children | bd98232872a3 |
| rev | line source |
|---|---|
| 5309 | 1 /** |
| 2 * @file notification.c Notification server functions | |
| 3 * | |
| 4 * gaim | |
| 5 * | |
| 6 * Copyright (C) 2003 Christian Hammond <chipx86@gnupdate.org> | |
| 7 * | |
| 8 * This program is free software; you can redistribute it and/or modify | |
| 9 * it under the terms of the GNU General Public License as published by | |
| 10 * the Free Software Foundation; either version 2 of the License, or | |
| 11 * (at your option) any later version. | |
| 12 * | |
| 13 * This program is distributed in the hope that it will be useful, | |
| 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 16 * GNU General Public License for more details. | |
| 17 * | |
| 18 * You should have received a copy of the GNU General Public License | |
| 19 * along with this program; if not, write to the Free Software | |
| 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 21 */ | |
| 22 #include "msn.h" | |
| 23 #include "notification.h" | |
| 24 #include "away.h" | |
| 25 #include "error.h" | |
| 26 #include "utils.h" | |
| 27 | |
| 28 typedef struct | |
| 29 { | |
| 30 struct gaim_connection *gc; | |
| 31 MsnUser *user; | |
| 32 | |
| 33 } MsnPermitAdd; | |
| 34 | |
| 35 static GHashTable *notification_commands = NULL; | |
| 36 static GHashTable *notification_msg_types = NULL; | |
|
5312
89948fedf782
[gaim-migrate @ 5684]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
37 G_MODULE_IMPORT GSList *connections; |
| 5309 | 38 |
| 39 /************************************************************************** | |
| 40 * Callbacks | |
| 41 **************************************************************************/ | |
| 42 static void | |
| 43 msn_accept_add_cb(MsnPermitAdd *pa) | |
| 44 { | |
| 45 if (g_slist_find(connections, pa->gc) != NULL) { | |
| 46 MsnSession *session = pa->gc->proto_data; | |
| 47 char outparams[MSN_BUF_LEN]; | |
| 48 | |
| 49 g_snprintf(outparams, sizeof(outparams), "AL %s %s", | |
| 50 msn_user_get_passport(pa->user), | |
| 51 msn_url_encode(msn_user_get_name(pa->user))); | |
| 52 | |
| 53 if (msn_servconn_send_command(session->notification_conn, | |
| 54 "ADD", outparams) <= 0) { | |
| 55 hide_login_progress(pa->gc, _("Write error")); | |
| 56 signoff(pa->gc); | |
| 57 return; | |
| 58 } | |
| 59 | |
| 60 gaim_privacy_permit_add(pa->gc->account, | |
| 61 msn_user_get_passport(pa->user)); | |
| 62 build_allow_list(); | |
| 63 | |
| 64 show_got_added(pa->gc, NULL, msn_user_get_passport(pa->user), | |
| 65 msn_user_get_name(pa->user), NULL); | |
| 66 } | |
| 67 | |
| 68 msn_user_destroy(pa->user); | |
| 69 g_free(pa); | |
| 70 } | |
| 71 | |
| 72 static void | |
| 73 msn_cancel_add_cb(MsnPermitAdd *pa) | |
| 74 { | |
| 75 if (g_slist_find(connections, pa->gc) != NULL) { | |
| 76 MsnSession *session = pa->gc->proto_data; | |
| 77 char outparams[MSN_BUF_LEN]; | |
| 78 | |
| 79 g_snprintf(outparams, sizeof(outparams), "BL %s %s", | |
| 80 msn_user_get_passport(pa->user), | |
| 81 msn_url_encode(msn_user_get_name(pa->user))); | |
| 82 | |
| 83 if (msn_servconn_send_command(session->notification_conn, | |
| 84 "ADD", outparams) <= 0) { | |
| 85 hide_login_progress(pa->gc, _("Write error")); | |
| 86 signoff(pa->gc); | |
| 87 return; | |
| 88 } | |
| 89 | |
| 90 gaim_privacy_deny_add(pa->gc->account, | |
| 91 msn_user_get_passport(pa->user)); | |
| 92 build_block_list(); | |
| 93 } | |
| 94 | |
| 95 msn_user_destroy(pa->user); | |
| 96 g_free(pa); | |
| 97 } | |
| 98 | |
| 99 /************************************************************************** | |
| 100 * Catch-all commands | |
| 101 **************************************************************************/ | |
| 102 static gboolean | |
| 103 __blank_cmd(MsnServConn *servconn, const char *command, const char **params, | |
| 104 size_t param_count) | |
| 105 { | |
| 106 return TRUE; | |
| 107 } | |
| 108 | |
| 109 static gboolean | |
| 110 __unknown_cmd(MsnServConn *servconn, const char *command, const char **params, | |
| 111 size_t param_count) | |
| 112 { | |
| 113 struct gaim_connection *gc = servconn->session->account->gc; | |
| 114 | |
| 115 if (isdigit(*command)) { | |
| 116 hide_login_progress(gc, (char *)msn_error_get_text(atoi(command))); | |
| 117 } | |
| 118 else | |
| 119 hide_login_progress(gc, _("Unable to parse message.")); | |
| 120 | |
| 121 signoff(gc); | |
| 122 | |
| 123 return FALSE; | |
| 124 } | |
| 125 | |
| 126 | |
| 127 /************************************************************************** | |
| 128 * Login | |
| 129 **************************************************************************/ | |
| 130 static gboolean | |
| 131 __ver_cmd(MsnServConn *servconn, const char *command, const char **params, | |
| 132 size_t param_count) | |
| 133 { | |
| 134 struct gaim_connection *gc = servconn->session->account->gc; | |
| 135 size_t i; | |
| 136 gboolean msnp5_found = FALSE; | |
| 137 | |
| 138 for (i = 1; i < param_count; i++) { | |
| 139 if (!strcmp(params[i], "MSNP5")) { | |
| 140 msnp5_found = TRUE; | |
| 141 break; | |
| 142 } | |
| 143 } | |
| 144 | |
| 145 if (!msnp5_found) { | |
| 146 hide_login_progress(gc, _("Protocol not supported")); | |
| 147 signoff(gc); | |
| 148 | |
| 149 return FALSE; | |
| 150 } | |
| 151 | |
| 152 if (!msn_servconn_send_command(servconn, "INF", NULL)) { | |
| 153 hide_login_progress(gc, _("Unable to request INF")); | |
| 154 signoff(gc); | |
| 155 | |
| 156 return FALSE; | |
| 157 } | |
| 158 | |
| 159 return TRUE; | |
| 160 } | |
| 161 | |
| 162 static gboolean | |
| 163 __inf_cmd(MsnServConn *servconn, const char *command, const char **params, | |
| 164 size_t param_count) | |
| 165 { | |
| 166 struct gaim_connection *gc = servconn->session->account->gc; | |
| 167 char outparams[MSN_BUF_LEN]; | |
| 168 | |
| 169 if (strcmp(params[1], "MD5")) { | |
| 170 hide_login_progress(gc, _("Unable to login using MD5")); | |
| 171 signoff(gc); | |
| 172 | |
| 173 return FALSE; | |
| 174 } | |
| 175 | |
| 176 g_snprintf(outparams, sizeof(outparams), "MD5 I %s", gc->username); | |
| 177 | |
| 178 if (!msn_servconn_send_command(servconn, "USR", outparams)) { | |
| 179 hide_login_progress(gc, _("Unable to send USR")); | |
| 180 signoff(gc); | |
| 181 | |
| 182 return FALSE; | |
| 183 } | |
| 184 | |
| 185 set_login_progress(gc, 3, _("Requesting to send password")); | |
| 186 | |
| 187 return TRUE; | |
| 188 } | |
| 189 | |
| 190 static gboolean | |
| 191 __usr_cmd(MsnServConn *servconn, const char *command, const char **params, | |
| 192 size_t param_count) | |
| 193 { | |
| 194 struct gaim_connection *gc = servconn->session->account->gc; | |
| 195 char outparams[MSN_BUF_LEN]; | |
| 196 | |
| 197 /* We're either getting the challenge or the OK. Let's find out. */ | |
| 198 if (!g_ascii_strcasecmp(params[1], "OK")) { | |
| 199 /* OK */ | |
| 200 | |
| 201 if (!msn_servconn_send_command(servconn, "SYN", "0")) { | |
| 202 hide_login_progress(gc, _("Unable to write")); | |
| 203 signoff(gc); | |
| 204 | |
| 205 return FALSE; | |
| 206 } | |
| 207 } | |
| 208 else { | |
| 209 /* Challenge */ | |
| 210 const char *challenge = params[3]; | |
| 211 char buf[MSN_BUF_LEN]; | |
| 212 md5_state_t st; | |
| 213 md5_byte_t di[16]; | |
| 214 int i; | |
| 215 | |
| 216 g_snprintf(buf, sizeof(buf), "%s%s", challenge, gc->password); | |
| 217 | |
| 218 md5_init(&st); | |
| 219 md5_append(&st, (const md5_byte_t *)buf, strlen(buf)); | |
| 220 md5_finish(&st, di); | |
| 221 | |
| 222 g_snprintf(outparams, sizeof(outparams), "MD5 S "); | |
| 223 | |
| 224 for (i = 0; i < 16; i++) { | |
| 225 g_snprintf(buf, sizeof(buf), "%02x", di[i]); | |
| 226 strcat(outparams, buf); | |
| 227 } | |
| 228 | |
| 229 if (!msn_servconn_send_command(servconn, "USR", outparams)) { | |
| 230 hide_login_progress(gc, _("Unable to send password")); | |
| 231 signoff(gc); | |
| 232 | |
| 233 return FALSE; | |
| 234 } | |
| 235 | |
| 236 set_login_progress(gc, 4, _("Password sent")); | |
| 237 } | |
| 238 | |
| 239 return TRUE; | |
| 240 } | |
| 241 | |
| 242 /************************************************************************** | |
| 243 * Log out | |
| 244 **************************************************************************/ | |
| 245 static gboolean | |
| 246 __out_cmd(MsnServConn *servconn, const char *command, const char **params, | |
| 247 size_t param_count) | |
| 248 { | |
| 249 struct gaim_connection *gc = servconn->session->account->gc; | |
| 250 | |
| 251 if (!g_ascii_strcasecmp(params[0], "OTH")) { | |
| 252 hide_login_progress(gc, | |
| 253 _("You have been disconnected. You have " | |
| 254 "signed on from another location.")); | |
| 255 signoff(gc); | |
| 256 } | |
| 257 else if (!g_ascii_strcasecmp(params[0], "SSD")) { | |
| 258 hide_login_progress(gc, | |
| 259 _("You have been disconnected. The MSN servers " | |
| 260 "are going down temporarily.")); | |
| 261 signoff(gc); | |
| 262 } | |
| 263 | |
| 264 return FALSE; | |
| 265 } | |
| 266 | |
| 267 /************************************************************************** | |
| 268 * Messages | |
| 269 **************************************************************************/ | |
| 270 static gboolean | |
| 271 __msg_cmd(MsnServConn *servconn, const char *command, const char **params, | |
| 272 size_t param_count) | |
| 273 { | |
| 274 gaim_debug(GAIM_DEBUG_INFO, "msn", "Found message. Parsing.\n"); | |
| 275 | |
| 276 servconn->parsing_msg = TRUE; | |
| 277 servconn->msg_passport = g_strdup(params[0]); | |
| 278 servconn->msg_friendly = g_strdup(params[1]); | |
| 279 servconn->msg_len = atoi(params[2]); | |
| 280 | |
| 281 return TRUE; | |
| 282 } | |
| 283 | |
| 284 /************************************************************************** | |
| 285 * Challenges | |
| 286 **************************************************************************/ | |
| 287 static gboolean | |
| 288 __chl_cmd(MsnServConn *servconn, const char *command, const char **params, | |
| 289 size_t param_count) | |
| 290 { | |
| 291 struct gaim_connection *gc = servconn->session->account->gc; | |
| 292 char buf[MSN_BUF_LEN]; | |
| 293 char buf2[3]; | |
| 294 md5_state_t st; | |
| 295 md5_byte_t di[16]; | |
| 296 int i; | |
| 297 | |
| 298 md5_init(&st); | |
| 299 md5_append(&st, (const md5_byte_t *)params[1], strlen(params[1])); | |
| 300 md5_append(&st, (const md5_byte_t *)"Q1P7W2E4J9R8U3S5", | |
| 301 strlen("Q1P7W2E4J9R8U3S5")); | |
| 302 md5_finish(&st, di); | |
| 303 | |
| 304 g_snprintf(buf, sizeof(buf), | |
| 305 "QRY %u msmsgs@msnmsgr.com 32\r\n", | |
| 306 servconn->session->trId++); | |
| 307 | |
| 308 for (i = 0; i < 16; i++) { | |
| 309 g_snprintf(buf2, sizeof(buf2), "%02x", di[i]); | |
| 310 strcat(buf, buf2); | |
| 311 } | |
| 312 | |
| 313 if (msn_servconn_write(servconn, buf, strlen(buf)) <= 0) { | |
| 314 hide_login_progress(gc, _("Unable to write to server")); | |
| 315 signoff(gc); | |
| 316 } | |
| 317 | |
| 318 return TRUE; | |
| 319 } | |
| 320 | |
| 321 /************************************************************************** | |
| 322 * Buddy Lists | |
| 323 **************************************************************************/ | |
| 324 static gboolean | |
| 325 __add_cmd(MsnServConn *servconn, const char *command, const char **params, | |
| 326 size_t param_count) | |
| 327 { | |
| 328 MsnSession *session = servconn->session; | |
| 329 struct gaim_connection *gc = session->account->gc; | |
| 330 MsnPermitAdd *pa; | |
| 331 GSList *sl; | |
| 332 const char *list, *passport; | |
| 333 char *friend; | |
| 334 char msg[MSN_BUF_LEN]; | |
| 335 | |
| 336 list = params[1]; | |
| 337 passport = params[3]; | |
| 338 | |
| 339 friend = msn_url_decode(params[4]); | |
| 340 | |
| 341 if (g_ascii_strcasecmp(list, "RL")) | |
| 342 return TRUE; | |
| 343 | |
| 344 for (sl = gc->account->permit; sl != NULL; sl = sl->next) { | |
| 345 if (!gaim_utf8_strcasecmp(sl->data, passport)) | |
| 346 return TRUE; | |
| 347 } | |
| 348 | |
| 349 pa = g_new0(MsnPermitAdd, 1); | |
| 350 pa->user = msn_user_new(session, passport, friend); | |
| 351 pa->gc = gc; | |
| 352 | |
| 353 g_snprintf(msg, sizeof(msg), | |
| 354 _("The user %s (%s) wants to add %s to his or her buddy list."), | |
| 355 passport, friend, gc->username); | |
| 356 | |
| 357 do_ask_dialog(msg, NULL, pa, | |
| 358 _("Authorize"), msn_accept_add_cb, | |
| 359 _("Deny"), msn_cancel_add_cb, | |
| 360 session->prpl->handle, FALSE); | |
| 361 | |
| 362 return TRUE; | |
| 363 } | |
| 364 | |
| 365 static gboolean | |
| 366 __blp_cmd(MsnServConn *servconn, const char *command, const char **params, | |
| 367 size_t param_count) | |
| 368 { | |
| 369 struct gaim_connection *gc = servconn->session->account->gc; | |
| 370 | |
| 371 if (!g_ascii_strcasecmp(params[2], "AL")) { | |
| 372 /* | |
| 373 * If the current setting is AL, messages from users who | |
| 374 * are not in BL will be delivered. | |
| 375 * | |
| 376 * In other words, deny some. | |
| 377 */ | |
| 378 gc->account->permdeny = DENY_SOME; | |
| 379 } | |
| 380 else { | |
| 381 /* If the current setting is BL, only messages from people | |
| 382 * who are in the AL will be delivered. | |
| 383 * | |
| 384 * In other words, permit some. | |
| 385 */ | |
| 386 gc->account->permdeny = PERMIT_SOME; | |
| 387 } | |
| 388 | |
| 389 return TRUE; | |
| 390 } | |
| 391 | |
| 392 static gboolean | |
| 393 __fln_cmd(MsnServConn *servconn, const char *command, const char **params, | |
| 394 size_t param_count) | |
| 395 { | |
| 396 struct gaim_connection *gc = servconn->session->account->gc; | |
| 397 | |
| 398 serv_got_update(gc, (char *)params[0], 0, 0, 0, 0, 0); | |
| 399 | |
| 400 return TRUE; | |
| 401 } | |
| 402 | |
| 403 static gboolean | |
| 404 __iln_cmd(MsnServConn *servconn, const char *command, const char **params, | |
| 405 size_t param_count) | |
| 406 { | |
| 407 struct gaim_connection *gc = servconn->session->account->gc; | |
| 408 int status = 0; | |
| 409 const char *state, *passport, *friend; | |
| 410 | |
| 411 state = params[1]; | |
| 412 passport = params[2]; | |
| 413 friend = msn_url_decode(params[3]); | |
| 414 | |
| 415 serv_got_alias(gc, (char *)passport, (char *)friend); | |
| 416 | |
| 417 if (!g_ascii_strcasecmp(state, "BSY")) | |
| 418 status |= UC_UNAVAILABLE | (MSN_BUSY << 1); | |
| 419 else if (!g_ascii_strcasecmp(state, "IDL")) | |
| 420 status |= UC_UNAVAILABLE | (MSN_IDLE << 1); | |
| 421 else if (!g_ascii_strcasecmp(state, "BRB")) | |
| 422 status |= UC_UNAVAILABLE | (MSN_BRB << 1); | |
| 423 else if (!g_ascii_strcasecmp(state, "AWY")) | |
| 424 status |= UC_UNAVAILABLE | (MSN_AWAY << 1); | |
| 425 else if (!g_ascii_strcasecmp(state, "PHN")) | |
| 426 status |= UC_UNAVAILABLE | (MSN_PHONE << 1); | |
| 427 else if (!g_ascii_strcasecmp(state, "LUN")) | |
| 428 status |= UC_UNAVAILABLE | (MSN_LUNCH << 1); | |
| 429 | |
| 430 serv_got_update(gc, (char *)passport, 1, 0, 0, 0, status); | |
| 431 | |
| 432 return TRUE; | |
| 433 } | |
| 434 | |
| 435 static gboolean | |
| 436 __lsg_cmd(MsnServConn *servconn, const char *command, const char **params, | |
| 437 size_t param_count) | |
| 438 { | |
| 439 MsnSession *session = servconn->session; | |
| 440 struct group *g; | |
| 441 const char *name; | |
| 442 int group_num, num_groups, group_id; | |
| 443 | |
| 444 group_num = atoi(params[2]); | |
| 445 num_groups = atoi(params[3]); | |
| 446 group_id = atoi(params[4]); | |
| 447 name = msn_url_decode(params[5]); | |
| 448 | |
| 449 if (group_num == 1) { | |
| 450 session->groups = g_hash_table_new_full(g_int_hash, g_int_equal, | |
| 451 NULL, g_free); | |
| 452 } | |
| 453 | |
| 454 g_hash_table_insert(session->groups, GINT_TO_POINTER(group_id), | |
| 455 g_strdup(name)); | |
| 456 | |
| 457 if ((g = gaim_find_group(name)) == NULL) { | |
| 458 g = gaim_group_new(name); | |
| 459 gaim_blist_add_group(g, NULL); | |
| 460 } | |
| 461 | |
| 462 return TRUE; | |
| 463 } | |
| 464 | |
| 465 static gboolean | |
| 466 __lst_cmd(MsnServConn *servconn, const char *command, const char **params, | |
| 467 size_t param_count) | |
| 468 { | |
| 469 MsnSession *session = servconn->session; | |
| 470 struct gaim_connection *gc = session->account->gc; | |
| 471 int user_num; | |
| 472 int num_users; | |
| 473 const char *type; | |
| 474 const char *passport; | |
| 475 const char *friend; | |
| 476 | |
| 477 user_num = atoi(params[3]); | |
| 478 num_users = atoi(params[4]); | |
| 479 | |
| 480 if (user_num == 0 && num_users == 0) | |
| 481 return TRUE; /* There are no users on this list. */ | |
| 482 | |
| 483 type = params[1]; | |
| 484 passport = params[5]; | |
| 485 friend = msn_url_decode(params[6]); | |
| 486 | |
| 487 if (!g_ascii_strcasecmp(type, "FL") && user_num != 0) { | |
| 488 /* These are users on our contact list. */ | |
| 489 MsnUser *user; | |
| 490 | |
| 491 user = msn_user_new(session, passport, friend); | |
| 492 | |
| 493 if (param_count == 8) | |
| 494 msn_user_set_group_id(user, atoi(params[7])); | |
| 495 | |
| 496 session->lists.forward = g_slist_append(session->lists.forward, user); | |
| 497 } | |
| 498 else if (!g_ascii_strcasecmp(type, "AL") && user_num != 0) { | |
| 499 /* These are users who are allowed to see our status. */ | |
| 500 if (g_slist_find_custom(gc->account->deny, passport, | |
| 501 (GCompareFunc)strcmp)) { | |
| 502 | |
| 503 gaim_debug(GAIM_DEBUG_INFO, "msn", | |
| 504 "Moving user from deny list to permit: %s (%s)\n", | |
| 505 passport, friend); | |
| 506 | |
| 507 gaim_privacy_deny_remove(gc->account, passport); | |
| 508 } | |
| 509 | |
| 510 gaim_privacy_permit_add(gc->account, passport); | |
| 511 } | |
| 512 else if (!g_ascii_strcasecmp(type, "BL") && user_num != 0) { | |
| 513 /* These are users who are not allowed to see our status. */ | |
| 514 gaim_privacy_deny_add(gc->account, passport); | |
| 515 } | |
| 516 else if (!g_ascii_strcasecmp(type, "RL")) { | |
| 517 /* These are users who have us on their contact list. */ | |
| 518 if (user_num > 0) { | |
| 519 gboolean new_entry = TRUE; | |
| 520 | |
| 521 if (g_slist_find_custom(gc->account->permit, passport, | |
| 522 (GCompareFunc)g_ascii_strcasecmp)) { | |
| 523 new_entry = FALSE; | |
| 524 } | |
| 525 | |
| 526 if (g_slist_find_custom(gc->account->deny, passport, | |
| 527 (GCompareFunc)g_ascii_strcasecmp)) { | |
| 528 new_entry = FALSE; | |
| 529 } | |
| 530 | |
| 531 if (new_entry) { | |
| 532 MsnPermitAdd *pa; | |
| 533 char msg[MSN_BUF_LEN]; | |
| 534 | |
| 535 gaim_debug(GAIM_DEBUG_WARNING, "msn", | |
| 536 "Unresolved MSN RL entry: %s\n", passport); | |
| 537 | |
| 538 pa = g_new0(MsnPermitAdd, 1); | |
| 539 pa->user = msn_user_new(session, passport, friend); | |
| 540 pa->gc = gc; | |
| 541 | |
| 542 g_snprintf(msg, sizeof(msg), | |
| 543 _("The user %s (%s) wants to add you to their " | |
| 544 "buddy list."), | |
| 545 msn_user_get_passport(pa->user), | |
| 546 msn_user_get_name(pa->user)); | |
| 547 | |
| 548 do_ask_dialog(msg, NULL, pa, | |
| 549 _("Authorize"), msn_accept_add_cb, | |
| 550 _("Deny"), msn_cancel_add_cb, | |
| 551 session->prpl->handle, FALSE); | |
| 552 } | |
| 553 } | |
| 554 | |
| 555 if (user_num != num_users) | |
| 556 return TRUE; /* This isn't the last one in the RL. */ | |
| 557 | |
| 558 if (!msn_servconn_send_command(servconn, "CHG", "NLN")) { | |
| 559 hide_login_progress(gc, _("Unable to write")); | |
| 560 signoff(gc); | |
| 561 | |
| 562 return FALSE; | |
| 563 } | |
| 564 | |
| 565 account_online(gc); | |
| 566 serv_finish_login(gc); | |
| 567 | |
| 568 session->lists.allow = g_slist_copy(gc->account->permit); | |
| 569 session->lists.block = g_slist_copy(gc->account->deny); | |
| 570 | |
| 571 while (session->lists.forward != NULL) { | |
| 572 MsnUser *user = session->lists.forward->data; | |
| 573 struct buddy *b; | |
| 574 | |
| 575 b = gaim_find_buddy(gc->account, msn_user_get_passport(user)); | |
| 576 | |
| 577 session->lists.forward = g_slist_remove(session->lists.forward, | |
| 578 user); | |
| 579 | |
| 580 if (b == NULL) { | |
| 581 struct group *g = NULL; | |
| 582 const char *group_name = NULL; | |
| 583 int group_id; | |
| 584 | |
| 585 group_id = msn_user_get_group_id(user); | |
| 586 | |
| 587 if (group_id > -1) { | |
| 588 group_name = g_hash_table_lookup(session->groups, | |
| 589 GINT_TO_POINTER(group_id)); | |
| 590 } | |
| 591 | |
| 592 if (group_name == NULL) { | |
| 593 gaim_debug(GAIM_DEBUG_WARNING, "msn", | |
| 594 "Group ID %d for user %s was not defined.\n", | |
| 595 group_id, passport); | |
| 596 } | |
| 597 else if ((g = gaim_find_group(group_name)) == NULL) { | |
| 598 gaim_debug(GAIM_DEBUG_ERROR, "msn", | |
| 599 "Group '%s' appears in server-side " | |
| 600 "buddy list, but not here!", | |
| 601 group_name); | |
| 602 } | |
| 603 | |
| 604 if (g == NULL) { | |
| 605 if ((g = gaim_find_group(_("Buddies"))) == NULL) { | |
| 606 g = gaim_group_new(_("Buddies")); | |
| 607 gaim_blist_add_group(g, NULL); | |
| 608 } | |
| 609 } | |
| 610 | |
| 611 b = gaim_buddy_new(gc->account, | |
| 612 msn_user_get_passport(user), NULL); | |
| 613 | |
| 614 gaim_blist_add_buddy(b, g, NULL); | |
| 615 } | |
| 616 | |
| 617 serv_got_alias(gc, (char *)msn_user_get_passport(user), | |
| 618 (char *)msn_user_get_name(user)); | |
| 619 | |
| 620 msn_user_destroy(user); | |
| 621 } | |
| 622 } | |
| 623 | |
| 624 return TRUE; | |
| 625 } | |
| 626 | |
| 627 static gboolean | |
| 628 __nln_cmd(MsnServConn *servconn, const char *command, const char **params, | |
| 629 size_t param_count) | |
| 630 { | |
| 631 MsnSession *session = servconn->session; | |
| 632 struct gaim_connection *gc = session->account->gc; | |
| 633 const char *state; | |
| 634 const char *passport; | |
| 635 const char *friend; | |
| 636 int status = 0; | |
| 637 | |
| 638 state = params[0]; | |
| 639 passport = params[1]; | |
| 640 friend = msn_url_decode(params[2]); | |
| 641 | |
| 642 serv_got_alias(gc, (char *)passport, (char *)friend); | |
| 643 | |
| 644 if (!g_ascii_strcasecmp(state, "BSY")) | |
| 645 status |= UC_UNAVAILABLE | (MSN_BUSY << 1); | |
| 646 else if (!g_ascii_strcasecmp(state, "IDL")) | |
| 647 status |= UC_UNAVAILABLE | (MSN_IDLE << 1); | |
| 648 else if (!g_ascii_strcasecmp(state, "BRB")) | |
| 649 status |= UC_UNAVAILABLE | (MSN_BRB << 1); | |
| 650 else if (!g_ascii_strcasecmp(state, "AWY")) | |
| 651 status |= UC_UNAVAILABLE | (MSN_AWAY << 1); | |
| 652 else if (!g_ascii_strcasecmp(state, "PHN")) | |
| 653 status |= UC_UNAVAILABLE | (MSN_PHONE << 1); | |
| 654 else if (!g_ascii_strcasecmp(state, "LUN")) | |
| 655 status |= UC_UNAVAILABLE | (MSN_LUNCH << 1); | |
| 656 | |
| 657 serv_got_update(gc, (char *)passport, 1, 0, 0, 0, status); | |
| 658 | |
| 659 return TRUE; | |
| 660 } | |
| 661 | |
| 662 static gboolean | |
| 663 __rea_cmd(MsnServConn *servconn, const char *command, const char **params, | |
| 664 size_t param_count) | |
| 665 { | |
| 666 MsnSession *session = servconn->session; | |
| 667 struct gaim_connection *gc = session->account->gc; | |
| 668 char *friend; | |
| 669 | |
| 670 friend = msn_url_decode(params[2]); | |
| 671 | |
| 672 g_snprintf(gc->displayname, sizeof(gc->displayname), "%s", friend); | |
| 673 | |
| 674 return TRUE; | |
| 675 } | |
| 676 | |
| 677 /************************************************************************** | |
| 678 * Misc commands | |
| 679 **************************************************************************/ | |
| 680 static gboolean | |
| 681 __url_cmd(MsnServConn *servconn, const char *command, const char **params, | |
| 682 size_t param_count) | |
| 683 { | |
| 684 MsnSession *session = servconn->session; | |
| 685 struct gaim_connection *gc = session->account->gc; | |
| 686 const char *rru; | |
| 687 const char *url; | |
| 688 md5_state_t st; | |
| 689 md5_byte_t di[16]; | |
| 690 FILE *fd; | |
| 691 char buf[2048]; | |
| 692 char buf2[3]; | |
| 693 char sendbuf[64]; | |
| 694 int i; | |
| 695 | |
| 696 rru = params[1]; | |
| 697 url = params[2]; | |
| 698 | |
| 699 g_snprintf(buf, sizeof(buf), "%s%lu%s", | |
| 700 session->passport_info.mspauth, | |
| 701 time(NULL) - session->passport_info.sl, gc->password); | |
| 702 | |
| 703 md5_init(&st); | |
| 704 md5_append(&st, (const md5_byte_t *)buf, strlen(buf)); | |
| 705 md5_finish(&st, di); | |
| 706 | |
| 707 memset(sendbuf, 0, sizeof(sendbuf)); | |
| 708 | |
| 709 for (i = 0; i < 16; i++) { | |
| 710 g_snprintf(buf2, sizeof(buf2), "%02x", di[i]); | |
| 711 strcat(sendbuf, buf2); | |
| 712 } | |
| 713 | |
| 714 if (session->passport_info.file != NULL) { | |
| 715 unlink(session->passport_info.file); | |
| 716 g_free(session->passport_info.file); | |
| 717 } | |
| 718 | |
| 719 if ((fd = gaim_mkstemp(&session->passport_info.file)) == NULL) { | |
| 720 gaim_debug(GAIM_DEBUG_ERROR, "msn", | |
| 721 "Error opening temp passport file: %s\n", | |
| 722 strerror(errno)); | |
| 723 } | |
| 724 else { | |
| 725 fputs("<html>\n" | |
| 726 "<head>\n" | |
| 727 "<noscript>\n" | |
| 728 "<meta http-equiv=\"Refresh\" content=\"0; " | |
| 729 "url=http://www.hotmail.com\">\n" | |
| 730 "</noscript>\n" | |
| 731 "</head>\n\n", | |
| 732 fd); | |
| 733 | |
| 734 fprintf(fd, "<body onload=\"document.pform.submit(); \">\n"); | |
| 735 fprintf(fd, "<form name=\"pform\" action=\"%s\" method=\"POST\">\n\n", | |
| 736 url); | |
| 737 fprintf(fd, "<input type=\"hidden\" name=\"mode\" value=\"ttl\">\n"); | |
| 738 fprintf(fd, "<input type=\"hidden\" name=\"login\" value=\"%s\">\n", | |
| 739 gc->username); | |
| 740 fprintf(fd, "<input type=\"hidden\" name=\"username\" value=\"%s\">\n", | |
| 741 gc->username); | |
| 742 fprintf(fd, "<input type=\"hidden\" name=\"sid\" value=\"%s\">\n", | |
| 743 session->passport_info.sid); | |
| 744 fprintf(fd, "<input type=\"hidden\" name=\"kv\" value=\"%s\">\n", | |
| 745 session->passport_info.kv); | |
| 746 fprintf(fd, "<input type=\"hidden\" name=\"id\" value=\"2\">\n"); | |
| 747 fprintf(fd, "<input type=\"hidden\" name=\"sl\" value=\"%ld\">\n", | |
| 748 time(NULL) - session->passport_info.sl); | |
| 749 fprintf(fd, "<input type=\"hidden\" name=\"rru\" value=\"%s\">\n", | |
| 750 rru); | |
| 751 fprintf(fd, "<input type=\"hidden\" name=\"auth\" value=\"%s\">\n", | |
| 752 session->passport_info.mspauth); | |
| 753 fprintf(fd, "<input type=\"hidden\" name=\"creds\" value=\"%s\">\n", | |
| 754 sendbuf); /* TODO Digest me (huh? -- ChipX86) */ | |
| 755 fprintf(fd, "<input type=\"hidden\" name=\"svc\" value=\"mail\">\n"); | |
| 756 fprintf(fd, "<input type=\"hiden\" name=\"js\" value=\"yes\">\n"); | |
| 757 fprintf(fd, "</form></body>\n"); | |
| 758 fprintf(fd, "</html>\n"); | |
| 759 | |
| 760 if (fclose(fd)) { | |
| 761 gaim_debug(GAIM_DEBUG_ERROR, "msn", | |
| 762 "Error closing temp passport file: %s\n", | |
| 763 strerror(errno)); | |
| 764 | |
| 765 unlink(session->passport_info.file); | |
| 766 g_free(session->passport_info.file); | |
| 767 } | |
| 768 else { | |
| 769 /* | |
| 770 * Renaming file with .html extension, so that the | |
| 771 * win32 open_url will work. | |
| 772 */ | |
| 773 char *tmp; | |
| 774 | |
| 775 if ((tmp = g_strdup_printf("%s.html", | |
| 776 session->passport_info.file)) != NULL) { | |
| 777 | |
| 778 if (rename(session->passport_info.file, tmp) == 0) { | |
| 779 g_free(session->passport_info.file); | |
| 780 session->passport_info.file = tmp; | |
| 781 } | |
| 782 else | |
| 783 g_free(tmp); | |
| 784 } | |
| 785 } | |
| 786 } | |
| 787 | |
| 788 return TRUE; | |
| 789 } | |
| 790 /************************************************************************** | |
| 791 * Switchboards | |
| 792 **************************************************************************/ | |
| 793 static gboolean | |
| 794 __rng_cmd(MsnServConn *servconn, const char *command, const char **params, | |
| 795 size_t param_count) | |
| 796 { | |
| 797 MsnSession *session = servconn->session; | |
| 798 MsnSwitchBoard *swboard; | |
| 799 MsnUser *user; | |
| 800 const char *session_id; | |
| 801 char *host, *c; | |
| 802 int port; | |
| 803 | |
| 804 session_id = params[0]; | |
| 805 | |
| 806 host = g_strdup(params[1]); | |
| 807 | |
| 808 if ((c = strchr(host, ':')) != NULL) { | |
| 809 *c = '\0'; | |
| 810 port = atoi(c + 1); | |
| 811 } | |
| 812 else | |
| 813 port = 1863; | |
| 814 | |
| 815 swboard = msn_switchboard_new(session); | |
| 816 | |
| 817 user = msn_user_new(session, params[4], NULL); | |
| 818 | |
| 819 msn_switchboard_set_invited(swboard, TRUE); | |
| 820 msn_switchboard_set_session_id(swboard, params[0]); | |
| 821 msn_switchboard_set_auth_key(swboard, params[3]); | |
| 822 msn_switchboard_set_user(swboard, user); | |
| 823 | |
| 824 if (!msn_switchboard_connect(swboard, host, port)) { | |
| 825 gaim_debug(GAIM_DEBUG_ERROR, "msn", | |
| 826 "Unable to connect to switchboard on %s, port %d\n", | |
| 827 host, port); | |
| 828 | |
| 829 g_free(host); | |
| 830 | |
| 831 return FALSE; | |
| 832 } | |
| 833 | |
| 834 g_free(host); | |
| 835 | |
| 836 return TRUE; | |
| 837 } | |
| 838 | |
| 839 static gboolean | |
| 840 __xfr_cmd(MsnServConn *servconn, const char *command, const char **params, | |
| 841 size_t param_count) | |
| 842 { | |
| 843 MsnSession *session = servconn->session; | |
| 844 MsnSwitchBoard *swboard; | |
| 845 struct gaim_connection *gc = session->account->gc; | |
| 846 char *host; | |
| 847 char *c; | |
| 848 int port; | |
| 849 | |
| 850 if (strcmp(params[1], "SB")) { | |
| 851 hide_login_progress(gc, _("Got invalid XFR")); | |
| 852 signoff(gc); | |
| 853 | |
| 854 return FALSE; | |
| 855 } | |
| 856 | |
| 857 host = g_strdup(params[2]); | |
| 858 | |
| 859 if ((c = strchr(host, ':')) != NULL) { | |
| 860 *c = '\0'; | |
| 861 port = atoi(c + 1); | |
| 862 } | |
| 863 else | |
| 864 port = 1863; | |
| 865 | |
| 866 swboard = msn_session_find_unused_switch(session); | |
| 867 | |
| 868 if (swboard == NULL) { | |
| 869 gaim_debug(GAIM_DEBUG_ERROR, "msn", | |
| 870 "Received an XFR SB request when there's no unused " | |
| 871 "switchboards!\n"); | |
| 872 } | |
| 873 | |
| 874 msn_switchboard_set_auth_key(swboard, params[4]); | |
| 875 | |
| 876 if (!msn_switchboard_connect(swboard, host, port)) { | |
| 877 gaim_debug(GAIM_DEBUG_ERROR, "msn", | |
| 878 "Unable to connect to switchboard on %s, port %d\n", | |
| 879 host, port); | |
| 880 | |
| 881 g_free(host); | |
| 882 | |
| 883 return FALSE; | |
| 884 } | |
| 885 | |
| 886 g_free(host); | |
| 887 | |
| 888 return TRUE; | |
| 889 } | |
| 890 | |
| 891 /************************************************************************** | |
| 892 * Message Types | |
| 893 **************************************************************************/ | |
| 894 static gboolean | |
| 895 __profile_msg(MsnServConn *servconn, const MsnMessage *msg) | |
| 896 { | |
| 897 MsnSession *session = servconn->session; | |
| 898 const char *value; | |
| 899 | |
| 900 if ((value = msn_message_get_attr(msg, "kv")) != NULL) | |
| 901 session->passport_info.kv = g_strdup(value); | |
| 902 | |
| 903 if ((value = msn_message_get_attr(msg, "sid")) != NULL) | |
| 904 session->passport_info.sid = g_strdup(value); | |
| 905 | |
| 906 if ((value = msn_message_get_attr(msg, "MSPAuth")) != NULL) | |
| 907 session->passport_info.mspauth = g_strdup(value); | |
| 908 | |
| 909 return TRUE; | |
| 910 } | |
| 911 | |
| 912 static gboolean | |
| 913 __initial_email_msg(MsnServConn *servconn, const MsnMessage *msg) | |
| 914 { | |
| 915 MsnSession *session = servconn->session; | |
| 916 struct gaim_connection *gc = session->account->gc; | |
| 917 GHashTable *table; | |
| 918 const char *unread; | |
| 919 | |
| 920 table = msn_message_get_hashtable_from_body(msg); | |
| 921 | |
| 922 unread = g_hash_table_lookup(table, "Inbox-Unread"); | |
| 923 | |
| 924 if (unread != NULL) | |
| 925 connection_has_mail(gc, atoi(unread), NULL, NULL, | |
| 926 session->passport_info.file); | |
| 927 | |
| 928 g_hash_table_destroy(table); | |
| 929 | |
| 930 return TRUE; | |
| 931 } | |
| 932 | |
| 933 static gboolean | |
| 934 __email_msg(MsnServConn *servconn, const MsnMessage *msg) | |
| 935 { | |
| 936 MsnSession *session = servconn->session; | |
| 937 struct gaim_connection *gc = session->account->gc; | |
| 938 GHashTable *table; | |
| 939 const char *from, *subject; | |
| 940 | |
| 941 table = msn_message_get_hashtable_from_body(msg); | |
| 942 | |
| 943 from = g_hash_table_lookup(table, "From"); | |
| 944 subject = g_hash_table_lookup(table, "Subject"); | |
| 945 | |
| 946 if (from == NULL || subject == NULL) { | |
| 947 connection_has_mail(gc, 1, NULL, NULL, session->passport_info.file); | |
| 948 } | |
| 949 else { | |
| 950 connection_has_mail(gc, -1, from, subject, | |
| 951 session->passport_info.file); | |
| 952 } | |
| 953 | |
| 954 g_hash_table_destroy(table); | |
| 955 | |
| 956 return TRUE; | |
| 957 } | |
| 958 | |
| 959 static gboolean | |
| 960 __connect_cb(gpointer data, gint source, GaimInputCondition cond) | |
| 961 { | |
| 962 MsnServConn *notification = data; | |
| 963 MsnSession *session = notification->session; | |
| 964 struct gaim_connection *gc = session->account->gc; | |
| 965 | |
| 966 if (source == -1) { | |
| 967 hide_login_progress(session->account->gc, _("Unable to connect")); | |
| 968 signoff(session->account->gc); | |
| 969 return FALSE; | |
| 970 } | |
| 971 | |
| 972 if (notification->fd != source) | |
| 973 notification->fd = source; | |
| 974 | |
| 975 if (!msn_servconn_send_command(notification, "VER", | |
| 976 "MSNP6 MSNP5 MSNP4 CVR0")) { | |
| 977 hide_login_progress(gc, _("Unable to write to server")); | |
| 978 signoff(gc); | |
| 979 return FALSE; | |
| 980 } | |
| 981 | |
| 982 set_login_progress(session->account->gc, 2, _("Syncing with server")); | |
| 983 | |
| 984 return TRUE; | |
| 985 } | |
| 986 | |
| 987 static void | |
| 988 __failed_read_cb(gpointer data, gint source, GaimInputCondition cond) | |
| 989 { | |
| 990 MsnServConn *notification = data; | |
| 991 struct gaim_connection *gc; | |
| 992 | |
| 993 gc = notification->session->account->gc; | |
| 994 | |
| 995 hide_login_progress(gc, _("Error reading from server")); | |
| 996 signoff(gc); | |
| 997 } | |
| 998 | |
| 999 MsnServConn * | |
| 1000 msn_notification_new(MsnSession *session, const char *server, int port) | |
| 1001 { | |
| 1002 MsnServConn *notification; | |
| 1003 | |
| 1004 notification = msn_servconn_new(session); | |
| 1005 | |
| 1006 msn_servconn_set_server(notification, server, port); | |
| 1007 msn_servconn_set_connect_cb(notification, __connect_cb); | |
| 1008 msn_servconn_set_failed_read_cb(notification, __failed_read_cb); | |
| 1009 | |
| 1010 if (notification_commands == NULL) { | |
| 1011 /* Register the command callbacks. */ | |
| 1012 msn_servconn_register_command(notification, "ADD", __add_cmd); | |
| 1013 msn_servconn_register_command(notification, "BLP", __blp_cmd); | |
| 1014 msn_servconn_register_command(notification, "BPR", __blank_cmd); | |
| 1015 msn_servconn_register_command(notification, "CHG", __blank_cmd); | |
| 1016 msn_servconn_register_command(notification, "CHL", __chl_cmd); | |
| 1017 msn_servconn_register_command(notification, "FLN", __fln_cmd); | |
| 1018 msn_servconn_register_command(notification, "GTC", __blank_cmd); | |
| 1019 msn_servconn_register_command(notification, "ILN", __iln_cmd); | |
| 1020 msn_servconn_register_command(notification, "INF", __inf_cmd); | |
| 1021 msn_servconn_register_command(notification, "LSG", __lsg_cmd); | |
| 1022 msn_servconn_register_command(notification, "LST", __lst_cmd); | |
| 1023 msn_servconn_register_command(notification, "MSG", __msg_cmd); | |
| 1024 msn_servconn_register_command(notification, "NLN", __nln_cmd); | |
| 1025 msn_servconn_register_command(notification, "OUT", __out_cmd); | |
| 1026 msn_servconn_register_command(notification, "PRP", __blank_cmd); | |
| 1027 msn_servconn_register_command(notification, "QNG", __blank_cmd); | |
| 1028 msn_servconn_register_command(notification, "QRY", __blank_cmd); | |
| 1029 msn_servconn_register_command(notification, "REA", __rea_cmd); | |
| 1030 msn_servconn_register_command(notification, "REM", __blank_cmd); | |
| 1031 msn_servconn_register_command(notification, "RNG", __rng_cmd); | |
| 1032 msn_servconn_register_command(notification, "SYN", __blank_cmd); | |
| 1033 msn_servconn_register_command(notification, "URL", __url_cmd); | |
| 1034 msn_servconn_register_command(notification, "USR", __usr_cmd); | |
| 1035 msn_servconn_register_command(notification, "VER", __ver_cmd); | |
| 1036 msn_servconn_register_command(notification, "XFR", __xfr_cmd); | |
| 1037 msn_servconn_register_command(notification, "_unknown_", __unknown_cmd); | |
| 1038 | |
| 1039 /* Register the message type callbacks. */ | |
| 1040 msn_servconn_register_msg_type(notification, "text/x-msmsgsprofile", | |
| 1041 __profile_msg); | |
| 1042 msn_servconn_register_msg_type(notification, | |
| 1043 "text/x-msmsgsinitialemailnotification", | |
| 1044 __initial_email_msg); | |
| 1045 msn_servconn_register_msg_type(notification, | |
| 1046 "text/x-msmsgsemailnotification", | |
| 1047 __email_msg); | |
| 1048 | |
| 1049 /* Save these for future use. */ | |
| 1050 notification_commands = notification->commands; | |
| 1051 notification_msg_types = notification->msg_types; | |
| 1052 } | |
| 1053 else { | |
| 1054 g_hash_table_destroy(notification->commands); | |
| 1055 g_hash_table_destroy(notification->msg_types); | |
| 1056 | |
| 1057 notification->commands = notification_commands; | |
| 1058 notification->msg_types = notification_msg_types; | |
| 1059 } | |
| 1060 | |
| 1061 return notification; | |
| 1062 } |
