//***************************************************************** // rewrite Remote Scripting utilities for client ver 1.0.e at 07/2003 // now work with other browser wich have XMH or HTTP object installed // for debug-version/information/problem/suggest/... and receive the correct RS.ASP file // ask at // meosoft // @tiscali.it // //***************************************************************** function RSVersion() { // 1.0.a resolve problem use Applet with IE browser // 1.0.b implement in rs.asp resolve param string for special char \'\"\n\r // 1.0.c bug fix for other browser // 1.0.d implement compatibility with previous Browser used applet Remote Scripting // 1.0.e secureoption implement and resolve char plus problem and debug function // in RS.ASP correct an evantual RSDipatch problem // 1.0.f destroy object after utilization // 1.0.g try to not cause error while MSRS is loaded // 1.0.h add a support withMsxml2.XMLHTTP // 1.0.i __xmlHTTP.readyState solve some bugs return "1.0.i"; } function useappletjava() { var __xmlHTTP=null; var rsapp=0; try {__xmlHTTP = new ActiveXObject("Msxml2.XMLHTTP");rsapp=4;}catch(e){} if (rsapp==0) { try {__xmlHTTP = new ActiveXObject("Microsoft.XMLHTTP");rsapp=1;}catch(e){} if (rsapp==0) { try {__xmlHTTP = new XMLHttpRequest();rsapp=2;} catch(e) {} if (rsapp==0) {try {__xmlHTTP = new HttpRequest();rsapp=3;} catch(e) {}} } } __xmlHTTP=null; return rsapp; } function RSEnableRemoteScripting(codebase) { // MSRS = new _MSRS_Object(); if (typeof(codebase) == 'undefined') { var secondSlash, path; codebase = ''; if ((secondSlash = (path = window.location.pathname).indexOf('/',1)) != -1) codebase = path.substring(0,secondSlash); codebase += '/ScriptLibrary'; } if (notuseapplet==0) { document.write('<' + 'APPLET name=RSAspProxyApplet codebase=' + codebase + ' code=RSProxy.class height=0 width=0 style=display:none>'); } else { document.write('<' + 'SPAN name=RSAspProxyApplet id=RSAspProxyApplet codebase=' + codebase + ' height=0 width=0>'); } } function RSExecute(url,method) { var cb, ecb, context; var params = new Array; var pn = 0; var len = RSExecute.arguments.length; for (var i=2; i < len; i++) params[pn++] = RSExecute.arguments[i]; return MSRS.invokeMethod(url,method,params); } function RSGetASPObject(url) { var cb, ecb, context; var params = new Array; var request = MSRS.startRequest(url,'GetServerProxy',params,cb,ecb,context); if (request.status == MSRS_COMPLETED) { var server = request.return_value; if (typeof(Function) == 'function') { for (var name in server) server[name] = Function('return MSRS.invokeMethod(this.location,"' + name + '",this.' + name + '.arguments);'); } else { for (var name in server) server[name] = eval('function t(p0,p1,p2,p3,p4,p5,p6,p7,p8,p9,pA,pB,pC,pD,pE,pF) { return MSRS.invokeMethod(this.location,"' + name + '",this.' + name + '.arguments);} t'); } server.location = url; return server; } alert('Failed to create ASP object for : ' + url); return null; } function RSCallObject(cb,ecb,context) { this.id = MSRS.nextRequestID++; this.status = MSRS_PENDING; this.message = ''; this.data = ''; this.return_value = ''; this.callback = cb; this.error_callback = ecb; this.context = context; this.wait = RSCallObject_wait; this.cancel = RSCallObject_cancel; MSRS.requestList[this.id] = this; } function RSCallObject_wait() { if (this.status != MSRS_PENDING) return; while (true) { if (MSRS.rsapplet.waitForResponse()) { if (MSRS.rsapplet.hasResponse()) { var rid = MSRS.rsapplet.getRequestID(); var res=MSRS.handleResponse(rid); if (!(res)) {break;} var strrid = String(rid); if (strrid == null) strrid = rid; if (strrid == this.id) break; } } else { this.status = MSRS_FAIL; this.message = 'Request not handled.' break; } } } function RSCallObject_cancel() { if (this.status == MSRS_PENDING) { MSRS.rsapplet.cancelRequest(this.id); this.status = MSRS_FAIL; this.message = 'Request cancelled.' } } function _MSRS_Object() { MSRS_FAIL = -1; MSRS_COMPLETED = 0; MSRS_PENDING = 1; MSRS_PARTIAL = 2; this.REQUEST_MODE_COMPLETE = 0; this.POLLING_PERIOD = 100; this.pollID = 0; this.pollCount = 0; this.nextRequestID = 1; this.requestList = new Array; this.rsapplet = null; this.startRequest = _MSRS_startRequest; this.invokeMethod = _MSRS_invokeMethod; this.handleResponse = _MSRS_handleResponse; this.evaluateRequest = _MSRS_evaluateRequest; this.setRequestPoll = _MSRS_setRequestPoll; this.requestPollHandler = _MSRS_requestPollHandler; this.buildURL = _MSRS_buildURL; } function _MSRS_startRequest(url,method,args,cb,ecb,context) { var request = new RSCallObject(cb,ecb,context); if (this.rsapplet == null) { if (notuseapplet==0) { if (typeof(document.RSAspProxyApplet) == 'object') this.rsapplet = document.RSAspProxyApplet; else if (typeof(document.thisForm) == 'object' && typeof(document.thisForm.RSAspProxyApplet) == 'object') this.rsapplet = document.thisForm.RSAspProxyApplet; else { errmsg = 'ERROR:\nCannot locate proxy which supports Remote Scripting.\nWas RSEnableRemoteScripting method invoked?'; request.status = MSRS_FAIL; request.message = errmsg; alert(errmsg); } } else { this.rsapplet = new __rsapplet_Object(request.id); } } else { if (!(notuseapplet==0)) { this.rsapplet = new __rsapplet_Object(request.id); } } if (request.status != MSRS_FAIL) { url = this.buildURL(url,method,args); url_context = window.location.href; if ( (typeof(cb) == 'function')&& (!(notuseapplet==0)) ) { this.rsapplet.startRequest(request.id,url_context,url,this.REQUEST_MODE_COMPLETE,true); } else if (!(notuseapplet==0)) { this.rsapplet.startRequest(request.id,url_context,url,this.REQUEST_MODE_COMPLETE,false); } else { this.rsapplet.startRequest(request.id,url_context,url,this.REQUEST_MODE_COMPLETE); } if (typeof(cb) == 'function') { if (this.pollCount++ == 0) this.setRequestPoll(); } else { request.wait(); } } return request; } function _MSRS_invokeMethod(url,method,args) { var cb, ecb, context; var params = new Array; var pn = 0; var i = 0; for (var i=0; i < args.length; i++) { if (typeof(args[i]) == 'function') { pn = -1; if (typeof(cb) == 'undefined') cb = args[i]; else ecb = args[i]; } else if (pn != -1) { params[pn++] = args[i]; } else context = args[i]; } return MSRS.startRequest(url,method,params,cb,ecb,context); } function _MSRS_handleResponse(requestid) { var request = this.requestList[requestid]; if ((typeof(request) == 'undefined')||(request == null)) { if (this.MS) alert('Unknown request id.'); return false; } request.status = this.rsapplet.getStatus(); if (request.status == MSRS_COMPLETED) { request.data = this.rsapplet.getData(); request.message = this.rsapplet.getMessage(); this.evaluateRequest(request); if (request.status == MSRS_FAIL) { if (typeof(request.error_callback) == 'function') { this.pollCount--; request.error_callback(request); } else alert('Remote Scripting Error\n' + request.message); } else { if (typeof(request.callback) == 'function') { this.pollCount--; request.callback(request); } } this.rsapplet.endResponse(); this.requestList[request.id] = null; } else if (request.status == MSRS_FAIL) { request.message = this.rsapplet.getMessage(); if (typeof(request.error_callback) == 'function') { this.pollCount--; request.error_callback(request); } this.rsapplet.endResponse(); this.requestList[request.id] = null; } else if (request.status == MSRS_PARTIAL) { } else if (request.status == MSRS_PENDING) { } return true; } function _MSRS_evaluateRequest(request) { var data = request.data; var start_index = 0; var end_index = 0; var start_key = '<' + 'RETURN_VALUE'; var end_key = '<' + '/RETURN_VALUE>'; if ((start_index = data.indexOf(start_key)) != -1) { try { var data_start_index = data.indexOf('>',start_index) + 1; end_index = data.indexOf(end_key,data_start_index); if (end_index == -1) end_index = data.length; var metatag = data.substring(start_index,data_start_index); if ((metatag.indexOf('TYPE=SIMPLE') != -1)||(metatag.indexOf('TYPE=\"SIMPLE\"') != -1)) { request.return_value = unescape(data.substring(data_start_index,end_index)); } else if ((metatag.indexOf('TYPE=EVAL_OBJECT') != -1)||(metatag.indexOf('TYPE=\"EVAL_OBJECT\"') != -1)) { request.return_value = data.substring(data_start_index,end_index); request.return_value = eval(unescape(request.return_value)); } else if ((metatag.indexOf('TYPE=ERROR') != -1)||(metatag.indexOf('TYPE=\"ERROR\"') != -1)) { request.status = MSRS_FAIL; request.message = unescape(data.substring(data_start_index,end_index)); } } catch(e) { request.status = MSRS_FAIL; request.message = 'REMOTE SCRIPTING ERROR: Page invoked does not support correctly remote scripting.\nUse XML status code:'+notuseapplet+'.'; } } else { request.status = MSRS_FAIL; request.message = 'REMOTE SCRIPTING ERROR: Page invoked does not support remote scripting.\nUse XML status code:'+notuseapplet+'.'; } } function _MSRS_setRequestPoll() { this.pollID = window.setTimeout('MSRS.requestPollHandler()',this.POLLING_PERIOD,'javascript'); } function _MSRS_requestPollHandler() { while (this.rsapplet.hasResponse()) { var res=this.handleResponse(this.rsapplet.getRequestID()); if (!(res)) {break;} } if (this.pollCount != 0) this.setRequestPoll(); } function _MSRS_buildURL(url,method,args) { if (url == '') url = window.location.pathname; if (typeof(method) == 'string') { url += '?_method=' + method; url += '&_mtype=execute'; //url += '&_securekey=xyz'; var params = '&pcount=0'; if (typeof(args) != 'undefined' && args.length) { params = '&pcount=' + args.length for (var i = 0; i < args.length; i++) { var arg = args[i]; arg=String(arg).replace(/\+/gi,"rsplus"); params += '&p' + i + '=' + escape(arg); } } url += params; } return url; } function __rsapplet_Object(valueid) { this.valueid=valueid; this.__xmlHTTP = null; try { if (notuseapplet==1) { this.__xmlHTTP = new ActiveXObject("Microsoft.XMLHTTP"); } else if (notuseapplet==2) { this.__xmlHTTP = new XMLHttpRequest(); } else if (notuseapplet==3) { this.__xmlHTTP = new HttpRequest(); } else if (notuseapplet==4) { this.__xmlHTTP = new ActiveXObject("Msxml2.XMLHTTP"); } } catch(e) { alert("This Browser doesn't support this script/page\n(\nver:"+RSVersion()+"\n"+e.description+"\nStatus XML:"+notuseapplet+")") this.waitForResponse = true; this.hasResponse = true; this.getRequestID = valueid; this.startRequest = ""; this.getStatus = MSRS_FAIL; this.getData = ""; this.getMessage = ""; this.endResponse = ""; return; } this.waitForResponse = __rsapplet_waitForResponse; this.hasResponse = __rsapplet_hasResponse; this.getRequestID = __rsapplet_getRequestID; this.startRequest = __rsapplet_startRequest; this.getStatus = __rsapplet_getStatus; this.getData = __rsapplet_getData; this.getMessage = __rsapplet_getMessage; this.endResponse = __rsapplet_endResponse; } function __rsapplet_waitForResponse() { if (this.__xmlHTTP!=null) { while (this.__xmlHTTP.readyState != 4) { void this.__xmlHTTP.waitForResponse(); } } return true; } function __rsapplet_hasResponse() { if ((this.__xmlHTTP==null )||(this.__xmlHTTP.readyState==4)) return true; else return false; } function __rsapplet_getRequestID() { return this.valueid; } function __cancelRequest(valueid) { this.__xmlHTTP.abort(); } function __rsapplet_startRequest(id,url_context,url,REQUEST_MODE_COMPLETE,async) { var asyncmethod=( (typeof(async)=="undefined") ? true : async); var codebase=document.getElementById("RSAspProxyApplet").codebase; this.__xmlHTTP.open("POST", url, asyncmethod); this.__xmlHTTP.send(""); } function __rsapplet_getStatus() { var tempvalue=MSRS_FAIL; if (this.__xmlHTTP!=null) { if (this.__xmlHTTP.readyState==4) {tempvalue=MSRS_COMPLETED} else if (this.__xmlHTTP.readyState>=2) {tempvalue=MSRS_PARTIAL} else if (this.__xmlHTTP.readyState>=1) {tempvalue=MSRS_PENDING} } return tempvalue; } function __rsapplet_getData() { var temp=""; try {temp=String(this.__xmlHTTP.ResponseText)} catch(e) {} if ((temp=="")||(temp=="undefined")) { try {temp=String(this.__xmlHTTP.responseText) } catch(e) {} } return temp; } function __rsapplet_getMessage() { var strmsg="undefined"; var xmlHTTP_readyState=0; if (this.__xmlHTTP!=null) xmlHTTP_readyState=this.__xmlHTTP.readyState; switch (xmlHTTP_readyState) { case 0:{strmsg="UNINITIALIZED";break;} case 1:{strmsg="LOADING";break;} case 2:{strmsg="LOADED";break;} case 3:{strmsg="INTERACTIVE";break;} case 4:{strmsg="COMPLETED";break;} } return strmsg; } function __rsapplet_endResponse() { try{void this.__xmlHTTP.abort();}catch(e){} try{this.__xmlHTTP=null;}catch(e){} } var notuseapplet=useappletjava(); var MSRS = new _MSRS_Object();