changeset 17561:a75079eae085

added preliminary frame for pep-support
author Andreas Monitzer <pidgin@monitzer.com>
date Wed, 06 Jun 2007 00:01:15 +0000
parents f41a561e3b7b
children 6ab1089e2101
files libpurple/protocols/jabber/disco.c libpurple/protocols/jabber/jabber.c libpurple/protocols/jabber/message.c libpurple/protocols/jabber/message.h libpurple/protocols/jabber/pep.c libpurple/protocols/jabber/pep.h
diffstat 6 files changed, 95 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/jabber/disco.c	Tue Jun 05 16:31:20 2007 +0000
+++ b/libpurple/protocols/jabber/disco.c	Wed Jun 06 00:01:15 2007 +0000
@@ -30,6 +30,7 @@
 #include "jabber.h"
 #include "presence.h"
 #include "roster.h"
+#include "pep.h"
 
 struct _jabber_disco_info_cb_data {
 	gpointer data;
@@ -261,9 +262,13 @@
 	     child = xmlnode_get_next_twin(child)) {
 		const char *category, *type, *name;
 		category = xmlnode_get_attrib(child, "category");
+		type = xmlnode_get_attrib(child, "type");
+        if(category && type && !strcmp(category, "pubsub") && !strcmp(type,"pep")) {
+            /* server supports pep, initialize it */
+            jabber_pep_init(js);
+        }
 		if (!category || strcmp(category, "server"))
 			continue;
-		type = xmlnode_get_attrib(child, "type");
 		if (!type || strcmp(type, "im"))
 			continue;
 
--- a/libpurple/protocols/jabber/jabber.c	Tue Jun 05 16:31:20 2007 +0000
+++ b/libpurple/protocols/jabber/jabber.c	Wed Jun 06 00:01:15 2007 +0000
@@ -53,6 +53,7 @@
 #include "roster.h"
 #include "si.h"
 #include "xdata.h"
+#include "pep.h"
 
 #define JABBER_CONNECT_STEPS (js->gsc ? 8 : 5)
 
--- a/libpurple/protocols/jabber/message.c	Tue Jun 05 16:31:20 2007 +0000
+++ b/libpurple/protocols/jabber/message.c	Wed Jun 06 00:01:15 2007 +0000
@@ -30,6 +30,7 @@
 #include "google.h"
 #include "message.h"
 #include "xmlnode.h"
+#include "pep.h"
 
 void jabber_message_free(JabberMessage *jm)
 {
@@ -308,22 +309,25 @@
 	jm->id = g_strdup(xmlnode_get_attrib(packet, "id"));
 
 	for(child = packet->child; child; child = child->next) {
+        const char *xmlns = xmlnode_get_namespace(child);
+        if(!xmlns)
+            xmlns = "";
 		if(child->type != XMLNODE_TYPE_TAG)
 			continue;
 
-		if(!strcmp(child->name, "subject")) {
+		if(!strcmp(child->name, "subject") && strlen(xmlns) == 0) {
 			if(!jm->subject)
 				jm->subject = xmlnode_get_data(child);
-		} else if(!strcmp(child->name, "thread")) {
+		} else if(!strcmp(child->name, "thread") && strlen(xmlns) == 0) {
 			if(!jm->thread_id)
 				jm->thread_id = xmlnode_get_data(child);
-		} else if(!strcmp(child->name, "body")) {
+		} else if(!strcmp(child->name, "body") && strlen(xmlns) == 0) {
 			if(!jm->body) {
 				char *msg = xmlnode_to_str(child, NULL);
 				jm->body = purple_strdup_withhtml(msg);
 				g_free(msg);
 			}
-		} else if(!strcmp(child->name, "html")) {
+		} else if(!strcmp(child->name, "html") && !strcmp(xmlns,"http://jabber.org/protocol/xhtml-im")) {
 			if(!jm->xhtml && xmlnode_get_child(child, "body")) {
 				char *c;
 				jm->xhtml = xmlnode_to_str(child, NULL);
@@ -335,21 +339,27 @@
 						*c = ' ';
 				}
 			}
-		} else if(!strcmp(child->name, "active")) {
+		} else if(!strcmp(child->name, "active") && !strcmp(xmlns,"http://jabber.org/protocol/chatstates")) {
 			jm->chat_state = JM_STATE_ACTIVE;
 			jm->typing_style |= JM_TS_JEP_0085;
-		} else if(!strcmp(child->name, "composing")) {
+		} else if(!strcmp(child->name, "composing") && !strcmp(xmlns,"http://jabber.org/protocol/chatstates")) {
 			jm->chat_state = JM_STATE_COMPOSING;
 			jm->typing_style |= JM_TS_JEP_0085;
-		} else if(!strcmp(child->name, "paused")) {
+		} else if(!strcmp(child->name, "paused") && !strcmp(xmlns,"http://jabber.org/protocol/chatstates")) {
 			jm->chat_state = JM_STATE_PAUSED;
 			jm->typing_style |= JM_TS_JEP_0085;
-		} else if(!strcmp(child->name, "inactive")) {
+		} else if(!strcmp(child->name, "inactive") && !strcmp(xmlns,"http://jabber.org/protocol/chatstates")) {
 			jm->chat_state = JM_STATE_INACTIVE;
 			jm->typing_style |= JM_TS_JEP_0085;
-		} else if(!strcmp(child->name, "gone")) {
+		} else if(!strcmp(child->name, "gone") && !strcmp(xmlns,"http://jabber.org/protocol/chatstates")) {
 			jm->chat_state = JM_STATE_GONE;
 			jm->typing_style |= JM_TS_JEP_0085;
+		} else if(!strcmp(child->name, "event") && jm->type == JABBER_MESSAGE_HEADLINE &&
+                  !strcmp(xmlns,"http://jabber.org/protocol/pubsub#event")) {
+            xmlnode *items;
+            jm->type = JABBER_MESSAGE_EVENT;
+            for(items = child->child; child; child = child->next)
+                jm->eventitems = g_list_append(jm->eventitems, items);
 		} else if(!strcmp(child->name, "error")) {
 			const char *code = xmlnode_get_attrib(child, "code");
 			char *code_txt = NULL;
@@ -365,7 +375,6 @@
 			g_free(code_txt);
 			g_free(text);
 		} else if(!strcmp(child->name, "x")) {
-			const char *xmlns = xmlnode_get_namespace(child);
 			if(xmlns && !strcmp(xmlns, "jabber:x:event")) {
 				if(xmlnode_get_child(child, "composing")) {
 					if(jm->chat_state == JM_STATE_ACTIVE)
@@ -425,6 +434,9 @@
 		case JABBER_MESSAGE_GROUPCHAT_INVITE:
 			handle_groupchat_invite(jm);
 			break;
+        case JABBER_MESSAGE_EVENT:
+            jabber_handle_event(jm);
+            break;
 		case JABBER_MESSAGE_ERROR:
 			handle_error(jm);
 			break;
@@ -461,6 +473,7 @@
 			type = "error";
 			break;
 		case JABBER_MESSAGE_OTHER:
+        default:
 			type = NULL;
 			break;
 	}
--- a/libpurple/protocols/jabber/message.h	Tue Jun 05 16:31:20 2007 +0000
+++ b/libpurple/protocols/jabber/message.h	Wed Jun 06 00:01:15 2007 +0000
@@ -35,6 +35,7 @@
 		JABBER_MESSAGE_HEADLINE,
 		JABBER_MESSAGE_ERROR,
 		JABBER_MESSAGE_GROUPCHAT_INVITE,
+        JABBER_MESSAGE_EVENT,
 		JABBER_MESSAGE_OTHER
 	} type;
 	time_t sent;
@@ -61,6 +62,7 @@
 		JM_STATE_GONE
 	} chat_state;
 	GList *etc;
+    GList *eventitems;
 } JabberMessage;
 
 void jabber_message_free(JabberMessage *jm);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libpurple/protocols/jabber/pep.c	Wed Jun 06 00:01:15 2007 +0000
@@ -0,0 +1,31 @@
+/*
+ * purple - Jabber Protocol Plugin
+ *
+ * Copyright (C) 2007, Andreas Monitzer <andy@monitzer.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+
+#include "pep.h"
+
+void jabber_pep_init(JabberStream *js) {
+    
+}
+
+void jabber_handle_event(JabberMessage *jm) {
+    /* this may be called even when the own server doesn't support pep! */
+    
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libpurple/protocols/jabber/pep.h	Wed Jun 06 00:01:15 2007 +0000
@@ -0,0 +1,32 @@
+/*
+ * purple - Jabber Protocol Plugin
+ *
+ * Copyright (C) 2007, Andreas Monitzer <andy@monitzer.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+
+#ifndef _PURPLE_JABBER_PEP_H_
+#define _PURPLE_JABBER_PEP_H_
+
+#include "jabber.h"
+#include "message.h"
+
+void jabber_pep_init(JabberStream *js);
+
+void jabber_handle_event(JabberMessage *jm);
+
+#endif /* _PURPLE_JABBER_PEP_H_ */