Back to index

lightning-sunbird  0.9+nobinonly
instance.c
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is the Netscape security libraries.
00015  *
00016  * The Initial Developer of the Original Code is
00017  * Netscape Communications Corporation.
00018  * Portions created by the Initial Developer are Copyright (C) 1994-2000
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *
00023  * Alternatively, the contents of this file may be used under the terms of
00024  * either the GNU General Public License Version 2 or later (the "GPL"), or
00025  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00026  * in which case the provisions of the GPL or the LGPL are applicable instead
00027  * of those above. If you wish to allow use of your version of this file only
00028  * under the terms of either the GPL or the LGPL, and not to allow others to
00029  * use your version of this file under the terms of the MPL, indicate your
00030  * decision by deleting the provisions above and replace them with the notice
00031  * and other provisions required by the GPL or the LGPL. If you do not delete
00032  * the provisions above, a recipient may use your version of this file under
00033  * the terms of any one of the MPL, the GPL or the LGPL.
00034  *
00035  * ***** END LICENSE BLOCK ***** */
00036 
00037 #ifdef DEBUG
00038 static const char CVS_ID[] = "@(#) $RCSfile: instance.c,v $ $Revision: 1.2.28.2 $ $Date: 2006/04/23 04:53:45 $";
00039 #endif /* DEBUG */
00040 
00041 #include "ckdbm.h"
00042 
00043 static CK_RV
00044 nss_dbm_mdInstance_Initialize
00045 (
00046   NSSCKMDInstance *mdInstance,                                    
00047   NSSCKFWInstance *fwInstance,
00048   NSSUTF8 *configurationData
00049 )
00050 {
00051   CK_RV rv = CKR_OK;
00052   NSSArena *arena;
00053   nss_dbm_instance_t *instance;
00054 
00055   arena = NSSCKFWInstance_GetArena(fwInstance, &rv);
00056   if( ((NSSArena *)NULL == arena) && (CKR_OK != rv) ) {
00057     return rv;
00058   }
00059 
00060   instance = nss_ZNEW(arena, nss_dbm_instance_t);
00061   if( (nss_dbm_instance_t *)NULL == instance ) {
00062     return CKR_HOST_MEMORY;
00063   }
00064 
00065   instance->arena = arena;
00066 
00067   /*
00068    * This should parse the configuration data for information on
00069    * number and locations of databases, modes (e.g. readonly), etc.
00070    * But for now, we'll have one slot with a creatable read-write
00071    * database called "cert8.db."
00072    */
00073 
00074   instance->nSlots = 1;
00075   instance->filenames = nss_ZNEWARRAY(arena, char *, instance->nSlots);
00076   if( (char **)NULL == instance->filenames ) {
00077     return CKR_HOST_MEMORY;
00078   }
00079 
00080   instance->flags = nss_ZNEWARRAY(arena, int, instance->nSlots);
00081   if( (int *)NULL == instance->flags ) {
00082     return CKR_HOST_MEMORY;
00083   }
00084 
00085   instance->filenames[0] = "cert8.db";
00086   instance->flags[0] = O_RDWR|O_CREAT;
00087 
00088   mdInstance->etc = (void *)instance;
00089   return CKR_OK;
00090 }
00091 
00092 /* nss_dbm_mdInstance_Finalize is not required */
00093 
00094 static CK_ULONG
00095 nss_dbm_mdInstance_GetNSlots
00096 (
00097   NSSCKMDInstance *mdInstance,                                    
00098   NSSCKFWInstance *fwInstance,
00099   CK_RV *pError
00100 )
00101 {
00102   nss_dbm_instance_t *instance = (nss_dbm_instance_t *)mdInstance->etc;
00103   return instance->nSlots;
00104 }
00105 
00106 static CK_VERSION
00107 nss_dbm_mdInstance_GetCryptokiVersion
00108 (
00109   NSSCKMDInstance *mdInstance,                                    
00110   NSSCKFWInstance *fwInstance
00111 )
00112 {
00113   static CK_VERSION rv = { 2, 1 };
00114   return rv;
00115 }
00116 
00117 static NSSUTF8 *
00118 nss_dbm_mdInstance_GetManufacturerID
00119 (
00120   NSSCKMDInstance *mdInstance,                                    
00121   NSSCKFWInstance *fwInstance,
00122   CK_RV *pError
00123 )
00124 {
00125   return "Mozilla Foundation";
00126 }
00127 
00128 static NSSUTF8 *
00129 nss_dbm_mdInstance_GetLibraryDescription
00130 (
00131   NSSCKMDInstance *mdInstance,                                    
00132   NSSCKFWInstance *fwInstance,
00133   CK_RV *pError
00134 )
00135 {
00136   return "Berkeley Database Module";
00137 }
00138 
00139 static CK_VERSION
00140 nss_dbm_mdInstance_GetLibraryVersion
00141 (
00142   NSSCKMDInstance *mdInstance,                                    
00143   NSSCKFWInstance *fwInstance
00144 )
00145 {
00146   static CK_VERSION rv = { 1, 0 }; /* My own version number */
00147   return rv;
00148 }
00149 
00150 static CK_BBOOL
00151 nss_dbm_mdInstance_ModuleHandlesSessionObjects
00152 (
00153   NSSCKMDInstance *mdInstance,                                    
00154   NSSCKFWInstance *fwInstance
00155 )
00156 {
00157   return CK_TRUE;
00158 }
00159 
00160 static CK_RV
00161 nss_dbm_mdInstance_GetSlots
00162 (
00163   NSSCKMDInstance *mdInstance,                                    
00164   NSSCKFWInstance *fwInstance,
00165   NSSCKMDSlot *slots[]
00166 )
00167 {
00168   nss_dbm_instance_t *instance = (nss_dbm_instance_t *)mdInstance->etc;
00169   CK_ULONG i;
00170   CK_RV rv = CKR_OK;
00171 
00172   for( i = 0; i < instance->nSlots; i++ ) {
00173     slots[i] = nss_dbm_mdSlot_factory(instance, instance->filenames[i], 
00174                                       instance->flags[i], &rv);
00175     if( (NSSCKMDSlot *)NULL == slots[i] ) {
00176       return rv;
00177     }
00178   }
00179 
00180   return rv;
00181 }
00182 
00183 /* nss_dbm_mdInstance_WaitForSlotEvent is not relevant */
00184 
00185 NSS_IMPLEMENT_DATA NSSCKMDInstance 
00186 nss_dbm_mdInstance = {
00187   NULL, /* etc; filled in later */
00188   nss_dbm_mdInstance_Initialize,
00189   NULL, /* nss_dbm_mdInstance_Finalize */
00190   nss_dbm_mdInstance_GetNSlots,
00191   nss_dbm_mdInstance_GetCryptokiVersion,
00192   nss_dbm_mdInstance_GetManufacturerID,
00193   nss_dbm_mdInstance_GetLibraryDescription,
00194   nss_dbm_mdInstance_GetLibraryVersion,
00195   nss_dbm_mdInstance_ModuleHandlesSessionObjects,
00196   nss_dbm_mdInstance_GetSlots,
00197   NULL, /* nss_dbm_mdInstance_WaitForSlotEvent */
00198   NULL /* terminator */
00199 };