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
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.
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 ***** */
38 static const char CVS_ID
[] = "@(#) $RCSfile: instance.c,v $ $Revision: 1.4 $ $Date: 2006/03/02 22:48:54 $";
44 nss_dbm_mdInstance_Initialize
46 NSSCKMDInstance
*mdInstance
,
47 NSSCKFWInstance
*fwInstance
,
48 NSSUTF8
*configurationData
53 nss_dbm_instance_t
*instance
;
55 arena
= NSSCKFWInstance_GetArena(fwInstance
, &rv
);
56 if( ((NSSArena
*)NULL
== arena
) && (CKR_OK
!= 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."
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
;
92 /* nss_dbm_mdInstance_Finalize is not required */
95 nss_dbm_mdInstance_GetNSlots
97 NSSCKMDInstance
*mdInstance
,
98 NSSCKFWInstance
*fwInstance
,
102 nss_dbm_instance_t
*instance
= (nss_dbm_instance_t
*)mdInstance
->etc
;
103 return instance
->nSlots
;
107 nss_dbm_mdInstance_GetCryptokiVersion
109 NSSCKMDInstance
*mdInstance
,
110 NSSCKFWInstance
*fwInstance
113 static CK_VERSION rv
= { 2, 1 };
118 nss_dbm_mdInstance_GetManufacturerID
120 NSSCKMDInstance
*mdInstance
,
121 NSSCKFWInstance
*fwInstance
,
125 return "Mozilla Foundation";
129 nss_dbm_mdInstance_GetLibraryDescription
131 NSSCKMDInstance
*mdInstance
,
132 NSSCKFWInstance
*fwInstance
,
136 return "Berkeley Database Module";
140 nss_dbm_mdInstance_GetLibraryVersion
142 NSSCKMDInstance
*mdInstance
,
143 NSSCKFWInstance
*fwInstance
146 static CK_VERSION rv
= { 1, 0 }; /* My own version number */
151 nss_dbm_mdInstance_ModuleHandlesSessionObjects
153 NSSCKMDInstance
*mdInstance
,
154 NSSCKFWInstance
*fwInstance
161 nss_dbm_mdInstance_GetSlots
163 NSSCKMDInstance
*mdInstance
,
164 NSSCKFWInstance
*fwInstance
,
168 nss_dbm_instance_t
*instance
= (nss_dbm_instance_t
*)mdInstance
->etc
;
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
] ) {
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 */