📄 msn.c
字号:
/* Business */ purple_notify_user_info_add_section_header(user_info, _("Work")); MSN_GOT_INFO_GET_FIELD("Name", _("Name")); MSN_GOT_INFO_GET_FIELD("Job title", _("Job Title")); MSN_GOT_INFO_GET_FIELD("Company", _("Company")); MSN_GOT_INFO_GET_FIELD("Department", _("Department")); MSN_GOT_INFO_GET_FIELD("Profession", _("Profession")); MSN_GOT_INFO_GET_FIELD("Work phone 1", _("Work Phone")); MSN_GOT_INFO_GET_FIELD("Work phone 2", _("Work Phone 2")); MSN_GOT_INFO_GET_FIELD("Work address", _("Work Address")); MSN_GOT_INFO_GET_FIELD("Work mobile", _("Work Mobile")); MSN_GOT_INFO_GET_FIELD("Work pager", _("Work Pager")); MSN_GOT_INFO_GET_FIELD("Work fax", _("Work Fax")); MSN_GOT_INFO_GET_FIELD("Work e-mail", _("Work E-Mail")); MSN_GOT_INFO_GET_FIELD("Work IM", _("Work IM")); MSN_GOT_INFO_GET_FIELD("Start date", _("Start Date")); MSN_GOT_INFO_GET_FIELD("Notes", _("Notes")); if (sect_info) { has_info = TRUE; sect_info = FALSE; has_contact_info = TRUE; } else { /* Remove the section header */ purple_notify_user_info_remove_last_item(user_info); } if (!has_contact_info) { /* Remove the Contact Info section header */ purple_notify_user_info_remove_last_item(user_info); }#if 0 /* these probably don't show up any more */ /* * The fields, 'A Little About Me', 'Favorite Things', 'Hobbies * and Interests', 'Favorite Quote', and 'My Homepage' may or may * not appear, in any combination. However, they do appear in * certain order, so we can successively search to pin down the * distinct values. */ /* Check if they have A Little About Me */ found = purple_markup_extract_info_field(stripped, stripped_len, s, " A Little About Me \n\n", 0, "Favorite Things", '\n', NULL, _("A Little About Me"), 0, NULL, NULL); if (!found) { found = purple_markup_extract_info_field(stripped, stripped_len, s, " A Little About Me \n\n", 0, "Hobbies and Interests", '\n', NULL, _("A Little About Me"), 0, NULL, NULL); } if (!found) { found = purple_markup_extract_info_field(stripped, stripped_len, s, " A Little About Me \n\n", 0, "Favorite Quote", '\n', NULL, _("A Little About Me"), 0, NULL, NULL); } if (!found) { found = purple_markup_extract_info_field(stripped, stripped_len, s, " A Little About Me \n\n", 0, "My Homepage \n\nTake a look", '\n', NULL, _("A Little About Me"), 0, NULL, NULL); } if (!found) { purple_markup_extract_info_field(stripped, stripped_len, s, " A Little About Me \n\n", 0, "last updated", '\n', NULL, _("A Little About Me"), 0, NULL, NULL); } if (found) has_info = TRUE; /* Check if they have Favorite Things */ found = purple_markup_extract_info_field(stripped, stripped_len, s, " Favorite Things \n\n", 0, "Hobbies and Interests", '\n', NULL, _("Favorite Things"), 0, NULL, NULL); if (!found) { found = purple_markup_extract_info_field(stripped, stripped_len, s, " Favorite Things \n\n", 0, "Favorite Quote", '\n', NULL, _("Favorite Things"), 0, NULL, NULL); } if (!found) { found = purple_markup_extract_info_field(stripped, stripped_len, s, " Favorite Things \n\n", 0, "My Homepage \n\nTake a look", '\n', NULL, _("Favorite Things"), 0, NULL, NULL); } if (!found) { purple_markup_extract_info_field(stripped, stripped_len, s, " Favorite Things \n\n", 0, "last updated", '\n', NULL, _("Favorite Things"), 0, NULL, NULL); } if (found) has_info = TRUE; /* Check if they have Hobbies and Interests */ found = purple_markup_extract_info_field(stripped, stripped_len, s, " Hobbies and Interests \n\n", 0, "Favorite Quote", '\n', NULL, _("Hobbies and Interests"), 0, NULL, NULL); if (!found) { found = purple_markup_extract_info_field(stripped, stripped_len, s, " Hobbies and Interests \n\n", 0, "My Homepage \n\nTake a look", '\n', NULL, _("Hobbies and Interests"), 0, NULL, NULL); } if (!found) { purple_markup_extract_info_field(stripped, stripped_len, s, " Hobbies and Interests \n\n", 0, "last updated", '\n', NULL, _("Hobbies and Interests"), 0, NULL, NULL); } if (found) has_info = TRUE; /* Check if they have Favorite Quote */ found = purple_markup_extract_info_field(stripped, stripped_len, s, "Favorite Quote \n\n", 0, "My Homepage \n\nTake a look", '\n', NULL, _("Favorite Quote"), 0, NULL, NULL); if (!found) { purple_markup_extract_info_field(stripped, stripped_len, s, "Favorite Quote \n\n", 0, "last updated", '\n', NULL, _("Favorite Quote"), 0, NULL, NULL); } if (found) has_info = TRUE; /* Extract the last updated date and put it in */ found = purple_markup_extract_info_field(stripped, stripped_len, s, " last updated:", 1, "\n", 0, NULL, _("Last Updated"), 0, NULL, msn_info_date_reformat); if (found) has_info = TRUE;#endif /* If we were able to fetch a homepage url earlier, stick it in there */ if (user_url != NULL) { tmp = g_strdup_printf("<a href=\"%s\">%s</a>", user_url, user_url); purple_notify_user_info_add_pair(user_info, _("Homepage"), tmp); g_free(tmp); g_free(user_url); has_info = TRUE; } if (!has_info) { /* MSN doesn't actually distinguish between "unknown member" and * a known member with an empty profile. Try to explain this fact. * Note that if we have a nonempty tooltip_text, we know the user * exists. */ /* This doesn't work with the new spaces profiles - Stu 3/2/06 char *p = strstr(url_buffer, "Unknown Member </TITLE>"); * This might not work for long either ... */ /* Nope, it failed some time before 5/2/07 :( char *p = strstr(url_buffer, "form id=\"SpacesSearch\" name=\"SpacesSearch\""); * Let's see how long this one holds out for ... */ char *p = strstr(url_buffer, "<form id=\"profile_form\" name=\"profile_form\" action=\"http://spaces.live.com/profile.aspx?cid=0\""); PurpleBuddy *b = purple_find_buddy (purple_connection_get_account(info_data->gc), info_data->name); purple_notify_user_info_add_pair(user_info, _("Error retrieving profile"), ((p && b) ? _("The user has not created a public profile.") : (p ? _("MSN reported not being able to find the user's profile. " "This either means that the user does not exist, " "or that the user exists " "but has not created a public profile.") : _("Could not find " /* This should never happen */ "any information in the user's profile. " "The user most likely does not exist.")))); } /* put a link to the actual profile URL */ tmp = g_strdup_printf("<a href=\"%s%s\">%s%s</a>", PROFILE_URL, info_data->name, PROFILE_URL, info_data->name); purple_notify_user_info_add_pair(user_info, _("Profile URL"), tmp); g_free(tmp); #if PHOTO_SUPPORT /* Find the URL to the photo; must be before the marshalling [Bug 994207] */ photo_url_text = msn_get_photo_url(url_text); /* Marshall the existing state */ info2_data = g_malloc0(sizeof(MsnGetInfoStepTwoData)); info2_data->info_data = info_data; info2_data->stripped = stripped; info2_data->url_buffer = url_buffer; info2_data->user_info = user_info; info2_data->photo_url_text = photo_url_text; /* Try to put the photo in there too, if there's one */ if (photo_url_text) { purple_util_fetch_url(photo_url_text, FALSE, NULL, FALSE, msn_got_photo, info2_data); } else { /* Emulate a callback */ /* TODO: Huh? */ msn_got_photo(NULL, info2_data, NULL, 0, NULL); }}static voidmsn_got_photo(PurpleUtilFetchUrlData *url_data, gpointer user_data, const gchar *url_text, size_t len, const gchar *error_message){ MsnGetInfoStepTwoData *info2_data = (MsnGetInfoStepTwoData *)user_data; int id = -1; /* Unmarshall the saved state */ MsnGetInfoData *info_data = info2_data->info_data; char *stripped = info2_data->stripped; char *url_buffer = info2_data->url_buffer; PurpleNotifyUserInfo *user_info = info2_data->user_info; char *photo_url_text = info2_data->photo_url_text; /* Make sure the connection is still valid if we got here by fetching a photo url */ if (url_text && (error_message != NULL || g_list_find(purple_connections_get_all(), info_data->gc) == NULL)) { purple_debug_warning("msn", "invalid connection. ignoring buddy photo info.\n"); g_free(stripped); g_free(url_buffer); g_free(user_info); g_free(info_data->name); g_free(info_data); g_free(photo_url_text); g_free(info2_data); return; } /* Try to put the photo in there too, if there's one and is readable */ if (user_data && url_text && len != 0) { if (strstr(url_text, "400 Bad Request") || strstr(url_text, "403 Forbidden") || strstr(url_text, "404 Not Found")) { purple_debug_info("msn", "Error getting %s: %s\n", photo_url_text, url_text); } else { char buf[1024]; purple_debug_info("msn", "%s is %d bytes\n", photo_url_text, len); id = purple_imgstore_add_with_id(g_memdup(url_text, len), len, NULL); g_snprintf(buf, sizeof(buf), "<img id=\"%d\"><br>", id); purple_notify_user_info_prepend_pair(user_info, NULL, buf); } } /* We continue here from msn_got_info, as if nothing has happened */#endif purple_notify_userinfo(info_data->gc, info_data->name, user_info, NULL, NULL); g_free(stripped); g_free(url_buffer); purple_notify_user_info_destroy(user_info); g_free(info_data->name); g_free(info_data);#if PHOTO_SUPPORT g_free(photo_url_text); g_free(info2_data); if (id != -1) purple_imgstore_unref_by_id(id);#endif}static voidmsn_get_info(PurpleConnection *gc, const char *name){ MsnGetInfoData *data; char *url; data = g_new0(MsnGetInfoData, 1); data->gc = gc; data->name = g_strdup(name); url = g_strdup_printf("%s%s", PROFILE_URL, name); purple_util_fetch_url(url, FALSE, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)", TRUE, msn_got_info, data); g_free(url);}static gboolean msn_load(PurplePlugin *plugin){ msn_notification_init(); msn_switchboard_init(); msn_sync_init(); return TRUE;}static gboolean msn_unload(PurplePlugin *plugin){ msn_notification_end(); msn_switchboard_end(); msn_sync_end(); return TRUE;}static PurpleAccount *find_acct(const char *prpl, const char *acct_id){ PurpleAccount *acct = NULL; /* If we have a specific acct, use it */ if (acct_id) { acct = purple_accounts_find(acct_id, prpl); if (acct && !purple_account_is_connected(acct)) acct = NULL; } else { /* Otherwise find an active account for the protocol */ GList *l = purple_accounts_get_all(); while (l) { if (!strcmp(prpl, purple_account_get_protocol_id(l->data)) && purple_account_is_connected(l->data)) { acct = l->data; break; } l = l->next; } } return acct;}static gboolean msn_uri_handler(const char *proto, const char *cmd, GHashTable *params){ char *acct_id = g_hash_table_lookup(params, "account"); PurpleAccount *acct; if (g_ascii_strcasecmp(proto, "msnim")) return FALSE; acct = find_acct("prpl-msn", acct_id); if (!acct) return FALSE; /* msnim:chat?contact=user@domain.tld */ if (!g_ascii_strcasecmp(cmd, "Chat")) { char *sname = g_hash_table_lookup(params, "contact"); if (sname) { PurpleConversation *conv = purple_find_conversation_with_account( PURPLE_CONV_TYPE_IM, sname, acct); if (conv == NULL) conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, acct, sname); purple_conversation_present(conv); } /*else **If pidgindialogs_im() was in the core, we could use it here. * It is all purple_request_* based, but I'm not sure it really belongs in the core pidgindialogs_im();*/ return TRUE; } /* msnim:add?contact=user@domain.tld */ else if (!g_ascii_strcasecmp(cmd, "Add")) { char *name = g_hash_table_lookup(params, "contact"); purple_blist_request_add_buddy(acct, name, NULL, NULL); return TRUE; } return FALSE;}static PurplePluginProtocolInfo prpl_info ={ OPT_PROTO_MAIL_CHECK, NULL, /* user_splits */ NULL, /* protocol_options */ {"png", 0, 0, 96, 96, 0, PURPLE_ICON_SCALE_SEND}, /* icon_spec */ msn_list_icon, /* list_icon */ NULL, /* list_emblems */ msn_status_text, /* status_text */ msn_tooltip_text, /* tooltip_text */ msn_status_types, /* away_states */ msn_blist_node_menu, /* blist_node_menu */ NULL, /* chat_info */ NULL, /* chat_info_defaults */ msn_login, /* login */ msn_close, /* close */ msn_send_im, /* send_im */ NULL, /* set_info */ msn_send_typing, /* send_typing */ msn_get_info, /* get_info */ msn_set_status, /* set_away */ msn_set_idle, /* set_idle */ NULL, /* change_passwd */ msn_add_buddy, /* add_buddy */ NULL, /* add_buddies */ msn_rem_buddy, /* remove_buddy */ NULL, /* remove_buddies */ msn_add_permit, /* add_permit */ msn_add_deny, /* add_deny */ msn_rem_permit, /* rem_permit */ msn_rem_deny, /* rem_deny */ msn_set_permit_deny, /* set_permit_deny */ NULL, /* join_chat */ NULL, /* reject chat invite */ NULL, /* get_chat_name */ msn_chat_invite, /* chat_invite */ msn_chat_leave, /* chat_leave */ NULL, /* chat_whisper */ msn_chat_send, /* chat_send */ msn_keepalive, /* keepalive */ NULL, /* register_user */ NULL, /* get_cb_info */ NULL, /* get_cb_away */ NULL, /* alias_buddy */ msn_group_buddy, /* group_buddy */ msn_rename_group, /* rename_group */ NULL, /* buddy_free */ msn_convo_closed, /* convo_closed */ msn_normalize, /* normalize */ msn_set_buddy_icon, /* set_buddy_icon */ msn_remove_group, /* remove_group */ NULL, /* get_cb_real_name */ NULL, /* set_chat_topic */ NULL, /* find_blist_chat */ NULL, /* roomlist_get_list */ NULL, /* roomlist_cancel */ NULL, /* roomlist_expand_category */ msn_can_receive_file, /* can_receive_file */ msn_send_file, /* send_file */ msn_new_xfer, /* new_xfer */ msn_offline_message, /* offline_message */ NULL, /* whiteboard_prpl_ops */ NULL, /* send_raw */ NULL, /* roomlist_room_serialize */ /* padding */ NULL, NULL, NULL, NULL};static PurplePluginInfo info ={ PURPLE_PLUGIN_MAGIC, PURPLE_MAJOR_VERSION, PURPLE_MINOR_VERSION, PURPLE_PLUGIN_PROTOCOL, /**< type */ NULL, /**< ui_requirement */ 0, /**< flags */ NULL, /**< dependencies */ PURPLE_PRIORITY_DEFAULT, /**< priority */ "prpl-msn", /**< id */ "MSN", /**< name */ VERSION, /**< version */ /** summary */ N_("MSN Protocol Plugin"), /** description */ N_("MSN Protocol Plugin"), "Christian Hammond <chipx86@gnupdate.org>", /**< author */ PURPLE_WEBSITE, /**< homepage */ msn_load, /**< load */ msn_unload, /**< unload */ NULL, /**< destroy */ NULL, /**< ui_info */ &prpl_info, /**< extra_info */ NULL, /**< prefs_info */ msn_actions, /* padding */ NULL, NULL, NULL, NULL};static voidinit_plugin(PurplePlugin *plugin){ PurpleAccountOption *option; option = purple_account_option_string_new(_("Server"), "server", MSN_SERVER); prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); option = purple_account_option_int_new(_("Port"), "port", 1863); prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); option = purple_account_option_bool_new(_("Use HTTP Method"), "http_method", FALSE); prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); option = purple_account_option_bool_new(_("Show custom smileys"), "custom_smileys", TRUE); prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); purple_cmd_register("nudge", "", PURPLE_CMD_P_PRPL, PURPLE_CMD_FLAG_IM | PURPLE_CMD_FLAG_PRPL_ONLY, "prpl-msn", msn_cmd_nudge, _("nudge: nudge a user to get their attention"), NULL); purple_prefs_remove("/plugins/prpl/msn"); purple_signal_connect(purple_get_core(), "uri-handler", plugin, PURPLE_CALLBACK(msn_uri_handler), NULL);}PURPLE_INIT_PLUGIN(msn, init_plugin, info);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -