merge IOS-1784
authorbuff <andreas@pep-project.org>
Sat, 31 Aug 2019 15:41:09 +0200
changeset 117669489664b17a
parent 1168 91dae11f1818
parent 1175 afeecbeb15bd
child 1207 dcb796de488a
child 1209 7e5d2533178c
merge IOS-1784
     1.1 --- a/pEpObjCAdapter/PEPObjCAdapter.m	Mon Aug 12 18:27:28 2019 +0200
     1.2 +++ b/pEpObjCAdapter/PEPObjCAdapter.m	Sat Aug 31 15:41:09 2019 +0200
     1.3 @@ -19,7 +19,11 @@
     1.4  
     1.5  const PEP_decrypt_flags PEP_decrypt_flag_none = 0x0;
     1.6  
     1.7 -const char* _Nullable SystemDB = NULL;
     1.8 +#if TARGET_OS_IPHONE
     1.9 +// marked for iOS to think about what we want on macOS
    1.10 +const char* _Nullable perMachineDirectory = NULL;
    1.11 +#endif
    1.12 +
    1.13  NSURL *s_homeURL;
    1.14  
    1.15  static BOOL s_unEncryptedSubjectEnabled = NO;
    1.16 @@ -56,7 +60,7 @@
    1.17  + (void)initialize
    1.18  {
    1.19      s_homeURL = [self createApplicationDirectory];
    1.20 -    [self setHomeDirectory:s_homeURL]; // Important, defines $HOME and $TEMP for the engine
    1.21 +    [self setPerMachineDirectory:s_homeURL]; // Important, defines $HOME for the engine //???: how I understand the OS does define HOME
    1.22  }
    1.23  
    1.24  + (NSURL *)homeURL
    1.25 @@ -98,14 +102,14 @@
    1.26      return dirPath;
    1.27  }
    1.28  
    1.29 -+ (void)setHomeDirectory:(NSURL *)homeDir
    1.30 ++ (void)setPerMachineDirectory:(NSURL *)homeDir
    1.31  {
    1.32 -    // create and set home directory
    1.33 -    setenv("HOME", [[homeDir path] cStringUsingEncoding:NSUTF8StringEncoding], 1);
    1.34 -    
    1.35 -    // create and set temp directory
    1.36 -    NSURL *tmpDirUrl = [NSURL fileURLWithPath:NSTemporaryDirectory() isDirectory:YES];
    1.37 -    setenv("TEMP", [[tmpDirUrl path] cStringUsingEncoding:NSUTF8StringEncoding], 1);
    1.38 +#if TARGET_OS_IPHONE
    1.39 +    if (perMachineDirectory) {
    1.40 +        free((void *) perMachineDirectory);
    1.41 +    }
    1.42 +    perMachineDirectory = strdup([homeDir path].UTF8String);
    1.43 +#endif
    1.44  }
    1.45  
    1.46  + (NSString *)getBundlePathFor: (NSString *) filename
    1.47 @@ -113,25 +117,24 @@
    1.48      return nil;
    1.49  }
    1.50  
    1.51 -+ (NSString *)copyAssetsIntoDocumentsDirectory:(NSBundle *)rootBundle
    1.52 ++ (void)copyAssetsIntoDocumentsDirectory:(NSBundle *)rootBundle
    1.53                                      bundleName:(NSString *)bundleName
    1.54                                        fileName:(NSString *)fileName {
    1.55 +
    1.56 +    NSString *systemDir = [NSString stringWithUTF8String:perMachineDirectory];
    1.57      
    1.58 -    NSURL *homeUrl = s_homeURL;
    1.59 -    NSString *documentsDirectory = [homeUrl path];
    1.60 -    
    1.61 -    if(!(documentsDirectory && bundleName && fileName))
    1.62 -        return nil;
    1.63 +    if(!(systemDir && bundleName && fileName))
    1.64 +        return;
    1.65      
    1.66      // Check if the database file exists in the documents directory.
    1.67 -    NSString *destinationPath = [documentsDirectory stringByAppendingPathComponent:fileName];
    1.68 +    NSString *destinationPath = [systemDir stringByAppendingPathComponent:fileName];
    1.69      if (![[NSFileManager defaultManager] fileExistsAtPath:destinationPath]) {
    1.70          // The file does not exist in the documents directory, so copy it from bundle now.
    1.71          NSBundle *bundleObj = [NSBundle bundleWithPath:
    1.72                                 [[rootBundle resourcePath]
    1.73                                  stringByAppendingPathComponent: bundleName]];
    1.74          if (!bundleObj)
    1.75 -            return nil;
    1.76 +            return;
    1.77          
    1.78          NSString *sourcePath =[[bundleObj resourcePath] stringByAppendingPathComponent: fileName];
    1.79          
    1.80 @@ -142,21 +145,18 @@
    1.81          // Check if any error occurred during copying and display it.
    1.82          if (error != nil) {
    1.83              NSLog(@"%@", [error localizedDescription]);
    1.84 -            return nil;
    1.85          }
    1.86      }
    1.87 -    return destinationPath;
    1.88  }
    1.89  
    1.90 -+ (void)setupTrustWordsDB:(NSBundle *)rootBundle{
    1.91 -    NSString *systemDBPath = [PEPObjCAdapter
    1.92 -                              copyAssetsIntoDocumentsDirectory:rootBundle
    1.93 -                              bundleName:@"pEpTrustWords.bundle"
    1.94 -                              fileName:@"system.db"];
    1.95 -    if (SystemDB) {
    1.96 -        free((void *) SystemDB);
    1.97 -    }
    1.98 -    SystemDB = strdup(systemDBPath.UTF8String);
    1.99 ++ (void)setupTrustWordsDB:(NSBundle *)rootBundle {
   1.100 +// iOS to force us to think about macOS
   1.101 +#if TARGET_OS_IPHONE
   1.102 +    [PEPObjCAdapter copyAssetsIntoDocumentsDirectory:rootBundle
   1.103 +                                          bundleName:@"pEpTrustWords.bundle"
   1.104 +                                            fileName:@"system.db"];
   1.105 +
   1.106 +#endif
   1.107  }
   1.108  
   1.109  + (void)setupTrustWordsDB