first page from index.php with sac-a-push technology (no authentication part)
[brisk.git] / web / spush / sac-a-push.phh
1 <?php
2
3 function spu_process_info($stream_info, $method, &$header, &$get, &$post, &$cookie)
4 {
5     $check_post = FALSE;
6     $header = array();
7     $get = array();
8     $post = array();
9     foreach(preg_split("/(\r?\n)/", $stream_info) as $line) {
10         // printf("LINE: [%s]\n", $line);
11         if ($check_post) {
12             if (!isset($header['The-Request'])) {
13                 return FALSE;
14             }
15             $req = explode(" ", $header['The-Request']);
16             $method = $req[0];
17             $path =   $req[1];
18
19             if (isset($header['Cookie'])) {
20                 $cookies = explode(";", $header['Cookie']);
21                 for ($i = 0 ; $i < count($cookies) ; $i++) {
22                     $nameval = explode("=", trim($cookies[$i]));
23                     if (count($nameval) != 2) {
24                         printf("WARNING: malformat cookie element [%s]\n", $cookies[$i]);
25                         continue;
26                     }
27                     $cookie[$nameval[0]] = urldecode($nameval[1]);
28                 }
29             }
30             // GET params management
31             $get_vars = explode('?', $req[1], 2);
32             if (count($get_vars) > 1) {
33                 $a = explode('&', $get_vars[1]);
34                 printf("A COUNT: [%s] %d\n", $a[0], count($a));
35                 for ($i = 0 ; $i < count($a) ; $i++) {
36                     $b = explode('=', $a[$i]);
37                     $get[$b[0]] = urldecode($b[1]);
38                 }
39             }
40             // POST params management
41             if ($req[0] == 'POST') {
42                 if ($header['Content-Type'] != 'application/x-www-form-urlencoded' 
43                     || !isset($header['Content-Length'])) {
44                     return FALSE;
45                 }
46                 $post_len = mb_strlen($line, "latin1");
47                 $a = explode('&', $line);
48                 for ($i = 0 ; $i < count($a) ; $i++) {
49                     $b = explode('=', $a[$i]);
50                     $post[$b[0]] = urldecode($b[1]);
51                 }
52                 printf("INFO: postlen: %d\n", $post_len);
53             }
54             break;
55         }
56         if ($line == "") {
57             $check_post = TRUE;
58             continue;
59         }
60         $split = explode(":", $line, 2);
61         $header[$split[0]] = $split[1];        
62     }
63     return $path;
64 }
65
66 ?>