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

📄 irc.c

📁 irc message protocol stack
💻 C
📖 第 1 页 / 共 2 页
字号:
	if (gc->away) {		g_free(gc->away);		gc->away = NULL;	}	if (msg)		gc->away = g_strdup(msg);	args[0] = msg;	irc_cmd_away(irc, "away", NULL, args);}static void irc_add_buddy(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *group){	struct irc_conn *irc = (struct irc_conn *)gc->proto_data;	struct irc_buddy *ib = g_new0(struct irc_buddy, 1);	ib->name = g_strdup(buddy->name);	g_hash_table_insert(irc->buddies, ib->name, ib);	/* if the timer isn't set, this is during signon, so we don't want to flood	 * ourself off with ISON's, so we don't, but after that we want to know when	 * someone's online asap */	if (irc->timer)		irc_ison_one(irc, ib);}static void irc_remove_buddy(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *group){	struct irc_conn *irc = (struct irc_conn *)gc->proto_data;	g_hash_table_remove(irc->buddies, buddy->name);}static void irc_input_cb(gpointer data, gint source, GaimInputCondition cond){	GaimConnection *gc = data;	struct irc_conn *irc = gc->proto_data;	char *cur, *end;	int len;	if (irc->inbuflen < irc->inbufused + IRC_INITIAL_BUFSIZE) {		irc->inbuflen += IRC_INITIAL_BUFSIZE;		irc->inbuf = g_realloc(irc->inbuf, irc->inbuflen);	}	if ((len = read(irc->fd, irc->inbuf + irc->inbufused, IRC_INITIAL_BUFSIZE - 1)) < 0) {		gaim_connection_error(gc, _("Read error"));		return;	} else if (len == 0) {		gaim_connection_error(gc, _("Server has disconnected"));		return;	}	irc->inbufused += len;	irc->inbuf[irc->inbufused] = '\0';	cur = irc->inbuf;	while (cur < irc->inbuf + irc->inbufused &&	       ((end = strstr(cur, "\r\n")) || (end = strstr(cur, "\n")))) {		int step = (*end == '\r' ? 2 : 1);		*end = '\0';		irc_parse_msg(irc, cur);		cur = end + step;	}	if (cur != irc->inbuf + irc->inbufused) { /* leftover */		irc->inbufused -= (cur - irc->inbuf);		memmove(irc->inbuf, cur, irc->inbufused);	} else {		irc->inbufused = 0;	}}static void irc_chat_join (GaimConnection *gc, GHashTable *data){	struct irc_conn *irc = gc->proto_data;	const char *args[2];	args[0] = g_hash_table_lookup(data, "channel");	args[1] = g_hash_table_lookup(data, "password");	irc_cmd_join(irc, "join", NULL, args);}static char *irc_get_chat_name(GHashTable *data) {	return g_strdup(g_hash_table_lookup(data, "channel"));}static void irc_chat_invite(GaimConnection *gc, int id, const char *message, const char *name) {	struct irc_conn *irc = gc->proto_data;	GaimConversation *convo = gaim_find_chat(gc, id);	const char *args[2];	if (!convo) {		gaim_debug(GAIM_DEBUG_ERROR, "irc", "Got chat invite request for bogus chat\n");		return;	}	args[0] = name;	args[1] = gaim_conversation_get_name(convo);	irc_cmd_invite(irc, "invite", gaim_conversation_get_name(convo), args);}static void irc_chat_leave (GaimConnection *gc, int id){	struct irc_conn *irc = gc->proto_data;	GaimConversation *convo = gaim_find_chat(gc, id);	const char *args[2];	if (!convo)		return;	args[0] = gaim_conversation_get_name(convo);	args[1] = NULL;	irc_cmd_part(irc, "part", gaim_conversation_get_name(convo), args);	serv_got_chat_left(gc, id);}static int irc_chat_send(GaimConnection *gc, int id, const char *what){	struct irc_conn *irc = gc->proto_data;	GaimConversation *convo = gaim_find_chat(gc, id);	const char *args[2];	char *tmp;	if (!convo) {		gaim_debug(GAIM_DEBUG_ERROR, "irc", "chat send on nonexistent chat\n");		return -EINVAL;	}#if 0	if (*what == '/') {		return irc_parse_cmd(irc, convo->name, what + 1);	}#endif	args[0] = convo->name;	args[1] = what;	irc_cmd_privmsg(irc, "msg", NULL, args);	tmp = gaim_escape_html(what);	serv_got_chat_in(gc, id, gaim_connection_get_display_name(gc), 0, tmp, time(NULL));	g_free(tmp);	return 0;}static guint irc_nick_hash(const char *nick){	char *lc;	guint bucket;	lc = g_utf8_strdown(nick, -1);	bucket = g_str_hash(lc);	g_free(lc);	return bucket;}static gboolean irc_nick_equal(const char *nick1, const char *nick2){	return (gaim_utf8_strcasecmp(nick1, nick2) == 0);}static void irc_buddy_free(struct irc_buddy *ib){	g_free(ib->name);	g_free(ib);}static void irc_chat_set_topic(GaimConnection *gc, int id, const char *topic){	char *buf;	const char *name = NULL;	struct irc_conn *irc;	irc = gc->proto_data;	name = gaim_conversation_get_name(gaim_find_chat(gc, id));	if (name == NULL)		return;	buf = irc_format(irc, "vt:", "TOPIC", name, topic);	irc_send(irc, buf);	g_free(buf);}static GaimRoomlist *irc_roomlist_get_list(GaimConnection *gc){	struct irc_conn *irc;	GList *fields = NULL;	GaimRoomlistField *f;	char *buf;	irc = gc->proto_data;	if (irc->roomlist)		gaim_roomlist_unref(irc->roomlist);	irc->roomlist = gaim_roomlist_new(gaim_connection_get_account(gc));	f = gaim_roomlist_field_new(GAIM_ROOMLIST_FIELD_STRING, "", "channel", TRUE);	fields = g_list_append(fields, f);	f = gaim_roomlist_field_new(GAIM_ROOMLIST_FIELD_INT, _("Users"), "users", FALSE);	fields = g_list_append(fields, f);	f = gaim_roomlist_field_new(GAIM_ROOMLIST_FIELD_STRING, _("Topic"), "topic", FALSE);	fields = g_list_append(fields, f);	gaim_roomlist_set_fields(irc->roomlist, fields);	buf = irc_format(irc, "v", "LIST");	irc_send(irc, buf);	g_free(buf);	return irc->roomlist;}static void irc_roomlist_cancel(GaimRoomlist *list){	GaimConnection *gc = gaim_account_get_connection(list->account);	struct irc_conn *irc;	if (gc == NULL)		return;	irc = gc->proto_data;	gaim_roomlist_set_in_progress(list, FALSE);	if (irc->roomlist == list) {		irc->roomlist = NULL;		gaim_roomlist_unref(list);	}}static GaimPluginProtocolInfo prpl_info ={	OPT_PROTO_CHAT_TOPIC | OPT_PROTO_PASSWORD_OPTIONAL,	NULL,					/* user_splits */	NULL,					/* protocol_options */	NO_BUDDY_ICONS,			/* icon_spec */	irc_blist_icon,			/* list_icon */	irc_blist_emblems,		/* list_emblems */	NULL,					/* status_text */	NULL,					/* tooltip_text */	irc_away_states,		/* away_states */	NULL,					/* blist_node_menu */	irc_chat_join_info,		/* chat_info */	irc_chat_info_defaults,	/* chat_info_defaults */	irc_login,				/* login */	irc_close,				/* close */	irc_im_send,			/* send_im */	NULL,					/* set_info */	NULL,					/* send_typing */	irc_get_info,			/* get_info */	irc_set_away,			/* set_away */	NULL,					/* set_idle */	NULL,					/* change_passwd */	irc_add_buddy,			/* add_buddy */	NULL,					/* add_buddies */	irc_remove_buddy,		/* remove_buddy */	NULL,					/* remove_buddies */	NULL,					/* add_permit */	NULL,					/* add_deny */	NULL,					/* rem_permit */	NULL,					/* rem_deny */	NULL,					/* set_permit_deny */	NULL,					/* warn */	irc_chat_join,			/* join_chat */	NULL,					/* reject_chat */	irc_get_chat_name,		/* get_chat_name */	irc_chat_invite,		/* chat_invite */	irc_chat_leave,			/* chat_leave */	NULL,					/* chat_whisper */	irc_chat_send,			/* chat_send */	NULL,					/* keepalive */	NULL,					/* register_user */	NULL,					/* get_cb_info */	NULL,					/* get_cb_away */	NULL,					/* alias_buddy */	NULL,					/* group_buddy */	NULL,					/* rename_group */	NULL,					/* buddy_free */	NULL,					/* convo_closed */	NULL,					/* normalize */	NULL,					/* set_buddy_icon */	NULL,					/* remove_group */	NULL,					/* get_cb_real_name */	irc_chat_set_topic,		/* set_chat_topic */	NULL,					/* find_blist_chat */	irc_roomlist_get_list,	/* roomlist_get_list */	irc_roomlist_cancel,	/* roomlist_cancel */	NULL,					/* roomlist_expand_category */	NULL,					/* can_receive_file */	irc_dccsend_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-irc",                                       /**< id             */	"IRC",                                            /**< name           */	VERSION,                                          /**< version        */	N_("IRC Protocol Plugin"),                        /**  summary        */	N_("The IRC Protocol Plugin that Sucks Less"),    /**  description    */	NULL,                                             /**< author         */	GAIM_WEBSITE,                                     /**< homepage       */	NULL,                                             /**< load           */	NULL,                                             /**< unload         */	NULL,                                             /**< destroy        */	NULL,                                             /**< ui_info        */	&prpl_info,                                       /**< extra_info     */	NULL,	irc_actions};static void _init_plugin(GaimPlugin *plugin){	GaimAccountUserSplit *split;	GaimAccountOption *option;	split = gaim_account_user_split_new(_("Server"), IRC_DEFAULT_SERVER, '@');	prpl_info.user_splits = g_list_append(prpl_info.user_splits, split);	option = gaim_account_option_int_new(_("Port"), "port", IRC_DEFAULT_PORT);	prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);	option = gaim_account_option_string_new(_("Encoding"), "encoding", IRC_DEFAULT_CHARSET);	prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);	option = gaim_account_option_string_new(_("Username"), "username", "");	prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);	option = gaim_account_option_string_new(_("Real name"), "realname", "");	prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);	_irc_plugin = plugin;	irc_register_commands();}GAIM_INIT_PLUGIN(irc, _init_plugin, info);

⌨️ 快捷键说明

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