]>
git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_utilities/lib/coderepository.h
2 * Copyright (c) 2004,2011,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@
26 // bundlerepository - directory search paths for bundles
28 #ifndef _H_BUNDLEREPOSITORY
29 #define _H_BUNDLEREPOSITORY
31 #include <security_utilities/cfutilities.h>
32 #include <security_utilities/refcount.h>
33 #include <CoreFoundation/CoreFoundation.h>
42 // PathList abstracts a directory search path.
43 // It's not really powerful enough to be useful on its own.
48 PathList(const string
&subPath
, const char *suffix
= NULL
,
49 const char *envar
= NULL
, bool forUser
= true);
52 void addDirectory(const string
&dirPath
);
55 vector
<string
> mPaths
;
57 IFDEBUG(string mDebugOverride
);
62 // CodeRepository<Code> represents all code objects within the PathList search path,
63 // represented forcibly as objects of type Code.
66 class CodeRepository
: public vector
<RefPointer
<Code
> >, public PathList
{
68 CodeRepository() { } // empty - populate with paths
69 CodeRepository(const string
&subPath
, const char *suffix
= NULL
,
70 const char *envar
= NULL
, bool forUser
= true)
71 : PathList(subPath
, suffix
, envar
, forUser
) { }
78 // The generic implementation of update works with subclasses of GenericBundle,
79 // represented through CFBundleRefs collected via CFBundle.
80 // (Technically, this would work with anything that has a constructor from CFBundleRef.)
81 // If we ever wanted a CodeRepository<ExecutableTool>, we'd specialize update() to deal with
82 // ExecutableTool's slightly different constructor.
85 void CodeRepository
<Code
>::update()
87 vector
<RefPointer
<Code
> > result
;
88 for (vector
<string
>::const_iterator it
= mPaths
.begin(); it
!= mPaths
.end(); it
++) {
89 if (CFRef
<CFArrayRef
> bundles
= CFBundleCreateBundlesFromDirectory(NULL
,
90 CFTempURL(*it
, true), mSuffix
.empty() ? NULL
: CFStringRef(CFTempString(mSuffix
)))) {
91 CFIndex count
= CFArrayGetCount(bundles
);
92 secinfo("coderep", "%p directory %s has %ld entries", this, it
->c_str(), count
);
93 for (CFIndex n
= 0; n
< count
; n
++)
95 result
.push_back(new Code((CFBundleRef
)CFArrayGetValueAtIndex(bundles
, n
)));
97 secinfo("coderep", "%p exception creating %s (skipped)",
98 this, cfString(CFBundleRef(CFArrayGetValueAtIndex(bundles
, n
))).c_str());
101 secinfo("coderep", "directory %s bundle read failed", it
->c_str());
103 secinfo("coderep", "%p total of %ld items in list", this, result
.size());
108 } // end namespace Security
110 #endif //_H_BUNDLEREPOSITORY