#include <NGObjWeb/WEClientCapabilities.h>
#include <SaxObjC/SaxObjC.h>
#include <SaxObjC/XMLNamespaces.h>
+#include <DOM/DOMDocument.h>
#include <NGExtensions/NSString+Ext.h>
#include "common.h"
ui = [NSDictionary dictionaryWithObjectsAndKeys:
self, @"dispatcher",
[NSNumber numberWithInt:_status], @"http-status",
- nil];
+ nil];
return [NSException exceptionWithName:
[NSString stringWithFormat:@"HTTP%i", _status]
reason:_reason
/* DAV reports */
- (id)doREPORT:(WOContext *)_ctx {
+ id<DOMDocument> domDocument;
WORequest *rq;
- id domDocument;
+ NSString *mname;
+ id method, resultObject;
rq = [_ctx request];
reason:@"Could not parse XML of WebDAV REPORT."];
}
- /* process DOM */
+ /* first try to lookup method with fully qualified name */
+
+ mname = [NSString stringWithFormat:@"{%@}%@",
+ [[domDocument documentElement] namespaceURI],
+ [[domDocument documentElement] localName]];
+ method = [self->object lookupName:mname inContext:_ctx acquire:NO];
+
+ if (method == nil || [method isKindOfClass:[NSException class]]) {
+ /* then try to lookup by simplified name */
+ id m2;
+
+ m2 = [self->object lookupName:[[domDocument documentElement] localName]
+ inContext:_ctx acquire:NO];
+ if (m2 == nil)
+ ; /* failed */
+ else if ([m2 isKindOfClass:[NSException class]]) {
+ if (method == nil)
+ method = m2; /* use the second exceptions */
+ }
+ else {
+ method = m2;
+ mname = [[domDocument documentElement] localName];
+ }
+ }
+
+ // TODO: what I would really like to have here is a pluggable dispatcher
+ // mechanism which translates the report payload into a customized
+ // method call.
+
+ /* check for lookup errors */
+
+ if (method == nil || [method isKindOfClass:[NSException class]]) {
+ [self logWithFormat:@"did not find a method to server the REPORT"];
+ return [NSException exceptionWithHTTPStatus:501 /* not implemented */
+ reason:@"did not find the specified REPORT"];
+ }
+ else if ([method isKindOfClass:[NSException class]]) {
+ [self logWithFormat:@"failed to lookup the REPORT: %@", method];
+ return method;
+ }
+ else if (![method isCallable]) {
+ [self warnWithFormat:
+ @"object found for REPORT '%@' is not callable: %@",
+ mname, method];
+ }
+ [self debugWithFormat:@"REPORT method: %@", method];
- [self logWithFormat:@"TODO: process REPORT: %@", domDocument];
+ /* perform call */
- return [self httpException:405 /* method not allowed */
- reason:@"WebDAV reports not yet implemented."];
+ resultObject = [method callOnObject:[_ctx clientObject] inContext:_ctx];
+ if (debugOn) [self debugWithFormat:@"got REPORT result: %@", resultObject];
+ return resultObject;
}
/* CalDAV */