pEpObjCAdapter/PEPObjCAdapter.m
author Dirk Zimmermann <dirk@pep-project.org>
Wed, 21 Feb 2018 12:05:12 +0100
changeset 484 e7b3f52190f1
parent 442 8de34676b7f5
child 504 9fa7b040133c
permissions -rw-r--r--
IOSAD-76 mimeDecode
dirk@187
     1
//
edouard@191
     2
//  pEpObjCAdapter.m
edouard@191
     3
//  pEpObjCAdapter
dirk@187
     4
//
dirk@187
     5
//  Created by Volker Birk on 28.04.15.
dirk@187
     6
//  Copyright (c) 2015 p≡p. All rights reserved.
dirk@187
     7
//
dirk@187
     8
dirk@187
     9
@import Foundation;
dirk@187
    10
dirk@187
    11
#import "PEPObjCAdapter.h"
dirk@187
    12
#import "PEPObjCAdapter+Internal.h"
dirk@367
    13
#import "PEPMessageUtil.h"
dirk@484
    14
#import "NSError+PEP.h"
dirk@484
    15
dirk@484
    16
#import "keymanagement.h"
dirk@484
    17
#import "mime.h"
dirk@484
    18
#import "message.h"
dirk@187
    19
dirk@187
    20
///////////////////////////////////////////////////////////////////////////////
dirk@187
    21
//  Keyserver and Identity lookup - C part
dirk@187
    22
dirk@187
    23
int examine_identity(pEp_identity *ident, void *management)
dirk@187
    24
{
dirk@187
    25
    //PEPQueue *q = (__bridge PEPQueue *)management;
dirk@187
    26
    PEPQueue *q = [PEPObjCAdapter getLookupQueue];
dirk@187
    27
    
dirk@187
    28
    NSDictionary *identity = PEP_identityDictFromStruct(ident);
dirk@187
    29
    
dirk@187
    30
    [q enqueue:identity];
dirk@187
    31
    return 0;
dirk@187
    32
}
dirk@187
    33
dirk@187
    34
static pEp_identity *retrieve_next_identity(void *management)
dirk@187
    35
{
dirk@187
    36
    //PEPQueue *q = (__bridge PEPQueue *)management;
dirk@187
    37
    PEPQueue *q = [PEPObjCAdapter getLookupQueue];
dirk@187
    38
    
dirk@187
    39
    // Dequeue is a blocking operation
dirk@187
    40
    // that returns nil when queue is killed
dirk@187
    41
    NSDictionary *ident = [q dequeue];
dirk@187
    42
    
dirk@187
    43
    if (ident)
dirk@187
    44
        return PEP_identityDictToStruct(ident);
dirk@187
    45
    else
dirk@187
    46
        return NULL;
dirk@187
    47
}
dirk@187
    48
dirk@187
    49
///////////////////////////////////////////////////////////////////////////////
dirk@331
    50
// Sync - C part
dirk@331
    51
dirk@331
    52
// Called by sync thread only
dirk@331
    53
PEP_STATUS notify_handshake(void *unused_object, pEp_identity *me, pEp_identity *partner, sync_handshake_signal signal)
dirk@331
    54
{
dirk@331
    55
    id <PEPSyncDelegate> syncDelegate = [PEPObjCAdapter getSyncDelegate];
dirk@331
    56
    if ( syncDelegate )
dirk@331
    57
        return [syncDelegate
dirk@331
    58
                notifyHandshakeWithSignal:signal
dirk@331
    59
                me:PEP_identityDictFromStruct(me)
dirk@331
    60
                partner:PEP_identityDictFromStruct(partner)];
dirk@331
    61
    else
dirk@331
    62
        return PEP_SYNC_NO_NOTIFY_CALLBACK;
dirk@331
    63
}
dirk@331
    64
dirk@331
    65
// Called by sync thread only
dirk@331
    66
PEP_STATUS message_to_send(void *unused_object, message *msg)
dirk@331
    67
{
dirk@331
    68
    id <PEPSyncDelegate> syncDelegate = [PEPObjCAdapter getSyncDelegate];
dirk@331
    69
    if ( syncDelegate )
dirk@331
    70
        return [syncDelegate sendMessage:PEP_messageDictFromStruct(msg)];
dirk@331
    71
    else
dirk@331
    72
        return PEP_SEND_FUNCTION_NOT_REGISTERED;
dirk@331
    73
}
dirk@331
    74
