2008-05-03 01:08:15 +02:00
|
|
|
/* SOGoUserFolder+Appointments.m - this file is part of SOGo
|
|
|
|
*
|
2010-09-14 20:18:10 +02:00
|
|
|
* Copyright (C) 2008-2010 Inverse inc.
|
2008-05-03 01:08:15 +02:00
|
|
|
*
|
|
|
|
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
|
|
|
*
|
|
|
|
* This file is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This file 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#import <Foundation/NSArray.h>
|
2008-07-10 23:30:56 +02:00
|
|
|
#import <Foundation/NSDictionary.h>
|
2008-07-04 18:06:09 +02:00
|
|
|
#import <Foundation/NSEnumerator.h>
|
2011-11-30 16:11:10 +01:00
|
|
|
#import <Foundation/NSNull.h>
|
2010-01-19 13:28:10 +01:00
|
|
|
#import <Foundation/NSValue.h>
|
2008-07-04 18:06:09 +02:00
|
|
|
|
2008-05-03 01:08:15 +02:00
|
|
|
#import <NGObjWeb/WOContext+SoObjects.h>
|
2008-07-10 23:30:56 +02:00
|
|
|
#import <NGObjWeb/WOResponse.h>
|
|
|
|
#import <NGExtensions/NSObject+Logs.h>
|
|
|
|
#import <NGExtensions/NSString+misc.h>
|
2010-01-15 00:19:19 +01:00
|
|
|
#import <DOM/DOMProtocols.h>
|
2008-07-10 23:30:56 +02:00
|
|
|
#import <SaxObjC/XMLNamespaces.h>
|
2008-05-03 01:08:15 +02:00
|
|
|
|
2010-01-15 00:19:19 +01:00
|
|
|
#import <SOGo/NSArray+Utilities.h>
|
2008-07-10 23:30:56 +02:00
|
|
|
#import <SOGo/NSObject+DAV.h>
|
|
|
|
#import <SOGo/NSString+DAV.h>
|
2010-01-15 00:19:19 +01:00
|
|
|
#import <SOGo/NSObject+Utilities.h>
|
|
|
|
#import <SOGo/SOGoGCSFolder.h>
|
|
|
|
#import <SOGo/SOGoUser.h>
|
|
|
|
#import <SOGo/SOGoUserSettings.h>
|
|
|
|
#import <SOGo/WOResponse+SOGo.h>
|
2009-10-21 23:17:11 +02:00
|
|
|
#import <SOGo/WORequest+SOGo.h>
|
|
|
|
|
2009-08-27 23:14:54 +02:00
|
|
|
#import "SOGoAppointmentFolders.h"
|
2008-05-03 01:08:15 +02:00
|
|
|
#import "SOGoUserFolder+Appointments.h"
|
|
|
|
|
2008-07-04 18:06:09 +02:00
|
|
|
@interface SOGoUserFolder (private)
|
|
|
|
|
|
|
|
- (SOGoAppointmentFolders *) privateCalendars: (NSString *) key
|
|
|
|
inContext: (WOContext *) localContext;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2008-05-03 01:08:15 +02:00
|
|
|
@implementation SOGoUserFolder (SOGoCalDAVSupport)
|
|
|
|
|
|
|
|
- (NSArray *) davCalendarUserAddressSet
|
|
|
|
{
|
2008-08-07 15:31:55 +02:00
|
|
|
NSArray *tag;
|
2008-05-03 01:08:15 +02:00
|
|
|
NSMutableArray *addresses;
|
|
|
|
NSEnumerator *emails;
|
2011-11-30 15:47:11 +01:00
|
|
|
NSMutableDictionary *doneEmails;
|
2008-05-03 01:08:15 +02:00
|
|
|
NSString *currentEmail;
|
2008-08-07 15:31:55 +02:00
|
|
|
SOGoUser *ownerUser;
|
2008-05-03 01:08:15 +02:00
|
|
|
|
|
|
|
addresses = [NSMutableArray array];
|
|
|
|
|
2011-11-30 15:47:11 +01:00
|
|
|
doneEmails = [NSMutableDictionary dictionary];
|
2009-08-25 23:28:24 +02:00
|
|
|
ownerUser = [SOGoUser userWithLogin: owner];
|
2008-08-07 15:31:55 +02:00
|
|
|
emails = [[ownerUser allEmails] objectEnumerator];
|
2008-05-03 01:08:15 +02:00
|
|
|
while ((currentEmail = [emails nextObject]))
|
|
|
|
{
|
2011-11-30 15:47:11 +01:00
|
|
|
if (![doneEmails objectForKey: currentEmail])
|
|
|
|
{
|
|
|
|
tag = [NSArray arrayWithObjects: @"href", XMLNS_WEBDAV, @"D",
|
|
|
|
[NSString stringWithFormat: @"mailto:%@", currentEmail],
|
|
|
|
nil];
|
|
|
|
[addresses addObject: tag];
|
|
|
|
[doneEmails setObject: [NSNull null] forKey: currentEmail];
|
|
|
|
}
|
2008-05-03 01:08:15 +02:00
|
|
|
}
|
|
|
|
|
2011-11-30 15:47:11 +01:00
|
|
|
tag = [NSArray arrayWithObjects: @"href", XMLNS_WEBDAV, @"D",
|
|
|
|
[NSString stringWithFormat: @"/SOGo/dav/%@/", nameInContainer],
|
|
|
|
nil];
|
|
|
|
[addresses addObjectUniquely: tag];
|
|
|
|
|
2008-05-03 01:08:15 +02:00
|
|
|
return addresses;
|
|
|
|
}
|
|
|
|
|
2012-03-19 21:57:35 +01:00
|
|
|
- (NSString *) davCalendarUserType
|
|
|
|
{
|
|
|
|
/* FIXME: not always true */
|
|
|
|
return @"INDIVIDUAL";
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) davEmailAddressSet
|
|
|
|
{
|
|
|
|
NSArray *tag;
|
|
|
|
NSMutableArray *addresses;
|
|
|
|
NSEnumerator *emails;
|
|
|
|
NSMutableDictionary *doneEmails;
|
|
|
|
NSString *currentEmail;
|
|
|
|
SOGoUser *ownerUser;
|
|
|
|
|
|
|
|
addresses = [NSMutableArray array];
|
|
|
|
|
|
|
|
doneEmails = [NSMutableDictionary dictionary];
|
|
|
|
ownerUser = [SOGoUser userWithLogin: owner];
|
|
|
|
emails = [[ownerUser allEmails] objectEnumerator];
|
|
|
|
while ((currentEmail = [emails nextObject]))
|
|
|
|
{
|
|
|
|
if (![doneEmails objectForKey: currentEmail])
|
|
|
|
{
|
|
|
|
tag = [NSArray arrayWithObjects: @"email-address", XMLNS_CalendarServerOrg, @"cso",
|
|
|
|
[NSString stringWithFormat: @"%@", currentEmail],
|
|
|
|
nil];
|
|
|
|
[addresses addObject: tag];
|
|
|
|
[doneEmails setObject: [NSNull null] forKey: currentEmail];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tag = [NSArray arrayWithObjects: @"href", XMLNS_WEBDAV, @"D",
|
|
|
|
[NSString stringWithFormat: @"/SOGo/dav/%@/", nameInContainer],
|
|
|
|
nil];
|
|
|
|
[addresses addObjectUniquely: tag];
|
|
|
|
|
|
|
|
return addresses;
|
|
|
|
}
|
|
|
|
|
2008-06-30 20:54:55 +02:00
|
|
|
/* CalDAV support */
|
|
|
|
- (NSArray *) davCalendarHomeSet
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
<C:calendar-home-set xmlns:D="DAV:"
|
|
|
|
xmlns:C="urn:ietf:params:xml:ns:caldav">
|
|
|
|
<D:href>http://cal.example.com/home/bernard/calendars/</D:href>
|
|
|
|
</C:calendar-home-set>
|
|
|
|
|
|
|
|
Note: this is the *container* for calendar collections, not the
|
|
|
|
collections itself. So for use its the home folder, the
|
|
|
|
public folder and the groups folder.
|
|
|
|
*/
|
|
|
|
NSArray *tag;
|
|
|
|
SOGoAppointmentFolders *parent;
|
|
|
|
|
|
|
|
parent = [self privateCalendars: @"Calendar" inContext: context];
|
2010-01-21 00:09:35 +01:00
|
|
|
tag = [NSArray arrayWithObjects: @"href", XMLNS_WEBDAV, @"D",
|
2009-10-21 23:17:11 +02:00
|
|
|
[parent davURLAsString], nil];
|
2008-06-30 20:54:55 +02:00
|
|
|
|
|
|
|
return [NSArray arrayWithObject: tag];
|
|
|
|
}
|
|
|
|
|
2010-01-15 00:19:19 +01:00
|
|
|
- (NSArray *) _davSpecialCalendarURLWithName: (NSString *) name
|
2008-06-30 20:54:55 +02:00
|
|
|
{
|
|
|
|
SOGoAppointmentFolders *parent;
|
2010-01-15 00:19:19 +01:00
|
|
|
NSArray *tag, *response;
|
2010-01-21 00:09:35 +01:00
|
|
|
NSString *parentURL;
|
2008-06-30 20:54:55 +02:00
|
|
|
|
2010-09-14 20:18:10 +02:00
|
|
|
// We do NOT return the schedule-inbox-URL to iCal clients
|
|
|
|
// if the current user isn't the owner of it. This is to prevent
|
|
|
|
// iCal from doing a PROPFIND on it later on since it'll
|
|
|
|
// ask for the schedule-inbox-URL.
|
|
|
|
if ([[context request] isICal] &&
|
|
|
|
[name isEqualToString: @"inbox"] &&
|
|
|
|
![owner isEqualToString: [[context activeUser] login]])
|
|
|
|
return nil;
|
|
|
|
|
2010-01-21 00:09:35 +01:00
|
|
|
parent = [self privateCalendars: @"Calendar" inContext: context];
|
|
|
|
parentURL = [parent davURLAsString];
|
|
|
|
tag = [NSArray arrayWithObjects: @"href", XMLNS_WEBDAV, @"D",
|
|
|
|
[NSString stringWithFormat: @"%@%@/", parentURL, name],
|
|
|
|
nil];
|
|
|
|
response = [NSArray arrayWithObject: tag];
|
2008-05-03 01:08:15 +02:00
|
|
|
|
2010-01-15 00:19:19 +01:00
|
|
|
return response;
|
2008-06-30 20:54:55 +02:00
|
|
|
}
|
|
|
|
|
2009-07-22 15:22:48 +02:00
|
|
|
- (NSArray *) davCalendarScheduleInboxURL
|
2008-06-30 20:54:55 +02:00
|
|
|
{
|
2010-01-15 00:19:19 +01:00
|
|
|
return [self _davSpecialCalendarURLWithName: @"inbox"];
|
2008-06-30 20:54:55 +02:00
|
|
|
}
|
|
|
|
|
2009-07-22 15:22:48 +02:00
|
|
|
- (NSArray *) davCalendarScheduleOutboxURL
|
2008-06-30 20:54:55 +02:00
|
|
|
{
|
2010-01-15 00:19:19 +01:00
|
|
|
return [self _davSpecialCalendarURLWithName: @"personal"];
|
2008-06-30 20:54:55 +02:00
|
|
|
}
|
|
|
|
|
2010-01-15 00:19:19 +01:00
|
|
|
- (NSArray *) _calendarProxiedUsersWithWriteAccess: (BOOL) write
|
2008-06-30 20:54:55 +02:00
|
|
|
{
|
2010-01-19 13:28:10 +01:00
|
|
|
NSMutableDictionary *proxiedUsers;
|
|
|
|
NSArray *references, *elements;
|
|
|
|
NSString *currentLogin;
|
|
|
|
NSNumber *yesNumber;
|
|
|
|
SOGoAppointmentFolders *parentFolder;
|
|
|
|
SOGoUserSettings *us;
|
2010-01-15 00:19:19 +01:00
|
|
|
int count, max;
|
|
|
|
|
2010-01-19 13:28:10 +01:00
|
|
|
yesNumber = [NSNumber numberWithBool: YES];
|
|
|
|
|
|
|
|
us = [[SOGoUser userWithLogin: owner] userSettings];
|
|
|
|
references = [us subscribedCalendars];
|
|
|
|
max = [references count];
|
|
|
|
proxiedUsers = [NSMutableDictionary dictionaryWithCapacity: max];
|
2010-01-15 00:19:19 +01:00
|
|
|
for (count = 0; count < max; count++)
|
2008-07-10 23:30:56 +02:00
|
|
|
{
|
2010-01-19 13:28:10 +01:00
|
|
|
elements = [[references objectAtIndex: count]
|
|
|
|
componentsSeparatedByString: @":"];
|
|
|
|
if ([elements count])
|
|
|
|
{
|
|
|
|
currentLogin = [elements objectAtIndex: 0];
|
|
|
|
if (![proxiedUsers objectForKey: currentLogin])
|
|
|
|
{
|
|
|
|
parentFolder = [[container lookupName: currentLogin
|
|
|
|
inContext: context
|
|
|
|
acquire: NO]
|
|
|
|
lookupName: @"Calendar"
|
|
|
|
inContext: context acquire: NO];
|
|
|
|
if ([parentFolder hasProxyCalendarsWithWriteAccess: write
|
|
|
|
forUserWithLogin: owner])
|
|
|
|
[proxiedUsers setObject: yesNumber forKey: currentLogin];
|
|
|
|
}
|
|
|
|
}
|
2008-07-10 23:30:56 +02:00
|
|
|
}
|
|
|
|
|
2010-01-19 13:28:10 +01:00
|
|
|
return [proxiedUsers allKeys];
|
2008-07-10 23:30:56 +02:00
|
|
|
}
|
|
|
|
|
2010-01-15 00:19:19 +01:00
|
|
|
- (void) _addGroupMembershipToArray: (NSMutableArray *) groups
|
|
|
|
forWriteAccess: (BOOL) write
|
2008-07-10 23:30:56 +02:00
|
|
|
{
|
2010-01-15 00:19:19 +01:00
|
|
|
NSArray *proxiedUsers, *tag;
|
|
|
|
NSString *appName, *groupId, *proxiedUser;
|
|
|
|
int count, max;
|
2008-07-10 23:30:56 +02:00
|
|
|
|
2010-01-15 00:19:19 +01:00
|
|
|
proxiedUsers = [self _calendarProxiedUsersWithWriteAccess: write];
|
|
|
|
max = [proxiedUsers count];
|
|
|
|
if (max)
|
2008-07-10 23:30:56 +02:00
|
|
|
{
|
2010-01-15 00:19:19 +01:00
|
|
|
appName = [[context request] applicationName];
|
|
|
|
groupId = [NSString stringWithFormat: @"calendar-proxy-%@",
|
|
|
|
(write ? @"write" : @"read")];
|
|
|
|
for (count = 0; count < max; count++)
|
|
|
|
{
|
|
|
|
proxiedUser = [proxiedUsers objectAtIndex: count];
|
2010-01-21 00:09:35 +01:00
|
|
|
tag = [NSArray arrayWithObjects: @"href", XMLNS_WEBDAV, @"D",
|
2010-01-15 00:19:19 +01:00
|
|
|
[NSString stringWithFormat: @"/%@/dav/%@/%@/",
|
|
|
|
appName, proxiedUser, groupId],
|
|
|
|
nil];
|
|
|
|
[groups addObject: tag];
|
|
|
|
}
|
2008-07-10 23:30:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-15 00:19:19 +01:00
|
|
|
- (NSArray *) davGroupMembership
|
2008-07-10 23:30:56 +02:00
|
|
|
{
|
2010-01-15 00:19:19 +01:00
|
|
|
NSMutableArray *groups;
|
2008-07-10 23:30:56 +02:00
|
|
|
|
2010-01-15 00:19:19 +01:00
|
|
|
groups = [NSMutableArray array];
|
2008-07-10 23:30:56 +02:00
|
|
|
|
2010-01-15 00:19:19 +01:00
|
|
|
[self _addGroupMembershipToArray: groups
|
|
|
|
forWriteAccess: YES];
|
|
|
|
[self _addGroupMembershipToArray: groups
|
|
|
|
forWriteAccess: NO];
|
2008-07-10 23:30:56 +02:00
|
|
|
|
2010-01-15 00:19:19 +01:00
|
|
|
return groups;
|
2008-07-10 23:30:56 +02:00
|
|
|
}
|
|
|
|
|
2010-01-15 00:19:19 +01:00
|
|
|
- (NSMutableArray *) _davCalendarProxyForWrite: (BOOL) write
|
2008-07-10 23:30:56 +02:00
|
|
|
{
|
2010-01-15 00:19:19 +01:00
|
|
|
NSMutableArray *proxyFor;
|
|
|
|
NSArray *proxiedUsers, *tag;
|
|
|
|
NSString *appName, *proxiedUser;
|
|
|
|
int count, max;
|
2008-07-10 23:30:56 +02:00
|
|
|
|
2010-01-15 00:19:19 +01:00
|
|
|
appName = [[context request] applicationName];
|
2008-07-10 23:30:56 +02:00
|
|
|
|
2010-01-15 00:19:19 +01:00
|
|
|
proxiedUsers = [self _calendarProxiedUsersWithWriteAccess: write];
|
|
|
|
max = [proxiedUsers count];
|
|
|
|
proxyFor = [NSMutableArray arrayWithCapacity: max];
|
|
|
|
if (max)
|
2008-07-10 23:30:56 +02:00
|
|
|
{
|
2010-01-15 00:19:19 +01:00
|
|
|
for (count = 0; count < max; count++)
|
|
|
|
{
|
|
|
|
proxiedUser = [proxiedUsers objectAtIndex: count];
|
2010-01-21 00:09:35 +01:00
|
|
|
tag = [NSArray arrayWithObjects: @"href", XMLNS_WEBDAV, @"D",
|
2010-01-15 00:19:19 +01:00
|
|
|
[NSString stringWithFormat: @"/%@/dav/%@/",
|
|
|
|
appName, proxiedUser],
|
|
|
|
nil];
|
|
|
|
[proxyFor addObject: tag];
|
|
|
|
}
|
2008-07-10 23:30:56 +02:00
|
|
|
}
|
|
|
|
|
2010-01-15 00:19:19 +01:00
|
|
|
return proxyFor;
|
2008-07-10 23:30:56 +02:00
|
|
|
}
|
|
|
|
|
2010-01-15 00:19:19 +01:00
|
|
|
- (NSArray *) davCalendarProxyWriteFor
|
2008-07-10 23:30:56 +02:00
|
|
|
{
|
2010-01-15 00:19:19 +01:00
|
|
|
return [self _davCalendarProxyForWrite: YES];
|
2008-07-10 23:30:56 +02:00
|
|
|
}
|
|
|
|
|
2010-01-15 00:19:19 +01:00
|
|
|
- (NSArray *) davCalendarProxyReadFor
|
2009-08-27 23:14:54 +02:00
|
|
|
{
|
2010-01-15 00:19:19 +01:00
|
|
|
return [self _davCalendarProxyForWrite: NO];
|
2009-08-27 23:14:54 +02:00
|
|
|
}
|
|
|
|
|
2008-05-03 01:08:15 +02:00
|
|
|
@end
|