1 /*
2 * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
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
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
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 *
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
175 free(tab);
176 return result;
177 }
178
179 JNIEXPORT jobjectArray JNICALL Java_sun_security_smartcardio_PCSC_SCardListReaders
180 (JNIEnv *env, jclass thisClass, jlong jContext)
181 {
182 SCARDCONTEXT context = (SCARDCONTEXT)jContext;
183 LONG rv;
184 LPTSTR mszReaders = NULL;
185 DWORD size = 0;
186 jobjectArray result;
187
188 dprintf1("-context: %x\n", context);
189 rv = CALL_SCardListReaders(context, NULL, NULL, &size);
190 if (handleRV(env, rv)) {
191 return NULL;
192 }
193 dprintf1("-size: %d\n", size);
194
195 if (size) {
196 mszReaders = malloc(size);
197 if (mszReaders == NULL) {
198 throwOutOfMemoryError(env, NULL);
199 return NULL;
200 }
201
202 rv = CALL_SCardListReaders(context, NULL, mszReaders, &size);
203 if (handleRV(env, rv)) {
204 free(mszReaders);
205 return NULL;
206 }
207 dprintf1("-String: %s\n", mszReaders);
208 }
209
210 result = pcsc_multi2jstring(env, mszReaders);
211 free(mszReaders);
212 return result;
213 }
214
215 JNIEXPORT jlong JNICALL Java_sun_security_smartcardio_PCSC_SCardConnect
216 (JNIEnv *env, jclass thisClass, jlong jContext, jstring jReaderName,
217 jint jShareMode, jint jPreferredProtocols)
218 {
219 SCARDCONTEXT context = (SCARDCONTEXT)jContext;
220 LONG rv;
221 LPCTSTR readerName;
222 SCARDHANDLE card = 0;
223 DWORD proto = 0;
224
225 readerName = (*env)->GetStringUTFChars(env, jReaderName, NULL);
226 if (readerName == NULL) {
227 return 0;
|
1 /*
2 * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
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
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
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 *
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
175 free(tab);
176 return result;
177 }
178
179 JNIEXPORT jobjectArray JNICALL Java_sun_security_smartcardio_PCSC_SCardListReaders
180 (JNIEnv *env, jclass thisClass, jlong jContext)
181 {
182 SCARDCONTEXT context = (SCARDCONTEXT)jContext;
183 LONG rv;
184 LPTSTR mszReaders = NULL;
185 DWORD size = 0;
186 jobjectArray result;
187
188 dprintf1("-context: %x\n", context);
189 rv = CALL_SCardListReaders(context, NULL, NULL, &size);
190 if (handleRV(env, rv)) {
191 return NULL;
192 }
193 dprintf1("-size: %d\n", size);
194
195 if (size != 0) {
196 mszReaders = malloc(size);
197 if (mszReaders == NULL) {
198 throwOutOfMemoryError(env, NULL);
199 return NULL;
200 }
201
202 rv = CALL_SCardListReaders(context, NULL, mszReaders, &size);
203 if (handleRV(env, rv)) {
204 free(mszReaders);
205 return NULL;
206 }
207 dprintf1("-String: %s\n", mszReaders);
208 } else {
209 return NULL;
210 }
211
212 result = pcsc_multi2jstring(env, mszReaders);
213 free(mszReaders);
214 return result;
215 }
216
217 JNIEXPORT jlong JNICALL Java_sun_security_smartcardio_PCSC_SCardConnect
218 (JNIEnv *env, jclass thisClass, jlong jContext, jstring jReaderName,
219 jint jShareMode, jint jPreferredProtocols)
220 {
221 SCARDCONTEXT context = (SCARDCONTEXT)jContext;
222 LONG rv;
223 LPCTSTR readerName;
224 SCARDHANDLE card = 0;
225 DWORD proto = 0;
226
227 readerName = (*env)->GetStringUTFChars(env, jReaderName, NULL);
228 if (readerName == NULL) {
229 return 0;
|