dirk@331
    75
// called indirectly by decrypt message - any thread/session
dirk@331
    76
int inject_sync_msg(void *msg, void *unused_management)
dirk@331
    77
{
dirk@331
    78
    PEPQueue *q = [PEPObjCAdapter getSyncQueue];
dirk@331
    79
    [q enqueue:[NSValue valueWithPointer:msg]];
dirk@331
    80
    
dirk@331
    81
    return 0;
dirk@331
    82
}
dirk@331
    83
dirk@331
    84
// Called by sync thread only
dirk@331
    85
void *retrieve_next_sync_msg(void *unused_mamagement, time_t *timeout)
dirk@331
    86
{
dirk@331
    87
    bool needs_fastpoll = (*timeout != 0);
dirk@331
    88
    
dirk@331
    89
    id <PEPSyncDelegate> syncDelegate = [PEPObjCAdapter getSyncDelegate];
dirk@331
    90
    if ( syncDelegate && needs_fastpoll )
dirk@331
    91
        [syncDelegate fastPolling:true];
dirk@331
    92
    
dirk@331
    93
    PEPQueue *q = [PEPObjCAdapter getSyncQueue];
dirk@331
    94
    
dirk@331
    95
    void* result = (void*)[[q timedDequeue:timeout] pointerValue];
dirk@331
    96
    
dirk@331
    97
    if ( syncDelegate && needs_fastpoll )
dirk@331
    98
        [syncDelegate fastPolling:false];
dirk@331
    99
    
dirk@331
   100
    return result;
dirk@331
   101
    
dirk@331
   102
}
dirk@331
   103
dirk@187
   104
const char* _Nullable SystemDB = NULL;
dirk@187
   105
NSURL *s_homeURL;
dirk@254
   106
static NSLock *s_initLock;
andreas@416
   107
static BOOL s_unecryptedSubjectEnabled = NO;
dirk@187
   108
dirk@187
   109
@implementation PEPObjCAdapter
dirk@187
   110
andreas@416
   111
#pragma mark - SUBJECT PROTECTION
andreas@416
   112
andreas@416
   113
+ (BOOL)unecryptedSubjectEnabled;
andreas@416
   114
{
andreas@416
   115
    return s_unecryptedSubjectEnabled;
andreas@416
   116
}
andreas@416
   117
andreas@416
   118
+ (void)setUnecryptedSubjectEnabled:(BOOL)enabled;
andreas@416
   119
{
andreas@416
   120
    s_unecryptedSubjectEnabled = enabled;
andreas@416
   121
}
andreas@416
   122
andreas@416
   123
#pragma mark - DB PATHS
andreas@416
   124
dirk@187
   125
+ (void)initialize
dirk@187
   126
{
dirk@187
   127
    s_homeURL = [self createApplicationDirectory];
dirk@442
   128
    [self setHomeDirectory:s_homeURL]; // Important, defines $HOME and $TEMP for the engine
dirk@254
   129
    s_initLock = [[NSLock alloc] init];
dirk@254
   130
}
dirk@254
   131
dirk@254
   132
+ (NSLock *)initLock
dirk@254
   133
{
dirk@254
   134
    return s_initLock;
dirk@187
   135
}
dirk@187
   136
dirk@187
   137
+ (NSURL *)homeURL
dirk@187
   138
{
dirk@187
   139
    return s_homeURL;
dirk@187
   140
}
dirk@187
   141
dirk@187
   142
