// Path: commons-eid-client/src/main/java/be/bosa/commons/eid/client/spi/Logger.java
// public interface Logger {
// 
// 	/**
// 	 * Error messages receiver.
// 	 *
// 	 * @param message the error message.
// 	 */
// 	void error(String message);
// 
// 	/**
// 	 * Debug messages receiver.
// 	 *
// 	 * @param message the debug message.
// 	 */
// 	void debug(String message);
// }


import java.io.File;
import be.bosa.commons.eid.client.spi.Logger;
/*
 * Commons eID Project.
 * Copyright (C) 2014 - 2018 BOSA.
 *
 * This is free software; you can redistribute it and/or modify it under the
 * terms of the GNU Lesser General Public License version 3.0 as published by
 * the Free Software Foundation.
 *
 * This software is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
 * for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this software; if not, see https://www.gnu.org/licenses/.
 */

/*
 * author Frank Marien
 */

package be.bosa.commons.eid.client.impl;



/**
 * Encapsulate fixes regarding the dynamic loading of the pcsclite library on
 * GNU/Linux Systems. statically call LibJ2PCSCGNULinuxFix.fixNativeLibrary()
 * before using a TerminalFactory.
 *
 * @author Frank Cornelis
 * @author Frank Marien
 */
public class LibJ2PCSCGNULinuxFix {

	private static final int PCSC_LIBRARY_VERSION = 1;
	private static final String SMARTCARDIO_LIBRARY_PROPERTY = "sun.security.smartcardio.library";
	private static final String LIBRARY_PATH_PROPERTY = "java.library.path";
	private static final String GNULINUX_OS_PROPERTY_PREFIX = "Linux";
	private static final String PCSC_LIBRARY_NAME = "pcsclite";
	private static final String UBUNTU_MULTILIB_32_SUFFIX = "i386-linux-gnu";
	private static final String UBUNTU_MULTILIB_64_SUFFIX = "x86_64-linux-gnu";
	private static final String JRE_BITNESS_PROPERTY = "os.arch";
	private static final String OS_NAME_PROPERTY = "os.name";
	private static final String JRE_BITNESS_32_VALUE = "i386";
	private static final String JRE_BITNESS_64_VALUE = "amd64";

	enum UbuntuBitness {
		NA, PURE32, PURE64, MULTILIB
	}

	private LibJ2PCSCGNULinuxFix() {
		super();
	}

	/**
	 * Make sure libpcsclite is found. The libj2pcsc.so from the JRE attempts to
	 * dlopen using the linker name "libpcsclite.so" instead of the appropriate
	 * "libpcsclite.so.1". This causes libpcsclite not to be found on GNU/Linux
	 * distributions that don't have the libpcsclite.so symbolic link. This
	 * method finds the library and forces the JRE to use it instead of
	 * attempting to locate it by itself. See also:
	 * http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=529339
	 * <br>
	 * Does nothing if not on a GNU/Linux system
	 */
	public static void fixNativeLibrary() {
		fixNativeLibrary(new VoidLogger());
	}

// Path: commons-eid-client/src/main/java/be/bosa/commons/eid/client/spi/Logger.java
// public interface Logger {
// 
// 	/**
// 	 * Error messages receiver.
// 	 *
// 	 * @param message the error message.
// 	 */
// 	void error(String message);
// 
// 	/**
// 	 * Debug messages receiver.
// 	 *
// 	 * @param message the debug message.
// 	 */
// 	void debug(String message);
// }


// Path: commons-eid-client/src/main/java/be/bosa/commons/eid/client/impl/LibJ2PCSCGNULinuxFix.java
import java.io.File;
import be.bosa.commons.eid.client.spi.Logger;

/*
 * Commons eID Project.
 * Copyright (C) 2014 - 2018 BOSA.
 *
 * This is free software; you can redistribute it and/or modify it under the
 * terms of the GNU Lesser General Public License version 3.0 as published by
 * the Free Software Foundation.
 *
 * This software is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
 * for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this software; if not, see https://www.gnu.org/licenses/.
 */

/*
 * author Frank Marien
 */

package be.bosa.commons.eid.client.impl;



/**
 * Encapsulate fixes regarding the dynamic loading of the pcsclite library on
 * GNU/Linux Systems. statically call LibJ2PCSCGNULinuxFix.fixNativeLibrary()
 * before using a TerminalFactory.
 *
 * @author Frank Cornelis
 * @author Frank Marien
 */
public class LibJ2PCSCGNULinuxFix {

	private static final int PCSC_LIBRARY_VERSION = 1;
	private static final String SMARTCARDIO_LIBRARY_PROPERTY = "sun.security.smartcardio.library";
	private static final String LIBRARY_PATH_PROPERTY = "java.library.path";
	private static final String GNULINUX_OS_PROPERTY_PREFIX = "Linux";
	private static final String PCSC_LIBRARY_NAME = "pcsclite";
	private static final String UBUNTU_MULTILIB_32_SUFFIX = "i386-linux-gnu";
	private static final String UBUNTU_MULTILIB_64_SUFFIX = "x86_64-linux-gnu";
	private static final String JRE_BITNESS_PROPERTY = "os.arch";
	private static final String OS_NAME_PROPERTY = "os.name";
	private static final String JRE_BITNESS_32_VALUE = "i386";
	private static final String JRE_BITNESS_64_VALUE = "amd64";

	enum UbuntuBitness {
		NA, PURE32, PURE64, MULTILIB
	}

	private LibJ2PCSCGNULinuxFix() {
		super();
	}

	/**
	 * Make sure libpcsclite is found. The libj2pcsc.so from the JRE attempts to
	 * dlopen using the linker name "libpcsclite.so" instead of the appropriate
	 * "libpcsclite.so.1". This causes libpcsclite not to be found on GNU/Linux
	 * distributions that don't have the libpcsclite.so symbolic link. This
	 * method finds the library and forces the JRE to use it instead of
	 * attempting to locate it by itself. See also:
	 * http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=529339
	 * <br>
	 * Does nothing if not on a GNU/Linux system
	 */
	public static void fixNativeLibrary() {
		fixNativeLibrary(new VoidLogger());
	}

	public static void fixNativeLibrary(Logger logger) {