[ekg2-devel] chatstates i talk.google.com
Wiesław Ochmiński
wiechu w wiechu.com
Nie, 13 Sty 2008, 00:18:59 CET
Kłaniam!
Zrobiłem kilka poprawek by przywrócić działanie chatstates
przychodzących z talk.google.com. (google.com przysyła "<cha:composing"
a nie "<composing" i analogicznie z atrybutami: "xmlns:cha" zamiast
zakładenego "xmlns").
Z braku czasu, skoncentrowałem się wyłącznie na fragmencie kodu dotyczącym
chatstates. Oto poprawki:
============================================================================
--- jabber.h.orig 2008-01-11 12:47:52.000000000 +0100
+++ jabber.h 2008-01-12 23:40:50.000000000 +0100
@@ -200,12 +200,15 @@
void jabber_iq_auth_send(session_t *s, const char *username, const char *passwd, const char *stream_id);
char *jabber_attr(char **atts, const char *att);
+char *jabber_attr_2(char **atts, const char *att);
char *jabber_escape(const char *text);
char *jabber_unescape(const char *text);
char *tlen_encode(const char *what);
char *tlen_decode(const char *what);
int jabber_write_status(session_t *s);
+int is_xitem_name(xmlnode_t *x, const char *name);
+
void jabber_convert_string_init(int is_tlen);
void jabber_convert_string_destroy();
QUERY(jabber_convert_string_reinit);
--- misc.c.orig 2007-12-14 18:53:26.000000000 +0100
+++ misc.c 2008-01-12 23:40:14.000000000 +0100
@@ -201,6 +201,38 @@
return NULL;
}
+char *jabber_attr_2(char **atts, const char *att)
+{
+ int i;
+
+ if (!atts) return NULL;
+ for (i = 0; atts[i]; i += 2)
+ if ( ( !xstrcmp(atts[i], att) ) |
+ ( ( xstrlen(att) < xstrlen(atts[i]) ) &
+ ( *(atts[i]+ xstrlen(att)) == ':' ) &
+ ( !xstrncmp(atts[i], att, xstrlen(att)) )
+ )
+ )
+ return atts[i + 1];
+
+ return NULL;
+}
+
+int is_xitem_name(xmlnode_t *x, const char *name)
+{
+ char *s;
+
+ if (!x) return 0;
+ s = x->name;
+ while (s) {
+ if (!xstrcmp(s, name))
+ return 1;
+ s=strchr(s,':');
+ if (s) s++;
+ }
+ return 0;
+}
+
/**
* jabber_escape()
*
--- jabber_handlers.c.orig 2008-01-11 20:16:38.000000000 +0100
+++ jabber_handlers.c 2008-01-12 23:48:42.000000000 +0100
@@ -869,25 +869,25 @@
}
#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(jabber_attr_2(xitem->atts, "xmlns"), "http://jabber.org/protocol/chatstates")) {
composing = 3; /* disable + higher prio */
- if (!xstrcmp(xitem->name, "composing"))
+ if (is_xitem_name(xitem, "active")) {
+ } else if (is_xitem_name(xitem, "composing")) {
composing = 7; /* enable + higher prio */
- else if (!xstrcmp(xitem->name, "gone"))
+ } else if (is_xitem_name(xitem, "paused")) {
+ } else if (is_xitem_name(xitem, "inactive")) {
+ } else if (is_xitem_name(xitem, "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 (!xstrcmp(jabber_attr_2(xitem->atts, "xmlns"), "http://jabber.org/protocol/chatstates")) {
+ /* W życiu tu nie trafi, bo identyczny warunek powyżej. WO */
} else if (j->istlen && !xstrcmp(xitem->name, "no"))
class = EKG_MSGCLASS_SYSTEM;
else debug_error("[JABBER, MESSAGE]: <%s\n", xitem->name);
============================================================================
--
Wiesław Ochmiński, Polska Północna, Malbork.
Więcej informacji o liście dyskusyjnej ekg2-devel