]> git.saurik.com Git - apple/security.git/blob - cdsa/cdsa_client/multidldb.h
Security-164.1.tar.gz
[apple/security.git] / cdsa / cdsa_client / multidldb.h
1 /*
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
3 *
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
8 * using this file.
9 *
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
16 */
17
18
19 //
20 // multidldb interfaces for searching multiple dls or db with a single cursor.
21 //
22 #ifndef _H_CDSA_CLIENT_MULTIDLDB
23 #define _H_CDSA_CLIENT_MULTIDLDB 1
24
25 #include <Security/dlclient.h>
26 #include <Security/DLDBList.h>
27
28 namespace Security
29 {
30
31 namespace CssmClient
32 {
33
34 //
35 // The MultiDLDb class.
36 //
37 class MultiDLDbImpl : public ObjectImpl, public DbCursorMaker
38 {
39 public:
40 struct List : public vector<DLDbIdentifier>, public RefCount
41 {
42 List(const vector<DLDbIdentifier> &list) : vector<DLDbIdentifier>(list) {}
43 };
44
45 struct ListRef : public RefPointer<List>
46 {
47 ListRef() {}
48 ListRef(const vector<DLDbIdentifier> &list) : RefPointer<List>(new List(list)) {}
49 };
50
51 MultiDLDbImpl(const vector<DLDbIdentifier> &list, bool useSecureStorage, const Cssm &cssm);
52 MultiDLDbImpl(const vector<DLDbIdentifier> &list, bool useSecureStorage);
53 virtual ~MultiDLDbImpl();
54
55 Cssm cssm() const { return parent<Cssm>(); }
56 Db database(const DLDbIdentifier &dlDbIdentifier);
57 ListRef listRef() { return mListRef; }
58 void list(const vector<DLDbIdentifier> &list);
59 const vector<DLDbIdentifier> &list() { return *mListRef; }
60
61 // DbCursorMaker
62 virtual DbCursorImpl *newDbCursor(const CSSM_QUERY &query, CssmAllocator &allocator);
63 virtual DbCursorImpl *newDbCursor(uint32 capacity, CssmAllocator &allocator);
64
65 protected:
66 void activate();
67 void deactivate();
68
69 private:
70 typedef map<DLDbIdentifier, Db> DbMap;
71
72 // Lock protecting this object during changes.
73 Mutex mLock;
74 ListRef mListRef;
75 DbMap mDbMap;
76 bool mUseSecureStorage;
77 };
78
79 class MultiDLDb : public Object
80 {
81 public:
82 typedef MultiDLDbImpl Impl;
83
84 explicit MultiDLDb(Impl *impl) : Object(impl) {}
85 MultiDLDb(const vector<DLDbIdentifier> &list, bool useSecureStorage, const Cssm &cssm)
86 : Object(new Impl(list, useSecureStorage, cssm)) {}
87 MultiDLDb(const vector<DLDbIdentifier> &list, bool useSecureStorage)
88 : Object(new Impl(list, useSecureStorage)) {}
89
90 Impl *operator ->() const { return &impl<Impl>(); }
91 Impl &operator *() const { return impl<Impl>(); }
92
93 // Conversion to DbCursorMaker
94 operator DbCursorMaker &() { return impl<Impl>(); }
95 };
96
97 }; // end namespace CssmClient
98
99 } // end namespace Security
100
101 #endif // _H_CDSA_CLIENT_MULTIDLDB