sstrigler / JSJaC

JavaScript Jabber Client Library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Firefox and namepaces

cajus opened this issue · comments

I've a problem when generating custom packets in firefox (18.0.1 in this case). For example here's code that adds capabilities:

JSJaCPresence.prototype.setC = function() {
  var c = this._setChildNode("c", "");
  c.setAttribute('ver', "1.0");
  c.setAttribute('node', "http://example.net/caps");
  c.setAttribute('xmlns', "http://jabber.org/protocol/caps");
  return this;
}

var p = new JSJaCPresence();
p.setC();
con.send(p);

This works fine in Chrome - it sends:

<presence xmlns="jabber:client">
  <c ver="1.0" node="http://example.net/caps" xmlns="http://jabber.org/protocol/caps"></c>
</presence>

Firefox tries to send:

<presence xmlns="jabber:client">
  <a0:c xmlns:a0="jabber:client" ver="1.0" node="http://example.net/caps" xmlns="http://jabber.org/protocol/caps"></a0:c>
</presence>

which gets lost on the way somewhere - I'm not getting PEP notifications I'm registered for.

There seem to be more strange namespace problems in firefox:

          var iq = new JSJaCIQ();

          iq.setTo(new JSJaCJID(to));
          iq.setType("set");
          iq.setID(id);
          iq.setQuery("jabber:iq:rpc");
          iq.getChild().appendChild(
                iq.buildNode("methodCall", [
                    iq.buildNode("methodName", "foo"),
                    []]));

Firefox adds a xmlns='' to methodCall which makes the receiving entity reject the packet.

Did I miss something in my code? Any idea why that happens?

You are using private functions (with underscore), which don't work as you would expect. Also, namespaces in XML are not ordinary attributes, you cannot get them to work properly by setAttribute. Just stick to the public methods:

var p = new JSJaCPresence();
var c = p.buildNode("c", {"xmlns": "http://jabber.org/protocol/caps"});
c.setAttribute("ver", "1.0");
c.setAttribute("node", "http://example.net/caps");
p.appendNode(c);
console.log(p.xml());

In case of IQ, the output is actually correct. You have created methodCall with empty namespace, so if it append to to an element with jabber:iq:rpc default namespace, empty xmlns is created. You must specifiy XML namespace for every element you create (as said above, XML namespaces are not simple attributes).

var iq = new JSJaCIQ();
iq.setType("set");
iq.setQuery("jabber:iq:rpc");
iq.getChild().appendChild(
  iq.buildNode("methodCall", {"xmlns": "jabber:iq:rpc"}, [
    iq.buildNode("methodName", {"xmlns": "jabber:iq:rpc"}, "foo"), []]));
console.log(iq.xml())

Ahhh. I didn't know these ones. Thanks for your quick reply!