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

📄 msn.c

📁 msn message protocol stack
💻 C
📖 第 1 页 / 共 3 页
字号:
		{			char *nicktext = g_markup_escape_text(b->server_alias, -1);			g_string_append_printf(s, _("<b>%s:</b> "), _("Nickname"));			g_string_append_printf(s, "<font sml=\"msn\">%s</font><br>",								   nicktext);			g_free(nicktext);		}		if (b->idle > 0)		{			char *idletime = gaim_str_seconds_to_string(time(NULL) - b->idle);			g_string_append_printf(s, _("<b>%s:</b> %s<br>"), _("Idle"),								   idletime);			g_free(idletime);		}		if (statustext)		{			char *tmp;			tmp = gaim_strreplace((*statustext == '\n' ? statustext + 1 : statustext),								  "\n", "<br>");			g_free(statustext);			g_string_append_printf(s, "%s<br>", tmp);			g_free(tmp);		}		user = b->proto_data;	}	return g_string_free(s, FALSE);}#if PHOTO_SUPPORTstatic char *msn_get_photo_url(const char *url_text){	char *p;	char *it = NULL;	p = strstr(url_text, " title=\"Click to see the full-size photo.\">");	if (p)	{		/* Search backwards for "http://". This is stupid, but it works. */		for (; !it && p > url_text; p -= 1)		{			if (strncmp(p, "\"http://", 8) == 0)			{				char *q;				p += 1; /* skip only the " */				q = strchr(p, '"');				if (q)				{					it = g_strndup(p, q - p);				}			}		}	}	return it;}static void msn_got_photo(void *data, const char *url_text, size_t len);#endifstatic voidmsn_got_info(void *data, const char *url_text, size_t len){	MsnGetInfoData *info_data = (MsnGetInfoData *)data;	char *stripped, *p, *q;	char buf[1024];	char *tooltip_text = NULL;	char *user_url = NULL;	gboolean found;	gboolean has_info = FALSE;	const char* title = NULL;	char *url_buffer;	GString *s;	int stripped_len;#if PHOTO_SUPPORT	char *photo_url_text = NULL;	MsnGetInfoStepTwoData *info2_data = NULL;#endif	gaim_debug_info("msn", "In msn_got_info\n");	tooltip_text = msn_tooltip_info_text(info_data);	title = _("MSN Profile");	if (url_text == NULL || strcmp(url_text, "") == 0)	{		g_snprintf(buf, 1024, "<html><body>%s<b>%s</b></body></html>",				tooltip_text, _("Error retrieving profile"));		gaim_notify_userinfo(info_data->gc, info_data->name, NULL,				title, NULL, buf, NULL, NULL);		g_free(tooltip_text);		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 gaim_markup_strip_html() nukes it */	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);	}	/*	 * gaim_markup_strip_html() doesn't strip out character entities like &nbsp;	 * and &#183;	 */	while ((p = strstr(url_buffer, "&nbsp;")) != NULL)	{		*p = ' '; /* Turn &nbsp;'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, "&#183;")) != 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 */	gaim_str_strip_cr(url_buffer);	/* MSN always puts in &#39; for apostrophes...replace them */	while ((p = strstr(url_buffer, "&#39;")) != 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 = gaim_markup_strip_html(url_buffer);	stripped_len = strlen(stripped);	gaim_debug_misc("msn", "stripped = %p\n", stripped);	gaim_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));	/* Extract their Name and put it in */	found = gaim_markup_extract_info_field(stripped, stripped_len, s,			"\tName\n", 0, "\t", 0, "Undisclosed", _("Name"), 0, NULL);	if (found)		has_info = TRUE;	/* Extract their Age and put it in */	found = gaim_markup_extract_info_field(stripped, stripped_len, s,			"\tAge\n", 0, "\n", 0, "Undisclosed", _("Age"), 0, NULL);	if (found)		has_info = TRUE;	/* Extract their Gender and put it in */	found = gaim_markup_extract_info_field(stripped, stripped_len, s,			"\nGender\n", 0, "\t", 0, "Undisclosed", _("Gender"), 0,			NULL);	if (found)		has_info = TRUE;	/* Extract their MaritalStatus and put it in */	found = gaim_markup_extract_info_field(stripped, stripped_len, s,			"\tMarital Status\n", 0, "\n", 0, "Undisclosed",			_("Marital Status"), 0, NULL);	if (found)		has_info = TRUE;	/* Extract their Location and put it in */	found = gaim_markup_extract_info_field(stripped, stripped_len, s,			"\nLocation\n", 0, "\n", 0, "Undisclosed", _("Location"), 0,			NULL);	if (found)		has_info = TRUE;	/* Extract their Occupation and put it in */	found = gaim_markup_extract_info_field(stripped, stripped_len, s,			" Occupation\n", 6, "\n", 0, "Undisclosed", _("Occupation"),			0, NULL);	if (found)		has_info = TRUE;	/*	 * 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 = gaim_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);	if (!found)	{		found = gaim_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);	}	if (!found)	{		found = gaim_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);	}	if (!found)	{		found = gaim_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);	}	if (!found)	{		gaim_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);	}	if (found)		has_info = TRUE;	/* Check if they have Favorite Things */	found = gaim_markup_extract_info_field(stripped, stripped_len, s,			" Favorite Things \n\n", 0, "Hobbies and Interests", '\n', NULL,			_("Favorite Things"), 0, NULL);	if (!found)	{		found = gaim_markup_extract_info_field(stripped, stripped_len, s,				" Favorite Things \n\n", 0, "Favorite Quote", '\n', NULL,				_("Favorite Things"), 0, NULL);	}	if (!found)	{		found = gaim_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);	}	if (!found)	{		gaim_markup_extract_info_field(stripped, stripped_len, s,				" Favorite Things \n\n", 0, "last updated", '\n', NULL,				_("Favorite Things"), 0, NULL);	}	if (found)		has_info = TRUE;	/* Check if they have Hobbies and Interests */	found = gaim_markup_extract_info_field(stripped, stripped_len, s,			" Hobbies and Interests \n\n", 0, "Favorite Quote", '\n', NULL,			_("Hobbies and Interests"), 0, NULL);	if (!found)	{		found = gaim_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);	}	if (!found)	{		gaim_markup_extract_info_field(stripped, stripped_len, s,				" Hobbies and Interests \n\n", 0, "last updated", '\n', NULL,				_("Hobbies and Interests"), 0, NULL);	}	if (found)		has_info = TRUE;	/* Check if they have Favorite Quote */	found = gaim_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);	if (!found)	{		gaim_markup_extract_info_field(stripped, stripped_len, s,				"Favorite Quote \n\n", 0, "last updated", '\n', NULL,				_("Favorite Quote"), 0, NULL);	}	if (found)		has_info = TRUE;	/* Extract the last updated date and put it in */	found = gaim_markup_extract_info_field(stripped, stripped_len, s,			" last updated:", 1, "\n", 0, NULL, _("Last Updated"), 0,			NULL);	if (found)		has_info = TRUE;	/* If we were able to fetch a homepage url earlier, stick it in there */	if (user_url != NULL)	{		g_snprintf(buf, sizeof(buf),				   "<b>%s:</b><br><a href=\"%s\">%s</a><br>\n",				   _("Homepage"), user_url, user_url);		g_string_append(s, buf);		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.		 */		char *p = strstr(url_buffer, "Unknown Member </TITLE>");		GaimBuddy *b = gaim_find_buddy				(gaim_connection_get_account(info_data->gc), info_data->name);		g_string_append_printf(s, "<br><b>%s</b><br>%s<br><br>",				_("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."):					_("Gaim 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 */	g_string_append_printf(s, _("<b>%s:</b> "), _("Profile URL"));	g_string_append_printf(s, "<br><a href=\"%s%s\">%s%s</a><br>",			PROFILE_URL, info_data->name, PROFILE_URL, info_data->name);	/* Finish it off, and show it to them */	g_string_append(s, "</body></html>\n");#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->s = s;	info2_data->photo_url_text = photo_url_text;	info2_data->tooltip_text = tooltip_text;	info2_data->title = title;	/* Try to put the photo in there too, if there's one */	if (photo_url_text)	{		gaim_url_fetch(photo_url_text, FALSE, NULL, FALSE, msn_got_photo,					   info2_data);	}	else	{		/* Emulate a callback */		msn_got_photo(info2_data, NULL, 0);	}}static voidmsn_got_photo(void *data, const char *url_text, size_t len){	MsnGetInfoStepTwoData *info2_data = (MsnGetInfoStepTwoData *)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;	GString *s = info2_data->s;	char *photo_url_text = info2_data->photo_url_text;	char *tooltip_text = info2_data->tooltip_text;	const char *title = info2_data->title;	/* Try to put the photo in there too, if there's one and is readable */	if (data && url_text && len != 0)	{		if (strstr(url_text, "400 Bad Request")			|| strstr(url_text, "403 Forbidden")			|| strstr(url_text, "404 Not Found"))		{			gaim_debug_info("msn", "Error getting %s: %s\n",					photo_url_text, url_text);		}		else		{			char buf[1024];			gaim_debug_info("msn", "%s is %d bytes\n", photo_url_text, len);			id = gaim_imgstore_add(url_text, len, NULL);			g_snprintf(buf, sizeof(buf), "<img id=\"%d\"><br>", id);			g_string_prepend(s, buf);		}	}	/* We continue here from msn_got_info, as if nothing has happened */#endif	g_string_prepend(s, tooltip_text);	gaim_notify_userinfo(info_data->gc, info_data->name, NULL, 						 title, NULL, s->str, NULL, NULL);	g_free(stripped);	g_free(url_buffer);	g_string_free(s, TRUE);	g_free(tooltip_text);	g_free(info_data->name);	g_free(info_data);#if PHOTO_SUPPORT	g_free(photo_url_text);	g_free(info2_data);	if (id != -1)		gaim_imgstore_unref(id);#endif}static voidmsn_get_info(GaimConnection *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);	gaim_url_fetch(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(GaimPlugin *plugin){	msn_notification_init();	msn_switchboard_init();	msn_sync_init();	return TRUE;}static gboolean msn_unload(GaimPlugin *plugin){	msn_notification_end();	msn_switchboard_end();	msn_sync_end();	return TRUE;}static GaimPluginPrefFrame *get_plugin_pref_frame(GaimPlugin *plugin){	GaimPluginPrefFrame *frame;	GaimPluginPref *ppref;	frame = gaim_plugin_pref_frame_new();	ppref = gaim_plugin_pref_new_with_label(_("Conversations"));	gaim_plugin_pref_frame_add(frame, ppref);	ppref = gaim_plugin_pref_new_with_name_and_label(								"/plugins/prpl/msn/conv_close_notice",								_("Display conversation closed notices"));	gaim_plugin_pref_frame_add(frame, ppref);	ppref = gaim_plugin_pref_new_with_name_and_label(								"/plugins/prpl/msn/conv_timeout_notice",								_("Display timeout notices"));	gaim_plugin_pref_frame_add(frame, ppref);	return frame;}static GaimPluginUiInfo prefs_info = {	get_plugin_pref_frame};static GaimPluginProtocolInfo prpl_info ={	OPT_PROTO_MAIL_CHECK,	NULL,					/* user_splits */	NULL,					/* protocol_options */	{"png", 0, 0, 96, 96, GAIM_ICON_SCALE_SEND},	/* icon_spec */	msn_list_icon,			/* list_icon */	msn_list_emblems,		/* list_emblems */	msn_status_text,		/* status_text */	msn_tooltip_text,		/* tooltip_text */	msn_away_states,		/* 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_away,			/* 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,					/* warn */	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 */};static GaimPluginInfo info ={	GAIM_PLUGIN_MAGIC,	GAIM_MAJOR_VERSION,	GAIM_MINOR_VERSION,	GAIM_PLUGIN_PROTOCOL,                             /**< type           */	NULL,                                             /**< ui_requirement */	0,                                                /**< flags          */	NULL,                                             /**< dependencies   */	GAIM_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         */	GAIM_WEBSITE,                                     /**< homepage       */	msn_load,                                         /**< load           */	msn_unload,                                       /**< unload         */	NULL,                                             /**< destroy        */	NULL,                                             /**< ui_info        */	&prpl_info,                                       /**< extra_info     */	&prefs_info,                                      /**< prefs_info     */	msn_actions};static voidinit_plugin(GaimPlugin *plugin){	GaimAccountOption *option;	option = gaim_account_option_string_new(_("Login server"), "server",											MSN_SERVER);	prpl_info.protocol_options = g_list_append(prpl_info.protocol_options,											   option);	option = gaim_account_option_int_new(_("Port"), "port", 1863);	prpl_info.protocol_options = g_list_append(prpl_info.protocol_options,											   option);	option = gaim_account_option_bool_new(_("Use HTTP Method"),										  "http_method", FALSE);	prpl_info.protocol_options = g_list_append(prpl_info.protocol_options,											   option);	my_protocol = plugin;	gaim_prefs_add_none("/plugins/prpl/msn");	gaim_prefs_add_bool("/plugins/prpl/msn/conv_close_notice",   TRUE);	gaim_prefs_add_bool("/plugins/prpl/msn/conv_timeout_notice", TRUE);}GAIM_INIT_PLUGIN(msn, init_plugin, info);

⌨️ 快捷键说明

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