/ include / CoreFoundation / CFBundle_Internal.h
CFBundle_Internal.h
  1  /*
  2   * Copyright (c) 2015 Apple Inc. All rights reserved.
  3   *
  4   * @APPLE_LICENSE_HEADER_START@
  5   *
  6   * This file contains Original Code and/or Modifications of Original Code
  7   * as defined in and that are subject to the Apple Public Source License
  8   * Version 2.0 (the 'License'). You may not use this file except in
  9   * compliance with the License. Please obtain a copy of the License at
 10   * http://www.opensource.apple.com/apsl/ and read it before using this
 11   * file.
 12   *
 13   * The Original Code and all software distributed under the License are
 14   * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
 15   * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
 16   * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
 17   * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
 18   * Please see the License for the specific language governing rights and
 19   * limitations under the License.
 20   *
 21   * @APPLE_LICENSE_HEADER_END@
 22   */
 23  
 24  /*	CFBundle_Internal.h
 25  	Copyright (c) 1999-2014, Apple Inc.  All rights reserved.
 26  */
 27  
 28  #if !defined(__COREFOUNDATION_CFBUNDLE_INTERNAL__)
 29  #define __COREFOUNDATION_CFBUNDLE_INTERNAL__ 1
 30  
 31  #include <CoreFoundation/CFDate.h>
 32  #include <CoreFoundation/CFBundle.h>
 33  #include <CoreFoundation/CFPlugIn.h>
 34  #include <CoreFoundation/CFError.h>
 35  #include "CFInternal.h"
 36  #include "CFPlugIn_Factory.h"
 37  #include "CFBundle_BinaryTypes.h"
 38  #include "CFByteOrder.h"
 39  
 40  CF_EXTERN_C_BEGIN
 41  
 42  #define __kCFLogBundle       3
 43  #define __kCFLogPlugIn       3
 44  
 45  #if DEPLOYMENT_TARGET_WINDOWS
 46  #define PLATFORM_PATH_STYLE kCFURLWindowsPathStyle
 47  #else
 48  #define PLATFORM_PATH_STYLE kCFURLPOSIXPathStyle
 49  #endif
 50  
 51  #define CFBundleExecutableNotFoundError             4
 52  #define CFBundleExecutableNotLoadableError          3584
 53  #define CFBundleExecutableArchitectureMismatchError 3585
 54  #define CFBundleExecutableRuntimeMismatchError      3586
 55  #define CFBundleExecutableLoadError                 3587
 56  #define CFBundleExecutableLinkError                 3588
 57  
 58  CF_INLINE uint32_t _CFBundleSwapInt32Conditional(uint32_t arg, Boolean swap) {return swap ? CFSwapInt32(arg) : arg;}
 59  CF_INLINE uint32_t _CFBundleSwapInt64Conditional(uint64_t arg, Boolean swap) {return swap ? CFSwapInt64(arg) : arg;}
 60  
 61  // uncomment this to enable the checking for 8302591
 62  //#define CFBUNDLE_NO_TRAVERSE_OUTSIDE
 63  
 64  typedef struct __CFResourceData {
 65      Boolean _executableLacksResourceFork;
 66      Boolean _infoDictionaryFromResourceFork;
 67      char _padding[2];
 68  } _CFResourceData;
 69  
 70  CF_PRIVATE _CFResourceData *__CFBundleGetResourceData(CFBundleRef bundle);
 71  
 72  typedef struct __CFPlugInData {
 73      Boolean _isPlugIn;
 74      Boolean _loadOnDemand;
 75      Boolean _isDoingDynamicRegistration;
 76      Boolean _unused1;
 77      UInt32 _instanceCount;
 78      CFMutableArrayRef _factories;
 79  } _CFPlugInData;
 80  
 81  struct __CFBundle {
 82      CFRuntimeBase _base;
 83      
 84      CFURLRef _url;
 85      CFDateRef _modDate;
 86      
 87      __strong CFDictionaryRef _infoDict;
 88      __strong CFDictionaryRef _localInfoDict;
 89      CFArrayRef _searchLanguages;
 90      
 91      __CFPBinaryType _binaryType;
 92      Boolean _isLoaded;
 93      uint8_t _version;
 94      Boolean _sharesStringsFiles;
 95      char _padding[1];
 96      
 97      /* CFM goop */
 98      void *_connectionCookie;
 99      
100      /* DYLD goop */
101      const void *_imageCookie;
102      const void *_moduleCookie;
103      
104      /* dlfcn goop */
105      void *_handleCookie;
106      
107      /* CFM<->DYLD glue */
108      CFMutableDictionaryRef _glueDict;
109      
110      /* Resource fork goop */
111      _CFResourceData _resourceData;
112      
113      _CFPlugInData _plugInData;
114      
115      pthread_mutex_t _bundleLoadingLock;
116      
117      CFStringRef _executablePath; // Calculated and cached here
118      CFStringRef _developmentRegion; // Calculated and cached here
119      dispatch_once_t _developmentRegionCalculated;
120      
121      CFLock_t _lock;
122      
123      CFArrayRef _localizations; // List of localizations, including the development language fallback if required
124      Boolean _lookedForLocalizations;
125      
126      CFMutableDictionaryRef _resourceDirectoryContents;
127      
128      CFMutableDictionaryRef _stringTable;
129      
130      CFLock_t _queryLock;
131      CFMutableDictionaryRef _queryTable;
132      CFStringRef _bundleBasePath;
133      
134  #if defined(BINARY_SUPPORT_DLL)
135      HMODULE _hModule;
136  #endif /* BINARY_SUPPORT_DLL */
137      
138  };
139  
140  extern _CFPlugInData *__CFBundleGetPlugInData(CFBundleRef bundle);
141  
142  /* Private CFBundle API */
143  
144  CF_PRIVATE CFErrorRef _CFBundleCreateErrorDebug(CFAllocatorRef allocator, CFBundleRef bundle, CFIndex code, CFStringRef debugString);
145  
146  CF_PRIVATE void _CFBundleInfoPlistProcessInfoDictionary(CFMutableDictionaryRef dict);
147  CF_PRIVATE Boolean _CFBundleSupportedProductName(CFStringRef fileName, CFRange searchRange);
148  CF_PRIVATE Boolean _CFBundleSupportedPlatformName(CFStringRef fileName, CFRange searchRange);
149  
150  CF_EXPORT CFStringRef _CFGetProductName(void);
151  CF_EXPORT CFStringRef _CFGetPlatformName(void);
152  CF_EXPORT CFStringRef _CFGetAlternatePlatformName(void);
153  
154  CF_PRIVATE void _CFBundleFlushQueryTableCache(CFBundleRef bundle);
155  
156  CF_PRIVATE SInt32 _CFBundleCurrentArchitecture(void);
157  CF_PRIVATE Boolean _CFBundleGetObjCImageInfo(CFBundleRef bundle, uint32_t *objcVersion, uint32_t *objcFlags);
158  
159  #if defined(BINARY_SUPPORT_DYLD)
160  CF_PRIVATE CFMutableDictionaryRef _CFBundleCreateInfoDictFromMainExecutable();
161  CF_PRIVATE Boolean _CFBundleGrokObjCImageInfoFromMainExecutable(uint32_t *objcVersion, uint32_t *objcFlags);
162  #endif
163  
164  CF_PRIVATE CFStringRef _CFBundleCopyLoadedImagePathForPointer(void *p);
165  
166  // Languages and locales
167  
168  CF_PRIVATE CFArrayRef _CFBundleCopyLanguageSearchListInDirectory(CFURLRef url, uint8_t *version);
169  CF_PRIVATE CFArrayRef _CFBundleCopyLanguageSearchListInBundle(CFBundleRef bundle);
170  
171  CF_PRIVATE Boolean CFBundleAllowMixedLocalizations(void);
172  
173  // Misc
174  
175  extern Boolean _CFIsResourceAtURL(CFURLRef url, Boolean *isDir);
176  extern Boolean _CFIsResourceAtPath(CFStringRef path, Boolean *isDir);
177  
178  CF_PRIVATE uint8_t _CFBundleGetBundleVersionForURL(CFURLRef url);
179  extern CFDictionaryRef _CFBundleCopyInfoDictionaryInDirectory(CFAllocatorRef alloc, CFURLRef url, UInt8 *version);
180  extern CFDictionaryRef _CFBundleCopyInfoDictionaryInDirectoryWithVersion(CFAllocatorRef alloc, CFURLRef url, UInt8 version);
181  extern CFURLRef _CFBundleCopySupportFilesDirectoryURLInDirectory(CFURLRef bundleURL, UInt8 version);
182  extern CFURLRef _CFBundleCopyResourcesDirectoryURLInDirectory(CFURLRef bundleURL, UInt8 version);
183  
184  extern Boolean _CFBundleCouldBeBundle(CFURLRef url);
185  extern CFDictionaryRef _CFBundleCopyInfoDictionaryInResourceForkWithAllocator(CFAllocatorRef alloc, CFURLRef url);
186  CF_PRIVATE CFStringRef _CFBundleCopyExecutableName(CFBundleRef bundle, CFURLRef url, CFDictionaryRef infoDict);
187  #if DEPLOYMENT_TARGET_MACOSX
188  CF_PRIVATE CFStringRef _CFBundleCopyBundleDevelopmentRegionFromVersResource(CFBundleRef bundle);
189  #endif
190  extern CFDictionaryRef _CFBundleCopyInfoDictionaryInExecutable(CFURLRef url);
191  extern CFArrayRef _CFBundleCopyArchitecturesForExecutable(CFURLRef url);
192  
193  extern CFStringRef _CFBundleGetPlatformExecutablesSubdirectoryName(void);
194  extern CFStringRef _CFBundleGetAlternatePlatformExecutablesSubdirectoryName(void);
195  extern CFStringRef _CFBundleGetOtherPlatformExecutablesSubdirectoryName(void);
196  extern CFStringRef _CFBundleGetOtherAlternatePlatformExecutablesSubdirectoryName(void);
197  
198  extern CFStringRef _CFCreateStringFromVersionNumber(CFAllocatorRef alloc, UInt32 vers);
199  extern UInt32 _CFVersionNumberFromString(CFStringRef versStr);
200  
201  extern void _CFBundleScheduleForUnloading(CFBundleRef bundle);
202  extern void _CFBundleUnscheduleForUnloading(CFBundleRef bundle);
203  extern void _CFBundleUnloadScheduledBundles(void);
204  
205  CF_PRIVATE void _CFBundleAppendResourceDir(CFMutableStringRef path, uint8_t version);
206  
207  CF_PRIVATE UInt8 _CFBundleLayoutVersion(CFBundleRef bundle);
208  
209  #if defined(BINARY_SUPPORT_DYLD)
210  // DYLD API
211  extern __CFPBinaryType _CFBundleGrokBinaryType(CFURLRef executableURL);
212  extern CFArrayRef _CFBundleDYLDCopyLoadedImagePathsIfChanged(void);
213  extern CFArrayRef _CFBundleDYLDCopyLoadedImagePathsForHint(CFStringRef hint);
214  #if !defined(BINARY_SUPPORT_DLFCN)
215  extern Boolean _CFBundleDYLDCheckLoaded(CFBundleRef bundle);
216  extern Boolean _CFBundleDYLDLoadBundle(CFBundleRef bundle, Boolean forceGlobal, CFErrorRef *error);
217  extern Boolean _CFBundleDYLDLoadFramework(CFBundleRef bundle, CFErrorRef *error);
218  extern void _CFBundleDYLDUnloadBundle(CFBundleRef bundle);
219  extern void *_CFBundleDYLDGetSymbolByName(CFBundleRef bundle, CFStringRef symbolName);
220  #endif /* !BINARY_SUPPORT_DLFCN */
221  #endif /* BINARY_SUPPORT_DYLD */
222  
223  #if defined(BINARY_SUPPORT_DLFCN)
224  // dlfcn API
225  extern Boolean _CFBundleDlfcnCheckLoaded(CFBundleRef bundle);
226  extern Boolean _CFBundleDlfcnPreflight(CFBundleRef bundle, CFErrorRef *error);
227  extern Boolean _CFBundleDlfcnLoadBundle(CFBundleRef bundle, Boolean forceGlobal, CFErrorRef *error);
228  extern Boolean _CFBundleDlfcnLoadFramework(CFBundleRef bundle, CFErrorRef *error);
229  extern void _CFBundleDlfcnUnload(CFBundleRef bundle);
230  extern void *_CFBundleDlfcnGetSymbolByName(CFBundleRef bundle, CFStringRef symbolName);
231  #endif /* BINARY_SUPPORT_DLFCN */
232  
233  #if defined(BINARY_SUPPORT_DLL)
234  extern Boolean _CFBundleDLLLoad(CFBundleRef bundle, CFErrorRef *error);
235  extern void _CFBundleDLLUnload(CFBundleRef bundle);
236  extern void *_CFBundleDLLGetSymbolByName(CFBundleRef bundle, CFStringRef symbolName);
237  #endif /* BINARY_SUPPORT_DLL */
238  
239  
240  /* Private PlugIn-related CFBundle API */
241  
242  extern Boolean _CFBundleNeedsInitPlugIn(CFBundleRef bundle);
243  extern void _CFBundleInitPlugIn(CFBundleRef bundle);
244  extern void _CFBundlePlugInLoaded(CFBundleRef bundle);
245  extern void _CFBundleDeallocatePlugIn(CFBundleRef bundle);
246  
247  extern void _CFPlugInWillUnload(CFPlugInRef plugIn);
248  
249  extern void _CFPlugInAddPlugInInstance(CFPlugInRef plugIn);
250  extern void _CFPlugInRemovePlugInInstance(CFPlugInRef plugIn);
251  
252  extern void _CFPlugInAddFactory(CFPlugInRef plugIn, _CFPFactoryRef factory);
253  extern void _CFPlugInRemoveFactory(CFPlugInRef plugIn, _CFPFactoryRef factory);
254  
255  
256  /* Strings for parsing bundle structure */
257  #define _CFBundleSupportFilesDirectoryName1 CFSTR("Support Files")
258  #define _CFBundleSupportFilesDirectoryName2 CFSTR("Contents")
259  #define _CFBundleResourcesDirectoryName CFSTR("Resources")
260  #define _CFBundleExecutablesDirectoryName CFSTR("Executables")
261  #define _CFBundleNonLocalizedResourcesDirectoryName CFSTR("Non-localized Resources")
262  
263  #if DEPLOYMENT_TARGET_WINDOWS
264  #define _CFBundleSupportFilesDirectoryName1WithResources CFSTR("Support Files\\Resources")
265  #define _CFBundleSupportFilesDirectoryName2WithResources CFSTR("Contents\\Resources")
266  #else
267  #define _CFBundleSupportFilesDirectoryName1WithResources CFSTR("Support Files/Resources")
268  #define _CFBundleSupportFilesDirectoryName2WithResources CFSTR("Contents/Resources")
269  #endif
270  
271  #define _CFBundleSupportFilesURLFromBase1 CFSTR("Support%20Files/")
272  #define _CFBundleSupportFilesURLFromBase2 CFSTR("Contents/")
273  #define _CFBundleResourcesURLFromBase0 CFSTR("Resources/")
274  #define _CFBundleResourcesURLFromBase1 CFSTR("Support%20Files/Resources/")
275  #define _CFBundleResourcesURLFromBase2 CFSTR("Contents/Resources/")
276  #define _CFBundleAppStoreReceiptURLFromBase0 CFSTR("_MASReceipt/receipt")
277  #define _CFBundleAppStoreReceiptURLFromBase1 CFSTR("Support%20Files/_MASReceipt/receipt")
278  #define _CFBundleAppStoreReceiptURLFromBase2 CFSTR("Contents/_MASReceipt/receipt")
279  #define _CFBundleExecutablesURLFromBase1 CFSTR("Support%20Files/Executables/")
280  #define _CFBundleExecutablesURLFromBase2 CFSTR("Contents/")
281  
282  #define _CFBundleInfoURLFromBase0 CFSTR("Resources/Info.plist")
283  #define _CFBundleInfoURLFromBase1 CFSTR("Support%20Files/Info.plist")
284  #define _CFBundleInfoURLFromBase2 CFSTR("Contents/Info.plist")
285  #define _CFBundleInfoURLFromBase3 CFSTR("Info.plist")
286  #define _CFBundleInfoURLFromBaseNoExtension3 CFSTR("Info")
287  
288  #if DEPLOYMENT_TARGET_MACOSX
289  #define _CFBundlePlatformInfoURLFromBase0 CFSTR("Resources/Info-macos.plist")
290  #define _CFBundlePlatformInfoURLFromBase1 CFSTR("Support%20Files/Info-macos.plist")
291  #define _CFBundlePlatformInfoURLFromBase2 CFSTR("Contents/Info-macos.plist")
292  #define _CFBundlePlatformInfoURLFromBase3 CFSTR("Info-macos.plist")
293  #elif DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_EMBEDDED_MINI
294  #define _CFBundlePlatformInfoURLFromBase0 CFSTR("Resources/Info-iphoneos.plist")
295  #define _CFBundlePlatformInfoURLFromBase1 CFSTR("Support%20Files/Info-iphoneos.plist")
296  #define _CFBundlePlatformInfoURLFromBase2 CFSTR("Contents/Info-iphoneos.plist")
297  #define _CFBundlePlatformInfoURLFromBase3 CFSTR("Info-iphoneos.plist")
298  #else
299  // No platform-specific variants in these cases
300  #define _CFBundlePlatformInfoURLFromBase0 _CFBundleInfoURLFromBase0
301  #define _CFBundlePlatformInfoURLFromBase1 _CFBundleInfoURLFromBase1
302  #define _CFBundlePlatformInfoURLFromBase2 _CFBundleInfoURLFromBase2
303  #define _CFBundlePlatformInfoURLFromBase3 _CFBundleInfoURLFromBase3
304  #endif
305  
306  #define _CFBundleInfoPlistName CFSTR("Info.plist")
307  
308  #if DEPLOYMENT_TARGET_MACOSX
309  #define _CFBundlePlatformInfoPlistName CFSTR("Info-macos.plist")
310  #elif DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_EMBEDDED_MINI
311  #define _CFBundlePlatformInfoPlistName CFSTR("Info-iphoneos.plist")
312  #else
313  // No platform-specific Info.plist for these
314  #define _CFBundlePlatformInfoPlistName _CFBundleInfoPlistName
315  #endif
316  
317  #define _CFBundleInfoExtension CFSTR("plist")
318  #define _CFBundleLocalInfoName CFSTR("InfoPlist")
319  #define _CFBundlePkgInfoURLFromBase1 CFSTR("Support%20Files/PkgInfo")
320  #define _CFBundlePkgInfoURLFromBase2 CFSTR("Contents/PkgInfo")
321  #define _CFBundlePseudoPkgInfoURLFromBase CFSTR("PkgInfo")
322  #define _CFBundlePrivateFrameworksURLFromBase0 CFSTR("Frameworks/")
323  #define _CFBundlePrivateFrameworksURLFromBase1 CFSTR("Support%20Files/Frameworks/")
324  #define _CFBundlePrivateFrameworksURLFromBase2 CFSTR("Contents/Frameworks/")
325  #define _CFBundleSharedFrameworksURLFromBase0 CFSTR("SharedFrameworks/")
326  #define _CFBundleSharedFrameworksURLFromBase1 CFSTR("Support%20Files/SharedFrameworks/")
327  #define _CFBundleSharedFrameworksURLFromBase2 CFSTR("Contents/SharedFrameworks/")
328  #define _CFBundleSharedSupportURLFromBase0 CFSTR("SharedSupport/")
329  #define _CFBundleSharedSupportURLFromBase1 CFSTR("Support%20Files/SharedSupport/")
330  #define _CFBundleSharedSupportURLFromBase2 CFSTR("Contents/SharedSupport/")
331  #define _CFBundleBuiltInPlugInsURLFromBase0 CFSTR("PlugIns/")
332  #define _CFBundleBuiltInPlugInsURLFromBase1 CFSTR("Support%20Files/PlugIns/")
333  #define _CFBundleBuiltInPlugInsURLFromBase2 CFSTR("Contents/PlugIns/")
334  #define _CFBundleAlternateBuiltInPlugInsURLFromBase0 CFSTR("Plug-ins/")
335  #define _CFBundleAlternateBuiltInPlugInsURLFromBase1 CFSTR("Support%20Files/Plug-ins/")
336  #define _CFBundleAlternateBuiltInPlugInsURLFromBase2 CFSTR("Contents/Plug-ins/")
337  
338  #define _CFBundleLprojExtension CFSTR("lproj")
339  #define _CFBundleLprojExtensionWithDot CFSTR(".lproj")
340  #define _CFBundleDot CFSTR(".")
341  #define _CFBundleAllFiles CFSTR("_CFBAF_")
342  #define _CFBundleTypeIndicator CFSTR("_CFBT_")
343  // This directory contains resources (especially nibs) that may look up localized resources or may fall back to the development language resources
344  #define _CFBundleBaseDirectory CFSTR("Base")
345  
346  #define _CFBundleMacOSXPlatformName CFSTR("macos")
347  #define _CFBundleAlternateMacOSXPlatformName CFSTR("macosx")
348  #define _CFBundleiPhoneOSPlatformName CFSTR("iphoneos")
349  #define _CFBundleMacOS8PlatformName CFSTR("macosclassic")
350  #define _CFBundleAlternateMacOS8PlatformName CFSTR("macos8")
351  #define _CFBundleWindowsPlatformName CFSTR("windows")
352  #define _CFBundleHPUXPlatformName CFSTR("hpux")
353  #define _CFBundleSolarisPlatformName CFSTR("solaris")
354  #define _CFBundleLinuxPlatformName CFSTR("linux")
355  #define _CFBundleFreeBSDPlatformName CFSTR("freebsd")
356  
357  #define _CFBundleDefaultStringTableName CFSTR("Localizable")
358  #define _CFBundleStringTableType CFSTR("strings")
359  #define _CFBundleStringDictTableType CFSTR("stringsdict")
360  
361  #define _CFBundleUserLanguagesPreferenceName CFSTR("AppleLanguages")
362  #define _CFBundleOldUserLanguagesPreferenceName CFSTR("NSLanguages")
363  
364  #define _CFBundleLocalizedResourceForkFileName CFSTR("Localized")
365  
366  #define _CFBundleWindowsResourceDirectoryExtension CFSTR("resources")
367  
368  #define _CFBundleMacOSXInfoPlistPlatformName_OLD CFSTR("macos")
369  #define _CFBundleWindowsInfoPlistPlatformName_OLD CFSTR("win32")
370  
371  CF_EXTERN_C_END
372  
373  #endif /* ! __COREFOUNDATION_CFBUNDLE_INTERNAL__ */
374