Skip to content
This repository
Browse code

Merge branch 'master' into develop

  • Loading branch information...
commit 77f2a339e1626501a1df388050f09342d7bbcd1d 2 parents 7c485c6 + 4190027
Lance Stout authored October 15, 2012
6  sleekxmpp/basexmpp.py
@@ -212,6 +212,10 @@ def start_stream_handler(self, xml):
212 212
         self.stream_version = xml.get('version', '')
213 213
         self.peer_default_lang = xml.get('{%s}lang' % XML_NS, None)
214 214
 
  215
+        if not self.is_component and not self.stream_version:
  216
+            log.warning('Legacy XMPP 0.9 protocol detected.')
  217
+            self.event('legacy_protocol')
  218
+
215 219
     def process(self, *args, **kwargs):
216 220
         """Initialize plugins and begin processing the XML stream.
217 221
 
@@ -742,6 +746,8 @@ def _handle_new_subscription(self, pres):
742 746
         item = self.roster[pres['to']][pres['from']]
743 747
         if item['whitelisted']:
744 748
             item.authorize()
  749
+            if roster.auto_subscribe:
  750
+                item.subscribe()
745 751
         elif roster.auto_authorize:
746 752
             item.authorize()
747 753
             if roster.auto_subscribe:
2  sleekxmpp/clientxmpp.py
@@ -273,6 +273,8 @@ def _handle_stream_features(self, features):
273 273
                     # Don't continue if the feature requires
274 274
                     # restarting the XML stream.
275 275
                     return True
  276
+        log.debug('Finished processing stream features.')
  277
+        self.event('stream_negotiated')
276 278
 
277 279
     def _handle_roster(self, iq):
278 280
         """Update the roster after receiving a roster stanza.
2  sleekxmpp/features/feature_mechanisms/mechanisms.py
@@ -44,7 +44,7 @@ class FeatureMechanisms(BasePlugin):
44 44
     }
45 45
 
46 46
     def plugin_init(self):
47  
-        if not self.use_mech and not self.xmpp.boundjid.user:
  47
+        if not self.use_mech and not self.xmpp.requested_jid.user:
48 48
             self.use_mech = 'ANONYMOUS'
49 49
 
50 50
         if self.sasl_callback is None:
1  sleekxmpp/plugins/xep_0054/stanza.py
@@ -541,6 +541,7 @@ def get_tz(self):
541 541
 register_stanza_plugin(VCardTemp, Mailer, iterable=True)
542 542
 register_stanza_plugin(VCardTemp, Note, iterable=True)
543 543
 register_stanza_plugin(VCardTemp, Nickname, iterable=True)
  544
+register_stanza_plugin(VCardTemp, Org, iterable=True)
544 545
 register_stanza_plugin(VCardTemp, Photo, iterable=True)
545 546
 register_stanza_plugin(VCardTemp, ProdID, iterable=True)
546 547
 register_stanza_plugin(VCardTemp, Rev, iterable=True)
29  sleekxmpp/plugins/xep_0078/legacyauth.py
@@ -44,16 +44,27 @@ def plugin_init(self):
44 44
                 restart=False,
45 45
                 order=self.order)
46 46
 
  47
+        self.xmpp.add_event_handler('legacy_protocol',
  48
+                self._handle_legacy_protocol)
  49
+
47 50
         register_stanza_plugin(Iq, stanza.IqAuth)
48 51
         register_stanza_plugin(StreamFeatures, stanza.AuthFeature)
49 52
 
50 53
     def plugin_end(self):
  54
+        self.xmpp.del_event_handler('legacy_protocol',
  55
+                self._handle_legacy_protocol)
51 56
         self.xmpp.unregister_feature('auth', self.order)
52 57
 
53 58
     def _handle_auth(self, features):
54 59
         # If we can or have already authenticated with SASL, do nothing.
55 60
         if 'mechanisms' in features['features']:
56 61
             return False
  62
+        return self.authenticate()
  63
+
  64
+    def _handle_legacy_protocol(self, event):
  65
+        self.authenticate()
  66
+
  67
