~jtaylor/ubuntu/oneiric/gajim/multiple-CVE

« back to all changes in this revision

Viewing changes to src/common/xmpp/protocol.py

  • Committer: Bazaar Package Importer
  • Author(s): Nafallo Bjälevik
  • Date: 2008-11-16 00:26:27 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20081116002627-4olie99o2rqc7001
Tags: 0.12~beta1-0ubuntu1
* New upstream beta release:
  + Security improvements: End-to-End encryption, SSL certificat verification
  + Ability to minimize groupchats in roster
  + Chat to groupchat transformation
  + Block/Unblock contacts directly from roster
  + Single window mode
  + PEP support (User activity, mood and tune)
  + Security improvements: Kerberos (GSSAPI) SASL Authentication mechanism
  + Improve GUI of some windows
  + Fix handling of invalid XML
  + Fix freeze on connection
* Dropped all changes, patches and backports.
* src/common/passwords.py:
  - Change keyring to 'login', which is what gets unlocked at login.
* debian/copyright:
  - Updated for the GPL-3 change and for the amount of upstream authors.
* debian/control:
  - Update Standards-Version and drop XS for Vcs-Bzr.
  - Add Homepage and use ${shlibs:Depends}.
* debian/rules:
  - Update to not ignore errors from make clean.
  - Update with dh_shlibdeps.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
NS_AMP          ='http://jabber.org/protocol/amp'
28
28
NS_AMP_ERRORS   =NS_AMP+'#errors'
29
29
NS_AUTH         ='jabber:iq:auth'
 
30
NS_AVATAR       ='http://www.xmpp.org/extensions/xep-0084.html#ns-metadata'
30
31
NS_BIND         ='urn:ietf:params:xml:ns:xmpp-bind'
31
32
NS_BROWSE       ='jabber:iq:browse'
32
 
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
 
33
NS_BROWSING     ='http://jabber.org/protocol/browsing'                  # XEP-0195
 
34
NS_BYTESTREAM   ='http://jabber.org/protocol/bytestreams'               # JEP-0065
 
35
NS_CAPS         ='http://jabber.org/protocol/caps'                      # JEP-0115
 
36
NS_CHATSTATES   ='http://jabber.org/protocol/chatstates'                # JEP-0085
 
37
NS_CHATTING     ='http://jabber.org/protocol/chatting'                  # XEP-0194
35
38
NS_CLIENT       ='jabber:client'
36
39
NS_COMMANDS     ='http://jabber.org/protocol/commands'
37
40
NS_COMPONENT_ACCEPT='jabber:component:accept'
40
43
NS_CONFERENCE   ='jabber:x:conference'
41
44
NS_DATA         ='jabber:x:data'                                        # XEP-0004
42
45
NS_DELAY        ='jabber:x:delay'
 
46
NS_DELAY2       ='urn:xmpp:delay'
43
47
NS_DIALBACK     ='jabber:server:dialback'
44
48
NS_DISCO        ='http://jabber.org/protocol/disco'
45
49
NS_DISCO_INFO   =NS_DISCO+'#info'
46
50
NS_DISCO_ITEMS  =NS_DISCO+'#items'
47
51
NS_ENCRYPTED    ='jabber:x:encrypted'                                   # XEP-0027
 
52
NS_ESESSION     ='http://www.xmpp.org/extensions/xep-0116.html#ns'
 
53
NS_ESESSION_INIT='http://www.xmpp.org/extensions/xep-0116.html#ns-init' # XEP-0116
48
54
NS_EVENT        ='jabber:x:event'                                       # XEP-0022
49
 
NS_FEATURE      ='http://jabber.org/protocol/feature-neg'  
50
 
NS_FILE         ='http://jabber.org/protocol/si/profile/file-transfer'  # XEP-0096
51
 
NS_GEOLOC       ='http://jabber.org/protocol/geoloc'                    # XEP-0080
 
55
NS_FEATURE      ='http://jabber.org/protocol/feature-neg'
 
56
NS_FILE         ='http://jabber.org/protocol/si/profile/file-transfer'  # JEP-0096
 
57
NS_GAMING       ='http://jabber.org/protocol/gaming'                    # XEP-0196
 
