2007-05-09 21:09:50 +02:00
|
|
|
/* SOGoContactLDIFEntry.m - this file is part of SOGo
|
2006-08-09 23:21:40 +02:00
|
|
|
*
|
2014-07-30 20:51:00 +02:00
|
|
|
* Copyright (C) 2006-2014 Inverse inc.
|
2006-08-09 23:21:40 +02:00
|
|
|
*
|
|
|
|
* 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>
|
|
|
|
#import <Foundation/NSDictionary.h>
|
|
|
|
#import <Foundation/NSString.h>
|
|
|
|
|
2006-09-13 23:28:38 +02:00
|
|
|
#import <NGCards/NGVCard.h>
|
|
|
|
#import <NGCards/CardVersitRenderer.h>
|
2006-08-09 23:21:40 +02:00
|
|
|
|
2011-03-30 17:01:55 +02:00
|
|
|
#import <SOGo/SOGoBuild.h>
|
2011-12-30 21:39:07 +01:00
|
|
|
#import <SOGo/SOGoSource.h>
|
|
|
|
#import <SOGo/SOGoPermissions.h>
|
2011-03-30 17:01:55 +02:00
|
|
|
|
2011-12-30 21:39:07 +01:00
|
|
|
#import "NGVCard+SOGo.h"
|
2008-08-10 23:44:25 +02:00
|
|
|
#import "SOGoContactGCSEntry.h"
|
2007-05-09 21:09:50 +02:00
|
|
|
#import "SOGoContactLDIFEntry.h"
|
2011-12-30 21:39:07 +01:00
|
|
|
#import "SOGoContactSourceFolder.h"
|
2006-08-09 23:21:40 +02:00
|
|
|
|
2007-05-09 21:09:50 +02:00
|
|
|
@implementation SOGoContactLDIFEntry
|
2006-08-09 23:21:40 +02:00
|
|
|
|
2007-05-09 21:09:50 +02:00
|
|
|
+ (SOGoContactLDIFEntry *) contactEntryWithName: (NSString *) newName
|
|
|
|
withLDIFEntry: (NSDictionary *) newEntry
|
2007-05-08 17:10:40 +02:00
|
|
|
inContainer: (id) newContainer
|
2006-08-09 23:21:40 +02:00
|
|
|
{
|
2007-05-09 21:09:50 +02:00
|
|
|
SOGoContactLDIFEntry *entry;
|
2006-08-09 23:21:40 +02:00
|
|
|
|
2007-05-08 17:10:40 +02:00
|
|
|
entry = [[self alloc] initWithName: newName
|
2011-12-30 21:39:07 +01:00
|
|
|
withLDIFEntry: newEntry
|
|
|
|
inContainer: newContainer];
|
2006-08-09 23:21:40 +02:00
|
|
|
[entry autorelease];
|
|
|
|
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
2007-05-08 17:10:40 +02:00
|
|
|
- (id) initWithName: (NSString *) newName
|
2007-05-09 21:09:50 +02:00
|
|
|
withLDIFEntry: (NSDictionary *) newEntry
|
2007-05-08 17:10:40 +02:00
|
|
|
inContainer: (id) newContainer
|
2006-08-09 23:21:40 +02:00
|
|
|
{
|
2010-02-03 01:32:26 +01:00
|
|
|
if ((self = [self initWithName: newName inContainer: newContainer]))
|
|
|
|
{
|
|
|
|
ASSIGN (ldifEntry, newEntry);
|
2011-12-30 21:39:07 +01:00
|
|
|
isNew = NO;
|
2010-02-03 01:32:26 +01:00
|
|
|
}
|
2006-08-09 23:21:40 +02:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2007-05-08 17:10:40 +02:00
|
|
|
- (void) dealloc
|
2006-08-09 23:21:40 +02:00
|
|
|
{
|
2007-05-09 21:09:50 +02:00
|
|
|
[ldifEntry release];
|
2007-05-08 17:10:40 +02:00
|
|
|
[super dealloc];
|
2006-08-09 23:21:40 +02:00
|
|
|
}
|
|
|
|
|
2011-12-30 21:39:07 +01:00
|
|
|
- (BOOL) isNew
|
2006-08-09 23:21:40 +02:00
|
|
|
{
|
2011-12-30 21:39:07 +01:00
|
|
|
return isNew;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setIsNew: (BOOL) newIsNew
|
|
|
|
{
|
|
|
|
isNew = newIsNew;
|
2006-08-09 23:21:40 +02:00
|
|
|
}
|
|
|
|
|
2011-12-30 21:39:07 +01:00
|
|
|
- (NSString *) contentAsString
|
2006-08-09 23:21:40 +02:00
|
|
|
{
|
2011-12-30 21:39:07 +01:00
|
|
|
return [[self vCard] versitString];
|
2006-08-09 23:21:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NGVCard *) vCard
|
|
|
|
{
|
2011-12-30 21:39:07 +01:00
|
|
|
NGVCard *vcard;
|
2006-08-09 23:21:40 +02:00
|
|
|
|
2011-12-30 21:39:07 +01:00
|
|
|
vcard = [NGVCard cardWithUid: [self nameInContainer]];
|
|
|
|
[vcard setProdID: [NSString
|
|
|
|
stringWithFormat: @"-//Inverse inc./SOGo %@//EN",
|
|
|
|
SOGoVersion]];
|
2012-03-21 16:50:07 +01:00
|
|
|
[vcard updateFromLDIFRecord: [self simplifiedLDIFRecord]];
|
2006-10-27 19:45:32 +02:00
|
|
|
|
2006-08-09 23:21:40 +02:00
|
|
|
return vcard;
|
|
|
|
}
|
|
|
|
|
2008-03-28 15:47:33 +01:00
|
|
|
- (BOOL) isFolderish
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2011-12-30 21:39:07 +01:00
|
|
|
- (void) setLDIFRecord: (NSDictionary *) newLDIFRecord
|
|
|
|
{
|
|
|
|
ASSIGN (ldifEntry, newLDIFRecord);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDictionary *) ldifRecord
|
|
|
|
{
|
|
|
|
return ldifEntry;
|
|
|
|
}
|
|
|
|
|
2012-03-21 16:50:07 +01:00
|
|
|
- (NSDictionary *) simplifiedLDIFRecord
|
|
|
|
{
|
|
|
|
NSMutableDictionary *newRecord;
|
|
|
|
NSArray *keys;
|
|
|
|
NSUInteger count, max;
|
|
|
|
NSString *key;
|
|
|
|
id value;
|
|
|
|
|
|
|
|
newRecord = [[self ldifRecord] mutableCopy];
|
|
|
|
[newRecord autorelease];
|
|
|
|
|
|
|
|
keys = [newRecord allKeys];
|
|
|
|
max = [keys count];
|
|
|
|
for (count = 0; count < max; count++)
|
|
|
|
{
|
|
|
|
key = [keys objectAtIndex: count];
|
|
|
|
value = [newRecord objectForKey: key];
|
|
|
|
if ([value isKindOfClass: [NSArray class]]
|
|
|
|
&& ![key isEqualToString: @"objectclass"])
|
|
|
|
{
|
|
|
|
if ([value count] > 0)
|
|
|
|
[newRecord setObject: [value objectAtIndex: 0]
|
|
|
|
forKey: key];
|
|
|
|
else
|
|
|
|
[newRecord removeObjectForKey: key];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return newRecord;
|
|
|
|
}
|
|
|
|
|
2011-12-30 21:39:07 +01:00
|
|
|
- (BOOL) hasPhoto
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2006-08-09 23:21:40 +02:00
|
|
|
- (NSString *) davEntityTag
|
|
|
|
{
|
2007-10-23 00:18:07 +02:00
|
|
|
unsigned int hash;
|
|
|
|
// return [ldifEntry objectForKey: @"modifyTimeStamp"];
|
|
|
|
|
|
|
|
hash = [[self contentAsString] hash];
|
|
|
|
|
|
|
|
return [NSString stringWithFormat: @"hash%u", hash];
|
2006-08-09 23:21:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) davContentType
|
|
|
|
{
|
|
|
|
return @"text/x-vcard";
|
|
|
|
}
|
|
|
|
|
2012-03-30 16:07:36 +02:00
|
|
|
- (NSString *) davAddressData
|
|
|
|
{
|
|
|
|
return [self contentAsString];
|
|
|
|
}
|
|
|
|
|
2011-12-30 21:39:07 +01:00
|
|
|
- (NSException *) save
|
|
|
|
{
|
|
|
|
return [(SOGoContactSourceFolder *) container saveLDIFEntry: self];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSException *) delete
|
2007-04-27 21:01:46 +02:00
|
|
|
{
|
2011-12-30 21:39:07 +01:00
|
|
|
return [(SOGoContactSourceFolder *) container deleteLDIFEntry: self];
|
2007-04-27 21:01:46 +02:00
|
|
|
}
|
|
|
|
|
2011-12-30 21:39:07 +01:00
|
|
|
/* acl */
|
|
|
|
|
|
|
|
- (NSArray *) aclsForUser: (NSString *) uid
|
2006-09-16 00:20:56 +02:00
|
|
|
{
|
2011-12-30 21:39:07 +01:00
|
|
|
NSMutableArray *acls;
|
|
|
|
NSArray *containerAcls;
|
|
|
|
|
|
|
|
acls = [NSMutableArray array];
|
|
|
|
/* this is unused... */
|
|
|
|
// ownAcls = [container aclsForUser: uid
|
|
|
|
// forObjectAtPath: [self pathArrayToSOGoObject]];
|
|
|
|
// [acls addObjectsFromArray: ownAcls];
|
|
|
|
containerAcls = [container aclsForUser: uid];
|
|
|
|
if ([containerAcls count] > 0)
|
|
|
|
{
|
|
|
|
[acls addObjectsFromArray: containerAcls];
|
|
|
|
/* The creation of an object is actually a "modification" to an
|
|
|
|
unexisting object. When the object is new, we give the
|
|
|
|
"ObjectCreator" the "ObjectModifier" role temporarily while we
|
|
|
|
disallow the "ObjectModifier" users to modify them, unless they are
|
|
|
|
ObjectCreators too. */
|
|
|
|
if (isNew)
|
|
|
|
{
|
|
|
|
if ([containerAcls containsObject: SOGoRole_ObjectCreator])
|
|
|
|
[acls addObject: SOGoRole_ObjectEditor];
|
|
|
|
else
|
|
|
|
[acls removeObject: SOGoRole_ObjectEditor];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return acls;
|
2006-09-16 00:20:56 +02:00
|
|
|
}
|
|
|
|
|
2008-08-10 23:44:25 +02:00
|
|
|
/* DAV */
|
|
|
|
- (NSException *) copyToFolder: (SOGoGCSFolder *) newFolder
|
|
|
|
{
|
|
|
|
NGVCard *newCard;
|
|
|
|
NSString *newUID;
|
|
|
|
SOGoContactGCSEntry *newContact;
|
|
|
|
|
|
|
|
// Change the contact UID
|
|
|
|
newUID = [self globallyUniqueObjectId];
|
|
|
|
newCard = [self vCard];
|
|
|
|
|
|
|
|
[newCard setUid: newUID];
|
|
|
|
|
|
|
|
newContact = [SOGoContactGCSEntry objectWithName:
|
|
|
|
[NSString stringWithFormat: @"%@.vcf", newUID]
|
|
|
|
inContainer: newFolder];
|
|
|
|
|
2014-07-30 20:51:00 +02:00
|
|
|
return [newContact saveComponent: newCard];
|
2008-08-10 23:44:25 +02:00
|
|
|
}
|
|
|
|
|
2006-08-09 23:21:40 +02:00
|
|
|
@end
|