changeset 7955:119a22025818

[gaim-migrate @ 8630] fun jabber stuff, which isn't done yet. mostly harmless, and committing this now makes the next commit that much easier for a lazy person such as myself to type. committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Mon, 29 Dec 2003 08:59:22 +0000
parents 6dc91824d8d4
children 1b8261f374ea
files src/protocols/jabber/buddy.c src/protocols/jabber/chat.c src/protocols/jabber/message.c src/protocols/jabber/roster.c
diffstat 4 files changed, 148 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/protocols/jabber/buddy.c	Mon Dec 29 07:19:55 2003 +0000
+++ b/src/protocols/jabber/buddy.c	Mon Dec 29 08:59:22 2003 +0000
@@ -530,8 +530,10 @@
 	JabberBuddyResource *jbr;
 	GString *info_text;
 	char *resource_name;
+	char *bare_jid;
 	char *title;
 	xmlnode *vcard;
+	GaimBuddy *b;
 
 	if(!from)
 		return;
@@ -539,6 +541,9 @@
 	/* XXX: make this handle handle errors */
 
 	resource_name = jabber_get_resource(from);
+	bare_jid = jabber_get_bare_jid(from);
+
+	b = gaim_find_buddy(js->gc->account, bare_jid);
 
 	jb = jabber_buddy_find(js, from, TRUE);
 	info_text = g_string_new("");
@@ -580,6 +585,7 @@
 	}
 
 	g_free(resource_name);
+	g_free(bare_jid);
 
 	if((vcard = xmlnode_get_child(packet, "vCard"))) {
 		xmlnode *child;
@@ -621,6 +627,10 @@
 				}
 			} else if(text && !strcmp(child->name, "NICKNAME")) {
 				serv_got_alias(js->gc, from, text);
+				if(b) {
+					gaim_blist_node_set_string((GaimBlistNode*)b, "servernick", text);
+					gaim_blist_save();
+				}
 				g_string_append_printf(info_text, "<b>%s:</b> %s<br/>\n",
 						_("Nickname"), text);
 			} else if(text && !strcmp(child->name, "BDAY")) {
--- a/src/protocols/jabber/chat.c	Mon Dec 29 07:19:55 2003 +0000
+++ b/src/protocols/jabber/chat.c	Mon Dec 29 08:59:22 2003 +0000
@@ -367,6 +367,12 @@
 	if(!chat)
 		return;
 
+	if(!chat->muc) {
+		gaim_notify_error(chat->js->gc, _("Room Configuration Error"), _("Room Configuration Error"),
+				_("This room is not capable of being configured"));
+		return;
+	}
+
 	iq = jabber_iq_new_query(chat->js, JABBER_IQ_SET,
 			"http://jabber.org/protocol/muc#owner");
 	query = xmlnode_get_child(iq->node, "query");
@@ -403,3 +409,126 @@
 
 	g_free(room_jid);
 }
