Import from 1.9a8 tarball
[mozilla-nss.git] / security / nss / lib / ckfw / dbm / instance.c
blobb121f5bfe914162fe8f5230bf0b863de3b2754a3
1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
12 * License.
14 * The Original Code is the Netscape security libraries.
16 * The Initial Developer of the Original Code is
17 * Netscape Communications Corporation.
18 * Portions created by the Initial Developer are Copyright (C) 1994-2000
19 * the Initial Developer. All Rights Reserved.
21 * Contributor(s):
23 * Alternatively, the contents of this file may be used under the terms of
24 * either the GNU General Public License Version 2 or later (the "GPL"), or
25 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26 * in which case the provisions of the GPL or the LGPL are applicable instead
27 * of those above. If you wish to allow use of your version of this file only
28 * under the terms of either the GPL or the LGPL, and not to allow others to
29 * use your version of this file under the terms of the MPL, indicate your
30 * decision by deleting the provisions above and replace them with the notice
31 * and other provisions required by the GPL or the LGPL. If you do not delete
32 * the provisions above, a recipient may use your version of this file under
33 * the terms of any one of the MPL, the GPL or the LGPL.
35 * ***** END LICENSE BLOCK ***** */
37 #ifdef DEBUG
38 static const char CVS_ID[] = "@(#) $RCSfile: instance.c,v $ $Revision: 1.4 $ $Date: 2006/03/02 22:48:54 $";
39 #endif /* DEBUG */
41 #include "ckdbm.h"
43 static CK_RV
44 nss_dbm_mdInstance_Initialize
46 NSSCKMDInstance *mdInstance,
47 NSSCKFWInstance *fwInstance,
48 NSSUTF8 *configurationData
51 CK_RV rv = CKR_OK;
52 NSSArena *arena;
53 nss_dbm_instance_t *instance;
55 arena = NSSCKFWInstance_GetArena(fwInstance, &rv);
56 if( ((NSSArena *)NULL == arena) && (CKR_OK != rv) ) {
57 return rv;
60 instance = nss_ZNEW(arena, nss_dbm_instance_t);
61 if( (nss_dbm_instance_t *)NULL == instance ) {
62 return CKR_HOST_MEMORY;
65 instance->arena = arena;
68 * This should parse the configuration data for information on
69 * number and locations of databases, modes (e.g. readonly), etc.
70 * But for now, we'll have one slot with a creatable read-write
71 * database called "cert8.db."
74 instance->nSlots = 1;
75 instance->filenames = nss_ZNEWARRAY(arena, char *, instance->nSlots);
76 if( (char **)NULL == instance->filenames ) {
77 return CKR_HOST_MEMORY;
80 instance->flags = nss_ZNEWARRAY(arena, int, instance->nSlots);
81 if( (int *)NULL == instance->flags ) {
82 return CKR_HOST_MEMORY;
85 instance->filenames[0] = "cert8.db";
86 instance->flags[0] = O_RDWR|O_CREAT;
88 mdInstance->etc = (void *)instance;
89 return CKR_OK;
92 /* nss_dbm_mdInstance_Finalize is not required */
94 static CK_ULONG
95 nss_dbm_mdInstance_GetNSlots
97 NSSCKMDInstance *mdInstance,
98 NSSCKFWInstance *fwInstance,
99 CK_RV *pError
102 nss_dbm_instance_t *instance = (nss_dbm_instance_t *)mdInstance->etc;
103 return instance->nSlots;
106 static CK_VERSION
107 nss_dbm_mdInstance_GetCryptokiVersion
109 NSSCKMDInstance *mdInstance,
110 NSSCKFWInstance *fwInstance
113 static CK_VERSION rv = { 2, 1 };
114 return rv;
117 static NSSUTF8 *
118 nss_dbm_mdInstance_GetManufacturerID
120 NSSCKMDInstance *mdInstance,
121 NSSCKFWInstance *fwInstance,
122 CK_RV *pError
125 return "Mozilla Foundation";
128 static NSSUTF8 *
129 nss_dbm_mdInstance_GetLibraryDescription
131 NSSCKMDInstance *mdInstance,
132 NSSCKFWInstance *fwInstance,
133 CK_RV *pError
136 return "Berkeley Database Module";
139 static CK_VERSION
140 nss_dbm_mdInstance_GetLibraryVersion
142 NSSCKMDInstance *mdInstance,
143 NSSCKFWInstance *fwInstance
146 static CK_VERSION rv = { 1, 0 }; /* My own version number */
147 return rv;
150 static CK_BBOOL
151 nss_dbm_mdInstance_ModuleHandlesSessionObjects
153 NSSCKMDInstance *mdInstance,
154 NSSCKFWInstance *fwInstance
157 return CK_TRUE;
160 static CK_RV
161 nss_dbm_mdInstance_GetSlots
163 NSSCKMDInstance *mdInstance,
164 NSSCKFWInstance *fwInstance,
165 NSSCKMDSlot *slots[]
168 nss_dbm_instance_t *instance = (nss_dbm_instance_t *)mdInstance->etc;
169 CK_ULONG i;
170 CK_RV rv = CKR_OK;
172 for( i = 0; i < instance->nSlots; i++ ) {
173 slots[i] = nss_dbm_mdSlot_factory(instance, instance->filenames[i],
174 instance->flags[i], &rv);
175 if( (NSSCKMDSlot *)NULL == slots[i] ) {
176 return rv;
180 return rv;
183 /* nss_dbm_mdInstance_WaitForSlotEvent is not relevant */
185 NSS_IMPLEMENT_DATA NSSCKMDInstance
186 nss_dbm_mdInstance = {
187 NULL, /* etc; filled in later */
188 nss_dbm_mdInstance_Initialize,
189 NULL, /* nss_dbm_mdInstance_Finalize */
190 nss_dbm_mdInstance_GetNSlots,
191 nss_dbm_mdInstance_GetCryptokiVersion,
192 nss_dbm_mdInstance_GetManufacturerID,
193 nss_dbm_mdInstance_GetLibraryDescription,
194 nss_dbm_mdInstance_GetLibraryVersion,
195 nss_dbm_mdInstance_ModuleHandlesSessionObjects,
196 nss_dbm_mdInstance_GetSlots,
197 NULL, /* nss_dbm_mdInstance_WaitForSlotEvent */
198 NULL /* terminator */