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.
23 var xhr_rd_cookiepath = "/brisk/";
25 var xhr_rd_stopped = true;
26 var xhr_rd_oldctx = "";
27 var xhr_rd_newctx = "";
29 var xhr_rd_cur_n = -1;
30 var xhr_rd_old_n = -1;
31 var xhr_rd_checkedlen = 0;
36 function xhr_rd_cb(xhr_rd)
40 if (xhr_rd.readyState == 4) {
42 if ((ret = safestatus(xhr_rd)) == 200) {
43 } else if (ret != -1) {
44 alert('There was a problem with the request.' + ret);
48 xhr_rd_stopped = true;
52 function xhr_rd_start(sess,stat,subst,step)
56 createCookie("sess", sess, 24*365, xhr_rd_cookiepath);
58 // NOTE: *ctx = "" to prevent konqueror stream commands duplication.
62 /* NOTE document.uniqueID exists only under IE */
64 xhr_rd.open('GET', 'index_rd.php?sess='+sess+"&stat="+stat+"&subst="+subst+"&step="+step+"&onlyone="+(document.uniqueID ? "TRUE" : "FALSE")+"&myfrom="+myfrom, true);
66 xhr_rd.onreadystatechange = function() { xhr_rd_cb(xhr_rd); }
69 xhr_rd_stopped = false;
73 function xhr_rd_poll(sess)
83 // alert("ABORT XHR_RD");
84 xhr_rd_stopped = true;
88 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;
90 if (zug != $("sandbox").innerHTML)
91 $("sandbox").innerHTML = zug;
94 $("heartbit").innerHTML += "_";
95 if ($("heartbit").innerHTML.length == 20)
96 $("heartbit").innerHTML = "_";
101 if (gst.st_loc < gst.st_loc_new) {
102 // there is some slow actions running
105 else if (gst.comms.length > 0) {
108 singlecomm = gst.comms.shift();
109 // alert("EXE"+gugu);
110 // $("xhrdeltalog").innerHTML = "EVALL: "+singlecomm.replace("<", "<", "g"); +"<br>";
119 if (xhr_rd.responseText != null)
120 xhr_rd_newctx = xhr_rd.responseText;
123 if (xhr_rd_stopped == true) {
124 xhr_rd_stopped = false;
125 // XX $("xhrstart").innerHTML += "XHRSTART: da catch<br>";
126 xhr_rd_start(sess, stat, subst, gst.st);
130 // $("sandbox").innerHTML += "return 1<br>";
131 if (the_end != true) {
133 setTimeout(xhr_rd_poll, tout, sess);
135 $("heartbit").innerHTML += "-";
136 if ($("heartbit").innerHTML.length == 20)
137 $("heartbit").innerHTML = "-";
144 // no new char from the last loop, break
145 if (xhr_rd_old_n == xhr_rd_cur_n &&
146 xhr_rd_newctx.length == xhr_rd_checkedlen) {
152 // $("sandbox").innerHTML += "BIG IF<br>";
160 var match_lines = /^_*$/;
162 // check for the same command group
163 if (xhr_rd_old_n != xhr_rd_cur_n) {
164 xhr_rd_old_n = xhr_rd_cur_n;
165 xhr_rd_checkedlen = 0;
169 delta = xhr_rd_oldctx.length;
171 // $("xhrlog").innerHTML += "EVERY SEC<br>";
172 for (i = delta ; i < xhr_rd_newctx.length ; i++) {
173 if (xhr_rd_newctx[i] != '_')
176 if (i == xhr_rd_newctx.length) {
177 xhr_rd_checkedlen = i;
181 // $("xhrlog").innerHTML += "CHECK COM<br>";
182 // extracts the new part of the command string
183 comm_newpart = xhr_rd_newctx.substr(delta);
185 // XX $("xhrlog").innerHTML = xhr_rd_newctx.replace("<", "<", "g");
187 // $("response").innerHTML = comm_newpart;
188 comm_match = /_*@BEGIN@(.*?)@END@/g;
189 comm_clean = /_*@BEGIN@(.*?)@END@/;
191 comm_arr = comm_newpart.match(comm_match);
193 // $("sandbox").innerHTML += "PRE COMMARR<br>";
195 // XX $("xhrdeltalog").innerHTML += "DELTA: "+delta +"<br>";
196 // XX alert("xhr_rd_newctx: "+xhr_rd_newctx);
197 // $("sandbox").innerHTML += "POST COMMARR<br>";
198 for (i = 0 ; i < comm_arr.length ; i++) {
199 var temp = comm_arr[i].replace(comm_clean,"$1").split("|");
200 gst.comms = gst.comms.concat(temp);
201 // XX alert("COMM_ARR["+i+"]: "+comm_arr[i]+" LEN:"+comm_arr[i].length);
202 comm_len += comm_arr[i].length;
205 xhr_rd_oldctx += comm_newpart.substr(0,comm_len);
206 // XX alert("XHR_RD_OLDCTX: "+xhr_rd_oldctx);
209 xhr_rd_checkedlen = xhr_rd_oldctx.length;
214 if (xhrrestart == 1 && xhr_rd_stopped == true) {
215 // $("sandbox").innerHTML += "LITTLE IF<br>";
217 // XX $("xhrstart").innerHTML += "XHRSTART: da end poll<br>";
218 xhr_rd_start(sess, stat, subst, gst.st);
219 // $("sandbox").innerHTML += "return 2<br>";
222 // $("sandbox").innerHTML += "return 3<br>";
223 if (the_end != true) {
224 setTimeout(xhr_rd_poll, tout, sess);
226 $("heartbit").innerHTML += "-";
227 if ($("heartbit").innerHTML.length == 20)
228 $("heartbit").innerHTML = "-";
235 window.onload = function () {
236 xhr_rd = createXMLHttpRequest();
238 sess = $("user").value;
239 window.setTimeout(xhr_rd_poll, 0, sess);