]> git.saurik.com Git - apple/security.git/blob - cdsa/mds/MDSDictionary.h
Security-164.1.tar.gz
[apple/security.git] / cdsa / mds / MDSDictionary.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 File: MDSDictionary.h
21
22 Contains: Internal representation of one MDS info file.
23
24 Copyright: (c) 2001 Apple Computer, Inc., all rights reserved.
25 */
26
27 #ifndef _MDS_DICTIONARY_H_
28 #define _MDS_DICTIONARY_H_ 1
29
30 #include <Security/cssmtype.h>
31 #include <Security/MDSSession.h>
32 #include <Security/MDSAttrStrings.h>
33 #include <CoreFoundation/CoreFoundation.h>
34
35 namespace Security
36 {
37
38 class MDSDictionary
39 {
40 public:
41 /* heavyweight constructor from file */
42 MDSDictionary(
43 CFURLRef fileUrl,
44 const char *fullPath);
45
46 /* lightweight constructor from existing CFDictionary */
47 MDSDictionary(
48 CFDictionaryRef theDict);
49
50 ~MDSDictionary();
51
52 /*
53 * Lookup by either C string or CFStringRef. Optionally checks for
54 * CFTypeID of resulting value. Both return NULL on error (either key not
55 * found or wrong CFTypeID).
56 */
57 const void *lookup(
58 const char *key,
59 bool checkType = false, // since we really don't know if 0 is a valid type
60 CFTypeID type = 0);
61 const void *lookup(
62 CFStringRef key,
63 bool checkType = false,
64 CFTypeID type = 0);
65
66 /*
67 * Common means to perform a lookup in a dictionary given a C-string key and
68 * placing the value - if present - in a CSSM_DB_ATTRIBUTE_DATA. Any errors
69 * are only logged via MPDebug. Returns true if the value was found and
70 * successfully placed in supplied CSSM_DB_ATTRIBUTE_DATA.
71 *
72 * For now we assume that the key in the dictionary is the same as the key
73 * in the DB to which we're writing.
74 *
75 * A MDSNameValuePair array may be specified to facilitate conversion of
76 * values which appears in the dictionary as strings but which are stored
77 * in the DB as integers.
78 *
79 * We're also assuming that all DB keys are of format
80 * CSSM_DB_ATTRIBUTE_NAME_AS_STRING.
81 */
82 bool lookupToDbAttr(
83 const char *key,
84 CSSM_DB_ATTRIBUTE_DATA &attr,
85 CSSM_DB_ATTRIBUTE_FORMAT attrFormat,
86 const MDSNameValuePair *nameValues = NULL);
87
88 /*
89 * Given a RelationInfo and an array of CSSM_DB_ATTRIBUTE_DATAs, fill in
90 * the CSSM_DB_ATTRIBUTE_DATA array with as many fields as we can find in
91 * the dictionary. All fields are treated as optional.
92 */
93 void lookupAttributes(
94 const RelationInfo *relInfo,
95 CSSM_DB_ATTRIBUTE_DATA_PTR outAttrs, // filled in on return
96 uint32 &numAttrs); // RETURNED
97
98 CFDictionaryRef dict() { return mDict; }
99 const char *urlPath() { return mUrlPath; }
100 const char *fileDesc() { return mFileDesc; }
101
102 /*
103 * Lookup with file-based indirection. Allows multiple mdsinfo file to share
104 * commmon info from a separate plist file.
105 */
106 const CFPropertyListRef lookupWithIndirect(
107 const char *key,
108 CFBundleRef bundle,
109 CFTypeID desiredType,
110 bool &fetchedFromDisk); // true --> caller must CFRelease the returned
111 // value
112 // false -> it's part of this dictionary
113 private:
114 CFDictionaryRef mDict;
115 bool mWeOwnDict;
116 char *mUrlPath;
117 char *mFileDesc;
118 };
119
120 } // end namespace Security
121
122 #endif /* _MDS_DICTIONARY_H_ */