+ (NSURL *)createApplicationDirectory
dirk@187
   143
{
dirk@187
   144
    NSString *bundleID = [[NSBundle mainBundle] bundleIdentifier];
dirk@187
   145
    if (!bundleID) {
dirk@187
   146
        // This can happen in unit tests
dirk@187
   147
        bundleID = @"test";
dirk@187
   148
    }
dirk@187
   149
    NSFileManager *fm = [NSFileManager defaultManager];
dirk@187
   150
    NSURL *dirPath = nil;
andreas@268
   151
    
dirk@187
   152
    // Find the application support directory in the home directory.
dirk@187
   153
    NSArray *appSupportDir = [fm URLsForDirectory:NSApplicationSupportDirectory
dirk@187
   154
                                        inDomains:NSUserDomainMask];
dirk@187
   155
    if ([appSupportDir count] > 0)
dirk@187
   156
    {
dirk@187
   157
        // Append the bundle ID to the URL for the
dirk@187
   158
        // Application Support directory.
dirk@187
   159
        // Mainly needed for OS X, but doesn't do any harm on iOS
dirk@187
   160
        dirPath = [[appSupportDir objectAtIndex:0] URLByAppendingPathComponent:bundleID];
andreas@268
   161
        
dirk@187
   162
        // If the directory does not exist, this method creates it.
dirk@187
   163
        // This method is only available in OS X v10.7 and iOS 5.0 or later.
dirk@187
   164
        NSError *theError = nil;
dirk@187
   165
        if (![fm createDirectoryAtURL:dirPath withIntermediateDirectories:YES
dirk@187
   166
                           attributes:nil error:&theError])
dirk@187
   167
        {
dirk@187
   168
            // Handle the error.
dirk@187
   169
            return nil;
dirk@187
   170
        }
dirk@187
   171
    }
andreas@268
   172
    
dirk@187
   173
    return dirPath;
dirk@187
   174
}
dirk@187
   175
dirk@442
   176
+ (void)setHomeDirectory:(NSURL *)homeDir
dirk@187
   177
{
dirk@187
   178
    // create and set home directory
dirk@442
   179
    setenv("HOME", [[homeDir path] cStringUsingEncoding:NSUTF8StringEncoding], 1);
andreas@268
   180
    
dirk@187
   181
    // create and set temp directory
dirk@187
   182
    NSURL *tmpDirUrl = [NSURL fileURLWithPath:NSTemporaryDirectory() isDirectory:YES];
dirk@187
   183
    setenv("TEMP", [[tmpDirUrl path] cStringUsingEncoding:NSUTF8StringEncoding], 1);
dirk@187
   184
}
dirk@187
   185
andreas@276
   186
+ (NSString *)getBundlePathFor: (NSString *) filename
dirk@187
   187
{
dirk@187
   188
    return nil;
dirk@187
   189
}
dirk@187
   190
dirk@442
   191
+ (NSString *)copyAssetsIntoDocumentsDirectory:(NSBundle *)rootBundle
dirk@442
   192
                                    bundleName:(NSString *)bundleName
dirk@442
   193
                                      fileName:(NSString *)fileName {
andreas@268
   194
    
dirk@442
   195
    NSURL *homeUrl = s_homeURL;
dirk@187
   196
    NSString *documentsDirectory = [homeUrl path];
dirk@187
   197
    
dirk@187
   198
    if(!(documentsDirectory && bundleName && fileName))
dirk@187
   199
        return nil;
dirk@187
   200
    
dirk@187
   201
    // Check if the database file exists in the documents directory.
dirk@187
   202
    NSString *destinationPath = [documentsDirectory stringByAppendingPathComponent:fileName];
dirk@187
   203
    if (![[NSFileManager defaultManager] fileExistsAtPath:destinationPath]) {
dirk@187
   204
        // The file does not exist in the documents directory, so copy it from bundle now.
dirk@187
   205
        NSBundle *bundleObj = [NSBundle bundleWithPath:
dirk@187
   206
                               [[rootBundle resourcePath]
dirk@187
   207
                                stringByAppendingPathComponent: bundleName]];
dirk@187
   208
        if (!bundleObj)
dirk@187
   209
            return nil;
dirk@187
   210
        
dirk@187
   211
        NSString *sourcePath =[[bundleObj resourcePath] stringByAppendingPathComponent: fileName];
dirk@187
   212
        
dirk@187
   213
        NSError *error;
dirk@187
   214
        [[NSFileManager defaultManager]
dirk@187
   215
         copyItemAtPath:sourcePath toPath:destinationPath error:&error];
dirk@187
   216
        
dirk@187
   217
        // Check if any error occurred during copying and display it.
dirk@187
   218
        if (error != nil) {
dirk@187
   219
            NSLog(@"%@", [error localizedDescription]);
dirk@187
   220
            return nil;
dirk@187
   221
        }
dirk@187
   222
    }
dirk@187
   223
    NSLog(@"Asset %@ copied into %@", fileName, destinationPath);
dirk@187
   224
    return destinationPath;
dirk@187
   225
}
dirk@187
   226
dirk@187
   227
