开发者

Why do all twisted/wokkel xmpp examples ignore the proper usage of JID in the xmpp protocol?

开发者 https://www.devze.com 2022-12-14 23:08 出处:网络
Okay, this isn\'t a question. All the examples of wokkel and twisted I have seen do not properly observe generated resources in the JID.

Okay, this isn't a question. All the examples of wokkel and twisted I have seen do not properly observe generated resources in the JID.

Google talk clients built using wokkel/twisted generally break because they do not set the full JID on responses, resulting in (very hidden, low level) errors like:

<message to="example@gmail.com" from="example2@synthasite.com/Example2C2F32A1" type="error"><body>echo: None</body><error code="400" type="modify"><bad-request xmlns="开发者_Python百科urn:ietf:params:xml:ns:xmpp-stanzas"/><text xmlns="urn:ietf:params:xml:ns:xmpp-stanzas">If set, the 'from' attribute must be set to the user's full JID.</text></error></message>

The full, server issued jid can be obtained in the protocol handler from self.parent.authenticator.jid.full()

So, when sending messages, ensure you use the full jid in your from field, or some servers will not like you and you will pull all your hair out, and cry.


In this particular case, the better answer to the non-question is that you should not set the from address at all. Every server will happily fill in the blank for you, saving you from figuring out what JID your client has.


According to my experiment, it is not self.parent.authenticator.jid.full() but self.parent.jid.full(). Code snippet as below

        reply = toResponse(msg, msg.getAttribute('type'))
        reply.addElement('body', content=unicode(msg.body))
        reply["from"] = self.parent.jid.full()
        self.send(reply)
0

精彩评论

暂无评论...
验证码 换一张
取 消