/g,">")).replace(/\"/g,""")).replace(/\n/g,"
")},String.prototype.revertHtmlEnc=function(){if(!this)return this;var e=this.replace(/&/gi,"&");return e=(e=(e=(e=e.replace(/</gi,"<")).replace(/>/gi,">")).replace(/"/gi,'"')).replace(/
/gi,"\n")},Date.jab2date=function(e){var t=new Date(Date.UTC(e.substr(0,4),e.substr(5,2)-1,e.substr(8,2),e.substr(11,2),e.substr(14,2),e.substr(17,2)));if("Z"!=e.substr(e.length-6,1)){var n=new Date;n.setTime(0),n.setUTCHours(e.substr(e.length-5,2)),n.setUTCMinutes(e.substr(e.length-2,2)),"+"==e.substr(e.length-6,1)?t.setTime(t.getTime()-n.getTime()):"-"==e.substr(e.length-6,1)&&t.setTime(t.getTime()+n.getTime())}return t},Date.hrTime=function(e){return Date.jab2date(e).toLocaleString()},Date.prototype.jabberDate=function(){var e=function(e){return e<10?"0"+e:e},t=this.getUTCFullYear()+"-";return t+=e(this.getUTCMonth()+1)+"-",t+=e(this.getUTCDate())+"T",t+=e(this.getUTCHours())+":",t+=e(this.getUTCMinutes())+":",t+=e(this.getUTCSeconds())+"Z"},Number.max=function(e,t){return e>t?e:t},Number.min=function(e,t){return e""?this.xdr.contentType:""},XMLHttpRequest.prototype.xdrGetAllResponseHeaders=function(){return this.xdr.contentType>""?"Content-Type: "+this.xdr.contentType:""},XMLHttpRequest.prototype.xdrSetRequestHeader=function(e,t){},XMLHttpRequest.prototype.xdrLoaded=function(){if(null!==this.onreadystatechange){if(this.readyState=4,this.status=200,this.statusText="OK",this.responseText=this.xdr.responseText,e.ActiveXObject){var t=new ActiveXObject("Microsoft.XMLDOM");t.async="false",t.loadXML(this.responseText),this.responseXML=t}this.onreadystatechange()}},XMLHttpRequest.prototype.xdrError=function(){null!==this.onreadystatechange&&(this.readyState=4,this.status=0,this.statusText="",this.responseText="",this.onreadystatechange())},XMLHttpRequest.prototype.xdrProgress=function(){null!==this.onreadystatechange&&3!==this.status&&(this.readyState=3,this.status=3,this.statusText="",this.onreadystatechange())},XMLHttpRequest.prototype.finalXDRRequest=function(){var e=this.xdr;delete e.onload,delete e.onerror,delete e.onprogress},XMLHttpRequest.prototype.sendXDR=function(e){var t=this.xdr;t.onload=this.xdrLoadedBinded,t.onerror=this.xdr.ontimeout=this.xdrErrorBinded,t.onprogress=this.xdrProgressBinded,this.responseText=null,this.xdr.send(e)},XMLHttpRequest.prototype.abortXDR=function(){this.finalXDRRequest(),this.xdr.abort()},XMLHttpRequest.prototype.setXDRActive=function(){this.send=this.sendXDR,this.abort=this.abortXDR,this.getResponseHeader=this.xdrGetResponseHeader,this.getAllResponseHeaders=this.xdrGetAllResponseHeaders,this.setRequestHeader=this.xdrSetRequestHeader},XMLHttpRequest.prototype.xhrGetResponseHeader=function(e){return this.xhr.getResponseHeader(e)},XMLHttpRequest.prototype.xhrGetAllResponseHeaders=function(){return this.xhr.getAllResponseHeaders()},XMLHttpRequest.prototype.xhrSetRequestHeader=function(e,t){return this.xhr.setRequestHeader(e,t)},XMLHttpRequest.prototype.xhrReadyStateChanged=function(){if(null!==this.onreadystatechange&&this.readyState!==this.xhr.readyState){var e=this.xhr;this.readyState=e.readyState,4===this.readyState&&(this.status=e.status,this.statusText=e.statusText,this.responseText=e.responseText,this.responseXML=e.responseXML,this.responseBody=e.responseBody),this.onreadystatechange()}},XMLHttpRequest.prototype.finalXHRRequest=function(){delete this.xhr.onreadystatechange},XMLHttpRequest.prototype.abortXHR=function(){this.finalXHRRequest(),this.xhr.abort()},XMLHttpRequest.prototype.sendXHR=function(e){this.xhr.onreadystatechange=this.xhrReadyStateChangedBinded,this.xhr.send(e)},XMLHttpRequest.prototype.setXHRActive=function(){this.send=this.sendXHR,this.abort=this.abortXHR,this.getResponseHeader=this.xhrGetResponseHeader,this.getAllResponseHeaders=this.xhrGetAllResponseHeaders,this.setRequestHeader=this.xhrSetRequestHeader},e.ieXDRToXHR=void 0},window.ieXDRToXHR(window));var hexcase=0,b64pad="=";function hex_sha1(e){return rstr2hex(rstr_sha1(str2rstr_utf8(e)))}function rstr_sha1(e){return binb2rstr(binb_sha1(rstr2binb(e),8*e.length))}function rstr_hmac_sha1(e,t){var n=rstr2binb(e);n.length>16&&(n=binb_sha1(n,8*e.length));for(var i=Array(16),r=Array(16),s=0;s<16;s++)i[s]=909522486^n[s],r[s]=1549556828^n[s];var o=binb_sha1(i.concat(rstr2binb(t)),512+8*t.length);return binb2rstr(binb_sha1(r.concat(o),672))}function rstr2binb(e){for(var t=Array(e.length>>2),n=0;n>5]|=(255&e.charCodeAt(n/8))<<24-n%32;return t}function binb2rstr(e){for(var t="",n=0;n<32*e.length;n+=8)t+=String.fromCharCode(e[n>>5]>>>24-n%32&255);return t}function binb_sha1(e,t){e[t>>5]|=128<<24-t%32,e[15+(t+64>>9<<4)]=t;for(var n=Array(80),i=1732584193,r=-271733879,s=-1732584194,o=271733878,a=-1009589776,h=0;h>>4&15)+n.charAt(15&t);return i}function rstr2b64(e){for(var t="",n=e.length,i=0;i8*e.length?t+=b64pad:t+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charAt(r>>>6*(3-s)&63);return t}function str2rstr_utf8(e){for(var t,n,i="",r=-1;++r>>6&31,128|63&t):t<=65535?i+=String.fromCharCode(224|t>>>12&15,128|t>>>6&63,128|63&t):t<=2097151&&(i+=String.fromCharCode(240|t>>>18&7,128|t>>>12&63,128|t>>>6&63,128|63&t));return i}function rstr2binl(e){for(var t=Array(e.length>>2),n=0;n>5]|=(255&e.charCodeAt(n/8))<>5]>>>n%32&255);return t}function binl_md5(e,t){e[t>>5]|=128<>>9<<4)]=t;for(var n=1732584193,i=-271733879,r=-1732584194,s=271733878,o=0;o>16)+(t>>16)+(n>>16)<<16|65535&n}function bit_rol(e,t){return e<>>32-t}function utf8t2d(e){e=e.replace(/\r\n/g,"\n");var t=new Array;if(String.fromCharCode(237).charCodeAt(0)<0)for(var n=0;n0?t[t.length]=i:(t[t.length]=256+i>>6|192,t[t.length]=256+i&63|128)}else for(n=0;n127&&i<2048?(t[t.length]=i>>6|192,t[t.length]=63&i|128):(t[t.length]=i>>12|224,t[t.length]=i>>6&63|128,t[t.length]=63&i|128)}return t}function utf8d2t(e){for(var t=new Array,n=0;n191&&e[n]<224?(t[t.length]=String.fromCharCode((31&e[n])<<6|63&e[n+1]),n+=2):(t[t.length]=String.fromCharCode((15&e[n])<<12|(63&e[n+1])<<6|63&e[n+2]),n+=3);return t.join("")}function b64arrays(){var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";b64=new Array,f64=new Array;for(var t=0;t<64;t++)b64[t]=e.charAt(t),f64[e.charAt(t)]=t}function b64d2t(e){var t=new Array,n=0,i=e.length;for(i%3==1&&(e[e.length]=0,e[e.length]=0),i%3==2&&(e[e.length]=0);n>2],t[t.length]=b64[(3&e[n])<<4|e[n+1]>>4],t[t.length]=b64[(15&e[n+1])<<2|e[n+2]>>6],t[t.length]=b64[63&e[n+2]],n+=3;return i%3==1&&(t[t.length-1]=t[t.length-2]="="),i%3==2&&(t[t.length-1]="="),t.join("")}function b64t2d(e){var t=new Array,n=0;for(e=(e=e.replace(/\n|\r/g,"")).replace(/=/g,"");n>4,t[t.length]=(15&f64[e.charAt(n+1)])<<4|f64[e.charAt(n+2)]>>2,t[t.length]=(3&f64[e.charAt(n+2)])<<6|f64[e.charAt(n+3)],n+=4;return e.length%4==2&&(t=t.slice(0,t.length-2)),e.length%4==3&&(t=t.slice(0,t.length-1)),t}if("undefined"!=typeof atob&&"undefined"!=typeof btoa||b64arrays(),"undefined"==typeof atob)var b64decode=function(e){return utf8d2t(b64t2d(e))},b64decode_bin=function(e){for(var t=b64t2d(e),n="",i=0;i","@"];function JSJaCJID(e){this._node="",this._domain="",this._resource="","string"==typeof e?(-1!=e.indexOf("@")&&(this.setNode(e.substring(0,e.indexOf("@"))),e=e.substring(e.indexOf("@")+1)),-1!=e.indexOf("/")&&(this.setResource(e.substring(e.indexOf("/")+1)),e=e.substring(0,e.indexOf("/"))),this.setDomain(e)):(this.setNode(e.node),this.setDomain(e.domain),this.setResource(e.resource))}function JSJaCKeys(e,t){var n=Math.random();if(this._k=[],this._k[0]=n.toString(),t?this.oDbg=t:(this.oDbg={},this.oDbg.log=function(){}),e)for(var i=1;i0)for(i=0,r=e.attributes.length;i0)for(i=0,r=e.childNodes.length;i2&&(t.childName=arguments[1]),arguments.length>3&&(t.childNS=arguments[2]),arguments.length>4&&(t.type=arguments[3]),this._events[e]?this._events[e]=this._events[e].concat(t):this._events[e]=[t],this._events[e]=this._events[e].sort((function(e,t){var n=0,i=0;return"*"==e.type&&n++,"*"==e.childNS&&n++,"*"==e.childName&&n++,"*"==t.type&&i++,"*"==t.childNS&&i++,"*"==t.childName&&i++,n>i?1:n0&&this._process(),!0},JSJaCConnection.prototype._doAuth=function(){return this.has_sasl&&"nonsasl"==this.authtype&&this.oDbg.log("Warning: SASL present but not used",1),!(!this._doSASLAuth()&&!this._doLegacyAuth())||(this.oDbg.log("Auth failed for authtype "+this.authtype,1),this.disconnect(),!1)},JSJaCConnection.prototype._doInBandReg=function(){if("saslanon"!=this.authtype&&"anonymous"!=this.authtype){var e=new JSJaCIQ;e.setType("set"),e.setID("reg1"),e.appendNode("query",{xmlns:NS_REGISTER},[["username",this.username],["password",this.pass]]),this.send(e,this._doInBandRegDone)}},JSJaCConnection.prototype._doInBandRegDone=function(e){if(e&&"error"==e.getType())return this.oDbg.log("registration failed for "+this.username,0),void this._handleEvent("onerror",e.getChild("error"));this.oDbg.log(this.username+" registered succesfully",0),this._doAuth()},JSJaCConnection.prototype._doLegacyAuth=function(){if("nonsasl"!=this.authtype&&"anonymous"!=this.authtype)return!1;var e=new JSJaCIQ;return e.setIQ(null,"get","auth1"),e.appendNode("query",{xmlns:NS_AUTH},[["username",this.username]]),this.send(e,this._doLegacyAuth2),!0},JSJaCConnection.prototype._doLegacyAuth2=function(e){if(!e||"result"!=e.getType())return e&&"error"==e.getType()&&this._handleEvent("onerror",e.getChild("error")),void this.disconnect();var t=null!==e.getChild("digest"),n=new JSJaCIQ;n.setIQ(null,"set","auth2");var i=n.appendNode("query",{xmlns:NS_AUTH},[["username",this.username],["resource",this.resource]]);if(t)i.appendChild(n.buildNode("digest",{xmlns:NS_AUTH},hex_sha1(this.streamid+this.pass)));else{if(!this._allow_plain)return this.oDbg.log("no valid login mechanism found",1),void this.disconnect();i.appendChild(n.buildNode("password",{xmlns:NS_AUTH},this.pass))}this.send(n,this._doLegacyAuthDone)},JSJaCConnection.prototype._doLegacyAuthDone=function(e){"result"!=e.getType()?("error"==e.getType()&&this._handleEvent("onerror",e.getChild("error")),this.disconnect()):this._handleEvent("onconnect")},JSJaCConnection.prototype._doSASLAuth=function(){if("nonsasl"==this.authtype||"anonymous"==this.authtype)return!1;if("saslanon"==this.authtype){if(this.mechs.ANONYMOUS)return this.oDbg.log("SASL using mechanism 'ANONYMOUS'",2),this._sendRaw("",this._doSASLAuthDone);this.oDbg.log("SASL ANONYMOUS requested but not supported",1)}else{if(this._allow_scram&&this.mechs["SCRAM-SHA-1"]){this.oDbg.log("SASL using mechanism 'SCRAM-SHA-1'",2),this._clientFirstMessageBare="n="+this.username.replace(/=/g,"=3D").replace(/,/g,"=2C")+",r="+JSJaCUtils.cnonce(16);var e=(this.authzid?"n,a="+this.authzid.replace(/=/g,"=3D").replace(/,/g,"=2C")+",":"n,,")+this._clientFirstMessageBare;return this._sendRaw(""+b64encode(e)+"",this._doSASLAuthScramSha1S1)}if(this.mechs["DIGEST-MD5"])return this.oDbg.log("SASL using mechanism 'DIGEST-MD5'",2),this._sendRaw("",this._doSASLAuthDigestMd5S1);if(this._allow_plain&&this.mechs.PLAIN){this.oDbg.log("SASL using mechanism 'PLAIN'",2);var t=this.authzid+String.fromCharCode(0)+this.username+String.fromCharCode(0)+this.pass;return this.oDbg.log("authenticating with '"+t+"'",2),t=b64encode(t),this._sendRaw(""+t+"",this._doSASLAuthDone)}this.oDbg.log("No SASL mechanism applied",1),this.authtype="nonsasl"}return!1},JSJaCConnection.prototype._doSASLAuthScramSha1S1=function(e){if("challenge"!=e.nodeName)this.oDbg.log("challenge missing",1),this._handleEvent("onerror",JSJaCError("401","auth","not-authorized")),this.disconnect();else{var t=b64decode(e.firstChild.nodeValue);this.oDbg.log("got challenge: "+t,2);var n={},i=t.split(",");for(var r in i)if(i.hasOwnProperty(r)){var s=i[r].substring(2);n[i[r].substring(0,1)]=s}for(var o,a,h=str2rstr_utf8(this.pass),u=b64decode_bin(n.s)+"\0\0\0",c=parseInt(n.i,10),l=0;l"+b64encode(m)+"",this._doSASLAuthScramSha1S2)}},JSJaCConnection.prototype._doSASLAuthScramSha1S2=function(e){if("success"!=e.nodeName)this.oDbg.log("auth failed",1),this._handleEvent("onerror",JSJaCError("401","auth","not-authorized")),this.disconnect();else{var t=b64decode(e.firstChild.nodeValue);this.oDbg.log("got success: "+t,2);var n={},i=t.split(",");for(var r in i)if(i.hasOwnProperty(r)){var s=i[r].substring(2);n[i[r].substring(0,1)]=s}var o=rstr_hmac_sha1(this._saltedPassword,"Server Key");rstr_hmac_sha1(o,str2rstr_utf8(this._authMessage))!==b64decode_bin(n.v)?(this.oDbg.log("server auth failed",1),this._handleEvent("onerror",JSJaCError("401","auth","not-authorized")),this.disconnect()):this._reInitStream(JSJaC.bind(this._doStreamBind,this))}},JSJaCConnection.prototype._doSASLAuthDigestMd5S1=function(e){if("challenge"!=e.nodeName)this.oDbg.log("challenge missing",1),this._handleEvent("onerror",JSJaCError("401","auth","not-authorized")),this.disconnect();else{var t,n=b64decode(e.firstChild.nodeValue);if(this.oDbg.log("got challenge: "+n,2),-1===(t=n.indexOf('nonce="')))return this.oDbg.log("no valid nonce found, aborting",1),void this.disconnect();this._nonce=n.substring(t+7),this._nonce=this._nonce.substring(0,this._nonce.indexOf('"')),this.oDbg.log("nonce: "+this._nonce,2),-1!==(t=n.indexOf('realm="'))&&(this._realm=n.substring(t+7),this._realm=this._realm.substring(0,this._realm.indexOf('"'))),this._realm=this._realm||this.domain,this.oDbg.log("realm: "+this._realm,2),this._digest_uri="xmpp/"+this.domain,this._cnonce=JSJaCUtils.cnonce(14),this._nc="00000001";var i=rstr_md5(str2rstr_utf8(this.username+":"+this._realm+":"+this.pass))+":"+this._nonce+":"+this._cnonce;this.authzid&&(i=i+":"+this.authzid);var r=rstr2hex(rstr_md5(i)),s=hex_md5("AUTHENTICATE:"+this._digest_uri),o=hex_md5(r+":"+this._nonce+":"+this._nc+":"+this._cnonce+":auth:"+s),a='username="'+this.username+'",realm="'+this._realm+'",nonce="'+this._nonce+'",cnonce="'+this._cnonce+'",nc='+this._nc+',qop=auth,digest-uri="'+this._digest_uri+'",response='+o+",charset=utf-8";this.authzid&&(a='authzid="'+this.authzid+'",'+a),this.oDbg.log("response: "+a,2),this._sendRaw(""+b64encode(a)+"",this._doSASLAuthDigestMd5S2)}},JSJaCConnection.prototype._doSASLAuthDigestMd5S2=function(e){if("failure"==e.nodeName)return e.xml?this.oDbg.log("auth error: "+e.xml,1):this.oDbg.log("auth error",1),this._handleEvent("onerror",JSJaCError("401","auth","not-authorized")),void this.disconnect();var t=b64decode(e.firstChild.nodeValue);this.oDbg.log("response: "+t,2);var n=t.substring(t.indexOf("rspauth=")+8);this.oDbg.log("rspauth: "+n,2);var i=rstr_md5(str2rstr_utf8(this.username+":"+this._realm+":"+this.pass))+":"+this._nonce+":"+this._cnonce;this.authzid&&(i=i+":"+this.authzid);var r=rstr2hex(rstr_md5(i)),s=hex_md5(":"+this._digest_uri),o=hex_md5(r+":"+this._nonce+":"+this._nc+":"+this._cnonce+":auth:"+s);if(this.oDbg.log("rsptest: "+o,2),o!=n)return this.oDbg.log("SASL Digest-MD5: server repsonse with wrong rspauth",1),void this.disconnect();"success"==e.nodeName?this._reInitStream(JSJaC.bind(this._doStreamBind,this)):this._sendRaw("",this._doSASLAuthDone)},JSJaCConnection.prototype._doSASLAuthDone=function(e){"success"!==e.nodeName?(this.oDbg.log("auth failed",1),this._handleEvent("onerror",JSJaCError("401","auth","not-authorized")),this.disconnect()):this._reInitStream(JSJaC.bind(this._doStreamBind,this))},JSJaCConnection.prototype._doStreamBind=function(){var e=new JSJaCIQ;e.setIQ(null,"set","bind_1"),e.appendNode("bind",{xmlns:NS_BIND},[["resource",this.resource]]),this.oDbg.log(e.xml()),this.send(e,this._doXMPPSess)},JSJaCConnection.prototype._doXMPPSess=function(e){if("result"!=e.getType()||"error"==e.getType())return this.disconnect(),void("error"==e.getType()&&this._handleEvent("onerror",e.getChild("error")));this.fulljid=e.getChildVal("jid"),this.jid=this.fulljid.substring(0,this.fulljid.lastIndexOf("/")),(e=new JSJaCIQ).setIQ(null,"set","sess_1"),e.appendNode("session",{xmlns:NS_SESSION},[]),this.oDbg.log(e.xml()),this.send(e,this._doXMPPSessDone)},JSJaCConnection.prototype._doXMPPSessDone=function(e){if("result"!=e.getType()||"error"==e.getType())return this.disconnect(),void("error"==e.getType()&&this._handleEvent("onerror",e.getChild("error")));this._handleEvent("onconnect")},JSJaCConnection.prototype._handleEvent=function(e,t){if(e=e.toLowerCase(),this.oDbg.log("incoming event '"+e+"'",3),this._events[e]){this.oDbg.log("handling event '"+e+"'",2);for(var n=0;n match for handler "+i.handler,3)}if(i.handler(t))break}else if(i.handler())break}}},JSJaCConnection.prototype._handlePID=function(e){if(!e.getID())return!1;var t=e.getFrom()||this.jid;e.getFrom()==this.domain&&(t=this.jid);var n=e.getID();if(this._regIDs[t]&&this._regIDs[t][n]){this.oDbg.log("handling id "+n,3);var i=this._regIDs[t][n];return!1!==i.cb.call(this,e,i.arg)&&(delete this._regIDs[t][n],!0)}return this.oDbg.log("not handling id '"+n+"' from jid "+t,1),!1},JSJaCConnection.prototype._handleResponse=function(e){var t=this._parseResponse(e);if(t)for(var n=0;nJSJAC_ERR_COUNT?this._abort():(this._setStatus("onerror_fallback"),setTimeout(JSJaC.bind(this._repeat,this),JSJAC_RETRYDELAY)))}),this)}catch(e){}var n=this._getRequestString();void 0!==this._rid&&(this._req[t].rid=this._rid),this.oDbg.log("sending: "+n,4),this._req[t].r.send(n)}else this.oDbg.log("all slots busy, standby ...",2);else this.oDbg.log("Slot "+t+" is not ready")},JSJaCConnection.prototype._registerPID=function(e,t,n){this.oDbg.log("registering id for packet "+e.xml(),3);var i=e.getID();if(!i)return this.oDbg.log("id missing",1),!1;if("function"!=typeof t)return this.oDbg.log("callback is not a function",1),!1;var r=e.getTo()||this.jid;return e.getTo()==this.domain&&(r=this.jid),this._regIDs[r]||(this._regIDs[r]={}),null!=this._regIDs[r][i]?(this.oDbg.log("id already registered: "+i,1),!1):(this._regIDs[r][i]={cb:t,arg:n,ts:JSJaCUtils.now()},this.oDbg.log("registered id "+i,3),this._cleanupRegisteredPIDs(),!0)},JSJaCConnection.prototype._cleanupRegisteredPIDs=function(){var e=Date.now();for(var t in this._regIDs)if(this._regIDs.hasOwnProperty(t))for(var n in this._regIDs[t])this._regIDs[t].hasOwnProperty(n)&&this._regIDs[t][n].ts+JSJAC_REGID_TIMEOUT1e3*this._inactivity?this._timerval=1e3*this._inactivity:this._timerval=e:this._timerval=100),this._timerval},JSJaCHttpBindingConnection.prototype.isPolling=function(){return 0===this._hold},JSJaCHttpBindingConnection.prototype._getFreeSlot=function(){for(var e=0;e"+e+i+"