+ (void)setupTrustWordsDB:(NSBundle *)rootBundle{
dirk@442
   228
    NSString *systemDBPath = [PEPObjCAdapter
dirk@442
   229
                              copyAssetsIntoDocumentsDirectory:rootBundle
dirk@442
   230
                              bundleName:@"pEpTrustWords.bundle"
dirk@442
   231
                              fileName:@"system.db"];
dirk@187
   232
    if (SystemDB) {
dirk@187
   233
        free((void *) SystemDB);
dirk@187
   234
    }
dirk@187
   235
    SystemDB = strdup(systemDBPath.UTF8String);
dirk@187
   236
}
dirk@187
   237
dirk@187
   238
+ (void)setupTrustWordsDB
dirk@187
   239
{
dirk@187
   240
    [PEPObjCAdapter setupTrustWordsDB:[NSBundle mainBundle]];
dirk@187
   241
}
dirk@187
   242
dirk@187
   243
static NSMutableArray* boundSessions = nil;
dirk@187
   244
dirk@187
   245
+ (NSMutableArray*)boundSessions
dirk@187
   246
{
dirk@187
   247
    static dispatch_once_t once;
dirk@187
   248
    dispatch_once(&once, ^{
dirk@187
   249
        boundSessions =  [[NSMutableArray alloc] init];
dirk@187
   250
    });
dirk@187
   251
    return boundSessions;
dirk@187
   252
}
dirk@187
   253
dirk@187
   254
///////////////////////////////////////////////////////////////////////////////
dirk@187
   255
//  Keyserver and Identity lookup - ObjC part
dirk@187
   256
dirk@187
   257
static PEPQueue *lookupQueue = nil;
dirk@187
   258
static NSThread *lookupThread = nil;
dirk@187
   259
static NSConditionLock *lookupThreadJoinCond = nil;
dirk@187
   260
dirk@187
   261
+ (void)lookupThreadRoutine:(id)object
dirk@187
   262
{
dirk@187
   263
    [lookupThreadJoinCond lock];
andreas@268
   264
    
dirk@187
   265
    // FIXME: do_KeyManagement asserts if management is null.
dirk@187
   266
    do_keymanagement(retrieve_next_identity, "NOTNULL" /* (__bridge void *)queue */);
dirk@187
   267
    
dirk@187
   268
    // Set and signal join()
dirk@187
   269
    [lookupThreadJoinCond unlockWithCondition:YES];
dirk@187
   270
}
dirk@187
   271
dirk@187
   272
+ (void)startKeyserverLookup
dirk@187
   273
{
dirk@187
   274
    if (!lookupQueue)
dirk@187
   275
    {
dirk@187
   276
        lookupQueue = [[PEPQueue alloc]init];
dirk@187
   277
        
dirk@187
   278
        // There is no join() call on NSThreads.
dirk@187
   279
        lookupThreadJoinCond = [[NSConditionLock alloc] initWithCondition:NO];
dirk@187
   280
        
dirk@187
   281
        lookupThread = [[NSThread alloc] initWithTarget:self selector:@selector(lookupThreadRoutine:) object:nil];
dirk@187
   282
        [lookupThread start];
dirk@187
   283
    }
dirk@187
   284
}
dirk@187
   285
dirk@187
   286
+ (void)stopKeyserverLookup
dirk@187
   287
{
dirk@187
   288
    
dirk@187
   289
    if (lookupQueue)
dirk@187
   290
    {
dirk@187
   291
        // Flush queue and kick the consumer
dirk@187
   292
        [lookupQueue kill];
dirk@187
   293
        
dirk@187
   294
        // Thread then bailout. Wait for that.
dirk@187
   295
        [lookupThreadJoinCond lockWhenCondition:YES];
dirk@187
   296
        [lookupThreadJoinCond unlock];
dirk@187
   297
        
dirk@187
   298
        lookupThread = nil;
dirk@187
   299
        lookupQueue = nil;
dirk@187
   300
        lookupThreadJoinCond = nil;
dirk@187
   301
    }
dirk@187
   302
}
dirk@187
   303
dirk@187
   304
+ (void)registerExamineFunction:(PEP_SESSION)session
dirk@187
   305
{
dirk@187
   306
    register_examine_function(session, examine_identity, NULL /* (__bridge void *)queue */);
dirk@187
   307
}
dirk@187
   308
dirk@187
   309
+ (PEPQueue*)getLookupQueue
dirk@187
   310
{
dirk@187
   311
    return lookupQueue;
dirk@187
   312
}
dirk@187
   313
