]> git.saurik.com Git - apple/security.git/blob - cdsa/mds/mdsapi.cpp
Security-54.1.tar.gz
[apple/security.git] / cdsa / mds / mdsapi.cpp
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
21 File: mds.h
22
23 Contains: Module Directory Services Data Types and API.
24
25 Copyright: (c) 1999 Apple Computer, Inc., all rights reserved.
26
27 This is the C API wrapper for the C++ MDS implementation. Most of this file
28 could also be generated by the same perl script that generates the plugin
29 C wrapper code.
30
31 */
32
33 #include "MDSSession.h"
34
35 #include <memory>
36
37 using namespace std;
38
39 static CSSM_RETURN CSSMAPI cssm_DataGetFirst(CSSM_DL_DB_HANDLE DLDBHandle,
40 const CSSM_QUERY *Query,
41 CSSM_HANDLE_PTR ResultsHandle,
42 CSSM_DB_RECORD_ATTRIBUTE_DATA_PTR Attributes,
43 CSSM_DATA_PTR Data,
44 CSSM_DB_UNIQUE_RECORD_PTR *UniqueId)
45 {
46 BEGIN_API
47 if (!(Required(ResultsHandle) = findHandle<MDSSession>(DLDBHandle.DLHandle).DataGetFirst(DLDBHandle.DBHandle,
48 DLQuery::optional(Query),
49 Attributes,
50 CssmData::optional(Data),
51 Required(UniqueId))))
52 return CSSMERR_DL_ENDOFDATA;
53 END_API(MDS)
54 }
55
56 static CSSM_RETURN CSSMAPI cssm_DataModify(CSSM_DL_DB_HANDLE DLDBHandle,
57 CSSM_DB_RECORDTYPE RecordType,
58 CSSM_DB_UNIQUE_RECORD_PTR UniqueRecordIdentifier,
59 const CSSM_DB_RECORD_ATTRIBUTE_DATA *AttributesToBeModified,
60 const CSSM_DATA *DataToBeModified,
61 CSSM_DB_MODIFY_MODE ModifyMode)
62 {
63 BEGIN_API
64 findHandle<MDSSession>(DLDBHandle.DLHandle).DataModify(DLDBHandle.DBHandle,
65 RecordType,
66 Required(UniqueRecordIdentifier),
67 AttributesToBeModified,
68 CssmData::optional(DataToBeModified),
69 ModifyMode);
70 END_API(MDS)
71 }
72
73 static CSSM_RETURN CSSMAPI cssm_GetDbNameFromHandle(CSSM_DL_DB_HANDLE DLDBHandle,
74 char **DbName)
75 {
76 BEGIN_API
77 findHandle<MDSSession>(DLDBHandle.DLHandle).GetDbNameFromHandle(DLDBHandle.DBHandle,
78 DbName);
79 END_API(MDS)
80 }
81
82 static CSSM_RETURN CSSMAPI cssm_DataAbortQuery(CSSM_DL_DB_HANDLE DLDBHandle,
83 CSSM_HANDLE ResultsHandle)
84 {
85 BEGIN_API
86 findHandle<MDSSession>(DLDBHandle.DLHandle).DataAbortQuery(DLDBHandle.DBHandle,
87 ResultsHandle);
88 END_API(MDS)
89 }
90
91 static CSSM_RETURN CSSMAPI cssm_DestroyRelation(CSSM_DL_DB_HANDLE DLDBHandle,
92 CSSM_DB_RECORDTYPE RelationID)
93 {
94 BEGIN_API
95 findHandle<MDSSession>(DLDBHandle.DLHandle).DestroyRelation(DLDBHandle.DBHandle,
96 RelationID);
97 END_API(MDS)
98 }
99
100 static CSSM_RETURN CSSMAPI cssm_DataDelete(CSSM_DL_DB_HANDLE DLDBHandle,
101 const CSSM_DB_UNIQUE_RECORD *UniqueRecordIdentifier)
102 {
103 BEGIN_API
104 findHandle<MDSSession>(DLDBHandle.DLHandle).DataDelete(DLDBHandle.DBHandle,
105 Required(UniqueRecordIdentifier));
106 END_API(MDS)
107 }
108
109 static CSSM_RETURN CSSMAPI cssm_DataInsert(CSSM_DL_DB_HANDLE DLDBHandle,
110 CSSM_DB_RECORDTYPE RecordType,
111 const CSSM_DB_RECORD_ATTRIBUTE_DATA *Attributes,
112 const CSSM_DATA *Data,
113 CSSM_DB_UNIQUE_RECORD_PTR *UniqueId)
114 {
115 BEGIN_API
116 findHandle<MDSSession>(DLDBHandle.DLHandle).DataInsert(DLDBHandle.DBHandle,
117 RecordType,
118 Attributes,
119 CssmData::optional(Data),
120 Required(UniqueId));
121 END_API(MDS)
122 }
123
124 static CSSM_RETURN CSSMAPI cssm_DataGetFromUniqueRecordId(CSSM_DL_DB_HANDLE DLDBHandle,
125 const CSSM_DB_UNIQUE_RECORD *UniqueRecord,
126 CSSM_DB_RECORD_ATTRIBUTE_DATA_PTR Attributes,
127 CSSM_DATA_PTR Data)
128 {
129 BEGIN_API
130 findHandle<MDSSession>(DLDBHandle.DLHandle).DataGetFromUniqueRecordId(DLDBHandle.DBHandle,
131 Required(UniqueRecord),
132 Attributes,
133 CssmData::optional(Data));
134 END_API(MDS)
135 }
136
137 static CSSM_RETURN CSSMAPI cssm_CreateRelation(CSSM_DL_DB_HANDLE DLDBHandle,
138 CSSM_DB_RECORDTYPE RelationID,
139 const char *RelationName,
140 uint32 NumberOfAttributes,
141 const CSSM_DB_SCHEMA_ATTRIBUTE_INFO *pAttributeInfo,
142 uint32 NumberOfIndexes,
143 const CSSM_DB_SCHEMA_INDEX_INFO *pIndexInfo)
144 {
145 BEGIN_API
146 findHandle<MDSSession>(DLDBHandle.DLHandle).CreateRelation(DLDBHandle.DBHandle,
147 RelationID,
148 RelationName,
149 NumberOfAttributes,
150 Required(pAttributeInfo),
151 NumberOfIndexes,
152 Required(pIndexInfo));
153 END_API(MDS)
154 }
155
156 static CSSM_RETURN CSSMAPI cssm_FreeUniqueRecord(CSSM_DL_DB_HANDLE DLDBHandle,
157 CSSM_DB_UNIQUE_RECORD_PTR UniqueRecord)
158 {
159 BEGIN_API
160 findHandle<MDSSession>(DLDBHandle.DLHandle).FreeUniqueRecord(DLDBHandle.DBHandle,
161 Required(UniqueRecord));
162 END_API(MDS)
163 }
164
165 static CSSM_RETURN CSSMAPI cssm_DbOpen(CSSM_DL_HANDLE DLHandle,
166 const char *DbName,
167 const CSSM_NET_ADDRESS *DbLocation,
168 CSSM_DB_ACCESS_TYPE AccessRequest,
169 const CSSM_ACCESS_CREDENTIALS *AccessCred,
170 const void *OpenParameters,
171 CSSM_DB_HANDLE *DbHandle)
172 {
173 BEGIN_API
174 findHandle<MDSSession>(DLHandle).DbOpen(DbName,
175 DbLocation,
176 AccessRequest,
177 AccessCredentials::optional(AccessCred),
178 OpenParameters,
179 Required(DbHandle));
180 END_API(MDS)
181 }
182
183 static CSSM_RETURN CSSMAPI cssm_DataGetNext(CSSM_DL_DB_HANDLE DLDBHandle,
184 CSSM_HANDLE ResultsHandle,
185 CSSM_DB_RECORD_ATTRIBUTE_DATA_PTR Attributes,
186 CSSM_DATA_PTR Data,
187 CSSM_DB_UNIQUE_RECORD_PTR *UniqueId)
188 {
189 BEGIN_API
190 if (!findHandle<MDSSession>(DLDBHandle.DLHandle).DataGetNext(DLDBHandle.DBHandle,
191 ResultsHandle,
192 Attributes,
193 CssmData::optional(Data),
194 Required(UniqueId)))
195 return CSSMERR_DL_ENDOFDATA;
196 END_API(MDS)
197 }
198
199 static CSSM_RETURN CSSMAPI cssm_GetDbNames(CSSM_DL_HANDLE DLHandle,
200 CSSM_NAME_LIST_PTR *NameList)
201 {
202 BEGIN_API
203 findHandle<MDSSession>(DLHandle).GetDbNames(Required(NameList));
204 END_API(MDS)
205 }
206
207 static CSSM_RETURN CSSMAPI cssm_DbClose(CSSM_DL_DB_HANDLE DLDBHandle)
208 {
209 BEGIN_API
210 findHandle<MDSSession>(DLDBHandle.DLHandle).DbClose(DLDBHandle.DBHandle);
211 END_API(MDS)
212 }
213
214 static CSSM_RETURN CSSMAPI cssm_FreeNameList(CSSM_DL_HANDLE DLHandle,
215 CSSM_NAME_LIST_PTR NameList)
216 {
217 BEGIN_API
218 findHandle<MDSSession>(DLHandle).FreeNameList(Required(NameList));
219 END_API(MDS)
220 }
221
222 static MDS_FUNCS gMDSFunctionTable =
223 {
224 cssm_DbOpen,
225 cssm_DbClose,
226 cssm_GetDbNames,
227 cssm_GetDbNameFromHandle,
228 cssm_FreeNameList,
229 cssm_DataInsert,
230 cssm_DataDelete,
231 cssm_DataModify,
232 cssm_DataGetFirst,
233 cssm_DataGetNext,
234 cssm_DataAbortQuery,
235 cssm_DataGetFromUniqueRecordId,
236 cssm_FreeUniqueRecord,
237 cssm_CreateRelation,
238 cssm_DestroyRelation,
239 };
240
241
242 #ifdef __MWERKS__
243 #pragma export on
244 #endif
245
246 CSSM_RETURN CSSMAPI
247 MDS_Initialize (const CSSM_GUID *inCallerGuid,
248 const CSSM_MEMORY_FUNCS *inMemoryFunctions,
249 MDS_FUNCS_PTR outDlFunctions,
250 MDS_HANDLE *outMDSHandle)
251 {
252 BEGIN_API
253 Required (outDlFunctions);
254 Required (outMDSHandle) = (new MDSSession (Guid::optional(inCallerGuid),
255 Required(inMemoryFunctions)))->handle ();
256 *outDlFunctions = gMDSFunctionTable;
257 END_API(MDS)
258 }
259
260 CSSM_RETURN CSSMAPI
261 MDS_Terminate (MDS_HANDLE inMDSHandle)
262 {
263 BEGIN_API
264 auto_ptr<MDSSession> aMDSSession (&killHandle<MDSSession> (inMDSHandle));
265 aMDSSession->terminate (); // Even if terminate throws the MDSSession object will be deleted.
266 END_API(MDS)
267 }
268
269 CSSM_RETURN CSSMAPI
270 MDS_Install (MDS_HANDLE inMDSHandle)
271 {
272 BEGIN_API
273 findHandle<MDSSession> (inMDSHandle).install ();
274 END_API(MDS)
275 }
276
277 CSSM_RETURN CSSMAPI
278 MDS_Uninstall (MDS_HANDLE inMDSHandle)
279 {
280 BEGIN_API
281 findHandle<MDSSession> (inMDSHandle).uninstall ();
282 END_API(MDS)
283 }
284
285 #ifdef __MWERKS__
286 #pragma export off
287 #endif