changeset 7145:0e4894b3e2a6

[gaim-migrate @ 7712] all sorts of fun jabber stuff including: 1. stop calling gaim_strdup_withhtml() with NULL values 2. real support for headline-type messages 3. fix a stupid presence bug when authorizing people 4. fix login default stuff so people can log in committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Sat, 04 Oct 2003 21:19:29 +0000
parents 4d5b0c1f2e7a
children 875303d4f004
files src/protocols/jabber/buddy.c src/protocols/jabber/jabber.c src/protocols/jabber/message.c src/protocols/jabber/message.h src/protocols/jabber/presence.c
diffstat 5 files changed, 79 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/protocols/jabber/buddy.c	Sat Oct 04 21:19:17 2003 +0000
+++ b/src/protocols/jabber/buddy.c	Sat Oct 04 21:19:29 2003 +0000
@@ -557,28 +557,33 @@
 	if(resource_name) {
 		jbr = jabber_buddy_find_resource(jb, resource_name);
 		if(jbr) {
-			char *purdy = gaim_strdup_withhtml(jbr->status);
+			char *purdy = NULL;
+			if(jbr->status)
+				purdy = gaim_strdup_withhtml(jbr->status);
 			g_string_append_printf(info_text, "<b>%s:</b> %s%s%s<br/>\n",
 					_("Status"), jabber_get_state_string(jbr->state),
 					purdy ? ": " : "",
 					purdy ? purdy : "");
-			g_free(purdy);
+			if(purdy)
+				g_free(purdy);
 		} else {
 			g_string_append_printf(info_text, "<b>%s:</b> %s<br/>\n",
 					_("Status"), _("Unknown"));
 		}
 	} else {
 		for(resources = jb->resources; resources; resources = resources->next) {
-			char *purdy;
+			char *purdy = NULL;
 			jbr = resources->data;
-			purdy = gaim_strdup_withhtml(jbr->status);
+			if(jbr->status)
+				purdy = gaim_strdup_withhtml(jbr->status);
 			g_string_append_printf(info_text, "<b>%s:</b> %s<br/>\n",
 					_("Resource"), jbr->name);
 			g_string_append_printf(info_text, "<b>%s:</b> %s%s%s<br/><br/>\n",
 					_("Status"), jabber_get_state_string(jbr->state),
 					purdy ? ": " : "",
 					purdy ? purdy : "");
-			g_free(purdy);
+			if(purdy)
+				g_free(purdy);
 		}
 	}
 
--- a/src/protocols/jabber/jabber.c	Sat Oct 04 21:19:17 2003 +0000
+++ b/src/protocols/jabber/jabber.c	Sat Oct 04 21:19:29 2003 +0000
@@ -357,6 +357,13 @@
 			g_free, NULL);
 	js->user = jabber_id_new(gaim_account_get_username(account));
 
+	if(!js->user->node) {
+		js->user->node = js->user->domain;
+		js->user->domain = g_strdup("jabber.org");
+	}
+	if(!js->user->resource)
+		js->user->resource = g_strdup("Gaim");
+
 	server = connect_server[0] ? connect_server : js->user->domain;
 
 	jabber_stream_set_state(js, JABBER_STREAM_CONNECTING);
--- a/src/protocols/jabber/message.c	Sat Oct 04 21:19:17 2003 +0000
+++ b/src/protocols/jabber/message.c	Sat Oct 04 21:19:29 2003 +0000
@@ -46,11 +46,13 @@
 		g_free(jm->xhtml);
 	if(jm->password)
 		g_free(jm->password);
+	if(jm->etc)
+		g_list_free(jm->etc);
 
 	g_free(jm);
 }
 
-void handle_chat(JabberMessage *jm)
+static void handle_chat(JabberMessage *jm)
 {
 	JabberID *jid = jabber_id_new(jm->from);
 	char *from;
@@ -84,7 +86,56 @@
 	jabber_id_free(jid);
 }
 
