📄 notification.c
字号:
{ char *host; int port; if (strcmp(cmd->params[1], "SB") && strcmp(cmd->params[1], "NS")) { msn_cmdproc_show_error(cmdproc, MSN_ERROR_MISC); return; } msn_parse_socket(cmd->params[2], &host, &port); if (!strcmp(cmd->params[1], "SB")) { gaim_debug_error("msn", "This shouldn't be handled here.\n");#if 0 swboard = cmd->trans->data; if (swboard != NULL) { msn_switchboard_set_auth_key(swboard, cmd->params[4]); if (session->http_method) port = 80; msn_switchboard_connect(swboard, host, port); }#endif } else if (!strcmp(cmd->params[1], "NS")) { MsnSession *session; session = cmdproc->session; msn_notification_connect(session->notification, host, port); } g_free(host);}/************************************************************************** * Message Types **************************************************************************/static voidprofile_msg(MsnCmdProc *cmdproc, MsnMessage *msg){ MsnSession *session; const char *value; session = cmdproc->session; if (strcmp(msg->remote_user, "Hotmail")) /* This isn't an official message. */ return; if ((value = msn_message_get_attr(msg, "kv")) != NULL) session->passport_info.kv = g_strdup(value); if ((value = msn_message_get_attr(msg, "sid")) != NULL) session->passport_info.sid = g_strdup(value); if ((value = msn_message_get_attr(msg, "MSPAuth")) != NULL) session->passport_info.mspauth = g_strdup(value); if ((value = msn_message_get_attr(msg, "ClientIP")) != NULL) session->passport_info.client_ip = g_strdup(value); if ((value = msn_message_get_attr(msg, "ClientPort")) != NULL) session->passport_info.client_port = ntohs(atoi(value));}static voidinitial_email_msg(MsnCmdProc *cmdproc, MsnMessage *msg){ MsnSession *session; GaimConnection *gc; GHashTable *table; const char *unread; session = cmdproc->session; gc = session->account->gc; if (strcmp(msg->remote_user, "Hotmail")) /* This isn't an official message. */ return; if (!gaim_account_get_check_mail(session->account)) return; if (session->passport_info.file == NULL) { MsnTransaction *trans; trans = msn_transaction_new("URL", "%s", "INBOX"); msn_transaction_queue_cmd(trans, msg->cmd); msn_cmdproc_send_trans(cmdproc, trans); return; } table = msn_message_get_hashtable_from_body(msg); unread = g_hash_table_lookup(table, "Inbox-Unread"); if (unread != NULL) { int count = atoi(unread); if (count > 0) { const char *passport; const char *url; passport = msn_user_get_passport(session->user); url = session->passport_info.file; gaim_notify_emails(gc, atoi(unread), FALSE, NULL, NULL, &passport, &url, NULL, NULL); } } g_hash_table_destroy(table);}static voidemail_msg(MsnCmdProc *cmdproc, MsnMessage *msg){ MsnSession *session; GaimConnection *gc; GHashTable *table; char *from, *subject, *tmp; session = cmdproc->session; gc = session->account->gc; if (strcmp(msg->remote_user, "Hotmail")) /* This isn't an official message. */ return; if (!gaim_account_get_check_mail(session->account)) return; if (session->passport_info.file == NULL) { MsnTransaction *trans; trans = msn_transaction_new("URL", "%s", "INBOX"); msn_transaction_queue_cmd(trans, msg->cmd); msn_cmdproc_send_trans(cmdproc, trans); return; } table = msn_message_get_hashtable_from_body(msg); from = subject = NULL; tmp = g_hash_table_lookup(table, "From"); if (tmp != NULL) from = gaim_mime_decode_field(tmp); tmp = g_hash_table_lookup(table, "Subject"); if (tmp != NULL) subject = gaim_mime_decode_field(tmp); gaim_notify_email(gc, (subject != NULL ? subject : ""), (from != NULL ? from : ""), msn_user_get_passport(session->user), session->passport_info.file, NULL, NULL); if (from != NULL) g_free(from); if (subject != NULL) g_free(subject); g_hash_table_destroy(table);}static voidsystem_msg(MsnCmdProc *cmdproc, MsnMessage *msg){ GHashTable *table; const char *type_s; if (strcmp(msg->remote_user, "Hotmail")) /* This isn't an official message. */ return; table = msn_message_get_hashtable_from_body(msg); if ((type_s = g_hash_table_lookup(table, "Type")) != NULL) { int type = atoi(type_s); char buf[MSN_BUF_LEN]; int minutes; switch (type) { case 1: minutes = atoi(g_hash_table_lookup(table, "Arg1")); g_snprintf(buf, sizeof(buf), ngettext( "The MSN server will shut down for maintenance " "in %d minute. You will automatically be " "signed out at that time. Please finish any " "conversations in progress.\n\nAfter the " "maintenance has been completed, you will be " "able to successfully sign in.", "The MSN server will shut down for maintenance " "in %d minutes. You will automatically be " "signed out at that time. Please finish any " "conversations in progress.\n\nAfter the " "maintenance has been completed, you will be " "able to successfully sign in.", minutes), minutes); default: break; } if (*buf != '\0') gaim_notify_info(cmdproc->session->account->gc, NULL, buf, NULL); } g_hash_table_destroy(table);}static voidconnect_cb(MsnServConn *servconn){ MsnNotification *notification; MsnCmdProc *cmdproc; MsnSession *session; GaimAccount *account; GaimConnection *gc; char **a, **c, *vers; int i; g_return_if_fail(servconn != NULL); notification = servconn->data; cmdproc = servconn->cmdproc; session = servconn->session; account = session->account; gc = gaim_account_get_connection(account); /* Allocate an array for CVR0, NULL, and all the versions */ a = c = g_new0(char *, session->protocol_ver - 8 + 3); for (i = session->protocol_ver; i >= 8; i--) *c++ = g_strdup_printf("MSNP%d", i); *c++ = g_strdup("CVR0"); vers = g_strjoinv(" ", a); msn_cmdproc_send(cmdproc, "VER", "%s", vers); g_strfreev(a); g_free(vers); if (cmdproc->error) return; session->user = msn_user_new(session->userlist, gaim_account_get_username(account), NULL);#if 0 gaim_connection_update_progress(gc, _("Syncing with server"), 4, MSN_CONNECT_STEPS);#endif}voidmsn_notification_add_buddy(MsnNotification *notification, const char *list, const char *who, const char *store_name, int group_id){ MsnCmdProc *cmdproc; cmdproc = notification->servconn->cmdproc; if (group_id < 0 && !strcmp(list, "FL")) group_id = 0; if (group_id >= 0) { msn_cmdproc_send(cmdproc, "ADD", "%s %s %s %d", list, who, store_name, group_id); } else { msn_cmdproc_send(cmdproc, "ADD", "%s %s %s", list, who, store_name); }}voidmsn_notification_rem_buddy(MsnNotification *notification, const char *list, const char *who, int group_id){ MsnCmdProc *cmdproc; cmdproc = notification->servconn->cmdproc; if (group_id >= 0) { msn_cmdproc_send(cmdproc, "REM", "%s %s %d", list, who, group_id); } else { msn_cmdproc_send(cmdproc, "REM", "%s %s", list, who); }}voidmsn_notification_init(void){ /* TODO: check prp, blp */ cbs_table = msn_table_new(); /* Syncronous */ msn_table_add_cmd(cbs_table, "CHG", "CHG", chg_cmd); msn_table_add_cmd(cbs_table, "CHG", "ILN", iln_cmd); msn_table_add_cmd(cbs_table, "ADD", "ADD", add_cmd); msn_table_add_cmd(cbs_table, "ADD", "ILN", iln_cmd); msn_table_add_cmd(cbs_table, "REM", "REM", rem_cmd); msn_table_add_cmd(cbs_table, "USR", "USR", usr_cmd); msn_table_add_cmd(cbs_table, "USR", "XFR", xfr_cmd); msn_table_add_cmd(cbs_table, "SYN", "SYN", syn_cmd); msn_table_add_cmd(cbs_table, "CVR", "CVR", cvr_cmd); msn_table_add_cmd(cbs_table, "INF", "INF", inf_cmd); msn_table_add_cmd(cbs_table, "VER", "VER", ver_cmd); msn_table_add_cmd(cbs_table, "REA", "REA", rea_cmd); /* msn_table_add_cmd(cbs_table, "PRP", "PRP", prp_cmd); */ /* msn_table_add_cmd(cbs_table, "BLP", "BLP", blp_cmd); */ msn_table_add_cmd(cbs_table, "BLP", "BLP", NULL); msn_table_add_cmd(cbs_table, "REG", "REG", reg_cmd); msn_table_add_cmd(cbs_table, "ADG", "ADG", adg_cmd); msn_table_add_cmd(cbs_table, "RMG", "RMG", rmg_cmd); msn_table_add_cmd(cbs_table, "XFR", "XFR", xfr_cmd); /* Asyncronous */ msn_table_add_cmd(cbs_table, NULL, "IPG", ipg_cmd); msn_table_add_cmd(cbs_table, NULL, "MSG", msg_cmd); msn_table_add_cmd(cbs_table, NULL, "NOT", not_cmd); msn_table_add_cmd(cbs_table, NULL, "CHL", chl_cmd); msn_table_add_cmd(cbs_table, NULL, "REM", rem_cmd); msn_table_add_cmd(cbs_table, NULL, "ADD", add_cmd); msn_table_add_cmd(cbs_table, NULL, "QRY", NULL); msn_table_add_cmd(cbs_table, NULL, "QNG", NULL); msn_table_add_cmd(cbs_table, NULL, "FLN", fln_cmd); msn_table_add_cmd(cbs_table, NULL, "NLN", nln_cmd); msn_table_add_cmd(cbs_table, NULL, "ILN", iln_cmd); msn_table_add_cmd(cbs_table, NULL, "OUT", out_cmd); msn_table_add_cmd(cbs_table, NULL, "RNG", rng_cmd); msn_table_add_cmd(cbs_table, NULL, "URL", url_cmd); msn_table_add_cmd(cbs_table, "fallback", "XFR", xfr_cmd); msn_table_add_error(cbs_table, "ADD", add_error); /* msn_table_add_error(cbs_table, "REA", rea_error); */ msn_table_add_msg_type(cbs_table, "text/x-msmsgsprofile", profile_msg); msn_table_add_msg_type(cbs_table, "text/x-msmsgsinitialemailnotification", initial_email_msg); msn_table_add_msg_type(cbs_table, "text/x-msmsgsemailnotification", email_msg); msn_table_add_msg_type(cbs_table, "application/x-msmsgssystemmessage", system_msg);}voidmsn_notification_end(void){ msn_table_destroy(cbs_table);}MsnNotification *msn_notification_new(MsnSession *session){ MsnNotification *notification; MsnServConn *servconn; g_return_val_if_fail(session != NULL, NULL); notification = g_new0(MsnNotification, 1); notification->session = session; notification->servconn = servconn = msn_servconn_new(session, MSN_SERVER_NS); notification->cmdproc = servconn->cmdproc; msn_servconn_set_connect_cb(servconn, connect_cb); if (session->http_method) servconn->http_data->server_type = "NS"; servconn->cmdproc->cbs_table = cbs_table; return notification;}voidmsn_notification_destroy(MsnNotification *notification){ msn_servconn_destroy(notification->servconn); g_free(notification);}gbooleanmsn_notification_connect(MsnNotification *notification, const char *host, int port){ MsnServConn *servconn; g_return_val_if_fail(notification != NULL, FALSE); servconn = notification->servconn; return (notification->in_use = msn_servconn_connect(servconn, host, port));}voidmsn_notification_disconnect(MsnNotification *notification){ g_return_if_fail(notification != NULL); notification->in_use = FALSE; if (notification->servconn->connected) msn_servconn_disconnect(notification->servconn);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -