4 * Copyright (C) 2006-2008 Matteo Nastasi
5 * mailto: nastasi@alternativeoutput.it
6 * matteo.nastasi@milug.org
7 * web: http://www.alternativeoutput.it
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABLILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details. You should have received a
18 * copy of the GNU General Public License along with this program; if
19 * not, write to the Free Software Foundation, Inc, 59 Temple Place -
20 * Suite 330, Boston, MA 02111-1307, USA.
26 var xhr_rd_cookiepath = "/brisk/";
28 var xhr_rd_stopped = true;
29 var xhr_rd_oldctx = "";
30 var xhr_rd_newctx = "";
32 var xhr_rd_delayed = null;
33 var xhr_rd_cur_n = -1;
34 var xhr_rd_old_n = -1;
35 var xhr_rd_checkedlen = 0;
36 var xhr_rd_watchdog = null;
43 if ($("heartbit").innerHTML.length >= 120) {
44 $("heartbit").innerHTML = $("heartbit").innerHTML.substring(10);
45 $("heartbit").innerHTML += symb;
48 $("heartbit").innerHTML += symb;
50 // $("heartbit").innerHTML = $("heartbit").innerHTML.substring(20,20); // DA METTERE APPOSTO!!!!
54 function xhr_rd_cb(xhr_rd)
58 // console.log(xhr_rd.readyState);
60 if (xhr_rd.readyState == 4) {
61 if (xhr_rd_watchdog != null) {
63 clearTimeout(xhr_rd_watchdog);
64 xhr_rd_watchdog = null;
67 // console.log("SS: "+safestatus(xhr_rd));
70 if ((ret = safestatus(xhr_rd)) == 200) {
72 // console.log("del a null "+xhr_rd_delayed);
73 } else if (ret != -1) {
76 // alert('There was a problem with the request.' + ret);
80 xhr_rd_delayed = null;
81 xhr_rd_stopped = true;
85 function xhr_rd_abort(xhr)
93 function xhr_rd_start(sess,stat,subst,step)
96 if (xhr_rd_watchdog != null) {
98 clearTimeout(xhr_rd_watchdog);
99 xhr_rd_watchdog = null;
103 createCookie("sess", sess, 24*365, xhr_rd_cookiepath);
105 // NOTE: *ctx = "" to prevent konqueror stream commands duplication.
109 /* NOTE document.uniqueID exists only under IE */
110 // if (g_is_spawn == 1)
111 // alert("di qui3: "+(g_is_spawn == 1 ? "&table_idx="+g_table_idx : ""));
112 xhr_rd.open('GET', 'index_rd.php?sess='+sess+"&stat="+stat+"&subst="+subst+"&step="+step+"&onlyone="+(document.uniqueID ? "TRUE" : "FALSE")+"&myfrom="+myfrom, true);
114 xhr_rd.onreadystatechange = function() { xhr_rd_cb(xhr_rd); }
117 // TODO: qui avvio del timer per riavviare xhr
119 xhr_rd_watchdog = setTimeout(xhr_rd_abort, 60000, xhr_rd);
121 xhr_rd_stopped = false;
125 function xhr_rd_poll(sess)
133 if (watchdog >= 50) {
135 // alert("ABORT XHR_RD");
136 xhr_rd_stopped = true;
140 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;
142 if (zug != $("sandbox").innerHTML)
143 $("sandbox").innerHTML = zug;
151 if (gst.st_loc < gst.st_loc_new) {
152 // there is some slow actions running
155 else if (gst.comms.length > 0) {
158 singlecomm = gst.comms.shift();
159 // alert("EXE"+gugu);
160 // $("xhrdeltalog").innerHTML = "EVALL: "+singlecomm.replace("<", "<", "g"); +"<br>";
171 if (xhr_rd.responseText != null)
172 xhr_rd_newctx = xhr_rd.responseText;
175 if (xhr_rd_stopped == true) {
176 xhr_rd_stopped = false;
177 // XX $("xhrstart").innerHTML += "XHRSTART: da catch<br>";
178 if (xhr_rd_delay > 0) {
179 if (xhr_rd_delayed == null) {
180 // console.log("XXX DI QUI "+xhr_rd_delay);
181 xhr_rd_delayed = setTimeout(xhr_rd_start, xhr_rd_delay, sess, stat, subst, gst.st);
182 // console.log("XXX DI QUI post"+xhr_rd_delayed);
186 // console.log("yyy DI QUI "+xhr_rd_delay);
187 xhr_rd_start(sess, stat, subst, gst.st);
192 // $("sandbox").innerHTML += "return 1<br>";
193 if (the_end != true) {
195 setTimeout(xhr_rd_poll, tout, sess);
201 if (xhr_rd_watchdog != null) {
202 clearTimeout(xhr_rd_watchdog);
203 xhr_rd_watchdog = null;
210 // no new char from the last loop, break
211 if (xhr_rd_old_n == xhr_rd_cur_n &&
212 xhr_rd_newctx.length == xhr_rd_checkedlen) {
218 // $("sandbox").innerHTML += "BIG IF<br>";
226 var match_lines = /^_*$/;
230 // check for the same command group
231 if (xhr_rd_old_n != xhr_rd_cur_n) {
232 xhr_rd_old_n = xhr_rd_cur_n;
233 xhr_rd_checkedlen = 0;
237 delta = xhr_rd_oldctx.length;
239 // $("xhrlog").innerHTML += "EVERY SEC<br>";
240 for (i = delta ; i < xhr_rd_newctx.length ; i++) {
241 if (xhr_rd_newctx[i] != '_')
244 if (i == xhr_rd_newctx.length) {
245 xhr_rd_checkedlen = i;
249 // $("xhrlog").innerHTML += "CHECK COM<br>";
250 // extracts the new part of the command string
251 comm_newpart = xhr_rd_newctx.substr(delta);
253 // XX $("xhrlog").innerHTML = xhr_rd_newctx.replace("<", "<", "g");
255 // $("response").innerHTML = comm_newpart;
256 comm_match = /_*@BEGIN@(.*?)@END@/g;
257 comm_clean = /_*@BEGIN@(.*?)@END@/;
259 comm_arr = comm_newpart.match(comm_match);
261 // $("sandbox").innerHTML += "PRE COMMARR<br>";
263 // XX $("xhrdeltalog").innerHTML += "DELTA: "+delta +"<br>";
264 // XX alert("xhr_rd_newctx: "+xhr_rd_newctx);
265 // $("sandbox").innerHTML += "POST COMMARR<br>";
266 for (i = 0 ; i < comm_arr.length ; i++) {
267 var temp = comm_arr[i].replace(comm_clean,"$1").split("|");
268 gst.comms = gst.comms.concat(temp);
269 // XX alert("COMM_ARR["+i+"]: "+comm_arr[i]+" LEN:"+comm_arr[i].length);
270 comm_len += comm_arr[i].length;
273 xhr_rd_oldctx += comm_newpart.substr(0,comm_len);
274 // XX alert("XHR_RD_OLDCTX: "+xhr_rd_oldctx);
277 xhr_rd_checkedlen = xhr_rd_oldctx.length;
282 if (xhrrestart == 1 && xhr_rd_stopped == true) {
283 // $("sandbox").innerHTML += "LITTLE IF<br>";
285 // XX $("xhrstart").innerHTML += "XHRSTART: da end poll<br>";
287 if (xhr_rd_delay > 0) {
288 if (xhr_rd_delayed == null) {
289 // console.log("XXX DI QUO "+xhr_rd_delay);
290 xhr_rd_delayed = setTimeout(xhr_rd_start, xhr_rd_delay, sess, stat, subst, gst.st);
291 // console.log("XXX DI QUO post"+xhr_rd_delayed);
295 // console.log("yyy DI QUO "+xhr_rd_delay);
296 xhr_rd_start(sess, stat, subst, gst.st);
301 if (the_end != true) {
302 setTimeout(xhr_rd_poll, tout, sess);
305 if (xhr_rd_watchdog != null) {
306 clearTimeout(xhr_rd_watchdog);
307 xhr_rd_watchdog = null;
314 window.onload = function () {
315 xhr_rd = createXMLHttpRequest();
317 sess = $("user").value;
318 window.setTimeout(xhr_rd_poll, 0, sess);