4 * Copyright (C) 2006 matteo.nastasi@milug.org
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABLILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details. You should have received a
15 * copy of the GNU General Public License along with this program; if
16 * not, write to the Free Software Foundation, Inc, 59 Temple Place -
17 * Suite 330, Boston, MA 02111-1307, USA.
21 var xhr_rd_cookiepath = "/brisk/";
23 var xhr_rd_stopped = true;
24 var xhr_rd_oldctx = "";
27 var xhr_rd_cur_n = -1;
28 var xhr_rd_old_n = -1;
29 var xhr_rd_checkedlen = 0;
34 function xhr_rd_cb(xhr_rd)
38 if (xhr_rd.readyState == 4) {
40 if ((ret = safestatus(xhr_rd)) == 200) {
41 } else if (ret != -1) {
42 alert('There was a problem with the request.' + ret);
46 xhr_rd_stopped = true;
50 function xhr_rd_start(sess,stat,subst,step)
54 createCookie("sess",sess,1,xhr_rd_cookiepath);
56 /* NOTE document.uniqueID exists only under IE */
58 xhr_rd.open('GET', 'index_rd.php?sess='+sess+"&stat="+stat+"&subst="+subst+"&step="+step+"&onlyone="+(document.uniqueID ? "TRUE" : "FALSE")+"&myfrom="+myfrom, true);
60 xhr_rd.onreadystatechange = function() { xhr_rd_cb(xhr_rd); }
63 xhr_rd_stopped = false;
67 function xhr_rd_poll(sess)
77 // alert("ABORT XHR_RD");
78 xhr_rd_stopped = true;
83 var zug = "XHR_RD_POLL sess = "+sess+" stat = "+stat+" subst = "+subst+" step = "+gst.st+" step_loc = "+gst.st_loc+" step_loc_new = "+gst.st_loc_new+" STOP: "+xhr_rd_stopped;
85 if (zug != $("sandbox").innerHTML)
86 $("sandbox").innerHTML = zug;
90 $("sandbox2").innerHTML += "_";
91 if ($("sandbox2").innerHTML.length == 20)
92 $("sandbox2").innerHTML = "_";
97 if (gst.st_loc < gst.st_loc_new) {
98 // there is some slow actions running
101 else if (gst.comms.length > 0) {
104 singlecomm = gst.comms.shift();
105 // alert("EXE"+gugu);
106 // $("xhrdeltalog").innerHTML = "EVALL: "+singlecomm.replace("<", "<", "g"); +"<br>";
113 xhr_rd_newctx = xhr_rd.responseText;
116 if (xhr_rd_stopped == true) {
117 xhr_rd_stopped = false;
118 // XX $("xhrstart").innerHTML += "XHRSTART: da catch<br>";
119 xhr_rd_start(sess, stat, subst, gst.st);
123 // $("sandbox").innerHTML += "return 1<br>";
124 if (the_end != true) {
126 setTimeout(xhr_rd_poll, tout, sess);
127 $("sandbox2").innerHTML += "-";
128 if ($("sandbox2").innerHTML.length == 20)
129 $("sandbox2").innerHTML = "-";
135 // no new char from the last loop, break
136 if (xhr_rd_old_n == xhr_rd_cur_n &&
137 xhr_rd_newctx.length == xhr_rd_checkedlen) {
143 // $("sandbox").innerHTML += "BIG IF<br>";
151 var match_lines = /^_*$/;
153 // check for the same command group
154 if (xhr_rd_old_n != xhr_rd_cur_n) {
155 xhr_rd_old_n = xhr_rd_cur_n;
156 xhr_rd_checkedlen = 0;
160 delta = xhr_rd_oldctx.length;
162 // $("xhrlog").innerHTML += "EVERY SEC<br>";
163 for (i = delta ; i < xhr_rd_newctx.length ; i++) {
164 if (xhr_rd_newctx[i] != '_')
167 if (i == xhr_rd_newctx.length) {
168 xhr_rd_checkedlen = i;
172 // $("xhrlog").innerHTML += "CHECK COM<br>";
173 // extracts the new part of the command string
174 comm_newpart = xhr_rd_newctx.substr(delta);
176 // XX $("xhrlog").innerHTML = xhr_rd_newctx.replace("<", "<", "g");
178 // $("response").innerHTML = comm_newpart;
179 comm_match = /_*@BEGIN@(.*?)@END@/g;
180 comm_clean = /_*@BEGIN@(.*?)@END@/;
182 comm_arr = comm_newpart.match(comm_match);
184 // $("sandbox").innerHTML += "PRE COMMARR<br>";
186 // XX $("xhrdeltalog").innerHTML += "DELTA: "+delta +"<br>";
187 // XX alert("xhr_rd_newctx: "+xhr_rd_newctx);
188 // $("sandbox").innerHTML += "POST COMMARR<br>";
189 for (i = 0 ; i < comm_arr.length ; i++) {
190 var temp = comm_arr[i].replace(comm_clean,"$1").split("|");
191 gst.comms = gst.comms.concat(temp);
192 // XX alert("COMM_ARR["+i+"]: "+comm_arr[i]+" LEN:"+comm_arr[i].length);
193 comm_len += comm_arr[i].length;
196 xhr_rd_oldctx += comm_newpart.substr(0,comm_len);
197 // XX alert("XHR_RD_OLDCTX: "+xhr_rd_oldctx);
200 xhr_rd_checkedlen = xhr_rd_oldctx.length;
205 if (xhrrestart == 1 && xhr_rd_stopped == true) {
206 // $("sandbox").innerHTML += "LITTLE IF<br>";
208 // XX $("xhrstart").innerHTML += "XHRSTART: da end poll<br>";
209 xhr_rd_start(sess, stat, subst, gst.st);
210 // $("sandbox").innerHTML += "return 2<br>";
213 // $("sandbox").innerHTML += "return 3<br>";
214 if (the_end != true) {
215 setTimeout(xhr_rd_poll, tout, sess);
216 $("sandbox2").innerHTML += "-";
217 if ($("sandbox2").innerHTML.length == 20)
218 $("sandbox2").innerHTML = "-";
224 window.onload = function () {
225 xhr_rd = createXMLHttpRequest();
227 sess = $("user").value;
228 window.setTimeout(xhr_rd_poll, 0, sess);