1/*
2 * Copyright (c) 2014 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-2013, 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
39CF_EXTERN_C_BEGIN
40
41#define __kCFLogBundle       3
42#define __kCFLogPlugIn       3
43
44#if DEPLOYMENT_TARGET_WINDOWS
45#define PLATFORM_PATH_STYLE kCFURLWindowsPathStyle
46#else
47#define PLATFORM_PATH_STYLE kCFURLPOSIXPathStyle
48#endif
49
50#define CFBundleExecutableNotFoundError             4
51#define CFBundleExecutableNotLoadableError          3584
52#define CFBundleExecutableArchitectureMismatchError 3585
53#define CFBundleExecutableRuntimeMismatchError      3586
54#define CFBundleExecutableLoadError                 3587
55#define CFBundleExecutableLinkError                 3588
56
57// uncomment this to enable the checking for 8302591
58//#define CFBUNDLE_NO_TRAVERSE_OUTSIDE
59
60typedef struct __CFResourceData {
61    CFMutableDictionaryRef _stringTableCache;
62    Boolean _executableLacksResourceFork;
63    Boolean _infoDictionaryFromResourceFork;
64    char _padding[2];
65} _CFResourceData;
66
67extern _CFResourceData *__CFBundleGetResourceData(CFBundleRef bundle);
68
69typedef struct __CFPlugInData {
70    Boolean _isPlugIn;
71    Boolean _loadOnDemand;
72    Boolean _isDoingDynamicRegistration;
73    Boolean _unused1;
74    UInt32 _instanceCount;
75    CFMutableArrayRef _factories;
76} _CFPlugInData;
77
78struct __CFBundle {
79    CFRuntimeBase _base;
80
81    CFURLRef _url;
82    CFDateRef _modDate;
83
84    __strong CFDictionaryRef _infoDict;
85    __strong CFDictionaryRef _localInfoDict;
86    CFArrayRef _searchLanguages;
87
88    __CFPBinaryType _binaryType;
89    Boolean _isLoaded;
90    uint8_t _version;
91    Boolean _sharesStringsFiles;
92    char _padding[1];
93
94    /* CFM goop */
95    void *_connectionCookie;
96
97    /* DYLD goop */
98    const void *_imageCookie;
99    const void *_moduleCookie;
100
101    /* dlfcn goop */
102    void *_handleCookie;
103
104    /* CFM<->DYLD glue */
105    CFMutableDictionaryRef _glueDict;
106
107    /* Resource fork goop */
108    _CFResourceData _resourceData;
109
110    _CFPlugInData _plugInData;
111
112    pthread_mutex_t _bundleLoadingLock;
113
114    CFStringRef _executablePath; // Calculated and cached here
115    CFStringRef _developmentRegion; // Calculated and cached here
116    Boolean _developmentRegionCalculated;
117
118    CFSpinLock_t _lock;
119
120    CFArrayRef _localizations; // List of localizations, including the development language fallback if required
121    Boolean _lookedForLocalizations;
122
123    CFMutableDictionaryRef _resourceDirectoryContents;
124
125    CFSpinLock_t _queryLock;
126    CFMutableDictionaryRef _queryTable;
127    CFStringRef _bundleBasePath;
128
129#if defined(BINARY_SUPPORT_DLL)
130    HMODULE _hModule;
131#endif /* BINARY_SUPPORT_DLL */
132
133};
134
135extern _CFPlugInData *__CFBundleGetPlugInData(CFBundleRef bundle);
136
137/* Private CFBundle API */
138
139CF_PRIVATE void _CFBundleInfoPlistProcessInfoDictionary(CFMutableDictionaryRef dict);
140CF_PRIVATE Boolean _CFBundleSupportedProductName(CFStringRef fileName, CFRange searchRange);
141CF_PRIVATE Boolean _CFBundleSupportedPlatformName(CFStringRef fileName, CFRange searchRange);
142
143CF_EXPORT CFStringRef _CFGetProductName(void);
144CF_EXPORT CFStringRef _CFGetPlatformName(void);
145CF_EXPORT CFStringRef _CFGetAlternatePlatformName(void);
146
147extern Boolean _CFIsResourceAtURL(CFURLRef url, Boolean *isDir);
148extern Boolean _CFIsResourceAtPath(CFStringRef path, Boolean *isDir);
149
150CF_PRIVATE uint8_t _CFBundleGetBundleVersionForURL(CFURLRef url);
151extern CFDictionaryRef _CFBundleCopyInfoDictionaryInDirectory(CFAllocatorRef alloc, CFURLRef url, UInt8 *version);
152extern CFDictionaryRef _CFBundleCopyInfoDictionaryInDirectoryWithVersion(CFAllocatorRef alloc, CFURLRef url, UInt8 version);
153extern CFURLRef _CFBundleCopySupportFilesDirectoryURLInDirectory(CFURLRef bundleURL, UInt8 version);
154extern CFURLRef _CFBundleCopyResourcesDirectoryURLInDirectory(CFURLRef bundleURL, UInt8 version);
155
156extern Boolean _CFBundleCouldBeBundle(CFURLRef url);
157extern CFDictionaryRef _CFBundleCopyInfoDictionaryInResourceForkWithAllocator(CFAllocatorRef alloc, CFURLRef url);
158CF_PRIVATE CFStringRef _CFBundleCopyExecutableName(CFBundleRef bundle, CFURLRef url, CFDictionaryRef infoDict);
159#if DEPLOYMENT_TARGET_MACOSX
160CF_PRIVATE CFStringRef _CFBundleCopyBundleDevelopmentRegionFromVersResource(CFBundleRef bundle);
161#endif
162extern CFDictionaryRef _CFBundleCopyInfoDictionaryInExecutable(CFURLRef url);
163extern CFArrayRef _CFBundleCopyArchitecturesForExecutable(CFURLRef url);
164
165extern CFStringRef _CFBundleGetPlatformExecutablesSubdirectoryName(void);
166extern CFStringRef _CFBundleGetAlternatePlatformExecutablesSubdirectoryName(void);
167extern CFStringRef _CFBundleGetOtherPlatformExecutablesSubdirectoryName(void);
168extern CFStringRef _CFBundleGetOtherAlternatePlatformExecutablesSubdirectoryName(void);
169
170extern CFStringRef _CFCreateStringFromVersionNumber(CFAllocatorRef alloc, UInt32 vers);
171extern UInt32 _CFVersionNumberFromString(CFStringRef versStr);
172
173extern void _CFBundleScheduleForUnloading(CFBundleRef bundle);
174extern void _CFBundleUnscheduleForUnloading(CFBundleRef bundle);
175extern void _CFBundleUnloadScheduledBundles(void);
176
177CF_PRIVATE void _CFBundleAppendResourceDir(CFMutableStringRef path, uint8_t version);
178
179CF_PRIVATE UInt8 _CFBundleLayoutVersion(CFBundleRef bundle);
180
181#if defined(BINARY_SUPPORT_DYLD)
182// DYLD API
183extern __CFPBinaryType _CFBundleGrokBinaryType(CFURLRef executableURL);
184extern CFArrayRef _CFBundleDYLDCopyLoadedImagePathsIfChanged(void);
185extern CFArrayRef _CFBundleDYLDCopyLoadedImagePathsForHint(CFStringRef hint);
186#if !defined(BINARY_SUPPORT_DLFCN)
187extern Boolean _CFBundleDYLDCheckLoaded(CFBundleRef bundle);
188extern Boolean _CFBundleDYLDLoadBundle(CFBundleRef bundle, Boolean forceGlobal, CFErrorRef *error);
189extern Boolean _CFBundleDYLDLoadFramework(CFBundleRef bundle, CFErrorRef *error);
190extern void _CFBundleDYLDUnloadBundle(CFBundleRef bundle);
191extern void *_CFBundleDYLDGetSymbolByName(CFBundleRef bundle, CFStringRef symbolName);
192#endif /* !BINARY_SUPPORT_DLFCN */
193#endif /* BINARY_SUPPORT_DYLD */
194
195#if defined(BINARY_SUPPORT_DLFCN)
196// dlfcn API
197extern Boolean _CFBundleDlfcnCheckLoaded(CFBundleRef bundle);
198extern Boolean _CFBundleDlfcnPreflight(CFBundleRef bundle, CFErrorRef *error);
199extern Boolean _CFBundleDlfcnLoadBundle(CFBundleRef bundle, Boolean forceGlobal, CFErrorRef *error);
200extern Boolean _CFBundleDlfcnLoadFramework(CFBundleRef bundle, CFErrorRef *error);
201extern void _CFBundleDlfcnUnload(CFBundleRef bundle);
202extern void *_CFBundleDlfcnGetSymbolByName(CFBundleRef bundle, CFStringRef symbolName);
203#endif /* BINARY_SUPPORT_DLFCN */
204
205#if defined(BINARY_SUPPORT_DLL)
206extern Boolean _CFBundleDLLLoad(CFBundleRef bundle, CFErrorRef *error);
207extern void _CFBundleDLLUnload(CFBundleRef bundle);
208extern void *_CFBundleDLLGetSymbolByName(CFBundleRef bundle, CFStringRef symbolName);
209#endif /* BINARY_SUPPORT_DLL */
210
211
212/* Private PlugIn-related CFBundle API */
213
214extern Boolean _CFBundleNeedsInitPlugIn(CFBundleRef bundle);
215extern void _CFBundleInitPlugIn(CFBundleRef bundle);
216extern void _CFBundlePlugInLoaded(CFBundleRef bundle);
217extern void _CFBundleDeallocatePlugIn(CFBundleRef bundle);
218
219extern void _CFPlugInWillUnload(CFPlugInRef plugIn);
220
221extern void _CFPlugInAddPlugInInstance(CFPlugInRef plugIn);
222extern void _CFPlugInRemovePlugInInstance(CFPlugInRef plugIn);
223
224extern void _CFPlugInAddFactory(CFPlugInRef plugIn, _CFPFactoryRef factory);
225extern void _CFPlugInRemoveFactory(CFPlugInRef plugIn, _CFPFactoryRef factory);
226
227
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")
234
235#if DEPLOYMENT_TARGET_WINDOWS
236#define _CFBundleSupportFilesDirectoryName1WithResources CFSTR("Support Files\\Resources")
237#define _CFBundleSupportFilesDirectoryName2WithResources CFSTR("Contents\\Resources")
238#else
239#define _CFBundleSupportFilesDirectoryName1WithResources CFSTR("Support Files/Resources")
240#define _CFBundleSupportFilesDirectoryName2WithResources CFSTR("Contents/Resources")
241#endif
242
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/")
253
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")
259
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")
270#else
271// No platform-specific variants in these cases
272#define _CFBundlePlatformInfoURLFromBase0 _CFBundleInfoURLFromBase0
273#define _CFBundlePlatformInfoURLFromBase1 _CFBundleInfoURLFromBase1
274#define _CFBundlePlatformInfoURLFromBase2 _CFBundleInfoURLFromBase2
275#define _CFBundlePlatformInfoURLFromBase3 _CFBundleInfoURLFromBase3
276#endif
277
278#define _CFBundleInfoPlistName CFSTR("Info.plist")
279
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")
284#else
285// No platform-specific Info.plist for these
286#define _CFBundlePlatformInfoPlistName _CFBundleInfoPlistName
287#endif
288
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/")
309
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")
317
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")
328
329#define _CFBundleDefaultStringTableName CFSTR("Localizable")
330#define _CFBundleStringTableType CFSTR("strings")
331#define _CFBundleStringDictTableType CFSTR("stringsdict")
332
333#define _CFBundleUserLanguagesPreferenceName CFSTR("AppleLanguages")
334#define _CFBundleOldUserLanguagesPreferenceName CFSTR("NSLanguages")
335
336#define _CFBundleLocalizedResourceForkFileName CFSTR("Localized")
337
338#define _CFBundleWindowsResourceDirectoryExtension CFSTR("resources")
339
340#define _CFBundleMacOSXInfoPlistPlatformName_OLD CFSTR("macos")
341#define _CFBundleWindowsInfoPlistPlatformName_OLD CFSTR("win32")
342
343CF_EXTERN_C_END
344
345#endif /* ! __COREFOUNDATION_CFBUNDLE_INTERNAL__ */
346
347