comparison libpurple/protocols/msn/switchboard.c @ 27967:e1cd44c7c7af

explicit merge of 'd957c051e839d63bfc0ef71320934890e7ae63c4' and '7fbd51e5a790f5cf3275a0bb8a8198acd078b4ec'
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Sat, 25 Jul 2009 04:54:36 +0000
parents 4fb5e292de75
children daa709ff32e3
comparison
equal deleted inserted replaced
27966:b4daae0798e3 27967:e1cd44c7c7af
40 40
41 MsnSwitchBoard * 41 MsnSwitchBoard *
42 msn_switchboard_new(MsnSession *session) 42 msn_switchboard_new(MsnSession *session)
43 { 43 {
44 MsnSwitchBoard *swboard; 44 MsnSwitchBoard *swboard;
45 MsnServConn *servconn;
46 45
47 g_return_val_if_fail(session != NULL, NULL); 46 g_return_val_if_fail(session != NULL, NULL);
48 47
49 swboard = g_new0(MsnSwitchBoard, 1); 48 swboard = g_new0(MsnSwitchBoard, 1);
50 49
51 swboard->session = session; 50 swboard->session = session;
52 swboard->servconn = servconn = msn_servconn_new(session, MSN_SERVCONN_SB); 51 swboard->servconn = msn_servconn_new(session, MSN_SERVCONN_SB);
53 swboard->cmdproc = servconn->cmdproc; 52 msn_servconn_set_idle_timeout(swboard->servconn, 60);
53 swboard->cmdproc = swboard->servconn->cmdproc;
54 54
55 swboard->msg_queue = g_queue_new(); 55 swboard->msg_queue = g_queue_new();
56 swboard->empty = TRUE; 56 swboard->empty = TRUE;
57 57
58 swboard->cmdproc->data = swboard; 58 swboard->cmdproc->data = swboard;
59 swboard->cmdproc->cbs_table = cbs_table; 59 swboard->cmdproc->cbs_table = cbs_table;
60 60
61 session->switches = g_list_prepend(session->switches, swboard); 61 session->switches = g_list_prepend(session->switches, swboard);
62
63 if (purple_debug_is_verbose())
64 purple_debug_info("msn", "switchboard new: swboard(%p)\n", swboard);
62 65
63 return swboard; 66 return swboard;
64 } 67 }
65 68
66 void 69 void
68 { 71 {
69 MsnSession *session; 72 MsnSession *session;
70 MsnMessage *msg; 73 MsnMessage *msg;
71 GList *l; 74 GList *l;
72 75
73 #ifdef MSN_DEBUG_SB 76 if (purple_debug_is_verbose())
74 purple_debug_info("msn", "switchboard_destroy: swboard(%p)\n", swboard); 77 purple_debug_info("msn", "switchboard destroy: swboard(%p)\n", swboard);
75 #endif
76 78
77 g_return_if_fail(swboard != NULL); 79 g_return_if_fail(swboard != NULL);
78 80
79 if (swboard->destroying) 81 if (swboard->destroying)
80 return; 82 return;
228 230
229 swboard->users = g_list_prepend(swboard->users, g_strdup(user)); 231 swboard->users = g_list_prepend(swboard->users, g_strdup(user));
230 swboard->current_users++; 232 swboard->current_users++;
231 swboard->empty = FALSE; 233 swboard->empty = FALSE;
232 234
233 #ifdef MSN_DEBUG_CHAT 235 if (purple_debug_is_verbose())
234 purple_debug_info("msn", "user=[%s], total=%d\n", user, 236 purple_debug_info("msn", "user=[%s], total=%d\n",
235 swboard->current_users); 237 user, swboard->current_users);
236 #endif
237 238
238 if (!(swboard->flag & MSN_SB_FLAG_IM) && (swboard->conv != NULL)) 239 if (!(swboard->flag & MSN_SB_FLAG_IM) && (swboard->conv != NULL))
239 { 240 {
240 /* This is a helper switchboard. */ 241 /* This is a helper switchboard. */
241 purple_debug_error("msn", "switchboard_add_user: conv != NULL\n"); 242 purple_debug_error("msn", "switchboard_add_user: conv != NULL\n");
252 { 253 {
253 if (swboard->conv == NULL || 254 if (swboard->conv == NULL ||
254 purple_conversation_get_type(swboard->conv) != PURPLE_CONV_TYPE_CHAT) 255 purple_conversation_get_type(swboard->conv) != PURPLE_CONV_TYPE_CHAT)
255 { 256 {
256 GList *l; 257 GList *l;
257
258 #ifdef MSN_DEBUG_CHAT
259 purple_debug_info("msn", "[chat] Switching to chat.\n");
260 #endif
261 258
262 #if 0 259 #if 0
263 /* this is bad - it causes msn_switchboard_close to be called on the 260 /* this is bad - it causes msn_switchboard_close to be called on the
264 * switchboard we're in the middle of using :( */ 261 * switchboard we're in the middle of using :( */
265 if (swboard->conv != NULL) 262 if (swboard->conv != NULL)
276 { 273 {
277 const char *tmp_user; 274 const char *tmp_user;
278 275
279 tmp_user = l->data; 276 tmp_user = l->data;
280 277
281 #ifdef MSN_DEBUG_CHAT
282 purple_debug_info("msn", "[chat] Adding [%s].\n", tmp_user);
283 #endif
284
285 purple_conv_chat_add_user(PURPLE_CONV_CHAT(swboard->conv), 278 purple_conv_chat_add_user(PURPLE_CONV_CHAT(swboard->conv),
286 tmp_user, NULL, PURPLE_CBFLAGS_NONE, TRUE); 279 tmp_user, NULL, PURPLE_CBFLAGS_NONE, TRUE);
287 } 280 }
288
289 #ifdef MSN_DEBUG_CHAT
290 purple_debug_info("msn", "[chat] We add ourselves.\n");
291 #endif
292 281
293 purple_conv_chat_add_user(PURPLE_CONV_CHAT(swboard->conv), 282 purple_conv_chat_add_user(PURPLE_CONV_CHAT(swboard->conv),
294 purple_account_get_username(account), 283 purple_account_get_username(account),
295 NULL, PURPLE_CBFLAGS_NONE, TRUE); 284 NULL, PURPLE_CBFLAGS_NONE, TRUE);
296 285
587 576
588 cmdproc = swboard->cmdproc; 577 cmdproc = swboard->cmdproc;
589 578
590 payload = msn_message_gen_payload(msg, &payload_len); 579 payload = msn_message_gen_payload(msg, &payload_len);
591 580
592 #ifdef MSN_DEBUG_SB 581 if (purple_debug_is_verbose()) {
593 purple_debug_info("msn", "SB length:{%" G_GSIZE_FORMAT "}\n", payload_len); 582 purple_debug_info("msn", "SB length:{%" G_GSIZE_FORMAT "}\n", payload_len);
594 msn_message_show_readable(msg, "SB SEND", FALSE); 583 msn_message_show_readable(msg, "SB SEND", FALSE);
595 #endif 584 }
596 585
597 flag = msn_message_get_flag(msg); 586 flag = msn_message_get_flag(msg);
598 trans = msn_transaction_new(cmdproc, "MSG", "%c %" G_GSIZE_FORMAT, 587 trans = msn_transaction_new(cmdproc, "MSG", "%c %" G_GSIZE_FORMAT,
599 flag, payload_len); 588 flag, payload_len);
600 589
788 777
789 msg = msn_message_new_from_cmd(cmdproc->session, cmd); 778 msg = msn_message_new_from_cmd(cmdproc->session, cmd);
790 779
791 msn_message_parse_payload(msg, payload, len, 780 msn_message_parse_payload(msg, payload, len,
792 MSG_LINE_DEM,MSG_BODY_DEM); 781 MSG_LINE_DEM,MSG_BODY_DEM);
793 #ifdef MSN_DEBUG_SB 782 if (purple_debug_is_verbose())
794 msn_message_show_readable(msg, "SB RECV", FALSE); 783 msn_message_show_readable(msg, "SB RECV", FALSE);
795 #endif
796 784
797 g_free (msg->remote_user); 785 g_free (msg->remote_user);
798 msg->remote_user = g_strdup(cmd->params[0]); 786 msg->remote_user = g_strdup(cmd->params[0]);
799 787
800 msn_cmdproc_process_msg(cmdproc, msg); 788 msn_cmdproc_process_msg(cmdproc, msg);