2 * Copyright (c) 2000-2001 Apple Computer, 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.
23 Contains: Module Directory Services Data Types and API.
25 Copyright: (c) 1999 Apple Computer, Inc., all rights reserved.
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
33 #include "MDSSession.h"
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
,
44 CSSM_DB_UNIQUE_RECORD_PTR
*UniqueId
)
47 if (!(Required(ResultsHandle
) = findHandle
<MDSSession
>(DLDBHandle
.DLHandle
).DataGetFirst(DLDBHandle
.DBHandle
,
48 DLQuery::optional(Query
),
50 CssmData::optional(Data
),
52 return CSSMERR_DL_ENDOFDATA
;
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
)
64 findHandle
<MDSSession
>(DLDBHandle
.DLHandle
).DataModify(DLDBHandle
.DBHandle
,
66 Required(UniqueRecordIdentifier
),
67 AttributesToBeModified
,
68 CssmData::optional(DataToBeModified
),
73 static CSSM_RETURN CSSMAPI
cssm_GetDbNameFromHandle(CSSM_DL_DB_HANDLE DLDBHandle
,
77 findHandle
<MDSSession
>(DLDBHandle
.DLHandle
).GetDbNameFromHandle(DLDBHandle
.DBHandle
,
82 static CSSM_RETURN CSSMAPI
cssm_DataAbortQuery(CSSM_DL_DB_HANDLE DLDBHandle
,
83 CSSM_HANDLE ResultsHandle
)
86 findHandle
<MDSSession
>(DLDBHandle
.DLHandle
).DataAbortQuery(DLDBHandle
.DBHandle
,
91 static CSSM_RETURN CSSMAPI
cssm_DestroyRelation(CSSM_DL_DB_HANDLE DLDBHandle
,
92 CSSM_DB_RECORDTYPE RelationID
)
95 findHandle
<MDSSession
>(DLDBHandle
.DLHandle
).DestroyRelation(DLDBHandle
.DBHandle
,
100 static CSSM_RETURN CSSMAPI
cssm_DataDelete(CSSM_DL_DB_HANDLE DLDBHandle
,
101 const CSSM_DB_UNIQUE_RECORD
*UniqueRecordIdentifier
)
104 findHandle
<MDSSession
>(DLDBHandle
.DLHandle
).DataDelete(DLDBHandle
.DBHandle
,
105 Required(UniqueRecordIdentifier
));
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
)
116 findHandle
<MDSSession
>(DLDBHandle
.DLHandle
).DataInsert(DLDBHandle
.DBHandle
,
119 CssmData::optional(Data
),
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
,
130 findHandle
<MDSSession
>(DLDBHandle
.DLHandle
).DataGetFromUniqueRecordId(DLDBHandle
.DBHandle
,
131 Required(UniqueRecord
),
133 CssmData::optional(Data
));
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
)
146 findHandle
<MDSSession
>(DLDBHandle
.DLHandle
).CreateRelation(DLDBHandle
.DBHandle
,
150 Required(pAttributeInfo
),
152 Required(pIndexInfo
));
156 static CSSM_RETURN CSSMAPI
cssm_FreeUniqueRecord(CSSM_DL_DB_HANDLE DLDBHandle
,
157 CSSM_DB_UNIQUE_RECORD_PTR UniqueRecord
)
160 findHandle
<MDSSession
>(DLDBHandle
.DLHandle
).FreeUniqueRecord(DLDBHandle
.DBHandle
,
161 Required(UniqueRecord
));
165 static CSSM_RETURN CSSMAPI
cssm_DbOpen(CSSM_DL_HANDLE DLHandle
,
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
)
174 findHandle
<MDSSession
>(DLHandle
).DbOpen(DbName
,
177 AccessCredentials::optional(AccessCred
),
183 static CSSM_RETURN CSSMAPI
cssm_DataGetNext(CSSM_DL_DB_HANDLE DLDBHandle
,
184 CSSM_HANDLE ResultsHandle
,
185 CSSM_DB_RECORD_ATTRIBUTE_DATA_PTR Attributes
,
187 CSSM_DB_UNIQUE_RECORD_PTR
*UniqueId
)
190 if (!findHandle
<MDSSession
>(DLDBHandle
.DLHandle
).DataGetNext(DLDBHandle
.DBHandle
,
193 CssmData::optional(Data
),
195 return CSSMERR_DL_ENDOFDATA
;
199 static CSSM_RETURN CSSMAPI
cssm_GetDbNames(CSSM_DL_HANDLE DLHandle
,
200 CSSM_NAME_LIST_PTR
*NameList
)
203 findHandle
<MDSSession
>(DLHandle
).GetDbNames(Required(NameList
));
207 static CSSM_RETURN CSSMAPI
cssm_DbClose(CSSM_DL_DB_HANDLE DLDBHandle
)
210 findHandle
<MDSSession
>(DLDBHandle
.DLHandle
).DbClose(DLDBHandle
.DBHandle
);
214 static CSSM_RETURN CSSMAPI
cssm_FreeNameList(CSSM_DL_HANDLE DLHandle
,
215 CSSM_NAME_LIST_PTR NameList
)
218 findHandle
<MDSSession
>(DLHandle
).FreeNameList(Required(NameList
));
222 static MDS_FUNCS gMDSFunctionTable
=
227 cssm_GetDbNameFromHandle
,
235 cssm_DataGetFromUniqueRecordId
,
236 cssm_FreeUniqueRecord
,
238 cssm_DestroyRelation
,
247 MDS_Initialize (const CSSM_GUID
*inCallerGuid
,
248 const CSSM_MEMORY_FUNCS
*inMemoryFunctions
,
249 MDS_FUNCS_PTR outDlFunctions
,
250 MDS_HANDLE
*outMDSHandle
)
253 Required (outDlFunctions
);
254 Required (outMDSHandle
) = (new MDSSession (Guid::optional(inCallerGuid
),
255 Required(inMemoryFunctions
)))->handle ();
256 *outDlFunctions
= gMDSFunctionTable
;
261 MDS_Terminate (MDS_HANDLE inMDSHandle
)
264 auto_ptr
<MDSSession
> aMDSSession (&killHandle
<MDSSession
> (inMDSHandle
));
265 aMDSSession
->terminate (); // Even if terminate throws the MDSSession object will be deleted.
270 MDS_Install (MDS_HANDLE inMDSHandle
)
273 findHandle
<MDSSession
> (inMDSHandle
).install ();
278 MDS_Uninstall (MDS_HANDLE inMDSHandle
)
281 findHandle
<MDSSession
> (inMDSHandle
).uninstall ();