2 * Copyright (c) 2014 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
24 /* CFBundle_Internal.h
25 Copyright (c) 1999-2013, Apple Inc. All rights reserved.
28 #if !defined(__COREFOUNDATION_CFBUNDLE_INTERNAL__)
29 #define __COREFOUNDATION_CFBUNDLE_INTERNAL__ 1
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"
41 #define __kCFLogBundle 3
42 #define __kCFLogPlugIn 3
44 #if DEPLOYMENT_TARGET_WINDOWS
45 #define PLATFORM_PATH_STYLE kCFURLWindowsPathStyle
47 #define PLATFORM_PATH_STYLE kCFURLPOSIXPathStyle
50 #define CFBundleExecutableNotFoundError 4
51 #define CFBundleExecutableNotLoadableError 3584
52 #define CFBundleExecutableArchitectureMismatchError 3585
53 #define CFBundleExecutableRuntimeMismatchError 3586
54 #define CFBundleExecutableLoadError 3587
55 #define CFBundleExecutableLinkError 3588
57 // uncomment this to enable the checking for 8302591
58 //#define CFBUNDLE_NO_TRAVERSE_OUTSIDE
60 typedef struct __CFResourceData
{
61 CFMutableDictionaryRef _stringTableCache
;
62 Boolean _executableLacksResourceFork
;
63 Boolean _infoDictionaryFromResourceFork
;
67 extern _CFResourceData
*__CFBundleGetResourceData(CFBundleRef bundle
);
69 typedef struct __CFPlugInData
{
71 Boolean _loadOnDemand
;
72 Boolean _isDoingDynamicRegistration
;
74 UInt32 _instanceCount
;
75 CFMutableArrayRef _factories
;
84 __strong CFDictionaryRef _infoDict
;
85 __strong CFDictionaryRef _localInfoDict
;
86 CFArrayRef _searchLanguages
;
88 __CFPBinaryType _binaryType
;
91 Boolean _sharesStringsFiles
;
95 void *_connectionCookie
;
98 const void *_imageCookie
;
99 const void *_moduleCookie
;
104 /* CFM<->DYLD glue */
105 CFMutableDictionaryRef _glueDict
;
107 /* Resource fork goop */
108 _CFResourceData _resourceData
;
110 _CFPlugInData _plugInData
;
112 pthread_mutex_t _bundleLoadingLock
;
114 CFStringRef _executablePath
; // Calculated and cached here
115 CFStringRef _developmentRegion
; // Calculated and cached here
116 Boolean _developmentRegionCalculated
;
120 CFArrayRef _localizations
; // List of localizations, including the development language fallback if required
121 Boolean _lookedForLocalizations
;
123 CFMutableDictionaryRef _resourceDirectoryContents
;
125 CFSpinLock_t _queryLock
;
126 CFMutableDictionaryRef _queryTable
;
127 CFStringRef _bundleBasePath
;
129 #if defined(BINARY_SUPPORT_DLL)
131 #endif /* BINARY_SUPPORT_DLL */
135 extern _CFPlugInData
*__CFBundleGetPlugInData(CFBundleRef bundle
);
137 /* Private CFBundle API */
139 CF_PRIVATE
void _CFBundleInfoPlistProcessInfoDictionary(CFMutableDictionaryRef dict
);
140 CF_PRIVATE Boolean
_CFBundleSupportedProductName(CFStringRef fileName
, CFRange searchRange
);
141 CF_PRIVATE Boolean
_CFBundleSupportedPlatformName(CFStringRef fileName
, CFRange searchRange
);
143 CF_EXPORT CFStringRef
_CFGetProductName(void);
144 CF_EXPORT CFStringRef
_CFGetPlatformName(void);
145 CF_EXPORT CFStringRef
_CFGetAlternatePlatformName(void);
147 extern Boolean
_CFIsResourceAtURL(CFURLRef url
, Boolean
*isDir
);
148 extern Boolean
_CFIsResourceAtPath(CFStringRef path
, Boolean
*isDir
);
150 CF_PRIVATE
uint8_t _CFBundleGetBundleVersionForURL(CFURLRef url
);
151 extern CFDictionaryRef
_CFBundleCopyInfoDictionaryInDirectory(CFAllocatorRef alloc
, CFURLRef url
, UInt8
*version
);
152 extern CFDictionaryRef
_CFBundleCopyInfoDictionaryInDirectoryWithVersion(CFAllocatorRef alloc
, CFURLRef url
, UInt8 version
);
153 extern CFURLRef
_CFBundleCopySupportFilesDirectoryURLInDirectory(CFURLRef bundleURL
, UInt8 version
);
154 extern CFURLRef
_CFBundleCopyResourcesDirectoryURLInDirectory(CFURLRef bundleURL
, UInt8 version
);
156 extern Boolean
_CFBundleCouldBeBundle(CFURLRef url
);
157 extern CFDictionaryRef
_CFBundleCopyInfoDictionaryInResourceForkWithAllocator(CFAllocatorRef alloc
, CFURLRef url
);
158 CF_PRIVATE CFStringRef
_CFBundleCopyExecutableName(CFBundleRef bundle
, CFURLRef url
, CFDictionaryRef infoDict
);
159 #if DEPLOYMENT_TARGET_MACOSX
160 CF_PRIVATE CFStringRef
_CFBundleCopyBundleDevelopmentRegionFromVersResource(CFBundleRef bundle
);
162 extern CFDictionaryRef
_CFBundleCopyInfoDictionaryInExecutable(CFURLRef url
);
163 extern CFArrayRef
_CFBundleCopyArchitecturesForExecutable(CFURLRef url
);
165 extern CFStringRef
_CFBundleGetPlatformExecutablesSubdirectoryName(void);
166 extern CFStringRef
_CFBundleGetAlternatePlatformExecutablesSubdirectoryName(void);
167 extern CFStringRef
_CFBundleGetOtherPlatformExecutablesSubdirectoryName(void);
168 extern CFStringRef
_CFBundleGetOtherAlternatePlatformExecutablesSubdirectoryName(void);
170 extern CFStringRef
_CFCreateStringFromVersionNumber(CFAllocatorRef alloc
, UInt32 vers
);
171 extern UInt32
_CFVersionNumberFromString(CFStringRef versStr
);
173 extern void _CFBundleScheduleForUnloading(CFBundleRef bundle
);
174 extern void _CFBundleUnscheduleForUnloading(CFBundleRef bundle
);
175 extern void _CFBundleUnloadScheduledBundles(void);
177 CF_PRIVATE
void _CFBundleAppendResourceDir(CFMutableStringRef path
, uint8_t version
);
179 CF_PRIVATE UInt8
_CFBundleLayoutVersion(CFBundleRef bundle
);
181 #if defined(BINARY_SUPPORT_DYLD)
183 extern __CFPBinaryType
_CFBundleGrokBinaryType(CFURLRef executableURL
);
184 extern CFArrayRef
_CFBundleDYLDCopyLoadedImagePathsIfChanged(void);
185 extern CFArrayRef
_CFBundleDYLDCopyLoadedImagePathsForHint(CFStringRef hint
);
186 #if !defined(BINARY_SUPPORT_DLFCN)
187 extern Boolean
_CFBundleDYLDCheckLoaded(CFBundleRef bundle
);
188 extern Boolean
_CFBundleDYLDLoadBundle(CFBundleRef bundle
, Boolean forceGlobal
, CFErrorRef
*error
);
189 extern Boolean
_CFBundleDYLDLoadFramework(CFBundleRef bundle
, CFErrorRef
*error
);
190 extern void _CFBundleDYLDUnloadBundle(CFBundleRef bundle
);
191 extern void *_CFBundleDYLDGetSymbolByName(CFBundleRef bundle
, CFStringRef symbolName
);
192 #endif /* !BINARY_SUPPORT_DLFCN */
193 #endif /* BINARY_SUPPORT_DYLD */
195 #if defined(BINARY_SUPPORT_DLFCN)
197 extern Boolean
_CFBundleDlfcnCheckLoaded(CFBundleRef bundle
);
198 extern Boolean
_CFBundleDlfcnPreflight(CFBundleRef bundle
, CFErrorRef
*error
);
199 extern Boolean
_CFBundleDlfcnLoadBundle(CFBundleRef bundle
, Boolean forceGlobal
, CFErrorRef
*error
);
200 extern Boolean
_CFBundleDlfcnLoadFramework(CFBundleRef bundle
, CFErrorRef
*error
);
201 extern void _CFBundleDlfcnUnload(CFBundleRef bundle
);
202 extern void *_CFBundleDlfcnGetSymbolByName(CFBundleRef bundle
, CFStringRef symbolName
);
203 #endif /* BINARY_SUPPORT_DLFCN */
205 #if defined(BINARY_SUPPORT_DLL)
206 extern Boolean
_CFBundleDLLLoad(CFBundleRef bundle
, CFErrorRef
*error
);
207 extern void _CFBundleDLLUnload(CFBundleRef bundle
);
208 extern void *_CFBundleDLLGetSymbolByName(CFBundleRef bundle
, CFStringRef symbolName
);
209 #endif /* BINARY_SUPPORT_DLL */
212 /* Private PlugIn-related CFBundle API */
214 extern Boolean
_CFBundleNeedsInitPlugIn(CFBundleRef bundle
);
215 extern void _CFBundleInitPlugIn(CFBundleRef bundle
);
216 extern void _CFBundlePlugInLoaded(CFBundleRef bundle
);
217 extern void _CFBundleDeallocatePlugIn(CFBundleRef bundle
);
219 extern void _CFPlugInWillUnload(CFPlugInRef plugIn
);
221 extern void _CFPlugInAddPlugInInstance(CFPlugInRef plugIn
);
222 extern void _CFPlugInRemovePlugInInstance(CFPlugInRef plugIn
);
224 extern void _CFPlugInAddFactory(CFPlugInRef plugIn
, _CFPFactoryRef factory
);
225 extern void _CFPlugInRemoveFactory(CFPlugInRef plugIn
, _CFPFactoryRef factory
);
228 /* Strings for parsing bundle structure */
229 #define _CFBundleSupportFilesDirectoryName1 CFSTR("Support Files")
230 #define _CFBundleSupportFilesDirectoryName2 CFSTR("Contents")
231 #define _CFBundleResourcesDirectoryName CFSTR("Resources")
232 #define _CFBundleExecutablesDirectoryName CFSTR("Executables")
233 #define _CFBundleNonLocalizedResourcesDirectoryName CFSTR("Non-localized Resources")
235 #if DEPLOYMENT_TARGET_WINDOWS
236 #define _CFBundleSupportFilesDirectoryName1WithResources CFSTR("Support Files\\Resources")
237 #define _CFBundleSupportFilesDirectoryName2WithResources CFSTR("Contents\\Resources")
239 #define _CFBundleSupportFilesDirectoryName1WithResources CFSTR("Support Files/Resources")
240 #define _CFBundleSupportFilesDirectoryName2WithResources CFSTR("Contents/Resources")
243 #define _CFBundleSupportFilesURLFromBase1 CFSTR("Support%20Files/")
244 #define _CFBundleSupportFilesURLFromBase2 CFSTR("Contents/")
245 #define _CFBundleResourcesURLFromBase0 CFSTR("Resources/")
246 #define _CFBundleResourcesURLFromBase1 CFSTR("Support%20Files/Resources/")
247 #define _CFBundleResourcesURLFromBase2 CFSTR("Contents/Resources/")
248 #define _CFBundleAppStoreReceiptURLFromBase0 CFSTR("_MASReceipt/receipt")
249 #define _CFBundleAppStoreReceiptURLFromBase1 CFSTR("Support%20Files/_MASReceipt/receipt")
250 #define _CFBundleAppStoreReceiptURLFromBase2 CFSTR("Contents/_MASReceipt/receipt")
251 #define _CFBundleExecutablesURLFromBase1 CFSTR("Support%20Files/Executables/")
252 #define _CFBundleExecutablesURLFromBase2 CFSTR("Contents/")
254 #define _CFBundleInfoURLFromBase0 CFSTR("Resources/Info.plist")
255 #define _CFBundleInfoURLFromBase1 CFSTR("Support%20Files/Info.plist")
256 #define _CFBundleInfoURLFromBase2 CFSTR("Contents/Info.plist")
257 #define _CFBundleInfoURLFromBase3 CFSTR("Info.plist")
258 #define _CFBundleInfoURLFromBaseNoExtension3 CFSTR("Info")
260 #if DEPLOYMENT_TARGET_MACOSX
261 #define _CFBundlePlatformInfoURLFromBase0 CFSTR("Resources/Info-macos.plist")
262 #define _CFBundlePlatformInfoURLFromBase1 CFSTR("Support%20Files/Info-macos.plist")
263 #define _CFBundlePlatformInfoURLFromBase2 CFSTR("Contents/Info-macos.plist")
264 #define _CFBundlePlatformInfoURLFromBase3 CFSTR("Info-macos.plist")
265 #elif DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_EMBEDDED_MINI
266 #define _CFBundlePlatformInfoURLFromBase0 CFSTR("Resources/Info-iphoneos.plist")
267 #define _CFBundlePlatformInfoURLFromBase1 CFSTR("Support%20Files/Info-iphoneos.plist")
268 #define _CFBundlePlatformInfoURLFromBase2 CFSTR("Contents/Info-iphoneos.plist")
269 #define _CFBundlePlatformInfoURLFromBase3 CFSTR("Info-iphoneos.plist")
271 // No platform-specific variants in these cases
272 #define _CFBundlePlatformInfoURLFromBase0 _CFBundleInfoURLFromBase0
273 #define _CFBundlePlatformInfoURLFromBase1 _CFBundleInfoURLFromBase1
274 #define _CFBundlePlatformInfoURLFromBase2 _CFBundleInfoURLFromBase2
275 #define _CFBundlePlatformInfoURLFromBase3 _CFBundleInfoURLFromBase3
278 #define _CFBundleInfoPlistName CFSTR("Info.plist")
280 #if DEPLOYMENT_TARGET_MACOSX
281 #define _CFBundlePlatformInfoPlistName CFSTR("Info-macos.plist")
282 #elif DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_EMBEDDED_MINI
283 #define _CFBundlePlatformInfoPlistName CFSTR("Info-iphoneos.plist")
285 // No platform-specific Info.plist for these
286 #define _CFBundlePlatformInfoPlistName _CFBundleInfoPlistName
289 #define _CFBundleInfoExtension CFSTR("plist")
290 #define _CFBundleLocalInfoName CFSTR("InfoPlist")
291 #define _CFBundlePkgInfoURLFromBase1 CFSTR("Support%20Files/PkgInfo")
292 #define _CFBundlePkgInfoURLFromBase2 CFSTR("Contents/PkgInfo")
293 #define _CFBundlePseudoPkgInfoURLFromBase CFSTR("PkgInfo")
294 #define _CFBundlePrivateFrameworksURLFromBase0 CFSTR("Frameworks/")
295 #define _CFBundlePrivateFrameworksURLFromBase1 CFSTR("Support%20Files/Frameworks/")
296 #define _CFBundlePrivateFrameworksURLFromBase2 CFSTR("Contents/Frameworks/")
297 #define _CFBundleSharedFrameworksURLFromBase0 CFSTR("SharedFrameworks/")
298 #define _CFBundleSharedFrameworksURLFromBase1 CFSTR("Support%20Files/SharedFrameworks/")
299 #define _CFBundleSharedFrameworksURLFromBase2 CFSTR("Contents/SharedFrameworks/")
300 #define _CFBundleSharedSupportURLFromBase0 CFSTR("SharedSupport/")
301 #define _CFBundleSharedSupportURLFromBase1 CFSTR("Support%20Files/SharedSupport/")
302 #define _CFBundleSharedSupportURLFromBase2 CFSTR("Contents/SharedSupport/")
303 #define _CFBundleBuiltInPlugInsURLFromBase0 CFSTR("PlugIns/")
304 #define _CFBundleBuiltInPlugInsURLFromBase1 CFSTR("Support%20Files/PlugIns/")
305 #define _CFBundleBuiltInPlugInsURLFromBase2 CFSTR("Contents/PlugIns/")
306 #define _CFBundleAlternateBuiltInPlugInsURLFromBase0 CFSTR("Plug-ins/")
307 #define _CFBundleAlternateBuiltInPlugInsURLFromBase1 CFSTR("Support%20Files/Plug-ins/")
308 #define _CFBundleAlternateBuiltInPlugInsURLFromBase2 CFSTR("Contents/Plug-ins/")
310 #define _CFBundleLprojExtension CFSTR("lproj")
311 #define _CFBundleLprojExtensionWithDot CFSTR(".lproj")
312 #define _CFBundleDot CFSTR(".")
313 #define _CFBundleAllFiles CFSTR("_CFBAF_")
314 #define _CFBundleTypeIndicator CFSTR("_CFBT_")
315 // This directory contains resources (especially nibs) that may look up localized resources or may fall back to the development language resources
316 #define _CFBundleBaseDirectory CFSTR("Base")
318 #define _CFBundleMacOSXPlatformName CFSTR("macos")
319 #define _CFBundleAlternateMacOSXPlatformName CFSTR("macosx")
320 #define _CFBundleiPhoneOSPlatformName CFSTR("iphoneos")
321 #define _CFBundleMacOS8PlatformName CFSTR("macosclassic")
322 #define _CFBundleAlternateMacOS8PlatformName CFSTR("macos8")
323 #define _CFBundleWindowsPlatformName CFSTR("windows")
324 #define _CFBundleHPUXPlatformName CFSTR("hpux")
325 #define _CFBundleSolarisPlatformName CFSTR("solaris")
326 #define _CFBundleLinuxPlatformName CFSTR("linux")
327 #define _CFBundleFreeBSDPlatformName CFSTR("freebsd")
329 #define _CFBundleDefaultStringTableName CFSTR("Localizable")
330 #define _CFBundleStringTableType CFSTR("strings")
331 #define _CFBundleStringDictTableType CFSTR("stringsdict")
333 #define _CFBundleUserLanguagesPreferenceName CFSTR("AppleLanguages")
334 #define _CFBundleOldUserLanguagesPreferenceName CFSTR("NSLanguages")
336 #define _CFBundleLocalizedResourceForkFileName CFSTR("Localized")
338 #define _CFBundleWindowsResourceDirectoryExtension CFSTR("resources")
340 #define _CFBundleMacOSXInfoPlistPlatformName_OLD CFSTR("macos")
341 #define _CFBundleWindowsInfoPlistPlatformName_OLD CFSTR("win32")
345 #endif /* ! __COREFOUNDATION_CFBUNDLE_INTERNAL__ */