author | igerasim |
Wed, 28 May 2014 11:41:26 +0400 | |
changeset 24622 | 0b2ad6558dc6 |
parent 23060 | 61ffe815de7c |
permissions | -rw-r--r-- |
2 | 1 |
/* |
23060
61ffe815de7c
8033571: [parfait] warning from b128 for security/smartcardio/pcsc_md.c: JNI exception pending
valeriep
parents:
23010
diff
changeset
|
2 |
* Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
#include <stdio.h> |
|
27 |
#include <stdlib.h> |
|
28 |
#include <string.h> |
|
29 |
#include <assert.h> |
|
30 |
||
31 |
#include <dlfcn.h> |
|
32 |
||
33 |
#include <winscard.h> |
|
34 |
||
35 |
#include "sun_security_smartcardio_PlatformPCSC.h" |
|
36 |
||
37 |
#include "pcsc_md.h" |
|
38 |
||
39 |
void *hModule; |
|
40 |
FPTR_SCardEstablishContext scardEstablishContext; |
|
41 |
FPTR_SCardConnect scardConnect; |
|
42 |
FPTR_SCardDisconnect scardDisconnect; |
|
43 |
FPTR_SCardStatus scardStatus; |
|
44 |
FPTR_SCardGetStatusChange scardGetStatusChange; |
|
45 |
FPTR_SCardTransmit scardTransmit; |
|
46 |
FPTR_SCardListReaders scardListReaders; |
|
47 |
FPTR_SCardBeginTransaction scardBeginTransaction; |
|
48 |
FPTR_SCardEndTransaction scardEndTransaction; |
|
49 |
FPTR_SCardControl scardControl; |
|
50 |
||
10798
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
51 |
/* |
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
52 |
* Throws a Java Exception by name |
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
53 |
*/ |
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
54 |
void throwByName(JNIEnv *env, const char *name, const char *msg) |
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
55 |
{ |
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
56 |
jclass cls = (*env)->FindClass(env, name); |
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
57 |
|
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
58 |
if (cls != 0) /* Otherwise an exception has already been thrown */ |
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
59 |
(*env)->ThrowNew(env, cls, msg); |
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
60 |
} |
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
61 |
|
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
62 |
/* |
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
63 |
* Throws java.lang.NullPointerException |
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
64 |
*/ |
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
65 |
void throwNullPointerException(JNIEnv *env, const char *msg) |
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
66 |
{ |
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
67 |
throwByName(env, "java/lang/NullPointerException", msg); |
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
68 |
} |
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
69 |
|
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
70 |
/* |
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
71 |
* Throws java.io.IOException |
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
72 |
*/ |
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
73 |
void throwIOException(JNIEnv *env, const char *msg) |
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
74 |
{ |
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
75 |
throwByName(env, "java/io/IOException", msg); |
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
76 |
} |
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
77 |
|
2 | 78 |
void *findFunction(JNIEnv *env, void *hModule, char *functionName) { |
79 |
void *fAddress = dlsym(hModule, functionName); |
|
80 |
if (fAddress == NULL) { |
|
81 |
char errorMessage[256]; |
|
82 |
snprintf(errorMessage, sizeof(errorMessage), "Symbol not found: %s", functionName); |
|
10798
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
83 |
throwNullPointerException(env, errorMessage); |
2 | 84 |
return NULL; |
85 |
} |
|
86 |
return fAddress; |
|
87 |
} |
|
88 |
||
89 |
JNIEXPORT void JNICALL Java_sun_security_smartcardio_PlatformPCSC_initialize |
|
90 |
(JNIEnv *env, jclass thisClass, jstring jLibName) { |
|
91 |
const char *libName = (*env)->GetStringUTFChars(env, jLibName, NULL); |
|
23060
61ffe815de7c
8033571: [parfait] warning from b128 for security/smartcardio/pcsc_md.c: JNI exception pending
valeriep
parents:
23010
diff
changeset
|
92 |
if (libName == NULL) { |
61ffe815de7c
8033571: [parfait] warning from b128 for security/smartcardio/pcsc_md.c: JNI exception pending
valeriep
parents:
23010
diff
changeset
|
93 |
throwNullPointerException(env, "PCSC library name is null"); |
61ffe815de7c
8033571: [parfait] warning from b128 for security/smartcardio/pcsc_md.c: JNI exception pending
valeriep
parents:
23010
diff
changeset
|
94 |
return; |
61ffe815de7c
8033571: [parfait] warning from b128 for security/smartcardio/pcsc_md.c: JNI exception pending
valeriep
parents:
23010
diff
changeset
|
95 |
} |
2 | 96 |
hModule = dlopen(libName, RTLD_LAZY); |
97 |
(*env)->ReleaseStringUTFChars(env, jLibName, libName); |
|
98 |
||
99 |
if (hModule == NULL) { |
|
10798
413b731e1818
7103549: Remove dependencies on libjava and libjvm from security libraries
chegar
parents:
5506
diff
changeset
|
100 |
throwIOException(env, dlerror()); |
2 | 101 |
return; |
102 |
} |
|
103 |
scardEstablishContext = (FPTR_SCardEstablishContext)findFunction(env, hModule, "SCardEstablishContext"); |
|
23060
61ffe815de7c
8033571: [parfait] warning from b128 for security/smartcardio/pcsc_md.c: JNI exception pending
valeriep
parents:
23010
diff
changeset
|
104 |
if ((*env)->ExceptionCheck(env)) { |
61ffe815de7c
8033571: [parfait] warning from b128 for security/smartcardio/pcsc_md.c: JNI exception pending
valeriep
parents:
23010
diff
changeset
|
105 |
return; |
61ffe815de7c
8033571: [parfait] warning from b128 for security/smartcardio/pcsc_md.c: JNI exception pending
valeriep
parents:
23010
diff
changeset
|
106 |
} |
2 | 107 |
scardConnect = (FPTR_SCardConnect) findFunction(env, hModule, "SCardConnect"); |
23060
61ffe815de7c
8033571: [parfait] warning from b128 for security/smartcardio/pcsc_md.c: JNI exception pending
valeriep
parents:
23010
diff
changeset
|
108 |
if ((*env)->ExceptionCheck(env)) { |
61ffe815de7c
8033571: [parfait] warning from b128 for security/smartcardio/pcsc_md.c: JNI exception pending
valeriep
parents:
23010
diff
changeset
|
109 |
return; |
61ffe815de7c
8033571: [parfait] warning from b128 for security/smartcardio/pcsc_md.c: JNI exception pending
valeriep
parents:
23010
diff
changeset
|
110 |
} |
2 | 111 |
scardDisconnect = (FPTR_SCardDisconnect) findFunction(env, hModule, "SCardDisconnect"); |
23060
61ffe815de7c
8033571: [parfait] warning from b128 for security/smartcardio/pcsc_md.c: JNI exception pending
valeriep
parents:
23010
diff
changeset
|
112 |
if ((*env)->ExceptionCheck(env)) { |
61ffe815de7c
8033571: [parfait] warning from b128 for security/smartcardio/pcsc_md.c: JNI exception pending
valeriep
parents:
23010
diff
changeset
|
113 |
return; |
61ffe815de7c
8033571: [parfait] warning from b128 for security/smartcardio/pcsc_md.c: JNI exception pending
valeriep
parents:
23010
diff
changeset
|
114 |
} |
2 | 115 |
scardStatus = (FPTR_SCardStatus) findFunction(env, hModule, "SCardStatus"); |
23060
61ffe815de7c
8033571: [parfait] warning from b128 for security/smartcardio/pcsc_md.c: JNI exception pending
valeriep
parents:
23010
diff
changeset
|
116 |
if ((*env)->ExceptionCheck(env)) { |
61ffe815de7c
8033571: [parfait] warning from b128 for security/smartcardio/pcsc_md.c: JNI exception pending
valeriep
parents:
23010
diff
changeset
|
117 |
return; |
61ffe815de7c
8033571: [parfait] warning from b128 for security/smartcardio/pcsc_md.c: JNI exception pending
valeriep
parents:
23010
diff
changeset
|
118 |
} |
2 | 119 |
scardGetStatusChange = (FPTR_SCardGetStatusChange) findFunction(env, hModule, "SCardGetStatusChange"); |
23060
61ffe815de7c
8033571: [parfait] warning from b128 for security/smartcardio/pcsc_md.c: JNI exception pending
valeriep
parents:
23010
diff
changeset
|
120 |
if ((*env)->ExceptionCheck(env)) { |
61ffe815de7c
8033571: [parfait] warning from b128 for security/smartcardio/pcsc_md.c: JNI exception pending
valeriep
parents:
23010
diff
changeset
|
121 |
return; |
61ffe815de7c
8033571: [parfait] warning from b128 for security/smartcardio/pcsc_md.c: JNI exception pending
valeriep
parents:
23010
diff
changeset
|
122 |
} |
2 | 123 |
scardTransmit = (FPTR_SCardTransmit) findFunction(env, hModule, "SCardTransmit"); |
23060
61ffe815de7c
8033571: [parfait] warning from b128 for security/smartcardio/pcsc_md.c: JNI exception pending
valeriep
parents:
23010
diff
changeset
|
124 |
if ((*env)->ExceptionCheck(env)) { |
61ffe815de7c
8033571: [parfait] warning from b128 for security/smartcardio/pcsc_md.c: JNI exception pending
valeriep
parents:
23010
diff
changeset
|
125 |
return; |
61ffe815de7c
8033571: [parfait] warning from b128 for security/smartcardio/pcsc_md.c: JNI exception pending
valeriep
parents:
23010
diff
changeset
|
126 |
} |
2 | 127 |
scardListReaders = (FPTR_SCardListReaders) findFunction(env, hModule, "SCardListReaders"); |
23060
61ffe815de7c
8033571: [parfait] warning from b128 for security/smartcardio/pcsc_md.c: JNI exception pending
valeriep
parents:
23010
diff
changeset
|
128 |
if ((*env)->ExceptionCheck(env)) { |
61ffe815de7c
8033571: [parfait] warning from b128 for security/smartcardio/pcsc_md.c: JNI exception pending
valeriep
parents:
23010
diff
changeset
|
129 |
return; |
61ffe815de7c
8033571: [parfait] warning from b128 for security/smartcardio/pcsc_md.c: JNI exception pending
valeriep
parents:
23010
diff
changeset
|
130 |
} |
2 | 131 |
scardBeginTransaction = (FPTR_SCardBeginTransaction)findFunction(env, hModule, "SCardBeginTransaction"); |
23060
61ffe815de7c
8033571: [parfait] warning from b128 for security/smartcardio/pcsc_md.c: JNI exception pending
valeriep
parents:
23010
diff
changeset
|
132 |
if ((*env)->ExceptionCheck(env)) { |
61ffe815de7c
8033571: [parfait] warning from b128 for security/smartcardio/pcsc_md.c: JNI exception pending
valeriep
parents:
23010
diff
changeset
|
133 |
return; |
61ffe815de7c
8033571: [parfait] warning from b128 for security/smartcardio/pcsc_md.c: JNI exception pending
valeriep
parents:
23010
diff
changeset
|
134 |
} |
2 | 135 |
scardEndTransaction = (FPTR_SCardEndTransaction) findFunction(env, hModule, "SCardEndTransaction"); |
23060
61ffe815de7c
8033571: [parfait] warning from b128 for security/smartcardio/pcsc_md.c: JNI exception pending
valeriep
parents:
23010
diff
changeset
|
136 |
if ((*env)->ExceptionCheck(env)) { |
61ffe815de7c
8033571: [parfait] warning from b128 for security/smartcardio/pcsc_md.c: JNI exception pending
valeriep
parents:
23010
diff
changeset
|
137 |
return; |
61ffe815de7c
8033571: [parfait] warning from b128 for security/smartcardio/pcsc_md.c: JNI exception pending
valeriep
parents:
23010
diff
changeset
|
138 |
} |
24622
0b2ad6558dc6
8039319: (smartcardio) Card.transmitControlCommand() does not work on Mac OS X
igerasim
parents:
23060
diff
changeset
|
139 |
#ifndef __APPLE__ |
2 | 140 |
scardControl = (FPTR_SCardControl) findFunction(env, hModule, "SCardControl"); |
24622
0b2ad6558dc6
8039319: (smartcardio) Card.transmitControlCommand() does not work on Mac OS X
igerasim
parents:
23060
diff
changeset
|
141 |
#else |
0b2ad6558dc6
8039319: (smartcardio) Card.transmitControlCommand() does not work on Mac OS X
igerasim
parents:
23060
diff
changeset
|
142 |
scardControl = (FPTR_SCardControl) findFunction(env, hModule, "SCardControl132"); |
0b2ad6558dc6
8039319: (smartcardio) Card.transmitControlCommand() does not work on Mac OS X
igerasim
parents:
23060
diff
changeset
|
143 |
#endif // __APPLE__ |
2 | 144 |
} |