Changeset 8206
- Timestamp:
- 06/03/07 16:00:09 (18 months ago)
- Location:
- trunk/src/common
- Files:
-
- 3 modified
-
connection_handlers.py (modified) (23 diffs)
-
connection.py (modified) (4 diffs)
-
xmpp/protocol.py (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/common/connection_handlers.py
r8163 r8206 19 19 20 20 import os 21 import time22 21 import base64 23 22 import sha … … 25 24 import sys 26 25 27 from time import localtime, strftime, gmtime 26 from time import (altzone, daylight, gmtime, localtime, mktime, strftime, 27 strptime, time as time_time, timezone, tzname) 28 28 from calendar import timegm 29 29 … … 413 413 def _ResultCB(self, con, iq_obj): 414 414 gajim.log.debug('_ResultCB') 415 # if we want to respect jep-0065 we have to check for proxy415 # if we want to respect xep-0065 we have to check for proxy 416 416 # activation result in any result iq 417 417 real_id = unicode(iq_obj.getAttr('id')) … … 587 587 ''' hold xmpppy handlers and public methods for discover services''' 588 588 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, 590 590 name, node, action is optional.''' 591 591 self._discover(common.xmpp.NS_DISCO_ITEMS, jid, node, id_prefix) 592 592 593 593 def discoverInfo(self, jid, node = None, id_prefix = None): 594 '''According to JEP-0030:594 '''According to XEP-0030: 595 595 For identity: category, type is mandatory, name is optional. 596 596 For feature: var is mandatory''' … … 739 739 q.addChild('feature', attrs = {'var': common.xmpp.NS_XHTML_IM}) 740 740 741 if node is None: 742 q.addChild('feature', attrs = {'var': common.xmpp.NS_TIME_REVISED}) 743 741 744 if q.getChildren(): 742 745 self.connection.send(iq) … … 750 753 def _DiscoverInfoCB(self, con, iq_obj): 751 754 gajim.log.debug('DiscoverInfoCB') 752 # According to JEP-0030:755 # According to XEP-0030: 753 756 # For identity: category, type is mandatory, name is optional. 754 757 # For feature: var is mandatory … … 823 826 824 827 def add_caps(self, p): 825 ''' advertise our capabilities in presence stanza ( jep-0115)'''828 ''' advertise our capabilities in presence stanza (xep-0115)''' 826 829 c = p.setTag('c', namespace = common.xmpp.NS_CAPS) 827 830 c.setAttr('node', 'http://gajim.org/caps') … … 1035 1038 if iq_obj.getType() == 'result': 1036 1039 # Metacontact tags 1037 # http://www. jabber.org/jeps/jep-XXXX.html1040 # http://www.xmpp.org/extensions/xep-0209.html 1038 1041 meta_list = {} 1039 1042 query = iq_obj.getTag('query') … … 1213 1216 def _PrivateCB(self, con, iq_obj): 1214 1217 ''' 1215 Private Data ( JEP 048 and 049)1218 Private Data (XEP 048 and 049) 1216 1219 ''' 1217 1220 gajim.log.debug('PrivateCB') … … 1222 1225 if ns == 'storage:bookmarks': 1223 1226 # Bookmarked URLs and Conferences 1224 # http://www. jabber.org/jeps/jep-0048.html1227 # http://www.xmpp.org/extensions/xep-0048.html 1225 1228 confs = storage.getTags('conference') 1226 1229 for conf in confs: … … 1243 1246 elif ns == 'gajim:prefs': 1244 1247 # Preferences data 1245 # http://www. jabber.org/jeps/jep-0049.html1248 # http://www.xmpp.org/extensions/xep-0049.html 1246 1249 #TODO: implement this 1247 1250 pass … … 1263 1266 if ns == 'storage:metacontacts': 1264 1267 self.metacontacts_supported = False 1265 # Private XML Storage ( JEP49) is not supported by server1268 # Private XML Storage (XEP49) is not supported by server 1266 1269 # Continue connecting 1267 1270 self.connection.initRoster() … … 1336 1339 iq_obj = iq_obj.buildReply('result') 1337 1340 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())) 1341 1344 self.connection.send(iq_obj) 1342 1345 raise common.xmpp.NodeProcessed … … 1345 1348 gajim.log.debug('TimeRevisedCB') 1346 1349 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)) 1350 1356 self.connection.send(iq_obj) 1351 1357 raise common.xmpp.NodeProcessed … … 1409 1415 subject = msg.getSubject() # if not there, it's None 1410 1416 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)) 1413 1419 frm = helpers.get_full_jid_from_iq(msg) 1414 1420 jid = helpers.get_jid_from_iq(msg) … … 1430 1436 delayed = msg.getTag('x', namespace = common.xmpp.NS_DELAY) != None 1431 1437 msg_id = None 1432 composing_ jep = None1438 composing_xep = None 1433 1439 # FIXME: Msn transport (CMSN1.2.1 and PyMSN0.10) do NOT RECOMMENDED 1434 1440 # invitation 1435 # stanza (MUC JEP) remove in 2007, as we do not do NOT RECOMMENDED1441 # stanza (MUC XEP) remove in 2007, as we do not do NOT RECOMMENDED 1436 1442 xtags = msg.getTags('x') 1437 1443 for xtag in xtags: … … 1442 1448 # chatstates - look for chatstate tags in a message if not delayed 1443 1449 if not delayed: 1444 composing_ jep = False1450 composing_xep = False 1445 1451 children = msg.getChildren() 1446 1452 for child in children: 1447 1453 if child.getNamespace() == 'http://jabber.org/protocol/chatstates': 1448 1454 chatstate = child.getName() 1449 composing_ jep = 'JEP-0085'1455 composing_xep = 'XEP-0085' 1450 1456 break 1451 # No JEP-0085 support, fallback to JEP-00221457 # No XEP-0085 support, fallback to XEP-0022 1452 1458 if not chatstate: 1453 1459 chatstate_child = msg.getTag('x', namespace = common.xmpp.NS_EVENT) 1454 1460 if chatstate_child: 1455 1461 chatstate = 'active' 1456 composing_ jep = 'JEP-0022'1462 composing_xep = 'XEP-0022' 1457 1463 if not msgtxt and chatstate_child.getTag('composing'): 1458 1464 chatstate = 'composing' 1459 # JEP-0172 User Nickname1465 # XEP-0172 User Nickname 1460 1466 user_nick = msg.getTagData('nick') 1461 1467 if not user_nick: … … 1496 1502 return 1497 1503 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)))\ 1499 1505 <= self.last_history_line[jid] and msgtxt: 1500 1506 gajim.logger.write('gc_msg', frm, msgtxt, tim = tim) … … 1524 1530 mtype = treat_as 1525 1531 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)) 1527 1533 # END messageCB 1528 1534 … … 1579 1585 ns_muc_user_x = None 1580 1586 avatar_sha = None 1581 # JEP-0172 User Nickname1587 # XEP-0172 User Nickname 1582 1588 user_nick = prs.getTagData('nick') 1583 1589 if not user_nick: … … 1598 1604 contact_nickname = x.getTagData('nickname') 1599 1605 elif namespace == common.xmpp.NS_DELAY: 1600 # JEP-00911606 # XEP-0091 1601 1607 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)) 1604 1610 elif namespace == 'http://delx.cjb.net/protocol/roster-subsync': 1605 1611 # see http://trac.gajim.org/ticket/326 … … 1733 1739 if not self.subscribed_events.has_key(jid_stripped): 1734 1740 self.subscribed_events[jid_stripped] = [] 1735 self.subscribed_events[jid_stripped].append(time .time())1741 self.subscribed_events[jid_stripped].append(time_time()) 1736 1742 block = False 1737 1743 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: 1739 1745 block = True 1740 1746 self.subscribed_events[jid_stripped] = self.subscribed_events[jid_stripped][1:] … … 1753 1759 if not self.subscribed_events.has_key(jid_stripped): 1754 1760 self.subscribed_events[jid_stripped] = [] 1755 self.subscribed_events[jid_stripped].append(time .time())1761 self.subscribed_events[jid_stripped].append(time_time()) 1756 1762 block = False 1757 1763 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: 1759 1765 block = True 1760 1766 self.subscribed_events[jid_stripped] = self.subscribed_events[jid_stripped][1:] -
trunk/src/common/connection.py
r8190 r8206 567 567 iq.addChild(name = 'ping', namespace = common.xmpp.NS_PING) 568 568 def _on_response(resp): 569 timePong = time .time()569 timePong = time_time() 570 570 if not common.xmpp.isResultNode(resp): 571 571 self.dispatch('PING_ERROR', (pingTo)) … … 574 574 self.dispatch('PING_REPLY', (pingTo, timeDiff)) 575 575 self.dispatch('PING_SENT', (pingTo)) 576 timePing = time .time()576 timePing = time_time() 577 577 self.connection.SendAndCallForResponse(iq, _on_response) 578 578 … … 851 851 else: 852 852 # Encryption failed, do not send message 853 tim = time.localtime()853 tim = localtime() 854 854 self.dispatch('MSGNOTSENT', (jid, error, msgtxt, tim)) 855 855 return 3 … … 1265 1265 # Save the time we quit to avoid duplicate logs AND be faster than 1266 1266 # get that date from DB 1267 self.last_history_line[jid] = time .time()1267 self.last_history_line[jid] = time_time() 1268 1268 1269 1269 def gc_set_role(self, room_jid, nick, role, reason = ''): -
trunk/src/common/xmpp/protocol.py
r7903 r8206 22 22 from simplexml import Node,NodeBuilder,ustr 23 23 import time 24 NS_ACTIVITY ='http://jabber.org/protocol/activity' # JEP-010825 NS_ADDRESS ='http://jabber.org/protocol/address' # JEP-003324 NS_ACTIVITY ='http://jabber.org/protocol/activity' # XEP-0108 25 NS_ADDRESS ='http://jabber.org/protocol/address' # XEP-0033 26 26 NS_AGENTS ='jabber:iq:agents' 27 27 NS_AMP ='http://jabber.org/protocol/amp' … … 30 30 NS_BIND ='urn:ietf:params:xml:ns:xmpp-bind' 31 31 NS_BROWSE ='jabber:iq:browse' 32 NS_BYTESTREAM ='http://jabber.org/protocol/bytestreams' # JEP-006533 NS_CAPS ='http://jabber.org/protocol/caps' # JEP-011534 NS_CHATSTATES ='http://jabber.org/protocol/chatstates' # JEP-008532 NS_BYTESTREAM ='http://jabber.org/protocol/bytestreams' # XEP-0065 33 NS_CAPS ='http://jabber.org/protocol/caps' # XEP-0115 34 NS_CHATSTATES ='http://jabber.org/protocol/chatstates' # XEP-0085 35 35 NS_CLIENT ='jabber:client' 36 36 NS_COMMANDS ='http://jabber.org/protocol/commands' 37 37 NS_COMPONENT_ACCEPT='jabber:component:accept' 38 38 NS_COMPONENT_1 ='http://jabberd.jabberstudio.org/ns/component/1.0' 39 NS_COMPRESS ='http://jabber.org/protocol/compress' # JEP-013839 NS_COMPRESS ='http://jabber.org/protocol/compress' # XEP-0138 40 40 NS_CONFERENCE ='jabber:x:conference' 41 NS_DATA ='jabber:x:data' # JEP-000441 NS_DATA ='jabber:x:data' # XEP-0004 42 42 NS_DELAY ='jabber:x:delay' 43 43 NS_DIALBACK ='jabber:server:dialback' … … 45 45 NS_DISCO_INFO =NS_DISCO+'#info' 46 46 NS_DISCO_ITEMS =NS_DISCO+'#items' 47 NS_ENCRYPTED ='jabber:x:encrypted' # JEP-002748 NS_EVENT ='jabber:x:event' # JEP-002247 NS_ENCRYPTED ='jabber:x:encrypted' # XEP-0027 48 NS_EVENT ='jabber:x:event' # XEP-0022 49 49 NS_FEATURE ='http://jabber.org/protocol/feature-neg' 50 NS_FILE ='http://jabber.org/protocol/si/profile/file-transfer' # JEP-009651 NS_GEOLOC ='http://jabber.org/protocol/geoloc' # JEP-008050 NS_FILE ='http://jabber.org/protocol/si/profile/file-transfer' # XEP-0096 51 NS_GEOLOC ='http://jabber.org/protocol/geoloc' # XEP-0080 52 52 NS_GROUPCHAT ='gc-1.0' 53 NS_HTTP_AUTH ='http://jabber.org/protocol/http-auth' # JEP-007054 NS_HTTP_BIND ='http://jabber.org/protocol/httpbind' # JEP-012453 NS_HTTP_AUTH ='http://jabber.org/protocol/http-auth' # XEP-0070 54 NS_HTTP_BIND ='http://jabber.org/protocol/httpbind' # XEP-0124 55 55 NS_IBB ='http://jabber.org/protocol/ibb' 56 56 NS_INVISIBLE ='presence-invisible' # Jabberd2 … … 58 58 NS_LAST ='jabber:iq:last' 59 59 NS_MESSAGE ='message' # Jabberd2 60 NS_MOOD ='http://jabber.org/protocol/mood' # JEP-010760 NS_MOOD ='http://jabber.org/protocol/mood' # XEP-0107 61 61 NS_MUC ='http://jabber.org/protocol/muc' 62 62 NS_MUC_USER =NS_MUC+'#user' 63 63 NS_MUC_ADMIN =NS_MUC+'#admin' 64 64 NS_MUC_OWNER =NS_MUC+'#owner' 65 NS_NICK ='http://jabber.org/protocol/nick' # JEP-017266 NS_OFFLINE ='http://www.jabber.org/jeps/jep-0030.html' # JEP-001367 NS_PHYSLOC ='http://jabber.org/protocol/physloc' # JEP-011265 NS_NICK ='http://jabber.org/protocol/nick' # XEP-0172 66 NS_OFFLINE ='http://www.jabber.org/jeps/jep-0030.html' # XEP-0013 67 NS_PHYSLOC ='http://jabber.org/protocol/physloc' # XEP-0112 68 68 NS_PRESENCE ='presence' # Jabberd2 69 69 NS_PRIVACY ='jabber:iq:privacy' 70 70 NS_PRIVATE ='jabber:iq:private' 71 NS_PROFILE ='http://jabber.org/protocol/profile' # JEP-015472 NS_PUBSUB ='http://jabber.org/protocol/pubsub' # JEP-006071 NS_PROFILE ='http://jabber.org/protocol/profile' # XEP-0154 72 NS_PUBSUB ='http://jabber.org/protocol/pubsub' # XEP-0060 73 73 NS_REGISTER ='jabber:iq:register' 74 74 NS_ROSTER ='jabber:iq:roster' 75 NS_ROSTERX ='http://jabber.org/protocol/rosterx' # JEP-014476 NS_RPC ='jabber:iq:rpc' # JEP-000975 NS_ROSTERX ='http://jabber.org/protocol/rosterx' # XEP-0144 76 NS_RPC ='jabber:iq:rpc' # XEP-0009 77 77 NS_SASL ='urn:ietf:params:xml:ns:xmpp-sasl' 78 78 NS_SEARCH ='jabber:iq:search' 79 79 NS_SERVER ='jabber:server' 80 80 NS_SESSION ='urn:ietf:params:xml:ns:xmpp-session' 81 NS_SI ='http://jabber.org/protocol/si' # JEP-009682 NS_SI_PUB ='http://jabber.org/protocol/sipub' # JEP-013783 NS_SIGNED ='jabber:x:signed' # JEP-002781 NS_SI ='http://jabber.org/protocol/si' # XEP-0096 82 NS_SI_PUB ='http://jabber.org/protocol/sipub' # XEP-0137 83 NS_SIGNED ='jabber:x:signed' # XEP-0027 84 84 NS_STANZAS ='urn:ietf:params:xml:ns:xmpp-stanzas' 85 85 NS_STREAM ='http://affinix.com/jabber/stream' 86 86 NS_STREAMS ='http://etherx.jabber.org/streams' 87 NS_TIME ='jabber:iq:time' # JEP-090088 NS_TIME_REVISED =' http://www.xmpp.org/extensions/xep-0202.html#ns' # JEP-020287 NS_TIME ='jabber:iq:time' # XEP-0900 88 NS_TIME_REVISED ='urn:xmpp:time' # XEP-0202 89 89 NS_TLS ='urn:ietf:params:xml:ns:xmpp-tls' 90 90 NS_VACATION ='http://jabber.org/protocol/vacation' … … 95 95 NS_VERSION ='jabber:iq:version' 96 96 NS_PING ='urn:xmpp:ping' # XEP-0199 97 NS_WAITINGLIST ='http://jabber.org/protocol/waitinglist' # JEP-013098 NS_XHTML_IM ='http://jabber.org/protocol/xhtml-im' # JEP-007197 NS_WAITINGLIST ='http://jabber.org/protocol/waitinglist' # XEP-0130 98 NS_XHTML_IM ='http://jabber.org/protocol/xhtml-im' # XEP-0071 99 99 NS_XHTML = 'http://www.w3.org/1999/xhtml' # " 100 NS_DATA_LAYOUT ='http://jabber.org/protocol/xdata-layout' # JEP-0141101 NS_DATA_VALIDATE='http://jabber.org/protocol/xdata-validate' # JEP-0122100 NS_DATA_LAYOUT ='http://jabber.org/protocol/xdata-layout' # XEP-0141 101 NS_DATA_VALIDATE='http://jabber.org/protocol/xdata-validate' # XEP-0122 102 102 NS_XMPP_STREAMS ='urn:ietf:params:xml:ns:xmpp-streams' 103 103 … … 423 423 424 424 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). 426 426 The parameter is the "inner html" to the body.""" 427 427 try: … … 591 591 class DataField(Node): 592 592 """ 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) 594 594 then you will need to work with instances of this class. """ 595 595 def __init__(self,name=None,value=None,typ=None,required=0,desc=None,options=[],node=None): … … 668 668 class DataForm(Node): 669 669 """ DataForm class. Used for manipulating dataforms in XMPP. 670 Relevant JEPs: 0004, 0068, 0122.670 Relevant XEPs: 0004, 0068, 0122. 671 671 Can be used in disco, pub-sub and many other applications.""" 672 672 def __init__(self, typ=None, data=[], title=None, node=None):
