⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 notification.c

📁 msn message protocol stack
💻 C
📖 第 1 页 / 共 3 页
字号:
/** * @file notification.c Notification server 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 "notification.h"#include "state.h"#include "error.h"#include "utils.h"#include "page.h"#include "userlist.h"#include "sync.h"#define BUDDY_ALIAS_MAXLEN 388static MsnTable *cbs_table;/************************************************************************** * Login **************************************************************************/voidmsn_got_login_params(MsnSession *session, const char *login_params){	MsnCmdProc *cmdproc;	cmdproc = session->notification->cmdproc;	msn_cmdproc_send(cmdproc, "USR", "TWN S %s", login_params);}static voidcvr_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd){	GaimAccount *account;	account = cmdproc->session->account;	msn_cmdproc_send(cmdproc, "USR", "TWN I %s",					 gaim_account_get_username(account));}static voidinf_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd){	GaimAccount *account;	GaimConnection *gc;	account = cmdproc->session->account;	gc = gaim_account_get_connection(account);	if (strcmp(cmd->params[1], "MD5"))	{		msn_cmdproc_show_error(cmdproc, MSN_ERROR_MISC);		return;	}	msn_cmdproc_send(cmdproc, "USR", "MD5 I %s",					 gaim_account_get_username(account));	if (cmdproc->error)		return;	gaim_connection_update_progress(gc, _("Requesting to send password"),									5, MSN_CONNECT_STEPS);}static voidusr_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd){	MsnSession *session;	GaimAccount *account;	GaimConnection *gc;	session = cmdproc->session;	account = session->account;	gc = gaim_account_get_connection(account);	/*	 * We're either getting the passport connect info (if we're on	 * MSNP8 or higher), or a challenge request (MSNP7 and lower).	 *	 * Let's find out.	 */	if (!g_ascii_strcasecmp(cmd->params[1], "OK"))	{		const char *friendly = gaim_url_decode(cmd->params[3]);		/* OK */		gaim_connection_set_display_name(gc, friendly);		msn_cmdproc_send(cmdproc, "SYN", "%s", "0");		if (cmdproc->error)			return;		gaim_connection_update_progress(gc, _("Retrieving buddy list"),										7, MSN_CONNECT_STEPS);	}	else if (!g_ascii_strcasecmp(cmd->params[1], "TWN"))	{		char **elems, **cur, **tokens;		/* Passport authentication */		session->nexus = msn_nexus_new(session);		/* Parse the challenge data. */		elems = g_strsplit(cmd->params[3], ",", 0);		for (cur = elems; *cur != NULL; cur++)		{				tokens = g_strsplit(*cur, "=", 2);				g_hash_table_insert(session->nexus->challenge_data, tokens[0], tokens[1]);				/* Don't free each of the tokens, only the array. */				g_free(tokens);		}		g_strfreev(elems);		msn_nexus_connect(session->nexus);		gaim_connection_update_progress(gc, _("Password sent"),										6, MSN_CONNECT_STEPS);	}	else if (!g_ascii_strcasecmp(cmd->params[1], "MD5"))	{		/* Challenge */		const char *challenge;		const char *password;		char buf[33];		md5_state_t st;		md5_byte_t di[16];		int i;		challenge = cmd->params[3];		password = gaim_account_get_password(account);		md5_init(&st);		md5_append(&st, (const md5_byte_t *)challenge, strlen(challenge));		md5_append(&st, (const md5_byte_t *)password, strlen(password));		md5_finish(&st, di);		for (i = 0; i < 16; i++)			g_snprintf(buf + (i*2), 3, "%02x", di[i]);		msn_cmdproc_send(cmdproc, "USR", "MD5 S %s", buf);		if (cmdproc->error)			return;		gaim_connection_update_progress(gc, _("Password sent"),										6, MSN_CONNECT_STEPS);	}}static voidver_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd){	MsnSession *session;	GaimAccount *account;	gboolean protocol_supported = FALSE;	char proto_str[8];	size_t i;	session = cmdproc->session;	account = session->account;	g_snprintf(proto_str, sizeof(proto_str), "MSNP%d", session->protocol_ver);	for (i = 1; i < cmd->param_count; i++)	{		if (!strcmp(cmd->params[i], proto_str))		{			protocol_supported = TRUE;			break;		}	}	if (!protocol_supported)	{		msn_cmdproc_show_error(cmdproc, MSN_ERROR_MISC);		return;	}	msn_cmdproc_send(cmdproc, "CVR",					 "0x0409 winnt 5.1 i386 MSNMSGR 6.0.0602 MSMSGS %s",					 gaim_account_get_username(account));}/************************************************************************** * Log out **************************************************************************/static voidout_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd){	if (!g_ascii_strcasecmp(cmd->params[0], "OTH"))		msn_cmdproc_show_error(cmdproc, MSN_ERROR_SIGNOTHER);	else if (!g_ascii_strcasecmp(cmd->params[0], "SSD"))		msn_cmdproc_show_error(cmdproc, MSN_ERROR_SERVDOWN);}/************************************************************************** * Messages **************************************************************************/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, "Notification", TRUE); */	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){	/* NOTE: cmd is not always cmdproc->last_cmd, sometimes cmd is a queued	 * command and we are processing it */	if (cmd->payload == NULL)	{		cmdproc->last_cmd->payload_cb  = msg_cmd_post;		cmdproc->servconn->payload_len = atoi(cmd->params[2]);	}	else	{		g_return_if_fail(cmd->payload_cb != NULL);		cmd->payload_cb(cmdproc, cmd, cmd->payload, cmd->payload_len);	}}/************************************************************************** * Challenges **************************************************************************/static voidchl_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd){	MsnTransaction *trans;	char buf[33];	const char *challenge_resp;	md5_state_t st;	md5_byte_t di[16];	int i;	md5_init(&st);	md5_append(&st, (const md5_byte_t *)cmd->params[1],			   strlen(cmd->params[1]));	challenge_resp = "VT6PX?UQTM4WM%YR";	md5_append(&st, (const md5_byte_t *)challenge_resp,			   strlen(challenge_resp));	md5_finish(&st, di);	for (i = 0; i < 16; i++)		g_snprintf(buf + (i*2), 3, "%02x", di[i]);	trans = msn_transaction_new("QRY", "%s 32", "PROD0038W!61ZTF9");	msn_transaction_set_payload(trans, buf, 32);	msn_cmdproc_send_trans(cmdproc, trans);}/************************************************************************** * Buddy Lists **************************************************************************/static voidadd_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd){	MsnSession *session;	MsnUser *user;	const char *list;	const char *passport;	const char *friendly;	MsnListId list_id;	int group_id;	list     = cmd->params[1];	passport = cmd->params[3];	friendly = gaim_url_decode(cmd->params[4]);	session = cmdproc->session;	user = msn_userlist_find_user(session->userlist, passport);	if (user == NULL)	{		user = msn_user_new(session->userlist, passport, friendly);		msn_userlist_add_user(session->userlist, user);	}	else		msn_user_set_friendly_name(user, friendly);	list_id = msn_get_list_id(list);	if (cmd->param_count >= 6)		group_id = atoi(cmd->params[5]);	else		group_id = -1;	msn_got_add_user(session, user, list_id, group_id);}static voidadd_error(MsnCmdProc *cmdproc, MsnTransaction *trans, int error){	MsnSession *session;	GaimAccount *account;	GaimConnection *gc;	const char *list, *passport;	char *reason = NULL;	char *msg = NULL;	char **params;	session = cmdproc->session;	account = session->account;	gc = gaim_account_get_connection(account);	params = g_strsplit(trans->params, " ", 0);	list     = params[0];	passport = params[1];	if (!strcmp(list, "FL"))		msg = g_strdup_printf("Unable to add user on %s (%s)",							  gaim_account_get_username(account),							  gaim_account_get_protocol_name(account));	else if (!strcmp(list, "BL"))		msg = g_strdup_printf("Unable to block user on %s (%s)",							  gaim_account_get_username(account),							  gaim_account_get_protocol_name(account));	else if (!strcmp(list, "AL"))		msg = g_strdup_printf("Unable to permit user on %s (%s)",							  gaim_account_get_username(account),							  gaim_account_get_protocol_name(account));	if (!strcmp(list, "FL"))	{		if (error == 210)		{			reason = g_strdup_printf("%s could not be added because "									 "your buddy list is full.", passport);		}	}	if (reason == NULL)	{		if (error == 208)		{			reason = g_strdup_printf("%s is not a valid passport account.",									 passport);		}		else		{			reason = g_strdup_printf("Unknown error.");		}	}	if (msg != NULL)	{		gaim_notify_error(gc, NULL, msg, reason);		g_free(msg);	}	if (!strcmp(list, "FL"))	{		GaimBuddy *buddy;		buddy = gaim_find_buddy(account, passport);		if (buddy != NULL)			gaim_blist_remove_buddy(buddy);	}	g_free(reason);	g_strfreev(params);}static voidadg_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd){	MsnGroup *group;	MsnSession *session;	gint group_id;	const char *group_name;	session = cmdproc->session;	group_id = atoi(cmd->params[3]);	group_name = gaim_url_decode(cmd->params[2]);	group = msn_group_new(session->userlist, group_id, group_name);	/* There is a user that must me moved to this group */	if (cmd->trans->data)	{		/* msn_userlist_move_buddy(); */		MsnUserList *userlist = cmdproc->session->userlist;		MsnMoveBuddy *data = cmd->trans->data;		if (data->old_group_name != NULL)		{			msn_userlist_rem_buddy(userlist, data->who, MSN_LIST_FL, data->old_group_name);			g_free(data->old_group_name);		}		msn_userlist_add_buddy(userlist, data->who, MSN_LIST_FL, group_name);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -