2362N/A * Copyright (c) 2003, 2009, Oracle and/or its affiliates. All rights reserved. 0N/A/* Copyright (c) 2002 Graz University of Technology. All rights reserved. 0N/A * Redistribution and use in source and binary forms, with or without 0N/A * modification, are permitted provided that the following conditions are met: 0N/A * 1. Redistributions of source code must retain the above copyright notice, 0N/A * this list of conditions and the following disclaimer. 0N/A * 2. Redistributions in binary form must reproduce the above copyright notice, 0N/A * this list of conditions and the following disclaimer in the documentation 0N/A * and/or other materials provided with the distribution. 0N/A * 3. The end-user documentation included with the redistribution, if any, must 0N/A * include the following acknowledgment: 0N/A * "This product includes software developed by IAIK of Graz University of 0N/A * Alternately, this acknowledgment may appear in the software itself, if 0N/A * and wherever such third-party acknowledgments normally appear. 0N/A * 4. The names "Graz University of Technology" and "IAIK of Graz University of 0N/A * Technology" must not be used to endorse or promote products derived from 0N/A * this software without prior written permission. 0N/A * 5. Products derived from this software may not be called 0N/A * "IAIK PKCS Wrapper", nor may "IAIK" appear in their name, without prior 0N/A * written permission of Graz University of Technology. 0N/A * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED 0N/A * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 0N/A * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 0N/A * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE LICENSOR BE 0N/A * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 0N/A * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 0N/A * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 0N/A * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 0N/A * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 0N/A * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 0N/A * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 0N/A * POSSIBILITY OF SUCH DAMAGE. 0N/A/* The initArgs that enable the application to do custom mutex-handling */ 0N/A#
endif /* NO_CALLBACKS */ 0N/A/* ************************************************************************** */ 0N/A/* Now come the functions for mutex handling and notification callbacks */ 0N/A/* ************************************************************************** */ 0N/A * converts the InitArgs object to a CK_C_INITIALIZE_ARGS structure and sets the functions 0N/A * that will call the right Java mutex functions 0N/A * @param env - used to call JNI funktions to get the Java classes, objects, methods and fields 0N/A * @param pInitArgs - the InitArgs object with the Java mutex functions to call 0N/A * @return - the pointer to the CK_C_INITIALIZE_ARGS structure with the functions that will call 0N/A * the corresponding Java functions 0N/A#
endif /* NO_CALLBACKS */ 0N/A /* convert the Java InitArgs object to a pointer to a CK_C_INITIALIZE_ARGS structure */ 0N/A /* Set the mutex functions that will call the Java mutex functions, but 0N/A * only set it, if the field is not null. 0N/A /* we only need to keep a global copy, if we need callbacks */ 0N/A /* set the global object jInitArgs so that the right Java mutex functions will be called */ 0N/A#
endif /* NO_CALLBACKS */ 0N/A /* convert and set the flags field */ 0N/A /* pReserved should be NULL_PTR in this version */ 0N/A /* we try to convert the reserved parameter also */ 0N/A * is the function that gets called by PKCS#11 to create a mutex and calls the Java 0N/A * CreateMutex function 0N/A * @param env - used to call JNI funktions to get the Java classes, objects, methods and fields 0N/A * @param ppMutex - the new created mutex 0N/A * @return - should return CKR_OK if the mutex creation was ok 0N/A /* Get the currently running Java VM */ 0N/A /* Determine, if current thread is already attached */ 0N/A /* thread detached, so attach it */ 0N/A /* this version of JNI is not supported, so just try to attach */ 0N/A /* we assume it was attached to ensure that this thread is not detached 0N/A * afterwards even though it should not 0N/A /* get the CreateMutex object out of the jInitArgs object */ 0N/A /* call the CK_CREATEMUTEX function of the CreateMutex object */ 0N/A /* and get the new Java mutex object */ 0N/A /* set a global reference on the Java mutex */ 0N/A /* convert the Java mutex to a CK mutex */ 0N/A /* check, if callback threw an exception */ 936N/A /* TBD: clear the pending exception with ExceptionClear? */ 0N/A /* The was an exception thrown, now we get the error-code from it */ 0N/A /* if we attached this thread to the VM just for callback, we detach it now */ 0N/A * is the function that gets called by PKCS#11 to destroy a mutex and calls the Java 0N/A * DestroyMutex function 0N/A * @param env - used to call JNI funktions to get the Java classes, objects, methods and fields 0N/A * @param pMutex - the mutex to destroy 0N/A * @return - should return CKR_OK if the mutex was destroyed 0N/A /* Get the currently running Java VM */ 0N/A /* Determine, if current thread is already attached */ 0N/A /* thread detached, so attach it */ 0N/A /* this version of JNI is not supported, so just try to attach */ 0N/A /* we assume it was attached to ensure that this thread is not detached 0N/A * afterwards even though it should not 0N/A /* convert the CK mutex to a Java mutex */ 0N/A /* get the DestroyMutex object out of the jInitArgs object */ 0N/A /* call the CK_DESTROYMUTEX method of the DestroyMutex object */ 0N/A /* delete the global reference on the Java mutex */ 0N/A /* check, if callback threw an exception */ 936N/A /* TBD: clear the pending exception with ExceptionClear? */ 0N/A /* The was an exception thrown, now we get the error-code from it */ 0N/A /* if we attached this thread to the VM just for callback, we detach it now */ 0N/A * is the function that gets called by PKCS#11 to lock a mutex and calls the Java 0N/A * LockMutex function 0N/A * @param env - used to call JNI funktions to get the Java classes, objects, methods and fields 0N/A * @param pMutex - the mutex to lock 0N/A * @return - should return CKR_OK if the mutex was not locked already 0N/A /* Get the currently running Java VM */ 0N/A /* Determine, if current thread is already attached */ 0N/A /* thread detached, so attach it */ 0N/A /* this version of JNI is not supported, so just try to attach */ 0N/A /* we assume it was attached to ensure that this thread is not detached 0N/A * afterwards even though it should not 0N/A /* convert the CK mutex to a Java mutex */ 0N/A /* get the LockMutex object out of the jInitArgs object */ 0N/A /* call the CK_LOCKMUTEX method of the LockMutex object */ 0N/A /* check, if callback threw an exception */ 936N/A /* TBD: clear the pending exception with ExceptionClear? */ 0N/A /* The was an exception thrown, now we get the error-code from it */ 0N/A /* if we attached this thread to the VM just for callback, we detach it now */ 0N/A * is the function that gets called by PKCS#11 to unlock a mutex and calls the Java 0N/A * UnlockMutex function 0N/A * @param env - used to call JNI funktions to get the Java classes, objects, methods and fields 0N/A * @param pMutex - the mutex to unlock 0N/A * @return - should return CKR_OK if the mutex was not unlocked already 0N/A /* Get the currently running Java VM */ 0N/A /* Determine, if current thread is already attached */ 0N/A /* thread detached, so attach it */ 0N/A /* this version of JNI is not supported, so just try to attach */ 0N/A /* we assume it was attached to ensure that this thread is not detached 0N/A * afterwards even though it should not 0N/A /* convert the CK-type mutex to a Java mutex */ 0N/A /* get the UnlockMutex object out of the jInitArgs object */ 0N/A /* call the CK_UNLOCKMUTEX method of the UnLockMutex object */ 0N/A /* check, if callback threw an exception */ 936N/A /* TBD: clear the pending exception with ExceptionClear? */ 0N/A /* The was an exception thrown, now we get the error-code from it */ 0N/A /* if we attached this thread to the VM just for callback, we detach it now */ 0N/A#
endif /* NO_CALLBACKS */