+    def authenticate(self):
57 68
         if self.xmpp.authenticated:
58 69
             return False
59 70
 
@@ -62,13 +73,13 @@ def _handle_auth(self, features):
62 73
         # Step 1: Request the auth form
63 74
         iq = self.xmpp.Iq()
64 75
         iq['type'] = 'get'
65  
-        iq['to'] = self.xmpp.boundjid.host
66  
-        iq['auth']['username'] = self.xmpp.boundjid.user
  76
+        iq['to'] = self.xmpp.requested_jid.host
  77
+        iq['auth']['username'] = self.xmpp.requested_jid.user
67 78
 
68 79
         try:
69 80
             resp = iq.send(now=True)
70  
-        except IqError:
71  
-            log.info("Authentication failed: %s", resp['error']['condition'])
  81
+        except IqError as err:
  82
+            log.info("Authentication failed: %s", err.iq['error']['condition'])
72 83
             self.xmpp.event('failed_auth', direct=True)
73 84
             self.xmpp.disconnect()
74 85
             return True
@@ -81,11 +92,11 @@ def _handle_auth(self, features):
81 92
         # Step 2: Fill out auth form for either password or digest auth
82 93
         iq = self.xmpp.Iq()
83 94
         iq['type'] = 'set'
84  
-        iq['auth']['username'] = self.xmpp.boundjid.user
  95
+        iq['auth']['username'] = self.xmpp.requested_jid.user
85 96
 
86 97
         # A resource is required, so create a random one if necessary
87  
-        if self.xmpp.boundjid.resource:
88  
-            iq['auth']['resource'] = self.xmpp.boundjid.resource
  98
+        if self.xmpp.requested_jid.resource:
  99
+            iq['auth']['resource'] = self.xmpp.requested_jid.resource
89 100
         else:
90 101
             iq['auth']['resource'] = '%s' % random.random()
91 102
 
@@ -109,12 +120,12 @@ def _handle_auth(self, features):
109 120
             result = iq.send(now=True)
110 121
         except IqError as err:
111 122
             log.info("Authentication failed")
112  
-            self.xmpp.disconnect()
113 123
             self.xmpp.event("failed_auth", direct=True)
  124
+            self.xmpp.disconnect()
114 125
         except IqTimeout:
115 126
             log.info("Authentication failed")
116  
-            self.xmpp.disconnect()
117 127
             self.xmpp.event("failed_auth", direct=True)
  128
+            self.xmpp.disconnect()
118 129
 
119 130
         self.xmpp.features.add('auth')
120 131
 
2  sleekxmpp/plugins/xep_0084/avatar.py
@@ -69,6 +69,8 @@ def publish_avatar_metadata(self, items=None, pointers=None,
69 69
         metadata = MetaData()
70 70
         if items is None:
71 71
             items = []
  72
+        if not isinstance(items, (list, set)):
  73
+            items = [items]
72 74
         for info in items:
73 75
             metadata.add_info(info['id'], info['type'], info['bytes'],
74 76
                     height=info.get('height', ''),
7  sleekxmpp/xmlstream/tostring.py
@@ -70,9 +70,10 @@ def tostring(xml=None, xmlns='', stream=None,
70 70
 
71 71
     # Output the tag name and derived namespace of the element.
72 72
     namespace = ''
73  
-    if top_level and tag_xmlns not in [default_ns, xmlns, stream_ns] \
74  
-      or not top_level and tag_xmlns != xmlns:
75  
-        namespace = ' xmlns="%s"' % tag_xmlns
  73
+    if tag_xmlns:
  74
+        if top_level and tag_xmlns not in [default_ns, xmlns, stream_ns] \
  75
+          or not top_level and tag_xmlns != xmlns:
  76
+            namespace = ' xmlns="%s"' % tag_xmlns
76 77
     if stream and tag_xmlns in stream.namespace_map:
77 78
         mapped_namespace = stream.namespace_map[tag_xmlns]
78 79
         if mapped_namespace:

0 notes on commit 77f2a33

Please sign in to comment.
Something went wrong with that request. Please try again.