annotate src/solaris/native/sun/security/smartcardio/pcsc_md.c @ 5290:257dee3bea4e

7153343: Dependency on non-POSIX header file <link.h> causes portability problem Summary: Remove the unneccessary link.h Reviewed-by: alanb, chegar
author luchsh
date Fri, 16 Mar 2012 10:47:25 +0800
parents 5cca2f1a37da
children 61ecb4a9aa13
rev   line source
duke@0 1 /*
ohair@2362 2 * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
duke@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@0 4 *
duke@0 5 * This code is free software; you can redistribute it and/or modify it
duke@0 6 * under the terms of the GNU General Public License version 2 only, as
ohair@2362 7 * published by the Free Software Foundation. Oracle designates this
duke@0 8 * particular file as subject to the "Classpath" exception as provided
ohair@2362 9 * by Oracle in the LICENSE file that accompanied this code.
duke@0 10 *
duke@0 11 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@0 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@0 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@0 14 * version 2 for more details (a copy is included in the LICENSE file that
duke@0 15 * accompanied this code).
duke@0 16 *
duke@0 17 * You should have received a copy of the GNU General Public License version
duke@0 18 * 2 along with this work; if not, write to the Free Software Foundation,
duke@0 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@0 20 *
ohair@2362 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@2362 22 * or visit www.oracle.com if you need additional information or have any
ohair@2362 23 * questions.
duke@0 24 */
duke@0 25
duke@0 26 #include <stdio.h>
duke@0 27 #include <stdlib.h>
duke@0 28 #include <string.h>
duke@0 29 #include <assert.h>
duke@0 30
duke@0 31 #include <dlfcn.h>
duke@0 32
duke@0 33 #include <winscard.h>
duke@0 34
duke@0 35 #include <jni_util.h>
duke@0 36
duke@0 37 #include "sun_security_smartcardio_PlatformPCSC.h"
duke@0 38
duke@0 39 #include "pcsc_md.h"
duke@0 40
duke@0 41 void *hModule;
duke@0 42 FPTR_SCardEstablishContext scardEstablishContext;
duke@0 43 FPTR_SCardConnect scardConnect;
duke@0 44 FPTR_SCardDisconnect scardDisconnect;
duke@0 45 FPTR_SCardStatus scardStatus;
duke@0 46 FPTR_SCardGetStatusChange scardGetStatusChange;
duke@0 47 FPTR_SCardTransmit scardTransmit;
duke@0 48 FPTR_SCardListReaders scardListReaders;
duke@0 49 FPTR_SCardBeginTransaction scardBeginTransaction;
duke@0 50 FPTR_SCardEndTransaction scardEndTransaction;
duke@0 51 FPTR_SCardControl scardControl;
duke@0 52
duke@0 53 void *findFunction(JNIEnv *env, void *hModule, char *functionName) {
duke@0 54 void *fAddress = dlsym(hModule, functionName);
duke@0 55 if (fAddress == NULL) {
duke@0 56 char errorMessage[256];
duke@0 57 snprintf(errorMessage, sizeof(errorMessage), "Symbol not found: %s", functionName);
duke@0 58 JNU_ThrowNullPointerException(env, errorMessage);
duke@0 59 return NULL;
duke@0 60 }
duke@0 61 return fAddress;
duke@0 62 }
duke@0 63
duke@0 64 JNIEXPORT void JNICALL Java_sun_security_smartcardio_PlatformPCSC_initialize
duke@0 65 (JNIEnv *env, jclass thisClass, jstring jLibName) {
duke@0 66 const char *libName = (*env)->GetStringUTFChars(env, jLibName, NULL);
duke@0 67 hModule = dlopen(libName, RTLD_LAZY);
duke@0 68 (*env)->ReleaseStringUTFChars(env, jLibName, libName);
duke@0 69
duke@0 70 if (hModule == NULL) {
duke@0 71 JNU_ThrowIOException(env, dlerror());
duke@0 72 return;
duke@0 73 }
duke@0 74 scardEstablishContext = (FPTR_SCardEstablishContext)findFunction(env, hModule, "SCardEstablishContext");
duke@0 75 scardConnect = (FPTR_SCardConnect) findFunction(env, hModule, "SCardConnect");
duke@0 76 scardDisconnect = (FPTR_SCardDisconnect) findFunction(env, hModule, "SCardDisconnect");
duke@0 77 scardStatus = (FPTR_SCardStatus) findFunction(env, hModule, "SCardStatus");
duke@0 78 scardGetStatusChange = (FPTR_SCardGetStatusChange) findFunction(env, hModule, "SCardGetStatusChange");
duke@0 79 scardTransmit = (FPTR_SCardTransmit) findFunction(env, hModule, "SCardTransmit");
duke@0 80 scardListReaders = (FPTR_SCardListReaders) findFunction(env, hModule, "SCardListReaders");
duke@0 81 scardBeginTransaction = (FPTR_SCardBeginTransaction)findFunction(env, hModule, "SCardBeginTransaction");
duke@0 82 scardEndTransaction = (FPTR_SCardEndTransaction) findFunction(env, hModule, "SCardEndTransaction");
duke@0 83 scardControl = (FPTR_SCardControl) findFunction(env, hModule, "SCardControl");
duke@0 84 }