dirk@331
   314
///////////////////////////////////////////////////////////////////////////////
dirk@331
   315
// Sync - ObjC part
dirk@331
   316
dirk@331
   317
static PEPQueue *syncQueue = nil;
dirk@331
   318
static NSThread *syncThread = nil;
dirk@331
   319
static NSConditionLock *syncThreadJoinCond = nil;
dirk@331
   320
static PEP_SESSION sync_session = NULL;
dirk@331
   321
static id <PEPSyncDelegate> syncDelegate = nil;
dirk@331
   322
dirk@331
   323
dirk@331
   324
+ (void)syncThreadRoutine:(id)object
dirk@331
   325
{
dirk@331
   326
    [syncThreadJoinCond lock];
dirk@331
   327
    
dirk@331
   328
    
dirk@331
   329
    PEP_STATUS status;
dirk@331
   330
    
dirk@331
   331
    status = do_sync_protocol(sync_session,
dirk@331
   332
                              /* "object" : notifying, sending (unused) */
dirk@331
   333
                              "NOTNULL");
dirk@331
   334
    
dirk@331
   335
    // TODO : log something if status not as expected
dirk@331
   336
dirk@331
   337
    [syncThreadJoinCond unlockWithCondition:YES];
dirk@331
   338
}
dirk@331
   339
dirk@331
   340
+ (void)attachSyncSession:(PEP_SESSION)session
dirk@331
   341
{
dirk@331
   342
    if(sync_session)
dirk@331
   343
        attach_sync_session(session, sync_session);
dirk@331
   344
}
dirk@331
   345
dirk@331
   346
+ (void)detachSyncSession:(PEP_SESSION)session
dirk@331
   347
{
dirk@331
   348
    detach_sync_session(session);
dirk@331
   349
}
dirk@331
   350
dirk@331
   351
+ (void)startSync:(id <PEPSyncDelegate>)delegate;
dirk@331
   352
{
dirk@331
   353
    syncDelegate = delegate;
dirk@331
   354
    
dirk@333
   355
    if (!syncQueue) {
dirk@333
   356
        syncQueue = [[PEPQueue alloc] init];
dirk@331
   357
        
dirk@331
   358
        syncThreadJoinCond = [[NSConditionLock alloc] initWithCondition:NO];
dirk@331
   359
        
dirk@331
   360
        [[PEPObjCAdapter initLock] lock];
dirk@331
   361
        PEP_STATUS status = init(&sync_session);
dirk@331
   362
        [[PEPObjCAdapter initLock] unlock];
dirk@331
   363
        if (status != PEP_STATUS_OK) {
dirk@331
   364
            return;
dirk@331
   365
        }
dirk@331
   366
        
dirk@331
   367
        register_sync_callbacks(sync_session,
dirk@331
   368
                                /* "management" : queuing (unused) */
dirk@331
   369
                                "NOTNULL",
dirk@331
   370
                                message_to_send,
dirk@331
   371
                                notify_handshake,
dirk@331
   372
                                inject_sync_msg,
dirk@331
   373
                                retrieve_next_sync_msg);
dirk@331
   374
        
dirk@331
   375
        syncThread = [[NSThread alloc]
dirk@331
   376
                      initWithTarget:self
dirk@331
   377
                      selector:@selector(syncThreadRoutine:)
dirk@331
   378
                      object:nil];
dirk@331
   379
        
dirk@331
   380
        [syncThread start];
dirk@331
   381
    }
dirk@331
   382
    
dirk@331
   383
    NSMutableArray* sessionList = [PEPObjCAdapter boundSessions];
dirk@331
   384
    NSValue* v;
dirk@331
   385
    PEPInternalSession* session;
dirk@331
   386
    @synchronized (sessionList) {
dirk@331
   387
        for (v in sessionList) {
dirk@331
   388
            session = [v nonretainedObjectValue];
dirk@331
   389
            [PEPObjCAdapter attachSyncSession:[session session]];
dirk@331
   390
        }
dirk@331
   391
    }
dirk@331
   392
}
dirk@331
   393
dirk@331
   394
