X-Git-Url: https://mop.ddnsfree.com/gitweb/?a=blobdiff_plain;f=web%2FObj%2Fsac-a-push.phh;h=5a525bb52e1bc551ce43744b599b979e3724c57d;hb=f341c32413c83788cf6cf23fe911c401c2f9adad;hp=c71cdf10455fdc4e14db4178496846784658fea6;hpb=9f6eaf300267272f769759b716158846ce11deac;p=brisk.git diff --git a/web/Obj/sac-a-push.phh b/web/Obj/sac-a-push.phh index c71cdf1..5a525bb 100644 --- a/web/Obj/sac-a-push.phh +++ b/web/Obj/sac-a-push.phh @@ -126,14 +126,24 @@ function spu_process_info($stream_info, &$method, &$header, &$get, &$post, &$coo $method = $req[0]; if (isset($header['Cookie'])) { - $cookies = explode(";", $header['Cookie']); + + // LINE: [Cookie:sess=50e053a9511ef; CO_splashdate4=1356420646; CO_list=all; table_idx=7; table_token=510d494986925; lang=it; CO_bin5_pref_ring_endauct=false; CO_splashdate5=1358372822; CO_splashdate1=1363203374; CO_splashdate2=1363374826; __utma=43654517.209888411.1356605271.1356605271.1356605271.1; __utmz=43654517.1356605271.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)] + + $cookies = explode("; ", $header['Cookie']); for ($i = 0 ; $i < count($cookies) ; $i++) { - $nameval = explode("=", trim($cookies[$i])); - if (count($nameval) != 2) { - printf("WARNING: malformat cookie element [%s]\n", $cookies[$i]); + $name = mb_strstr($cookies[$i], "=", TRUE, 'UTF-8'); + if ($name == FALSE) { + if (mb_strlen($cookies[$i]) > 0) { + $cookie[$cookies[$i]] = ""; + } + else { + printf("WARNING: malformat cookie element [%s]\n", $cookies[$i]); + } continue; } - $cookie[$nameval[0]] = urldecode($nameval[1]); + + $value = mb_substr($cookies[$i], mb_strlen($name)+1, 10140, 'UTF-8'); + $cookie[$name] = urldecode($value); } } // GET params management @@ -178,7 +188,8 @@ function spu_process_info($stream_info, &$method, &$header, &$get, &$post, &$coo continue; } $split = explode(":", $line, 2); - $header[$split[0]] = $split[1]; + $hea_id = trim(mb_convert_case($split[0], MB_CASE_TITLE, 'UTF-8')); + $header[$hea_id] = $split[1]; } return $path; } @@ -210,6 +221,14 @@ function headers_render($header, $len) } else if (isset($header['HTTP-Response'])) { $s = sprintf("HTTP/1.1 %s\r\n", $header['HTTP-Response']); + foreach($header as $key => $value) { + if (strtolower($key) == "http-response") + continue; + $s .= sprintf("%s: %s\r\n", $key, $value); + } + if ($len >= 0) { + $s .= sprintf("Content-Length: %ld\r\n", $len); + } } else { $s = "HTTP/1.1 200 OK\r\n"; @@ -257,25 +276,6 @@ register_shutdown_function('shutta'); * MAIN */ -function chunked_content($zls, $content) -{ - if ($zls) { - $cont_comp = $zls->compress_chunk($content); - } - else { - $cont_comp = $content; - } - $cont_comp_l = mb_strlen($cont_comp, "ASCII"); - printf("CHUNK: [%s]\n", $content); - - return (sprintf("%X\r\n", $cont_comp_l).$cont_comp."\r\n"); -} - -function chunked_fini() -{ - return sprintf("0\r\n"); -} - function get_encoding($header) { $enc = "plain"; @@ -611,6 +611,7 @@ class Sac_a_push { GLOBAL $G_splash_w, $G_topbanner, $G_with_donors, $G_with_poll; GLOBAL $G_with_sidebanner, $G_with_sidebanner2, $G_with_splash; GLOBAL $G_with_topbanner; + GLOBAL $G_tos_vers, $G_tos_fname, $G_tos_dtsoft, $G_tos_dthard, $G_tos_idx, $G_doc_path; if ($this->main_loop) { return (FALSE); @@ -637,7 +638,7 @@ class Sac_a_push { } $write = NULL; $except = NULL; - $num_changed_sockets = @stream_select($read, $write, $except, 5, 500000); + $num_changed_sockets = @stream_select($read, $write, $except, 0, 500000); if ($num_changed_sockets == 0) { printf(" no data in 5 secs, splash [%d]\n", $G_with_splash); @@ -709,7 +710,7 @@ class Sac_a_push { if ($buf == FALSE || mb_strlen($buf, "ASCII") == 0) { // close socket case if ($buf == FALSE) { - printf("ERROR READING\n"); + printf("INFO: read return false\n"); } if ($sock === $this->list) { printf("Arrivati %d bytes da list\n", mb_strlen($buf, "ASCII")); @@ -724,6 +725,10 @@ class Sac_a_push { if (isset($this->s2u[$id])) { // $user_a[$s2u[$id]]->disable(); if ($this->s2u[$id]->rd_socket_get() != NULL) { + // try to send close frame (for websocket) + $clo = $this->s2u[$id]->stream_close(); + $clo_l = mb_strlen($clo, "ASCII"); + @fwrite($sock, $clo, $clo_l); $this->s2u[$id]->rd_socket_set(NULL); } unset($this->s2u[$id]); @@ -752,7 +757,7 @@ class Sac_a_push { global_dump(); } - else if ($line == "shutdown") { + else if ($line == "shutdown" || $line == "sd") { if ($this->app->dump_data()) { return(0); } @@ -849,15 +854,15 @@ class Sac_a_push { $content = $user->stream_keepalive(FALSE); } if ($content != "") { - $response = chunked_content($user->rd_zls_get(), $content); + $response = $user->chunked_content($content); } } if ($response != "") { // echo "SPIA: [".substr($response, 0, 60)."...]\n"; - echo "SPIA: [".$response."]\n"; + // echo "SPIA: [".$response."]\n"; $response_l = mb_strlen($response, "ASCII"); - $wret = @fwrite($sock, $response); + $wret = @fwrite($sock, $response, $response_l); if ($wret < $response_l) { printf("TROUBLE WITH FWRITE: %d\n", $wret); $user->rd_cache_set(mb_substr($response, $wret, $response_l - $wret, "ASCII")); @@ -876,6 +881,9 @@ class Sac_a_push { } unset($this->socks[$id]); unset($this->s2u[$id]); + $clo = $user->stream_close(); + $clo_l = mb_strlen($clo, "ASCII"); + @fwrite($sock, $clo, $clo_l); fclose($sock); printf("CLOSE ON LOOP\n"); }