]> err.no Git - scalable-opengroupware.org/blobdiff - SoObjects/SOGo/SOGoObject.m
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1292 d1b88da0-ebda-0310...
[scalable-opengroupware.org] / SoObjects / SOGo / SOGoObject.m
index 33d660174584446769bbd4ff5faf338c7221eb08..8bb510661e65ee54f916f9fd4300633634df1c5b 100644 (file)
        Please use gnustep-base instead.
 #endif
 
+#import <unistd.h>
+
+#import <Foundation/NSBundle.h>
 #import <Foundation/NSClassDescription.h>
 #import <Foundation/NSString.h>
 #import <Foundation/NSUserDefaults.h>
 #import <Foundation/NSURL.h>
 #import <Foundation/NSValue.h>
 
+#import <NGObjWeb/SoClass.h>
 #import <NGObjWeb/SoClassSecurityInfo.h>
 #import <NGObjWeb/SoObject+SoDAV.h>
 #import <NGObjWeb/WEClientCapabilities.h>
 #import <NGObjWeb/WOApplication.h>
 #import <NGObjWeb/WOContext.h>
+#import <NGObjWeb/WOResourceManager.h>
 #import <NGObjWeb/WOResponse.h>
 #import <NGObjWeb/WORequest.h>
 #import <NGObjWeb/WORequest+So.h>
 #import <NGObjWeb/NSException+HTTP.h>
 #import <NGExtensions/NSObject+Logs.h>
 #import <NGExtensions/NSString+misc.h>
+#import <DOM/DOMProtocols.h>
 #import <NGCards/NSDictionary+NGCards.h>
 #import <UI/SOGoUI/SOGoACLAdvisory.h>
 
 #import "SOGoPermissions.h"
 #import "SOGoUser.h"
-#import "SOGoAuthenticator.h"
+#import "SOGoDAVAuthenticator.h"
 #import "SOGoUserFolder.h"
 
 #import "SOGoDAVRendererTypes.h"
 
 #import "NSArray+Utilities.h"
+#import "NSCalendarDate+SOGo.h"
+#import "NSDictionary+Utilities.h"
 #import "NSString+Utilities.h"
 
 #import "SOGoObject.h"
@@ -167,10 +175,10 @@ static BOOL kontactGroupDAV = YES;
 //   SoClass security declarations
   
 //   require View permission to access the root (bound to authenticated ...)
-  [[self soClassSecurityInfo] declareObjectProtected: SoPerm_View];
+//   [[self soClassSecurityInfo] declareObjectProtected: SoPerm_View];
 
 //   to allow public access to all contained objects (subkeys)
-  [[self soClassSecurityInfo] setDefaultAccess: @"allow"];
+//   [[self soClassSecurityInfo] setDefaultAccess: @"allow"];
   
 //   /* require Authenticated role for View and WebDAV */
 //   [[self soClassSecurityInfo] declareRole: SoRole_Owner
@@ -179,6 +187,35 @@ static BOOL kontactGroupDAV = YES;
 //                               asDefaultForPermission: SoPerm_WebDAVAccess];
 }
 
++ (NSString *) globallyUniqueObjectId
+{
+  /*
+    4C08AE1A-A808-11D8-AC5A-000393BBAFF6
+    SOGo-Web-28273-18283-288182
+    printf( "%x", *(int *) &f);
+  */
+  static int pid = 0;
+  static int sequence = 0;
+  static float rndm = 0;
+  float f;
+
+  if (pid == 0)
+    { /* break if we fork ;-) */
+      pid = getpid();
+      rndm = random();
+    }
+  sequence++;
+  f = [[NSDate date] timeIntervalSince1970];
+
+  return [NSString stringWithFormat:@"%0X-%0X-%0X-%0X",
+                  pid, (int) f, sequence++, random];
+}
+
+- (NSString *) globallyUniqueObjectId
+{
+  return [[self class] globallyUniqueObjectId];
+}
+
 + (void) _fillDictionary: (NSMutableDictionary *) dictionary
           withDAVMethods: (NSString *) firstMethod, ...
 {
@@ -268,13 +305,13 @@ static BOOL kontactGroupDAV = YES;
 
 - (SOGoDAVSet *) davCurrentUserPrivilegeSet
 {
-  SOGoAuthenticator *sAuth;
+  SOGoDAVAuthenticator *sAuth;
   SoUser *user;
   NSArray *roles;
   SoClassSecurityInfo *sInfo;
   NSArray *davPermissions;
 
-  sAuth = [SOGoAuthenticator sharedSOGoAuthenticator];
+  sAuth = [SOGoDAVAuthenticator sharedSOGoDAVAuthenticator];
   user = [sAuth userInContext: context];
   roles = [user rolesForObject: self inContext: context];
   sInfo = [[self class] soClassSecurityInfo];
@@ -447,6 +484,33 @@ static BOOL kontactGroupDAV = YES;
   return container;
 }
 
+- (NSArray *) pathArrayToSOGoObject
+{
+  NSMutableArray *realPathArray;
+  NSString *objectName;
+  NSArray *objectDescription;
+
+  realPathArray
+    = [NSMutableArray arrayWithArray: [self pathArrayToSoObject]];
+  if ([realPathArray count] > 2)
+    {
+      objectName = [realPathArray objectAtIndex: 2];
+      if ([objectName isKindOfClass: [NSString class]])
+       {
+         objectDescription = [objectName componentsSeparatedByString: @"_"];
+         if ([objectDescription count] > 1)
+           {
+             [realPathArray replaceObjectAtIndex: 0
+                            withObject: [objectDescription objectAtIndex: 0]];
+             [realPathArray replaceObjectAtIndex: 2
+                            withObject: [objectDescription objectAtIndex: 1]];
+           }
+       }
+    }
+
+  return realPathArray;
+}
+
 /* ownership */
 
 - (void) setOwner: (NSString *) newOwner
@@ -491,16 +555,31 @@ static BOOL kontactGroupDAV = YES;
   return ma;
 }
 
