2

I'm trying to create a nodejs component using node-xmpp-component. But I keep getting error code 400, type modify, bad request, but I don't see anything wrong with my iq message.

My ejabberd configuration:

{5282, ejabberd_service, [ 
    { hosts, ["nodejs.myejabberddomain"], [{password, "admin"}] } 
 ]}

My nodejs Component code:

var Component = require('node-xmpp-component')
  , ltx = require('node-xmpp-core').ltx;


var component = new Component({
  jid       : "nodejs.myejabberddomain",
  password  : "admin",
  host      : "localhost",
  port      : "5282"
})

component.on('online', function() {
    console.log('Component is online')

    var iq = new ltx.Element('iq',{type:'set',id:'reg2', to: 'myejabberddomain'})
                .c('query',{xmlns:'jabber:iq:register'});

    component.send(iq);

})

component.on('error', function(e) {
    console.error(e)
    process.exit(1)
})

I'm not sure if I have any ejabberd configuration missing, or if I have any problem with my nodejs component connection or if this nodejs-xmpp-component is "broken"!

Anyone knows what I'm doing wrong? Any tips?

Canastro
  • 2,979
  • 30
  • 39

3 Answers3

0

Using version 1.0.0-alpha1 I am able to sucessfully connect to a prosody server using your code above.

Do you receive your 'online' message? if so my suggestion would be that your ejabberd server doesn't support registering and is sending you an error response?

Lloyd Watkin
  • 485
  • 4
  • 10
  • Yes I receive a online message, and I get error "400 modify" to the registration request. I guess that if registration wasnt supported I would receive a "cancel" error. – Canastro Jun 11 '14 at 09:21
  • Right so in this case the issue isn't node-xmpp-component at all as that appears to be working fine. There's something with ejabberd or its setup. – Lloyd Watkin Jun 11 '14 at 09:29
  • Could you just send yourself a simple IM to a connected client? This would (mostly) show you whether it's ejabberd or the component code. – Lloyd Watkin Jun 11 '14 at 15:44
  • I'm sorry, I've been on vacation the past few days. Soon I'll answer this and your comment on github. thank you – Canastro Jun 24 '14 at 09:46
0

From XEP-0114: Jabber Component Protocol:

Once authenticated, the component can send stanzas through the server and receive stanzas from the server. All stanzas sent to the server MUST possess a 'from' attribute and a 'to' attribute, as in the 'jabber:server' namespace. The domain identifier portion of the JID contained in the 'from' attribute MUST match the hostname of the component. However, this is the only restriction on 'from' addresses, and the component MAY send stanzas from any user at its hostname.

vitalyster
  • 4,980
  • 3
  • 19
  • 27
  • So if I did this: var iq = new ltx.Element('iq',{type:'set',id:'reg2', to: 'myejabberddomain', from: 'admin@nodejs.myejabberddomain'}) .c('query',{xmlns:'jabber:iq:register'}); I still get the same message... – Canastro Jun 11 '14 at 09:04
  • What do you want to achieve with "registration" of component user? ejabberd may just not handle these queries as unusual. If you want to register ejabberd user on the component side - component need to provide its own registration form. – vitalyster Jun 11 '14 at 11:44
0

I've changed from ejabberd to prosody, but at first the registration was returning "service-unavailable".

So I had to go on prosody chat, and user called Zash helped me creating a module named mod_register_from_component.

In the lines 182 to 185 I changed the original mod_register to:

module:hook("iq/host/jabber:iq:register:query", function(event)
   local session, stanza = event.origin, event.stanza;

   if session.type ~= "component" then

Then in the prosody.cfg.lua in the modules_enabled I added my new module (and commented the original one)

Canastro
  • 2,979
  • 30
  • 39