Merge local branch into tizen accepted/tizen/20130912.185847 accepted/tizen/20130912.194034 accepted/tizen/20130913.025052 submit/tizen/20130912.080408 submit/tizen/20130912.090707
authorYoungjae Shin <yj99.shin@samsung.com>
Thu, 12 Sep 2013 03:10:32 +0000 (12:10 +0900)
committerYoungjae Shin <yj99.shin@samsung.com>
Thu, 12 Sep 2013 04:00:45 +0000 (13:00 +0900)
Conflicts:
CMakeLists.txt
client/CMakeLists.txt
client/ClientChannel.cpp
client/ClientDispatcher.cpp
client/ClientIPC.cpp
client/Reader.cpp
client/SEService.cpp
client/Session.cpp
client/include/ClientChannel.h
client/include/ClientDispatcher.h
client/include/ClientIPC.h
client/include/Reader.h
client/include/SEService.h
client/include/Session.h
common/APDUHelper.cpp
common/AccessCondition.cpp
common/AccessControlList.cpp
common/ByteArray.cpp
common/CMakeLists.txt
common/DispatcherHelper.cpp
common/EFDIR.cpp
common/FCI.cpp
common/FileObject.cpp
common/IPCHelper.cpp
common/ISO7816BERTLV.cpp
common/Message.cpp
common/NumberStream.cpp
common/OpensslHelper.cpp
common/PKCS15.cpp
common/PKCS15DODF.cpp
common/PKCS15ODF.cpp
common/PKCS15OID.cpp
common/PKCS15Object.cpp
common/PKCS15Path.cpp
common/PKCS15TokenInfo.cpp
common/SignatureHelper.cpp
common/SimpleTLV.cpp
common/TLVHelper.cpp
common/include/APDUHelper.h
common/include/AccessCondition.h
common/include/AccessControlList.h
common/include/ByteArray.h
common/include/Channel.h
common/include/Debug.h
common/include/DispatcherHelper.h
common/include/DispatcherMsg.h
common/include/EFDIR.h
common/include/Exception.h
common/include/FCI.h
common/include/FileObject.h
common/include/IPCHelper.h
common/include/ISO7816BERTLV.h
common/include/Message.h
common/include/NumberStream.h
common/include/OpensslHelper.h
common/include/PKCS15.h
common/include/PKCS15DODF.h
common/include/PKCS15ODF.h
common/include/PKCS15OID.h
common/include/PKCS15Object.h
common/include/PKCS15Path.h
common/include/PKCS15TokenInfo.h
common/include/ProviderHelper.h
common/include/ReaderHelper.h
common/include/Record.h
common/include/SEServiceHelper.h
common/include/Serializable.h
common/include/SessionHelper.h
common/include/SignatureHelper.h
common/include/SimpleTLV.h
common/include/TLVHelper.h
common/include/Terminal.h
packaging/smartcard-service.spec
server/CMakeLists.txt
server/ClientInstance.cpp
server/ServerChannel.cpp
server/ServerDispatcher.cpp
server/ServerIPC.cpp
server/ServerReader.cpp
server/ServerResource.cpp
server/ServerSEService.cpp
server/ServerSession.cpp
server/ServiceInstance.cpp
server/include/ClientInstance.h
server/include/ServerChannel.h
server/include/ServerDispatcher.h
server/include/ServerIPC.h
server/include/ServerReader.h
server/include/ServerResource.h
server/include/ServerSEService.h
server/include/ServerSession.h
server/include/ServiceInstance.h
server/org.tizen.smartcard_service.service
server/smartcard-daemon.cpp
test-client/CMakeLists.txt
test-client/test-client-sync.cpp
test-client/test-client.cpp

Change-Id: Id1dee9e43f2d75752a75dccae9e7e3a8c70b5775

138 files changed:
CMakeLists.txt
client/CMakeLists.txt
client/ClientChannel.cpp
client/ClientDispatcher.cpp
client/ClientGDBus.cpp [moved from common/SEServiceHelper.cpp with 84% similarity]
client/ClientIPC.cpp
client/Reader.cpp
client/SEService.cpp
client/Session.cpp
client/include/ClientChannel.h
client/include/ClientDispatcher.h
client/include/ClientGDBus.h [moved from common/SessionHelper.cpp with 73% similarity]
client/include/ClientIPC.h
client/include/Reader.h
client/include/SEService.h
client/include/Session.h
client/smartcard-service.pc [moved from client/smartcard-service.pc.in with 79% similarity]
common/APDUHelper.cpp
common/AccessCondition.cpp
common/AccessControlList.cpp
common/ByteArray.cpp
common/CMakeLists.txt
common/DispatcherHelper.cpp
common/EFDIR.cpp
common/FCI.cpp
common/FileObject.cpp
common/GDBusHelper.cpp [new file with mode: 0644]
common/GPACE.cpp [new file with mode: 0644]
common/GPARAACL.cpp [new file with mode: 0644]
common/GPARAM.cpp [new file with mode: 0644]
common/GPARFACL.cpp [new file with mode: 0644]
common/GPSEACL.cpp [deleted file]
common/IPCHelper.cpp
common/ISO7816BERTLV.cpp
common/Message.cpp
common/NumberStream.cpp
common/OpensslHelper.cpp
common/PKCS15.cpp
common/PKCS15DODF.cpp
common/PKCS15ODF.cpp
common/PKCS15OID.cpp
common/PKCS15Object.cpp
common/PKCS15Path.cpp
common/PKCS15TokenInfo.cpp
common/SignatureHelper.cpp
common/SimpleTLV.cpp
common/TLVHelper.cpp
common/include/APDUHelper.h
common/include/AccessCondition.h
common/include/AccessControlList.h
common/include/ByteArray.h
common/include/Channel.h
common/include/Debug.h
common/include/DispatcherHelper.h
common/include/DispatcherMsg.h
common/include/EFDIR.h
common/include/Exception.h
common/include/FCI.h
common/include/FileObject.h
common/include/GDBusHelper.h [moved from common/ProviderHelper.cpp with 60% similarity]
common/include/GPACE.h [new file with mode: 0644]
common/include/GPARAACL.h [new file with mode: 0644]
common/include/GPARAM.h [new file with mode: 0644]
common/include/GPARFACL.h [moved from common/include/GPSEACL.h with 55% similarity]
common/include/IPCHelper.h
common/include/ISO7816BERTLV.h
common/include/Message.h
common/include/NumberStream.h
common/include/OpensslHelper.h
common/include/PKCS15.h
common/include/PKCS15DODF.h
common/include/PKCS15ODF.h
common/include/PKCS15OID.h
common/include/PKCS15Object.h
common/include/PKCS15Path.h
common/include/PKCS15TokenInfo.h
common/include/ProviderHelper.h
common/include/ReaderHelper.h
common/include/Record.h
common/include/SEServiceHelper.h
common/include/Serializable.h
common/include/SessionHelper.h
common/include/SignatureHelper.h
common/include/SimpleTLV.h
common/include/TLVHelper.h
common/include/Terminal.h
common/smartcard-service-common.pc [moved from common/smartcard-service-common.pc.in with 78% similarity]
common/smartcard-service-gdbus.xml [new file with mode: 0755]
common/smartcard-service.xml [moved from server/smartcard-service.xml with 100% similarity]
debian/changelog [new file with mode: 0644]
debian/compat [new file with mode: 0644]
debian/control [new file with mode: 0644]
debian/rules [new file with mode: 0755]
debian/smartcard-service-common-dev.dirs [new file with mode: 0644]
debian/smartcard-service-common-dev.install [new file with mode: 0644]
debian/smartcard-service-common.dirs [new file with mode: 0644]
debian/smartcard-service-common.install [new file with mode: 0644]
debian/smartcard-service-dev.dirs [new file with mode: 0644]
debian/smartcard-service-dev.install [new file with mode: 0644]
debian/smartcard-service-server.dirs [new file with mode: 0644]
debian/smartcard-service-server.init [new file with mode: 0755]
debian/smartcard-service-server.install [new file with mode: 0644]
debian/smartcard-service.dirs [new file with mode: 0644]
debian/smartcard-service.install [new file with mode: 0644]
packaging/smartcard-service.spec
server/CMakeLists.txt
server/ClientInstance.cpp
server/ServerChannel.cpp
server/ServerDispatcher.cpp
server/ServerGDBus.cpp [new file with mode: 0644]
server/ServerIPC.cpp
server/ServerReader.cpp
server/ServerResource.cpp
server/ServerSEService.cpp
server/ServerSession.cpp
server/ServiceInstance.cpp
server/include/ClientInstance.h
server/include/ServerChannel.h
server/include/ServerDispatcher.h
server/include/ServerGDBus.h [new file with mode: 0644]
server/include/ServerIPC.h
server/include/ServerReader.h
server/include/ServerResource.h
server/include/ServerSEService.h
server/include/ServerSession.h
server/include/ServiceInstance.h
server/include/smartcard-daemon.h [moved from common/ReaderHelper.cpp with 58% similarity]
server/org.tizen.smartcard_service.service
server/smartcard-daemon.cpp
server/smartcard-service-server.xml [new file with mode: 0644]
smartcard-service-common-devel.manifest [new file with mode: 0644]
smartcard-service-common.manifest [new file with mode: 0644]
smartcard-service-devel.manifest [new file with mode: 0644]
smartcard-service-server.manifest [new file with mode: 0644]
smartcard-service.manifest [new file with mode: 0644]
test-client/CMakeLists.txt
test-client/test-client-sync.cpp
test-client/test-client.cpp

index 65b1733..f78f23c 100644 (file)
@@ -4,15 +4,42 @@ MESSAGE("build smartcard-service")
 
 SET(CMAKE_VERBOSE_MAKEFILE OFF)
 
-IF("${USE_AUTOSTART}" STREQUAL "1")
-       ADD_DEFINITIONS("-DUSE_AUTOSTART")
-ENDIF()
+IF(DEFINED USE_GDBUS)
+       ADD_DEFINITIONS("-DUSE_GDBUS")
+
+       # apply smack
+       ##ADD_DEFINITIONS("-DUSER_SPACE_SMACK")
+
+       IF(DEFINED USE_AUTOSTART)
+               ADD_DEFINITIONS("-DUSE_AUTOSTART")
+       ENDIF()
+
+       FIND_PROGRAM(GDBUS_CODEGEN NAMES gdbus-codegen)
+       EXEC_PROGRAM(${GDBUS_CODEGEN} ARGS
+               " \\
+               --generate-c-code ${CMAKE_CURRENT_SOURCE_DIR}/common/smartcard-service-gdbus \\
+               --c-namespace SmartcardService\\
+               --interface-prefix org.tizen.SmartcardService. \\
+               ${CMAKE_CURRENT_SOURCE_DIR}/common/smartcard-service-gdbus.xml \\
+               ")
+ELSE()
+       ADD_DEFINITIONS("-DCLIENT_IPC_THREAD")
+       ADD_DEFINITIONS("-DUSE_IPC_EPOLL")
 
-ADD_DEFINITIONS("-DCLIENT_IPC_THREAD")
-ADD_DEFINITIONS("-DUSE_IPC_EPOLL")
+       IF(DEFINED USE_AUTOSTART)
+               ADD_DEFINITIONS("-DUSE_AUTOSTART")
+
+               FIND_PROGRAM(DBUS_BINDING_TOOL NAMES dbus-binding-tool)
+               EXEC_PROGRAM("${DBUS_BINDING_TOOL}" ARGS "--prefix=smartcard_service ${CMAKE_CURRENT_SOURCE_DIR}/common/smartcard-service.xml --mode=glib-server --output=${CMAKE_CURRENT_SOURCE_DIR}/common/include/smartcard-service-binding.h")
+               EXEC_PROGRAM("${DBUS_BINDING_TOOL}" ARGS "--prefix=smartcard_service ${CMAKE_CURRENT_SOURCE_DIR}/common/smartcard-service.xml --mode=glib-client --output=${CMAKE_CURRENT_SOURCE_DIR}/common/include/smartcard-service-glue.h")
+       ENDIF()
+ENDIF()
 
 ADD_SUBDIRECTORY(common)
 ADD_SUBDIRECTORY(client)
 ADD_SUBDIRECTORY(server)
-ADD_SUBDIRECTORY(test-client)
+
+IF(DEFINED TEST_CLIENT)
+       ADD_SUBDIRECTORY(test-client)
+ENDIF()
 
index 30369af..d78c8ab 100644 (file)
@@ -5,6 +5,7 @@ SET(LIB_NAME "smartcard-service")
 SET(VERSION_MAJOR 1)
 SET(VERSION ${VERSION_MAJOR}.0.0)
 
+include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../common)
 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../common/include)
 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../server/include)
 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
@@ -12,12 +13,19 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
 AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SRCS)
 
 IF("${CMAKE_BUILD_TYPE}" STREQUAL "")
-        SET(CMAKE_BUILD_TYPE "Release")
+       SET(CMAKE_BUILD_TYPE "Release")
 ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "")
 MESSAGE("Build type: ${CMAKE_BUILD_TYPE}")
 
+# pkg config
 INCLUDE(FindPkgConfig)
-pkg_check_modules(pkgs_client REQUIRED gthread-2.0 dlog dbus-glib-1 security-server)
+
+SET(PKG_MODULE glib-2.0 dlog)
+IF(NOT DEFINED USE_GDBUS)
+       SET(PKG_MODULE ${PKG_MODULE} dbus-glib-1)
+ENDIF()
+
+pkg_check_modules(pkgs_client REQUIRED ${PKG_MODULE})
 
 MESSAGE("${LIB_NAME} ld flag : ${pkgs_client_LDFLAGS}")
 
@@ -26,13 +34,11 @@ FOREACH(flag ${pkgs_client_CFLAGS})
        SET(EXTRA_CXXFLAGS "${EXTRA_CXXFLAGS} ${flag}")
 ENDFOREACH(flag)
 
-#SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -finstrument-functions")
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -finstrument-functions")
 #SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
 #SET(CMAKE_C_FLAGS_RELEASE "-O2")
 
-#SET(EXTRA_CXXFLAGS "${EXTRA_CXXFLAGS} -finstrument-functions -std=c++0x")
-SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CXXFLAGS}")
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CXXFLAGS} -finstrument-functions -std=c++0x")
 #SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")
 #SET(CMAKE_CXX_FLAGS_RELEASE "-O2")
 
@@ -81,14 +87,8 @@ SET(EXPORT_HEADER
 #      include/
 )
 
-
-CONFIGURE_FILE(
-     ${CMAKE_CURRENT_SOURCE_DIR}/${LIB_NAME}.pc.in
-    ${CMAKE_CURRENT_SOURCE_DIR}/${LIB_NAME}.pc
-    @ONLY
-)
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${LIB_NAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
 INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR})
 FOREACH(hfile ${EXPORT_HEADER})
-        INSTALL(FILES ${hfile} DESTINATION include/${LIB_NAME})
+       INSTALL(FILES ${hfile} DESTINATION include/${LIB_NAME})
 ENDFOREACH(hfile)
index cb69384..9639c43 100644 (file)
 #include <stdlib.h>
 #include <unistd.h>
 #include <string.h>
+#ifdef USE_GDBUS
+#include <glib.h>
+#endif
 
 /* SLP library header */
 
 /* local header */
 #include "Debug.h"
-#include "Message.h"
-#include "ClientIPC.h"
 #include "ClientChannel.h"
 #include "ReaderHelper.h"
 #include "APDUHelper.h"
+#ifdef USE_GDBUS
+#include "ClientGDBus.h"
+#else
+#include "Message.h"
+#include "ClientIPC.h"
+#endif
 
 #ifndef EXTERN_API
 #define EXTERN_API __attribute__((visibility("default")))
@@ -36,7 +43,7 @@
 namespace smartcard_service_api
 {
        ClientChannel::ClientChannel(void *context, Session *session,
-               int channelNum, ByteArray selectResponse, void *handle)
+               int channelNum, const ByteArray &selectResponse, void *handle)
                : Channel(session)
        {
                this->channelNum = -1;
@@ -45,7 +52,7 @@ namespace smartcard_service_api
 
                if (handle == NULL)
                {
-                       SCARD_DEBUG_ERR("ClientIPC::getInstance() failed");
+                       _ERR("ClientIPC::getInstance() failed");
 
                        return;
                }
@@ -54,6 +61,30 @@ namespace smartcard_service_api
                this->handle = handle;
                this->selectResponse = selectResponse;
                this->context = context;
+#ifdef USE_GDBUS
+               /* initialize client */
+               if (!g_thread_supported())
+               {
+                       g_thread_init(NULL);
+               }
+
+               g_type_init();
+
+               /* init default context */
+               GError *error = NULL;
+
+               proxy = smartcard_service_channel_proxy_new_for_bus_sync(
+                       G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE,
+                       "org.tizen.SmartcardService",
+                       "/org/tizen/SmartcardService/Channel",
+                       NULL, &error);
+               if (proxy == NULL)
+               {
+                       _ERR("Can not create proxy : %s", error->message);
+                       g_error_free(error);
+                       return;
+               }
+#endif
        }
 
        ClientChannel::~ClientChannel()
@@ -61,18 +92,128 @@ namespace smartcard_service_api
                closeSync();
        }
 
+#ifdef USE_GDBUS
+       void ClientChannel::channel_transmit_cb(GObject *source_object,
+               GAsyncResult *res, gpointer user_data)
+       {
+               CallbackParam *param = (CallbackParam *)user_data;
+               transmitCallback callback;
+               gint result;
+               GVariant *var_response;
+               GError *error = NULL;
+               ByteArray response;
+
+               _INFO("MSG_REQUEST_TRANSMIT");
+
+               if (param == NULL) {
+                       _ERR("null parameter!!!");
+                       return;
+               }
+
+               callback = (transmitCallback)param->callback;
+
+               if (smartcard_service_channel_call_transmit_finish(
+                       SMARTCARD_SERVICE_CHANNEL(source_object),
+                       &result, &var_response, res, &error) == true) {
+                       if (result == SCARD_ERROR_OK) {
+                               GDBusHelper::convertVariantToByteArray(var_response, response);
+                       } else {
+                               _ERR("smartcard_service_channel_call_transmit failed, [%d]", result);
+                       }
+               } else {
+                       _ERR("smartcard_service_channel_call_transmit failed, [%s]", error->message);
+                       g_error_free(error);
+
+                       result = SCARD_ERROR_IPC_FAILED;
+               }
+
+               if (callback != NULL) {
+                       callback(response.getBuffer(),
+                               response.size(),
+                               result, param->user_param);
+               }
+
+               delete param;
+       }
+
+       void ClientChannel::channel_close_cb(GObject *source_object,
+               GAsyncResult *res, gpointer user_data)
+       {
+               CallbackParam *param = (CallbackParam *)user_data;
+               ClientChannel *channel;
+               closeChannelCallback callback;
+               gint result;
+               GError *error = NULL;
+
+               _INFO("MSG_REQUEST_CLOSE_CHANNEL");
+
+               if (param == NULL) {
+                       _ERR("null parameter!!!");
+                       return;
+               }
+
+               channel = (ClientChannel *)param->instance;
+               callback = (closeChannelCallback)param->callback;
+
+               if (smartcard_service_channel_call_close_channel_finish(
+                       SMARTCARD_SERVICE_CHANNEL(source_object),
+                       &result, res, &error) == true) {
+                       if (result == SCARD_ERROR_OK) {
+                               channel->channelNum = -1;
+                       } else {
+                               _ERR("smartcard_service_channel_call_close_channel failed, [%d]", result);
+                       }
+               } else {
+                       _ERR("smartcard_service_channel_call_close_channel failed, [%s]", error->message);
+                       g_error_free(error);
+
+                       result = SCARD_ERROR_IPC_FAILED;
+               }
+
+               if (callback != NULL) {
+                       callback(result, param->user_param);
+               }
+
+               delete param;
+       }
+#endif
        void ClientChannel::closeSync()
                throw(ExceptionBase &, ErrorIO &, ErrorSecurity &,
                        ErrorIllegalState &, ErrorIllegalParameter &)
        {
-#ifdef CLIENT_IPC_THREAD
                if (isClosed() == false)
                {
                        if (getSession()->getReader()->isSecureElementPresent() == true)
                        {
+#ifdef USE_GDBUS
+                               gint ret;
+                               GError *error = NULL;
+
+                               if (proxy == NULL) {
+                                       _ERR("dbus proxy is not initialized yet");
+                                       throw ErrorIllegalState(SCARD_ERROR_NOT_INITIALIZED);
+                               }
+
+                               if (smartcard_service_channel_call_close_channel_sync(
+                                       (SmartcardServiceChannel *)proxy,
+                                       GPOINTER_TO_UINT(context),
+                                       GPOINTER_TO_UINT(handle),
+                                       &ret, NULL, &error) == true) {
+                                       if (ret != SCARD_ERROR_OK) {
+                                               _ERR("smartcard_service_channel_call_close_channel_sync failed, [%d]", ret);
+                                               THROW_ERROR(ret);
+                                       }
+                               } else {
+                                       _ERR("smartcard_service_channel_call_close_channel_sync failed, [%s]", error->message);
+                                       g_error_free(error);
+
+                                       throw ErrorIO(SCARD_ERROR_IPC_FAILED);
+                               }
+#else
                                Message msg;
                                int rv;
 
+#ifdef CLIENT_IPC_THREAD
                                /* send message to server */
                                msg.message = Message::MSG_REQUEST_CLOSE_CHANNEL;
                                msg.param1 = (unsigned long)handle;
@@ -81,18 +222,18 @@ namespace smartcard_service_api
                                msg.callback = (void *)this; /* if callback is class instance, it means synchronized call */
 
                                syncLock();
-                               if (ClientIPC::getInstance().sendMessage(&msg) == true)
+                               if (ClientIPC::getInstance().sendMessage(msg) == true)
                                {
                                        rv = waitTimedCondition(0);
                                        if (rv < 0)
                                        {
-                                               SCARD_DEBUG_ERR("closeSync failed [%d]", rv);
+                                               _ERR("timeout [%d]", rv);
                                                this->error = SCARD_ERROR_OPERATION_TIMEOUT;
                                        }
                                }
                                else
                                {
-                                       SCARD_DEBUG_ERR("sendMessage failed");
+                                       _ERR("sendMessage failed");
                                        this->error = SCARD_ERROR_IPC_FAILED;
                                }
                                syncUnlock();
@@ -103,17 +244,17 @@ namespace smartcard_service_api
                                {
                                        ThrowError::throwError(this->error);
                                }
+#endif
+#endif
                        }
                        else
                        {
-                               /* FIXME */
-                               SCARD_DEBUG("unavailable channel");
+                               _INFO("unavailable channel");
                        }
                }
-#endif
        }
 
-       int ClientChannel::close(closeCallback callback, void *userParam)
+       int ClientChannel::close(closeChannelCallback callback, void *userParam)
        {
                int result = SCARD_ERROR_OK;
 
@@ -121,6 +262,19 @@ namespace smartcard_service_api
                {
                        if (getSession()->getReader()->isSecureElementPresent() == true)
                        {
+#ifdef USE_GDBUS
+                               CallbackParam *param = new CallbackParam();
+
+                               param->instance = this;
+                               param->callback = (void *)callback;
+                               param->user_param = userParam;
+
+                               smartcard_service_channel_call_close_channel(
+                                       (SmartcardServiceChannel *)proxy,
+                                       GPOINTER_TO_UINT(context),
+                                       GPOINTER_TO_UINT(handle), NULL,
+                                       &ClientChannel::channel_close_cb, param);
+#else
                                Message msg;
                                channelNum = -1;
 
@@ -132,14 +286,16 @@ namespace smartcard_service_api
                                msg.callback = (void *)callback;
                                msg.userParam = userParam;
 
-                               if (ClientIPC::getInstance().sendMessage(&msg) == false)
+                               if (ClientIPC::getInstance().sendMessage(msg) == false)
                                {
+                                       _ERR("sendMessage failed");
                                        result = SCARD_ERROR_IPC_FAILED;
                                }
+#endif
                        }
                        else
                        {
-                               SCARD_DEBUG_ERR("unavailable channel");
+                               _ERR("unavailable channel");
                                result = SCARD_ERROR_ILLEGAL_STATE;
                        }
                }
@@ -147,15 +303,41 @@ namespace smartcard_service_api
                return result;
        }
 
-       int ClientChannel::transmitSync(ByteArray command, ByteArray &result)
+       int ClientChannel::transmitSync(const ByteArray &command, ByteArray &result)
                throw(ExceptionBase &, ErrorIO &, ErrorIllegalState &,
                        ErrorIllegalParameter &, ErrorSecurity &)
        {
                int rv = SCARD_ERROR_OK;
+
                if (getSession()->getReader()->isSecureElementPresent() == true)
                {
-                       Message msg;
+#ifdef USE_GDBUS
+                       GVariant *var_command = NULL, *var_response = NULL;
+                       GError *error = NULL;
+
+                       var_command = GDBusHelper::convertByteArrayToVariant(command);
+
+                       if (smartcard_service_channel_call_transmit_sync(
+                               (SmartcardServiceChannel *)proxy,
+                               GPOINTER_TO_UINT(context),
+                               GPOINTER_TO_UINT(handle),
+                               var_command, &rv, &var_response,
+                               NULL, &error) == true) {
+
+                               if (rv == SCARD_ERROR_OK) {
+                                       GDBusHelper::convertVariantToByteArray(var_response, result);
+                               } else {
+                                       _ERR("smartcard_service_session_call_get_atr_sync failed, [%d]", rv);
+                                       THROW_ERROR(rv);
+                               }
+                       } else {
+                               _ERR("smartcard_service_session_call_get_atr_sync failed, [%s]", error->message);
+                               g_error_free(error);
 
+                               throw ErrorIO(SCARD_ERROR_IPC_FAILED);
+                       }
+#else
+                       Message msg;
 #ifdef CLIENT_IPC_THREAD
                        /* send message to server */
                        msg.message = Message::MSG_REQUEST_TRANSMIT;
@@ -167,25 +349,23 @@ namespace smartcard_service_api
                        msg.callback = (void *)this; /* if callback is class instance, it means synchronized call */
 
                        syncLock();
-                       if (ClientIPC::getInstance().sendMessage(&msg) == true)
+                       if (ClientIPC::getInstance().sendMessage(msg) == true)
                        {
                                rv = waitTimedCondition(0);
                                if (rv >= 0)
                                {
                                        result = response;
-
                                        rv = SCARD_ERROR_OK;
                                }
                                else
                                {
-                                       SCARD_DEBUG_ERR("timeout");
-
+                                       _ERR("timeout [%d]", rv);
                                        this->error = SCARD_ERROR_OPERATION_TIMEOUT;
                                }
                        }
                        else
                        {
-                               SCARD_DEBUG_ERR("sendMessage failed");
+                               _ERR("sendMessage failed");
                        }
                        syncUnlock();
 
@@ -194,22 +374,42 @@ namespace smartcard_service_api
                                ThrowError::throwError(this->error);
                        }
 #endif
+#endif
                }
                else
                {
-                       SCARD_DEBUG_ERR("unavailable channel");
+                       _ERR("unavailable channel");
                        throw ErrorIllegalState(SCARD_ERROR_UNAVAILABLE);
                }
 
                return rv;
        }
 
-       int ClientChannel::transmit(ByteArray command, transmitCallback callback, void *userParam)
+       int ClientChannel::transmit(const ByteArray &command, transmitCallback callback, void *userParam)
        {
                int result;
 
                if (getSession()->getReader()->isSecureElementPresent() == true)
                {
+#ifdef USE_GDBUS
+                       GVariant *var_command;
+                       CallbackParam *param = new CallbackParam();
+
+                       param->instance = this;
+                       param->callback = (void *)callback;
+                       param->user_param = userParam;
+
+                       var_command = GDBusHelper::convertByteArrayToVariant(command);
+
+                       smartcard_service_channel_call_transmit(
+                               (SmartcardServiceChannel *)proxy,
+                               GPOINTER_TO_UINT(context),
+                               GPOINTER_TO_UINT(handle),
+                               var_command, NULL,
+                               &ClientChannel::channel_transmit_cb, param);
+
+                       result = SCARD_ERROR_OK;
+#else
                        Message msg;
 
                        /* send message to server */
@@ -222,24 +422,27 @@ namespace smartcard_service_api
                        msg.callback = (void *)callback;
                        msg.userParam = userParam;
 
-                       if (ClientIPC::getInstance().sendMessage(&msg) == true)
+                       if (ClientIPC::getInstance().sendMessage(msg) == true)
                        {
                                result = SCARD_ERROR_OK;
                        }
                        else
                        {
+                               _ERR("sendMessage failed");
                                result = SCARD_ERROR_IPC_FAILED;
                        }
+#endif
                }
                else
                {
-                       SCARD_DEBUG_ERR("unavailable channel");
+                       _ERR("unavailable channel");
                        result = SCARD_ERROR_ILLEGAL_STATE;
                }
 
                return result;
        }
 
+#ifndef USE_GDBUS
        bool ClientChannel::dispatcherCallback(void *message)
        {
                Message *msg = (Message *)message;
@@ -248,7 +451,7 @@ namespace smartcard_service_api
 
                if (msg == NULL)
                {
-                       SCARD_DEBUG_ERR("message is null");
+                       _ERR("message is null");
                        return result;
                }
 
@@ -259,15 +462,7 @@ namespace smartcard_service_api
                case Message::MSG_REQUEST_TRANSMIT :
                        {
                                /* transmit result */
-                               SCARD_DEBUG("MSG_REQUEST_TRANSMIT");
-
-                               if (msg->error == 0 &&
-                                       ResponseHelper::getStatus(msg->data) == 0)
-                               {
-                                       /* store select response */
-                                       if (msg->data.getAt(1) == APDUCommand::INS_SELECT_FILE)
-                                               channel->setSelectResponse(msg->data);
-                               }
+                               _INFO("MSG_REQUEST_TRANSMIT");
 
                                if (msg->isSynchronousCall() == true) /* synchronized call */
                                {
@@ -286,14 +481,17 @@ namespace smartcard_service_api
                                        transmitCallback cb = (transmitCallback)msg->callback;
 
                                        /* async call */
-                                       cb(msg->data.getBuffer(), msg->data.getLength(), msg->error, msg->userParam);
+                                       cb(msg->data.getBuffer(),
+                                               msg->data.size(),
+                                               msg->error,
+                                               msg->userParam);
                                }
                        }
                        break;
 
                case Message::MSG_REQUEST_CLOSE_CHANNEL :
                        {
-                               SCARD_DEBUG("MSG_REQUEST_CLOSE_CHANNEL");
+                               _INFO("MSG_REQUEST_CLOSE_CHANNEL");
 
                                if (msg->isSynchronousCall() == true) /* synchronized call */
                                {
@@ -307,7 +505,7 @@ namespace smartcard_service_api
                                }
                                else if (msg->callback != NULL)
                                {
-                                       closeCallback cb = (closeCallback)msg->callback;
+                                       closeChannelCallback cb = (closeChannelCallback)msg->callback;
 
                                        /* async call */
                                        cb(msg->error, msg->userParam);
@@ -316,12 +514,15 @@ namespace smartcard_service_api
                        break;
 
                default:
-                       SCARD_DEBUG("unknwon message : %s", msg->toString());
+                       _DBG("Unknown message : %s", msg->toString().c_str());
                        break;
                }
 
+               delete msg;
+
                return result;
        }
+#endif /* USE_GDBUS */
 } /* namespace smartcard_service_api */
 
 /* export C API */
@@ -334,7 +535,7 @@ namespace smartcard_service_api
        } \
        else \
        { \
-               SCARD_DEBUG_ERR("Invalid param"); \
+               _ERR("Invalid param"); \
        }
 
 using namespace smartcard_service_api;
@@ -344,7 +545,7 @@ EXTERN_API int channel_close(channel_h handle, channel_close_cb callback, void *
        int result = -1;
 
        CHANNEL_EXTERN_BEGIN;
-       result = channel->close((closeCallback)callback, userParam);
+       result = channel->close((closeChannelCallback)callback, userParam);
        CHANNEL_EXTERN_END;
 
        return result;
@@ -358,7 +559,7 @@ EXTERN_API int channel_transmit(channel_h handle, unsigned char *command,
        CHANNEL_EXTERN_BEGIN;
        ByteArray temp;
 
-       temp.setBuffer(command, length);
+       temp.assign(command, length);
        result = channel->transmit(temp, (transmitCallback)callback, userParam);
        CHANNEL_EXTERN_END;
 
@@ -392,14 +593,14 @@ EXTERN_API int channel_transmit_sync(channel_h handle, unsigned char *command,
        CHANNEL_EXTERN_BEGIN;
        ByteArray temp, resp;
 
-       temp.setBuffer(command, cmd_len);
+       temp.assign(command, cmd_len);
 
        try
        {
                result = channel->transmitSync(temp, resp);
-               if (resp.getLength() > 0)
+               if (resp.size() > 0)
                {
-                       *resp_len = resp.getLength();
+                       *resp_len = resp.size();
                        *response = (unsigned char *)calloc(1, *resp_len);
                        memcpy(*response, resp.getBuffer(), *resp_len);
                }
@@ -441,7 +642,7 @@ EXTERN_API unsigned int channel_get_select_response_length(channel_h handle)
        unsigned int result = 0;
 
        CHANNEL_EXTERN_BEGIN;
-       result = channel->getSelectResponse().getLength();
+       result = channel->getSelectResponse().size();
        CHANNEL_EXTERN_END;
 
        return result;
@@ -461,9 +662,9 @@ EXTERN_API bool channel_get_select_response(channel_h handle,
        ByteArray response;
 
        response = channel->getSelectResponse();
-       if (response.getLength() > 0)
+       if (response.size() > 0)
        {
-               memcpy(buffer, response.getBuffer(), MIN(length, response.getLength()));
+               memcpy(buffer, response.getBuffer(), MIN(length, response.size()));
                result = true;
        }
        CHANNEL_EXTERN_END;
index 158689e..4af04ba 100644 (file)
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 
+#ifndef USE_GDBUS
 /* standard library header */
 #include <glib.h>
 
@@ -45,48 +46,48 @@ namespace smartcard_service_api
                return clientDispatcher;
        }
 
-       bool ClientDispatcher::addSEService(void *context, SEService *service)
+       bool ClientDispatcher::addSEService(unsigned int handle, SEService *service)
        {
                bool result = true;
-               map<void *, SEService *>::iterator item;
+               map<unsigned int, SEService *>::iterator item;
 
-               SCARD_BEGIN();
+               _BEGIN();
 
-               if ((item = mapSESerivces.find(context)) == mapSESerivces.end())
+               if ((item = mapSESerivces.find(handle)) == mapSESerivces.end())
                {
-                       mapSESerivces.insert(make_pair(context, service));
+                       mapSESerivces.insert(make_pair(handle, service));
                }
                else
                {
-                       SCARD_DEBUG("SEService [%p] exists", context);
+                       _DBG("SEService [%p] exists", handle);
                }
 
-               SCARD_END();
+               _END();
 
                return result;
        }
 
-       void ClientDispatcher::removeSEService(void *context)
+       void ClientDispatcher::removeSEService(unsigned int handle)
        {
-               map<void *, SEService *>::iterator item;
+               map<unsigned int, SEService *>::iterator item;
 
-               SCARD_BEGIN();
+               _BEGIN();
 
-               if ((item = mapSESerivces.find(context)) != mapSESerivces.end())
+               if ((item = mapSESerivces.find(handle)) != mapSESerivces.end())
                {
                        mapSESerivces.erase(item);
                }
                else
                {
-                       SCARD_DEBUG("SEService doesn't exist");
+                       _DBG("SEService doesn't exist");
                }
 
-               SCARD_END();
+               _END();
        }
 
        void *ClientDispatcher::dispatcherThreadFunc(DispatcherMsg *msg, void *data)
        {
-               SCARD_BEGIN();
+               _BEGIN();
 
                if (msg == NULL)
                        return NULL;
@@ -98,17 +99,17 @@ namespace smartcard_service_api
                case Message::MSG_REQUEST_READERS :
                case Message::MSG_REQUEST_SHUTDOWN :
                        {
+                               DispatcherMsg *tempMsg = new DispatcherMsg(*msg);
+
                                if (msg->isSynchronousCall() == false)
                                {
-                                       DispatcherMsg *tempMsg = new DispatcherMsg(msg);
-
                                        /* Asynchronous call */
                                        g_idle_add((GSourceFunc)&SEService::dispatcherCallback, (gpointer)tempMsg);
                                }
                                else
                                {
                                        /* Synchronous call */
-                                       SEService::dispatcherCallback(msg);
+                                       SEService::dispatcherCallback(tempMsg);
                                }
                        }
                        break;
@@ -116,17 +117,17 @@ namespace smartcard_service_api
                /* Reader requests */
                case Message::MSG_REQUEST_OPEN_SESSION :
                        {
+                               DispatcherMsg *tempMsg = new DispatcherMsg(*msg);
+
                                if (msg->isSynchronousCall() == false)
                                {
-                                       DispatcherMsg *tempMsg = new DispatcherMsg(msg);
-
                                        /* Asynchronous call */
                                        g_idle_add((GSourceFunc)&Reader::dispatcherCallback, (gpointer)tempMsg);
                                }
                                else
                                {
                                        /* Synchronous call */
-                                       Reader::dispatcherCallback(msg);
+                                       Reader::dispatcherCallback(tempMsg);
                                }
                        }
                        break;
@@ -137,17 +138,17 @@ namespace smartcard_service_api
                case Message::MSG_REQUEST_CLOSE_SESSION :
                case Message::MSG_REQUEST_GET_CHANNEL_COUNT :
                        {
+                               DispatcherMsg *tempMsg = new DispatcherMsg(*msg);
+
                                if (msg->isSynchronousCall() == false)
                                {
-                                       DispatcherMsg *tempMsg = new DispatcherMsg(msg);
-
                                        /* Asynchronous call */
                                        g_idle_add((GSourceFunc)&Session::dispatcherCallback, (gpointer)tempMsg);
                                }
                                else
                                {
                                        /* Synchronous call */
-                                       Session::dispatcherCallback(msg);
+                                       Session::dispatcherCallback(tempMsg);
                                }
                        }
                        break;
@@ -156,17 +157,17 @@ namespace smartcard_service_api
                case Message::MSG_REQUEST_TRANSMIT :
                case Message::MSG_REQUEST_CLOSE_CHANNEL :
                        {
+                               DispatcherMsg *tempMsg = new DispatcherMsg(*msg);
+
                                if (msg->isSynchronousCall() == false)
                                {
-                                       DispatcherMsg *tempMsg = new DispatcherMsg(msg);
-
                                        /* Asynchronous call */
                                        g_idle_add((GSourceFunc)&ClientChannel::dispatcherCallback, (gpointer)tempMsg);
                                }
                                else
                                {
                                        /* Synchronous call */
-                                       ClientChannel::dispatcherCallback(msg);
+                                       ClientChannel::dispatcherCallback(tempMsg);
                                }
                        }
                        break;
@@ -174,11 +175,11 @@ namespace smartcard_service_api
                case Message::MSG_NOTIFY_SE_INSERTED :
                case Message::MSG_NOTIFY_SE_REMOVED :
                        {
-                               map<void *, SEService *>::iterator item;
+                               map<unsigned int, SEService *>::iterator item;
 
                                for (item = mapSESerivces.begin(); item != mapSESerivces.end(); item++)
                                {
-                                       DispatcherMsg *tempMsg = new DispatcherMsg(msg);
+                                       DispatcherMsg *tempMsg = new DispatcherMsg(*msg);
 
                                        tempMsg->caller = item->second;
 
@@ -190,11 +191,11 @@ namespace smartcard_service_api
 
                case Message::MSG_OPERATION_RELEASE_CLIENT :
                        {
-                               map<void *, SEService *>::iterator item;
+                               map<unsigned int, SEService *>::iterator item;
 
                                for (item = mapSESerivces.begin(); item != mapSESerivces.end(); item++)
                                {
-                                       DispatcherMsg *tempMsg = new DispatcherMsg(msg);
+                                       DispatcherMsg *tempMsg = new DispatcherMsg(*msg);
 
                                        tempMsg->caller = item->second;
                                        tempMsg->error = -1;
@@ -209,10 +210,10 @@ namespace smartcard_service_api
                        break;
                }
 
-               SCARD_END();
+               _END();
 
                return NULL;
        }
 
 } /* namespace open_mobile_api */
-
+#endif /* USE_GDBUS */
similarity index 84%
rename from common/SEServiceHelper.cpp
rename to client/ClientGDBus.cpp
index 85ce608..799917f 100644 (file)
  * limitations under the License.
  */
 
+#ifdef USE_GDBUS
 /* standard library header */
-#include <stdio.h>
+#include <glib.h>
 
 /* SLP library header */
 
 /* local header */
+#include "smartcard-types.h"
 #include "Debug.h"
-#include "SEServiceHelper.h"
+#include "ByteArray.h"
+#include "ClientGDBus.h"
+
+using namespace std;
 
 namespace smartcard_service_api
 {
-       SEServiceHelper::~SEServiceHelper()
-       {
-               SCARD_BEGIN();
-               SCARD_END();
-       }
-
 } /* namespace smartcard_service_api */
+#endif
index b4de978..5239ff9 100644 (file)
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 
+#ifndef USE_GDBUS
 /* standard library header */
 #include <sys/socket.h>
 #include <unistd.h>
@@ -30,7 +31,7 @@
 
 namespace smartcard_service_api
 {
-       ClientIPC::ClientIPC():IPCHelper()
+       ClientIPC::ClientIPC() : IPCHelper()
        {
 #ifdef USE_AUTOSTART
                _launch_daemon();
@@ -47,16 +48,16 @@ namespace smartcard_service_api
                        {
                                int error;
 
-                               if ((error = security_server_request_cookie(buffer, length))
+                               if ((error = security_server_request_cookie((char *)buffer, length))
                                        == SECURITY_SERVER_API_SUCCESS)
                                {
-                                       cookie.setBuffer(buffer, length);
+                                       cookie.assign(buffer, length);
 
-                                       SCARD_DEBUG("cookie : %s", cookie.toString());
+                                       _DBG("cookie : %s", cookie.toString().c_str());
                                }
                                else
                                {
-                                       SCARD_DEBUG_ERR("security_server_request_cookie failed [%d]", error);
+                                       _ERR("security_server_request_cookie failed [%d]", error);
                                }
 
                                delete []buffer;
@@ -64,7 +65,7 @@ namespace smartcard_service_api
                }
                else
                {
-                       SCARD_DEBUG_ERR("security_server_get_cookie_size failed");
+                       _ERR("security_server_get_cookie_size failed");
                }
 #endif
        }
@@ -86,7 +87,7 @@ namespace smartcard_service_api
                DBusGConnection *connection;
                GError *error = NULL;
 
-               SCARD_BEGIN();
+               _BEGIN();
 
                dbus_g_thread_init();
 
@@ -106,30 +107,30 @@ namespace smartcard_service_api
                                if (dbus_g_proxy_call(proxy, "launch", &error, G_TYPE_INVALID,
                                        G_TYPE_INT, &result, G_TYPE_INVALID) == false)
                                {
-                                       SCARD_DEBUG_ERR("org_tizen_smartcard_service_launch failed");
+                                       _ERR("org_tizen_smartcard_service_launch failed");
                                        if (error != NULL)
                                        {
-                                               SCARD_DEBUG_ERR("message : [%s]", error->message);
+                                               _ERR("message : [%s]", error->message);
                                                g_error_free(error);
                                        }
                                }
                        }
                        else
                        {
-                               SCARD_DEBUG_ERR("ERROR: Can't make dbus proxy");
+                               _ERR("ERROR: Can't make dbus proxy");
                        }
                }
                else
                {
-                       SCARD_DEBUG_ERR("ERROR: Can't get on system bus [%s]", error->message);
+                       _ERR("ERROR: Can't get on system bus [%s]", error->message);
                        g_error_free(error);
                }
 
-               SCARD_END();
+               _END();
        }
 #endif
 
-       bool ClientIPC::sendMessage(Message *msg)
+       bool ClientIPC::sendMessage(const Message &msg)
        {
                ByteArray stream;
                unsigned int length;
@@ -138,21 +139,21 @@ namespace smartcard_service_api
                        return false;
 
 #ifdef SECURITY_SERVER
-               stream = cookie + msg->serialize();
+               stream = cookie + msg.serialize();
 #else
-               stream = msg->serialize();
+               stream = msg.serialize();
 #endif
-               length = stream.getLength();
+               length = stream.size();
 
-               SCARD_DEBUG(">>>[SEND]>>> socket [%d], msg [%d], length [%d]",
-                       ipcSocket, msg->message, stream.getLength());
+               _DBG(">>>[SEND]>>> socket [%d], msg [%d], length [%d]",
+                       ipcSocket, msg.message, stream.size());
 
                return IPCHelper::sendMessage(ipcSocket, stream);
        }
 
        int ClientIPC::handleIOErrorCondition(void *channel, GIOCondition condition)
        {
-               SCARD_BEGIN();
+               _BEGIN();
 
                if (dispatcher != NULL)
                {
@@ -169,19 +170,19 @@ namespace smartcard_service_api
 #endif
                }
 
-               SCARD_END();
+               _END();
 
                return FALSE;
        }
 
        int ClientIPC::handleInvalidSocketCondition(void *channel, GIOCondition condition)
        {
-               SCARD_BEGIN();
+               _BEGIN();
 
                /* finalize context */
                destroyConnectSocket();
 
-               SCARD_END();
+               _END();
 
                return FALSE;
        }
@@ -190,7 +191,7 @@ namespace smartcard_service_api
        {
                int result = FALSE;
 
-               SCARD_BEGIN();
+               _BEGIN();
 
 #ifndef CLIENT_IPC_THREAD
                if (channel == ioChannel)
@@ -198,13 +199,13 @@ namespace smartcard_service_api
 #endif
                        Message *msg = NULL;
 
-                       SCARD_DEBUG("message from server to client socket");
+                       _DBG("message from server to client socket");
 
                        /* read message */
                        msg = retrieveMessage();
                        if (msg != NULL)
                        {
-                               DispatcherMsg dispMsg(msg);
+                               DispatcherMsg dispMsg(*msg);
 
                                /* set peer socket */
                                dispMsg.setPeerSocket(ipcSocket);
@@ -234,13 +235,13 @@ namespace smartcard_service_api
                }
                else
                {
-                       SCARD_DEBUG_ERR("Unknown channel event [%p]", channel);
+                       _ERR("Unknown channel event [%p]", channel);
                }
 #endif
 
-               SCARD_END();
+               _END();
 
                return result;
        }
-
 } /* namespace open_mobile_api */
+#endif /* USE_GDBUS */
index 8acb9a7..e218553 100644 (file)
 
 /* local header */
 #include "Debug.h"
-#include "Message.h"
-#include "ClientIPC.h"
 #include "Reader.h"
 #include "Session.h"
+#ifdef USE_GDBUS
+#include "ClientGDBus.h"
+#else
+#include "Message.h"
+#include "ClientIPC.h"
+#endif
 
 #ifndef EXTERN_API
 #define EXTERN_API __attribute__((visibility("default")))
 
 namespace smartcard_service_api
 {
-       Reader::Reader(void *context, const char *name, void *handle)
-               : ReaderHelper()
+       Reader::Reader(void *context, const char *name, void *handle) :
+               ReaderHelper(name), context(context), handle(handle)
        {
-               unsigned int length = 0;
-
-               SCARD_BEGIN();
+               _BEGIN();
 
-               this->context = NULL;
-               this->handle = NULL;
-
-               if (context == NULL || name == NULL || strlen(name) == 0 || handle == NULL)
+               if (context == NULL || handle == NULL)
                {
-                       SCARD_DEBUG_ERR("invalid param");
+                       _ERR("invalid param");
 
                        return;
                }
+#ifdef USE_GDBUS
+               /* initialize client */
+               if (!g_thread_supported())
+               {
+                       g_thread_init(NULL);
+               }
 
-               this->handle = handle;
-               this->context = context;
+               g_type_init();
 
-               length = strlen(name);
-               length = (length < sizeof(this->name)) ? length : sizeof(this->name);
-               memcpy(this->name, name, length);
+               /* init default context */
+               GError *error = NULL;
 
+               proxy = smartcard_service_reader_proxy_new_for_bus_sync(
+                       G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE,
+                       "org.tizen.SmartcardService",
+                       "/org/tizen/SmartcardService/Reader",
+                       NULL, &error);
+               if (proxy == NULL)
+               {
+                       _ERR("Can not create proxy : %s", error->message);
+                       g_error_free(error);
+                       return;
+               }
+#endif
                present = true;
 
-               SCARD_END();
+               _END();
        }
 
        Reader::~Reader()
@@ -92,13 +107,47 @@ namespace smartcard_service_api
                throw(ExceptionBase &, ErrorIO &, ErrorIllegalState &,
                        ErrorIllegalParameter &, ErrorSecurity &)
        {
-               openedSession = NULL;
+               Session *session = NULL;
 
                if (isSecureElementPresent() == true)
                {
+#ifdef USE_GDBUS
+                       gint result;
+                       GError *error = NULL;
+                       guint session_id;
+
+                       if (smartcard_service_reader_call_open_session_sync(
+                               (SmartcardServiceReader *)proxy,
+                               GPOINTER_TO_UINT(context),
+                               GPOINTER_TO_UINT(handle),
+                               &result, &session_id, NULL, &error) == true) {
+                               if (result == SCARD_ERROR_OK) {
+                                       /* create new instance of channel */
+                                       session = new Session(context, this,
+                                               GUINT_TO_POINTER(session_id));
+                                       if (session != NULL) {
+                                               sessions.push_back(session);
+                                       } else {
+                                               _ERR("Session creating instance failed");
+
+                                               THROW_ERROR(SCARD_ERROR_OUT_OF_MEMORY);
+                                       }
+                               } else {
+                                       _ERR("smartcard_service_reader_call_open_session_sync failed, [%d]", result);
+
+                                       THROW_ERROR(result);
+                               }
+                       } else {
+                               _ERR("smartcard_service_reader_call_open_session_sync failed, [%s]", error->message);
+                               g_error_free(error);
+
+                               THROW_ERROR(SCARD_ERROR_IPC_FAILED);
+                       }
+#else
                        Message msg;
                        int rv;
 
+                       openedSession = NULL;
 #ifdef CLIENT_IPC_THREAD
                        /* request channel handle from server */
                        msg.message = Message::MSG_REQUEST_OPEN_SESSION;
@@ -108,18 +157,20 @@ namespace smartcard_service_api
                        msg.callback = (void *)this; /* if callback is class instance, it means synchronized call */
 
                        syncLock();
-                       if (ClientIPC::getInstance().sendMessage(&msg) == true)
+                       if (ClientIPC::getInstance().sendMessage(msg) == true)
                        {
                                rv = waitTimedCondition(0);
                                if (rv != 0)
                                {
-                                       SCARD_DEBUG_ERR("time over");
+                                       _ERR("time over");
                                        this->error = SCARD_ERROR_OPERATION_TIMEOUT;
                                }
+
+                               session = openedSession;
                        }
                        else
                        {
-                               SCARD_DEBUG_ERR("sendMessage failed");
+                               _ERR("sendMessage failed");
                                this->error = SCARD_ERROR_IPC_FAILED;
                        }
                        syncUnlock();
@@ -129,24 +180,93 @@ namespace smartcard_service_api
                                ThrowError::throwError(this->error);
                        }
 #endif
+#endif
                }
                else
                {
-                       SCARD_DEBUG_ERR("unavailable reader");
+                       _ERR("unavailable reader");
                        throw ErrorIllegalState(SCARD_ERROR_UNAVAILABLE);
                }
 
-               return (Session *)openedSession;
+               return session;
        }
 
+#ifdef USE_GDBUS
+       void Reader::reader_open_session_cb(GObject *source_object,
+               GAsyncResult *res, gpointer user_data)
+       {
+               CallbackParam *param = (CallbackParam *)user_data;
+               Reader *reader;
+               openSessionCallback callback;
+               Session *session = NULL;
+               gint result;
+               guint handle;
+               GError *error = NULL;
+
+               _INFO("MSG_REQUEST_OPEN_SESSION");
+
+               if (param == NULL) {
+                       _ERR("null parameter!!!");
+                       return;
+               }
+
+               reader = (Reader *)param->instance;
+               callback = (openSessionCallback)param->callback;
+
+               if (smartcard_service_reader_call_open_session_finish(
+                       SMARTCARD_SERVICE_READER(source_object),
+                       &result, &handle, res, &error) == true) {
+                       if (result == SCARD_ERROR_OK) {
+                               /* create new instance of channel */
+                               session = new Session(reader->context, reader,
+                                       GUINT_TO_POINTER(handle));
+                               if (session != NULL) {
+                                       reader->sessions.push_back(session);
+                               } else {
+                                       _ERR("Session creating instance failed");
+
+                                       result = SCARD_ERROR_OUT_OF_MEMORY;
+                               }
+                       } else {
+                               _ERR("smartcard_service_reader_call_open_session failed, [%d]", result);
+                       }
+               } else {
+                       _ERR("smartcard_service_reader_call_open_session failed, [%s]", error->message);
+                       g_error_free(error);
+
+                       result = SCARD_ERROR_IPC_FAILED;
+               }
+
+               if (callback != NULL) {
+                       callback(session, result, param->user_param);
+               }
+
+               delete param;
+       }
+#endif
        int Reader::openSession(openSessionCallback callback, void *userData)
        {
                int result;
 
-               SCARD_BEGIN();
+               _BEGIN();
 
                if (isSecureElementPresent() == true)
                {
+#ifdef USE_GDBUS
+                       CallbackParam *param = new CallbackParam();
+
+                       param->instance = this;
+                       param->callback = (void *)callback;
+                       param->user_param = userData;
+
+                       smartcard_service_reader_call_open_session(
+                               (SmartcardServiceReader *)proxy,
+                               GPOINTER_TO_UINT(context),
+                               GPOINTER_TO_UINT(handle),
+                               NULL, &Reader::reader_open_session_cb, param);
+
+                       result = SCARD_ERROR_OK;
+#else
                        Message msg;
 
                        /* request channel handle from server */
@@ -157,38 +277,40 @@ namespace smartcard_service_api
                        msg.callback = (void *)callback;
                        msg.userParam = userData;
 
-                       if (ClientIPC::getInstance().sendMessage(&msg) == true)
+                       if (ClientIPC::getInstance().sendMessage(msg) == true)
                        {
                                result = SCARD_ERROR_OK;
                        }
                        else
                        {
-                               SCARD_DEBUG_ERR("sendMessage failed");
+                               _ERR("sendMessage failed");
                                result = SCARD_ERROR_IPC_FAILED;
                        }
+#endif
                }
                else
                {
-                       SCARD_DEBUG_ERR("unavailable reader");
+                       _ERR("unavailable reader");
                        result = SCARD_ERROR_ILLEGAL_STATE;
                }
 
-               SCARD_END();
+               _END();
 
                return result;
        }
 
+#ifndef USE_GDBUS
        bool Reader::dispatcherCallback(void *message)
        {
                Message *msg = (Message *)message;
                Reader *reader;
                bool result = false;
 
-               SCARD_BEGIN();
+               _BEGIN();
 
                if (msg == NULL)
                {
-                       SCARD_DEBUG_ERR("message is null");
+                       _ERR("message is null");
                        return result;
                }
 
@@ -200,7 +322,7 @@ namespace smartcard_service_api
                        {
                                Session *session = NULL;
 
-                               SCARD_DEBUG("MSG_REQUEST_OPEN_SESSION");
+                               _INFO("MSG_REQUEST_OPEN_SESSION");
 
                                if (msg->param1 != 0)
                                {
@@ -208,7 +330,7 @@ namespace smartcard_service_api
                                        session = new Session(reader->context, reader, (void *)msg->param1);
                                        if (session == NULL)
                                        {
-                                               SCARD_DEBUG_ERR("Session creating instance failed");
+                                               _ERR("Session creating instance failed");
 
                                                return session;
                                        }
@@ -239,15 +361,17 @@ namespace smartcard_service_api
                        break;
 
                default:
-                       SCARD_DEBUG("unknown [%s]", msg->toString());
+                       _DBG("unknown [%s]", msg->toString().c_str());
                        break;
                }
 
-               SCARD_END();
+               delete msg;
+
+               _END();
 
                return result;
        }
-
+#endif
 } /* namespace smartcard_service_api */
 
 /* export C API */
@@ -260,7 +384,7 @@ namespace smartcard_service_api
        } \
        else \
        { \
-               SCARD_DEBUG_ERR("Invalid param"); \
+               _ERR("Invalid param"); \
        }
 
 using namespace smartcard_service_api;
index f5a29a9..b97d9b9 100644 (file)
 #include <unistd.h>
 #include <string.h>
 #include <glib.h>
+#include <glib-object.h>
 
 /* SLP library header */
 
 /* local header */
 #include "Debug.h"
-#include "ClientIPC.h"
-#include "ClientDispatcher.h"
 #include "SEService.h"
 #include "Reader.h"
+#ifdef USE_GDBUS
+#include "ClientGDBus.h"
+#else
 #include "Message.h"
+#include "ClientIPC.h"
+#include "ClientDispatcher.h"
+#endif
 
 #ifndef EXTERN_API
 #define EXTERN_API __attribute__((visibility("default")))
 
 namespace smartcard_service_api
 {
-       SEService::SEService() :
-               SEServiceHelper()
+       SEService::SEService() : SEServiceHelper(),
+               handle(-1), context(NULL), handler(NULL), listener(NULL)
        {
-               this->context = NULL;
-               this->handler = NULL;
-               this->listener = NULL;
-               connected = false;
+#ifdef USE_GDBUS
+               proxy = NULL;
+#endif
        }
 
        SEService::SEService(void *user_data, serviceConnected handler)
                throw(ErrorIO &, ErrorIllegalParameter &) :
-               SEServiceHelper()
+               SEServiceHelper(), handle(-1),
+               listener(NULL)
        {
-               this->listener = NULL;
-               connected = false;
-
                initialize(user_data, handler);
        }
 
        SEService::SEService(void *user_data, SEServiceListener *listener)
                throw(ErrorIO &, ErrorIllegalParameter &) :
-               SEServiceHelper()
+               SEServiceHelper(), handle(-1),
+               handler(NULL)
        {
-               this->handler = NULL;
-               connected = false;
-
                initialize(user_data, listener);
        }
 
@@ -74,11 +74,11 @@ namespace smartcard_service_api
                }
                catch(ExceptionBase &e)
                {
-                       SCARD_DEBUG_ERR("EXCEPTION : %s", e.what());
+                       _ERR("EXCEPTION : %s", e.what());
                }
                catch(...)
                {
-                       SCARD_DEBUG_ERR("EXCEPTION!!!");
+                       _ERR("EXCEPTION!!!");
                }
 
                for (i = 0; i < readers.size(); i++)
@@ -88,18 +88,142 @@ namespace smartcard_service_api
                readers.clear();
        }
 
-       SEService *SEService::createInstance(void *user_data, SEServiceListener *listener)
+       SEService *SEService::createInstance(void *user_data,
+               SEServiceListener *listener)
                throw(ErrorIO &, ErrorIllegalParameter &)
        {
                return new SEService(user_data, listener);
        }
 
-       SEService *SEService::createInstance(void *user_data, serviceConnected handler)
+       SEService *SEService::createInstance(void *user_data,
+               serviceConnected handler)
                throw(ErrorIO &, ErrorIllegalParameter &)
        {
                return new SEService(user_data, handler);
        }
 
+#ifdef USE_GDBUS
+       void SEService::reader_inserted(GObject *source_object,
+               guint reader_id, gchar *reader_name, gpointer user_data)
+       {
+               Reader *reader = NULL;
+               SEService *service = (SEService *)user_data;
+
+               _INFO("[MSG_NOTIFY_SE_INSERTED]");
+
+               /* add readers */
+               reader = new Reader(service->context,
+                       reader_name, GUINT_TO_POINTER(reader_id));
+               if (reader != NULL)
+               {
+                       service->readers.push_back(reader);
+               }
+               else
+               {
+                       _ERR("alloc failed");
+               }
+
+               if (service->listener != NULL)
+               {
+                       service->listener->eventHandler(service,
+                               reader_name, 1, service->context);
+               }
+               else
+               {
+                       _DBG("listener is null");
+               }
+       }
+
+       void SEService::reader_removed(GObject *source_object,
+               guint reader_id, gchar *reader_name, gpointer user_data)
+       {
+               SEService *service = (SEService *)user_data;
+               size_t i;
+
+               _INFO("[MSG_NOTIFY_SE_REMOVED]");
+
+               for (i = 0; i < service->readers.size(); i++)
+               {
+                       if (((Reader *)service->readers[i])->handle ==
+                               GUINT_TO_POINTER(reader_id))
+                       {
+                               ((Reader *)service->readers[i])->unavailable();
+                               break;
+                       }
+               }
+
+               if (service->listener != NULL)
+               {
+                       service->listener->eventHandler(service,
+                               reader_name, 2, service->context);
+               }
+               else
+               {
+                       _DBG("listener is null");
+               }
+       }
+
+       void SEService::se_service_shutdown_cb(GObject *source_object,
+               GAsyncResult *res, gpointer user_data)
+       {
+               SEService *service = (SEService *)user_data;
+               gint result;
+               GError *error = NULL;
+
+               if (smartcard_service_se_service_call_shutdown_finish(
+                       SMARTCARD_SERVICE_SE_SERVICE(source_object),
+                       &result, res, &error) == true) {
+                       if (result == SCARD_ERROR_OK) {
+                               service->connected = false;
+                       } else {
+                               _ERR("smartcard_service_se_service_call_shutdown failed, [%d]", result);
+                       }
+               } else {
+                       _ERR("smartcard_service_se_service_call_shutdown failed, [%s]", error->message);
+                       g_error_free(error);
+               }
+       }
+
+       void SEService::se_service_cb(GObject *source_object,
+               GAsyncResult *res, gpointer user_data)
+       {
+               SEService *service = (SEService *)user_data;
+               gint result;
+               guint handle;
+               GVariant *readers = NULL;
+               GError *error = NULL;
+
+               if (service == NULL) {
+                       _ERR("null parameter!!!");
+                       return;
+               }
+
+               if (smartcard_service_se_service_call_se_service_finish(
+                       SMARTCARD_SERVICE_SE_SERVICE(source_object),
+                       &result, &handle, &readers, res, &error) == true) {
+                       if (result == SCARD_ERROR_OK) {
+                               service->connected = true;
+                               service->handle = handle;
+                               service->parseReaderInformation(readers);
+                       }
+               } else {
+                       _ERR("smartcard_service_se_service_call_se_service failed, [%s]", error->message);
+                       g_error_free(error);
+
+                       result = SCARD_ERROR_IPC_FAILED;
+               }
+
+               if (service->handler != NULL) {
+                       service->handler(service, service->context);
+               } else if (service->listener != NULL) {
+                       if (result == SCARD_ERROR_OK) {
+                               service->listener->serviceConnected(service, service->context);
+                       } else {
+                               service->listener->errorHandler(service, result, service->context);
+                       }
+               }
+       }
+#endif
        void SEService::shutdown()
        {
                if (connected == true)
@@ -110,24 +234,32 @@ namespace smartcard_service_api
                        {
                                readers[i]->closeSessions();
                        }
-
+#ifdef USE_GDBUS
+                       smartcard_service_se_service_call_shutdown(
+                               (SmartcardServiceSeService *)proxy,
+                               handle,
+                               NULL,
+                               &SEService::se_service_shutdown_cb,
+                               this);
+#else
                        Message msg;
 
                        msg.message = Message::MSG_REQUEST_SHUTDOWN;
+                       msg.param1 = (unsigned long)handle;
                        msg.error = (unsigned long)this; /* using error to context */
                        msg.caller = (void *)this;
                        msg.callback = (void *)NULL;
 
-                       if (ClientIPC::getInstance().sendMessage(&msg) == false)
+                       if (ClientIPC::getInstance().sendMessage(msg) == false)
                        {
-                               SCARD_DEBUG_ERR("time over");
+                               _ERR("time over");
                        }
+#endif
                }
        }
 
        void SEService::shutdownSync()
        {
-#ifdef CLIENT_IPC_THREAD
                if (connected == true)
                {
                        uint32_t i;
@@ -136,49 +268,68 @@ namespace smartcard_service_api
                        {
                                readers[i]->closeSessions();
                        }
+#ifdef USE_GDBUS
+                       gint result;
+                       GError *error = NULL;
+
+                       if (smartcard_service_se_service_call_shutdown_sync(
+                               (SmartcardServiceSeService *)proxy,
+                               handle,
+                               &result,
+                               NULL,
+                               &error) == false) {
+                               _ERR("smartcard_service_se_service_call_shutdown_sync failed, [%s]", error->message);
+
+                               g_error_free(error);
+                       }
 
+                       connected = false;
+#else
+#ifdef CLIENT_IPC_THREAD
                        /* send message to load se */
                        Message msg;
 
                        msg.message = Message::MSG_REQUEST_SHUTDOWN;
+                       msg.param1 = (unsigned long)handle;
                        msg.error = (unsigned long)this; /* using error to context */
                        msg.caller = (void *)this;
                        msg.callback = (void *)this; /* if callback is class instance, it means synchronized call */
 
                        syncLock();
-                       if (ClientIPC::getInstance().sendMessage(&msg) == true)
+                       if (ClientIPC::getInstance().sendMessage(msg) == true)
                        {
                                int rv;
 
                                rv = waitTimedCondition(0);
-
                                if (rv == 0)
                                {
-                                       ClientDispatcher::getInstance().removeSEService(context);
+                                       ClientDispatcher::getInstance().removeSEService(handle);
 
                                        connected = false;
                                }
                                else
                                {
-                                       SCARD_DEBUG_ERR("time over");
+                                       _ERR("time over");
                                }
                        }
                        else
                        {
-                               SCARD_DEBUG_ERR("sendMessage failed");
+                               _ERR("sendMessage failed");
                        }
                        syncUnlock();
-               }
 #endif
+#endif
+               }
        }
 
        bool SEService::_initialize() throw(ErrorIO &)
        {
                bool result = false;
+#ifndef USE_GDBUS
                ClientIPC *clientIPC;
                ClientDispatcher *clientDispatcher;
-
-               SCARD_BEGIN();
+#endif
+               _BEGIN();
 
                /* initialize client */
                if (!g_thread_supported())
@@ -186,6 +337,37 @@ namespace smartcard_service_api
                        g_thread_init(NULL);
                }
 
+               g_type_init();
+
+#ifdef USE_GDBUS
+               /* init default context */
+               GError *error = NULL;
+
+               proxy = smartcard_service_se_service_proxy_new_for_bus_sync(
+                       G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE,
+                       "org.tizen.SmartcardService",
+                       "/org/tizen/SmartcardService/SeService",
+                       NULL, &error);
+               if (proxy == NULL)
+               {
+                       _ERR("Can not create proxy : %s", error->message);
+                       g_error_free(error);
+                       return false;
+               }
+
+               g_signal_connect(proxy, "reader-inserted",
+                               G_CALLBACK(&SEService::reader_inserted), this);
+
+               g_signal_connect(proxy, "reader-removed",
+                               G_CALLBACK(&SEService::reader_removed), this);
+
+               /* request reader */
+               smartcard_service_se_service_call_se_service(
+                       (SmartcardServiceSeService *)proxy,
+                       NULL,
+                       &SEService::se_service_cb,
+                       this);
+#else
                clientDispatcher = &ClientDispatcher::getInstance();
                clientIPC = &ClientIPC::getInstance();
 
@@ -194,7 +376,7 @@ namespace smartcard_service_api
 #ifndef CLIENT_IPC_THREAD
                if (clientDispatcher->runDispatcherThread() == false)
                {
-                       SCARD_DEBUG_ERR("clientDispatcher->runDispatcherThread() failed");
+                       _ERR("clientDispatcher->runDispatcherThread() failed");
 
                        return result;
                }
@@ -202,13 +384,11 @@ namespace smartcard_service_api
 
                if (clientIPC->createConnectSocket() == false)
                {
-                       SCARD_DEBUG_ERR("clientIPC->createConnectSocket() failed");
+                       _ERR("clientIPC->createConnectSocket() failed");
 
                        return result;
                }
 
-               clientDispatcher->addSEService(context, this);
-
                {
                        /* send message to load se */
                        Message msg;
@@ -218,10 +398,10 @@ namespace smartcard_service_api
                        msg.caller = (void *)this;
                        msg.userParam = context;
 
-                       result = clientIPC->sendMessage(&msg);
+                       result = clientIPC->sendMessage(msg);
                }
-
-               SCARD_END();
+#endif
+               _END();
 
                return result;
        }
@@ -254,7 +434,39 @@ namespace smartcard_service_api
                return _initialize();
        }
 
-       bool SEService::parseReaderInformation(unsigned int count, ByteArray data)
+#ifdef USE_GDBUS
+       bool SEService::parseReaderInformation(GVariant *variant)
+       {
+               Reader *reader = NULL;
+
+               GVariantIter *iter;
+               gsize count;
+               guint handle;
+               gchar *name;
+
+               g_variant_get(variant, "a(us)", &iter);
+
+               count = g_variant_iter_n_children(iter);
+               while (g_variant_iter_loop(iter, "(us)", &handle, &name) == true)
+               {
+                       /* add readers */
+                       reader = new Reader((void *)this->handle, name, GUINT_TO_POINTER(handle));
+                       if (reader == NULL)
+                       {
+                               _ERR("alloc failed");
+                               continue;
+                       }
+
+                       readers.push_back(reader);
+               }
+
+               g_variant_iter_free(iter);
+
+               return true;
+       }
+#endif
+       bool SEService::parseReaderInformation(unsigned int count,
+               const ByteArray &data)
        {
                size_t i;
                unsigned int offset = 0;
@@ -263,7 +475,7 @@ namespace smartcard_service_api
                Reader *reader = NULL;
                char name[100];
 
-               for (i = 0; i < count && offset < data.getLength(); i++)
+               for (i = 0; i < count && offset < data.size(); i++)
                {
                        memset(name, 0, sizeof(name));
 
@@ -276,13 +488,11 @@ namespace smartcard_service_api
                        memcpy(&handle, data.getBuffer(offset), sizeof(handle));
                        offset += sizeof(handle);
 
-                       SCARD_DEBUG("Reader [%d] : name [%s], handle [%p]", i, name, handle);
-
                        /* add readers */
                        reader = new Reader(context, name, handle);
                        if (reader == NULL)
                        {
-                               SCARD_DEBUG_ERR("alloc failed");
+                               _ERR("alloc failed");
                                continue;
                        }
 
@@ -292,17 +502,18 @@ namespace smartcard_service_api
                return true;
        }
 
+#ifndef USE_GDBUS
        bool SEService::dispatcherCallback(void *message)
        {
                Message *msg = (Message *)message;
-               SEService *service = NULL;
+               SEService *service;
                bool result = false;
 
-               SCARD_BEGIN();
+               _BEGIN();
 
                if (msg == NULL)
                {
-                       SCARD_DEBUG_ERR("message is null");
+                       _ERR("message is null");
                        return result;
                }
 
@@ -311,9 +522,12 @@ namespace smartcard_service_api
                switch (msg->message)
                {
                case Message::MSG_REQUEST_READERS :
-                       SCARD_DEBUG("[MSG_REQUEST_READERS]");
+                       _INFO("[MSG_REQUEST_READERS]");
 
                        service->connected = true;
+                       service->handle = (unsigned int)msg->param2;
+
+                       ClientDispatcher::getInstance().addSEService(service->handle, service);
 
                        /* parse message data */
                        service->parseReaderInformation(msg->param1, msg->data);
@@ -330,7 +544,7 @@ namespace smartcard_service_api
                        break;
 
                case Message::MSG_REQUEST_SHUTDOWN :
-                       SCARD_DEBUG("[MSG_REQUEST_SHUTDOWN]");
+                       _INFO("[MSG_REQUEST_SHUTDOWN]");
 
                        if (msg->isSynchronousCall() == true) /* synchronized call */
                        {
@@ -352,7 +566,7 @@ namespace smartcard_service_api
                        {
                                Reader *reader = NULL;
 
-                               SCARD_DEBUG("[MSG_NOTIFY_SE_INSERTED]");
+                               _INFO("[MSG_NOTIFY_SE_INSERTED]");
 
                                /* add readers */
                                reader = new Reader(service->context,
@@ -363,7 +577,7 @@ namespace smartcard_service_api
                                }
                                else
                                {
-                                       SCARD_DEBUG_ERR("alloc failed");
+                                       _ERR("alloc failed");
                                }
 
                                if (service->listener != NULL)
@@ -373,7 +587,7 @@ namespace smartcard_service_api
                                }
                                else
                                {
-                                       SCARD_DEBUG("listener is null");
+                                       _DBG("listener is null");
                                }
                        }
                        break;
@@ -382,7 +596,7 @@ namespace smartcard_service_api
                        {
                                size_t i;
 
-                               SCARD_DEBUG("[MSG_NOTIFY_SE_REMOVED]");
+                               _INFO("[MSG_NOTIFY_SE_REMOVED]");
 
                                for (i = 0; i < service->readers.size(); i++)
                                {
@@ -400,37 +614,39 @@ namespace smartcard_service_api
                                }
                                else
                                {
-                                       SCARD_DEBUG("listener is null");
+                                       _DBG("listener is null");
                                }
                        }
                        break;
 
                case Message::MSG_OPERATION_RELEASE_CLIENT :
-                       SCARD_DEBUG("[MSG_OPERATION_RELEASE_CLIENT]");
+                       _INFO("[MSG_OPERATION_RELEASE_CLIENT]");
 
                        if (service->listener != NULL)
                        {
                                service->listener->errorHandler(service, msg->error, service->context);
 
-                               ClientDispatcher::getInstance().removeSEService(service->context);
+                               ClientDispatcher::getInstance().removeSEService(service->handle);
                                service->connected = false;
                        }
                        else
                        {
-                               SCARD_DEBUG_ERR("service->listener is null");
+                               _ERR("service->listener is null");
                        }
                        break;
 
                default :
-                       SCARD_DEBUG("unknown message [%s]", msg->toString());
+                       _DBG("unknown message [%s]", msg->toString().c_str());
                        break;
                }
 
-               SCARD_END();
+               delete msg;
+
+               _END();
 
                return result;
        }
-
+#endif
 } /* namespace smartcard_service_api */
 
 /* export C API */
@@ -443,7 +659,7 @@ namespace smartcard_service_api
        } \
        else \
        { \
-               SCARD_DEBUG_ERR("Invalid param"); \
+               _ERR("Invalid param"); \
        }
 
 using namespace smartcard_service_api;
index 95f85af..e08abd1 100644 (file)
 #include "Session.h"
 #include "Reader.h"
 #include "ClientChannel.h"
+#ifdef USE_GDBUS
+#include "ClientGDBus.h"
+#else
 #include "ClientIPC.h"
+#endif
 
 #ifndef EXTERN_API
 #define EXTERN_API __attribute__((visibility("default")))
@@ -42,13 +46,38 @@ namespace smartcard_service_api
 
                if (context == NULL || handle == NULL)
                {
-                       SCARD_DEBUG_ERR("handle is null");
+                       _ERR("handle is null");
 
                        return;
                }
 
                this->context = context;
                this->handle = handle;
+
+#ifdef USE_GDBUS
+               /* initialize client */
+               if (!g_thread_supported())
+               {
+                       g_thread_init(NULL);
+               }
+
+               g_type_init();
+
+               /* init default context */
+               GError *error = NULL;
+
+               proxy = smartcard_service_session_proxy_new_for_bus_sync(
+                       G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE,
+                       "org.tizen.SmartcardService",
+                       "/org/tizen/SmartcardService/Session",
+                       NULL, &error);
+               if (proxy == NULL)
+               {
+                       _ERR("Can not create proxy : %s", error->message);
+                       g_error_free(error);
+                       return;
+               }
+#endif
                closed = false;
        }
 
@@ -75,19 +104,192 @@ namespace smartcard_service_api
                        channels[i]->closeSync();
                }
        }
+#ifdef USE_GDBUS
+       void Session::session_get_atr_cb(GObject *source_object,
+               GAsyncResult *res, gpointer user_data)
+       {
+               CallbackParam *param = (CallbackParam *)user_data;
+               Session *session;
+               getATRCallback callback;
+               gint result;
+               GVariant *var_atr;
+               GError *error = NULL;
+               ByteArray atr;
+
+               _INFO("MSG_REQUEST_GET_ATR");
+
+               if (param == NULL) {
+                       _ERR("null parameter!!!");
+                       return;
+               }
+
+               session = (Session *)param->instance;
+               callback = (getATRCallback)param->callback;
+
+               if (smartcard_service_session_call_get_atr_finish(
+                       SMARTCARD_SERVICE_SESSION(source_object),
+                       &result, &var_atr, res, &error) == true) {
+                       if (result == SCARD_ERROR_OK) {
+                               GDBusHelper::convertVariantToByteArray(var_atr, atr);
+
+                               session->atr = atr;
+                       } else {
+                               _ERR("smartcard_service_session_call_get_atr failed, [%d]", result);
+                       }
+               } else {
+                       _ERR("smartcard_service_session_call_get_atr failed, [%s]", error->message);
+                       g_error_free(error);
+
+                       result = SCARD_ERROR_IPC_FAILED;
+               }
+
+               if (callback != NULL) {
+                       callback(atr.getBuffer(),
+                               atr.size(), result, param->user_param);
+               }
+
+               delete param;
+       }
+
+       void Session::session_open_channel_cb(GObject *source_object,
+               GAsyncResult *res, gpointer user_data)
+       {
+               CallbackParam *param = (CallbackParam *)user_data;
+               Session *session;
+               openChannelCallback callback;
+               gint result;
+               guint channel_id;
+               GVariant *var_response;
+               GError *error = NULL;
+               Channel *channel;
+
+               _INFO("MSG_REQUEST_OPEN_CHANNEL");
+
+               if (param == NULL) {
+                       _ERR("null parameter!!!");
+                       return;
+               }
+
+               session = (Session *)param->instance;
+               callback = (openChannelCallback)param->callback;
+
+               if (smartcard_service_session_call_open_channel_finish(
+                       SMARTCARD_SERVICE_SESSION(source_object),
+                       &result, &channel_id, &var_response,
+                       res, &error) == true) {
+                       if (result == SCARD_ERROR_OK) {
+                               ByteArray response;
+
+                               GDBusHelper::convertVariantToByteArray(
+                                       var_response, response);
+
+                               /* create new instance of channel */
+                               channel = new ClientChannel(session->context,
+                                       session, channel_id,
+                                       response, (void *)channel_id);
+                               if (channel != NULL) {
+                                       session->channels.push_back(channel);
+                               } else {
+                                       _ERR("alloc failed");
+
+                                       result = SCARD_ERROR_OUT_OF_MEMORY;
+                               }
+                       } else {
+                               _ERR("smartcard_service_session_call_open_channel failed, [%d]", result);
+                       }
+               } else {
+                       _ERR("smartcard_service_session_call_open_channel failed, [%s]", error->message);
+                       g_error_free(error);
+
+                       result = SCARD_ERROR_IPC_FAILED;
+               }
+
+               if (callback != NULL) {
+                       callback(channel, result, param->user_param);
+               }
+
+               delete param;
+       }
+
+       void Session::session_close_cb(GObject *source_object,
+               GAsyncResult *res, gpointer user_data)
+       {
+               CallbackParam *param = (CallbackParam *)user_data;
+               Session *session;
+               closeSessionCallback callback;
+               gint result;
+               GError *error = NULL;
+
+               _INFO("MSG_REQUEST_CLOSE_SESSION");
+
+               if (param == NULL) {
+                       _ERR("null parameter!!!");
+                       return;
+               }
+
+               session = (Session *)param->instance;
+               callback = (closeSessionCallback)param->callback;
+
+               if (smartcard_service_session_call_close_session_finish(
+                       SMARTCARD_SERVICE_SESSION(source_object),
+                       &result, res, &error) == true) {
+                       if (result == SCARD_ERROR_OK) {
+                               session->closed = true;
+                       } else {
+                               _ERR("smartcard_service_session_call_close_session failed, [%d]", result);
+                       }
+               } else {
+                       _ERR("smartcard_service_session_call_close_session failed, [%s]", error->message);
+                       g_error_free(error);
 
-       ByteArray Session::getATRSync()
+                       result = SCARD_ERROR_IPC_FAILED;
+               }
+
+               if (callback != NULL) {
+                       callback(result, param->user_param);
+               }
+
+               delete param;
+       }
+#endif
+       const ByteArray Session::getATRSync()
                throw (ExceptionBase &, ErrorIO &, ErrorSecurity &,
                        ErrorIllegalState &, ErrorIllegalParameter &)
        {
                ByteArray result;
+
                if (getReader()->isSecureElementPresent() == true)
                {
                        if (atr.isEmpty() == true)
                        {
+#ifdef USE_GDBUS
+                               gint ret;
+                               GVariant *var_atr = NULL;
+                               GError *error = NULL;
+
+                               if (smartcard_service_session_call_get_atr_sync(
+                                       (SmartcardServiceSession *)proxy,
+                                       GPOINTER_TO_UINT(context),
+                                       GPOINTER_TO_UINT(handle),
+                                       &ret, &var_atr, NULL, &error) == true) {
+                                       if (ret == SCARD_ERROR_OK) {
+                                               GDBusHelper::convertVariantToByteArray(var_atr, result);
+
+                                               atr = result;
+                                       } else {
+                                               _ERR("smartcard_service_session_call_get_atr_sync failed, [%d]", ret);
+
+                                               THROW_ERROR(ret);
+                                       }
+                               } else {
+                                       _ERR("smartcard_service_session_call_get_atr_sync failed, [%s]", error->message);
+                                       g_error_free(error);
+
+                                       THROW_ERROR(SCARD_ERROR_IPC_FAILED);
+                               }
+#else
                                Message msg;
                                int rv;
-
 #ifdef CLIENT_IPC_THREAD
                                /* request channel handle from server */
                                msg.message = Message::MSG_REQUEST_GET_ATR;
@@ -97,18 +299,18 @@ namespace smartcard_service_api
                                msg.callback = (void *)this; /* if callback is class instance, it means synchronized call */
 
                                syncLock();
-                               if (ClientIPC::getInstance().sendMessage(&msg) == true)
+                               if (ClientIPC::getInstance().sendMessage(msg) == true)
                                {
                                        rv = waitTimedCondition(0);
                                        if (rv != 0)
                                        {
-                                               SCARD_DEBUG_ERR("time over");
+                                               _ERR("time over");
                                                this->error = SCARD_ERROR_OPERATION_TIMEOUT;
                                        }
                                }
                                else
                                {
-                                       SCARD_DEBUG_ERR("sendMessage failed");
+                                       _ERR("sendMessage failed");
                                        this->error = SCARD_ERROR_IPC_FAILED;
                                }
                                syncUnlock();
@@ -118,13 +320,14 @@ namespace smartcard_service_api
                                        ThrowError::throwError(this->error);
                                }
 #endif
+#endif
                        }
 
                        result = atr;
                }
                else
                {
-                       SCARD_DEBUG_ERR("unavailable session");
+                       _ERR("unavailable session");
                        throw ErrorIllegalState(SCARD_ERROR_UNAVAILABLE);
                }
 
@@ -139,10 +342,24 @@ namespace smartcard_service_api
                {
                        if (atr.isEmpty() == true)
                        {
-                               Message msg;
+#ifdef USE_GDBUS
+                               CallbackParam *param = new CallbackParam();
 
+                               param->instance = this;
+                               param->callback = (void *)callback;
+                               param->user_param = userData;
 
-                       /* request channel handle from server */
+                               smartcard_service_session_call_get_atr(
+                                       (SmartcardServiceSession *)proxy,
+                                       GPOINTER_TO_UINT(context),
+                                       GPOINTER_TO_UINT(handle), NULL,
+                                       &Session::session_get_atr_cb, param);
+
+                               result = SCARD_ERROR_OK;
+#else
+                               Message msg;
+
+                               /* request channel handle from server */
                                msg.message = Message::MSG_REQUEST_GET_ATR;
                                msg.param1 = (unsigned long)handle;
                                msg.error = (unsigned long)context; /* using error to context */
@@ -150,26 +367,29 @@ namespace smartcard_service_api
                                msg.callback = (void *)callback;
                                msg.userParam = userData;
 
-                               if (ClientIPC::getInstance().sendMessage(&msg) == true)
+                               if (ClientIPC::getInstance().sendMessage(msg) == true)
                                {
                                        result = SCARD_ERROR_OK;
                                }
                                else
                                {
+                                       _ERR("sendMessage failed");
                                        result = SCARD_ERROR_IPC_FAILED;
                                }
+#endif
                        }
                        else
                        {
                                result = SCARD_ERROR_OK;
 
                                /* TODO : invoke callback directly */
-                               callback(atr.getBuffer(), atr.getLength(), 0, userData);
+                               callback(atr.getBuffer(),
+                                       atr.size(), 0, userData);
                        }
                }
                else
                {
-                       SCARD_DEBUG_ERR("unavailable session");
+                       _ERR("unavailable session");
                        result = SCARD_ERROR_ILLEGAL_STATE;
                }
 
@@ -180,15 +400,37 @@ namespace smartcard_service_api
                throw (ExceptionBase &, ErrorIO &, ErrorSecurity &,
                        ErrorIllegalState &, ErrorIllegalParameter &)
        {
-               Message msg;
-               int rv;
-
-#ifdef CLIENT_IPC_THREAD
                if (isClosed() == false)
                {
                        closed = true;
                        closeChannels();
+#ifdef USE_GDBUS
+                       gint ret;
+                       GError *error = NULL;
+
+                       if (smartcard_service_session_call_close_session_sync(
+                               (SmartcardServiceSession *)proxy,
+                               GPOINTER_TO_UINT(context),
+                               GPOINTER_TO_UINT(handle),
+                               &ret, NULL, &error) == true) {
+                               if (ret == SCARD_ERROR_OK) {
+                                       closed = true;
+                               } else {
+                                       _ERR("smartcard_service_session_call_close_session_sync failed, [%d]", ret);
+
+                                       THROW_ERROR(ret);
+                               }
+                       } else {
+                               _ERR("smartcard_service_session_call_get_atr_sync failed, [%s]", error->message);
+                               g_error_free(error);
 
+                               THROW_ERROR(SCARD_ERROR_IPC_FAILED);
+                       }
+#else
+                       int rv;
+                       Message msg;
+
+#ifdef CLIENT_IPC_THREAD
                        /* request channel handle from server */
                        msg.message = Message::MSG_REQUEST_CLOSE_SESSION;
                        msg.param1 = (unsigned long)handle;
@@ -197,19 +439,19 @@ namespace smartcard_service_api
                        msg.callback = (void *)this; /* if callback is class instance, it means synchronized call */
 
                        syncLock();
-                       if (ClientIPC::getInstance().sendMessage(&msg) == true)
+                       if (ClientIPC::getInstance().sendMessage(msg) == true)
                        {
                                rv = waitTimedCondition(0);
 
                                if (rv != 0)
                                {
-                                       SCARD_DEBUG_ERR("time over");
+                                       _ERR("time over");
                                        this->error = SCARD_ERROR_OPERATION_TIMEOUT;
                                }
                        }
                        else
                        {
-                               SCARD_DEBUG_ERR("sendMessage failed");
+                               _ERR("sendMessage failed");
                                this->error = SCARD_ERROR_IPC_FAILED;
                        }
                        syncUnlock();
@@ -218,20 +460,33 @@ namespace smartcard_service_api
                        {
                                ThrowError::throwError(this->error);
                        }
-               }
 #endif
+#endif
+               }
        }
 
        int Session::close(closeSessionCallback callback, void *userData)
        {
                int result = SCARD_ERROR_OK;
-               Message msg;
 
                if (isClosed() == false)
                {
                        closed = true;
                        closeChannels();
-
+#ifdef USE_GDBUS
+                       CallbackParam *param = new CallbackParam();
+
+                       param->instance = this;
+                       param->callback = (void *)callback;
+                       param->user_param = userData;
+
+                       smartcard_service_session_call_close_session(
+                               (SmartcardServiceSession *)proxy,
+                               GPOINTER_TO_UINT(context),
+                               GPOINTER_TO_UINT(handle), NULL,
+                               &Session::session_close_cb, param);
+#else
+                       Message msg;
                        /* request channel handle from server */
                        msg.message = Message::MSG_REQUEST_CLOSE_SESSION;
                        msg.param1 = (unsigned long)handle;
@@ -240,109 +495,88 @@ namespace smartcard_service_api
                        msg.callback = (void *)callback;
                        msg.userParam = userData;
 
-                       if (ClientIPC::getInstance().sendMessage(&msg) == false)
+                       if (ClientIPC::getInstance().sendMessage(msg) == false)
                        {
+                               _ERR("sendMessage failed");
                                result = SCARD_ERROR_IPC_FAILED;
                        }
+#endif
                }
 
                return result;
        }
 
-       unsigned int Session::getChannelCountSync()
+       size_t Session::getChannelCount() const
        {
-               channelCount = -1;
+               size_t count = 0;
 
                if (getReader()->isSecureElementPresent() == true)
                {
-                       Message msg;
-                       int rv;
-
-
-#ifdef CLIENT_IPC_THREAD
-                       /* request channel handle from server */
-                       msg.message = Message::MSG_REQUEST_GET_CHANNEL_COUNT;
-                       msg.param1 = (unsigned long)handle;
-                       msg.error = (unsigned long)context; /* using error to context */
-                       msg.caller = (void *)this;
-                       msg.callback = (void *)this; /* if callback is class instance, it means synchronized call */
-
-                       channelCount = -1;
-
-                       syncLock();
-                       if (ClientIPC::getInstance().sendMessage(&msg) == true)
-                       {
-                               rv = waitTimedCondition(0);
-                               if (rv != 0)
-                               {
-                                       SCARD_DEBUG_ERR("time over");
-                                       this->error = SCARD_ERROR_OPERATION_TIMEOUT;
-                               }
-                       }
-                       else
-                       {
-                               SCARD_DEBUG_ERR("sendMessage failed");
-                               this->error = SCARD_ERROR_IPC_FAILED;
-                       }
-                       syncUnlock();
-
-                       if (this->error != SCARD_ERROR_OK)
-                       {
-                               ThrowError::throwError(this->error);
-                       }
-#endif
+                       count = channels.size();
                }
                else
                {
-                       SCARD_DEBUG_ERR("unavailable session");
+                       _ERR("unavailable session");
                        throw ErrorIllegalState(SCARD_ERROR_UNAVAILABLE);
                }
 
-               return channelCount;
+               return count;
        }
 
-       int Session::getChannelCount(getChannelCountCallback callback, void *userData)
+       Channel *Session::openChannelSync(int id, const ByteArray &aid)
+               throw (ExceptionBase &, ErrorIO &, ErrorIllegalState &,
+                       ErrorIllegalParameter &, ErrorSecurity &)
        {
-               int result;
+               Channel *channel = NULL;
 
                if (getReader()->isSecureElementPresent() == true)
                {
-                       Message msg;
-
-
-                       msg.message = Message::MSG_REQUEST_GET_CHANNEL_COUNT;
-                       msg.param1 = (unsigned long)handle;
-                       msg.error = (unsigned long)context; /* using error to context */
-                       msg.caller = (void *)this;
-                       msg.callback = (void *)callback;
-                       msg.userParam = userData;
+#ifdef USE_GDBUS
+                       gint ret;
+                       GVariant *var_aid = NULL, *var_response = NULL;
+                       guint channel_id;
+                       GError *error = NULL;
+
+                       var_aid = GDBusHelper::convertByteArrayToVariant(aid);
+
+                       if (smartcard_service_session_call_open_channel_sync(
+                               (SmartcardServiceSession *)proxy,
+                               GPOINTER_TO_UINT(context),
+                               GPOINTER_TO_UINT(handle),
+                               (guint)id, var_aid, &ret, &channel_id,
+                               &var_response, NULL, &error) == true) {
+                               if (ret == SCARD_ERROR_OK && channel_id != 0) {
+                                       ByteArray response;
+
+                                       GDBusHelper::convertVariantToByteArray(
+                                               var_response, response);
 
-                       if (ClientIPC::getInstance().sendMessage(&msg) == true)
-                       {
-                               result = SCARD_ERROR_OK;
-                       }
-                       else
-                       {
-                               result = SCARD_ERROR_IPC_FAILED;
-                       }
-               }
-               else
-               {
-                       SCARD_DEBUG_ERR("unavailable session");
-                       result = SCARD_ERROR_ILLEGAL_STATE;
-               }
+                                       /* create new instance of channel */
+                                       channel = new ClientChannel(context,
+                                               this, channel_id,
+                                               response, (void *)channel_id);
+                                       if (channel != NULL)
+                                       {
+                                               channels.push_back(channel);
+                                       }
+                                       else
+                                       {
+                                               _ERR("alloc failed");
 
-               return result;
-       }
+                                               THROW_ERROR(SCARD_ERROR_OUT_OF_MEMORY);
+                                       }
+                               } else {
+                                       _ERR("smartcard_service_session_call_open_channel_sync failed, [%d]", ret);
 
-       Channel *Session::openChannelSync(int id, ByteArray aid)
-               throw (ExceptionBase &, ErrorIO &, ErrorIllegalState &,
-                       ErrorIllegalParameter &, ErrorSecurity &)
-       {
-               openedChannel = NULL;
+                                       THROW_ERROR(ret);
+                               }
+                       } else {
+                               _ERR("smartcard_service_session_call_open_channel_sync failed, [%s]", error->message);
+                               g_error_free(error);
 
-               if (getReader()->isSecureElementPresent() == true)
-               {
+                               THROW_ERROR(SCARD_ERROR_IPC_FAILED);
+                       }
+#else
                        Message msg;
                        int rv;
 
@@ -357,18 +591,20 @@ namespace smartcard_service_api
                        msg.callback = (void *)this; /* if callback is class instance, it means synchronized call */
 
                        syncLock();
-                       if (ClientIPC::getInstance().sendMessage(&msg) == true)
+                       if (ClientIPC::getInstance().sendMessage(msg) == true)
                        {
                                rv = waitTimedCondition(0);
                                if (rv != 0)
                                {
-                                       SCARD_DEBUG_ERR("time over");
+                                       _ERR("time over");
                                        this->error = SCARD_ERROR_OPERATION_TIMEOUT;
                                }
+
+                               channel = openedChannel;
                        }
                        else
                        {
-                               SCARD_DEBUG_ERR("sendMessage failed");
+                               _ERR("sendMessage failed");
                                this->error = SCARD_ERROR_IPC_FAILED;
                        }
                        syncUnlock();
@@ -377,22 +613,44 @@ namespace smartcard_service_api
                        {
                                ThrowError::throwError(this->error);
                        }
+#endif
                }
                else
                {
-                       SCARD_DEBUG_ERR("unavailable session");
+                       _ERR("unavailable session");
+
                        throw ErrorIllegalState(SCARD_ERROR_UNAVAILABLE);
                }
 
-               return (Channel *)openedChannel;
+               return (Channel *)channel;
        }
 
-       int Session::openChannel(int id, ByteArray aid, openChannelCallback callback, void *userData)
+       int Session::openChannel(int id, const ByteArray &aid, openChannelCallback callback, void *userData)
        {
                int result;
 
                if (getReader()->isSecureElementPresent() == true)
                {
+#ifdef USE_GDBUS
+                       GVariant *var_aid;
+
+                       CallbackParam *param = new CallbackParam();
+
+                       param->instance = this;
+                       param->callback = (void *)callback;
+                       param->user_param = userData;
+
+                       var_aid = GDBusHelper::convertByteArrayToVariant(aid);
+
+                       smartcard_service_session_call_open_channel(
+                               (SmartcardServiceSession *)proxy,
+                               GPOINTER_TO_UINT(context),
+                               GPOINTER_TO_UINT(handle),
+                               (guint)id, var_aid, NULL,
+                               &Session::session_open_channel_cb, param);
+
+                       result = SCARD_ERROR_OK;
+#else
                        Message msg;
 
                        /* request channel handle from server */
@@ -405,79 +663,94 @@ namespace smartcard_service_api
                        msg.callback = (void *)callback;
                        msg.userParam = userData;
 
-                       if (ClientIPC::getInstance().sendMessage(&msg) == true)
+                       if (ClientIPC::getInstance().sendMessage(msg) == true)
                        {
                                result = SCARD_ERROR_OK;
                        }
                        else
                        {
+                               _ERR("sendMessage failed");
                                result = SCARD_ERROR_IPC_FAILED;
                        }
+#endif
                }
                else
                {
-                       SCARD_DEBUG_ERR("unavailable session");
+                       _ERR("unavailable session");
                        result = SCARD_ERROR_ILLEGAL_STATE;
                }
 
                return result;
        }
 
-       Channel *Session::openBasicChannelSync(ByteArray aid)
-               throw (ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &)
+       Channel *Session::openBasicChannelSync(const ByteArray &aid)
+               throw (ExceptionBase &, ErrorIO &, ErrorIllegalState &,
+                       ErrorIllegalParameter &, ErrorSecurity &)
        {
                return openChannelSync(0, aid);
        }
 
-       Channel *Session::openBasicChannelSync(unsigned char *aid, unsigned int length)
-               throw (ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &)
+       Channel *Session::openBasicChannelSync(const unsigned char *aid, unsigned int length)
+               throw (ExceptionBase &, ErrorIO &, ErrorIllegalState &,
+                       ErrorIllegalParameter &, ErrorSecurity &)
        {
-               return openBasicChannelSync(ByteArray(aid, length));
+               ByteArray temp(aid, length);
+
+               return openBasicChannelSync(temp);
        }
 
-       int Session::openBasicChannel(ByteArray aid, openChannelCallback callback, void *userData)
+       int Session::openBasicChannel(const ByteArray &aid, openChannelCallback callback, void *userData)
        {
                return openChannel(0, aid, callback, userData);
        }
 
-       int Session::openBasicChannel(unsigned char *aid, unsigned int length,
+       int Session::openBasicChannel(const unsigned char *aid, unsigned int length,
                openChannelCallback callback, void *userData)
        {
-               return openBasicChannel(ByteArray(aid, length), callback, userData);
+               ByteArray temp(aid, length);
+
+               return openBasicChannel(temp, callback, userData);
        }
 
-       Channel *Session::openLogicalChannelSync(ByteArray aid)
-               throw (ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &)
+       Channel *Session::openLogicalChannelSync(const ByteArray &aid)
+               throw (ExceptionBase &, ErrorIO &, ErrorIllegalState &,
+                       ErrorIllegalParameter &, ErrorSecurity &)
        {
                return openChannelSync(1, aid);
        }
 
-       Channel *Session::openLogicalChannelSync(unsigned char *aid, unsigned int length)
-               throw (ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &)
+       Channel *Session::openLogicalChannelSync(const unsigned char *aid, unsigned int length)
+               throw (ExceptionBase &, ErrorIO &, ErrorIllegalState &,
+                       ErrorIllegalParameter &, ErrorSecurity &)
        {
-               return openLogicalChannelSync(ByteArray(aid, length));
+               ByteArray temp(aid, length);
+
+               return openLogicalChannelSync(temp);
        }
 
-       int Session::openLogicalChannel(ByteArray aid, openChannelCallback callback, void *userData)
+       int Session::openLogicalChannel(const ByteArray &aid, openChannelCallback callback, void *userData)
        {
                return openChannel(1, aid, callback, userData);
        }
 
-       int Session::openLogicalChannel(unsigned char *aid, unsigned int length,
+       int Session::openLogicalChannel(const unsigned char *aid, unsigned int length,
                openChannelCallback callback, void *userData)
        {
-               return openLogicalChannel(ByteArray(aid, length), callback, userData);
+               ByteArray temp(aid, length);
+
+               return openLogicalChannel(temp, callback, userData);
        }
 
+#ifndef USE_GDBUS
        bool Session::dispatcherCallback(void *message)
        {
                Message *msg = (Message *)message;
-               Session *session = NULL;
+               Session *session;
                bool result = false;
 
                if (msg == NULL)
                {
-                       SCARD_DEBUG_ERR("message is null");
+                       _ERR("message is null");
                        return result;
                }
 
@@ -489,7 +762,7 @@ namespace smartcard_service_api
                        {
                                Channel *channel = NULL;
 
-                               SCARD_DEBUG("MSG_REQUEST_OPEN_CHANNEL");
+                               _INFO("MSG_REQUEST_OPEN_CHANNEL");
 
                                if (msg->param1 != 0)
                                {
@@ -502,7 +775,7 @@ namespace smartcard_service_api
                                        }
                                        else
                                        {
-                                               SCARD_DEBUG_ERR("alloc failed");
+                                               _ERR("alloc failed");
 
                                                msg->error = SCARD_ERROR_OUT_OF_MEMORY;
                                        }
@@ -532,7 +805,7 @@ namespace smartcard_service_api
 
                case Message::MSG_REQUEST_GET_ATR :
                        {
-                               SCARD_DEBUG("MSG_REQUEST_GET_ATR");
+                               _INFO("MSG_REQUEST_GET_ATR");
 
                                if (msg->isSynchronousCall() == true) /* synchronized call */
                                {
@@ -550,14 +823,17 @@ namespace smartcard_service_api
                                        getATRCallback cb = (getATRCallback)msg->callback;
 
                                        /* async call */
-                                       cb(msg->data.getBuffer(), msg->data.getLength(), msg->error, msg->userParam);
+                                       cb(msg->data.getBuffer(),
+                                               msg->data.size(),
+                                               msg->error,
+                                               msg->userParam);
                                }
                        }
                        break;
 
                case Message::MSG_REQUEST_CLOSE_SESSION :
                        {
-                               SCARD_DEBUG("MSG_REQUEST_CLOSE_SESSION");
+                               _INFO("MSG_REQUEST_CLOSE_SESSION");
 
                                if (msg->isSynchronousCall() == true) /* synchronized call */
                                {
@@ -581,7 +857,7 @@ namespace smartcard_service_api
 
                case Message::MSG_REQUEST_GET_CHANNEL_COUNT :
                        {
-                               SCARD_DEBUG("MSG_REQUEST_GET_CHANNEL_COUNT");
+                               _INFO("MSG_REQUEST_GET_CHANNEL_COUNT");
 
                                if (msg->isSynchronousCall() == true) /* synchronized call */
                                {
@@ -605,12 +881,15 @@ namespace smartcard_service_api
                        break;
 
                default :
-                       SCARD_DEBUG("unknown message : %s", msg->toString());
+                       _DBG("unknown message : %s", msg->toString().c_str());
                        break;
                }
 
+               delete msg;
+
                return result;
        }
+#endif
 } /* namespace smartcard_service_api */
 
 /* export C API */
@@ -623,7 +902,7 @@ namespace smartcard_service_api
        } \
        else \
        { \
-               SCARD_DEBUG_ERR("Invalid param"); \
+               _ERR("Invalid param"); \
        }
 
 using namespace smartcard_service_api;
@@ -703,17 +982,6 @@ EXTERN_API int session_open_logical_channel(session_h handle, unsigned char *aid
        return result;
 }
 
-EXTERN_API int session_get_channel_count(session_h handle, session_get_channel_count_cb callback, void * userData)
-{
-       int result = -1;
-
-       SESSION_EXTERN_BEGIN;
-               result = session->getChannelCount((getChannelCountCallback)callback, userData);
-       SESSION_EXTERN_END;
-
-       return result;
-}
-
 EXTERN_API void session_destroy_instance(session_h handle)
 {
 }
@@ -729,9 +997,9 @@ EXTERN_API int session_get_atr_sync(session_h handle, unsigned char **buffer, un
 
        SESSION_EXTERN_BEGIN;
                temp = session->getATRSync();
-               if (temp.getLength() > 0)
+               if (temp.size() > 0)
                {
-                       *length = temp.getLength();
+                       *length = temp.size();
                        *buffer = (unsigned char *)calloc(1, *length);
                        memcpy(*buffer, temp.getBuffer(), *length);
 
@@ -778,13 +1046,13 @@ EXTERN_API channel_h session_open_logical_channel_sync(session_h handle, unsigne
        return result;
 }
 
-EXTERN_API unsigned int session_get_channel_count_sync(session_h handle)
+EXTERN_API size_t session_get_channel_count(session_h handle)
 {
-       unsigned int result = 0;
+       size_t result = 0;
 
 #ifdef CLIENT_IPC_THREAD
        SESSION_EXTERN_BEGIN;
-               result = session->getChannelCountSync();
+               result = session->getChannelCount();
        SESSION_EXTERN_END;
 #endif
 
index 9a8ae6f..f8c6676 100644 (file)
@@ -18,7 +18,9 @@
 #define CLIENTCHANNEL_H_
 
 /* standard library header */
-
+#ifdef USE_GDBUS
+#include <gio/gio.h>
+#endif
 /* SLP library header */
 
 /* local header */
@@ -36,32 +38,42 @@ namespace smartcard_service_api
        private:
                void *context;
                void *handle;
+#ifdef USE_GDBUS
+               void *proxy;
+#else
                /* temporary data for sync function */
                int error;
                ByteArray response;
-
+#endif
                ClientChannel(void *context, Session *session, int channelNum,
-                       ByteArray selectResponse, void *handle);
+                       const ByteArray &selectResponse, void *handle);
                ~ClientChannel();
 
+#ifdef USE_GDBUS
+               static void channel_transmit_cb(GObject *source_object,
+                       GAsyncResult *res, gpointer user_data);
+               static void channel_close_cb(GObject *source_object,
+                       GAsyncResult *res, gpointer user_data);
+#else
                static bool dispatcherCallback(void *message);
-
+#endif
        public:
-               int close(closeCallback callback, void *userParam);
-               int transmit(ByteArray command, transmitCallback callback,
+               int close(closeChannelCallback callback, void *userParam);
+               int transmit(const ByteArray &command, transmitCallback callback,
                        void *userParam);
 
                void closeSync()
                        throw(ExceptionBase &, ErrorIO &, ErrorIllegalState &,
                                ErrorSecurity &, ErrorIllegalParameter &);
-               int transmitSync(ByteArray command, ByteArray &result)
+               int transmitSync(const ByteArray &command, ByteArray &result)
                        throw(ExceptionBase &, ErrorIO &, ErrorIllegalState &,
                                ErrorIllegalParameter &, ErrorSecurity &);
 
+#ifndef USE_GDBUS
                friend class ClientDispatcher;
+#endif
                friend class Session;
        };
-
 } /* namespace smartcard_service_api */
 #endif /* __cplusplus */
 
index 3305b28..719cfeb 100644 (file)
@@ -16,7 +16,7 @@
 
 #ifndef CLIENTDISPATCHER_H_
 #define CLIENTDISPATCHER_H_
-
+#ifndef USE_GDBUS
 /* standard library header */
 #include <map>
 
@@ -34,7 +34,7 @@ namespace smartcard_service_api
        class ClientDispatcher: public DispatcherHelper
        {
        private:
-               map<void *, SEService *> mapSESerivces;
+               map<unsigned int, SEService *> mapSESerivces;
 
                ClientDispatcher();
                ~ClientDispatcher();
@@ -44,9 +44,10 @@ namespace smartcard_service_api
        public:
                static ClientDispatcher &getInstance();
 
-               bool addSEService(void *context, SEService *service);
-               void removeSEService(void *context);
+               bool addSEService(unsigned int handle, SEService *service);
+               void removeSEService(unsigned int handle);
        };
 
 } /* namespace open_mobile_api */
+#endif /* USE_GDBUS */
 #endif /* CLIENTDISPATCHER_H_ */
similarity index 73%
rename from common/SessionHelper.cpp
rename to client/include/ClientGDBus.h
index fde6560..5f71d61 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * limitations under the License.
  */
 
+#ifndef CLIENTGDBUS_H_
+#define CLIENTGDBUS_H_
+
+#ifdef USE_GDBUS
 /* standard library header */
+#include <glib.h>
 
 /* SLP library header */
 
 /* local header */
-#include "ReaderHelper.h"
+#include "GDBusHelper.h"
+#include "smartcard-service-gdbus.h"
 
 namespace smartcard_service_api
 {
-       SessionHelper::SessionHelper(ReaderHelper *reader) :
-               closed(true)
+       class ClientGDBus
        {
-               this->reader = reader;
-       }
+       };
 } /* namespace smartcard_service_api */
+#endif
+#endif /* CLIENTGDBUS_H_ */
index 4dbbc76..76f6c21 100644 (file)
@@ -16,7 +16,7 @@
 
 #ifndef CLIENTIPC_H_
 #define CLIENTIPC_H_
-
+#ifndef USE_GDBUS
 /* standard library header */
 #ifdef USE_AUTOSTART
 #include <dbus/dbus-glib.h>
@@ -51,8 +51,9 @@ namespace smartcard_service_api
 
        public:
                static ClientIPC &getInstance();
-               bool sendMessage(Message *msg);
+               bool sendMessage(const Message &msg);
        };
 
 } /* namespace open_mobile_api */
+#endif /* USE_GDBUS */
 #endif /* CLIENTIPC_H_ */
index d06e22a..08ea874 100644 (file)
 #define READER_H_
 
 /* standard library header */
+#ifdef USE_GDBUS
+#include <glib.h>
+#include <gio/gio.h>
+#endif
 
 /* SLP library header */
 
@@ -36,16 +40,24 @@ namespace smartcard_service_api
        private:
                void *context;
                void *handle;
+#ifdef USE_GDBUS
+               void *proxy;
+#else
                /* temporary data for sync function */
                int error;
                Session *openedSession;
+#endif
 
                Reader(void *context, const char *name, void *handle);
                ~Reader();
 
-               void unavailable();
-
+               inline void unavailable() { present = false; }
+#ifdef USE_GDBUS
+               static void reader_open_session_cb(GObject *source_object,
+                       GAsyncResult *res, gpointer user_data);
+#else
                static bool dispatcherCallback(void *message);
+#endif
 
        public:
                void closeSessions()
@@ -57,7 +69,9 @@ namespace smartcard_service_api
                                ErrorIllegalParameter &, ErrorSecurity &);
 
                friend class SEService;
+#ifndef USE_GDBUS
                friend class ClientDispatcher;
+#endif
        };
 } /* namespace smartcard_service_api */
 #endif /* __cplusplus */
index 0070fe3..85ac371 100644 (file)
 #define SESERVICE_H_
 
 /* standard library header */
+#ifdef USE_GDBUS
+#include <glib.h>
+#include <gio/gio.h>
+#endif
 
 /* SLP library header */
 
@@ -35,18 +39,25 @@ namespace smartcard_service_api
 {
        typedef void (*serviceConnected)(SEServiceHelper *service, void *context);
 
-       class SEService: public SEServiceHelper
+       class SEService : public SEServiceHelper
        {
        private:
-               int pid;
+               unsigned int handle;
                void *context;
                serviceConnected handler;
                SEServiceListener *listener;
-
+#ifdef USE_GDBUS
+               void *proxy;
+#endif
                SEService();
 
+               void addReader(unsigned int handle, const char *name);
+               bool parseReaderInformation(unsigned int count, const ByteArray &data);
+#ifdef USE_GDBUS
+               bool parseReaderInformation(GVariant *variant);
+#else
                static bool dispatcherCallback(void *message);
-               bool parseReaderInformation(unsigned int count, ByteArray data);
+#endif
 
                bool _initialize()
                        throw(ErrorIO &);
@@ -57,6 +68,18 @@ namespace smartcard_service_api
                SEService *initializeSync(void *context, serviceConnected handler)
                        throw(ErrorIO &, ErrorIllegalParameter &);
 
+#ifdef USE_GDBUS
+               static void reader_inserted(GObject *source_object,
+                       guint reader_id, gchar *reader_name,
+                       gpointer user_data);
+               static void reader_removed(GObject *source_object,
+                       guint reader_id, gchar *reader_name,
+                       gpointer user_data);
+               static void se_service_shutdown_cb(GObject *source_object,
+                       GAsyncResult *res, gpointer user_data);
+               static void se_service_cb(GObject *source_object,
+                       GAsyncResult *res, gpointer user_data);
+#endif
        public:
                SEService(void *user_data, serviceConnected handler)
                        throw(ErrorIO &, ErrorIllegalParameter &);
@@ -72,7 +95,9 @@ namespace smartcard_service_api
                void shutdown();
                void shutdownSync();
 
+#ifndef USE_GDBUS
                friend class ClientDispatcher;
+#endif
        };
 } /* namespace smartcard_service_api */
 #endif /* __cplusplus */
index 2329e59..69df451 100644 (file)
@@ -18,6 +18,9 @@
 #define SESSION_H_
 
 /* standard library header */
+#ifdef USE_GDBUS
+#include <gio/gio.h>
+#endif
 
 /* SLP library header */
 
@@ -32,25 +35,36 @@ namespace smartcard_service_api
 {
        class Reader;
 
-       class Session: public SessionHelper
+       class Session : public SessionHelper
        {
        private:
                void *context;
                void *handle;
+#ifdef USE_GDBUS
+               void *proxy;
+#else
                /* temporary data for sync function */
                int error;
                Channel *openedChannel;
                unsigned int channelCount;
-
+#endif
                Session(void *context, Reader *reader, void *handle);
                ~Session();
 
-               int openChannel(int id, ByteArray aid, openChannelCallback callback, void *userData);
-               static bool dispatcherCallback(void *message);
-
-               Channel *openChannelSync(int id, ByteArray aid)
+               int openChannel(int id, const ByteArray &aid, openChannelCallback callback, void *userData);
+               Channel *openChannelSync(int id, const ByteArray &aid)
                        throw(ExceptionBase &, ErrorIO &, ErrorIllegalState &,
                                ErrorIllegalParameter &, ErrorSecurity &);
+#ifdef USE_GDBUS
+               static void session_get_atr_cb(GObject *source_object,
+                       GAsyncResult *res, gpointer user_data);
+               static void session_open_channel_cb(GObject *source_object,
+                       GAsyncResult *res, gpointer user_data);
+               static void session_close_cb(GObject *source_object,
+                       GAsyncResult *res, gpointer user_data);
+#else
+               static bool dispatcherCallback(void *message);
+#endif
 
        public:
                void closeChannels()
@@ -59,13 +73,12 @@ namespace smartcard_service_api
                int getATR(getATRCallback callback, void *userData);
                int close(closeSessionCallback callback, void *userData);
 
-               int openBasicChannel(ByteArray aid, openChannelCallback callback, void *userData);
-               int openBasicChannel(unsigned char *aid, unsigned int length, openChannelCallback callback, void *userData);
-               int openLogicalChannel(ByteArray aid, openChannelCallback callback, void *userData);
-               int openLogicalChannel(unsigned char *aid, unsigned int length, openChannelCallback callback, void *userData);
-               int getChannelCount(getChannelCountCallback callback, void * userData);
+               int openBasicChannel(const ByteArray &aid, openChannelCallback callback, void *userData);
+               int openBasicChannel(const unsigned char *aid, unsigned int length, openChannelCallback callback, void *userData);
+               int openLogicalChannel(const ByteArray &aid, openChannelCallback callback, void *userData);
+               int openLogicalChannel(const unsigned char *aid, unsigned int length, openChannelCallback callback, void *userData);
 
-               ByteArray getATRSync()
+               const ByteArray getATRSync()
                        throw(ExceptionBase &, ErrorIO &, ErrorSecurity &,
                                ErrorIllegalState &, ErrorIllegalParameter &);
 
@@ -73,28 +86,29 @@ namespace smartcard_service_api
                        throw(ExceptionBase &, ErrorIO &, ErrorSecurity &,
                                ErrorIllegalState &, ErrorIllegalParameter &);
 
-               Channel *openBasicChannelSync(ByteArray aid)
-                       throw(ErrorIO &, ErrorIllegalState &,
+               Channel *openBasicChannelSync(const ByteArray &aid)
+                       throw(ExceptionBase &, ErrorIO &, ErrorIllegalState &,
                                ErrorIllegalParameter &, ErrorSecurity &);
 
-               Channel *openBasicChannelSync(unsigned char *aid, unsigned int length)
-                       throw(ErrorIO &, ErrorIllegalState &,
+               Channel *openBasicChannelSync(const unsigned char *aid, unsigned int length)
+                       throw(ExceptionBase &, ErrorIO &, ErrorIllegalState &,
                                ErrorIllegalParameter &, ErrorSecurity &);
 
-               Channel *openLogicalChannelSync(ByteArray aid)
-                       throw(ErrorIO &, ErrorIllegalState &,
+               Channel *openLogicalChannelSync(const ByteArray &aid)
+                       throw(ExceptionBase &, ErrorIO &, ErrorIllegalState &,
                                ErrorIllegalParameter &, ErrorSecurity &);
 
-               Channel *openLogicalChannelSync(unsigned char *aid, unsigned int length)
-                       throw(ErrorIO &, ErrorIllegalState &,
+               Channel *openLogicalChannelSync(const unsigned char *aid, unsigned int length)
+                       throw(ExceptionBase &, ErrorIO &, ErrorIllegalState &,
                                ErrorIllegalParameter &, ErrorSecurity &);
 
-               unsigned int getChannelCountSync();
+               size_t getChannelCount() const;
 
+#ifndef USE_GDBUS
                friend class ClientDispatcher;
+#endif
                friend class Reader;
        };
-
 } /* namespace smartcard_service_api */
 #endif /* __cplusplus */
 
@@ -116,14 +130,14 @@ int session_open_basic_channel(session_h handle, unsigned char *aid,
        unsigned int length, session_open_channel_cb callback, void *userData);
 int session_open_logical_channel(session_h handle, unsigned char *aid,
        unsigned int length, session_open_channel_cb callback, void *userData);
-int session_get_channel_count(session_h handle, session_get_channel_count_cb callback, void * userData);
 
 int session_get_atr_sync(session_h handle, unsigned char **buffer, unsigned int *length);
 void session_close_sync(session_h handle);
 
 channel_h session_open_basic_channel_sync(session_h handle, unsigned char *aid, unsigned int length);
 channel_h session_open_logical_channel_sync(session_h handle, unsigned char *aid, unsigned int length);
-unsigned int session_get_channel_count_sync(session_h handle);
+
+size_t session_get_channel_count(session_h handle);
 
 #ifdef __cplusplus
 }
similarity index 79%
rename from client/smartcard-service.pc.in
rename to client/smartcard-service.pc
index eaa674a..a58f2e7 100644 (file)
@@ -3,11 +3,11 @@
 prefix=/usr
 exec_prefix=${prefix}/bin
 includedir=${prefix}/include
-libdir=@LIB_INSTALL_DIR@
+libdir=${prefix}/lib
 
 Name: smartcard-service
 Description: Make flags of Common library of Smartcard service
 Version: 1.0
 Requires: 
 Libs: -L${libdir} -lsmartcard-service
-Cflags: -I${includedir}/smartcard-service
+Cflags: -I${includedir}/smartcard-service
\ No newline at end of file
index 8718737..ae5589c 100644 (file)
 /* SLP library header */
 
 /* local header */
+#include "smartcard-types.h"
 #include "Debug.h"
 #include "APDUHelper.h"
 
 namespace smartcard_service_api
 {
        /* ResponseHelper class */
-       ResponseHelper::ResponseHelper()
-               : status(0)
+       ResponseHelper::ResponseHelper() : status(0)
        {
        }
 
@@ -44,22 +44,22 @@ namespace smartcard_service_api
        bool ResponseHelper::setResponse(const ByteArray &response)
        {
                bool result = false;
-               status = 0;
-               dataField.releaseBuffer();
+               status = SCARD_ERROR_UNKNOWN;
+               dataField.clear();
 
                this->response = response;
 
-               if (response.getLength() >= 2)
+               if (response.size() >= 2)
                {
-                       sw[0] = response.getReverseAt(1);
-                       sw[1] = response.getReverseAt(0);
+                       sw[0] = response.reverseAt(1);
+                       sw[1] = response.reverseAt(0);
 
                        status = parseStatusWord(sw);
 
-                       if (response.getLength() > 2)
+                       if (response.size() > 2)
                        {
-                               dataField.setBuffer(response.getBuffer(),
-                                       response.getLength() - 2);
+                               dataField.assign(response.getBuffer(),
+                                       response.size() - 2);
                        }
 
                        result = true;
@@ -68,7 +68,7 @@ namespace smartcard_service_api
                return result;
        }
 
-       int ResponseHelper::parseStatusWord(unsigned char *sw)
+       int ResponseHelper::parseStatusWord(const unsigned char *sw)
        {
                int result = sw[0] << 8 | sw[1];
 
@@ -78,7 +78,6 @@ namespace smartcard_service_api
                case (unsigned char)0x90 : /* SW2:00, No further qualification */
                case (unsigned char)0x91 : /* extra information */
                case (unsigned char)0x92 : /* extra information */
-                       result = 0;
                        break;
 
                default :
@@ -89,45 +88,25 @@ namespace smartcard_service_api
                return result;
        }
 
-       int ResponseHelper::getStatus()
-       {
-               return status;
-       }
-
        int ResponseHelper::getStatus(const ByteArray &response)
        {
                int status = 0;
 
-               if (response.getLength() >= 2)
+               if (response.size() >= 2)
                {
-                       status = ResponseHelper::parseStatusWord(response.getBuffer((response.getLength() - 2)));
+                       status = ResponseHelper::parseStatusWord(response.getBuffer((response.size() - 2)));
                }
 
                return status;
        }
 
-       unsigned char ResponseHelper::getSW1()
-       {
-               return sw[0];
-       }
-
-       unsigned char ResponseHelper::getSW2()
-       {
-               return sw[1];
-       }
-
-       ByteArray ResponseHelper::getDataField()
-       {
-               return dataField;
-       }
-
-       ByteArray ResponseHelper::getDataField(const ByteArray &response)
+       const ByteArray ResponseHelper::getDataField(const ByteArray &response)
        {
                ByteArray result;
 
-               if (response.getLength() > 2)
+               if (response.size() > 2)
                {
-                       result.setBuffer(response.getBuffer(), response.getLength() - 2);
+                       result.assign(response.getBuffer(), response.size() - 2);
                }
 
                return result;
@@ -145,8 +124,10 @@ namespace smartcard_service_api
        {
        }
 
-       bool APDUCommand::setCommand(unsigned char cla, unsigned char ins, unsigned char p1,
-               unsigned char p2, ByteArray commandData, unsigned int maxResponseSize)
+       bool APDUCommand::setCommand(unsigned char cla, unsigned char ins,
+               unsigned char p1, unsigned char p2,
+               const ByteArray &commandData,
+               unsigned int maxResponseSize)
        {
                setCLA(cla);
                setINS(ins);
@@ -164,7 +145,7 @@ namespace smartcard_service_api
                uint32_t offset = 0;
                uint32_t lengthSize = 1;
 
-               if (command.getLength() < sizeof(header))
+               if (command.size() < sizeof(header))
                {
                        return false;
                }
@@ -177,7 +158,7 @@ namespace smartcard_service_api
                        lengthSize = 2;
                }
 
-               if (command.getLength() - offset > lengthSize)
+               if (command.size() - offset > lengthSize)
                {
                        unsigned int length = 0;
 
@@ -189,7 +170,7 @@ namespace smartcard_service_api
                        }
                        else
                        {
-                               length = command.getAt(offset);
+                               length = command.at(offset);
                                offset += 1;
                        }
 
@@ -197,14 +178,14 @@ namespace smartcard_service_api
                        offset += length;
                }
 
-               if (command.getLength() - offset == lengthSize)
+               if (command.size() - offset == lengthSize)
                {
                        if (isExtendedLength)
                        {
                                unsigned int temp;
 
-                               temp = command.getAt(offset) << 8;
-                               temp |= command.getAt(offset + 1);
+                               temp = command.at(offset) << 8;
+                               temp |= command.at(offset + 1);
 
                                if (temp == 0)
                                        setMaxResponseSize(APDUCommand::LE_MAX);
@@ -215,22 +196,22 @@ namespace smartcard_service_api
                        }
                        else
                        {
-                               if (command.getAt(offset) == 0)
+                               if (command.at(offset) == 0)
                                        setMaxResponseSize(APDUCommand::LE_MAX);
                                else
-                                       setMaxResponseSize(command.getAt(offset));
+                                       setMaxResponseSize(command.at(offset));
 
                                offset += 1;
                        }
                }
 
-               if (command.getLength() == offset)
+               if (command.size() == offset)
                {
                        result = true;
                }
                else
                {
-                       SCARD_DEBUG_ERR("command stream is not correct, command.getLength() [%d], offset [%d]", command.getLength(), offset);
+                       _ERR("command stream is not correct, command.size() [%d], offset [%d]", command.size(), offset);
                }
 
                return result;
@@ -303,7 +284,7 @@ namespace smartcard_service_api
                header.cla = cla;
        }
 
-       unsigned char APDUCommand::getCLA()
+       unsigned char APDUCommand::getCLA() const
        {
                return header.cla;
        }
@@ -317,7 +298,7 @@ namespace smartcard_service_api
                header.ins = ins;
        }
 
-       unsigned char APDUCommand::getINS()
+       unsigned char APDUCommand::getINS() const
        {
                return header.ins;
        }
@@ -328,7 +309,7 @@ namespace smartcard_service_api
                header.param[0] = p1;
        }
 
-       unsigned char APDUCommand::getP1()
+       unsigned char APDUCommand::getP1() const
        {
                return header.param[0];
        }
@@ -339,7 +320,7 @@ namespace smartcard_service_api
                header.param[1] = p2;
        }
 
-       unsigned char APDUCommand::getP2()
+       unsigned char APDUCommand::getP2() const
        {
                return header.param[1];
        }
@@ -349,7 +330,7 @@ namespace smartcard_service_api
                commandData = data;
        }
 
-       ByteArray APDUCommand::getCommandData()
+       const ByteArray APDUCommand::getCommandData() const
        {
                return commandData;
        }
@@ -359,12 +340,12 @@ namespace smartcard_service_api
                this->maxResponseSize = maxResponseSize;
        }
 
-       unsigned int APDUCommand::getMaxResponseSize()
+       unsigned int APDUCommand::getMaxResponseSize() const
        {
                return maxResponseSize;
        }
 
-       bool APDUCommand::getBuffer(ByteArray &array)
+       bool APDUCommand::getBuffer(ByteArray &array) const
        {
                unsigned char *temp_buffer = NULL;
                unsigned int temp_len = 0;
@@ -378,18 +359,18 @@ namespace smartcard_service_api
                temp_len += sizeof(header);
 
                /* calculate lc length */
-               if (commandData.getLength() > 0)
+               if (commandData.size() > 0)
                {
-                       if (isExtendedLength/*commandData.getLength() > 255*/)
+                       if (isExtendedLength/*commandData.size() > 255*/)
                        {
-                               lc[1] = (commandData.getLength() >> 8) & 0x000000FF;
-                               lc[2] = commandData.getLength() & 0x000000FF;
+                               lc[1] = (commandData.size() >> 8) & 0x000000FF;
+                               lc[2] = commandData.size() & 0x000000FF;
 
                                lc_len = 3;
                        }
                        else
                        {
-                               lc[0] = commandData.getLength() & 0x000000FF;
+                               lc[0] = commandData.size() & 0x000000FF;
 
                                lc_len = 1;
                        }
@@ -398,12 +379,12 @@ namespace smartcard_service_api
                temp_len += lc_len;
 
                /* add command data length */
-               temp_len += commandData.getLength();
+               temp_len += commandData.size();
 
                /* calculate le length */
                if (maxResponseSize > 0)
                {
-                       if (isExtendedLength/*commandData.getLength() > 255*/)
+                       if (isExtendedLength/*commandData.size() > 255*/)
                        {
                                if (maxResponseSize < 65536)
                                {
@@ -438,13 +419,13 @@ namespace smartcard_service_api
                memcpy(temp_buffer + offset, &header, sizeof(header));
                offset += sizeof(header);
 
-               if (commandData.getLength() > 0)
+               if (commandData.size() > 0)
                {
                        memcpy(temp_buffer + offset, &lc, lc_len);
                        offset += lc_len;
 
-                       memcpy(temp_buffer + offset, commandData.getBuffer(), commandData.getLength());
-                       offset += commandData.getLength();
+                       memcpy(temp_buffer + offset, commandData.getBuffer(), commandData.size());
+                       offset += commandData.size();
                }
 
                if (maxResponseSize > 0)
@@ -453,14 +434,15 @@ namespace smartcard_service_api
                        offset += le_len;
                }
 
-               array.setBuffer(temp_buffer, temp_len);
+               array.assign(temp_buffer, temp_len);
                delete []temp_buffer;
 
                return true;
        }
 
        /* APDUHelper class */
-       ByteArray APDUHelper::generateAPDU(int command, int channel, ByteArray data)
+       const ByteArray APDUHelper::generateAPDU(int command,
+               int channel, const ByteArray &data)
        {
                ByteArray result;
                APDUCommand apdu;
index 703d0de..10593d5 100644 (file)
 /* local header */
 #include "Debug.h"
 #include "SimpleTLV.h"
+#include "AccessControlList.h"
 #include "AccessCondition.h"
 
 namespace smartcard_service_api
 {
-       void APDUAccessRule::loadAPDUAccessRule(const ByteArray &data)
+       void AccessRule::addAPDUAccessRule(const ByteArray &apdu,
+               const ByteArray &mask)
        {
-               SimpleTLV tlv(data);
+               pair<ByteArray, ByteArray> item(apdu, mask);
 
-               if (tlv.decodeTLV() == true)
-               {
-                       switch (tlv.getTag())
-                       {
-                       case 0xA0 : /* CHOICE 0 : APDUPermission */
-                               permission = SimpleTLV::getBoolean(tlv.getValue());
-                               break;
-
-                       case 0xA1 : /* CHOICE 1 : APDUFilters */
-                               tlv.enterToValueTLV();
-                               while (tlv.decodeTLV() == true)
-                               {
-                                       if (tlv.getTag() == 0x04) /* OCTET STRING */
-                                       {
-                                               ByteArray apdu, mask, value;
-
-                                               value = tlv.getValue();
-
-                                               SCARD_DEBUG("APDU rule : %s", value.toString());
-
-                                               if (value.getLength() == 8) /* apdu 4 bytes + mask 4 bytes */
-                                               {
-                                                       apdu.setBuffer(value.getBuffer(), 4);
-                                                       mask.setBuffer(value.getBuffer(4), 4);
-
-                                                       pair<ByteArray, ByteArray> newItem(apdu, mask);
-
-                                                       mapApduFilters.insert(newItem);
-                                               }
-                                               else
-                                               {
-                                                       SCARD_DEBUG_ERR("Invalid APDU rule : %s", value.toString());
-                                               }
-                                       }
-                                       else
-                                       {
-                                               SCARD_DEBUG_ERR("Unknown tag : 0x%02X", tlv.getTag());
-                                       }
-                               }
-                               tlv.returnToParentTLV();
-                               break;
-
-                       default :
-                               SCARD_DEBUG_ERR("Unknown tag : 0x%02X", tlv.getTag());
-                               break;
-                       }
-               }
+               listFilters.push_back(item);
        }
 
-       bool APDUAccessRule::isAuthorizedAccess(const ByteArray &command)
+       bool AccessRule::isAuthorizedAPDUAccess(const ByteArray &command) const
        {
                bool result = false;
 
-               if (mapApduFilters.size() > 0)
+               if (command.size() < 4) /* apdu header size */
+                       return false;
+
+               if (listFilters.size() > 0)
                {
-                       /* TODO : search command and check validity */
+                       unsigned int cmd, mask, rule;
+                       vector<pair<ByteArray, ByteArray> >::const_iterator item;
+
+                       cmd = *(unsigned int *)command.getBuffer();
+                       for (item = listFilters.begin(); item != listFilters.end(); item++)
+                       {
+                               mask = *(unsigned int *)item->second.getBuffer();
+                               rule = *(unsigned int *)item->first.getBuffer();
+
+                               if ((cmd & mask) == rule)
+                               {
+                                       result = true;
+                                       break;
+                               }
+                       }
                }
                else
                {
                        /* no filter entry. if permission is true, all access will be granted, if not, all access will be denied */
-                       result = permission;
+                       result = apduRule;
                }
 
                return result;
        }
 
-       void APDUAccessRule::printAPDUAccessRules()
+       bool AccessRule::isAuthorizedNFCAccess(void) const
        {
-               SCARD_DEBUG("  +-- APDU Access Rule");
+               return nfcRule;
+       }
 
-               if (mapApduFilters.size() > 0)
-               {
-                       map<ByteArray, ByteArray>::iterator iterMap;
+       AccessRule *AccessCondition::getAccessRule(const ByteArray &certHash)
+       {
+               AccessRule *result = NULL;
+               map<ByteArray, AccessRule>::iterator item;
 
-                       for (iterMap = mapApduFilters.begin(); iterMap != mapApduFilters.end(); iterMap++)
-                       {
-                               SCARD_DEBUG("  +--- APDU : %s, Mask : %s", ((ByteArray)(iterMap->first)).toString(), iterMap->second.toString());
-                       }
-               }
-               else
-               {
-                       SCARD_DEBUG("  +--- permission : %s", permission ? "granted all" : "denied all");
+               item = mapRules.find(certHash);
+               if (item != mapRules.end()) {
+                       result = &item->second;
                }
-       }
 
-       void NFCAccessRule::loadNFCAccessRule(const ByteArray &data)
-       {
-               permission = SimpleTLV::getBoolean(data);
+               return result;
        }
 
-       bool NFCAccessRule::isAuthorizedAccess(void)
+       const AccessRule *AccessCondition::getAccessRule(const ByteArray &certHash) const
        {
-               bool result = false;
+               const AccessRule *result = NULL;
+               map<ByteArray, AccessRule>::const_iterator item;
 
-               result = permission;
+               item = mapRules.find(certHash);
+               if (item != mapRules.end()) {
+                       result = &item->second;
+               }
 
                return result;
        }
 
-       void NFCAccessRule::printNFCAccessRules()
+       void AccessCondition::addAccessRule(const ByteArray &hash)
        {
-               SCARD_DEBUG("   +-- NFC Access Rule");
-               SCARD_DEBUG("   +--- permission : %s", permission ? "granted all" : "denied all");
+               AccessRule rule;
+
+               pair<ByteArray, AccessRule> item(hash, rule);
+
+               mapRules.insert(item);
        }
 
-       void AccessCondition::loadAccessCondition(ByteArray &aid, ByteArray &data)
+       bool AccessCondition::isAuthorizedAccess(const ByteArray &certHash) const
        {
-               if (data.getLength() > 0)
-               {
-                       SimpleTLV tlv(data);
-
-                       while (tlv.decodeTLV() == true && tlv.getTag() == 0x30) /* SEQUENCE */
-                       {
-                               if (tlv.getLength() > 0)
-                               {
-                                       /* access granted for specific applications */
-                                       tlv.enterToValueTLV();
-                                       if (tlv.decodeTLV())
-                                       {
-                                               switch (tlv.getTag())
-                                               {
-                                               case 0x04 : /* OCTET STRING : CertHash */
-                                                       SCARD_DEBUG("aid : %s, hash : %s", aid.toString(), tlv.getValue().toString());
-
-                                                       hashes.push_back(tlv.getValue());
-                                                       break;
-
-                                               case 0xA0 : /* CHOICE 0 : AccessRules */
-                                                       tlv.enterToValueTLV();
-                                                       if (tlv.decodeTLV())
-                                                       {
-                                                               switch (tlv.getTag())
-                                                               {
-                                                               case 0xA0 : /* CHOICE 0 : APDUAccessRule */
-                                                                       apduRule.loadAPDUAccessRule(tlv.getValue());
-                                                                       break;
-
-                                                               case 0xA1 : /* CHOICE 1 : NFCAccessRule */
-                                                                       nfcRule.loadNFCAccessRule(tlv.getValue());
-                                                                       break;
-
-                                                               default :
-                                                                       SCARD_DEBUG_ERR("Unknown tag : 0x%02X", tlv.getTag());
-                                                                       break;
-                                                               }
-                                                       }
-                                                       else
-                                                       {
-                                                               SCARD_DEBUG_ERR("tlv.decodeTLV failed");
-                                                       }
-                                                       tlv.returnToParentTLV();
-                                                       break;
-
-                                               default :
-                                                       SCARD_DEBUG_ERR("Unknown tag : 0x%02X", tlv.getTag());
-                                                       break;
-                                               }
-                                       }
-                                       else
-                                       {
-                                               SCARD_DEBUG_ERR("tlv.decodeTLV failed");
-                                       }
-                                       tlv.returnToParentTLV();
-                               }
-                               else
-                               {
-                                       SCARD_DEBUG("access granted for all applications, aid : %s", aid.toString());
+               bool result = permission;
+               const AccessRule *rule = getAccessRule(certHash);
 
-                                       permission = true;
-                                       break;
-                               }
-                       }
+               if (rule != NULL) {
+                       result = true;
                }
-               else
-               {
-                       SCARD_DEBUG("access denied for all applications, aid : %s", aid.toString());
 
-                       permission = false;
-               }
+               return result;
        }
 
-       bool AccessCondition::isAuthorizedAccess(ByteArray &certHash)
+       void AccessCondition::setAPDUAccessRule(const ByteArray &certHash,
+               bool rule)
        {
-               bool result = false;
-
-               if (hashes.size() > 0)
-               {
-                       size_t i;
+               AccessRule *access = getAccessRule(certHash);
 
-                       for (i = 0; i < hashes.size(); i++)
-                       {
-                               if (certHash == hashes[i])
-                               {
-                                       result = true;
-                                       break;
-                               }
-                       }
-               }
-               else
-               {
-                       result = permission;
+               if (access != NULL) {
+                       access->setAPDUAccessRule(rule);
                }
+       }
 
-               return result;
+       void AccessCondition::addAPDUAccessRule(const ByteArray &certHash,
+               const ByteArray &apdu, const ByteArray &mask)
+       {
+               AccessRule *access = getAccessRule(certHash);
+
+               if (access != NULL) {
+                       access->addAPDUAccessRule(apdu, mask);
+               }
        }
 
-       bool AccessCondition::isAuthorizedAPDUAccess(ByteArray &command)
+       void AccessCondition::addAPDUAccessRule(const ByteArray &certHash,
+               const ByteArray &rule)
        {
-               bool result = false;
+               if (rule.size() != 8)
+                       return;
 
-               result = apduRule.isAuthorizedAccess(command);
+               addAPDUAccessRule(certHash, rule.sub(0, 4), rule.sub(4, 4));
+       }
 
-               return result;
+       void AccessCondition::setNFCAccessRule(const ByteArray &certHash,
+                       bool rule)
+       {
+               AccessRule *access = getAccessRule(certHash);
+
+               if (access != NULL) {
+                       access->setNFCAccessRule(rule);
+               }
        }
 
-       bool AccessCondition::isAuthorizedNFCAccess()
+       bool AccessCondition::isAuthorizedAPDUAccess(const ByteArray &certHash,
+               const ByteArray &command) const
        {
                bool result = false;
+               const AccessRule *rule = getAccessRule(certHash);
 
-               result = nfcRule.isAuthorizedAccess();
+               if (rule != NULL) {
+                       result = rule->isAuthorizedAPDUAccess(command);
+               }
 
                return result;
        }
 
-       void AccessCondition::printAccessConditions()
+       bool AccessCondition::isAuthorizedNFCAccess(const ByteArray &certHash) const
        {
-               SCARD_DEBUG(" +-- Access Condition");
-
-               if (hashes.size() > 0)
-               {
-                       size_t i;
+               bool result = false;
+               const AccessRule *rule = getAccessRule(certHash);
 
-                       for (i = 0; i < hashes.size(); i++)
-                       {
-                               SCARD_DEBUG(" +--- hash : %s", hashes[i].toString());
-                       }
-               }
-               else
-               {
-                       SCARD_DEBUG(" +--- permission : %s", permission ? "granted all" : "denied all");
+               if (rule != NULL) {
+                       result = rule->isAuthorizedNFCAccess();
                }
+
+               return result;
        }
 } /* namespace smartcard_service_api */
index 9ed93f1..2122eed 100644 (file)
 #include "Debug.h"
 #include "AccessControlList.h"
 #include "PKCS15.h"
-#include "AccessCondition.h"
 
 namespace smartcard_service_api
 {
-       const unsigned char aid_all[] = { 0x00, 0x00 };
-       const unsigned char aid_default[] = { 0x00, 0x01 };
+       const unsigned char all_se_apps[] = { 0x00, 0x00 };
+       const unsigned char default_se_app[] = { 0x00, 0x01 };
+       const unsigned char all_device_apps[] = { 0x00, 0x02 };
 
-       ByteArray AccessControlList::AID_ALL(ARRAY_AND_SIZE(aid_all));
-       ByteArray AccessControlList::AID_DEFAULT(ARRAY_AND_SIZE(aid_default));
+       ByteArray AccessControlList::ALL_SE_APPS(ARRAY_AND_SIZE(all_se_apps));
+       ByteArray AccessControlList::DEFAULT_SE_APP(ARRAY_AND_SIZE(default_se_app));
+       ByteArray AccessControlList::ALL_DEVICE_APPS(ARRAY_AND_SIZE(all_device_apps));
 
-       AccessControlList::AccessControlList()
+       AccessControlList::AccessControlList() : allGranted(false)
        {
-               allGranted = false;
        }
 
        AccessControlList::~AccessControlList()
@@ -49,82 +49,176 @@ namespace smartcard_service_api
                allGranted = false;
        }
 
-       bool AccessControlList::isAuthorizedAccess(ByteArray aid, ByteArray certHash, bool update)
+       AccessCondition &AccessControlList::getAccessCondition(const ByteArray &aid)
        {
-               bool result = allGranted;
-               map<ByteArray, AccessCondition>::iterator iterMap;
+               map<ByteArray, AccessCondition>::iterator item;
 
-               if (result == false)
+               item = mapConditions.find(aid);
+               if (item == mapConditions.end())
                {
-                       SCARD_DEBUG("aid : %s", aid.toString());
-                       SCARD_DEBUG("hash : %s", certHash.toString());
+                       AccessCondition condition;
+                       pair<ByteArray, AccessCondition> temp(aid, condition);
+                       mapConditions.insert(temp);
 
-                       /* null aid means default applet */
-                       if (aid.isEmpty() == true)
-                       {
-                               aid = AID_DEFAULT;
-                       }
+                       item = mapConditions.find(aid);
+               }
 
-                       /* first.. find hashes matched with aid */
-                       if ((iterMap = mapConditions.find(aid)) != mapConditions.end())
-                       {
-                               result = iterMap->second.isAuthorizedAccess(certHash);
-                       }
-                       /* finally.. find hashes in 'all' list */
-                       else if ((iterMap = mapConditions.find(AID_ALL)) != mapConditions.end())
-                       {
-                               result = iterMap->second.isAuthorizedAccess(certHash);
-                       }
+               return item->second;
+       }
+
+       const AccessRule *AccessControlList::findAccessRule(const ByteArray &aid,
+               const ByteArray &hash) const
+       {
+               const AccessRule *result = NULL;
+               map<ByteArray, AccessCondition>::const_iterator item;
+
+               item = mapConditions.find(aid);
+               if (item != mapConditions.end()) {
+                       result = item->second.getAccessRule(hash);
                }
 
                return result;
        }
 
-       bool AccessControlList::isAuthorizedAccess(ByteArray aid, ByteArray certHash)
+       bool AccessControlList::isAuthorizedAccess(const ByteArray &aid,
+               const ByteArray &certHash) const
        {
-               return isAuthorizedAccess(aid, certHash, true);
+               vector<ByteArray> hashes;
+
+               hashes.push_back(certHash);
+
+               return isAuthorizedAccess(aid, hashes);
+       }
+
+       bool AccessControlList::isAuthorizedAccess(const unsigned char *aidBuffer,
+               unsigned int aidLength, const unsigned char *certHashBuffer,
+               unsigned int certHashLength) const
+       {
+               ByteArray aid(aidBuffer, aidLength);
+               ByteArray certHash(certHashBuffer, certHashLength);
+
+               return isAuthorizedAccess(aid, certHash);
        }
 
-       bool AccessControlList::isAuthorizedAccess(unsigned char *aidBuffer, unsigned int aidLength, unsigned char *certHashBuffer, unsigned int certHashLength)
+       bool AccessControlList::isAuthorizedAccess(const ByteArray &aid,
+               const vector<ByteArray> &certHashes) const
        {
-               return isAuthorizedAccess(ByteArray(aidBuffer, aidLength), ByteArray(certHashBuffer, certHashLength), true);
+               return isAuthorizedAccess(aid, certHashes, ByteArray::EMPTY);
        }
 
-       bool AccessControlList::isAuthorizedAccess(ByteArray aid, vector<ByteArray> &certHashes)
+       bool AccessControlList::isAuthorizedAccess(const ByteArray &aid,
+               const vector<ByteArray> &certHashes, const ByteArray &command) const
        {
-               bool result;
-               size_t i;
+               bool result = allGranted;
+               vector<ByteArray>::const_reverse_iterator item;
+               const AccessRule *rule = NULL;
 
-               result = allGranted;
+               if (result == true) {
+                       goto END;
+               }
 
-               if (result == false)
-               {
-                       for (i = 0; result == false && i < certHashes.size(); i++)
-                       {
-                               result = isAuthorizedAccess(aid, certHashes[i], false);
+               /* Step A, find with aid and cert hashes */
+               for (item = certHashes.rbegin(); item != certHashes.rend(); item++) {
+                       rule = findAccessRule(aid, *item);
+                       if (rule != NULL) {
+                               if (command.isEmpty()) {
+                                       result = rule->isAuthorizedAccess();
+                               } else {
+                                       result = rule->isAuthorizedAPDUAccess(command);
+                               }
+                               _INFO("rule found (%s): [%s:%s]", result ? "accept" : "deny", aid.toString().c_str(), (*item).toString().c_str());
+                               goto END;
+                       }
+               }
+
+               /* Step B, find with aid and ALL_DEVICES_APPS */
+               rule = findAccessRule(aid, ALL_DEVICE_APPS);
+               if (rule != NULL) {
+                       if (command.isEmpty()) {
+                               result = rule->isAuthorizedAccess();
+                       } else {
+                               result = rule->isAuthorizedAPDUAccess(command);
+                       }
+                       _INFO("rule found (%s): [%s:%s]", result ? "accept" : "deny", aid.toString().c_str(), ALL_DEVICE_APPS.toString().c_str());
+                       goto END;
+               }
+
+               /* Step C, find with ALL_SE_APPS and hashes */
+               for (item = certHashes.rbegin(); item != certHashes.rend(); item++) {
+                       rule = findAccessRule(ALL_SE_APPS, *item);
+                       if (rule != NULL) {
+                               if (command.isEmpty()) {
+                                       result = rule->isAuthorizedAccess();
+                               } else {
+                                       result = rule->isAuthorizedAPDUAccess(command);
+                               }
+                               _INFO("rule found (%s): [%s:%s]", result ? "accept" : "deny", "All SE Applications", (*item).toString().c_str());
+                               goto END;
                        }
                }
 
+               /* Step D, find with ALL_SE_APPS and ALL_DEVICES_APPS */
+               rule = findAccessRule(ALL_SE_APPS, ALL_DEVICE_APPS);
+               if (rule != NULL) {
+                       if (command.isEmpty()) {
+                               result = rule->isAuthorizedAccess();
+                       } else {
+                               result = rule->isAuthorizedAPDUAccess(command);
+                       }
+                       _INFO("rule found (%s): [%s:%s]", result ? "accept" : "deny", "All SE Applications", "All device applications");
+               }
+
+END :
                return result;
        }
 
-       void AccessControlList::printAccessControlList()
+       bool AccessControlList::isAuthorizedNFCAccess(const ByteArray &aid,
+               const vector<ByteArray> &certHashes) const
        {
-               ByteArray temp;
+               bool result = allGranted;
+               vector<ByteArray>::const_reverse_iterator item;
+               const AccessRule *rule = NULL;
+
+               if (result == true) {
+                       goto END;
+               }
 
-               /* release map and vector */
-               map<ByteArray, AccessCondition>::iterator iterMap;
+               /* Step A, find with aid and cert hashes */
+               for (item = certHashes.rbegin(); item != certHashes.rend(); item++) {
+                       rule = findAccessRule(aid, *item);
+                       if (rule != NULL) {
+                               result = rule->isAuthorizedNFCAccess();
+                               _INFO("rule found (%s): [%s:%s]", result ? "accept" : "deny", aid.toString().c_str(), (*item).toString().c_str());
+                               goto END;
+                       }
+               }
 
-               SCARD_DEBUG("================ Certification Hashes ==================");
-               for (iterMap = mapConditions.begin(); iterMap != mapConditions.end(); iterMap++)
-               {
-                       temp = iterMap->first;
+               /* Step B, find with aid and ALL_DEVICES_APPS */
+               rule = findAccessRule(aid, ALL_DEVICE_APPS);
+               if (rule != NULL) {
+                       result = rule->isAuthorizedNFCAccess();
+                       _INFO("rule found (%s): [%s:%s]", result ? "accept" : "deny", aid.toString().c_str(), "All device applications");
+                       goto END;
+               }
 
-                       SCARD_DEBUG("+ aid : %s", (temp == AID_DEFAULT) ? "DEFAULT" : (temp == AID_ALL) ? "ALL" : temp.toString());
+               /* Step C, find with ALL_SE_APPS and hashes */
+               for (item = certHashes.rbegin(); item != certHashes.rend(); item++) {
+                       rule = findAccessRule(ALL_SE_APPS, *item);
+                       if (rule != NULL) {
+                               result = rule->isAuthorizedNFCAccess();
+                               _INFO("rule found (%s): [%s:%s]", result ? "accept" : "deny", "All SE Applications", (*item).toString().c_str());
+                               goto END;
+                       }
+               }
 
-                       iterMap->second.printAccessConditions();
+               /* Step D, find with ALL_SE_APPS and ALL_DEVICES_APPS */
+               rule = findAccessRule(ALL_SE_APPS, ALL_DEVICE_APPS);
+               if (rule != NULL) {
+                       result = rule->isAuthorizedNFCAccess();
+                       _INFO("rule found (%s): [%s:%s]", result ? "accept" : "deny", "All SE Applications", "All device applications");
                }
-               SCARD_DEBUG("========================================================");
-       }
 
+END :
+               return result;
+       }
 } /* namespace smartcard_service_api */
index 745800f..0f26704 100644 (file)
  */
 
 /* standard library header */
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
+#include <cstdio>
+#include <cstring>
+#include <cerrno>
+#include <sstream>
 
 /* SLP library header */
 
@@ -29,134 +30,172 @@ namespace smartcard_service_api
 {
        ByteArray ByteArray::EMPTY = ByteArray();
 
-       ByteArray::ByteArray()
+       ByteArray::ByteArray() : buffer(NULL), length(0)
        {
-               buffer = NULL;
-               length = 0;
        }
 
-       ByteArray::ByteArray(uint8_t *array, uint32_t bufferLen)
+       ByteArray::ByteArray(const uint8_t *array, size_t size) :
+               buffer(NULL), length(0)
        {
-               buffer = NULL;
-               length = 0;
-
-               setBuffer(array, bufferLen);
+               assign(array, size);
        }
 
-       ByteArray::ByteArray(const ByteArray &T)
+       ByteArray::ByteArray(const ByteArray &T) : buffer(NULL), length(0)
        {
-               buffer = NULL;
-               length = 0;
-
-               setBuffer(T.buffer, T.length);
+               assign(T.buffer, T.length);
        }
 
        ByteArray::~ByteArray()
        {
-               releaseBuffer();
+               clear();
        }
 
-       bool ByteArray::setBuffer(uint8_t *array, uint32_t bufferLen)
+       bool ByteArray::assign(const uint8_t *array, size_t size)
        {
-               if (array == NULL || bufferLen == 0)
+               if (array == NULL || size == 0)
                {
                        return false;
                }
 
-               releaseBuffer();
+               clear();
 
-               buffer = new uint8_t[bufferLen];
+               buffer = new uint8_t[size];
                if (buffer == NULL)
                {
-                       SCARD_DEBUG_ERR("alloc failed");
+                       _ERR("alloc failed");
                        return false;
                }
 
-               memcpy(buffer, array, bufferLen);
-               length = bufferLen;
+               memcpy(buffer, array, size);
+               length = size;
 
                return true;
        }
 
-       bool ByteArray::_setBuffer(uint8_t *array, uint32_t bufferLen)
+       bool ByteArray::_assign(uint8_t *array, size_t size)
        {
-               if (array == NULL || bufferLen == 0)
+               if (array == NULL || size == 0)
                {
                        return false;
                }
 
-               releaseBuffer();
+               clear();
 
                buffer = array;
-               length = bufferLen;
+               length = size;
 
                return true;
        }
 
-       uint32_t ByteArray::getLength() const
+       size_t ByteArray::size() const
        {
                return length;
        }
 
-       uint8_t *ByteArray::getBuffer() const
+       uint8_t *ByteArray::getBuffer()
        {
                return getBuffer(0);
        }
 
-       uint8_t *ByteArray::getBuffer(uint32_t offset) const
+       const uint8_t *ByteArray::getBuffer() const
+       {
+               return getBuffer(0);
+       }
+
+       uint8_t *ByteArray::getBuffer(size_t offset)
        {
                if (length == 0)
                        return NULL;
 
                if (offset >= length)
                {
-                       SCARD_DEBUG_ERR("buffer overflow, offset [%d], length [%d]", offset, length);
+                       _ERR("buffer overflow, offset [%d], length [%d]", offset, length);
                        return NULL;
                }
 
                return buffer + offset;
        }
 
-       uint8_t ByteArray::getAt(uint32_t index) const
+       const uint8_t *ByteArray::getBuffer(size_t offset) const
+       {
+               if (length == 0)
+                       return NULL;
+
+               if (offset >= length)
+               {
+                       _ERR("buffer overflow, offset [%d], length [%d]", offset, length);
+                       return NULL;
+               }
+
+               return buffer + offset;
+       }
+
+       uint8_t ByteArray::at(size_t index) const
        {
                if (index >= length)
                {
-                       SCARD_DEBUG_ERR("buffer overflow, index [%d], length [%d]", index, length);
-                       return buffer[length -1];
+                       _ERR("buffer overflow, index [%d], length [%d]", index, length);
+                       if (length > 0)
+                       {
+                               return buffer[length - 1];
+                       }
+                       else
+                       {
+                               return 0;
+                       }
                }
 
                return buffer[index];
        }
 
-       uint8_t ByteArray::getReverseAt(uint32_t index) const
+       uint8_t ByteArray::reverseAt(size_t index) const
        {
                if (index >= length)
                {
-                       SCARD_DEBUG_ERR("buffer underflow, index [%d], length [%d]", index, length);
-                       return buffer[0];
+                       _ERR("buffer underflow, index [%d], length [%d]", index, length);
+                       if (length > 0)
+                       {
+                               return buffer[0];
+                       }
+                       else
+                       {
+                               return 0;
+                       }
                }
 
                return buffer[length - index - 1];
        }
 
-       uint32_t ByteArray::copyFromArray(uint8_t *array, uint32_t bufferLen) const
+       size_t ByteArray::extract(uint8_t *array, size_t size) const
        {
                uint32_t min_len = 0;
 
-               if (array == NULL || bufferLen == 0)
+               if (array == NULL || size == 0)
                {
-                       SCARD_DEBUG_ERR("invaild param");
-                       return false;
+                       _ERR("invalid param");
+                       return min_len;
                }
 
-               min_len = (bufferLen < length) ? bufferLen : length;
+               min_len = (size < length) ? size : length;
 
                memcpy(array, buffer, min_len);
 
                return min_len;
        }
 
-       void ByteArray::releaseBuffer()
+       const ByteArray ByteArray::sub(size_t offset, size_t size) const
+       {
+               if (length == 0 || offset >= length || (offset + size) > length)
+               {
+                       _DBG("length is zero");
+
+                       return ByteArray();
+               }
+
+               return ByteArray(buffer + offset, size);
+       }
+
+       void ByteArray::clear()
        {
                if (buffer != NULL)
                {
@@ -169,13 +208,13 @@ namespace smartcard_service_api
        /* operator overloading */
        ByteArray ByteArray::operator +(const ByteArray &T)
        {
-               uint32_t newLen;
+               size_t newLen;
                uint8_t *newBuffer;
                ByteArray newArray;
 
                if (length == 0)
                {
-                       SCARD_DEBUG("length is zero");
+                       _DBG("length is zero");
 
                        return T;
                }
@@ -191,7 +230,7 @@ namespace smartcard_service_api
                if (newBuffer == NULL)
                {
                        /* assert.... */
-                       SCARD_DEBUG_ERR("alloc failed");
+                       _ERR("alloc failed");
 
                        return *this;
                }
@@ -199,7 +238,7 @@ namespace smartcard_service_api
                memcpy(newBuffer, buffer, length);
                memcpy(newBuffer + length, T.buffer, T.length);
 
-               newArray._setBuffer(newBuffer, newLen);
+               newArray._assign(newBuffer, newLen);
 
                return newArray;
        }
@@ -208,7 +247,7 @@ namespace smartcard_service_api
        {
                if (this != &T)
                {
-                       setBuffer(T.buffer, T.length);
+                       assign(T.buffer, T.length);
                }
 
                return *this;
@@ -244,29 +283,32 @@ namespace smartcard_service_api
                return (memcmp(buffer, T.buffer, (length < T.length) ? length : T.length) > 0);
        }
 
-       uint8_t &ByteArray::operator [](uint32_t index) const
+       uint8_t ByteArray::operator [](size_t index) const
        {
                if (index >= length)
                {
-                       SCARD_DEBUG_ERR("buffer overflow, index [%d], length [%d]", index, length);
-                       return buffer[length -1];
+                       _ERR("buffer overflow, index [%d], length [%d]", index, length);
+                       if (length > 0)
+                       {
+                               return buffer[length -1];
+                       }
+                       else
+                       {
+                               return 0;
+                       }
                }
 
                return buffer[index];
        }
-
-       const char *ByteArray::toString()
+       const string ByteArray::toString() const
        {
-               memset(strBuffer, 0, sizeof(strBuffer));
+               stringstream ss;
 
-               if (length == 0)
-               {
-                       snprintf(strBuffer, sizeof(strBuffer), "buffer is empty");
-               }
-               else
+               if (length > 0)
                {
+                       char temp[20];
                        int count;
-                       int i, offset = 0;
+                       int i = 0;
                        bool ellipsis = false;
 
                        count = length;
@@ -276,26 +318,27 @@ namespace smartcard_service_api
                                ellipsis = true;
                        }
 
-                       snprintf(strBuffer + offset, sizeof(strBuffer) - offset, "{ ");
-                       offset += 2;
+                       ss << "{ ";
 
                        for (i = 0; i < count; i++)
                        {
-                               snprintf(strBuffer + offset, sizeof(strBuffer) - offset, "%02X ", buffer[i]);
-                               offset += 3;
+                               snprintf(temp, sizeof(temp), "%02X ", buffer[i]);
+                               ss << temp;
                        }
 
                        if (ellipsis)
                        {
-                               snprintf(strBuffer + offset, sizeof(strBuffer) - offset, "... }");
-                       }
-                       else
-                       {
-                               snprintf(strBuffer + offset, sizeof(strBuffer) - offset, "}");
+                               ss << "... ";
                        }
+
+                       ss << "}";
+               }
+               else
+               {
+                       ss << "buffer is empty";
                }
 
-               return (const char *)strBuffer;
+               return ss.str();
        }
 
        void ByteArray::save(const char *filePath)
@@ -309,13 +352,11 @@ namespace smartcard_service_api
                {
                        fwrite(buffer, 1, length, file);
                        fflush(file);
-
                        fclose(file);
-                       SCARD_DEBUG("file has written, file [%s], length[%d]", filePath, length);
                }
                else
                {
-                       SCARD_DEBUG_ERR("file open failed, [%d]", errno);
+                       _ERR("file open failed, [%d]", errno);
                }
        }
 
index 3894b38..0c77a9b 100644 (file)
@@ -10,12 +10,12 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
 AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SRCS)
 
 #IF("${CMAKE_BUILD_TYPE}" STREQUAL "")
-#        SET(CMAKE_BUILD_TYPE "Debug")
+#      SET(CMAKE_BUILD_TYPE "Debug")
 #ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "")
 #MESSAGE("Build type: ${CMAKE_BUILD_TYPE}")
 
 INCLUDE(FindPkgConfig)
-pkg_check_modules(pkgs_common REQUIRED dlog glib-2.0 aul libssl pkgmgr pkgmgr-info)
+pkg_check_modules(pkgs_common REQUIRED glib-2.0 gio-unix-2.0 dlog aul libssl pkgmgr pkgmgr-info)
 
 MESSAGE("${LIB_NAME} ld flag : ${pkgs_common_LDFLAGS}")
 
@@ -24,13 +24,11 @@ FOREACH(flag ${pkgs_common_CFLAGS})
        SET(EXTRA_CXXFLAGS "${EXTRA_CXXFLAGS} ${flag}")
 ENDFOREACH(flag)
 
-#SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -finstrument-functions")
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -finstrument-functions")
 #SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
 #SET(CMAKE_C_FLAGS_RELEASE "-O2")
 
-#SET(EXTRA_CXXFLAGS "${EXTRA_CXXFLAGS} -finstrument-functions -std=c++0x")
-SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CXXFLAGS}")
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CXXFLAGS} -finstrument-functions -std=c++0x")
 #SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")
 #SET(CMAKE_CXX_FLAGS_RELEASE "-O2")
 
@@ -41,8 +39,6 @@ IF("${ARCH}" STREQUAL "arm")
        MESSAGE("add -DTARGET")
 ENDIF("${ARCH}" STREQUAL "arm")
 
-MESSAGE("CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}")
-
 ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"")
 ADD_DEFINITIONS("-DSLP_DEBUG")
 ADD_DEFINITIONS("-DUSE_UNIX_DOMAIN")
@@ -57,25 +53,20 @@ SET_TARGET_PROPERTIES(${LIB_NAME} PROPERTIES VERSION ${VERSION})
 
 TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_common_LDFLAGS})
 
-SET(EXPORT_HEADER 
+SET(EXPORT_HEADER
+       include/smartcard-types.h
        include/Debug.h
        include/Exception.h
        include/ByteArray.h
        include/Lock.h
-       include/Synchronous.h   
+       include/Synchronous.h
        include/TerminalInterface.h
        include/Terminal.h
        include/SignatureHelper.h
-       include/GPSEACL.h
 )
 
-CONFIGURE_FILE(
-     ${CMAKE_CURRENT_SOURCE_DIR}/${LIB_NAME}.pc.in
-    ${CMAKE_CURRENT_SOURCE_DIR}/${LIB_NAME}.pc
-    @ONLY
-)
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${LIB_NAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
 INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR})
 FOREACH(hfile ${EXPORT_HEADER})
-        INSTALL(FILES ${hfile} DESTINATION include/${LIB_NAME})
+       INSTALL(FILES ${hfile} DESTINATION include/${LIB_NAME})
 ENDFOREACH(hfile)
index a4b5510..208b2e2 100644 (file)
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 
+#ifndef USE_GDBUS
 /* standard library header */
 #include <stdio.h>
 #include <string.h>
@@ -60,7 +61,7 @@ namespace smartcard_service_api
                }
        }
 
-       void DispatcherHelper::pushMessage(DispatcherMsg *msg)
+       void DispatcherHelper::pushMessage(const DispatcherMsg &msg)
        {
                DispatcherMsg *pushMsg = new DispatcherMsg(msg);
 
@@ -117,17 +118,17 @@ namespace smartcard_service_api
 
                        if ((ret = pthread_create(&dispatcherThread, &attr, &DispatcherHelper::_dispatcherThreadFunc, this)) != 0)
                        {
-                               SCARD_DEBUG_ERR("pthread_create failed [%d]", ret);
+                               _ERR("pthread_create failed [%d]", ret);
                        }
                        else
                        {
-                               SCARD_DEBUG("pthread_create success");
+                               _DBG("pthread_create success");
                                result = true;
                        }
                }
                else
                {
-                       SCARD_DEBUG("thread already start");
+                       _DBG("thread already start");
                        result = true;
                }
 
@@ -144,3 +145,4 @@ namespace smartcard_service_api
        }
 
 } /* namespace smartcard_service_api */
+#endif
index 16dfc54..e6035e5 100644 (file)
 
 namespace smartcard_service_api
 {
+       static unsigned char path_efdir[] = { 0x2f, 0x00 };
+       static ByteArray PATH_EFDIR(ARRAY_AND_SIZE(path_efdir));
+
        EFDIR::EFDIR(Channel *channel) : FileObject(channel)
        {
-               unsigned char path[] = { 0x2f, 0x00 };
-               ByteArray dirPath(ARRAY_AND_SIZE(path));
-               int ret;
-
-               ret = select(dirPath, false);
-               if (ret == FileObject::SUCCESS)
-               {
-                       SCARD_DEBUG("response : %s", selectResponse.toString());
-               }
-               else
-               {
-                       SCARD_DEBUG_ERR("EFDIR select failed, [%d]", ret);
-               }
        }
 
-       EFDIR::EFDIR(Channel *channel, ByteArray selectResponse)
-               FileObject(channel, selectResponse)
+       EFDIR::EFDIR(Channel *channel, const ByteArray &selectResponse) :
+               FileObject(channel, selectResponse)
        {
        }
 
@@ -53,7 +43,20 @@ namespace smartcard_service_api
        {
        }
 
-       ByteArray EFDIR::parseRecord(Record &record, ByteArray &aid)
+       int EFDIR::select()
+       {
+               int ret;
+
+               ret = FileObject::select(PATH_EFDIR, false);
+               if (ret < SCARD_ERROR_OK)
+               {
+                       _ERR("EFDIR select failed, [%d]", ret);
+               }
+
+               return ret;
+       }
+
+       const ByteArray EFDIR::parseRecord(const Record &record, const ByteArray &aid)
        {
                bool matched = false;
                ByteArray result;
@@ -83,18 +86,18 @@ namespace smartcard_service_api
 
                        if (matched == true)
                        {
-                               SCARD_DEBUG("Found!! : path %s", result.toString());
+                               _DBG("Found!! : path %s", result.toString().c_str());
                        }
                        else
                        {
-                               result.setBuffer(NULL, 0);
+                               result.clear();
                        }
                }
 
                return result;
        }
 
-       ByteArray EFDIR::getPathByAID(ByteArray &aid)
+       const ByteArray EFDIR::getPathByAID(const ByteArray &aid)
        {
                ByteArray result;
                Record record;
@@ -107,7 +110,7 @@ namespace smartcard_service_api
                        if (status >= 0)
                        {
                                result = parseRecord(record, aid);
-                               if (result.getLength() > 0)
+                               if (result.size() > 0)
                                        break;
                        }
                }
index 1771dea..11d2279 100644 (file)
@@ -15,8 +15,9 @@
  */
 
 /* standard library header */
-#include <stdio.h>
-#include <string.h>
+#include <cstdio>
+#include <cstring>
+#include <sstream>
 
 /* SLP library header */
 
@@ -35,7 +36,7 @@ namespace smartcard_service_api
                resetMemberVar();
        }
 
-       FCP::FCP(ByteArray &array)
+       FCP::FCP(const ByteArray &array)
        {
                resetMemberVar();
 
@@ -59,28 +60,28 @@ namespace smartcard_service_api
                lcs = FCI::INFO_NOT_AVAILABLE;
        }
 
-       bool FCP::setFCP(ByteArray array)
+       bool FCP::setFCP(const ByteArray &array)
        {
                bool result = false;
                SimpleTLV tlv;
 
-               SCARD_BEGIN();
+               _BEGIN();
 
                releaseFCP();
 
-               if (array.getLength() == 0)
+               if (array.size() == 0)
                        return false;
 
                fcpBuffer = array;
 
                if (fcpBuffer[0] != 0x62)
                {
-                       SCARD_DEBUG_ERR("it is not FCP response [%02X]", fcpBuffer[0]);
+                       _ERR("it is not FCP response [%02X]", fcpBuffer[0]);
                        return false;
                }
 
                /* parse... */
-               tlv.setTLVBuffer(fcpBuffer.getBuffer(), fcpBuffer.getLength());
+               tlv.setTLVBuffer(fcpBuffer.getBuffer(), fcpBuffer.size());
 
                if (tlv.decodeTLV())
                {
@@ -90,20 +91,20 @@ namespace smartcard_service_api
                        {
                                switch (tlv.getTag())
                                {
-                               case 0x80 : /* file length without sturctural inforamtion */
+                               case 0x80 : /* file length without structural information */
                                        {
-                                               SCARD_DEBUG("0x%02X : file length without sturctural inforamtion : %s", tlv.getTag(), tlv.getValue().toString());
-                                               if (tlv.getLength() > 0)
+                                               _DBG("0x%02X : file length without structural information : %s", tlv.getTag(), tlv.getValue().toString().c_str());
+                                               if (tlv.size() > 0)
                                                {
                                                        fileSize = NumberStream::getBigEndianNumber(tlv.getValue());
                                                }
                                        }
                                        break;
 
-                               case 0x81 : /* file length with sturctural inforamtion */
+                               case 0x81 : /* file length with structural information */
                                        {
-                                               SCARD_DEBUG("0x%02X : file length with sturctural inforamtion : %s", tlv.getTag(), tlv.getValue().toString());
-                                               if (tlv.getLength() > 0)
+                                               _DBG("0x%02X : file length with structural information : %s", tlv.getTag(), tlv.getValue().toString().c_str());
+                                               if (tlv.size() > 0)
                                                {
                                                        maxRecordSize = NumberStream::getBigEndianNumber(tlv.getValue());
                                                }
@@ -112,162 +113,152 @@ namespace smartcard_service_api
 
                                case 0x82 : /* file descriptor bytes */
                                        {
-                                               SCARD_DEBUG("0x%02X : file descriptor bytes : %s", tlv.getTag(), tlv.getValue().toString());
+                                               _DBG("0x%02X : file descriptor bytes : %s", tlv.getTag(), tlv.getValue().toString().c_str());
        //                                      ByteArray value = tlv.getValue();
                                        }
                                        break;
 
                                case 0x83 : /* file identifier */
                                        {
-                                               SCARD_DEBUG("0x%02X : file identifier : %s", tlv.getTag(), tlv.getValue().toString());
-                                               if (tlv.getLength() > 0)
+                                               _DBG("0x%02X : file identifier : %s", tlv.getTag(), tlv.getValue().toString().c_str());
+                                               if (tlv.size() > 0)
                                                {
                                                        ByteArray value = tlv.getValue();
 
                                                        fid = 0;
 
-                                                       memcpy(&fid, value.getBuffer(), value.getLength());
+                                                       memcpy(&fid, value.getBuffer(), value.size());
                                                }
                                        }
                                        break;
 
                                case 0x84 : /* DF name */
                                        {
-                                               SCARD_DEBUG("0x%02X : DF name : %s", tlv.getTag(), tlv.getValue().toString());
        //                                      ByteArray value = tlv.getValue();
                                        }
                                        break;
 
                                case 0x85 : /* proprietary information not encoded in BER-TLV */
                                        {
-                                               SCARD_DEBUG("0x%02X : proprietary information not encoded in BER-TLV : %s", tlv.getTag(), tlv.getValue().toString());
+                                               _DBG("0x%02X : proprietary information not encoded in BER-TLV : %s", tlv.getTag(), tlv.getValue().toString().c_str());
        //                                      ByteArray value = tlv.getValue();
                                        }
                                        break;
 
                                case 0x86 : /* Security attribute in proprietary format */
                                        {
-                                               SCARD_DEBUG("0x%02X : Security attribute in proprietary format : %s", tlv.getTag(), tlv.getValue().toString());
        //                                      ByteArray value = tlv.getValue();
                                        }
                                        break;
 
                                case 0x87 : /* Identifier of an EF containing an extension of the file control information */
                                        {
-                                               SCARD_DEBUG("0x%02X : Identifier of an EF containing an extension of the file control information : %s", tlv.getTag(), tlv.getValue().toString());
+                                               _DBG("0x%02X : Identifier of an EF containing an extension of the file control information : %s", tlv.getTag(), tlv.getValue().toString().c_str());
        //                                      ByteArray value = tlv.getValue();
                                        }
                                        break;
 
                                case 0x88 : /* Short EF identifier */
                                        {
-                                               SCARD_DEBUG("0x%02X : Short EF identifier : %s", tlv.getTag(), tlv.getValue().toString());
+                                               _DBG("0x%02X : Short EF identifier : %s", tlv.getTag(), tlv.getValue().toString().c_str());
 
-                                               if (tlv.getLength() > 0)
+                                               if (tlv.size() > 0)
                                                {
                                                        ByteArray value = tlv.getValue();
 
                                                        sfi = 0;
 
-                                                       memcpy(&sfi, value.getBuffer(), value.getLength());
+                                                       memcpy(&sfi, value.getBuffer(), value.size());
                                                }
                                        }
                                        break;
 
                                case 0x8A : /* life cycle status byte */
                                        {
-                                               SCARD_DEBUG("0x%02X : life cycle status byte : %s", tlv.getTag(), tlv.getValue().toString());
-                                               if (tlv.getLength() > 0)
+                                               _DBG("0x%02X : life cycle status byte : %s", tlv.getTag(), tlv.getValue().toString().c_str());
+                                               if (tlv.size() > 0)
                                                {
                                                        ByteArray value = tlv.getValue();
 
                                                        lcs = 0;
 
-                                                       memcpy(&lcs, value.getBuffer(), value.getLength());
+                                                       memcpy(&lcs, value.getBuffer(), value.size());
                                                }
                                        }
                                        break;
 
                                case 0x8B : /* Security attribute referencing the expanded format */
                                        {
-                                               SCARD_DEBUG("0x%02X : Security attribute referencing the expanded format : %s", tlv.getTag(), tlv.getValue().toString());
        //                                      ByteArray value = tlv.getValue();
                                        }
                                        break;
 
                                case 0x8C : /* Security attribute in compact format */
                                        {
-                                               SCARD_DEBUG("0x%02X : Security attribute in compact format : %s", tlv.getTag(), tlv.getValue().toString());
        //                                      ByteArray value = tlv.getValue();
                                        }
                                        break;
 
                                case 0x8D : /* Identifier of an EF containing security environment templates */
                                        {
-                                               SCARD_DEBUG("0x%02X : Identifier of an EF containing security environment templates : %s", tlv.getTag(), tlv.getValue().toString());
        //                                      ByteArray value = tlv.getValue();
                                        }
                                        break;
 
                                case 0x8E : /* Channel security attribute */
                                        {
-                                               SCARD_DEBUG("0x%02X : Channel security attribute : %s", tlv.getTag(), tlv.getValue().toString());
        //                                      ByteArray value = tlv.getValue();
                                        }
                                        break;
 
                                case 0xA0 : /* Security attribute template for data objects */
                                        {
-                                               SCARD_DEBUG("0x%02X : Security attribute template for data objects : %s", tlv.getTag(), tlv.getValue().toString());
        //                                      ByteArray value = tlv.getValue();
                                        }
                                        break;
 
                                case 0xA1 : /* Security attribute template in proprietary format */
                                        {
-                                               SCARD_DEBUG("0x%02X : Security attribute template in proprietary format : %s", tlv.getTag(), tlv.getValue().toString());
        //                                      ByteArray value = tlv.getValue();
                                        }
                                        break;
 
                                case 0xA2 : /* Template consisting of one or more pairs of data objects */
                                        {
-                                               SCARD_DEBUG("0x%02X : Template consisting of one or more pairs of data objects : %s", tlv.getTag(), tlv.getValue().toString());
+                                               _DBG("0x%02X : Template consisting of one or more pairs of data objects : %s", tlv.getTag(), tlv.getValue().toString().c_str());
        //                                      ByteArray value = tlv.getValue();
                                        }
                                        break;
 
                                case 0xA5 : /* proprietary information encoded in BER-TLV */
                                        {
-                                               SCARD_DEBUG("0x%02X : proprietary information encoded in BER-TLV : %s", tlv.getTag(), tlv.getValue().toString());
+                                               _DBG("0x%02X : proprietary information encoded in BER-TLV : %s", tlv.getTag(), tlv.getValue().toString().c_str());
        //                                      ByteArray value = tlv.getValue();
                                        }
                                        break;
 
                                case 0xAB : /* Security attribute template in expanded format */
                                        {
-                                               SCARD_DEBUG("0x%02X : Security attribute template in expanded format : %s", tlv.getTag(), tlv.getValue().toString());
        //                                      ByteArray value = tlv.getValue();
                                        }
                                        break;
 
                                case 0xAC : /* Cryptographic mechanism identifier template */
                                        {
-                                               SCARD_DEBUG("0x%02X : Cryptographic mechanism identifier template : %s", tlv.getTag(), tlv.getValue().toString());
+                                               _DBG("0x%02X : Cryptographic mechanism identifier template : %s", tlv.getTag(), tlv.getValue().toString().c_str());
        //                                      ByteArray value = tlv.getValue();
                                        }
                                        break;
 
                                case 0xC6 : /* PIN status template DO */
                                        {
-                                               SCARD_DEBUG("0x%02X : PIN status template DO : %s", tlv.getTag(), tlv.getValue().toString());
        //                                      ByteArray value = tlv.getValue();
                                        }
                                        break;
 
                                default :
                                        {
-                                               SCARD_DEBUG("0x%02X : unknown : %s", tlv.getTag(), tlv.getValue().toString());
+                                               _DBG("0x%02X : unknown : %s", tlv.getTag(), tlv.getValue().toString().c_str());
                                        }
                                        break;
                                }
@@ -276,79 +267,103 @@ namespace smartcard_service_api
                }
                else
                {
-                       SCARD_DEBUG_ERR("tlv.decodeTLV failed");
+                       _ERR("tlv.decodeTLV failed");
                }
 
-               SCARD_END();
+               _END();
 
                return result;
        }
 
-       ByteArray FCP::getFCP()
+       const ByteArray FCP::getFCP() const
        {
                return fcpBuffer;
        }
 
        void FCP::releaseFCP()
        {
-               fcpBuffer.releaseBuffer();
+               fcpBuffer.clear();
 
                resetMemberVar();
        }
 
-       unsigned int FCP::getFileSize()
+       int FCP::getFileSize() const
        {
                return fileSize;
        }
 
-       unsigned int FCP::getTotalFileSize()
+       int FCP::getTotalFileSize() const
        {
                return totalFileSize;
        }
 
-       unsigned int FCP::getFID()
+       int FCP::getFID() const
        {
                return fid;
        }
 
-       unsigned int FCP::getSFI()
+       int FCP::getSFI() const
        {
                return sfi;
        }
 
-       unsigned int FCP::getMaxRecordSize()
+       int FCP::getMaxRecordSize() const
        {
                return maxRecordSize;
        }
 
-       unsigned int FCP::getNumberOfRecord()
+       int FCP::getNumberOfRecord() const
        {
                return numberOfRecord;
        }
 
-       unsigned int FCP::getFileType()
+       int FCP::getFileType() const
        {
                return fileType;
        }
 
-       unsigned int FCP::getFileStructure()
+       int FCP::getFileStructure() const
        {
                return fileStructure;
        }
 
-       unsigned int FCP::getLCS()
+       int FCP::getLCS() const
        {
                return lcs;
        }
 
-       const char *FCP::toString()
+       const string FCP::toString() const
        {
-               memset(strBuffer, 0, sizeof(strBuffer));
+               stringstream ss;
 
-               snprintf(strBuffer, sizeof(strBuffer), "size [%d], total size [%d], fid [%x], sfi [%x], max rec [%d], n of rec [%d], type [%d], struct [%d], lcs [%d]",
-                       getFileSize(), getTotalFileSize(), getFID(), getSFI(), getMaxRecordSize(), getNumberOfRecord(), getFileType(), getFileStructure(), getLCS());
+               if (fileSize != FCI::INFO_NOT_AVAILABLE)
+                       ss << "size [" << fileSize << "], ";
 
-               return (const char *)strBuffer;
+               if (totalFileSize != FCI::INFO_NOT_AVAILABLE)
+                       ss << "total size [" << totalFileSize << "], ";
+
+               if (fid != FCI::INFO_NOT_AVAILABLE)
+                       ss << "fid [" << fid << "], ";
+
+               if (sfi != FCI::INFO_NOT_AVAILABLE)
+                       ss << "sfi [" << sfi << "], ";
+
+               if (maxRecordSize != FCI::INFO_NOT_AVAILABLE)
+                       ss << "max rec. [" << maxRecordSize << "], ";
+
+               if (numberOfRecord != FCI::INFO_NOT_AVAILABLE)
+                       ss << "n of rec [" << numberOfRecord << "], ";
+
+               if (fileType != FCI::INFO_NOT_AVAILABLE)
+                       ss << "type [" << fileType << "], ";
+
+               if (fileStructure != FCI::INFO_NOT_AVAILABLE)
+                       ss << "struct [" << fileStructure << "], ";
+
+               if (lcs != FCI::INFO_NOT_AVAILABLE)
+                       ss << "lcs [" << lcs << "], ";
+
+               return ss.str();
        }
 
 
@@ -371,7 +386,7 @@ namespace smartcard_service_api
        {
        }
 
-       bool FCI::setFCIBuffer(ByteArray array)
+       bool FCI::setFCIBuffer(const ByteArray &array)
        {
                bool result = false;
 
index e93e459..46112f1 100644 (file)
@@ -32,7 +32,7 @@ namespace smartcard_service_api
                opened = false;
        }
 
-       FileObject::FileObject(Channel *channel, ByteArray selectResponse)
+       FileObject::FileObject(Channel *channel, const ByteArray &selectResponse)
                : ProviderHelper(channel)
        {
                opened = false;
@@ -47,51 +47,51 @@ namespace smartcard_service_api
        void FileObject::close()
        {
                opened = false;
-               selectResponse.releaseBuffer();
+               selectResponse.clear();
        }
 
-       bool FileObject::setSelectResponse(ByteArray &response)
+       bool FileObject::setSelectResponse(const ByteArray &response)
        {
                bool result = false;
 
-               if (response.getLength() >= 2)
+               if (response.size() >= 2)
                {
                        ResponseHelper resp(response);
                        selectResponse = response;
 
-                       if (resp.getStatus() == 0)
+                       if (resp.getStatus() >= 0)
                        {
                                fcp.releaseFCP();
 
                                fcp.setFCP(resp.getDataField());
 
-                               SCARD_DEBUG("FCP : %s", fcp.toString());
+                               _DBG("FCP : %s", fcp.toString().c_str());
 
                                opened = true;
                                result = true;
                        }
                        else
                        {
-                               SCARD_DEBUG_ERR("status word [%d][ %02X %02X ]",
-                                       resp.getStatus(), resp.getSW1(), resp.getSW2());
+                               _ERR("status word [ %02X %02X ]",
+                                       resp.getSW1(), resp.getSW2());
                        }
                }
                else
                {
-                       SCARD_DEBUG_ERR("invalid response : %s", response.toString());
+                       _ERR("invalid response");
                }
 
                return result;
        }
 
-       int FileObject::_select(ByteArray command)
+       int FileObject::_select(const ByteArray &command)
        {
                int ret = ERROR_ILLEGAL_STATE;
                ByteArray result;
 
                if (channel == NULL || channel->isClosed())
                {
-                       SCARD_DEBUG_ERR("channel is not open");
+                       _ERR("channel is not open");
 
                        return ret;
                }
@@ -103,27 +103,17 @@ namespace smartcard_service_api
                {
                        ResponseHelper resp(result);
 
-                       if (resp.getStatus() == 0)
-                       {
-                               if (setSelectResponse(result) == true)
-                               {
-                                       opened = true;
-                                       ret = SUCCESS;
-                               }
-                               else
-                               {
-                                       ret = ERROR_ILLEGAL_STATE;
-                               }
-                       }
-                       else if (resp.getStatus() == ResponseHelper::ERROR_FILE_NOT_FOUND)
+                       ret = resp.getStatus();
+
+                       if (setSelectResponse(result) == true)
                        {
-                               ret = ResponseHelper::ERROR_FILE_NOT_FOUND;
+                               opened = true;
                        }
                }
                else
                {
-                       SCARD_DEBUG_ERR("select apdu is failed, rv [%d], length [%d]",
-                               ret, result.getLength());
+                       _ERR("select apdu is failed, rv [%d], length [%d]",
+                               ret, result.size());
 
                        ret = ERROR_ILLEGAL_STATE;
                }
@@ -131,7 +121,7 @@ namespace smartcard_service_api
                return ret;
        }
 
-       int FileObject::select(ByteArray aid)
+       int FileObject::select(const ByteArray &aid)
        {
                int ret = ERROR_ILLEGAL_STATE;
                ByteArray command;
@@ -144,7 +134,7 @@ namespace smartcard_service_api
                return ret;
        }
 
-       int FileObject::select(ByteArray path, bool fromCurrentDF)
+       int FileObject::select(const ByteArray &path, bool fromCurrentDF)
        {
                int ret = ERROR_ILLEGAL_STATE;
                ByteArray command;
@@ -158,10 +148,10 @@ namespace smartcard_service_api
                {
                        ByteArray temp(path);
 
-                       if (path.getLength() > 2 && path[0] == 0x3f && path[1] == 0x00) /* check MF */
+                       if (path.size() > 2 && path[0] == 0x3f && path[1] == 0x00) /* check MF */
                        {
                                /* remove MF from path */
-                               temp.setBuffer(path.getBuffer(2), path.getLength() - 2);
+                               temp.assign(path.getBuffer(2), path.size() - 2);
                        }
 
                        command = APDUHelper::generateAPDU(APDUHelper::COMMAND_SELECT_BY_PATH, 0, temp);
@@ -198,12 +188,12 @@ namespace smartcard_service_api
                return ret;
        }
 
-       FCI *FileObject::getFCI()
+       const FCI *FileObject::getFCI() const
        {
                return NULL;
        }
 
-       FCP *FileObject::getFCP()
+       const FCP *FileObject::getFCP() const
        {
                return &fcp;
        }
@@ -218,36 +208,36 @@ namespace smartcard_service_api
                apdu.getBuffer(command);
 
                ret = channel->transmitSync(command, response);
-               if (ret == 0 && response.getLength() >= 2)
+               if (ret == 0 && response.size() >= 2)
                {
                        ResponseHelper resp(response);
 
                        ret = resp.getStatus();
-                       if (ret == 0)
+                       if (ret >= 0)
                        {
-                               SCARD_DEBUG("response [%d] : %s", response.getLength(), response.toString());
+                               _DBG("response [%d] : %s", response.size(), response.toString().c_str());
 
                                result = Record(recordId, resp.getDataField());
                        }
                        else
                        {
-                               SCARD_DEBUG_ERR("status word [%d][ %02X %02X ]", resp.getStatus(), resp.getSW1(), resp.getSW2());
+                               _ERR("status word [ %02X %02X ]", resp.getSW1(), resp.getSW2());
                        }
                }
                else
                {
-                       SCARD_DEBUG_ERR("select apdu is failed, rv [%d], length [%d]", ret, response.getLength());
+                       _ERR("select apdu is failed, rv [%d], length [%d]", ret, response.size());
                }
 
                return ret;
        }
 
-       int FileObject::writeRecord(unsigned int sfi, Record record)
+       int FileObject::writeRecord(unsigned int sfi, const Record &record)
        {
                return 0;
        }
 
-       int FileObject::searchRecord(unsigned int sfi, ByteArray searchParam, vector<int> &result)
+       int FileObject::searchRecord(unsigned int sfi, const ByteArray &searchParam, vector<int> &result)
        {
                return 0;
        }
@@ -262,13 +252,13 @@ namespace smartcard_service_api
                apdu.getBuffer(command);
 
                ret = channel->transmitSync(command, response);
-               if (ret == 0 && response.getLength() >= 2)
+               if (ret == 0 && response.size() >= 2)
                {
                        ResponseHelper resp(response);
 
-                       if (resp.getStatus() == 0)
+                       if (resp.getStatus() >= 0)
                        {
-                               SCARD_DEBUG("response [%d] : %s", response.getLength(), response.toString());
+                               _DBG("response [%d] : %s", response.size(), response.toString().c_str());
 
                                result = resp.getDataField();
 
@@ -276,18 +266,18 @@ namespace smartcard_service_api
                        }
                        else
                        {
-                               SCARD_DEBUG_ERR("status word [%d][ %02X %02X ]", resp.getStatus(), resp.getSW1(), resp.getSW2());
+                               _ERR("status word [ %02X %02X ]", resp.getSW1(), resp.getSW2());
                        }
                }
                else
                {
-                       SCARD_DEBUG_ERR("select apdu is failed, rv [%d], length [%d]", ret, response.getLength());
+                       _ERR("select apdu is failed, rv [%d], length [%d]", ret, response.size());
                }
 
                return ret;
        }
 
-       int FileObject::writeBinary(unsigned int sfi, ByteArray data, unsigned int offset, unsigned int length)
+       int FileObject::writeBinary(unsigned int sfi, const ByteArray &data, unsigned int offset, unsigned int length)
        {
                ByteArray command, response;
                APDUCommand apdu;
@@ -297,24 +287,24 @@ namespace smartcard_service_api
                apdu.getBuffer(command);
 
                ret = channel->transmitSync(command, response);
-               if (ret == 0 && response.getLength() >= 2)
+               if (ret == 0 && response.size() >= 2)
                {
                        ResponseHelper resp(response);
 
-                       if (resp.getStatus() == 0)
+                       if (resp.getStatus() >= 0)
                        {
-                               SCARD_DEBUG("response [%d] : %s", response.getLength(), response.toString());
+                               _DBG("response [%d] : %s", response.size(), response.toString().c_str());
 
                                ret = SUCCESS;
                        }
                        else
                        {
-                               SCARD_DEBUG_ERR("status word [%d][ %02X %02X ]", resp.getStatus(), resp.getSW1(), resp.getSW2());
+                               _ERR("status word [ %02X %02X ]", resp.getSW1(), resp.getSW2());
                        }
                }
                else
                {
-                       SCARD_DEBUG_ERR("select apdu is failed, rv [%d], length [%d]", ret, response.getLength());
+                       _ERR("select apdu is failed, rv [%d], length [%d]", ret, response.size());
                }
 
                return ret;
diff --git a/common/GDBusHelper.cpp b/common/GDBusHelper.cpp
new file mode 100644 (file)
index 0000000..0422100
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifdef USE_GDBUS
+#include "GDBusHelper.h"
+
+namespace smartcard_service_api
+{
+       void GDBusHelper::convertVariantToByteArray(GVariant *var,
+               ByteArray &array)
+       {
+               GVariantIter *iter;
+               guint8 element;
+               guint8 *buf = NULL;
+               guint size = 0;
+               guint i;
+
+               g_variant_get(var, "a(y)", &iter);
+
+               size = g_variant_iter_n_children(iter);
+               buf  = g_new0(guint8, size);
+
+               for (i = 0; g_variant_iter_loop(iter, "(y)", &element); i++)
+               {
+                       buf[i] = element;
+               }
+
+               g_variant_iter_free(iter);
+
+               array.assign((uint8_t *)buf, (uint32_t)i);
+
+               g_free(buf);
+       }
+
+       GVariant *GDBusHelper::convertByteArrayToVariant(const ByteArray &array)
+       {
+               GVariantBuilder builder;
+               uint32_t i;
+
+               g_variant_builder_init(&builder, G_VARIANT_TYPE("a(y)"));
+
+               for (i = 0; i < array.size(); i++)
+                       g_variant_builder_add(&builder, "(y)", array[i]);
+
+               return g_variant_builder_end(&builder);
+       }
+} /* namespace smartcard_service_api */
+#endif
diff --git a/common/GPACE.cpp b/common/GPACE.cpp
new file mode 100644 (file)
index 0000000..3aa3ba7
--- /dev/null
@@ -0,0 +1,123 @@
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* standard library header */
+
+/* SLP library header */
+
+/* local header */
+#include "Debug.h"
+#include "GPACE.h"
+#include "GPARAACL.h"
+#include "GPARFACL.h"
+#include "SessionHelper.h"
+#include "ReaderHelper.h"
+
+#ifndef EXTERN_API
+#define EXTERN_API __attribute__((visibility("default")))
+#endif
+
+namespace smartcard_service_api
+{
+       GPACE::GPACE() : AccessControlList(), acl(NULL)
+       {
+       }
+
+       GPACE::~GPACE()
+       {
+               if (acl != NULL) {
+                       delete acl;
+               }
+       }
+
+       int GPACE::loadACL(Channel *channel)
+       {
+               int result = SCARD_ERROR_OK;
+
+               _BEGIN();
+
+               if (channel == NULL)
+               {
+                       return SCARD_ERROR_ILLEGAL_PARAM;
+               }
+
+               if (acl == NULL) {
+                       /* first, check ara-m */
+                       GPARAACL *araACL = new GPARAACL;
+
+                       result = araACL->loadACL(channel);
+                       if (result < SCARD_ERROR_OK) {
+                               _ERR("ARA not found");
+
+                               delete araACL;
+
+                               if (true) {
+                                       _INFO("try to use ARF");
+                                       /* second, check arf when channel is for SIM */
+                                       GPARFACL *arfACL = new GPARFACL;
+
+                                       result = arfACL->loadACL(channel);
+                                       if (result >= SCARD_ERROR_OK) {
+                                               acl = arfACL;
+                                       } else {
+                                               delete arfACL;
+                                       }
+                               }
+                       } else {
+                               acl = araACL;
+                       }
+               } else {
+                       result = acl->loadACL(channel);
+               }
+
+               _END();
+
+               return result;
+       }
+
+       bool GPACE::isAuthorizedAccess(const ByteArray &aid,
+               const ByteArray &certHash) const
+       {
+               return (acl != NULL) ? acl->isAuthorizedAccess(aid, certHash) : false;
+       }
+
+       bool GPACE::isAuthorizedAccess(const unsigned char *aidBuffer,
+               unsigned int aidLength, const unsigned char *certHashBuffer,
+               unsigned int certHashLength) const
+       {
+               return (acl != NULL) ? acl->isAuthorizedAccess(aidBuffer, aidLength, certHashBuffer, certHashLength) : false;
+       }
+
+       bool GPACE::isAuthorizedAccess(const ByteArray &aid,
+               const vector<ByteArray> &certHashes) const
+       {
+               return (acl != NULL) ? acl->isAuthorizedAccess(aid, certHashes) : false;
+       }
+
+       bool GPACE::isAuthorizedAccess(const ByteArray &aid,
+               const vector<ByteArray> &certHashes,
+               const ByteArray &command) const
+       {
+               return (acl != NULL) ? acl->isAuthorizedAccess(aid, certHashes, command) : false;
+       }
+
+       bool GPACE::isAuthorizedNFCAccess(const ByteArray &aid,
+               const vector<ByteArray> &certHashes) const
+       {
+               return (acl != NULL) ? acl->isAuthorizedNFCAccess(aid, certHashes) : false;
+       }
+
+} /* namespace smartcard_service_api */
diff --git a/common/GPARAACL.cpp b/common/GPARAACL.cpp
new file mode 100644 (file)
index 0000000..31c082d
--- /dev/null
@@ -0,0 +1,527 @@
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* standard library header */
+
+/* SLP library header */
+
+/* local header */
+#include "Debug.h"
+#include "GPARAACL.h"
+#include "GPARAM.h"
+#include "NumberStream.h"
+#include "SimpleTLV.h"
+#include "ISO7816BERTLV.h"
+#include "AccessCondition.h"
+
+#ifndef EXTERN_API
+#define EXTERN_API __attribute__((visibility("default")))
+#endif
+
+namespace smartcard_service_api
+{
+       static unsigned char aid_aram[] = { 0xA0, 0x00, 0x00, 0x01, 0x51, 0x41, 0x43, 0x4C, 0x00 };
+       static ByteArray AID_ARAM(ARRAY_AND_SIZE(aid_aram));
+
+#define GET_DATA_ALL           0
+#define GET_DATA_SPECIFIC      1
+#define GET_DATA_REFRESH_TAG   2
+#define GET_DATA_NEXT          3
+
+#define ARAM_TAG_ALL_AR                0x0000FF40
+#define ARAM_TAG_AR            0x0000FF50
+#define ARAM_TAG_REFRESH       0x0000DF20
+
+#define DO_TAG_AID_REF         0x0000004F
+#define DO_TAG_AID_REF_DEFAULT 0x000000C0
+#define DO_TAG_HASH_REF                0x000000C1
+#define DO_TAG_APDU_AR         0x000000D0
+#define DO_TAG_NFC_AR          0x000000D1
+#define DO_TAG_REF             0x000000E1
+#define DO_TAG_REF_AR          0x000000E2
+#define DO_TAG_AR              0x000000E3
+
+       GPARAACL::GPARAACL() : AccessControlList()
+       {
+       }
+
+       GPARAACL::~GPARAACL()
+       {
+       }
+
+       static ByteArray getAID(SimpleTLV &tlv)
+       {
+               ByteArray result;
+
+               _BEGIN();
+
+               if (tlv.decodeTLV() == true) {
+                       switch (tlv.getTag()) {
+                       case DO_TAG_AID_REF :
+                               if (tlv.size() > 0) {
+                                       result = tlv.getValue();
+                               } else {
+                                       result = AccessControlList::ALL_SE_APPS;
+                               }
+                               break;
+
+                       case DO_TAG_AID_REF_DEFAULT :
+                               result = AccessControlList::DEFAULT_SE_APP;
+                               break;
+
+                       default :
+                               _ERR("decodeTLV failed, %s", tlv.toString().c_str());
+                               break;
+                       }
+               } else {
+                       _ERR("decodeTLV failed, %s", tlv.toString().c_str());
+               }
+
+               _END();
+
+               return result;
+       }
+
+       static ByteArray getHash(SimpleTLV &tlv)
+       {
+               ByteArray result;
+
+               _BEGIN();
+
+               if (tlv.decodeTLV() == true &&
+                       tlv.getTag() == DO_TAG_HASH_REF) {
+                       if (tlv.size() > 0) {
+                               result = tlv.getValue();
+                       } else {
+                               result = AccessControlList::ALL_DEVICE_APPS;
+                       }
+               } else {
+                       _ERR("decodeTLV failed, %s", tlv.toString().c_str());
+               }
+
+               _END();
+
+               return result;
+       }
+
+       static int parseRefDO(SimpleTLV &tlv, ByteArray &aid, ByteArray &hash)
+       {
+               int result = SCARD_ERROR_OK;
+
+               _BEGIN();
+
+               if (tlv.decodeTLV() == true && tlv.getTag() == DO_TAG_REF) {
+                       tlv.enterToValueTLV();
+                       aid = getAID(tlv);
+                       hash = getHash(tlv);
+                       tlv.returnToParentTLV();
+
+                       _DBG("aid : %s, hash : %s", aid.toString().c_str(), hash.toString().c_str());
+               } else {
+                       _ERR("unknown tag : %s", tlv.toString().c_str());
+                       result = SCARD_ERROR_ILLEGAL_PARAM;
+               }
+
+               _END();
+
+               return result;
+       }
+
+       static int parseARDO(SimpleTLV &tlv, vector<ByteArray> &apduRule,
+               ByteArray &nfcRule)
+       {
+               int result = SCARD_ERROR_OK;
+
+               _BEGIN();
+
+               if (tlv.decodeTLV() == true && tlv.getTag() == DO_TAG_AR) {
+                       tlv.enterToValueTLV();
+                       while (tlv.decodeTLV() == true) {
+                               int length = tlv.size();
+
+                               switch (tlv.getTag()) {
+                               case DO_TAG_APDU_AR :
+                                       if (length > 1) {
+                                               int i;
+                                               ByteArray temp;
+
+                                               for (i = 0; i < length; i += 8) {
+                                                       temp.assign(tlv.getValue().getBuffer(i), 8);
+                                                       _DBG("apdu rule[%d] : %s", temp.size(), temp.toString().c_str());
+                                                       apduRule.push_back(temp);
+                                               }
+                                       } else if (length == 1){
+                                               _DBG("apdu rule : %s", tlv.getValue().toString().c_str());
+                                               apduRule.push_back(tlv.getValue());
+                                       } else {
+                                               _ERR("invalid rule, %s", tlv.toString().c_str());
+                                       }
+                                       break;
+
+                               case DO_TAG_NFC_AR :
+                                       nfcRule = tlv.getValue();
+                                       _DBG("nfc rule : %s", tlv.getValue().toString().c_str());
+                                       break;
+
+                               default :
+                                       break;
+                               }
+                       }
+                       tlv.returnToParentTLV();
+               } else {
+                       result = SCARD_ERROR_ILLEGAL_PARAM;
+               }
+
+               _END();
+
+               return result;
+       }
+
+       void GPARAACL::addCondition(const ByteArray &aid, const ByteArray &hash,
+               const vector<ByteArray> &apduRule, const ByteArray &nfcRule)
+       {
+               AccessCondition &condition = getAccessCondition(aid);
+
+               _BEGIN();
+
+               condition.addAccessRule(hash);
+
+               if (apduRule.size() > 0) {
+                       if (apduRule.size() == 1 &&
+                               apduRule[0].size() == 1) {
+                               /* apdu grant/deny */
+                               if (apduRule[0][0] == 1) {
+                                       condition.setAPDUAccessRule(hash, true);
+                               } else {
+                                       condition.setAPDUAccessRule(hash, false);
+                               }
+                       } else {
+                               size_t i;
+
+                               for (i = 0; i < apduRule.size(); i++) {
+                                       condition.addAPDUAccessRule(hash, apduRule[i]);
+                               }
+                       }
+               }
+
+               if (nfcRule.size() == 1) {
+                       if (nfcRule[0] == 1) {
+                               condition.setNFCAccessRule(hash, true);
+                       } else {
+                               condition.setNFCAccessRule(hash, false);
+                       }
+               }
+
+               _END();
+       }
+
+       int GPARAACL::updateRule(const ByteArray &data)
+       {
+               int result = SCARD_ERROR_OK;
+               SimpleTLV tlv(data);
+
+               _BEGIN();
+
+               while (tlv.decodeTLV() == true) {
+                       if (tlv.getTag() == DO_TAG_REF_AR) {
+                               ByteArray aid, hash, nfcRule;
+                               vector<ByteArray> apduRule;
+
+                               tlv.enterToValueTLV();
+                               result = parseRefDO(tlv, aid, hash);
+
+                               if (result >= SCARD_ERROR_OK) {
+                                       result = parseARDO(tlv, apduRule, nfcRule);
+                               }
+                               tlv.returnToParentTLV();
+
+                               addCondition(aid, hash, apduRule, nfcRule);
+                       } else {
+                               _ERR("unknown tag, [%x]", tlv.getTag());
+                               result = SCARD_ERROR_ILLEGAL_PARAM;
+                               break;
+                       }
+               }
+
+               _END();
+
+               return result;
+       }
+
+       int GPARAACL::loadACL(GPARAM &aram)
+       {
+               int result = SCARD_ERROR_OK;
+               ByteArray refreshTag, response;
+
+               _BEGIN();
+
+               if (aram.isClosed() == true) {
+                       return SCARD_ERROR_ILLEGAL_STATE;
+               }
+
+               /* get refresh tag */
+               result = aram.getDataRefreshTag(refreshTag);
+               if (result >= SCARD_ERROR_OK) {
+                       /* check refresh tag */
+                       if (this->refreshTag.isEmpty() == true ||
+                               this->refreshTag != refreshTag) {
+                               result = aram.getDataAll(response);
+                               if (result >= SCARD_ERROR_OK) {
+                                       result = updateRule(response);
+
+                                       /* update refresh tag */
+                                       this->refreshTag = refreshTag;
+                               } else {
+                                       _ERR("getDataAll failed, [%x]", result);
+                               }
+                       }
+                       else
+                       {
+                               _INFO("access rules are not changed. skip update");
+                       }
+               } else {
+                       _ERR("transmitSync failed, %x", result);
+               }
+
+               _END();
+
+               return result;
+       }
+
+       int GPARAACL::loadACL(Channel *channel)
+       {
+               int result = SCARD_ERROR_OK;
+
+               _BEGIN();
+
+               if (channel == NULL) {
+                       return SCARD_ERROR_ILLEGAL_PARAM;
+               }
+
+               GPARAM aram(channel);
+
+               result = aram.select();
+               if (result >= SCARD_ERROR_OK) {
+                       result = loadACL(aram);
+               } else {
+                       _ERR("select failed, [%x]", result);
+               }
+
+               _END();
+
+               return result;
+       }
+
+       static bool _isAuthorizedAccess(const ByteArray &data, const ByteArray &command)
+       {
+               vector<ByteArray> apduRule;
+               ByteArray nfcRule;
+               SimpleTLV tlv(data);
+               bool result = false;
+
+               if (parseARDO(tlv, apduRule, nfcRule) >= SCARD_ERROR_OK) {
+                       if (apduRule.size() > 0) {
+                               if (apduRule.size() > 1 ||
+                                       apduRule[0].size() != 1) {
+                                       if (command.size() > 0) {
+                                               /* TODO : check apdu rule */
+                                       } else {
+                                               /* check hash only */
+                                               result = true;
+                                       }
+                               } else {
+                                       result = (apduRule[0][0] == 1 ? true : false);
+                               }
+                       } else {
+                               _ERR("unknown data : %s", tlv.toString().c_str());
+                       }
+               } else {
+                       _ERR("parseARDO failed : %s", tlv.toString().c_str());
+               }
+
+               return result;
+       }
+
+       static bool _isAuthorizedNFCAccess(const ByteArray &data)
+       {
+               vector<ByteArray> apduRule;
+               ByteArray nfcRule;
+               SimpleTLV tlv(data);
+               bool result = false;
+
+               if (parseARDO(tlv, apduRule, nfcRule) >= SCARD_ERROR_OK) {
+                       if (nfcRule.size() == 1) {
+                               result = (nfcRule[0] == 1 ? true : false);
+                       } else {
+                               _ERR("unknown data : %s", nfcRule.toString().c_str());
+                       }
+               } else {
+                       _ERR("parseARDO failed : %s", tlv.toString().c_str());
+               }
+
+               return result;
+       }
+
+       bool GPARAACL::isAuthorizedAccess(GPARAM &aram, const ByteArray &aid,
+               const ByteArray &certHash) const
+       {
+               vector<ByteArray> hashes;
+
+               hashes.push_back(certHash);
+
+               return isAuthorizedAccess(aram, aid, hashes, ByteArray::EMPTY);
+       }
+
+       bool GPARAACL::isAuthorizedAccess(GPARAM &aram,
+               const unsigned char *aidBuffer,
+               unsigned int aidLength,
+               const unsigned char *certHashBuffer,
+               unsigned int certHashLength) const
+       {
+               ByteArray aid(aidBuffer, aidLength);
+               ByteArray hash(certHashBuffer, certHashLength);
+
+               return isAuthorizedAccess(aram, aid, hash);
+       }
+
+       bool GPARAACL::isAuthorizedAccess(GPARAM &aram, const ByteArray &aid,
+               const vector<ByteArray> &certHashes) const
+       {
+               return isAuthorizedAccess(aram, aid, certHashes, ByteArray::EMPTY);
+       }
+
+       bool GPARAACL::isAuthorizedAccess(GPARAM &aram, const ByteArray &aid,
+               const vector<ByteArray> &certHashes, const ByteArray &command) const
+       {
+               bool result = allGranted;
+               ByteArray data;
+               vector<ByteArray>::const_reverse_iterator item;
+
+               if (aram.isClosed() == true)
+                       return result;
+
+               _BEGIN();
+
+               if (result == true) {
+                       goto END;
+               }
+               /* Step A, find with aid and cert hashes */
+               for (item = certHashes.rbegin();
+                       result == false && item != certHashes.rend();
+                       item++) {
+                       if (aram.getDataSpecific(aid, *item, data)
+                               >= SCARD_ERROR_OK && data.size() > 0) {
+                               result = _isAuthorizedAccess(data, command);
+                               _INFO("rule found (%s): [%s:%s]", result ? "accept" : "deny", aid.toString().c_str(), (*item).toString().c_str());
+                               goto END;
+                       }
+               }
+
+               /* Step B, find with aid and ALL_DEVICES_APPS */
+               if (aram.getDataSpecific(aid, ByteArray::EMPTY, data)
+                       >= SCARD_ERROR_OK && data.size() > 0) {
+                       result = _isAuthorizedAccess(data, command);
+                       _INFO("rule found (%s): [%s:%s]", result ? "accept" : "deny", aid.toString().c_str(), "All device applications");
+                       goto END;
+               }
+
+               /* Step C, find with ALL_SE_APPS and hashes */
+               for (item = certHashes.rbegin();
+                       result == false && item != certHashes.rend();
+                       item++) {
+                       if (aram.getDataSpecific(ByteArray::EMPTY, *item, data)
+                               >= SCARD_ERROR_OK && data.size() > 0) {
+                               result = _isAuthorizedAccess(data, command);
+                               _INFO("rule found (%s): [%s:%s]", result ? "accept" : "deny", "All SE Applications", (*item).toString().c_str());
+                               goto END;
+                       }
+               }
+
+               /* Step D, find with ALL_SE_APPS and ALL_DEVICES_APPS */
+               if (aram.getDataSpecific(ByteArray::EMPTY, ByteArray::EMPTY, data)
+                       >= SCARD_ERROR_OK && data.size() > 0) {
+                       result = _isAuthorizedAccess(data, command);
+                       _INFO("rule found (%s): [%s:%s]", result ? "accept" : "deny", "All SE Applications", "All device applications");
+                       goto END;
+               }
+
+       END :
+               _END();
+
+               return result;
+       }
+
+       bool GPARAACL::isAuthorizedNFCAccess(GPARAM &aram, const ByteArray &aid,
+               const vector<ByteArray> &certHashes) const
+       {
+               bool result = allGranted;
+               ByteArray data;
+               vector<ByteArray>::const_reverse_iterator item;
+
+               if (aram.isClosed() == true)
+                       return result;
+
+               _BEGIN();
+
+               if (result == true) {
+                       goto END;
+               }
+               /* Step A, find with aid and cert hashes */
+               for (item = certHashes.rbegin();
+                       result == false && item != certHashes.rend();
+                       item++) {
+                       if (aram.getDataSpecific(aid, *item, data)
+                               >= SCARD_ERROR_OK && data.size() > 0) {
+                               result = _isAuthorizedNFCAccess(data);
+                               _INFO("rule found (%s): [%s:%s]", result ? "accept" : "deny", aid.toString().c_str(), (*item).toString().c_str());
+                               goto END;
+                       }
+               }
+
+               /* Step B, find with aid and ALL_DEVICES_APPS */
+               if (aram.getDataSpecific(aid, ByteArray::EMPTY, data)
+                       >= SCARD_ERROR_OK && data.size() > 0) {
+                       result = _isAuthorizedNFCAccess(data);
+                       _INFO("rule found (%s): [%s:%s]", result ? "accept" : "deny", aid.toString().c_str(), "All device applications");
+                       goto END;
+               }
+
+               /* Step C, find with ALL_SE_APPS and hashes */
+               for (item = certHashes.rbegin();
+                       result == false && item != certHashes.rend();
+                       item++) {
+                       if (aram.getDataSpecific(ByteArray::EMPTY, *item, data)
+                               >= SCARD_ERROR_OK && data.size() > 0) {
+                               result = _isAuthorizedNFCAccess(data);
+                               _INFO("rule found (%s): [%s:%s]", result ? "accept" : "deny", "All SE Applications", (*item).toString().c_str());
+                               goto END;
+                       }
+               }
+
+               /* Step D, find with ALL_SE_APPS and ALL_DEVICES_APPS */
+               if (aram.getDataSpecific(ByteArray::EMPTY, ByteArray::EMPTY, data)
+                       >= SCARD_ERROR_OK && data.size() > 0) {
+                       result = _isAuthorizedNFCAccess(data);
+                       _INFO("rule found (%s): [%s:%s]", result ? "accept" : "deny", "All SE Applications", "All device applications");
+                       goto END;
+               }
+
+       END :
+               _END();
+
+               return result;
+       }
+} /* namespace smartcard_service_api */
diff --git a/common/GPARAM.cpp b/common/GPARAM.cpp
new file mode 100644 (file)
index 0000000..ac0081b
--- /dev/null
@@ -0,0 +1,278 @@
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* standard library header */
+
+/* SLP library header */
+
+/* local header */
+#include "Debug.h"
+#include "GPARAM.h"
+#include "APDUHelper.h"
+#include "FileObject.h"
+#include "NumberStream.h"
+#include "SimpleTLV.h"
+#include "ISO7816BERTLV.h"
+#include "AccessCondition.h"
+
+#ifndef EXTERN_API
+#define EXTERN_API __attribute__((visibility("default")))
+#endif
+
+namespace smartcard_service_api
+{
+       static unsigned char aid_aram[] = { 0xA0, 0x00, 0x00, 0x01, 0x51, 0x41, 0x43, 0x4C, 00 };
+       static ByteArray AID_ARAM(ARRAY_AND_SIZE(aid_aram));
+
+#define GET_DATA_ALL           0
+#define GET_DATA_SPECIFIC      1
+#define GET_DATA_REFRESH_TAG   2
+#define GET_DATA_NEXT          3
+
+#define ARAM_TAG_ALL_AR                0x0000FF40
+#define ARAM_TAG_AR            0x0000FF50
+#define ARAM_TAG_REFRESH       0x0000DF20
+
+#define DO_TAG_AID_REF         0x0000004F
+#define DO_TAG_AID_REF_DEFAULT 0x000000C0
+#define DO_TAG_HASH_REF                0x000000C1
+#define DO_TAG_APDU_AR         0x000000D0
+#define DO_TAG_NFC_AR          0x000000D1
+#define DO_TAG_REF             0x000000E1
+#define DO_TAG_REF_AR          0x000000E2
+#define DO_TAG_AR              0x000000E3
+
+       GPARAM::GPARAM(Channel *channel)
+               : FileObject(channel)
+       {
+       }
+
+       int GPARAM::select()
+       {
+               return FileObject::select(AID_ARAM);
+       }
+
+       static int doTransmit(Channel *channel, const ByteArray &command, ByteArray &response)
+       {
+               int result;
+               ByteArray resp;
+
+               _BEGIN();
+
+               result = channel->transmitSync(command, resp);
+               if (result == SCARD_ERROR_OK) {
+                       result = ResponseHelper::getStatus(resp);
+                       if (result >= SCARD_ERROR_OK) {
+                               response = ResponseHelper::getDataField(resp);
+                               _DBG("response[%d] : %s", response.size(), response.toString().c_str());
+                       } else {
+                               _ERR("transmit returns error, [%d]", result);
+                       }
+               } else {
+                       _ERR("transmitSync failed, [%d]", result);
+               }
+
+               _END();
+
+               return result;
+       }
+
+       static int doCommand(Channel *channel, int command, ByteArray &response)
+       {
+               int result;
+               APDUCommand helper;
+               ByteArray cmd, resp;
+
+               _BEGIN();
+
+               switch (command) {
+               case GET_DATA_ALL :
+                       helper.setCommand(0x80, 0xCA, 0xFF, 0x40, ByteArray::EMPTY, 0);
+                       break;
+
+               case GET_DATA_REFRESH_TAG :
+                       helper.setCommand(0x80, 0xCA, 0xDF, 0x20, ByteArray::EMPTY, 0);
+                       break;
+
+               case GET_DATA_NEXT :
+                       helper.setCommand(0x80, 0xCA, 0xFF, 0x60, ByteArray::EMPTY, 0);
+                       break;
+               }
+
+               helper.getBuffer(cmd);
+
+               _DBG("command[%d] : %s", cmd.size(), cmd.toString().c_str());
+
+               result = doTransmit(channel, cmd, response);
+
+               _END();
+
+               return result;
+       }
+
+       static int doCommand(Channel *channel, ByteArray &data, ByteArray &response)
+       {
+               int result;
+               APDUCommand helper;
+               ByteArray cmd;
+
+               helper.setCommand(0x80, 0xCA, 0xFF, 0x50, data, 0);
+               helper.getBuffer(cmd);
+
+               result = doTransmit(channel, cmd, response);
+
+               return result;
+       }
+
+       int GPARAM::getDataAll(ByteArray &data)
+       {
+               int result;
+               ByteArray response;
+
+               _BEGIN();
+
+               result = doCommand(channel, GET_DATA_ALL, response);
+               if (result >= SCARD_ERROR_OK) {
+                       ISO7816BERTLV tlv(response);
+
+                       if (tlv.decodeTLV() == true &&
+                               tlv.getTag() == ARAM_TAG_ALL_AR) {
+                               unsigned int length = tlv.size();
+
+                               if (length > 0){
+                                       data = tlv.getValue();
+
+                                       while (length > data.size()) {
+                                               result = doCommand(channel, GET_DATA_NEXT, response);
+                                               if (result >= SCARD_ERROR_OK) {
+                                                       data += response;
+                                               } else {
+                                                       _ERR("generateCommand failed, [%d]", result);
+                                                       data.clear();
+                                                       break;
+                                               }
+                                       }
+
+                                       _DBG("data[%d] : %s", data.size(), data.toString().c_str());
+                               } else {
+                                       _INFO("Response-ALL-AR-DO is empty");
+                                       data.clear();
+                               }
+                       } else {
+                               _ERR("decodeTLV failed, %s", response.toString().c_str());
+                               result = SCARD_ERROR_ILLEGAL_PARAM;
+                       }
+               } else {
+                       _ERR("generateCommand failed, [%d]", result);
+               }
+
+               _END();
+
+               return result;
+       }
+
+       static int createRefDo(const ByteArray &aid, const ByteArray &hash, ByteArray &refDo)
+       {
+               ByteArray temp;
+
+               temp = SimpleTLV::encode(DO_TAG_AID_REF, aid);
+               temp += SimpleTLV::encode(DO_TAG_HASH_REF, hash);
+
+               refDo = SimpleTLV::encode(DO_TAG_REF, temp);
+               _DBG("encoded Ref DO : %s", refDo.toString().c_str());
+
+               return SCARD_ERROR_OK;
+       }
+
+       int GPARAM::getDataSpecific(const ByteArray &aid, const ByteArray &hash,
+               ByteArray &data)
+       {
+               int result;
+               ByteArray refDo, response;
+
+               _BEGIN();
+
+               createRefDo(aid, hash, refDo);
+
+               result = doCommand(channel, refDo, response);
+               if (result >= SCARD_ERROR_OK) {
+                       ISO7816BERTLV tlv(response);
+
+                       if (tlv.decodeTLV() == true &&
+                               tlv.getTag() == ARAM_TAG_AR) {
+                               unsigned int length = tlv.size();
+
+                               if (length > 0){
+                                       data = tlv.getValue();
+
+                                       while (length > data.size()) {
+                                               result = doCommand(channel, GET_DATA_NEXT, response);
+                                               if (result >= SCARD_ERROR_OK) {
+                                                       data += response;
+                                               } else {
+                                                       _ERR("generateCommand failed, [%d]", result);
+                                                       data.clear();
+                                                       break;
+                                               }
+                                       }
+                                       _DBG("data[%d] : %s", data.size(), data.toString().c_str());
+                               } else {
+                                       _INFO("Response-ALL-AR-DO is empty");
+                                       data.clear();
+                               }
+                       } else {
+                               _ERR("decodeTLV failed, %s", response.toString().c_str());
+                               result = SCARD_ERROR_ILLEGAL_PARAM;
+                       }
+               } else {
+                       _ERR("doCommand failed, [%d]", result);
+               }
+
+               _END();
+
+               return result;
+       }
+
+       int GPARAM::getDataRefreshTag(ByteArray &tag)
+       {
+               int result;
+               ByteArray response;
+
+               _BEGIN();
+
+               result = doCommand(channel, GET_DATA_REFRESH_TAG, response);
+               if (result >= SCARD_ERROR_OK) {
+                       ISO7816BERTLV tlv(response);
+
+                       if (tlv.decodeTLV() == true &&
+                               tlv.getTag() == ARAM_TAG_REFRESH &&
+                               tlv.size() == 8) {
+                               tag = tlv.getValue();
+                               result = SCARD_ERROR_OK;
+                               _DBG("refreshTag[%d] : %s", tag.size(), tag.toString().c_str());
+                       } else {
+                               _ERR("decodeTLV failed, %s", response.toString().c_str());
+                               result = SCARD_ERROR_ILLEGAL_PARAM;
+                       }
+               } else {
+                       _ERR("generateCommand failed, [%d]", result);
+               }
+
+               _END();
+
+               return result;
+       }
+} /* namespace smartcard_service_api */
diff --git a/common/GPARFACL.cpp b/common/GPARFACL.cpp
new file mode 100644 (file)
index 0000000..a136c83
--- /dev/null
@@ -0,0 +1,425 @@
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* standard library header */
+
+/* SLP library header */
+
+/* local header */
+#include "Debug.h"
+#include "GPARFACL.h"
+#include "PKCS15ODF.h"
+#include "PKCS15DODF.h"
+#include "NumberStream.h"
+#include "SimpleTLV.h"
+#include "AccessCondition.h"
+
+#ifndef EXTERN_API
+#define EXTERN_API __attribute__((visibility("default")))
+#endif
+
+namespace smartcard_service_api
+{
+       static unsigned char oid_globalplatform[] = { 0x2A, 0x86, 0x48, 0x86, 0xFC, 0x6B, 0x81, 0x48, 0x01, 0x01 };
+       static ByteArray OID_GLOBALPLATFORM(ARRAY_AND_SIZE(oid_globalplatform));
+
+       GPARFACL::GPARFACL() : AccessControlList()
+       {
+       }
+
+       GPARFACL::~GPARFACL()
+       {
+       }
+
+       int GPARFACL::loadACL(Channel *channel)
+       {
+               int result = SCARD_ERROR_OK;
+
+               _BEGIN();
+
+               if (channel == NULL)
+               {
+                       return SCARD_ERROR_ILLEGAL_PARAM;
+               }
+
+               PKCS15 pkcs15(channel);
+
+               /* basically, all requests will be accepted when PKCS #15 doesn't exist or global platform OID is not placed */
+               allGranted = false;
+
+               result = pkcs15.select();
+               if (result >= SCARD_ERROR_OK)
+               {
+                       PKCS15ODF *odf;
+
+                       result = SCARD_ERROR_OK;
+                       allGranted = true;
+
+                       if ((odf = pkcs15.getODF()) != NULL)
+                       {
+                               PKCS15DODF *dodf;
+
+                               if ((dodf = odf->getDODF()) != NULL)
+                               {
+                                       result = loadAccessControl(channel, dodf);
+                                       if (result == SCARD_ERROR_OK)
+                                       {
+                                       }
+                                       else
+                                       {
+                                               _INFO("loadAccessControl failed, every request will be accepted.");
+                                               result = SCARD_ERROR_OK;
+                                       }
+                               }
+                               else
+                               {
+                                       _INFO("dodf null, every request will be accepted.");
+                               }
+                       }
+                       else
+                       {
+                               _INFO("odf null, every request will be accepted.");
+                       }
+               }
+               else
+               {
+                       _ERR("failed to open PKCS15, every request will be denied.");
+               }
+
+               _END();
+
+               return result;
+       }
+
+       int GPARFACL::loadAccessControl(Channel *channel, PKCS15DODF *dodf)
+       {
+               int result = -1;
+               ByteArray path;
+
+               if ((result = dodf->searchOID(OID_GLOBALPLATFORM, path)) == 0)
+               {
+                       ByteArray data;
+                       FileObject file(channel);
+
+                       _DBG("oid path : %s", path.toString().c_str());
+
+                       file.select(NumberStream::getLittleEndianNumber(path));
+                       file.readBinary(0, 0, file.getFCP()->getFileSize(), data);
+
+                       _DBG("data : %s", data.toString().c_str());
+
+                       /* PKCS #15 and DODF OID exists. apply access control rule!! */
+                       allGranted = false;
+
+                       SimpleTLV tlv(data);
+
+                       if (tlv.decodeTLV() == true && tlv.getTag() == 0x30) /* SEQUENCE : AccessControlMainFile */
+                       {
+                               tlv.enterToValueTLV();
+
+                               /* refresh Tag */
+                               ByteArray refreshTag;
+
+                               refreshTag = SimpleTLV::getOctetString(tlv);
+                               _DBG("current refresh tag : %s", refreshTag.toString().c_str());
+
+                               if (this->refreshTag != refreshTag) /* need to update access control list */
+                               {
+                                       this->refreshTag = refreshTag;
+
+                                       releaseACL();
+
+                                       /* access control rule path */
+                                       if (tlv.decodeTLV() == true && tlv.getTag() == 0x30) /* SEQUENCE : Path */
+                                       {
+                                               /* TODO : parse path */
+                                               ByteArray path;
+
+                                               /* OCTET STRING */
+                                               path = SimpleTLV::getOctetString(tlv.getValue());
+                                               _DBG("access control rule path : %s", path.toString().c_str());
+
+                                               if (loadRules(channel, path) == 0)
+                                               {
+                                                       _DBG("loadRules success");
+                                               }
+                                               else
+                                               {
+                                                       _ERR("loadRules failed");
+                                               }
+                                       }
+                               }
+                               else
+                               {
+                                       _INFO("access rules are not changed. skip update");
+                               }
+                               tlv.returnToParentTLV();
+                       }
+                       else
+                       {
+                               _ERR("tlv.decodeTLV failed");
+                       }
+               }
+               else
+               {
+                       _ERR("OID not found");
+               }
+
+               return result;
+       }
+
+       int GPARFACL::loadRules(Channel *channel, const ByteArray &path)
+       {
+               FileObject file(channel);
+               ByteArray data, aid;
+
+               file.select(NumberStream::getLittleEndianNumber(path));
+               file.readBinary(0, 0, file.getFCP()->getFileSize(), data);
+
+               _DBG("data : %s", data.toString().c_str());
+
+               SimpleTLV tlv(data);
+
+               while (tlv.decodeTLV() == true && tlv.getTag() == 0x30) /* SEQUENCE : Rule */
+               {
+                       tlv.enterToValueTLV();
+                       if (tlv.decodeTLV() == true)
+                       {
+                               /* target */
+                               switch (tlv.getTag())
+                               {
+                               case 0xA0 : /* CHOICE 0 : EXPLICIT AID */
+                                       /* OCTET STRING */
+                                       aid = SimpleTLV::getOctetString(tlv.getValue());
+                                       break;
+
+                               case 0x81 : /* CHOICE 1?? : default */
+                                       aid = AccessControlList::DEFAULT_SE_APP;
+                                       break;
+
+                               case 0x82 : /* CHOICE 2?? : any application */
+                                       aid = AccessControlList::ALL_SE_APPS;
+                                       break;
+                               }
+
+                               _DBG("aid : %s", aid.toString().c_str());
+
+                               /* access condition path */
+                               if (tlv.decodeTLV() == true && tlv.getTag() == 0x30) /* SEQUENCE : Path */
+                               {
+                                       ByteArray path;
+
+                                       /* OCTET STRING */
+                                       path = SimpleTLV::getOctetString(tlv.getValue());
+                                       _DBG("path : %s", path.toString().c_str());
+
+                                       if (loadAccessConditions(channel, aid, path) == 0)
+                                       {
+                                               _DBG("loadCertHashes success");
+                                       }
+                                       else
+                                       {
+                                               _ERR("loadCertHashes failed");
+                                       }
+                               }
+                               else
+                               {
+                                       _ERR("decodeTLV failed");
+                               }
+                       }
+                       else
+                       {
+                               _ERR("decodeTLV failed");
+                       }
+                       tlv.returnToParentTLV();
+               }
+
+               return 0;
+       }
+
+       static void loadAPDUAccessRule(AccessRule *rule, const ByteArray &data)
+       {
+               SimpleTLV tlv(data);
+
+               if (rule == NULL) {
+                       _ERR("invalid parameter");
+                       return;
+               }
+
+               if (tlv.decodeTLV() == true)
+               {
+                       switch (tlv.getTag())
+                       {
+                       case 0xA0 : /* CHOICE 0 : APDUPermission */
+                               rule->setAPDUAccessRule(SimpleTLV::getBoolean(tlv.getValue()));
+                               break;
+
+                       case 0xA1 : /* CHOICE 1 : APDUFilters */
+                               tlv.enterToValueTLV();
+                               while (tlv.decodeTLV() == true)
+                               {
+                                       if (tlv.getTag() == 0x04) /* OCTET STRING */
+                                       {
+                                               ByteArray apdu, mask, value;
+
+                                               value = tlv.getValue();
+
+                                               _DBG("APDU rule : %s", value.toString().c_str());
+
+                                               if (value.size() == 8) /* apdu 4 bytes + mask 4 bytes */
+                                               {
+                                                       apdu.assign(value.getBuffer(), 4);
+                                                       mask.assign(value.getBuffer(4), 4);
+
+                                                       rule->addAPDUAccessRule(apdu, mask);
+                                               }
+                                               else
+                                               {
+                                                       _ERR("Invalid APDU rule : %s", value.toString().c_str());
+                                               }
+                                       }
+                                       else
+                                       {
+                                               _ERR("Unknown tag : 0x%02X", tlv.getTag());
+                                       }
+                               }
+                               tlv.returnToParentTLV();
+                               break;
+
+                       default :
+                               _ERR("Unknown tag : 0x%02X", tlv.getTag());
+                               break;
+                       }
+               }
+       }
+
+       static void loadNFCAccessRule(AccessRule *rule, const ByteArray &data)
+       {
+               if (rule == NULL) {
+                       _ERR("invalid parameter");
+                       return;
+               }
+
+               rule->setNFCAccessRule(SimpleTLV::getBoolean(data));
+       }
+
+       static void loadAccessCondition(AccessCondition &condition, const ByteArray &data)
+       {
+               if (data.size() > 0)
+               {
+                       SimpleTLV tlv(data);
+                       ByteArray hash;
+
+                       while (tlv.decodeTLV() == true && tlv.getTag() == 0x30) /* SEQUENCE */
+                       {
+                               if (tlv.size() > 0)
+                               {
+                                       /* access granted for specific applications */
+                                       tlv.enterToValueTLV();
+                                       if (tlv.decodeTLV())
+                                       {
+                                               switch (tlv.getTag())
+                                               {
+                                               case 0x04 : /* OCTET STRING : CertHash */
+                                                       _DBG("aid : %s, hash : %s", condition.getAID().toString().c_str(), tlv.getValue().toString().c_str());
+
+                                                       hash = tlv.getValue();
+                                                       condition.addAccessRule(tlv.getValue());
+                                                       break;
+
+                                               case 0xA0 : /* CHOICE 0 : AccessRules */
+                                                       tlv.enterToValueTLV();
+                                                       if (tlv.decodeTLV())
+                                                       {
+                                                               AccessRule *rule = condition.getAccessRule(hash);
+                                                               if (rule == NULL) {
+                                                                       condition.addAccessRule(hash);
+                                                                       rule = condition.getAccessRule(hash);
+                                                               }
+
+                                                               switch (tlv.getTag())
+                                                               {
+                                                               case 0xA0 : /* CHOICE 0 : APDUAccessRule */
+                                                                       loadAPDUAccessRule(rule, tlv.getValue());
+                                                                       break;
+
+                                                               case 0xA1 : /* CHOICE 1 : NFCAccessRule */
+                                                                       loadNFCAccessRule(rule, tlv.getValue());
+                                                                       break;
+
+                                                               default :
+                                                                       _ERR("Unknown tag : 0x%02X", tlv.getTag());
+                                                                       break;
+                                                               }
+                                                       }
+                                                       else
+                                                       {
+                                                               _ERR("tlv.decodeTLV failed");
+                                                       }
+                                                       tlv.returnToParentTLV();
+                                                       break;
+
+                                               default :
+                                                       _ERR("Unknown tag : 0x%02X", tlv.getTag());
+                                                       break;
+                                               }
+                                       }
+                                       else
+                                       {
+                                               _ERR("tlv.decodeTLV failed");
+                                       }
+                                       tlv.returnToParentTLV();
+                               }
+                               else
+                               {
+                                       _INFO("access denied for all applications, aid : %s", condition.getAID().toString().c_str());
+
+                                       condition.setAccessCondition(false);
+                                       break;
+                               }
+                       }
+               }
+               else
+               {
+                       _INFO("access denied for all applications, aid : %s", condition.getAID().toString().c_str());
+
+                       condition.setAccessCondition(false);
+               }
+       }
+
+       int GPARFACL::loadAccessConditions(Channel *channel, const ByteArray &aid, const ByteArray &path)
+       {
+               FileObject file(channel);
+               ByteArray data;
+
+               file.select(NumberStream::getLittleEndianNumber(path));
+               file.readBinary(0, 0, file.getFCP()->getFileSize(), data);
+
+               _DBG("data : %s", data.toString().c_str());
+
+               AccessCondition condition;
+
+               condition.setAID(aid);
+               loadAccessCondition(condition, data);
+
+               pair<ByteArray, AccessCondition> newItem(aid, condition);
+
+               mapConditions.insert(newItem);
+
+               return 0;
+       }
+
+} /* namespace smartcard_service_api */
diff --git a/common/GPSEACL.cpp b/common/GPSEACL.cpp
deleted file mode 100644 (file)
index a6eb0f7..0000000
+++ /dev/null
@@ -1,341 +0,0 @@
-/*
- * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/* standard library header */
-
-/* SLP library header */
-
-/* local header */
-#include "Debug.h"
-#include "GPSEACL.h"
-#include "PKCS15ODF.h"
-#include "PKCS15DODF.h"
-#include "NumberStream.h"
-#include "SimpleTLV.h"
-#include "AccessCondition.h"
-
-#ifndef EXTERN_API
-#define EXTERN_API __attribute__((visibility("default")))
-#endif
-
-namespace smartcard_service_api
-{
-       static unsigned char oid_globalplatform[] = { 0x2A, 0x86, 0x48, 0x86, 0xFC, 0x6B, 0x81, 0x48, 0x01, 0x01 };
-       ByteArray GPSEACL::OID_GLOBALPLATFORM(ARRAY_AND_SIZE(oid_globalplatform));
-
-       GPSEACL::GPSEACL():AccessControlList()
-       {
-       }
-
-       GPSEACL::~GPSEACL()
-       {
-       }
-
-       int GPSEACL::loadACL(Channel *channel)
-       {
-               int result = 0;
-               PKCS15 *pkcs15;
-
-               if (channel == NULL)
-               {
-                       return -1;
-               }
-
-               pkcs15 = new PKCS15(channel, channel->getSelectResponse());
-               if (pkcs15 != NULL)
-               {
-                       /* basically, all requests will be accepted when PKCS #15 doesn't exist or global platform OID is not placed */
-                       allGranted = true;
-
-                       if (pkcs15->isClosed() == false)
-                       {
-                               PKCS15ODF *odf;
-
-                               if ((odf = pkcs15->getODF()) != NULL)
-                               {
-                                       PKCS15DODF *dodf;
-
-                                       if ((dodf = odf->getDODF()) != NULL)
-                                       {
-                                               if (loadAccessControl(channel, dodf) == 0)
-                                               {
-                                                       printAccessControlList();
-
-                                                       result = 0;
-                                               }
-                                               else
-                                               {
-                                                       SCARD_DEBUG_ERR("loadAccessControl failed, every request will be accepted.");
-                                               }
-                                       }
-                                       else
-                                       {
-                                               SCARD_DEBUG_ERR("dodf null, every request will be accepted.");
-                                       }
-                               }
-                               else
-                               {
-                                       SCARD_DEBUG_ERR("odf null, every request will be accepted.");
-                               }
-                       }
-                       else
-                       {
-                               SCARD_DEBUG_ERR("failed to open PKCS15, every request will be accepted.");
-                       }
-
-                       delete pkcs15;
-               }
-               else
-               {
-                       return -1;
-               }
-
-               return result;
-       }
-
-       int GPSEACL::loadAccessControl(Channel *channel, PKCS15DODF *dodf)
-       {
-               int result = -1;
-               ByteArray path;
-
-               if ((result = dodf->searchOID(OID_GLOBALPLATFORM, path)) == 0)
-               {
-                       ByteArray data;
-                       FileObject file(channel);
-
-                       SCARD_DEBUG("oid path : %s", path.toString());
-
-                       file.select(NumberStream::getLittleEndianNumber(path));
-                       file.readBinary(0, 0, file.getFCP()->getFileSize(), data);
-
-                       SCARD_DEBUG("data : %s", data.toString());
-
-                       /* PKCS #15 and DODF OID exists. apply access control rule!! */
-                       allGranted = false;
-
-                       SimpleTLV tlv(data);
-
-                       if (tlv.decodeTLV() == true && tlv.getTag() == 0x30) /* SEQUENCE : AccessControlMainFile */
-                       {
-                               tlv.enterToValueTLV();
-
-                               /* refresh Tag */
-                               ByteArray refreshTag;
-
-                               refreshTag = SimpleTLV::getOctetString(tlv);
-                               SCARD_DEBUG("current refresh tag : %s", refreshTag.toString());
-
-                               if (this->refreshTag != refreshTag) /* need to update access control list */
-                               {
-                                       this->refreshTag = refreshTag;
-
-                                       releaseACL();
-
-                                       /* access control rule path */
-                                       if (tlv.decodeTLV() == true && tlv.getTag() == 0x30) /* SEQUENCE : Path */
-                                       {
-                                               /* TODO : parse path */
-                                               ByteArray path;
-
-                                               /* OCTET STRING */
-                                               path = SimpleTLV::getOctetString(tlv.getValue());
-                                               SCARD_DEBUG("access control rule path : %s", path.toString());
-
-                                               if (loadRules(channel, path) == 0)
-                                               {
-                                                       SCARD_DEBUG("loadRules success");
-                                               }
-                                               else
-                                               {
-                                                       SCARD_DEBUG_ERR("loadRules failed");
-                                               }
-                                       }
-                               }
-                               tlv.returnToParentTLV();
-                       }
-                       else
-                       {
-                               SCARD_DEBUG_ERR("tlv.decodeTLV failed");
-                       }
-               }
-               else
-               {
-                       SCARD_DEBUG_ERR("OID not found");
-               }
-
-               return result;
-       }
-
-       int GPSEACL::loadRules(Channel *channel, ByteArray path)
-       {
-               FileObject file(channel);
-               ByteArray data, aid;
-
-               file.select(NumberStream::getLittleEndianNumber(path));
-               file.readBinary(0, 0, file.getFCP()->getFileSize(), data);
-
-               SCARD_DEBUG("data : %s", data.toString());
-
-               SimpleTLV tlv(data);
-
-               while (tlv.decodeTLV() == true && tlv.getTag() == 0x30) /* SEQUENCE : Rule */
-               {
-                       tlv.enterToValueTLV();
-                       if (tlv.decodeTLV() == true)
-                       {
-                               /* target */
-                               switch (tlv.getTag())
-                               {
-                               case 0xA0 : /* CHOICE 0 : EXPLICIT AID */
-                                       /* OCTET STRING */
-                                       aid = SimpleTLV::getOctetString(tlv.getValue());
-                                       break;
-
-                               case 0x81 : /* CHOICE 1?? : default */
-                                       aid = AccessControlList::AID_DEFAULT;
-                                       break;
-
-                               case 0x82 : /* CHOICE 2?? : any application */
-                                       aid = AccessControlList::AID_ALL;
-                                       break;
-                               }
-
-                               SCARD_DEBUG("aid : %s", aid.toString());
-
-                               /* access condition path */
-                               if (tlv.decodeTLV() == true && tlv.getTag() == 0x30) /* SEQUENCE : Path */
-                               {
-                                       ByteArray path;
-
-                                       /* OCTET STRING */
-                                       path = SimpleTLV::getOctetString(tlv.getValue());
-                                       SCARD_DEBUG("path : %s", path.toString());
-
-                                       if (loadAccessConditions(channel, aid, path) == 0)
-                                       {
-                                               SCARD_DEBUG("loadCertHashes success");
-                                       }
-                                       else
-                                       {
-                                               SCARD_DEBUG_ERR("loadCertHashes failed");
-                                       }
-                               }
-                               else
-                               {
-                                       SCARD_DEBUG_ERR("decodeTLV failed");
-                               }
-                       }
-                       else
-                       {
-                               SCARD_DEBUG_ERR("decodeTLV failed");
-                       }
-                       tlv.returnToParentTLV();
-               }
-
-               return 0;
-       }
-
-       int GPSEACL::loadAccessConditions(Channel *channel, ByteArray aid, ByteArray path)
-       {
-               FileObject file(channel);
-               ByteArray data;
-
-               file.select(NumberStream::getLittleEndianNumber(path));
-               file.readBinary(0, 0, file.getFCP()->getFileSize(), data);
-
-               SCARD_DEBUG("data : %s", data.toString());
-
-               AccessCondition condition;
-
-               condition.loadAccessCondition(aid, data);
-
-               pair<ByteArray, AccessCondition> newItem(aid, condition);
-
-               mapConditions.insert(newItem);
-
-               return 0;
-       }
-
-} /* namespace smartcard_service_api */
-
-/* export C API */
-#define GP_SE_ACL_EXTERN_BEGIN \
-       if (handle != NULL) \
-       { \
-               GPSEACL *acl = (GPSEACL *)handle;
-
-#define GP_SE_ACL_EXTERN_END \
-       } \
-       else \
-       { \
-               SCARD_DEBUG_ERR("Invalid param"); \
-       }
-
-using namespace smartcard_service_api;
-
-EXTERN_API gp_se_acl_h gp_se_acl_create_instance()
-{
-       GPSEACL *acl = new GPSEACL();
-
-       return (gp_se_acl_h)acl;
-}
-
-EXTERN_API int gp_se_acl_load_acl(gp_se_acl_h handle, channel_h channel)
-{
-       int result = -1;
-
-       GP_SE_ACL_EXTERN_BEGIN;
-       result = acl->loadACL((Channel *)channel);
-       GP_SE_ACL_EXTERN_END;
-
-       return result;
-}
-
-EXTERN_API int gp_se_acl_update_acl(gp_se_acl_h handle, channel_h channel)
-{
-       int result = -1;
-
-       GP_SE_ACL_EXTERN_BEGIN;
-       acl->updateACL((Channel *)channel);
-       GP_SE_ACL_EXTERN_END;
-
-       return result;
-}
-
-EXTERN_API void gp_se_acl_release_acl(gp_se_acl_h handle)
-{
-       GP_SE_ACL_EXTERN_BEGIN;
-       acl->releaseACL();
-       GP_SE_ACL_EXTERN_END;
-}
-
-EXTERN_API bool gp_se_acl_is_authorized_access(gp_se_acl_h handle, unsigned char *aidBuffer, unsigned int aidLength, unsigned char *certHashBuffer, unsigned int certHashLength)
-{
-       bool result = false;
-
-       GP_SE_ACL_EXTERN_BEGIN;
-       result = acl->isAuthorizedAccess(aidBuffer, aidLength, certHashBuffer, certHashLength);
-       GP_SE_ACL_EXTERN_END;
-
-       return result;
-}
-
-EXTERN_API void gp_se_acl_destroy_instance(gp_se_acl_h handle)
-{
-       GP_SE_ACL_EXTERN_BEGIN;
-       delete acl;
-       GP_SE_ACL_EXTERN_END;
-}
index 708575a..4f8a363 100644 (file)
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 
+#ifndef USE_GDBUS
 /* standard library header */
 #include <stdio.h>
 #include <stdlib.h>
@@ -39,7 +40,7 @@
 #include "IPCHelper.h"
 
 #ifdef USE_UNIX_DOMAIN
-#define SCARD_SERVER_DOMAIN "/tmp/omapi-server-domain"
+#define SCARD_SERVER_DOMAIN "/tmp/smartcard-server-domain"
 #endif /* USE_UNIX_DOMAIN */
 
 static void setNonBlockSocket(int socket)
@@ -52,7 +53,7 @@ static void setNonBlockSocket(int socket)
 
        if (fcntl(socket, F_SETFL, flags) < 0)
        {
-               /* SCARD_DEBUG_ERR("fcntl, executing nonblock error"); */
+               /* _ERR("fcntl, executing nonblock error"); */
        }
 }
 
@@ -78,11 +79,11 @@ namespace smartcard_service_api
                IPCHelper *helper = (IPCHelper *)data;
                gboolean result = FALSE;
 
-               SCARD_DEBUG("channel [%p], condition [%d], data [%p]", channel, condition, data);
+               _DBG("channel [%p], condition [%d], data [%p]", channel, condition, data);
 
                if (helper == NULL)
                {
-                       SCARD_DEBUG_ERR("ipchelper is null");
+                       _ERR("ipchelper is null");
                        return result;
                }
 
@@ -117,7 +118,7 @@ namespace smartcard_service_api
                ipcSocket = socket(AF_UNIX, SOCK_STREAM, 0);
                if (ipcSocket == -1)
                {
-                       SCARD_DEBUG_ERR("get socket is failed");
+                       _ERR("get socket is failed");
                        return false;
                }
 
@@ -128,19 +129,19 @@ namespace smartcard_service_api
 
                if (bind(ipcSocket, (struct sockaddr *)&saddrun_rv, sizeof(saddrun_rv)) < 0)
                {
-                       SCARD_DEBUG_ERR("bind is failed \n");
+                       _ERR("bind is failed");
                        goto ERROR;
                }
 
                if (chmod(SCARD_SERVER_DOMAIN, 0777) < 0)
                {
-                       SCARD_DEBUG_ERR("can not change permission of UNIX DOMAIN file");
+                       _ERR("can not change permission of UNIX DOMAIN file");
                        goto ERROR;
                }
 
                if (listen(ipcSocket, IPC_SERVER_MAX_CLIENT) < 0)
                {
-                       SCARD_DEBUG_ERR("listen is failed \n");
+                       _ERR("listen is failed");
                        goto ERROR;
                }
 
@@ -148,13 +149,13 @@ namespace smartcard_service_api
                {
                        if ((watchId = g_io_add_watch(ioChannel, condition, &IPCHelper::channelCallbackFunc, this)) < 1)
                        {
-                               SCARD_DEBUG_ERR(" g_io_add_watch is failed \n");
+                               _ERR(" g_io_add_watch is failed");
                                goto ERROR;
                        }
                }
                else
                {
-                       SCARD_DEBUG_ERR(" g_io_channel_unix_new is failed \n");
+                       _ERR(" g_io_channel_unix_new is failed");
                        goto ERROR;
                }
 
@@ -165,7 +166,7 @@ namespace smartcard_service_api
                gid = security_server_get_gid("smartcard-service");
                if(gid == 0)
                {
-                       SCARD_DEBUG("get gid from security server is failed. this object is not allowed by security server");
+                       _DBG("get gid from security server is failed. this object is not allowed by security server");
                        goto ERROR;
                }
 
@@ -178,11 +179,11 @@ namespace smartcard_service_api
                }
 #endif
 
-               SCARD_DEBUG("server ipc is initialized");
+               _INFO("server ipc is initialized");
 
                return true;
 ERROR :
-               SCARD_DEBUG_ERR("error while initializing server ipc");
+               _ERR("error while initializing server ipc");
 
                destroyListenSocket();
 
@@ -203,11 +204,11 @@ ERROR :
 
                        for (i = 0; i < events; i++)
                        {
-                               SCARD_DEBUG("pollEvents[%d].events [%X]", i, pollEvents[i].events);
+                               _DBG("pollEvents[%d].events [%X]", i, pollEvents[i].events);
 
                                if ((pollEvents[i].events & EPOLLHUP) || (pollEvents[i].events & EPOLLERR))
                                {
-                                       SCARD_DEBUG_ERR("connection is closed");
+                                       _ERR("connection is closed");
                                        result = 0;
                                        break;
                                }
@@ -220,13 +221,13 @@ ERROR :
                }
                else if (errno == EINTR)
                {
-                       SCARD_DEBUG_ERR("epoll_wait interrupted");
+                       _ERR("epoll_wait interrupted");
                }
                else
                {
                        char buffer[1024];
 
-                       SCARD_DEBUG_ERR("epoll_wait failed, errno [%d], %s", errno, strerror_r(errno, buffer, sizeof(buffer)));
+                       _ERR("epoll_wait failed, errno [%d], %s", errno, strerror_r(errno, buffer, sizeof(buffer)));
                }
 #else
                if (select(ipcSocket + 1, &fdSetRead, NULL, NULL, NULL) > 0)
@@ -240,30 +241,30 @@ ERROR :
                                {
                                        if (val == 0)
                                        {
-                                               SCARD_DEBUG("socket is readable");
+                                               _DBG("socket is readable");
                                                result = 1;
                                        }
                                        else
                                        {
-                                               SCARD_DEBUG("socket is not available. maybe disconnected");
+                                               _DBG("socket is not available. maybe disconnected");
                                                result = 0;
                                        }
                                }
                                else
                                {
-                                       SCARD_DEBUG_ERR("getsockopt failed, errno [%d]", errno);
+                                       _ERR("getsockopt failed, errno [%d]", errno);
                                        result = errno;
                                }
                        }
                        else
                        {
-                               SCARD_DEBUG_ERR("FD_ISSET false!!! what's wrong");
+                               _ERR("FD_ISSET false!!! what's wrong");
                                result = -1;
                        }
                }
                else
                {
-                       SCARD_DEBUG_ERR("select failed [%d]", errno);
+                       _ERR("select failed [%d]", errno);
                        result = errno;
                }
 #endif
@@ -282,7 +283,7 @@ ERROR :
                sigemptyset(&newmask);
                sigaddset(&newmask, SIGTERM);
                pthread_sigmask(SIG_UNBLOCK, &newmask, NULL);
-               SCARD_DEBUG("sighandler is registered");
+               _DBG("sighandler is registered");
 
                pthread_mutex_lock(&g_client_lock);
                pthread_cond_signal ((pthread_cond_t *) data);
@@ -312,7 +313,7 @@ ERROR :
                        }
                }
 
-               SCARD_DEBUG("threadRead is terminated");
+               _INFO("threadRead is terminated");
 
                return (void *)NULL;
        }
@@ -326,7 +327,7 @@ ERROR :
                int result = 0;
                char err[200] = { 0, };
 
-               SCARD_BEGIN();
+               _BEGIN();
 
                if (ipcSocket >= 0)
                        return true;
@@ -341,12 +342,12 @@ ERROR :
                ipcSocket = socket(AF_UNIX, SOCK_STREAM, 0);
                if (ipcSocket == -1)
                {
-                       SCARD_DEBUG_ERR("get socket is failed [%d, %s]",
+                       _ERR("get socket is failed [%d, %s]",
                                errno, strerror_r(errno, err, sizeof(err)));
                        goto ERROR;
                }
 
-               SCARD_DEBUG("socket is created");
+               _DBG("socket is created");
 
                ::setNonBlockSocket(ipcSocket);
 
@@ -357,7 +358,7 @@ ERROR :
 
                if ((result = connect(ipcSocket, (struct sockaddr *)&saddrun_rv, len_saddr)) < 0)
                {
-                       SCARD_DEBUG_ERR("connect failed [%d, %s]",
+                       _ERR("connect failed [%d, %s]",
                                errno, strerror_r(errno, err, sizeof(err)));
                        goto ERROR;
                }
@@ -366,7 +367,7 @@ ERROR :
 #ifdef USE_IPC_EPOLL
                if((fdPoll = epoll_create1(EPOLL_CLOEXEC)) == -1)
                {
-                       SCARD_DEBUG_ERR("epoll_create1 failed [%d, %s]",
+                       _ERR("epoll_create1 failed [%d, %s]",
                                errno, strerror_r(errno, err, sizeof(err)));
                        goto ERROR;
                }
@@ -374,7 +375,7 @@ ERROR :
                pollEvents = (struct epoll_event *)calloc(EPOLL_SIZE, sizeof(struct epoll_event));
                if (pollEvents == NULL)
                {
-                       SCARD_DEBUG_ERR("alloc failed");
+                       _ERR("alloc failed");
                        goto ERROR;
                }
 
@@ -396,7 +397,7 @@ ERROR :
                if (pthread_create(&readThread, NULL, &IPCHelper::threadRead, this) != 0)
 #endif
                {
-                       SCARD_DEBUG_ERR("pthread_create is failed");
+                       _ERR("pthread_create is failed");
                        goto ERROR;
                }
 
@@ -409,32 +410,32 @@ ERROR :
                {
                        if ((watchId = g_io_add_watch(ioChannel, condition, &IPCHelper::channelCallbackFunc, this)) < 1)
                        {
-                               SCARD_DEBUG_ERR(" g_io_add_watch is failed");
+                               _ERR(" g_io_add_watch is failed");
                                goto ERROR;
                        }
                }
                else
                {
-                       SCARD_DEBUG_ERR(" g_io_channel_unix_new is failed");
+                       _ERR(" g_io_channel_unix_new is failed");
                        goto ERROR;
                }
 #endif
                pthread_mutex_unlock(&ipcLock);
 
-               SCARD_DEBUG("connecting success");
+               _INFO("connecting success");
 
-               SCARD_END();
+               _END();
 
                return true;
 
 ERROR :
-               SCARD_DEBUG_ERR("error while initializing client ipc");
+               _ERR("error while initializing client ipc");
 
                destroyConnectSocket();
 
                pthread_mutex_unlock(&ipcLock);
 
-               SCARD_END();
+               _END();
 
                return false;
        }
@@ -516,26 +517,26 @@ ERROR :
                }
        }
 
-       bool IPCHelper::sendMessage(int socket, Message *msg)
+       bool IPCHelper::sendMessage(int socket, const Message &msg)
        {
                ByteArray stream;
                unsigned int length = 0;
 
-               stream = msg->serialize();
-               length = stream.getLength();
+               stream = msg.serialize();
+               length = stream.size();
 
-               SCARD_DEBUG(">>>[SEND]>>> socket [%d], msg [%d], length [%d]",
-                       socket, msg->message, stream.getLength());
+               _DBG(">>>[SEND]>>> socket [%d], msg [%d], length [%d]",
+                       socket, msg.message, stream.size());
 
                return sendMessage(socket, stream);
        }
 
-       bool IPCHelper::sendMessage(int socket, ByteArray &buffer)
+       bool IPCHelper::sendMessage(int socket, const ByteArray &buffer)
        {
                bool result = false;
                unsigned int length = 0;
 
-               length = buffer.getLength();
+               length = buffer.size();
 
                if (length > 0)
                {
@@ -564,12 +565,12 @@ ERROR :
                        }
                        else
                        {
-                               SCARD_DEBUG_ERR("send failed, sentBytes [%d]", sentBytes);
+                               _ERR("send failed, sentBytes [%d]", sentBytes);
                        }
                }
                else
                {
-                       SCARD_DEBUG_ERR("stream length is zero");
+                       _ERR("stream length is zero");
                }
 
                return result;
@@ -585,10 +586,10 @@ ERROR :
                ByteArray buffer;
                Message *msg = NULL;
 
-               SCARD_BEGIN();
+               _BEGIN();
 
                buffer = retrieveBuffer(socket);
-               if (buffer.getLength() > 0)
+               if (buffer.size() > 0)
                {
                        msg = new Message();
                        if (msg != NULL)
@@ -597,26 +598,26 @@ ERROR :
                        }
                        else
                        {
-                               SCARD_DEBUG_ERR("alloc failed");
+                               _ERR("alloc failed");
                        }
                }
                else
                {
-                       SCARD_DEBUG_ERR("retrieveBuffer failed ");
+                       _ERR("retrieveBuffer failed ");
                }
 
-               SCARD_END();
+               _END();
 
                return msg;
        }
 
-       ByteArray IPCHelper::retrieveBuffer(int socket)
+       const ByteArray IPCHelper::retrieveBuffer(int socket)
        {
                ByteArray buffer;
                unsigned int length = 0;
                int readBytes = 0;
 
-               SCARD_BEGIN();
+               _BEGIN();
 
                /* read 4 bytes (length) */
                pthread_mutex_lock(&ipcLock);
@@ -647,28 +648,28 @@ ERROR :
                                        while (current < length);
                                        pthread_mutex_unlock(&ipcLock);
 
-                                       SCARD_DEBUG("<<<[RETRIEVE]<<< socket [%d], msg_length [%d]", socket, length);
+                                       _DBG("<<<[RETRIEVE]<<< socket [%d], msg_length [%d]", socket, length);
 
-                                       buffer.setBuffer(temp, length);
+                                       buffer.assign(temp, length);
 
                                        delete []temp;
                                }
                                else
                                {
-                                       SCARD_DEBUG_ERR("allocation failed");
+                                       _ERR("allocation failed");
                                }
                        }
                        else
                        {
-                               SCARD_DEBUG_ERR("invalid length, socket = [%d], msg_length = [%d]", socket, length);
+                               _ERR("invalid length, socket = [%d], msg_length = [%d]", socket, length);
                        }
                }
                else
                {
-                       SCARD_DEBUG_ERR("failed to recv length, socket = [%d], readBytes [%d]", socket, readBytes);
+                       _ERR("failed to recv length, socket = [%d], readBytes [%d]", socket, readBytes);
                }
 
-               SCARD_END();
+               _END();
 
                return buffer;
        }
@@ -679,3 +680,4 @@ ERROR :
        }
 
 } /* namespace smartcard_service_api */
+#endif
index 425376a..3ea9054 100644 (file)
 
 namespace smartcard_service_api
 {
-       ISO7816BERTLV::ISO7816BERTLV():TLVHelper()
+       ISO7816BERTLV::ISO7816BERTLV() : TLVHelper(), firstByte(0), tagClass(0),
+               encoding(0)
        {
-               tagClass = 0;
-               encoding = 0;
        }
 
-       ISO7816BERTLV::ISO7816BERTLV(TLVHelper *parent):TLVHelper(parent)
+       ISO7816BERTLV::ISO7816BERTLV(TLVHelper *parent) : TLVHelper(parent),
+               firstByte(0), tagClass(0), encoding(0)
        {
-               parentTLV = parent;
-
-               tagClass = 0;
-               encoding = 0;
        }
 
-       ISO7816BERTLV::ISO7816BERTLV(const ByteArray &array):TLVHelper(array)
+       ISO7816BERTLV::ISO7816BERTLV(const ByteArray &array) : TLVHelper(array),
+                       firstByte(0), tagClass(0), encoding(0)
        {
-               tagClass = 0;
-               encoding = 0;
        }
 
-       ISO7816BERTLV::ISO7816BERTLV(const ByteArray &array, TLVHelper *parent):TLVHelper(array, parent)
+       ISO7816BERTLV::ISO7816BERTLV(const ByteArray &array, TLVHelper *parent) :
+               TLVHelper(array, parent), firstByte(0), tagClass(0), encoding(0)
        {
-               parentTLV = parent;
-
-               tagClass = 0;
-               encoding = 0;
        }
 
        ISO7816BERTLV::~ISO7816BERTLV()
@@ -62,7 +54,7 @@ namespace smartcard_service_api
                }
        }
 
-       int ISO7816BERTLV::decodeTag(unsigned char *buffer)
+       int ISO7816BERTLV::decodeTag(const unsigned char *buffer)
        {
                /* 0x00 is invalid tag value */
                if (buffer[0] == 0x00)
@@ -71,7 +63,7 @@ namespace smartcard_service_api
                }
 
                /* first byte */
-               tagClass = (buffer[0] & 0xE0) >> 6;
+               tagClass = (buffer[0] & 0xC0) >> 6;
                encoding = (buffer[0] & 0x20) >> 5;
 
                currentT = buffer[0];
@@ -99,7 +91,7 @@ namespace smartcard_service_api
                return 2;
        }
 
-       int ISO7816BERTLV::decodeLength(unsigned char *buffer)
+       int ISO7816BERTLV::decodeLength(const unsigned char *buffer)
        {
                if (buffer[0] & 0x80)
                {
@@ -110,7 +102,7 @@ namespace smartcard_service_api
                        if (count > 4)
                                return -1;
 
-                       count++; /* increse count and increase i value, too */
+                       count++;
 
                        for (i = 1; i < count; i++)
                        {
@@ -131,27 +123,27 @@ namespace smartcard_service_api
                }
        }
 
-       int ISO7816BERTLV::decodeValue(unsigned char *buffer)
+       int ISO7816BERTLV::decodeValue(const unsigned char *buffer)
        {
                if (currentL == 0)
                        return 0;
 
-               currentV.setBuffer(buffer, currentL);
+               currentV.assign(buffer, currentL);
 
                return currentL;
        }
 
-       unsigned int ISO7816BERTLV::getClass()
+       unsigned int ISO7816BERTLV::getClass() const
        {
                return tagClass;
        }
 
-       unsigned int ISO7816BERTLV::getEncoding()
+       unsigned int ISO7816BERTLV::getEncoding() const
        {
                return encoding;
        }
 
-       ByteArray ISO7816BERTLV::encode(unsigned int tagClass, unsigned int encoding, unsigned int tag, ByteArray buffer)
+       const ByteArray ISO7816BERTLV::encode(unsigned int tagClass, unsigned int encoding, unsigned int tag, const ByteArray &buffer)
        {
                unsigned char temp_tag[3] = { 0, };
                unsigned char temp_tag_len = 0;
@@ -195,9 +187,9 @@ namespace smartcard_service_api
                total_len += temp_tag_len;
 
                /* add length's length */
-               if (buffer.getLength() < 128)
+               if (buffer.size() < 128)
                {
-                       temp_len[0] = buffer.getLength();
+                       temp_len[0] = buffer.size();
 
                        temp_len_len = 1;
                }
@@ -206,32 +198,32 @@ namespace smartcard_service_api
                        temp_len[0] = 0x80;
                        temp_len_len = 1;
 
-                       if (buffer.getLength() > 0x00FFFFFF)
+                       if (buffer.size() > 0x00FFFFFF)
                        {
-                               temp_len[4] = (buffer.getLength() & 0xFF000000) >> 24;
+                               temp_len[4] = (buffer.size() & 0xFF000000) >> 24;
                                temp_len_len++;
                        }
 
-                       if (buffer.getLength() > 0x0000FFFF)
+                       if (buffer.size() > 0x0000FFFF)
                        {
-                               temp_len[3] = (buffer.getLength() & 0x00FF0000) >> 16;
+                               temp_len[3] = (buffer.size() & 0x00FF0000) >> 16;
                                temp_len_len++;
                        }
 
-                       if (buffer.getLength() > 0x000000FF)
+                       if (buffer.size() > 0x000000FF)
                        {
-                               temp_len[2] = (buffer.getLength() & 0x0000FF00) >> 8;
+                               temp_len[2] = (buffer.size() & 0x0000FF00) >> 8;
                                temp_len_len++;
                        }
 
-                       temp_len[1] = buffer.getLength() & 0x000000FF;
+                       temp_len[1] = buffer.size() & 0x000000FF;
                        temp_len_len++;
 
                        temp_len[0] |= temp_len_len;
                }
 
                /* add buffer's length */
-               total_len += buffer.getLength();
+               total_len += buffer.size();
 
                /* alloc new buffer */
                temp_buffer = new unsigned char[total_len];
@@ -250,22 +242,22 @@ namespace smartcard_service_api
                current += temp_len_len;
 
                /* fill value */
-               if (buffer.getLength() > 0)
-                       memcpy(temp_buffer + current, buffer.getBuffer(), buffer.getLength());
+               if (buffer.size() > 0)
+                       memcpy(temp_buffer + current, buffer.getBuffer(), buffer.size());
 
-               result.setBuffer(temp_buffer, total_len);
+               result.assign(temp_buffer, total_len);
 
                delete []temp_buffer;
 
                return result;
        }
 
-       ByteArray ISO7816BERTLV::encode(unsigned int tagClass, unsigned int encoding, unsigned int tag, unsigned char *buffer, unsigned int length)
+       const ByteArray ISO7816BERTLV::encode(unsigned int tagClass, unsigned int encoding, unsigned int tag, unsigned char *buffer, unsigned int length)
        {
                return encode(tagClass, encoding, tag, ByteArray(buffer, length));
        }
 
-       TLVHelper *ISO7816BERTLV::getChildTLV(ByteArray data)
+       TLVHelper *ISO7816BERTLV::getChildTLV(const ByteArray &data)
        {
                if (childTLV != NULL)
                {
index 098528f..5beab7f 100644 (file)
  * limitations under the License.
  */
 
+#ifndef USE_GDBUS
 /* standard library header */
-#include <stdio.h>
-#include <string.h>
+#include <cstdio>
+#include <cstring>
+#include <sstream>
 
 /* SLP library header */
 
@@ -41,7 +43,7 @@ namespace smartcard_service_api
        {
        }
 
-       ByteArray Message::serialize()
+       const ByteArray Message::serialize() const
        {
                ByteArray result;
                unsigned int length = 0;
@@ -49,10 +51,10 @@ namespace smartcard_service_api
                unsigned char *buffer = NULL;
 
                length = sizeof(message) + sizeof(param1) + sizeof(param2) + sizeof(error) + sizeof(caller) + sizeof(callback) + sizeof(userParam);
-               if (data.getLength() > 0)
+               if (data.size() > 0)
                {
-                       dataLength = data.getLength();
-                       length += sizeof(dataLength) + data.getLength();
+                       dataLength = data.size();
+                       length += sizeof(dataLength) + data.size();
                }
 
                buffer = new unsigned char[length];
@@ -83,53 +85,53 @@ namespace smartcard_service_api
                        memcpy(buffer + current, &userParam, sizeof(userParam));
                        current += sizeof(userParam);
 
-                       if (data.getLength() > 0)
+                       if (data.size() > 0)
                        {
                                memcpy(buffer + current, &dataLength, sizeof(dataLength));
                                current += sizeof(dataLength);
 
                                memcpy(buffer + current, data.getBuffer(), dataLength);
-                               current += data.getLength();
+                               current += data.size();
                        }
 
-                       result.setBuffer(buffer, length);
+                       result.assign(buffer, length);
 
                        delete []buffer;
                }
                else
                {
-                       SCARD_DEBUG_ERR("allocation failed");
+                       _ERR("allocation failed");
                }
 
                return result;
        }
 
-       void Message::deserialize(ByteArray buffer)
+       void Message::deserialize(const ByteArray &buffer)
        {
-               deserialize(buffer.getBuffer(), buffer.getLength());
+               deserialize(buffer.getBuffer(), buffer.size());
        }
 
-       void Message::deserialize(unsigned char *buffer, unsigned int length)
+       void Message::deserialize(const unsigned char *buffer, unsigned int length)
        {
                unsigned int current = 0;
                unsigned int dataLength = 0;
 
-//             SCARD_DEBUG("buffer [%p], length [%d]", buffer, length);
+//             _DBG("buffer [%p], length [%d]", buffer, length);
 
                memcpy(&message, buffer + current, sizeof(message));
                current += sizeof(message);
 
-//             SCARD_DEBUG("message [%d]", message);
+//             _DBG("message [%d]", message);
 
                memcpy(&param1, buffer + current, sizeof(param1));
                current += sizeof(param1);
 
-//             SCARD_DEBUG("param1 [%d]", param1);
+//             _DBG("param1 [%d]", param1);
 
                memcpy(&param2, buffer + current, sizeof(param2));
                current += sizeof(param2);
 
-//             SCARD_DEBUG("param2 [%d]", param2);
+//             _DBG("param2 [%d]", param2);
 
                memcpy(&error, buffer + current, sizeof(error));
                current += sizeof(error);
@@ -143,26 +145,25 @@ namespace smartcard_service_api
                memcpy(&userParam, buffer + current, sizeof(userParam));
                current += sizeof(userParam);
 
-//             SCARD_DEBUG("userContext [%p]", userContext);
+//             _DBG("userContext [%p]", userContext);
 
                if (current + sizeof(dataLength) < length)
                {
                        memcpy(&dataLength, buffer + current, sizeof(dataLength));
                        current += sizeof(dataLength);
 
-//                     SCARD_DEBUG("dataLength [%d]", dataLength);
+//                     _DBG("dataLength [%d]", dataLength);
 
-                       data.setBuffer(buffer + current, dataLength);
+                       data.assign(buffer + current, dataLength);
                        current += dataLength;
                }
        }
 
-       const char *Message::toString()
+       const string Message::toString() const
        {
+               stringstream ss;
                const char *msg = NULL;
 
-               memset(&text, 0, sizeof(text));
-
                switch (message)
                {
                case MSG_REQUEST_READERS :
@@ -206,9 +207,10 @@ namespace smartcard_service_api
                        break;
                }
 
-               snprintf(text, sizeof(text), "Message [%s, %d], param1 [%ld], param2 [%ld], error [%ld], caller [%p], callback [%p], userParam [%p], data length [%d]", msg, message, param1, param2, error, caller, callback, userParam, data.getLength());
+               ss << "Message [" << msg << ", " << message << "], param1 [" << param1 << "], param2 [" << param2 << "], error [" << error << "], caller [" << "], callback [" << callback << "], userParam [" << userParam << "], data length [" << data.size() << "]";
 
-               return (const char *)text;
+               return ss.str();
        }
 
 } /* namespace smartcard_service_api */
+#endif
index 455ce16..bc7bd04 100644 (file)
@@ -20,15 +20,15 @@ namespace smartcard_service_api
 {
        NumberStream::NumberStream(const ByteArray &T)
        {
-               setBuffer(T.getBuffer(), T.getLength());
+               assign(T.getBuffer(), T.size());
        }
 
-       unsigned int NumberStream::getBigEndianNumber()
+       unsigned int NumberStream::getBigEndianNumber() const
        {
                return getBigEndianNumber(*this);
        }
 
-       unsigned int NumberStream::getLittleEndianNumber()
+       unsigned int NumberStream::getLittleEndianNumber() const
        {
                return getLittleEndianNumber(*this);
        }
@@ -37,7 +37,7 @@ namespace smartcard_service_api
        {
                if (this != &T)
                {
-                       setBuffer(T.getBuffer(), T.getLength());
+                       assign(T.getBuffer(), T.size());
                }
 
                return *this;
@@ -47,7 +47,7 @@ namespace smartcard_service_api
        {
                if (this != &T)
                {
-                       setBuffer(T.getBuffer(), T.getLength());
+                       assign(T.getBuffer(), T.size());
                }
 
                return *this;
@@ -58,11 +58,11 @@ namespace smartcard_service_api
                int i, len;
                unsigned int result = 0;
 
-               len = (T.getLength() < 4) ? T.getLength() : 4;
+               len = (T.size() < 4) ? T.size() : 4;
 
                for (i = 0; i < len; i++)
                {
-                       result = (result << 8) | T.getAt(i);
+                       result = (result << 8) | T.at(i);
                }
 
                return result;
@@ -73,11 +73,11 @@ namespace smartcard_service_api
                int i, len;
                unsigned int result = 0;
 
-               len = (T.getLength() < 4) ? T.getLength() : 4;
+               len = (T.size() < 4) ? T.size() : 4;
 
                for (i = 0; i < len; i++)
                {
-                       result = result | (T.getAt(i) << (i * 8));
+                       result = result | (T.at(i) << (i * 8));
                }
 
                return result;
index 52161d7..c4f670c 100644 (file)
@@ -36,7 +36,7 @@ namespace smartcard_service_api
                BUF_MEM *bptr;
                BIO *b64, *bmem;
 
-               if (buffer.getLength() == 0)
+               if (buffer.size() == 0)
                {
                        return ret;
                }
@@ -49,11 +49,11 @@ namespace smartcard_service_api
 
                b64 = BIO_push(b64, bmem);
 
-               BIO_write(b64, buffer.getBuffer(), buffer.getLength());
+               BIO_write(b64, buffer.getBuffer(), buffer.size());
                BIO_flush(b64);
                BIO_get_mem_ptr(b64, &bptr);
 
-               result.setBuffer((unsigned char *)bptr->data, bptr->length);
+               result.assign((unsigned char *)bptr->data, bptr->length);
 
                BIO_free_all(b64);
 
@@ -66,7 +66,7 @@ namespace smartcard_service_api
        {
                ByteArray temp;
 
-               temp.setBuffer((unsigned char *)buffer, strlen(buffer));
+               temp.assign((unsigned char *)buffer, strlen(buffer));
 
                return decodeBase64String(temp, result, newLineChar);
        }
@@ -77,12 +77,12 @@ namespace smartcard_service_api
                unsigned int length = 0;
                char *temp;
 
-               if (buffer.getBuffer() == NULL || buffer.getLength() == 0)
+               if (buffer.getBuffer() == NULL || buffer.size() == 0)
                {
                        return ret;
                }
 
-               length = buffer.getLength();
+               length = buffer.size();
 
                temp = new char[length];
                if (temp != NULL)
@@ -92,7 +92,7 @@ namespace smartcard_service_api
                        memset(temp, 0, length);
 
                        b64 = BIO_new(BIO_f_base64());
-                       bmem = BIO_new_mem_buf(buffer.getBuffer(), length);
+                       bmem = BIO_new_mem_buf((void *)buffer.getBuffer(), length);
                        if (newLineChar == false)
                                BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL);
                        bmem = BIO_push(b64, bmem);
@@ -101,7 +101,7 @@ namespace smartcard_service_api
 
                        BIO_free_all(bmem);
 
-                       result.setBuffer((unsigned char *)temp, length);
+                       result.assign((unsigned char *)temp, length);
 
                        delete []temp;
 
@@ -109,25 +109,27 @@ namespace smartcard_service_api
                }
                else
                {
-                       SCARD_DEBUG_ERR("alloc failed");
+                       _ERR("alloc failed");
                }
 
                return ret;
        }
 
-       bool OpensslHelper::digestBuffer(const char *algorithm, const uint8_t *buffer, const uint32_t length, ByteArray &result)
+       bool OpensslHelper::digestBuffer(const char *algorithm,
+               const uint8_t *buffer, uint32_t length, ByteArray &result)
        {
-               ByteArray temp((uint8_t *)buffer, (uint32_t)length);
+               ByteArray temp(buffer, length);
 
                return digestBuffer(algorithm, temp, result);
        }
 
-       bool OpensslHelper::digestBuffer(const char *algorithm, const ByteArray &buffer, ByteArray &result)
+       bool OpensslHelper::digestBuffer(const char *algorithm,
+               const ByteArray &buffer, ByteArray &result)
        {
                const EVP_MD *md;
                bool ret = false;
 
-               if (algorithm == NULL || buffer.getLength() == 0)
+               if (algorithm == NULL || buffer.size() == 0)
                {
                        return ret;
                }
@@ -142,22 +144,22 @@ namespace smartcard_service_api
 
                        if (EVP_DigestInit(&mdCtx, md) > 0)
                        {
-                               if (EVP_DigestUpdate(&mdCtx, buffer.getBuffer(), buffer.getLength()) == 0)
+                               if (EVP_DigestUpdate(&mdCtx, buffer.getBuffer(), buffer.size()) == 0)
                                {
-                                       SCARD_DEBUG_ERR("EVP_DigestUpdate failed");
+                                       _ERR("EVP_DigestUpdate failed");
                                }
 
                                if (EVP_DigestFinal(&mdCtx, temp, &resultLen) > 0 &&
                                        resultLen > 0)
                                {
-                                       result.setBuffer(temp, resultLen);
+                                       result.assign(temp, resultLen);
                                        ret = true;
                                }
                        }
                }
                else
                {
-                       SCARD_DEBUG_ERR("EVP_get_digestbyname(\"%s\") returns NULL", algorithm);
+                       _ERR("EVP_get_digestbyname(\"%s\") returns NULL", algorithm);
                }
 
                return ret;
index 46236d7..729d209 100644 (file)
@@ -30,76 +30,86 @@ namespace smartcard_service_api
                0x4B, 0x43, 0x53, 0x2D, 0x31, 0x35 };
        ByteArray PKCS15::PKCS15_AID(ARRAY_AND_SIZE(aid));
 
-       PKCS15::PKCS15(Channel *channel)
-               : PKCS15Object(channel), odf(NULL)
+       PKCS15::PKCS15(Channel *channel) :
+               PKCS15Object(channel), odf(NULL)
+       {
+       }
+
+       PKCS15::PKCS15(Channel *channel, const ByteArray &selectResponse) :
+               PKCS15Object(channel, selectResponse), odf(NULL)
+       {
+       }
+
+       PKCS15::~PKCS15()
+       {
+               if (odf != NULL)
+               {
+                       delete odf;
+                       odf = NULL;
+               }
+       }
+
+       int PKCS15::select()
        {
                int ret;
 
-               ret = select(PKCS15::PKCS15_AID);
-               if (ret == FileObject::SUCCESS)
+               ret = PKCS15Object::select(PKCS15::PKCS15_AID);
+               if (ret >= SCARD_ERROR_OK)
                {
-                       SCARD_DEBUG("response : %s", selectResponse.toString());
+                       _DBG("response : %s", selectResponse.toString().c_str());
                }
                else if (ret == ResponseHelper::ERROR_FILE_NOT_FOUND)
                {
-                       SCARD_DEBUG_ERR("PKCS15 AID not found, search in EF DIR");
+                       _ERR("PKCS15 AID not found, search in EF DIR");
 
-                       if (selectFromEFDIR() == true)
+                       ret = selectFromEFDIR();
+                       if (ret >= SCARD_ERROR_OK)
                        {
-                               SCARD_DEBUG("response : %s", selectResponse.toString());
+                               _DBG("response : %s", selectResponse.toString().c_str());
                        }
                        else
                        {
-                               SCARD_DEBUG_ERR("PKCS15 select failed, [%d]", ret);
+                               _ERR("PKCS15 select failed, [%d]", ret);
                        }
                }
                else
                {
-                       SCARD_DEBUG_ERR("PKCS15 select failed, [%d]", ret);
+                       _ERR("PKCS15 select failed, [%d]", ret);
                }
-       }
 
-       PKCS15::PKCS15(Channel *channel, ByteArray selectResponse)
-               : PKCS15Object(channel, selectResponse), odf(NULL)
-       {
-       }
-
-       PKCS15::~PKCS15()
-       {
-               if (odf != NULL)
-               {
-                       delete odf;
-                       odf = NULL;
-               }
+               return ret;
        }
 
-       bool PKCS15::selectFromEFDIR()
+       int PKCS15::selectFromEFDIR()
        {
-               bool result = false;
+               int ret;
                ByteArray path;
                EFDIR dir(channel);
 
-               path = dir.getPathByAID(PKCS15_AID);
-               if (path.getLength() > 0)
+               ret = dir.select();
+               if (ret >= SCARD_ERROR_OK)
                {
-                       int ret;
-
-                       ret = select(path, false);
-                       if (ret == FileObject::SUCCESS)
+                       path = dir.getPathByAID(PKCS15_AID);
+                       if (path.size() > 0)
                        {
-                               result = true;
+                               ret = PKCS15Object::select(path, false);
+                               if (ret < SCARD_ERROR_OK)
+                               {
+                                       _ERR("PKCS15 select failed, [%d]", ret);
+                               }
                        }
                        else
                        {
-                               SCARD_DEBUG_ERR("path select failed, [%d]", ret);
+                               _ERR("PKCS15 path is not found");
+                               ret = SCARD_ERROR_NOT_SUPPORTED;
                        }
                }
                else
                {
-                       SCARD_DEBUG_ERR("PKCS15 not found");
+                       _ERR("select EFDIR failed, [%x]", -ret);
                }
 
-               return result;
+               return ret;
        }
 
        PKCS15ODF *PKCS15::getODF()
@@ -110,14 +120,14 @@ namespace smartcard_service_api
 
                        if (odf != NULL && odf->isClosed() == true)
                        {
-                               SCARD_DEBUG_ERR("failed to open ODF");
+                               _ERR("failed to open ODF");
 
                                delete odf;
                                odf = NULL;
                        }
                }
 
-               SCARD_DEBUG("odf [%p]", odf);
+               _DBG("odf [%p]", odf);
 
                return odf;
        }
index 7009957..86514c7 100644 (file)
 
 namespace smartcard_service_api
 {
-//     PKCS15DODF::PKCS15DODF():PKCS15Object()
-//     {
-//
-//     }
-
-       PKCS15DODF::PKCS15DODF(unsigned int fid, Channel *channel):PKCS15Object(channel)
+       PKCS15DODF::PKCS15DODF(unsigned int fid, Channel *channel) :
+               PKCS15Object(channel)
        {
                int ret = 0;
 
-               if ((ret = select(fid)) == 0)
+               if ((ret = select(fid)) >= SCARD_ERROR_OK)
                {
                        ByteArray dodfData, extra;
 
-                       SCARD_DEBUG("response : %s", selectResponse.toString());
+                       _DBG("response : %s", selectResponse.toString().c_str());
 
                        if ((ret = readBinary(0, 0, getFCP()->getFileSize(), dodfData)) == 0)
                        {
-                               SCARD_DEBUG("odfData : %s", dodfData.toString());
+                               _DBG("odfData : %s", dodfData.toString().c_str());
 
                                parseData(dodfData);
                        }
                        else
                        {
-                               SCARD_DEBUG_ERR("readBinary failed, [%d]", ret);
+                               _ERR("readBinary failed, [%d]", ret);
                        }
                }
                else
                {
-                       SCARD_DEBUG_ERR("select failed, [%d]", ret);
+                       _ERR("select failed, [%d]", ret);
                }
        }
 
-       PKCS15DODF::PKCS15DODF(ByteArray path, Channel *channel):PKCS15Object(channel)
+       PKCS15DODF::PKCS15DODF(const ByteArray &path, Channel *channel) :
+               PKCS15Object(channel)
        {
                int ret = 0;
 
-               if ((ret = select(path)) == 0)
+               if ((ret = select(path)) >= SCARD_ERROR_OK)
                {
                        ByteArray dodfData, extra;
 
-                       SCARD_DEBUG("response : %s", selectResponse.toString());
+                       _DBG("response : %s", selectResponse.toString().c_str());
 
                        if ((ret = readBinary(0, 0, getFCP()->getFileSize(), dodfData)) == 0)
                        {
-                               SCARD_DEBUG("dodfData : %s", dodfData.toString());
+                               _DBG("dodfData : %s", dodfData.toString().c_str());
 
                                parseData(dodfData);
                        }
                        else
                        {
-                               SCARD_DEBUG_ERR("readBinary failed, [%d]", ret);
+                               _ERR("readBinary failed, [%d]", ret);
                        }
                }
                else
                {
-                       SCARD_DEBUG_ERR("select failed, [%d]", ret);
+                       _ERR("select failed, [%d]", ret);
                }
        }
 
@@ -88,7 +85,7 @@ namespace smartcard_service_api
        {
        }
 
-       bool PKCS15DODF::parseData(ByteArray data)
+       bool PKCS15DODF::parseData(const ByteArray &data)
        {
                bool result = false;
                SimpleTLV tlv(data);
@@ -101,28 +98,27 @@ namespace smartcard_service_api
                                {
                                        PKCS15OID oid(tlv.getValue());
 
-                                       SCARD_DEBUG("OID DataObject");
+                                       _DBG("OID DataObject : %s", oid.getOID().toString().c_str());
 
-                                       pair<ByteArray, PKCS15OID> newPair(oid.getOID(), oid);
-                                       mapOID.insert(newPair);
+                                       mapOID.insert(make_pair(oid.getOID(), oid));
                                }
                                break;
 
                        default :
-                               SCARD_DEBUG("Unknown tlv : t [%X], l [%d], v %s", tlv.getTag(), tlv.getLength(), tlv.getValue().toString());
+                               _DBG("Unknown tlv : t [%X], l [%d], v %s", tlv.getTag(), tlv.size(), tlv.getValue().toString().c_str());
                                break;
                        }
                }
 
-               SCARD_DEBUG("dataList.size() = %d", mapOID.size());
+               _INFO("dataList.size() = %d", mapOID.size());
 
                return result;
        }
 
-       int PKCS15DODF::searchOID(ByteArray oid, ByteArray &data)
+       int PKCS15DODF::searchOID(const ByteArray &oid, ByteArray &data) const
        {
                int result = -1;
-               map<ByteArray, PKCS15OID>::iterator item;
+               map<ByteArray, PKCS15OID>::const_iterator item;
 
                item = mapOID.find(oid);
                if (item != mapOID.end())
index 686cef6..4ca414b 100644 (file)
 
 namespace smartcard_service_api
 {
-       PKCS15ODF::PKCS15ODF(Channel *channel)
-               PKCS15Object(channel), dodf(NULL)
+       PKCS15ODF::PKCS15ODF(Channel *channel) :
+               PKCS15Object(channel), dodf(NULL)
        {
                int ret = 0;
 
-               if ((ret = select(PKCS15ODF::ODF_FID)) == 0)
+               if ((ret = select(PKCS15ODF::ODF_FID)) >= SCARD_ERROR_OK)
                {
                        ByteArray odfData, extra;
 
-                       SCARD_DEBUG("response : %s", selectResponse.toString());
+                       _DBG("response : %s", selectResponse.toString().c_str());
 
                        if ((ret = readBinary(0, 0, getFCP()->getFileSize(), odfData)) == 0)
                        {
-                               SCARD_DEBUG("odfData : %s", odfData.toString());
+                               _DBG("odfData : %s", odfData.toString().c_str());
 
                                parseData(odfData);
                        }
                        else
                        {
-                               SCARD_DEBUG_ERR("readBinary failed, [%d]", ret);
+                               _ERR("readBinary failed, [%d]", ret);
                        }
                }
                else
                {
-                       SCARD_DEBUG_ERR("select failed, [%d]", ret);
+                       _ERR("select failed, [%d]", ret);
                }
        }
 
-       PKCS15ODF::PKCS15ODF(Channel *channel, ByteArray selectResponse)
-               PKCS15Object(channel, selectResponse), dodf(NULL)
+       PKCS15ODF::PKCS15ODF(Channel *channel, const ByteArray &selectResponse) :
+               PKCS15Object(channel, selectResponse), dodf(NULL)
        {
                int ret = 0;
                ByteArray odfData;
 
                if ((ret = readBinary(0, 0, 0, odfData)) == 0)
                {
-                       SCARD_DEBUG("odfData : %s", odfData.toString());
+                       _DBG("odfData : %s", odfData.toString().c_str());
 
                        parseData(odfData);
                }
                else
                {
-                       SCARD_DEBUG_ERR("readBinary failed, [%d]", ret);
+                       _ERR("readBinary failed, [%d]", ret);
                }
        }
 
@@ -81,7 +81,7 @@ namespace smartcard_service_api
                }
        }
 
-       bool PKCS15ODF::parseData(ByteArray data)
+       bool PKCS15ODF::parseData(const ByteArray &data)
        {
                bool result = false;
                SimpleTLV tlv(data);
@@ -94,11 +94,11 @@ namespace smartcard_service_api
                                {
                                        ByteArray dodf;
 
-                                       SCARD_DEBUG("TAG_DODF");
+                                       _DBG("TAG_DODF");
 
                                        dodf = PKCS15Object::getOctetStream(tlv.getValue());
 
-                                       SCARD_DEBUG("path : %s", dodf.toString());
+                                       _DBG("path : %s", dodf.toString().c_str());
 
                                        pair<unsigned int, ByteArray> newPair(tlv.getTag(), dodf);
                                        dataList.insert(newPair);
@@ -109,11 +109,11 @@ namespace smartcard_service_api
                                {
                                        ByteArray tokeninfo;
 
-                                       SCARD_DEBUG("TAG_TOKENINFO");
+                                       _DBG("TAG_TOKENINFO");
 
                                        tokeninfo = PKCS15Object::getOctetStream(tlv.getValue());
 
-                                       SCARD_DEBUG("path : %s", tokeninfo.toString());
+                                       _DBG("path : %s", tokeninfo.toString().c_str());
 
                                        pair<unsigned int, ByteArray> newPair(tlv.getTag(), tokeninfo);
                                        dataList.insert(newPair);
@@ -121,14 +121,14 @@ namespace smartcard_service_api
                                break;
 
                        default :
-                               SCARD_DEBUG("Unknown tlv : t [%X], l [%d], v %s",
-                                       tlv.getTag(), tlv.getLength(), tlv.getValue().toString());
+                               _DBG("Unknown tlv : t [%X], l [%d], v %s",
+                                       tlv.getTag(), tlv.size(), tlv.getValue().toString().c_str());
                                break;
                        }
 
                }
 
-               SCARD_DEBUG("dataList.size() = %d", dataList.size());
+               _INFO("dataList.size() = %d", dataList.size());
 
                return result;
        }
@@ -145,12 +145,12 @@ namespace smartcard_service_api
                                NumberStream num(item->second);
                                unsigned int fid = num.getLittleEndianNumber();
 
-                               SCARD_DEBUG("fid [%X]", fid);
+                               _DBG("fid [%X]", fid);
 
                                dodf = new PKCS15DODF(fid, channel);
                                if (dodf != NULL && dodf->isClosed() == true)
                                {
-                                       SCARD_DEBUG_ERR("failed to open DODF");
+                                       _ERR("failed to open DODF");
 
                                        delete dodf;
                                        dodf = NULL;
@@ -158,11 +158,11 @@ namespace smartcard_service_api
                        }
                        else
                        {
-                               SCARD_DEBUG_ERR("[%02X] is not found. total [%d]", TAG_DODF, dataList.size());
+                               _ERR("[%02X] is not found. total [%d]", TAG_DODF, dataList.size());
                        }
                }
 
-               SCARD_DEBUG("dodf [%p]", dodf);
+               _DBG("dodf [%p]", dodf);
 
                return dodf;
        }
index 86a7923..088a3fa 100644 (file)
@@ -26,7 +26,7 @@
 
 namespace smartcard_service_api
 {
-       PKCS15OID::PKCS15OID(ByteArray data)
+       PKCS15OID::PKCS15OID(const ByteArray &data)
        {
                parseOID(data);
        }
@@ -35,26 +35,25 @@ namespace smartcard_service_api
        {
        }
 
-       bool PKCS15OID::parseOID(ByteArray data)
+       bool PKCS15OID::parseOID(const ByteArray &data)
        {
                bool result = false;
                SimpleTLV tlv(data);
 
-               SCARD_BEGIN();
+               _BEGIN();
 
                while (tlv.decodeTLV() == true)
                {
                        switch (tlv.getTag())
                        {
                        case PKCS15::TAG_SEQUENCE :
-                               if (tlv.getLength() > 0)
+                               if (tlv.size() > 0)
                                {
                                        /* common object attribute */
                                        tlv.enterToValueTLV();
                                        if (tlv.decodeTLV() == true && tlv.getTag() == 0x0C) /* ?? */
                                        {
                                                name = tlv.getValue();
-                                               SCARD_DEBUG("name : %s", name.toString());
                                        }
                                        tlv.returnToParentTLV();
                                }
@@ -62,12 +61,12 @@ namespace smartcard_service_api
                                {
                                        /* common object attribute */
                                        /* if you want to use this value, add member variable and parse here */
-//                                     SCARD_DEBUG_ERR("common object attribute is empty");
+//                                     _ERR("common object attribute is empty");
                                }
                                break;
 
                        case 0xA0 : /* CHOICE 0 : External Oid??? */
-                               SCARD_DEBUG_ERR("oid doesn't exist");
+                               _ERR("oid doesn't exist");
                                break;
 
                        case 0xA1 : /* CHOICE 1 : OidDO */
@@ -83,11 +82,11 @@ namespace smartcard_service_api
                                        {
                                                oid = tlv.getValue();
 
-                                               SCARD_DEBUG("oid : %s", oid.toString());
+                                               _DBG("oid : %s", oid.toString().c_str());
                                        }
                                        else
                                        {
-                                               SCARD_DEBUG_ERR("oid is empty");
+                                               _ERR("oid is empty");
                                        }
 
                                        /* path */
@@ -95,49 +94,33 @@ namespace smartcard_service_api
                                        {
                                                path = SimpleTLV::getOctetString(tlv.getValue());
 
-                                               SCARD_DEBUG("path : %s", path.toString());
+                                               _DBG("path : %s", path.toString().c_str());
 
                                                result = true;
                                        }
                                        else
                                        {
-                                               SCARD_DEBUG_ERR("sequence is empty");
+                                               _ERR("sequence is empty");
                                        }
 
                                        tlv.returnToParentTLV();
                                }
                                else
                                {
-                                       SCARD_DEBUG_ERR("common dataobject attribute is empty");
+                                       _ERR("common dataobject attribute is empty");
                                }
                                tlv.returnToParentTLV();
 
                                break;
 
                        default :
-                               SCARD_DEBUG_ERR("Unknown tag : 0x%02X", tlv.getTag());
+                               _ERR("Unknown tag : 0x%02X", tlv.getTag());
                                break;
                        }
                }
 
-               SCARD_END();
+               _END();
 
                return result;
        }
-
-       ByteArray PKCS15OID::getOID()
-       {
-               return oid;
-       }
-
-       ByteArray PKCS15OID::getName()
-       {
-               return name;
-       }
-
-       ByteArray PKCS15OID::getPath()
-       {
-               return path;
-       }
-
 } /* namespace smartcard_service_api */
index debc182..6c4c790 100644 (file)
@@ -29,11 +29,13 @@ namespace smartcard_service_api
 //     {
 //     }
 
-       PKCS15Object::PKCS15Object(Channel *channel):FileObject(channel)
+       PKCS15Object::PKCS15Object(Channel *channel) : FileObject(channel)
        {
        }
 
-       PKCS15Object::PKCS15Object(Channel *channel, ByteArray selectResponse):FileObject(channel, selectResponse)
+       PKCS15Object::PKCS15Object(Channel *channel,
+               const ByteArray &selectResponse) :
+               FileObject(channel, selectResponse)
        {
        }
 
@@ -41,7 +43,7 @@ namespace smartcard_service_api
        {
        }
 
-       ByteArray PKCS15Object::getOctetStream(const ByteArray &data)
+       const ByteArray PKCS15Object::getOctetStream(const ByteArray &data)
        {
                ByteArray result;
                SimpleTLV tlv(data);
@@ -56,13 +58,13 @@ namespace smartcard_service_api
                        }
                        else
                        {
-                               SCARD_DEBUG_ERR("TAG_OCTET_STREAM not found");
+                               _ERR("TAG_OCTET_STREAM not found");
                        }
                        tlv.returnToParentTLV();
                }
                else
                {
-                       SCARD_DEBUG_ERR("TAG_SEQUENCE not found");
+                       _ERR("TAG_SEQUENCE not found");
                }
 
                return result;
index b3664bf..0e28b13 100644 (file)
 
 namespace smartcard_service_api
 {
-       PKCS15Path::PKCS15Path()
+       PKCS15Path::PKCS15Path() : index(-1), length(0)
+       {
+       }
+
+       PKCS15Path::PKCS15Path(const ByteArray &data) : index(-1), length(0)
+       {
+               parseData(data);
+       }
+
+       PKCS15Path::PKCS15Path(const ByteArray &path, int index) :
+               path(path), index(index), length(0)
+       {
+       }
+
+       PKCS15Path::PKCS15Path(const unsigned char *path,
+               size_t length, int index) :
+               path(path, length), index(index), length(0)
        {
        }
 
@@ -31,13 +47,9 @@ namespace smartcard_service_api
        {
        }
 
-//     PKCS15Path(ByteArray &data);
-//     PKCS15Path(ByteArray path, int index);
-//     PKCS15Path(unsigned char *path, unsigned int length, int index);
-//     ~PKCS15Path();
-//
-//     bool PKCS15Path::parseData(ByteArray &data)
-//     {
+       bool PKCS15Path::parseData(const ByteArray &data)
+       {
+               /* TODO */
 //             SimpleTLV tlv(data);
 //
 //             if (tlv.decodeTLV() == true && tlv.getTag() == 0x30) /* SEQUENCE */
@@ -46,15 +58,14 @@ namespace smartcard_service_api
 //                     path = tlv.getOctetString();
 //
 //                     if (tlv.decodeTLV())
-//                     index = t
-//
 //             }
-//     }
-//
-//     int getPath(ByteArray &path);
-//     bool hasIndexLength();
-//     int getIndex();
-//     unsigned int getLength();
-//     int encode(ByteArray &result);
+               return true;
+       }
+
+       int PKCS15Path::encode(ByteArray &result) const
+       {
+               /* TODO */
+               return 0;
+       }
 
 } /* namespace smartcard_service_api */
index 58bcef7..259d939 100644 (file)
@@ -23,7 +23,8 @@
 
 namespace smartcard_service_api
 {
-       PKCS15TokenInfo::PKCS15TokenInfo(Channel *channel):PKCS15Object(channel)
+       PKCS15TokenInfo::PKCS15TokenInfo(Channel *channel) :
+               PKCS15Object(channel)
        {
        }
 
index abd5ca4..a4491b6 100644 (file)
@@ -15,9 +15,9 @@
  */
 
 /* standard library header */
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
+#include <cstdio>
+#include <cstring>
+#include <cstdlib>
 #include <unistd.h>
 #include <list>
 #include <string>
 
 namespace smartcard_service_api
 {
-       ByteArray SignatureHelper::getCertificationHash(const char *packageName)
+       int SignatureHelper::getPackageName(int pid, char *package, size_t length)
+       {
+               return aul_app_get_pkgname_bypid(pid, package, length);
+       }
+
+       const ByteArray SignatureHelper::getCertificationHash(const char *packageName)
        {
                ByteArray result;
                int ret = 0;
@@ -49,20 +54,18 @@ namespace smartcard_service_api
 
                if(pkgmgrinfo_appinfo_get_appinfo(packageName, &handle_appinfo) != PMINFO_R_OK)
                {
-                       SCARD_DEBUG_ERR("pkgmgrinfo_appinfo_get_appinfo fail");
+                       _ERR("pkgmgrinfo_appinfo_get_appinfo fail");
                        return result;
                }
 
                if(pkgmgrinfo_appinfo_get_pkgid(handle_appinfo, &pkgid) != PMINFO_R_OK)
                {
                        pkgmgrinfo_appinfo_destroy_appinfo(handle_appinfo);
-                       SCARD_DEBUG_ERR("pkgmgrinfo_appinfo_get_pkgid fail");
+                       _ERR("pkgmgrinfo_appinfo_get_pkgid fail");
                        return result;
                }
                pkgmgrinfo_appinfo_destroy_appinfo(handle_appinfo);
 
-               SCARD_DEBUG("package name : %s", pkgid);
-
                if ((ret = pkgmgr_pkginfo_create_certinfo(&handle)) == 0)
                {
                        if ((ret = pkgmgr_pkginfo_load_certinfo(pkgid, handle)) == 0)
@@ -78,9 +81,9 @@ namespace smartcard_service_api
                                                if (value != NULL && strlen(value) > 0)
                                                {
                                                        OpensslHelper::decodeBase64String(value, result, false);
-                                                       if (result.getLength() > 0)
+                                                       if (result.size() > 0)
                                                        {
-                                                               SCARD_DEBUG("type [%d] hash [%d] : %s", type, result.getLength(), result.toString());
+                                                               _DBG("type [%d] hash [%d] : %s", type, result.size(), result.toString().c_str());
                                                                break;
                                                        }
                                                }
@@ -89,20 +92,20 @@ namespace smartcard_service_api
                        }
                        else
                        {
-                               SCARD_DEBUG_ERR("pkgmgr_pkginfo_load_certinfo failed [%d]", ret);
+                               _ERR("pkgmgr_pkginfo_load_certinfo failed [%d]", ret);
                        }
 
                        pkgmgr_pkginfo_destroy_certinfo(handle);
                }
                else
                {
-                       SCARD_DEBUG_ERR("pkgmgr_pkginfo_create_certinfo failed [%d]", ret);
+                       _ERR("pkgmgr_pkginfo_create_certinfo failed [%d]", ret);
                }
 
                return result;
        }
 
-       ByteArray SignatureHelper::getCertificationHash(int pid)
+       const ByteArray SignatureHelper::getCertificationHash(int pid)
        {
                ByteArray result;
                int error = 0;
@@ -114,7 +117,7 @@ namespace smartcard_service_api
                }
                else
                {
-                       SCARD_DEBUG_ERR("aul_app_get_pkgname_bypid failed [%d]", error);
+                       _ERR("aul_app_get_pkgname_bypid failed [%d]", error);
                }
 
                return result;
@@ -132,7 +135,7 @@ namespace smartcard_service_api
                }
                else
                {
-                       SCARD_DEBUG_ERR("aul_app_get_pkgname_bypid failed [%d]", error);
+                       _ERR("aul_app_get_pkgname_bypid failed [%d]", error);
                }
 
                return result;
@@ -148,19 +151,17 @@ namespace smartcard_service_api
 
                if(pkgmgrinfo_appinfo_get_appinfo(packageName, &handle_appinfo) != PMINFO_R_OK)
                {
-                       SCARD_DEBUG_ERR("pkgmgrinfo_appinfo_get_appinfo fail");
+                       _ERR("pkgmgrinfo_appinfo_get_appinfo fail");
                        return result;
                }
 
                if(pkgmgrinfo_appinfo_get_pkgid(handle_appinfo, &pkgid) != PMINFO_R_OK)
                {
                        pkgmgrinfo_appinfo_destroy_appinfo(handle_appinfo);
-                       SCARD_DEBUG_ERR("pkgmgrinfo_appinfo_get_pkgid fail");
+                       _ERR("pkgmgrinfo_appinfo_get_pkgid fail");
                        return result;
                }
 
-               SCARD_DEBUG("package name : %s", pkgid);
-
                if ((ret = pkgmgr_pkginfo_create_certinfo(&handle)) == 0)
                {
                        if ((ret = pkgmgr_pkginfo_load_certinfo(pkgid, handle)) == 0)
@@ -178,12 +179,12 @@ namespace smartcard_service_api
                                                        ByteArray decodeValue, hash;
 
                                                        OpensslHelper::decodeBase64String(value, decodeValue, false);
-                                                       if (decodeValue.getLength() > 0)
+                                                       if (decodeValue.size() > 0)
                                                        {
-                                                               OpensslHelper::digestBuffer("sha1", decodeValue.getBuffer(), decodeValue.getLength(), hash);
-                                                               if(hash.getLength() > 0)
+                                                               OpensslHelper::digestBuffer("sha1", decodeValue.getBuffer(), decodeValue.size(), hash);
+                                                               if(hash.size() > 0)
                                                                {
-                                                                       SCARD_DEBUG("type [%d] hash [%d] : %s", type, hash.getLength(), hash.toString());
+                                                                       _DBG("type [%d] hash [%d] : %s", type, hash.size(), hash.toString().c_str());
                                                                        certHashes.push_back(hash);
                                                                }
                                                        }
@@ -195,7 +196,7 @@ namespace smartcard_service_api
                        }
                        else
                        {
-                               SCARD_DEBUG_ERR("pkgmgr_pkginfo_load_certinfo failed [%d]", ret);
+                               _ERR("pkgmgr_pkginfo_load_certinfo failed [%d]", ret);
                        }
 
                        pkgmgrinfo_appinfo_destroy_appinfo(handle_appinfo);
@@ -204,7 +205,7 @@ namespace smartcard_service_api
                }
                else
                {
-                       SCARD_DEBUG_ERR("pkgmgr_pkginfo_create_certinfo failed [%d]", ret);
+                       _ERR("pkgmgr_pkginfo_create_certinfo failed [%d]", ret);
                }
 
                return result;
@@ -226,7 +227,7 @@ certiHash *__signature_helper_vector_to_linked_list(vector<ByteArray> &certHashe
                if ((tmp = (certiHash *)calloc(1, sizeof(certiHash))) == NULL)
                        goto ERROR;
 
-               tmp->length = (*item).getLength();
+               tmp->length = (*item).size();
 
                if ((tmp->value = (uint8_t *)calloc(tmp->length, sizeof(uint8_t))) == NULL)
                {
@@ -250,7 +251,7 @@ certiHash *__signature_helper_vector_to_linked_list(vector<ByteArray> &certHashe
        return head;
 
 ERROR :
-       SCARD_DEBUG_ERR("mem alloc fail");
+       _ERR("alloc fail");
 
        while (head)
        {
index 638e6c7..e9500b9 100644 (file)
 
 namespace smartcard_service_api
 {
-       SimpleTLV::SimpleTLV():TLVHelper()
+       SimpleTLV::SimpleTLV() : TLVHelper()
        {
        }
 
-       SimpleTLV::SimpleTLV(TLVHelper *parent):TLVHelper(parent)
+       SimpleTLV::SimpleTLV(TLVHelper *parent) : TLVHelper(parent)
        {
-               parentTLV = parent;
        }
 
-       SimpleTLV::SimpleTLV(const ByteArray &array):TLVHelper(array)
+       SimpleTLV::SimpleTLV(const ByteArray &array) : TLVHelper(array)
        {
        }
 
-       SimpleTLV::SimpleTLV(const ByteArray &array, TLVHelper *parent):TLVHelper(array, parent)
+       SimpleTLV::SimpleTLV(const ByteArray &array, TLVHelper *parent) :
+               TLVHelper(array, parent)
        {
-               parentTLV = parent;
        }
 
        SimpleTLV::~SimpleTLV()
@@ -53,7 +52,7 @@ namespace smartcard_service_api
                }
        }
 
-       int SimpleTLV::decodeTag(unsigned char *buffer)
+       int SimpleTLV::decodeTag(const unsigned char *buffer)
        {
                /* 0x00 or 0xFF is invalid tag value */
                if (buffer[0] == 0x00 || buffer[0] == 0xFF)
@@ -66,7 +65,7 @@ namespace smartcard_service_api
                return 1;
        }
 
-       int SimpleTLV::decodeLength(unsigned char *buffer)
+       int SimpleTLV::decodeLength(const unsigned char *buffer)
        {
                int count = 0;
 
@@ -86,17 +85,17 @@ namespace smartcard_service_api
                return count;
        }
 
-       int SimpleTLV::decodeValue(unsigned char *buffer)
+       int SimpleTLV::decodeValue(const unsigned char *buffer)
        {
                if (currentL == 0)
                        return 0;
 
-               currentV.setBuffer(buffer, currentL);
+               currentV.assign(buffer, currentL);
 
                return currentL;
        }
 
-       ByteArray SimpleTLV::encode(unsigned int tag, ByteArray buffer)
+       const ByteArray SimpleTLV::encode(unsigned int tag, const ByteArray &buffer)
        {
                bool isLongBuffer = false;
                ByteArray result;
@@ -108,11 +107,11 @@ namespace smartcard_service_api
                total_len += 1;
 
                /* add length's length */
-               if (buffer.getLength() < 255)
+               if (buffer.size() < 255)
                {
                        total_len += 1;
                }
-               else if (buffer.getLength() < 65536)
+               else if (buffer.size() < 65536)
                {
                        total_len += 3;
                        isLongBuffer = true;
@@ -123,7 +122,7 @@ namespace smartcard_service_api
                }
 
                /* add buffer's length */
-               total_len += buffer.getLength();
+               total_len += buffer.size();
 
                /* alloc new buffer */
                temp_buffer = new unsigned char[total_len];
@@ -140,31 +139,31 @@ namespace smartcard_service_api
                if (isLongBuffer == true)
                {
                        temp_buffer[current++] = (unsigned char)(0xFF);
-                       temp_buffer[current++] = (unsigned char)(buffer.getLength() >> 8);
-                       temp_buffer[current++] = (unsigned char)(buffer.getLength());
+                       temp_buffer[current++] = (unsigned char)(buffer.size() >> 8);
+                       temp_buffer[current++] = (unsigned char)(buffer.size());
                }
                else
                {
-                       temp_buffer[current++] = (unsigned char)(buffer.getLength());
+                       temp_buffer[current++] = (unsigned char)(buffer.size());
                }
 
                /* fill value */
-               if (buffer.getLength() > 0)
-                       memcpy(temp_buffer + current, buffer.getBuffer(), buffer.getLength());
+               if (buffer.size() > 0)
+                       memcpy(temp_buffer + current, buffer.getBuffer(), buffer.size());
 
-               result.setBuffer(temp_buffer, total_len);
+               result.assign(temp_buffer, total_len);
 
                delete []temp_buffer;
 
                return result;
        }
 
-       ByteArray SimpleTLV::encode(unsigned int tag, unsigned char *buffer, unsigned int length)
+       const ByteArray SimpleTLV::encode(unsigned int tag, unsigned char *buffer, unsigned int length)
        {
                return encode(tag, ByteArray(buffer, length));
        }
 
-       TLVHelper *SimpleTLV::getChildTLV(ByteArray data)
+       TLVHelper *SimpleTLV::getChildTLV(const ByteArray &data)
        {
                if (childTLV != NULL)
                {
@@ -176,14 +175,14 @@ namespace smartcard_service_api
                return (TLVHelper *)childTLV;
        }
 
-       ByteArray SimpleTLV::getOctetString(const ByteArray &array)
+       const ByteArray SimpleTLV::getOctetString(const ByteArray &array)
        {
                SimpleTLV tlv(array);
 
                return SimpleTLV::getOctetString(tlv);
        }
 
-       ByteArray SimpleTLV::getOctetString(SimpleTLV &tlv)
+       const ByteArray SimpleTLV::getOctetString(SimpleTLV &tlv)
        {
                ByteArray result;
 
@@ -193,7 +192,7 @@ namespace smartcard_service_api
                }
                else
                {
-                       SCARD_DEBUG_ERR("getOctetString failed (0x%02X)", tlv.getTag());
+                       _ERR("getOctetString failed (0x%02X)", tlv.getTag());
                }
 
                return result;
@@ -212,14 +211,14 @@ namespace smartcard_service_api
 
                if (tlv.decodeTLV() == true && tlv.getTag() == 0x80) /* BOOLEAN */
                {
-                       if (tlv.getValue().getAt(0) == 0)
+                       if (tlv.getValue().at(0) == 0)
                                result = false;
                        else
                                result = true;
                }
                else
                {
-                       SCARD_DEBUG_ERR("getBoolean failed (0x%02X)", tlv.getTag());
+                       _ERR("getBoolean failed (0x%02X)", tlv.getTag());
                }
 
                return result;
@@ -241,7 +240,7 @@ namespace smartcard_service_api
                }
                else
                {
-                       SCARD_DEBUG_ERR("getInteger failed (0x%02X)", tlv.getTag());
+                       _ERR("getInteger failed (0x%02X)", tlv.getTag());
                }
 
                return result;
index b577996..85406dd 100644 (file)
@@ -15,8 +15,9 @@
  */
 
 /* standard library header */
-#include <stdio.h>
-#include <string.h>
+#include <cstdio>
+#include <cstring>
+#include <sstream>
 
 /* SLP library header */
 
 
 namespace smartcard_service_api
 {
-       void TLVHelper::initialize(TLVHelper *parent)
+       TLVHelper::TLVHelper() : currentTLV(this), parentTLV(NULL),
+               childTLV(NULL), offset(0), currentT(0), currentL(0)
        {
-               parentTLV = parent;
-               childTLV = NULL;
-               currentTLV = this;
-               offset = 0;
-               currentT = 0;
-               currentL = 0;
        }
 
-       TLVHelper::TLVHelper()
+       TLVHelper::TLVHelper(TLVHelper *parent) : currentTLV(this),
+               parentTLV(parent), childTLV(NULL),
+               offset(0), currentT(0), currentL(0)
        {
-               initialize();
        }
 
-       TLVHelper::TLVHelper(TLVHelper *parent)
-       {
-               initialize(parent);
-       }
-
-       TLVHelper::TLVHelper(const ByteArray &array)
+       TLVHelper::TLVHelper(const ByteArray &array) : currentTLV(this),
+               parentTLV(NULL), childTLV(NULL),
+               offset(0), currentT(0), currentL(0)
        {
                setTLVBuffer(array);
        }
 
-       TLVHelper::TLVHelper(const ByteArray &array, TLVHelper *parent)
+       TLVHelper::TLVHelper(const ByteArray &array, TLVHelper *parent) :
+               currentTLV(this), parentTLV(NULL), childTLV(NULL),
+               offset(0), currentT(0), currentL(0)
        {
                setTLVBuffer(array, parent);
        }
@@ -62,17 +58,22 @@ namespace smartcard_service_api
 
        bool TLVHelper::setTLVBuffer(const ByteArray &array, TLVHelper *parent)
        {
-               initialize(parent);
-
-               if (array.getLength() == 0)
+               if (array.size() == 0)
                        return false;
 
+               currentTLV = this;
+               parentTLV = parent;
+               childTLV = NULL;
+               offset = 0;
+               currentT = 0;
+               currentL = 0;
+
                tlvBuffer = array;
 
                return true;
        }
 
-       bool TLVHelper::setTLVBuffer(unsigned char *buffer, unsigned int length, TLVHelper *parent)
+       bool TLVHelper::setTLVBuffer(const unsigned char *buffer, unsigned int length, TLVHelper *parent)
        {
                return setTLVBuffer(ByteArray(buffer, length), parent);
        }
@@ -84,7 +85,7 @@ namespace smartcard_service_api
 
                currentT = 0;
                currentL = 0;
-               currentV.releaseBuffer();
+               currentV.clear();
 
                if (isEndOfBuffer())
                        return false;
@@ -103,7 +104,7 @@ namespace smartcard_service_api
 
                if (currentL > 0)
                {
-                       if (currentL > (tlvBuffer.getLength() - (offset + temp)))
+                       if (currentL > (tlvBuffer.size() - (offset + temp)))
                                return false;
 
                        /* V */
@@ -118,20 +119,17 @@ namespace smartcard_service_api
                return true;
        }
 
-       const char *TLVHelper::toString()
+       const string TLVHelper::toString() const
        {
-               memset(strBuffer, 0, sizeof(strBuffer));
+               stringstream ss;
 
-               if (currentL == 0)
-               {
-                       snprintf(strBuffer, sizeof(strBuffer), "T [%X], L [%d]", getTag(), getLength());
-               }
-               else
+               ss << "T [" << getTag() << "], L [" << size() << "]";
+               if (currentL > 0)
                {
-                       snprintf(strBuffer, sizeof(strBuffer), "T [%X], L [%d], V %s", getTag(), getLength(), getValue().toString());
+                       ss << ", V " << getValue().toString();
                }
 
-               return strBuffer;
+               return ss.str();
        }
 
        TLVHelper *TLVHelper::getParentTLV()
@@ -144,7 +142,7 @@ namespace smartcard_service_api
                bool result = false;
                TLVHelper *temp = NULL;
 
-               if (getLength() >= 2)
+               if (size() >= 2)
                {
                        temp = currentTLV->getChildTLV(getValue());
 
@@ -162,8 +160,6 @@ namespace smartcard_service_api
        {
                bool result = true;
 
-//             SCARD_DEBUG("current [%p], parent [%p]", currentTLV, currentTLV->getParentTLV());
-
                if (currentTLV->getParentTLV() != NULL)
                {
                        currentTLV = currentTLV->getParentTLV();
index 0f24ac8..5f3cf95 100644 (file)
@@ -34,7 +34,7 @@ namespace smartcard_service_api
                int status;
                ByteArray dataField;
 
-               static int parseStatusWord(unsigned char *sw);
+               static int parseStatusWord(const unsigned char *sw);
 
        public:
                static const int SUCCESS = 0;
@@ -63,15 +63,15 @@ namespace smartcard_service_api
                ~ResponseHelper();
 
                bool setResponse(const ByteArray &response);
-               int getStatus();
-               unsigned char getSW1();
-               unsigned char getSW2();
+               inline int getStatus() const { return status; }
+               inline unsigned char getSW1() const { return sw[0]; }
+               inline unsigned char getSW2() const { return sw[1]; }
 
 //             char *getErrorString();
-               ByteArray getDataField();
+               inline const ByteArray getDataField() const { return dataField; }
 
                static int getStatus(const ByteArray &response);
-               static ByteArray getDataField(const ByteArray &response);
+               static const ByteArray getDataField(const ByteArray &response);
 //             static char *getErrorString();
        };
 
@@ -145,30 +145,30 @@ namespace smartcard_service_api
                ~APDUCommand();
 
                bool setCommand(unsigned char cla, unsigned char ins, unsigned char p1,
-                       unsigned char p2, ByteArray commandData, unsigned int maxResponseSize);
+                       unsigned char p2, const ByteArray &commandData, unsigned int maxResponseSize);
                bool setCommand(const ByteArray &command);
 
                bool setChannel(int type, int channelNum);
 
                void setCLA(unsigned char cla);
-               unsigned char getCLA();
+               unsigned char getCLA() const;
 
                void setINS(unsigned char ins);
-               unsigned char getINS();
+               unsigned char getINS() const;
 
                void setP1(unsigned char p1);
-               unsigned char getP1();
+               unsigned char getP1() const;
 
                void setP2(unsigned char p2);
-               unsigned char getP2();
+               unsigned char getP2() const;
 
                void setCommandData(const ByteArray &data);
-               ByteArray getCommandData();
+               const ByteArray getCommandData() const;
 
                void setMaxResponseSize(unsigned int maxResponseSize);
-               unsigned int getMaxResponseSize();
+               unsigned int getMaxResponseSize() const;
 
-               bool getBuffer(ByteArray &array);
+               bool getBuffer(ByteArray &array) const;
        };
 
        class APDUHelper
@@ -186,7 +186,8 @@ namespace smartcard_service_api
                static const int COMMAND_WRITE_BINARY = 10;
                static const int COMMAND_WRITE_RECORD = 11;
 
-               static ByteArray generateAPDU(int command, int channel, ByteArray data);
+               static const ByteArray generateAPDU(int command,
+                       int channel, const ByteArray &data);
        };
 
 } /* namespace smartcard_service_api */
index 20ca90a..787bdd0 100644 (file)
@@ -18,8 +18,8 @@
 #define ACCESSCONDITION_H_
 
 /* standard library header */
-#include <vector>
 #include <map>
+#include <vector>
 
 /* SLP library header */
 
@@ -30,39 +30,30 @@ using namespace std;
 
 namespace smartcard_service_api
 {
-       class APDUAccessRule
+       class AccessRule
        {
        private :
-               bool permission;
-               map<ByteArray, ByteArray> mapApduFilters;
+               bool apduRule;
+               bool nfcRule;
+               vector<pair<ByteArray, ByteArray> > listFilters;
 
        public :
-               APDUAccessRule()
-               {
-                       permission = true;
-               }
+               AccessRule() : apduRule(true), nfcRule(true) {}
 
-               void loadAPDUAccessRule(const ByteArray &data);
-               bool isAuthorizedAccess(const ByteArray &command);
+               inline void setAPDUAccessRule(bool rule) { apduRule = rule; }
+               inline void setNFCAccessRule(bool rule) { nfcRule = rule; }
 
-               void printAPDUAccessRules();
-       };
-
-       class NFCAccessRule
-       {
-       private :
-               bool permission;
+               void addAPDUAccessRule(const ByteArray &apdu,
+                       const ByteArray &mask);
 
-       public :
-               NFCAccessRule()
+               inline bool isAuthorizedAccess(void) const
                {
-                       permission = true;
+                       return (apduRule || (listFilters.size() > 0));
                }
+               bool isAuthorizedAPDUAccess(const ByteArray &command) const;
+               bool isAuthorizedNFCAccess(void) const;
 
-               void loadNFCAccessRule(const ByteArray &data);
-               bool isAuthorizedAccess(void);
-
-               void printNFCAccessRules();
+               friend class AccessCondition;
        };
 
        class AccessCondition
@@ -70,21 +61,33 @@ namespace smartcard_service_api
        private :
                bool permission;
                ByteArray aid;
-               vector<ByteArray> hashes;
-               APDUAccessRule apduRule;
-               NFCAccessRule nfcRule;
+               map<ByteArray, AccessRule> mapRules;
 
        public :
-               AccessCondition() : permission(false)
-               {
-               }
+               AccessCondition() : permission(false) {}
+
+               inline void setAID(const ByteArray &aid) { this->aid = aid; }
+               inline const ByteArray getAID() const { return aid; }
+               inline void setAccessCondition(bool rule) { permission = rule; }
+               void addAccessRule(const ByteArray &hash);
+
+               void setAPDUAccessRule(const ByteArray &certHash, bool rule);
+               void addAPDUAccessRule(const ByteArray &certHash,
+                       const ByteArray &apdu, const ByteArray &mask);
+               void addAPDUAccessRule(const ByteArray &certHash,
+                       const ByteArray &rule);
+
+               void setNFCAccessRule(const ByteArray &certHash, bool rule);
+
+               bool isAuthorizedAccess(const ByteArray &certHash) const;
+               bool isAuthorizedAPDUAccess(const ByteArray &certHash,
+                       const ByteArray &command) const;
+               bool isAuthorizedNFCAccess(const ByteArray &certHash) const;
 
-               void loadAccessCondition(ByteArray &aid, ByteArray &data);
-               bool isAuthorizedAccess(ByteArray &certHash);
-               bool isAuthorizedAPDUAccess(ByteArray &command);
-               bool isAuthorizedNFCAccess();
+               AccessRule *getAccessRule(const ByteArray &certHash);
+               const AccessRule *getAccessRule(const ByteArray &certHash) const;
 
-               void printAccessConditions();
+               friend class AccessControlList;
        };
 
 } /* namespace smartcard_service_api */
index 1bbbb76..df98c75 100644 (file)
 /* local header */
 #include "ByteArray.h"
 #include "Channel.h"
+#include "AccessCondition.h"
 
 using namespace std;
 
 namespace smartcard_service_api
 {
-       class AccessCondition;
-
        class AccessControlList
        {
        protected:
                map<ByteArray, AccessCondition> mapConditions;
                bool allGranted;
 
-               void printAccessControlList();
-               bool isAuthorizedAccess(ByteArray aid, ByteArray certHash, bool update);
+               const AccessRule *findAccessRule(const ByteArray &aid,
+                       const ByteArray &hash) const;
+               AccessCondition &getAccessCondition(const ByteArray &aid);
 
        public:
-               static ByteArray AID_ALL;
-               static ByteArray AID_DEFAULT;
+               static ByteArray ALL_SE_APPS;
+               static ByteArray DEFAULT_SE_APP;
+               static ByteArray ALL_DEVICE_APPS;
 
                AccessControlList();
                virtual ~AccessControlList();
@@ -54,9 +55,17 @@ namespace smartcard_service_api
                int updateACL(Channel *channel) { return loadACL(channel); }
                void releaseACL();
 
-               bool isAuthorizedAccess(ByteArray aid, ByteArray certHash);
-               bool isAuthorizedAccess(unsigned char *aidBuffer, unsigned int aidLength, unsigned char *certHashBuffer, unsigned int certHashLength);
-               bool isAuthorizedAccess(ByteArray aid, vector<ByteArray> &certHashes);
+               virtual bool isAuthorizedAccess(const ByteArray &aid,
+                       const ByteArray &certHash) const;
+               virtual bool isAuthorizedAccess(const unsigned char *aidBuffer,
+                       unsigned int aidLength, const unsigned char *certHashBuffer,
+                       unsigned int certHashLength) const;
+               virtual bool isAuthorizedAccess(const ByteArray &aid,
+                       const vector<ByteArray> &certHashes) const;
+               virtual bool isAuthorizedAccess(const ByteArray &aid,
+                       const vector<ByteArray> &certHashes, const ByteArray &command) const;
+               virtual bool isAuthorizedNFCAccess(const ByteArray &aid,
+                       const vector<ByteArray> &certHashes) const;
        };
 
 } /* namespace smartcard_service_api */
index cc08c5b..e35bef0 100644 (file)
@@ -18,7 +18,9 @@
 #define BYTEARRAY_H_
 
 /* standard library header */
+#include <string>
 #include <stdint.h>
+#include <stddef.h>
 
 /* SLP library header */
 
 
 #define ARRAY_AND_SIZE(x) (uint8_t *)(&x), sizeof(x)
 
+using namespace std;
+
 namespace smartcard_service_api
 {
        class ByteArray //: public Serializable
        {
        protected:
                uint8_t *buffer;
-               uint32_t length;
-               char strBuffer[100];
+               size_t length;
 
-               bool _setBuffer(uint8_t *array, uint32_t bufferLen);
+               bool _assign(uint8_t *array, size_t size);
                void save(const char *filePath);
 
        public:
                static ByteArray EMPTY;
 
                ByteArray();
-               ByteArray(uint8_t *array, uint32_t bufferLen);
+               ByteArray(const uint8_t *array, size_t size);
                ByteArray(const ByteArray &T);
                ~ByteArray();
 
 //             ByteArray serialize();
 //             void deserialize(ByteArray buffer);
 
-               bool setBuffer(uint8_t *array, uint32_t bufferLen);
-               void releaseBuffer();
+               bool assign(const uint8_t *array, size_t size);
+               inline bool setBuffer(const uint8_t *array, size_t size) { return assign(array, size); }
+               void clear();
+
+               size_t size() const;
+               inline size_t getLength() const { return size(); }
+               uint8_t *getBuffer();
+               const uint8_t *getBuffer() const;
+               uint8_t *getBuffer(size_t offset);
+               const uint8_t *getBuffer(size_t offset) const;
 
-               uint32_t getLength() const;
-               uint8_t *getBuffer() const;
-               uint8_t *getBuffer(uint32_t offset) const;
+               uint8_t at(size_t index) const;
+               uint8_t reverseAt(size_t index) const;
 
-               uint8_t getAt(uint32_t index) const;
-               uint8_t getReverseAt(uint32_t index) const;
+               size_t extract(uint8_t *array, size_t size) const;
 
-               uint32_t copyFromArray(uint8_t *array, uint32_t bufferLen) const;
+               const ByteArray sub(size_t offset, size_t size) const;
 
                /* operator overloading */
                ByteArray &operator =(const ByteArray &T);
@@ -70,10 +79,10 @@ namespace smartcard_service_api
                bool operator !=(const ByteArray &T) const;
                bool operator <(const ByteArray &T) const;
                bool operator >(const ByteArray &T) const;
-               uint8_t &operator [](uint32_t index) const;
+               uint8_t operator [](size_t index) const;
 
-               inline bool isEmpty() { return (buffer == (void *)0 || length == 0); }
-               const char *toString();
+               inline bool isEmpty() const { return (buffer == (void *)0 || length == 0); }
+               const string toString() const;
        };
 
 } /* namespace smartcard_service_api */
index 2e0579f..e2b6899 100644 (file)
@@ -30,9 +30,9 @@ namespace smartcard_service_api
 {
        class SessionHelper;    /* explicit declaration */
 
-       typedef void (*transmitCallback)(unsigned char *buffer, unsigned int length,
-               int error, void *userParam);
-       typedef void (*closeCallback)(int error, void *userParam);
+       typedef void (*transmitCallback)(unsigned char *buffer,
+               unsigned int length, int error, void *userParam);
+       typedef void (*closeChannelCallback)(int error, void *userParam);
 
        class Channel : public Synchronous
        {
@@ -41,10 +41,10 @@ namespace smartcard_service_api
                SessionHelper *session;
                int channelNum;
 
-               Channel() : Synchronous() { channelNum = -1; }
-               Channel(SessionHelper *session) : Synchronous() { this->session = session; }
+               Channel() : session(NULL), channelNum(-1) {}
+               Channel(SessionHelper *session) : session(session), channelNum(-1) {}
 
-               inline void setSelectResponse(ByteArray &response) { selectResponse = response; }
+               inline void setSelectResponse(const ByteArray &response) { selectResponse = response; }
 
        public :
                virtual ~Channel() {};
@@ -52,17 +52,17 @@ namespace smartcard_service_api
                inline bool isBasicChannel() const throw() { return (channelNum == 0); }
                inline bool isClosed() const throw() { return (channelNum < 0); }
 
-               inline ByteArray getSelectResponse() const throw() { return selectResponse; }
+               inline const ByteArray getSelectResponse() const throw() { return selectResponse; }
                inline SessionHelper *getSession() const throw() { return session; }
 
-               virtual int close(closeCallback callback, void *userParam) = 0;
-               virtual int transmit(ByteArray command, transmitCallback callback, void *userData) = 0;
+               virtual int close(closeChannelCallback callback, void *userParam) = 0;
+               virtual int transmit(const ByteArray &command, transmitCallback callback, void *userData) = 0;
 
                virtual void closeSync()
                        throw(ExceptionBase &, ErrorIO &, ErrorSecurity &,
                        ErrorIllegalState &, ErrorIllegalParameter &) = 0;
 
-               virtual int transmitSync(ByteArray command, ByteArray &result)
+               virtual int transmitSync(const ByteArray &command, ByteArray &result)
                        throw(ExceptionBase &, ErrorIO &, ErrorIllegalState &,
                                ErrorIllegalParameter &, ErrorSecurity &) = 0;
        };
index e3f918a..355974a 100644 (file)
 #define DEBUG_H_
 
 /* standard library header */
+#include <iostream>
 
 /* SLP library header */
 #include "dlog.h"
 
 /* local header */
 
-#define COLOR_RED              "\033[0;31m"
-#define COLOR_GREEN    "\033[0;32m"
-#define COLOR_BROWN    "\033[0;33m"
-#define COLOR_BLUE             "\033[0;34m"
-#define COLOR_PURPLE   "\033[0;35m"
-#define COLOR_CYAN             "\033[0;36m"
-#define COLOR_LIGHTBLUE "\033[0;37m"
-#define COLOR_END              "\033[0;m"
-
-#define SCARD_DEBUG(fmt, ...)\
-       do\
-       {\
-               LOGD(fmt, ##__VA_ARGS__);\
-       } while (0)
-
-#define SCARD_DEBUG_ERR(fmt, ...)\
-       do\
-       {\
-               LOGE(COLOR_RED fmt COLOR_END, ##__VA_ARGS__);\
-       }while (0)
-
-#define SCARD_BEGIN() \
-       do\
-    {\
-               LOGD(COLOR_BLUE "BEGIN >>>>" COLOR_END);\
-    } while( 0 )
-
-#define SCARD_END() \
-       do\
-    {\
-               LOGD(COLOR_BLUE "END <<<<" COLOR_END);\
-    } \
-    while( 0 )
+#define COLOR_BLACK    "\033[0;30m"
+#define COLOR_RED      "\033[0;31m"
+#define COLOR_GREEN    "\033[0;32m"
+#define COLOR_BROWN    "\033[0;33m"
+#define COLOR_BLUE     "\033[0;34m"
+#define COLOR_PURPLE   "\033[0;35m"
+#define COLOR_CYAN     "\033[0;36m"
+#define COLOR_GRAY     "\033[0;37m"
+#define COLOR_END      "\033[0;m"
+
+#define _ERR(fmt, ...) \
+       do \
+       { \
+               LOGE(COLOR_RED fmt COLOR_END, ##__VA_ARGS__); \
+       } \
+       while (0)
+
+#define _INFO(fmt, ...) \
+       do \
+       { \
+               LOGI(COLOR_GREEN fmt COLOR_END, ##__VA_ARGS__); \
+       } \
+       while (0)
+
+#define _WARN(fmt, ...) \
+       do \
+       { \
+               LOGI(COLOR_BROWN fmt COLOR_END, ##__VA_ARGS__); \
+       } \
+       while (0)
+
+#define _DBG(fmt, ...) \
+       do \
+       { \
+               LOGD(fmt, ##__VA_ARGS__); \
+       } \
+       while (0)
+
+#define _BEGIN() \
+       do \
+       { \
+               LOGD(COLOR_BLUE"BEGIN >>>>"COLOR_END); \
+       } \
+       while (0)
+
+#define _END() \
+       do \
+       { \
+               LOGD(COLOR_BLUE"END <<<<"COLOR_END); \
+       } \
+       while (0)
 
 #endif /* DEBUG_H_ */
index 2703f43..7a669e8 100644 (file)
@@ -16,7 +16,7 @@
 
 #ifndef DISPATCHERHELPER_H_
 #define DISPATCHERHELPER_H_
-
+#ifndef USE_GDBUS
 /* standard library header */
 #include <queue>
 #include <pthread.h>
@@ -47,11 +47,11 @@ namespace smartcard_service_api
 
        public:
                DispatcherHelper();
-               ~DispatcherHelper();
+               virtual ~DispatcherHelper();
 
                void clearQueue();
 
-               void pushMessage(DispatcherMsg *msg);
+               void pushMessage(const DispatcherMsg &msg);
                void processMessage(DispatcherMsg *msg);
 
                bool runDispatcherThread();
@@ -61,4 +61,5 @@ namespace smartcard_service_api
        };
 
 } /* namespace smartcard_service_api */
+#endif
 #endif /* DISPATCHERHELPER_H_ */
index 69138ba..becd584 100644 (file)
@@ -16,7 +16,7 @@
 
 #ifndef DISPATCHERMSG_H_
 #define DISPATCHERMSG_H_
-
+#ifndef USE_GDBUS
 /* standard library header */
 
 /* SLP library header */
 
 namespace smartcard_service_api
 {
-       class DispatcherMsg: public Message
+       class DispatcherMsg : public Message
        {
        private:
                int peerSocket;
 
        public:
-               DispatcherMsg():Message()
+               DispatcherMsg() : Message()
                {
                        peerSocket = -1;
                }
 
-               DispatcherMsg(Message *msg):Message()
+               DispatcherMsg(const Message &msg) : Message()
                {
                        peerSocket = -1;
-                       message = msg->message;
-                       param1 = msg->param1;
-                       param2 = msg->param2;
-                       error = msg->error;
-                       data = msg->data;
-                       caller = msg->caller;
-                       callback = msg->callback;
-                       userParam = msg->userParam;
+                       message = msg.message;
+                       param1 = msg.param1;
+                       param2 = msg.param2;
+                       error = msg.error;
+                       data = msg.data;
+                       caller = msg.caller;
+                       callback = msg.callback;
+                       userParam = msg.userParam;
                }
 
-               DispatcherMsg(DispatcherMsg *msg):Message()
+               DispatcherMsg(const DispatcherMsg &msg) : Message()
                {
-                       peerSocket = msg->peerSocket;
-                       message = msg->message;
-                       param1 = msg->param1;
-                       param2 = msg->param2;
-                       error = msg->error;
-                       data = msg->data;
-                       caller = msg->caller;
-                       callback = msg->callback;
-                       userParam = msg->userParam;
+                       peerSocket = msg.peerSocket;
+                       message = msg.message;
+                       param1 = msg.param1;
+                       param2 = msg.param2;
+                       error = msg.error;
+                       data = msg.data;
+                       caller = msg.caller;
+                       callback = msg.callback;
+                       userParam = msg.userParam;
                }
 
-               DispatcherMsg(Message *msg, int socket):Message()
+               DispatcherMsg(const Message &msg, int socket) : Message()
                {
                        peerSocket = socket;
-                       message = msg->message;
-                       param1 = msg->param1;
-                       param2 = msg->param2;
-                       error = msg->error;
-                       data = msg->data;
-                       caller = msg->caller;
-                       callback = msg->callback;
-                       userParam = msg->userParam;
+                       message = msg.message;
+                       param1 = msg.param1;
+                       param2 = msg.param2;
+                       error = msg.error;
+                       data = msg.data;
+                       caller = msg.caller;
+                       callback = msg.callback;
+                       userParam = msg.userParam;
                }
 
                ~DispatcherMsg() {}
 
-               inline int getPeerSocket() { return peerSocket; }
+               inline int getPeerSocket() const { return peerSocket; }
                inline void setPeerSocket(int socket) { peerSocket = socket; }
        };
 
 } /* namespace smartcard_service_api */
+#endif
 #endif /* DISPATCHERMSG_H_ */
index c2fd9f1..c19eec9 100644 (file)
@@ -32,16 +32,16 @@ namespace smartcard_service_api
        class EFDIR : public FileObject
        {
        private:
-               ByteArray parseRecord(Record &record, ByteArray &aid);
+               const ByteArray parseRecord(const Record &record, const ByteArray &aid);
 
        public:
-               static const unsigned int EFDIR_FID = 0x002f;
-
                EFDIR(Channel *channel);
-               EFDIR(Channel *channel, ByteArray selectResponse);
+               EFDIR(Channel *channel, const ByteArray &selectResponse);
                ~EFDIR();
 
-               ByteArray getPathByAID(ByteArray &aid);
+               int select();
+
+               const ByteArray getPathByAID(const ByteArray &aid);
        };
 } /* namespace smartcard_service_api */
 #endif /* EFDIR_H_ */
index 655b50b..cb59d1d 100644 (file)
 
 #include "smartcard-types.h"
 
+#define THROW_ERROR(errorCode) \
+               { \
+                       switch (errorCode) \
+                       { \
+                       case SCARD_ERROR_OK : \
+                               /* do nothing */ \
+                               break; \
+               \
+                       case SCARD_ERROR_IPC_FAILED : \
+                       case SCARD_ERROR_IO_FAILED : \
+                       case SCARD_ERROR_OPERATION_TIMEOUT : \
+                               throw ErrorIO(errorCode); \
+                               break; \
+               \
+                       case SCARD_ERROR_SECURITY_NOT_ALLOWED : \
+                               throw ErrorSecurity(errorCode); \
+                               break; \
+               \
+                       case SCARD_ERROR_UNAVAILABLE : \
+                       case SCARD_ERROR_NOT_SUPPORTED : \
+                       case SCARD_ERROR_NOT_INITIALIZED : \
+                       case SCARD_ERROR_SE_NOT_INITIALIZED : \
+                       case SCARD_ERROR_ILLEGAL_STATE : \
+                       case SCARD_ERROR_OPERATION_NOT_SUPPORTED : \
+                               throw ErrorIllegalState(errorCode); \
+                               break; \
+               \
+                       case SCARD_ERROR_ILLEGAL_PARAM : \
+                       case SCARD_ERROR_ILLEGAL_REFERENCE : \
+                               throw ErrorIllegalParameter(errorCode); \
+                               break; \
+               \
+                       default : \
+                       case SCARD_ERROR_UNKNOWN : \
+                       case SCARD_ERROR_OUT_OF_MEMORY : \
+                       case SCARD_ERROR_NOT_ENOUGH_RESOURCE : \
+                       case SCARD_ERROR_NEED_MORE_BUFFER : \
+                               throw ExceptionBase(errorCode); \
+                               break; \
+                       } \
+               }
+
 namespace smartcard_service_api
 {
        class ExceptionBase : public std::exception
index 78917d0..1b303e5 100644 (file)
@@ -18,6 +18,7 @@
 #define FCI_H_
 
 /* standard library header */
+#include <string>
 
 /* SLP library header */
 
@@ -31,40 +32,38 @@ namespace smartcard_service_api
        private:
                ByteArray fcpBuffer;
 
-               char strBuffer[400];
-
-               unsigned int fileSize;
-               unsigned int totalFileSize;
-               unsigned int fid;
-               unsigned int sfi;
-               unsigned int maxRecordSize;
-               unsigned int numberOfRecord;
-               unsigned int fileType;
-               unsigned int fileStructure;
-               unsigned int lcs;
+               int fileSize;
+               int totalFileSize;
+               int fid;
+               int sfi;
+               int maxRecordSize;
+               int numberOfRecord;
+               int fileType;
+               int fileStructure;
+               int lcs;
 
                void resetMemberVar();
 
        public:
                FCP();
-               FCP(ByteArray &array);
+               FCP(const ByteArray &array);
                ~FCP();
 
-               bool setFCP(ByteArray array);
-               ByteArray getFCP();
+               bool setFCP(const ByteArray &array);
+               const ByteArray getFCP() const;
                void releaseFCP();
 
-               unsigned int getFileSize();
-               unsigned int getTotalFileSize();
-               unsigned int getFID();
-               unsigned int getSFI();
-               unsigned int getMaxRecordSize();
-               unsigned int getNumberOfRecord();
-               unsigned int getFileType();
-               unsigned int getFileStructure();
-               unsigned int getLCS();
-
-               const char *toString();
+               int getFileSize() const;
+               int getTotalFileSize() const;
+               int getFID() const;
+               int getSFI() const;
+               int getMaxRecordSize() const;
+               int getNumberOfRecord() const;
+               int getFileType() const;
+               int getFileStructure() const;
+               int getLCS() const;
+
+               const string toString() const;
        };
 
        class FCM
@@ -106,7 +105,7 @@ namespace smartcard_service_api
                FCI();
                ~FCI();
 
-               bool setFCIBuffer(ByteArray array);
+               bool setFCIBuffer(const ByteArray &array);
        };
 
 } /* namespace smartcard_service_api */
index ec9e90b..1802784 100644 (file)
@@ -39,11 +39,11 @@ namespace smartcard_service_api
                FCP fcp;
                bool opened;
 
-               int _select(ByteArray command);
+               int _select(const ByteArray &command);
 
        protected:
                ByteArray selectResponse;
-               bool setSelectResponse(ByteArray &response);
+               bool setSelectResponse(const ByteArray &response);
 
        public:
                static const int SUCCESS = 0;
@@ -58,26 +58,28 @@ namespace smartcard_service_api
                static const unsigned int MF_FID = 0x003F;
 
                FileObject(Channel *channel);
-               FileObject(Channel *channel, ByteArray selectResponse);
+               FileObject(Channel *channel, const ByteArray &selectResponse);
                ~FileObject();
 
                void close();
-               inline bool isClosed() { return (opened == false); }
-               int select(ByteArray aid);
-               int select(ByteArray path, bool fromCurrentDF);
+               inline bool isClosed() const { return (opened == false); }
+               int select(const ByteArray &aid);
+               int select(const ByteArray &path, bool fromCurrentDF);
                int select(unsigned int fid);
                int selectParent();
 
-               FCI *getFCI();
-               FCP *getFCP();
+               inline const ByteArray getSelectResponse() const { return selectResponse; }
+
+               const FCI *getFCI() const;
+               const FCP *getFCP() const;
 
                int readRecord(unsigned int sfi, unsigned int recordId, Record &result);
-               int writeRecord(unsigned int sfi, Record record);
+               int writeRecord(unsigned int sfi, const Record &record);
 
-               int searchRecord(unsigned int sfi, ByteArray searchParam, vector<int> &result);
+               int searchRecord(unsigned int sfi, const ByteArray &searchParam, vector<int> &result);
 
                int readBinary(unsigned int sfi, unsigned int offset, unsigned int length, ByteArray &result);
-               int writeBinary(unsigned int sfi, ByteArray data, unsigned int offset, unsigned int length);
+               int writeBinary(unsigned int sfi, const ByteArray &data, unsigned int offset, unsigned int length);
        };
 
 } /* namespace smartcard_service_api */
similarity index 60%
rename from common/ProviderHelper.cpp
rename to common/include/GDBusHelper.h
index 39817be..8de47d4 100644 (file)
  * limitations under the License.
  */
 
-/* standard library header */
+#ifndef GDBUSHELPER_H_
+#define GDBUSHELPER_H_
 
-/* SLP library header */
+#ifdef USE_GDBUS
+#include <glib.h>
 
-/* local header */
-#include "Debug.h"
-#include "ProviderHelper.h"
+#include "ByteArray.h"
 
 namespace smartcard_service_api
 {
-//     ProviderHelper::ProviderHelper()
-//     {
-//     }
-
-       ProviderHelper::ProviderHelper(Channel *channel)
-       {
-               this->channel = NULL;
-
-               if (channel == NULL)
-               {
-                       SCARD_DEBUG_ERR("invalid channel");
-                       return;
-               }
-
-               this->channel = channel;
-       }
-
-       ProviderHelper::~ProviderHelper()
+       class CallbackParam
        {
-       }
+       public :
+               void *instance;
+               void *callback;
+               void *user_param;
+       };
 
-       Channel *ProviderHelper::getChannel()
+       class GDBusHelper
        {
-               return channel;
-       }
+       public :
+               static void convertVariantToByteArray(GVariant *var,
+                       ByteArray &array);
 
+               static GVariant *convertByteArrayToVariant(
+                       const ByteArray &array);
+       };
 } /* namespace smartcard_service_api */
+#endif
+#endif /* GDBUSHELPER_H_ */
diff --git a/common/include/GPACE.h b/common/include/GPACE.h
new file mode 100644 (file)
index 0000000..5300dfd
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef GPACE_H_
+#define GPACE_H_
+
+/* standard library header */
+
+/* SLP library header */
+
+/* local header */
+#include "smartcard-types.h"
+#ifdef __cplusplus
+#include "AccessControlList.h"
+#endif /* __cplusplus */
+
+#ifdef __cplusplus
+namespace smartcard_service_api
+{
+       class GPACE : public AccessControlList
+       {
+       private :
+               AccessControlList *acl;
+
+       public :
+               GPACE();
+               ~GPACE();
+
+               int loadACL(Channel *channel);
+
+               bool isAuthorizedAccess(const ByteArray &aid,
+                       const ByteArray &certHash) const;
+               bool isAuthorizedAccess(const unsigned char *aidBuffer,
+                       unsigned int aidLength,
+                       const unsigned char *certHashBuffer,
+                       unsigned int certHashLength) const;
+               bool isAuthorizedAccess(const ByteArray &aid,
+                       const vector<ByteArray> &certHashes) const;
+               bool isAuthorizedAccess(const ByteArray &aid,
+                       const vector<ByteArray> &certHashes,
+                       const ByteArray &command) const;
+               bool isAuthorizedNFCAccess(const ByteArray &aid,
+                       const vector<ByteArray> &certHashes) const;
+       };
+
+} /* namespace smartcard_service_api */
+#endif /* __cplusplus */
+#endif /* GPACE_H_ */
diff --git a/common/include/GPARAACL.h b/common/include/GPARAACL.h
new file mode 100644 (file)
index 0000000..4038b41
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef GPARAACL_H_
+#define GPARAACL_H_
+
+/* standard library header */
+
+/* SLP library header */
+
+/* local header */
+#include "smartcard-types.h"
+#ifdef __cplusplus
+#include "AccessControlList.h"
+#include "GPARAM.h"
+#endif /* __cplusplus */
+
+#ifdef __cplusplus
+namespace smartcard_service_api
+{
+       class GPARAACL : public AccessControlList
+       {
+       private:
+               ByteArray refreshTag;
+
+               void addCondition(const ByteArray &aid, const ByteArray &hash,
+                       const vector<ByteArray> &apduRule, const ByteArray &nfcRule);
+
+               int updateRule(const ByteArray &data);
+
+       public:
+               GPARAACL();
+               ~GPARAACL();
+
+               int loadACL(Channel *channel);
+               int loadACL(GPARAM &aram);
+
+               bool isAuthorizedAccess(GPARAM &aram, const ByteArray &aid,
+                       const ByteArray &certHash) const;
+               bool isAuthorizedAccess(GPARAM &aram, const ByteArray &aid,
+                       const ByteArray &certHash,
+                       const ByteArray &command) const;
+               bool isAuthorizedAccess(GPARAM &aram,
+                       const unsigned char *aidBuffer,
+                       unsigned int aidLength,
+                       const unsigned char *certHashBuffer,
+                       unsigned int certHashLength) const;
+               bool isAuthorizedAccess(GPARAM &aram, const ByteArray &aid,
+                       const vector<ByteArray> &certHashes) const;
+               bool isAuthorizedAccess(GPARAM &aram, const ByteArray &aid,
+                       const vector<ByteArray> &certHashes,
+                       const ByteArray &command) const;
+               bool isAuthorizedNFCAccess(GPARAM &aram, const ByteArray &aid,
+                       const vector<ByteArray> &certHashes) const;
+       };
+
+} /* namespace smartcard_service_api */
+#endif /* __cplusplus */
+
+#endif /* GPARAACL_H_ */
diff --git a/common/include/GPARAM.h b/common/include/GPARAM.h
new file mode 100644 (file)
index 0000000..d4b3116
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef GPARAM_H_
+#define GPARAM_H_
+
+/* standard library header */
+#include <vector>
+
+/* SLP library header */
+
+/* local header */
+#include "FileObject.h"
+
+using namespace std;
+
+namespace smartcard_service_api
+{
+       class GPARAM : public FileObject
+       {
+       public:
+               GPARAM(Channel *channel);
+               GPARAM(Channel *channel, const ByteArray &selectResponse);
+               ~GPARAM() {}
+
+               int select();
+
+               int getDataAll(ByteArray &data);
+               int getDataSpecific(const ByteArray &aid, const ByteArray &hash, ByteArray &data);
+               int getDataRefreshTag(ByteArray &tag);
+
+               /* override not supported functions */
+               int select(const ByteArray &aid) { return SCARD_ERROR_NOT_SUPPORTED; }
+               int select(const ByteArray &path, bool fromCurrentDF) { return SCARD_ERROR_NOT_SUPPORTED; }
+               int select(unsigned int fid) { return SCARD_ERROR_NOT_SUPPORTED; }
+               int selectParent() { return SCARD_ERROR_NOT_SUPPORTED; }
+               int readRecord(unsigned int sfi, unsigned int recordId, Record &result) { return SCARD_ERROR_NOT_SUPPORTED; }
+               int writeRecord(unsigned int sfi, const Record &record) { return SCARD_ERROR_NOT_SUPPORTED; }
+               int searchRecord(unsigned int sfi, const ByteArray &searchParam, vector<int> &result) { return SCARD_ERROR_NOT_SUPPORTED; }
+               int readBinary(unsigned int sfi, unsigned int offset, unsigned int length, ByteArray &result) { return SCARD_ERROR_NOT_SUPPORTED; }
+               int writeBinary(unsigned int sfi, const ByteArray &data, unsigned int offset, unsigned int length) { return SCARD_ERROR_NOT_SUPPORTED; }
+       };
+
+} /* namespace smartcard_service_api */
+#endif /* GPARAM_H_ */
similarity index 55%
rename from common/include/GPSEACL.h
rename to common/include/GPARFACL.h
index 4e1bb8e..396adbe 100644 (file)
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef GPSEACL_H_
-#define GPSEACL_H_
+#ifndef GPARFACL_H_
+#define GPARFACL_H_
 
 /* standard library header */
 
 #ifdef __cplusplus
 namespace smartcard_service_api
 {
-       class GPSEACL: public AccessControlList
+       class GPARFACL : public AccessControlList
        {
        private:
                ByteArray refreshTag;
 
-               static ByteArray OID_GLOBALPLATFORM;
-
                int loadAccessControl(Channel *channel, PKCS15DODF *dodf);
-               int loadRules(Channel *channel, ByteArray path);
-               int loadAccessConditions(Channel *channel, ByteArray aid, ByteArray path);
+               int loadRules(Channel *channel, const ByteArray &path);
+               int loadAccessConditions(Channel *channel, const ByteArray &aid, const ByteArray &path);
 
        public:
-               GPSEACL();
-               ~GPSEACL();
+               GPARFACL();
+               ~GPARFACL();
 
                int loadACL(Channel *channel);
-
        };
 
 } /* namespace smartcard_service_api */
 #endif /* __cplusplus */
-
-/* export C API */
-#ifdef __cplusplus
-extern "C"
-{
-#endif /* __cplusplus */
-
-typedef void *gp_se_acl_h;
-
-gp_se_acl_h gp_se_acl_create_instance();
-int gp_se_acl_load_acl(gp_se_acl_h handle, channel_h channel);
-int gp_se_acl_update_acl(gp_se_acl_h handle, channel_h channel);
-void gp_se_acl_release_acl(gp_se_acl_h handle);
-bool gp_se_acl_is_authorized_access(gp_se_acl_h handle, unsigned char *aidBuffer, unsigned int aidLength, unsigned char *certHashBuffer, unsigned int certHashLength);
-void gp_se_acl_destroy_instance(gp_se_acl_h handle);
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-
-#endif /* GPSEACL_H_ */
+#endif /* GPARFACL_H_ */
index de6e931..8761815 100644 (file)
@@ -17,6 +17,7 @@
 #ifndef IPCHELPER_H_
 #define IPCHELPER_H_
 
+#ifndef USE_GDBUS
 /* standard library header */
 #include <glib.h>
 #include <pthread.h>
@@ -72,10 +73,10 @@ namespace smartcard_service_api
                void destroyListenSocket();
                void destroyConnectSocket();
 
-               bool sendMessage(int socket, Message *msg);
-               bool sendMessage(int socket, ByteArray &buffer);
+               bool sendMessage(int socket, const Message &msg);
+               bool sendMessage(int socket, const ByteArray &buffer);
                Message *retrieveMessage();
-               ByteArray retrieveBuffer(int socket);
+               const ByteArray retrieveBuffer(int socket);
                Message *retrieveMessage(int socket);
 
                void setDispatcher(DispatcherHelper *dispatcher);
@@ -87,4 +88,5 @@ namespace smartcard_service_api
        };
 
 } /* namespace smartcard_service_api */
+#endif
 #endif /* IPCHELPER_H_ */
index 45340ec..d5a0cd7 100644 (file)
 
 namespace smartcard_service_api
 {
-       class ISO7816BERTLV: public TLVHelper
+       class ISO7816BERTLV : public TLVHelper
        {
        private:
-//             ISO7816BERTLV child;
-
                unsigned char firstByte;
                unsigned int tagClass;
                unsigned int encoding;
@@ -39,22 +37,22 @@ namespace smartcard_service_api
                ISO7816BERTLV(TLVHelper *parent);
                ISO7816BERTLV(const ByteArray &array, TLVHelper *parent);
 
-               int decodeTag(unsigned char *buffer);
-               int decodeLength(unsigned char *buffer);
-               int decodeValue(unsigned char *buffer);
+               int decodeTag(const unsigned char *buffer);
+               int decodeLength(const unsigned char *buffer);
+               int decodeValue(const unsigned char *buffer);
 
-               TLVHelper *getChildTLV(ByteArray data);
+               TLVHelper *getChildTLV(const ByteArray &data);
 
        public:
                ISO7816BERTLV();
                ISO7816BERTLV(const ByteArray &array);
                ~ISO7816BERTLV();
 
-               unsigned int getClass();
-               unsigned int getEncoding();
+               unsigned int getClass() const;
+               unsigned int getEncoding() const;
 
-               static ByteArray encode(unsigned int tagClass, unsigned int encoding, unsigned int tag, ByteArray buffer);
-               static ByteArray encode(unsigned int tagClass, unsigned int encoding, unsigned int tag, unsigned char *buffer, unsigned int length);
+               static const ByteArray encode(unsigned int tagClass, unsigned int encoding, unsigned int tag, const ByteArray &buffer);
+               static const ByteArray encode(unsigned int tagClass, unsigned int encoding, unsigned int tag, unsigned char *buffer, unsigned int length);
        };
 
 } /* namespace smartcard_service_api */
index 2cdb2a4..28abd03 100644 (file)
 
 #ifndef MESSAGE_H_
 #define MESSAGE_H_
-
+#ifndef USE_GDBUS
 /* standard library header */
+#include <string>
 
 /* SLP library header */
 
 /* local header */
 #include "Serializable.h"
 
+using namespace std;
+
 namespace smartcard_service_api
 {
-       class Message: public Serializable
+       class Message : public Serializable
        {
        private:
-               char text[200];
-
        public:
                static const int MSG_REQUEST_READERS = 0x80;
                static const int MSG_REQUEST_SHUTDOWN = 0x81;
@@ -57,16 +58,17 @@ namespace smartcard_service_api
                void *userParam;
 
                Message();
-               ~Message();
+               virtual ~Message();
 
-               ByteArray serialize();
-               void deserialize(unsigned char *buffer, unsigned int length);
-               void deserialize(ByteArray buffer);
+               const ByteArray serialize() const;
+               void deserialize(const unsigned char *buffer, unsigned int length);
+               void deserialize(const ByteArray &buffer);
 
-               inline bool isSynchronousCall() { return (caller == callback); }
+               inline bool isSynchronousCall() const { return (caller == callback); }
 
-               const char *toString();
+               const string toString() const;
        };
 
 } /* namespace smartcard_service_api */
+#endif
 #endif /* MESSAGE_H_ */
index 2df1185..74b1f8b 100644 (file)
 
 namespace smartcard_service_api
 {
-       class NumberStream: public ByteArray
+       class NumberStream : public ByteArray
        {
        public:
                NumberStream(const ByteArray &T);
 
-               unsigned int getBigEndianNumber();
-               unsigned int getLittleEndianNumber();
+               unsigned int getBigEndianNumber() const;
+               unsigned int getLittleEndianNumber() const;
 
                static unsigned int getBigEndianNumber(const ByteArray &T);
                static unsigned int getLittleEndianNumber(const ByteArray &T);
index b914701..05cd2c2 100644 (file)
@@ -31,13 +31,19 @@ namespace smartcard_service_api
        {
        public:
                /* base64 method */
-               static bool encodeBase64String(const ByteArray &buffer, ByteArray &result, bool newLineChar = false);
-               static bool decodeBase64String(const char *buffer, ByteArray &result, bool newLineChar = true);
-               static bool decodeBase64String(const ByteArray &buffer, ByteArray &result, bool newLineChar = true);
+               static bool encodeBase64String(const ByteArray &buffer,
+                       ByteArray &result, bool newLineChar = false);
+               static bool decodeBase64String(const char *buffer,
+                       ByteArray &result, bool newLineChar = true);
+               static bool decodeBase64String(const ByteArray &buffer,
+                       ByteArray &result, bool newLineChar = true);
 
                /* digest method */
-               static bool digestBuffer(const char *algorithm, const uint8_t *buffer, const uint32_t length, ByteArray &result);
-               static bool digestBuffer(const char *algorithm, const ByteArray &buffer, ByteArray &result);
+               static bool digestBuffer(const char *algorithm,
+                       const uint8_t *buffer, uint32_t length,
+                       ByteArray &result);
+               static bool digestBuffer(const char *algorithm,
+                       const ByteArray &buffer, ByteArray &result);
        };
 
 } /* namespace smartcard_service_api */
index b761eba..3900f13 100644 (file)
@@ -36,17 +36,19 @@ namespace smartcard_service_api
                map<unsigned int, ByteArray> recordElement;
                PKCS15ODF *odf;
 
-               bool selectFromEFDIR();
+               int selectFromEFDIR();
 
        public:
                static ByteArray PKCS15_AID;
 
                PKCS15(Channel *channel);
-               PKCS15(Channel *channel, ByteArray selectResponse);
+               PKCS15(Channel *channel, const ByteArray &selectResponse);
                ~PKCS15();
 
+               int select();
+
                PKCS15ODF *getODF();
-               int getTokenInfo(ByteArray &path);
+               int getTokenInfo(ByteArray &path) const;
        };
 
 } /* namespace smartcard_service_api */
index 3860b54..9364245 100644 (file)
 
 namespace smartcard_service_api
 {
-       class PKCS15DODF: public PKCS15Object
+       class PKCS15DODF : public PKCS15Object
        {
        private:
                map<ByteArray, PKCS15OID> mapOID;
 
-               bool parseData(ByteArray data);
+               bool parseData(const ByteArray &data);
 
        public:
-               PKCS15DODF();
                PKCS15DODF(unsigned int fid, Channel *channel);
-               PKCS15DODF(ByteArray path, Channel *channel);
+               PKCS15DODF(const ByteArray &path, Channel *channel);
                ~PKCS15DODF();
 
-               int searchOID(ByteArray oid, ByteArray &data);
+               int searchOID(const ByteArray &oid, ByteArray &data) const;
        };
 
 } /* namespace smartcard_service_api */
index 3139959..1deb36d 100644 (file)
@@ -30,10 +30,10 @@ using namespace std;
 
 namespace smartcard_service_api
 {
-       class PKCS15ODF: public PKCS15Object
+       class PKCS15ODF : public PKCS15Object
        {
        private:
-               bool parseData(ByteArray data);
+               bool parseData(const ByteArray &data);
                PKCS15DODF *dodf;
 
        public:
@@ -44,7 +44,7 @@ namespace smartcard_service_api
 
 //             PKCS15ODF();
                PKCS15ODF(Channel *channel);
-               PKCS15ODF(Channel *channel, ByteArray selectResponse);
+               PKCS15ODF(Channel *channel, const ByteArray &selectResponse);
                ~PKCS15ODF();
 
                int getPuKDFPath(ByteArray &path);
index 86b1312..248150b 100644 (file)
@@ -33,16 +33,15 @@ namespace smartcard_service_api
                ByteArray name;
                ByteArray path;
 
-               bool parseOID(ByteArray data);
+               bool parseOID(const ByteArray &data);
 
        public:
-               PKCS15OID(ByteArray data);
+               PKCS15OID(const ByteArray &data);
                ~PKCS15OID();
 
-               ByteArray getOID();
-               ByteArray getName();
-               ByteArray getPath();
-
+               inline const ByteArray getOID() const { return oid; }
+               inline const ByteArray getName() const { return name; }
+               inline const ByteArray getPath() const { return path; }
        };
 
 } /* namespace smartcard_service_api */
index 8a0653e..df76f72 100644 (file)
@@ -31,7 +31,7 @@ using namespace std;
 
 namespace smartcard_service_api
 {
-       class PKCS15Object: public FileObject
+       class PKCS15Object : public FileObject
        {
        protected:
                map<unsigned int, ByteArray> dataList;
@@ -41,16 +41,15 @@ namespace smartcard_service_api
                static const unsigned int TAG_SEQUENCE = (unsigned int)0x30;
                static const unsigned int TAG_OCTET_STREAM = (unsigned int)0x04;
 
-//             PKCS15Object();
                PKCS15Object(Channel *channel);
-               PKCS15Object(Channel *channel, ByteArray selectResponse);
+               PKCS15Object(Channel *channel, const ByteArray &selectResponse);
                ~PKCS15Object();
 
-               int decodePath(ByteArray path, PKCS15Path &result);
-               int getPath(unsigned int type, PKCS15Path &result);
-               int getPaths(vector<PKCS15Path> &paths);
+               int decodePath(const ByteArray &path, PKCS15Path &result);
+               int getPath(unsigned int type, PKCS15Path &result) const;
+               int getPaths(vector<PKCS15Path> &paths) const;
 
-               static ByteArray getOctetStream(const ByteArray &data);
+               static const ByteArray getOctetStream(const ByteArray &data);
        };
 
 } /* namespace smartcard_service_api */
index c57dfe9..52f3894 100644 (file)
@@ -31,22 +31,23 @@ namespace smartcard_service_api
        private :
                ByteArray path;
                int index;
-               int length;
+               size_t length;
 
-               bool parseData(ByteArray &data);
+               bool parseData(const ByteArray &data);
 
        public:
                PKCS15Path();
-               PKCS15Path(ByteArray &data);
-               PKCS15Path(ByteArray path, int index);
-               PKCS15Path(unsigned char *path, unsigned int length, int index);
+               PKCS15Path(const ByteArray &data);
+               PKCS15Path(const ByteArray &path, int index);
+               PKCS15Path(const unsigned char *path,
+                       size_t length, int index);
                ~PKCS15Path();
 
-               int getPath(ByteArray &path);
-               bool hasIndexLength();
-               int getIndex();
-               unsigned int getLength();
-               int encode(ByteArray &result);
+               inline const ByteArray getPath() const { return path; }
+               inline bool hasIndexLength() const { return (length != 0); }
+               inline int getIndex() const { return index; }
+               inline size_t size() const { return length; }
+               int encode(ByteArray &result) const;
        };
 
 } /* namespace smartcard_service_api */
index 44a86f3..9f3ff80 100644 (file)
@@ -26,7 +26,7 @@
 
 namespace smartcard_service_api
 {
-       class PKCS15TokenInfo: public PKCS15Object
+       class PKCS15TokenInfo : public PKCS15Object
        {
        public:
                PKCS15TokenInfo(Channel *channel);
index ef6dab4..7418b6c 100644 (file)
@@ -31,13 +31,11 @@ namespace smartcard_service_api
        protected:
                Channel *channel;
 
-//             ProviderHelper();
-
        public:
-               ProviderHelper(Channel *channel);
-               ~ProviderHelper();
+               ProviderHelper(Channel *channel) : channel(channel) {}
+               virtual ~ProviderHelper() {}
 
-               Channel *getChannel();
+               inline Channel *getChannel() { return channel; }
        };
 
 } /* namespace smartcard_service_api */
index 807cc64..259044a 100644 (file)
@@ -19,6 +19,7 @@
 
 /* standard library header */
 #include <vector>
+#include <string>
 
 /* SLP library header */
 
@@ -32,23 +33,26 @@ namespace smartcard_service_api
 {
        class SEServiceHelper;
 
-       typedef void (*openSessionCallback)(SessionHelper *session, int error, void *userData);
+       typedef void (*openSessionCallback)(SessionHelper *session, int error,
+               void *userData);
 
        class ReaderHelper : public Synchronous
        {
        protected:
-               char name[30];
-               vector<SessionHelper *> sessions;
                SEServiceHelper *seService;
+               string name;
                bool present;
+               vector<SessionHelper *> sessions;
 
-               ReaderHelper();
+               ReaderHelper() : seService(NULL), present(false) {}
+               ReaderHelper(const char *name) : seService(NULL), name(name),
+                       present(false) {}
                virtual ~ReaderHelper() {}
 
        public:
-               inline const char *getName() { return name; }
-               inline SEServiceHelper *getSEService() { return seService; }
-               inline bool isSecureElementPresent() { return present; }
+               inline const char *getName() const { return name.c_str(); }
+               inline SEServiceHelper *getSEService() const { return seService; }
+               inline bool isSecureElementPresent() const { return present; }
 
                virtual void closeSessions()
                        throw(ErrorIO &, ErrorIllegalState &) = 0;
index 0044d4d..c1aca80 100644 (file)
@@ -29,12 +29,12 @@ namespace smartcard_service_api
 
        public:
                Record() : id(0) {}
-               Record(unsigned int id, ByteArray buffer)
-                       : id(id), data(buffer) {};
+               Record(unsigned int id, const ByteArray &buffer) : id(id),
+                       data(buffer) {};
                ~Record() {}
 
-               inline unsigned int getID() { return id; }
-               inline ByteArray getData() { return data; }
+               inline unsigned int getID() const { return id; }
+               inline const ByteArray getData() const { return data; }
        };
 
 } /* namespace smartcard_service_api */
index f95270b..4afbfcb 100644 (file)
@@ -38,7 +38,7 @@ namespace smartcard_service_api
 
        public:
                SEServiceHelper() : connected(false) {}
-               virtual ~SEServiceHelper();
+               virtual ~SEServiceHelper() {}
 
                vector<ReaderHelper *> getReaders() { return readers; }
                bool isConnected() { return connected; }
index 564f80d..a138cd6 100644 (file)
@@ -23,8 +23,8 @@ namespace smartcard_service_api
 {
        class Serializable
        {
-               virtual ByteArray serialize() = 0;
-               virtual void deserialize(ByteArray buffer) = 0;
+               virtual const ByteArray serialize() const = 0;
+               virtual void deserialize(const ByteArray &buffer) = 0;
        };
 
 } /* namespace smartcard_service_api */
index 1798563..ead9c47 100644 (file)
@@ -47,7 +47,8 @@ namespace smartcard_service_api
                bool closed;
 
        public:
-               SessionHelper(ReaderHelper *reader);
+               SessionHelper(ReaderHelper *reader) :
+                       reader(reader), closed(true) {}
                virtual ~SessionHelper() {}
 
                ReaderHelper *getReader() const throw() { return reader; }
@@ -59,12 +60,12 @@ namespace smartcard_service_api
                virtual int getATR(getATRCallback callback, void *userData) = 0;
                virtual int close(closeSessionCallback callback, void *userData) = 0;
 
-               virtual int openBasicChannel(ByteArray aid, openChannelCallback callback, void *userData) = 0;
-               virtual int openBasicChannel(unsigned char *aid, unsigned int length, openChannelCallback callback, void *userData) = 0;
-               virtual int openLogicalChannel(ByteArray aid, openChannelCallback callback, void *userData) = 0;
-               virtual int openLogicalChannel(unsigned char *aid, unsigned int length, openChannelCallback callback, void *userData) = 0;
+               virtual int openBasicChannel(const ByteArray &aid, openChannelCallback callback, void *userData) = 0;
+               virtual int openBasicChannel(const unsigned char *aid, unsigned int length, openChannelCallback callback, void *userData) = 0;
+               virtual int openLogicalChannel(const ByteArray &aid, openChannelCallback callback, void *userData) = 0;
+               virtual int openLogicalChannel(const unsigned char *aid, unsigned int length, openChannelCallback callback, void *userData) = 0;
 
-               virtual ByteArray getATRSync()
+               virtual const ByteArray getATRSync()
                        throw(ExceptionBase &, ErrorIO &, ErrorSecurity &,
                        ErrorIllegalState &, ErrorIllegalParameter &) = 0;
 
@@ -72,17 +73,21 @@ namespace smartcard_service_api
                        throw(ExceptionBase &, ErrorIO &, ErrorSecurity &,
                        ErrorIllegalState &, ErrorIllegalParameter &) = 0;
 
-               virtual Channel *openBasicChannelSync(ByteArray aid)
-                       throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &) = 0;
+               virtual Channel *openBasicChannelSync(const ByteArray &aid)
+                       throw(ExceptionBase &, ErrorIO &, ErrorIllegalState &,
+                               ErrorIllegalParameter &, ErrorSecurity &) = 0;
 
-               virtual Channel *openBasicChannelSync(unsigned char *aid, unsigned int length)
-                       throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &) = 0;
+               virtual Channel *openBasicChannelSync(const unsigned char *aid, unsigned int length)
+                       throw(ExceptionBase &, ErrorIO &, ErrorIllegalState &,
+                               ErrorIllegalParameter &, ErrorSecurity &) = 0;
 
-               virtual Channel *openLogicalChannelSync(ByteArray aid)
-                       throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &) = 0;
+               virtual Channel *openLogicalChannelSync(const ByteArray &aid)
+                       throw(ExceptionBase &, ErrorIO &, ErrorIllegalState &,
+                               ErrorIllegalParameter &, ErrorSecurity &) = 0;
 
-               virtual Channel *openLogicalChannelSync(unsigned char *aid, unsigned int length)
-                       throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &) = 0;
+               virtual Channel *openLogicalChannelSync(const unsigned char *aid, unsigned int length)
+                       throw(ExceptionBase &, ErrorIO &, ErrorIllegalState &,
+                               ErrorIllegalParameter &, ErrorSecurity &) = 0;
        };
 
 } /* namespace smartcard_service_api */
index 05d074e..f65844c 100644 (file)
@@ -38,8 +38,9 @@ namespace smartcard_service_api
        class SignatureHelper
        {
        public:
-               static ByteArray getCertificationHash(const char *packageName);
-               static ByteArray getCertificationHash(int pid);
+               static int getPackageName(int pid, char *package, size_t length);
+               static const ByteArray getCertificationHash(const char *packageName);
+               static const ByteArray getCertificationHash(int pid);
                static bool getCertificationHashes(int pid, vector<ByteArray> &certHashes);
                static bool getCertificationHashes(const char *packageName, vector<ByteArray> &certHashes);
        };
@@ -55,10 +56,10 @@ extern "C"
 
 typedef struct _certiHash
 {
-   uint8_t *value;
-   uint32_t length;
-   struct _certiHash *next;
-}certiHash;
+       uint8_t *value;
+       uint32_t length;
+       struct _certiHash *next;
+} certiHash;
 
 typedef void (*signature_helper_get_certificate_hashes_cb)(void *user_param, uint8_t *hash, uint32_t length);
 
index a31d182..d3311b4 100644 (file)
@@ -33,27 +33,27 @@ namespace smartcard_service_api
                SimpleTLV(TLVHelper *parent);
                SimpleTLV(const ByteArray &array, TLVHelper *parent);
 
-               int decodeTag(unsigned char *buffer);
-               int decodeLength(unsigned char *buffer);
-               int decodeValue(unsigned char *buffer);
+               int decodeTag(const unsigned char *buffer);
+               int decodeLength(const unsigned char *buffer);
+               int decodeValue(const unsigned char *buffer);
 
-               TLVHelper *getChildTLV(ByteArray data);
+               TLVHelper *getChildTLV(const ByteArray &data);
 
        public:
                SimpleTLV();
                SimpleTLV(const ByteArray &array);
                ~SimpleTLV();
 
-               static ByteArray getOctetString(const ByteArray &array);
+               static const ByteArray getOctetString(const ByteArray &array);
                static bool getBoolean(const ByteArray &array);
                static int getInteger(const ByteArray &array);
 
-               static ByteArray getOctetString(SimpleTLV &tlv);
+               static const ByteArray getOctetString(SimpleTLV &tlv);
                static bool getBoolean(SimpleTLV &tlv);
                static int getInteger(SimpleTLV &tlv);
 
-               static ByteArray encode(unsigned int tag, ByteArray buffer);
-               static ByteArray encode(unsigned int tag, unsigned char *buffer, unsigned int length);
+               static const ByteArray encode(unsigned int tag, const ByteArray &buffer);
+               static const ByteArray encode(unsigned int tag, unsigned char *buffer, unsigned int length);
        };
 
 } /* namespace smartcard_service_api */
index 55e64ca..04c6694 100644 (file)
@@ -34,7 +34,6 @@ namespace smartcard_service_api
                TLVHelper *parentTLV;
                TLVHelper *childTLV;
 
-               char strBuffer[200];
                ByteArray tlvBuffer;
                unsigned int offset;
 
@@ -42,43 +41,42 @@ namespace smartcard_service_api
                unsigned int currentL;
                ByteArray currentV;
 
-               void initialize(TLVHelper *parent = NULL);
                TLVHelper(TLVHelper *parent);
                TLVHelper(const ByteArray &array, TLVHelper *parent);
 
-               virtual int decodeTag(unsigned char *buffer) = 0;
-               virtual int decodeLength(unsigned char *buffer) = 0;
-               virtual int decodeValue(unsigned char *buffer) = 0;
+               virtual int decodeTag(const unsigned char *buffer) = 0;
+               virtual int decodeLength(const unsigned char *buffer) = 0;
+               virtual int decodeValue(const unsigned char *buffer) = 0;
 
-               virtual TLVHelper *getChildTLV(ByteArray data) = 0;
+               virtual TLVHelper *getChildTLV(const ByteArray &data) = 0;
                TLVHelper *getParentTLV();
 
                bool setTLVBuffer(const ByteArray &array, TLVHelper *parent);
-               bool setTLVBuffer(unsigned char *buffer, unsigned int length, TLVHelper *parent);
+               bool setTLVBuffer(const unsigned char *buffer, unsigned int length, TLVHelper *parent);
 
-               bool _isEndOfBuffer() { return offset >= tlvBuffer.getLength(); }
+               inline bool _isEndOfBuffer() const { return offset >= tlvBuffer.size(); }
                bool _decodeTLV();
 
-               unsigned int _getTag() { return currentT; }
-               unsigned int _getLength() { return currentL; }
-               ByteArray _getValue() { return currentV; }
+               inline unsigned int _getTag() const { return currentT; }
+               inline unsigned int _size() const { return currentL; }
+               inline const ByteArray _getValue() const { return currentV; }
 
        public:
                TLVHelper();
                TLVHelper(const ByteArray &array);
-               ~TLVHelper();
+               virtual ~TLVHelper();
 
                bool setTLVBuffer(const ByteArray &array) { return setTLVBuffer(array, NULL); }
-               bool setTLVBuffer(unsigned char *buffer, unsigned int length) { return setTLVBuffer(buffer, length, NULL); }
+               bool setTLVBuffer(const unsigned char *buffer, unsigned int length) { return setTLVBuffer(buffer, length, NULL); }
 
-               bool isEndOfBuffer() { return currentTLV->_isEndOfBuffer(); }
-               bool decodeTLV() { return currentTLV->_decodeTLV(); }
+               inline bool isEndOfBuffer() const { return currentTLV->_isEndOfBuffer(); }
+               inline bool decodeTLV() { return currentTLV->_decodeTLV(); }
 
-               unsigned int getTag() { return currentTLV->_getTag(); }
-               unsigned int getLength() { return currentTLV->_getLength(); }
-               ByteArray getValue() { return currentTLV->_getValue(); }
+               unsigned int getTag() const { return currentTLV->_getTag(); }
+               unsigned int size() const { return currentTLV->_size(); }
+               const ByteArray getValue() const { return currentTLV->_getValue(); }
 
-               const char *toString();
+               const string toString() const;
 
                bool enterToValueTLV();
                bool returnToParentTLV();
index dccc9bf..3cfc912 100644 (file)
 
 namespace smartcard_service_api
 {
-       typedef void (*terminalNotificationCallback)(void *terminal, int event, int error, void *user_param);
+       typedef void (*terminalNotificationCallback)(const void *terminal, int event, int error, void *user_param);
 
-       typedef void (*terminalTransmitCallback)(unsigned char *buffer, unsigned int length, int error, void *userParam);
-       typedef void (*terminalGetATRCallback)(unsigned char *buffer, unsigned int length, int error, void *userParam);
+       typedef void (*terminalTransmitCallback)(const unsigned char *buffer, unsigned int length, int error, void *userParam);
+       typedef void (*terminalGetATRCallback)(const unsigned char *buffer, unsigned int length, int error, void *userParam);
 
        class Terminal : public Synchronous
        {
@@ -43,27 +43,24 @@ namespace smartcard_service_api
                static const int NOTIFY_SE_AVAILABLE = 1;
                static const int NOTIFY_SE_NOT_AVAILABLE = -1;
 
-               Terminal()
-               {
-                       statusCallback = NULL;
-                       initialized = false;
-                       name = NULL;
-               }
+               Terminal() : statusCallback(NULL),
+                       initialized(false), name(NULL) {}
+
                virtual ~Terminal() {}
 
                virtual bool initialize() = 0;
                virtual void finalize() = 0;
-               inline bool isInitialized() { return initialized; }
+               inline bool isInitialized() const { return initialized; }
 
-               inline char *getName() { return name; }
+               inline const char *getName() const { return name; }
                inline void setStatusCallback(terminalNotificationCallback callback) { statusCallback = callback; }
 
-               virtual bool isSecureElementPresence() = 0;
+               virtual bool isSecureElementPresence() const = 0;
 
-               virtual int transmitSync(ByteArray command, ByteArray &result) = 0;
+               virtual int transmitSync(const ByteArray &command, ByteArray &result) = 0;
                virtual int getATRSync(ByteArray &atr) = 0;
 
-               virtual int transmit(ByteArray command, terminalTransmitCallback callback, void *userData) = 0;
+               virtual int transmit(const ByteArray &command, terminalTransmitCallback callback, void *userData) = 0;
                virtual int getATR(terminalGetATRCallback callback, void *userData) = 0;
        };
 
similarity index 78%
rename from common/smartcard-service-common.pc.in
rename to common/smartcard-service-common.pc
index a051e12..36ea9c9 100644 (file)
@@ -3,11 +3,11 @@
 prefix=/usr
 exec_prefix=${prefix}/bin
 includedir=${prefix}/include
-libdir=@LIB_INSTALL_DIR@
+libdir=${prefix}/lib
 
 Name: smartcard-service-common
 Description: Make flags of Common library of Smartcard service
 Version: 1.0
 Requires: 
 Libs: -L${libdir} -lsmartcard-service-common
-Cflags: -I${includedir}/smartcard-service-common
+Cflags: -I${includedir}/smartcard-service-common
\ No newline at end of file
diff --git a/common/smartcard-service-gdbus.xml b/common/smartcard-service-gdbus.xml
new file mode 100755 (executable)
index 0000000..cc8b21a
--- /dev/null
@@ -0,0 +1,105 @@
+<!--
+  org.tizen.SmartcardService
+-->
+
+<node>
+  <interface name="org.tizen.SmartcardService.SeService">
+    <!--
+      SeService
+    -->
+    <method name="SeService">
+      <arg type="i" name="result" direction="out" />
+      <arg type="u" name="handle" direction="out" />
+      <arg type="a(us)" name="readers" direction="out" />
+    </method>
+
+    <!--
+      shutdown
+    -->
+    <method name="shutdown">
+      <arg type="u" name="service_id" direction="in" />
+      <arg type="i" name="result" direction="out" />
+    </method>
+
+    <!--
+      ReaderInserted
+    -->
+    <signal name="ReaderInserted">
+      <arg type="u" name="reader_id" />
+      <arg type="s" name="reader_name" />
+    </signal>
+
+    <!--
+      ReaderRemoved
+    -->
+    <signal name="ReaderRemoved">
+      <arg type="u" name="reader_id" />
+      <arg type="s" name="reader_name" />
+    </signal>
+  </interface>
+
+  <interface name="org.tizen.SmartcardService.Reader">
+    <!--
+      openSession
+    -->
+    <method name="openSession">
+      <arg type="u" name="service_id" direction="in" />
+      <arg type="u" name="reader_id" direction="in" />
+      <arg type="i" name="result" direction="out" />
+      <arg type="u" name="handle" direction="out" />
+    </method>
+  </interface>
+
+  <interface name="org.tizen.SmartcardService.Session">
+    <!--
+      getATR
+    -->
+    <method name="getATR">
+      <arg type="u" name="service_id" direction="in" />
+      <arg type="u" name="session_id" direction="in" />
+      <arg type="i" name="result" direction="out" />
+      <arg type="a(y)" name="atr" direction="out" />
+    </method>
+    <!--
+      openChannel
+    -->
+    <method name="openChannel">
+      <arg type="u" name="service_id" direction="in" />
+      <arg type="u" name="session_id" direction="in" />
+      <arg type="u" name="type" direction="in" />
+      <arg type="a(y)" name="aid" direction="in" />
+      <arg type="i" name="result" direction="out" />
+      <arg type="u" name="handle" direction="out" />
+      <arg type="a(y)" name="select_response" direction="out" />
+    </method>
+    <!--
+      closeSession
+    -->
+    <method name="closeSession">
+      <arg type="u" name="service_id" direction="in" />
+      <arg type="u" name="session_id" direction="in" />
+      <arg type="i" name="result" direction="out" />
+    </method>
+  </interface>
+
+  <interface name="org.tizen.SmartcardService.Channel">
+    <!--
+      transmit
+    -->
+    <method name="transmit">
+      <arg type="u" name="service_id" direction="in" />
+      <arg type="u" name="channel_id" direction="in" />
+      <arg type="a(y)" name="command" direction="in" />
+      <arg type="i" name="result" direction="out" />
+      <arg type="a(y)" name="response" direction="out" />
+    </method>
+    <!--
+      closeChannel
+    -->
+    <method name="closeChannel">
+      <arg type="u" name="service_id" direction="in" />
+      <arg type="u" name="channel_id" direction="in" />
+      <arg type="i" name="result" direction="out" />
+    </method>
+  </interface>
+</node>
diff --git a/debian/changelog b/debian/changelog
new file mode 100644 (file)
index 0000000..c7c2e9a
--- /dev/null
@@ -0,0 +1,55 @@
+smartcard-service (0.1.0-3) unstable; urgency=low
+
+  * add an exceptional case when is openning client channel (nfc-manager)
+  * Git: slp/pkgs/s/smartcard-service
+  * Tag: smartcard-service_0.1.0-3
+
+ -- Wonkyu Kwon <wonkyu.kwon@samsung.com>  Fri, 20 Apr 2012 11:00:00 +0900
+
+smartcard-service (0.1.0-2) unstable; urgency=low
+
+  * add helpers for openssl and package signature
+  * Git: slp/pkgs/s/smartcard-service
+  * Tag: smartcard-service_0.1.0-2
+
+ -- Wonkyu Kwon <wonkyu.kwon@samsung.com>  Fri, 23 Mar 2012 12:40:00 +0900
+
+smartcard-service (0.1.0-1) unstable; urgency=low
+
+  * Upload package
+  * Git: slp/pkgs/s/smartcard-service
+  * Tag: smartcard-service_0.1.0-1
+
+ -- Wonkyu Kwon <wonkyu.kwon@samsung.com>  Wed, 14 Mar 2012 13:30:00 +0900
+
+smartcard-service (0.0.0-4) unstable; urgency=low
+
+  * Upload package
+  * Git: slp/pkgs/s/smartcard-service
+  * Tag: smartcard-service_0.0.0-4
+
+ -- Wonkyu Kwon <wonkyu.kwon@samsung.com>  Tue, 13 Mar 2012 13:10:00 +0900
+
+smartcard-service (0.0.0-3) unstable; urgency=low
+
+  * namespace and macro name change
+  * Git: slp/pkgs/s/smartcard-service
+  * Tag: smartcard-service_0.0.0-3
+
+ -- Sangsoo Lee <constant.lee@samsung.com>  Wed, 07 Mar 2012 19:26:46 +0900
+
+smartcard-service (0.0.0-2) unstable; urgency=low
+
+  * getChannelCount api add
+  * Git: slp/pkgs/s/smartcard-service
+  * Tag: smartcard-service_0.0.0-2
+
+ -- Sangsoo Lee <constant.lee@samsung.com>  Thu, 23 Feb 2012 21:10:42 +0900
+
+smartcard-service (0.0.0-1) unstable; urgency=low
+
+  * Initial release
+  * Git: slp/pkgs/s/smartcard-service
+  * Tag: smartcard-service_0.0.0-1
+
+ -- Wonkyu Kwon <wonkyu.kwon@samsung.com>  Thu, 31 Jan 2012 00:00:00 +0900
diff --git a/debian/compat b/debian/compat
new file mode 100644 (file)
index 0000000..45a4fb7
--- /dev/null
@@ -0,0 +1 @@
+8
diff --git a/debian/control b/debian/control
new file mode 100644 (file)
index 0000000..f0eabd9
--- /dev/null
@@ -0,0 +1,65 @@
+Source: smartcard-service
+Priority: extra
+Maintainer: Wonkyu Kwon <wonkyu.kwon@samsung.com>, Sangsoo Lee <constant.lee@samsung.com>, Sungjae Lim <sungjae.lim@samsung.com>, Junyong Sim <junyong.sim@samsung.com>, Sechang Sohn <sc.sohn@samsung.com>
+Build-Depends: debhelper (>= 8.0.0), libglib2.0-dev, libvconf-dev, libsecurity-server-client-dev, dlog-dev, wrt-commons-dev, libaul-1-dev, libssl-dev
+#Build-Depends: debhelper (>= 8.0.0), libglib2.0-dev, libvconf-dev, libsecurity-server-client-dev, dlog-dev, libpkcs11-helper1-dev, wrt-commons, libaul-dev, libssl-dev
+#Standards-Version: 3.9.2
+Section: mixed
+Homepage: <insert the upstream URL, if relevant>
+#Vcs-Git: git://git.debian.org/collab-maint/smartcard-service.git
+#Vcs-Browser: http://git.debian.org/?p=collab-maint/smartcard-service.git;a=summary
+
+Package: smartcard-service-common
+Section: libs
+Architecture: any
+Depends: ${shlibs:Depends}, ${misc:Depends}
+Description: Common library of Smart card service
+ Common library of Smart card service
+
+Package: smartcard-service-common-dev
+Section: libdevel
+Architecture: any
+Depends: smartcard-service-common (= ${binary:Version})
+Description: Common library of Smart card service
+ Common library of Smart card service
+
+Package: smartcard-service-common-dbg
+Section: debug
+Architecture: any
+Depends: smartcard-service-common (= ${binary:Version})
+Description: Common library of Smart card service (unstripped)
+ Common library of Smart card service (unstripped)
+
+Package: smartcard-service-server
+Architecture: any
+Depends: smartcard-service-common-dev (= ${binary:Version})
+Description: Main process of Smart card service
+ Main process of Smart card service
+
+Package: smartcard-service-server-dbg
+Section: debug
+Architecture: any
+Depends: smartcard-service-server (= ${binary:Version})
+Description: Main process of Smart card service (unstripped)
+ Main process of Smart card service (unstripped)
+
+Package: smartcard-service
+Section: libs
+Architecture: any
+Depends: smartcard-service-common-dev (= ${binary:Version})
+Description: User library of Smart card service 
+ User library of Smart card service
+
+Package: smartcard-service-dev
+Section: libdevel
+Architecture: any
+Depends: smartcard-service (= ${binary:Version})
+Description: User library of Smart card service
+ User library of Smart card service
+
+Package: smartcard-service-dbg
+Section: debug
+Architecture: any
+Depends: smartcard-service (= ${binary:Version})
+Description: User library of Smart card service (unstripped)
+ User library of Smart card service (unstripped)
diff --git a/debian/rules b/debian/rules
new file mode 100755 (executable)
index 0000000..d6ef688
--- /dev/null
@@ -0,0 +1,33 @@
+#!/usr/bin/make -f
+# -*- makefile -*-
+# Sample debian/rules that uses debhelper.
+# This file was originally written by Joey Hess and Craig Small.
+# As a special exception, when this file is copied by dh-make into a
+# dh-make output file, you may use that output file without restriction.
+# This special exception was added by Craig Small in version 0.37 of dh-make.
+
+# Uncomment this to turn on verbose mode.
+#export DH_VERBOSE=1
+
+override_dh_auto_build:
+
+       cd $(CMAKE_BINARY_DIR)
+       dh_auto_build
+
+override_dh_install:
+       
+       mkdir -p $(CURDIR)/debian/tmp/etc/init.d
+       mkdir -p $(CURDIR)/debian/tmp/etc/rc.d/rc3.d/
+       mkdir -p $(CURDIR)/debian/tmp/etc/rc.d/rc5.d/
+       
+       cp -af $(CURDIR)/debian/smartcard-service-server.init $(CURDIR)/debian/tmp/etc/init.d/smartcard-service-server
+       ln -s ../init.d/smartcard-service-server $(CURDIR)/debian/tmp/etc/rc.d/rc3.d/S79smartcard-service-server
+       ln -s ../init.d/smartcard-service-server $(CURDIR)/debian/tmp/etc/rc.d/rc5.d/S79smartcard-service-server
+       
+       dh_install
+       
+override_dh_installinit:
+
+%:
+       dh $@ 
+
diff --git a/debian/smartcard-service-common-dev.dirs b/debian/smartcard-service-common-dev.dirs
new file mode 100644 (file)
index 0000000..4418816
--- /dev/null
@@ -0,0 +1,2 @@
+usr/lib
+usr/include
diff --git a/debian/smartcard-service-common-dev.install b/debian/smartcard-service-common-dev.install
new file mode 100644 (file)
index 0000000..2d332a5
--- /dev/null
@@ -0,0 +1,5 @@
+usr/include/smartcard-service-common/*
+#usr/lib/lib*.a
+usr/lib/libsmartcard-service-common.so
+usr/lib/pkgconfig/smartcard-service-common.pc
+#usr/share/pkgconfig/*
diff --git a/debian/smartcard-service-common.dirs b/debian/smartcard-service-common.dirs
new file mode 100644 (file)
index 0000000..6845771
--- /dev/null
@@ -0,0 +1 @@
+usr/lib
diff --git a/debian/smartcard-service-common.install b/debian/smartcard-service-common.install
new file mode 100644 (file)
index 0000000..3b87046
--- /dev/null
@@ -0,0 +1 @@
+usr/lib/libsmartcard-service-common.so.*
diff --git a/debian/smartcard-service-dev.dirs b/debian/smartcard-service-dev.dirs
new file mode 100644 (file)
index 0000000..4418816
--- /dev/null
@@ -0,0 +1,2 @@
+usr/lib
+usr/include
diff --git a/debian/smartcard-service-dev.install b/debian/smartcard-service-dev.install
new file mode 100644 (file)
index 0000000..a547e24
--- /dev/null
@@ -0,0 +1,5 @@
+usr/include/smartcard-service/*
+#usr/lib/lib*.a
+usr/lib/libsmartcard-service.so
+usr/lib/pkgconfig/smartcard-service.pc
+#usr/share/pkgconfig/*
diff --git a/debian/smartcard-service-server.dirs b/debian/smartcard-service-server.dirs
new file mode 100644 (file)
index 0000000..2d445a0
--- /dev/null
@@ -0,0 +1,2 @@
+usr/bin
+etc
\ No newline at end of file
diff --git a/debian/smartcard-service-server.init b/debian/smartcard-service-server.init
new file mode 100755 (executable)
index 0000000..ffc409b
--- /dev/null
@@ -0,0 +1,28 @@
+#!/bin/sh
+### BEGIN INIT INFO
+# Provides:          smartcard-service-server
+# Required-Start:    $network $local_fs
+# Required-Stop:
+# Default-Start:     2 3 4 5
+# Default-Stop:      0 1 6
+# Short-Description: <Enter a short description of the sortware>
+# Description:       <Enter a long description of the software>
+#                    <...>
+#                    <...>
+### END INIT INFO
+
+# Author: Wonkyu Kwon <wonkyu.kwon@samsung.com>
+
+# PATH should only include /usr/* if it runs after the mountnfs.sh script
+PATH=/usr/bin
+DESC=smartcard-daemon      # Introduce a short description here
+NAME=smartcard-daemon      # Introduce the short server's name here
+DAEMON=/usr/bin/smartcard-daemon # Introduce the server's location here
+DAEMON_ARGS=""             # Arguments to run the daemon with
+PIDFILE=/var/run/$NAME.pid
+SCRIPTNAME=/etc/init.d/$NAME
+
+# Exit if the package is not installed
+[ -x $DAEMON ] || exit 0
+
+$DAEMON $DAEMON_ARGS &
\ No newline at end of file
diff --git a/debian/smartcard-service-server.install b/debian/smartcard-service-server.install
new file mode 100644 (file)
index 0000000..8a71c41
--- /dev/null
@@ -0,0 +1,2 @@
+usr/bin/smartcard-daemon
+etc/*
\ No newline at end of file
diff --git a/debian/smartcard-service.dirs b/debian/smartcard-service.dirs
new file mode 100644 (file)
index 0000000..6845771
--- /dev/null
@@ -0,0 +1 @@
+usr/lib
diff --git a/debian/smartcard-service.install b/debian/smartcard-service.install
new file mode 100644 (file)
index 0000000..05b76e3
--- /dev/null
@@ -0,0 +1 @@
+usr/lib/libsmartcard-service.so.*
index cb579db..2af01c9 100644 (file)
@@ -1,69 +1,83 @@
+# FOR COMMENTING DEFINITION, MUST USE %% instead of %
+%global use_autostart "-DUSE_AUTOSTART=1"
+%global use_gdbus "-DUSE_GDBUS=1"
+#%%global test_client "-DTEST_CLIENT=1"
+
 Name:       smartcard-service
 Summary:    Smartcard Service FW
-Version:    0.1.19
-Release:    1
+Version:    0.1.22
+Release:    0
 Group:      libs
 License:    Apache-2.0
 Source0:    %{name}-%{version}.tar.gz
-#Source1:    smartcard-service-server.init
-Source1001:    %{name}.manifest
-Source1002:    %{name}-devel.manifest
-Source1003:    smartcard-service-common.manifest
-Source1004:    smartcard-service-common-devel.manifest
-Source1005:    smartcard-service-server.manifest
-
+%if 0%{!?use_autostart:1}
+Source1:    smartcard-service-server.init
+%endif
+BuildRequires: cmake
 BuildRequires: pkgconfig(glib-2.0)
+BuildRequires: pkgconfig(gio-unix-2.0)
 BuildRequires: pkgconfig(security-server)
 BuildRequires: pkgconfig(dlog)
-BuildRequires: pkgconfig(vconf)
 BuildRequires: pkgconfig(aul)
 BuildRequires: pkgconfig(libssl)
-BuildRequires: pkgconfig(dbus-glib-1)
 BuildRequires: pkgconfig(pkgmgr)
 BuildRequires: pkgconfig(pkgmgr-info)
-BuildRequires: cmake
-BuildRequires: gettext-tools
+%if 0%{!?use_gdbus:1}
+BuildRequires: pkgconfig(dbus-glib-1)
+%endif
+# for gdbus
+%if 0%{?use_gdbus:1}
+BuildRequires: python
+BuildRequires: python-xml
+%endif
 
 Requires(post):   /sbin/ldconfig
-Requires(post):   /usr/bin/vconftool
-requires(postun): /sbin/ldconfig
+Requires(postun): /sbin/ldconfig
+Requires:         smartcard-service-common = %{version}-%{release}
+
 
 %description
 Smartcard Service FW.
 
+
 %prep
 %setup -q
-cp %{SOURCE1001} %{SOURCE1002} %{SOURCE1003} %{SOURCE1004} %{SOURCE1005} .
+
 
 %package    devel
-Summary:    Smartcard service
+Summary:    smartcard service
 Group:      Development/Libraries
 Requires:   %{name} = %{version}-%{release}
 
+
 %description devel
 smartcard service.
 
+
 %package -n smartcard-service-common
-Summary:    Common smartcard service
+Summary:    common smartcard service
 Group:      Development/Libraries
-Requires:   %{name} = %{version}-%{release}
+
 
 %description -n smartcard-service-common
 common smartcard service.
 
+
 %package -n smartcard-service-common-devel
-Summary:    Common smartcard service
+Summary:    common smartcard service
 Group:      Development/Libraries
-Requires:   %{name} = %{version}-%{release}
 Requires:   smartcard-service-common = %{version}-%{release}
 
+
 %description -n smartcard-service-common-devel
 common smartcard service.
 
+
 %package -n smartcard-service-server
-Summary:    Server smartcard service
+Summary:    server smartcard service
 Group:      Development/Libraries
-Requires:   %{name} = %{version}-%{release}
+Requires:   smartcard-service-common = %{version}-%{release}
+
 
 %description -n smartcard-service-server
 smartcard service.
@@ -72,49 +86,63 @@ smartcard service.
 %build
 mkdir obj-arm-limux-qnueabi
 cd obj-arm-limux-qnueabi
-%cmake .. -DUSE_AUTOSTART=1 # daemon will be started when client makes instance by DBUS
+%cmake .. -DCMAKE_INSTALL_PREFIX=%{_prefix} %{?use_autostart} %{?use_gdbus} %{?test_client}
+#make %{?jobs:-j%jobs}
+
 
 %install
 cd obj-arm-limux-qnueabi
 %make_install
-%__mkdir -p  %{buildroot}/etc/init.d/
-%__mkdir -p  %{buildroot}/etc/rc.d/rc3.d/
-%__mkdir -p  %{buildroot}/etc/rc.d/rc5.d/
+%if 0%{!?use_autostart:1}
+       %__mkdir -p  %{buildroot}/etc/init.d/
+       %__mkdir -p  %{buildroot}/etc/rc.d/rc3.d/
+       %__mkdir -p  %{buildroot}/etc/rc.d/rc5.d/
+       %__cp -af %SOURCE1 %{buildroot}/etc/init.d/smartcard-service-server
+       chmod 755 %{buildroot}/etc/init.d/smartcard-service-server
+%endif
+mkdir -p %{buildroot}/usr/share/license
+cp -af %{_builddir}/%{name}-%{version}/packaging/%{name} %{buildroot}/usr/share/license/
+cp -af %{_builddir}/%{name}-%{version}/packaging/smartcard-service-common %{buildroot}/usr/share/license/
+cp -af %{_builddir}/%{name}-%{version}/packaging/smartcard-service-server %{buildroot}/usr/share/license/
 
-%post
-/sbin/ldconfig
-ln -sf /etc/init.d/smartcard-service-server /etc/rc.d/rc3.d/S79smartcard-service-server
-ln -sf /etc/init.d/smartcard-service-server /etc/rc.d/rc5.d/S79smartcard-service-server
 
-%postun
+%post
 /sbin/ldconfig
-rm -f /etc/rc.d/rc3.d/S79smartcard-service-server
-rm -f /etc/rc.d/rc5.d/S79smartcard-service-server
+%if 0%{!?use_autostart:1}
+       ln -sf /etc/init.d/smartcard-service-server /etc/rc.d/rc3.d/S79smartcard-service-server
+       ln -sf /etc/init.d/smartcard-service-server /etc/rc.d/rc5.d/S79smartcard-service-server
+%endif
 
 
-%post -n smartcard-service-common
-/sbin/ldconfig
-
-%postun -n smartcard-service-common
+%postun
 /sbin/ldconfig
+%if 0%{!?use_autostart:1}
+       rm -f /etc/rc.d/rc3.d/S79smartcard-service-server
+       rm -f /etc/rc.d/rc5.d/S79smartcard-service-server
+%endif
 
 
 %files
 %manifest %{name}.manifest
 %defattr(-,root,root,-)
 %{_libdir}/libsmartcard-service.so.*
+%{_datadir}/license/%{name}
+
 
 %files  devel
-%manifest %{name}-devel.manifest
+%manifest smartcard-service-devel.manifest
 %defattr(-,root,root,-)
-%{_includedir}/smartcard-service/*
+%{_includedir}/%{name}/*
 %{_libdir}/libsmartcard-service.so
-%{_libdir}/pkgconfig/smartcard-service.pc
+%{_libdir}/pkgconfig/%{name}.pc
+
 
 %files -n smartcard-service-common
 %manifest smartcard-service-common.manifest
 %defattr(-,root,root,-)
 %{_libdir}/libsmartcard-service-common.so.*
+%{_datadir}/license/smartcard-service-common
+
 
 %files -n smartcard-service-common-devel
 %manifest smartcard-service-common-devel.manifest
@@ -123,9 +151,18 @@ rm -f /etc/rc.d/rc5.d/S79smartcard-service-server
 %{_libdir}/libsmartcard-service-common.so
 %{_libdir}/pkgconfig/smartcard-service-common.pc
 
+
 %files -n smartcard-service-server
 %manifest smartcard-service-server.manifest
 %defattr(-,root,root,-)
 %{_bindir}/smartcard-daemon
-/usr/share/dbus-1/services/org.tizen.smartcard_service.service
-
+%{_datadir}/packages/smartcard-service-server.xml
+%if 0%{?test_client:1}
+       %{_bindir}/smartcard-test-client
+%endif
+%if 0%{?use_autostart:1}
+       %{_datadir}/dbus-1/services/org.tizen.smartcard_service.service
+%else
+       %{_sysconfdir}/init.d/smartcard-service-server
+%endif
+%{_datadir}/license/smartcard-service-server
index 8f9d778..9d3be5d 100644 (file)
@@ -1,17 +1,28 @@
 CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
 PROJECT(smartcard-daemon CXX)
 
+include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../common)
 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../common/include)
 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
 
 AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/ SRCS)
+IF(DEFINED USE_GDBUS)
+       AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/private SRCS)
+ENDIF()
 
 IF("${CMAKE_BUILD_TYPE}" STREQUAL "")
        SET(CMAKE_BUILD_TYPE "Release")
 ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "")
 
+# pkg config
 INCLUDE(FindPkgConfig)
-pkg_check_modules(pkgs_server REQUIRED glib-2.0 gobject-2.0 security-server vconf dlog dbus-glib-1)
+
+SET(PKG_MODULE glib-2.0 gio-2.0 gio-unix-2.0 security-server dlog)
+IF(NOT DEFINED USE_GDBUS)
+       SET(PKG_MODULE ${PKG_MODULE} dbus-glib-1)
+ENDIF()
+
+pkg_check_modules(pkgs_server REQUIRED ${PKG_MODULE})
 
 FOREACH(flag ${pkgs_server_CFLAGS})
        SET(EXTRA_CXXFLAGS "${EXTRA_CXXFLAGS} ${flag}")
@@ -20,22 +31,16 @@ ENDFOREACH(flag)
 
 MESSAGE("CHECK MODULE in ${PROJECT_NAME} ${pkgs_server_LDFLAGS}")
 
-IF("${USE_AUTOSTART}" STREQUAL "1")
-       FIND_PROGRAM(DBUS_BINDING_TOOL NAMES dbus-binding-tool)
-       EXEC_PROGRAM("${DBUS_BINDING_TOOL}" ARGS "--prefix=smartcard_service ${CMAKE_CURRENT_SOURCE_DIR}/smartcard-service.xml --mode=glib-server --output=${CMAKE_CURRENT_SOURCE_DIR}/include/smartcard-service-binding.h")
-       EXEC_PROGRAM("${DBUS_BINDING_TOOL}" ARGS "--prefix=smartcard_service ${CMAKE_CURRENT_SOURCE_DIR}/smartcard-service.xml --mode=glib-client --output=${CMAKE_CURRENT_SOURCE_DIR}/include/smartcard-service-glue.h")
-ENDIF()
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -pipe -fomit-frame-pointer -Wall -Wno-trigraphs  -fno-strict-aliasing -Wl,-zdefs -fvisibility=hidden")
+SET(ARM_CFLAGS "${ARM_CLAGS} -mapcs -mno-sched-prolog -mabi=aapcs-linux -Uarm -fno-common -fpic")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
 
 SET(EXTRA_CXXFLAGS "${EXTRA_CXXFLAGS} -pipe -fomit-frame-pointer -Wall -Wno-trigraphs  -fno-strict-aliasing -Wl,-zdefs -fvisibility=hidden -std=c++0x")
 SET(ARM_CXXFLAGS "${ARM_CXXLAGS} -mapcs -mno-sched-prolog -mabi=aapcs-linux -Uarm -fno-common -fpic")
 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CXXFLAGS}")
 SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")
 
-SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -pipe -fomit-frame-pointer -Wall -Wno-trigraphs  -fno-strict-aliasing -Wl,-zdefs -fvisibility=hidden")
-SET(ARM_CFLAGS "${ARM_CLAGS} -mapcs -mno-sched-prolog -mabi=aapcs-linux -Uarm -fno-common -fpic")
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
-SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
-
 FIND_PROGRAM(UNAME NAMES uname)
 EXEC_PROGRAM("${UNAME}" ARGS "-m" OUTPUT_VARIABLE "ARCH")
 IF("${ARCH}" MATCHES "^arm.*")
@@ -47,15 +52,15 @@ ENDIF()
 
 ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"")
 ADD_DEFINITIONS("-DLOG_TAG=\"SMARTCARD_SERVICE_SERVER\"")
-ADD_DEFINITIONS("-DLIBPATH=\"${CMAKE_INSTALL_LIB}\"")
 
 SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed")
 
 ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS})
 
-TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_server_LDFLAGS} "-L../common" "-lsmartcard-service-common" "-ldl")
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_server_LDFLAGS} "-L../common" "-lsmartcard-service-common" "-pie -ldl")
 
 INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin)
 IF("${USE_AUTOSTART}" STREQUAL "1")
        INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/org.tizen.smartcard_service.service DESTINATION share/dbus-1/services)
 ENDIF()
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/smartcard-service-server.xml DESTINATION share/packages)
index 667608b..d2dfcb9 100644 (file)
 
 namespace smartcard_service_api
 {
-       gboolean ClientInstance::_getCertificationHashes(gpointer user_data)
-       {
-               gboolean result = false;
-               ClientInstance *instance = (ClientInstance *)user_data;
-
-               SignatureHelper::getCertificationHashes(instance->getPID(), instance->certHashes);
-
-               return result;
-       }
-
-       void ClientInstance::setPID(int pid)
-       {
-               this->pid = pid;
-
-       }
-
-       ServiceInstance *ClientInstance::createService(unsigned int context)
+       ServiceInstance *ClientInstance::createService()
        {
                ServiceInstance *result = NULL;
 
-               if ((result = getService(context)) == NULL)
+               result = new ServiceInstance(this);
+               if (result != NULL)
                {
-                       result = new ServiceInstance(this, context);
-                       if (result != NULL)
-                       {
-                               mapServices.insert(make_pair(context, result));
-                       }
-                       else
-                       {
-                               SCARD_DEBUG_ERR("alloc failed");
-                       }
+                       mapServices.insert(make_pair(result->getHandle(), result));
                }
                else
                {
-                       SCARD_DEBUG_ERR("service already exist [%d]", context);
+                       _ERR("alloc failed");
                }
 
                return result;
        }
 
-       ServiceInstance *ClientInstance::getService(unsigned int context)
+       ServiceInstance *ClientInstance::getService(unsigned int handle)
        {
                ServiceInstance *result = NULL;
                map<unsigned int, ServiceInstance *>::iterator item;
 
-               if ((item = mapServices.find(context)) != mapServices.end())
+               if ((item = mapServices.find(handle)) != mapServices.end())
                {
                        result = item->second;
                }
@@ -80,11 +57,11 @@ namespace smartcard_service_api
                return result;
        }
 
-       void ClientInstance::removeService(unsigned int context)
+       void ClientInstance::removeService(unsigned int handle)
        {
                map<unsigned int, ServiceInstance *>::iterator item;
 
-               if ((item = mapServices.find(context)) != mapServices.end())
+               if ((item = mapServices.find(handle)) != mapServices.end())
                {
                        delete item->second;
                        mapServices.erase(item);
@@ -103,22 +80,24 @@ namespace smartcard_service_api
                mapServices.clear();
        }
 
-       bool ClientInstance::sendMessageToAllServices(int socket, Message &msg)
+#ifndef USE_GDBUS
+       bool ClientInstance::sendMessageToAllServices(int socket, const Message &msg)
        {
                bool result = true;
-               map<unsigned int, ServiceInstance *>::iterator item;
+               map<unsigned int, ServiceInstance *>::const_iterator item;
 
                for (item = mapServices.begin(); item != mapServices.end(); item++)
                {
-                       if (ServerIPC::getInstance()->sendMessage(socket, &msg) == false)
+                       if (ServerIPC::getInstance()->sendMessage(socket, msg) == false)
                                result = false;
                }
 
                return result;
        }
+#endif
 
        void ClientInstance::generateCertificationHashes()
        {
-               g_idle_add(_getCertificationHashes, (gpointer)this);
+               SignatureHelper::getCertificationHashes(getPID(), certHashes);
        }
 } /* namespace smartcard_service_api */
index d0f880a..a77406d 100644 (file)
 namespace smartcard_service_api
 {
        ServerChannel::ServerChannel(ServerSession *session, void *caller,
-               int channelNum, Terminal *terminal)
-               : Channel(session)
+               int channelNum, Terminal *terminal) :
+               Channel(session), terminal(terminal), caller(caller),
+               privilege(true)
        {
-               this->terminal = terminal;
-               this->caller = caller;
                this->channelNum = channelNum;
-               this->privilege = true;
        }
 
        ServerChannel::~ServerChannel()
@@ -50,39 +48,40 @@ namespace smartcard_service_api
                APDUHelper apdu;
                int rv;
 
-               if (isBasicChannel() == false)
+               if (isClosed() == false && isBasicChannel() == false)
                {
                        /* close channel */
                        command = apdu.generateAPDU(APDUHelper::COMMAND_CLOSE_LOGICAL_CHANNEL, channelNum, ByteArray::EMPTY);
                        rv = terminal->transmitSync(command, result);
 
-                       if (rv == 0 && result.getLength() >= 2)
+                       if (rv == 0 && result.size() >= 2)
                        {
                                ResponseHelper resp(result);
 
-                               if (resp.getStatus() == 0)
+                               if (resp.getStatus() >= 0)
                                {
-                                       SCARD_DEBUG("close success");
+                                       _DBG("close success");
                                }
                                else
                                {
-                                       SCARD_DEBUG_ERR("status word [%d][ %02X %02X ]", resp.getStatus(), resp.getSW1(), resp.getSW2());
+                                       _ERR("status word [ %02X %02X ]", resp.getSW1(), resp.getSW2());
                                }
                        }
                        else
                        {
-                               SCARD_DEBUG_ERR("select apdu is failed, rv [%d], length [%d]", rv, result.getLength());
+                               _ERR("select apdu is failed, rv [%d], length [%d]", rv, result.size());
                        }
-               }
 
-               channelNum = -1;
+                       channelNum = -1;
+               }
        }
 
-       int ServerChannel::transmitSync(ByteArray command, ByteArray &result)
+       int ServerChannel::transmitSync(const ByteArray &command, ByteArray &result)
                throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &)
        {
                int ret = -1;
                APDUCommand helper;
+               ByteArray cmd;
 
                if (isClosed() == true)
                {
@@ -98,24 +97,17 @@ namespace smartcard_service_api
                                helper.getP1() == APDUCommand::P1_SELECT_BY_DF_NAME) ||
                                (helper.getINS() == APDUCommand::INS_MANAGE_CHANNEL))
                        {
-                               return -4; /* security reason */
+                               return SCARD_ERROR_SECURITY_NOT_ALLOWED;
                        }
                }
 
                /* TODO : insert channel ID using atr information */
                helper.setChannel(APDUCommand::CLA_CHANNEL_STANDARD, channelNum);
+               helper.getBuffer(cmd);
 
-               helper.getBuffer(command);
-
-               SCARD_DEBUG("command [%d] : %s", command.getLength(), command.toString());
+               _DBG("command [%d] : %s", cmd.size(), cmd.toString().c_str());
 
-               ret = terminal->transmitSync(command, result);
-               if (ret == 0 && ResponseHelper::getStatus(result) == 0)
-               {
-                       /* store select response */
-                       if (helper.getINS() == APDUCommand::INS_SELECT_FILE)
-                               setSelectResponse(result);
-               }
+               ret = terminal->transmitSync(cmd, result);
 
                return ret;
        }
index c45e66c..bd49ad4 100644 (file)
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 
+#ifndef USE_GDBUS
 /* standard library header */
 #include <stdio.h>
 #include <string.h>
@@ -24,6 +25,7 @@
 #include "Debug.h"
 #include "Exception.h"
 #include "ServerDispatcher.h"
+#include "ServerIPC.h"
 #include "ServerResource.h"
 #include "ServerSEService.h"
 #include "ServerChannel.h"
@@ -34,11 +36,11 @@ namespace smartcard_service_api
 {
        ServerDispatcher::ServerDispatcher():DispatcherHelper()
        {
-               SCARD_BEGIN();
+               _BEGIN();
 
                runDispatcherThread();
 
-               SCARD_END();
+               _END();
        }
 
        ServerDispatcher::~ServerDispatcher()
@@ -59,13 +61,13 @@ namespace smartcard_service_api
 
                if (data == NULL)
                {
-                       SCARD_DEBUG_ERR("dispatcher instance is null");
+                       _ERR("dispatcher instance is null");
                        return NULL;
                }
 
                if (msg == NULL)
                {
-                       SCARD_DEBUG_ERR("message is null");
+                       _ERR("message is null");
                        return NULL;
                }
 
@@ -77,12 +79,13 @@ namespace smartcard_service_api
                /* handle message */
                case Message::MSG_REQUEST_READERS :
                        {
-                               SCARD_DEBUG("[MSG_REQUEST_READERS]");
+                               _INFO("[MSG_REQUEST_READERS]");
 
                                int count = 0;
                                Message response(*msg);
                                ByteArray info;
                                ClientInstance *instance = NULL;
+                               ServiceInstance *service = NULL;
 
                                response.param1 = 0;
                                response.param2 = 0;
@@ -96,16 +99,17 @@ namespace smartcard_service_api
                                        if (instance->getPID() == -1)
                                        {
                                                instance->setPID(msg->error);
-                                               SCARD_DEBUG_ERR("update PID [%d]", msg->error);
+                                               _INFO("update PID [%d]", msg->error);
 
                                                /* generate certification hashes */
                                                instance->generateCertificationHashes();
                                        }
 
                                        /* create service */
-                                       if (resource->createService(socket, (unsigned long)msg->userParam) != NULL)
+                                       if ((service = resource->createService(socket)) != NULL)
                                        {
                                                response.error = SCARD_ERROR_OK;
+                                               response.param2 = service->getHandle();
 
                                                if ((count = resource->getReadersInformation(info)) > 0)
                                                {
@@ -114,25 +118,25 @@ namespace smartcard_service_api
                                                }
                                                else
                                                {
-                                                       SCARD_DEBUG("no secure elements");
+                                                       _INFO("no secure elements");
                                                }
                                        }
                                        else
                                        {
-                                               SCARD_DEBUG_ERR("createClient failed");
+                                               _ERR("createClient failed");
 
                                                response.error = SCARD_ERROR_UNAVAILABLE;
                                        }
                                }
                                else
                                {
-                                       SCARD_DEBUG("client doesn't exist, socket [%d]", socket);
+                                       _ERR("client doesn't exist, socket [%d]", socket);
 
                                        response.error = SCARD_ERROR_UNAVAILABLE;
                                }
 
                                /* response to client */
-                               ServerIPC::getInstance()->sendMessage(socket, &response);
+                               ServerIPC::getInstance()->sendMessage(socket, response);
                        }
                        break;
 
@@ -140,14 +144,14 @@ namespace smartcard_service_api
                        {
                                Message response(*msg);
 
-                               SCARD_DEBUG("[MSG_REQUEST_SHUTDOWN]");
+                               _INFO("[MSG_REQUEST_SHUTDOWN]");
 
                                response.error = SCARD_ERROR_OK;
 
-                               resource->removeService(socket, msg->error/* service context */);
+                               resource->removeService(socket, msg->param1);
 
                                /* response to client */
-                               ServerIPC::getInstance()->sendMessage(socket, &response);
+                               ServerIPC::getInstance()->sendMessage(socket, response);
                        }
                        break;
 
@@ -156,7 +160,7 @@ namespace smartcard_service_api
                                Message response(*msg);
                                unsigned int handle = IntegerHandle::INVALID_HANDLE;
 
-                               SCARD_DEBUG("[MSG_REQUEST_OPEN_SESSION]");
+                               _INFO("[MSG_REQUEST_OPEN_SESSION]");
 
                                if (resource->isValidReaderHandle(msg->param1))
                                {
@@ -169,20 +173,20 @@ namespace smartcard_service_api
                                        }
                                        else
                                        {
-                                               SCARD_DEBUG_ERR("createSession failed [%d]", handle);
+                                               _ERR("createSession failed [%d]", handle);
                                                response.error = SCARD_ERROR_OUT_OF_MEMORY;
                                        }
                                }
                                else
                                {
-                                       SCARD_DEBUG_ERR("request invalid reader handle [%d]", msg->param1);
+                                       _ERR("request invalid reader handle [%d]", msg->param1);
                                        response.error = SCARD_ERROR_ILLEGAL_PARAM;
                                }
 
                                response.param1 = handle;
 
                                /* response to client */
-                               ServerIPC::getInstance()->sendMessage(socket, &response);
+                               ServerIPC::getInstance()->sendMessage(socket, response);
                        }
                        break;
 
@@ -190,7 +194,7 @@ namespace smartcard_service_api
                        {
                                Message response(*msg);
 
-                               SCARD_DEBUG("[MSG_REQUEST_CLOSE_SESSION]");
+                               _INFO("[MSG_REQUEST_CLOSE_SESSION]");
 
                                response.param1 = 0;
                                response.error = SCARD_ERROR_OK;
@@ -201,7 +205,7 @@ namespace smartcard_service_api
                                }
 
                                /* response to client */
-                               ServerIPC::getInstance()->sendMessage(socket, &response);
+                               ServerIPC::getInstance()->sendMessage(socket, response);
                        }
                        break;
 
@@ -209,11 +213,11 @@ namespace smartcard_service_api
                        {
                                Message response(*msg);
 
-                               SCARD_DEBUG("[MSG_REQUEST_OPEN_CHANNEL]");
+                               _INFO("[MSG_REQUEST_OPEN_CHANNEL]");
 
                                response.param1 = IntegerHandle::INVALID_HANDLE;
                                response.param2 = 0;
-                               response.data.releaseBuffer();
+                               response.data.clear();
 
                                try
                                {
@@ -234,13 +238,13 @@ namespace smartcard_service_api
                                                }
                                                else
                                                {
-                                                       SCARD_DEBUG_ERR("IS IT POSSIBLE??????????????????");
+                                                       _ERR("IS IT POSSIBLE??????????????????");
                                                        response.error = SCARD_ERROR_UNKNOWN;
                                                }
                                        }
                                        else
                                        {
-                                               SCARD_DEBUG_ERR("channel is null.");
+                                               _ERR("channel is null.");
 
                                                /* set error value */
                                                response.error = SCARD_ERROR_UNAVAILABLE;
@@ -252,7 +256,7 @@ namespace smartcard_service_api
                                }
 
                                /* response to client */
-                               ServerIPC::getInstance()->sendMessage(socket, &response);
+                               ServerIPC::getInstance()->sendMessage(socket, response);
                        }
                        break;
 
@@ -260,13 +264,13 @@ namespace smartcard_service_api
                        {
                                Message response(*msg);
 
-                               SCARD_DEBUG("[MSG_REQUEST_GET_CHANNEL_COUNT]");
+                               _INFO("[MSG_REQUEST_GET_CHANNEL_COUNT]");
 
                                response.error = SCARD_ERROR_OK;
                                response.param1 = resource->getChannelCount(socket, msg->error/* service context */, msg->param1);
 
                                /* response to client */
-                               ServerIPC::getInstance()->sendMessage(socket, &response);
+                               ServerIPC::getInstance()->sendMessage(socket, response);
                        }
                        break;
 
@@ -274,7 +278,7 @@ namespace smartcard_service_api
                        {
                                Message response(*msg);
 
-                               SCARD_DEBUG("[MSG_REQUEST_CLOSE_CHANNEL]");
+                               _INFO("[MSG_REQUEST_CLOSE_CHANNEL]");
 
                                response.error = SCARD_ERROR_OK;
 
@@ -284,7 +288,7 @@ namespace smartcard_service_api
                                }
 
                                /* response to client */
-                               ServerIPC::getInstance()->sendMessage(socket, &response);
+                               ServerIPC::getInstance()->sendMessage(socket, response);
                        }
                        break;
 
@@ -295,7 +299,7 @@ namespace smartcard_service_api
                                ByteArray result;
                                ServiceInstance *client = NULL;
 
-                               SCARD_DEBUG("[MSG_REQUEST_GET_ATR]");
+                               _INFO("[MSG_REQUEST_GET_ATR]");
 
                                if ((client = resource->getService(socket, msg->error/* service context */)) != NULL)
                                {
@@ -310,25 +314,25 @@ namespace smartcard_service_api
                                                }
                                                else
                                                {
-                                                       SCARD_DEBUG_ERR("transmit failed [%d]", rv);
+                                                       _ERR("transmit failed [%d]", rv);
 
                                                        response.error = rv;
                                                }
                                        }
                                        else
                                        {
-                                               SCARD_DEBUG_ERR("getTerminal failed : socket [%d], context [%d], session [%d]", socket, msg->error/* service context */, msg->param1);
+                                               _ERR("getTerminal failed : socket [%d], context [%d], session [%d]", socket, msg->error/* service context */, msg->param1);
                                                response.error = SCARD_ERROR_UNAVAILABLE;
                                        }
                                }
                                else
                                {
-                                       SCARD_DEBUG_ERR("getClient failed : socket [%d], context [%d], session [%d]", socket, msg->error/* service context */, msg->param1);
+                                       _ERR("getClient failed : socket [%d], context [%d], session [%d]", socket, msg->error/* service context */, msg->param1);
                                        response.error = SCARD_ERROR_UNAVAILABLE;
                                }
 
                                /* response to client */
-                               ServerIPC::getInstance()->sendMessage(socket, &response);
+                               ServerIPC::getInstance()->sendMessage(socket, response);
                        }
                        break;
 
@@ -339,7 +343,7 @@ namespace smartcard_service_api
                                ByteArray result;
                                Channel *channel = NULL;
 
-                               SCARD_DEBUG("[MSG_REQUEST_TRANSMIT]");
+                               _INFO("[MSG_REQUEST_TRANSMIT]");
 
                                if ((channel = resource->getChannel(socket, msg->error/* service context */, msg->param1)) != NULL)
                                {
@@ -350,40 +354,40 @@ namespace smartcard_service_api
                                        }
                                        else
                                        {
-                                               SCARD_DEBUG_ERR("transmit failed [%d]", rv);
+                                               _ERR("transmit failed [%d]", rv);
 
                                                response.error = rv;
                                        }
                                }
                                else
                                {
-                                       SCARD_DEBUG_ERR("invalid handle : socket [%d], context [%d], channel [%d]", socket, msg->error/* service context */, msg->param1);
+                                       _ERR("invalid handle : socket [%d], context [%d], channel [%d]", socket, msg->error/* service context */, msg->param1);
                                        response.error = SCARD_ERROR_UNAVAILABLE;
                                }
 
                                /* response to client */
-                               ServerIPC::getInstance()->sendMessage(socket, &response);
+                               ServerIPC::getInstance()->sendMessage(socket, response);
                        }
                        break;
 
                case Message::MSG_OPERATION_RELEASE_CLIENT :
                        {
-                               SCARD_DEBUG("[MSG_OPERATION_RELEASE_CLIENT]");
+                               _INFO("[MSG_OPERATION_RELEASE_CLIENT]");
 
                                resource->removeClient(msg->param1);
-                               SCARD_DEBUG("remain client [%d]", resource->getClientCount());
+                               _DBG("remain client [%d]", resource->getClientCount());
                        }
 #ifdef USE_AUTOSTART
                        if (resource->getClientCount() == 0)
                        {
-                               SCARD_DEBUG("There is no client. shutting down service");
+                               _INFO("There is no client. shutting down service");
                                g_main_loop_quit((GMainLoop *)resource->getMainLoopInstance());
                        }
 #endif
                        break;
 
                default :
-                       SCARD_DEBUG("unknown message [%s], socket [%d]", msg->toString(), socket);
+                       _DBG("unknown message [%s], socket [%d]", msg->toString().c_str(), socket);
                        break;
                }
 
@@ -391,3 +395,4 @@ namespace smartcard_service_api
        }
 
 } /* namespace smartcard_service_api */
+#endif
diff --git a/server/ServerGDBus.cpp b/server/ServerGDBus.cpp
new file mode 100644 (file)
index 0000000..1f60e1e
--- /dev/null
@@ -0,0 +1,1379 @@
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifdef USE_GDBUS
+/* standard library header */
+#include <unistd.h>
+#include <glib.h>
+#include <gio/gio.h>
+#include <vector>
+#include <string>
+#include <sys/socket.h>
+
+/* SLP library header */
+#ifdef USER_SPACE_SMACK
+#include "security-server.h"
+#endif
+
+/* local header */
+#include "smartcard-types.h"
+#include "Debug.h"
+#include "ByteArray.h"
+#include "ServerResource.h"
+#include "GDBusHelper.h"
+#include "ServerGDBus.h"
+
+using namespace std;
+
+namespace smartcard_service_api
+{
+       GDBusDispatcher::GDBusDispatcher() : Synchronous()
+       {
+       }
+
+       GDBusDispatcher::~GDBusDispatcher()
+       {
+       }
+
+       GDBusDispatcher &GDBusDispatcher::getInstance()
+       {
+               static GDBusDispatcher dispatcher;
+
+               return dispatcher;
+       }
+
+       void GDBusDispatcher::_push(dispatcher_cb_t cb,
+               const vector<void *> &params)
+       {
+               syncLock();
+
+               q.push(make_pair(cb, params));
+               _INFO("request pushed, count [%d]", q.size());
+
+               if (q.size() == 1) {
+                       /* start dispatch */
+                       _INFO("start dispatcher");
+                       g_idle_add(&GDBusDispatcher::dispatch, this);
+               }
+
+               syncUnlock();
+       }
+
+       void GDBusDispatcher::push(dispatcher_cb_t cb,
+               const vector<void *> &params)
+       {
+               GDBusDispatcher::getInstance()._push(cb, params);
+       }
+
+       gboolean GDBusDispatcher::dispatch(gpointer user_data)
+       {
+               GDBusDispatcher *dispatcher = (GDBusDispatcher *)user_data;
+               gboolean result = false;
+
+               _BEGIN();
+
+               dispatcher->syncLock();
+
+               pair<dispatcher_cb_t, vector<void *> > &job =
+                       dispatcher->q.front();
+
+               dispatcher->syncUnlock();
+
+               job.first(job.second);
+
+               dispatcher->syncLock();
+
+               dispatcher->q.pop();
+               if (dispatcher->q.size() > 0) {
+                       _INFO("remaining messages : %d", dispatcher->q.size());
+
+                       result = true;
+               } else {
+                       _INFO("dispatch finished");
+               }
+
+               dispatcher->syncUnlock();
+
+               _END();
+
+               return result;
+       }
+
+       ServerGDBus::ServerGDBus() : dbus_proxy(NULL), connection(NULL),
+               seService(NULL), reader(NULL), session(NULL), channel(NULL)
+       {
+       }
+
+       ServerGDBus::~ServerGDBus()
+       {
+               deinit();
+       }
+
+       ServerGDBus &ServerGDBus::getInstance()
+       {
+               static ServerGDBus serverGDBus;
+
+               return serverGDBus;
+       }
+
+       static void name_owner_changed(GDBusProxy *proxy,
+               const gchar *name, const gchar *old_owner,
+               const gchar *new_owner, void *user_data)
+       {
+               if (name == NULL || old_owner == NULL || new_owner == NULL) {
+                       _ERR("invalid parameter");
+                       return;
+               }
+
+               if (strlen(new_owner) == 0) {
+                       ClientInstance *client;
+
+                       ServerResource &resource = ServerResource::getInstance();
+
+                       client = resource.getClient(old_owner);
+                       if (client != NULL) {
+                               _INFO("terminated client, pid [%d]", client->getPID());
+                               resource.removeClient(old_owner);
+
+                               resource.finish();
+                       }
+               }
+       }
+
+       static void _on_name_owner_changed(GDBusConnection *connection,
+               const gchar *sender_name, const gchar *object_path,
+               const gchar *interface_name, const gchar *signal_name,
+               GVariant *parameters, gpointer user_data)
+       {
+               GVariantIter *iter;
+               gchar *name;
+               gchar *old_owner;
+               gchar *new_owner;
+
+               iter = g_variant_iter_new(parameters);
+
+               g_variant_iter_next(iter, "s", &name);
+               g_variant_iter_next(iter, "s", &old_owner);
+               g_variant_iter_next(iter, "s", &new_owner);
+
+               name_owner_changed((GDBusProxy *)connection,
+                       name, old_owner, new_owner, user_data);
+       }
+
+       bool ServerGDBus::_init()
+       {
+               GError *error = NULL;
+
+               /* init default context */
+               dbus_proxy = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM,
+                       G_DBUS_PROXY_FLAGS_NONE,
+                       NULL, /* GDBusInterfaceInfo */
+                       "org.freedesktop.DBus",
+                       "/org/freedesktop/DBus",
+                       "org.freedesktop.DBus",
+                       NULL, /* GCancellable */
+                       &error);
+               if (dbus_proxy == NULL)
+               {
+                       _ERR("Can not create proxy : %s", error->message);
+                       g_error_free(error);
+
+                       return false;
+               }
+
+               /* subscribe signal */
+               g_dbus_connection_signal_subscribe(connection,
+                       "org.freedesktop.DBus", /* bus name */
+                       "org.freedesktop.DBus", /* interface */
+                       "NameOwnerChanged", /* member */
+                       "/org/freedesktop/DBus", /* path */
+                       NULL, /* arg0 */
+                       G_DBUS_SIGNAL_FLAGS_NONE,
+                       _on_name_owner_changed,
+                       NULL, NULL);
+
+               return true;
+       }
+
+       void ServerGDBus::_deinit()
+       {
+               if (dbus_proxy != NULL) {
+                       g_object_unref(dbus_proxy);
+                       dbus_proxy = NULL;
+               }
+       }
+
+       bool ServerGDBus::init()
+       {
+               GError *error = NULL;
+
+               connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
+               if (connection != NULL) {
+               } else {
+                       _ERR("Can not get connection %s", error->message);
+                       g_error_free(error);
+
+                       return false;
+               }
+
+               _init();
+
+               initSEService();
+               initReader();
+               initSession();
+               initChannel();
+
+               return true;
+       }
+
+       void ServerGDBus::deinit()
+       {
+               deinitChannel();
+               deinitSession();
+               deinitReader();
+               deinitSEService();
+
+               _deinit();
+
+               if (connection != NULL) {
+                       g_object_unref(connection);
+                       connection = NULL;
+               }
+       }
+
+       static gboolean _call_get_connection_unix_process_id_sync(
+               GDBusProxy *proxy, const gchar *arg_name, guint *out_pid,
+               GCancellable *cancellable, GError **error) {
+               GVariant *_ret;
+
+               _ret = g_dbus_proxy_call_sync(proxy,
+                       "GetConnectionUnixProcessID",
+                       g_variant_new("(s)", arg_name),
+                       G_DBUS_CALL_FLAGS_NONE,
+                       -1, cancellable, error);
+               if (_ret != NULL) {
+                       g_variant_get(_ret, "(u)", out_pid);
+                       g_variant_unref(_ret);
+               }
+
+               return _ret != NULL;
+       }
+
+       pid_t ServerGDBus::getPID(const char *name)
+       {
+               guint pid = 0;
+               GError *error = NULL;
+
+               if (_call_get_connection_unix_process_id_sync(
+                       (GDBusProxy *)dbus_proxy, name,
+                       &pid, NULL, &error) == true) {
+               } else {
+                       _ERR("_g_freedesktop_dbus_call_get_connection_unix_process_id_sync failed  : %s", error->message);
+                       g_error_free(error);
+               }
+
+               return pid;
+       }
+
+       static bool _is_authorized_request(GDBusMethodInvocation *invocation,
+               const char *rights)
+       {
+               bool result = true;
+#ifdef USER_SPACE_SMACK
+               pid_t pid;
+               const char *name;
+               ClientInstance *instance;
+
+               name = g_dbus_method_invocation_get_sender(invocation);
+
+               instance = ServerResource::getInstance().getClient(name);
+               if (instance != NULL) {
+                       pid = instance->getPID();
+               } else {
+                       pid = ServerGDBus::getInstance().getPID(name);
+               }
+
+               result = (security_server_check_privilege_by_pid(
+                       pid,
+                       "smartcard-service",
+                       rights) == SECURITY_SERVER_API_SUCCESS);
+#endif
+               return result;
+       }
+
+       /* SEService *
+        *
+        *
+        */
+       static GVariant *_reader_to_variant(
+               vector<pair<unsigned int, string> > &readers)
+       {
+               GVariantBuilder builder;
+               uint32_t i;
+
+               g_variant_builder_init(&builder, G_VARIANT_TYPE("a(us)"));
+
+               for (i = 0; i < readers.size(); i++) {
+                       g_variant_builder_add(&builder, "(us)",
+                               readers[i].first, readers[i].second.c_str());
+               }
+
+               return g_variant_builder_end(&builder);
+       }
+
+       static gboolean __process_se_service(SmartcardServiceSeService *object,
+               GDBusMethodInvocation *invocation,
+               void *user_data)
+       {
+               gint result = SCARD_ERROR_OK;
+               GVariant *readers = NULL;
+               vector<pair<unsigned int, string> > list;
+               unsigned int handle = IntegerHandle::INVALID_HANDLE;
+               const char *name;
+               pid_t pid;
+
+               _INFO("[MSG_REQUEST_READERS]");
+
+               ServerResource &resource = ServerResource::getInstance();
+
+               name = g_dbus_method_invocation_get_sender(invocation);
+
+               /* load secure elements */
+               resource.loadSecureElements();
+
+               pid = ServerGDBus::getInstance().getPID(name);
+
+               _DBG("service requested, pid [%d]", pid);
+
+               if (pid > 0) {
+                       ClientInstance *instance;
+
+                       instance = resource.getClient(name);
+                       if (instance == NULL) {
+                               _INFO("create client instance, pid [%d]", pid);
+
+                               resource.createClient(name, pid);
+
+                               instance = resource.getClient(name);
+                               if (instance != NULL) {
+                                       /* generate certification hashes */
+                                       instance->generateCertificationHashes();
+                               } else {
+                                       _ERR("createClient failed");
+                               }
+                       }
+
+                       if (instance != NULL) {
+                               ServiceInstance *service;
+
+                               /* create service */
+                               service = resource.createService(name);
+                               if (service != NULL) {
+
+                                       handle = service->getHandle();
+                                       resource.getReaders(list);
+
+                                       if (list.size() == 0) {
+                                               _INFO("no secure elements");
+                                       }
+                               } else {
+                                       _ERR("createService failed");
+
+                                       result = SCARD_ERROR_OUT_OF_MEMORY;
+                               }
+                       } else {
+                               _ERR("client doesn't exist, pid [%d]", pid);
+
+                               result = SCARD_ERROR_OUT_OF_MEMORY;
+                       }
+               } else {
+                       _ERR("invalid pid, [%d]", pid);
+
+                       result = SCARD_ERROR_IPC_FAILED;
+               }
+
+               readers = _reader_to_variant(list);
+
+               /* response to client */
+               smartcard_service_se_service_complete_se_service(object,
+                       invocation, result, handle, readers);
+
+               return true;
+       }
+
+       static void _process_se_service(vector<void *> &params)
+       {
+               SmartcardServiceSeService *object;
+               GDBusMethodInvocation *invocation;
+               void *user_data;
+
+               if (params.size() != 3) {
+                       _ERR("invalid parameter");
+
+                       return;
+               }
+
+               object = (SmartcardServiceSeService *)params[0];
+               invocation = (GDBusMethodInvocation *)params[1];
+               user_data = params[2];
+
+               __process_se_service(object, invocation, user_data);
+
+               g_object_unref(object);
+               g_object_unref(invocation);
+       }
+
+       static gboolean _handle_se_service(SmartcardServiceSeService *object,
+               GDBusMethodInvocation *invocation,
+               void *user_data)
+       {
+               vector<void *> params;
+
+               /* apply user space smack */
+               if (_is_authorized_request(invocation, "r") == true) {
+                       g_object_ref(object);
+                       params.push_back((void *)object);
+
+                       g_object_ref(invocation);
+                       params.push_back((void *)invocation);
+
+                       params.push_back((void *)user_data);
+
+                       GDBusDispatcher::push(_process_se_service, params);
+               } else {
+                       vector<pair<unsigned int, string> > list;
+
+                       _ERR("access denied");
+
+                       /* response to client */
+                       smartcard_service_se_service_complete_se_service(object,
+                               invocation,
+                               SCARD_ERROR_SECURITY_NOT_ALLOWED,
+                               IntegerHandle::INVALID_HANDLE,
+                               _reader_to_variant(list));
+               }
+
+               return true;
+       }
+
+       static gboolean __process_shutdown(SmartcardServiceSeService *object,
+               GDBusMethodInvocation *invocation,
+               guint handle, void *user_data)
+       {
+               const char *name;
+
+               _INFO("[MSG_REQUEST_SHUTDOWN]");
+
+               ServerResource &resource = ServerResource::getInstance();
+
+               name = g_dbus_method_invocation_get_sender(invocation);
+
+               resource.removeService(name, handle);
+
+               /* response to client */
+               smartcard_service_se_service_complete_shutdown(object,
+                       invocation, SCARD_ERROR_OK);
+
+               /* terminate */
+               resource.finish();
+
+               return true;
+       }
+
+       static void _process_shutdown(vector<void *> &params)
+       {
+               SmartcardServiceSeService *object;
+               GDBusMethodInvocation *invocation;
+               guint handle;
+               void *user_data;
+
+               if (params.size() != 4) {
+                       _ERR("invalid parameter");
+
+                       return;
+               }
+
+               object = (SmartcardServiceSeService *)params[0];
+               invocation = (GDBusMethodInvocation *)params[1];
+               handle = (guint)params[2];
+               user_data = params[3];
+
+               __process_shutdown(object, invocation, handle, user_data);
+
+               g_object_unref(object);
+               g_object_unref(invocation);
+       }
+
+       static gboolean _handle_shutdown(SmartcardServiceSeService *object,
+               GDBusMethodInvocation *invocation,
+               guint handle,
+               void *user_data)
+       {
+               vector<void *> params;
+
+               /* apply user space smack */
+               if (_is_authorized_request(invocation, "r") == true) {
+                       g_object_ref(object);
+                       params.push_back((void *)object);
+
+                       g_object_ref(invocation);
+                       params.push_back((void *)invocation);
+
+                       params.push_back((void *)handle);
+                       params.push_back(user_data);
+
+                       GDBusDispatcher::push(_process_shutdown, params);
+               } else {
+                       _ERR("access denied");
+
+                       /* response to client */
+                       smartcard_service_se_service_complete_shutdown(object,
+                               invocation, SCARD_ERROR_SECURITY_NOT_ALLOWED);
+               }
+
+               return true;
+       }
+
+       bool ServerGDBus::initSEService()
+       {
+               GError *error = NULL;
+
+               seService = smartcard_service_se_service_skeleton_new();
+
+               g_signal_connect(seService,
+                       "handle-se-service",
+                       G_CALLBACK(_handle_se_service),
+                       this);
+
+               g_signal_connect(seService,
+                       "handle-shutdown",
+                       G_CALLBACK(_handle_shutdown),
+                       this);
+
+               if (g_dbus_interface_skeleton_export(
+                       G_DBUS_INTERFACE_SKELETON(seService),
+                       connection,
+                       "/org/tizen/SmartcardService/SeService",
+                       &error) == false)
+               {
+                       _ERR("Can not skeleton_export %s", error->message);
+
+                       g_error_free(error);
+                       g_object_unref(seService);
+                       seService = NULL;
+
+                       return false;
+               }
+
+               return true;
+       }
+
+       void ServerGDBus::deinitSEService()
+       {
+               if (seService != NULL) {
+                       g_object_unref(seService);
+                       seService = NULL;
+               }
+       }
+
+       void ServerGDBus::emitReaderInserted(unsigned int reader_id,
+               const char *reader_name)
+       {
+               smartcard_service_se_service_emit_reader_inserted(
+                       SMARTCARD_SERVICE_SE_SERVICE(seService),
+                       reader_id, reader_name);
+       }
+
+       void ServerGDBus::emitReaderRemoved(unsigned int reader_id,
+               const char *reader_name)
+       {
+               smartcard_service_se_service_emit_reader_removed(
+                       SMARTCARD_SERVICE_SE_SERVICE(seService),
+                       reader_id, reader_name);
+       }
+
+       /* Reader *
+        *
+        *
+        */
+       static gboolean __process_open_session(SmartcardServiceReader *object,
+               GDBusMethodInvocation *invocation, guint service_id,
+               guint reader_id, void *user_data)
+       {
+               unsigned int handle = IntegerHandle::INVALID_HANDLE;
+               int result;
+               const char *name;
+
+               _INFO("[MSG_REQUEST_OPEN_SESSION]");
+
+               ServerResource &resource = ServerResource::getInstance();
+
+               name = g_dbus_method_invocation_get_sender(invocation);
+
+               if (resource.isValidReaderHandle(reader_id)) {
+                       vector<ByteArray> temp;
+
+                       handle = resource.createSession(name,
+                               service_id,
+                               reader_id,
+                               temp,
+                               (void *)NULL);
+                       if (handle != IntegerHandle::INVALID_HANDLE) {
+                               result = SCARD_ERROR_OK;
+                       } else {
+                               _ERR("createSession failed [%d]", handle);
+
+                               result = SCARD_ERROR_OUT_OF_MEMORY;
+                       }
+               } else {
+                       _ERR("request invalid reader handle [%d]", reader_id);
+
+                       result = SCARD_ERROR_ILLEGAL_PARAM;
+               }
+
+               /* response to client */
+               smartcard_service_reader_complete_open_session(object,
+                       invocation, result, handle);
+
+               return true;
+       }
+
+       static void _process_open_session(vector<void *> &params)
+       {
+               SmartcardServiceReader *object;
+               GDBusMethodInvocation *invocation;
+               guint service_id;
+               guint reader_id;
+               void *user_data;
+
+               if (params.size() != 5) {
+                       _ERR("invalid parameter");
+
+                       return;
+               }
+
+               object = (SmartcardServiceReader *)params[0];
+               invocation = (GDBusMethodInvocation *)params[1];
+               service_id = (guint)params[2];
+               reader_id = (guint)params[3];
+               user_data = params[4];
+
+               __process_open_session(object, invocation, service_id,
+                       reader_id, user_data);
+
+               g_object_unref(object);
+               g_object_unref(invocation);
+       }
+
+       static gboolean _handle_open_session(SmartcardServiceReader *object,
+               GDBusMethodInvocation *invocation,
+               guint service_id,
+               guint reader_id, void *user_data)
+       {
+               vector<void *> params;
+
+               /* apply user space smack */
+               if (_is_authorized_request(invocation, "r") == true) {
+                       g_object_ref(object);
+                       params.push_back((void *)object);
+
+                       g_object_ref(invocation);
+                       params.push_back((void *)invocation);
+
+                       params.push_back((void *)service_id);
+                       params.push_back((void *)reader_id);
+                       params.push_back(user_data);
+
+                       GDBusDispatcher::push(_process_open_session, params);
+               } else {
+                       _ERR("access denied");
+
+                       /* response to client */
+                       smartcard_service_reader_complete_open_session(object,
+                               invocation,
+                               SCARD_ERROR_SECURITY_NOT_ALLOWED,
+                               IntegerHandle::INVALID_HANDLE);
+               }
+
+               return true;
+       }
+
+       bool ServerGDBus::initReader()
+       {
+               GError *error = NULL;
+
+               reader = smartcard_service_reader_skeleton_new();
+
+               g_signal_connect(reader,
+                       "handle-open-session",
+                       G_CALLBACK(_handle_open_session),
+                       this);
+
+               if (g_dbus_interface_skeleton_export(
+                       G_DBUS_INTERFACE_SKELETON(reader),
+                       connection,
+                       "/org/tizen/SmartcardService/Reader",
+                       &error) == false)
+               {
+                       _ERR("Can not skeleton_export %s", error->message);
+
+                       g_error_free(error);
+                       g_object_unref(reader);
+                       reader = NULL;
+
+                       return false;
+               }
+
+               return true;
+       }
+
+       void ServerGDBus::deinitReader()
+       {
+               if (reader != NULL) {
+                       g_object_unref(reader);
+                       reader = NULL;
+               }
+       }
+
+       /* Session *
+        *
+        *
+        */
+       static gboolean __process_close_session(SmartcardServiceSession *object,
+               GDBusMethodInvocation *invocation, guint service_id,
+               guint session_id, void *user_data)
+       {
+               const char *name;
+
+               _INFO("[MSG_REQUEST_CLOSE_SESSION]");
+
+               ServerResource &resource = ServerResource::getInstance();
+
+               name = g_dbus_method_invocation_get_sender(invocation);
+
+               if (resource.isValidSessionHandle(name, service_id,
+                       session_id)) {
+                       resource.removeSession(name, service_id,
+                               session_id);
+               } else {
+                       _ERR("invalid parameters");
+               }
+
+               /* response to client */
+               smartcard_service_session_complete_close_session(object,
+                       invocation, SCARD_ERROR_OK);
+
+               return true;
+       }
+
+       static void _process_close_session(vector<void *> &params)
+       {
+               SmartcardServiceSession *object;
+               GDBusMethodInvocation *invocation;
+               guint service_id;
+               guint session_id;
+               void *user_data;
+
+               if (params.size() != 5) {
+                       _ERR("invalid parameter");
+
+                       return;
+               }
+
+               object = (SmartcardServiceSession *)params[0];
+               invocation = (GDBusMethodInvocation *)params[1];
+               service_id = (guint)params[2];
+               session_id = (guint)params[3];
+               user_data = params[4];
+
+               __process_close_session(object, invocation, service_id,
+                       session_id, user_data);
+
+               g_object_unref(object);
+               g_object_unref(invocation);
+       }
+
+       static gboolean _handle_close_session(SmartcardServiceSession *object,
+               GDBusMethodInvocation *invocation,
+               guint service_id,
+               guint session_id, void *user_data)
+       {
+               vector<void *> params;
+
+               /* apply user space smack */
+               if (_is_authorized_request(invocation, "r") == true) {
+                       g_object_ref(object);
+                       params.push_back((void *)object);
+
+                       g_object_ref(invocation);
+                       params.push_back((void *)invocation);
+
+                       params.push_back((void *)service_id);
+                       params.push_back((void *)session_id);
+                       params.push_back(user_data);
+
+                       GDBusDispatcher::push(_process_close_session, params);
+               } else {
+                       _ERR("access denied");
+
+                       /* response to client */
+                       smartcard_service_session_complete_close_session(object,
+                               invocation, SCARD_ERROR_SECURITY_NOT_ALLOWED);
+               }
+
+               return true;
+       }
+
+       static gboolean __process_get_atr(SmartcardServiceSession *object,
+               GDBusMethodInvocation *invocation, guint service_id,
+               guint session_id, void *user_data)
+       {
+               int result;
+               ByteArray resp;
+               GVariant *atr = NULL;
+               const char *name;
+               ServiceInstance *client = NULL;
+
+               _INFO("[MSG_REQUEST_GET_ATR]");
+
+               ServerResource &resource = ServerResource::getInstance();
+
+               name = g_dbus_method_invocation_get_sender(invocation);
+
+               client = resource.getService(name, service_id);
+               if (client != NULL) {
+                       Terminal *terminal;
+
+                       terminal = client->getTerminal(session_id);
+                       if (terminal != NULL) {
+                               int rv;
+
+                               if ((rv = terminal->getATRSync(resp)) == 0) {
+                                       result = SCARD_ERROR_OK;
+                               } else {
+                                       _ERR("getATRSync failed : name [%s], service_id [%d], session_id [%d]", name, service_id, session_id);
+
+                                       result = rv;
+                               }
+                       } else {
+                               _ERR("getTerminal failed : name [%s], service_id [%d], session_id [%d]", name, service_id, session_id);
+
+                               result = SCARD_ERROR_UNAVAILABLE;
+                       }
+               } else {
+                       _ERR("getClient failed : name [%s], service_id [%d], session_id [%d]", name, service_id, session_id);
+
+                       result = SCARD_ERROR_UNAVAILABLE;
+               }
+
+               atr = GDBusHelper::convertByteArrayToVariant(resp);
+
+               /* response to client */
+               smartcard_service_session_complete_get_atr(object, invocation,
+                       result, atr);
+
+               return true;
+       }
+
+       static void _process_get_atr(vector<void *> &params)
+       {
+               SmartcardServiceSession *object;
+               GDBusMethodInvocation *invocation;
+               guint service_id;
+               guint session_id;
+               void *user_data;
+
+               if (params.size() != 5) {
+                       _ERR("invalid parameter");
+
+                       return;
+               }
+
+               object = (SmartcardServiceSession *)params[0];
+               invocation = (GDBusMethodInvocation *)params[1];
+               service_id = (guint)params[2];
+               session_id = (guint)params[3];
+               user_data = params[4];
+
+               __process_get_atr(object, invocation, service_id,
+                       session_id, user_data);
+
+               g_object_unref(object);
+               g_object_unref(invocation);
+       }
+
+       static gboolean _handle_get_atr(SmartcardServiceSession *object,
+               GDBusMethodInvocation *invocation,
+               guint service_id,
+               guint session_id, void *user_data)
+       {
+               vector<void *> params;
+
+               /* apply user space smack */
+               if (_is_authorized_request(invocation, "r") == true) {
+                       g_object_ref(object);
+                       params.push_back((void *)object);
+
+                       g_object_ref(invocation);
+                       params.push_back((void *)invocation);
+
+                       params.push_back((void *)service_id);
+                       params.push_back((void *)session_id);
+                       params.push_back(user_data);
+
+                       GDBusDispatcher::push(_process_get_atr, params);
+               } else {
+                       ByteArray resp;
+
+                       _ERR("access denied");
+
+                       /* response to client */
+                       smartcard_service_session_complete_get_atr(
+                               object,
+                               invocation,
+                               SCARD_ERROR_SECURITY_NOT_ALLOWED,
+                               GDBusHelper::convertByteArrayToVariant(resp));
+               }
+
+               return true;
+       }
+
+       static gboolean __process_open_channel(SmartcardServiceSession *object,
+               GDBusMethodInvocation *invocation, guint service_id,
+               guint session_id, guint type, GVariant *aid, void *user_data)
+       {
+               int result = SCARD_ERROR_UNKNOWN;
+               ByteArray resp;
+               GVariant *response = NULL;
+               unsigned int channelID = IntegerHandle::INVALID_HANDLE;
+               const char *name;
+
+               _INFO("[MSG_REQUEST_OPEN_CHANNEL]");
+
+               ServerResource &resource = ServerResource::getInstance();
+
+               name = g_dbus_method_invocation_get_sender(invocation);
+
+               try
+               {
+                       ByteArray tempAid;
+
+                       GDBusHelper::convertVariantToByteArray(aid,
+                               tempAid);
+
+                       channelID = resource.createChannel(name,
+                               service_id, session_id, type, tempAid);
+                       if (channelID != IntegerHandle::INVALID_HANDLE) {
+                               ServerChannel *temp;
+
+                               temp = (ServerChannel *)resource.getChannel(
+                                       name, service_id, channelID);
+                               if (temp != NULL) {
+                                       resp = temp->getSelectResponse();
+
+                                       result = SCARD_ERROR_OK;
+                               }
+                       } else {
+                               _ERR("channel is null.");
+
+                               /* set error value */
+                               result = SCARD_ERROR_UNAVAILABLE;
+                       }
+               }
+               catch (ExceptionBase &e)
+               {
+                       result = e.getErrorCode();
+               }
+
+               response = GDBusHelper::convertByteArrayToVariant(resp);
+
+               /* response to client */
+               smartcard_service_session_complete_open_channel(object,
+                       invocation, result, channelID, response);
+
+               return true;
+       }
+
+       static void _process_open_channel(vector<void *> &params)
+       {
+               SmartcardServiceSession *object;
+               GDBusMethodInvocation *invocation;
+               guint service_id;
+               guint session_id;
+               guint type;
+               GVariant *aid;
+               void *user_data;
+
+               if (params.size() != 7) {
+                       _ERR("invalid parameter");
+
+                       return;
+               }
+
+               object = (SmartcardServiceSession *)params[0];
+               invocation = (GDBusMethodInvocation *)params[1];
+               service_id = (guint)params[2];
+               session_id = (guint)params[3];
+               type = (guint)params[4];
+               aid = (GVariant *)params[5];
+               user_data = params[6];
+
+               __process_open_channel(object, invocation, service_id,
+                       session_id, type, aid, user_data);
+
+               g_object_unref(object);
+               g_object_unref(invocation);
+               g_object_unref(aid);
+       }
+
+       static gboolean _handle_open_channel(SmartcardServiceSession *object,
+               GDBusMethodInvocation *invocation,
+               guint service_id,
+               guint session_id, guint type, GVariant *aid, void *user_data)
+       {
+               vector<void *> params;
+
+               /* apply user space smack */
+               if (_is_authorized_request(invocation, "rw") == true) {
+                       g_object_ref(object);
+                       params.push_back((void *)object);
+
+                       g_object_ref(invocation);
+                       params.push_back((void *)invocation);
+
+                       params.push_back((void *)service_id);
+                       params.push_back((void *)session_id);
+                       params.push_back((void *)type);
+
+                       g_object_ref(aid);
+                       params.push_back((void *)aid);
+                       params.push_back(user_data);
+
+                       GDBusDispatcher::push(_process_open_channel, params);
+               } else {
+                       ByteArray resp;
+
+                       _ERR("access denied");
+
+                       /* response to client */
+                       smartcard_service_session_complete_open_channel(object,
+                               invocation,
+                               SCARD_ERROR_SECURITY_NOT_ALLOWED,
+                               IntegerHandle::INVALID_HANDLE,
+                               GDBusHelper::convertByteArrayToVariant(resp));
+               }
+
+               return true;
+       }
+
+       bool ServerGDBus::initSession()
+       {
+               GError *error = NULL;
+
+               session = smartcard_service_session_skeleton_new();
+
+               g_signal_connect(session,
+                       "handle-close-session",
+                       G_CALLBACK(_handle_close_session),
+                       this);
+
+               g_signal_connect(session,
+                       "handle-get-atr",
+                       G_CALLBACK(_handle_get_atr),
+                       this);
+
+               g_signal_connect(session,
+                       "handle-open-channel",
+                       G_CALLBACK(_handle_open_channel),
+                       this);
+
+               if (g_dbus_interface_skeleton_export(
+                       G_DBUS_INTERFACE_SKELETON(session),
+                       connection,
+                       "/org/tizen/SmartcardService/Session",
+                       &error) == false)
+               {
+                       _ERR("Can not skeleton_export %s", error->message);
+
+                       g_error_free(error);
+                       g_object_unref(session);
+                       session = NULL;
+
+                       return false;
+               }
+
+               return true;
+       }
+
+       void ServerGDBus::deinitSession()
+       {
+               if (session != NULL) {
+                       g_object_unref(session);
+                       session = NULL;
+               }
+       }
+
+       /* Channel *
+        *
+        *
+        */
+       static gboolean __process_close_channel(SmartcardServiceChannel *object,
+               GDBusMethodInvocation *invocation, guint service_id,
+               guint channel_id, void *user_data)
+       {
+               int result;
+               const char *name;
+
+               _INFO("[MSG_REQUEST_CLOSE_CHANNEL]");
+
+               ServerResource &resource = ServerResource::getInstance();
+
+               name = g_dbus_method_invocation_get_sender(invocation);
+
+               resource.removeChannel(name, service_id, channel_id);
+
+               result = SCARD_ERROR_OK;
+
+               /* response to client */
+               smartcard_service_channel_complete_close_channel(object,
+                       invocation, result);
+
+               return true;
+       }
+
+       static void _process_close_channel(vector<void *> &params)
+       {
+               SmartcardServiceChannel *object;
+               GDBusMethodInvocation *invocation;
+               guint service_id;
+               guint channel_id;
+               void *user_data;
+
+               if (params.size() != 5) {
+                       _ERR("invalid parameter");
+
+                       return;
+               }
+
+               object = (SmartcardServiceChannel *)params[0];
+               invocation = (GDBusMethodInvocation *)params[1];
+               service_id = (guint)params[2];
+               channel_id = (guint)params[3];
+               user_data = params[4];
+
+               __process_close_channel(object, invocation, service_id,
+                       channel_id, user_data);
+
+               g_object_unref(object);
+               g_object_unref(invocation);
+       }
+
+       static gboolean _handle_close_channel(SmartcardServiceChannel *object,
+               GDBusMethodInvocation *invocation,
+               guint service_id, guint channel_id, void *user_data)
+       {
+               vector<void *> params;
+
+               /* apply user space smack */
+               if (_is_authorized_request(invocation, "r") == true) {
+                       g_object_ref(object);
+                       params.push_back((void *)object);
+
+                       g_object_ref(invocation);
+                       params.push_back((void *)invocation);
+
+                       params.push_back((void *)service_id);
+                       params.push_back((void *)channel_id);
+                       params.push_back(user_data);
+
+                       GDBusDispatcher::push(_process_close_channel, params);
+               } else {
+                       _ERR("access denied");
+
+                       /* response to client */
+                       smartcard_service_channel_complete_close_channel(
+                               object,
+                               invocation,
+                               SCARD_ERROR_SECURITY_NOT_ALLOWED);
+               }
+
+               return true;
+       }
+
+       static gboolean __process_transmit(SmartcardServiceChannel *object,
+               GDBusMethodInvocation *invocation,
+               guint service_id,
+               guint channel_id,
+               GVariant *command,
+               void *user_data)
+       {
+               int result;
+               Channel *channel = NULL;
+               ByteArray resp;
+               GVariant *response = NULL;
+               const char *name;
+
+               _INFO("[MSG_REQUEST_TRANSMIT]");
+
+               ServerResource &resource = ServerResource::getInstance();
+
+               name = g_dbus_method_invocation_get_sender(invocation);
+
+               channel = resource.getChannel(name, service_id, channel_id);
+               if (channel != NULL) {
+                       int rv;
+                       ByteArray cmd;
+
+                       GDBusHelper::convertVariantToByteArray(command, cmd);
+
+                       rv = channel->transmitSync(cmd, resp);
+                       if (rv == 0) {
+                               result = SCARD_ERROR_OK;
+                       } else {
+                               _ERR("transmit failed [%d]", rv);
+
+                               result = rv;
+                       }
+               } else {
+                       _ERR("invalid handle : name [%s], service_id [%d], channel_id [%d]", name, service_id, channel_id);
+
+                       result = SCARD_ERROR_UNAVAILABLE;
+               }
+
+               response = GDBusHelper::convertByteArrayToVariant(resp);
+
+               /* response to client */
+               smartcard_service_channel_complete_transmit(object, invocation,
+                       result, response);
+
+               return true;
+       }
+
+       static void _process_transmit(vector<void *> &params)
+       {
+               SmartcardServiceChannel *object;
+               GDBusMethodInvocation *invocation;
+               guint service_id;
+               guint channel_id;
+               GVariant *command;
+               void *user_data;
+
+               if (params.size() != 6) {
+                       _ERR("invalid parameter");
+
+                       return;
+               }
+
+               object = (SmartcardServiceChannel *)params[0];
+               invocation = (GDBusMethodInvocation *)params[1];
+               service_id = (guint)params[2];
+               channel_id = (guint)params[3];
+               command = (GVariant *)params[4];
+               user_data = params[5];
+
+               __process_transmit(object, invocation, service_id,
+                       channel_id, command, user_data);
+
+               g_object_unref(object);
+               g_object_unref(invocation);
+               g_object_unref(command);
+       }
+
+       static gboolean _handle_transmit(SmartcardServiceChannel *object,
+               GDBusMethodInvocation *invocation,
+               guint service_id,
+               guint channel_id,
+               GVariant *command,
+               void *user_data)
+       {
+               vector<void *> params;
+
+               /* apply user space smack */
+               if (_is_authorized_request(invocation, "r") == true) {
+                       /* enqueue message */
+                       g_object_ref(object);
+                       params.push_back((void *)object);
+
+                       g_object_ref(invocation);
+                       params.push_back((void *)invocation);
+
+                       params.push_back((void *)service_id);
+                       params.push_back((void *)channel_id);
+
+                       g_object_ref(command);
+                       params.push_back((void *)command);
+
+                       params.push_back(user_data);
+
+                       GDBusDispatcher::push(_process_transmit, params);
+               } else {
+                       ByteArray resp;
+
+                       _ERR("access denied");
+
+                       /* response to client */
+                       smartcard_service_channel_complete_transmit(object,
+                               invocation,
+                               SCARD_ERROR_SECURITY_NOT_ALLOWED,
+                               GDBusHelper::convertByteArrayToVariant(resp));
+               }
+
+               return true;
+       }
+
+       bool ServerGDBus::initChannel()
+       {
+               GError *error = NULL;
+
+               channel = smartcard_service_channel_skeleton_new();
+
+               g_signal_connect(channel,
+                       "handle-close-channel",
+                       G_CALLBACK(_handle_close_channel),
+                       this);
+
+               g_signal_connect(channel,
+                       "handle-transmit",
+                       G_CALLBACK(_handle_transmit),
+                       this);
+
+               if (g_dbus_interface_skeleton_export(
+                       G_DBUS_INTERFACE_SKELETON(channel),
+                       connection,
+                       "/org/tizen/SmartcardService/Channel",
+                       &error) == false)
+               {
+                       _ERR("Can not skeleton_export %s", error->message);
+
+                       g_error_free(error);
+                       g_object_unref(channel);
+                       channel = NULL;
+
+                       return false;
+               }
+
+               return true;
+       }
+
+       void ServerGDBus::deinitChannel()
+       {
+               if (channel != NULL) {
+                       g_object_unref(channel);
+                       channel = NULL;
+               }
+       }
+} /* namespace smartcard_service_api */
+#endif
index eb25f24..419fc15 100644 (file)
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 
+#ifndef USE_GDBUS
 /* standard library header */
 #include <string.h>
 #include <sys/socket.h>
 
 namespace smartcard_service_api
 {
-       ServerIPC::ServerIPC():IPCHelper()
+       ServerIPC::ServerIPC() : IPCHelper()
        {
-               SCARD_BEGIN();
+               _BEGIN();
 
                setDispatcher(ServerDispatcher::getInstance());
 
-               SCARD_END();
+               _END();
        }
 
        ServerIPC::~ServerIPC()
@@ -61,24 +62,24 @@ namespace smartcard_service_api
                ByteArray buffer;
                Message *msg = NULL;
 
-               SCARD_BEGIN();
+               _BEGIN();
 
                buffer = IPCHelper::retrieveBuffer(socket);
-               if (buffer.getLength() > 0)
+               if (buffer.size() > 0)
                {
 #ifdef SECURITY_SERVER
                        ByteArray cookie;
                        int result, gid;
 
-                       if (buffer.getLength() < 20)
+                       if (buffer.size() < 20)
                                return msg;
 
-                       cookie.setBuffer(buffer.getBuffer(), 20);
+                       cookie.assign(buffer.getBuffer(), 20);
 
                        gid = security_server_get_gid("smartcard-daemon");
-                       if ((result = security_server_check_privilege(cookie.getBuffer(), gid)) != SECURITY_SERVER_API_SUCCESS)
+                       if ((result = security_server_check_privilege((char *)cookie.getBuffer(), gid)) != SECURITY_SERVER_API_SUCCESS)
                        {
-                               SCARD_DEBUG_ERR("security_server_check_privilege failed [%d]", result);
+                               _ERR("security_server_check_privilege failed [%d]", result);
                                return msg;
                        }
 #endif
@@ -89,15 +90,15 @@ namespace smartcard_service_api
                        }
                        else
                        {
-                               SCARD_DEBUG_ERR("alloc failed");
+                               _ERR("alloc failed");
                        }
                }
                else
                {
-                       SCARD_DEBUG_ERR("retrieveBuffer failed ");
+                       _ERR("retrieveBuffer failed ");
                }
 
-               SCARD_END();
+               _END();
 
                return msg;
        }
@@ -110,7 +111,7 @@ namespace smartcard_service_api
                GIOChannel *client_channel = NULL;
                int client_src_id;
 
-               SCARD_DEBUG("client is trying to connect to server");
+               _DBG("client is trying to connect to server");
 
                pthread_mutex_lock(&ipcLock);
                client_sock_fd = accept(ipcSocket, NULL, &addrlen);
@@ -118,29 +119,29 @@ namespace smartcard_service_api
 
                if (client_sock_fd < 0)
                {
-                       SCARD_DEBUG_ERR("can not accept client");
+                       _ERR("can not accept client");
                        goto ERROR;
                }
 
-               SCARD_DEBUG("client is accepted by server");
+               _DBG("client is accepted by server");
 
                if ((client_channel = g_io_channel_unix_new(client_sock_fd)) == NULL)
                {
-                       SCARD_DEBUG_ERR("create new g io channel is failed");
+                       _ERR("create new g io channel is failed");
                        goto ERROR;
                }
 
                if ((client_src_id = g_io_add_watch(client_channel, condition, &IPCHelper::channelCallbackFunc, this)) < 1)
                {
-                       SCARD_DEBUG_ERR("add io callback is failed");
+                       _ERR("add io callback is failed");
                        goto ERROR;
                }
 
-               SCARD_DEBUG("client socket is bond with g_io_channel");
+               _INFO("client socket is bond with g_io_channel");
 
                if (ServerResource::getInstance().createClient(client_channel, client_sock_fd, client_src_id, 0, -1) == false)
                {
-                       SCARD_DEBUG_ERR("failed to add client");
+                       _ERR("failed to add client");
                }
 
                return true;
@@ -188,11 +189,11 @@ ERROR :
 
        int ServerIPC::handleIOErrorCondition(void *channel, GIOCondition condition)
        {
-               SCARD_BEGIN();
+               _BEGIN();
 
                if(channel == ioChannel)
                {
-                       SCARD_DEBUG("server socket is closed");
+                       _INFO("server socket is closed");
                        restartServerIPC();
                }
                else
@@ -200,26 +201,26 @@ ERROR :
                        DispatcherMsg dispMsg;
                        int peerSocket = g_io_channel_unix_get_fd((GIOChannel *)channel);
 
-                       SCARD_DEBUG("client socket is closed, socket [%d]", peerSocket);
+                       _INFO("client socket is closed, socket [%d]", peerSocket);
 
-                       /* push messsage to dispatcher */
+                       /* push message to dispatcher */
                        dispMsg.message = Message::MSG_OPERATION_RELEASE_CLIENT;
                        dispMsg.param1 = peerSocket;
                        dispMsg.setPeerSocket(peerSocket);
 
                        /* push to dispatcher */
-                       ServerDispatcher::getInstance()->pushMessage(&dispMsg);
+                       ServerDispatcher::getInstance()->pushMessage(dispMsg);
                }
 
-               SCARD_END();
+               _END();
 
                return FALSE;
        }
 
        int ServerIPC::handleInvalidSocketCondition(void *channel, GIOCondition condition)
        {
-               SCARD_BEGIN();
-               SCARD_END();
+               _BEGIN();
+               _END();
 
                return FALSE;
        }
@@ -228,12 +229,12 @@ ERROR :
        {
                int result = FALSE;
 
-               SCARD_BEGIN();
+               _BEGIN();
 
                if(channel == ioChannel)
                {
                        /* connect state. should accept */
-                       SCARD_DEBUG("new client connected");
+                       _INFO("new client connected");
 
                        result = acceptClient();
                }
@@ -241,7 +242,7 @@ ERROR :
                {
                        int peerSocket = g_io_channel_unix_get_fd((GIOChannel *)channel);
 
-                       SCARD_DEBUG("data incomming from [%d]", peerSocket);
+                       _DBG("data incoming from [%d]", peerSocket);
 
                        if (peerSocket >= 0)
                        {
@@ -250,10 +251,10 @@ ERROR :
                                /* read message */
                                if ((msg = retrieveMessage(peerSocket)) != NULL)
                                {
-                                       DispatcherMsg dispMsg(msg, peerSocket);
+                                       DispatcherMsg dispMsg(*msg, peerSocket);
 
                                        /* push to dispatcher */
-                                       ServerDispatcher::getInstance()->pushMessage(&dispMsg);
+                                       ServerDispatcher::getInstance()->pushMessage(dispMsg);
 
                                        result = TRUE;
 
@@ -262,16 +263,16 @@ ERROR :
                                else
                                {
                                        /* clear client connection */
-                                       SCARD_DEBUG_ERR("retrieve message failed, socket [%d]", peerSocket);
+                                       _ERR("retrieve message failed, socket [%d]", peerSocket);
                                }
                        }
                        else
                        {
-                               SCARD_DEBUG_ERR("client context doesn't exist, socket [%d]", peerSocket);
+                               _ERR("client context doesn't exist, socket [%d]", peerSocket);
                        }
                }
 
-               SCARD_END();
+               _END();
 
                return result;
        }
@@ -286,3 +287,4 @@ EXTERN_API void server_ipc_create_listen_socket()
 
        ipc->createListenSocket();
 }
+#endif /* USE_GDBUS */
index fa51f1a..4b880d2 100644 (file)
 #include "Debug.h"
 #include "ServerSEService.h"
 #include "ServerReader.h"
-#include "GPSEACL.h"
+#include "GPACE.h"
 
 namespace smartcard_service_api
 {
-       ServerReader::ServerReader(ServerSEService *seService, char *name, Terminal *terminal) :
-               ReaderHelper()
+       ServerReader::ServerReader(ServerSEService *seService,
+               const char *name, Terminal *terminal) : ReaderHelper()
        {
-               unsigned int length = 0;
-
-               acList = NULL;
-
-               if (seService == NULL || name == NULL || strlen(name) == 0 || terminal == NULL)
+               if (seService == NULL || name == NULL ||
+                       strlen(name) == 0 || terminal == NULL)
                {
-                       SCARD_DEBUG_ERR("invalid param");
+                       _ERR("invalid param");
 
                        return;
                }
 
                this->terminal = terminal;
                this->seService = seService;
-
-               length = strlen(name);
-               length = (length < sizeof(this->name)) ? length : sizeof(this->name);
-               memcpy(this->name, name, length);
-
-               /* open admin channel */
-               adminChannel = new ServerChannel(NULL, NULL, 0, terminal);
-               if (adminChannel == NULL)
-               {
-                       SCARD_DEBUG_ERR("alloc failed");
-               }
+               this->name = name;
        }
 
        ServerReader::~ServerReader()
        {
                closeSessions();
-
-               if (acList != NULL)
-               {
-                       delete acList;
-                       acList = NULL;
-               }
-
-               if (adminChannel != NULL)
-               {
-                       delete adminChannel;
-                       adminChannel = NULL;
-               }
        }
 
        void ServerReader::closeSessions()
@@ -90,25 +65,6 @@ namespace smartcard_service_api
                sessions.clear();
        }
 
-       AccessControlList *ServerReader::getAccessControlList()
-       {
-               if (acList == NULL)
-               {
-                       /* load access control */
-                       acList = new GPSEACL();
-                       if (acList != NULL)
-                       {
-                               acList->loadACL(adminChannel);
-                       }
-                       else
-                       {
-                               SCARD_DEBUG_ERR("alloc failed");
-                       }
-               }
-
-               return acList;
-       }
-
        ServerSession *ServerReader::openSessionSync()
                throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &)
        {
@@ -117,7 +73,7 @@ namespace smartcard_service_api
                return openSessionSync(temp, NULL);
        }
 
-       ServerSession *ServerReader::openSessionSync(vector<ByteArray> &certHashes, void *caller)
+       ServerSession *ServerReader::openSessionSync(const vector<ByteArray> &certHashes, void *caller)
                throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &)
        {
                ServerSession *session = NULL;
index 31b1ce8..63c7d2f 100644 (file)
 #include "TerminalInterface.h"
 #include "APDUHelper.h"
 #include "SignatureHelper.h"
-#include "GPSEACL.h"
+#include "GPACE.h"
+#include "PKCS15.h"
+#ifdef USE_GDBUS
+#include "ServerGDBus.h"
+#endif
+#include "smartcard-daemon.h"
 
 #ifndef EXTERN_API
 #define EXTERN_API __attribute__((visibility("default")))
 #endif
 
+using namespace std;
+
 namespace smartcard_service_api
 {
        unsigned int IntegerHandle::newHandle = 0;
@@ -61,14 +68,14 @@ namespace smartcard_service_api
                        while (!result.second);
                }
 
-               SCARD_DEBUG("assign handle : newHandle [%d]", newHandle);
+               _DBG("assign handle : newHandle [%d]", newHandle);
 
                return newHandle;
        }
 
        void IntegerHandle::releaseHandle(unsigned int handle)
        {
-               SCARD_DEBUG("will be released : Handle [%d]", handle);
+               _DBG("will be released : Handle [%d]", handle);
 
                SCOPE_LOCK(mutexLock)
                {
@@ -76,17 +83,16 @@ namespace smartcard_service_api
                }
        }
 
-#define OMAPI_SE_PATH LIBPATH"/se"
+#define OMAPI_SE_PATH "/usr/lib/se"
 
-       ServerResource::ServerResource()
-               : mainLoop(NULL), seLoaded(false)
+       ServerResource::ServerResource() : seLoaded(false)
        {
-               SCARD_BEGIN();
-
+               _BEGIN();
+#ifndef USE_GDBUS
                serverIPC = ServerIPC::getInstance();
                serverDispatcher = ServerDispatcher::getInstance();
-
-               SCARD_END();
+#endif
+               _END();
        }
 
        ServerResource::~ServerResource()
@@ -100,13 +106,310 @@ namespace smartcard_service_api
                return serverResource;
        }
 
-       bool ServerResource::createClient(void *ioChannel, int socket, int watchID, int state, int pid)
+#ifdef USE_GDBUS
+       bool ServerResource::createClient(const char *name, pid_t pid)
+       {
+               bool result = false;
+
+               if (getClient(name) == NULL)
+               {
+                       ClientInstance *instance = new ClientInstance(name, pid);
+                       if (instance != NULL)
+                       {
+                               mapClients.insert(make_pair(name, instance));
+                               result = true;
+                       }
+                       else
+                       {
+                               _ERR("alloc failed");
+                       }
+               }
+               else
+               {
+                       _ERR("client already exist, name [%s]", name);
+               }
+
+               return result;
+       }
+
+       ClientInstance *ServerResource::getClient(const char *name)
+       {
+               ClientInstance *result = NULL;
+               map<string, ClientInstance *>::iterator item;
+
+               if ((item = mapClients.find(name)) != mapClients.end())
+               {
+                       result = item->second;
+               }
+
+               return result;
+       }
+
+       void ServerResource::removeClient(const char *name)
+       {
+               map<string, ClientInstance *>::iterator item;
+
+               if ((item = mapClients.find(name)) != mapClients.end())
+               {
+                       delete item->second;
+                       mapClients.erase(item);
+               }
+               else
+               {
+                       _DBG("client removed already, name [%s]", name);
+               }
+       }
+
+       void ServerResource::removeClients()
+       {
+               map<string, ClientInstance *>::iterator item;
+
+               for (item = mapClients.begin(); item != mapClients.end(); item++)
+               {
+                       delete item->second;
+               }
+
+               mapClients.clear();
+       }
+
+       int ServerResource::getClientCount() const
+       {
+               return (int)mapClients.size();
+       }
+
+       ServiceInstance *ServerResource::createService(const char *name)
+       {
+               ServiceInstance *result = NULL;
+               ClientInstance *instance = NULL;
+
+               if ((instance = getClient(name)) != NULL)
+               {
+                       if ((result = instance->createService()) == NULL)
+                       {
+                               _ERR("ClientInstance::createService failed [%d]", name);
+                       }
+               }
+               else
+               {
+                       _ERR("client doesn't exist, name [%s]", name);
+               }
+
+               return result;
+       }
+
+       ServiceInstance *ServerResource::getService(const char *name, unsigned int handle)
+       {
+               ServiceInstance *result = NULL;
+               ClientInstance *instance = NULL;
+
+               if ((instance = getClient(name)) != NULL)
+               {
+                       result = instance->getService(handle);
+               }
+               else
+               {
+                       _ERR("client doesn't exist, name [%s]", name);
+               }
+
+               return result;
+       }
+
+       void ServerResource::removeService(const char *name, unsigned int handle)
+       {
+               ClientInstance *instance = NULL;
+
+               if ((instance = getClient(name)) != NULL)
+               {
+                       instance->removeService(handle);
+                       if (instance->getServiceCounts() == 0) {
+
+                               /* remove client instance */
+                               removeClient(name);
+                       }
+               }
+               else
+               {
+                       _ERR("client doesn't exist, name [%s]", name);
+               }
+       }
+
+       void ServerResource::removeServices(const char *name)
+       {
+               ClientInstance *instance = NULL;
+
+               if ((instance = getClient(name)) != NULL)
+               {
+                       instance->removeServices();
+
+                       /* remove client instance */
+                       removeClient(name);
+               }
+               else
+               {
+                       _ERR("client doesn't exist, name [%s]", name);
+               }
+       }
+
+       unsigned int ServerResource::createSession(const char *name, unsigned int handle, unsigned int readerID, vector<ByteArray> &certHashes, void *caller)
+       {
+               unsigned int result = -1;
+               Terminal *temp = NULL;
+               ServiceInstance *instance = NULL;
+
+               if ((instance = getService(name, handle)) != NULL)
+               {
+                       if ((temp = getTerminalByReaderID(readerID)) != NULL)
+                       {
+                               result = instance->openSession(temp, certHashes, caller);
+                       }
+               }
+               else
+               {
+                       _ERR("getService doesn't exist : name [%s], handle [%d]", name, handle);
+               }
+
+               return result;
+       }
+
+       ServerSession *ServerResource::getSession(const char *name, unsigned int handle, unsigned int sessionID)
+       {
+               ServerSession *result = NULL;
+               ServiceInstance *instance = NULL;
+
+               if ((instance = getService(name, handle)) != NULL)
+               {
+                       result = instance->getSession(sessionID);
+               }
+               else
+               {
+                       _ERR("Session doesn't exist : name [%s], handle [%d], handle [%d]", name, handle, sessionID);
+               }
+
+               return result;
+       }
+
+       bool ServerResource::isValidSessionHandle(const char *name, unsigned int handle, unsigned int session)
+       {
+               ServiceInstance *instance = NULL;
+
+               return (((instance = getService(name, handle)) != NULL) && (instance->isVaildSessionHandle(session)));
+       }
+
+       unsigned int ServerResource::getChannelCount(const char *name, unsigned int handle, unsigned int sessionID)
+       {
+               unsigned int result = -1;
+               ServiceInstance *instance = NULL;
+
+               if ((instance = getService(name, handle)) != NULL)
+               {
+                       result = instance->getChannelCountBySession(sessionID);
+               }
+               else
+               {
+                       _ERR("getService doesn't exist : name [%s], handle [%d]", name, handle);
+               }
+
+               return result;
+       }
+
+       void ServerResource::removeSession(const char *name, unsigned int handle, unsigned int sessionID)
+       {
+               ServiceInstance *instance = NULL;
+
+               if ((instance = getService(name, handle)) != NULL)
+               {
+                       instance->closeSession(sessionID);
+               }
+               else
+               {
+                       _ERR("getService doesn't exist : name [%s], handle [%d]", name, handle);
+               }
+       }
+
+       unsigned int ServerResource::createChannel(const char *name, unsigned int handle, unsigned int sessionID, int channelType, ByteArray aid)
+               throw(ExceptionBase &)
+       {
+               unsigned int result = -1;
+               ServiceInstance *service = NULL;
+
+               if ((service = getService(name, handle)) != NULL)
+               {
+                       if (service->isVaildSessionHandle(sessionID) == true)
+                       {
+                               ServerSession *session = NULL;
+                               Terminal *terminal = NULL;
+
+                               terminal = service->getTerminal(sessionID);
+                               session = service->getSession(sessionID);
+                               if (terminal != NULL && session != NULL)
+                               {
+                                       result = _createChannel(terminal, service, channelType, sessionID, aid);
+                                       if (result == IntegerHandle::INVALID_HANDLE)
+                                       {
+                                               _ERR("create channel failed [%d]", sessionID);
+                                       }
+                               }
+                               else
+                               {
+                                       _ERR("session is invalid [%d]", sessionID);
+                                       throw ExceptionBase(SCARD_ERROR_UNAVAILABLE);
+                               }
+                       }
+                       else
+                       {
+                               _ERR("session is invalid [%d]", sessionID);
+                               throw ExceptionBase(SCARD_ERROR_ILLEGAL_STATE);
+                       }
+               }
+               else
+               {
+                       _ERR("getService is failed, name [%s], handle [%d]", name, handle);
+                       throw ExceptionBase(SCARD_ERROR_UNAVAILABLE);
+               }
+
+               return result;
+       }
+
+       Channel *ServerResource::getChannel(const char *name, unsigned int handle, unsigned int channelID)
+       {
+               Channel *result = NULL;
+               ServiceInstance *instance = NULL;
+
+               if ((instance = getService(name, handle)) != NULL)
+               {
+                       result = instance->getChannel(channelID);
+               }
+               else
+               {
+                       _ERR("Channel doesn't exist : name [%s], handle [%d], handle [%d]", name, handle, channelID);
+               }
+
+               return result;
+       }
+
+       void ServerResource::removeChannel(const char *name, unsigned int handle, unsigned int channelID)
+       {
+               ServiceInstance *instance = NULL;
+
+               if ((instance = getService(name, handle)) != NULL)
+               {
+                       instance->closeChannel(channelID);
+               }
+               else
+               {
+                       _ERR("getService doesn't exist : name [%s], handle [%d]", name, handle);
+               }
+       }
+#else
+       bool ServerResource::createClient(void *ioChannel, int socket,
+               int watchID, int state, int pid)
        {
                bool result = false;
 
                if (getClient(socket) == NULL)
                {
-                       ClientInstance *instance = new ClientInstance(ioChannel, socket, watchID, state, pid);
+                       ClientInstance *instance = new ClientInstance(ioChannel,
+                               socket, watchID, state, pid);
                        if (instance != NULL)
                        {
                                mapClients.insert(make_pair(socket, instance));
@@ -114,12 +417,37 @@ namespace smartcard_service_api
                        }
                        else
                        {
-                               SCARD_DEBUG_ERR("alloc failed");
+                               _ERR("alloc failed");
                        }
                }
                else
                {
-                       SCARD_DEBUG_ERR("client already exist [%d]", socket);
+                       _ERR("client already exist, socket[%d]", socket);
+               }
+
+               return result;
+       }
+
+       bool ServerResource::createClient(int pid)
+       {
+               bool result = false;
+
+               if (getClient(pid) == NULL)
+               {
+                       ClientInstance *instance = new ClientInstance(pid);
+                       if (instance != NULL)
+                       {
+                               mapClients.insert(make_pair(pid, instance));
+                               result = true;
+                       }
+                       else
+                       {
+                               _ERR("alloc failed");
+                       }
+               }
+               else
+               {
+                       _ERR("client already exist, pid[%d]", pid);
                }
 
                return result;
@@ -138,6 +466,19 @@ namespace smartcard_service_api
                return result;
        }
 
+       const ClientInstance *ServerResource::getClient(int socket) const
+       {
+               const ClientInstance *result = NULL;
+               map<int, ClientInstance *>::const_iterator item;
+
+               if ((item = mapClients.find(socket)) != mapClients.end())
+               {
+                       result = item->second;
+               }
+
+               return result;
+       }
+
        void ServerResource::setPID(int socket, int pid)
        {
                map<int, ClientInstance *>::iterator item;
@@ -149,114 +490,281 @@ namespace smartcard_service_api
                }
        }
 
-       int ServerResource::getClientCount()
-       {
-               return (int)mapClients.size();
-       }
-
        void ServerResource::removeClient(int socket)
        {
                map<int, ClientInstance *>::iterator item;
 
                if ((item = mapClients.find(socket)) != mapClients.end())
                {
+#ifndef USE_GDBUS
                        ServerIPC::getInstance()->releaseClient(item->second->getIOChannel(), item->second->getSocket(), item->second->getWatchID());
-
+#endif
                        delete item->second;
                        mapClients.erase(item);
                }
                else
                {
-                       SCARD_DEBUG("client removed already [%d]", socket);
+                       _DBG("client removed already [%d]", socket);
+               }
+       }
+
+       void ServerResource::removeClients()
+       {
+               map<int, ClientInstance *>::iterator item;
+
+               for (item = mapClients.begin(); item != mapClients.end(); item++)
+               {
+#ifndef USE_GDBUS
+                       ServerIPC::getInstance()->releaseClient(item->second->getIOChannel(), item->second->getSocket(), item->second->getWatchID());
+#endif
+                       delete item->second;
+               }
+
+               mapClients.clear();
+       }
+
+       int ServerResource::getClientCount() const
+       {
+               return (int)mapClients.size();
+       }
+
+       ServiceInstance *ServerResource::createService(int socket)
+       {
+               ServiceInstance *result = NULL;
+               ClientInstance *instance = NULL;
+
+               if ((instance = getClient(socket)) != NULL)
+               {
+                       if ((result = instance->createService()) == NULL)
+                       {
+                               _ERR("ClientInstance::createService failed [%d]", socket);
+                       }
+               }
+               else
+               {
+                       _ERR("client doesn't exist [%d]", socket);
+               }
+
+               return result;
+       }
+
+       ServiceInstance *ServerResource::getService(int socket, unsigned int handle)
+       {
+               ServiceInstance *result = NULL;
+               ClientInstance *instance = NULL;
+
+               if ((instance = getClient(socket)) != NULL)
+               {
+                       result = instance->getService(handle);
+               }
+               else
+               {
+                       _ERR("client doesn't exist [%d]", socket);
+               }
+
+               return result;
+       }
+
+       void ServerResource::removeService(int socket, unsigned int handle)
+       {
+               ClientInstance *instance = NULL;
+
+               if ((instance = getClient(socket)) != NULL)
+               {
+                       instance->removeService(handle);
+               }
+               else
+               {
+                       _ERR("client doesn't exist [%d]", socket);
+               }
+       }
+
+       void ServerResource::removeServices(int socket)
+       {
+               ClientInstance *instance = NULL;
+
+               if ((instance = getClient(socket)) != NULL)
+               {
+                       instance->removeServices();
+               }
+               else
+               {
+                       _ERR("client doesn't exist [%d]", socket);
+               }
+       }
+
+       unsigned int ServerResource::createSession(int socket, unsigned int handle, unsigned int readerID, const vector<ByteArray> &certHashes, void *caller)
+       {
+               unsigned int result = -1;
+               Terminal *temp = NULL;
+               ServiceInstance *instance = NULL;
+
+               if ((instance = getService(socket, handle)) != NULL)
+               {
+                       if ((temp = getTerminalByReaderID(readerID)) != NULL)
+                       {
+                               result = instance->openSession(temp, certHashes, caller);
+                       }
+               }
+               else
+               {
+                       _ERR("getService doesn't exist : socket [%d], handle [%d]", socket, handle);
+               }
+
+               return result;
+       }
+
+       ServerSession *ServerResource::getSession(int socket, unsigned int handle, unsigned int sessionID)
+       {
+               ServerSession *result = NULL;
+               ServiceInstance *instance = NULL;
+
+               if ((instance = getService(socket, handle)) != NULL)
+               {
+                       result = instance->getSession(sessionID);
+               }
+               else
+               {
+                       _ERR("Session doesn't exist : socket [%d], handle [%d], handle [%d]", socket, handle, sessionID);
+               }
+
+               return result;
+       }
+
+       bool ServerResource::isValidSessionHandle(int socket, unsigned int handle, unsigned int session)
+       {
+               ServiceInstance *instance = NULL;
+
+               return (((instance = getService(socket, handle)) != NULL) && (instance->isVaildSessionHandle(session)));
+       }
+
+       unsigned int ServerResource::getChannelCount(int socket, unsigned int handle, unsigned int sessionID)
+       {
+               unsigned int result = -1;
+               ServiceInstance *instance = NULL;
+
+               if ((instance = getService(socket, handle)) != NULL)
+               {
+                       result = instance->getChannelCountBySession(sessionID);
+               }
+               else
+               {
+                       _ERR("getService doesn't exist : socket [%d], handle [%d]", socket, handle);
                }
+
+               return result;
        }
 
-       void ServerResource::removeClients()
+       void ServerResource::removeSession(int socket, unsigned int handle, unsigned int sessionID)
        {
-               map<int, ClientInstance *>::iterator item;
+               ServiceInstance *instance = NULL;
 
-               for (item = mapClients.begin(); item != mapClients.end(); item++)
+               if ((instance = getService(socket, handle)) != NULL)
                {
-                       ServerIPC::getInstance()->releaseClient(item->second->getIOChannel(), item->second->getSocket(), item->second->getWatchID());
-
-                       delete item->second;
+                       instance->closeSession(sessionID);
+               }
+               else
+               {
+                       _ERR("getService doesn't exist : socket [%d], handle [%d]", socket, handle);
                }
-
-               mapClients.clear();
        }
 
-       ServiceInstance *ServerResource::createService(int socket, unsigned int context)
+       unsigned int ServerResource::createChannel(int socket, unsigned int handle, unsigned int sessionID, int channelType, const ByteArray &aid)
+               throw(ExceptionBase &)
        {
-               ServiceInstance *result = NULL;
-               ClientInstance *instance = NULL;
+               unsigned int result = -1;
+               ServiceInstance *service = NULL;
 
-               if ((instance = getClient(socket)) != NULL)
+               if ((service = getService(socket, handle)) != NULL)
                {
-                       if ((result = instance->getService(context)) == NULL)
+                       if (service->isVaildSessionHandle(sessionID) == true)
                        {
-                               if ((result = instance->createService(context)) == NULL)
+                               ServerSession *session = NULL;
+                               Terminal *terminal = NULL;
+
+                               terminal = service->getTerminal(sessionID);
+                               session = service->getSession(sessionID);
+                               if (terminal != NULL && session != NULL)
+                               {
+                                       result = _createChannel(terminal, service, channelType, sessionID, aid);
+                                       if (result == IntegerHandle::INVALID_HANDLE)
+                                       {
+                                               _ERR("create channel failed [%d]", sessionID);
+                                       }
+                               }
+                               else
                                {
-                                       SCARD_DEBUG_ERR("ClientInstance::createService failed [%d] [%d]", socket, context);
+                                       _ERR("session is invalid [%d]", sessionID);
+                                       throw ExceptionBase(SCARD_ERROR_UNAVAILABLE);
                                }
                        }
+                       else
+                       {
+                               _ERR("session is invalid [%d]", sessionID);
+                               throw ExceptionBase(SCARD_ERROR_ILLEGAL_STATE);
+                       }
                }
                else
                {
-                       SCARD_DEBUG_ERR("client doesn't exist [%d]", socket);
+                       _ERR("getService is failed [%d] [%d]", socket, handle);
+                       throw ExceptionBase(SCARD_ERROR_UNAVAILABLE);
                }
 
                return result;
        }
 
-       ServiceInstance *ServerResource::getService(int socket, unsigned int context)
+       Channel *ServerResource::getChannel(int socket, unsigned int handle, unsigned int channelID)
        {
-               ServiceInstance *result = NULL;
-               ClientInstance *instance = NULL;
+               Channel *result = NULL;
+               ServiceInstance *instance = NULL;
 
-               if ((instance = getClient(socket)) != NULL)
+               if ((instance = getService(socket, handle)) != NULL)
                {
-                       result = instance->getService(context);
+                       result = instance->getChannel(channelID);
                }
                else
                {
-                       SCARD_DEBUG_ERR("client doesn't exist [%d]", socket);
+                       _ERR("Channel doesn't exist : socket [%d], handle [%d], handle [%d]", socket, handle, channelID);
                }
 
                return result;
        }
 
-       void ServerResource::removeService(int socket, unsigned int context)
+       void ServerResource::removeChannel(int socket, unsigned int handle, unsigned int channelID)
        {
-               ClientInstance *instance = NULL;
+               ServiceInstance *instance = NULL;
 
-               if ((instance = getClient(socket)) != NULL)
+               if ((instance = getService(socket, handle)) != NULL)
                {
-                       instance->removeService(context);
+                       instance->closeChannel(channelID);
                }
                else
                {
-                       SCARD_DEBUG_ERR("client doesn't exist [%d]", socket);
+                       _ERR("getService doesn't exist : socket [%d], handle [%d]", socket, handle);
                }
        }
-
-       void ServerResource::removeServices(int socket)
+#endif
+       Terminal *ServerResource::getTerminal(unsigned int terminalID)
        {
-               ClientInstance *instance = NULL;
+               Terminal *result = NULL;
+               map<unsigned int, Terminal *>::iterator item;
 
-               if ((instance = getClient(socket)) != NULL)
+               if ((item = mapTerminals.find(terminalID)) != mapTerminals.end())
                {
-                       instance->removeServices();
+                       result = item->second;
                }
                else
                {
-                       SCARD_DEBUG_ERR("client doesn't exist [%d]", socket);
+                       _ERR("Terminal doesn't exist [%d]", terminalID);
                }
+
+               return result;
        }
 
-       Terminal *ServerResource::getTerminal(unsigned int terminalID)
+       const Terminal *ServerResource::getTerminal(unsigned int terminalID) const
        {
-               Terminal *result = NULL;
-               map<unsigned int, Terminal *>::iterator item;
+               const Terminal *result = NULL;
+               map<unsigned int, Terminal *>::const_iterator item;
 
                if ((item = mapTerminals.find(terminalID)) != mapTerminals.end())
                {
@@ -264,7 +772,7 @@ namespace smartcard_service_api
                }
                else
                {
-                       SCARD_DEBUG_ERR("Terminal doesn't exist [%d]", terminalID);
+                       _ERR("Terminal doesn't exist [%d]", terminalID);
                }
 
                return result;
@@ -298,116 +806,89 @@ namespace smartcard_service_api
                }
                else
                {
-                       SCARD_DEBUG_ERR("Terminal doesn't exist, reader ID [%d]", readerID);
-               }
-
-               return result;
-       }
-
-       unsigned int ServerResource::getTerminalID(const char *name)
-       {
-               unsigned int result = IntegerHandle::INVALID_HANDLE;
-               map<unsigned int, Terminal *>::iterator item;
-
-               for (item = mapTerminals.begin(); item != mapTerminals.end(); item++)
-               {
-                       if (strncmp(name, item->second->getName(), strlen(name)) == 0)
-                       {
-                               result = item->first;
-                               break;
-                       }
+                       _ERR("Terminal doesn't exist, reader ID [%d]", readerID);
                }
 
                return result;
        }
 
-       unsigned int ServerResource::createSession(int socket, unsigned int context, unsigned int readerID, vector<ByteArray> &certHashes, void *caller)
+       const Terminal *ServerResource::getTerminalByReaderID(unsigned int readerID) const
        {
-               unsigned int result = -1;
-               Terminal *temp = NULL;
-               ServiceInstance *instance = NULL;
+               const Terminal *result = NULL;
+               map<unsigned int, unsigned int>::const_iterator item;
 
-               if ((instance = getService(socket, context)) != NULL)
+               if ((item = mapReaders.find(readerID)) != mapReaders.end())
                {
-                       if ((temp = getTerminalByReaderID(readerID)) != NULL)
-                       {
-                               result = instance->openSession(temp, certHashes, caller);
-                       }
+                       result = getTerminal(item->second);
                }
                else
                {
-                       SCARD_DEBUG_ERR("getService doesn't exist : socket [%d], context [%d]", socket, context);
+                       _ERR("Terminal doesn't exist, reader ID [%d]", readerID);
                }
 
                return result;
        }
 
-       ServerSession *ServerResource::getSession(int socket, unsigned int context, unsigned int sessionID)
+       unsigned int ServerResource::getTerminalID(const char *name) const
        {
-               ServerSession *result = NULL;
-               ServiceInstance *instance = NULL;
+               unsigned int result = IntegerHandle::INVALID_HANDLE;
+               map<unsigned int, Terminal *>::const_iterator item;
 
-               if ((instance = getService(socket, context)) != NULL)
+               for (item = mapTerminals.begin();
+                       item != mapTerminals.end(); item++)
                {
-                       result = instance->getSession(sessionID);
-               }
-               else
-               {
-                       SCARD_DEBUG_ERR("Session doesn't exist : socket [%d], context [%d], handle [%d]", socket, context, sessionID);
+                       if (strncmp(name, item->second->getName(),
+                               strlen(name)) == 0)
+                       {
+                               result = item->first;
+                               break;
+                       }
                }
 
                return result;
        }
 
-       unsigned int ServerResource::getChannelCount(int socket, unsigned int context, unsigned int sessionID)
+       bool ServerResource::_isAuthorizedAccess(ServerChannel *channel,
+               const ByteArray &aid, const vector<ByteArray> &hashes)
        {
-               unsigned int result = -1;
-               ServiceInstance *instance = NULL;
+               bool result = false;
+               AccessControlList *acList = NULL;
 
-               if ((instance = getService(socket, context)) != NULL)
-               {
-                       result = instance->getChannelCountBySession(sessionID);
-               }
-               else
+               /* request open channel sequence */
+               if ((acList = getAccessControlList(channel)) == NULL)
                {
-                       SCARD_DEBUG_ERR("getService doesn't exist : socket [%d], context [%d]", socket, context);
-               }
-
-               return result;
-       }
-
-       void ServerResource::removeSession(int socket, unsigned int context, unsigned int sessionID)
-       {
-               ServiceInstance *instance = NULL;
+                       /* load access control defined by Global Platform */
+                       GPACE *acl = new GPACE();
+                       if (acl != NULL)
+                       {
+                               int ret;
 
-               if ((instance = getService(socket, context)) != NULL)
-               {
-                       instance->closeSession(sessionID);
+                               ret = acl->loadACL(channel);
+                               if (ret >= SCARD_ERROR_OK)
+                               {
+                                       acList = acl;
+                                       addAccessControlList(channel, acList);
+                               }
+                               else
+                               {
+                                       _ERR("unknown error, 0x%x", -ret);
+                                       delete acl;
+                               }
+                       }
+                       else
+                       {
+                               _ERR("alloc failed");
+                       }
                }
                else
                {
-                       SCARD_DEBUG_ERR("getService doesn't exist : socket [%d], context [%d]", socket, context);
+                       acList->loadACL(channel);
                }
-       }
-
-       bool ServerResource::_isAuthorizedAccess(ServerChannel *channel, int pid, ByteArray aid, vector<ByteArray> &hashes)
-       {
-               bool result = true;
-               AccessControlList *acList = NULL;
 
-               /* request open channel sequence */
-               if ((acList = getAccessControlList(channel)) != NULL)
+               if (acList != NULL)
                {
-                       PKCS15 pkcs15(channel);
-
-                       acList->loadACL(channel);
                        result = acList->isAuthorizedAccess(aid, hashes);
                }
-               else
-               {
-                       SCARD_DEBUG_ERR("acList is null");
-                       result = false;
-               }
 
                return result;
        }
@@ -422,28 +903,22 @@ namespace smartcard_service_api
                /* open channel */
                command = APDUHelper::generateAPDU(APDUHelper::COMMAND_OPEN_LOGICAL_CHANNEL, 0, ByteArray::EMPTY);
                rv = terminal->transmitSync(command, response);
-               if (rv == 0 && response.getLength() >= 2)
+               if (rv == 0 && response.size() >= 2)
                {
                        ResponseHelper resp(response);
 
-                       if (resp.getStatus() == 0)
+                       if (resp.getStatus() >= 0)
                        {
                                result = resp.getDataField()[0];
                        }
                        else
                        {
-                               SCARD_DEBUG_ERR("status word [%d][ %02X %02X ]", resp.getStatus(), resp.getSW1(), resp.getSW2());
-                               if (0)
-                               {
-                                       /* TODO : if there is no more channel, return error code */
-                                       SCARD_DEBUG_ERR("no more logical channel");
-                                       result = -2;
-                               }
+                               result = resp.getStatus();
                        }
                }
                else
                {
-                       SCARD_DEBUG_ERR("select apdu is failed, rv [%d], length [%d]", rv, response.getLength());
+                       _ERR("transmitSync failed, rv [%d], length [%d]", rv, response.size());
                }
 
                return result;
@@ -451,7 +926,7 @@ namespace smartcard_service_api
 
        int ServerResource::_closeLogicalChannel(Terminal *terminal, int channelNum)
        {
-               int result = -1;
+               int result = SCARD_ERROR_UNKNOWN;
                int rv = 0;
                ByteArray command;
                ByteArray response;
@@ -459,29 +934,31 @@ namespace smartcard_service_api
                /* open channel */
                command = APDUHelper::generateAPDU(APDUHelper::COMMAND_CLOSE_LOGICAL_CHANNEL, channelNum, ByteArray::EMPTY);
                rv = terminal->transmitSync(command, response);
-               if (rv == 0 && response.getLength() >= 2)
+               if (rv == 0 && response.size() >= 2)
                {
                        ResponseHelper resp(response);
 
-                       if (resp.getStatus() == 0)
+                       if (resp.getStatus() >= 0)
                        {
-                               SCARD_DEBUG("channel closed [%d]", channelNum);
-                               result = 0;
+                               _DBG("channel closed [%d]", channelNum);
+                               result = SCARD_ERROR_OK;
                        }
                        else
                        {
-                               SCARD_DEBUG_ERR("status word [%d][ %02X %02X ]", resp.getStatus(), resp.getSW1(), resp.getSW2());
+                               _ERR("status word [ %02X %02X ]", resp.getSW1(), resp.getSW2());
                        }
                }
                else
                {
-                       SCARD_DEBUG_ERR("select apdu is failed, rv [%d], length [%d]", rv, response.getLength());
+                       _ERR("select apdu is failed, rv [%d], length [%d]", rv, response.size());
                }
 
                return result;
        }
 
-       unsigned int ServerResource::_createChannel(Terminal *terminal, ServiceInstance *service, int channelType, unsigned int sessionID, ByteArray aid)
+       unsigned int ServerResource::_createChannel(Terminal *terminal,
+               ServiceInstance *service, int channelType,
+               unsigned int sessionID, const ByteArray &aid)
                throw(ExceptionBase &)
        {
                unsigned int result = IntegerHandle::INVALID_HANDLE;
@@ -494,11 +971,11 @@ namespace smartcard_service_api
                        channelNum = _openLogicalChannel(terminal);
                        if (channelNum > 0)
                        {
-                               SCARD_DEBUG("channelNum [%d]", channelNum);
+                               _DBG("channelNum [%d]", channelNum);
                        }
                        else
                        {
-                               SCARD_DEBUG_ERR("_openLogicalChannel failed [%d]", channelNum);
+                               _ERR("_openLogicalChannel failed [%d]", channelNum);
                                throw ExceptionBase(SCARD_ERROR_NOT_ENOUGH_RESOURCE);
                        }
                }
@@ -507,7 +984,7 @@ namespace smartcard_service_api
                result = service->openChannel(sessionID, channelNum, ByteArray::EMPTY);
                if (result == IntegerHandle::INVALID_HANDLE)
                {
-                       SCARD_DEBUG_ERR("channel is null.");
+                       _ERR("channel is null.");
 
                        /* close logical channel */
                        if (channelNum > 0)
@@ -520,8 +997,8 @@ namespace smartcard_service_api
                channel = service->getChannel(result);
 
                /* check */
-               if (_isAuthorizedAccess(channel, service->getParent()->getPID(),
-                               aid, service->getParent()->getCertificationHashes()) == true)
+               if (_isAuthorizedAccess(channel, aid,
+                       service->getParent()->getCertificationHashes()) == true)
                {
                        int rv = 0;
 
@@ -530,14 +1007,16 @@ namespace smartcard_service_api
                        {
                                PKCS15 pkcs15(channel);
 
-                               if (pkcs15.isClosed() == false)
+                               rv = pkcs15.select();
+                               if (rv >= SCARD_ERROR_OK)
                                {
                                        /* remove privilege mode */
                                        channel->unsetPrivilegeMode();
+                                       channel->setSelectResponse(pkcs15.getSelectResponse());
                                }
                                else
                                {
-                                       SCARD_DEBUG_ERR("select failed");
+                                       _ERR("select failed, [%x]", -rv);
 
                                        service->closeChannel(result);
                                        throw ExceptionBase(SCARD_ERROR_IO_FAILED);
@@ -548,14 +1027,15 @@ namespace smartcard_service_api
                                FileObject file(channel);
 
                                rv = file.select(aid);
-                               if (rv == FileObject::SUCCESS)
+                               if (rv >= SCARD_ERROR_OK)
                                {
                                        /* remove privilege mode */
                                        channel->unsetPrivilegeMode();
+                                       channel->setSelectResponse(file.getSelectResponse());
                                }
                                else
                                {
-                                       SCARD_DEBUG_ERR("select failed [%d]", rv);
+                                       _ERR("select failed [%x]", -rv);
 
                                        service->closeChannel(result);
                                        throw ExceptionBase(SCARD_ERROR_IO_FAILED);
@@ -564,7 +1044,7 @@ namespace smartcard_service_api
                }
                else
                {
-                       SCARD_DEBUG_ERR("unauthorized access");
+                       _ERR("unauthorized access");
 
                        service->closeChannel(result);
                        throw ExceptionBase(SCARD_ERROR_SECURITY_NOT_ALLOWED);
@@ -573,78 +1053,31 @@ namespace smartcard_service_api
                return result;
        }
 
-       unsigned int ServerResource::createChannel(int socket, unsigned int context, unsigned int sessionID, int channelType, ByteArray aid)
-               throw(ExceptionBase &)
-       {
-               unsigned int result = -1;
-               ServiceInstance *service = NULL;
-
-               if ((service = getService(socket, context)) != NULL)
-               {
-                       if (service->isVaildSessionHandle(sessionID) == true)
-                       {
-                               ServerSession *session = NULL;
-                               Terminal *terminal = NULL;
-
-                               terminal = service->getTerminal(sessionID);
-                               session = service->getSession(sessionID);
-                               if (terminal != NULL && session != NULL)
-                               {
-                                       result = _createChannel(terminal, service, channelType, sessionID, aid);
-                                       if (result == IntegerHandle::INVALID_HANDLE)
-                                       {
-                                               SCARD_DEBUG_ERR("create channel failed [%d]", sessionID);
-                                       }
-                               }
-                               else
-                               {
-                                       SCARD_DEBUG_ERR("session is invalid [%d]", sessionID);
-                                       throw ExceptionBase(SCARD_ERROR_UNAVAILABLE);
-                               }
-                       }
-                       else
-                       {
-                               SCARD_DEBUG_ERR("session is invalid [%d]", sessionID);
-                               throw ExceptionBase(SCARD_ERROR_ILLEGAL_PARAM);
-                       }
-               }
-               else
-               {
-                       SCARD_DEBUG_ERR("getService is failed [%d] [%d]", socket, context);
-                       throw ExceptionBase(SCARD_ERROR_UNAVAILABLE);
-               }
-
-               return result;
-       }
-
-       Channel *ServerResource::getChannel(int socket, unsigned int context, unsigned int channelID)
+       void ServerResource::addAccessControlList(Terminal *terminal, AccessControlList *acl)
        {
-               Channel *result = NULL;
-               ServiceInstance *instance = NULL;
+               map<Terminal *, AccessControlList *>::iterator item;
 
-               if ((instance = getService(socket, context)) != NULL)
+               if ((item = mapACL.find(terminal)) == mapACL.end())
                {
-                       result = instance->getChannel(channelID);
+                       mapACL.insert(make_pair(terminal, acl));
                }
                else
                {
-                       SCARD_DEBUG_ERR("Channel doesn't exist : socket [%d], context [%d], handle [%d]", socket, context, channelID);
+                       item->second = acl;
                }
-
-               return result;
        }
 
-       void ServerResource::removeChannel(int socket, unsigned int context, unsigned int channelID)
+       void ServerResource::addAccessControlList(ServerChannel *channel, AccessControlList *acl)
        {
-               ServiceInstance *instance = NULL;
+               map<Terminal *, AccessControlList *>::iterator item;
 
-               if ((instance = getService(socket, context)) != NULL)
+               if ((item = mapACL.find(channel->getTerminal())) == mapACL.end())
                {
-                       instance->closeChannel(channelID);
+                       mapACL.insert(make_pair(channel->getTerminal(), acl));
                }
                else
                {
-                       SCARD_DEBUG_ERR("getService doesn't exist : socket [%d], context [%d]", socket, context);
+                       item->second = acl;
                }
        }
 
@@ -653,20 +1086,7 @@ namespace smartcard_service_api
                AccessControlList *result = NULL;
                map<Terminal *, AccessControlList *>::iterator item;
 
-               if ((item = mapACL.find(terminal)) == mapACL.end())
-               {
-                       /* load access control */
-                       result = new GPSEACL();
-                       if (result != NULL)
-                       {
-                               mapACL.insert(make_pair(terminal, result));
-                       }
-                       else
-                       {
-                               SCARD_DEBUG_ERR("alloc failed");
-                       }
-               }
-               else
+               if ((item = mapACL.find(terminal)) != mapACL.end())
                {
                        result = item->second;
                }
@@ -679,20 +1099,7 @@ namespace smartcard_service_api
                AccessControlList *result = NULL;
                map<Terminal *, AccessControlList *>::iterator item;
 
-               if ((item = mapACL.find(channel->getTerminal())) == mapACL.end())
-               {
-                       /* load access control */
-                       result = new GPSEACL();
-                       if (result != NULL)
-                       {
-                               mapACL.insert(make_pair(channel->getTerminal(), result));
-                       }
-                       else
-                       {
-                               SCARD_DEBUG_ERR("alloc failed");
-                       }
-               }
-               else
+               if ((item = mapACL.find(channel->getTerminal())) != mapACL.end())
                {
                        result = item->second;
                }
@@ -712,16 +1119,16 @@ namespace smartcard_service_api
                        terminal = (Terminal *)createInstance();
                        if (terminal != NULL)
                        {
-                               SCARD_DEBUG("terminal [%p]", terminal);
+                               _DBG("terminal [%p]", terminal);
                        }
                        else
                        {
-                               SCARD_DEBUG_ERR("terminal is null");
+                               _ERR("terminal is null");
                        }
                }
                else
                {
-                       SCARD_DEBUG_ERR("create_instance is null [%d]", errno);
+                       _ERR("create_instance is null [%d]", errno);
                }
 
                return terminal;
@@ -747,7 +1154,7 @@ namespace smartcard_service_api
 
                                terminal->setStatusCallback(&ServerResource::terminalCallback);
 
-                               SCARD_DEBUG("register success [%s] [%p] [%s] [%p]", library, libHandle, terminal->getName(), terminal);
+                               _DBG("register success [%s] [%p] [%s] [%p]", library, libHandle, terminal->getName(), terminal);
 
                                if (terminal->isSecureElementPresence() == true)
                                {
@@ -758,14 +1165,14 @@ namespace smartcard_service_api
                        }
                        else
                        {
-                               SCARD_DEBUG_ERR("terminal is null [%s]", library);
+                               _ERR("terminal is null [%s]", library);
 
                                dlclose(libHandle);
                        }
                }
                else
                {
-                       SCARD_DEBUG_ERR("it is not se file [%s] [%d]", library, errno);
+                       _ERR("it is not se file [%s] [%d]", library, errno);
                }
 
                return result;
@@ -795,8 +1202,6 @@ namespace smartcard_service_api
                                                snprintf(fullPath, sizeof(fullPath),
                                                        "%s/%s", OMAPI_SE_PATH, entry->d_name);
 
-                                               SCARD_DEBUG("se name [%s]", fullPath);
-
                                                result = appendSELibrary(fullPath);
                                        }
                                }
@@ -842,19 +1247,32 @@ namespace smartcard_service_api
                }
        }
 
-       bool ServerResource::isValidReaderHandle(unsigned int reader)
+       bool ServerResource::isValidReaderHandle(unsigned int reader) const
        {
                return (getTerminalByReaderID(reader) != NULL);
        }
 
-       bool ServerResource::isValidSessionHandle(int socket, unsigned int context, unsigned int session)
+       void ServerResource::getReaders(vector<pair<unsigned int, string> > &readers) const
        {
-               ServiceInstance *instance = NULL;
+               const Terminal *terminal;
+               map<unsigned int, unsigned int>::const_iterator item;
+
+               readers.clear();
 
-               return (((instance = getService(socket, context)) != NULL) && (instance->isVaildSessionHandle(session)));
+               for (item = mapReaders.begin(); item != mapReaders.end(); item++)
+               {
+                       if (item->second != IntegerHandle::INVALID_HANDLE)
+                       {
+                               terminal = getTerminal(item->second);
+                               if (terminal != NULL && terminal->isSecureElementPresence() == true)
+                               {
+                                       readers.push_back(make_pair(item->first, terminal->getName()));
+                               }
+                       }
+               }
        }
 
-       int ServerResource::getReadersInformation(ByteArray &info)
+       int ServerResource::getReadersInformation(ByteArray &info) const
        {
                int result = 0;
                unsigned char *buffer = NULL;
@@ -864,8 +1282,8 @@ namespace smartcard_service_api
 
                if (mapReaders.size() > 0)
                {
-                       Terminal *terminal = NULL;
-                       map<unsigned int, unsigned int>::iterator item;
+                       const Terminal *terminal = NULL;
+                       map<unsigned int, unsigned int>::const_iterator item;
 
                        for (item = mapReaders.begin(); item != mapReaders.end(); item++)
                        {
@@ -912,40 +1330,46 @@ namespace smartcard_service_api
                                        }
                                }
 
-                               info.setBuffer(buffer, length);
+                               info.assign(buffer, length);
                                delete []buffer;
                        }
                        else
                        {
-                               SCARD_DEBUG_ERR("alloc failed");
+                               _ERR("alloc failed");
                                result = -1;
                        }
                }
                else
                {
-                       SCARD_DEBUG("no secure element");
+                       _INFO("no secure element");
                }
 
                return result;
        }
 
-       bool ServerResource::sendMessageToAllClients(Message &msg)
+#ifndef USE_GDBUS
+       bool ServerResource::sendMessageToAllClients(const Message &msg)
        {
                bool result = true;
-               map<int, ClientInstance *>::iterator item;
 
-               for (item = mapClients.begin(); item != mapClients.end(); item++)
+               map<int, ClientInstance *>::const_iterator item;
+
+               for (item = mapClients.begin();
+                       item != mapClients.end(); item++)
                {
-                       if (item->second->sendMessageToAllServices(item->second->getSocket(), msg) == false)
+                       if (item->second->sendMessageToAllServices(
+                               item->second->getSocket(), msg) == false)
                                result = false;
                }
 
                return result;
        }
+#endif
 
-       void ServerResource::terminalCallback(void *terminal, int event, int error, void *user_param)
+       void ServerResource::terminalCallback(const void *terminal, int event,
+               int error, void *user_param)
        {
-               SCARD_DEBUG("terminal [%s], event [%d], error [%d], user_param [%p]", (char *)terminal, event, error, user_param);
+               _DBG("terminal [%s], event [%d], error [%d], user_param [%p]", (char *)terminal, event, error, user_param);
 
                switch (event)
                {
@@ -953,19 +1377,26 @@ namespace smartcard_service_api
                        {
                                ServerResource &instance = ServerResource::getInstance();
                                unsigned int terminalID = IntegerHandle::INVALID_HANDLE;
-                               Message msg;
 
-                               SCARD_DEBUG("[NOTIFY_SE_AVAILABLE]");
+                               _INFO("[NOTIFY_SE_AVAILABLE]");
 
                                terminalID = instance.getTerminalID((char *)terminal);
                                if (terminalID != IntegerHandle::INVALID_HANDLE)
                                {
+                                       unsigned int readerID = instance.createReader(terminalID);
+#ifdef USE_GDBUS
+                                       ServerGDBus::getInstance().emitReaderInserted(readerID, (const char *)terminal);
+#else
+                                       Message msg;
+
                                        /* send all client to refresh reader */
                                        msg.message = msg.MSG_NOTIFY_SE_INSERTED;
-                                       msg.param1 = instance.createReader(terminalID);
-                                       msg.data.setBuffer((unsigned char *)terminal, strlen((char *)terminal) + 1);
+                                       msg.param1 = readerID;
+                                       msg.data.assign((uint8_t *)terminal,
+                                               strlen((char *)terminal) + 1);
 
                                        instance.sendMessageToAllClients(msg);
+#endif
                                }
                        }
                        break;
@@ -974,24 +1405,30 @@ namespace smartcard_service_api
                        {
                                ServerResource &instance = ServerResource::getInstance();
                                unsigned int readerID = IntegerHandle::INVALID_HANDLE;
-                               Message msg;
 
-                               SCARD_DEBUG("[NOTIFY_SE_NOT_AVAILABLE]");
+                               _INFO("[NOTIFY_SE_NOT_AVAILABLE]");
 
                                readerID = instance.getReaderID((char *)terminal);
+#ifdef USE_GDBUS
+                               ServerGDBus::getInstance().emitReaderRemoved(
+                                       readerID, (const char *)terminal);
+#else
+                               Message msg;
 
                                /* send all client to refresh reader */
                                msg.message = msg.MSG_NOTIFY_SE_REMOVED;
                                msg.param1 = readerID;
-                               msg.data.setBuffer((unsigned char *)terminal, strlen((char *)terminal) + 1);
+                               msg.data.assign((uint8_t *)terminal,
+                                       strlen((char *)terminal) + 1);
 
                                instance.sendMessageToAllClients(msg);
+#endif
                                instance.removeReader(readerID);
                        }
                        break;
 
                default :
-                       SCARD_DEBUG("terminal [%s], event [%d], error [%d], user_param [%p]", (char *)terminal, event, error, user_param);
+                       _DBG("terminal [%s], event [%d], error [%d], user_param [%p]", (char *)terminal, event, error, user_param);
                        break;
                }
        }
@@ -1007,16 +1444,18 @@ namespace smartcard_service_api
                return result;
        }
 
-       unsigned int ServerResource::getReaderID(const char *name)
+       unsigned int ServerResource::getReaderID(const char *name) const
        {
-               unsigned int result = IntegerHandle::INVALID_HANDLE, terminalID = IntegerHandle::INVALID_HANDLE;
+               unsigned int result = IntegerHandle::INVALID_HANDLE,
+                       terminalID = IntegerHandle::INVALID_HANDLE;
 
                terminalID = getTerminalID(name);
                if (terminalID != IntegerHandle::INVALID_HANDLE)
                {
-                       map<unsigned int, unsigned int>::iterator item;
+                       map<unsigned int, unsigned int>::const_iterator item;
 
-                       for (item = mapReaders.begin(); item != mapReaders.end(); item++)
+                       for (item = mapReaders.begin();
+                               item != mapReaders.end(); item++)
                        {
                                if (item->second == terminalID)
                                {
@@ -1039,11 +1478,67 @@ namespace smartcard_service_api
                }
        }
 
-} /* namespace smartcard_service_api */
+       bool ServerResource::isAuthorizedNFCAccess(Terminal *terminal,
+               const ByteArray &aid, const vector<ByteArray> &hashes)
+       {
+               bool result = false;
 
-using namespace smartcard_service_api;
+               if (terminal == NULL) {
+                       return result;
+               }
 
-EXTERN_API void server_resource_set_main_loop_instance(void *instance)
-{
-       ServerResource::getInstance().setMainLoopInstance(instance);
-}
+               int num = _openLogicalChannel(terminal);
+               if (num > 0) {
+                       /* create channel instance */
+                       ServerChannel *channel = new ServerChannel(NULL, NULL, num, terminal);
+                       if (channel != NULL) {
+                               AccessControlList *acl = getAccessControlList(channel);
+                               if (acl == NULL) {
+
+                                       /* load access control defined by Global Platform */
+                                       acl = new GPACE();
+                                       if (acl != NULL) {
+                                               int ret;
+
+                                               ret = acl->loadACL(channel);
+                                               if (ret >= SCARD_ERROR_OK) {
+                                                       addAccessControlList(channel, acl);
+                                               } else {
+                                                       _ERR("unknown error, 0x%x", -ret);
+
+                                                       delete acl;
+                                                       acl = NULL;
+                                               }
+                                       } else {
+                                               _ERR("alloc failed");
+                                       }
+                               } else {
+                                       acl->updateACL(channel);
+                               }
+
+                               if (acl != NULL) {
+                                       result = acl->isAuthorizedNFCAccess(aid, hashes);
+                               } else {
+                                       _ERR("acl is null");
+                               }
+
+                               delete channel;
+                       } else {
+                               _ERR("alloc failed");
+                       }
+               } else {
+                       _ERR("_openLogicalChannel failed");
+               }
+
+               return result;
+       }
+
+       void ServerResource::finish()
+       {
+               if (getClientCount() == 0) {
+                       _INFO("no client connected. terminate server");
+
+                       smartcard_daemon_exit();
+               }
+       }
+} /* namespace smartcard_service_api */
index 534fb95..cc4fc5c 100644 (file)
 
 /* local header */
 #include "Debug.h"
-#include "Message.h"
 #include "TerminalInterface.h"
-#include "ServerSEService.h"
+#ifndef USE_GDBUS
+#include "Message.h"
+#include "ServerIPC.h"
+#endif
 #include "ServerResource.h"
+#include "ServerSEService.h"
 
 namespace smartcard_service_api
 {
-#define OMAPI_SE_PATH LIBPATH"/se"
+#define OMAPI_SE_PATH "/usr/lib/se"
 
        ServerSEService::ServerSEService():SEServiceHelper()
        {
@@ -62,16 +65,16 @@ namespace smartcard_service_api
                        terminal = (Terminal *)createInstance();
                        if (terminal != NULL)
                        {
-                               SCARD_DEBUG("terminal [%p]", terminal);
+                               _DBG("terminal [%p]", terminal);
                        }
                        else
                        {
-                               SCARD_DEBUG_ERR("terminal is null");
+                               _ERR("terminal is null");
                        }
                }
                else
                {
-                       SCARD_DEBUG_ERR("create_instance is null [%d]", errno);
+                       _ERR("create_instance is null [%d]", errno);
                }
 
                return terminal;
@@ -90,11 +93,11 @@ namespace smartcard_service_api
                        terminal = createInstance(libHandle);
                        if (terminal != NULL)
                        {
-                               SCARD_DEBUG("SE info : [%s] [%s]", library, terminal->getName());
+                               _DBG("SE info : [%s] [%s]", library, terminal->getName());
 
                                libraries.push_back(libHandle);
 
-                               pair<char *, Terminal *> newPair(terminal->getName(), terminal);
+                               pair<string, Terminal *> newPair(terminal->getName(), terminal);
                                mapTerminals.insert(newPair);
 
                                if (terminal->isSecureElementPresence() == true)
@@ -102,33 +105,33 @@ namespace smartcard_service_api
                                        ServerReader *reader = new ServerReader(this, terminal->getName(), terminal);
                                        if (reader != NULL)
                                        {
-                                               SCARD_DEBUG("register success [%s]", terminal->getName());
+                                               _DBG("register success [%s]", terminal->getName());
 
                                                readers.push_back(reader);
                                        }
                                        else
                                        {
-                                               SCARD_DEBUG_ERR("ServerReader alloc failed [%s]", terminal->getName());
+                                               _ERR("ServerReader alloc failed [%s]", terminal->getName());
                                                /* throw exception */
                                        }
                                }
                                else
                                {
-                                       SCARD_DEBUG("SE is not ready [%s]", terminal->getName());
+                                       _DBG("SE is not ready [%s]", terminal->getName());
                                }
 
                                result = true;
                        }
                        else
                        {
-                               SCARD_DEBUG_ERR("createInstance failed [%s]", library);
+                               _ERR("createInstance failed [%s]", library);
 
                                dlclose(libHandle);
                        }
                }
                else
                {
-                       SCARD_DEBUG_ERR("it is not se file [%s] [%d]", library, errno);
+                       _ERR("it is not se file [%s] [%d]", library, errno);
                }
 
                return result;
@@ -155,8 +158,6 @@ namespace smartcard_service_api
 
                                        snprintf(fullPath, sizeof(fullPath), "%s/%s", OMAPI_SE_PATH, entry->d_name);
 
-                                       SCARD_DEBUG("se name [%s]", fullPath);
-
                                        result = appendSELibrary(fullPath);
                                }
                        }
@@ -189,17 +190,20 @@ namespace smartcard_service_api
 
        bool ServerSEService::dispatcherCallback(void *message, int socket)
        {
+#ifndef USE_GDBUS
                int count;
                ByteArray info;
                Message *msg = (Message *)message;
                Message response(*msg);
                ServerResource &resource = ServerResource::getInstance();
+               ServiceInstance *service;
 
-               if (resource.createService(socket, msg->error) != NULL)
+               if ((service = resource.createService(socket)) != NULL)
                {
-                       SCARD_DEBUG_ERR("client added : pid [%d]", msg->error);
+                       _ERR("client added : pid [%d]", msg->error);
 
                        response.error = SCARD_ERROR_OK;
+                       response.param2 = service->getHandle();
 
                        if ((count = resource.getReadersInformation(info)) > 0)
                        {
@@ -208,46 +212,55 @@ namespace smartcard_service_api
                        }
                        else
                        {
-                               SCARD_DEBUG("no secure elements");
+                               _DBG("no secure elements");
                                response.param1 = 0;
                        }
                }
                else
                {
-                       SCARD_DEBUG_ERR("createClient failed");
+                       _ERR("createClient failed");
 
                        response.error = SCARD_ERROR_OUT_OF_MEMORY;
                }
 
                /* response to client */
-               ServerIPC::getInstance()->sendMessage(socket, &response);
-
+               ServerIPC::getInstance()->sendMessage(socket, response);
+#endif
                return false;
        }
 
-       void ServerSEService::terminalCallback(void *terminal, int event, int error, void *user_param)
+       void ServerSEService::terminalCallback(const void *terminal, int event, int error, void *user_param)
        {
-               Message msg;
-//             Terminal *term = NULL;
-
                switch (event)
                {
                case Terminal::NOTIFY_SE_AVAILABLE :
-                       /* send all client to refresh reader */
-                       msg.message = msg.MSG_NOTIFY_SE_INSERTED;
-                       msg.data.setBuffer((unsigned char *)terminal,
-                               strlen((char *)terminal) + 1);
+                       {
+#ifndef USE_GDBUS
+                               Message msg;
+
+                               /* send all client to refresh reader */
+                               msg.message = msg.MSG_NOTIFY_SE_INSERTED;
+                               msg.data.assign((unsigned char *)terminal,
+                                       strlen((char *)terminal) + 1);
 
-                       ServerResource::getInstance().sendMessageToAllClients(msg);
+                               ServerResource::getInstance().sendMessageToAllClients(msg);
+#endif
+                       }
                        break;
 
                case Terminal::NOTIFY_SE_NOT_AVAILABLE :
-                       /* send all client to refresh reader */
-                       msg.message = msg.MSG_NOTIFY_SE_REMOVED;
-                       msg.data.setBuffer((unsigned char *)terminal,
-                               strlen((char *)terminal) + 1);
+                       {
+#ifndef USE_GDBUS
+                               Message msg;
+
+                               /* send all client to refresh reader */
+                               msg.message = msg.MSG_NOTIFY_SE_REMOVED;
+                               msg.data.assign((unsigned char *)terminal,
+                                       strlen((char *)terminal) + 1);
 
-                       ServerResource::getInstance().sendMessageToAllClients(msg);
+                               ServerResource::getInstance().sendMessageToAllClients(msg);
+#endif
+                       }
                        break;
 
                default :
index 0b8fcb9..fcbc37a 100644 (file)
 #include "ServerReader.h"
 #include "ServerChannel.h"
 #include "APDUHelper.h"
-#include "GPSEACL.h"
+#include "GPACE.h"
 
 namespace smartcard_service_api
 {
-       ServerSession::ServerSession(ServerReader *reader, vector<ByteArray> &certHashes, void *caller, Terminal *terminal):SessionHelper(reader)
+       ServerSession::ServerSession(ServerReader *reader,
+               const vector<ByteArray> &certHashes,
+               void *caller, Terminal *terminal) : SessionHelper(reader)
        {
-               this->caller = NULL;
                this->terminal = NULL;
 
-               if (caller == NULL || terminal == NULL)
+               if (terminal == NULL)
                {
-                       SCARD_DEBUG_ERR("invalid param");
+                       _ERR("invalid param");
 
                        return;
                }
 
-               this->caller = caller;
                this->terminal = terminal;
                this->certHashes = certHashes;
        }
@@ -53,10 +53,22 @@ namespace smartcard_service_api
                        closeSync();
        }
 
-       ByteArray ServerSession::getATRSync()
+       const ByteArray ServerSession::getATRSync()
                throw(ErrorIO &, ErrorIllegalState &)
        {
                /* call get atr to terminal */
+               if (atr.isEmpty()) {
+                       if (terminal != NULL) {
+                               int error = terminal->getATRSync(atr);
+
+                               if (error < SCARD_ERROR_OK) {
+                                       _ERR("getATRSync failed, [%d]", error);
+                               }
+                       } else {
+                               _ERR("terminal is null.");
+                       }
+               }
+
                return atr;
        }
 
@@ -84,54 +96,62 @@ namespace smartcard_service_api
                channels.clear();
        }
 
-       Channel *ServerSession::openBasicChannelSync(ByteArray aid)
+       Channel *ServerSession::openBasicChannelSync(const ByteArray &aid)
                throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &)
        {
                return openBasicChannelSync(aid, NULL);
        }
 
-       Channel *ServerSession::openBasicChannelSync(ByteArray aid, void *caller)
+       Channel *ServerSession::openBasicChannelSync(const ByteArray &aid, void *caller)
                throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &)
        {
                ServerChannel *channel = NULL;
                return channel;
        }
 
-       Channel *ServerSession::openBasicChannelSync(unsigned char *aid, unsigned int length)
+       Channel *ServerSession::openBasicChannelSync(const unsigned char *aid, unsigned int length)
                throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &)
        {
-               return openBasicChannelSync(ByteArray(aid, length));
+               ByteArray temp(aid, length);
+
+               return openBasicChannelSync(temp);
        }
 
-       Channel *ServerSession::openBasicChannelSync(unsigned char *aid, unsigned int length, void *caller)
+       Channel *ServerSession::openBasicChannelSync(const unsigned char *aid, unsigned int length, void *caller)
                throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &)
        {
-               return openBasicChannelSync(ByteArray(aid, length), caller);
+               ByteArray temp(aid, length);
+
+               return openBasicChannelSync(temp, caller);
        }
 
-       Channel *ServerSession::openLogicalChannelSync(ByteArray aid)
+       Channel *ServerSession::openLogicalChannelSync(const ByteArray &aid)
                throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &)
        {
                return openLogicalChannelSync(aid, NULL);
        }
 
-       Channel *ServerSession::openLogicalChannelSync(ByteArray aid, void *caller)
+       Channel *ServerSession::openLogicalChannelSync(const ByteArray &aid, void *caller)
                throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &)
        {
                ServerChannel *channel = NULL;
                return channel;
        }
 
-       Channel *ServerSession::openLogicalChannelSync(unsigned char *aid, unsigned int length)
+       Channel *ServerSession::openLogicalChannelSync(const unsigned char *aid, unsigned int length)
                throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &)
        {
-               return openLogicalChannelSync(ByteArray(aid, length), NULL);
+               ByteArray temp(aid, length);
+
+               return openLogicalChannelSync(temp, NULL);
        }
 
-       Channel *ServerSession::openLogicalChannelSync(unsigned char *aid, unsigned int length, void *caller)
+       Channel *ServerSession::openLogicalChannelSync(const unsigned char *aid, unsigned int length, void *caller)
                throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &)
        {
-               return openLogicalChannelSync(ByteArray(aid, length), caller);
+               ByteArray temp(aid, length);
+
+               return openLogicalChannelSync(temp, caller);
        }
 
 } /* namespace smartcard_service_api */
index 94979dd..c7c1129 100644 (file)
 
 namespace smartcard_service_api
 {
-       unsigned int ServiceInstance::openSession(Terminal *terminal, vector<ByteArray> &certHashes, void *caller)
+       ServiceInstance::ServiceInstance(ClientInstance *parent) :
+               parent(parent)
+       {
+               handle = IntegerHandle::assignHandle();
+       }
+
+       ServiceInstance::~ServiceInstance()
+       {
+               closeSessions();
+
+               if (handle != IntegerHandle::INVALID_HANDLE) {
+                       IntegerHandle::releaseHandle(handle);
+                       handle = IntegerHandle::INVALID_HANDLE;
+               }
+       }
+
+       unsigned int ServiceInstance::openSession(Terminal *terminal, const vector<ByteArray> &certHashes, void *caller)
        {
                unsigned int handle = IntegerHandle::assignHandle();
 
@@ -96,7 +112,7 @@ namespace smartcard_service_api
                mapSessions.clear();
        }
 
-       unsigned int ServiceInstance::openChannel(unsigned int session, int channelNum, ByteArray response)
+       unsigned int ServiceInstance::openChannel(unsigned int session, int channelNum, const ByteArray &response)
        {
                Terminal *terminal = getTerminal(session);
                ServerChannel *channel = NULL;
@@ -114,7 +130,7 @@ namespace smartcard_service_api
                }
                else
                {
-                       SCARD_DEBUG_ERR("alloc failed");
+                       _ERR("alloc failed");
                }
 
                return handle;
index e4c883d..65f3006 100644 (file)
 /* standard library header */
 #include <map>
 #include <vector>
+#include <string>
+#ifndef USE_GDBUS
 #include <glib.h>
+#endif
 
 /* SLP library header */
 
 /* local header */
+#ifndef USE_GDBUS
 #include "Message.h"
+#endif
 #include "ServiceInstance.h"
 
 namespace smartcard_service_api
 {
        class ClientInstance
        {
-       private:
+       private :
+#ifdef USE_GDBUS
+               string name;
+#else
                void *ioChannel;
                int socket;
                int watchID;
                int state;
-               int pid;
+#endif
+               pid_t pid;
                vector<ByteArray> certHashes;
                map<unsigned int, ServiceInstance *> mapServices;
 
-               static gboolean _getCertificationHashes(gpointer user_data);
-
-       public:
-               ClientInstance(void *ioChannel, int socket, int watchID, int state, int pid)
+       public :
+#ifdef USE_GDBUS
+               ClientInstance(const char *name, pid_t pid) :
+                       name(name), pid(pid)
+               {
+               }
+#else
+               ClientInstance(void *ioChannel, int socket, int watchID,
+                       int state, int pid) : ioChannel(ioChannel),
+                       socket(socket), watchID(watchID), state(state), pid(pid)
                {
-                       this->ioChannel = ioChannel;
-                       this->socket = socket;
-                       this->watchID = watchID;
-                       this->state = state;
-                       this->pid = pid;
                }
-               ~ClientInstance() { removeServices(); }
 
+               ClientInstance(pid_t pid) : ioChannel(NULL),
+                       socket(pid), watchID(0), state(0), pid(pid)
+               {
+               }
+#endif
+               inline ~ClientInstance() { removeServices(); }
+#ifdef USE_GDBUS
+               inline bool operator ==(const char *name) const { return (this->name.compare(name) == 0); }
+#else
                inline bool operator ==(const int &socket) const { return (this->socket == socket); }
+#endif
 
+#ifndef USE_GDBUS
                inline void *getIOChannel() { return ioChannel; }
                inline int getSocket() { return socket; }
                inline int getWatchID() { return watchID; }
                inline int getState() { return state; }
+#endif
+               inline void setPID(int pid) { this->pid = pid; }
+               inline int getPID() const { return pid; }
 
-               void setPID(int pid);
-               inline int getPID() { return pid; }
-
-               ServiceInstance *createService(unsigned int context);
-               ServiceInstance *getService(unsigned int context);
-               void removeService(unsigned int context);
+               ServiceInstance *createService();
+               ServiceInstance *getService(unsigned int handle);
+               void removeService(unsigned int handle);
                void removeServices();
-
-               bool sendMessageToAllServices(int socket, Message &msg);
+               inline size_t getServiceCounts() const { return mapServices.size(); }
+#ifndef USE_GDBUS
+               bool sendMessageToAllServices(int socket, const Message &msg);
+#endif
                void generateCertificationHashes();
 
                inline vector<ByteArray> &getCertificationHashes() { return certHashes; }
-
-               friend gboolean _getCertificationHashes(gpointer user_data);
        };
 } /* namespace smartcard_service_api */
 #endif /* CLIENTINSTANCE_H_ */
index aecef89..1df1576 100644 (file)
@@ -42,7 +42,7 @@ namespace smartcard_service_api
        protected:
                void closeSync()
                        throw(ErrorIO &, ErrorIllegalState &);
-               int transmitSync(ByteArray command, ByteArray &result)
+               int transmitSync(const ByteArray &command, ByteArray &result)
                        throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &);
 
        public:
@@ -51,8 +51,8 @@ namespace smartcard_service_api
                int getChannelNumber() { return channelNum; }
                Terminal *getTerminal() { return terminal; }
 
-               int close(closeCallback callback, void *userParam) { return -1; }
-               int transmit(ByteArray command, transmitCallback callback, void *userParam) { return -1; };
+               int close(closeChannelCallback callback, void *userParam) { return -1; }
+               int transmit(const ByteArray &command, transmitCallback callback, void *userParam) { return -1; };
 
                friend class ServerReader;
                friend class ServerSession;
index 785860f..cd6f652 100644 (file)
@@ -16,7 +16,7 @@
 
 #ifndef SERVERDISPATCHER_H_
 #define SERVERDISPATCHER_H_
-
+#ifndef USE_GDBUS
 /* standard library header */
 
 /* SLP library header */
@@ -41,4 +41,5 @@ namespace smartcard_service_api
        };
 
 } /* namespace smartcard_service_api */
+#endif /* USE_GDBUS */
 #endif /* SERVERDISPATCHER_H_ */
diff --git a/server/include/ServerGDBus.h b/server/include/ServerGDBus.h
new file mode 100644 (file)
index 0000000..8ede3c6
--- /dev/null
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef SERVERGDBUS_H_
+#define SERVERGDBUS_H_
+#ifdef USE_GDBUS
+/* standard library header */
+#include <glib.h>
+#include <queue>
+#include <vector>
+
+/* SLP library header */
+
+/* local header */
+#include "Synchronous.h"
+#include "GDBusHelper.h"
+#include "smartcard-service-gdbus.h"
+
+using namespace std;
+
+namespace smartcard_service_api
+{
+       typedef void (*dispatcher_cb_t)(vector<void *> &params);
+
+       class GDBusDispatcher : public Synchronous
+       {
+       public :
+               static GDBusDispatcher &getInstance();
+
+               /* push to queue */
+               static void push(dispatcher_cb_t cb, const vector<void *> &params);
+
+       private :
+               std::queue<pair<dispatcher_cb_t, vector<void *> > > q;
+
+               GDBusDispatcher();
+               ~GDBusDispatcher();
+
+               void _push(dispatcher_cb_t cb, const vector<void *> &params);
+               static gboolean dispatch(gpointer user_data);
+       };
+
+       class ServerGDBus
+       {
+       public :
+               GDBusProxy *dbus_proxy;
+
+               static ServerGDBus &getInstance();
+
+               bool init();
+               void deinit();
+
+               /* connect to dbus daemon */
+               bool _init();
+               void _deinit();
+               pid_t getPID(const char *name);
+
+               void emitReaderInserted(unsigned int reader_id,
+                       const char *reader_name);
+               void emitReaderRemoved(unsigned int reader_id,
+                       const char *reader_name);
+
+       private :
+               GDBusConnection *connection;
+
+               SmartcardServiceSeService *seService;
+               SmartcardServiceReader *reader;
+               SmartcardServiceSession *session;
+               SmartcardServiceChannel *channel;
+
+               ServerGDBus();
+               ~ServerGDBus();
+
+               bool initSEService();
+               void deinitSEService();
+
+               bool initReader();
+               void deinitReader();
+
+               bool initSession();
+               void deinitSession();
+
+               bool initChannel();
+               void deinitChannel();
+       };
+} /* namespace smartcard_service_api */
+#endif
+#endif /* SERVERGDBUS_H_ */
index a1f7b70..3dbc322 100644 (file)
@@ -16,7 +16,7 @@
 
 #ifndef SERVERIPC_H_
 #define SERVERIPC_H_
-
+#ifndef USE_GDBUS
 /* standard library header */
 #ifdef __cplusplus
 #include <map>
@@ -69,5 +69,5 @@ void server_ipc_create_listen_socket();
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
-
+#endif /* USE_GDBUS */
 #endif /* SERVERIPC_H_ */
index 307473a..063410b 100644 (file)
@@ -39,10 +39,8 @@ namespace smartcard_service_api
        {
        private:
                Terminal *terminal;
-               ServerChannel *adminChannel;
-               AccessControlList *acList;
 
-               ServerReader(ServerSEService *seService, char *name, Terminal *terminal);
+               ServerReader(ServerSEService *seService, const char *name, Terminal *terminal);
                ~ServerReader();
 
                int openSession(openSessionCallback callback, void *userData) { return -1; }
@@ -52,11 +50,9 @@ namespace smartcard_service_api
                void closeSessions()
                        throw(ErrorIO &, ErrorIllegalState &);
 
-               AccessControlList *getAccessControlList();
-
                ServerSession *openSessionSync()
                        throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &);
-               ServerSession *openSessionSync(vector<ByteArray> &certHashes, void *caller)
+               ServerSession *openSessionSync(const vector<ByteArray> &certHashes, void *caller)
                        throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &);
 
                friend class ServerSEService;
index ea544d8..20f377c 100644 (file)
 #define SERVERRESOURCE_H_
 
 /* standard library header */
-#ifdef __cplusplus
 #include <map>
 #include <vector>
 #include <set>
-#endif /* __cplusplus */
+#include <string>
 
 /* SLP library header */
 
 /* local header */
-#ifdef __cplusplus
 #include "Exception.h"
 #include "Terminal.h"
 #include "Lock.h"
+#ifndef USE_GDBUS
 #include "ServerIPC.h"
 #include "ServerDispatcher.h"
+#endif
 #include "ServerReader.h"
 #include "ServerSession.h"
 #include "ClientInstance.h"
 #include "ServiceInstance.h"
-#endif /* __cplusplus */
 
-#ifdef __cplusplus
 using namespace std;
 
 namespace smartcard_service_api
@@ -65,11 +63,16 @@ namespace smartcard_service_api
                vector<void *> libraries;
                map<unsigned int, Terminal *> mapTerminals; /* terminal unique id <-> terminal instance map */
                map<unsigned int, unsigned int> mapReaders; /* reader unique id <-> terminal unique id map */
+#ifdef USE_GDBUS
+               map<string, ClientInstance *> mapClients; /* client pid <-> client instance map */
+#else
                map<int, ClientInstance *> mapClients; /* client pid <-> client instance map */
+#endif
                map<Terminal *, AccessControlList *> mapACL; /* terminal instance <-> access control instance map */
-               void *mainLoop;
+#ifndef USE_GDBUS
                ServerIPC *serverIPC;
                ServerDispatcher *serverDispatcher;
+#endif
                bool seLoaded;
 
                ServerResource();
@@ -79,86 +82,99 @@ namespace smartcard_service_api
                bool appendSELibrary(char *library);
                void clearSELibraries();
 
-               static void terminalCallback(void *terminal, int event, int error, void *user_param);
+               static void terminalCallback(const void *terminal, int event, int error, void *user_param);
 
                int _openLogicalChannel(Terminal *terminal);
                int _closeLogicalChannel(Terminal *terminal, int channelNum);
-               bool _isAuthorizedAccess(ServerChannel *channel, int pid, ByteArray aid, vector<ByteArray> &hashes);
-               unsigned int _createChannel(Terminal *terminal, ServiceInstance *service, int channelType, unsigned int sessionID, ByteArray aid)
+               bool _isAuthorizedAccess(ServerChannel *channel, const ByteArray &aid, const vector<ByteArray> &hashes);
+               unsigned int _createChannel(Terminal *terminal, ServiceInstance *service, int channelType, unsigned int sessionID, const ByteArray &aid)
                        throw(ExceptionBase &);
+
        public:
                /* static member */
                static ServerResource &getInstance();
 
-               /* non-static member */
-               inline void setMainLoopInstance(void *mainLoop)
-               {
-                       this->mainLoop = mainLoop;
-               }
-               inline void *getMainLoopInstance()
-               {
-                       return this->mainLoop;
-               }
-
                int loadSecureElements();
                void unloadSecureElements();
 
                Terminal *getTerminal(unsigned int terminalID);
+               const Terminal *getTerminal(unsigned int terminalID) const;
                Terminal *getTerminal(const char *name);
                Terminal *getTerminalByReaderID(unsigned int readerID);
-               unsigned int getTerminalID(const char *name);
-               int getReadersInformation(ByteArray &info);
-               bool isValidReaderHandle(unsigned int reader);
+               const Terminal *getTerminalByReaderID(unsigned int readerID) const;
+               unsigned int getTerminalID(const char *name) const;
+               int getReadersInformation(ByteArray &info) const;
+               void getReaders(vector<pair<unsigned int, string> > &readers) const;
+               bool isValidReaderHandle(unsigned int reader) const;
 
                unsigned int createReader(unsigned int terminalID);
-               unsigned int getReaderID(const char *name);
+               unsigned int getReaderID(const char *name) const;
                void removeReader(unsigned int readerID);
 
+#ifdef USE_GDBUS
+               bool createClient(const char *name, pid_t pid);
+               ClientInstance *getClient(const char *name);
+               void removeClient(const char *name);
+               void removeClients();
+               int getClientCount() const;
+
+               ServiceInstance *createService(const char *name);
+               ServiceInstance *getService(const char *name, unsigned int handle);
+               void removeService(const char *name, unsigned int handle);
+               void removeServices(const char *name);
+
+               unsigned int createSession(const char *name, unsigned int handle, unsigned int readerID, vector<ByteArray> &certHashes, void *caller);
+               ServerSession *getSession(const char *name, unsigned int handle, unsigned int sessionID);
+               unsigned int getChannelCount(const char *name, unsigned int handle, unsigned int sessionID);
+               void removeSession(const char *name, unsigned int handle, unsigned int session);
+               bool isValidSessionHandle(const char *name, unsigned int handle, unsigned int sessionID);
+
+               unsigned int createChannel(const char *name, unsigned int handle,
+                       unsigned int sessionID, int channelType, ByteArray aid)
+                       throw(ExceptionBase &);
+               Channel *getChannel(const char *name, unsigned int handle, unsigned int channelID);
+               void removeChannel(const char *name, unsigned int handle, unsigned int channelID);
+#else
                bool createClient(void *ioChannel, int socket, int watchID, int state, int pid);
+               bool createClient(int pid);
                ClientInstance *getClient(int socket);
+               const ClientInstance *getClient(int socket) const;
                void setPID(int socket, int pid);
-               int getClientCount();
                void removeClient(int socket);
                void removeClients();
+               int getClientCount() const;
 
-               ServiceInstance *createService(int socket, unsigned int context);
-               ServiceInstance *getService(int socket, unsigned int context);
-               void removeService(int socket, unsigned int context);
+               ServiceInstance *createService(int socket);
+               ServiceInstance *getService(int socket, unsigned int handle);
+               void removeService(int socket, unsigned int handle);
                void removeServices(int socket);
 
-               unsigned int createSession(int socket, unsigned int context, unsigned int readerID, vector<ByteArray> &certHashes, void *caller);
-               ServerSession *getSession(int socket, unsigned int context, unsigned int sessionID);
-               unsigned int getChannelCount(int socket, unsigned int context, unsigned int sessionID);
-               void removeSession(int socket, unsigned int context, unsigned int session);
-               bool isValidSessionHandle(int socket, unsigned int context, unsigned int sessionID);
+               unsigned int createSession(int socket, unsigned int handle, unsigned int readerID, const vector<ByteArray> &certHashes, void *caller);
+               ServerSession *getSession(int socket, unsigned int handle, unsigned int sessionID);
+               unsigned int getChannelCount(int socket, unsigned int handle, unsigned int sessionID);
+               void removeSession(int socket, unsigned int handle, unsigned int session);
+               bool isValidSessionHandle(int socket, unsigned int handle, unsigned int sessionID);
 
-               unsigned int createChannel(int socket, unsigned int context,
-                       unsigned int sessionID, int channelType, ByteArray aid)
+               unsigned int createChannel(int socket, unsigned int handle,
+                       unsigned int sessionID, int channelType, const ByteArray &aid)
                        throw(ExceptionBase &);
-               Channel *getChannel(int socket, unsigned int context, unsigned int channelID);
-               void removeChannel(int socket, unsigned int context, unsigned int channelID);
-
+               Channel *getChannel(int socket, unsigned int handle, unsigned int channelID);
+               void removeChannel(int socket, unsigned int handle, unsigned int channelID);
+#endif
+               void addAccessControlList(Terminal *terminal, AccessControlList *acl);
+               void addAccessControlList(ServerChannel *channel, AccessControlList *acl);
                AccessControlList *getAccessControlList(Terminal *terminal);
                AccessControlList *getAccessControlList(ServerChannel *channel);
+#ifndef USE_GDBUS
+               bool sendMessageToAllClients(const Message &msg);
+#endif
+               bool isAuthorizedNFCAccess(Terminal *terminal, const ByteArray &aid,
+                       const vector<ByteArray> &hashes);
 
-               bool sendMessageToAllClients(Message &msg);
+               void finish();
 
                friend void terminalCallback(void *terminal, int event, int error, void *user_param);
        };
 
 } /* namespace smartcard_service_api */
-#endif /* __cplusplus */
-
-/* export C API */
-#ifdef __cplusplus
-extern "C"
-{
-#endif /* __cplusplus */
-
-void server_resource_set_main_loop_instance(void *instance);
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-
 #endif /* SERVERRESOURCE_H_ */
index 2be3b37..fd0c471 100644 (file)
@@ -35,7 +35,7 @@ namespace smartcard_service_api
        {
        private:
                vector<void *> libraries;
-               map<char *, Terminal *> mapTerminals;
+               map<string, Terminal *> mapTerminals;
 
                ServerSEService();
                ~ServerSEService();
@@ -46,7 +46,7 @@ namespace smartcard_service_api
                int openSELibraries();
                void closeSELibraries();
 
-               static void terminalCallback(void *terminal, int event, int error, void *user_param);
+               static void terminalCallback(const void *terminal, int event, int error, void *user_param);
                static bool dispatcherCallback(void *message, int socket);
 
        public:
@@ -54,7 +54,8 @@ namespace smartcard_service_api
 
                void shutdown() {}
                void shutdownSync() {}
-               friend void terminalCallback(char *name, int event, int error, void *user_param);
+
+               friend void terminalCallback(const void *name, int event, int error, void *user_param);
                friend bool dispatcherCallback(void *message, int socket);
                friend class ServerDispatcher;
        };
index eb0767b..a2f66df 100644 (file)
@@ -38,23 +38,24 @@ namespace smartcard_service_api
        class ServerSession : public SessionHelper
        {
        private:
-               void *caller;
                Terminal *terminal;
                vector<ByteArray> certHashes;
 
-               ServerSession(ServerReader *reader, vector<ByteArray> &certHashes, void *caller, Terminal *terminal);
+               ServerSession(ServerReader *reader,
+                       const vector<ByteArray> &certHashes,
+                       void *caller, Terminal *terminal);
 
-               int getATR(getATRCallback callback, void *userData){ return -1; }
-               int close(closeSessionCallback callback, void *userData){ return -1; }
+               int getATR(getATRCallback callback, void *userData) { return -1; }
+               int close(closeSessionCallback callback, void *userData) { return -1; }
 
-               int openBasicChannel(ByteArray aid, openChannelCallback callback, void *userData){ return -1; }
-               int openBasicChannel(unsigned char *aid, unsigned int length, openChannelCallback callback, void *userData){ return -1; }
-               int openLogicalChannel(ByteArray aid, openChannelCallback callback, void *userData){ return -1; }
-               int openLogicalChannel(unsigned char *aid, unsigned int length, openChannelCallback callback, void *userData){ return -1; }
+               int openBasicChannel(const ByteArray &aid, openChannelCallback callback, void *userData){ return -1; }
+               int openBasicChannel(const unsigned char *aid, unsigned int length, openChannelCallback callback, void *userData){ return -1; }
+               int openLogicalChannel(const ByteArray &aid, openChannelCallback callback, void *userData){ return -1; }
+               int openLogicalChannel(const unsigned char *aid, unsigned int length, openChannelCallback callback, void *userData){ return -1; }
        public:
                ~ServerSession();
 
-               ByteArray getATRSync()
+               const ByteArray getATRSync()
                        throw(ErrorIO &, ErrorIllegalState &);
                void closeSync()
                        throw(ErrorIO &, ErrorIllegalState &);
@@ -62,22 +63,22 @@ namespace smartcard_service_api
                void closeChannels()
                        throw(ErrorIO &, ErrorIllegalState &);
 
-               Channel *openBasicChannelSync(ByteArray aid)
+               Channel *openBasicChannelSync(const ByteArray &aid)
                        throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &);
-               Channel *openBasicChannelSync(unsigned char *aid, unsigned int length)
+               Channel *openBasicChannelSync(const unsigned char *aid, unsigned int length)
                        throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &);
-               Channel *openBasicChannelSync(ByteArray aid, void *caller)
+               Channel *openBasicChannelSync(const ByteArray &aid, void *caller)
                        throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &);
-               Channel *openBasicChannelSync(unsigned char *aid, unsigned int length, void *caller)
+               Channel *openBasicChannelSync(const unsigned char *aid, unsigned int length, void *caller)
                        throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &);
 
-               Channel *openLogicalChannelSync(ByteArray aid)
+               Channel *openLogicalChannelSync(const ByteArray &aid)
                        throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &);
-               Channel *openLogicalChannelSync(unsigned char *aid, unsigned int length)
+               Channel *openLogicalChannelSync(const unsigned char *aid, unsigned int length)
                        throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &);
-               Channel *openLogicalChannelSync(ByteArray aid, void *caller)
+               Channel *openLogicalChannelSync(const ByteArray &aid, void *caller)
                        throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &);
-               Channel *openLogicalChannelSync(unsigned char *aid, unsigned int length, void *caller)
+               Channel *openLogicalChannelSync(const unsigned char *aid, unsigned int length, void *caller)
                        throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &);
 
                friend class ServerReader;
index 51f7a77..a1acaea 100644 (file)
@@ -34,34 +34,33 @@ namespace smartcard_service_api
        class ServiceInstance
        {
        private:
-               unsigned int context;
+               unsigned int handle;
                ClientInstance *parent;
                map<unsigned int, pair<ServerSession *, Terminal *> > mapSessions; /* session unique id <-> terminal instance map */
                map<unsigned int, pair<unsigned int, ServerChannel *> > mapChannels; /* channel unique id <-> (session unique id, channel instance) map */
 
        public:
-               ServiceInstance(ClientInstance *parent, unsigned int context)
-               {
-                       this->parent = parent;
-                       this->context = context;
-               }
-               ~ServiceInstance() { closeSessions(); };
+               ServiceInstance(ClientInstance *parent);
+               ~ServiceInstance();
 
-               inline bool operator ==(const unsigned int &context) const { return (this->context == context); }
+               inline unsigned int getHandle() { return handle; }
+
+               inline bool operator ==(const unsigned int &handle) const { return (this->handle == handle); }
                inline bool isVaildSessionHandle(unsigned int handle) { return (mapSessions.find(handle) != mapSessions.end()); }
                inline bool isVaildChannelHandle(unsigned int handle) { return (mapChannels.find(handle) != mapChannels.end()); }
                inline ClientInstance *getParent() { return parent; }
 
-               unsigned int openSession(Terminal *terminal, vector<ByteArray> &certHashes, void *caller);
+               unsigned int openSession(Terminal *terminal, const vector<ByteArray> &certHashes, void *caller);
                ServerSession *getSession(unsigned int session);
                void closeSession(unsigned int session);
                void closeSessions();
 
                Terminal *getTerminal(unsigned int session);
 
-               unsigned int openChannel(unsigned int session, int channelNum, ByteArray response = ByteArray::EMPTY);
+               unsigned int openChannel(unsigned int session, int channelNum, const ByteArray &response = ByteArray::EMPTY);
                ServerChannel *getChannel(/*unsigned int session, */unsigned int channel);
                unsigned int getChannelCountBySession(unsigned int session);
+
                void closeChannel(unsigned int channel);
                void closeChannelsBySession(unsigned int session);
                void closeChannels();
similarity index 58%
rename from common/ReaderHelper.cpp
rename to server/include/smartcard-daemon.h
index 1583a9b..17cc583 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * limitations under the License.
  */
 
-/* standard library header */
-#include <stdio.h>
-#include <string.h>
+#ifndef SMARTCARD_DAEMON_H_
+#define SMARTCARD_DAEMON_H_
 
-/* SLP library header */
+void smartcard_daemon_exit();
 
-/* local header */
-#include "Debug.h"
-#include "ReaderHelper.h"
-
-namespace smartcard_service_api
-{
-       ReaderHelper::ReaderHelper() : seService(NULL), present(false)
-       {
-               memset(name, 0, sizeof(name));
-       }
-} /* namespace smartcard_service_api */
+#endif /* SMARTCARD_DAEMON_H_ */
index 204a686..8b75c5e 100644 (file)
@@ -1,4 +1,3 @@
 [D-BUS Service]
-Name=org.tizen.smartcard_service
+Name=org.tizen.SmartcardService
 Exec=/usr/bin/smartcard-daemon
-User=root
\ No newline at end of file
index 4309bab..a8ddbd3 100644 (file)
 #include <unistd.h>
 #include <string.h>
 #include <glib.h>
+#include <glib-object.h>
 #include <dirent.h>
 #include <fcntl.h>
 #include <sys/stat.h>
 #include <signal.h>
-#ifdef __cplusplus
 #include <vector>
-#endif /* __cplusplus */
-#ifdef USE_AUTOSTART
+#if defined(USE_AUTOSTART) && !defined(USE_GDBUS)
 #include <dbus/dbus-glib.h>
 #include <dbus/dbus-glib-bindings.h>
 #endif
 #include "Debug.h"
 #include "ServerIPC.h"
 #include "ServerResource.h"
+#ifdef USE_GDBUS
+#include "smartcard-service-gdbus.h"
+#include "ServerGDBus.h"
+#else
 #ifdef USE_AUTOSTART
 #include "SmartcardDbus.h"
 #include "smartcard-service-binding.h"
 #endif
+#endif
 
 /* definition */
-#ifdef __cplusplus
 using namespace std;
 using namespace smartcard_service_api;
-#endif /* __cplusplus */
 
 /* global variable */
-#ifdef USE_AUTOSTART
+GMainLoop *main_loop = NULL;
+#if defined(USE_AUTOSTART) && !defined(USE_GDBUS)
 GObject *object = NULL;
 DBusGConnection *connection = NULL;
 #endif
@@ -98,6 +101,32 @@ static void daemonize(void)
 }
 #endif
 
+#ifdef USE_GDBUS
+static void _bus_acquired_cb(GDBusConnection *connection,
+       const gchar *path, gpointer user_data)
+{
+       _DBG("bus path : %s", path);
+
+       ServerResource::getInstance();
+
+       ServerGDBus::getInstance().init();
+}
+
+static void _name_acquired_cb(GDBusConnection *connection,
+       const gchar *name, gpointer user_data)
+{
+       _DBG("name : %s", name);
+}
+
+static void _name_lost_cb(GDBusConnection *connnection,
+       const gchar *name, gpointer user_data)
+{
+       _DBG("name : %s", name);
+
+       ServerGDBus::getInstance().deinit();
+}
+
+#else
 #ifdef USE_AUTOSTART
 G_DEFINE_TYPE(Smartcard_Service, smartcard_service, G_TYPE_OBJECT)
 
@@ -114,26 +143,26 @@ G_STMT_END
 
 GQuark smartcard_service_error_quark(void)
 {
-       SCARD_DEBUG("smartcard_service_error_quark entered");
+       _DBG("smartcard_service_error_quark entered");
 
        return g_quark_from_static_string("smartcard_service_error");
 }
 
 static void smartcard_service_init(Smartcard_Service *smartcard_service)
 {
-       SCARD_DEBUG("smartcard_service_init entered");
+       _DBG("smartcard_service_init entered");
 }
 
 static void smartcard_service_class_init(Smartcard_ServiceClass *smartcard_service_class)
 {
-       SCARD_DEBUG("smartcard_service_class_init entered");
+       _DBG("smartcard_service_class_init entered");
 
        dbus_g_object_type_install_info(SMARTCARD_SERVICE_TYPE, &dbus_glib_smartcard_service_object_info);
 }
 
 gboolean smartcard_service_launch(Smartcard_Service *smartcard_service, guint *result_val, GError **error)
 {
-       SCARD_DEBUG("smartcard_service_launch entered");
+       _DBG("smartcard_service_launch entered");
 
        return TRUE;
 }
@@ -144,7 +173,7 @@ static void _initialize_dbus()
        DBusGProxy *proxy = NULL;
        guint ret = 0;
 
-       SCARD_BEGIN();
+       _BEGIN();
 
        g_type_init();
 
@@ -160,7 +189,7 @@ static void _initialize_dbus()
                {
                        if (!org_freedesktop_DBus_request_name(proxy, SMARTCARD_SERVICE_NAME, 0, &ret, &error))
                        {
-                               SCARD_DEBUG_ERR("Unable to register service: %s", error->message);
+                               _ERR("Unable to register service: %s", error->message);
                                g_error_free(error);
                        }
 
@@ -168,73 +197,93 @@ static void _initialize_dbus()
                }
                else
                {
-                       SCARD_DEBUG_ERR("dbus_g_proxy_new_for_name failed");
+                       _ERR("dbus_g_proxy_new_for_name failed");
                }
        }
        else
        {
-               SCARD_DEBUG_ERR("ERROR: Can't get on system bus [%s]", error->message);
+               _ERR("ERROR: Can't get on system bus [%s]", error->message);
                g_error_free(error);
        }
 
-       SCARD_END();
+       _END();
 }
 
 static void _finalize_dbus()
 {
-       SCARD_BEGIN();
+       _BEGIN();
 
        dbus_g_connection_unregister_g_object(connection, object);
        g_object_unref(object);
 
-       SCARD_END();
+       _END();
 }
 #endif
+#endif
 
 static void __sighandler(int sig)
 {
-       SCARD_DEBUG("signal!! [%d]", sig);
+       _DBG("signal!! [%d]", sig);
 
+#ifdef USE_GDBUS
+#else
 #ifdef USE_AUTOSTART
        _finalize_dbus();
 #endif
+#endif
 }
 
-int main()
+int main(int argc, char *argv[])
 {
-       GMainLoop *loop = NULL;
-
+#ifdef USE_GDBUS
+       guint id = 0;
+#endif
        signal(SIGTERM, &__sighandler);
 
 #ifndef USE_AUTOSTART
        daemonize();
 #endif
 
-       if (!g_thread_supported())
-       {
+       if (!g_thread_supported()) {
                g_thread_init(NULL);
        }
 
-       loop = g_main_new(TRUE);
+       g_type_init();
 
-#ifdef __cplusplus
-       ServerResource::getInstance().setMainLoopInstance(loop);
+       main_loop = g_main_new(TRUE);
+
+#ifdef USE_GDBUS
+       id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
+                       "org.tizen.SmartcardService",
+                       G_BUS_NAME_OWNER_FLAGS_NONE,
+                       _bus_acquired_cb,
+                       _name_acquired_cb,
+                       _name_lost_cb,
+                       NULL,
+                       NULL);
+#else
        ServerIPC::getInstance()->createListenSocket();
-#else /* __cplusplus */
-       server_resource_set_main_loop_instance(loop);
-       server_ipc_create_listen_socket();
-#endif /* __cplusplus */
-
 #ifdef USE_AUTOSTART
        _initialize_dbus();
 #endif
-       g_main_loop_run(loop);
+#endif
+       g_main_loop_run(main_loop);
 
+#ifdef USE_GDBUS
+       if (id)
+               g_bus_unown_name(id);
+#else
 #ifdef USE_AUTOSTART
        _finalize_dbus();
 #endif
+#endif
        /* release secure element.. (pure virtual function problem..) */
        ServerResource::getInstance().unloadSecureElements();
 
        return 0;
 }
+
+void smartcard_daemon_exit()
+{
+       g_main_loop_quit(main_loop);
+}
diff --git a/server/smartcard-service-server.xml b/server/smartcard-service-server.xml
new file mode 100644 (file)
index 0000000..82c673a
--- /dev/null
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<manifest xmlns="http://tizen.org/ns/packages"
+       package="smartcard-service-server"
+       version="0.1.20"
+       install-location="internal-only"
+       type="rpm">
+       <label>Smartcard Service Server</label>
+       <author email="constant.lee@samsung.com" href="www.samsung.com">Sangsoo Lee</author>
+       <author email="wonkyu.kwon@samsung.com" href="www.samsung.com">Wonkyu Kwon</author>
+       <description>Smartcard Service Server</description>
+       <ui-application appid="smartcard-service-server"
+               exec="/usr/bin/smartcard-daemon"
+               nodisplay="true"
+               multiple="false"
+               type="capp"
+               taskmanage="false"
+               mainapp="true">
+               <label>Smartcard Service Server</label>
+       </ui-application>
+</manifest>
diff --git a/smartcard-service-common-devel.manifest b/smartcard-service-common-devel.manifest
new file mode 100644 (file)
index 0000000..ca37499
--- /dev/null
@@ -0,0 +1,6 @@
+<manifest>
+       <request>
+               <domain name="_" />
+       </request>
+</manifest>
+
diff --git a/smartcard-service-common.manifest b/smartcard-service-common.manifest
new file mode 100644 (file)
index 0000000..ca37499
--- /dev/null
@@ -0,0 +1,6 @@
+<manifest>
+       <request>
+               <domain name="_" />
+       </request>
+</manifest>
+
diff --git a/smartcard-service-devel.manifest b/smartcard-service-devel.manifest
new file mode 100644 (file)
index 0000000..ca37499
--- /dev/null
@@ -0,0 +1,6 @@
+<manifest>
+       <request>
+               <domain name="_" />
+       </request>
+</manifest>
+
diff --git a/smartcard-service-server.manifest b/smartcard-service-server.manifest
new file mode 100644 (file)
index 0000000..d4d3a32
--- /dev/null
@@ -0,0 +1,17 @@
+<manifest>
+       <define>
+               <domain name="smartcard-service" />
+               <request>
+                       <smack request="sys-assert::core" type="rwxat" />
+               </request>
+       </define>
+       <assign>
+               <filesystem path="/usr/bin/smartcard-daemon" exec_label="smartcard-service" />
+               <!-- <filesystem path="/usr/bin/smartcard-test-client" exec_label="smartcard-service" /> -->
+               <filesystem path="/usr/share/dbus-1/services/smartcard-service.service" label="_" />
+       </assign>
+       <request>
+               <domain name="smartcard-service" />
+       </request>
+</manifest>
+
diff --git a/smartcard-service.manifest b/smartcard-service.manifest
new file mode 100644 (file)
index 0000000..ca37499
--- /dev/null
@@ -0,0 +1,6 @@
+<manifest>
+       <request>
+               <domain name="_" />
+       </request>
+</manifest>
+
index 6c6878f..b7c3e66 100644 (file)
@@ -7,15 +7,15 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../client/include)
 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
 
 #AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/ SRCS)
-#SET(SRCS "${CMAKE_CURRENT_SOURCE_DIR}/test-client-async.cpp")
-SET(SRCS "${CMAKE_CURRENT_SOURCE_DIR}/test-client.cpp")
+SET(SRCS "${CMAKE_CURRENT_SOURCE_DIR}/test-client-sync.cpp")
+#SET(SRCS "${CMAKE_CURRENT_SOURCE_DIR}/test-client.cpp")
 
 IF("${CMAKE_BUILD_TYPE}" STREQUAL "")
        SET(CMAKE_BUILD_TYPE "Release")
 ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "")
 
 INCLUDE(FindPkgConfig)
-pkg_check_modules(pkgs_test_client REQUIRED glib-2.0 gthread-2.0 gobject-2.0 security-server vconf dlog)
+pkg_check_modules(pkgs_test_client REQUIRED glib-2.0 dlog)
 
 FOREACH(flag ${pkgs_test_client_CFLAGS})
        SET(EXTRA_CXXFLAGS "${EXTRA_CXXFLAGS} ${flag}")
@@ -44,5 +44,5 @@ ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"")
 ADD_DEFINITIONS("-DLOG_TAG=\"SMARTCARD_SERVICE_TEST\"")
 
 ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS})
-TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_test_client_LDFLAGS} "-L../common" "-lsmartcard-service-common" "-L../client" "-lsmartcard-service" "-ldl")
-#INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin)
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_test_client_LDFLAGS} "-L../common" "-lsmartcard-service-common" "-L../client" "-lsmartcard-service" "-pie -ldl")
+INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin)
index 69bb32e..27dc303 100644 (file)
@@ -51,27 +51,27 @@ class TestEventHandler : public SEServiceListener
 {
        void serviceConnected(SEServiceHelper *service, void *userData)
        {
-               SCARD_BEGIN();
+               _BEGIN();
                testConnectedCallback(service, userData);
-               SCARD_END();
+               _END();
        }
 
        void eventHandler(SEServiceHelper *service, char *seName, int event, void *userData)
        {
-               SCARD_BEGIN();
+               _BEGIN();
 
-               SCARD_DEBUG("event occured service [%p], seName[%p], event [%d]", service, seName, event);
+               _INFO("event occurred service [%p], seName[%p], event [%d]", service, seName, event);
 
-               SCARD_END();
+               _END();
        }
 
        void errorHandler(SEServiceHelper *service, int error, void *userData)
        {
-               SCARD_BEGIN();
+               _BEGIN();
 
-               SCARD_DEBUG("error occured service [%p], error [%d]", service, error);
+               _ERR("error occurred service [%p], error [%d]", service, error);
 
-               SCARD_END();
+               _END();
        }
 };
 
@@ -81,87 +81,99 @@ void testConnectedCallback(SEServiceHelper *service, void *userData)
 {
        vector<ReaderHelper *> readers;
        user_context_t *context = (user_context_t *)userData;
+       uint8_t buffer[] = { 0xA0, 0x00, 0x00, 0x00, 0x63, 0x50, 0x4B, 0x43, 0x53, 0x2D, 0x31, 0x35 };
+//     uint8_t buffer[] = { 0xA0, 0x00, 0x00, 0x00, 0x63, 0x50, 0x4B, 0x43, 0x53, 0x2D, 0x31, 0x35 };
 
-       SCARD_BEGIN();
+       _BEGIN();
 
        if (service != NULL)
        {
-               SCARD_DEBUG("callback called, service [%p]", service);
+               _DBG("callback called, service [%p]", service);
 
                context->clientService = service;
 
                readers = service->getReaders();
 
-               if (readers.size() > 0)
+               size_t i;
+               for (i = 0; i < readers.size(); i++)
                {
                        Reader *reader = NULL;
 
-                       reader = (Reader *)readers[0];
+                       reader = (Reader *)readers[i];
 
-                       SCARD_DEBUG("reader [%p]", reader);
+                       _DBG("reader [%p]", reader);
 
                        Session *session = (Session *)reader->openSessionSync();
                        if (session != NULL)
                        {
-                               SCARD_DEBUG("session [%p]", session);
+                               _DBG("session [%p]", session);
 
                                ByteArray temp;
-                               temp = session->getATRSync();
-                               SCARD_DEBUG("atr[%d] : %s", temp.getLength(), temp.toString());
+                               try
+                               {
+                                       temp = session->getATRSync();
+                               }
+                               catch (...)
+                               {
+                                       _ERR("exception....");
+                               }
+                               _DBG("atr[%d] : %s", temp.size(), temp.toString().c_str());
 
-                               unsigned char MF[] = { 0xA0, 0x00, 0x00, 0x00, 0x63, 0x50, 0x4B, 0x43, 0x53, 0x2D, 0x31, 0x35 };
                                ByteArray aid;
 
-                               aid.setBuffer(MF, sizeof(MF));
-                               ClientChannel *channel = (ClientChannel *)session->openLogicalChannelSync(aid);
-                               if (channel != NULL)
+                               aid.assign(buffer, sizeof(buffer));
+                               try
                                {
-                                       SCARD_DEBUG("channel [%p]", channel);
-                                       ByteArray response;
-                                       ByteArray data, command;
-                                       int fid = 0x00003150;
-
-                                       response = channel->getSelectResponse();
-                                       SCARD_DEBUG("response : %s", response.toString());
-
-                                       SCARD_DEBUG("isBasicChannel() = %s", channel->isBasicChannel() ? "Basic" : "Logical");
-                                       SCARD_DEBUG("isClosed() = %s", channel->isClosed() ? "Closed" : "Opened");
-
-                                       data.setBuffer((unsigned char *)&fid, 2);
-                                       command = APDUHelper::generateAPDU(APDUHelper::COMMAND_SELECT_BY_ID, 0, data);
-                                       int error = channel->transmitSync(command, response);
-
-                                       SCARD_DEBUG("error : %d, response : %s", error, response.toString());
-
-                                       channel->closeSync();
+                                       ClientChannel *channel = (ClientChannel *)session->openLogicalChannelSync(aid);
+                                       if (channel != NULL)
+                                       {
+                                               _DBG("channel [%p]", channel);
+                                               ByteArray response;
+                                               ByteArray data, command;
+                                               int fid = 0x00003150;
+
+                                               response = channel->getSelectResponse();
+                                               _INFO("response : %s", response.toString().c_str());
+
+                                               _DBG("isBasicChannel() = %s", channel->isBasicChannel() ? "Basic" : "Logical");
+                                               _DBG("isClosed() = %s", channel->isClosed() ? "Closed" : "Opened");
+
+                                               data.assign((unsigned char *)&fid, 2);
+                                               command = APDUHelper::generateAPDU(APDUHelper::COMMAND_SELECT_BY_ID, 0, data);
+                                               int error = channel->transmitSync(command, response);
+
+                                               _INFO("error : %d, response : %s", error, response.toString().c_str());
+
+                                               channel->closeSync();
+                                       }
+                                       else
+                                       {
+                                               _ERR("openLogicalChannelSync failed");
+                                       }
                                }
-                               else
+                               catch (...)
                                {
-                                       SCARD_DEBUG_ERR("openLogicalChannelSync failed");
+                                       _ERR("exception....");
                                }
 
                                session->closeSync();
                        }
                        else
                        {
-                               SCARD_DEBUG_ERR("openSessionSync failed");
+                               _ERR("openSessionSync failed");
                        }
-
-                       service->shutdown();
-               }
-               else
-               {
-                       SCARD_DEBUG_ERR("reader is empty");
                }
+
+               ((SEService *)service)->shutdownSync();
        }
        else
        {
-               SCARD_DEBUG_ERR("service is NULL");
+               _ERR("service is NULL");
        }
 
        g_main_loop_quit(loop);
 
-       SCARD_END();
+       _END();
 }
 
 int main(int argv, char *args[])
index d55d0fe..6397f47 100644 (file)
@@ -50,9 +50,9 @@ class TestEventHandler : public SEServiceListener
 {
        void serviceConnected(SEServiceHelper *service, void *userData)
        {
-               SCARD_BEGIN();
+               _BEGIN();
                testConnectedCallback(service, userData);
-               SCARD_END();
+               _END();
        }
 
        void eventHandler(SEServiceHelper *service, char *seName, int event, void *userData)
@@ -61,15 +61,15 @@ class TestEventHandler : public SEServiceListener
                vector<ReaderHelper *> readers;
                size_t i;
 
-               SCARD_BEGIN();
+               _BEGIN();
 
-               SCARD_DEBUG("event occured service [%p], seName[%s], event [%d], userData [%p]", service, seName, event, userData);
+               _INFO("event occurred service [%p], seName[%s], event [%d], userData [%p]", service, seName, event, userData);
 
                readers = service->getReaders();
 
                for (i = 0; i < readers.size(); i++)
                {
-                       SCARD_DEBUG("Reader[%d] : name [%s], %s", i, readers[i]->getName(), readers[i]->isSecureElementPresent() ? "available" : "unavailable");
+                       _DBG("Reader[%d] : name [%s], %s", i, readers[i]->getName(), readers[i]->isSecureElementPresent() ? "available" : "unavailable");
                }
 
                if (event == 1)
@@ -77,16 +77,16 @@ class TestEventHandler : public SEServiceListener
                        testConnectedCallback(service, userData);
                }
 
-               SCARD_END();
+               _END();
        }
 
        void errorHandler(SEServiceHelper *service, int error, void *userData)
        {
-               SCARD_BEGIN();
+               _BEGIN();
 
-               SCARD_DEBUG("error occured service [%p], error [%d]", service, error);
+               _ERR("error occurred service [%p], error [%d]", service, error);
 
-               SCARD_END();
+               _END();
        }
 };
 
@@ -96,7 +96,7 @@ void testCloseCallback(int error, void *userData)
 {
        user_context_t *context = (user_context_t *)userData;
 
-       SCARD_DEBUG("result [%d], userData [%p]", error, userData);
+       _DBG("result [%d], userData [%p]", error, userData);
 
        context->clientService->shutdown();
 }
@@ -106,14 +106,14 @@ void testTransmitCallback(unsigned char *buffer, unsigned int length, int error,
        ByteArray response(buffer, length);
        user_context_t *context = (user_context_t *)userData;
 
-       SCARD_DEBUG("buffer [%p], length [%d], error [%d], userData [%p]", buffer, length, error, userData);
+       _DBG("buffer [%p], length [%d], error [%d], userData [%p]", buffer, length, error, userData);
 
        context->clientChannel->close(testCloseCallback, userData);
 }
 
 void testOpenChannelCallback(Channel *channel, int error, void *userData)
 {
-       SCARD_DEBUG("channel [%p]", channel);
+       _DBG("channel [%p]", channel);
 
        if (error == 0 && channel != NULL)
        {
@@ -126,18 +126,18 @@ void testOpenChannelCallback(Channel *channel, int error, void *userData)
 
                response = channel->getSelectResponse();
 
-               SCARD_DEBUG("response : %s", response.toString());
+               _INFO("response : %s", response.toString().c_str());
 
-               SCARD_DEBUG("isBasicChannel() = %s", channel->isBasicChannel() ? "Basic" : "Logical");
-               SCARD_DEBUG("isClosed() = %s", channel->isClosed() ? "Closed" : "Opened");
+               _DBG("isBasicChannel() = %s", channel->isBasicChannel() ? "Basic" : "Logical");
+               _DBG("isClosed() = %s", channel->isClosed() ? "Closed" : "Opened");
 
-               data.setBuffer((unsigned char *)&fid, 2);
+               data.assign((unsigned char *)&fid, 2);
                command = APDUHelper::generateAPDU(APDUHelper::COMMAND_SELECT_BY_ID, 0, data);
                context->clientChannel->transmit(command, testTransmitCallback, userData);
        }
        else
        {
-               SCARD_DEBUG_ERR("openBasicChannel failed");
+               _ERR("openBasicChannel failed");
        }
 }
 
@@ -148,9 +148,9 @@ void testGetATRCallback(unsigned char *atr, unsigned int length, int error, void
        ByteArray aid, result(atr, length);
        user_context_t *context = (user_context_t *)userData;
 
-       SCARD_DEBUG("atr[%d] : %s", result.getLength(), result.toString());
+       _DBG("atr[%d] : %s", result.size(), result.toString().c_str());
 
-       aid.setBuffer(MF, sizeof(MF));
+       aid.assign(MF, sizeof(MF));
        context->clientSession->openLogicalChannel(aid, testOpenChannelCallback, userData);
 }
 
@@ -161,7 +161,7 @@ void testCloseSessionCallback(int error, void *userData)
 
 void testOpenSessionCallback(SessionHelper *session, int error, void *userData)
 {
-       SCARD_DEBUG("session [%p]", session);
+       _DBG("session [%p]", session);
 
        if (session != NULL)
        {
@@ -172,7 +172,7 @@ void testOpenSessionCallback(SessionHelper *session, int error, void *userData)
        }
        else
        {
-               SCARD_DEBUG_ERR("openSession failed");
+               _ERR("openSession failed");
        }
 }
 
@@ -181,11 +181,11 @@ void testConnectedCallback(SEServiceHelper *service, void *userData)
        vector<ReaderHelper *> readers;
        user_context_t *context = (user_context_t *)userData;
 
-       SCARD_BEGIN();
+       _BEGIN();
 
        if (service != NULL)
        {
-               SCARD_DEBUG("callback called, service [%p]", service);
+               _DBG("callback called, service [%p]", service);
 
                context->clientService = service;
 
@@ -197,21 +197,21 @@ void testConnectedCallback(SEServiceHelper *service, void *userData)
 
                        reader = (Reader *)readers[0];
 
-                       SCARD_DEBUG("reader [%p]", reader);
+                       _DBG("reader [%p]", reader);
 
                        reader->openSession(testOpenSessionCallback, userData);
                }
                else
                {
-                       SCARD_DEBUG_ERR("reader is empty");
+                       _ERR("reader is empty");
                }
        }
        else
        {
-               SCARD_DEBUG_ERR("service is NULL");
+               _ERR("service is NULL");
        }
 
-       SCARD_END();
+       _END();
 }
 
 int main(int argv, char *args[])
@@ -224,7 +224,7 @@ int main(int argv, char *args[])
        }
        catch (...)
        {
-               SCARD_DEBUG_ERR("exception raised!!!");
+               _ERR("exception raised!!!");
        }
 
        if (service != NULL)