comparison lightstring.js @ 21:b7d52bf259e0

Coding style: always use "" for XML strings.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Thu, 26 Jan 2012 16:01:37 +0100
parents 7fcccf59e6ec
children 6a6bb8ded046
comparison
equal deleted inserted replaced
20:7fcccf59e6ec 21:b7d52bf259e0
33 */ 33 */
34 stanza: { 34 stanza: {
35 stream: { 35 stream: {
36 open: function(aService) { 36 open: function(aService) {
37 //FIXME no ending "/" - node-xmpp-bosh bug 37 //FIXME no ending "/" - node-xmpp-bosh bug
38 return "<stream:stream to='" + aService + "'\ 38 return "<stream:stream to='" + aService + "'" +
39 xmlns='" + Lightstring.NS.jabberClient + "'\ 39 " xmlns='" + Lightstring.NS.jabberClient + "'" +
40 xmlns:stream='" + Lightstring.NS.stream + "'\ 40 " xmlns:stream='" + Lightstring.NS.stream + "'" +
41 version='1.0'/>"; 41 " version='1.0'/>";
42 }, 42 },
43 close: function() { 43 close: function() {
44 return '</stream:stream>'; 44 return "</stream:stream>";
45 } 45 }
46 } 46 }
47 }, 47 },
48 /** 48 /**
49 * @private 49 * @private
96 96
97 97
98 //FIXME support SCRAM-SHA1 && allow specify method preferences 98 //FIXME support SCRAM-SHA1 && allow specify method preferences
99 if ('DIGEST-MD5' in mechanisms) 99 if ('DIGEST-MD5' in mechanisms)
100 that.send( 100 that.send(
101 "<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl'\ 101 "<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl'" +
102 mechanism='DIGEST-MD5'/>" 102 " mechanism='DIGEST-MD5'/>"
103 ); 103 );
104 else if ('PLAIN' in mechanisms) { 104 else if ('PLAIN' in mechanisms) {
105 var token = btoa( 105 var token = btoa(
106 that.jid + 106 that.jid +
107 '\u0000' + 107 '\u0000' +
108 that.jid.node + 108 that.jid.node +
109 '\u0000' + 109 '\u0000' +
110 that.password 110 that.password
111 ); 111 );
112 that.send( 112 that.send(
113 "<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl'\ 113 "<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl'" +
114 mechanism='PLAIN'>" + token + '</auth>' 114 " mechanism='PLAIN'>" + token + "</auth>"
115 ); 115 );
116 } 116 }
117 } 117 }
118 //XMPP features 118 //XMPP features
119 else { 119 else {
120 that.emit('features', stanza); 120 that.emit('features', stanza);
121 //Bind http://xmpp.org/rfcs/rfc3920.html#bind 121 //Bind http://xmpp.org/rfcs/rfc3920.html#bind
122 that.send( 122 that.send(
123 "<iq type='set' xmlns='jabber:client'>\ 123 "<iq type='set' xmlns='jabber:client'>" +
124 <bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'/>\ 124 "<bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'/>" +
125 </iq>", 125 "</iq>",
126 function() { 126 function() {
127 //Session http://xmpp.org/rfcs/rfc3921.html#session 127 //Session http://xmpp.org/rfcs/rfc3921.html#session
128 that.send( 128 that.send(
129 "<iq type='set' xmlns='jabber:client'>\ 129 "<iq type='set' xmlns='jabber:client'>" +
130 <session xmlns='urn:ietf:params:xml:ns:xmpp-session'/>\ 130 "<session xmlns='urn:ietf:params:xml:ns:xmpp-session'/>" +
131 </iq>", 131 "</iq>",
132 function() { 132 function() {
133 that.emit('connected'); 133 that.emit('connected');
134 } 134 }
135 ); 135 );
136 }); 136 });
137 } 137 }
138 }); 138 });
139 this.on('success', function(stanza, that) { 139 this.on('success', function(stanza, that) {
140 that.send( 140 that.send(
141 "<stream:stream to='" + that.host + "'\ 141 "<stream:stream to='" + that.host + "'" +
142 xmlns='jabber:client'\ 142 " xmlns='jabber:client'" +
143 xmlns:stream='http://etherx.jabber.org/streams'\ 143 " xmlns:stream='http://etherx.jabber.org/streams'" +
144 version='1.0' />" 144 " version='1.0'/>"
145 ); 145 );
146 }); 146 });
147 this.on('failure', function(stanza, that) { 147 this.on('failure', function(stanza, that) {
148 that.emit('conn-error', stanza.firstChild.tagName); 148 that.emit('conn-error', stanza.firstChild.tagName);
149 }); 149 });
184 break; 184 break;
185 } 185 }
186 } 186 }
187 187
188 var digest_uri = 'xmpp/' + that.host; 188 var digest_uri = 'xmpp/' + that.host;
189 if (host !== null) { 189 if (host !== null)
190 digest_uri = digest_uri + '/' + host; 190 digest_uri = digest_uri + '/' + host;
191 }
192 var A1 = MD5.hash(that.node + 191 var A1 = MD5.hash(that.node +
193 ':' + realm + ':' + that.password) + 192 ':' + realm + ':' + that.password) +
194 ':' + nonce + ':' + cnonce; 193 ':' + nonce + ':' + cnonce;
195 var A2 = 'AUTHENTICATE:' + digest_uri; 194 var A2 = 'AUTHENTICATE:' + digest_uri;
196 195
207 nonce + ':00000001:' + 206 nonce + ':00000001:' +
208 cnonce + ':auth:' + 207 cnonce + ':auth:' +
209 MD5.hexdigest(A2))) + ','; 208 MD5.hexdigest(A2))) + ',';
210 responseText += 'charset="utf-8"'; 209 responseText += 'charset="utf-8"';
211 that.send( 210 that.send(
212 "<response xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>" 211 "<response xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>" +
213 + btoa(responseText) + 212 btoa(responseText) +
214 '</response>'); 213 "</response>");
215 }); 214 });
216 }; 215 };
217 Lightstring.Connection.prototype = { 216 Lightstring.Connection.prototype = {
218 /** 217 /**
219 * @function Create and open a websocket then go though the XMPP authentification process. 218 * @function Create and open a websocket then go though the XMPP authentification process.
301 str = Lightstring.dom2xml(elm); 300 str = Lightstring.dom2xml(elm);
302 } 301 }
303 if (aCallback) 302 if (aCallback)
304 this.on(elm.getAttribute('id'), aCallback); 303 this.on(elm.getAttribute('id'), aCallback);
305 } 304 }
306 else if (aCallback) { 305 else if (aCallback)
307 this.emit('warning', 'Callback can\'t be called with non-iq stanza.'); 306 this.emit('warning', 'Callback can\'t be called with non-iq stanza.');
308 }
309 307
310 308
311 this.socket.send(str); 309 this.socket.send(str);
312 this.emit('XMLOutput', str); 310 this.emit('XMLOutput', str);
313 this.emit('DOMOutput', elm); 311 this.emit('DOMOutput', elm);