IOSAD-150 Leaving original implementation for macOS. IOSAD-150
authorDirk Zimmermann <dz@pep.security>
Wed, 09 Oct 2019 15:23:58 +0200
branchIOSAD-150
changeset 13094f51ddaa35dc
parent 1308 1ebf67a0806f
child 1310 9b967238e92f
IOSAD-150 Leaving original implementation for macOS.
pEpObjCAdapter/PEPObjCAdapter.m
     1.1 --- a/pEpObjCAdapter/PEPObjCAdapter.m	Wed Oct 09 10:41:49 2019 +0200
     1.2 +++ b/pEpObjCAdapter/PEPObjCAdapter.m	Wed Oct 09 15:23:58 2019 +0200
     1.3 @@ -19,6 +19,8 @@
     1.4  
     1.5  const PEP_decrypt_flags PEP_decrypt_flag_none = 0x0;
     1.6  
     1.7 +static NSString * const s_pEpHomeComponent = @"pEp_home";
     1.8 +
     1.9  #if TARGET_OS_IPHONE
    1.10  // marked for iOS to think about what we want on macOS
    1.11  const char* _Nullable perMachineDirectory = NULL;
    1.12 @@ -74,18 +76,45 @@
    1.13  }
    1.14  
    1.15  /**
    1.16 + Looks up (and creates if necessary) a pEp directory under "Application Support".
    1.17 +
    1.18 + @return A URL pointing a pEp directory under "Application Support".
    1.19 + */
    1.20 ++ (NSURL *)createApplicationDirectoryOSX
    1.21 +{
    1.22 +    NSFileManager *fm = [NSFileManager defaultManager];
    1.23 +    NSURL *dirPath = nil;
    1.24 +
    1.25 +    // Find the application support directory in the home directory.
    1.26 +    NSArray *appSupportDir = [fm URLsForDirectory:NSApplicationSupportDirectory
    1.27 +                                        inDomains:NSUserDomainMask];
    1.28 +    if ([appSupportDir count] > 0)
    1.29 +    {
    1.30 +        // Append the bundle ID to the URL for the
    1.31 +        // Application Support directory.
    1.32 +        // Mainly needed for OS X, but doesn't do any harm on iOS
    1.33 +        dirPath = [[appSupportDir objectAtIndex:0] URLByAppendingPathComponent:s_pEpHomeComponent];
    1.34 +
    1.35 +        // If the directory does not exist, this method creates it.
    1.36 +        // This method is only available in OS X v10.7 and iOS 5.0 or later.
    1.37 +        NSError *theError = nil;
    1.38 +        if (![fm createDirectoryAtURL:dirPath withIntermediateDirectories:YES
    1.39 +                           attributes:nil error:&theError])
    1.40 +        {
    1.41 +            // Handle the error.
    1.42 +            return nil;
    1.43 +        }
    1.44 +    }
    1.45 +
    1.46 +    return dirPath;
    1.47 +}
    1.48 +
    1.49 +/**
    1.50   Looks up the shared directory for pEp apps under iOS and makes sure it exists.
    1.51  
    1.52 - Derived settings:
    1.53 -
    1.54 - * $HOME (the engine uses that).
    1.55 - * The engine's per_user_directory (which is placed under $HOME).
    1.56 - * The engine's per_machine_directory (see [PEPObjCAdapter setPerMachineDirectory:]).
    1.57 -
    1.58 - @return A URL pointing to as app-specific directory under the OS defined
    1.59 -         application support directory for the current user.
    1.60 - */
    1.61 -+ (NSURL *)createApplicationDirectory
    1.62 + @return A URL pointing a pEp directory in the app container.
    1.63 +*/
    1.64 ++ (NSURL *)createApplicationDirectoryiOS
    1.65  {
    1.66      NSString *appGroupId = @"group.security.pep.pep4ios";
    1.67      NSFileManager *fm = [NSFileManager defaultManager];
    1.68 @@ -103,7 +132,7 @@
    1.69          NSLog(@"ERROR: No app container, no application support directory.");
    1.70      }
    1.71  
    1.72 -    NSURL *dirPath = [containerUrl URLByAppendingPathComponent:@"pEp_home"];
    1.73 +    NSURL *dirPath = [containerUrl URLByAppendingPathComponent:s_pEpHomeComponent];
    1.74  
    1.75      // If the directory does not exist, this method creates it.
    1.76      NSError *theError = nil;
    1.77 @@ -116,6 +145,22 @@
    1.78  }
    1.79  
    1.80  /**
    1.81 + Looks up the shared directory for pEp apps under iOS and makes sure it exists.
    1.82 +
    1.83 + Derived settings:
    1.84 +
    1.85 + * $HOME (the engine uses that).
    1.86 + * The engine's per_user_directory (which is placed under $HOME).
    1.87 + * The engine's per_machine_directory (see [PEPObjCAdapter setPerMachineDirectory:]).
    1.88 +
    1.89 + @return A URL pointing to as app-specific directory under the OS defined
    1.90 + application support directory for the current user.
    1.91 + */
    1.92 ++ (NSURL *)createApplicationDirectory
    1.93 +{
    1.94 +}
    1.95 +
    1.96 +/**
    1.97   Sets the directory that will be fed into the engine's per_machine_directory.
    1.98  
    1.99   Does not handle macOS. For macOS, either PER_MACHINE_DIRECTORY has to be defined