[ekg2-devel] chatstates i talk.google.com

Michał Górny mgorny.hejl w mailnull.com
Sob, 19 Sty 2008, 16:18:15 CET


Ok, zmodyfikowałem to-to trochę. Tak na przyszłość - lepiej pilnuj
pamięci. Co prawda, nie sprawdziłem jeszcze, czy w ogóle działa, ale to
jak dostanę się do stacjonarki. Na razie przesyłam diffkę wzgl.
aktualnego CVS do przejrzenia i komentowania.

-- 
Z powaĹźaniem,
Michał Górny

<http://mailnull.com/w?au=f6744c6f5e097cc9816a562802f331c2>
<xmpp:mgorny w jabster.pl>
-------------- następna część ---------
Index: jabber.c
===================================================================
RCS file: /home/cvs/ekg2/plugins/jabber/jabber.c,v
retrieving revision 1.370
diff -d -u -p -r1.370 jabber.c
--- jabber.c	11 Jan 2008 22:58:06 -0000	1.370
+++ jabber.c	19 Jan 2008 15:15:10 -0000
@@ -479,7 +479,12 @@ static void xmlnode_handle_start(void *d
 	 * 	XXX, rtfm expat
 	 */
 
-        if (/* !j->node && */ !(s->connected) && ((j->istlen && !xstrcmp(name, "s")) || (!j->istlen && !xstrcmp(name, "stream:stream")))) {
+	/* (WO) Nie można, bo przetwarzanie rozpoczęoby się dopiero po skompletowaniu, czyli po otrzymaniu </stream:stream>
+	 * Wątpię, by ktoś chciał czekać aż to nastąpi, ale ładniej byłoby gdyby cała ta część po if wylądowała
+	 * w jakiejś jabber_just_like_starting_over()
+	 */
+
+        if (/* !j->node && */ !(s->connected) && ((j->istlen && !xstrcmp(name, "s")) || (!j->istlen && !xstrcmp(name, "http://etherx.jabber.org/streams#stream")))) {
 		const char *passwd	= session_get(s, "password");
 
 		char *username;
@@ -527,7 +532,23 @@ static void xmlnode_handle_start(void *d
 		int i;
 
 		newnode = xmalloc(sizeof(xmlnode_t));
-		newnode->name = xstrdup(name);
+
+		newnode->nsname = xstrdup(name);
+
+		{
+			char *x		= NULL;
+			char *tmp	= xstrdup(name);
+			char *sep	= xstrchr(tmp, '#');
+			if (sep) {
+				*(sep++) = '\0';
+				name	= sep;
+				x	= tmp;
+			}
+
+			newnode->name = xstrdup(name);
+			newnode->xmlns = xstrdup(x);
+			xfree(tmp);
+		}
 
 		if ((n = j->node)) {
 			newnode->parent = n;
@@ -547,13 +568,36 @@ static void xmlnode_handle_start(void *d
 
 /*		newnode->atts = NULL; */
 
+#define _WO_TMP_ADD_XMLNS_2_ATTS 1
+
+	    /* (WO) tymczasowo dodaję xmlns do atrybutów choć jest już pole xmlns, ale nie chciało mi się
+	     * robić poprawek w całym kodzie. Do wyrzucenia w przyszłości.
+	     */
+
+#ifdef _WO_TMP_ADD_XMLNS_2_ATTS
+		int c = x ? 3 : 1;
+		i=0;
+
+		if (arrcount +c > 1) {		/* we don't need to allocate table if arrcount = 0 */
+			newnode->atts = xmalloc((arrcount + c) * sizeof(char *));
+#else
 		if (arrcount > 0) {		/* we don't need to allocate table if arrcount = 0 */
 			newnode->atts = xmalloc((arrcount + 1) * sizeof(char *));
+#endif
 			for (i = 0; i < arrcount; i++)
 				newnode->atts[i] = xstrdup(atts[i]);
 /*			newnode->atts[i] = NULL; */
 		}
 
+#ifdef _WO_TMP_ADD_XMLNS_2_ATTS
+		if (x) {
+			newnode->atts[i++]=xstrdup("xmlns");
+			newnode->atts[i]=xstrdup(x);
+		}
+#endif
+
+		xfree(x);
+
 		j->node = newnode;
 	}
 }
@@ -769,7 +813,7 @@ static WATCHER(jabber_handle_connect_tle
 XML_Parser jabber_parser_recreate(XML_Parser parser, void *data) {
 /*	debug_function("jabber_parser_recreate() 0x%x 0x%x\n", parser, data); */
 
-	if (!parser) 	parser = XML_ParserCreate("UTF-8");	/*   new parser */
+	if (!parser) 	parser = XML_ParserCreateNS("UTF-8",'#');	/*   new parser */
 	else		XML_ParserReset(parser, "UTF-8");	/* reset parser */
 
 	XML_SetUserData(parser, (void*) data);
Index: jabber.h
===================================================================
RCS file: /home/cvs/ekg2/plugins/jabber/jabber.h,v
retrieving revision 1.81
diff -d -u -p -r1.81 jabber.h
--- jabber.h	11 Jan 2008 11:47:53 -0000	1.81
+++ jabber.h	19 Jan 2008 15:15:10 -0000
@@ -31,6 +31,8 @@ struct xmlnode_s {
 	char *name;
 	char *data; 
 	char **atts;
+	char *xmlns;
+	char *nsname;	/* WO czy nie wiem, czy komu to na coś, ale tworzę przy okazji w xmlnode_handle_start */
 
 	struct xmlnode_s *parent;
 	struct xmlnode_s *children;
Index: jabber_handlers.c
===================================================================
RCS file: /home/cvs/ekg2/plugins/jabber/jabber_handlers.c,v
retrieving revision 1.151
diff -d -u -p -r1.151 jabber_handlers.c
--- jabber_handlers.c	11 Jan 2008 19:16:38 -0000	1.151
+++ jabber_handlers.c	19 Jan 2008 15:15:10 -0000
@@ -664,8 +664,10 @@ static const struct jabber_generic_handl
 	{ "presence",		jabber_handle_presence },
 	{ "iq",			jabber_handle_iq },
 
-	{ "stream:features",	jabber_handle_stream_features },
-	{ "stream:error",	jabber_handle_stream_error },
+//	{ "stream:features",	jabber_handle_stream_features },
+	{ "features",	jabber_handle_stream_features },
+//	{ "stream:error",	jabber_handle_stream_error },
+	{ "error",	jabber_handle_stream_error },
 
 	{ "challenge",		jabber_handle_challenge },
 	{ "compressed",		jabber_handle_compressed },
@@ -869,25 +871,21 @@ JABBER_HANDLER(jabber_handle_message) {
 				}
 #endif
 			} else debug_error("[JABBER, MESSAGE]: <x xmlns=%s>\n", __(ns));
-/* x */		} else if (!xstrcmp(jabber_attr(xitem->atts, "xmlns"), "http://jabber.org/protocol/chatstates")) {
+/* x */		} else if (!xstrcmp(xitem->xmlns, "http://jabber.org/protocol/chatstates")) {
 			composing = 3;	/* disable + higher prio */
-			if (!xstrcmp(xitem->name, "composing"))
+			if (!xstrcmp(xitem->name, "active")) { 
+			} else if (!xstrcmp(xitem->name, "composing")) {
 				composing = 7; /* enable + higher prio */
-			else if (!xstrcmp(xitem->name, "gone"))
+			} else if (!xstrcmp(xitem->name, "paused")) {
+			} else if (!xstrcmp(xitem->name, "inactive")) {
+			} else if (!xstrcmp(xitem->name, "gone")) {
 				print_window(uid, s, 0, "jabber_gone", session_name(s), get_nickname(s, uid));
+			} else debug_error("[JABBER, MESSAGE]: INVALID CHATSTATE: %s\n", xitem->name);
 /* chatstate */	} else if (!xstrcmp(xitem->name, "subject")) {
 			nsubject = xitem;
 		} else if (!xstrcmp(xitem->name, "thread")) {
 			nthread = xitem;
 /* subject */	} else if (!xstrcmp(xitem->name, "body")) {
-		} /* XXX, JEP-0085 here */
-		else if (!xstrcmp(jabber_attr(xitem->atts, "xmlns"), "http://jabber.org/protocol/chatstates")) {
-			if (!xstrcmp(xitem->name, "active"))		{ }
-			else if (!xstrcmp(xitem->name, "composing"))	{ } 
-			else if (!xstrcmp(xitem->name, "paused"))	{ } 
-			else if (!xstrcmp(xitem->name, "inactive"))	{ } 
-			else if (!xstrcmp(xitem->name, "gone")) 	{ } 
-			else debug_error("[JABBER, MESSAGE]: INVALID CHATSTATE: %s\n", xitem->name);
 		} else if (j->istlen && !xstrcmp(xitem->name, "no"))
 			class = EKG_MSGCLASS_SYSTEM;
 		else debug_error("[JABBER, MESSAGE]: <%s\n", xitem->name);
Index: xmlnode.c
===================================================================
RCS file: /home/cvs/ekg2/plugins/jabber/xmlnode.c,v
retrieving revision 1.15
diff -d -u -p -r1.15 xmlnode.c
--- xmlnode.c	7 May 2007 16:14:01 -0000	1.15
+++ xmlnode.c	19 Jan 2008 15:15:10 -0000
@@ -20,6 +20,9 @@ static void xmlnode_free(xmlnode_t *n)
 		xmlnode_free(cur);
 	}
 
+	xfree(n->nsname);
+	xfree(n->xmlns);
+
 	xfree(n->name);
 	xfree(n->data);
 	array_free(n->atts);


Więcej informacji o liście dyskusyjnej ekg2-devel