]> git.saurik.com Git - apple/security.git/blob - cdsa/mds/MDSAttrUtils.h
Security-54.1.tar.gz
[apple/security.git] / cdsa / mds / MDSAttrUtils.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: MDSAttrUtils.h
21
22 Contains: Stateless functions used by MDSAttrParser.
23
24 Copyright: (c) 2001 Apple Computer, Inc., all rights reserved.
25 */
26
27 #ifndef _MDS_ATTR_UTILS_H_
28 #define _MDS_ATTR_UTILS_H_ 1
29
30 #include <Security/cssmtype.h>
31 #include <Security/debugging.h>
32 #include <CoreFoundation/CoreFoundation.h>
33 #include "MDSAttrStrings.h"
34 #include "MDSSession.h"
35
36 /* log parsing events */
37 #define MPDebug(args...) debug("MDS_Parse", ## args)
38
39 /* log scanning events */
40 #define MSDebug(args...) debug("MDS_Scan", ## args)
41
42 /*
43 * I can't believe that CFRelease does not do this...
44 */
45 #define CF_RELEASE(c) if(c != NULL) { CFRelease(c); c = NULL; }
46
47 namespace Security
48 {
49
50 /*
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.
53 * Assumes:
54 * -- AttributeNameFormat = CSSM_DB_ATTRIBUTE_NAME_AS_STRING
55 */
56 extern void MDSRawValueToDbAttr(
57 const void *value,
58 size_t len,
59 CSSM_DB_ATTRIBUTE_FORMAT attrFormat, // CSSM_DB_ATTRIBUTE_FORMAT_STRING, etc.
60 const char *attrName,
61 CSSM_DB_ATTRIBUTE_DATA &attr,
62 uint32 numValues = 1);
63
64 /*
65 * Free data new[]'d in the above function.
66 */
67 extern void MDSFreeDbRecordAttrs(
68 CSSM_DB_ATTRIBUTE_DATA *attrs,
69 unsigned numAttrs);
70
71
72 /* safely get a new[]'d C string from a CFString */
73 char *MDSCFStringToCString(
74 CFStringRef cfStr);
75
76 /* copy a new[]'d C string from a C string */
77 char *MDSCopyCstring(
78 const char *inStr);
79
80 /*
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.
86 */
87 bool MDSCfTypeToInt(
88 CFTypeRef cfValue,
89 const MDSNameValuePair *nameValues, // optional for converting strings to numbers
90 const char *key, // for debug logging only
91 uint32 &value); // RETURNED
92
93 /*
94 * Insert a record, defined by a CSSM_DB_ATTRIBUTE_DATA array, into specified
95 * DL and DB. Returns true on success.
96 */
97 bool MDSInsertRecord(
98 const CSSM_DB_ATTRIBUTE_DATA *inAttr,
99 unsigned numAttrs,
100 CSSM_DB_RECORDTYPE recordType,
101 MDSSession &dl,
102 CSSM_DB_HANDLE dbHand);
103
104 /*
105 * Convert a number expressed as a CFString to a uint32 using the specified
106 * name/value conversion table. The string may have multiple fields from that
107 * table, ORd together in normal C syntax. Like
108 *
109 * CSSM_SERVICE_CSP | CSSM_SERVICE_DL
110 */
111 CSSM_RETURN MDSStringToUint32(
112 CFStringRef str,
113 const MDSNameValuePair *table,
114 uint32 &value); // RETURNED
115
116
117 } // end namespace Security
118
119 #endif /* _MDS_ATTR_UTILS_H_ */