📄 switchboard.c
字号:
/** * @file switchboard.c MSN switchboard functions * * gaim * * Gaim is the legal property of its developers, whose names are too numerous * to list here. Please refer to the COPYRIGHT file distributed with this * source distribution. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */#include "msn.h"#include "prefs.h"#include "switchboard.h"#include "notification.h"#include "utils.h"#include "error.h"static MsnTable *cbs_table;/************************************************************************** * Utility functions **************************************************************************/static voidsend_clientcaps(MsnSwitchBoard *swboard){ MsnMessage *msg; msg = msn_message_new(); msn_message_set_content_type(msg, "text/x-clientcaps"); msn_message_set_flag(msg, 'U'); msn_message_set_bin_data(msg, MSN_CLIENTINFO, strlen(MSN_CLIENTINFO)); msn_switchboard_send_msg(swboard, msg); msn_message_destroy(msg);}voidmsn_switchboard_add_user(MsnSwitchBoard *swboard, const char *user){ MsnCmdProc *cmdproc; GaimAccount *account; g_return_if_fail(swboard != NULL); cmdproc = swboard->servconn->cmdproc; account = swboard->servconn->session->account; swboard->users = g_list_prepend(swboard->users, g_strdup(user)); swboard->current_users++; /* gaim_debug_info("msn", "user=[%s], total=%d\n", user, * swboard->current_users); */ if ((swboard->conv != NULL) && (gaim_conversation_get_type(swboard->conv) == GAIM_CONV_CHAT)) { gaim_conv_chat_add_user(GAIM_CONV_CHAT(swboard->conv), user, NULL, GAIM_CBFLAGS_NONE, TRUE); } else if (swboard->current_users > 1 || swboard->total_users > 1) { if (swboard->conv == NULL || gaim_conversation_get_type(swboard->conv) != GAIM_CONV_CHAT) { GList *l; /* gaim_debug_info("msn", "[chat] Switching to chat.\n"); */ if (swboard->conv != NULL) gaim_conversation_destroy(swboard->conv); cmdproc->session->conv_seq++; swboard->chat_id = cmdproc->session->conv_seq; swboard->conv = serv_got_joined_chat(account->gc, swboard->chat_id, "MSN Chat"); for (l = swboard->users; l != NULL; l = l->next) { const char *tmp_user; tmp_user = l->data; /* gaim_debug_info("msn", "[chat] Adding [%s].\n", * tmp_user); */ gaim_conv_chat_add_user(GAIM_CONV_CHAT(swboard->conv), tmp_user, NULL, GAIM_CBFLAGS_NONE, TRUE); } /* gaim_debug_info("msn", "[chat] We add ourselves.\n"); */ gaim_conv_chat_add_user(GAIM_CONV_CHAT(swboard->conv), gaim_account_get_username(account), NULL, GAIM_CBFLAGS_NONE, TRUE); g_free(swboard->im_user); swboard->im_user = NULL; } } else if (swboard->conv == NULL) { swboard->conv = gaim_find_conversation_with_account(user, account); } else { gaim_debug_warning("msn", "This should not happen!" "(msn_switchboard_add_user)\n"); }}/************************************************************************** * Switchboard Commands **************************************************************************/static voidans_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd){ MsnSwitchBoard *swboard; swboard = cmdproc->servconn->data; swboard->ready = TRUE;}static voidbye_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd){ GaimAccount *account; MsnSwitchBoard *swboard; const char *user; account = cmdproc->session->account; swboard = cmdproc->servconn->data; user = cmd->params[0]; if (swboard->hidden) return; if (swboard->current_users > 1) { gaim_conv_chat_remove_user(GAIM_CONV_CHAT(swboard->conv), user, NULL); } else { char *username; GaimConversation *conv; GaimBuddy *b; char *str = NULL; if ((b = gaim_find_buddy(account, user)) != NULL) username = gaim_escape_html(gaim_buddy_get_alias(b)); else username = gaim_escape_html(user); if (cmd->param_count == 2 && atoi(cmd->params[1]) == 1) { if (gaim_prefs_get_bool("/plugins/prpl/msn/conv_timeout_notice")) { str = g_strdup_printf(_("The conversation has become " "inactive and timed out.")); } } else { if (gaim_prefs_get_bool("/plugins/prpl/msn/conv_close_notice")) { str = g_strdup_printf(_("%s has closed the conversation " "window."), username); } } if (str != NULL && (conv = gaim_find_conversation_with_account(user, account)) != NULL) { gaim_conversation_write(conv, NULL, str, GAIM_MESSAGE_SYSTEM, time(NULL)); g_free(str); } msn_switchboard_disconnect(swboard); g_free(username); }}static voidiro_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd){ GaimAccount *account; GaimConnection *gc; MsnSwitchBoard *swboard; account = cmdproc->session->account; gc = account->gc; swboard = cmdproc->servconn->data; swboard->total_users = atoi(cmd->params[2]); msn_switchboard_add_user(swboard, cmd->params[3]);}static voidjoi_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd){ MsnSession *session; GaimAccount *account; GaimConnection *gc; MsnSwitchBoard *swboard; const char *passport; passport = cmd->params[0]; session = cmdproc->session; account = session->account; gc = account->gc; swboard = cmdproc->servconn->data; msn_switchboard_add_user(swboard, passport); swboard->user_joined = TRUE; /* msn_cmdproc_process_queue(cmdproc); */ msn_switchboard_process_queue(swboard); send_clientcaps(swboard);}static voidmsg_cmd_post(MsnCmdProc *cmdproc, MsnCommand *cmd, char *payload, size_t len){ MsnMessage *msg; msg = msn_message_new_from_cmd(cmdproc->session, cmd); msn_message_parse_payload(msg, payload, len); /* msn_message_show_readable(msg, "SB RECV", FALSE); */ msg->remote_user = g_strdup(cmd->params[0]); msn_cmdproc_process_msg(cmdproc, msg); msn_message_destroy(msg);}static voidmsg_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd){ cmdproc->servconn->payload_len = atoi(cmd->params[2]); cmdproc->last_cmd->payload_cb = msg_cmd_post;}static voidnak_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd){ /* gaim_notify_error(cmdproc->session->account->gc, NULL, _("A MSN message may not have been received."), NULL); */}static voidack_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd){#if 0 MsnMessage *msg; const char *body; msg = msn_message_new(); msn_message_parse_payload(msg, cmd->trans->payload, cmd->trans->payload_len); body = msn_message_get_body(msg); gaim_debug_info("msn", "ACK: {%s}\n", body); msn_message_destroy(msg);#endif}static voidout_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd){ GaimConnection *gc; MsnSwitchBoard *swboard; gc = cmdproc->session->account->gc; swboard = cmdproc->servconn->data; if (swboard->current_users > 1) serv_got_chat_left(gc, swboard->chat_id); msn_switchboard_disconnect(swboard);}static voidusr_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd){ MsnSwitchBoard *swboard; swboard = cmdproc->servconn->data;#if 0 GList *l; for (l = swboard->users; l != NULL; l = l->next) { const char *user; user = l->data; msn_cmdproc_send(cmdproc, "CAL", "%s", user); }#endif swboard->ready = TRUE; msn_cmdproc_process_queue(cmdproc);}/************************************************************************** * Message Types **************************************************************************/static voidplain_msg(MsnCmdProc *cmdproc, MsnMessage *msg){ GaimConnection *gc; MsnSwitchBoard *swboard; const char *body; char *body_str; char *body_enc; char *body_final; size_t body_len; const char *passport; const char *value; gc = cmdproc->session->account->gc; swboard = cmdproc->servconn->data; body = msn_message_get_bin_data(msg, &body_len); body_str = g_strndup(body, body_len); body_enc = gaim_escape_html(body_str); g_free(body_str); passport = msg->remote_user; if (!strcmp(passport, "messenger@microsoft.com") && strstr(body, "immediate security update")) { return; }#if 0 if ((value = msn_message_get_attr(msg, "User-Agent")) != NULL) { gaim_debug_misc("msn", "User-Agent = '%s'\n", value); }#endif if ((value = msn_message_get_attr(msg, "X-MMS-IM-Format")) != NULL) { char *pre_format, *post_format; msn_parse_format(value, &pre_format, &post_format); body_final = g_strdup_printf("%s%s%s", pre_format, body_enc, post_format); g_free(pre_format); g_free(post_format); g_free(body_enc); } else { body_final = body_enc; } if (swboard->current_users > 1) { serv_got_chat_in(gc, swboard->chat_id, passport, 0, body_final, time(NULL)); } else serv_got_im(gc, passport, body_final, 0, time(NULL)); g_free(body_final);}static voidcontrol_msg(MsnCmdProc *cmdproc, MsnMessage *msg){ GaimConnection *gc; MsnSwitchBoard *swboard; const char *value; char *passport; gc = cmdproc->session->account->gc; swboard = cmdproc->servconn->data; passport = msg->remote_user; if (swboard->current_users == 1 && (value = msn_message_get_attr(msg, "TypingUser")) != NULL) { serv_got_typing(gc, passport, MSN_TYPING_RECV_TIMEOUT, GAIM_TYPING); }}static voidclientcaps_msg(MsnCmdProc *cmdproc, MsnMessage *msg){#if 0 MsnSession *session; MsnSwitchBoard *swboard; MsnUser *user; GHashTable *clientcaps; const char *value; char *passport = msg->sender; session = cmdproc->session;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -