From 037928c46a32e543b21132df725a91d22abba0e9 Mon Sep 17 00:00:00 2001 From: Wonkyu Kwon Date: Thu, 21 Feb 2013 21:49:23 +0900 Subject: [PATCH] Change sequence of loading secure elements - load secure element after receiving 'get reader' message - fix minor bugs Change-Id: If5abf50932e80278969a4ad481ecdbeae7c3c6d0 --- server/ServerDispatcher.cpp | 2 ++ server/ServerIPC.cpp | 2 +- server/ServerResource.cpp | 56 ++++++++++++++++++++++------------------- server/include/ServerResource.h | 1 + 4 files changed, 34 insertions(+), 27 deletions(-) diff --git a/server/ServerDispatcher.cpp b/server/ServerDispatcher.cpp index 2982af9..c502f8a 100644 --- a/server/ServerDispatcher.cpp +++ b/server/ServerDispatcher.cpp @@ -86,6 +86,8 @@ namespace smartcard_service_api ByteArray info; ClientInstance *instance = NULL; + resource->loadSecureElements(); + if ((instance = resource->getClient(socket)) != NULL) { /* update client PID */ diff --git a/server/ServerIPC.cpp b/server/ServerIPC.cpp index 20638de..eb25f24 100644 --- a/server/ServerIPC.cpp +++ b/server/ServerIPC.cpp @@ -245,7 +245,7 @@ ERROR : if (peerSocket >= 0) { - Message *msg = NULL; + Message *msg; /* read message */ if ((msg = retrieveMessage(peerSocket)) != NULL) diff --git a/server/ServerResource.cpp b/server/ServerResource.cpp index adae5c5..ab38f11 100644 --- a/server/ServerResource.cpp +++ b/server/ServerResource.cpp @@ -78,21 +78,20 @@ namespace smartcard_service_api #define OMAPI_SE_PATH "/usr/lib/se" - ServerResource::ServerResource() : mainLoop(NULL) + ServerResource::ServerResource() + : mainLoop(NULL), seLoaded(false) { SCARD_BEGIN(); serverIPC = ServerIPC::getInstance(); serverDispatcher = ServerDispatcher::getInstance(); -#if 1 - loadSecureElements(); -#endif SCARD_END(); } ServerResource::~ServerResource() { + unloadSecureElements(); } ServerResource &ServerResource::getInstance() @@ -840,39 +839,42 @@ namespace smartcard_service_api int ServerResource::loadSecureElements() { - int result; - void *libHandle; - DIR *dir = NULL; - struct dirent *entry = NULL; + int result = 0; - if ((dir = opendir(OMAPI_SE_PATH)) != NULL) + if (seLoaded == false) { - while ((entry = readdir(dir)) != NULL) + DIR *dir; + struct dirent *entry; + + if ((dir = opendir(OMAPI_SE_PATH)) != NULL) { - if (strncmp(entry->d_name, ".", 1) != 0 && strncmp(entry->d_name, "..", 2) != 0) + while ((entry = readdir(dir)) != NULL) { - char fullPath[1024] = { 0, }; - - /* TODO : need additional name rule :) */ + if (strncmp(entry->d_name, ".", 1) != 0 && + strncmp(entry->d_name, "..", 2) != 0) + { + char fullPath[1024]; - /* open each files */ - libHandle = NULL; + /* TODO : need additional name rule :) */ - snprintf(fullPath, sizeof(fullPath), "%s/%s", OMAPI_SE_PATH, entry->d_name); + /* append each files */ + snprintf(fullPath, sizeof(fullPath), + "%s/%s", OMAPI_SE_PATH, entry->d_name); - SCARD_DEBUG("se name [%s]", fullPath); + SCARD_DEBUG("se name [%s]", fullPath); - result = appendSELibrary(fullPath); + result = appendSELibrary(fullPath); + } } - } - closedir(dir); + closedir(dir); - result = 0; - } - else - { - result = -1; + seLoaded = true; + } + else + { + result = -1; + } } return result; @@ -899,6 +901,8 @@ namespace smartcard_service_api } libraries.clear(); + + seLoaded = false; } bool ServerResource::isValidReaderHandle(unsigned int reader) diff --git a/server/include/ServerResource.h b/server/include/ServerResource.h index 5e97ce8..0f345d8 100644 --- a/server/include/ServerResource.h +++ b/server/include/ServerResource.h @@ -69,6 +69,7 @@ namespace smartcard_service_api void *mainLoop; ServerIPC *serverIPC; ServerDispatcher *serverDispatcher; + bool seLoaded; ServerResource(); ~ServerResource(); -- 2.7.4