4 * Copyright (C) 2006-2011 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.
24 var xhr_rd_cookiepath = "/brisk/";
26 var xhr_rd_stopped = true;
27 var xhr_rd_oldctx = "";
28 var xhr_rd_newctx = "";
30 var xhr_rd_delayed = null;
31 var xhr_rd_cur_n = -1;
32 var xhr_rd_old_n = -1;
33 var xhr_rd_checkedlen = 0;
34 var xhr_rd_watchdog = null;
41 if ($("heartbit").innerHTML.length >= 120) {
42 $("heartbit").innerHTML = $("heartbit").innerHTML.substring(10);
43 $("heartbit").innerHTML += symb;
46 $("heartbit").innerHTML += symb;
48 // $("heartbit").innerHTML = $("heartbit").innerHTML.substring(20,20); // DA METTERE APPOSTO!!!!
52 function xhr_rd_cb(xhr_rd)
56 // console.log(xhr_rd.readyState);
58 if (xhr_rd.readyState == 4) {
59 if (xhr_rd_watchdog != null) {
61 clearTimeout(xhr_rd_watchdog);
62 xhr_rd_watchdog = null;
65 // console.log("SS: "+safestatus(xhr_rd));
68 if ((ret = safestatus(xhr_rd)) == 200) {
70 // console.log("del a null "+xhr_rd_delayed);
71 } else if (ret != -1) {
74 // alert('There was a problem with the request.' + ret);
78 xhr_rd_delayed = null;
79 xhr_rd_stopped = true;
83 function xhr_rd_abort(xhr)
91 function xhr_rd_start(sess,stat,subst,step)
94 if (xhr_rd_watchdog != null) {
96 clearTimeout(xhr_rd_watchdog);
97 xhr_rd_watchdog = null;
101 createCookie("sess", sess, 24*365, xhr_rd_cookiepath);
103 // NOTE: *ctx = "" to prevent konqueror stream commands duplication.
107 /* NOTE document.uniqueID exists only under IE */
108 // if (g_is_spawn == 1)
109 // alert("di qui3: "+(g_is_spawn == 1 ? "&table_idx="+g_table_idx : ""));
110 xhr_rd.open('GET', 'index_rd.php?sess='+sess+"&stat="+stat+"&subst="+subst+"&step="+step+"&onlyone="+(document.uniqueID ? "TRUE" : "FALSE")+"&myfrom="+myfrom, true);
112 xhr_rd.onreadystatechange = function() { xhr_rd_cb(xhr_rd); }
115 // TODO: qui avvio del timer per riavviare xhr
117 xhr_rd_watchdog = setTimeout(xhr_rd_abort, 60000, xhr_rd);
119 xhr_rd_stopped = false;
123 function xhr_rd_poll(sess)
131 if (watchdog >= 50) {
133 // alert("ABORT XHR_RD");
134 xhr_rd_stopped = true;
138 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;
140 if (zug != $("sandbox").innerHTML)
141 $("sandbox").innerHTML = zug;
149 if (gst.st_loc < gst.st_loc_new) {
150 // there is some slow actions running
153 else if (gst.comms.length > 0) {
156 singlecomm = gst.comms.shift();
157 // alert("EXE"+gugu);
158 // $("xhrdeltalog").innerHTML = "EVALL: "+singlecomm.replace("<", "<", "g"); +"<br>";
169 if (xhr_rd.responseText != null)
170 xhr_rd_newctx = xhr_rd.responseText;
173 if (xhr_rd_stopped == true) {
174 xhr_rd_stopped = false;
175 // XX $("xhrstart").innerHTML += "XHRSTART: da catch<br>";
176 if (xhr_rd_delay > 0) {
177 if (xhr_rd_delayed == null) {
178 // console.log("XXX DI QUI "+xhr_rd_delay);
179 xhr_rd_delayed = setTimeout(xhr_rd_start, xhr_rd_delay, sess, stat, subst, gst.st);
180 // console.log("XXX DI QUI post"+xhr_rd_delayed);
184 // console.log("yyy DI QUI "+xhr_rd_delay);
185 xhr_rd_start(sess, stat, subst, gst.st);
190 // $("sandbox").innerHTML += "return 1<br>";
191 if (the_end != true) {
193 setTimeout(xhr_rd_poll, tout, sess);
199 if (xhr_rd_watchdog != null) {
200 clearTimeout(xhr_rd_watchdog);
201 xhr_rd_watchdog = null;
208 // no new char from the last loop, break
209 if (xhr_rd_old_n == xhr_rd_cur_n &&
210 xhr_rd_newctx.length == xhr_rd_checkedlen) {
216 // $("sandbox").innerHTML += "BIG IF<br>";
224 var match_lines = /^_*$/;
228 // check for the same command group
229 if (xhr_rd_old_n != xhr_rd_cur_n) {
230 xhr_rd_old_n = xhr_rd_cur_n;
231 xhr_rd_checkedlen = 0;
235 delta = xhr_rd_oldctx.length;
237 // $("xhrlog").innerHTML += "EVERY SEC<br>";
238 for (i = delta ; i < xhr_rd_newctx.length ; i++) {
239 if (xhr_rd_newctx[i] != '_')
242 if (i == xhr_rd_newctx.length) {
243 xhr_rd_checkedlen = i;
247 // $("xhrlog").innerHTML += "CHECK COM<br>";
248 // extracts the new part of the command string
249 comm_newpart = xhr_rd_newctx.substr(delta);
251 // XX $("xhrlog").innerHTML = xhr_rd_newctx.replace("<", "<", "g");
253 // $("response").innerHTML = comm_newpart;
254 comm_match = /_*@BEGIN@(.*?)@END@/g;
255 comm_clean = /_*@BEGIN@(.*?)@END@/;
257 comm_arr = comm_newpart.match(comm_match);
259 // $("sandbox").innerHTML += "PRE COMMARR<br>";
261 // XX $("xhrdeltalog").innerHTML += "DELTA: "+delta +"<br>";
262 // XX alert("xhr_rd_newctx: "+xhr_rd_newctx);
263 // $("sandbox").innerHTML += "POST COMMARR<br>";
264 for (i = 0 ; i < comm_arr.length ; i++) {
265 var temp = comm_arr[i].replace(comm_clean,"$1").split("|");
266 gst.comms = gst.comms.concat(temp);
267 // XX alert("COMM_ARR["+i+"]: "+comm_arr[i]+" LEN:"+comm_arr[i].length);
268 comm_len += comm_arr[i].length;
271 xhr_rd_oldctx += comm_newpart.substr(0,comm_len);
272 // XX alert("XHR_RD_OLDCTX: "+xhr_rd_oldctx);
275 xhr_rd_checkedlen = xhr_rd_oldctx.length;
280 if (xhrrestart == 1 && xhr_rd_stopped == true) {
281 // $("sandbox").innerHTML += "LITTLE IF<br>";
283 // XX $("xhrstart").innerHTML += "XHRSTART: da end poll<br>";
285 if (xhr_rd_delay > 0) {
286 if (xhr_rd_delayed == null) {
287 // console.log("XXX DI QUO "+xhr_rd_delay);
288 xhr_rd_delayed = setTimeout(xhr_rd_start, xhr_rd_delay, sess, stat, subst, gst.st);
289 // console.log("XXX DI QUO post"+xhr_rd_delayed);
293 // console.log("yyy DI QUO "+xhr_rd_delay);
294 xhr_rd_start(sess, stat, subst, gst.st);
299 if (the_end != true) {
300 setTimeout(xhr_rd_poll, tout, sess);
303 if (xhr_rd_watchdog != null) {
304 clearTimeout(xhr_rd_watchdog);
305 xhr_rd_watchdog = null;
312 window.onload = function () {
313 xhr_rd = createXMLHttpRequest();
315 sess = $("user").value;
316 window.setTimeout(xhr_rd_poll, 0, sess);