58
NS_GEOLOC       ='http://jabber.org/protocol/geoloc'                    # JEP-0080
52
59
NS_GROUPCHAT    ='gc-1.0'
53
60
NS_HTTP_AUTH    ='http://jabber.org/protocol/http-auth'                 # XEP-0070
54
61
NS_HTTP_BIND    ='http://jabber.org/protocol/httpbind'                  # XEP-0124
62
69
NS_MUC_USER     =NS_MUC+'#user'
63
70
NS_MUC_ADMIN    =NS_MUC+'#admin'
64
71
NS_MUC_OWNER    =NS_MUC+'#owner'
 
72
NS_MUC_UNIQUE   =NS_MUC+'#unique'
 
73
NS_MUC_CONFIG   =NS_MUC+'#roomconfig'
65
74
NS_NICK         ='http://jabber.org/protocol/nick'                      # XEP-0172
66
75
NS_OFFLINE      ='http://www.jabber.org/jeps/jep-0030.html'             # XEP-0013
67
76
NS_PHYSLOC      ='http://jabber.org/protocol/physloc'                   # XEP-0112
 
77
NS_PING         ='urn:xmpp:ping'                                        # SEP-0199
68
78
NS_PRESENCE     ='presence'                                             # Jabberd2
69
79
NS_PRIVACY      ='jabber:iq:privacy'
70
80
NS_PRIVATE      ='jabber:iq:private'
71
81
NS_PROFILE      ='http://jabber.org/protocol/profile'                   # XEP-0154
72
82
NS_PUBSUB       ='http://jabber.org/protocol/pubsub'                    # XEP-0060
 
83
NS_PUBSUB_OWNER ='http://jabber.org/protocol/pubsub#owner'              # JEP-0060
73
84
NS_REGISTER     ='jabber:iq:register'
74
85
NS_ROSTER       ='jabber:iq:roster'
75
86
NS_ROSTERX      ='http://jabber.org/protocol/rosterx'                   # XEP-0144
81
92
NS_SI           ='http://jabber.org/protocol/si'                        # XEP-0096
82
93
NS_SI_PUB       ='http://jabber.org/protocol/sipub'                     # XEP-0137
83
94
NS_SIGNED       ='jabber:x:signed'                                      # XEP-0027
 
95
NS_STANZA_CRYPTO='http://www.xmpp.org/extensions/xep-0200.html#ns'                      # JEP-0200
84
96
NS_STANZAS      ='urn:ietf:params:xml:ns:xmpp-stanzas'
85
97
NS_STREAM       ='http://affinix.com/jabber/stream'
86
98
NS_STREAMS      ='http://etherx.jabber.org/streams'
87
99
NS_TIME         ='jabber:iq:time'                                       # XEP-0900
88
100
NS_TIME_REVISED ='urn:xmpp:time'                                        # XEP-0202
89
101
NS_TLS          ='urn:ietf:params:xml:ns:xmpp-tls'
 
102
NS_TUNE         ='http://jabber.org/protocol/tune'                      # XEP-0118
90
103
NS_VACATION     ='http://jabber.org/protocol/vacation'
91
104
NS_VCARD        ='vcard-temp'
92
105
NS_GMAILNOTIFY  ='google:mail:notify'
93
106
NS_GTALKSETTING ='google:setting'
94
107
NS_VCARD_UPDATE =NS_VCARD+':x:update'
95
108
NS_VERSION      ='jabber:iq:version'
96
 
NS_PING         ='urn:xmpp:ping'                                        # XEP-0199
 
109
NS_VIEWING      ='http://jabber.org/protocol/viewing'                   # XEP--197
97
110
NS_WAITINGLIST  ='http://jabber.org/protocol/waitinglist'               # XEP-0130
98
111
NS_XHTML_IM     ='http://jabber.org/protocol/xhtml-im'                  # XEP-0071
99
112
NS_XHTML        = 'http://www.w3.org/1999/xhtml'                        #  "
100
113
NS_DATA_LAYOUT  ='http://jabber.org/protocol/xdata-layout'              # XEP-0141
101
114
NS_DATA_VALIDATE='http://jabber.org/protocol/xdata-validate'            # XEP-0122
102
115
NS_XMPP_STREAMS ='urn:ietf:params:xml:ns:xmpp-streams'
 
116
NS_RECEIPTS     ='urn:xmpp:receipts'
103
117
 
104
118
xmpp_stream_error_conditions="""
105
119
bad-format --  --  -- The entity has sent XML that cannot be processed.
159
173
temporary-auth-failure --  --  -- The authentication failed because of a temporary error condition within the receiving entity; sent in reply to an <auth/> element or <response/> element."""
160
174
 
161
175
ERRORS,_errorcodes={},{}
162
 
