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