📄 msn.c
字号:
msn_userlist_rem_buddy(userlist, who, MSN_LIST_BL, NULL); if (user != NULL && user->list_op & MSN_LIST_RL_OP) msn_userlist_add_buddy(userlist, who, MSN_LIST_AL, NULL);}static voidmsn_set_permit_deny(PurpleConnection *gc){ PurpleAccount *account; MsnSession *session; MsnCmdProc *cmdproc; account = purple_connection_get_account(gc); session = gc->proto_data; cmdproc = session->notification->cmdproc; if (account->perm_deny == PURPLE_PRIVACY_ALLOW_ALL || account->perm_deny == PURPLE_PRIVACY_DENY_USERS) { msn_cmdproc_send(cmdproc, "BLP", "%s", "AL"); } else { msn_cmdproc_send(cmdproc, "BLP", "%s", "BL"); }}static voidmsn_chat_invite(PurpleConnection *gc, int id, const char *msg, const char *who){ MsnSession *session; MsnSwitchBoard *swboard; session = gc->proto_data; swboard = msn_session_find_swboard_with_id(session, id); if (swboard == NULL) { /* if we have no switchboard, everyone else left the chat already */ swboard = msn_switchboard_new(session); msn_switchboard_request(swboard); swboard->chat_id = id; swboard->conv = purple_find_chat(gc, id); } swboard->flag |= MSN_SB_FLAG_IM; msn_switchboard_request_add_user(swboard, who);}static voidmsn_chat_leave(PurpleConnection *gc, int id){ MsnSession *session; MsnSwitchBoard *swboard; PurpleConversation *conv; session = gc->proto_data; swboard = msn_session_find_swboard_with_id(session, id); /* if swboard is NULL we were the only person left anyway */ if (swboard == NULL) return; conv = swboard->conv; msn_switchboard_release(swboard, MSN_SB_FLAG_IM); /* If other switchboards managed to associate themselves with this * conv, make sure they know it's gone! */ if (conv != NULL) { while ((swboard = msn_session_find_swboard_with_conv(session, conv)) != NULL) swboard->conv = NULL; }}static intmsn_chat_send(PurpleConnection *gc, int id, const char *message, PurpleMessageFlags flags){ PurpleAccount *account; MsnSession *session; MsnSwitchBoard *swboard; MsnMessage *msg; char *msgformat; char *msgtext; account = purple_connection_get_account(gc); session = gc->proto_data; swboard = msn_session_find_swboard_with_id(session, id); if (swboard == NULL) return -EINVAL; if (!swboard->ready) return 0; swboard->flag |= MSN_SB_FLAG_IM; msn_import_html(message, &msgformat, &msgtext); if (strlen(msgtext) + strlen(msgformat) + strlen(VERSION) > 1564) { g_free(msgformat); g_free(msgtext); return -E2BIG; } msg = msn_message_new_plain(msgtext); msn_message_set_attr(msg, "X-MMS-IM-Format", msgformat); msn_switchboard_send_msg(swboard, msg, FALSE); msn_message_destroy(msg); g_free(msgformat); g_free(msgtext); serv_got_chat_in(gc, id, purple_account_get_username(account), 0, message, time(NULL)); return 0;}static voidmsn_keepalive(PurpleConnection *gc){ MsnSession *session; session = gc->proto_data; if (!session->http_method) { MsnCmdProc *cmdproc; cmdproc = session->notification->cmdproc; msn_cmdproc_send_quick(cmdproc, "PNG", NULL, NULL); }}static voidmsn_group_buddy(PurpleConnection *gc, const char *who, const char *old_group_name, const char *new_group_name){ MsnSession *session; MsnUserList *userlist; session = gc->proto_data; userlist = session->userlist; msn_userlist_move_buddy(userlist, who, old_group_name, new_group_name);}static voidmsn_rename_group(PurpleConnection *gc, const char *old_name, PurpleGroup *group, GList *moved_buddies){ MsnSession *session; MsnCmdProc *cmdproc; int old_gid; const char *enc_new_group_name; session = gc->proto_data; cmdproc = session->notification->cmdproc; enc_new_group_name = purple_url_encode(group->name); old_gid = msn_userlist_find_group_id(session->userlist, old_name); if (old_gid >= 0) { msn_cmdproc_send(cmdproc, "REG", "%d %s 0", old_gid, enc_new_group_name); } else { msn_cmdproc_send(cmdproc, "ADG", "%s 0", enc_new_group_name); }}static voidmsn_convo_closed(PurpleConnection *gc, const char *who){ MsnSession *session; MsnSwitchBoard *swboard; PurpleConversation *conv; session = gc->proto_data; swboard = msn_session_find_swboard(session, who); /* * Don't perform an assertion here. If swboard is NULL, then the * switchboard was either closed by the other party, or the person * is talking to himself. */ if (swboard == NULL) return; conv = swboard->conv; /* If we release the switchboard here, it may still have messages pending ACK which would result in incorrect unsent message errors. Just let it timeout... This is *so* going to screw with people who use dumb clients that report "User has closed the conversation window" */ /* msn_switchboard_release(swboard, MSN_SB_FLAG_IM); */ swboard->conv = NULL; /* If other switchboards managed to associate themselves with this * conv, make sure they know it's gone! */ if (conv != NULL) { while ((swboard = msn_session_find_swboard_with_conv(session, conv)) != NULL) swboard->conv = NULL; }}static voidmsn_set_buddy_icon(PurpleConnection *gc, PurpleStoredImage *img){ MsnSession *session; MsnUser *user; session = gc->proto_data; user = session->user; msn_user_set_buddy_icon(user, img); msn_change_status(session);}static voidmsn_remove_group(PurpleConnection *gc, PurpleGroup *group){ MsnSession *session; MsnCmdProc *cmdproc; int group_id; session = gc->proto_data; cmdproc = session->notification->cmdproc; if ((group_id = msn_userlist_find_group_id(session->userlist, group->name)) >= 0) { msn_cmdproc_send(cmdproc, "RMG", "%d", group_id); }}/** * Extract info text from info_data and add it to user_info */static gbooleanmsn_tooltip_extract_info_text(PurpleNotifyUserInfo *user_info, MsnGetInfoData *info_data){ PurpleBuddy *b; b = purple_find_buddy(purple_connection_get_account(info_data->gc), info_data->name); if (b) { char *tmp; if (b->alias && b->alias[0]) { char *aliastext = g_markup_escape_text(b->alias, -1); purple_notify_user_info_add_pair(user_info, _("Alias"), aliastext); g_free(aliastext); } if (b->server_alias) { char *nicktext = g_markup_escape_text(b->server_alias, -1); tmp = g_strdup_printf("<font sml=\"msn\">%s</font><br>", nicktext); purple_notify_user_info_add_pair(user_info, _("Nickname"), tmp); g_free(tmp); g_free(nicktext); } /* Add the tooltip information */ msn_tooltip_text(b, user_info, TRUE); return TRUE; } return FALSE;}#if PHOTO_SUPPORTstatic char *msn_get_photo_url(const char *url_text){ char *p, *q; if ((p = strstr(url_text, " contactparams:photopreauthurl=\"")) != NULL) { p += strlen(" contactparams:photopreauthurl=\""); } if (p && (strncmp(p, "http://", 8) == 0) && ((q = strchr(p, '"')) != NULL)) return g_strndup(p, q - p); return NULL;}static void msn_got_photo(PurpleUtilFetchUrlData *url_data, gpointer data, const gchar *url_text, size_t len, const gchar *error_message);#endif#if 0static char *msn_info_date_reformat(const char *field, size_t len){ char *tmp = g_strndup(field, len); time_t t = purple_str_to_time(tmp, FALSE, NULL, NULL, NULL); g_free(tmp); return g_strdup(purple_date_format_short(localtime(&t)));}#endif#define MSN_GOT_INFO_GET_FIELD(a, b) \ found = purple_markup_extract_info_field(stripped, stripped_len, user_info, \ "\n" a ":", 0, "\n", 0, "Undisclosed", b, 0, NULL, NULL); \ if (found) \ sect_info = TRUE;#define MSN_GOT_INFO_GET_FIELD_NO_SEARCH(a, b) \ found = purple_markup_extract_info_field(stripped, stripped_len, user_info, \ "\n" a ":", 0, "\n", 0, "Undisclosed", b, 0, NULL, msn_info_strip_search_link); \ if (found) \ sect_info = TRUE;static char *msn_info_strip_search_link(const char *field, size_t len){ const char *c; if ((c = strstr(field, " (http://spaces.live.com/default.aspx?page=searchresults")) == NULL && (c = strstr(field, " (http://spaces.msn.com/default.aspx?page=searchresults")) == NULL) return g_strndup(field, len); return g_strndup(field, c - field);}static voidmsn_got_info(PurpleUtilFetchUrlData *url_data, gpointer data, const gchar *url_text, size_t len, const gchar *error_message){ MsnGetInfoData *info_data = (MsnGetInfoData *)data; PurpleNotifyUserInfo *user_info; char *stripped, *p, *q, *tmp; char *user_url = NULL; gboolean found; gboolean has_tooltip_text = FALSE; gboolean has_info = FALSE; gboolean sect_info = FALSE; gboolean has_contact_info = FALSE; char *url_buffer; GString *s, *s2; int stripped_len;#if PHOTO_SUPPORT char *photo_url_text = NULL; MsnGetInfoStepTwoData *info2_data = NULL;#endif purple_debug_info("msn", "In msn_got_info\n"); /* Make sure the connection is still valid */ if (g_list_find(purple_connections_get_all(), info_data->gc) == NULL) { purple_debug_warning("msn", "invalid connection. ignoring buddy info.\n"); g_free(info_data->name); g_free(info_data); return; } user_info = purple_notify_user_info_new(); has_tooltip_text = msn_tooltip_extract_info_text(user_info, info_data); if (error_message != NULL || url_text == NULL || strcmp(url_text, "") == 0) { tmp = g_strdup_printf("<b>%s</b>", _("Error retrieving profile")); purple_notify_user_info_add_pair(user_info, NULL, tmp); g_free(tmp); purple_notify_userinfo(info_data->gc, info_data->name, user_info, NULL, NULL); purple_notify_user_info_destroy(user_info); g_free(info_data->name); g_free(info_data); return; } url_buffer = g_strdup(url_text); /* If they have a homepage link, MSN masks it such that we need to * fetch the url out before purple_markup_strip_html() nukes it */ /* I don't think this works with the new spaces profiles - Stu 3/2/06 */ if ((p = strstr(url_text, "Take a look at my </font><A class=viewDesc title=\"")) != NULL) { p += 50; if ((q = strchr(p, '"')) != NULL) user_url = g_strndup(p, q - p); } /* * purple_markup_strip_html() doesn't strip out character entities like * and · */ while ((p = strstr(url_buffer, " ")) != NULL) { *p = ' '; /* Turn 's into ordinary blanks */ p += 1; memmove(p, p + 5, strlen(p + 5)); url_buffer[strlen(url_buffer) - 5] = '\0'; } while ((p = strstr(url_buffer, "·")) != NULL) { memmove(p, p + 6, strlen(p + 6)); url_buffer[strlen(url_buffer) - 6] = '\0'; } /* Nuke the nasty \r's that just get in the way */ purple_str_strip_char(url_buffer, '\r'); /* MSN always puts in ' for apostrophes...replace them */ while ((p = strstr(url_buffer, "'")) != NULL) { *p = '\''; memmove(p + 1, p + 5, strlen(p + 5)); url_buffer[strlen(url_buffer) - 4] = '\0'; } /* Nuke the html, it's easier than trying to parse the horrid stuff */ stripped = purple_markup_strip_html(url_buffer); stripped_len = strlen(stripped); purple_debug_misc("msn", "stripped = %p\n", stripped); purple_debug_misc("msn", "url_buffer = %p\n", url_buffer); /* Gonna re-use the memory we've already got for url_buffer */ /* No we're not. */ s = g_string_sized_new(strlen(url_buffer)); s2 = g_string_sized_new(strlen(url_buffer)); /* General section header */ if (has_tooltip_text) purple_notify_user_info_add_section_break(user_info); purple_notify_user_info_add_section_header(user_info, _("General")); /* Extract their Name and put it in */ MSN_GOT_INFO_GET_FIELD("Name", _("Name")); /* General */ MSN_GOT_INFO_GET_FIELD("Nickname", _("Nickname")); MSN_GOT_INFO_GET_FIELD_NO_SEARCH("Age", _("Age")); MSN_GOT_INFO_GET_FIELD_NO_SEARCH("Gender", _("Gender")); MSN_GOT_INFO_GET_FIELD_NO_SEARCH("Occupation", _("Occupation")); MSN_GOT_INFO_GET_FIELD_NO_SEARCH("Location", _("Location")); /* Extract their Interests and put it in */ found = purple_markup_extract_info_field(stripped, stripped_len, user_info, "\nInterests\t", 0, " (/default.aspx?page=searchresults", 0, "Undisclosed", _("Hobbies and Interests") /* _("Interests") */, 0, NULL, NULL); if (found) sect_info = TRUE; MSN_GOT_INFO_GET_FIELD("More about me", _("A Little About Me")); if (sect_info) { has_info = TRUE; sect_info = FALSE; } else { /* Remove the section header */ purple_notify_user_info_remove_last_item(user_info); if (has_tooltip_text) purple_notify_user_info_remove_last_item(user_info); } /* Social */ purple_notify_user_info_add_section_break(user_info); purple_notify_user_info_add_section_header(user_info, _("Social")); MSN_GOT_INFO_GET_FIELD("Marital status", _("Marital Status")); MSN_GOT_INFO_GET_FIELD("Interested in", _("Interests")); MSN_GOT_INFO_GET_FIELD("Pets", _("Pets")); MSN_GOT_INFO_GET_FIELD("Hometown", _("Hometown")); MSN_GOT_INFO_GET_FIELD("Places lived", _("Places Lived")); MSN_GOT_INFO_GET_FIELD("Fashion", _("Fashion")); MSN_GOT_INFO_GET_FIELD("Humor", _("Humor")); MSN_GOT_INFO_GET_FIELD("Music", _("Music")); MSN_GOT_INFO_GET_FIELD("Favorite quote", _("Favorite Quote")); if (sect_info) { has_info = TRUE; sect_info = FALSE; } else { /* Remove the section header */ purple_notify_user_info_remove_last_item(user_info); purple_notify_user_info_remove_last_item(user_info); } /* Contact Info */ /* Personal */ purple_notify_user_info_add_section_break(user_info); purple_notify_user_info_add_section_header(user_info, _("Contact Info")); purple_notify_user_info_add_section_header(user_info, _("Personal")); MSN_GOT_INFO_GET_FIELD("Name", _("Name")); MSN_GOT_INFO_GET_FIELD("Significant other", _("Significant Other")); MSN_GOT_INFO_GET_FIELD("Home phone", _("Home Phone")); MSN_GOT_INFO_GET_FIELD("Home phone 2", _("Home Phone 2")); MSN_GOT_INFO_GET_FIELD("Home address", _("Home Address")); MSN_GOT_INFO_GET_FIELD("Personal Mobile", _("Personal Mobile")); MSN_GOT_INFO_GET_FIELD("Home fax", _("Home Fax")); MSN_GOT_INFO_GET_FIELD("Personal e-mail", _("Personal E-Mail")); MSN_GOT_INFO_GET_FIELD("Personal IM", _("Personal IM")); MSN_GOT_INFO_GET_FIELD("Birthday", _("Birthday")); MSN_GOT_INFO_GET_FIELD("Anniversary", _("Anniversary")); 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); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -