Changeset 371

Show
Ignore:
Timestamp:
05/09/07 17:05:29 (15 months ago)
Author:
smoku
Message:

Implemented XEP-0202: Entity Time. Closes #144

Location:
trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/sm/mod_iq_time.c

    r2 r371  
    2828  */ 
    2929 
    30 #define uri_TIME    "jabber:iq:time" 
     30#ifdef ENABLE_SUPERSEDED 
    3131static int ns_TIME = 0; 
     32#endif 
     33static int ns_URN_TIME = 0; 
    3234 
    3335#ifdef HAVE_TZNAME 
     
    4345 
    4446    /* we only want to play with iq:time gets */ 
    45     if(pkt->type != pkt_IQ || pkt->ns != ns_TIME) 
     47#ifdef ENABLE_SUPERSEDED 
     48    if(pkt->type != pkt_IQ || (pkt->ns != ns_TIME && pkt->ns != ns_URN_TIME)) 
     49#else 
     50    if(pkt->type != pkt_IQ || pkt->ns != ns_URN_TIME) 
     51#endif 
    4652        return mod_PASS; 
    4753 
    4854    t = time(NULL); 
     55    tm = localtime(&t); 
     56#ifdef HAVE_TZSET 
     57    tzset(); 
     58#endif 
    4959 
    50     sm_timestamp(t, buf); 
     60#ifdef ENABLE_SUPERSEDED 
     61    if(pkt->ns == ns_TIME) { 
     62        datetime_out(t, dt_LEGACY, buf, 64); 
     63        nad_insert_elem(pkt->nad, 2, NAD_ENS(pkt->nad, 1), "utc", buf); 
     64 
     65        strcpy(buf, asctime(tm)); 
     66        c = strchr(buf, '\n'); 
     67        if(c != NULL) 
     68            *c = '\0'; 
     69        nad_insert_elem(pkt->nad, 2, NAD_ENS(pkt->nad, 1), "display", buf); 
     70#if defined(HAVE_STRUCT_TM_TM_ZONE) 
     71        nad_insert_elem(pkt->nad, 2, NAD_ENS(pkt->nad, 1), "tz", (char *) tm->tm_zone); 
     72#elif defined(HAVE_TZNAME) 
     73        nad_insert_elem(pkt->nad, 2, NAD_ENS(pkt->nad, 1), "tz", tzname[0]); 
     74#endif 
     75    } else { 
     76#endif /* ENABLE_SUPERSEDED */ 
     77 
     78    datetime_out(t, dt_DATETIME, buf, 64); 
    5179    nad_insert_elem(pkt->nad, 2, NAD_ENS(pkt->nad, 1), "utc", buf); 
    5280 
    53     tm = localtime(&t); 
     81    snprintf(buf, 64, "%+03d:%02d", (int) -timezone/(60*60), (int) -timezone%(60*60)); 
     82    nad_insert_elem(pkt->nad, 2, NAD_ENS(pkt->nad, 1), "tzo", buf); 
    5483 
    55     strcpy(buf, asctime(tm)); 
    56     c = strchr(buf, '\n'); 
    57     if(c != NULL) 
    58         *c = '\0'; 
    59     nad_insert_elem(pkt->nad, 2, NAD_ENS(pkt->nad, 1), "display", buf); 
    60      
    61     tzset(); 
    62 #if defined(HAVE_STRUCT_TM_TM_ZONE) 
    63     nad_insert_elem(pkt->nad, 2, NAD_ENS(pkt->nad, 1), "tz", (char *) tm->tm_zone); 
    64 #elif defined(HAVE_TZNAME) 
    65     nad_insert_elem(pkt->nad, 2, NAD_ENS(pkt->nad, 1), "tz", tzname[0]); 
     84#ifdef ENABLE_SUPERSEDED 
     85    } 
    6686#endif 
    67  
    6887    /* tell them */ 
    6988    nad_set_attr(pkt->nad, 1, -1, "type", "result", 6); 
     
    86105    mod->free = _iq_time_free; 
    87106 
     107#ifdef ENABLE_SUPERSEDED 
    88108    ns_TIME = sm_register_ns(mod->mm->sm, uri_TIME); 
    89109    feature_register(mod->mm->sm, uri_TIME); 
     110#endif 
     111    ns_URN_TIME = sm_register_ns(mod->mm->sm, uri_URN_TIME); 
     112    feature_register(mod->mm->sm, uri_URN_TIME); 
    90113 
    91114    return 0; 
  • trunk/sm/sm.c

    r233 r371  
    262262} 
    263263 
    264 /** this was jutil_timestamp in a former life */ 
    265 void sm_timestamp(time_t t, char timestamp[18]) 
    266 { 
    267     struct tm *gm = gmtime(&t); 
    268  
    269     snprintf(timestamp, 18, "%d%02d%02dT%02d:%02d:%02d", 1900 + gm->tm_year, 
    270              gm->tm_mon + 1, gm->tm_mday, gm->tm_hour, gm->tm_min, gm->tm_sec); 
    271  
    272     return; 
    273 } 
    274  
    275264/** send a new action route */ 
    276265void sm_c2s_action(sess_t dest, char *action, char *target) { 
  • trunk/util/uri.h

    r287 r371  
    2929#define INCL_UTIL_URI_H 1 
    3030 
     31#define uri_XML         "http://www.w3.org/XML/1998/namespace" 
     32 
    3133/* known namespace uri */ 
    3234#define uri_STREAMS     "http://etherx.jabber.org/streams" 
     
    3436#define uri_SERVER      "jabber:server" 
    3537#define uri_DIALBACK    "jabber:server:dialback" 
     38#define uri_DIALBACK_L  22      /* strlen(uri_DIALBACK) */ 
    3639#define uri_TLS         "urn:ietf:params:xml:ns:xmpp-tls" 
    3740#define uri_SASL        "urn:ietf:params:xml:ns:xmpp-sasl" 
    3841#define uri_BIND        "urn:ietf:params:xml:ns:xmpp-bind" 
    3942#define uri_XSESSION    "urn:ietf:params:xml:ns:xmpp-session" 
     43#define uri_COMPRESS    "http://jabber.org/protocol/compress" 
     44#define uri_IQAUTH      "http://jabber.org/features/iq-auth" 
     45#define uri_IQREGISTER  "http://jabber.org/features/iq-register" 
    4046#define uri_STREAM_ERR  "urn:ietf:params:xml:ns:xmpp-streams" 
    4147#define uri_STANZA_ERR  "urn:ietf:params:xml:ns:xmpp-stanzas" 
     
    4450#define uri_RESOLVER    "http://jabberd.jabberstudio.org/ns/resolver/1.0" 
    4551#define uri_XDATA       "jabber:x:data" 
    46 #define uri_XML         "http://www.w3.org/XML/1998/namespace" 
    4752#define uri_OOB         "jabber:x:oob" 
    4853 
     54/* these are used by SM mainly */ 
     55#define uri_AUTH        "jabber:iq:auth" 
     56#define uri_REGISTER    "jabber:iq:register" 
     57#define uri_ROSTER      "jabber:iq:roster" 
     58#define uri_AGENTS      "jabber:iq:agents" 
     59#define uri_DELAY       "jabber:x:delay" 
     60#define uri_URN_DELAY   "urn:xmpp:delay" 
     61#define uri_TIME        "jabber:iq:time" 
     62#define uri_URN_TIME    "urn:xmpp:time" 
     63#define uri_BROWSE      "jabber:iq:browse" 
     64#define uri_EVENT       "jabber:x:event" 
     65#define uri_GATEWAY     "jabber:iq:gateway" 
     66#define uri_EXPIRE      "jabber:x:expire" 
     67#define uri_SEARCH      "jabber:iq:search" 
     68#define uri_DISCO       "http://jabber.org/protocol/disco" 
     69#define uri_DISCO_ITEMS "http://jabber.org/protocol/disco#items" 
     70#define uri_DISCO_INFO  "http://jabber.org/protocol/disco#info" 
     71 
     72#define uri_AMP                         "http://jabber.org/protocol/amp" 
     73#define uri_AMP_ERRORS                  "http://jabber.org/protocol/amp#errors" 
     74#define uri_AMP_ACTION_DROP             "http://jabber.org/protocol/amp?action=drop" 
     75#define uri_AMP_ACTION_ERROR            "http://jabber.org/protocol/amp?action=error" 
     76#define uri_AMP_ACTION_NOTIFY           "http://jabber.org/protocol/amp?action=notify" 
     77#define uri_AMP_CONDITION_DELIVER       "http://jabber.org/protocol/amp?condition=deliver" 
     78#define uri_AMP_CONDITION_EXPIREAT      "http://jabber.org/protocol/amp?condition=expire-at" 
     79#define uri_AMP_CONDITION_MATCHRESOURCE "http://jabber.org/protocol/amp?condition=match-resource" 
     80 
    4981#endif