simplify auth mechanism a bit more
[platal.git] / include / xorg.varstream.inc.php
1 <?php
2 /***************************************************************************
3 * Copyright (C) 2003-2006 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
18 * Foundation, Inc., *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
21
22 // {{{ class VarStream
23
24 class VarStream
25 {
26 // {{{ properties
27
28 // Stream handler to read from global variables
29 var $varname;
30 var $position;
31
32 // }}}
33 // {{{ stream_open
34
35 function stream_open($path, $mode, $options, &$opened_path)
36 {
37 $url = parse_url($path);
38 $this->varname = $url['host'];
39 $this->position = 0;
40 if (!isset($GLOBALS[$this->varname]))
41 {
42 trigger_error('Global variable '.$this->varname.' does not exist', E_USER_WARNING);
43 return false;
44 }
45 return true;
46 }
47
48 // }}}
49 // {{{ stream_close
50
51 function stream_close()
52 {
53 }
54
55 // }}}
56 // {{{ stream_read
57
58 function stream_read($count)
59 {
60 $ret = substr($GLOBALS[$this->varname], $this->position, $count);
61 $this->position += strlen($ret);
62 return $ret;
63 }
64
65 // }}}
66 // {{{ stream_write
67
68 function stream_write($data)
69 {
70 $len = strlen($data);
71 if ($len > $this->position + strlen($GLOBALS[$this->varname])) {
72 str_pad($GLOBALS[$this->varname], $len);
73 }
74
75 $GLOBALS[$this->varname] = substr_replace($GLOBALS[$this->varname], $data, $this->position, $len);
76 $this->position += $len;
77 }
78
79 // }}}
80 // {{{ stream_eof
81
82 function stream_eof()
83 {
84 return $this->position >= strlen($GLOBALS[$this->varname]);
85 }
86
87 // }}}
88 // {{{ stream_tell
89
90 function stream_tell()
91 {
92 return $this->position;
93 }
94
95 // }}}
96 // {{{ stream_seek
97
98 function stream_seek($offs, $whence)
99 {
100 switch ($whence) {
101 case SEEK_SET:
102 $final = $offs;
103 break;
104
105 case SEEK_CUR:
106 $final += $offs;
107 break;
108
109 case SEEK_END:
110 $final = strlen($GLOBALS[$this->varname]) + $offs;
111 break;
112 }
113
114 if ($final < 0) {
115 return -1;
116 }
117 $this->position = $final;
118 return 0;
119 }
120
121 // }}}
122 // {{{ stream_flush
123
124 function stream_flush()
125 {
126 }
127
128 // }}}
129 }
130
131 // }}}
132
133 stream_wrapper_register('var','VarStream');
134
135 // vim:set et sw=4 sts=4 sws=4:
136 ?>