+
+static void jabber_chat_register_x_data_result_cb(JabberStream *js, xmlnode *packet, gpointer data)
+{
+	const char *type = xmlnode_get_attrib(packet, "type");
+
+	if(type && !strcmp(type, "error")) {
+		/* XXX: handle an error (you'll get a 409 if the nick is already registered) */
+	}
+}
+
+static void jabber_chat_register_x_data_cb(JabberStream *js, xmlnode *result, gpointer data)
+{
+	JabberChat *chat = data;
+	xmlnode *query;
+	JabberIq *iq;
+	char *to = g_strdup_printf("%s@%s", chat->room, chat->server);
+
+	iq = jabber_iq_new_query(js, JABBER_IQ_SET, "jabber:iq:register");
+	xmlnode_set_attrib(iq->node, "to", to);
+	g_free(to);
+
+	query = xmlnode_get_child(iq->node, "query");
+
+	xmlnode_insert_child(query, result);
+
+	jabber_iq_set_callback(iq, jabber_chat_register_x_data_result_cb, NULL);
+
+	jabber_iq_send(iq);
+}
+
+static void jabber_chat_register_cb(JabberStream *js, xmlnode *packet, gpointer data)
+{
+	xmlnode *query, *x;
+	const char *type = xmlnode_get_attrib(packet, "type");
+	const char *from = xmlnode_get_attrib(packet, "from");
+	char *msg;
+	JabberChat *chat;
+	JabberID *jid;
+
+	if(!type || !from)
+		return;
+
+	if(!strcmp(type, "result")) {
+		jid = jabber_id_new(from);
+
+		if(!jid)
+			return;
+
+		chat = jabber_chat_find(js, jid->node, jid->domain);
+		jabber_id_free(jid);
+
+		if(!chat)
+			return;
+
+		if(!(query = xmlnode_get_child(packet, "query")))
+			return;
+
+		for(x = query->child; x; x = x->next) {
+			const char *xmlns;
+			if(strcmp(x->name, "x"))
+				continue;
+
+			if(!(xmlns = xmlnode_get_attrib(x, "xmlns")))
+				continue;
+
+			if(!strcmp(xmlns, "jabber:x:data")) {
+				jabber_x_data_request(js, x, jabber_chat_register_x_data_cb, chat);
+				return;
+			}
+		}
+	} else if(!strcmp(type, "error")) {
+		/* XXX: how many places is this code duplicated?  Fix it, immediately */
+		xmlnode *errnode = xmlnode_get_child(packet, "error");
+		const char *code = NULL;
+		char *code_txt = NULL;
+		char *msg;
+		char *text = NULL;
+
+		if(errnode) {
+			code = xmlnode_get_attrib(errnode, "code");
+			text = xmlnode_get_data(errnode);
+		}
+
+		if(code)
+			code_txt = g_strdup_printf(_(" (Code %s)"), code);
+
+		msg = g_strdup_printf("%s%s", text ? text : "", code_txt ? code_txt : "");
+		gaim_notify_error(js->gc, _("Registration error"), _("Registration error"), msg);
+
+		g_free(msg);
+		if(code_txt)
+			g_free(code_txt);
+
+		return;
+	}
+
+	msg = g_strdup_printf("Unable to configure room %s", from);
+
+	gaim_notify_info(js->gc, _("Unable to configure"), _("Unable to configure"), msg);
+	g_free(msg);
+
+}
+
+void jabber_chat_register(JabberChat *chat)
+{
+	JabberIq *iq;
+	char *room_jid;
+
+	if(!chat)
+		return;
+
+	room_jid = g_strdup_printf("%s@%s", chat->room, chat->server);
+
+	iq = jabber_iq_new_query(chat->js, JABBER_IQ_GET, "jabber:iq:register");
+	xmlnode_set_attrib(iq->node, "to", room_jid);
+	g_free(room_jid);
+
+	jabber_iq_set_callback(iq, jabber_chat_register_cb, NULL);
+
+	jabber_iq_send(iq);
+}
+
+
--- a/src/protocols/jabber/message.c	Mon Dec 29 07:19:55 2003 +0000
+++ b/src/protocols/jabber/message.c	Mon Dec 29 08:59:22 2003 +0000
@@ -483,6 +483,8 @@
 	if(!strcmp(msg, "/configure") || !strcmp(msg, "/config")) {
 		jabber_chat_request_room_configure(chat);
 		return 1;
+	} else if(!strcmp(msg, "/register")) {
+		jabber_chat_register(chat);
 	}
 
 	jm = g_new0(JabberMessage, 1);
--- a/src/protocols/jabber/roster.c	Mon Dec 29 07:19:55 2003 +0000
+++ b/src/protocols/jabber/roster.c	Mon Dec 29 08:59:22 2003 +0000
@@ -55,7 +55,7 @@
 		const char *alias, GSList *groups)
 {
 	GSList *buddies, *g2, *l;
-	int present =0, idle=0, signon=0, state=0;
+	int present =0, idle=0, state=0;
 
 	buddies = gaim_find_buddies(js->gc->account, jid);
 
@@ -70,7 +70,6 @@
 
 	if(buddies) {
 		present = ((GaimBuddy*)buddies->data)->present;
-		signon = ((GaimBuddy*)buddies->data)->signon;
 		idle = ((GaimBuddy*)buddies->data)->idle;
 		state = ((GaimBuddy*)buddies->data)->uc;
 	}
@@ -82,6 +81,11 @@
 		buddies = g_slist_remove(buddies, b);
 
 		if((l = g_slist_find_custom(g2, g->name, (GCompareFunc)strcmp))) {
+			const char *servernick;
+
+			if((servernick = gaim_blist_node_get_string((GaimBlistNode*)b, "servernick")))
+				serv_got_alias(js->gc, jid, servernick);
+
 			if(alias && (!b->alias || strcmp(b->alias, alias)))
 				gaim_blist_alias_buddy(b, alias);
 			g_free(l->data);
@@ -101,11 +105,11 @@
 		}
 
 		b->present = present;
-		b->signon = signon;
 		b->idle = idle;
 		b->uc = state;
 
 		gaim_blist_add_buddy(b, NULL, g, NULL);
+		gaim_blist_alias_buddy(b, alias);
 		g_free(g2->data);
 		g2 = g_slist_delete_link(g2, g2);
 	}