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

📄 jabber.c

📁 Linux下的多协议即时通讯程序源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
PurpleChat *jabber_find_blist_chat(PurpleAccount *account, const char *name){	PurpleBlistNode *gnode, *cnode;	JabberID *jid;	if(!(jid = jabber_id_new(name)))		return NULL;	for(gnode = purple_get_blist()->root; gnode; gnode = gnode->next) {		for(cnode = gnode->child; cnode; cnode = cnode->next) {			PurpleChat *chat = (PurpleChat*)cnode;			const char *room, *server;			if(!PURPLE_BLIST_NODE_IS_CHAT(cnode))				continue;			if(chat->account != account)				continue;			if(!(room = g_hash_table_lookup(chat->components, "room")))				continue;			if(!(server = g_hash_table_lookup(chat->components, "server")))				continue;			if(jid->node && jid->domain &&					!g_utf8_collate(room, jid->node) && !g_utf8_collate(server, jid->domain)) {				jabber_id_free(jid);				return chat;			}		}	}	jabber_id_free(jid);	return NULL;}void jabber_convo_closed(PurpleConnection *gc, const char *who){	JabberStream *js = gc->proto_data;	JabberID *jid;	JabberBuddy *jb;	JabberBuddyResource *jbr;	if(!(jid = jabber_id_new(who)))		return;	if((jb = jabber_buddy_find(js, who, TRUE)) &&			(jbr = jabber_buddy_find_resource(jb, jid->resource))) {		if(jbr->thread_id) {			g_free(jbr->thread_id);			jbr->thread_id = NULL;		}		if(jbr->chat_states == JABBER_CHAT_STATES_SUPPORTED)			jabber_message_conv_closed(js, who);	}	jabber_id_free(jid);}char *jabber_parse_error(JabberStream *js, xmlnode *packet){	xmlnode *error;	const char *code = NULL, *text = NULL;	const char *xmlns = xmlnode_get_namespace(packet);	char *cdata = NULL;	if((error = xmlnode_get_child(packet, "error"))) {		cdata = xmlnode_get_data(error);		code = xmlnode_get_attrib(error, "code");		/* Stanza errors */		if(xmlnode_get_child(error, "bad-request")) {			text = _("Bad Request");		} else if(xmlnode_get_child(error, "conflict")) {			text = _("Conflict");		} else if(xmlnode_get_child(error, "feature-not-implemented")) {			text = _("Feature Not Implemented");		} else if(xmlnode_get_child(error, "forbidden")) {			text = _("Forbidden");		} else if(xmlnode_get_child(error, "gone")) {			text = _("Gone");		} else if(xmlnode_get_child(error, "internal-server-error")) {			text = _("Internal Server Error");		} else if(xmlnode_get_child(error, "item-not-found")) {			text = _("Item Not Found");		} else if(xmlnode_get_child(error, "jid-malformed")) {			text = _("Malformed XMPP ID");		} else if(xmlnode_get_child(error, "not-acceptable")) {			text = _("Not Acceptable");		} else if(xmlnode_get_child(error, "not-allowed")) {			text = _("Not Allowed");		} else if(xmlnode_get_child(error, "not-authorized")) {			text = _("Not Authorized");		} else if(xmlnode_get_child(error, "payment-required")) {			text = _("Payment Required");		} else if(xmlnode_get_child(error, "recipient-unavailable")) {			text = _("Recipient Unavailable");		} else if(xmlnode_get_child(error, "redirect")) {			/* XXX */		} else if(xmlnode_get_child(error, "registration-required")) {			text = _("Registration Required");		} else if(xmlnode_get_child(error, "remote-server-not-found")) {			text = _("Remote Server Not Found");		} else if(xmlnode_get_child(error, "remote-server-timeout")) {			text = _("Remote Server Timeout");		} else if(xmlnode_get_child(error, "resource-constraint")) {			text = _("Server Overloaded");		} else if(xmlnode_get_child(error, "service-unavailable")) {			text = _("Service Unavailable");		} else if(xmlnode_get_child(error, "subscription-required")) {			text = _("Subscription Required");		} else if(xmlnode_get_child(error, "unexpected-request")) {			text = _("Unexpected Request");		} else if(xmlnode_get_child(error, "undefined-condition")) {			text = _("Unknown Error");		}	} else if(xmlns && !strcmp(xmlns, "urn:ietf:params:xml:ns:xmpp-sasl")) {		if(xmlnode_get_child(packet, "aborted")) {			js->gc->wants_to_die = TRUE;			text = _("Authorization Aborted");		} else if(xmlnode_get_child(packet, "incorrect-encoding")) {			text = _("Incorrect encoding in authorization");		} else if(xmlnode_get_child(packet, "invalid-authzid")) {			js->gc->wants_to_die = TRUE;			text = _("Invalid authzid");		} else if(xmlnode_get_child(packet, "invalid-mechanism")) {			js->gc->wants_to_die = TRUE;			text = _("Invalid Authorization Mechanism");		} else if(xmlnode_get_child(packet, "mechanism-too-weak")) {			js->gc->wants_to_die = TRUE;			text = _("Authorization mechanism too weak");		} else if(xmlnode_get_child(packet, "not-authorized")) {			js->gc->wants_to_die = TRUE;			text = _("Not Authorized");		} else if(xmlnode_get_child(packet, "temporary-auth-failure")) {			text = _("Temporary Authentication Failure");		} else {			js->gc->wants_to_die = TRUE;			text = _("Authentication Failure");		}	} else if(!strcmp(packet->name, "stream:error") ||			 (!strcmp(packet->name, "error") &&				!strcmp(xmlns, "http://etherx.jabber.org/streams"))) {		if(xmlnode_get_child(packet, "bad-format")) {			text = _("Bad Format");		} else if(xmlnode_get_child(packet, "bad-namespace-prefix")) {			text = _("Bad Namespace Prefix");		} else if(xmlnode_get_child(packet, "conflict")) {			js->gc->wants_to_die = TRUE;			text = _("Resource Conflict");		} else if(xmlnode_get_child(packet, "connection-timeout")) {			text = _("Connection Timeout");		} else if(xmlnode_get_child(packet, "host-gone")) {			text = _("Host Gone");		} else if(xmlnode_get_child(packet, "host-unknown")) {			text = _("Host Unknown");		} else if(xmlnode_get_child(packet, "improper-addressing")) {			text = _("Improper Addressing");		} else if(xmlnode_get_child(packet, "internal-server-error")) {			text = _("Internal Server Error");		} else if(xmlnode_get_child(packet, "invalid-id")) {			text = _("Invalid ID");		} else if(xmlnode_get_child(packet, "invalid-namespace")) {			text = _("Invalid Namespace");		} else if(xmlnode_get_child(packet, "invalid-xml")) {			text = _("Invalid XML");		} else if(xmlnode_get_child(packet, "nonmatching-hosts")) {			text = _("Non-matching Hosts");		} else if(xmlnode_get_child(packet, "not-authorized")) {			text = _("Not Authorized");		} else if(xmlnode_get_child(packet, "policy-violation")) {			text = _("Policy Violation");		} else if(xmlnode_get_child(packet, "remote-connection-failed")) {			text = _("Remote Connection Failed");		} else if(xmlnode_get_child(packet, "resource-constraint")) {			text = _("Resource Constraint");		} else if(xmlnode_get_child(packet, "restricted-xml")) {			text = _("Restricted XML");		} else if(xmlnode_get_child(packet, "see-other-host")) {			text = _("See Other Host");		} else if(xmlnode_get_child(packet, "system-shutdown")) {			text = _("System Shutdown");		} else if(xmlnode_get_child(packet, "undefined-condition")) {			text = _("Undefined Condition");		} else if(xmlnode_get_child(packet, "unsupported-encoding")) {			text = _("Unsupported Encoding");		} else if(xmlnode_get_child(packet, "unsupported-stanza-type")) {			text = _("Unsupported Stanza Type");		} else if(xmlnode_get_child(packet, "unsupported-version")) {			text = _("Unsupported Version");		} else if(xmlnode_get_child(packet, "xml-not-well-formed")) {			text = _("XML Not Well Formed");		} else {			text = _("Stream Error");		}	}	if(text || cdata) {		char *ret = g_strdup_printf("%s%s%s", code ? code : "",				code ? ": " : "", text ? text : cdata);		g_free(cdata);		return ret;	} else {		return NULL;	}}static PurpleCmdRet jabber_cmd_chat_config(PurpleConversation *conv,		const char *cmd, char **args, char **error, void *data){	JabberChat *chat = jabber_chat_find_by_conv(conv);	jabber_chat_request_room_configure(chat);	return PURPLE_CMD_RET_OK;}static PurpleCmdRet jabber_cmd_chat_register(PurpleConversation *conv,		const char *cmd, char **args, char **error, void *data){	JabberChat *chat = jabber_chat_find_by_conv(conv);	jabber_chat_register(chat);	return PURPLE_CMD_RET_OK;}static PurpleCmdRet jabber_cmd_chat_topic(PurpleConversation *conv,		const char *cmd, char **args, char **error, void *data){	JabberChat *chat = jabber_chat_find_by_conv(conv);	jabber_chat_change_topic(chat, args ? args[0] : NULL);	return PURPLE_CMD_RET_OK;}static PurpleCmdRet jabber_cmd_chat_nick(PurpleConversation *conv,		const char *cmd, char **args, char **error, void *data){	JabberChat *chat = jabber_chat_find_by_conv(conv);	if(!args || !args[0])		return PURPLE_CMD_RET_FAILED;	jabber_chat_change_nick(chat, args[0]);	return PURPLE_CMD_RET_OK;}static PurpleCmdRet jabber_cmd_chat_part(PurpleConversation *conv,		const char *cmd, char **args, char **error, void *data){	JabberChat *chat = jabber_chat_find_by_conv(conv);	jabber_chat_part(chat, args ? args[0] : NULL);	return PURPLE_CMD_RET_OK;}static PurpleCmdRet jabber_cmd_chat_ban(PurpleConversation *conv,		const char *cmd, char **args, char **error, void *data){	JabberChat *chat = jabber_chat_find_by_conv(conv);	if(!args || !args[0])		return PURPLE_CMD_RET_FAILED;	if(!jabber_chat_ban_user(chat, args[0], args[1])) {		*error = g_strdup_printf(_("Unable to ban user %s"), args[0]);		return PURPLE_CMD_RET_FAILED;	}	return PURPLE_CMD_RET_OK;}static PurpleCmdRet jabber_cmd_chat_affiliate(PurpleConversation *conv,		const char *cmd, char **args, char **error, void *data){	JabberChat *chat = jabber_chat_find_by_conv(conv);	if (!args || !args[0] || !args[1])		return PURPLE_CMD_RET_FAILED;	if (strcmp(args[1], "owner") != 0 && 	    strcmp(args[1], "admin") != 0 &&	    strcmp(args[1], "member") != 0 &&	    strcmp(args[1], "outcast") != 0 &&	    strcmp(args[1], "none") != 0) {		*error = g_strdup_printf(_("Unknown affiliation: \"%s\""), args[1]);		return PURPLE_CMD_RET_FAILED;	}	if (!jabber_chat_affiliate_user(chat, args[0], args[1])) {		*error = g_strdup_printf(_("Unable to affiliate user %s as \"%s\""), args[0], args[1]);		return PURPLE_CMD_RET_FAILED;	}	return PURPLE_CMD_RET_OK;}static PurpleCmdRet jabber_cmd_chat_role(PurpleConversation *conv,		const char *cmd, char **args, char **error, void *data){	JabberChat *chat;	if (!args || !args[0] || !args[1])		return PURPLE_CMD_RET_FAILED;	if (strcmp(args[1], "moderator") != 0 &&	    strcmp(args[1], "participant") != 0 &&	    strcmp(args[1], "visitor") != 0 &&	    strcmp(args[1], "none") != 0) {		*error = g_strdup_printf(_("Unknown role: \"%s\""), args[1]);		return PURPLE_CMD_RET_FAILED;	}	chat = jabber_chat_find_by_conv(conv);	if (!jabber_chat_role_user(chat, args[0], args[1])) {		*error = g_strdup_printf(_("Unable to set role \"%s\" for user: %s"),		                         args[1], args[0]);		return PURPLE_CMD_RET_FAILED;	}	return PURPLE_CMD_RET_OK;}static PurpleCmdRet jabber_cmd_chat_invite(PurpleConversation *conv,		const char *cmd, char **args, char **error, void *data){	if(!args || !args[0])		return PURPLE_CMD_RET_FAILED;	jabber_chat_invite(purple_conversation_get_gc(conv),			purple_conv_chat_get_id(PURPLE_CONV_CHAT(conv)), args[1] ? args[1] : "",			args[0]);	return PURPLE_CMD_RET_OK;}static PurpleCmdRet jabber_cmd_chat_join(PurpleConversation *conv,		const char *cmd, char **args, char **error, void *data){	JabberChat *chat = jabber_chat_find_by_conv(conv);	GHashTable *components;	if(!args || !args[0])		return PURPLE_CMD_RET_FAILED;	components = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL);	g_hash_table_replace(components, "room", args[0]);	g_hash_table_replace(components, "server", chat->server);	g_hash_table_replace(components, "handle", chat->handle);	if(args[1])		g_hash_table_replace(components, "password", args[1]);	jabber_chat_join(purple_conversation_get_gc(conv), components);	g_hash_table_destroy(components);	return PURPLE_CMD_RET_OK;}static PurpleCmdRet jabber_cmd_chat_kick(PurpleConversation *conv,		const char *cmd, char **args, char **error, void *data){	JabberChat *chat = jabber_chat_find_by_conv(conv);	if(!args || !args[0])		return PURPLE_CMD_RET_FAILED;	if(!jabber_chat_kick_user(chat, args[0], args[1])) {		*error = g_strdup_printf(_("Unable to kick user %s"), args[0]);		return PURPLE_CMD_RET_FAILED;	}	return PURPLE_CMD_RET_OK;}static PurpleCmdRet jabber_cmd_chat_msg(PurpleConversation *conv,		const char *cmd, char **args, char **error, void *data){	JabberChat *chat = jabber_chat_find_by_conv(conv);	char *who;	who = g_strdup_printf("%s@%s/%s", chat->room, chat->server, args[0]);	jabber_message_send_im(purple_conversation_get_gc(conv), who, args[1], 0);	g_free(who);	return PURPLE_CMD_RET_OK;}gboolean jabber_offline_message(const PurpleBuddy *buddy){	return TRUE;}void jabber_register_commands(void){	purple_cmd_register("config", "", PURPLE_CMD_P_PRPL,	                  PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_PRPL_ONLY,	                  "prpl-jabber", jabber_cmd_chat_config,	                  _("config:  Configure a chat room."), NULL);	purple_cmd_register("configure", "", PURPLE_CMD_P_PRPL,	                  PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_PRPL_ONLY,	                  "prpl-jabber", jabber_cmd_chat_config,	                  _("configure:  Configure a chat room."), NULL);	purple_cmd_register("nick", "s", PURPLE_CMD_P_PRPL,	                  PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_PRPL_ONLY,	                  "prpl-jabber", jabber_cmd_chat_nick,	                  _("nick <new nickname>:  Change your nickname."),	                  NULL);	purple_cmd_register("part", "s", PURPLE_CMD_P_PRPL,	                  PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_PRPL_ONLY |	                  PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-jabber",	                  jabber_cmd_chat_part, _("part [room]:  Leave the room."),	                  NULL);	purple_cmd_register("register", "", PURPLE_CMD_P_PRPL,	                  PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_PRPL_ONLY,	                  "prpl-jabber", jabber_cmd_chat_register,	                  _("register:  Register with a chat room."), NULL);	/* XXX: there needs to be a core /topic cmd, methinks */	purple_cmd_register("topic", "s", PURPLE_CMD_P_PRPL,	                  PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_PRPL_ONLY |	                  PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-jabber",	                  jabber_cmd_chat_topic,	                  _("topic [new topic]:  View or change the topic."),	                  NULL);	purple_cmd_register("ban", "ws", PURPLE_CMD_P_PRPL,	                  PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_PRPL_ONLY |	                  PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-jabber",	                  jabber_cmd_chat_ban,	                  _("ban <user> [room]:  Ban a user from the room."),	                  NULL);	purple_cmd_register("affiliate", "ws", PURPLE_CMD_P_PRPL,	                  PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_PRPL_ONLY |	                  PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-jabber",	                  jabber_cmd_chat_affiliate,	                  _("affiliate <user> <owner|admin|member|outcast|none>: Set a user's affiliation with the room."),	                  NULL);	purple_cmd_register("role", "ws", PURPLE_CMD_P_PRPL,	                  PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_PRPL_ONLY |	                  PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-jabber",	                  jabber_cmd_chat_role,	                  _("role <user> <moderator|participant|visitor|none>: Set a user's role in the room."),	                  NULL);	purple_cmd_register("invite", "ws", PURPLE_CMD_P_PRPL,	                  PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_PRPL_ONLY |	                  PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-jabber",	                  jabber_cmd_chat_invite,	                  _("invite <user> [message]:  Invite a user to the room."),	                  NULL);	purple_cmd_register("join", "ws", PURPLE_CMD_P_PRPL,	                  PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_PRPL_ONLY |	                  PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-jabber",	                  jabber_cmd_chat_join,	                  _("join: <room> [server]:  Join a chat on this server."),	                  NULL);	purple_cmd_register("kick", "ws", PURPLE_CMD_P_PRPL,	                  PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_PRPL_ONLY |	                  PURPLE_CMD_FLAG_ALLOW_WRONG_ARGS, "prpl-jabber",	                  jabber_cmd_chat_kick,	                  _("kick <user> [room]:  Kick a user from the room."),	                  NULL);	purple_cmd_register("msg", "ws", PURPLE_CMD_P_PRPL,	                  PURPLE_CMD_FLAG_CHAT | PURPLE_CMD_FLAG_PRPL_ONLY,	                  "prpl-jabber", jabber_cmd_chat_msg,	                  _("msg <user> <message>:  Send a private message to another user."),	                  NULL);}voidjabber_init_plugin(PurplePlugin *plugin){        my_protocol = plugin;}

⌨️ 快捷键说明

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