2 * Copyright (c) 2000-2001,2011,2014 Apple Inc. All Rights Reserved.
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
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.
22 Contains: Stateless functions used by MDSAttrParser.
24 Copyright (c) 2001,2011,2014 Apple Inc. All Rights Reserved.
27 #ifndef _MDS_ATTR_UTILS_H_
28 #define _MDS_ATTR_UTILS_H_ 1
30 #include <Security/cssmtype.h>
31 #include <security_utilities/debugging.h>
32 #include <CoreFoundation/CoreFoundation.h>
33 #include "MDSAttrStrings.h"
34 #include "MDSSession.h"
36 /* log parsing events */
37 #define MPDebug(args...) secinfo("MDS_Parse", ## args)
39 /* log scanning events */
40 #define MSDebug(args...) secinfo("MDS_Scan", ## args)
43 * I can't believe that CFRelease does not do this...
45 #define CF_RELEASE(c) if(c != NULL) { CFRelease(c); c = NULL; }
51 * Fill in one CSSM_DB_ATTRIBUTE_DATA with specified data, type and attribute name.
52 * CSSM_DB_ATTRIBUTE_DATA.Value and its referent are new[]'d and copied.
54 * -- AttributeNameFormat = CSSM_DB_ATTRIBUTE_NAME_AS_STRING
56 extern void MDSRawValueToDbAttr(
59 CSSM_DB_ATTRIBUTE_FORMAT attrFormat
, // CSSM_DB_ATTRIBUTE_FORMAT_STRING, etc.
61 CSSM_DB_ATTRIBUTE_DATA
&attr
,
62 uint32 numValues
= 1);
65 * Free data new[]'d in the above function.
67 extern void MDSFreeDbRecordAttrs(
68 CSSM_DB_ATTRIBUTE_DATA
*attrs
,
72 /* safely get a new[]'d C string from a CFString */
73 char *MDSCFStringToCString(
76 /* copy a new[]'d C string from a C string */
81 * Given a CFTypeRef which is either a CFString or a CFNumber, do our best to
82 * convert it to a uint32. If it's a CFString, we'll use a MDSNameValuePair
83 * to convert it. CFStrings expressed as decimal numbers are also converted
84 * properly. (MAYBE we'll convert hex strings too...TBD...)
85 * Returns true if conversion was successful.
87 bool MDSCfTypeToUInt32(
89 const MDSNameValuePair
*nameValues
, // optional for converting strings to numbers
90 const char *key
, // for debug logging only
91 uint32
&value
, // RETURNED
92 size_t &valueLen
); // RETURNED
95 * Insert a record, defined by a CSSM_DB_ATTRIBUTE_DATA array, into specified
96 * DL and DB. Returns true on success.
99 const CSSM_DB_ATTRIBUTE_DATA
*inAttr
,
101 CSSM_DB_RECORDTYPE recordType
,
103 CSSM_DB_HANDLE dbHand
);
106 * Convert a number expressed as a CFString to a uint32 using the specified
107 * name/value conversion table. The string may have multiple fields from that
108 * table, ORd together in normal C syntax. Like
110 * CSSM_SERVICE_CSP | CSSM_SERVICE_DL
112 CSSM_RETURN
MDSStringToUint32(
114 const MDSNameValuePair
*table
,
115 uint32
&value
); // RETURNED
118 } // end namespace Security
120 #endif /* _MDS_ATTR_UTILS_H_ */