xmpp4r and Iq.new_register for in-band registration

人盡茶涼 提交于 2019-12-23 02:59:13

问题


I've been having trouble using xmpp4r to do in-band registration following the SO thread here:

XMPP transport to another protocol

The problem comes down to that I get a NoMethodError Exception error for new_register when I run the following code:

require "xmpp4r"
require "xmpp4r/client" 
require "xmpp4r/iq"

def in_band_reg

     chat_name = 'testChatName'
     password  = 'pword'

     reg    = Jabber::Iq.new_register(chat_name, password)

end

NoMethodError Exception: undefined method `new_register' for Jabber::Iq:Class

In the xmpp4r gem in the file iq.rb I can see the new_register method defined as:

 def Iq.new_register(username=nil, password=nil)
        ...
 end

but when I examine the class's methods I'm not able to see the new_register method. I.E.

Jabber::Iq.singleton_methods(false)
["new_authset", "new_rosterget", "new_vcard", "new_rosterset", "import",    "new_authset_digest", "new_query", "add_elementclass", "new_browseget"]

Jabber::Iq.public_instance_methods(false)
 ["query=", "queryns", "set_type", "type", "typed_add", "type=", "query", "vcard"]

Jabber::Iq.respond_to?("new_register")
false

Any idea why I can't access the new_register method in 'xmpp4r/iq' ?


回答1:


I got this working by just coding it up myself. First connect a client that can in-band register new users:

jid = JID::new('admin@ejabberd.server.com/res')
client = Client::new(jid, false)
client.connect
client.auth("admin_password")

then have that client register a new user by sending an in-band message

iqr = Iq.new(:set)
qr = IqQuery.new
qr.add_namespace('jabber:iq:register')
username = 'new_user'
password = 'new_user_password'
qr.add(REXML::Element.new('username').add_text(username))
qr.add(REXML::Element.new('password').add_text(password))
iqr.add(qr)
client.send iqr



回答2:


What version of xmpp4r are you using? Have you tried the GitHub version?

gem sources -a http://gems.github.com (you only need to do this once!)
gem install ln-xmpp4r


来源:https://stackoverflow.com/questions/4866527/xmpp4r-and-iq-new-register-for-in-band-registration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!