Mercurial > libervia-backend
comparison src/plugins/plugin_xep_0033.py @ 999:c37a24922f27
plugin XEP_0033: fixes the server part and the tests
author | souliane <souliane@mailoo.org> |
---|---|
date | Fri, 11 Apr 2014 11:02:42 +0200 |
parents | 301b342c697a |
children | e88bff4c8b77 |
comparison
equal
deleted
inserted
replaced
998:f5761534e0f3 | 999:c37a24922f27 |
---|---|
80 | 80 |
81 def treatment(mess_data): | 81 def treatment(mess_data): |
82 if not 'address' in mess_data['extra']: | 82 if not 'address' in mess_data['extra']: |
83 return mess_data | 83 return mess_data |
84 | 84 |
85 def discoCallback(entity): | 85 def discoCallback(entities): |
86 if entity is None: | 86 if not entities: |
87 return Failure(AbortSendMessage(_("XEP-0033 is being used but the server doesn't support it!"))) | 87 return Failure(AbortSendMessage(_("XEP-0033 is being used but the server doesn't support it!"))) |
88 if mess_data["to"] != entity: | 88 if mess_data["to"] not in entities: |
89 log.warning(_("Stanzas using XEP-0033 should be addressed to %(expected)s, not %(current)s!") % {'expected': entity, 'current': mess_data["to"]}) | 89 expected = _(' or ').join([entity.userhost() for entity in entities]) |
90 log.warning(_("TODO: addressing has be fixed by the backend... fix it in the frontend!")) | 90 log.warning(_("Stanzas using XEP-0033 should be addressed to %(expected)s, not %(current)s!") % {'expected': expected, 'current': mess_data["to"]}) |
91 mess_data["to"] = entity | 91 log.warning(_("TODO: addressing has been fixed by the backend... fix it in the frontend!")) |
92 mess_data["to"] = list(entities)[0].userhostJID() | |
92 element = mess_data['xml'].addElement('addresses', NS_ADDRESS) | 93 element = mess_data['xml'].addElement('addresses', NS_ADDRESS) |
93 entries = [entry.split(':') for entry in mess_data['extra']['address'].split('\n') if entry != ''] | 94 entries = [entry.split(':') for entry in mess_data['extra']['address'].split('\n') if entry != ''] |
94 for type_, jid_ in entries: | 95 for type_, jid_ in entries: |
95 element.addChild(domish.Element((None, 'address'), None, {'type': type_, 'jid': jid_})) | 96 element.addChild(domish.Element((None, 'address'), None, {'type': type_, 'jid': jid_})) |
96 # when the prosody plugin is completed, we can immediately return mess_data from here | 97 # when the prosody plugin is completed, we can immediately return mess_data from here |
97 self.sendAndStoreMessage(mess_data, entries, profile) | 98 self.sendAndStoreMessage(mess_data, entries, profile) |
98 return Failure(MessageSentAndStored("XEP-0033 took over", mess_data)) | 99 return Failure(MessageSentAndStored("XEP-0033 took over", mess_data)) |
99 d = self.host.requestServerDisco(NS_ADDRESS, profile_key=profile) | 100 d = self.host.findFeaturesSet([NS_ADDRESS], profile_key=profile) |
100 d.addCallbacks(discoCallback, lambda dummy: discoCallback(None)) | 101 d.addCallbacks(discoCallback, lambda dummy: discoCallback(None)) |
101 return d | 102 return d |
102 | 103 |
103 post_xml_treatments.addCallback(treatment) | 104 post_xml_treatments.addCallback(treatment) |
104 return True | 105 return True |
114 Ideas: | 115 Ideas: |
115 - fix Prosody plugin to check if target server support the feature | 116 - fix Prosody plugin to check if target server support the feature |
116 - redesign the database to save only one entry to the database | 117 - redesign the database to save only one entry to the database |
117 - change the newMessage signal to eventually pass more than one recipient | 118 - change the newMessage signal to eventually pass more than one recipient |
118 """ | 119 """ |
119 def discoCallback(entity, to_jid): | 120 def discoCallback(entities, to_jid_s): |
120 new_data = copy.deepcopy(mess_data) | 121 history_data = copy.deepcopy(mess_data) |
121 new_data['to'] = JID(to_jid) | 122 history_data['to'] = JID(to_jid_s) |
122 new_data['xml']['to'] = to_jid | 123 history_data['xml']['to'] = to_jid_s |
123 if entity: | 124 if entities: |
124 if entity not in self.internal_data[timestamp]: | 125 if entities not in self.internal_data[timestamp]: |
125 self.host.sendAndStoreMessage(mess_data, False, profile) | 126 sent_data = copy.deepcopy(mess_data) |
126 self.internal_data[timestamp].append(entity) | 127 sent_data['to'] = JID(JID(to_jid_s).host) |
128 sent_data['xml']['to'] = JID(to_jid_s).host | |
129 self.host.sendAndStoreMessage(sent_data, False, profile) | |
130 self.internal_data[timestamp].append(entities) | |
127 # we still need to fill the history and signal the echo... | 131 # we still need to fill the history and signal the echo... |
128 self.host.sendAndStoreMessage(new_data, True, profile) | 132 self.host.sendAndStoreMessage(history_data, True, profile) |
129 else: | 133 else: |
130 # target server misses the addressing feature | 134 # target server misses the addressing feature |
131 self.host.sendAndStoreMessage(new_data, False, profile) | 135 self.host.sendAndStoreMessage(history_data, False, profile) |
132 | 136 |
133 def errback(failure, to_jid): | 137 def errback(failure, to_jid): |
134 discoCallback(None, to_jid) | 138 discoCallback(None, to_jid) |
135 | 139 |
136 timestamp = time() | 140 timestamp = time() |
137 self.internal_data[timestamp] = [] | 141 self.internal_data[timestamp] = [] |
138 defer_list = [] | 142 defer_list = [] |
139 for type_, jid_ in entries: | 143 for type_, jid_ in entries: |
140 d = defer.Deferred() | 144 d = defer.Deferred() |
141 d.addCallback(self.host.requestServerDisco, JID(JID(jid_).host), profile_key=profile) | 145 d.addCallback(self.host.findFeaturesSet, jid_=JID(JID(jid_).host), profile_key=profile) |
142 d.addCallbacks(discoCallback, errback, callbackArgs=[jid_], errbackArgs=[jid_]) | 146 d.addCallbacks(discoCallback, errback, callbackArgs=[jid_], errbackArgs=[jid_]) |
143 d.callback(NS_ADDRESS) | 147 d.callback([NS_ADDRESS]) |
144 defer_list.append(d) | 148 defer_list.append(d) |
145 d = defer.Deferred().addCallback(lambda dummy: self.internal_data.pop(timestamp)) | 149 d = defer.Deferred().addCallback(lambda dummy: self.internal_data.pop(timestamp)) |
146 defer.DeferredList(defer_list).chainDeferred(d) | 150 defer.DeferredList(defer_list).chainDeferred(d) |
147 | 151 |
148 def messageReceivedTrigger(self, message, post_treat, profile): | 152 def messageReceivedTrigger(self, message, post_treat, profile): |