xmppo / node-xmpp-bosh

An XMPP BOSH & WebSocket server (connection manager) written on node.js using Javascript
https://github.com/xmppo/node-xmpp-bosh
263 stars 85 forks source link

PHP Prebind with node-xmpp-bosh #102

Closed majimboo closed 10 years ago

majimboo commented 10 years ago

Is there any library that in PHP that can prebind with this bosh manager? I am using openfire. I keep getting XML Parsing ERROR

<?xml version="1.0" encoding="UTF-8"?>
<body xmlns="http://jabber.org/protocol/httpbind" content="text/xml charset=utf-8" 
  rid="4501812881" xml:lang="en" hold="1" to="xxxxx" 
  route="xmpp:xxxx:7070" xmlns:xmpp="urn:xmpp:xbosh" xmpp:version="1.0" wait="60"/>

Also how does prebinding work? I am using PHP, do I only do the prebind on login? or on every refresh? I get dc'ed on every refresh only the connection after the login works. I am using XMPP like facebook chat on my website.

Also how do I specify that this bosh forward connection to openfires port 7070?

dhruvbird commented 10 years ago

Sorry, but I have no idea what "prebind" means. Please could you elaborate?

majimboo commented 10 years ago

I too am lost. I believe pre-binding is when you attach to an existing connection.

Let us say I logged into my website, together with my authentication I also sent a login request to openfire.

Now I am authenticated in both my site and the openfire server. So I won't be logging into the openfire server on each page refresh I will do something like a pre bind, where I just attach to the session_id that was created when I first login. On each refresh of the page I attach to the session.

Also is there a way for node-xmpp-bosh to have a pre-defined connection? the BOSH of openfire defaults to port 7070. Should I use this to point to the openfire bosh? or do I connect to the openfire server directly from this bosh manager.

Technically is it?

 node-xmpp-bosh:5280-> openfire-bosh:7070 -> openfire:5222

or

 node-xmpp-bosh:5280-> openfire:5222
dhruvbird commented 10 years ago

You will need to connect directly to the openfile server on port 5222 (which is probably the default).

It's 5280 -> 5222

The pre-binding is probably handled by the client library using cookies to store our session ID and rid.

majimboo commented 10 years ago

So if I reload the page will this node-xmpp-bosh still remember me? I mean won't it kill my session once I refresh the page?

majimboo commented 10 years ago

Anyways, I would just like to point out my first question.

Why was I getting the XML error? Thank you.

dhruvbird commented 10 years ago

@majimboo It's client library specific - you will need to consult the docs. of the specific client library you are using.

Also, where exactly do you get the XML error? Please could you run the proxy with TRACE level logging and print some context and stack traces (if any) so that I can try to know what's going on.

majimboo commented 10 years ago

Was getting this:

[2014-03-16 17:18:49.867] [TRACE] [http-server.js:Server.http_request_handler:317] - Processing POST request at location: /http-bind/
[2014-03-16 17:18:49.871] [DEBUG] [bosh-request-parser.js:BoshRequestParser.dutil.copy.reset:66] - Reseting parser state
[2014-03-16 17:18:49.872] [WARN] [http-server.js:UNKNOWN:00] - XML parsing Error: <?xml version="1.0" encoding="UTF-8"?>
<body xmlns="http://jabber.org/protocol/httpbind" content="text/xml charset=utf-8" rid="7591898397" xml:lang="en" hold="1" to="channel.xxxxxx.com" xmlns:xmpp="urn:xmpp:xbosh" xmpp:version="1.0" wait="60"/>

Then I tried using punjab with the same client and there was no error. Changed back to this and still getting the error.

dhruvbird commented 10 years ago

@majimboo Don't send the XML header in the request. That is causing the parser to get confused.

majimboo commented 10 years ago

@dhruvbird shouldn't it also accept this? most bosh managers do. I've tried 2 and only this one gives this error. Anyways, Thank you for your help. I was also thinking that was the case. Great work btw :)

dhruvbird commented 10 years ago

@majimboo All examples on http://xmpp.org/extensions/xep-0124.html#wrapper suggest that the XML declaration isn't part of the request.

smokku commented 10 years ago

Every time you start XML document it is allowed to begin with XML declaration. We allow XML declaration as a beginning of document in XMPP, even though XMPP stream is not exactly an XML document. In BOSH one may treat every request as separate document.

Remember the Robustness principle: "Be conservative in what you send, and liberal in what you accept".

Also, XML declaration allows you to check the encoding used by the client and bork when it is not UTF-8 (you don't have to support all encodings, but should fail on unsupported ones).

majimboo commented 10 years ago

I see. That makes sense. :+1:

dhruvbird commented 10 years ago

@smokku I agree with "Be conservative in what you send, and liberal in what you accept", and in an ideal world, it would be nice to accept the xml declaration with every request, but this was a choice made early on, and am happy to accept patches that fix the same w/o affecting performance in the common case.

w.r.t. the encoding, I didn't get you - you can always send it in the "content" attribute of the body tag. nxb doesn't respect this as of now and always expects 'text/xml; charset=utf-8'.

majimboo commented 10 years ago

Honestly I am just using a toolkit available on github for the pre-binding. Which the case builds that xml declaration. I have modified the source to not include it. All is well.

smokku commented 10 years ago

Handling the XML declaration allows you to bork if one connects with i.e. charset=iso-8859-1 early instead later on with some cryptic parse error.