From 13b4af80986847eb1b8477768683ef63b4f90576 Mon Sep 17 00:00:00 2001 From: "psyc://psyced.org/~lynX" <@> Date: Wed, 17 Mar 2010 10:19:14 +0100 Subject: [PATCH] support for XEP-0203 --- world/default/en/jabber.textdb | 8 ++++---- world/net/jabber/jabber.h | 6 +++++- world/net/jabber/mixin_parse.c | 29 +++++++++++++++++++---------- world/net/jabber/mixin_render.c | 2 ++ world/net/jabber/user.c | 2 ++ 5 files changed, 32 insertions(+), 15 deletions(-) diff --git a/world/default/en/jabber.textdb b/world/default/en/jabber.textdb index 68b98f8..52b1e52 100644 --- a/world/default/en/jabber.textdb +++ b/world/default/en/jabber.textdb @@ -189,7 +189,7 @@ _message_echo_public_action_possessive |/me 's [_action_possessive] _message_public_history -|[_data] +|[_data] _message_public_action |/me [_action] @@ -473,10 +473,10 @@ _status_description_vCard |[_INTERNAL_data_XML] _status_person_present -| +| _status_person_present_implied -| +| _status_person_present_action |{_status_person_present} @@ -491,7 +491,7 @@ _status_person_present_netburp_action |{_status_person_present_netburp} _status_person_away -|away[_action] +|away[_action] _status_person_absent |Offline diff --git a/world/net/jabber/jabber.h b/world/net/jabber/jabber.h index ad431c5..ea3f9cb 100644 --- a/world/net/jabber/jabber.h +++ b/world/net/jabber/jabber.h @@ -42,7 +42,11 @@ virtual inherit JABBER_PATH "common"; #define IMPLODE_XML(list, tag) pointerp(list) ? tag + implode(list, "" -#define JABBERTIME(gm) sprintf("%d%02d%02dT%02d:%02d:%02d", gm[TM_YEAR], gm[TM_MON] + 1, gm[TM_MDAY], gm[TM_HOUR], gm[TM_MIN], gm[TM_SEC]) +// http://xmpp.org/extensions/xep-0203.html +#define JABBERTIME(gm) sprintf("%d-%02d-%02dT%02d:%02d:%02dZ", gm[TM_YEAR], gm[TM_MON] + 1, gm[TM_MDAY], gm[TM_HOUR], gm[TM_MIN], gm[TM_SEC]) +// http://xmpp.org/extensions/xep-0091.html +#define JABBERTIMELEGACY(gm) sprintf("%d%02d%02dT%02d:%02d:%02d", gm[TM_YEAR], gm[TM_MON] + 1, gm[TM_MDAY], gm[TM_HOUR], gm[TM_MIN], gm[TM_SEC]) +// "Implementations that support XEP-0091 should support the protocol defined herein as soon as possible, but should continue to support the protocol defined in XEP-0091 for backwards compatibility until the status of that specification is changed to Obsolete." #define xbuddylist v("peoplegroups") diff --git a/world/net/jabber/mixin_parse.c b/world/net/jabber/mixin_parse.c index 1bb6d4f..a87f005 100644 --- a/world/net/jabber/mixin_parse.c +++ b/world/net/jabber/mixin_parse.c @@ -214,17 +214,26 @@ jabberMsg(XMLNode node, mixed origin, mixed *su, array(mixed) tu) { vars["_nick_place"] = vars["_INTERNAL_identification"] || origin; #if __EFUN_DEFINED__(mktime) - if (helper = getchild(node, "x", "jabber:x:delay")) { + if ((helper = getchild(node, "x", "jabber:x:delay")) || (helper = getchild(node, "x", "urn:xmpp:delay")) { string fmt = helper["@stamp"]; int *time = allocate(TM_MAX); int res; - // xep 0091 style CCYYMMDDThh:mm:ss - // 20080410T19:12:22 - res = sscanf(fmt, "%4d%2d%2dT%2d:%2d:%2d", - time[TM_YEAR], time[TM_MON], - time[TM_MDAY], time[TM_HOUR], - time[TM_MIN], time[TM_SEC]); + if (helper["@xmlns"] == "jabber:x:delay") { + // xep 0091 style CCYYMMDDThh:mm:ss + // 20080410T19:12:22 + res = sscanf(fmt, "%4d%2d%2dT%2d:%2d:%2d", + time[TM_YEAR], time[TM_MON], + time[TM_MDAY], time[TM_HOUR], + time[TM_MIN], time[TM_SEC]); + } else { + // xep 0203 style CC-YY-MMDDThh:mm:ssZ + // 2002-09-10T23:05:37Z + res = sscanf(fmt, "%d-%2d-%2dT%2d:%2d:%2dZ", + time[TM_YEAR], time[TM_MON], + time[TM_MDAY], time[TM_HOUR], + time[TM_MIN], time[TM_SEC]); + } if (res == 6) { // mktime uses month from 0 to 11, december error fixed time[TM_MON]--; @@ -690,10 +699,10 @@ jabberMsg(XMLNode node, mixed origin, mixed *su, array(mixed) tu) { int isstatus; /* see http://www.psyc.eu/presence */ // if the node contains a x element in the - // jabber:x:delay namespace this is a - // _status_presence_here + // jabber:x:delay namespace or the urm:xmpp:delay namespace + // this is a _status_presence o = summon_person(tu[UUser]); - if (helper = getchild(node, "x", "jabber:x:delay")) { + if ((helper = getchild(node, "x", "jabber:x:delay")) || (helper = getchild(node, "x", "urn:xmpp:delay"))) { isstatus = 1; } // if (!intp(isstatus)) { diff --git a/world/net/jabber/mixin_render.c b/world/net/jabber/mixin_render.c index b692b2a..3ff5401 100644 --- a/world/net/jabber/mixin_render.c +++ b/world/net/jabber/mixin_render.c @@ -28,6 +28,7 @@ int msg(string source, string mc, string data, PT(("_time_idle %O == %O, right?\n", vars["_time_idle"], t)) } t = gmtime(time() - t); + vars["_INTERNAL_time_jabber_legacy"] = JABBERTIMELEGACY(t); vars["_INTERNAL_time_jabber"] = JABBERTIME(t); } else { return 1; @@ -385,6 +386,7 @@ int msg(string source, string mc, string data, // and JEP-0091 Delayed Delivery mc = "_message_public_history"; t = gmtime(vars["_time_place"]); + vars["_INTERNAL_time_place_jabber_legacy"] = JABBERTIMELEGACY(t); vars["_INTERNAL_time_place_jabber"] = JABBERTIME(t); } else if (!vars["_context"]) { mc = "_request_message_public"; diff --git a/world/net/jabber/user.c b/world/net/jabber/user.c index d842c02..a3ab42f 100644 --- a/world/net/jabber/user.c +++ b/world/net/jabber/user.c @@ -144,8 +144,10 @@ msg(source, mc, data, mapping vars, showingLog) { P2(("_time_idle %O == %O, right?\n", vars["_time_idle"], t)) } t = gmtime(time() - t); + vars["_INTERNAL_time_jabber_legacy"] = JABBERTIMELEGACY(t); vars["_INTERNAL_time_jabber"] = JABBERTIME(t); } else { + vars["_INTERNAL_time_jabber_legacy"] = JABBERTIMELEGACY(gmtime(time())); vars["_INTERNAL_time_jabber"] = JABBERTIME(gmtime(time())); } break;