2006-06-15 21:34:10 +02:00
|
|
|
/*
|
|
|
|
Copyright (C) 2004-2005 SKYRIX Software AG
|
|
|
|
|
|
|
|
This file is part of OpenGroupware.org.
|
|
|
|
|
|
|
|
OGo is free software; you can redistribute it and/or modify it under
|
|
|
|
the terms of the GNU Lesser General Public License as published by the
|
|
|
|
Free Software Foundation; either version 2, or (at your option) any
|
|
|
|
later version.
|
|
|
|
|
|
|
|
OGo is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
|
|
|
License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with OGo; see the file COPYING. If not, write to the
|
|
|
|
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
|
|
|
|
02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2007-08-07 20:37:31 +02:00
|
|
|
#import <Foundation/NSCalendarDate.h>
|
2008-07-04 18:06:09 +02:00
|
|
|
#import <Foundation/NSDictionary.h>
|
2007-08-07 20:37:31 +02:00
|
|
|
#import <Foundation/NSEnumerator.h>
|
2008-03-18 18:26:34 +01:00
|
|
|
#import <Foundation/NSURL.h>
|
2007-11-09 00:18:52 +01:00
|
|
|
#import <Foundation/NSUserDefaults.h>
|
2007-08-07 20:37:31 +02:00
|
|
|
#import <Foundation/NSValue.h>
|
|
|
|
|
|
|
|
#import <NGObjWeb/NSException+HTTP.h>
|
|
|
|
#import <NGObjWeb/SoObject+SoDAV.h>
|
2007-12-06 23:54:01 +01:00
|
|
|
#import <NGObjWeb/SoSecurityManager.h>
|
2007-08-07 20:37:31 +02:00
|
|
|
#import <NGObjWeb/WOContext+SoObjects.h>
|
2007-02-09 22:21:35 +01:00
|
|
|
#import <NGObjWeb/WOMessage.h>
|
2007-08-07 20:37:31 +02:00
|
|
|
#import <NGObjWeb/WORequest.h>
|
|
|
|
#import <NGObjWeb/WOResponse.h>
|
|
|
|
#import <NGExtensions/NGLoggerManager.h>
|
|
|
|
#import <NGExtensions/NSString+misc.h>
|
|
|
|
#import <GDLContentStore/GCSFolder.h>
|
2008-05-16 17:52:19 +02:00
|
|
|
#import <DOM/DOMNode.h>
|
2007-08-07 20:37:31 +02:00
|
|
|
#import <DOM/DOMProtocols.h>
|
2008-06-30 20:52:20 +02:00
|
|
|
#import <EOControl/EOFetchSpecification.h>
|
2007-08-07 20:37:31 +02:00
|
|
|
#import <EOControl/EOQualifier.h>
|
2008-06-30 20:52:20 +02:00
|
|
|
#import <EOControl/EOSortOrdering.h>
|
2007-11-26 18:40:44 +01:00
|
|
|
#import <NGCards/iCalCalendar.h>
|
2008-06-30 20:52:20 +02:00
|
|
|
#import <NGCards/iCalFreeBusy.h>
|
2007-08-07 20:37:31 +02:00
|
|
|
#import <NGCards/iCalDateTime.h>
|
|
|
|
#import <NGCards/iCalPerson.h>
|
|
|
|
#import <NGCards/iCalRecurrenceCalculator.h>
|
|
|
|
#import <NGCards/NSString+NGCards.h>
|
2006-10-11 20:48:25 +02:00
|
|
|
#import <NGExtensions/NGCalendarDateRange.h>
|
2007-08-07 20:37:31 +02:00
|
|
|
#import <NGExtensions/NSNull+misc.h>
|
|
|
|
#import <NGExtensions/NSObject+Logs.h>
|
2007-03-10 00:10:43 +01:00
|
|
|
#import <SaxObjC/XMLNamespaces.h>
|
2006-10-11 20:48:25 +02:00
|
|
|
|
2007-02-09 22:21:35 +01:00
|
|
|
// #import <NGObjWeb/SoClassSecurityInfo.h>
|
2008-05-03 01:08:15 +02:00
|
|
|
#import <SOGo/NSArray+Utilities.h>
|
|
|
|
#import <SOGo/NSObject+DAV.h>
|
|
|
|
#import <SOGo/NSString+Utilities.h>
|
2008-01-16 19:57:58 +01:00
|
|
|
#import <SOGo/SOGoCache.h>
|
2008-05-03 01:08:15 +02:00
|
|
|
// #import <SOGo/SOGoCustomGroupFolder.h>
|
2007-05-09 20:25:51 +02:00
|
|
|
#import <SOGo/LDAPUserManager.h>
|
2008-07-12 00:28:12 +02:00
|
|
|
#import <SOGo/NSDictionary+Utilities.h>
|
2006-12-14 22:20:13 +01:00
|
|
|
#import <SOGo/SOGoPermissions.h>
|
2007-03-07 22:27:19 +01:00
|
|
|
#import <SOGo/SOGoUser.h>
|
2008-06-30 20:52:20 +02:00
|
|
|
#import <SOGo/SOGoUserFolder.h>
|
2008-05-03 01:08:15 +02:00
|
|
|
#import <SOGo/SOGoWebDAVAclManager.h>
|
2006-11-02 22:53:27 +01:00
|
|
|
|
2008-07-12 00:28:12 +02:00
|
|
|
#import "iCalEntityObject+SOGo.h"
|
2006-09-27 00:27:34 +02:00
|
|
|
#import "SOGoAppointmentObject.h"
|
2007-11-07 16:58:43 +01:00
|
|
|
#import "SOGoAppointmentFolders.h"
|
2008-06-30 20:52:20 +02:00
|
|
|
#import "SOGoFreeBusyObject.h"
|
2006-10-11 20:48:25 +02:00
|
|
|
#import "SOGoTaskObject.h"
|
|
|
|
|
|
|
|
#import "SOGoAppointmentFolder.h"
|
2006-09-27 00:27:34 +02:00
|
|
|
|
2008-04-22 01:03:48 +02:00
|
|
|
#define defaultColor @"#AAAAAA"
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
@implementation SOGoAppointmentFolder
|
|
|
|
|
2008-06-30 20:52:20 +02:00
|
|
|
static NGLogger *logger = nil;
|
|
|
|
static NSNumber *sharedYes = nil;
|
2008-06-13 22:22:51 +02:00
|
|
|
static NSArray *reportQueryFields = nil;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
static Class sogoAppointmentFolderKlass = Nil;
|
2006-08-16 00:04:37 +02:00
|
|
|
|
|
|
|
+ (void) initialize
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
NGLoggerManager *lm;
|
|
|
|
static BOOL didInit = NO;
|
2007-02-09 22:21:35 +01:00
|
|
|
// SoClassSecurityInfo *securityInfo;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
|
|
|
if (didInit) return;
|
|
|
|
didInit = YES;
|
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
if (!sogoAppointmentFolderKlass)
|
2008-07-12 00:28:12 +02:00
|
|
|
{
|
|
|
|
sogoAppointmentFolderKlass = self;
|
|
|
|
[iCalEntityObject initializeSOGoExtensions];
|
|
|
|
}
|
2008-06-13 22:22:51 +02:00
|
|
|
|
|
|
|
if (!reportQueryFields)
|
|
|
|
reportQueryFields = [[NSArray alloc] initWithObjects: @"c_name",
|
|
|
|
@"c_content", @"c_creationdate",
|
|
|
|
@"c_lastmodified", @"c_version",
|
|
|
|
@"c_component", nil];
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
NSAssert2([super version] == 0,
|
|
|
|
@"invalid superclass (%@) version %i !",
|
|
|
|
NSStringFromClass([self superclass]), [super version]);
|
|
|
|
|
|
|
|
lm = [NGLoggerManager defaultLoggerManager];
|
2007-04-02 21:24:49 +02:00
|
|
|
logger = [lm loggerForDefaultKey: @"SOGoAppointmentFolderDebugEnabled"];
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-02-08 17:27:26 +01:00
|
|
|
// securityInfo = [self soClassSecurityInfo];
|
|
|
|
// [securityInfo declareRole: SOGoRole_Delegate
|
|
|
|
// asDefaultForPermission: SoPerm_AddDocumentsImagesAndFiles];
|
|
|
|
// [securityInfo declareRole: SOGoRole_Delegate
|
|
|
|
// asDefaultForPermission: SoPerm_ChangeImagesAndFiles];
|
|
|
|
// [securityInfo declareRoles: [NSArray arrayWithObjects:
|
|
|
|
// SOGoRole_Delegate,
|
|
|
|
// SOGoRole_Assistant, nil]
|
|
|
|
// asDefaultForPermission: SoPerm_View];
|
2006-12-14 22:20:13 +01:00
|
|
|
|
2007-04-11 21:08:58 +02:00
|
|
|
sharedYes = [[NSNumber numberWithBool: YES] retain];
|
|
|
|
}
|
|
|
|
|
2008-05-03 01:08:15 +02:00
|
|
|
+ (SOGoWebDAVAclManager *) webdavAclManager
|
|
|
|
{
|
2008-07-29 18:36:16 +02:00
|
|
|
SOGoWebDAVAclManager *aclManager = nil;
|
2008-06-30 20:52:20 +02:00
|
|
|
NSString *nsI;
|
2008-05-03 01:08:15 +02:00
|
|
|
|
2008-07-29 18:36:16 +02:00
|
|
|
if (!aclManager)
|
2008-05-03 01:08:15 +02:00
|
|
|
{
|
|
|
|
nsI = @"urn:inverse:params:xml:ns:inverse-dav";
|
|
|
|
|
2008-07-29 18:36:16 +02:00
|
|
|
aclManager = [SOGoWebDAVAclManager new];
|
|
|
|
[aclManager registerDAVPermission: davElement (@"read", XMLNS_WEBDAV)
|
|
|
|
abstract: YES
|
|
|
|
withEquivalent: SoPerm_WebDAVAccess
|
|
|
|
asChildOf: davElement (@"all", XMLNS_WEBDAV)];
|
|
|
|
[aclManager registerDAVPermission: davElement (@"read-current-user-privilege-set", XMLNS_WEBDAV)
|
|
|
|
abstract: YES
|
|
|
|
withEquivalent: SoPerm_WebDAVAccess
|
|
|
|
asChildOf: davElement (@"read", XMLNS_WEBDAV)];
|
|
|
|
[aclManager registerDAVPermission: davElement (@"read-free-busy", XMLNS_WEBDAV)
|
|
|
|
abstract: NO
|
|
|
|
withEquivalent: SoPerm_AccessContentsInformation
|
|
|
|
asChildOf: davElement (@"read", XMLNS_WEBDAV)];
|
|
|
|
[aclManager registerDAVPermission: davElement (@"write", XMLNS_WEBDAV)
|
|
|
|
abstract: YES
|
|
|
|
withEquivalent: nil
|
|
|
|
asChildOf: davElement (@"all", XMLNS_WEBDAV)];
|
|
|
|
[aclManager registerDAVPermission: davElement (@"bind", XMLNS_WEBDAV)
|
|
|
|
abstract: NO
|
|
|
|
withEquivalent: SoPerm_AddDocumentsImagesAndFiles
|
|
|
|
asChildOf: davElement (@"write", XMLNS_WEBDAV)];
|
|
|
|
[aclManager registerDAVPermission: davElement (@"schedule",
|
|
|
|
XMLNS_CALDAV)
|
|
|
|
abstract: NO
|
|
|
|
withEquivalent: nil
|
|
|
|
asChildOf: davElement (@"bind", XMLNS_WEBDAV)];
|
|
|
|
[aclManager registerDAVPermission: davElement (@"schedule-post",
|
|
|
|
XMLNS_CALDAV)
|
|
|
|
abstract: NO
|
|
|
|
withEquivalent: nil
|
|
|
|
asChildOf: davElement (@"schedule", XMLNS_CALDAV)];
|
|
|
|
[aclManager registerDAVPermission:
|
|
|
|
davElement (@"schedule-post-vevent", XMLNS_CALDAV)
|
|
|
|
abstract: NO
|
|
|
|
withEquivalent: nil
|
|
|
|
asChildOf: davElement (@"schedule-post", XMLNS_CALDAV)];
|
|
|
|
[aclManager registerDAVPermission:
|
|
|
|
davElement (@"schedule-post-vtodo", XMLNS_CALDAV)
|
|
|
|
abstract: NO
|
|
|
|
withEquivalent: nil
|
|
|
|
asChildOf: davElement (@"schedule-post", XMLNS_CALDAV)];
|
|
|
|
[aclManager registerDAVPermission:
|
|
|
|
davElement (@"schedule-post-vjournal", XMLNS_CALDAV)
|
|
|
|
abstract: NO
|
|
|
|
withEquivalent: nil
|
|
|
|
asChildOf: davElement (@"schedule-post", XMLNS_CALDAV)];
|
|
|
|
[aclManager registerDAVPermission:
|
|
|
|
davElement (@"schedule-post-vfreebusy", XMLNS_CALDAV)
|
|
|
|
abstract: NO
|
|
|
|
withEquivalent: nil
|
|
|
|
asChildOf: davElement (@"schedule-post", XMLNS_CALDAV)];
|
|
|
|
[aclManager registerDAVPermission: davElement (@"schedule-deliver",
|
|
|
|
XMLNS_CALDAV)
|
|
|
|
abstract: NO
|
|
|
|
withEquivalent: nil
|
|
|
|
asChildOf: davElement (@"schedule", XMLNS_CALDAV)];
|
|
|
|
[aclManager registerDAVPermission:
|
|
|
|
davElement (@"schedule-deliver-vevent", XMLNS_CALDAV)
|
|
|
|
abstract: NO
|
|
|
|
withEquivalent: nil
|
|
|
|
asChildOf: davElement (@"schedule-deliver", XMLNS_CALDAV)];
|
|
|
|
[aclManager registerDAVPermission:
|
|
|
|
davElement (@"schedule-deliver-vtodo", XMLNS_CALDAV)
|
|
|
|
abstract: NO
|
|
|
|
withEquivalent: nil
|
|
|
|
asChildOf: davElement (@"schedule-deliver", XMLNS_CALDAV)];
|
|
|
|
[aclManager registerDAVPermission:
|
|
|
|
davElement (@"schedule-deliver-vjournal", XMLNS_CALDAV)
|
|
|
|
abstract: NO
|
|
|
|
withEquivalent: nil
|
|
|
|
asChildOf: davElement (@"schedule-deliver", XMLNS_CALDAV)];
|
|
|
|
[aclManager registerDAVPermission:
|
|
|
|
davElement (@"schedule-deliver-vfreebusy", XMLNS_CALDAV)
|
|
|
|
abstract: NO
|
|
|
|
withEquivalent: nil
|
|
|
|
asChildOf: davElement (@"schedule-deliver", XMLNS_CALDAV)];
|
|
|
|
[aclManager registerDAVPermission: davElement (@"schedule-respond",
|
|
|
|
XMLNS_CALDAV)
|
|
|
|
abstract: NO
|
|
|
|
withEquivalent: nil
|
|
|
|
asChildOf: davElement (@"schedule", XMLNS_CALDAV)];
|
|
|
|
[aclManager registerDAVPermission:
|
|
|
|
davElement (@"schedule-respond-vevent", XMLNS_CALDAV)
|
|
|
|
abstract: NO
|
|
|
|
withEquivalent: nil
|
|
|
|
asChildOf: davElement (@"schedule-respond", XMLNS_CALDAV)];
|
|
|
|
[aclManager registerDAVPermission:
|
|
|
|
davElement (@"schedule-respond-vtodo", XMLNS_CALDAV)
|
|
|
|
abstract: NO
|
|
|
|
withEquivalent: nil
|
|
|
|
asChildOf: davElement (@"schedule-respond", XMLNS_CALDAV)];
|
|
|
|
[aclManager registerDAVPermission: davElement (@"unbind", XMLNS_WEBDAV)
|
|
|
|
abstract: NO
|
|
|
|
withEquivalent: SoPerm_DeleteObjects
|
|
|
|
asChildOf: davElement (@"write", XMLNS_WEBDAV)];
|
|
|
|
[aclManager
|
2008-06-30 20:52:20 +02:00
|
|
|
registerDAVPermission: davElement (@"write-properties", XMLNS_WEBDAV)
|
2008-05-03 01:08:15 +02:00
|
|
|
abstract: YES
|
|
|
|
withEquivalent: SoPerm_ChangePermissions /* hackish */
|
2008-06-30 20:52:20 +02:00
|
|
|
asChildOf: davElement (@"write", XMLNS_WEBDAV)];
|
2008-07-29 18:36:16 +02:00
|
|
|
[aclManager
|
2008-06-30 20:52:20 +02:00
|
|
|
registerDAVPermission: davElement (@"write-content", XMLNS_WEBDAV)
|
2008-05-03 01:08:15 +02:00
|
|
|
abstract: YES
|
|
|
|
withEquivalent: nil
|
2008-06-30 20:52:20 +02:00
|
|
|
asChildOf: davElement (@"write", XMLNS_WEBDAV)];
|
2008-07-29 18:36:16 +02:00
|
|
|
[aclManager registerDAVPermission: davElement (@"admin", nsI)
|
|
|
|
abstract: YES
|
|
|
|
withEquivalent: nil
|
|
|
|
asChildOf: davElement (@"all", XMLNS_WEBDAV)];
|
|
|
|
[aclManager registerDAVPermission: davElement (@"read-acl", XMLNS_WEBDAV)
|
|
|
|
abstract: YES
|
|
|
|
withEquivalent: SOGoPerm_ReadAcls
|
|
|
|
asChildOf: davElement (@"admin", nsI)];
|
|
|
|
[aclManager registerDAVPermission: davElement (@"write-acl", XMLNS_WEBDAV)
|
|
|
|
abstract: YES
|
|
|
|
withEquivalent: SoPerm_ChangePermissions
|
|
|
|
asChildOf: davElement (@"admin", nsI)];
|
2008-05-03 01:08:15 +02:00
|
|
|
}
|
|
|
|
|
2008-07-29 18:36:16 +02:00
|
|
|
return aclManager;
|
2008-05-03 01:08:15 +02:00
|
|
|
}
|
|
|
|
|
2007-04-11 21:08:58 +02:00
|
|
|
- (id) initWithName: (NSString *) name
|
|
|
|
inContainer: (id) newContainer
|
|
|
|
{
|
|
|
|
if ((self = [super initWithName: name inContainer: newContainer]))
|
|
|
|
{
|
|
|
|
timeZone = [[context activeUser] timeZone];
|
2007-11-26 18:40:44 +01:00
|
|
|
aclMatrix = [NSMutableDictionary new];
|
|
|
|
stripFields = nil;
|
|
|
|
uidToFilename = nil;
|
2007-04-11 21:08:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2006-08-16 00:04:37 +02:00
|
|
|
- (void) dealloc
|
|
|
|
{
|
2007-11-26 18:40:44 +01:00
|
|
|
[aclMatrix release];
|
|
|
|
[stripFields release];
|
2007-04-11 21:08:58 +02:00
|
|
|
[uidToFilename release];
|
2006-06-15 21:34:10 +02:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
- (Class) objectClassForComponentName: (NSString *) componentName
|
|
|
|
{
|
|
|
|
Class objectClass;
|
|
|
|
|
|
|
|
if ([componentName isEqualToString: @"vevent"])
|
|
|
|
objectClass = [SOGoAppointmentObject class];
|
|
|
|
else if ([componentName isEqualToString: @"vtodo"])
|
|
|
|
objectClass = [SOGoTaskObject class];
|
|
|
|
else
|
|
|
|
objectClass = Nil;
|
|
|
|
|
|
|
|
return objectClass;
|
|
|
|
}
|
|
|
|
|
2008-04-22 01:03:48 +02:00
|
|
|
- (NSString *) calendarColor
|
|
|
|
{
|
|
|
|
NSUserDefaults *settings;
|
|
|
|
NSDictionary *colors;
|
|
|
|
NSString *color;
|
|
|
|
|
|
|
|
settings = [[context activeUser] userSettings];
|
|
|
|
colors = [[settings objectForKey: @"Calendar"]
|
|
|
|
objectForKey: @"FolderColors"];
|
|
|
|
color = [colors objectForKey: [self folderReference]];
|
|
|
|
if (!color)
|
|
|
|
color = defaultColor;
|
|
|
|
|
|
|
|
return color;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setCalendarColor: (NSString *) newColor
|
|
|
|
{
|
|
|
|
NSUserDefaults *settings;
|
|
|
|
NSMutableDictionary *calendarSettings;
|
|
|
|
NSMutableDictionary *colors;
|
|
|
|
|
|
|
|
settings = [[context activeUser] userSettings];
|
|
|
|
calendarSettings = [settings objectForKey: @"Calendar"];
|
|
|
|
if (!calendarSettings)
|
|
|
|
{
|
|
|
|
calendarSettings = [NSMutableDictionary dictionary];
|
|
|
|
[settings setObject: calendarSettings
|
|
|
|
forKey: @"Calendar"];
|
|
|
|
}
|
|
|
|
colors = [calendarSettings objectForKey: @"FolderColors"];
|
|
|
|
if (!colors)
|
|
|
|
{
|
|
|
|
colors = [NSMutableDictionary dictionary];
|
|
|
|
[calendarSettings setObject: colors forKey: @"FolderColors"];
|
|
|
|
}
|
|
|
|
[colors setObject: newColor forKey: [self folderReference]];
|
|
|
|
[settings synchronize];
|
|
|
|
}
|
|
|
|
|
2008-06-20 16:52:40 +02:00
|
|
|
- (NSString *) syncTag
|
|
|
|
{
|
|
|
|
NSUserDefaults *settings;
|
|
|
|
NSDictionary *syncTags;
|
|
|
|
NSString *syncTag;
|
|
|
|
|
|
|
|
settings = [[context activeUser] userSettings];
|
|
|
|
syncTags = [[settings objectForKey: @"Calendar"]
|
|
|
|
objectForKey: @"FolderSyncTags"];
|
|
|
|
syncTag = [syncTags objectForKey: [self folderReference]];
|
|
|
|
if (!syncTag)
|
|
|
|
syncTag = @"";
|
|
|
|
|
|
|
|
return syncTag;
|
|
|
|
}
|
|
|
|
|
|
|
|
#warning this code shares a lot with the colour code
|
|
|
|
- (void) setSyncTag: (NSString *) newSyncTag
|
|
|
|
{
|
|
|
|
NSUserDefaults *settings;
|
|
|
|
NSMutableDictionary *calendarSettings;
|
|
|
|
NSMutableDictionary *syncTags;
|
|
|
|
|
|
|
|
settings = [[context activeUser] userSettings];
|
|
|
|
calendarSettings = [settings objectForKey: @"Calendar"];
|
|
|
|
if (!calendarSettings)
|
|
|
|
{
|
|
|
|
calendarSettings = [NSMutableDictionary dictionary];
|
|
|
|
[settings setObject: calendarSettings
|
|
|
|
forKey: @"Calendar"];
|
|
|
|
}
|
|
|
|
syncTags = [calendarSettings objectForKey: @"FolderSyncTags"];
|
|
|
|
if (!syncTags)
|
|
|
|
{
|
|
|
|
syncTags = [NSMutableDictionary dictionary];
|
|
|
|
[calendarSettings setObject: syncTags forKey: @"FolderSyncTags"];
|
|
|
|
}
|
|
|
|
[syncTags setObject: newSyncTag forKey: [self folderReference]];
|
|
|
|
[settings synchronize];
|
|
|
|
}
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
/* logging */
|
|
|
|
|
2006-08-16 00:04:37 +02:00
|
|
|
- (id) debugLogger
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
return logger;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* selection */
|
|
|
|
|
2006-08-16 00:04:37 +02:00
|
|
|
- (NSArray *) calendarUIDs
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
/* this is used for group calendars (this folder just returns itself) */
|
|
|
|
NSString *s;
|
|
|
|
|
|
|
|
s = [[self container] nameInContainer];
|
2007-04-11 21:08:58 +02:00
|
|
|
// [self logWithFormat:@"CAL UID: %@", s];
|
2006-06-15 21:34:10 +02:00
|
|
|
return [s isNotNull] ? [NSArray arrayWithObjects:&s count:1] : nil;
|
|
|
|
}
|
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
/* fetching */
|
2008-03-18 18:26:34 +01:00
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
- (NSString *) _sqlStringForComponent: (id) _component
|
2008-03-18 18:26:34 +01:00
|
|
|
{
|
2008-06-13 22:22:51 +02:00
|
|
|
NSString *sqlString;
|
|
|
|
NSArray *components;
|
2008-03-18 18:26:34 +01:00
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
if (_component)
|
2008-03-18 18:26:34 +01:00
|
|
|
{
|
2008-06-13 22:22:51 +02:00
|
|
|
if ([_component isKindOfClass: [NSArray class]])
|
|
|
|
components = _component;
|
|
|
|
else
|
|
|
|
components = [NSArray arrayWithObject: _component];
|
2008-03-18 18:26:34 +01:00
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
sqlString
|
|
|
|
= [NSString stringWithFormat: @"AND (c_component = '%@')",
|
|
|
|
[components componentsJoinedByString: @"' OR c_component = '"]];
|
|
|
|
}
|
2008-03-18 18:26:34 +01:00
|
|
|
else
|
2008-06-13 22:22:51 +02:00
|
|
|
sqlString = @"";
|
2008-03-18 18:26:34 +01:00
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
return sqlString;
|
2008-03-18 18:26:34 +01:00
|
|
|
}
|
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
- (NSString *) _sqlStringRangeFrom: (NSCalendarDate *) _startDate
|
|
|
|
to: (NSCalendarDate *) _endDate
|
2006-09-27 00:27:34 +02:00
|
|
|
{
|
2008-06-13 22:22:51 +02:00
|
|
|
unsigned int start, end;
|
2006-09-27 00:27:34 +02:00
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
start = (unsigned int) [_startDate timeIntervalSince1970];
|
|
|
|
end = (unsigned int) [_endDate timeIntervalSince1970];
|
2006-09-27 00:27:34 +02:00
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
return [NSString stringWithFormat:
|
|
|
|
@" AND (c_startdate <= %u) AND (c_enddate >= %u)",
|
|
|
|
end, start];
|
2008-03-18 18:26:34 +01:00
|
|
|
}
|
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
- (NSString *) _privacyClassificationStringsForUID: (NSString *) uid
|
2008-03-18 18:26:34 +01:00
|
|
|
{
|
2008-06-13 22:22:51 +02:00
|
|
|
NSMutableString *classificationString;
|
|
|
|
NSString *currentRole;
|
|
|
|
unsigned int counter;
|
|
|
|
iCalAccessClass classes[] = {iCalAccessPublic, iCalAccessPrivate,
|
|
|
|
iCalAccessConfidential};
|
2008-03-18 18:26:34 +01:00
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
classificationString = [NSMutableString string];
|
|
|
|
for (counter = 0; counter < 3; counter++)
|
|
|
|
{
|
|
|
|
currentRole = [self roleForComponentsWithAccessClass: classes[counter]
|
|
|
|
forUser: uid];
|
|
|
|
if ([currentRole length] > 0)
|
|
|
|
[classificationString appendFormat: @"c_classification = %d or ",
|
|
|
|
classes[counter]];
|
|
|
|
}
|
2007-03-07 22:27:19 +01:00
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
return classificationString;
|
2008-03-18 18:26:34 +01:00
|
|
|
}
|
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
- (NSString *) _privacySqlString
|
2008-03-18 18:26:34 +01:00
|
|
|
{
|
2008-06-13 22:22:51 +02:00
|
|
|
NSString *privacySqlString, *email, *login;
|
|
|
|
SOGoUser *activeUser;
|
2008-03-18 18:26:34 +01:00
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
activeUser = [context activeUser];
|
2008-03-18 18:26:34 +01:00
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
if (activeUserIsOwner
|
|
|
|
|| [[self ownerInContext: context] isEqualToString: [[context activeUser] login]]
|
|
|
|
|| [[activeUser rolesForObject: self inContext: context]
|
|
|
|
containsObject: SoRole_Owner])
|
|
|
|
privacySqlString = @"";
|
|
|
|
else if ([[activeUser login] isEqualToString: @"freebusy"])
|
|
|
|
privacySqlString = @"and (c_isopaque = 1)";
|
|
|
|
else
|
2008-03-18 18:26:34 +01:00
|
|
|
{
|
2008-06-13 22:22:51 +02:00
|
|
|
#warning we do not manage all the possible user emails
|
|
|
|
email = [[activeUser primaryIdentity] objectForKey: @"email"];
|
|
|
|
login = [activeUser login];
|
|
|
|
|
|
|
|
privacySqlString
|
|
|
|
= [NSString stringWithFormat:
|
|
|
|
@"(%@(c_orgmail = '%@')"
|
|
|
|
@" or ((c_partmails caseInsensitiveLike '%@%%'"
|
|
|
|
@" or c_partmails caseInsensitiveLike '%%\n%@%%')))",
|
|
|
|
[self _privacyClassificationStringsForUID: login],
|
|
|
|
email, email, email];
|
2008-03-18 18:26:34 +01:00
|
|
|
}
|
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
return privacySqlString;
|
2008-03-18 18:26:34 +01:00
|
|
|
}
|
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
- (NSArray *) bareFetchFields: (NSArray *) fields
|
|
|
|
from: (NSCalendarDate *) startDate
|
|
|
|
to: (NSCalendarDate *) endDate
|
|
|
|
title: (NSString *) title
|
|
|
|
component: (id) component
|
|
|
|
additionalFilters: (NSString *) filters
|
2008-03-18 18:26:34 +01:00
|
|
|
{
|
2008-06-13 22:22:51 +02:00
|
|
|
EOQualifier *qualifier;
|
|
|
|
GCSFolder *folder;
|
|
|
|
NSString *sql, *dateSqlString, *titleSqlString, *componentSqlString,
|
|
|
|
*filterSqlString;
|
2008-03-18 18:26:34 +01:00
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
folder = [self ocsFolder];
|
|
|
|
if (startDate && endDate)
|
2008-10-08 18:03:24 +02:00
|
|
|
dateSqlString = [self _sqlStringRangeFrom: startDate to: endDate];
|
2008-03-18 18:26:34 +01:00
|
|
|
else
|
2008-10-08 18:03:24 +02:00
|
|
|
dateSqlString = @"";
|
2008-06-13 22:22:51 +02:00
|
|
|
|
|
|
|
if ([title length])
|
|
|
|
titleSqlString = [NSString stringWithFormat: @"AND (c_title"
|
|
|
|
@" isCaseInsensitiveLike: '%%%@%%')", title];
|
2008-03-18 18:26:34 +01:00
|
|
|
else
|
2008-06-13 22:22:51 +02:00
|
|
|
titleSqlString = @"";
|
2008-03-18 18:26:34 +01:00
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
componentSqlString = [self _sqlStringForComponent: component];
|
|
|
|
if (filters)
|
|
|
|
filterSqlString = [NSString stringWithFormat: @"AND (%@)", filters];
|
|
|
|
else
|
|
|
|
filterSqlString = @"";
|
2008-03-18 18:26:34 +01:00
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
/* prepare mandatory fields */
|
2006-09-27 00:27:34 +02:00
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
sql = [[NSString stringWithFormat: @"%@%@%@%@",
|
|
|
|
dateSqlString, titleSqlString, componentSqlString,
|
|
|
|
filterSqlString] substringFromIndex: 4];
|
2006-09-27 00:27:34 +02:00
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
/* fetch non-recurrent apts first */
|
|
|
|
qualifier = [EOQualifier qualifierWithQualifierFormat: sql];
|
2008-03-18 18:26:34 +01:00
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
return [folder fetchFields: fields matchingQualifier: qualifier];
|
2008-03-18 18:26:34 +01:00
|
|
|
}
|
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
- (BOOL) _checkIfWeCanRememberRecords: (NSArray *) fields
|
2008-03-18 18:26:34 +01:00
|
|
|
{
|
2008-06-13 22:22:51 +02:00
|
|
|
return ([fields containsObject: @"c_name"]
|
|
|
|
&& [fields containsObject: @"c_version"]
|
|
|
|
&& [fields containsObject: @"c_lastmodified"]
|
|
|
|
&& [fields containsObject: @"c_creationdate"]
|
|
|
|
&& [fields containsObject: @"c_component"]);
|
2006-09-27 00:27:34 +02:00
|
|
|
}
|
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
- (void) _rememberRecords: (NSArray *) records
|
2006-10-17 21:57:14 +02:00
|
|
|
{
|
2008-06-13 22:22:51 +02:00
|
|
|
NSEnumerator *recordsEnum;
|
|
|
|
NSDictionary *currentRecord;
|
2006-10-17 21:57:14 +02:00
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
recordsEnum = [records objectEnumerator];
|
|
|
|
while ((currentRecord = [recordsEnum nextObject]))
|
|
|
|
[childRecords setObject: currentRecord
|
|
|
|
forKey: [currentRecord objectForKey: @"c_name"]];
|
2006-10-17 21:57:14 +02:00
|
|
|
}
|
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
- (NSMutableDictionary *) fixupRecord: (NSDictionary *) _record
|
2008-05-16 17:52:19 +02:00
|
|
|
{
|
2008-06-13 22:22:51 +02:00
|
|
|
NSMutableDictionary *md;
|
2008-06-19 20:31:18 +02:00
|
|
|
static NSString *fields[] = { @"c_startdate", @"startDate",
|
|
|
|
@"c_enddate", @"endDate" };
|
|
|
|
unsigned int count;
|
|
|
|
NSCalendarDate *date;
|
|
|
|
NSNumber *dateValue;
|
2008-07-16 23:47:18 +02:00
|
|
|
BOOL isAllDay;
|
|
|
|
|
|
|
|
isAllDay = [[_record objectForKey: @"c_isallday"] boolValue];
|
2008-06-19 20:31:18 +02:00
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
md = [[_record mutableCopy] autorelease];
|
2008-06-19 20:31:18 +02:00
|
|
|
for (count = 0; count < 2; count++)
|
|
|
|
{
|
|
|
|
dateValue = [_record objectForKey: fields[count * 2]];
|
|
|
|
if (dateValue)
|
|
|
|
{
|
2008-08-10 19:14:56 +02:00
|
|
|
date = [NSCalendarDate dateWithTimeIntervalSince1970: [dateValue unsignedIntValue]];
|
2008-06-19 20:31:18 +02:00
|
|
|
if (date)
|
|
|
|
{
|
|
|
|
[date setTimeZone: timeZone];
|
|
|
|
[md setObject: date forKey: fields[count * 2 + 1]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2008-07-16 23:47:18 +02:00
|
|
|
[self logWithFormat: @"missing '%@' in record?", fields[count * 2]];
|
2008-06-19 20:31:18 +02:00
|
|
|
}
|
2008-05-16 17:52:19 +02:00
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
return md;
|
2008-05-16 17:52:19 +02:00
|
|
|
}
|
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
- (NSArray *) fixupRecords: (NSArray *) records
|
|
|
|
fetchRange: (NGCalendarDateRange *) r
|
2006-10-17 21:57:14 +02:00
|
|
|
{
|
2008-06-13 22:22:51 +02:00
|
|
|
// TODO: is the result supposed to be sorted by date?
|
|
|
|
NSMutableArray *ma;
|
|
|
|
unsigned count, max;
|
|
|
|
id row; // TODO: what is the type of the record?
|
2006-10-17 21:57:14 +02:00
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
if (records)
|
2006-10-17 21:57:14 +02:00
|
|
|
{
|
2008-06-13 22:22:51 +02:00
|
|
|
max = [records count];
|
|
|
|
ma = [NSMutableArray arrayWithCapacity: max];
|
|
|
|
for (count = 0; count < max; count++)
|
|
|
|
{
|
2008-07-12 00:28:12 +02:00
|
|
|
row = [self fixupRecord: [records objectAtIndex: count]];
|
2008-06-13 22:22:51 +02:00
|
|
|
if (row)
|
|
|
|
[ma addObject: row];
|
|
|
|
}
|
2006-10-17 21:57:14 +02:00
|
|
|
}
|
|
|
|
else
|
2008-06-13 22:22:51 +02:00
|
|
|
ma = nil;
|
|
|
|
|
|
|
|
return ma;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSMutableDictionary *) fixupCycleRecord: (NSDictionary *) _record
|
|
|
|
cycleRange: (NGCalendarDateRange *) _r
|
|
|
|
{
|
|
|
|
NSMutableDictionary *md;
|
2008-07-17 23:12:43 +02:00
|
|
|
NSNumber *dateSecs;
|
2008-06-13 22:22:51 +02:00
|
|
|
id tmp;
|
|
|
|
|
|
|
|
md = [[_record mutableCopy] autorelease];
|
2008-08-10 19:14:56 +02:00
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
/* cycle is in _r. We also have to override the c_startdate/c_enddate with the date values of
|
|
|
|
the reccurence since we use those when displaying events in SOGo Web */
|
|
|
|
tmp = [_r startDate];
|
|
|
|
[tmp setTimeZone: timeZone];
|
2008-08-10 19:14:56 +02:00
|
|
|
[md setObject: tmp forKey: @"startDate"];
|
2008-07-17 23:12:43 +02:00
|
|
|
dateSecs = [NSNumber numberWithInt: [tmp timeIntervalSince1970]];
|
|
|
|
[md setObject: dateSecs forKey: @"c_startdate"];
|
|
|
|
[md setObject: dateSecs forKey: @"c_recurrence_id"];
|
2008-08-10 19:14:56 +02:00
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
tmp = [_r endDate];
|
|
|
|
[tmp setTimeZone: timeZone];
|
2008-08-10 19:14:56 +02:00
|
|
|
[md setObject: tmp forKey: @"endDate"];
|
|
|
|
dateSecs = [NSNumber numberWithInt: [tmp timeIntervalSince1970]];
|
|
|
|
[md setObject: dateSecs forKey: @"c_enddate"];
|
2008-06-13 22:22:51 +02:00
|
|
|
|
|
|
|
return md;
|
|
|
|
}
|
|
|
|
|
2008-07-12 00:28:12 +02:00
|
|
|
- (int) _indexOfRecordMatchingDate: (NSCalendarDate *) matchDate
|
|
|
|
inArray: (NSArray *) recordArray
|
|
|
|
{
|
|
|
|
int count, max, recordIndex;
|
|
|
|
NSDictionary *currentRecord;
|
|
|
|
|
|
|
|
recordIndex = -1;
|
|
|
|
|
|
|
|
count = 0;
|
|
|
|
max = [recordArray count];
|
|
|
|
while (recordIndex == -1 && count < max)
|
|
|
|
{
|
|
|
|
currentRecord = [recordArray objectAtIndex: count];
|
|
|
|
if ([[currentRecord objectForKey: @"startDate"]
|
|
|
|
isEqual: matchDate])
|
|
|
|
recordIndex = count;
|
2008-07-14 17:14:40 +02:00
|
|
|
else
|
|
|
|
count++;
|
2008-07-12 00:28:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return recordIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) _fixExceptionRecord: (NSMutableDictionary *) recRecord
|
|
|
|
fromRow: (NSDictionary *) row
|
|
|
|
{
|
|
|
|
NSArray *objects;
|
|
|
|
static NSArray *fields = nil;
|
|
|
|
|
|
|
|
if (!fields)
|
|
|
|
{
|
|
|
|
fields = [NSArray arrayWithObjects: @"c_name", nil];
|
|
|
|
[fields retain];
|
|
|
|
}
|
|
|
|
|
|
|
|
objects = [row objectsForKeys: fields notFoundMarker: @""];
|
|
|
|
[recRecord setObjects: objects forKeys: fields];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) _appendCycleException: (iCalRepeatableEntityObject *) component
|
|
|
|
fromRow: (NSDictionary *) row
|
|
|
|
forRange: (NGCalendarDateRange *) dateRange
|
|
|
|
toArray: (NSMutableArray *) ma
|
|
|
|
{
|
|
|
|
NSCalendarDate *startDate, *recurrenceId;
|
|
|
|
NSMutableDictionary *newRecord;
|
2008-07-17 23:12:43 +02:00
|
|
|
NSDictionary *oldRecord;
|
2008-07-12 00:28:12 +02:00
|
|
|
NGCalendarDateRange *newRecordRange;
|
|
|
|
int recordIndex;
|
|
|
|
|
|
|
|
newRecord = nil;
|
|
|
|
recurrenceId = [component recurrenceId];
|
|
|
|
if ([dateRange containsDate: recurrenceId])
|
|
|
|
{
|
|
|
|
recordIndex = [self _indexOfRecordMatchingDate: recurrenceId
|
|
|
|
inArray: ma];
|
|
|
|
if (recordIndex > -1)
|
|
|
|
{
|
|
|
|
startDate = [component startDate];
|
|
|
|
if ([dateRange containsDate: startDate])
|
|
|
|
{
|
|
|
|
newRecord = [self fixupRecord: [component quickRecord]];
|
2008-07-17 23:12:43 +02:00
|
|
|
[newRecord setObject: [NSNumber numberWithInt: 1]
|
|
|
|
forKey: @"c_iscycle"];
|
|
|
|
oldRecord = [ma objectAtIndex: recordIndex];
|
|
|
|
[newRecord setObject: [oldRecord objectForKey: @"c_recurrence_id"]
|
|
|
|
forKey: @"c_recurrence_id"];
|
2008-07-12 00:28:12 +02:00
|
|
|
[ma replaceObjectAtIndex: recordIndex withObject: newRecord];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
[ma removeObjectAtIndex: recordIndex];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
[self errorWithFormat:
|
|
|
|
@"missing exception record for recurrence-id: %@",
|
|
|
|
recurrenceId];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
newRecord = [self fixupRecord: [component quickRecord]];
|
|
|
|
newRecordRange = [NGCalendarDateRange calendarDateRangeWithStartDate:
|
|
|
|
[newRecord objectForKey:
|
|
|
|
@"startDate"]
|
|
|
|
endDate: [newRecord objectForKey:
|
|
|
|
@"endDate"]];
|
|
|
|
if ([dateRange doesIntersectWithDateRange: newRecordRange])
|
|
|
|
[ma addObject: newRecord];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (newRecord)
|
|
|
|
[self _fixExceptionRecord: newRecord fromRow: row];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) _appendCycleExceptionsFromRow: (NSDictionary *) row
|
2008-07-14 17:14:40 +02:00
|
|
|
forRange: (NGCalendarDateRange *) dateRange
|
|
|
|
toArray: (NSMutableArray *) ma
|
2008-07-12 00:28:12 +02:00
|
|
|
{
|
|
|
|
NSArray *elements, *components;
|
|
|
|
unsigned int count, max;
|
|
|
|
NSString *content;
|
|
|
|
|
|
|
|
content = [row objectForKey: @"c_content"];
|
|
|
|
if ([content length])
|
|
|
|
{
|
|
|
|
elements = [iCalCalendar parseFromSource: content];
|
|
|
|
if ([elements count])
|
|
|
|
{
|
|
|
|
components = [[elements objectAtIndex: 0] allObjects];
|
|
|
|
max = [components count];
|
|
|
|
for (count = 1; count < max; count++)
|
|
|
|
[self _appendCycleException: [components objectAtIndex: count]
|
|
|
|
fromRow: row
|
|
|
|
forRange: dateRange
|
|
|
|
toArray: ma];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
- (void) _flattenCycleRecord: (NSDictionary *) _row
|
|
|
|
forRange: (NGCalendarDateRange *) _r
|
|
|
|
intoArray: (NSMutableArray *) _ma
|
|
|
|
{
|
|
|
|
NSMutableDictionary *row, *fixedRow;
|
2008-07-17 23:12:43 +02:00
|
|
|
NSMutableArray *recordArray;
|
2008-06-13 22:22:51 +02:00
|
|
|
NSDictionary *cycleinfo;
|
|
|
|
NSCalendarDate *startDate, *endDate;
|
|
|
|
NGCalendarDateRange *fir, *rRange;
|
|
|
|
NSArray *rules, *exRules, *exDates, *ranges;
|
|
|
|
unsigned i, count;
|
|
|
|
NSString *content;
|
|
|
|
|
2008-07-17 23:12:43 +02:00
|
|
|
recordArray = [NSMutableArray array];
|
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
content = [_row objectForKey: @"c_cycleinfo"];
|
|
|
|
if (![content isNotNull])
|
|
|
|
{
|
|
|
|
[self errorWithFormat:@"cyclic record doesn't have cycleinfo -> %@",
|
|
|
|
_row];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
cycleinfo = [content propertyList];
|
|
|
|
if (!cycleinfo)
|
|
|
|
{
|
|
|
|
[self errorWithFormat:@"cyclic record doesn't have cycleinfo -> %@",
|
|
|
|
_row];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-07-12 00:28:12 +02:00
|
|
|
row = [self fixupRecord: _row];
|
2008-06-13 22:22:51 +02:00
|
|
|
[row removeObjectForKey: @"c_cycleinfo"];
|
|
|
|
[row setObject: sharedYes forKey: @"isRecurrentEvent"];
|
|
|
|
|
|
|
|
startDate = [row objectForKey: @"startDate"];
|
|
|
|
endDate = [row objectForKey: @"endDate"];
|
|
|
|
fir = [NGCalendarDateRange calendarDateRangeWithStartDate: startDate
|
|
|
|
endDate: endDate];
|
|
|
|
rules = [cycleinfo objectForKey: @"rules"];
|
|
|
|
exRules = [cycleinfo objectForKey: @"exRules"];
|
|
|
|
exDates = [cycleinfo objectForKey: @"exDates"];
|
|
|
|
|
|
|
|
ranges = [iCalRecurrenceCalculator recurrenceRangesWithinCalendarDateRange: _r
|
|
|
|
firstInstanceCalendarDateRange: fir
|
|
|
|
recurrenceRules: rules
|
|
|
|
exceptionRules: exRules
|
|
|
|
exceptionDates: exDates];
|
|
|
|
count = [ranges count];
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
2008-07-14 17:14:40 +02:00
|
|
|
rRange = [ranges objectAtIndex: i];
|
2008-06-13 22:22:51 +02:00
|
|
|
fixedRow = [self fixupCycleRecord: row cycleRange: rRange];
|
|
|
|
if (fixedRow)
|
2008-07-17 23:12:43 +02:00
|
|
|
[recordArray addObject: fixedRow];
|
2008-06-13 22:22:51 +02:00
|
|
|
}
|
2008-07-12 00:28:12 +02:00
|
|
|
|
|
|
|
[self _appendCycleExceptionsFromRow: row
|
|
|
|
forRange: _r
|
2008-07-17 23:12:43 +02:00
|
|
|
toArray: recordArray];
|
|
|
|
|
|
|
|
[_ma addObjectsFromArray: recordArray];
|
2008-06-13 22:22:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) fixupCyclicRecords: (NSArray *) _records
|
|
|
|
fetchRange: (NGCalendarDateRange *) _r
|
|
|
|
{
|
|
|
|
// TODO: is the result supposed to be sorted by date?
|
|
|
|
NSMutableArray *ma;
|
|
|
|
NSDictionary *row;
|
2008-07-12 00:28:12 +02:00
|
|
|
unsigned int count, max;
|
2008-06-13 22:22:51 +02:00
|
|
|
|
2008-07-12 00:28:12 +02:00
|
|
|
max = [_records count];
|
|
|
|
ma = [NSMutableArray arrayWithCapacity: max];
|
|
|
|
|
|
|
|
for (count = 0; count < max; count++)
|
|
|
|
{
|
|
|
|
row = [_records objectAtIndex: count];
|
|
|
|
[self _flattenCycleRecord: row forRange: _r intoArray: ma];
|
|
|
|
}
|
2008-06-13 22:22:51 +02:00
|
|
|
|
|
|
|
return ma;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) _buildStripFieldsFromFields: (NSArray *) fields
|
|
|
|
{
|
|
|
|
stripFields = [[NSMutableArray alloc] initWithCapacity: [fields count]];
|
|
|
|
[stripFields setArray: fields];
|
|
|
|
[stripFields removeObjectsInArray: [NSArray arrayWithObjects: @"c_name",
|
|
|
|
@"c_uid", @"c_startdate",
|
|
|
|
@"c_enddate", @"c_isallday",
|
|
|
|
@"c_iscycle",
|
|
|
|
@"c_classification",
|
|
|
|
@"c_component", nil]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) _fixupProtectedInformation: (NSEnumerator *) ma
|
|
|
|
inFields: (NSArray *) fields
|
|
|
|
forUser: (NSString *) uid
|
|
|
|
{
|
|
|
|
NSMutableDictionary *currentRecord;
|
|
|
|
NSString *roles[] = {nil, nil, nil};
|
|
|
|
iCalAccessClass accessClass;
|
|
|
|
NSString *fullRole, *role;
|
|
|
|
|
|
|
|
if (!stripFields)
|
|
|
|
[self _buildStripFieldsFromFields: fields];
|
|
|
|
|
|
|
|
#warning we do not take the participation status into account
|
|
|
|
while ((currentRecord = [ma nextObject]))
|
|
|
|
{
|
|
|
|
accessClass
|
|
|
|
= [[currentRecord objectForKey: @"c_classification"] intValue];
|
|
|
|
role = roles[accessClass];
|
|
|
|
if (!role)
|
|
|
|
{
|
|
|
|
fullRole = [self roleForComponentsWithAccessClass: accessClass
|
|
|
|
forUser: uid];
|
|
|
|
if ([fullRole length] > 9)
|
|
|
|
role = [fullRole substringFromIndex: 9];
|
|
|
|
roles[accessClass] = role;
|
|
|
|
}
|
|
|
|
if ([role isEqualToString: @"DAndTViewer"])
|
|
|
|
[currentRecord removeObjectsForKeys: stripFields];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) fetchFields: (NSArray *) _fields
|
|
|
|
from: (NSCalendarDate *) _startDate
|
|
|
|
to: (NSCalendarDate *) _endDate
|
|
|
|
title: (NSString *) title
|
|
|
|
component: (id) _component
|
|
|
|
additionalFilters: (NSString *) filters
|
|
|
|
{
|
|
|
|
EOQualifier *qualifier;
|
|
|
|
GCSFolder *folder;
|
|
|
|
NSMutableArray *fields, *ma = nil;
|
|
|
|
NSArray *records;
|
|
|
|
NSString *sql, *dateSqlString, *titleSqlString, *componentSqlString,
|
|
|
|
*privacySqlString, *currentLogin, *filterSqlString;
|
|
|
|
NGCalendarDateRange *r;
|
|
|
|
BOOL rememberRecords;
|
|
|
|
|
|
|
|
rememberRecords = [self _checkIfWeCanRememberRecords: _fields];
|
|
|
|
// if (rememberRecords)
|
|
|
|
// NSLog (@"we will remember those records!");
|
|
|
|
|
|
|
|
folder = [self ocsFolder];
|
|
|
|
if (!folder)
|
|
|
|
{
|
|
|
|
[self errorWithFormat:@"(%s): missing folder for fetch!",
|
|
|
|
__PRETTY_FUNCTION__];
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_startDate && _endDate)
|
|
|
|
{
|
|
|
|
r = [NGCalendarDateRange calendarDateRangeWithStartDate: _startDate
|
|
|
|
endDate: _endDate];
|
|
|
|
dateSqlString = [self _sqlStringRangeFrom: _startDate to: _endDate];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
r = nil;
|
|
|
|
dateSqlString = @"";
|
|
|
|
}
|
|
|
|
|
|
|
|
if ([title length])
|
|
|
|
titleSqlString = [NSString stringWithFormat: @"AND (c_title"
|
|
|
|
@" isCaseInsensitiveLike: '%%%@%%')", title];
|
|
|
|
else
|
|
|
|
titleSqlString = @"";
|
|
|
|
|
|
|
|
componentSqlString = [self _sqlStringForComponent: _component];
|
|
|
|
privacySqlString = [self _privacySqlString];
|
|
|
|
if (filters)
|
|
|
|
filterSqlString = [NSString stringWithFormat: @"AND (%@)", filters];
|
|
|
|
else
|
|
|
|
filterSqlString = @"";
|
|
|
|
|
|
|
|
/* prepare mandatory fields */
|
|
|
|
|
|
|
|
fields = [NSMutableArray arrayWithArray: _fields];
|
2008-07-16 23:47:18 +02:00
|
|
|
[fields addObjectUniquely: @"c_name"];
|
|
|
|
[fields addObjectUniquely: @"c_uid"];
|
|
|
|
[fields addObjectUniquely: @"c_startdate"];
|
|
|
|
[fields addObjectUniquely: @"c_enddate"];
|
|
|
|
[fields addObjectUniquely: @"c_isallday"];
|
2008-06-13 22:22:51 +02:00
|
|
|
|
|
|
|
if (logger)
|
|
|
|
[self debugWithFormat:@"should fetch (%@=>%@) ...", _startDate, _endDate];
|
|
|
|
|
|
|
|
sql = [NSString stringWithFormat: @"(c_iscycle = 0)%@%@%@%@%@",
|
|
|
|
dateSqlString, titleSqlString, componentSqlString,
|
|
|
|
privacySqlString, filterSqlString];
|
|
|
|
|
|
|
|
/* fetch non-recurrent apts first */
|
|
|
|
qualifier = [EOQualifier qualifierWithQualifierFormat: sql];
|
|
|
|
|
|
|
|
records = [folder fetchFields: fields matchingQualifier: qualifier];
|
|
|
|
if (records)
|
|
|
|
{
|
|
|
|
if (r)
|
|
|
|
records = [self fixupRecords: records fetchRange: r];
|
|
|
|
if (logger)
|
|
|
|
[self debugWithFormat: @"fetched %i records: %@",
|
|
|
|
[records count], records];
|
|
|
|
ma = [NSMutableArray arrayWithArray: records];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fetch recurrent apts now. we do NOT consider the date range when doing that
|
|
|
|
as the c_startdate/c_enddate of a recurring event is always set to the first
|
|
|
|
recurrence - others are generated on the fly */
|
|
|
|
sql = [NSString stringWithFormat: @"(c_iscycle = 1)%@%@%@%@", titleSqlString,
|
|
|
|
componentSqlString, privacySqlString, filterSqlString];
|
|
|
|
|
|
|
|
qualifier = [EOQualifier qualifierWithQualifierFormat: sql];
|
|
|
|
|
|
|
|
records = [folder fetchFields: fields matchingQualifier: qualifier];
|
|
|
|
if (records)
|
|
|
|
{
|
2008-06-19 20:31:18 +02:00
|
|
|
if (r)
|
2008-06-13 22:22:51 +02:00
|
|
|
records = [self fixupCyclicRecords: records fetchRange: r];
|
2008-07-12 00:28:12 +02:00
|
|
|
if (ma)
|
|
|
|
[ma addObjectsFromArray: records];
|
|
|
|
else
|
|
|
|
ma = [NSMutableArray arrayWithArray: records];
|
2008-06-13 22:22:51 +02:00
|
|
|
}
|
|
|
|
else if (!ma)
|
|
|
|
{
|
|
|
|
[self errorWithFormat: @"(%s): fetch failed!", __PRETTY_FUNCTION__];
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (logger)
|
|
|
|
[self debugWithFormat:@"returning %i records", [ma count]];
|
|
|
|
|
|
|
|
currentLogin = [[context activeUser] login];
|
|
|
|
if (![currentLogin isEqualToString: owner])
|
|
|
|
[self _fixupProtectedInformation: [ma objectEnumerator]
|
|
|
|
inFields: _fields
|
|
|
|
forUser: currentLogin];
|
|
|
|
// [ma makeObjectsPerform: @selector (setObject:forKey:)
|
|
|
|
// withObject: owner
|
|
|
|
// withObject: @"owner"];
|
|
|
|
|
|
|
|
if (rememberRecords)
|
|
|
|
[self _rememberRecords: ma];
|
|
|
|
|
|
|
|
return ma;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) _appendPropstat: (NSDictionary *) propstat
|
|
|
|
toResponse: (WOResponse *) r
|
|
|
|
{
|
|
|
|
NSArray *properties;
|
|
|
|
unsigned int count, max;
|
|
|
|
|
|
|
|
[r appendContentString: @"<D:propstat><D:prop>"];
|
|
|
|
properties = [propstat objectForKey: @"properties"];
|
|
|
|
max = [properties count];
|
|
|
|
for (count = 0; count < max; count++)
|
|
|
|
[r appendContentString: [properties objectAtIndex: count]];
|
|
|
|
[r appendContentString: @"</D:prop><D:status>"];
|
|
|
|
[r appendContentString: [propstat objectForKey: @"status"]];
|
|
|
|
[r appendContentString: @"</D:status></D:propstat>"];
|
|
|
|
}
|
|
|
|
|
|
|
|
#warning we should use the EOFetchSpecification for that!!! (see doPROPFIND:)
|
|
|
|
|
|
|
|
#warning components in calendar-data query are ignored
|
2008-07-12 00:28:12 +02:00
|
|
|
|
|
|
|
#warning the two following methods should be replaced with the new dav rendering mechanism
|
2008-06-13 22:22:51 +02:00
|
|
|
- (NSString *) _nodeTagForProperty: (NSString *) property
|
|
|
|
{
|
|
|
|
NSString *namespace, *nodeName, *nsRep;
|
|
|
|
NSRange nsEnd;
|
|
|
|
|
|
|
|
nsEnd = [property rangeOfString: @"}"];
|
|
|
|
namespace
|
|
|
|
= [property substringFromRange: NSMakeRange (1, nsEnd.location - 1)];
|
|
|
|
nodeName = [property substringFromIndex: nsEnd.location + 1];
|
2008-06-30 20:52:20 +02:00
|
|
|
if ([namespace isEqualToString: XMLNS_CALDAV])
|
2008-06-13 22:22:51 +02:00
|
|
|
nsRep = @"C";
|
|
|
|
else
|
|
|
|
nsRep = @"D";
|
|
|
|
|
|
|
|
return [NSString stringWithFormat: @"%@:%@", nsRep, nodeName];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) _nodeTag: (NSString *) property
|
|
|
|
{
|
|
|
|
static NSMutableDictionary *tags = nil;
|
|
|
|
NSString *nodeTag;
|
|
|
|
|
|
|
|
if (!tags)
|
|
|
|
tags = [NSMutableDictionary new];
|
|
|
|
nodeTag = [tags objectForKey: property];
|
|
|
|
if (!nodeTag)
|
|
|
|
{
|
|
|
|
nodeTag = [self _nodeTagForProperty: property];
|
|
|
|
[tags setObject: nodeTag forKey: property];
|
|
|
|
}
|
|
|
|
|
|
|
|
return nodeTag;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString **) _properties: (NSString **) properties
|
|
|
|
ofObject: (NSDictionary *) object
|
|
|
|
{
|
|
|
|
NSString **currentProperty;
|
|
|
|
NSString **values, **currentValue;
|
|
|
|
SOGoObject *sogoObject;
|
|
|
|
SoSecurityManager *mgr;
|
|
|
|
SEL methodSel;
|
|
|
|
|
|
|
|
#warning things may crash here...
|
2008-06-14 00:43:33 +02:00
|
|
|
values = calloc (100, sizeof (NSMutableString *));
|
2008-06-13 22:22:51 +02:00
|
|
|
|
|
|
|
// NSLog (@"_properties:ofObject:: %@", [NSDate date]);
|
|
|
|
|
|
|
|
#warning this check should be done directly in the query... we should fix this sometime
|
|
|
|
mgr = [SoSecurityManager sharedSecurityManager];
|
|
|
|
sogoObject = [self _createChildComponentWithRecord: object];
|
|
|
|
|
|
|
|
if (activeUserIsOwner
|
|
|
|
|| [[self ownerInContext: context]
|
|
|
|
isEqualToString: [[context activeUser] login]]
|
|
|
|
|| !([mgr validatePermission: SOGoPerm_AccessObject
|
|
|
|
onObject: sogoObject
|
|
|
|
inContext: context]))
|
|
|
|
{
|
|
|
|
currentProperty = properties;
|
|
|
|
currentValue = values;
|
|
|
|
while (*currentProperty)
|
|
|
|
{
|
2008-07-09 23:09:08 +02:00
|
|
|
methodSel = SOGoSelectorForPropertyGetter (*currentProperty);
|
2008-06-13 22:22:51 +02:00
|
|
|
if (methodSel && [sogoObject respondsToSelector: methodSel])
|
|
|
|
*currentValue = [[sogoObject performSelector: methodSel]
|
|
|
|
stringByEscapingXMLString];
|
|
|
|
currentProperty++;
|
|
|
|
currentValue++;
|
|
|
|
}
|
2008-06-14 00:41:40 +02:00
|
|
|
}
|
2008-06-13 22:22:51 +02:00
|
|
|
|
|
|
|
// NSLog (@"/_properties:ofObject:: %@", [NSDate date]);
|
|
|
|
|
|
|
|
return values;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) _propstats: (NSString **) properties
|
|
|
|
ofObject: (NSDictionary *) object
|
|
|
|
{
|
|
|
|
NSMutableArray *propstats, *properties200, *properties404, *propDict;
|
|
|
|
NSString **property, **values, **currentValue;
|
|
|
|
NSString *propertyValue, *nodeTag;
|
|
|
|
|
|
|
|
// NSLog (@"_propstats:ofObject:: %@", [NSDate date]);
|
|
|
|
|
|
|
|
propstats = [NSMutableArray array];
|
|
|
|
|
|
|
|
properties200 = [NSMutableArray new];
|
|
|
|
properties404 = [NSMutableArray new];
|
|
|
|
|
|
|
|
values = [self _properties: properties ofObject: object];
|
|
|
|
currentValue = values;
|
2008-06-13 23:35:23 +02:00
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
property = properties;
|
2008-06-13 23:27:27 +02:00
|
|
|
while (*property)
|
2008-06-13 22:22:51 +02:00
|
|
|
{
|
|
|
|
nodeTag = [self _nodeTag: *property];
|
|
|
|
if (*currentValue)
|
|
|
|
{
|
|
|
|
propertyValue = [NSString stringWithFormat: @"<%@>%@</%@>",
|
|
|
|
nodeTag, *currentValue, nodeTag];
|
|
|
|
propDict = properties200;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
propertyValue = [NSString stringWithFormat: @"<%@/>", nodeTag];
|
|
|
|
propDict = properties404;
|
|
|
|
}
|
2008-06-13 23:35:23 +02:00
|
|
|
[propDict addObject: propertyValue];
|
2008-06-13 22:22:51 +02:00
|
|
|
property++;
|
2008-06-13 23:27:27 +02:00
|
|
|
currentValue++;
|
2008-06-13 22:22:51 +02:00
|
|
|
}
|
|
|
|
free (values);
|
|
|
|
|
|
|
|
if ([properties200 count])
|
2008-06-30 20:52:20 +02:00
|
|
|
[propstats addObject: [NSDictionary dictionaryWithObjectsAndKeys:
|
|
|
|
properties200, @"properties",
|
|
|
|
@"HTTP/1.1 200 OK", @"status",
|
|
|
|
nil]];
|
|
|
|
[properties200 release];
|
2008-06-13 22:22:51 +02:00
|
|
|
|
|
|
|
if ([properties404 count])
|
2008-06-30 20:52:20 +02:00
|
|
|
[propstats addObject: [NSDictionary dictionaryWithObjectsAndKeys:
|
|
|
|
properties404, @"properties",
|
|
|
|
@"HTTP/1.1 404 Not Found", @"status",
|
2008-06-13 22:22:51 +02:00
|
|
|
nil]];
|
2008-06-30 20:52:20 +02:00
|
|
|
[properties404 release];
|
2008-06-13 22:22:51 +02:00
|
|
|
|
|
|
|
// NSLog (@"/_propstats:ofObject:: %@", [NSDate date]);
|
|
|
|
|
|
|
|
return propstats;
|
|
|
|
}
|
|
|
|
|
|
|
|
#warning We need to use the new DAV utilities here...
|
2008-07-05 00:25:27 +02:00
|
|
|
#warning this is baddddd because we return a single-valued dictionary containing \
|
|
|
|
a cname which may not event exist... the logic behind appendObject:... should be \
|
|
|
|
rethought, especially since we may start using SQL views
|
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
- (void) appendObject: (NSDictionary *) object
|
|
|
|
properties: (NSString **) properties
|
|
|
|
withBaseURL: (NSString *) baseURL
|
|
|
|
toComplexResponse: (WOResponse *) r
|
|
|
|
{
|
|
|
|
NSArray *propstats;
|
|
|
|
unsigned int count, max;
|
|
|
|
|
|
|
|
[r appendContentString: @"<D:response><D:href>"];
|
|
|
|
[r appendContentString: baseURL];
|
|
|
|
// if (![baseURL hasSuffix: @"/"])
|
|
|
|
// [r appendContentString: @"/"];
|
|
|
|
[r appendContentString: [object objectForKey: @"c_name"]];
|
|
|
|
[r appendContentString: @"</D:href>"];
|
|
|
|
|
|
|
|
// NSLog (@"(appendPropstats...): %@", [NSDate date]);
|
|
|
|
propstats = [self _propstats: properties ofObject: object];
|
|
|
|
max = [propstats count];
|
|
|
|
for (count = 0; count < max; count++)
|
|
|
|
[self _appendPropstat: [propstats objectAtIndex: count]
|
|
|
|
toResponse: r];
|
|
|
|
// NSLog (@"/(appendPropstats...): %@", [NSDate date]);
|
|
|
|
|
|
|
|
[r appendContentString: @"</D:response>\r\n"];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) appendMissingObjectRef: (NSString *) href
|
|
|
|
toComplexResponse: (WOResponse *) r
|
|
|
|
{
|
|
|
|
[r appendContentString: @"<D:response><D:href>"];
|
|
|
|
[r appendContentString: href];
|
|
|
|
[r appendContentString: @"</D:href><D:status>HTTP/1.1 404 Not Found</D:status></D:response>\r\n"];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) _appendTimeRange: (id <DOMElement>) timeRangeElement
|
|
|
|
toFilter: (NSMutableDictionary *) filter
|
|
|
|
{
|
|
|
|
NSCalendarDate *parsedDate;
|
|
|
|
|
|
|
|
parsedDate = [[timeRangeElement attribute: @"start"] asCalendarDate];
|
|
|
|
[filter setObject: parsedDate forKey: @"start"];
|
|
|
|
parsedDate = [[timeRangeElement attribute: @"end"] asCalendarDate];
|
|
|
|
[filter setObject: parsedDate forKey: @"end"];
|
|
|
|
}
|
|
|
|
|
|
|
|
#warning This method lacks support for timeranges
|
|
|
|
- (void) _appendPropertyFilter: (id <DOMElement>) propFilter
|
|
|
|
toFilter: (NSMutableDictionary *) filter
|
|
|
|
{
|
|
|
|
NSString *propName, *textMatch;
|
|
|
|
id <DOMNodeList> matches;
|
|
|
|
|
|
|
|
propName = [[propFilter attribute: @"name"] lowercaseString];
|
|
|
|
matches = [propFilter getElementsByTagName: @"text-match"];
|
|
|
|
if ([matches length])
|
|
|
|
textMatch = [[matches objectAtIndex: 0] textValue];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
matches = [propFilter getElementsByTagName: @"is-not-defined"];
|
|
|
|
if ([matches length])
|
|
|
|
textMatch = @"NULL";
|
|
|
|
else
|
|
|
|
textMatch = @"";
|
|
|
|
}
|
|
|
|
|
|
|
|
[filter setObject: textMatch forKey: propName];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDictionary *) _parseCalendarFilter: (id <DOMElement>) filterElement
|
|
|
|
{
|
|
|
|
NSMutableDictionary *filterData;
|
|
|
|
id <DOMElement> parentNode;
|
|
|
|
id <DOMNodeList> elements;
|
|
|
|
NSString *componentName;
|
|
|
|
|
|
|
|
parentNode = (id <DOMElement>) [filterElement parentNode];
|
|
|
|
if ([[parentNode tagName] isEqualToString: @"comp-filter"]
|
|
|
|
&& [[parentNode attribute: @"name"] isEqualToString: @"VCALENDAR"])
|
|
|
|
{
|
|
|
|
componentName = [[filterElement attribute: @"name"] lowercaseString];
|
|
|
|
filterData = [NSMutableDictionary dictionary];
|
|
|
|
[filterData setObject: componentName forKey: @"name"];
|
|
|
|
elements = [filterElement getElementsByTagName: @"time-range"];
|
|
|
|
if ([elements length])
|
|
|
|
[self _appendTimeRange: [elements objectAtIndex: 0]
|
|
|
|
toFilter: filterData];
|
|
|
|
|
|
|
|
elements = [filterElement getElementsByTagName: @"prop-filter"];
|
|
|
|
if ([elements length])
|
|
|
|
[self _appendPropertyFilter: [elements objectAtIndex: 0]
|
|
|
|
toFilter: filterData];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
filterData = nil;
|
2006-10-17 21:57:14 +02:00
|
|
|
|
|
|
|
return filterData;
|
|
|
|
}
|
|
|
|
|
2008-03-18 18:26:34 +01:00
|
|
|
- (NSArray *) _parseRequestedProperties: (id <DOMElement>) parentNode
|
|
|
|
{
|
|
|
|
NSMutableArray *properties;
|
|
|
|
NSObject <DOMNodeList> *propList, *children;
|
|
|
|
NSObject <DOMNode> *currentChild;
|
|
|
|
unsigned int count, max, count2, max2;
|
2008-06-13 22:22:51 +02:00
|
|
|
NSString *flatProperty;
|
2008-03-18 18:26:34 +01:00
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
// NSLog (@"parseRequestProperties: %@", [NSDate date]);
|
2008-03-18 18:26:34 +01:00
|
|
|
properties = [NSMutableArray array];
|
|
|
|
|
|
|
|
propList = [parentNode getElementsByTagName: @"prop"];
|
|
|
|
max = [propList length];
|
|
|
|
for (count = 0; count < max; count++)
|
|
|
|
{
|
|
|
|
children = [[propList objectAtIndex: count] childNodes];
|
|
|
|
max2 = [children length];
|
|
|
|
for (count2 = 0; count2 < max2; count2++)
|
|
|
|
{
|
|
|
|
currentChild = [children objectAtIndex: count2];
|
2008-06-13 22:22:51 +02:00
|
|
|
if ([currentChild conformsToProtocol: @protocol (DOMElement)])
|
|
|
|
{
|
|
|
|
flatProperty = [NSString stringWithFormat: @"{%@}%@",
|
|
|
|
[currentChild namespaceURI],
|
|
|
|
[currentChild nodeName]];
|
|
|
|
[properties addObject: flatProperty];
|
|
|
|
}
|
2008-03-18 18:26:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// while ([children hasChildNodes])
|
|
|
|
// [properties addObject: [children next]];
|
|
|
|
}
|
2008-06-13 22:22:51 +02:00
|
|
|
// NSLog (@"/parseRequestProperties: %@", [NSDate date]);
|
2008-03-18 18:26:34 +01:00
|
|
|
|
|
|
|
return properties;
|
|
|
|
}
|
|
|
|
|
2006-10-17 21:57:14 +02:00
|
|
|
- (NSArray *) _parseCalendarFilters: (id <DOMElement>) parentNode
|
|
|
|
{
|
2008-03-18 18:26:34 +01:00
|
|
|
id <DOMNodeList> children;
|
|
|
|
id <DOMElement> node;
|
2006-10-17 21:57:14 +02:00
|
|
|
NSMutableArray *filters;
|
|
|
|
NSDictionary *filter;
|
2008-03-18 18:26:34 +01:00
|
|
|
unsigned int count, max;
|
2006-10-17 21:57:14 +02:00
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
// NSLog (@"parseCalendarFilter: %@", [NSDate date]);
|
|
|
|
|
2007-12-05 00:28:52 +01:00
|
|
|
filters = [NSMutableArray array];
|
2008-03-18 18:26:34 +01:00
|
|
|
children = [parentNode getElementsByTagName: @"comp-filter"];
|
|
|
|
max = [children length];
|
|
|
|
for (count = 0; count < max; count++)
|
2006-10-17 21:57:14 +02:00
|
|
|
{
|
2008-03-18 18:26:34 +01:00
|
|
|
node = [children objectAtIndex: count];
|
2006-10-17 21:57:14 +02:00
|
|
|
filter = [self _parseCalendarFilter: node];
|
|
|
|
if (filter)
|
2008-03-18 18:26:34 +01:00
|
|
|
[filters addObject: filter];
|
2006-10-17 21:57:14 +02:00
|
|
|
}
|
2008-06-13 22:22:51 +02:00
|
|
|
// NSLog (@"/parseCalendarFilter: %@", [NSDate date]);
|
2006-10-17 21:57:14 +02:00
|
|
|
|
|
|
|
return filters;
|
|
|
|
}
|
|
|
|
|
2008-05-16 17:52:19 +02:00
|
|
|
- (NSString *) _additionalFilterKey: (NSString *) key
|
|
|
|
value: (NSString *) value
|
|
|
|
{
|
|
|
|
NSString *filterString;
|
|
|
|
|
|
|
|
if ([value length])
|
|
|
|
{
|
|
|
|
if ([value isEqualToString: @"NULL"])
|
|
|
|
filterString = [NSString stringWithFormat: @"(%@ = '')", key];
|
|
|
|
else
|
|
|
|
filterString
|
|
|
|
= [NSString stringWithFormat: @"(%@ like '%%%@%%')", key, value];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
filterString = [NSString stringWithFormat: @"(%@ != '')", key];
|
|
|
|
|
|
|
|
return filterString;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) _composeAdditionalFilters: (NSDictionary *) filter
|
|
|
|
{
|
|
|
|
NSString *additionalFilter;
|
|
|
|
NSEnumerator *keys;
|
|
|
|
NSString *currentKey, *keyField, *filterString;
|
|
|
|
static NSArray *fields = nil;
|
|
|
|
NSMutableArray *filters;
|
|
|
|
|
|
|
|
#warning the list of fields should be taken from the .ocs description file
|
|
|
|
if (!fields)
|
|
|
|
{
|
|
|
|
fields = [NSArray arrayWithObject: @"c_uid"];
|
|
|
|
[fields retain];
|
|
|
|
}
|
2008-06-13 22:22:51 +02:00
|
|
|
|
|
|
|
filters = [NSMutableArray new];
|
|
|
|
keys = [[filter allKeys] objectEnumerator];
|
|
|
|
while ((currentKey = [keys nextObject]))
|
|
|
|
{
|
|
|
|
keyField = [NSString stringWithFormat: @"c_%@", currentKey];
|
|
|
|
if ([fields containsObject: keyField])
|
|
|
|
{
|
|
|
|
filterString = [self _additionalFilterKey: keyField
|
|
|
|
value: [filter objectForKey: currentKey]];
|
|
|
|
[filters addObject: filterString];
|
|
|
|
}
|
2006-10-11 20:48:25 +02:00
|
|
|
}
|
2006-09-27 00:27:34 +02:00
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
if ([filters count])
|
|
|
|
additionalFilter = [filters componentsJoinedByString: @" and "];
|
|
|
|
else
|
|
|
|
additionalFilter = nil;
|
|
|
|
[filters release];
|
2008-01-16 19:57:58 +01:00
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
return additionalFilter;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
- (NSString *) davCalendarColor
|
|
|
|
{
|
|
|
|
NSString *color;
|
2006-11-02 22:53:27 +01:00
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
color = [[self calendarColor] uppercaseString];
|
2006-11-02 22:53:27 +01:00
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
return [NSString stringWithFormat: @"%@FF", color];
|
2006-11-02 22:53:27 +01:00
|
|
|
}
|
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
- (NSException *) setDavCalendarColor: (NSString *) newColor
|
2006-12-14 22:20:13 +01:00
|
|
|
{
|
2008-06-13 22:22:51 +02:00
|
|
|
NSException *error;
|
|
|
|
NSString *realColor;
|
|
|
|
|
|
|
|
if ([newColor length] == 9
|
|
|
|
&& [newColor hasPrefix: @"#"])
|
|
|
|
{
|
|
|
|
realColor = [newColor substringToIndex: 7];
|
|
|
|
[self setCalendarColor: realColor];
|
|
|
|
error = nil;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
error = [NSException exceptionWithHTTPStatus: 400
|
|
|
|
reason: @"Bad color format (should be '#XXXXXXXX')."];
|
|
|
|
|
|
|
|
return error;
|
2006-12-14 22:20:13 +01:00
|
|
|
}
|
|
|
|
|
2008-07-14 18:46:10 +02:00
|
|
|
- (NSString *) davCalendarOrder
|
|
|
|
{
|
|
|
|
unsigned int order;
|
|
|
|
|
|
|
|
order = [[container subFolders] indexOfObject: self];
|
|
|
|
|
|
|
|
return [NSString stringWithFormat: @"%d", order];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSException *) setDavCalendarOrder: (NSString *) newColor
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2008-07-09 17:54:39 +02:00
|
|
|
- (SOGoWebDAVValue *) davCalendarFreeBusySet
|
|
|
|
{
|
|
|
|
NSEnumerator *subFolders;
|
|
|
|
SOGoAppointmentFolder *currentFolder;
|
|
|
|
NSMutableArray *response;
|
|
|
|
SOGoWebDAVValue *responseValue;
|
|
|
|
|
|
|
|
response = [NSMutableArray new];
|
|
|
|
subFolders = [[container subFolders] objectEnumerator];
|
|
|
|
while ((currentFolder = [subFolders nextObject]))
|
|
|
|
[response addObject: davElementWithContent (@"href", XMLNS_WEBDAV,
|
|
|
|
[currentFolder davURL])];
|
|
|
|
responseValue = [davElementWithContent (@"calendar-free-busy-set", XMLNS_CALDAV, response)
|
|
|
|
asWebDAVValue];
|
|
|
|
[response release];
|
|
|
|
|
|
|
|
return responseValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This method is ignored but we must return a success value. */
|
|
|
|
- (NSException *) setDavCalendarFreeBusySet: (NSString *) newFreeBusySet
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
- (void) _appendComponentProperties: (NSString **) properties
|
|
|
|
matchingFilters: (NSArray *) filters
|
|
|
|
toResponse: (WOResponse *) response
|
2007-03-10 00:10:43 +01:00
|
|
|
{
|
2008-06-13 22:22:51 +02:00
|
|
|
NSArray *apts;
|
|
|
|
NSDictionary *currentFilter;
|
|
|
|
NSEnumerator *filterList;
|
2008-06-14 00:27:35 +02:00
|
|
|
NSString *additionalFilters, *baseURL;
|
2008-06-13 22:22:51 +02:00
|
|
|
unsigned int count, max;
|
2007-03-10 00:10:43 +01:00
|
|
|
|
2008-06-14 00:27:35 +02:00
|
|
|
baseURL = [[self davURL] absoluteString];
|
2008-06-13 22:22:51 +02:00
|
|
|
|
|
|
|
filterList = [filters objectEnumerator];
|
|
|
|
while ((currentFilter = [filterList nextObject]))
|
2007-03-10 00:10:43 +01:00
|
|
|
{
|
2008-06-13 22:22:51 +02:00
|
|
|
additionalFilters = [self _composeAdditionalFilters: currentFilter];
|
|
|
|
// NSLog(@"query");
|
|
|
|
apts = [self bareFetchFields: reportQueryFields
|
|
|
|
from: [currentFilter objectForKey: @"start"]
|
|
|
|
to: [currentFilter objectForKey: @"end"]
|
|
|
|
title: [currentFilter objectForKey: @"title"]
|
|
|
|
component: [currentFilter objectForKey: @"name"]
|
|
|
|
additionalFilters: additionalFilters];
|
|
|
|
// NSLog(@"adding properties");
|
|
|
|
max = [apts count];
|
|
|
|
for (count = 0; count < max; count++)
|
|
|
|
[self appendObject: [apts objectAtIndex: count]
|
|
|
|
properties: properties
|
|
|
|
withBaseURL: baseURL
|
|
|
|
toComplexResponse: response];
|
|
|
|
// NSLog(@"done");
|
2007-03-10 00:10:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
- (id) davCalendarQuery: (id) queryContext
|
2006-08-16 00:04:37 +02:00
|
|
|
{
|
2008-06-13 22:22:51 +02:00
|
|
|
WOResponse *r;
|
|
|
|
id <DOMDocument> document;
|
|
|
|
id <DOMElement> documentElement;
|
|
|
|
NSString **properties;
|
|
|
|
|
|
|
|
r = [context response];
|
|
|
|
[r setStatus: 207];
|
|
|
|
[r setContentEncoding: NSUTF8StringEncoding];
|
|
|
|
[r setHeader: @"text/xml; charset=\"utf-8\"" forKey: @"content-type"];
|
|
|
|
[r setHeader: @"no-cache" forKey: @"pragma"];
|
|
|
|
[r setHeader: @"no-cache" forKey: @"cache-control"];
|
|
|
|
[r appendContentString:@"<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n"];
|
|
|
|
[r appendContentString: @"<D:multistatus xmlns:D=\"DAV:\""
|
|
|
|
@" xmlns:C=\"urn:ietf:params:xml:ns:caldav\">\r\n"];
|
|
|
|
|
|
|
|
document = [[context request] contentAsDOMDocument];
|
|
|
|
documentElement = [document documentElement];
|
|
|
|
properties = [[self _parseRequestedProperties: documentElement]
|
|
|
|
asPointersOfObjects];
|
|
|
|
[self _appendComponentProperties: properties
|
|
|
|
matchingFilters: [self _parseCalendarFilters: documentElement]
|
|
|
|
toResponse: r];
|
|
|
|
[r appendContentString:@"</D:multistatus>\r\n"];
|
|
|
|
free (properties);
|
|
|
|
|
|
|
|
return r;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2008-06-14 00:27:35 +02:00
|
|
|
- (NSDictionary *) _deduceObjectNamesFromURLs: (NSArray *) urls
|
2006-08-16 00:04:37 +02:00
|
|
|
{
|
2008-06-13 22:22:51 +02:00
|
|
|
unsigned int count, max;
|
2008-06-14 00:27:35 +02:00
|
|
|
NSString *url, *componentURLPath, *cName, *baseURLString;
|
|
|
|
NSMutableDictionary *cNames;
|
|
|
|
NSURL *componentURL, *baseURL;
|
2008-06-13 22:22:51 +02:00
|
|
|
NSArray *urlComponents;
|
|
|
|
|
|
|
|
max = [urls count];
|
2008-06-14 00:27:35 +02:00
|
|
|
cNames = [NSMutableDictionary dictionaryWithCapacity: max];
|
|
|
|
baseURL = [self davURL];
|
|
|
|
baseURLString = [baseURL absoluteString];
|
2008-06-13 22:22:51 +02:00
|
|
|
|
|
|
|
for (count = 0; count < max; count++)
|
2008-05-16 17:52:19 +02:00
|
|
|
{
|
2008-06-13 22:22:51 +02:00
|
|
|
url = [urls objectAtIndex: count];
|
2008-06-14 00:27:35 +02:00
|
|
|
componentURL = [[NSURL URLWithString: url relativeToURL: baseURL]
|
2008-06-13 22:22:51 +02:00
|
|
|
standardizedURL];
|
|
|
|
componentURLPath = [componentURL absoluteString];
|
2008-06-14 00:27:35 +02:00
|
|
|
if ([componentURLPath rangeOfString: baseURLString].location
|
2008-06-13 22:22:51 +02:00
|
|
|
!= NSNotFound)
|
|
|
|
{
|
|
|
|
urlComponents = [componentURLPath componentsSeparatedByString: @"/"];
|
|
|
|
cName = [urlComponents objectAtIndex: [urlComponents count] - 1];
|
2008-06-14 00:27:35 +02:00
|
|
|
[cNames setObject: url forKey: cName];
|
2008-06-13 22:22:51 +02:00
|
|
|
}
|
2006-10-11 20:48:25 +02:00
|
|
|
}
|
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
return cNames;
|
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
- (NSArray *) _fetchComponentsWithNames: (NSArray *) cNames
|
2006-06-15 21:34:10 +02:00
|
|
|
{
|
2008-06-13 22:22:51 +02:00
|
|
|
NSMutableString *filterString;
|
|
|
|
NSArray *records;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
// NSLog (@"fetchComponentsWithNames");
|
|
|
|
filterString = [NSMutableString new];
|
|
|
|
[filterString appendFormat: @"c_name='%@'",
|
|
|
|
[cNames componentsJoinedByString: @"' OR c_name='"]];
|
|
|
|
// NSLog (@"fetchComponentsWithNames: query");
|
|
|
|
records = [self bareFetchFields: reportQueryFields
|
|
|
|
from: nil
|
|
|
|
to: nil
|
|
|
|
title: nil
|
|
|
|
component: nil
|
|
|
|
additionalFilters: filterString];
|
|
|
|
[filterString release];
|
|
|
|
// NSLog (@"/fetchComponentsWithNames");
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
return records;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
#define maxQuerySize 2500
|
|
|
|
#define baseQuerySize 160
|
|
|
|
#define idQueryOverhead 13
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
- (NSArray *) _fetchComponentsMatchingObjectNames: (NSArray *) cNames
|
2007-04-11 21:08:58 +02:00
|
|
|
{
|
2008-06-13 22:22:51 +02:00
|
|
|
NSMutableArray *components;
|
|
|
|
NSArray *records;
|
|
|
|
NSMutableArray *currentNames;
|
|
|
|
unsigned int count, max, currentSize, queryNameLength;
|
|
|
|
NSString *currentName;
|
2007-04-11 21:08:58 +02:00
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
// NSLog (@"fetching components matching names");
|
|
|
|
|
|
|
|
currentNames = [NSMutableArray new];
|
|
|
|
currentSize = baseQuerySize;
|
|
|
|
|
|
|
|
max = [cNames count];
|
|
|
|
components = [NSMutableArray arrayWithCapacity: max];
|
|
|
|
for (count = 0; count < max; count++)
|
2007-04-11 21:08:58 +02:00
|
|
|
{
|
2008-06-13 22:22:51 +02:00
|
|
|
currentName = [cNames objectAtIndex: count];
|
|
|
|
queryNameLength = idQueryOverhead + [currentName length];
|
|
|
|
if ((currentSize + queryNameLength)
|
|
|
|
> maxQuerySize)
|
2007-04-11 21:08:58 +02:00
|
|
|
{
|
2008-06-13 22:22:51 +02:00
|
|
|
records = [self _fetchComponentsWithNames: currentNames];
|
|
|
|
[components addObjectsFromArray: records];
|
|
|
|
[currentNames removeAllObjects];
|
|
|
|
currentSize = baseQuerySize;
|
2007-04-11 21:08:58 +02:00
|
|
|
}
|
2008-06-13 22:22:51 +02:00
|
|
|
[currentNames addObject: currentName];
|
|
|
|
currentSize += queryNameLength;
|
2007-04-11 21:08:58 +02:00
|
|
|
}
|
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
records = [self _fetchComponentsWithNames: currentNames];
|
|
|
|
[components addObjectsFromArray: records];
|
|
|
|
[currentNames release];
|
|
|
|
|
|
|
|
// NSLog (@"/fetching components matching names");
|
|
|
|
|
|
|
|
return components;
|
2007-04-11 21:08:58 +02:00
|
|
|
}
|
|
|
|
|
2008-06-14 00:27:35 +02:00
|
|
|
- (NSDictionary *) _fetchComponentsMatchingURLs: (NSArray *) urls
|
2006-06-15 21:34:10 +02:00
|
|
|
{
|
2008-06-13 22:22:51 +02:00
|
|
|
NSMutableDictionary *components;
|
2008-06-14 00:27:35 +02:00
|
|
|
NSDictionary *cnames, *record;
|
2008-06-13 22:22:51 +02:00
|
|
|
NSString *recordURL;
|
2008-06-14 00:27:35 +02:00
|
|
|
NSArray *records;
|
|
|
|
unsigned int count, max;
|
|
|
|
|
|
|
|
components = [NSMutableDictionary dictionary];
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2008-06-14 00:27:35 +02:00
|
|
|
cnames = [self _deduceObjectNamesFromURLs: urls];
|
|
|
|
records = [self _fetchComponentsMatchingObjectNames: [cnames allKeys]];
|
2008-06-13 22:22:51 +02:00
|
|
|
max = [records count];
|
|
|
|
for (count = 0; count < max; count++)
|
2008-01-24 16:36:26 +01:00
|
|
|
{
|
2008-06-14 00:27:35 +02:00
|
|
|
record = [records objectAtIndex: count];
|
|
|
|
recordURL = [cnames objectForKey: [record objectForKey: @"c_name"]];
|
|
|
|
[components setObject: record forKey: recordURL];
|
2008-01-24 16:36:26 +01:00
|
|
|
}
|
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
return components;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) _appendComponentProperties: (NSString **) properties
|
|
|
|
matchingURLs: (id <DOMNodeList>) refs
|
|
|
|
toResponse: (WOResponse *) response
|
|
|
|
{
|
|
|
|
NSObject <DOMElement> *element;
|
|
|
|
NSDictionary *currentComponent, *components;
|
2008-06-14 00:27:35 +02:00
|
|
|
NSString *currentURL, *baseURL;
|
2008-06-13 22:22:51 +02:00
|
|
|
NSMutableArray *urls;
|
|
|
|
unsigned int count, max;
|
|
|
|
|
2008-06-14 00:27:35 +02:00
|
|
|
baseURL = [[self davURL] absoluteString];
|
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
urls = [NSMutableArray new];
|
|
|
|
max = [refs length];
|
|
|
|
for (count = 0; count < max; count++)
|
2008-01-24 16:36:26 +01:00
|
|
|
{
|
2008-06-13 22:22:51 +02:00
|
|
|
element = [refs objectAtIndex: count];
|
|
|
|
currentURL = [[element firstChild] nodeValue];
|
|
|
|
[urls addObject: currentURL];
|
2008-01-24 16:36:26 +01:00
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2008-06-14 00:27:35 +02:00
|
|
|
components = [self _fetchComponentsMatchingURLs: urls];
|
2008-06-13 22:22:51 +02:00
|
|
|
max = [urls count];
|
|
|
|
// NSLog (@"adding properties with url");
|
|
|
|
for (count = 0; count < max; count++)
|
2008-03-26 21:30:53 +01:00
|
|
|
{
|
2008-06-13 22:22:51 +02:00
|
|
|
currentComponent
|
|
|
|
= [components objectForKey: [urls objectAtIndex: count]];
|
|
|
|
if (currentComponent)
|
|
|
|
[self appendObject: currentComponent
|
|
|
|
properties: properties
|
|
|
|
withBaseURL: baseURL
|
|
|
|
toComplexResponse: response];
|
|
|
|
else
|
|
|
|
[self appendMissingObjectRef: currentURL
|
|
|
|
toComplexResponse: response];
|
2008-03-26 21:30:53 +01:00
|
|
|
}
|
2008-06-13 22:22:51 +02:00
|
|
|
// NSLog (@"/adding properties with url");
|
|
|
|
|
|
|
|
[urls release];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
- (id) davCalendarMultiget: (id) queryContext
|
2006-06-15 21:34:10 +02:00
|
|
|
{
|
2008-06-13 22:22:51 +02:00
|
|
|
WOResponse *r;
|
|
|
|
id <DOMDocument> document;
|
|
|
|
id <DOMElement> documentElement;
|
|
|
|
NSString **properties;
|
2008-03-26 21:30:53 +01:00
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
r = [context response];
|
|
|
|
[r setStatus: 207];
|
|
|
|
[r setContentEncoding: NSUTF8StringEncoding];
|
|
|
|
[r setHeader: @"text/xml; charset=\"utf-8\"" forKey: @"content-type"];
|
|
|
|
[r setHeader: @"no-cache" forKey: @"pragma"];
|
|
|
|
[r setHeader: @"no-cache" forKey: @"cache-control"];
|
|
|
|
[r appendContentString:@"<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n"];
|
|
|
|
[r appendContentString: @"<D:multistatus xmlns:D=\"DAV:\""
|
|
|
|
@" xmlns:C=\"urn:ietf:params:xml:ns:caldav\">\r\n"];
|
2008-03-26 21:30:53 +01:00
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
document = [[context request] contentAsDOMDocument];
|
|
|
|
documentElement = [document documentElement];
|
|
|
|
properties = [[self _parseRequestedProperties: documentElement]
|
|
|
|
asPointersOfObjects];
|
|
|
|
[self _appendComponentProperties: properties
|
|
|
|
matchingURLs: [documentElement getElementsByTagName: @"href"]
|
|
|
|
toResponse: r];
|
|
|
|
[r appendContentString:@"</D:multistatus>\r\n"];
|
|
|
|
free (properties);
|
|
|
|
|
|
|
|
return r;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
- (Class) objectClassForContent: (NSString *) content
|
2006-10-11 20:48:25 +02:00
|
|
|
{
|
2008-06-13 22:22:51 +02:00
|
|
|
iCalCalendar *calendar;
|
|
|
|
NSArray *elements;
|
|
|
|
NSString *firstTag;
|
|
|
|
Class objectClass;
|
2006-10-11 20:48:25 +02:00
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
objectClass = Nil;
|
2006-10-11 20:48:25 +02:00
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
calendar = [iCalCalendar parseSingleFromSource: content];
|
|
|
|
if (calendar)
|
|
|
|
{
|
|
|
|
elements = [calendar allObjects];
|
|
|
|
if ([elements count])
|
|
|
|
{
|
|
|
|
firstTag = [[[elements objectAtIndex: 0] tag] uppercaseString];
|
|
|
|
if ([firstTag isEqualToString: @"VEVENT"])
|
|
|
|
objectClass = [SOGoAppointmentObject class];
|
|
|
|
else if ([firstTag isEqualToString: @"VTODO"])
|
|
|
|
objectClass = [SOGoTaskObject class];
|
|
|
|
}
|
2006-10-11 20:48:25 +02:00
|
|
|
}
|
2008-06-13 22:22:51 +02:00
|
|
|
|
|
|
|
return objectClass;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) requestNamedIsHandledLater: (NSString *) name
|
|
|
|
{
|
|
|
|
return [name isEqualToString: @"OPTIONS"];
|
|
|
|
}
|
|
|
|
|
2008-06-30 23:11:20 +02:00
|
|
|
- (id) lookupComponentByUID: (NSString *) uid
|
|
|
|
{
|
|
|
|
NSString *filename;
|
|
|
|
id component;
|
|
|
|
|
|
|
|
filename = [self resourceNameForEventUID: uid];
|
|
|
|
if (filename)
|
|
|
|
{
|
|
|
|
component = [self lookupName: filename inContext: context acquire: NO];
|
|
|
|
if ([component isKindOfClass: [NSException class]])
|
|
|
|
component = nil;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
component = nil;
|
|
|
|
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
- (id) lookupName: (NSString *)_key
|
|
|
|
inContext: (id)_ctx
|
|
|
|
acquire: (BOOL)_flag
|
|
|
|
{
|
|
|
|
id obj;
|
|
|
|
NSString *url;
|
|
|
|
BOOL handledLater;
|
|
|
|
|
|
|
|
/* first check attributes directly bound to the application */
|
|
|
|
handledLater = [self requestNamedIsHandledLater: _key];
|
|
|
|
if (handledLater)
|
|
|
|
obj = nil;
|
2006-10-11 20:48:25 +02:00
|
|
|
else
|
2008-06-13 22:22:51 +02:00
|
|
|
{
|
|
|
|
obj = [super lookupName:_key inContext:_ctx acquire:NO];
|
|
|
|
if (!obj)
|
|
|
|
{
|
|
|
|
if ([self isValidContentName:_key])
|
|
|
|
{
|
2008-07-14 17:14:40 +02:00
|
|
|
url = [[[_ctx request] uri] urlWithoutParameters];
|
|
|
|
if ([url hasSuffix: @"AsTask"])
|
|
|
|
obj = [SOGoTaskObject objectWithName: _key
|
|
|
|
inContainer: self];
|
|
|
|
else if ([url hasSuffix: @"AsAppointment"])
|
|
|
|
obj = [SOGoAppointmentObject objectWithName: _key
|
|
|
|
inContainer: self];
|
2008-07-14 18:46:10 +02:00
|
|
|
[obj setIsNew: YES];
|
2008-06-13 22:22:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!obj)
|
|
|
|
obj = [NSException exceptionWithHTTPStatus:404 /* Not Found */];
|
|
|
|
}
|
2006-10-11 20:48:25 +02:00
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
if (obj)
|
|
|
|
[[SOGoCache sharedCache] registerObject: obj
|
|
|
|
withName: _key
|
|
|
|
inContainer: container];
|
|
|
|
|
|
|
|
return obj;
|
2006-10-11 20:48:25 +02:00
|
|
|
}
|
|
|
|
|
2008-06-30 20:52:20 +02:00
|
|
|
- (NSDictionary *) freebusyResponseForRecipient: (NSString *) recipient
|
|
|
|
withUser: (SOGoUser *) user
|
|
|
|
andCalendarData: (NSString *) calendarData
|
|
|
|
{
|
|
|
|
NSDictionary *response;
|
|
|
|
NSMutableArray *content;
|
|
|
|
|
|
|
|
content = [NSMutableArray new];
|
|
|
|
|
|
|
|
[content addObject: davElementWithContent (@"recipient", XMLNS_CALDAV, recipient)];
|
|
|
|
if (user)
|
|
|
|
{
|
|
|
|
[content addObject: davElementWithContent (@"request-status", XMLNS_CALDAV,
|
|
|
|
@"2.0;Success")];
|
|
|
|
[content addObject: davElementWithContent (@"calendar-data", XMLNS_CALDAV,
|
|
|
|
calendarData)];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
[content addObject:
|
|
|
|
davElementWithContent (@"request-status", XMLNS_CALDAV,
|
|
|
|
@"3.7;Invalid Calendar User")];
|
|
|
|
response = davElementWithContent (@"response", XMLNS_CALDAV, content);
|
|
|
|
[content release];
|
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDictionary *) caldavFreeBusyRequestOnRecipient: (NSString *) recipient
|
|
|
|
from: (NSCalendarDate *) start
|
|
|
|
to: (NSCalendarDate *) to
|
|
|
|
{
|
|
|
|
LDAPUserManager *um;
|
|
|
|
SOGoUser *user;
|
|
|
|
NSString *lRecipient, *login, *calendarData;
|
|
|
|
SOGoFreeBusyObject *freebusy;
|
|
|
|
|
|
|
|
user = nil;
|
|
|
|
calendarData = nil;
|
|
|
|
|
|
|
|
lRecipient = [recipient lowercaseString];
|
|
|
|
if ([lRecipient hasPrefix: @"mailto:"])
|
|
|
|
{
|
|
|
|
um = [LDAPUserManager sharedUserManager];
|
|
|
|
login = [um getUIDForEmail: [lRecipient substringFromIndex: 7]];
|
|
|
|
if ([login length])
|
|
|
|
{
|
|
|
|
user = [SOGoUser userWithLogin: login roles: nil];
|
|
|
|
freebusy = [[user homeFolderInContext: context]
|
|
|
|
freeBusyObject: @"freebusy.ifb"
|
|
|
|
inContext: context];
|
|
|
|
calendarData = [freebusy contentAsStringWithMethod: @"REPLY"
|
|
|
|
from: start to: to];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return [self freebusyResponseForRecipient: recipient
|
|
|
|
withUser: user
|
|
|
|
andCalendarData: calendarData];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDictionary *) caldavFreeBusyRequest: (iCalFreeBusy *) freebusy
|
|
|
|
from: (NSString *) originator
|
|
|
|
to: (NSArray *) recipients
|
|
|
|
{
|
|
|
|
NSDictionary *responseElement;
|
|
|
|
NSMutableArray *elements;
|
|
|
|
NSString *recipient;
|
2008-07-05 00:25:27 +02:00
|
|
|
NSEnumerator *allRecipients;
|
2008-06-30 20:52:20 +02:00
|
|
|
NSCalendarDate *startDate, *endDate;
|
|
|
|
|
|
|
|
elements = [NSMutableArray new];
|
|
|
|
[freebusy fillStartDate: &startDate andEndDate: &endDate];
|
2008-07-05 00:25:27 +02:00
|
|
|
allRecipients = [recipients objectEnumerator];
|
|
|
|
while ((recipient = [allRecipients nextObject]))
|
|
|
|
[elements addObject: [self caldavFreeBusyRequestOnRecipient: recipient
|
|
|
|
from: startDate to: endDate]];
|
2008-06-30 20:52:20 +02:00
|
|
|
responseElement = davElementWithContent (@"schedule-response",
|
|
|
|
XMLNS_CALDAV, elements);
|
|
|
|
[elements release];
|
|
|
|
|
|
|
|
return responseElement;
|
|
|
|
}
|
|
|
|
|
2008-07-08 17:44:50 +02:00
|
|
|
#warning we should merge this code with the code from the iTIP interpreter in MailPartViewer
|
2008-06-30 22:18:32 +02:00
|
|
|
- (NSDictionary *) caldavEventRequest: (iCalEvent *) event
|
2008-07-05 00:25:27 +02:00
|
|
|
withContent: (NSString *) iCalString
|
2008-06-30 22:18:32 +02:00
|
|
|
from: (NSString *) originator
|
|
|
|
to: (NSArray *) recipients
|
|
|
|
{
|
|
|
|
NSDictionary *responseElement;
|
2008-07-08 17:44:50 +02:00
|
|
|
NSArray *elements;
|
|
|
|
NSString *method, *filename;
|
|
|
|
SOGoAppointmentObject *apt;
|
2008-06-30 22:18:32 +02:00
|
|
|
|
2008-07-08 17:44:50 +02:00
|
|
|
filename = [NSString stringWithFormat: @"%@.ics", [event uid]];
|
|
|
|
apt = [SOGoAppointmentObject objectWithName: filename
|
|
|
|
andContent: iCalString
|
|
|
|
inContainer: self];
|
2008-06-30 22:18:32 +02:00
|
|
|
method = [[event parent] method];
|
|
|
|
if ([method isEqualToString: @"REQUEST"])
|
2008-07-08 17:44:50 +02:00
|
|
|
elements = [apt postCalDAVEventRequestTo: recipients];
|
2008-06-30 22:18:32 +02:00
|
|
|
else if ([method isEqualToString: @"REPLY"])
|
2008-07-09 17:54:39 +02:00
|
|
|
elements = [apt postCalDAVEventReplyTo: recipients];
|
|
|
|
else if ([method isEqualToString: @"CANCEL"])
|
|
|
|
elements = [apt postCalDAVEventCancelTo: recipients];
|
2008-07-08 17:44:50 +02:00
|
|
|
else
|
|
|
|
elements = nil;
|
|
|
|
|
|
|
|
if (elements)
|
|
|
|
responseElement = davElementWithContent (@"schedule-response",
|
|
|
|
XMLNS_CALDAV, elements);
|
2008-06-30 22:18:32 +02:00
|
|
|
else
|
|
|
|
responseElement = nil;
|
|
|
|
|
|
|
|
return responseElement;
|
|
|
|
}
|
|
|
|
|
2008-06-30 20:52:20 +02:00
|
|
|
- (WOResponse *) _caldavScheduleResponse: (NSDictionary *) tags
|
|
|
|
{
|
|
|
|
WOResponse *response;
|
|
|
|
|
|
|
|
response = [context response];
|
|
|
|
if (tags)
|
|
|
|
{
|
|
|
|
[response setStatus: 200];
|
|
|
|
[response appendContentString:@"<?xml version=\"1.0\""
|
|
|
|
@" encoding=\"utf-8\"?>\r\n"];
|
|
|
|
[response setHeader: @"application/xml; charset=utf-8"
|
|
|
|
forKey: @"Content-Type"];
|
|
|
|
[response appendContentString:
|
|
|
|
[tags asWebDavStringWithNamespaces: nil]];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
[response setStatus: 415];
|
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
2008-07-05 00:25:27 +02:00
|
|
|
- (WOResponse *) caldavScheduleRequest: (NSString *) iCalString
|
|
|
|
from: (NSString *) originator
|
|
|
|
to: (NSArray *) recipients
|
2008-06-30 20:52:20 +02:00
|
|
|
{
|
2008-07-05 00:25:27 +02:00
|
|
|
NSString *tag;
|
|
|
|
iCalCalendar *calendar;
|
2008-06-30 20:52:20 +02:00
|
|
|
iCalEntityObject *element;
|
|
|
|
NSDictionary *tags;
|
|
|
|
|
|
|
|
#warning needs to handle errors
|
2008-07-05 00:25:27 +02:00
|
|
|
calendar = [iCalCalendar parseSingleFromSource: iCalString];
|
|
|
|
element = [[calendar allObjects] objectAtIndex: 0];
|
|
|
|
tag = [[element tag] uppercaseString];
|
|
|
|
if ([tag isEqualToString: @"VFREEBUSY"])
|
|
|
|
tags = [self caldavFreeBusyRequest: (iCalFreeBusy *) element
|
|
|
|
from: originator to: recipients];
|
|
|
|
else if ([tag isEqualToString: @"VEVENT"])
|
|
|
|
tags = [self caldavEventRequest: (iCalEvent *) element
|
|
|
|
withContent: iCalString
|
|
|
|
from: originator to: recipients];
|
|
|
|
else
|
|
|
|
tags = nil;
|
2008-06-30 20:52:20 +02:00
|
|
|
|
|
|
|
return [self _caldavScheduleResponse: tags];
|
|
|
|
}
|
|
|
|
|
2008-07-04 20:22:06 +02:00
|
|
|
- (id) davPOSTRequest: (WORequest *) request
|
|
|
|
withContentType: (NSString *) cType
|
|
|
|
inContext: (WOContext *) localContext
|
2008-06-30 20:52:20 +02:00
|
|
|
{
|
|
|
|
id obj;
|
2008-07-05 00:25:27 +02:00
|
|
|
NSString *originator;
|
|
|
|
NSArray *recipients;
|
2008-06-30 20:52:20 +02:00
|
|
|
|
2008-07-04 20:22:06 +02:00
|
|
|
if ([cType hasPrefix: @"text/calendar"])
|
2008-06-30 20:52:20 +02:00
|
|
|
{
|
2008-07-05 00:25:27 +02:00
|
|
|
originator = [request headerForKey: @"originator"];
|
|
|
|
recipients = [[request headerForKey: @"recipient"]
|
|
|
|
componentsSeparatedByString: @", "];
|
|
|
|
obj = [self caldavScheduleRequest: [request contentAsString]
|
|
|
|
from: originator to: recipients];
|
2008-06-30 20:52:20 +02:00
|
|
|
}
|
2008-07-04 20:22:06 +02:00
|
|
|
else
|
|
|
|
obj = [super davPOSTRequest: request withContentType: cType
|
|
|
|
inContext: localContext];
|
2008-06-30 20:52:20 +02:00
|
|
|
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
- (NSArray *) davComplianceClassesInContext: (id)_ctx
|
2006-10-30 23:39:31 +01:00
|
|
|
{
|
2008-06-13 22:22:51 +02:00
|
|
|
NSMutableArray *classes;
|
|
|
|
NSArray *primaryClasses;
|
2006-10-30 23:39:31 +01:00
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
classes = [NSMutableArray new];
|
|
|
|
[classes autorelease];
|
2006-10-30 23:39:31 +01:00
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
primaryClasses = [super davComplianceClassesInContext: _ctx];
|
|
|
|
if (primaryClasses)
|
|
|
|
[classes addObjectsFromArray: primaryClasses];
|
|
|
|
[classes addObject: @"calendar-access"];
|
2008-06-30 20:52:20 +02:00
|
|
|
[classes addObject: @"calendar-schedule"];
|
2008-06-13 22:22:51 +02:00
|
|
|
|
|
|
|
return classes;
|
2006-10-30 23:39:31 +01:00
|
|
|
}
|
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
- (NSArray *) groupDavResourceType
|
2007-04-26 03:16:19 +02:00
|
|
|
{
|
2008-06-13 22:22:51 +02:00
|
|
|
return [NSArray arrayWithObjects: @"vevent-collection",
|
|
|
|
@"vtodo-collection", nil];
|
|
|
|
}
|
2007-04-26 03:16:19 +02:00
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
- (NSArray *) davResourceType
|
|
|
|
{
|
|
|
|
static NSArray *colType = nil;
|
|
|
|
NSArray *cdCol, *gdRT, *gdVEventCol, *gdVTodoCol;
|
|
|
|
|
|
|
|
if (!colType)
|
2007-04-26 03:16:19 +02:00
|
|
|
{
|
2008-06-13 22:22:51 +02:00
|
|
|
gdRT = [self groupDavResourceType];
|
|
|
|
gdVEventCol = [NSArray arrayWithObjects: [gdRT objectAtIndex: 0],
|
|
|
|
XMLNS_GROUPDAV, nil];
|
|
|
|
gdVTodoCol = [NSArray arrayWithObjects: [gdRT objectAtIndex: 1],
|
|
|
|
XMLNS_GROUPDAV, nil];
|
|
|
|
cdCol = [NSArray arrayWithObjects: @"calendar", XMLNS_CALDAV, nil];
|
|
|
|
colType = [NSArray arrayWithObjects: @"collection", cdCol,
|
|
|
|
gdVEventCol, gdVTodoCol, nil];
|
|
|
|
[colType retain];
|
2007-04-26 03:16:19 +02:00
|
|
|
}
|
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
return colType;
|
2007-04-26 03:16:19 +02:00
|
|
|
}
|
|
|
|
|
2008-06-30 20:52:20 +02:00
|
|
|
- (NSString *) davCollectionTag
|
|
|
|
{
|
|
|
|
NSArray *records;
|
|
|
|
GCSFolder *folder;
|
|
|
|
static EOFetchSpecification *cTagSpec = nil;
|
|
|
|
EOSortOrdering *ordering;
|
|
|
|
NSNumber *lastModified;
|
|
|
|
NSString *cTag;
|
|
|
|
|
|
|
|
folder = [self ocsFolder];
|
2008-09-22 22:33:30 +02:00
|
|
|
ordering = [EOSortOrdering sortOrderingWithKey: @"c_lastmodified"
|
|
|
|
selector: EOCompareDescending];
|
|
|
|
cTagSpec = [EOFetchSpecification
|
|
|
|
fetchSpecificationWithEntityName: [folder folderName]
|
|
|
|
qualifier: nil
|
|
|
|
sortOrderings: [NSArray arrayWithObject: ordering]];
|
2008-06-30 20:52:20 +02:00
|
|
|
|
|
|
|
records = [folder fetchFields: [NSArray arrayWithObject: @"c_lastmodified"]
|
2008-09-22 22:33:30 +02:00
|
|
|
fetchSpecification: cTagSpec
|
|
|
|
ignoreDeleted: NO];
|
2008-06-30 20:52:20 +02:00
|
|
|
if ([records count])
|
|
|
|
{
|
|
|
|
lastModified = [[records objectAtIndex: 0] objectForKey: @"c_lastmodified"];
|
|
|
|
cTag = [lastModified stringValue];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
cTag = @"-1";
|
|
|
|
|
|
|
|
return cTag;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) davDescription
|
|
|
|
{
|
|
|
|
return @"";
|
|
|
|
}
|
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
/* vevent UID handling */
|
2007-03-07 22:27:19 +01:00
|
|
|
|
2008-06-30 23:11:20 +02:00
|
|
|
- (NSString *) resourceNameForEventUID: (NSString *) uid
|
|
|
|
inFolder: (GCSFolder *) folder
|
2008-06-13 22:22:51 +02:00
|
|
|
{
|
|
|
|
static NSArray *nameFields = nil;
|
|
|
|
EOQualifier *qualifier;
|
2008-06-30 23:11:20 +02:00
|
|
|
NSArray *records;
|
|
|
|
NSString *filename;
|
|
|
|
unsigned int count;
|
|
|
|
|
2008-06-30 23:46:05 +02:00
|
|
|
filename = nil;
|
|
|
|
|
2008-06-30 23:11:20 +02:00
|
|
|
if (!nameFields)
|
2008-06-13 22:22:51 +02:00
|
|
|
nameFields = [[NSArray alloc] initWithObjects: @"c_name", nil];
|
2008-06-30 23:11:20 +02:00
|
|
|
|
|
|
|
if (uid && folder)
|
|
|
|
{
|
2008-07-05 00:25:27 +02:00
|
|
|
qualifier = [EOQualifier qualifierWithQualifierFormat: @"c_uid = %@",
|
|
|
|
uid];
|
2008-06-30 23:11:20 +02:00
|
|
|
records = [folder fetchFields: nameFields matchingQualifier: qualifier];
|
|
|
|
count = [records count];
|
|
|
|
if (count)
|
|
|
|
{
|
|
|
|
filename = [[records objectAtIndex:0] valueForKey:@"c_name"];
|
|
|
|
if (count > 1)
|
|
|
|
[self errorWithFormat:
|
2008-07-05 00:25:27 +02:00
|
|
|
@"The storage contains more than file with UID '%@'",
|
|
|
|
uid];
|
2008-06-30 23:11:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return filename;
|
2008-06-13 22:22:51 +02:00
|
|
|
}
|
2007-03-07 22:27:19 +01:00
|
|
|
|
2008-06-30 23:11:20 +02:00
|
|
|
- (NSString *) resourceNameForEventUID: (NSString *) uid
|
2008-06-13 22:22:51 +02:00
|
|
|
{
|
|
|
|
/* caches UIDs */
|
|
|
|
GCSFolder *folder;
|
|
|
|
NSString *rname;
|
2008-06-30 23:11:20 +02:00
|
|
|
|
|
|
|
rname = nil;
|
|
|
|
if (uid)
|
2007-03-07 22:27:19 +01:00
|
|
|
{
|
2008-06-30 23:11:20 +02:00
|
|
|
if (!uidToFilename)
|
|
|
|
uidToFilename = [NSMutableDictionary new];
|
|
|
|
rname = [uidToFilename objectForKey: uid];
|
|
|
|
if (!rname)
|
|
|
|
{
|
|
|
|
folder = [self ocsFolder];
|
|
|
|
rname = [self resourceNameForEventUID: uid inFolder: folder];
|
|
|
|
if (rname)
|
|
|
|
[uidToFilename setObject: rname forKey: uid];
|
|
|
|
}
|
2007-03-07 22:27:19 +01:00
|
|
|
}
|
2008-06-30 23:11:20 +02:00
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
return rname;
|
2007-03-07 22:27:19 +01:00
|
|
|
}
|
|
|
|
|
2007-11-29 17:14:11 +01:00
|
|
|
- (NSArray *) subscriptionRoles
|
|
|
|
{
|
|
|
|
return [NSArray arrayWithObjects:
|
|
|
|
SOGoRole_ObjectCreator, SOGoRole_ObjectEraser,
|
|
|
|
SOGoCalendarRole_PublicResponder,
|
|
|
|
SOGoCalendarRole_PublicModifier,
|
|
|
|
SOGoCalendarRole_PublicViewer,
|
|
|
|
SOGoCalendarRole_PublicDAndTViewer,
|
|
|
|
SOGoCalendarRole_PrivateResponder,
|
|
|
|
SOGoCalendarRole_PrivateModifier,
|
|
|
|
SOGoCalendarRole_PrivateViewer,
|
|
|
|
SOGoCalendarRole_PrivateDAndTViewer,
|
|
|
|
SOGoCalendarRole_ConfidentialResponder,
|
|
|
|
SOGoCalendarRole_ConfidentialModifier,
|
|
|
|
SOGoCalendarRole_ConfidentialViewer,
|
|
|
|
SOGoCalendarRole_ConfidentialDAndTViewer, nil];
|
|
|
|
}
|
|
|
|
|
2007-04-26 03:16:19 +02:00
|
|
|
- (NSString *) roleForComponentsWithAccessClass: (iCalAccessClass) accessClass
|
|
|
|
forUser: (NSString *) uid
|
|
|
|
{
|
|
|
|
NSString *accessRole, *prefix, *currentRole, *suffix;
|
|
|
|
NSEnumerator *acls;
|
2007-11-26 18:40:44 +01:00
|
|
|
NSMutableDictionary *userRoles;
|
2007-04-26 03:16:19 +02:00
|
|
|
|
|
|
|
accessRole = nil;
|
|
|
|
|
|
|
|
if (accessClass == iCalAccessPublic)
|
|
|
|
prefix = @"Public";
|
|
|
|
else if (accessClass == iCalAccessPrivate)
|
|
|
|
prefix = @"Private";
|
|
|
|
else
|
|
|
|
prefix = @"Confidential";
|
|
|
|
|
2007-11-26 18:40:44 +01:00
|
|
|
userRoles = [aclMatrix objectForKey: uid];
|
|
|
|
if (!userRoles)
|
|
|
|
{
|
|
|
|
userRoles = [NSMutableDictionary dictionaryWithCapacity: 3];
|
|
|
|
[aclMatrix setObject: userRoles forKey: uid];
|
|
|
|
}
|
|
|
|
|
|
|
|
accessRole = [userRoles objectForKey: prefix];
|
|
|
|
if (!accessRole)
|
|
|
|
{
|
|
|
|
acls = [[self aclsForUser: uid] objectEnumerator];
|
2007-04-26 03:16:19 +02:00
|
|
|
currentRole = [acls nextObject];
|
2007-11-26 18:40:44 +01:00
|
|
|
while (currentRole && !accessRole)
|
|
|
|
if ([currentRole hasPrefix: prefix])
|
|
|
|
{
|
|
|
|
suffix = [currentRole substringFromIndex: [prefix length]];
|
|
|
|
accessRole = [NSString stringWithFormat: @"Component%@", suffix];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
currentRole = [acls nextObject];
|
|
|
|
if (!accessRole)
|
|
|
|
accessRole = @"";
|
|
|
|
[userRoles setObject: accessRole forKey: prefix];
|
|
|
|
}
|
2007-04-26 03:16:19 +02:00
|
|
|
|
|
|
|
return accessRole;
|
|
|
|
}
|
|
|
|
|
2006-12-14 22:20:13 +01:00
|
|
|
- (NSArray *) fetchFreeBusyInfosFrom: (NSCalendarDate *) _startDate
|
2006-08-16 00:04:37 +02:00
|
|
|
to: (NSCalendarDate *) _endDate
|
2006-06-15 21:34:10 +02:00
|
|
|
{
|
|
|
|
static NSArray *infos = nil; // TODO: move to a plist file
|
2006-10-26 02:08:24 +02:00
|
|
|
|
|
|
|
if (!infos)
|
2007-07-24 20:45:52 +02:00
|
|
|
infos = [[NSArray alloc] initWithObjects: @"c_partmails", @"c_partstates",
|
2008-06-19 20:31:18 +02:00
|
|
|
@"c_isopaque", @"c_status", @"c_cycleinfo", nil];
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2008-05-16 17:52:19 +02:00
|
|
|
return [self fetchFields: infos
|
|
|
|
from: _startDate to: _endDate
|
2007-11-21 18:23:51 +01:00
|
|
|
title: nil
|
2008-05-16 17:52:19 +02:00
|
|
|
component: @"vevent"
|
|
|
|
additionalFilters: nil];
|
2006-10-26 02:08:24 +02:00
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2006-08-16 00:04:37 +02:00
|
|
|
- (NSArray *) fetchCoreInfosFrom: (NSCalendarDate *) _startDate
|
2006-10-11 20:48:25 +02:00
|
|
|
to: (NSCalendarDate *) _endDate
|
2007-11-21 18:23:51 +01:00
|
|
|
title: (NSString *) title
|
2006-10-11 20:48:25 +02:00
|
|
|
component: (id) _component
|
2008-05-16 17:52:19 +02:00
|
|
|
{
|
|
|
|
return [self fetchCoreInfosFrom: _startDate to: _endDate title: title
|
|
|
|
component: _component additionalFilters: nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) fetchCoreInfosFrom: (NSCalendarDate *) _startDate
|
|
|
|
to: (NSCalendarDate *) _endDate
|
|
|
|
title: (NSString *) title
|
|
|
|
component: (id) _component
|
|
|
|
additionalFilters: (NSString *) filters
|
2006-06-15 21:34:10 +02:00
|
|
|
{
|
|
|
|
static NSArray *infos = nil; // TODO: move to a plist file
|
2006-08-16 00:04:37 +02:00
|
|
|
|
2006-10-11 20:48:25 +02:00
|
|
|
if (!infos)
|
2008-06-13 22:22:51 +02:00
|
|
|
infos = [[NSArray alloc] initWithObjects: @"c_name", @"c_content",
|
|
|
|
@"c_creationdate", @"c_lastmodified",
|
|
|
|
@"c_version", @"c_component", @"c_title",
|
|
|
|
@"c_location", @"c_orgmail", @"c_status",
|
|
|
|
@"c_classification", @"c_isallday",
|
|
|
|
@"c_isopaque", @"c_participants", @"c_partmails",
|
|
|
|
@"c_partstates", @"c_sequence", @"c_priority",
|
2008-07-16 04:12:18 +02:00
|
|
|
@"c_cycleinfo", @"c_iscycle", nil];
|
2006-10-11 20:48:25 +02:00
|
|
|
|
2007-11-21 18:23:51 +01:00
|
|
|
return [self fetchFields: infos from: _startDate to: _endDate title: title
|
2008-05-16 17:52:19 +02:00
|
|
|
component: _component
|
|
|
|
additionalFilters: filters];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* URL generation */
|
|
|
|
|
2006-08-16 00:04:37 +02:00
|
|
|
- (NSString *) baseURLForAptWithUID: (NSString *)_uid
|
|
|
|
inContext: (id)_ctx
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
// TODO: who calls this?
|
|
|
|
NSString *url;
|
|
|
|
|
|
|
|
if ([_uid length] == 0)
|
|
|
|
return nil;
|
|
|
|
|
|
|
|
url = [self baseURLInContext:_ctx];
|
2007-06-01 06:15:56 +02:00
|
|
|
if (![url hasSuffix: @"/"])
|
|
|
|
url = [url stringByAppendingString: @"/"];
|
2006-06-15 21:34:10 +02:00
|
|
|
|
|
|
|
// TODO: this should run a query to determine the uid!
|
|
|
|
return [url stringByAppendingString:_uid];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* folder management */
|
2007-11-08 18:12:30 +01:00
|
|
|
- (BOOL) create
|
|
|
|
{
|
|
|
|
BOOL rc;
|
|
|
|
NSUserDefaults *userSettings;
|
|
|
|
NSMutableDictionary *calendarSettings;
|
|
|
|
SOGoUser *ownerUser;
|
|
|
|
|
|
|
|
rc = [super create];
|
|
|
|
if (rc)
|
|
|
|
{
|
|
|
|
ownerUser = [SOGoUser userWithLogin: [self ownerInContext: context]
|
|
|
|
roles: nil];
|
|
|
|
userSettings = [ownerUser userSettings];
|
|
|
|
calendarSettings = [userSettings objectForKey: @"Calendar"];
|
|
|
|
if (!calendarSettings)
|
|
|
|
{
|
|
|
|
calendarSettings = [NSMutableDictionary dictionary];
|
|
|
|
[userSettings setObject: calendarSettings forKey: @"Calendar"];
|
|
|
|
}
|
|
|
|
[userSettings synchronize];
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2006-08-16 00:04:37 +02:00
|
|
|
- (id) lookupHomeFolderForUID: (NSString *) _uid
|
|
|
|
inContext: (id)_ctx
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
// TODO: DUP to SOGoGroupFolder
|
|
|
|
NSException *error = nil;
|
|
|
|
NSArray *path;
|
|
|
|
id ctx, result;
|
|
|
|
|
|
|
|
if (![_uid isNotNull])
|
|
|
|
return nil;
|
2007-06-01 06:15:56 +02:00
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
/* create subcontext, so that we don't destroy our environment */
|
|
|
|
|
2007-04-11 21:08:58 +02:00
|
|
|
if ((ctx = [context createSubContext]) == nil) {
|
2006-06-15 21:34:10 +02:00
|
|
|
[self errorWithFormat:@"could not create SOPE subcontext!"];
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* build path */
|
|
|
|
|
|
|
|
path = _uid != nil ? [NSArray arrayWithObjects:&_uid count:1] : nil;
|
|
|
|
|
|
|
|
/* traverse path */
|
|
|
|
|
|
|
|
result = [[ctx application] traversePathArray:path inContext:ctx
|
|
|
|
error:&error acquire:NO];
|
|
|
|
if (error != nil) {
|
2007-07-27 19:30:57 +02:00
|
|
|
[self errorWithFormat: @"folder lookup failed (c_uid=%@): %@",
|
2006-06-15 21:34:10 +02:00
|
|
|
_uid, error];
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
[self debugWithFormat:@"Note: got folder for uid %@ path %@: %@",
|
|
|
|
_uid, [path componentsJoinedByString:@"=>"], result];
|
2008-08-18 17:21:23 +02:00
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2007-01-04 15:37:07 +01:00
|
|
|
- (SOGoAppointmentFolder *) lookupCalendarFolderForUID: (NSString *) uid
|
|
|
|
{
|
2007-11-07 16:58:43 +01:00
|
|
|
SOGoFolder *currentContainer;
|
|
|
|
SOGoAppointmentFolders *parent;
|
|
|
|
NSException *error;
|
|
|
|
|
|
|
|
currentContainer = [[container container] container];
|
|
|
|
currentContainer = [currentContainer lookupName: uid
|
|
|
|
inContext: context
|
|
|
|
acquire: NO];
|
|
|
|
parent = [currentContainer lookupName: @"Calendar" inContext: context
|
|
|
|
acquire: NO];
|
|
|
|
currentContainer = [parent lookupName: @"personal" inContext: context
|
|
|
|
acquire: NO];
|
|
|
|
if (!currentContainer)
|
|
|
|
{
|
|
|
|
error = [parent newFolderWithName: [parent defaultFolderName]
|
|
|
|
andNameInContainer: @"personal"];
|
|
|
|
if (!error)
|
|
|
|
currentContainer = [parent lookupName: @"personal"
|
|
|
|
inContext: context
|
|
|
|
acquire: NO];
|
|
|
|
}
|
|
|
|
|
|
|
|
return (SOGoAppointmentFolder *) currentContainer;
|
2007-01-04 15:37:07 +01:00
|
|
|
}
|
|
|
|
|
2006-08-16 00:04:37 +02:00
|
|
|
- (NSArray *) lookupCalendarFoldersForUIDs: (NSArray *) _uids
|
|
|
|
inContext: (id)_ctx
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
/* Note: can return NSNull objects in the array! */
|
|
|
|
NSMutableArray *folders;
|
|
|
|
NSEnumerator *e;
|
2007-09-15 00:01:02 +02:00
|
|
|
NSString *uid, *ownerLogin;
|
|
|
|
id folder;
|
|
|
|
|
|
|
|
ownerLogin = [self ownerInContext: context];
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
if ([_uids count] == 0) return nil;
|
|
|
|
folders = [NSMutableArray arrayWithCapacity:16];
|
|
|
|
e = [_uids objectEnumerator];
|
2007-09-15 00:01:02 +02:00
|
|
|
while ((uid = [e nextObject]))
|
|
|
|
{
|
|
|
|
if ([uid isEqualToString: ownerLogin])
|
|
|
|
folder = self;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
folder = [self lookupCalendarFolderForUID: uid];
|
|
|
|
if (![folder isNotNull])
|
|
|
|
[self logWithFormat:@"Note: did not find folder for uid: '%@'", uid];
|
|
|
|
}
|
2007-11-07 16:58:43 +01:00
|
|
|
|
|
|
|
if (folder)
|
|
|
|
[folders addObject: folder];
|
2007-09-15 00:01:02 +02:00
|
|
|
}
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
return folders;
|
|
|
|
}
|
|
|
|
|
2006-08-16 00:04:37 +02:00
|
|
|
- (NSArray *) lookupFreeBusyObjectsForUIDs: (NSArray *) _uids
|
|
|
|
inContext: (id) _ctx
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
/* Note: can return NSNull objects in the array! */
|
|
|
|
NSMutableArray *objs;
|
|
|
|
NSEnumerator *e;
|
|
|
|
NSString *uid;
|
|
|
|
|
|
|
|
if ([_uids count] == 0) return nil;
|
|
|
|
objs = [NSMutableArray arrayWithCapacity:16];
|
|
|
|
e = [_uids objectEnumerator];
|
2008-05-16 17:52:19 +02:00
|
|
|
while ((uid = [e nextObject]))
|
|
|
|
{
|
|
|
|
id obj;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2008-05-16 17:52:19 +02:00
|
|
|
obj = [self lookupHomeFolderForUID:uid inContext:nil];
|
|
|
|
if ([obj isNotNull])
|
|
|
|
{
|
|
|
|
obj = [obj lookupName: @"freebusy.ifb" inContext: nil acquire: NO];
|
|
|
|
if ([obj isKindOfClass: [NSException class]])
|
|
|
|
obj = nil;
|
|
|
|
}
|
|
|
|
if (![obj isNotNull])
|
|
|
|
[self logWithFormat: @"Note: did not find freebusy.ifb for uid: '%@'",
|
|
|
|
uid];
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2008-05-16 17:52:19 +02:00
|
|
|
/* Note: intentionally add 'null' folders to allow a mapping */
|
|
|
|
if (!obj)
|
|
|
|
obj = [NSNull null];
|
|
|
|
[objs addObject: obj];
|
|
|
|
}
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
return objs;
|
|
|
|
}
|
|
|
|
|
2006-08-16 00:04:37 +02:00
|
|
|
- (NSArray *) uidsFromICalPersons: (NSArray *) _persons
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
/* Note: can return NSNull objects in the array! */
|
|
|
|
NSMutableArray *uids;
|
2007-05-09 20:25:51 +02:00
|
|
|
LDAPUserManager *um;
|
2006-06-15 21:34:10 +02:00
|
|
|
unsigned i, count;
|
2008-06-30 20:52:20 +02:00
|
|
|
iCalPerson *person;
|
|
|
|
NSString *email;
|
|
|
|
NSString *uid;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2008-06-30 20:52:20 +02:00
|
|
|
if (_persons)
|
2008-05-16 17:52:19 +02:00
|
|
|
{
|
2008-06-30 20:52:20 +02:00
|
|
|
count = [_persons count];
|
|
|
|
uids = [NSMutableArray arrayWithCapacity:count + 1];
|
|
|
|
um = [LDAPUserManager sharedUserManager];
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
person = [_persons objectAtIndex:i];
|
|
|
|
email = [person rfc822Email];
|
|
|
|
if ([email isNotNull])
|
|
|
|
uid = [um getUIDForEmail:email];
|
|
|
|
else
|
|
|
|
uid = nil;
|
|
|
|
|
|
|
|
if (!uid)
|
|
|
|
uid = (NSString *) [NSNull null];
|
|
|
|
[uids addObject: uid];
|
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
2008-06-30 20:52:20 +02:00
|
|
|
else
|
|
|
|
uids = nil;
|
2008-05-16 17:52:19 +02:00
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
return uids;
|
|
|
|
}
|
|
|
|
|
2008-06-30 20:52:20 +02:00
|
|
|
- (NSArray *) lookupCalendarFoldersForICalPerson: (NSArray *) _persons
|
|
|
|
inContext: (id) _ctx
|
2006-06-15 21:34:10 +02:00
|
|
|
{
|
|
|
|
/* Note: can return NSNull objects in the array! */
|
2008-06-30 20:52:20 +02:00
|
|
|
NSArray *uids, *folders;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2008-06-30 20:52:20 +02:00
|
|
|
uids = [self uidsFromICalPersons: _persons];
|
|
|
|
if (uids)
|
|
|
|
folders = [self lookupCalendarFoldersForUIDs: uids
|
|
|
|
inContext: _ctx];
|
|
|
|
else
|
|
|
|
folders = nil;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2008-06-30 20:52:20 +02:00
|
|
|
return folders;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2008-05-03 01:08:15 +02:00
|
|
|
// - (id) lookupGroupFolderForUIDs: (NSArray *) _uids
|
|
|
|
// inContext: (id)_ctx
|
|
|
|
// {
|
|
|
|
// SOGoCustomGroupFolder *folder;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2008-05-03 01:08:15 +02:00
|
|
|
// if (_uids == nil)
|
|
|
|
// return nil;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2008-05-03 01:08:15 +02:00
|
|
|
// folder = [[SOGoCustomGroupFolder alloc] initWithUIDs:_uids inContainer:self];
|
|
|
|
// return [folder autorelease];
|
|
|
|
// }
|
2006-08-16 00:04:37 +02:00
|
|
|
|
2008-05-03 01:08:15 +02:00
|
|
|
// - (id) lookupGroupCalendarFolderForUIDs: (NSArray *) _uids
|
|
|
|
// inContext: (id) _ctx
|
|
|
|
// {
|
|
|
|
// SOGoCustomGroupFolder *folder;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2008-05-03 01:08:15 +02:00
|
|
|
// if ((folder = [self lookupGroupFolderForUIDs:_uids inContext:_ctx]) == nil)
|
|
|
|
// return nil;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2008-05-03 01:08:15 +02:00
|
|
|
// folder = [folder lookupName:@"Calendar" inContext:_ctx acquire:NO];
|
|
|
|
// if (![folder isNotNull])
|
|
|
|
// return nil;
|
|
|
|
// if ([folder isKindOfClass:[NSException class]]) {
|
|
|
|
// [self debugWithFormat:@"Note: could not lookup 'Calendar' in folder: %@",
|
|
|
|
// folder];
|
|
|
|
// return nil;
|
|
|
|
// }
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2008-05-03 01:08:15 +02:00
|
|
|
// return folder;
|
|
|
|
// }
|
2006-06-15 21:34:10 +02:00
|
|
|
|
|
|
|
/* bulk fetches */
|
|
|
|
|
2007-09-15 00:01:02 +02:00
|
|
|
// #warning We only support ONE calendar per user at this time
|
|
|
|
// - (BOOL) _appendSubscribedFolders: (NSDictionary *) subscribedFolders
|
|
|
|
// toFolderList: (NSMutableArray *) calendarFolders
|
|
|
|
// {
|
|
|
|
// NSEnumerator *keys;
|
|
|
|
// NSString *currentKey;
|
|
|
|
// NSMutableDictionary *currentCalendar;
|
|
|
|
// BOOL firstShouldBeActive;
|
|
|
|
// unsigned int count;
|
|
|
|
|
|
|
|
// firstShouldBeActive = YES;
|
|
|
|
|
|
|
|
// keys = [[subscribedFolders allKeys] objectEnumerator];
|
|
|
|
// currentKey = [keys nextObject];
|
|
|
|
// count = 1;
|
|
|
|
// while (currentKey)
|
|
|
|
// {
|
|
|
|
// currentCalendar = [NSMutableDictionary new];
|
|
|
|
// [currentCalendar autorelease];
|
|
|
|
// [currentCalendar
|
|
|
|
// setDictionary: [subscribedFolders objectForKey: currentKey]];
|
|
|
|
// [currentCalendar setObject: currentKey forKey: @"folder"];
|
|
|
|
// [calendarFolders addObject: currentCalendar];
|
|
|
|
// if ([[currentCalendar objectForKey: @"active"] boolValue])
|
|
|
|
// firstShouldBeActive = NO;
|
|
|
|
// count++;
|
|
|
|
// currentKey = [keys nextObject];
|
|
|
|
// }
|
|
|
|
|
|
|
|
// return firstShouldBeActive;
|
|
|
|
// }
|
2007-04-02 21:24:49 +02:00
|
|
|
|
2007-09-15 00:01:02 +02:00
|
|
|
// - (NSArray *) calendarFolders
|
|
|
|
// {
|
|
|
|
// NSMutableDictionary *userCalendar, *calendarDict;
|
|
|
|
// NSMutableArray *calendarFolders;
|
|
|
|
// SOGoUser *calendarUser;
|
|
|
|
// BOOL firstActive;
|
|
|
|
|
|
|
|
// calendarFolders = [NSMutableArray new];
|
|
|
|
// [calendarFolders autorelease];
|
|
|
|
|
|
|
|
// calendarUser = [SOGoUser userWithLogin: [self ownerInContext: context]
|
|
|
|
// roles: nil];
|
|
|
|
// userCalendar = [NSMutableDictionary new];
|
|
|
|
// [userCalendar autorelease];
|
|
|
|
// [userCalendar setObject: @"/" forKey: @"folder"];
|
|
|
|
// [userCalendar setObject: @"Calendar" forKey: @"displayName"];
|
|
|
|
// [calendarFolders addObject: userCalendar];
|
|
|
|
|
|
|
|
// calendarDict = [[calendarUser userSettings] objectForKey: @"Calendar"];
|
|
|
|
// firstActive = [[calendarDict objectForKey: @"activateUserFolder"] boolValue];
|
|
|
|
// firstActive = ([self _appendSubscribedFolders:
|
|
|
|
// [calendarDict objectForKey: @"SubscribedFolders"]
|
|
|
|
// toFolderList: calendarFolders]
|
|
|
|
// || firstActive);
|
|
|
|
// [userCalendar setObject: [NSNumber numberWithBool: firstActive]
|
|
|
|
// forKey: @"active"];
|
|
|
|
|
|
|
|
// return calendarFolders;
|
|
|
|
// }
|
2007-04-02 21:24:49 +02:00
|
|
|
|
2007-06-01 06:15:56 +02:00
|
|
|
// - (NSArray *) fetchContentObjectNames
|
|
|
|
// {
|
|
|
|
// NSMutableArray *objectNames;
|
|
|
|
// NSArray *records;
|
|
|
|
// NSCalendarDate *today, *startDate, *endDate;
|
|
|
|
|
|
|
|
// #warning this should be user-configurable
|
|
|
|
// objectNames = [NSMutableArray array];
|
|
|
|
// today = [[NSCalendarDate calendarDate] beginOfDay];
|
|
|
|
// [today setTimeZone: timeZone];
|
|
|
|
|
|
|
|
// startDate = [today dateByAddingYears: 0 months: 0 days: -1
|
|
|
|
// hours: 0 minutes: 0 seconds: 0];
|
|
|
|
// endDate = [startDate dateByAddingYears: 0 months: 0 days: 2
|
|
|
|
// hours: 0 minutes: 0 seconds: 0];
|
|
|
|
// records = [self fetchFields: [NSArray arrayWithObject: @"c_name"]
|
|
|
|
// from: startDate to: endDate
|
|
|
|
// component: @"vevent"];
|
|
|
|
// [objectNames addObjectsFromArray: [records valueForKey: @"c_name"]];
|
|
|
|
// records = [self fetchFields: [NSArray arrayWithObject: @"c_name"]
|
|
|
|
// from: startDate to: endDate
|
|
|
|
// component: @"vtodo"];
|
|
|
|
// [objectNames addObjectsFromArray: [records valueForKey: @"c_name"]];
|
|
|
|
|
|
|
|
// return objectNames;
|
|
|
|
// }
|
2007-05-15 23:49:50 +02:00
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
/* folder type */
|
|
|
|
|
2007-02-09 22:21:35 +01:00
|
|
|
- (NSString *) folderType
|
|
|
|
{
|
|
|
|
return @"Appointment";
|
|
|
|
}
|
|
|
|
|
2006-08-16 00:04:37 +02:00
|
|
|
- (NSString *) outlookFolderClass
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
return @"IPF.Appointment";
|
|
|
|
}
|
|
|
|
|
2007-09-15 00:01:02 +02:00
|
|
|
- (BOOL) isActive
|
2007-08-24 20:47:32 +02:00
|
|
|
{
|
2007-09-15 00:01:02 +02:00
|
|
|
NSUserDefaults *settings;
|
2008-05-06 01:39:07 +02:00
|
|
|
NSArray *inactiveFolders;
|
2007-08-24 20:47:32 +02:00
|
|
|
|
2007-09-15 00:01:02 +02:00
|
|
|
settings = [[context activeUser] userSettings];
|
2008-05-06 01:39:07 +02:00
|
|
|
inactiveFolders
|
|
|
|
= [[settings objectForKey: @"Calendar"] objectForKey: @"InactiveFolders"];
|
2007-08-24 20:47:32 +02:00
|
|
|
|
2008-06-13 22:22:51 +02:00
|
|
|
return (![inactiveFolders containsObject: nameInContainer]);
|
2007-08-24 20:47:32 +02:00
|
|
|
}
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
@end /* SOGoAppointmentFolder */
|