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