comparison src/protocols/msn/switchboard.c @ 9158:c30d81b4dd22

[gaim-migrate @ 9942] Patch from Felipe Contreras to sync our MSN prpl with what's in his tree. He says this may fix a couple bugs, but the important thing is the restructuring of how MsnMessages work. Lots of style changes and other stuff as well. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Tue, 01 Jun 2004 06:42:20 +0000
parents 2185ced3b087
children 502707ca1836
comparison
equal deleted inserted replaced
9157:bd1ea0a717d7 9158:c30d81b4dd22
35 { 35 {
36 MsnMessage *msg; 36 MsnMessage *msg;
37 37
38 msg = msn_message_new(); 38 msg = msn_message_new();
39 msn_message_set_content_type(msg, "text/x-clientcaps"); 39 msn_message_set_content_type(msg, "text/x-clientcaps");
40 msn_message_set_charset(msg, NULL); 40 msn_message_set_flag(msg, 'U');
41 msn_message_set_attr(msg, "User-Agent", NULL); 41 msn_message_set_bin_data(msg, MSN_CLIENTINFO, strlen(MSN_CLIENTINFO));
42 msn_message_set_body(msg, MSN_CLIENTINFO);
43 42
44 msn_switchboard_send_msg(swboard, msg); 43 msn_switchboard_send_msg(swboard, msg);
45 44
46 msn_message_destroy(msg); 45 msn_message_destroy(msg);
47 } 46 }
96 95
97 if (swboard->hidden) 96 if (swboard->hidden)
98 return; 97 return;
99 98
100 if (swboard->chat != NULL) 99 if (swboard->chat != NULL)
100 {
101 gaim_conv_chat_remove_user(GAIM_CONV_CHAT(swboard->chat), user, NULL); 101 gaim_conv_chat_remove_user(GAIM_CONV_CHAT(swboard->chat), user, NULL);
102 }
102 else 103 else
103 { 104 {
104 const char *username; 105 const char *username;
105 GaimConversation *conv; 106 GaimConversation *conv;
106 GaimBuddy *b; 107 GaimBuddy *b;
107 char buf[MSN_BUF_LEN]; 108 char *str = NULL;
108 109
109 if ((b = gaim_find_buddy(account, user)) != NULL) 110 if ((b = gaim_find_buddy(account, user)) != NULL)
110 username = gaim_get_buddy_alias(b); 111 username = gaim_get_buddy_alias(b);
111 else 112 else
112 username = user; 113 username = user;
113 114
114 *buf = '\0';
115
116 if (cmd->param_count == 2 && atoi(cmd->params[1]) == 1) 115 if (cmd->param_count == 2 && atoi(cmd->params[1]) == 1)
117 { 116 {
118 if (gaim_prefs_get_bool("/plugins/prpl/msn/conv_timeout_notice")) 117 if (gaim_prefs_get_bool("/plugins/prpl/msn/conv_timeout_notice"))
119 { 118 {
120 g_snprintf(buf, sizeof(buf), 119 str = g_strdup_printf(_("The conversation has become "
121 _("The conversation has become inactive " 120 "inactive and timed out."));
122 "and timed out."));
123 } 121 }
124 } 122 }
125 else 123 else
126 { 124 {
127 if (gaim_prefs_get_bool("/plugins/prpl/msn/conv_close_notice")) 125 if (gaim_prefs_get_bool("/plugins/prpl/msn/conv_close_notice"))
128 { 126 {
129 g_snprintf(buf, sizeof(buf), 127 str = g_strdup_printf(_("%s has closed the conversation "
130 _("%s has closed the conversation window."), 128 "window."), username);
131 username);
132 } 129 }
133 } 130 }
134 131
135 if (*buf != '\0' && 132 if (str != NULL &&
136 (conv = gaim_find_conversation_with_account(user, account)) != NULL) 133 (conv = gaim_find_conversation_with_account(user, account)) != NULL)
137 { 134 {
138 gaim_conversation_write(conv, NULL, buf, GAIM_MESSAGE_SYSTEM, 135 gaim_conversation_write(conv, NULL, str, GAIM_MESSAGE_SYSTEM,
139 time(NULL)); 136 time(NULL));
137
138 g_free(str);
140 } 139 }
141 140
142 msn_switchboard_destroy(swboard); 141 msn_switchboard_destroy(swboard);
143 } 142 }
144 } 143 }
169 swboard->chat_id = cmdproc->session->last_chat_id; 168 swboard->chat_id = cmdproc->session->last_chat_id;
170 swboard->chat = serv_got_joined_chat(gc, swboard->chat_id, 169 swboard->chat = serv_got_joined_chat(gc, swboard->chat_id,
171 "MSN Chat"); 170 "MSN Chat");
172 171
173 gaim_conv_chat_add_user(GAIM_CONV_CHAT(swboard->chat), 172 gaim_conv_chat_add_user(GAIM_CONV_CHAT(swboard->chat),
174 gaim_account_get_username(account), NULL); 173 gaim_account_get_username(account), NULL);
175 174
176 gaim_conversation_destroy(conv); 175 gaim_conversation_destroy(conv);
177 } 176 }
178 177
179 gaim_conv_chat_add_user(GAIM_CONV_CHAT(swboard->chat), cmd->params[3], NULL); 178 gaim_conv_chat_add_user(GAIM_CONV_CHAT(swboard->chat), cmd->params[3], NULL);
241 } 240 }
242 241
243 static void 242 static void
244 msg_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd) 243 msg_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
245 { 244 {
246 gaim_debug(GAIM_DEBUG_INFO, "msn", "Found message. Parsing.\n");
247
248 cmdproc->payload_cb = msg_cmd_post; 245 cmdproc->payload_cb = msg_cmd_post;
249 cmdproc->servconn->payload_len = atoi(cmd->params[2]); 246 cmdproc->servconn->payload_len = atoi(cmd->params[2]);
250 cmdproc->temp = g_strdup(cmd->params[0]); 247 cmdproc->temp = g_strdup(cmd->params[0]);
251 } 248 }
252 249
299 static void 296 static void
300 plain_msg(MsnCmdProc *cmdproc, MsnMessage *msg) 297 plain_msg(MsnCmdProc *cmdproc, MsnMessage *msg)
301 { 298 {
302 GaimConnection *gc; 299 GaimConnection *gc;
303 MsnSwitchBoard *swboard; 300 MsnSwitchBoard *swboard;
304 char *body; 301 const char *body;
305 char *passport; 302 char *body_str;
303 char *body_enc;
304 char *body_final;
305 int body_len;
306 const char *passport;
306 const char *value; 307 const char *value;
307 308
308 gc = cmdproc->session->account->gc; 309 gc = cmdproc->session->account->gc;
309 swboard = cmdproc->servconn->data; 310 swboard = cmdproc->servconn->data;
310 body = gaim_escape_html(msn_message_get_body(msg)); 311
312 body = msn_message_get_bin_data(msg, &body_len);
313 body_str = g_strndup(body, body_len);
314 body_enc = gaim_escape_html(body_str);
315 g_free(body_str);
316
311 passport = msg->passport; 317 passport = msg->passport;
312 318
313 if (!strcmp(passport, "messenger@microsoft.com") && 319 if (!strcmp(passport, "messenger@microsoft.com") &&
314 strstr(body, "immediate security update")) 320 strstr(body, "immediate security update"))
315 { 321 {
316 g_free(body);
317
318 return; 322 return;
319 } 323 }
320 324
321 #if 0 325 #if 0
322 gaim_debug(GAIM_DEBUG_INFO, "msn", "Checking User-Agent...\n"); 326 if ((value = msn_message_get_attr(msg, "User-Agent")) != NULL)
323 327 {
324 if ((value = msn_message_get_attr(msg, "User-Agent")) != NULL) { 328 gaim_debug_misc("msn", "User-Agent = '%s'\n", value);
325 gaim_debug(GAIM_DEBUG_MISC, "msn", "value = '%s'\n", value);
326 } 329 }
327 #endif 330 #endif
328 331
329 if ((value = msn_message_get_attr(msg, "X-MMS-IM-Format")) != NULL) 332 if ((value = msn_message_get_attr(msg, "X-MMS-IM-Format")) != NULL)
330 { 333 {
331 char *pre_format, *post_format; 334 char *pre_format, *post_format;
332 335
333 msn_parse_format(value, &pre_format, &post_format); 336 msn_parse_format(value, &pre_format, &post_format);
334 337
335 body = g_strdup_printf("%s%s%s", pre_format, body, post_format); 338 body_final = g_strdup_printf("%s%s%s", pre_format, body_enc, post_format);
336 339
337 g_free(pre_format); 340 g_free(pre_format);
338 g_free(post_format); 341 g_free(post_format);
342 g_free(body_enc);
343 }
344 else
345 {
346 body_final = body_enc;
339 } 347 }
340 348
341 if (swboard->chat != NULL) 349 if (swboard->chat != NULL)
342 { 350 {
343 serv_got_chat_in(gc, 351 serv_got_chat_in(gc,
344 gaim_conv_chat_get_id(GAIM_CONV_CHAT(swboard->chat)), 352 gaim_conv_chat_get_id(GAIM_CONV_CHAT(swboard->chat)),
345 passport, 0, body, time(NULL)); 353 passport, 0, body_final, time(NULL));
346 } 354 }
347 else 355 else
348 serv_got_im(gc, passport, body, 0, time(NULL)); 356 serv_got_im(gc, passport, body_final, 0, time(NULL));
349 357
350 g_free(body); 358 g_free(body_final);
351 } 359 }
352 360
353 static void 361 static void
354 control_msg(MsnCmdProc *cmdproc, MsnMessage *msg) 362 control_msg(MsnCmdProc *cmdproc, MsnMessage *msg)
355 { 363 {
385 393
386 user = msn_user_new(session, msg->passport, NULL); 394 user = msn_user_new(session, msg->passport, NULL);
387 395
388 clientcaps = msn_message_get_hashtable_from_body(msg); 396 clientcaps = msn_message_get_hashtable_from_body(msg);
389 #endif 397 #endif
398 }
399
400 void
401 msn_switchboard_send_msg(MsnSwitchBoard *swboard, MsnMessage *msg)
402 {
403 MsnCmdProc *cmdproc;
404 MsnTransaction *trans;
405 char *payload;
406 size_t payload_len;
407
408 g_return_if_fail(swboard != NULL);
409 g_return_if_fail(msg != NULL);
410
411 cmdproc = swboard->servconn->cmdproc;
412
413 payload = msn_message_gen_payload(msg, &payload_len);
414
415 trans = msn_transaction_new("MSG", "%c %d", msn_message_get_flag(msg),
416 payload_len);
417
418 trans->payload = payload;
419 trans->payload_len = payload_len;
420
421 if (!g_queue_is_empty(cmdproc->txqueue) || !swboard->joined)
422 msn_cmdproc_queue_trans(cmdproc, trans);
423 else
424 msn_cmdproc_send_trans(cmdproc, trans);
390 } 425 }
391 426
392 /************************************************************************** 427 /**************************************************************************
393 * Connect stuff 428 * Connect stuff
394 **************************************************************************/ 429 **************************************************************************/
395 static gboolean 430 static gboolean
396 connect_cb(MsnServConn *servconn) 431 connect_cb(MsnServConn *servconn)
397 { 432 {
433 MsnSwitchBoard *swboard;
434 MsnCmdProc *cmdproc;
398 GaimAccount *account; 435 GaimAccount *account;
399 MsnSwitchBoard *swboard; 436
437 cmdproc = servconn->cmdproc;
438 g_return_val_if_fail(cmdproc != NULL, FALSE);
400 439
401 account = servconn->session->account; 440 account = servconn->session->account;
402 swboard = servconn->data; 441 swboard = servconn->data;
442 g_return_val_if_fail(swboard != NULL, FALSE);
443
444 /* swboard->user_joined = TRUE; */
403 445
404 swboard->in_use = TRUE; 446 swboard->in_use = TRUE;
405 447
406 gaim_debug_info("msn", "Connecting to switchboard...\n");
407
408 if (msn_switchboard_is_invited(swboard)) 448 if (msn_switchboard_is_invited(swboard))
409 { 449 {
410 msn_cmdproc_send(swboard->cmdproc, "ANS", "%s %s %s", 450 msn_cmdproc_send(cmdproc, "ANS", "%s %s %s",
411 gaim_account_get_username(account), 451 gaim_account_get_username(account),
412 swboard->auth_key, swboard->session_id); 452 swboard->auth_key, swboard->session_id);
413 } 453 }
414 else 454 else
415 { 455 {
416 msn_cmdproc_send(swboard->cmdproc, "USR", "%s %s", 456 msn_cmdproc_send(cmdproc, "USR", "%s %s",
417 gaim_account_get_username(account), 457 gaim_account_get_username(account),
418 swboard->auth_key); 458 swboard->auth_key);
419 } 459 }
420 460
421 if (swboard->cmdproc->error) 461 if (swboard->cmdproc->error)
457 msn_table_add_cmd(cbs_table, NULL, "BYE", bye_cmd); 497 msn_table_add_cmd(cbs_table, NULL, "BYE", bye_cmd);
458 msn_table_add_cmd(cbs_table, NULL, "OUT", out_cmd); 498 msn_table_add_cmd(cbs_table, NULL, "OUT", out_cmd);
459 499
460 /* Register the message type callbacks. */ 500 /* Register the message type callbacks. */
461 msn_table_add_msg_type(cbs_table, "text/plain", 501 msn_table_add_msg_type(cbs_table, "text/plain",
462 plain_msg); 502 plain_msg);
463 msn_table_add_msg_type(cbs_table, "text/x-msmsgscontrol", 503 msn_table_add_msg_type(cbs_table, "text/x-msmsgscontrol",
464 control_msg); 504 control_msg);
465 msn_table_add_msg_type(cbs_table, "text/x-clientcaps", 505 msn_table_add_msg_type(cbs_table, "text/x-clientcaps",
466 clientcaps_msg); 506 clientcaps_msg);
467 msn_table_add_msg_type(cbs_table, "text/x-clientinfo", 507 msn_table_add_msg_type(cbs_table, "text/x-clientinfo",
468 clientcaps_msg); 508 clientcaps_msg);
469 #if 0 509 #if 0
470 msn_table_add_msg_type(cbs_table, "application/x-msnmsgrp2p", 510 msn_table_add_msg_type(cbs_table, "application/x-msnmsgrp2p",
471 msn_p2p_msg); 511 msn_p2p_msg);
472 #endif 512 #endif
473 } 513 }
474 514
475 void 515 void
476 msn_switchboard_end(void) 516 msn_switchboard_end(void)
494 534
495 msn_servconn_set_connect_cb(servconn, connect_cb); 535 msn_servconn_set_connect_cb(servconn, connect_cb);
496 msn_servconn_set_disconnect_cb(servconn, disconnect_cb); 536 msn_servconn_set_disconnect_cb(servconn, disconnect_cb);
497 537
498 if (session->http_method) 538 if (session->http_method)
499 swboard->servconn->http_data->server_type = "SB"; 539 servconn->http_data->server_type = "SB";
500 540
501 servconn->data = swboard; 541 servconn->data = swboard;
502 542
503 session->switches = g_list_append(session->switches, swboard); 543 session->switches = g_list_append(session->switches, swboard);
504 544
505 cmdproc->cbs_table = cbs_table; 545 cmdproc->cbs_table = cbs_table;
506 546
507 return swboard; 547 return swboard;
508 } 548 }
509 549
510 void 550 void
627 667
628 msn_servconn_disconnect(swboard->servconn); 668 msn_servconn_disconnect(swboard->servconn);
629 669
630 swboard->in_use = FALSE; 670 swboard->in_use = FALSE;
631 } 671 }
632
633 void
634 msn_switchboard_send_msg(MsnSwitchBoard *swboard, MsnMessage *msg)
635 {
636 MsnCmdProc *cmdproc;
637 MsnTransaction *trans;
638 char *payload;
639 size_t payload_len;
640
641 g_return_if_fail(swboard != NULL);
642 g_return_if_fail(msg != NULL);
643
644 cmdproc = swboard->servconn->cmdproc;
645 payload = msn_message_gen_payload(msg, &payload_len);
646
647 trans = msn_transaction_new("MSG", "%c %d", msn_message_get_flag(msg),
648 payload_len);
649
650 trans->payload = payload;
651 trans->payload_len = payload_len;
652
653 if (!g_queue_is_empty(cmdproc->txqueue) || !swboard->joined)
654 msn_cmdproc_queue_trans(cmdproc, trans);
655 else
656 msn_cmdproc_send_trans(cmdproc, trans);
657 }