-void handle_groupchat(JabberMessage *jm)
+static void handle_headline(JabberMessage *jm)
+{
+	char *title;
+	GString *body = g_string_new("");
+	GList *etc;
+
+	title = g_strdup_printf(_("Message from %s"), jm->from);
+
+	if(jm->xhtml)
+		g_string_append(body, jm->xhtml);
+	else if(jm->body)
+		g_string_append(body, jm->body);
+
+	for(etc = jm->etc; etc; etc = etc->next) {
+		xmlnode *x = etc->data;
+		const char *xmlns = xmlnode_get_attrib(x, "xmlns");
+		if(xmlns && !strcmp(xmlns, "jabber:x:oob")) {
+			xmlnode *url, *desc;
+			char *urltxt, *desctxt;
+
+			url = xmlnode_get_child(x, "url");
+			desc = xmlnode_get_child(x, "desc");
+
+			if(!url || !desc)
+				continue;
+
+			urltxt = xmlnode_get_data(url);
+			desctxt = xmlnode_get_data(desc);
+
+			/* I'm all about ugly hacks */
+			if(body->len && !strcmp(body->str, jm->body))
+				g_string_printf(body, "<a href='%s'>%s</a>",
+						urltxt, desctxt);
+			else
+				g_string_append_printf(body, "<br/><a href='%s'>%s</a>",
+						urltxt, desctxt);
+
+			g_free(urltxt);
+			g_free(desctxt);
+		}
+	}
+
+	gaim_notify_formatted(jm->js->gc, title, jm->subject ? jm->subject : title,
+			NULL, body->str, NULL, NULL);
+
+	g_free(title);
+	g_string_free(body, TRUE);
+}
+
+static void handle_groupchat(JabberMessage *jm)
 {
 	JabberID *jid = jabber_id_new(jm->from);
 	JabberChat *chat = jabber_chat_find(jm->js, jid->node, jid->domain);
@@ -100,7 +151,7 @@
 	jabber_id_free(jid);
 }
 
-void handle_groupchat_invite(JabberMessage *jm)
+static void handle_groupchat_invite(JabberMessage *jm)
 {
 	GHashTable *components = g_hash_table_new_full(g_str_hash, g_str_equal,
 			g_free, g_free);
@@ -115,7 +166,7 @@
 	serv_got_chat_invite(jm->js->gc, jm->to, jm->from, jm->body, components);
 }
 
-void handle_error(JabberMessage *jm)
+static void handle_error(JabberMessage *jm)
 {
 	char *buf;
 
@@ -231,6 +282,8 @@
 
 					jm->type = JABBER_MESSAGE_GROUPCHAT_INVITE;
 				}
+			} else {
+				jm->etc = g_list_append(jm->etc, child);
 			}
 		}
 	}
@@ -238,8 +291,10 @@
 	switch(jm->type) {
 		case JABBER_MESSAGE_NORMAL:
 		case JABBER_MESSAGE_CHAT:
+			handle_chat(jm);
+			break;
 		case JABBER_MESSAGE_HEADLINE:
-			handle_chat(jm);
+			handle_headline(jm);
 			break;
 		case JABBER_MESSAGE_GROUPCHAT:
 			handle_groupchat(jm);
--- a/src/protocols/jabber/message.h	Sat Oct 04 21:19:17 2003 +0000
+++ b/src/protocols/jabber/message.h	Sat Oct 04 21:19:29 2003 +0000
@@ -47,6 +47,7 @@
 	enum {
 		JABBER_MESSAGE_EVENT_COMPOSING = 1 << 1
 	} events;
+	GList *etc;
 } JabberMessage;
 
 
--- a/src/protocols/jabber/presence.c	Sat Oct 04 21:19:17 2003 +0000
+++ b/src/protocols/jabber/presence.c	Sat Oct 04 21:19:29 2003 +0000
@@ -179,6 +179,7 @@
 				_("Authorize"), G_CALLBACK(authorize_add_cb),
 				_("Deny"), G_CALLBACK(deny_add_cb));
 		g_free(msg);
+		return;
 	} else if(type && (!strcmp(type, "subscribed") ||
 				!strcmp(type, "unsubscribed"))) {
 		/* we've been allowed to see their presence, but we don't care */