comparison mod_tcpproxy/web/strophe.js @ 1343:7dbde05b48a9

all the things: Remove trailing whitespace
author Florian Zeitz <florob@babelmonkeys.de>
date Tue, 11 Mar 2014 18:44:01 +0100
parents f2f9b965d1ad
children
comparison
equal deleted inserted replaced
1342:0ae065453dc9 1343:7dbde05b48a9
13 encode: function (input) { 13 encode: function (input) {
14 var output = ""; 14 var output = "";
15 var chr1, chr2, chr3; 15 var chr1, chr2, chr3;
16 var enc1, enc2, enc3, enc4; 16 var enc1, enc2, enc3, enc4;
17 var i = 0; 17 var i = 0;
18 18
19 do { 19 do {
20 chr1 = input.charCodeAt(i++); 20 chr1 = input.charCodeAt(i++);
21 chr2 = input.charCodeAt(i++); 21 chr2 = input.charCodeAt(i++);
22 chr3 = input.charCodeAt(i++); 22 chr3 = input.charCodeAt(i++);
23 23
24 enc1 = chr1 >> 2; 24 enc1 = chr1 >> 2;
25 enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); 25 enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
26 enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); 26 enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
27 enc4 = chr3 & 63; 27 enc4 = chr3 & 63;
28 28
29 if (isNaN(chr2)) { 29 if (isNaN(chr2)) {
30 enc3 = enc4 = 64; 30 enc3 = enc4 = 64;
31 } else if (isNaN(chr3)) { 31 } else if (isNaN(chr3)) {
32 enc4 = 64; 32 enc4 = 64;
33 } 33 }
34 34
35 output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) + 35 output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) +
36 keyStr.charAt(enc3) + keyStr.charAt(enc4); 36 keyStr.charAt(enc3) + keyStr.charAt(enc4);
37 } while (i < input.length); 37 } while (i < input.length);
38 38
39 return output; 39 return output;
40 }, 40 },
41 41
42 /** 42 /**
43 * Decodes a base64 string. 43 * Decodes a base64 string.
44 * @param {String} input The string to decode. 44 * @param {String} input The string to decode.
45 */ 45 */
46 decode: function (input) { 46 decode: function (input) {
47 var output = ""; 47 var output = "";
48 var chr1, chr2, chr3; 48 var chr1, chr2, chr3;
49 var enc1, enc2, enc3, enc4; 49 var enc1, enc2, enc3, enc4;
50 var i = 0; 50 var i = 0;
51 51
52 // remove all characters that are not A-Z, a-z, 0-9, +, /, or = 52 // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
53 input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); 53 input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
54 54
55 do { 55 do {
56 enc1 = keyStr.indexOf(input.charAt(i++)); 56 enc1 = keyStr.indexOf(input.charAt(i++));
57 enc2 = keyStr.indexOf(input.charAt(i++)); 57 enc2 = keyStr.indexOf(input.charAt(i++));
58 enc3 = keyStr.indexOf(input.charAt(i++)); 58 enc3 = keyStr.indexOf(input.charAt(i++));
59 enc4 = keyStr.indexOf(input.charAt(i++)); 59 enc4 = keyStr.indexOf(input.charAt(i++));
60 60
61 chr1 = (enc1 << 2) | (enc2 >> 4); 61 chr1 = (enc1 << 2) | (enc2 >> 4);
62 chr2 = ((enc2 & 15) << 4) | (enc3 >> 2); 62 chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
63 chr3 = ((enc3 & 3) << 6) | enc4; 63 chr3 = ((enc3 & 3) << 6) | enc4;
64 64
65 output = output + String.fromCharCode(chr1); 65 output = output + String.fromCharCode(chr1);
66 66
67 if (enc3 != 64) { 67 if (enc3 != 64) {
68 output = output + String.fromCharCode(chr2); 68 output = output + String.fromCharCode(chr2);
69 } 69 }
70 if (enc4 != 64) { 70 if (enc4 != 64) {
71 output = output + String.fromCharCode(chr3); 71 output = output + String.fromCharCode(chr3);
72 } 72 }
73 } while (i < input.length); 73 } while (i < input.length);
74 74
75 return output; 75 return output;
76 } 76 }
77 }; 77 };
78 78
79 return obj; 79 return obj;
195 }; 195 };
196 196
197 var md5_ii = function (a, b, c, d, x, s, t) { 197 var md5_ii = function (a, b, c, d, x, s, t) {
198 return md5_cmn(c ^ (b | (~d)), a, b, x, s, t); 198 return md5_cmn(c ^ (b | (~d)), a, b, x, s, t);
199 }; 199 };
200 200
201 /* 201 /*
202 * Calculate the MD5 of an array of little-endian words, and a bit length 202 * Calculate the MD5 of an array of little-endian words, and a bit length
203 */ 203 */
204 var core_md5 = function (x, len) { 204 var core_md5 = function (x, len) {
205 /* append padding */ 205 /* append padding */
216 { 216 {
217 olda = a; 217 olda = a;
218 oldb = b; 218 oldb = b;
219 oldc = c; 219 oldc = c;
220 oldd = d; 220 oldd = d;
221 221
222 a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936); 222 a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936);
223 d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586); 223 d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586);
224 c = md5_ff(c, d, a, b, x[i+ 2], 17, 606105819); 224 c = md5_ff(c, d, a, b, x[i+ 2], 17, 606105819);
225 b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330); 225 b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330);
226 a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897); 226 a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897);
233 b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162); 233 b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162);
234 a = md5_ff(a, b, c, d, x[i+12], 7 , 1804603682); 234 a = md5_ff(a, b, c, d, x[i+12], 7 , 1804603682);
235 d = md5_ff(d, a, b, c, x[i+13], 12, -40341101); 235 d = md5_ff(d, a, b, c, x[i+13], 12, -40341101);
236 c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290); 236 c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290);
237 b = md5_ff(b, c, d, a, x[i+15], 22, 1236535329); 237 b = md5_ff(b, c, d, a, x[i+15], 22, 1236535329);
238 238
239 a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510); 239 a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510);
240 d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632); 240 d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632);
241 c = md5_gg(c, d, a, b, x[i+11], 14, 643717713); 241 c = md5_gg(c, d, a, b, x[i+11], 14, 643717713);
242 b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302); 242 b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302);
243 a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691); 243 a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691);
250 b = md5_gg(b, c, d, a, x[i+ 8], 20, 1163531501); 250 b = md5_gg(b, c, d, a, x[i+ 8], 20, 1163531501);
251 a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467); 251 a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467);
252 d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784); 252 d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784);
253 c = md5_gg(c, d, a, b, x[i+ 7], 14, 1735328473); 253 c = md5_gg(c, d, a, b, x[i+ 7], 14, 1735328473);
254 b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734); 254 b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734);
255 255
256 a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558); 256 a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558);
257 d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463); 257 d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463);
258 c = md5_hh(c, d, a, b, x[i+11], 16, 1839030562); 258 c = md5_hh(c, d, a, b, x[i+11], 16, 1839030562);
259 b = md5_hh(b, c, d, a, x[i+14], 23, -35309556); 259 b = md5_hh(b, c, d, a, x[i+14], 23, -35309556);
260 a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060); 260 a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060);
267 b = md5_hh(b, c, d, a, x[i+ 6], 23, 76029189); 267 b = md5_hh(b, c, d, a, x[i+ 6], 23, 76029189);
268 a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487); 268 a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487);
269 d = md5_hh(d, a, b, c, x[i+12], 11, -421815835); 269 d = md5_hh(d, a, b, c, x[i+12], 11, -421815835);
270 c = md5_hh(c, d, a, b, x[i+15], 16, 530742520); 270 c = md5_hh(c, d, a, b, x[i+15], 16, 530742520);
271 b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651); 271 b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651);
272 272
273 a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844); 273 a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844);
274 d = md5_ii(d, a, b, c, x[i+ 7], 10, 1126891415); 274 d = md5_ii(d, a, b, c, x[i+ 7], 10, 1126891415);
275 c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905); 275 c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905);
276 b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055); 276 b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055);
277 a = md5_ii(a, b, c, d, x[i+12], 6 , 1700485571); 277 a = md5_ii(a, b, c, d, x[i+12], 6 , 1700485571);
284 b = md5_ii(b, c, d, a, x[i+13], 21, 1309151649); 284 b = md5_ii(b, c, d, a, x[i+13], 21, 1309151649);
285 a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070); 285 a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070);
286 d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379); 286 d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379);
287 c = md5_ii(c, d, a, b, x[i+ 2], 15, 718787259); 287 c = md5_ii(c, d, a, b, x[i+ 2], 15, 718787259);
288 b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551); 288 b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551);
289 289
290 a = safe_add(a, olda); 290 a = safe_add(a, olda);
291 b = safe_add(b, oldb); 291 b = safe_add(b, oldb);
292 c = safe_add(c, oldc); 292 c = safe_add(c, oldc);
293 d = safe_add(d, oldd); 293 d = safe_add(d, oldd);
294 } 294 }
300 * Calculate the HMAC-MD5, of a key and some data 300 * Calculate the HMAC-MD5, of a key and some data
301 */ 301 */
302 var core_hmac_md5 = function (key, data) { 302 var core_hmac_md5 = function (key, data) {
303 var bkey = str2binl(key); 303 var bkey = str2binl(key);
304 if(bkey.length > 16) { bkey = core_md5(bkey, key.length * chrsz); } 304 if(bkey.length > 16) { bkey = core_md5(bkey, key.length * chrsz); }
305 305
306 var ipad = new Array(16), opad = new Array(16); 306 var ipad = new Array(16), opad = new Array(16);
307 for(var i = 0; i < 16; i++) 307 for(var i = 0; i < 16; i++)
308 { 308 {
309 ipad[i] = bkey[i] ^ 0x36363636; 309 ipad[i] = bkey[i] ^ 0x36363636;
310 opad[i] = bkey[i] ^ 0x5C5C5C5C; 310 opad[i] = bkey[i] ^ 0x5C5C5C5C;
311 } 311 }
312 312
313 var hash = core_md5(ipad.concat(str2binl(data)), 512 + data.length * chrsz); 313 var hash = core_md5(ipad.concat(str2binl(data)), 512 + data.length * chrsz);
314 return core_md5(opad.concat(hash), 512 + 128); 314 return core_md5(opad.concat(hash), 512 + 128);
315 }; 315 };
316 316
317 var obj = { 317 var obj = {
577 SESSION: "urn:ietf:params:xml:ns:xmpp-session", 577 SESSION: "urn:ietf:params:xml:ns:xmpp-session",
578 VERSION: "jabber:iq:version", 578 VERSION: "jabber:iq:version",
579 STANZAS: "urn:ietf:params:xml:ns:xmpp-stanzas" 579 STANZAS: "urn:ietf:params:xml:ns:xmpp-stanzas"
580 }, 580 },
581 581
582 /** Function: addNamespace 582 /** Function: addNamespace
583 * This function is used to extend the current namespaces in 583 * This function is used to extend the current namespaces in
584 * Strophe.NS. It takes a key and a value with the key being the 584 * Strophe.NS. It takes a key and a value with the key being the
585 * name of the new namespace, with its actual value. 585 * name of the new namespace, with its actual value.
586 * For example: 586 * For example:
587 * Strophe.addNamespace('PUBSUB', "http://jabber.org/protocol/pubsub"); 587 * Strophe.addNamespace('PUBSUB', "http://jabber.org/protocol/pubsub");
588 * 588 *
589 * Parameters: 589 * Parameters:
590 * (String) name - The name under which the namespace will be 590 * (String) name - The name under which the namespace will be
591 * referenced under Strophe.NS 591 * referenced under Strophe.NS
592 * (String) value - The actual namespace. 592 * (String) value - The actual namespace.
593 */ 593 */
594 addNamespace: function (name, value) 594 addNamespace: function (name, value)
595 { 595 {
596 Strophe.NS[name] = value; 596 Strophe.NS[name] = value;
597 }, 597 },
791 } else if (typeof(arguments[a]) == "object") { 791 } else if (typeof(arguments[a]) == "object") {
792 for (k in arguments[a]) { 792 for (k in arguments[a]) {
793 if (arguments[a].hasOwnProperty(k)) { 793 if (arguments[a].hasOwnProperty(k)) {
794 node.setAttribute(k, arguments[a][k]); 794 node.setAttribute(k, arguments[a][k]);
795 } 795 }
796 } 796 }
797 } 797 }
798 } 798 }
799 799
800 return node; 800 return node;
801 }, 801 },
807 * (String) text - text to escape. 807 * (String) text - text to escape.
808 * 808 *
809 * Returns: 809 * Returns:
810 * Escaped text. 810 * Escaped text.
811 */ 811 */
812 xmlescape: function(text) 812 xmlescape: function(text)
813 { 813 {
814 text = text.replace(/\&/g, "&amp;"); 814 text = text.replace(/\&/g, "&amp;");
815 text = text.replace(/</g, "&lt;"); 815 text = text.replace(/</g, "&lt;");
816 text = text.replace(/>/g, "&gt;"); 816 text = text.replace(/>/g, "&gt;");
817 return text; 817 return text;
818 }, 818 },
819 819
820 /** Function: xmlTextNode 820 /** Function: xmlTextNode
821 * Creates an XML DOM text node. 821 * Creates an XML DOM text node.
822 * 822 *
1414 this.ns = ns; 1414 this.ns = ns;
1415 this.name = name; 1415 this.name = name;
1416 this.type = type; 1416 this.type = type;
1417 this.id = id; 1417 this.id = id;
1418 this.options = options || {matchbare: false}; 1418 this.options = options || {matchbare: false};
1419 1419
1420 // default matchBare to false if undefined 1420 // default matchBare to false if undefined
1421 if (!this.options.matchBare) { 1421 if (!this.options.matchBare) {
1422 this.options.matchBare = false; 1422 this.options.matchBare = false;
1423 } 1423 }
1424 1424
1444 */ 1444 */
1445 isMatch: function (elem) 1445 isMatch: function (elem)
1446 { 1446 {
1447 var nsMatch; 1447 var nsMatch;
1448 var from = null; 1448 var from = null;
1449 1449
1450 if (this.options.matchBare) { 1450 if (this.options.matchBare) {
1451 from = Strophe.getBareJidFromJid(elem.getAttribute('from')); 1451 from = Strophe.getBareJidFromJid(elem.getAttribute('from'));
1452 } else { 1452 } else {
1453 from = elem.getAttribute('from'); 1453 from = elem.getAttribute('from');
1454 } 1454 }
2096 this._idleTimeout = setTimeout(this._onIdle.bind(this), 100); 2096 this._idleTimeout = setTimeout(this._onIdle.bind(this), 100);
2097 }, 2097 },
2098 2098
2099 /** Function: flush 2099 /** Function: flush
2100 * Immediately send any pending outgoing data. 2100 * Immediately send any pending outgoing data.
2101 * 2101 *
2102 * Normally send() queues outgoing data until the next idle period 2102 * Normally send() queues outgoing data until the next idle period
2103 * (100ms), which optimizes network use in the common cases when 2103 * (100ms), which optimizes network use in the common cases when
2104 * several send()s are called in succession. flush() can be used to 2104 * several send()s are called in succession. flush() can be used to
2105 * immediately send all pending data. 2105 * immediately send all pending data.
2106 */ 2106 */
2107 flush: function () 2107 flush: function ()
2108 { 2108 {
2109 // cancel the pending idle period and run the idle function 2109 // cancel the pending idle period and run the idle function
2116 * Helper function to send IQ stanzas. 2116 * Helper function to send IQ stanzas.
2117 * 2117 *
2118 * Parameters: 2118 * Parameters:
2119 * (XMLElement) elem - The stanza to send. 2119 * (XMLElement) elem - The stanza to send.
2120 * (Function) callback - The callback function for a successful request. 2120 * (Function) callback - The callback function for a successful request.
2121 * (Function) errback - The callback function for a failed or timed 2121 * (Function) errback - The callback function for a failed or timed
2122 * out request. On timeout, the stanza will be null. 2122 * out request. On timeout, the stanza will be null.
2123 * (Integer) timeout - The time specified in milliseconds for a 2123 * (Integer) timeout - The time specified in milliseconds for a
2124 * timeout to occur. 2124 * timeout to occur.
2125 * 2125 *
2126 * Returns: 2126 * Returns:
2127 * The id used to send the IQ. 2127 * The id used to send the IQ.
2128 */ 2128 */
2194 throw { 2194 throw {
2195 name: "StropheError", 2195 name: "StropheError",
2196 message: "Cannot queue non-DOMElement." 2196 message: "Cannot queue non-DOMElement."
2197 }; 2197 };
2198 } 2198 }
2199 2199
2200 this._data.push(element); 2200 this._data.push(element);
2201 }, 2201 },
2202 2202
2203 /** PrivateFunction: _sendRestart 2203 /** PrivateFunction: _sendRestart
2204 * Send an xmpp:restart stanza. 2204 * Send an xmpp:restart stanza.
2277 * The options argument contains handler matching flags that affect how 2277 * The options argument contains handler matching flags that affect how
2278 * matches are determined. Currently the only flag is matchBare (a 2278 * matches are determined. Currently the only flag is matchBare (a
2279 * boolean). When matchBare is true, the from parameter and the from 2279 * boolean). When matchBare is true, the from parameter and the from
2280 * attribute on the stanza will be matched as bare JIDs instead of 2280 * attribute on the stanza will be matched as bare JIDs instead of
2281 * full JIDs. To use this, pass {matchBare: true} as the value of 2281 * full JIDs. To use this, pass {matchBare: true} as the value of
2282 * options. The default value for matchBare is false. 2282 * options. The default value for matchBare is false.
2283 * 2283 *
2284 * The return value should be saved if you wish to remove the handler 2284 * The return value should be saved if you wish to remove the handler
2285 * with deleteHandler(). 2285 * with deleteHandler().
2286 * 2286 *
2287 * Parameters: 2287 * Parameters:
2890 if (wind) { this.window = parseInt(wind, 10); } 2890 if (wind) { this.window = parseInt(wind, 10); }
2891 var hold = bodyWrap.getAttribute('hold'); 2891 var hold = bodyWrap.getAttribute('hold');
2892 if (hold) { this.hold = parseInt(hold, 10); } 2892 if (hold) { this.hold = parseInt(hold, 10); }
2893 var wait = bodyWrap.getAttribute('wait'); 2893 var wait = bodyWrap.getAttribute('wait');
2894 if (wait) { this.wait = parseInt(wait, 10); } 2894 if (wait) { this.wait = parseInt(wait, 10); }
2895 2895
2896 2896
2897 var do_sasl_plain = false; 2897 var do_sasl_plain = false;
2898 var do_sasl_digest_md5 = false; 2898 var do_sasl_digest_md5 = false;
2899 var do_sasl_anonymous = false; 2899 var do_sasl_anonymous = false;
2900 2900
3090 * Returns: 3090 * Returns:
3091 * quoted string 3091 * quoted string
3092 */ 3092 */
3093 _quote: function (str) 3093 _quote: function (str)
3094 { 3094 {
3095 return '"' + str.replace(/\\/g, "\\\\").replace(/"/g, '\\"') + '"'; 3095 return '"' + str.replace(/\\/g, "\\\\").replace(/"/g, '\\"') + '"';
3096 //" end string workaround for emacs 3096 //" end string workaround for emacs
3097 }, 3097 },
3098 3098
3099 3099
3100 /** PrivateFunction: _sasl_challenge2_cb 3100 /** PrivateFunction: _sasl_challenge2_cb