+- (id) lookupName: (NSString *) lookupName
+        inContext: (id) localContext
+          acquire: (BOOL) acquire
+{
+  id obj;
+
+  obj = [[self soClass] lookupKey: lookupName inContext: localContext];
+  if (obj)
+    [obj bindToObject: self inContext: localContext];
+
+  return obj;
+}
+
 /* looking up shared objects */
 
-- (SOGoUserFolder *)lookupUserFolder {
+- (SOGoUserFolder *) lookupUserFolder
+{
   if (![container respondsToSelector:_cmd])
     return nil;
   
   return [container lookupUserFolder];
 }
 
-- (SOGoGroupsFolder *)lookupGroupsFolder {
+- (SOGoGroupsFolder *) lookupGroupsFolder
+{
   return [[self lookupUserFolder] lookupGroupsFolder];
 }
 
@@ -551,6 +630,11 @@ static BOOL kontactGroupDAV = YES;
   return @"text/plain";
 }
 
+- (NSString *) davLastModified
+{
+  return [[NSCalendarDate date] rfc822DateString];
+}
+
 - (WOResponse *) _webDAVResponse: (WOContext *) localContext
 {
   WOResponse *response;
@@ -569,6 +653,42 @@ static BOOL kontactGroupDAV = YES;
   return response;
 }
 
+- (NSString *) _parseXMLCommand: (id <DOMDocument>) document
+{
+  NSString *command;
+
+  command = [[document firstChild] nodeName];
+
+  return [NSString stringWithFormat: @"%@:", command];
+}
+
+- (id) POSTAction: (id) localContext
+{
+  id obj;
+  NSString *cType, *command;
+  id <DOMDocument> document;
+  SEL commandSel;
+  WORequest *rq;
+
+  obj = nil;
+
+  rq = [localContext request];
+  if ([rq isSoWebDAVRequest])
+    {
+      cType = [rq headerForKey: @"content-type"];
+      if ([cType isEqualToString: @"application/xml"])
+       {
+         document = [rq contentAsDOMDocument];
+         command = [[self _parseXMLCommand: document] davMethodToObjC];
+         commandSel = NSSelectorFromString (command);
+         if ([self respondsToSelector: commandSel])
+           obj = [self performSelector: commandSel withObject: localContext];
+       }
+    }
+
+  return obj;
+}
+
 - (id) GETAction: (id) localContext
 {
   // TODO: I guess this should really be done by SOPE (redirect to
@@ -753,6 +873,12 @@ static BOOL kontactGroupDAV = YES;
 
 /* acls */
 
+/* roles required to obtain the "authorized subscriber" role */
+- (NSArray *) subscriptionRoles
+{
+  return [container subscriptionRoles];
+}
+
 - (NSArray *) aclUsers
 {
   [self subclassResponsibility: _cmd];
@@ -830,9 +956,9 @@ static BOOL kontactGroupDAV = YES;
                                                    @"/"]];
   if ([baseURL hasPrefix: @"http"])
     {
-      [path removeObjectAtIndex: 2];
       [path removeObjectAtIndex: 1];
       [path removeObjectAtIndex: 0];
+      [path replaceObjectAtIndex: 0 withObject: @""];
     }
   urlMethod = [path objectAtIndex: 2];
   if (![urlMethod isEqualToString: expected])
@@ -905,6 +1031,36 @@ static BOOL kontactGroupDAV = YES;
   return nil;
 }
 
+- (NSString *) labelForKey: (NSString *) key
+{
+  NSString *userLanguage, *label;
+  NSArray *paths;
+  NSBundle *bundle;
+  NSDictionary *strings;
+
+  bundle = [NSBundle bundleForClass: [self class]];
+  if (!bundle)
+    bundle = [NSBundle mainBundle];
+
+  userLanguage = [[context activeUser] language];
+  paths = [bundle pathsForResourcesOfType: @"strings"
+                 inDirectory: [NSString stringWithFormat: @"%@.lproj",
+                                        userLanguage]
+                 forLocalization: userLanguage];
+  if ([paths count] > 0)
+    {
+      strings = [NSDictionary
+                 dictionaryFromStringsFile: [paths objectAtIndex: 0]];
+      label = [strings objectForKey: key];
+      if (!label)
+       label = key;
+    }
+  else
+    label = key;
+  
+  return label;
+}
+
 /* description */
 
 - (void)appendAttributesToDescription:(NSMutableString *)_ms {
@@ -926,4 +1082,11 @@ static BOOL kontactGroupDAV = YES;
   return ms;
 }
 
+- (NSString *) loggingPrefix
+{
+  return [NSString stringWithFormat:@"<0x%08X[%@]:%@>",
+                  self, NSStringFromClass([self class]),
+                  [self nameInContainer]];
+}
+
 @end /* SOGoObject */