+ (void)stopSync
dirk@331
   395
{
dirk@331
   396
    NSMutableArray* sessionList = [PEPObjCAdapter boundSessions];
dirk@331
   397
    NSValue* v;
dirk@331
   398
    PEPInternalSession* session;
dirk@331
   399
    @synchronized (sessionList) {
dirk@331
   400
        for (v in sessionList) {
dirk@331
   401
            session = [v nonretainedObjectValue];
dirk@331
   402
            [PEPObjCAdapter detachSyncSession:[session session]];
dirk@331
   403
        }
dirk@331
   404
    }
dirk@331
   405
    
dirk@331
   406
    syncDelegate = nil;
dirk@331
   407
    
dirk@331
   408
    if (syncQueue)
dirk@331
   409
    {
dirk@331
   410
        [syncQueue purge:^(id item){
dirk@331
   411
            sync_msg_t *msg = [item pointerValue];
dirk@331
   412
            free_sync_msg(msg);
dirk@331
   413
        }];
dirk@331
   414
        
dirk@331
   415
        [syncThreadJoinCond lockWhenCondition:YES];
dirk@331
   416
        [syncThreadJoinCond unlock];
dirk@331
   417
        
dirk@331
   418
        [[PEPObjCAdapter initLock] lock];
dirk@331
   419
        release(sync_session);
dirk@331
   420
        [[PEPObjCAdapter initLock] unlock];
dirk@331
   421
        
dirk@331
   422
        sync_session = NULL;
dirk@331
   423
        syncThread = nil;
dirk@331
   424
        syncQueue = nil;
dirk@331
   425
        syncThreadJoinCond = nil;
dirk@331
   426
    }
dirk@331
   427
}
dirk@331
   428
dirk@331
   429
+ (PEPQueue*)getSyncQueue
dirk@331
   430
{
dirk@331
   431
    return syncQueue;
dirk@331
   432
}
dirk@331
   433
dirk@331
   434
+ (id <PEPSyncDelegate>)getSyncDelegate
dirk@331
   435
{
dirk@331
   436
    return syncDelegate;
dirk@331
   437
}
dirk@331
   438
dirk@331
   439
+ (void)bindSession:(PEPInternalSession*)session
dirk@331
   440
{
dirk@331
   441
    NSMutableArray* sessionList = [PEPObjCAdapter boundSessions];
dirk@331
   442
    @synchronized (sessionList) {
dirk@331
   443
        [sessionList addObject:[NSValue valueWithNonretainedObject:session]];
dirk@331
   444
    }
dirk@331
   445
    
dirk@331
   446
    [PEPObjCAdapter registerExamineFunction:[session session]];
dirk@331
   447
    [PEPObjCAdapter attachSyncSession:[session session]];
dirk@331
   448
}
dirk@331
   449
dirk@331
   450
+ (void)unbindSession:(PEPInternalSession*)session
dirk@331
   451
{
dirk@331
   452
    [PEPObjCAdapter detachSyncSession:[session session]];
dirk@331
   453
    
dirk@331
   454
    NSMutableArray* sessionList = [PEPObjCAdapter boundSessions];
dirk@331
   455
    @synchronized (sessionList) {
dirk@331
   456
        [sessionList removeObject:[NSValue valueWithNonretainedObject:session]];
dirk@331
   457
    }
dirk@331
   458
}
dirk@331
   459
dirk@484
   460
+ (PEPMessage * _Nullable)mimeDecode:(NSString * _Nonnull)mimeText
dirk@484
   461
                          pEpMessage:(PEPMessage *_Nullable * _Nonnull)pEpMessage
dirk@484
   462
                               error:(NSError * _Nonnull * _Nullable)error
dirk@484
   463
{
dirk@484
   464
    message *dstMsg = NULL;
dirk@484
   465
    const char *utfString = [[mimeText precomposedStringWithCanonicalMapping] UTF8String];
dirk@484
   466
    PEP_STATUS status = mime_decode_message(utfString, strlen(utfString), &dstMsg);
dirk@484
   467
dirk@484
   468
    if (status == PEP_STATUS_OK) {
dirk@484
   469
        if (dstMsg) {
dirk@484
   470
            return pEpMessageFromStruct(dstMsg);
dirk@484
   471
        } else {
dirk@484
   472
            return nil;
dirk@484
   473
        }
dirk@484
   474
    } else {
dirk@484
   475
        if (error) {
dirk@484
   476
            *error = [NSError errorWithPEPStatus:status];
dirk@484
   477
        }
dirk@484
   478
        return nil;
dirk@484
   479
    }
dirk@484
   480
}
dirk@484
   481
dirk@187
   482
@end