20
20
* @author Jack Bates <[email protected] >
21
21
* @copyright 2006 The PHP Group
22
22
* @license PHP License 3.0 http://www.php.net/license/3_0.txt
23
- * @version CVS: $Id: Server.php,v 1.4 2006/04/13 22:33:13 jablko Exp $
23
+ * @version CVS: $Id: Server.php,v 1.5 2006/04/18 03: 22:12 jablko Exp $
24
24
* @link http://pear.php.net/package/HTTP_CalDAV_Server
25
25
* @see HTTP_WebDAV_Server
26
26
*/
27
27
28
28
require_once 'Tools/ReportParser.php ' ;
29
+ require_once 'Tools/ICalendarParser.php ' ;
29
30
30
31
/**
31
32
* CalDav Server class
37
38
* @author Jack Bates <[email protected] >
38
39
* @copyright 2006 The PHP Group
39
40
* @license PHP License 3.0 http://www.php.net/license/3_0.txt
40
- * @version CVS: $Id: Server.php,v 1.4 2006/04/13 22:33:13 jablko Exp $
41
+ * @version CVS: $Id: Server.php,v 1.5 2006/04/18 03: 22:12 jablko Exp $
41
42
* @link http://pear.php.net/package/HTTP_CalDAV_Server
42
43
* @see HTTP_WebDAV_Server
43
44
*/
@@ -69,7 +70,9 @@ function report_request_helper(&$options)
69
70
$ options = array ();
70
71
$ options ['path ' ] = $ this ->path ;
71
72
72
- $ options ['depth ' ] = 'infinity ' ;
73
+ /* The request MAY include a Depth header. If no Depth header is
74
+ included, Depth:0 is assumed. */
75
+ $ options ['depth ' ] = 0 ;
73
76
if (isset ($ _SERVER ['HTTP_DEPTH ' ])) {
74
77
$ options ['depth ' ] = $ _SERVER ['HTTP_DEPTH ' ];
75
78
}
@@ -147,30 +150,36 @@ function getProp($reqprop, $file, $options)
147
150
148
151
$ status = $ this ->get ($ options );
149
152
if (empty ($ status )) {
150
- $ status = '403 Forbidden ' ;
153
+ $ status = '404 Not Found ' ;
151
154
}
152
155
153
156
if ($ status !== true ) {
154
157
return $ this ->calDavProp ('calendar-data ' , null , $ status );
155
158
}
156
159
157
160
if ($ options ['mimetype ' ] != 'text/calendar ' ) {
158
- return $ this ->calDavProp ('calendar-data ' , null , '404 Not Found ' );
161
+ return $ this ->calDavProp ('calendar-data ' , null ,
162
+ '404 Not Found ' );
159
163
}
160
164
161
165
if ($ options ['stream ' ]) {
162
166
$ handle = $ options ['stream ' ];
163
167
} else if ($ options ['data ' ]) {
164
168
// What about data?
165
169
} else {
166
- return $ this ->calDavProp ('calendar-data ' , null , '404 Not Found ' );
170
+ return $ this ->calDavProp ('calendar-data ' , null ,
171
+ '404 Not Found ' );
167
172
}
168
173
169
- if (!($ value = $ this ->_parseComponent ($ handle , $ reqprop ['value ' ], $ filters ))) {
170
- return $ this ->calDavProp ('calendar-data ' , null , '404 Not Found ' );
174
+ $ parser = new ICalendarParser ($ handle , null , null ,
175
+ $ reqprop ['value ' ], $ filters );
176
+ if (!$ parser ->success ) {
177
+ return $ this ->calDavProp ('calendar-data ' , null ,
178
+ '404 Not Found ' );
171
179
}
172
180
173
- return HTTP_CalDAV_Server::calDavProp ('calendar-data ' , $ value );
181
+ return HTTP_CalDAV_Server::calDavProp ('calendar-data ' ,
182
+ $ parser ->comps [count ($ parser ->comps ) - 1 ]);
174
183
}
175
184
176
185
// incase the requested property had a value, like calendar-data
@@ -179,96 +188,6 @@ function getProp($reqprop, $file, $options)
179
188
return $ reqprop ;
180
189
}
181
190
182
- function _parseComponent ($ handle , $ value =null , $ filters =null )
183
- {
184
- $ comps = array ();
185
- $ compValues = array ($ value );
186
- $ compFilters = array ($ filters );
187
- while (($ line = fgets ($ handle , 4096 )) !== false ) {
188
- $ line = explode (': ' , trim ($ line ));
189
-
190
- if ($ line [0 ] == 'END ' ) {
191
- if ($ line [1 ] != $ comps [count ($ comps ) - 1 ]->name ) {
192
- return ;
193
- }
194
-
195
- if (is_array ($ compFilters [count ($ compFilters ) - 1 ]['filters ' ])) {
196
- foreach ($ compFilters [count ($ compFilters ) - 1 ]['filters ' ] as $ filter ) {
197
- if ($ filter ['name ' ] == 'time-range ' ) {
198
- if ($ filter ['value ' ]['start ' ] > $ comps [count ($ comps ) - 1 ]->properties ['DTEND ' ][0 ]->value || $ filter ['value ' ]['end ' ] < $ comps [count ($ comps ) - 1 ]->properties ['DTSTART ' ][0 ]->value ) {
199
- array_pop ($ compValues );
200
- array_pop ($ compFilters );
201
- continue ;
202
- }
203
- }
204
- }
205
- }
206
-
207
- // If we're about to pop the root component, we ignore the rest
208
- // of our input
209
- if (count ($ comps ) == 1 ) {
210
- return array_pop ($ comps );
211
- }
212
-
213
- if (!$ comps [count ($ comps ) - 2 ]->add_component (array_pop ($ comps ))) {
214
- return ;
215
- }
216
-
217
- array_pop ($ compValues );
218
- array_pop ($ compFilters );
219
- continue ;
220
- }
221
-
222
- if ($ line [0 ] == 'BEGIN ' ) {
223
- $ compName = $ line [1 ];
224
- if (is_array ($ compValues [count ($ compValues ) - 1 ]['comps ' ]) &&
225
- !isset ($ compValues [count ($ compValues ) - 1 ]['comps ' ][$ compName ])) {
226
- while (($ line = fgets ($ handle , 4096 )) !== false ) {
227
- if (trim ($ line ) == "END: $ compName " ) {
228
- continue (2 );
229
- }
230
- }
231
-
232
- return ;
233
- }
234
-
235
- $ className = 'iCalendar_ ' . ltrim (strtolower ($ compName ), 'v ' );
236
- if ($ line [1 ] == 'VCALENDAR ' ) {
237
- $ className = 'iCalendar ' ;
238
- }
239
-
240
- if (!class_exists ($ className )) {
241
- while (($ line = fgets ($ handle , 4096 )) !== false ) {
242
- if (trim ($ line ) == "END: $ compName " ) {
243
- continue (2 );
244
- }
245
- }
246
-
247
- return ;
248
- }
249
-
250
- $ comps [] = new $ className ;
251
- $ compValues [] = $ compValues [count ($ compValues ) - 1 ]['comps ' ][$ compName ];
252
- $ compFilters [] = $ compFilters [count ($ compFilters ) - 1 ]['comps ' ][$ compName ];
253
- continue ;
254
- }
255
-
256
- $ line [0 ] = explode (';= ' , $ line [0 ]);
257
- $ propName = array_shift ($ line [0 ]);
258
- if (is_array ($ compValues [count ($ compValues ) - 1 ]['props ' ]) &&
259
- !in_array ($ propName ,
260
- $ compValues [count ($ compValues ) - 1 ]['props ' ])) {
261
- continue ;
262
- }
263
-
264
- $ params = array ();
265
- while (!empty ($ line [0 ])) {
266
- $ params [array_shift ($ line [0 ])] = array_shift ($ line [0 ]);
267
- }
268
- $ comps [count ($ comps ) - 1 ]->add_property ($ propName , $ line [1 ], $ params );
269
- }
270
- }
271
-
272
191
function _multistatus ($ responses )
273
192
{
274
193
// now we generate the response header...
0 commit comments