for ns,errname,errpool in [(NS_XMPP_STREAMS,'STREAM',xmpp_stream_error_conditions),
 
176
for ns,errname,errpool in ((NS_XMPP_STREAMS,'STREAM',xmpp_stream_error_conditions),
163
177
                           (NS_STANZAS     ,'ERR'   ,xmpp_stanza_error_conditions),
164
 
                           (NS_SASL        ,'SASL'  ,sasl_error_conditions)]:
 
178
                           (NS_SASL        ,'SASL'  ,sasl_error_conditions)):
165
179
    for err in errpool.split('\n')[1:]:
166
180
        cond,code,typ,text=err.split(' -- ')
167
181
        name=errname+'_'+cond.upper().replace('-','_')
240
254
            JID(node='node',domain='domain.org')
241
255
        """
242
256
        if not jid and not domain: raise ValueError('JID must contain at least domain name')
243
 
        elif type(jid)==type(self): self.node,self.domain,self.resource=jid.node,jid.domain,jid.resource
 
257
        elif isinstance(jid, type(self)): self.node,self.domain,self.resource=jid.node,jid.domain,jid.resource
244
258
        elif domain: self.node,self.domain,self.resource=node,domain,resource
245
259
        else:
246
260
            if jid.find('@')+1: self.node,jid=jid.split('@',1)
307
321
        if not node and xmlns: self.setNamespace(xmlns)
308
322
        if self['to']: self.setTo(self['to'])
309
323
        if self['from']: self.setFrom(self['from'])
310
 
        if node and type(self)==type(node) and self.__class__==node.__class__ and self.attrs.has_key('id'): del self.attrs['id']
 
324
        if node and isinstance(self, type(node)) and self.__class__==node.__class__ and 'id' in self.attrs: del self.attrs['id']
311
325
        self.timestamp=None
312
 
        for x in self.getTags('x',namespace=NS_DELAY):
 
326
        for d in self.getTags('delay',namespace=NS_DELAY2):
313
327
            try:
314
 
                if x.getAttr('stamp')<self.getTimestamp(): self.setTimestamp(x.getAttr('stamp'))
 
328
                if d.getAttr('stamp')<self.getTimestamp2(): self.setTimestamp(d.getAttr('stamp'))
315
329
            except: pass
 
330
        if not self.timestamp:
 
331
            for x in self.getTags('x',namespace=NS_DELAY):
 
332
                try:
 
333
                    if x.getAttr('stamp')<self.getTimestamp(): self.setTimestamp(x.getAttr('stamp'))
 
334
                except: pass
316
335
        if timestamp is not None: self.setTimestamp(timestamp)  # To auto-timestamp stanza just pass timestamp=''
317
336
    def getTo(self):
318
337
        """ Return value of the 'to' attribute. """
326
345
        """ Return the timestamp in the 'yyyymmddThhmmss' format. """
327
346
        if self.timestamp: return self.timestamp
328
347
        return time.strftime('%Y%m%dT%H:%M:%S', time.gmtime())
 
348
    def getTimestamp2(self):
 
349
        """ Return the timestamp in the 'yyyymmddThhmmss' format. """
 
350
        if self.timestamp: return self.timestamp
 
351
        return time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime())
329
352
    def getID(self):
330
353
        """ Return the value of the 'id' attribute. """
331
354
        return self.getAttr('id')
349
372
        errtag=self.getTag('error')
350
373
        if errtag:
351
374
            for tag in errtag.getChildren():
352
 
                if tag.getName()<>'text': return tag.getName()
 
375
                if tag.getName()!='text': return tag.getName()
353
376
            return errtag.getData()
354
377
    def getErrorMsg(self):
355
378
        """ Return the textual description of the error (if present) or the error condition """
366
389
        if code:
367
390
            if str(code) in _errorcodes.keys(): error=ErrorNode(_errorcodes[str(code)],text=error)
368
391
            else: error=ErrorNode(ERR_UNDEFINED_CONDITION,code=code,typ='cancel',text=error)
369
 
        elif type(error) in [type(''),type(u'')]: error=ErrorNode(error)
 
392
        elif isinstance(error, basestring): error=ErrorNode(error)
370
393
        self.setType('error')
371
394
        self.addChild(node=error)
372
395
    def setTimestamp(self,val=None):
395
418
        Protocol.__init__(self, 'message', to=to, typ=typ, attrs=attrs, frm=frm, payload=payload, timestamp=timestamp, xmlns=xmlns, node=node)
396
419
        if body: self.setBody(body)
397
420
        if xhtml: self.setXHTML(xhtml)
398
 
        if subject != None: self.setSubject(subject)
 
421
        if subject is not None: self.setSubject(subject)
399
422
    def getBody(self):
400
423
        """ Returns text of the message. """
401
424
        return self.getTagData('body')
449
472
        th=self.getThread()
450
473
        if th: m.setThread(th)
451
474
        return m
 
475
    def getStatusCode(self):
 
476
        """Returns the status code of the message (for groupchat config
 
477
        change)"""
 
478
        attrs = []
 
479
        for xtag in self.getTags('x'):
 
480
            for child in xtag.getTags('status'):
 
481
                attrs.append(child.getAttr('code'))
 
482
        return attrs
452
483
 
453
484
class Presence(Protocol):
454
485
    """ XMPP Presence object."""
481
512
 
482
513
    def _muc_getItemAttr(self,tag,attr):
483
514
        for xtag in self.getTags('x'):
 
515
            if xtag.getNamespace() not in (NS_MUC_USER, NS_MUC_ADMIN):
 
516
                continue
484
517
            for child in xtag.getTags(tag):
485
518
                return child.getAttr(attr)
486
519
    def _muc_getSubTagDataAttr(self,tag,attr):
487
520
        for xtag in self.getTags('x'):
 
521
            if xtag.getNamespace() not in (NS_MUC_USER, NS_MUC_ADMIN):
 
522
                continue
488
523
            for child in xtag.getTags('item'):
489
524
                for cchild in child.getTags(tag):
490
525
                    return cchild.getData(),cchild.getAttr(attr)
563
598
        """ Create new error node object.
