Back to index

lightning-sunbird  0.9+nobinonly
object.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: object.c,v $ $Revision: 1.2.28.1 $ $Date: 2006/03/02 22:45:14 $";
00039 #endif /* DEBUG */
00040 
00041 #include "ckdbm.h"
00042 
00043 static void
00044 nss_dbm_mdObject_Finalize
00045 (
00046   NSSCKMDObject *mdObject,
00047   NSSCKFWObject *fwObject,
00048   NSSCKMDSession *mdSession,
00049   NSSCKFWSession *fwSession,
00050   NSSCKMDToken *mdToken,
00051   NSSCKFWToken *fwToken,
00052   NSSCKMDInstance *mdInstance,
00053   NSSCKFWInstance *fwInstance
00054 )
00055 {
00056   ;
00057 }
00058 
00059 static CK_RV
00060 nss_dbm_mdObject_Destroy
00061 (
00062   NSSCKMDObject *mdObject,
00063   NSSCKFWObject *fwObject,
00064   NSSCKMDSession *mdSession,
00065   NSSCKFWSession *fwSession,
00066   NSSCKMDToken *mdToken,
00067   NSSCKFWToken *fwToken,
00068   NSSCKMDInstance *mdInstance,
00069   NSSCKFWInstance *fwInstance
00070 )
00071 {
00072   nss_dbm_object_t *object = (nss_dbm_object_t *)mdObject->etc;
00073   return nss_dbm_db_delete_object(object->handle);
00074 }
00075 
00076 static CK_ULONG
00077 nss_dbm_mdObject_GetAttributeCount
00078 (
00079   NSSCKMDObject *mdObject,
00080   NSSCKFWObject *fwObject,
00081   NSSCKMDSession *mdSession,
00082   NSSCKFWSession *fwSession,
00083   NSSCKMDToken *mdToken,
00084   NSSCKFWToken *fwToken,
00085   NSSCKMDInstance *mdInstance,
00086   NSSCKFWInstance *fwInstance,
00087   CK_RV *pError
00088 )
00089 {
00090   nss_dbm_object_t *object = (nss_dbm_object_t *)mdObject->etc;
00091   nss_dbm_session_t *session = (nss_dbm_session_t *)mdSession->etc;
00092   return nss_dbm_db_get_object_attribute_count(object->handle, pError, 
00093                                                &session->deviceError);
00094 }
00095 
00096 static CK_RV
00097 nss_dbm_mdObject_GetAttributeTypes
00098 (
00099   NSSCKMDObject *mdObject,
00100   NSSCKFWObject *fwObject,
00101   NSSCKMDSession *mdSession,
00102   NSSCKFWSession *fwSession,
00103   NSSCKMDToken *mdToken,
00104   NSSCKFWToken *fwToken,
00105   NSSCKMDInstance *mdInstance,
00106   NSSCKFWInstance *fwInstance,
00107   CK_ATTRIBUTE_TYPE_PTR typeArray,
00108   CK_ULONG ulCount
00109 )
00110 {
00111   nss_dbm_object_t *object = (nss_dbm_object_t *)mdObject->etc;
00112   nss_dbm_session_t *session = (nss_dbm_session_t *)mdSession->etc;
00113   return nss_dbm_db_get_object_attribute_types(object->handle, typeArray,
00114                                                ulCount, &session->deviceError);
00115 }
00116 
00117 static CK_ULONG
00118 nss_dbm_mdObject_GetAttributeSize
00119 (
00120   NSSCKMDObject *mdObject,
00121   NSSCKFWObject *fwObject,
00122   NSSCKMDSession *mdSession,
00123   NSSCKFWSession *fwSession,
00124   NSSCKMDToken *mdToken,
00125   NSSCKFWToken *fwToken,
00126   NSSCKMDInstance *mdInstance,
00127   NSSCKFWInstance *fwInstance,
00128   CK_ATTRIBUTE_TYPE attribute,
00129   CK_RV *pError
00130 )
00131 {
00132   nss_dbm_object_t *object = (nss_dbm_object_t *)mdObject->etc;
00133   nss_dbm_session_t *session = (nss_dbm_session_t *)mdSession->etc;
00134   return nss_dbm_db_get_object_attribute_size(object->handle, attribute, pError, 
00135                                               &session->deviceError);
00136 }
00137 
00138 static NSSItem *
00139 nss_dbm_mdObject_GetAttribute
00140 (
00141   NSSCKMDObject *mdObject,
00142   NSSCKFWObject *fwObject,
00143   NSSCKMDSession *mdSession,
00144   NSSCKFWSession *fwSession,
00145   NSSCKMDToken *mdToken,
00146   NSSCKFWToken *fwToken,
00147   NSSCKMDInstance *mdInstance,
00148   NSSCKFWInstance *fwInstance,
00149   CK_ATTRIBUTE_TYPE attribute,
00150   CK_RV *pError
00151 )
00152 {
00153   nss_dbm_object_t *object = (nss_dbm_object_t *)mdObject->etc;
00154   nss_dbm_session_t *session = (nss_dbm_session_t *)mdSession->etc;
00155   return nss_dbm_db_get_object_attribute(object->handle, object->arena, attribute,
00156                                          pError, &session->deviceError);
00157 }
00158 
00159 static CK_RV
00160 nss_dbm_mdObject_SetAttribute
00161 (
00162   NSSCKMDObject *mdObject,
00163   NSSCKFWObject *fwObject,
00164   NSSCKMDSession *mdSession,
00165   NSSCKFWSession *fwSession,
00166   NSSCKMDToken *mdToken,
00167   NSSCKFWToken *fwToken,
00168   NSSCKMDInstance *mdInstance,
00169   NSSCKFWInstance *fwInstance,
00170   CK_ATTRIBUTE_TYPE attribute,
00171   NSSItem *value
00172 )
00173 {
00174   nss_dbm_object_t *object = (nss_dbm_object_t *)mdObject->etc;
00175   nss_dbm_session_t *session = (nss_dbm_session_t *)mdSession->etc;
00176   return nss_dbm_db_set_object_attribute(object->handle, attribute, value,
00177                                          &session->deviceError);
00178 }
00179 
00180 NSS_IMPLEMENT NSSCKMDObject *
00181 nss_dbm_mdObject_factory
00182 (
00183   nss_dbm_object_t *object,
00184   CK_RV *pError
00185 )
00186 {
00187   NSSCKMDObject *rv;
00188 
00189   rv = nss_ZNEW(object->arena, NSSCKMDObject);
00190   if( (NSSCKMDObject *)NULL == rv ) {
00191     *pError = CKR_HOST_MEMORY;
00192     return (NSSCKMDObject *)NULL;
00193   }
00194 
00195   rv->etc = (void *)object;
00196   rv->Finalize = nss_dbm_mdObject_Finalize;
00197   rv->Destroy = nss_dbm_mdObject_Destroy;
00198   /*  IsTokenObject can be deferred */
00199   rv->GetAttributeCount = nss_dbm_mdObject_GetAttributeCount;
00200   rv->GetAttributeTypes = nss_dbm_mdObject_GetAttributeTypes;
00201   rv->GetAttributeSize = nss_dbm_mdObject_GetAttributeSize;
00202   rv->GetAttribute = nss_dbm_mdObject_GetAttribute;
00203   rv->SetAttribute = nss_dbm_mdObject_SetAttribute;
00204   /*  GetObjectSize can be deferred */
00205 
00206   return rv;
00207 }