8dfea848462c93da151ac5acf7b16ae423597e17
[brisk.git] / web / spush / sac-a-push.phh
1 <?php
2
3 function spu_process_info($stream_info, &$header, &$get, &$post)
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             // GET params management
18             $get_vars = explode('?', $req[1], 2);
19             if (count($get_vars) > 1) {
20                 $a = explode('&', $get_vars[1]);
21                 printf("A COUNT: [%s] %d\n", $a[0], count($a));
22                 for ($i = 0 ; $i < count($a) ; $i++) {
23                     $b = explode('=', $a[$i]);
24                     $get[$b[0]] = urldecode($b[1]);
25                 }
26             }
27             // POST params management
28             if ($req[0] == 'POST') {
29                 if ($header['Content-Type'] != 'application/x-www-form-urlencoded' 
30                     || !isset($header['Content-Length'])) {
31                     return FALSE;
32                 }
33                 $post_len = mb_strlen($line, "latin1");
34                 $a = explode('&', $line);
35                 for ($i = 0 ; $i < count($a) ; $i++) {
36                     $b = explode('=', $a[$i]);
37                     $post[$b[0]] = urldecode($b[1]);
38                 }
39                 printf("INFO: postlen: %d\n", $post_len);
40             }
41             break;
42         }
43         if ($line == "") {
44             $check_post = TRUE;
45             continue;
46         }
47         $split = explode(":", $line, 2);
48         $header[$split[0]] = $split[1];        
49     }
50     return $method;
51 }
52
53 ?>