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

I have problem with XML parser using WebSockets #59

Closed ghost closed 11 years ago

ghost commented 11 years ago

Hi,

Im using this chat script: https://github.com/szimek/xmpp-chat In backend is running node-xmpp-bosh over ejabberd

I am also using Strophe, and to work with WebSockets use https://gist.github.com/739147

But, node-xmpp-bosh says this error:

root@host3 [/etc/bosh/src]# bosh
+---------------------------------------------------------------------------------------------------------------------------+
| Starting BOSH server 'v0.7.0' on 'http://0.0.0.0:5280/^\/http-bind(\/+)?$/' at 'Mon Jan 07 2013 23:29:05 GMT-0300 (CLST)' |
+---------------------------------------------------------------------------------------------------------------------------+
+--------------------------------------------------------------------------------------------------------+
| Starting WEBSOCKET server 'v0.7.0' on ws://0.0.0.0:5280' at 'Mon Jan 07 2013 23:29:05 GMT-0300 (CLST)' |
+--------------------------------------------------------------------------------------------------------+
[2013-01-08 02:29:12.625] [WARN] [dutil.js:_real_xml_parse:248] - _real_xml_parse::Error (Error: XML or text declaration not at start of entity) parsing XML: <dummy><?xml version="1.0"?><stream:stream xmlns:stream="http://etherx.jabber.org/streams" version="1.0" xmlns="jabber:client" to="localhost" xml:lang="en" xmlns:xml="http://www.w3.org/XML/1998/namespace" ></stream:stream></dummy>
[2013-01-08 02:29:12.627] [WARN] [dutil.js:_real_xml_parse:249] - Error: XML or text declaration not at start of entity
    at exports.Parser.write (/etc/bosh/node_modules/ltx/lib/parse.js:46:28)
    at Object.exports.parse (/etc/bosh/node_modules/ltx/lib/parse.js:77:7)
    at _real_xml_parse (/etc/bosh/src/dutil.js:245:14)
    at Object.xml_parse (/etc/bosh/src/dutil.js:267:10)
    at WebSocket.exports.createServer (/etc/bosh/src/websocket.js:185:31)
    at WebSocket.EventEmitter.emit (events.js:99:17)
    at Receiver.self._receiver.ontext (/etc/bosh/node_modules/ws/lib/WebSocket.js:514:10)
    at Receiver.opcodes.1.finish (/etc/bosh/node_modules/ws/lib/Receiver.js:397:14)
    at Receiver.opcodes.1.getData [as expectHandler] (/etc/bosh/node_modules/ws/lib/Receiver.js:378:33)
    at Receiver.add (/etc/bosh/node_modules/ws/lib/Receiver.js:93:24)
[2013-01-08 02:29:12.627] [WARN] [websocket.js:WebSocket.exports.createServer:187] - 94480a58-9b6b-4fbd-a322-3e6611ac3042 Closing connection due to invalid packet

I newbie in NodeJS, XMPP and WebSockets, so I have no idea who may be failing

PD: sorry for my english

dhruvbird commented 11 years ago

The <dummy></dummy> is causing a problem. This is added to prevent entity expansion and other forms of attacks on the xml stream. The BOSH parser has been changed with the correct fix and doesn't use the dummy tags any more, but the websocket bit has been largely ignored.

It's funny that it fails with strophe since that is the one we've been testing with.

ps. You need to enclose code any anything else that is pre-formatted and you want to be displayed verbatim in a pair of triple ticks (`).

ghost commented 11 years ago

But I can make this work as well?

dhruvbird commented 11 years ago

Commit c5523d22cb43c7742834e555714b494919da57d2 tries to hack-fix this. Please do let me know of it works for you.

ghost commented 11 years ago

bosh I guess it is working well. although the chat is not working, but I guess that is the script. Thank you very much...

dhruvbird commented 11 years ago

Welcome & thanks for reporting! :)

ghost commented 11 years ago

I was using an incorrect protocol. The correct protocol was proposed by you (for websockets): https://github.com/superfeedr/strophejs/tree/protocol-ed , not the one I was using: https://gist.github.com/739147

Again, thanks for your great work.

dhruvbird commented 11 years ago

Welcome - and thanks for the updates!