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.3 2006/04/13 21:14:17 jablko Exp $
23
+ * @version CVS: $Id: Server.php,v 1.4 2006/04/13 22:33:13 jablko Exp $
24
24
* @link http://pear.php.net/package/HTTP_CalDAV_Server
25
25
* @see HTTP_WebDAV_Server
26
26
*/
37
37
* @author Jack Bates <[email protected] >
38
38
* @copyright 2006 The PHP Group
39
39
* @license PHP License 3.0 http://www.php.net/license/3_0.txt
40
- * @version CVS: $Id: Server.php,v 1.3 2006/04/13 21:14:17 jablko Exp $
40
+ * @version CVS: $Id: Server.php,v 1.4 2006/04/13 22:33:13 jablko Exp $
41
41
* @link http://pear.php.net/package/HTTP_CalDAV_Server
42
42
* @see HTTP_WebDAV_Server
43
43
*/
@@ -86,177 +86,6 @@ function report_request_helper(&$options)
86
86
return true ;
87
87
}
88
88
89
- /**
90
- * REPORT response helper - format REPORT response
91
- *
92
- * @param options
93
- * @return void
94
- * @access public
95
- */
96
- function report_response_helper ($ options , $ files )
97
- {
98
- $ responses = array ();
99
-
100
- // now loop over all returned files
101
- foreach ($ files as $ file ) {
102
-
103
- // collect namespaces here
104
- $ ns_hash = array ('urn:ietf:params:xml:ns:caldav ' => 'C ' );
105
-
106
- $ response = array ();
107
-
108
- $ response ['href ' ] = $ this ->getHref ($ file ['path ' ]);
109
- if (isset ($ file ['href ' ])) {
110
- $ response ['href ' ] = $ file ['href ' ];
111
- }
112
-
113
- $ response ['propstat ' ] = array ();
114
-
115
- // nothing to do if no properties were returend
116
- if (isset ($ file ['props ' ]) && is_array ($ file ['props ' ])) {
117
-
118
- // now loop over all returned properties
119
- foreach ($ file ['props ' ] as $ prop ) {
120
- $ status = '200 OK ' ;
121
-
122
- // as a convenience feature we do not require user handlers
123
- // restrict returned properties to the requested ones
124
- // here we ignore unrequested entries
125
- switch ($ options ['props ' ]) {
126
- case 'propname ' :
127
-
128
- // only names of all existing properties were requested
129
- // so remove values
130
- unset($ prop ['value ' ]);
131
-
132
- case 'allprop ' :
133
- if (isset ($ prop ['status ' ])) {
134
- $ status = $ prop ['status ' ];
135
- }
136
-
137
- if (!isset ($ response ['propstat ' ][$ status ])) {
138
- $ response ['propstat ' ][$ status ] = array ();
139
- }
140
-
141
- $ response ['propstat ' ][$ status ][] = $ prop ;
142
- break ;
143
-
144
- default :
145
-
146
- // search property name in requested properties
147
- foreach ($ options ['props ' ] as $ reqprop ) {
148
- if ($ reqprop ['name ' ] == $ prop ['name ' ] &&
149
- $ reqprop ['ns ' ] == $ prop ['ns ' ]) {
150
- if (isset ($ prop ['status ' ])) {
151
- $ status = $ prop ['status ' ];
152
- }
153
-
154
- if (!isset ($ response ['propstat ' ][$ status ])) {
155
- $ response ['propstat ' ][$ status ] = array ();
156
- }
157
-
158
- $ response ['propstat ' ][$ status ][] = $ prop ;
159
- break (2 );
160
- }
161
- }
162
-
163
- continue (2 );
164
- }
165
-
166
- // namespace handling
167
- if (empty ($ prop ['ns ' ]) || // empty namespace
168
- $ prop ['ns ' ] == 'DAV: ' || // default namespace
169
- isset ($ ns_hash [$ prop ['ns ' ]])) { // already known
170
- continue ;
171
- }
172
-
173
- // register namespace
174
- $ ns_hash [$ prop ['ns ' ]] = 'ns ' . count ($ ns_hash );
175
- }
176
- }
177
-
178
- // also need empty entries for properties requested
179
- // but for which no values where returned
180
- if (isset ($ options ['props ' ]) && is_array ($ options ['props ' ])) {
181
-
182
- // now loop over all requested properties
183
- foreach ($ options ['props ' ] as $ reqprop ) {
184
- $ status = '404 Not Found ' ;
185
-
186
- // check if property exists in result
187
- foreach ($ file ['props ' ] as $ prop ) {
188
- if ($ reqprop ['name ' ] == $ prop ['name ' ] &&
189
- $ reqprop ['ns ' ] == $ prop ['ns ' ]) {
190
- continue (2 );
191
- }
192
- }
193
-
194
- if ($ reqprop ['name ' ] == 'lockdiscovery ' &&
195
- $ reqprop ['ns ' ] == 'DAV: ' &&
196
- method_exists ($ this , 'getLocks ' )) {
197
-
198
- $ status = '200 OK ' ;
199
- if (!isset ($ response ['propstat ' ][$ status ])) {
200
- $ response ['propstat ' ][$ status ] = array ();
201
- }
202
-
203
- $ response ['propstat ' ][$ status ][] =
204
- $ this ->mkprop ('DAV: ' , 'lockdiscovery ' ,
205
- $ this ->getLocks ($ file ['path ' ]));
206
- continue ;
207
- }
208
-
209
- if ($ reqprop ['name ' ] == 'calendar-data ' &&
210
- $ reqprop ['ns ' ] == 'urn:ietf:params:xml:ns:caldav ' &&
211
- method_exists ($ this , 'get ' )) {
212
-
213
- $ prop = $ this ->_calendarData ($ reqprop , $ file , $ options );
214
- if (isset ($ prop )) {
215
- $ status = '200 OK ' ;
216
- if (isset ($ prop ['status ' ])) {
217
- $ status = $ prop ['status ' ];
218
- }
219
- } else {
220
- $ prop = HTTP_CalDAV_Server::calDavProp (
221
- 'calendar-data ' );
222
- }
223
-
224
- if (!isset ($ response ['propstat ' ][$ status ])) {
225
- $ response ['propstat ' ][$ status ] = array ();
226
- }
227
-
228
- $ response ['propstat ' ][$ status ][] = $ prop ;
229
- continue ;
230
- }
231
-
232
- if (!isset ($ response ['propstat ' ][$ status ])) {
233
- $ response ['propstat ' ][$ status ] = array ();
234
- }
235
-
236
- // add empty value for this property
237
- $ response ['propstat ' ][$ status ][] =
238
- $ this ->mkprop ($ reqprop ['ns ' ], $ reqprop ['name ' ],
239
- null );
240
-
241
- // namespace handling
242
- if (empty ($ reqprop ['ns ' ]) || // empty namespace
243
- $ reqprop ['ns ' ] == 'DAV: ' || // default namespace
244
- isset ($ ns_hash [$ reqprop ['ns ' ]])) { // already known
245
- continue ;
246
- }
247
-
248
- // register namespace
249
- $ ns_hash [$ reqprop ['ns ' ]] = 'ns ' . count ($ ns_hash );
250
- }
251
- }
252
-
253
- $ response ['ns_hash ' ] = $ ns_hash ;
254
- $ responses [] = $ response ;
255
- }
256
-
257
- $ this ->_multistatus ($ responses );
258
- }
259
-
260
89
/**
261
90
* REPORT method wrapper
262
91
*
@@ -285,64 +114,88 @@ function report_wrapper()
285
114
}
286
115
287
116
/* Format REPORT response */
288
- $ this ->report_response_helper ($ options , $ files );
117
+
118
+ // TODO Make ns_hash a class variable so we can prettify C:
119
+ // Or make getNsName so we can return C:
120
+ $ this ->propfind_response_helper ($ options , $ files );
289
121
}
290
122
291
- function _calendarData ($ reqprop , $ file , $ options )
123
+ function getProp ($ reqprop , $ file , $ options )
292
124
{
293
- $ filters = $ options ['filters ' ];
294
-
295
- $ options = array ();
296
- $ options ['path ' ] = $ file ['path ' ];
297
-
298
- $ status = $ this ->get ($ options );
299
- if (empty ($ status )) {
300
- $ status = '403 Forbidden ' ;
125
+ // check if property exists in response
126
+ foreach ($ file ['props ' ] as $ prop ) {
127
+ if ($ reqprop ['name ' ] == $ prop ['name ' ] &&
128
+ $ reqprop ['ns ' ] == $ prop ['ns ' ]) {
129
+ return $ prop ;
130
+ }
301
131
}
302
132
303
- if ($ status !== true ) {
304
- return HTTP_CalDAV_Server::calDavProp ('calendar-data ' , null ,
305
- $ status );
133
+ if ($ reqprop ['name ' ] == 'lockdiscovery ' &&
134
+ $ reqprop ['ns ' ] == 'DAV: ' &&
135
+ method_exists ($ this , 'getLocks ' )) {
136
+ return $ this ->mkprop ('DAV: ' , 'lockdiscovery ' ,
137
+ $ this ->getLocks ($ file ['path ' ]));
306
138
}
307
139
308
- if ($ options ['mimetype ' ] != 'text/calendar ' ) {
309
- return ;
310
- }
140
+ if ($ reqprop ['name ' ] == 'calendar-data ' &&
141
+ $ reqprop ['ns ' ] == 'urn:ietf:params:xml:ns:caldav ' &&
142
+ method_exists ($ this , 'get ' )) {
143
+ $ filters = $ options ['filters ' ];
311
144
312
- if ($ options ['stream ' ]) {
313
- $ handle = $ options ['stream ' ];
314
- } else if ($ options ['data ' ]) {
315
- // What about data?
316
- } else {
317
- return ;
318
- }
145
+ $ options = array ();
146
+ $ options ['path ' ] = $ file ['path ' ];
319
147
320
- if (!($ value = HTTP_CalDAV_Server::_parseComponent ($ handle ,
321
- $ reqprop ['value ' ], $ filters ))) {
322
- return ;
148
+ $ status = $ this ->get ($ options );
149
+ if (empty ($ status )) {
150
+ $ status = '403 Forbidden ' ;
151
+ }
152
+
153
+ if ($ status !== true ) {
154
+ return $ this ->calDavProp ('calendar-data ' , null , $ status );
155
+ }
156
+
157
+ if ($ options ['mimetype ' ] != 'text/calendar ' ) {
158
+ return $ this ->calDavProp ('calendar-data ' , null , '404 Not Found ' );
159
+ }
160
+
161
+ if ($ options ['stream ' ]) {
162
+ $ handle = $ options ['stream ' ];
163
+ } else if ($ options ['data ' ]) {
164
+ // What about data?
165
+ } else {
166
+ return $ this ->calDavProp ('calendar-data ' , null , '404 Not Found ' );
167
+ }
168
+
169
+ if (!($ value = $ this ->_parseComponent ($ handle , $ reqprop ['value ' ], $ filters ))) {
170
+ return $ this ->calDavProp ('calendar-data ' , null , '404 Not Found ' );
171
+ }
172
+
173
+ return HTTP_CalDAV_Server::calDavProp ('calendar-data ' , $ value );
323
174
}
324
175
325
- return HTTP_CalDAV_Server::calDavProp ('calendar-data ' , $ value );
176
+ // incase the requested property had a value, like calendar-data
177
+ unset($ reqprop ['value ' ]);
178
+ $ reqprop ['status ' ] = '404 Not Found ' ;
179
+ return $ reqprop ;
326
180
}
327
181
328
182
function _parseComponent ($ handle , $ value =null , $ filters =null )
329
183
{
330
- $ components = array ();
184
+ $ comps = array ();
331
185
$ compValues = array ($ value );
332
186
$ compFilters = array ($ filters );
333
187
while (($ line = fgets ($ handle , 4096 )) !== false ) {
334
188
$ line = explode (': ' , trim ($ line ));
335
189
336
190
if ($ line [0 ] == 'END ' ) {
337
- if ($ line [1 ] != $ components [ key ( $ components ) ]->name ) {
191
+ if ($ line [1 ] != $ comps [ count ( $ comps ) - 1 ]->name ) {
338
192
return ;
339
193
}
340
194
341
- if (is_array ($ compFilters [key ($ compFilters )]['filters ' ])) {
342
- foreach ($ compFilters [key ($ compFilters )]['filters ' ] as $ filter ) {
343
- print $ filter ['name ' ];
195
+ if (is_array ($ compFilters [count ($ compFilters ) - 1 ]['filters ' ])) {
196
+ foreach ($ compFilters [count ($ compFilters ) - 1 ]['filters ' ] as $ filter ) {
344
197
if ($ filter ['name ' ] == 'time-range ' ) {
345
- if ($ filter ['value ' ]['start ' ] > $ components [ key ( $ components ) ]->properties ['DTEND ' ][0 ]->value || $ filter ['value ' ]['end ' ] < $ components [ key ( $ components ) ]->properties ['DTSTART ' ][0 ]->value ) {
198
+ if ($ filter ['value ' ]['start ' ] > $ comps [ count ( $ comps ) - 1 ]->properties ['DTEND ' ][0 ]->value || $ filter ['value ' ]['end ' ] < $ comps [ count ( $ comps ) - 1 ]->properties ['DTSTART ' ][0 ]->value ) {
346
199
array_pop ($ compValues );
347
200
array_pop ($ compFilters );
348
201
continue ;
@@ -353,11 +206,11 @@ function _parseComponent($handle, $value=null, $filters=null)
353
206
354
207
// If we're about to pop the root component, we ignore the rest
355
208
// of our input
356
- if (count ($ components ) == 1 ) {
357
- return array_pop ($ components );
209
+ if (count ($ comps ) == 1 ) {
210
+ return array_pop ($ comps );
358
211
}
359
212
360
- if (!$ components [ key ( $ components ) ]->add_component (array_pop ($ components ))) {
213
+ if (!$ comps [ count ( $ comps ) - 2 ]->add_component (array_pop ($ comps ))) {
361
214
return ;
362
215
}
363
216
@@ -368,11 +221,8 @@ function _parseComponent($handle, $value=null, $filters=null)
368
221
369
222
if ($ line [0 ] == 'BEGIN ' ) {
370
223
$ compName = $ line [1 ];
371
- var_dump ($ compName );
372
- var_dump ($ compValues );
373
- var_dump ($ compValues [key ($ compValues )]);
374
- if (is_array ($ compValues [key ($ compValues )]['comps ' ]) &&
375
- !isset ($ compValues [key ($ compValues )]['comps ' ][$ compName ])) {
224
+ if (is_array ($ compValues [count ($ compValues ) - 1 ]['comps ' ]) &&
225
+ !isset ($ compValues [count ($ compValues ) - 1 ]['comps ' ][$ compName ])) {
376
226
while (($ line = fgets ($ handle , 4096 )) !== false ) {
377
227
if (trim ($ line ) == "END: $ compName " ) {
378
228
continue (2 );
@@ -397,27 +247,25 @@ function _parseComponent($handle, $value=null, $filters=null)
397
247
return ;
398
248
}
399
249
400
- $ components [] = new $ className ;
401
- end ($ components );
402
- $ compValues [] = $ compValues [key ($ compValues )]['comps ' ][$ compName ];
403
- end ($ components );
404
- $ compFilters [] = $ compFilters [key ($ compFilters )]['comps ' ][$ compName ];
405
- end ($ components );
250
+ $ comps [] = new $ className ;
251
+ $ compValues [] = $ compValues [count ($ compValues ) - 1 ]['comps ' ][$ compName ];
252
+ $ compFilters [] = $ compFilters [count ($ compFilters ) - 1 ]['comps ' ][$ compName ];
406
253
continue ;
407
254
}
408
255
409
256
$ line [0 ] = explode (';= ' , $ line [0 ]);
410
257
$ propName = array_shift ($ line [0 ]);
411
- if (is_array ($ data ['props ' ]) &&
412
- !in_array ($ propName , $ data ['props ' ])) {
258
+ if (is_array ($ compValues [count ($ compValues ) - 1 ]['props ' ]) &&
259
+ !in_array ($ propName ,
260
+ $ compValues [count ($ compValues ) - 1 ]['props ' ])) {
413
261
continue ;
414
262
}
415
263
416
264
$ params = array ();
417
265
while (!empty ($ line [0 ])) {
418
266
$ params [array_shift ($ line [0 ])] = array_shift ($ line [0 ]);
419
267
}
420
- $ components [ key ( $ components ) ]->add_property ($ propName , $ line [1 ], $ params );
268
+ $ comps [ count ( $ comps ) - 1 ]->add_property ($ propName , $ line [1 ], $ params );
421
269
}
422
270
}
423
271
0 commit comments