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.
29 * - sandbox management
30 * - myfrom into the constructor
31 * - target page into the constructor
32 * - type of streaming into the constructor
33 * - all iframe related streaming add
34 * - substitute fixed "eval" with a generic command hunks processor
36 * DONE - xhr_rd prefix remove from inner class attrs
42 if ($("heartbit").innerHTML.length >= 120) {
43 $("heartbit").innerHTML = $("heartbit").innerHTML.substring(10);
44 $("heartbit").innerHTML += symb;
47 $("heartbit").innerHTML += symb;
51 function http_streaming(cookiename)
53 this.xhr = createXMLHttpRequest();
54 this.cookiename = cookiename;
57 http_streaming.prototype = {
59 cookiepath: "/brisk/",
71 /* watchdog_old: 0, */
77 hbit_set: function (hbit) {
84 if (this.xhr.readyState == 4) {
85 if (this.watchdog != null) {
87 clearTimeout(this.watchdog);
91 // console.log("SS: "+safestatus(xhr));
94 if ((ret = safestatus(this.xhr)) == 200) {
96 // console.log("del a null "+this.delayed);
97 } else if (ret != -1) {
100 // alert('There was a problem with the request.' + ret);
109 xhr_abort: function()
112 if (this.xhr != null)
117 run: function(sess, stat, subst, step)
120 //x alert("the_end1");
121 if (this.watchdog != null) {
123 clearTimeout(this.watchdog);
124 this.watchdog = null;
128 createCookie(this.cookie_name, sess, 24*365, this.cookiepath);
130 // NOTE: *ctx = "" to prevent konqueror stream commands duplication.
134 /* NOTE document.uniqueID exists only under IE */
135 // if (g_is_spawn == 1)
136 // alert("di qui3: "+(g_is_spawn == 1 ? "&table_idx="+g_table_idx : ""));
137 this.xhr.open('GET', 'index_rd.php?sess='+sess+"&stat="+stat+"&subst="+subst+"&step="+step+"&onlyone="+(document.uniqueID ? "TRUE" : "FALSE")+"&myfrom="+myfrom, true);
141 this.xhr.onreadystatechange = function () { self.xhr_cb(); };
144 // TODO: qui avvio del timer per riavviare xhr
146 this.watchdog = setTimeout(function(obj){ obj.xhr_abort(); }, 60000, this);
148 this.stopped = false;
152 /* WORK HERE TO RUN WIN OR LIN STREAM */
154 start: function(sess)
173 if (this.watchdog_old >= 50) {
174 this.watchdog_old = 0;
175 // alert("ABORT XHR");
180 var zug = "POLL sess = "+sess+" stat = "+stat+" subst = "+subst+" step = "+gst.st+" step_loc = "+gst.st_loc+" step_loc_new = "+gst.st_loc_new+" STOP: "+this.stopped;
182 if (zug != $("sandbox").innerHTML)
183 $("sandbox").innerHTML = zug;
190 if (gst.st_loc < gst.st_loc_new) {
191 // there is some slow actions running
194 else if (gst.comms.length > 0) {
197 singlecomm = gst.comms.shift();
198 // alert("EXE"+gugu);
199 // $("xhrdeltalog").innerHTML = "EVALL: "+singlecomm.replace("<", "<", "g"); +"<br>";
208 if (this.xhr == null)
210 if (this.xhr.responseText != null)
211 this.newctx = this.xhr.responseText;
214 if (this.stopped == true) {
215 this.stopped = false;
216 // XX $("xhrstart").innerHTML += "XHRSTART: da catch<br>";
217 if (this.delay > 0) {
218 if (this.delayed == null) {
219 // console.log("XXX DI QUI "+this.delay);
221 this.delayed = setTimeout(
222 function(f_obj, f_sess, f_stat, f_subst, f_step){ f_obj.run(f_sess, f_stat, f_subst, f_step); },
223 this.delay, this, sess, stat, subst, gst.st);
224 // console.log("XXX DI QUI post"+this.delayed);
228 // console.log("yyy DI QUI "+this.delay);
229 this.run(sess, stat, subst, gst.st);
234 // $("sandbox").innerHTML += "return 1<br>";
235 if (this.the_end != true) {
236 /* this.watchdog_old = 0; */
237 setTimeout(function(obj, sess){ obj.poll(sess); }, tout, this, sess);
243 //x alert("the_end2");
244 if (this.watchdog != null) {
245 clearTimeout(this.watchdog);
246 this.watchdog = null;
253 // no new char from the last loop, break
254 if (this.old_n == this.cur_n &&
255 this.newctx.length == this.checkedlen) {
256 /* this.watchdog++; */
260 // $("sandbox").innerHTML += "BIG IF<br>";
268 var match_lines = /^_*$/;
270 /* this.watchdog = 0; */
273 // check for the same command group
274 if (this.old_n != this.cur_n) {
275 this.old_n = this.cur_n;
280 delta = this.oldctx.length;
282 // $("xhrlog").innerHTML += "EVERY SEC<br>";
283 for (i = delta ; i < this.newctx.length ; i++) {
284 if (this.newctx[i] != '_')
287 if (i == this.newctx.length) {
292 // $("xhrlog").innerHTML += "CHECK COM<br>";
293 // extracts the new part of the command string
294 comm_newpart = this.newctx.substr(delta);
296 // XX $("xhrlog").innerHTML = newctx.replace("<", "<", "g");
298 // $("response").innerHTML = comm_newpart;
299 comm_match = /_*@BEGIN@(.*?)@END@/g;
300 comm_clean = /_*@BEGIN@(.*?)@END@/;
302 comm_arr = comm_newpart.match(comm_match);
304 // $("sandbox").innerHTML += "PRE COMMARR<br>";
306 // XX $("xhrdeltalog").innerHTML += "DELTA: "+delta +"<br>";
307 // XX alert("newctx: "+this.newctx);
308 // $("sandbox").innerHTML += "POST COMMARR<br>";
309 for (i = 0 ; i < comm_arr.length ; i++) {
310 var temp = comm_arr[i].replace(comm_clean,"$1").split("|");
311 gst.comms = gst.comms.concat(temp);
312 // XX alert("COMM_ARR["+i+"]: "+comm_arr[i]+" LEN:"+comm_arr[i].length);
313 comm_len += comm_arr[i].length;
316 this.oldctx += comm_newpart.substr(0,comm_len);
317 // XX alert("OLDCTX: "+this.oldctx);
320 this.checkedlen = this.oldctx.length;
325 if (xhrrestart == 1 && this.stopped == true) {
326 // $("sandbox").innerHTML += "LITTLE IF<br>";
328 // XX $("xhrstart").innerHTML += "XHRSTART: da end poll<br>";
329 if (this.delay > 0) {
330 if (this.delayed == null) {
331 // console.log("XXX DI QUO "+this.delay);
333 this.delayed = setTimeout(
334 function(obj, sess, stat, subst, step){ obj.run(sess, stat, subst, step); },
335 this.delay, this, sess, stat, subst, gst.st);
336 // console.log("XXX DI QUO post"+this.delayed);
340 // console.log("yyy DI QUO "+this.delay);
341 this.run(sess, stat, subst, gst.st);
346 if (this.the_end != true) {
347 setTimeout(function(obj, sess){ obj.poll(sess); }, tout, this, sess);
350 //x alert("the_end3");
351 if (this.watchdog != null) {
352 clearTimeout(this.watchdog);
353 this.watchdog = null;
361 window.onload = function () {
362 xhr = createXMLHttpRequest();
364 sess = $("user").value;
365 window.setTimeout(poll, 0, sess);