Fixes for import/export

Monotone-Parent: 3e7ac334a4ea19aa4ec2dcbc525628005ca75fb7
Monotone-Revision: d124c012f70febcfcbb9a2b5d4f3a20a7a001d7a

Monotone-Author: crobert@inverse.ca
Monotone-Date: 2009-09-09T13:31:45
Monotone-Branch: ca.inverse.sogo
This commit is contained in:
C Robert committed 2009-09-09 13:31:45 +00:00
1 parent cb888a11ff
commit c543b9e9a7
24 files changed
+687 -547

No files matched your search

-2
View File
@@ -14,8 +14,6 @@ $(SOGO_TOOL)_OBJC_FILES += \
SOGoToolRestore.m \
SOGoToolCheckDoubles.m \
SOGoToolRemoveDoubles.m \
\
NSDictionary+SOGoTool.m
TOOL_NAME = $(SOGO_TOOL)
-34
View File
@@ -1,34 +0,0 @@
/* NSDictionary+SOGoTool.h - this file is part of SOGo
*
* Copyright (C) 2009 Inverse inc.
*
* 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.
*/
#ifndef NSDICTIONARY_SOGOTOOL_H
#define NSDICTIONARY_SOGOTOOL_H
#import <Foundation/NSDictionary.h>
@interface NSDictionary (SOGoToolsExtension)
- (NSString *) userRecordAsLDIFEntry;
@end
#endif /* NSDICTIONARY_SOGOTOOL_H */
-150
View File
@@ -1,150 +0,0 @@
/* NSDictionary+SOGoTool.m - this file is part of SOGo
*
* Copyright (C) 2009 Inverse inc.
*
* 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>
#import <Foundation/NSCharacterSet.h>
#import <Foundation/NSEnumerator.h>
#import <Foundation/NSString.h>
#import <NGExtensions/NGBase64Coding.h>
#import "NSDictionary+SOGoTool.h"
@interface NSString (SOGoToolsExtension)
- (BOOL) _isLDIFSafe;
@end
@implementation NSString (SOGoToolsExtension)
static NSMutableCharacterSet *safeLDIFChars = nil;
static NSMutableCharacterSet *safeLDIFStartChars = nil;
- (void) _initSafeLDIFChars
{
safeLDIFChars = [NSMutableCharacterSet new];
[safeLDIFChars addCharactersInRange: NSMakeRange (0x01, 9)];
[safeLDIFChars addCharactersInRange: NSMakeRange (0x0b, 2)];
[safeLDIFChars addCharactersInRange: NSMakeRange (0x0e, 114)];
safeLDIFStartChars = [safeLDIFChars mutableCopy];
[safeLDIFStartChars removeCharactersInString: @" :<"];
}
- (BOOL) _isLDIFSafe
{
int count, max;
BOOL rc;
if (!safeLDIFChars)
[self _initSafeLDIFChars];
rc = YES;
max = [self length];
if (max > 0)
{
if ([safeLDIFStartChars characterIsMember: [self characterAtIndex: 0]])
for (count = 1; rc && count < max; count++)
rc = [safeLDIFChars
characterIsMember: [self characterAtIndex: count]];
else
rc = NO;
}
return rc;
}
@end
@implementation NSDictionary (SOGoToolsExtension)
- (void) _appendLDIFKey: (NSString *) key
value: (NSString *) value
toString: (NSMutableString *) ldifString
{
if ([value _isLDIFSafe])
[ldifString appendFormat: @"%@: %@\n", key, value];
else
[ldifString appendFormat: @"%@:: %@\n",
key, [value stringByEncodingBase64]];
}
- (void) _appendLDIFKey: (NSString *) key
toString: (NSMutableString *) ldifString
{
id value;
int count, max;
value = [self objectForKey: key];
if ([value isKindOfClass: [NSArray class]])
{
max = [value count];
for (count = 0; count < max; count++)
[self _appendLDIFKey: key value: [value objectAtIndex: count]
toString: ldifString];
}
else
[self _appendLDIFKey: key value: [self objectForKey: key]
toString: ldifString];
}
- (void) _appendObjectClassesToString: (NSMutableString *) ldifString
{
NSEnumerator *classes;
NSString *currentClass;
classes = [[self objectForKey: @"objectClasses"] objectEnumerator];
while ((currentClass = [classes nextObject]))
[self _appendLDIFKey: @"objectClass" value: currentClass
toString: ldifString];
}
- (NSString *) userRecordAsLDIFEntry
{
NSMutableString *ldifString;
NSEnumerator *keys;
NSString *currentKey;
// {CalendarAccess = YES; MailAccess = YES; c_cn = "Wolfgang Sourdeau"; c_emails = ("wolfgang@test.com"); c_name = "wolfgang@test.com"; c_uid = "wolfgang@test.com"; cn = "wolfgang@test.com"; displayName = "Wolfgang Sourdeau"; dn = "cn=wolfgang@test.com,ou=evariste,o=inverse.ca"; givenName = Wolfgang; mail = "wolfgang@test.com"; objectClass = organizationalPerson; sn = Sourdeau; }
ldifString = [NSMutableString string];
[self _appendLDIFKey: @"dn" toString: ldifString];
[self _appendObjectClassesToString: ldifString];
keys = [[self allKeys] objectEnumerator];
while ((currentKey = [keys nextObject]))
{
if (!([currentKey isEqualToString: @"CalendarAccess"]
|| [currentKey isEqualToString: @"MailAccess"]
|| [currentKey isEqualToString: @"ContactAccess"]
|| [currentKey hasPrefix: @"objectClass"]
|| [currentKey hasPrefix: @"c_"]
|| [currentKey isEqualToString: @"dn"]))
[self _appendLDIFKey: currentKey toString: ldifString];
}
return ldifString;
}
@end
+1 -1
View File
@@ -35,10 +35,10 @@
#import <SOGo/LDAPUserManager.h>
#import <SOGo/LDAPSource.h>
#import <SOGo/NSArray+Utilities.h>
#import <SOGo/NSDictionary+Utilities.h>
#import <SOGo/SOGoUser.h>
#import <SOGo/SOGoUserDefaults.h>
#import "NSDictionary+SOGoTool.h"
#import "SOGoToolBackup.h"
/* TODO: