Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Firefox and namepaces #42

Closed
cajus opened this issue Jan 31, 2013 · 2 comments
Closed

Firefox and namepaces #42

cajus opened this issue Jan 31, 2013 · 2 comments

Comments

@cajus
Copy link
Contributor

cajus commented Jan 31, 2013

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?

@rraptorr
Copy link
Collaborator

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())

@cajus
Copy link
Contributor Author

cajus commented Jan 31, 2013

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

@cajus cajus closed this as completed Jan 31, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants