Changeset 8206

Show
Ignore:
Timestamp:
06/03/07 16:00:09 (18 months ago)
Author:
asterix
Message:

[elghinn] fix entity time support (xep 90 and 202)

Location:
trunk/src/common
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/common/connection_handlers.py

    r8163 r8206  
    1919 
    2020import os 
    21 import time 
    2221import base64 
    2322import sha 
     
    2524import sys 
    2625 
    27 from time import localtime, strftime, gmtime 
     26from time import (altzone, daylight, gmtime, localtime, mktime, strftime, 
     27                  strptime, time as time_time, timezone, tzname) 
    2828from calendar import timegm 
    2929 
     
    413413        def _ResultCB(self, con, iq_obj): 
    414414                gajim.log.debug('_ResultCB') 
    415                 # if we want to respect jep-0065 we have to check for proxy 
     415                # if we want to respect xep-0065 we have to check for proxy 
    416416                # activation result in any result iq 
    417417                real_id = unicode(iq_obj.getAttr('id')) 
     
    587587        ''' hold xmpppy handlers and public methods for discover services''' 
    588588        def discoverItems(self, jid, node = None, id_prefix = None): 
    589                 '''According to JEP-0030: jid is mandatory, 
     589                '''According to XEP-0030: jid is mandatory, 
    590590                name, node, action is optional.''' 
    591591                self._discover(common.xmpp.NS_DISCO_ITEMS, jid, node, id_prefix) 
    592592 
    593593        def discoverInfo(self, jid, node = None, id_prefix = None): 
    594                 '''According to JEP-0030: 
     594                '''According to XEP-0030: 
    595595                        For identity: category, type is mandatory, name is optional. 
    596596                        For feature: var is mandatory''' 
     
    739739                                q.addChild('feature', attrs = {'var': common.xmpp.NS_XHTML_IM}) 
    740740 
     741                        if node is None: 
     742                                q.addChild('feature', attrs = {'var': common.xmpp.NS_TIME_REVISED}) 
     743 
    741744                        if q.getChildren(): 
    742745                                self.connection.send(iq) 
     
    750753        def _DiscoverInfoCB(self, con, iq_obj): 
    751754                gajim.log.debug('DiscoverInfoCB') 
    752                 # According to JEP-0030: 
     755                # According to XEP-0030: 
    753756                # For identity: category, type is mandatory, name is optional. 
    754757                # For feature: var is mandatory 
     
    823826         
    824827        def add_caps(self, p): 
    825                 ''' advertise our capabilities in presence stanza (jep-0115)''' 
     828                ''' advertise our capabilities in presence stanza (xep-0115)''' 
    826829                c = p.setTag('c', namespace = common.xmpp.NS_CAPS) 
    827830                c.setAttr('node', 'http://gajim.org/caps') 
     
    10351038                        if iq_obj.getType() == 'result': 
    10361039                                # Metacontact tags 
    1037                                 # http://www.jabber.org/jeps/jep-XXXX.html 
     1040                                # http://www.xmpp.org/extensions/xep-0209.html 
    10381041                                meta_list = {} 
    10391042                                query = iq_obj.getTag('query') 
     
    12131216        def _PrivateCB(self, con, iq_obj): 
    12141217                ''' 
    1215                 Private Data (JEP 048 and 049) 
     1218                Private Data (XEP 048 and 049) 
    12161219                ''' 
    12171220                gajim.log.debug('PrivateCB') 
     
    12221225                        if ns == 'storage:bookmarks': 
    12231226                                # Bookmarked URLs and Conferences 
    1224                                 # http://www.jabber.org/jeps/jep-0048.html 
     1227                                # http://www.xmpp.org/extensions/xep-0048.html 
    12251228                                confs = storage.getTags('conference') 
    12261229                                for conf in confs: 
     
    12431246                        elif ns == 'gajim:prefs': 
    12441247                                # Preferences data 
    1245                                 # http://www.jabber.org/jeps/jep-0049.html 
     1248                                # http://www.xmpp.org/extensions/xep-0049.html 
    12461249                                #TODO: implement this 
    12471250                                pass 
     
    12631266                        if ns == 'storage:metacontacts': 
    12641267                                self.metacontacts_supported = False 
    1265                                 # Private XML Storage (JEP49) is not supported by server 
     1268                                # Private XML Storage (XEP49) is not supported by server 
    12661269                                # Continue connecting 
    12671270                                self.connection.initRoster() 
     
    13361339                iq_obj = iq_obj.buildReply('result') 
    13371340                qp = iq_obj.getTag('query') 
    1338                 qp.setTagData('utc', strftime("%Y%m%dT%T", gmtime())) 
    1339                 qp.setTagData('tz', strftime("%Z", gmtime())) 
    1340                 qp.setTagData('display', strftime("%c", localtime())) 
     1341                qp.setTagData('utc', strftime('%Y%m%dT%T', gmtime())) 
     1342                qp.setTagData('tz', tzname[daylight]) 
     1343                qp.setTagData('display', strftime('%c', localtime())) 
    13411344                self.connection.send(iq_obj) 
    13421345                raise common.xmpp.NodeProcessed 
     
    13451348                gajim.log.debug('TimeRevisedCB') 
    13461349                iq_obj = iq_obj.buildReply('result') 
    1347                 qp = iq_obj.setTag('time') 
    1348                 qp.setTagData('utc', strftime("%Y-%m-%dT%TZ", gmtime())) 
    1349                 qp.setTagData('tzo', "%+03d:00"% (-time.timezone/(60*60))) 
     1350                qp = iq_obj.setTag('time', 
     1351                                   namespace=common.xmpp.NS_TIME_REVISED) 
     1352                qp.setTagData('utc', strftime('%Y-%m-%dT%TZ', gmtime())) 
     1353                zone = -(timezone, altzone)[daylight] / 60 
     1354                tzo = (zone / 60, abs(zone % 60)) 
     1355                qp.setTagData('tzo', '%+03d:%02d' % (tzo)) 
    13501356                self.connection.send(iq_obj) 
    13511357                raise common.xmpp.NodeProcessed 
     
    14091415                subject = msg.getSubject() # if not there, it's None 
    14101416                tim = msg.getTimestamp() 
    1411                 tim = time.strptime(tim, '%Y%m%dT%H:%M:%S') 
    1412                 tim = time.localtime(timegm(tim)) 
     1417                tim = strptime(tim, '%Y%m%dT%H:%M:%S') 
     1418                tim = localtime(timegm(tim)) 
    14131419                frm = helpers.get_full_jid_from_iq(msg) 
    14141420                jid = helpers.get_jid_from_iq(msg) 
     
    14301436                delayed = msg.getTag('x', namespace = common.xmpp.NS_DELAY) != None 
    14311437                msg_id = None 
    1432                 composing_jep = None 
     1438                composing_xep = None 
    14331439                # FIXME: Msn transport (CMSN1.2.1 and PyMSN0.10) do NOT RECOMMENDED 
    14341440                # invitation 
    1435                 # stanza (MUC JEP) remove in 2007, as we do not do NOT RECOMMENDED 
     1441                # stanza (MUC XEP) remove in 2007, as we do not do NOT RECOMMENDED 
    14361442                xtags = msg.getTags('x') 
    14371443                for xtag in xtags: 
     
    14421448                # chatstates - look for chatstate tags in a message if not delayed 
    14431449                if not delayed: 
    1444                         composing_jep = False 
     1450                        composing_xep = False 
    14451451                        children = msg.getChildren() 
    14461452                        for child in children: 
    14471453                                if child.getNamespace() == 'http://jabber.org/protocol/chatstates': 
    14481454                                        chatstate = child.getName() 
    1449                                         composing_jep = 'JEP-0085' 
     1455                                        composing_xep = 'XEP-0085' 
    14501456                                        break 
    1451                         # No JEP-0085 support, fallback to JEP-0022 
     1457                        # No XEP-0085 support, fallback to XEP-0022 
    14521458                        if not chatstate: 
    14531459                                chatstate_child = msg.getTag('x', namespace = common.xmpp.NS_EVENT) 
    14541460                                if chatstate_child: 
    14551461                                        chatstate = 'active' 
    1456                                         composing_jep = 'JEP-0022' 
     1462                                        composing_xep = 'XEP-0022' 
    14571463                                        if not msgtxt and chatstate_child.getTag('composing'): 
    14581464                                                chatstate = 'composing' 
    1459                 # JEP-0172 User Nickname 
     1465                # XEP-0172 User Nickname 
    14601466                user_nick = msg.getTagData('nick') 
    14611467                if not user_nick: 
     
    14961502                                        return 
    14971503                                self.dispatch('GC_MSG', (frm, msgtxt, tim, has_timestamp, msghtml)) 
    1498                                 if self.name not in no_log_for and not int(float(time.mktime(tim)))\ 
     1504                                if self.name not in no_log_for and not int(float(mktime(tim)))\ 
    14991505                                <= self.last_history_line[jid] and msgtxt: 
    15001506                                        gajim.logger.write('gc_msg', frm, msgtxt, tim = tim) 
     
    15241530                        mtype = treat_as 
    15251531                self.dispatch('MSG', (frm, msgtxt, tim, encrypted, mtype, 
    1526                         subject, chatstate, msg_id, composing_jep, user_nick, msghtml)) 
     1532                        subject, chatstate, msg_id, composing_xep, user_nick, msghtml)) 
    15271533        # END messageCB 
    15281534 
     
    15791585                ns_muc_user_x = None 
    15801586                avatar_sha = None 
    1581                 # JEP-0172 User Nickname 
     1587                # XEP-0172 User Nickname 
    15821588                user_nick = prs.getTagData('nick') 
    15831589                if not user_nick: 
     
    15981604                                contact_nickname = x.getTagData('nickname') 
    15991605                        elif namespace == common.xmpp.NS_DELAY: 
    1600                                 # JEP-0091 
     1606                                # XEP-0091 
    16011607                                tim = prs.getTimestamp() 
    1602                                 tim = time.strptime(tim, '%Y%m%dT%H:%M:%S') 
    1603                                 timestamp = time.localtime(timegm(tim)) 
     1608                                tim = strptime(tim, '%Y%m%dT%H:%M:%S') 
     1609                                timestamp = localtime(timegm(tim)) 
    16041610                        elif namespace == 'http://delx.cjb.net/protocol/roster-subsync': 
    16051611                                # see http://trac.gajim.org/ticket/326 
     
    17331739                                if not self.subscribed_events.has_key(jid_stripped): 
    17341740                                        self.subscribed_events[jid_stripped] = [] 
    1735                                 self.subscribed_events[jid_stripped].append(time.time()) 
     1741                                self.subscribed_events[jid_stripped].append(time_time()) 
    17361742                                block = False 
    17371743                                if len(self.subscribed_events[jid_stripped]) > 5: 
    1738                                         if time.time() - self.subscribed_events[jid_stripped][0] < 5: 
     1744                                        if time_time() - self.subscribed_events[jid_stripped][0] < 5: 
    17391745                                                block = True 
    17401746                                        self.subscribed_events[jid_stripped] = self.subscribed_events[jid_stripped][1:] 
     
    17531759                        if not self.subscribed_events.has_key(jid_stripped): 
    17541760                                self.subscribed_events[jid_stripped] = [] 
    1755                         self.subscribed_events[jid_stripped].append(time.time()) 
     1761                        self.subscribed_events[jid_stripped].append(time_time()) 
    17561762                        block = False 
    17571763                        if len(self.subscribed_events[jid_stripped]) > 5: 
    1758                                 if time.time() - self.subscribed_events[jid_stripped][0] < 5: 
     1764                                if time_time() - self.subscribed_events[jid_stripped][0] < 5: 
    17591765                                        block = True 
    17601766                                self.subscribed_events[jid_stripped] = self.subscribed_events[jid_stripped][1:] 
  • trunk/src/common/connection.py

    r8190 r8206  
    567567                iq.addChild(name = 'ping', namespace = common.xmpp.NS_PING) 
    568568                def _on_response(resp): 
    569                         timePong = time.time() 
     569                        timePong = time_time() 
    570570                        if not common.xmpp.isResultNode(resp): 
    571571                                self.dispatch('PING_ERROR', (pingTo)) 
     
    574574                        self.dispatch('PING_REPLY', (pingTo, timeDiff)) 
    575575                self.dispatch('PING_SENT', (pingTo)) 
    576                 timePing = time.time() 
     576                timePing = time_time() 
    577577                self.connection.SendAndCallForResponse(iq, _on_response) 
    578578 
     
    851851                        else: 
    852852                                # Encryption failed, do not send message 
    853                                 tim = time.localtime() 
     853                                tim = localtime() 
    854854                                self.dispatch('MSGNOTSENT', (jid, error, msgtxt, tim)) 
    855855                                return 3 
     
    12651265                # Save the time we quit to avoid duplicate logs AND be faster than  
    12661266                # get that date from DB 
    1267                 self.last_history_line[jid] = time.time() 
     1267                self.last_history_line[jid] = time_time() 
    12681268 
    12691269        def gc_set_role(self, room_jid, nick, role, reason = ''): 
  • trunk/src/common/xmpp/protocol.py

    r7903 r8206  
    2222from simplexml import Node,NodeBuilder,ustr 
    2323import time 
    24 NS_ACTIVITY     ='http://jabber.org/protocol/activity'                  # JEP-0108 
    25 NS_ADDRESS      ='http://jabber.org/protocol/address'                   # JEP-0033 
     24NS_ACTIVITY     ='http://jabber.org/protocol/activity'                  # XEP-0108 
     25NS_ADDRESS      ='http://jabber.org/protocol/address'                   # XEP-0033 
    2626NS_AGENTS       ='jabber:iq:agents' 
    2727NS_AMP          ='http://jabber.org/protocol/amp' 
     
    3030NS_BIND         ='urn:ietf:params:xml:ns:xmpp-bind' 
    3131NS_BROWSE       ='jabber:iq:browse' 
    32 NS_BYTESTREAM   ='http://jabber.org/protocol/bytestreams'               # JEP-0065 
    33 NS_CAPS         ='http://jabber.org/protocol/caps'                      # JEP-0115 
    34 NS_CHATSTATES   ='http://jabber.org/protocol/chatstates'                # JEP-0085 
     32NS_BYTESTREAM   ='http://jabber.org/protocol/bytestreams'               # XEP-0065 
     33NS_CAPS         ='http://jabber.org/protocol/caps'                      # XEP-0115 
     34NS_CHATSTATES   ='http://jabber.org/protocol/chatstates'                # XEP-0085 
    3535NS_CLIENT       ='jabber:client' 
    3636NS_COMMANDS     ='http://jabber.org/protocol/commands' 
    3737NS_COMPONENT_ACCEPT='jabber:component:accept' 
    3838NS_COMPONENT_1  ='http://jabberd.jabberstudio.org/ns/component/1.0' 
    39 NS_COMPRESS     ='http://jabber.org/protocol/compress'                  # JEP-0138 
     39NS_COMPRESS     ='http://jabber.org/protocol/compress'                  # XEP-0138 
    4040NS_CONFERENCE   ='jabber:x:conference' 
    41 NS_DATA         ='jabber:x:data'                                        # JEP-0004 
     41NS_DATA         ='jabber:x:data'                                        # XEP-0004 
    4242NS_DELAY        ='jabber:x:delay' 
    4343NS_DIALBACK     ='jabber:server:dialback' 
     
    4545NS_DISCO_INFO   =NS_DISCO+'#info' 
    4646NS_DISCO_ITEMS  =NS_DISCO+'#items' 
    47 NS_ENCRYPTED    ='jabber:x:encrypted'                                   # JEP-0027 
    48 NS_EVENT        ='jabber:x:event'                                       # JEP-0022 
     47NS_ENCRYPTED    ='jabber:x:encrypted'                                   # XEP-0027 
     48NS_EVENT        ='jabber:x:event'                                       # XEP-0022 
    4949NS_FEATURE      ='http://jabber.org/protocol/feature-neg'   
    50 NS_FILE         ='http://jabber.org/protocol/si/profile/file-transfer'  # JEP-0096 
    51 NS_GEOLOC       ='http://jabber.org/protocol/geoloc'                    # JEP-0080 
     50NS_FILE         ='http://jabber.org/protocol/si/profile/file-transfer'  # XEP-0096 
     51NS_GEOLOC       ='http://jabber.org/protocol/geoloc'                    # XEP-0080 
    5252NS_GROUPCHAT    ='gc-1.0' 
    53 NS_HTTP_AUTH    ='http://jabber.org/protocol/http-auth'         # JEP-0070 
    54 NS_HTTP_BIND    ='http://jabber.org/protocol/httpbind'                  # JEP-0124 
     53NS_HTTP_AUTH    ='http://jabber.org/protocol/http-auth'                 # XEP-0070 
     54NS_HTTP_BIND    ='http://jabber.org/protocol/httpbind'                  # XEP-0124 
    5555NS_IBB          ='http://jabber.org/protocol/ibb' 
    5656NS_INVISIBLE    ='presence-invisible'                                   # Jabberd2 
     
    5858NS_LAST         ='jabber:iq:last' 
    5959NS_MESSAGE      ='message'                                              # Jabberd2 
    60 NS_MOOD         ='http://jabber.org/protocol/mood'                      # JEP-0107 
     60NS_MOOD         ='http://jabber.org/protocol/mood'                      # XEP-0107 
    6161NS_MUC          ='http://jabber.org/protocol/muc' 
    6262NS_MUC_USER     =NS_MUC+'#user' 
    6363NS_MUC_ADMIN    =NS_MUC+'#admin' 
    6464NS_MUC_OWNER    =NS_MUC+'#owner' 
    65 NS_NICK         ='http://jabber.org/protocol/nick'                      # JEP-0172 
    66 NS_OFFLINE      ='http://www.jabber.org/jeps/jep-0030.html'             # JEP-0013 
    67 NS_PHYSLOC      ='http://jabber.org/protocol/physloc'                   # JEP-0112 
     65NS_NICK         ='http://jabber.org/protocol/nick'                      # XEP-0172 
     66NS_OFFLINE      ='http://www.jabber.org/jeps/jep-0030.html'             # XEP-0013 
     67NS_PHYSLOC      ='http://jabber.org/protocol/physloc'                   # XEP-0112 
    6868NS_PRESENCE     ='presence'                                             # Jabberd2 
    6969NS_PRIVACY      ='jabber:iq:privacy' 
    7070NS_PRIVATE      ='jabber:iq:private' 
    71 NS_PROFILE      ='http://jabber.org/protocol/profile'                   # JEP-0154 
    72 NS_PUBSUB       ='http://jabber.org/protocol/pubsub'                    # JEP-0060 
     71NS_PROFILE      ='http://jabber.org/protocol/profile'                   # XEP-0154 
     72NS_PUBSUB       ='http://jabber.org/protocol/pubsub'                    # XEP-0060 
    7373NS_REGISTER     ='jabber:iq:register' 
    7474NS_ROSTER       ='jabber:iq:roster' 
    75 NS_ROSTERX      ='http://jabber.org/protocol/rosterx'                   # JEP-0144 
    76 NS_RPC          ='jabber:iq:rpc'                                        # JEP-0009 
     75NS_ROSTERX      ='http://jabber.org/protocol/rosterx'                   # XEP-0144 
     76NS_RPC          ='jabber:iq:rpc'                                        # XEP-0009 
    7777NS_SASL         ='urn:ietf:params:xml:ns:xmpp-sasl' 
    7878NS_SEARCH       ='jabber:iq:search' 
    7979NS_SERVER       ='jabber:server' 
    8080NS_SESSION      ='urn:ietf:params:xml:ns:xmpp-session' 
    81 NS_SI           ='http://jabber.org/protocol/si'                        # JEP-0096 
    82 NS_SI_PUB       ='http://jabber.org/protocol/sipub'                     # JEP-0137 
    83 NS_SIGNED       ='jabber:x:signed'                                      # JEP-0027 
     81NS_SI           ='http://jabber.org/protocol/si'                        # XEP-0096 
     82NS_SI_PUB       ='http://jabber.org/protocol/sipub'                     # XEP-0137 
     83NS_SIGNED       ='jabber:x:signed'                                      # XEP-0027 
    8484NS_STANZAS      ='urn:ietf:params:xml:ns:xmpp-stanzas' 
    8585NS_STREAM       ='http://affinix.com/jabber/stream' 
    8686NS_STREAMS      ='http://etherx.jabber.org/streams' 
    87 NS_TIME         ='jabber:iq:time'                                       # JEP-0900 
    88 NS_TIME_REVISED ='http://www.xmpp.org/extensions/xep-0202.html#ns'      # JEP-0202 
     87NS_TIME         ='jabber:iq:time'                                       # XEP-0900 
     88NS_TIME_REVISED ='urn:xmpp:time'                                        # XEP-0202 
    8989NS_TLS          ='urn:ietf:params:xml:ns:xmpp-tls' 
    9090NS_VACATION     ='http://jabber.org/protocol/vacation' 
     
    9595NS_VERSION      ='jabber:iq:version' 
    9696NS_PING         ='urn:xmpp:ping'                                        # XEP-0199 
    97 NS_WAITINGLIST  ='http://jabber.org/protocol/waitinglist'               # JEP-0130 
    98 NS_XHTML_IM     ='http://jabber.org/protocol/xhtml-im'                  # JEP-0071 
     97NS_WAITINGLIST  ='http://jabber.org/protocol/waitinglist'               # XEP-0130 
     98NS_XHTML_IM     ='http://jabber.org/protocol/xhtml-im'                  # XEP-0071 
    9999NS_XHTML        = 'http://www.w3.org/1999/xhtml'                        #  " 
    100 NS_DATA_LAYOUT  ='http://jabber.org/protocol/xdata-layout'              # JEP-0141 
    101 NS_DATA_VALIDATE='http://jabber.org/protocol/xdata-validate'            # JEP-0122 
     100NS_DATA_LAYOUT  ='http://jabber.org/protocol/xdata-layout'              # XEP-0141 
     101NS_DATA_VALIDATE='http://jabber.org/protocol/xdata-validate'            # XEP-0122 
    102102NS_XMPP_STREAMS ='urn:ietf:params:xml:ns:xmpp-streams' 
    103103 
     
    423423 
    424424    def setXHTML(self,val,xmllang=None): 
    425         """ Sets the xhtml text of the message (JEP-0071). 
     425        """ Sets the xhtml text of the message (XEP-0071). 
    426426            The parameter is the "inner html" to the body.""" 
    427427        try: 
     
    591591class DataField(Node): 
    592592    """ This class is used in the DataForm class to describe the single data item. 
    593         If you are working with jabber:x:data (JEP-0004, JEP-0068, JEP-0122)  
     593        If you are working with jabber:x:data (XEP-0004, XEP-0068, XEP-0122)  
    594594        then you will need to work with instances of this class. """ 
    595595    def __init__(self,name=None,value=None,typ=None,required=0,desc=None,options=[],node=None): 
     
    668668class DataForm(Node): 
    669669    """ DataForm class. Used for manipulating dataforms in XMPP. 
    670         Relevant JEPs: 0004, 0068, 0122. 
     670        Relevant XEPs: 0004, 0068, 0122. 
    671671        Can be used in disco, pub-sub and many other applications.""" 
    672672    def __init__(self, typ=None, data=[], title=None, node=None):