564
599
            Mandatory parameter: name - name of error condition.
565
600
            Optional parameters: code, typ, text. Used for backwards compartibility with older jabber protocol."""
566
 
        if ERRORS.has_key(name):
 
601
        if name in ERRORS:
567
602
            cod,type,txt=ERRORS[name]
568
603
            ns=name.split()[0]
569
604
        else: cod,ns,type,txt='500',NS_STANZAS,'cancel',''
603
638
            """
604
639
        Node.__init__(self,'field',node=node)
605
640
        if name: self.setVar(name)
606
 
        if type(value) in [list,tuple]: self.setValues(value)
 
641
        if isinstance(value, (list, tuple)): self.setValues(value)
607
642
        elif value: self.setValue(value)
608
643
        if typ: self.setType(typ)
609
644
        elif not typ and not node: self.setType('text-single')
654
689
        for opt in lst: self.addOption(opt)
655
690
    def addOption(self,opt):
656
691
        """ Add one more label-option pair to this field."""
657
 
        if type(opt) in [str,unicode]: self.addChild('option').setTagData('value',opt)
 
692
        if isinstance(opt, basestring): self.addChild('option').setTagData('value',opt)
658
693
        else: self.addChild('option',{'label':opt[0]}).setTagData('value',opt[1])
659
694
    def getType(self):
660
695
        """ Get type of this field. """
697
732
        if typ: self.setType(typ)
698
733
        self.setNamespace(NS_DATA)
699
734
        if title: self.setTitle(title)
700
 
        if type(data)==type({}):
 
735
        if isinstance(data, dict):
701
736
            newdata=[]
702
737
            for name in data.keys(): newdata.append(DataField(name,data[name]))
703
738
            data=newdata
704
739
        for child in data:
705
 
            if type(child) in [type(''),type(u'')]: self.addInstructions(child)
 
740
            if isinstance(child, basestring): self.addInstructions(child)
706
741
            elif child.__class__.__name__=='DataField': self.kids.append(child)
707
742
            else: self.kids.append(DataField(node=child))
708
743
    def getType(self):
740
775
        for field in self.getTags('field'):
741
776
            name=field.getAttr('var')
742
777
            typ=field.getType()
743
 
            if type(typ) in [type(''),type(u'')] and typ[-6:]=='-multi':
 
778
            if isinstance(typ, basestring) and typ.endswith('-multi'):
744
779
                val=[]
745
780
                for i in field.getTags('value'): val.append(i.getData())
746
781
            else: val=field.getTagData('value')
755
790
    def __setitem__(self,name,val):
756
791
        """ Simple dictionary interface for setting datafields values by their names."""
757
792
        return self.setField(name).setValue(val)
 
793
 
 
794
# vim: se ts=3: