Minor change
authorWonkyu Kwon <wonkyu.kwon@samsung.com>
Wed, 24 Jul 2013 08:31:21 +0000 (17:31 +0900)
committerWonkyu Kwon <wonkyu.kwon@samsung.com>
Wed, 24 Jul 2013 08:56:38 +0000 (17:56 +0900)
 - assign qualifier for managing instance strictly
 - rename some methods of ByteArray
 - use c++ header

Change-Id: I31b8b9f6d8934e168f7112a7e29be5bde3fa9cc4

99 files changed:
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/ClientIPC.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/GDBusHelper.cpp
common/GPACE.cpp
common/GPARAACL.cpp
common/GPARAM.cpp
common/GPARFACL.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/ProviderHelper.cpp [deleted file]
common/ReaderHelper.cpp [deleted file]
common/SEServiceHelper.cpp [deleted file]
common/SessionHelper.cpp [deleted file]
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/FCI.h
common/include/FileObject.h
common/include/GDBusHelper.h
common/include/GPACE.h
common/include/GPARAACL.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/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/ServerReader.h
server/include/ServerResource.h
server/include/ServerSEService.h
server/include/ServerSession.h
server/include/ServiceInstance.h
test-client/test-client-sync.cpp
test-client/test-client.cpp

index e1cb236..c2ebbd7 100644 (file)
@@ -34,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")
 
index e3fd2df..d42aaa6 100644 (file)
@@ -44,7 +44,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;
@@ -130,7 +130,7 @@ namespace smartcard_service_api
 
                if (callback != NULL) {
                        callback(response.getBuffer(),
-                               response.getLength(),
+                               response.size(),
                                result, param->user_param);
                }
 
@@ -223,7 +223,7 @@ 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)
@@ -287,7 +287,7 @@ 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;
@@ -304,7 +304,7 @@ 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 &)
        {
@@ -350,7 +350,7 @@ 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)
@@ -386,7 +386,7 @@ namespace smartcard_service_api
                return rv;
        }
 
-       int ClientChannel::transmit(ByteArray command, transmitCallback callback, void *userParam)
+       int ClientChannel::transmit(const ByteArray &command, transmitCallback callback, void *userParam)
        {
                int result;
 
@@ -423,7 +423,7 @@ 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;
                        }
@@ -482,7 +482,10 @@ 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;
@@ -512,7 +515,7 @@ namespace smartcard_service_api
                        break;
 
                default:
-                       _DBG("Unknown message : %s", msg->toString());
+                       _DBG("Unknown message : %s", msg->toString().c_str());
                        break;
                }
 
@@ -557,7 +560,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;
 
@@ -591,14 +594,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);
                }
@@ -640,7 +643,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;
@@ -660,9 +663,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 765d33d..4af04ba 100644 (file)
@@ -99,7 +99,7 @@ namespace smartcard_service_api
                case Message::MSG_REQUEST_READERS :
                case Message::MSG_REQUEST_SHUTDOWN :
                        {
-                               DispatcherMsg *tempMsg = new DispatcherMsg(msg);
+                               DispatcherMsg *tempMsg = new DispatcherMsg(*msg);
 
                                if (msg->isSynchronousCall() == false)
                                {
@@ -117,7 +117,7 @@ namespace smartcard_service_api
                /* Reader requests */
                case Message::MSG_REQUEST_OPEN_SESSION :
                        {
-                               DispatcherMsg *tempMsg = new DispatcherMsg(msg);
+                               DispatcherMsg *tempMsg = new DispatcherMsg(*msg);
 
                                if (msg->isSynchronousCall() == false)
                                {
@@ -138,7 +138,7 @@ namespace smartcard_service_api
                case Message::MSG_REQUEST_CLOSE_SESSION :
                case Message::MSG_REQUEST_GET_CHANNEL_COUNT :
                        {
-                               DispatcherMsg *tempMsg = new DispatcherMsg(msg);
+                               DispatcherMsg *tempMsg = new DispatcherMsg(*msg);
 
                                if (msg->isSynchronousCall() == false)
                                {
@@ -157,7 +157,7 @@ namespace smartcard_service_api
                case Message::MSG_REQUEST_TRANSMIT :
                case Message::MSG_REQUEST_CLOSE_CHANNEL :
                        {
-                               DispatcherMsg *tempMsg = new DispatcherMsg(msg);
+                               DispatcherMsg *tempMsg = new DispatcherMsg(*msg);
 
                                if (msg->isSynchronousCall() == false)
                                {
@@ -179,7 +179,7 @@ namespace smartcard_service_api
 
                                for (item = mapSESerivces.begin(); item != mapSESerivces.end(); item++)
                                {
-                                       DispatcherMsg *tempMsg = new DispatcherMsg(msg);
+                                       DispatcherMsg *tempMsg = new DispatcherMsg(*msg);
 
                                        tempMsg->caller = item->second;
 
@@ -195,7 +195,7 @@ namespace smartcard_service_api
 
                                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;
index 2012434..4f6dbb0 100644 (file)
@@ -31,7 +31,7 @@
 
 namespace smartcard_service_api
 {
-       ClientIPC::ClientIPC():IPCHelper()
+       ClientIPC::ClientIPC() : IPCHelper()
        {
 #ifdef USE_AUTOSTART
                _launch_daemon();
@@ -51,9 +51,9 @@ namespace smartcard_service_api
                                if ((error = security_server_request_cookie(buffer, length))
                                        == SECURITY_SERVER_API_SUCCESS)
                                {
-                                       cookie.setBuffer(buffer, length);
+                                       cookie.assign(buffer, length);
 
-                                       _DBG("cookie : %s", cookie.toString());
+                                       _DBG("cookie : %s", cookie.toString().c_str());
                                }
                                else
                                {
@@ -130,7 +130,7 @@ namespace smartcard_service_api
        }
 #endif
 
-       bool ClientIPC::sendMessage(Message *msg)
+       bool ClientIPC::sendMessage(const Message &msg)
        {
                ByteArray stream;
                unsigned int length;
@@ -139,14 +139,14 @@ 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();
 
                _DBG(">>>[SEND]>>> socket [%d], msg [%d], length [%d]",
-                       ipcSocket, msg->message, stream.getLength());
+                       ipcSocket, msg.message, stream.size());
 
                return IPCHelper::sendMessage(ipcSocket, stream);
        }
@@ -205,7 +205,7 @@ namespace smartcard_service_api
                        msg = retrieveMessage();
                        if (msg != NULL)
                        {
-                               DispatcherMsg dispMsg(msg);
+                               DispatcherMsg dispMsg(*msg);
 
                                /* set peer socket */
                                dispMsg.setPeerSocket(ipcSocket);
index b27ded3..c140b04 100644 (file)
@@ -42,8 +42,6 @@ namespace smartcard_service_api
        Reader::Reader(void *context, const char *name, void *handle) :
                ReaderHelper(), context(context), handle(handle)
        {
-               unsigned int length = 0;
-
                _BEGIN();
 
                if (context == NULL || name == NULL || strlen(name) == 0 || handle == NULL)
@@ -55,11 +53,7 @@ namespace smartcard_service_api
 
                this->handle = handle;
                this->context = context;
-
-               length = strlen(name);
-               length = (length < sizeof(this->name)) ? length : sizeof(this->name);
-               memcpy(this->name, name, length);
-
+               this->name = name;
 #ifdef USE_GDBUS
                /* initialize client */
                if (!g_thread_supported())
@@ -169,7 +163,7 @@ 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)
@@ -289,7 +283,7 @@ 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;
                        }
@@ -373,7 +367,7 @@ namespace smartcard_service_api
                        break;
 
                default:
-                       _DBG("unknown [%s]", msg->toString());
+                       _DBG("unknown [%s]", msg->toString().c_str());
                        break;
                }
 
index bc4c139..9136258 100644 (file)
@@ -245,7 +245,7 @@ namespace smartcard_service_api
                        msg.caller = (void *)this;
                        msg.callback = (void *)NULL;
 
-                       if (ClientIPC::getInstance().sendMessage(&msg) == false)
+                       if (ClientIPC::getInstance().sendMessage(msg) == false)
                        {
                                _ERR("time over");
                        }
@@ -288,7 +288,7 @@ 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)
                        {
                                int rv;
 
@@ -388,7 +388,7 @@ namespace smartcard_service_api
                        msg.caller = (void *)this;
                        msg.userParam = context;
 
-                       result = clientIPC->sendMessage(&msg);
+                       result = clientIPC->sendMessage(msg);
                }
 #endif
                _END();
@@ -457,7 +457,7 @@ namespace smartcard_service_api
                return true;
        }
 #endif
-       bool SEService::parseReaderInformation(unsigned int count, ByteArray data)
+       bool SEService::parseReaderInformation(unsigned int count, const ByteArray &data)
        {
                size_t i;
                unsigned int offset = 0;
@@ -466,7 +466,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));
 
@@ -627,7 +627,7 @@ namespace smartcard_service_api
                        break;
 
                default :
-                       _DBG("unknown message [%s]", msg->toString());
+                       _DBG("unknown message [%s]", msg->toString().c_str());
                        break;
                }
 
index de4478c..6951ced 100644 (file)
@@ -145,7 +145,8 @@ namespace smartcard_service_api
                }
 
                if (callback != NULL) {
-                       callback(atr.getBuffer(), atr.getLength(), result, param->user_param);
+                       callback(atr.getBuffer(),
+                               atr.size(), result, param->user_param);
                }
 
                delete param;
@@ -252,7 +253,7 @@ namespace smartcard_service_api
                delete param;
        }
 #endif
-       ByteArray Session::getATRSync()
+       const ByteArray Session::getATRSync()
                throw (ExceptionBase &, ErrorIO &, ErrorSecurity &,
                        ErrorIllegalState &, ErrorIllegalParameter &)
        {
@@ -299,7 +300,7 @@ 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)
@@ -367,7 +368,7 @@ 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;
                                }
@@ -383,7 +384,8 @@ namespace smartcard_service_api
                                result = SCARD_ERROR_OK;
 
                                /* TODO : invoke callback directly */
-                               callback(atr.getBuffer(), atr.getLength(), 0, userData);
+                               callback(atr.getBuffer(),
+                                       atr.size(), 0, userData);
                        }
                }
                else
@@ -438,7 +440,7 @@ 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);
 
@@ -494,7 +496,7 @@ 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;
@@ -527,7 +529,7 @@ 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)
@@ -578,7 +580,7 @@ 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;
                        }
@@ -598,7 +600,7 @@ namespace smartcard_service_api
                return result;
        }
 
-       Channel *Session::openChannelSync(int id, ByteArray &aid)
+       Channel *Session::openChannelSync(int id, const ByteArray &aid)
                throw (ExceptionBase &, ErrorIO &, ErrorIllegalState &,
                        ErrorIllegalParameter &, ErrorSecurity &)
        {
@@ -666,7 +668,7 @@ 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)
@@ -700,7 +702,7 @@ namespace smartcard_service_api
                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;
 
@@ -736,7 +738,7 @@ 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;
                        }
@@ -756,13 +758,13 @@ namespace smartcard_service_api
                return result;
        }
 
-       Channel *Session::openBasicChannelSync(ByteArray &aid)
+       Channel *Session::openBasicChannelSync(const ByteArray &aid)
                throw (ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &)
        {
                return openChannelSync(0, aid);
        }
 
-       Channel *Session::openBasicChannelSync(unsigned char *aid, unsigned int length)
+       Channel *Session::openBasicChannelSync(const unsigned char *aid, unsigned int length)
                throw (ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &)
        {
                ByteArray temp(aid, length);
@@ -770,12 +772,12 @@ namespace smartcard_service_api
                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)
        {
                ByteArray temp(aid, length);
@@ -783,13 +785,13 @@ namespace smartcard_service_api
                return openBasicChannel(temp, callback, userData);
        }
 
-       Channel *Session::openLogicalChannelSync(ByteArray &aid)
+       Channel *Session::openLogicalChannelSync(const ByteArray &aid)
                throw (ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &)
        {
                return openChannelSync(1, aid);
        }
 
-       Channel *Session::openLogicalChannelSync(unsigned char *aid, unsigned int length)
+       Channel *Session::openLogicalChannelSync(const unsigned char *aid, unsigned int length)
                throw (ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &)
        {
                ByteArray temp(aid, length);
@@ -797,12 +799,12 @@ namespace smartcard_service_api
                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)
        {
                ByteArray temp(aid, length);
@@ -892,7 +894,10 @@ 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;
@@ -947,7 +952,7 @@ namespace smartcard_service_api
                        break;
 
                default :
-                       _DBG("unknown message : %s", msg->toString());
+                       _DBG("unknown message : %s", msg->toString().c_str());
                        break;
                }
 
@@ -1074,9 +1079,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);
 
index 3d0f6d2..f8c6676 100644 (file)
@@ -46,7 +46,7 @@ namespace smartcard_service_api
                ByteArray response;
 #endif
                ClientChannel(void *context, Session *session, int channelNum,
-                       ByteArray selectResponse, void *handle);
+                       const ByteArray &selectResponse, void *handle);
                ~ClientChannel();
 
 #ifdef USE_GDBUS
@@ -59,13 +59,13 @@ namespace smartcard_service_api
 #endif
        public:
                int close(closeChannelCallback callback, void *userParam);
-               int transmit(ByteArray command, transmitCallback callback,
+               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 &);
 
index e2d49aa..76f6c21 100644 (file)
@@ -51,7 +51,7 @@ namespace smartcard_service_api
 
        public:
                static ClientIPC &getInstance();
-               bool sendMessage(Message *msg);
+               bool sendMessage(const Message &msg);
        };
 
 } /* namespace open_mobile_api */
index f557c5a..85ac371 100644 (file)
@@ -52,7 +52,7 @@ namespace smartcard_service_api
                SEService();
 
                void addReader(unsigned int handle, const char *name);
-               bool parseReaderInformation(unsigned int count, ByteArray data);
+               bool parseReaderInformation(unsigned int count, const ByteArray &data);
 #ifdef USE_GDBUS
                bool parseReaderInformation(GVariant *variant);
 #else
index 3b44110..3635191 100644 (file)
@@ -51,8 +51,8 @@ namespace smartcard_service_api
                Session(void *context, Reader *reader, void *handle);
                ~Session();
 
-               int openChannel(int id, ByteArray &aid, openChannelCallback callback, void *userData);
-               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
@@ -73,13 +73,13 @@ 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 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);
                int getChannelCount(getChannelCountCallback callback, void * userData);
 
-               ByteArray getATRSync()
+               const ByteArray getATRSync()
                        throw(ExceptionBase &, ErrorIO &, ErrorSecurity &,
                                ErrorIllegalState &, ErrorIllegalParameter &);
 
@@ -87,19 +87,19 @@ namespace smartcard_service_api
                        throw(ExceptionBase &, ErrorIO &, ErrorSecurity &,
                                ErrorIllegalState &, ErrorIllegalParameter &);
 
-               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 *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 &);
 
index f864111..ae5589c 100644 (file)
@@ -28,8 +28,7 @@
 namespace smartcard_service_api
 {
        /* ResponseHelper class */
-       ResponseHelper::ResponseHelper()
-               : status(0)
+       ResponseHelper::ResponseHelper() : status(0)
        {
        }
 
@@ -46,21 +45,21 @@ namespace smartcard_service_api
        {
                bool result = false;
                status = SCARD_ERROR_UNKNOWN;
-               dataField.releaseBuffer();
+               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;
@@ -69,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];
 
@@ -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
                {
-                       _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 44280b4..5fd66ea 100644 (file)
@@ -35,17 +35,17 @@ namespace smartcard_service_api
                listFilters.push_back(item);
        }
 
-       bool AccessRule::isAuthorizedAPDUAccess(const ByteArray &command)
+       bool AccessRule::isAuthorizedAPDUAccess(const ByteArray &command) const
        {
                bool result = false;
 
-               if (command.getLength() < 4) /* apdu header size */
+               if (command.size() < 4) /* apdu header size */
                        return false;
 
                if (listFilters.size() > 0)
                {
                        unsigned int cmd, mask, rule;
-                       vector<pair<ByteArray, ByteArray> >::iterator item;
+                       vector<pair<ByteArray, ByteArray> >::const_iterator item;
 
                        cmd = *(unsigned int *)command.getBuffer();
                        for (item = listFilters.begin(); item != listFilters.end(); item++)
@@ -69,17 +69,17 @@ namespace smartcard_service_api
                return result;
        }
 
-       void AccessRule::printAccessRules()
+       void AccessRule::printAccessRules() const
        {
                if (listFilters.size() > 0)
                {
-                       vector<pair<ByteArray, ByteArray> >::iterator item;
+                       vector<pair<ByteArray, ByteArray> >::const_iterator item;
 
                        _DBG("         +---- Granted APDUs");
 
                        for (item = listFilters.begin(); item != listFilters.end(); item++)
                        {
-                               _DBG("         +----- APDU : %s, Mask : %s", item->first.toString(), item->second.toString());
+                               _DBG("         +----- APDU : %s, Mask : %s", item->first.toString().c_str(), item->second.toString().c_str());
                        }
                }
                else
@@ -90,7 +90,7 @@ namespace smartcard_service_api
                _DBG("         +---- NFC  Access ALLOW : %s", nfcRule ? "ALWAYS" : "NEVER");
        }
 
-       bool AccessRule::isAuthorizedNFCAccess(void)
+       bool AccessRule::isAuthorizedNFCAccess(void) const
        {
                return nfcRule;
        }
@@ -108,6 +108,19 @@ namespace smartcard_service_api
                return result;
        }
 
+       const AccessRule *AccessCondition::getAccessRule(const ByteArray &certHash) const
+       {
+               const AccessRule *result = NULL;
+               map<ByteArray, AccessRule>::const_iterator item;
+
+               item = mapRules.find(certHash);
+               if (item != mapRules.end()) {
+                       result = &item->second;
+               }
+
+               return result;
+       }
+
        void AccessCondition::addAccessRule(const ByteArray &hash)
        {
                AccessRule rule;
@@ -117,38 +130,31 @@ namespace smartcard_service_api
                mapRules.insert(item);
        }
 
-       bool AccessCondition::isAuthorizedAccess(const ByteArray &certHash)
+       bool AccessCondition::isAuthorizedAccess(const ByteArray &certHash) const
        {
-               bool result = false;
-               map<ByteArray, AccessRule>::iterator item;
+               bool result = permission;
+               const AccessRule *rule = getAccessRule(certHash);
 
-               item = mapRules.find(certHash);
-               if (item != mapRules.end())
-               {
+               if (rule != NULL) {
                        result = true;
                }
-               else
-               {
-                       /* TODO */
-                       result = permission;
-               }
 
                return result;
        }
 
-       void AccessCondition::printAccessConditions()
+       void AccessCondition::printAccessConditions() const
        {
                _DBG("   +-- Access Condition");
 
                if (mapRules.size() > 0)
                {
-                       map<ByteArray, AccessRule>::iterator item;
+                       map<ByteArray, AccessRule>::const_iterator item;
 
                        for (item = mapRules.begin(); item != mapRules.end(); item++)
                        {
                                ByteArray temp = item->first;
 
-                               _DBG("   +--- hash : %s", (temp == AccessControlList::ALL_DEVICE_APPS) ? "All device applications" : temp.toString());
+                               _DBG("   +--- hash : %s", (temp == AccessControlList::ALL_DEVICE_APPS) ? "All device applications" : temp.toString().c_str());
                                item->second.printAccessRules();
                        }
                }
@@ -181,7 +187,7 @@ namespace smartcard_service_api
        void AccessCondition::addAPDUAccessRule(const ByteArray &certHash,
                const ByteArray &rule)
        {
-               if (rule.getLength() != 8)
+               if (rule.size() != 8)
                        return;
 
                addAPDUAccessRule(certHash, rule.sub(0, 4), rule.sub(4, 4));
@@ -198,25 +204,25 @@ namespace smartcard_service_api
        }
 
        bool AccessCondition::isAuthorizedAPDUAccess(const ByteArray &certHash,
-               const ByteArray &command)
+               const ByteArray &command) const
        {
                bool result = false;
-               AccessRule *access = getAccessRule(certHash);
+               const AccessRule *rule = getAccessRule(certHash);
 
-               if (access != NULL) {
-                       result = access->isAuthorizedAPDUAccess(command);
+               if (rule != NULL) {
+                       result = rule->isAuthorizedAPDUAccess(command);
                }
 
                return result;
        }
 
-       bool AccessCondition::isAuthorizedNFCAccess(const ByteArray &certHash)
+       bool AccessCondition::isAuthorizedNFCAccess(const ByteArray &certHash) const
        {
                bool result = false;
-               AccessRule *access = getAccessRule(certHash);
+               const AccessRule *rule = getAccessRule(certHash);
 
-               if (access != NULL) {
-                       result = access->isAuthorizedNFCAccess();
+               if (rule != NULL) {
+                       result = rule->isAuthorizedNFCAccess();
                }
 
                return result;
index 3bc9f53..00c9984 100644 (file)
@@ -66,11 +66,11 @@ namespace smartcard_service_api
                return item->second;
        }
 
-       AccessRule *AccessControlList::findAccessRule(const ByteArray &aid,
-               const ByteArray &hash)
+       const AccessRule *AccessControlList::findAccessRule(const ByteArray &aid,
+               const ByteArray &hash) const
        {
-               AccessRule *result = NULL;
-               map<ByteArray, AccessCondition>::iterator item;
+               const AccessRule *result = NULL;
+               map<ByteArray, AccessCondition>::const_iterator item;
 
                item = mapConditions.find(aid);
                if (item != mapConditions.end()) {
@@ -80,8 +80,8 @@ namespace smartcard_service_api
                return result;
        }
 
-       bool AccessControlList::isAuthorizedAccess(ByteArray &aid,
-               ByteArray &certHash)
+       bool AccessControlList::isAuthorizedAccess(const ByteArray &aid,
+               const ByteArray &certHash) const
        {
                vector<ByteArray> hashes;
 
@@ -90,9 +90,9 @@ namespace smartcard_service_api
                return isAuthorizedAccess(aid, hashes);
        }
 
-       bool AccessControlList::isAuthorizedAccess(unsigned char *aidBuffer,
-               unsigned int aidLength, unsigned char *certHashBuffer,
-               unsigned int certHashLength)
+       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);
@@ -100,18 +100,18 @@ namespace smartcard_service_api
                return isAuthorizedAccess(aid, certHash);
        }
 
-       bool AccessControlList::isAuthorizedAccess(ByteArray &aid,
-               vector<ByteArray> &certHashes)
+       bool AccessControlList::isAuthorizedAccess(const ByteArray &aid,
+               const vector<ByteArray> &certHashes) const
        {
                return isAuthorizedAccess(aid, certHashes, ByteArray::EMPTY);
        }
 
-       bool AccessControlList::isAuthorizedAccess(ByteArray &aid,
-               vector<ByteArray> &certHashes, ByteArray &command)
+       bool AccessControlList::isAuthorizedAccess(const ByteArray &aid,
+               const vector<ByteArray> &certHashes, const ByteArray &command) const
        {
                bool result = allGranted;
-               vector<ByteArray>::reverse_iterator item;
-               AccessRule *rule = NULL;
+               vector<ByteArray>::const_reverse_iterator item;
+               const AccessRule *rule = NULL;
 
                if (result == true) {
                        goto END;
@@ -126,7 +126,7 @@ namespace smartcard_service_api
                                } else {
                                        result = rule->isAuthorizedAPDUAccess(command);
                                }
-                               _INFO("rule found (%s): [%s:%s]", result ? "accept" : "deny", aid.toString(), (*item).toString());
+                               _INFO("rule found (%s): [%s:%s]", result ? "accept" : "deny", aid.toString().c_str(), (*item).toString().c_str());
                                goto END;
                        }
                }
@@ -139,7 +139,7 @@ namespace smartcard_service_api
                        } else {
                                result = rule->isAuthorizedAPDUAccess(command);
                        }
-                       _INFO("rule found (%s): [%s:%s]", result ? "accept" : "deny", aid.toString(), ALL_DEVICE_APPS.toString());
+                       _INFO("rule found (%s): [%s:%s]", result ? "accept" : "deny", aid.toString().c_str(), ALL_DEVICE_APPS.toString().c_str());
                        goto END;
                }
 
@@ -152,7 +152,7 @@ namespace smartcard_service_api
                                } else {
                                        result = rule->isAuthorizedAPDUAccess(command);
                                }
-                               _INFO("rule found (%s): [%s:%s]", result ? "accept" : "deny", "All SE Applications", (*item).toString());
+                               _INFO("rule found (%s): [%s:%s]", result ? "accept" : "deny", "All SE Applications", (*item).toString().c_str());
                                goto END;
                        }
                }
@@ -172,12 +172,12 @@ END :
                return result;
        }
 
-       bool AccessControlList::isAuthorizedNFCAccess(ByteArray &aid,
-               vector<ByteArray> &certHashes)
+       bool AccessControlList::isAuthorizedNFCAccess(const ByteArray &aid,
+               const vector<ByteArray> &certHashes) const
        {
                bool result = allGranted;
-               vector<ByteArray>::reverse_iterator item;
-               AccessRule *rule = NULL;
+               vector<ByteArray>::const_reverse_iterator item;
+               const AccessRule *rule = NULL;
 
                if (result == true) {
                        goto END;
@@ -188,7 +188,7 @@ END :
                        rule = findAccessRule(aid, *item);
                        if (rule != NULL) {
                                result = rule->isAuthorizedNFCAccess();
-                               _INFO("rule found (%s): [%s:%s]", result ? "accept" : "deny", aid.toString(), (*item).toString());
+                               _INFO("rule found (%s): [%s:%s]", result ? "accept" : "deny", aid.toString().c_str(), (*item).toString().c_str());
                                goto END;
                        }
                }
@@ -197,7 +197,7 @@ END :
                rule = findAccessRule(aid, ALL_DEVICE_APPS);
                if (rule != NULL) {
                        result = rule->isAuthorizedNFCAccess();
-                       _INFO("rule found (%s): [%s:%s]", result ? "accept" : "deny", aid.toString(), "All device applications");
+                       _INFO("rule found (%s): [%s:%s]", result ? "accept" : "deny", aid.toString().c_str(), "All device applications");
                        goto END;
                }
 
@@ -206,7 +206,7 @@ END :
                        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());
+                               _INFO("rule found (%s): [%s:%s]", result ? "accept" : "deny", "All SE Applications", (*item).toString().c_str());
                                goto END;
                        }
                }
@@ -222,17 +222,17 @@ END :
                return result;
        }
 
-       void AccessControlList::printAccessControlList()
+       void AccessControlList::printAccessControlList() const
        {
                ByteArray temp;
-               map<ByteArray, AccessCondition>::iterator iterMap;
+               map<ByteArray, AccessCondition>::const_iterator iterMap;
 
                _DBG("================ Access Control Rules ==================");
                for (iterMap = mapConditions.begin(); iterMap != mapConditions.end(); iterMap++)
                {
                        temp = iterMap->first;
 
-                       _DBG("+ aid : %s", (temp == DEFAULT_SE_APP) ? "Default Application" : (temp == ALL_SE_APPS) ? "All SE Applications" : temp.toString());
+                       _DBG("+ aid : %s", (temp == DEFAULT_SE_APP) ? "Default Application" : (temp == ALL_SE_APPS) ? "All SE Applications" : temp.toString().c_str());
 
                        iterMap->second.printAccessConditions();
                }
index c62c775..b41c098 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,81 +30,74 @@ 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)
                {
                        _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
+       uint8_t *ByteArray::getBuffer(size_t offset)
        {
                if (length == 0)
                        return NULL;
@@ -117,62 +111,72 @@ namespace smartcard_service_api
                return buffer + offset;
        }
 
-       uint8_t ByteArray::getAt(uint32_t index) const
+       uint8_t ByteArray::at(size_t index) const
        {
                if (index >= length)
                {
                        _ERR("buffer overflow, index [%d], length [%d]", index, length);
-                       return buffer[length -1];
+                       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)
                {
                        _ERR("buffer underflow, index [%d], length [%d]", index, length);
-                       return buffer[0];
+                       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)
                {
-                       _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;
        }
 
-       ByteArray ByteArray::sub(uint32_t offset, uint32_t size) const
+       const ByteArray ByteArray::sub(size_t offset, size_t size) const
        {
-               ByteArray newArray;
-
                if (length == 0 || offset >= length || (offset + size) > length)
                {
                        _DBG("length is zero");
 
-                       return newArray;
+                       return ByteArray();
                }
 
-               newArray.setBuffer(buffer + offset, size);
-
-               return newArray;
+               return ByteArray(buffer + offset, size);
        }
 
-       void ByteArray::releaseBuffer()
+       void ByteArray::clear()
        {
                if (buffer != NULL)
                {
@@ -185,7 +189,7 @@ namespace smartcard_service_api
        /* operator overloading */
        ByteArray ByteArray::operator +(const ByteArray &T)
        {
-               uint32_t newLen;
+               size_t newLen;
                uint8_t *newBuffer;
                ByteArray newArray;
 
@@ -215,7 +219,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;
        }
@@ -224,7 +228,7 @@ namespace smartcard_service_api
        {
                if (this != &T)
                {
-                       setBuffer(T.buffer, T.length);
+                       assign(T.buffer, T.length);
                }
 
                return *this;
@@ -260,29 +264,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)
                {
                        _ERR("buffer overflow, index [%d], length [%d]", index, length);
-                       return buffer[length -1];
+                       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;
@@ -292,26 +299,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)
@@ -325,7 +333,6 @@ namespace smartcard_service_api
                {
                        fwrite(buffer, 1, length, file);
                        fflush(file);
-
                        fclose(file);
                }
                else
index de3a042..0be1cb8 100644 (file)
@@ -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")
 
index 240704a..208b2e2 100644 (file)
@@ -61,7 +61,7 @@ namespace smartcard_service_api
                }
        }
 
-       void DispatcherHelper::pushMessage(DispatcherMsg *msg)
+       void DispatcherHelper::pushMessage(const DispatcherMsg &msg)
        {
                DispatcherMsg *pushMsg = new DispatcherMsg(msg);
 
index 26022ba..e6035e5 100644 (file)
@@ -34,7 +34,7 @@ namespace smartcard_service_api
        {
        }
 
-       EFDIR::EFDIR(Channel *channel, ByteArray selectResponse) :
+       EFDIR::EFDIR(Channel *channel, const ByteArray &selectResponse) :
                FileObject(channel, selectResponse)
        {
        }
@@ -56,7 +56,7 @@ namespace smartcard_service_api
                return ret;
        }
 
-       ByteArray EFDIR::parseRecord(Record &record, ByteArray &aid)
+       const ByteArray EFDIR::parseRecord(const Record &record, const ByteArray &aid)
        {
                bool matched = false;
                ByteArray result;
@@ -86,18 +86,18 @@ namespace smartcard_service_api
 
                        if (matched == true)
                        {
-                               _DBG("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;
@@ -110,7 +110,7 @@ namespace smartcard_service_api
                        if (status >= 0)
                        {
                                result = parseRecord(record, aid);
-                               if (result.getLength() > 0)
+                               if (result.size() > 0)
                                        break;
                        }
                }
index 6be4bc0..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,7 +60,7 @@ 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;
@@ -68,7 +69,7 @@ namespace smartcard_service_api
 
                releaseFCP();
 
-               if (array.getLength() == 0)
+               if (array.size() == 0)
                        return false;
 
                fcpBuffer = array;
@@ -80,7 +81,7 @@ namespace smartcard_service_api
                }
 
                /* parse... */
-               tlv.setTLVBuffer(fcpBuffer.getBuffer(), fcpBuffer.getLength());
+               tlv.setTLVBuffer(fcpBuffer.getBuffer(), fcpBuffer.size());
 
                if (tlv.decodeTLV())
                {
@@ -92,8 +93,8 @@ namespace smartcard_service_api
                                {
                                case 0x80 : /* file length without structural information */
                                        {
-                                               _DBG("0x%02X : file length without structural information : %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());
                                                }
@@ -102,8 +103,8 @@ namespace smartcard_service_api
 
                                case 0x81 : /* file length with structural information */
                                        {
-                                               _DBG("0x%02X : file length with structural information : %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 */
                                        {
-                                               _DBG("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 */
                                        {
-                                               _DBG("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 */
                                        {
-                                               _DBG("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 */
                                        {
-                                               _DBG("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 */
                                        {
-                                               _DBG("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 */
                                        {
-                                               _DBG("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 */
                                        {
-                                               _DBG("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 */
                                        {
-                                               _DBG("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 */
                                        {
-                                               _DBG("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 :
                                        {
-                                               _DBG("0x%02X : unknown : %s", tlv.getTag(), tlv.getValue().toString());
+                                               _DBG("0x%02X : unknown : %s", tlv.getTag(), tlv.getValue().toString().c_str());
                                        }
                                        break;
                                }
@@ -284,71 +275,95 @@ namespace smartcard_service_api
                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 41c07ad..46112f1 100644 (file)
@@ -47,14 +47,14 @@ namespace smartcard_service_api
        void FileObject::close()
        {
                opened = false;
-               selectResponse.releaseBuffer();
+               selectResponse.clear();
        }
 
        bool FileObject::setSelectResponse(const ByteArray &response)
        {
                bool result = false;
 
-               if (response.getLength() >= 2)
+               if (response.size() >= 2)
                {
                        ResponseHelper resp(response);
                        selectResponse = response;
@@ -65,7 +65,7 @@ namespace smartcard_service_api
 
                                fcp.setFCP(resp.getDataField());
 
-                               _DBG("FCP : %s", fcp.toString());
+                               _DBG("FCP : %s", fcp.toString().c_str());
 
                                opened = true;
                                result = true;
@@ -113,7 +113,7 @@ namespace smartcard_service_api
                else
                {
                        _ERR("select apdu is failed, rv [%d], length [%d]",
-                               ret, result.getLength());
+                               ret, result.size());
 
                        ret = ERROR_ILLEGAL_STATE;
                }
@@ -148,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);
@@ -188,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;
        }
@@ -208,14 +208,14 @@ 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)
                        {
-                               _DBG("response [%d] : %s", response.getLength(), response.toString());
+                               _DBG("response [%d] : %s", response.size(), response.toString().c_str());
 
                                result = Record(recordId, resp.getDataField());
                        }
@@ -226,7 +226,7 @@ namespace smartcard_service_api
                }
                else
                {
-                       _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;
@@ -252,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)
                        {
-                               _DBG("response [%d] : %s", response.getLength(), response.toString());
+                               _DBG("response [%d] : %s", response.size(), response.toString().c_str());
 
                                result = resp.getDataField();
 
@@ -271,7 +271,7 @@ namespace smartcard_service_api
                }
                else
                {
-                       _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;
@@ -287,13 +287,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)
                        {
-                               _DBG("response [%d] : %s", response.getLength(), response.toString());
+                               _DBG("response [%d] : %s", response.size(), response.toString().c_str());
 
                                ret = SUCCESS;
                        }
@@ -304,7 +304,7 @@ namespace smartcard_service_api
                }
                else
                {
-                       _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;
index 38a9de5..0422100 100644 (file)
 
 namespace smartcard_service_api
 {
-       GDBusHelper::GDBusHelper()
-       {
-       }
-
-       GDBusHelper::~GDBusHelper()
-       {
-       }
-
        void GDBusHelper::convertVariantToByteArray(GVariant *var,
                ByteArray &array)
        {
@@ -48,7 +40,7 @@ namespace smartcard_service_api
 
                g_variant_iter_free(iter);
 
-               array.setBuffer((uint8_t *)buf, (uint32_t)i);
+               array.assign((uint8_t *)buf, (uint32_t)i);
 
                g_free(buf);
        }
@@ -60,7 +52,7 @@ namespace smartcard_service_api
 
                g_variant_builder_init(&builder, G_VARIANT_TYPE("a(y)"));
 
-               for (i = 0; i < array.getLength(); i++)
+               for (i = 0; i < array.size(); i++)
                        g_variant_builder_add(&builder, "(y)", array[i]);
 
                return g_variant_builder_end(&builder);
index 5f4cec2..3aa3ba7 100644 (file)
@@ -88,33 +88,34 @@ namespace smartcard_service_api
                return result;
        }
 
-       bool GPACE::isAuthorizedAccess(ByteArray &aid,
-               ByteArray &certHash)
+       bool GPACE::isAuthorizedAccess(const ByteArray &aid,
+               const ByteArray &certHash) const
        {
                return (acl != NULL) ? acl->isAuthorizedAccess(aid, certHash) : false;
        }
 
-       bool GPACE::isAuthorizedAccess(unsigned char *aidBuffer,
-               unsigned int aidLength, unsigned char *certHashBuffer,
-               unsigned int certHashLength)
+       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(ByteArray &aid,
-               vector<ByteArray> &certHashes)
+       bool GPACE::isAuthorizedAccess(const ByteArray &aid,
+               const vector<ByteArray> &certHashes) const
        {
                return (acl != NULL) ? acl->isAuthorizedAccess(aid, certHashes) : false;
        }
 
-       bool GPACE::isAuthorizedAccess(ByteArray &aid,
-               vector<ByteArray> &certHashes, ByteArray &command)
+       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(ByteArray &aid,
-               vector<ByteArray> &certHashes)
+       bool GPACE::isAuthorizedNFCAccess(const ByteArray &aid,
+               const vector<ByteArray> &certHashes) const
        {
                return (acl != NULL) ? acl->isAuthorizedNFCAccess(aid, certHashes) : false;
        }
index 4a93c33..95a9f65 100644 (file)
@@ -71,7 +71,7 @@ namespace smartcard_service_api
                if (tlv.decodeTLV() == true) {
                        switch (tlv.getTag()) {
                        case DO_TAG_AID_REF :
-                               if (tlv.getLength() > 0) {
+                               if (tlv.size() > 0) {
                                        result = tlv.getValue();
                                } else {
                                        result = AccessControlList::ALL_SE_APPS;
@@ -83,11 +83,11 @@ namespace smartcard_service_api
                                break;
 
                        default :
-                               _ERR("decodeTLV failed, %s", tlv.toString());
+                               _ERR("decodeTLV failed, %s", tlv.toString().c_str());
                                break;
                        }
                } else {
-                       _ERR("decodeTLV failed, %s", tlv.toString());
+                       _ERR("decodeTLV failed, %s", tlv.toString().c_str());
                }
 
                _END();
@@ -103,13 +103,13 @@ namespace smartcard_service_api
 
                if (tlv.decodeTLV() == true &&
                        tlv.getTag() == DO_TAG_HASH_REF) {
-                       if (tlv.getLength() > 0) {
+                       if (tlv.size() > 0) {
                                result = tlv.getValue();
                        } else {
                                result = AccessControlList::ALL_DEVICE_APPS;
                        }
                } else {
-                       _ERR("decodeTLV failed, %s", tlv.toString());
+                       _ERR("decodeTLV failed, %s", tlv.toString().c_str());
                }
 
                _END();
@@ -129,9 +129,9 @@ namespace smartcard_service_api
                        hash = getHash(tlv);
                        tlv.returnToParentTLV();
 
-                       _DBG("aid : %s, hash : %s", aid.toString(), hash.toString());
+                       _DBG("aid : %s, hash : %s", aid.toString().c_str(), hash.toString().c_str());
                } else {
-                       _ERR("unknown tag : %s", tlv.toString());
+                       _ERR("unknown tag : %s", tlv.toString().c_str());
                        result = SCARD_ERROR_ILLEGAL_PARAM;
                }
 
@@ -150,7 +150,7 @@ namespace smartcard_service_api
                if (tlv.decodeTLV() == true && tlv.getTag() == DO_TAG_AR) {
                        tlv.enterToValueTLV();
                        while (tlv.decodeTLV() == true) {
-                               int length = tlv.getLength();
+                               int length = tlv.size();
 
                                switch (tlv.getTag()) {
                                case DO_TAG_APDU_AR :
@@ -159,21 +159,21 @@ namespace smartcard_service_api
                                                ByteArray temp;
 
                                                for (i = 0; i < length; i += 8) {
-                                                       temp.setBuffer(tlv.getValue().getBuffer(i), 8);
-                                                       _DBG("apdu rule[%d] : %s", temp.getLength(), temp.toString());
+                                                       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());
+                                               _DBG("apdu rule : %s", tlv.getValue().toString().c_str());
                                                apduRule.push_back(tlv.getValue());
                                        } else {
-                                               _ERR("invalid rule, %s", tlv.toString());
+                                               _ERR("invalid rule, %s", tlv.toString().c_str());
                                        }
                                        break;
 
                                case DO_TAG_NFC_AR :
                                        nfcRule = tlv.getValue();
-                                       _DBG("nfc rule : %s", tlv.getValue().toString());
+                                       _DBG("nfc rule : %s", tlv.getValue().toString().c_str());
                                        break;
 
                                default :
@@ -201,7 +201,7 @@ namespace smartcard_service_api
 
                if (apduRule.size() > 0) {
                        if (apduRule.size() == 1 &&
-                               apduRule[0].getLength() == 1) {
+                               apduRule[0].size() == 1) {
                                /* apdu grant/deny */
                                if (apduRule[0][0] == 1) {
                                        condition.setAPDUAccessRule(hash, true);
@@ -217,7 +217,7 @@ namespace smartcard_service_api
                        }
                }
 
-               if (nfcRule.getLength() == 1) {
+               if (nfcRule.size() == 1) {
                        if (nfcRule[0] == 1) {
                                condition.setNFCAccessRule(hash, true);
                        } else {
@@ -228,7 +228,7 @@ namespace smartcard_service_api
                _END();
        }
 
-       int GPARAACL::updateRule(ByteArray &data)
+       int GPARAACL::updateRule(const ByteArray &data)
        {
                int result = SCARD_ERROR_OK;
                SimpleTLV tlv(data);
@@ -327,7 +327,7 @@ namespace smartcard_service_api
                return result;
        }
 
-       static bool _isAuthorizedAccess(ByteArray &data, ByteArray &command)
+       static bool _isAuthorizedAccess(const ByteArray &data, const ByteArray &command)
        {
                vector<ByteArray> apduRule;
                ByteArray nfcRule;
@@ -337,8 +337,8 @@ namespace smartcard_service_api
                if (parseARDO(tlv, apduRule, nfcRule) >= SCARD_ERROR_OK) {
                        if (apduRule.size() > 0) {
                                if (apduRule.size() > 1 ||
-                                       apduRule[0].getLength() != 1) {
-                                       if (command.getLength() > 0) {
+                                       apduRule[0].size() != 1) {
+                                       if (command.size() > 0) {
                                                /* TODO : check apdu rule */
                                        } else {
                                                /* check hash only */
@@ -348,16 +348,16 @@ namespace smartcard_service_api
                                        result = (apduRule[0][0] == 1 ? true : false);
                                }
                        } else {
-                               _ERR("unknown data : %s", tlv.toString());
+                               _ERR("unknown data : %s", tlv.toString().c_str());
                        }
                } else {
-                       _ERR("parseARDO failed : %s", tlv.toString());
+                       _ERR("parseARDO failed : %s", tlv.toString().c_str());
                }
 
                return result;
        }
 
-       static bool _isAuthorizedNFCAccess(ByteArray &data)
+       static bool _isAuthorizedNFCAccess(const ByteArray &data)
        {
                vector<ByteArray> apduRule;
                ByteArray nfcRule;
@@ -365,20 +365,20 @@ namespace smartcard_service_api
                bool result = false;
 
                if (parseARDO(tlv, apduRule, nfcRule) >= SCARD_ERROR_OK) {
-                       if (nfcRule.getLength() == 1) {
+                       if (nfcRule.size() == 1) {
                                result = (nfcRule[0] == 1 ? true : false);
                        } else {
-                               _ERR("unknown data : %s", nfcRule.toString());
+                               _ERR("unknown data : %s", nfcRule.toString().c_str());
                        }
                } else {
-                       _ERR("parseARDO failed : %s", tlv.toString());
+                       _ERR("parseARDO failed : %s", tlv.toString().c_str());
                }
 
                return result;
        }
 
-       bool GPARAACL::isAuthorizedAccess(GPARAM &aram, ByteArray &aid,
-               ByteArray &certHash)
+       bool GPARAACL::isAuthorizedAccess(GPARAM &aram, const ByteArray &aid,
+               const ByteArray &certHash) const
        {
                vector<ByteArray> hashes;
 
@@ -387,9 +387,11 @@ namespace smartcard_service_api
                return isAuthorizedAccess(aram, aid, hashes, ByteArray::EMPTY);
        }
 
-       bool GPARAACL::isAuthorizedAccess(GPARAM &aram, unsigned char *aidBuffer,
-               unsigned int aidLength, unsigned char *certHashBuffer,
-               unsigned int certHashLength)
+       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);
@@ -397,18 +399,18 @@ namespace smartcard_service_api
                return isAuthorizedAccess(aram, aid, hash);
        }
 
-       bool GPARAACL::isAuthorizedAccess(GPARAM &aram, ByteArray &aid,
-               vector<ByteArray> &certHashes)
+       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, ByteArray &aid,
-               vector<ByteArray> &certHashes, ByteArray &command)
+       bool GPARAACL::isAuthorizedAccess(GPARAM &aram, const ByteArray &aid,
+               const vector<ByteArray> &certHashes, const ByteArray &command) const
        {
                bool result = allGranted;
                ByteArray data;
-               vector<ByteArray>::reverse_iterator item;
+               vector<ByteArray>::const_reverse_iterator item;
 
                if (aram.isClosed() == true)
                        return result;
@@ -423,18 +425,18 @@ namespace smartcard_service_api
                        result == false && item != certHashes.rend();
                        item++) {
                        if (aram.getDataSpecific(aid, *item, data)
-                               >= SCARD_ERROR_OK && data.getLength() > 0) {
+                               >= SCARD_ERROR_OK && data.size() > 0) {
                                result = _isAuthorizedAccess(data, command);
-                               _INFO("rule found (%s): [%s:%s]", result ? "accept" : "deny", aid.toString(), (*item).toString());
+                               _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.getLength() > 0) {
+                       >= SCARD_ERROR_OK && data.size() > 0) {
                        result = _isAuthorizedAccess(data, command);
-                       _INFO("rule found (%s): [%s:%s]", result ? "accept" : "deny", aid.toString(), "All device applications");
+                       _INFO("rule found (%s): [%s:%s]", result ? "accept" : "deny", aid.toString().c_str(), "All device applications");
                        goto END;
                }
 
@@ -443,16 +445,16 @@ namespace smartcard_service_api
                        result == false && item != certHashes.rend();
                        item++) {
                        if (aram.getDataSpecific(ByteArray::EMPTY, *item, data)
-                               >= SCARD_ERROR_OK && data.getLength() > 0) {
+                               >= SCARD_ERROR_OK && data.size() > 0) {
                                result = _isAuthorizedAccess(data, command);
-                               _INFO("rule found (%s): [%s:%s]", result ? "accept" : "deny", "All SE Applications", (*item).toString());
+                               _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.getLength() > 0) {
+                       >= 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;
@@ -464,12 +466,12 @@ namespace smartcard_service_api
                return result;
        }
 
-       bool GPARAACL::isAuthorizedNFCAccess(GPARAM &aram, ByteArray &aid,
-               vector<ByteArray> &certHashes)
+       bool GPARAACL::isAuthorizedNFCAccess(GPARAM &aram, const ByteArray &aid,
+               const vector<ByteArray> &certHashes) const
        {
                bool result = allGranted;
                ByteArray data;
-               vector<ByteArray>::reverse_iterator item;
+               vector<ByteArray>::const_reverse_iterator item;
 
                if (aram.isClosed() == true)
                        return result;
@@ -484,18 +486,18 @@ namespace smartcard_service_api
                        result == false && item != certHashes.rend();
                        item++) {
                        if (aram.getDataSpecific(aid, *item, data)
-                               >= SCARD_ERROR_OK && data.getLength() > 0) {
+                               >= SCARD_ERROR_OK && data.size() > 0) {
                                result = _isAuthorizedNFCAccess(data);
-                               _INFO("rule found (%s): [%s:%s]", result ? "accept" : "deny", aid.toString(), (*item).toString());
+                               _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.getLength() > 0) {
+                       >= SCARD_ERROR_OK && data.size() > 0) {
                        result = _isAuthorizedNFCAccess(data);
-                       _INFO("rule found (%s): [%s:%s]", result ? "accept" : "deny", aid.toString(), "All device applications");
+                       _INFO("rule found (%s): [%s:%s]", result ? "accept" : "deny", aid.toString().c_str(), "All device applications");
                        goto END;
                }
 
@@ -504,16 +506,16 @@ namespace smartcard_service_api
                        result == false && item != certHashes.rend();
                        item++) {
                        if (aram.getDataSpecific(ByteArray::EMPTY, *item, data)
-                               >= SCARD_ERROR_OK && data.getLength() > 0) {
+                               >= SCARD_ERROR_OK && data.size() > 0) {
                                result = _isAuthorizedNFCAccess(data);
-                               _INFO("rule found (%s): [%s:%s]", result ? "accept" : "deny", "All SE Applications", (*item).toString());
+                               _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.getLength() > 0) {
+                       >= 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;
index ff7f12c..ac0081b 100644 (file)
@@ -77,7 +77,7 @@ namespace smartcard_service_api
                        result = ResponseHelper::getStatus(resp);
                        if (result >= SCARD_ERROR_OK) {
                                response = ResponseHelper::getDataField(resp);
-                               _DBG("response[%d] : %s", response.getLength(), response.toString());
+                               _DBG("response[%d] : %s", response.size(), response.toString().c_str());
                        } else {
                                _ERR("transmit returns error, [%d]", result);
                        }
@@ -114,7 +114,7 @@ namespace smartcard_service_api
 
                helper.getBuffer(cmd);
 
-               _DBG("command[%d] : %s", cmd.getLength(), cmd.toString());
+               _DBG("command[%d] : %s", cmd.size(), cmd.toString().c_str());
 
                result = doTransmit(channel, cmd, response);
 
@@ -150,29 +150,29 @@ namespace smartcard_service_api
 
                        if (tlv.decodeTLV() == true &&
                                tlv.getTag() == ARAM_TAG_ALL_AR) {
-                               unsigned int length = tlv.getLength();
+                               unsigned int length = tlv.size();
 
                                if (length > 0){
                                        data = tlv.getValue();
 
-                                       while (length > data.getLength()) {
+                                       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.releaseBuffer();
+                                                       data.clear();
                                                        break;
                                                }
                                        }
 
-                                       _DBG("data[%d] : %s", data.getLength(), data.toString());
+                                       _DBG("data[%d] : %s", data.size(), data.toString().c_str());
                                } else {
                                        _INFO("Response-ALL-AR-DO is empty");
-                                       data.releaseBuffer();
+                                       data.clear();
                                }
                        } else {
-                               _ERR("decodeTLV failed, %s", response.toString());
+                               _ERR("decodeTLV failed, %s", response.toString().c_str());
                                result = SCARD_ERROR_ILLEGAL_PARAM;
                        }
                } else {
@@ -192,7 +192,7 @@ namespace smartcard_service_api
                temp += SimpleTLV::encode(DO_TAG_HASH_REF, hash);
 
                refDo = SimpleTLV::encode(DO_TAG_REF, temp);
-               _DBG("encoded Ref DO : %s", refDo.toString());
+               _DBG("encoded Ref DO : %s", refDo.toString().c_str());
 
                return SCARD_ERROR_OK;
        }
@@ -213,28 +213,28 @@ namespace smartcard_service_api
 
                        if (tlv.decodeTLV() == true &&
                                tlv.getTag() == ARAM_TAG_AR) {
-                               unsigned int length = tlv.getLength();
+                               unsigned int length = tlv.size();
 
                                if (length > 0){
                                        data = tlv.getValue();
 
-                                       while (length > data.getLength()) {
+                                       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.releaseBuffer();
+                                                       data.clear();
                                                        break;
                                                }
                                        }
-                                       _DBG("data[%d] : %s", data.getLength(), data.toString());
+                                       _DBG("data[%d] : %s", data.size(), data.toString().c_str());
                                } else {
                                        _INFO("Response-ALL-AR-DO is empty");
-                                       data.releaseBuffer();
+                                       data.clear();
                                }
                        } else {
-                               _ERR("decodeTLV failed, %s", response.toString());
+                               _ERR("decodeTLV failed, %s", response.toString().c_str());
                                result = SCARD_ERROR_ILLEGAL_PARAM;
                        }
                } else {
@@ -259,12 +259,12 @@ namespace smartcard_service_api
 
                        if (tlv.decodeTLV() == true &&
                                tlv.getTag() == ARAM_TAG_REFRESH &&
-                               tlv.getLength() == 8) {
+                               tlv.size() == 8) {
                                tag = tlv.getValue();
                                result = SCARD_ERROR_OK;
-                               _DBG("refreshTag[%d] : %s", tag.getLength(), tag.toString());
+                               _DBG("refreshTag[%d] : %s", tag.size(), tag.toString().c_str());
                        } else {
-                               _ERR("decodeTLV failed, %s", response.toString());
+                               _ERR("decodeTLV failed, %s", response.toString().c_str());
                                result = SCARD_ERROR_ILLEGAL_PARAM;
                        }
                } else {
index 4cad060..018473a 100644 (file)
@@ -115,12 +115,12 @@ namespace smartcard_service_api
                        ByteArray data;
                        FileObject file(channel);
 
-                       _DBG("oid path : %s", path.toString());
+                       _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());
+                       _DBG("data : %s", data.toString().c_str());
 
                        /* PKCS #15 and DODF OID exists. apply access control rule!! */
                        allGranted = false;
@@ -135,7 +135,7 @@ namespace smartcard_service_api
                                ByteArray refreshTag;
 
                                refreshTag = SimpleTLV::getOctetString(tlv);
-                               _DBG("current refresh tag : %s", refreshTag.toString());
+                               _DBG("current refresh tag : %s", refreshTag.toString().c_str());
 
                                if (this->refreshTag != refreshTag) /* need to update access control list */
                                {
@@ -151,7 +151,7 @@ namespace smartcard_service_api
 
                                                /* OCTET STRING */
                                                path = SimpleTLV::getOctetString(tlv.getValue());
-                                               _DBG("access control rule path : %s", path.toString());
+                                               _DBG("access control rule path : %s", path.toString().c_str());
 
                                                if (loadRules(channel, path) == 0)
                                                {
@@ -190,7 +190,7 @@ namespace smartcard_service_api
                file.select(NumberStream::getLittleEndianNumber(path));
                file.readBinary(0, 0, file.getFCP()->getFileSize(), data);
 
-               _DBG("data : %s", data.toString());
+               _DBG("data : %s", data.toString().c_str());
 
                SimpleTLV tlv(data);
 
@@ -216,7 +216,7 @@ namespace smartcard_service_api
                                        break;
                                }
 
-                               _DBG("aid : %s", aid.toString());
+                               _DBG("aid : %s", aid.toString().c_str());
 
                                /* access condition path */
                                if (tlv.decodeTLV() == true && tlv.getTag() == 0x30) /* SEQUENCE : Path */
@@ -225,7 +225,7 @@ namespace smartcard_service_api
 
                                        /* OCTET STRING */
                                        path = SimpleTLV::getOctetString(tlv.getValue());
-                                       _DBG("path : %s", path.toString());
+                                       _DBG("path : %s", path.toString().c_str());
 
                                        if (loadAccessConditions(channel, aid, path) == 0)
                                        {
@@ -273,18 +273,18 @@ namespace smartcard_service_api
 
                                                value = tlv.getValue();
 
-                                               _DBG("APDU rule : %s", value.toString());
+                                               _DBG("APDU rule : %s", value.toString().c_str());
 
-                                               if (value.getLength() == 8) /* apdu 4 bytes + mask 4 bytes */
+                                               if (value.size() == 8) /* apdu 4 bytes + mask 4 bytes */
                                                {
-                                                       apdu.setBuffer(value.getBuffer(), 4);
-                                                       mask.setBuffer(value.getBuffer(4), 4);
+                                                       apdu.assign(value.getBuffer(), 4);
+                                                       mask.assign(value.getBuffer(4), 4);
 
                                                        rule->addAPDUAccessRule(apdu, mask);
                                                }
                                                else
                                                {
-                                                       _ERR("Invalid APDU rule : %s", value.toString());
+                                                       _ERR("Invalid APDU rule : %s", value.toString().c_str());
                                                }
                                        }
                                        else
@@ -309,14 +309,14 @@ namespace smartcard_service_api
 
        static void loadAccessCondition(AccessCondition &condition, const ByteArray &data)
        {
-               if (data.getLength() > 0)
+               if (data.size() > 0)
                {
                        SimpleTLV tlv(data);
                        ByteArray hash;
 
                        while (tlv.decodeTLV() == true && tlv.getTag() == 0x30) /* SEQUENCE */
                        {
-                               if (tlv.getLength() > 0)
+                               if (tlv.size() > 0)
                                {
                                        /* access granted for specific applications */
                                        tlv.enterToValueTLV();
@@ -325,7 +325,7 @@ namespace smartcard_service_api
                                                switch (tlv.getTag())
                                                {
                                                case 0x04 : /* OCTET STRING : CertHash */
-                                                       _DBG("aid : %s, hash : %s", condition.getAID().toString(), tlv.getValue().toString());
+                                                       _DBG("aid : %s, hash : %s", condition.getAID().toString().c_str(), tlv.getValue().toString().c_str());
 
                                                        hash = tlv.getValue();
                                                        condition.addAccessRule(tlv.getValue());
@@ -376,7 +376,7 @@ namespace smartcard_service_api
                                }
                                else
                                {
-                                       _INFO("access denied for all applications, aid : %s", condition.getAID().toString());
+                                       _INFO("access denied for all applications, aid : %s", condition.getAID().toString().c_str());
 
                                        condition.setAccessCondition(false);
                                        break;
@@ -385,7 +385,7 @@ namespace smartcard_service_api
                }
                else
                {
-                       _INFO("access denied for all applications, aid : %s", condition.getAID().toString());
+                       _INFO("access denied for all applications, aid : %s", condition.getAID().toString().c_str());
 
                        condition.setAccessCondition(false);
                }
@@ -399,7 +399,7 @@ namespace smartcard_service_api
                file.select(NumberStream::getLittleEndianNumber(path));
                file.readBinary(0, 0, file.getFCP()->getFileSize(), data);
 
-               _DBG("data : %s", data.toString());
+               _DBG("data : %s", data.toString().c_str());
 
                AccessCondition condition;
 
index 567070a..4f8a363 100644 (file)
@@ -517,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();
 
                _DBG(">>>[SEND]>>> socket [%d], msg [%d], length [%d]",
-                       socket, msg->message, stream.getLength());
+                       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)
                {
@@ -589,7 +589,7 @@ ERROR :
                _BEGIN();
 
                buffer = retrieveBuffer(socket);
-               if (buffer.getLength() > 0)
+               if (buffer.size() > 0)
                {
                        msg = new Message();
                        if (msg != NULL)
@@ -611,7 +611,7 @@ ERROR :
                return msg;
        }
 
-       ByteArray IPCHelper::retrieveBuffer(int socket)
+       const ByteArray IPCHelper::retrieveBuffer(int socket)
        {
                ByteArray buffer;
                unsigned int length = 0;
@@ -650,7 +650,7 @@ ERROR :
 
                                        _DBG("<<<[RETRIEVE]<<< socket [%d], msg_length [%d]", socket, length);
 
-                                       buffer.setBuffer(temp, length);
+                                       buffer.assign(temp, length);
 
                                        delete []temp;
                                }
index 2633526..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()
@@ -66,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)
@@ -103,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)
                {
@@ -135,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;
@@ -199,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;
                }
@@ -210,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];
@@ -254,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 d34d375..5beab7f 100644 (file)
@@ -16,8 +16,9 @@
 
 #ifndef USE_GDBUS
 /* standard library header */
-#include <stdio.h>
-#include <string.h>
+#include <cstdio>
+#include <cstring>
+#include <sstream>
 
 /* SLP library header */
 
@@ -42,7 +43,7 @@ namespace smartcard_service_api
        {
        }
 
-       ByteArray Message::serialize()
+       const ByteArray Message::serialize() const
        {
                ByteArray result;
                unsigned int length = 0;
@@ -50,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];
@@ -84,16 +85,16 @@ 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;
                }
@@ -105,12 +106,12 @@ namespace smartcard_service_api
                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;
@@ -153,17 +154,16 @@ namespace smartcard_service_api
 
 //                     _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 :
@@ -207,9 +207,9 @@ namespace smartcard_service_api
                        break;
                }
 
-               snprintf(text, sizeof(text), "Message [%s, %d], param1 [%d], param2 [%d], error [%d], 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 */
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 3f9a3b9..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;
 
@@ -115,19 +115,21 @@ namespace smartcard_service_api
                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,7 +144,7 @@ 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)
                                {
                                        _ERR("EVP_DigestUpdate failed");
                                }
@@ -150,7 +152,7 @@ namespace smartcard_service_api
                                if (EVP_DigestFinal(&mdCtx, temp, &resultLen) > 0 &&
                                        resultLen > 0)
                                {
-                                       result.setBuffer(temp, resultLen);
+                                       result.assign(temp, resultLen);
                                        ret = true;
                                }
                        }
index dc195fa..729d209 100644 (file)
@@ -56,7 +56,7 @@ namespace smartcard_service_api
                ret = PKCS15Object::select(PKCS15::PKCS15_AID);
                if (ret >= SCARD_ERROR_OK)
                {
-                       _DBG("response : %s", selectResponse.toString());
+                       _DBG("response : %s", selectResponse.toString().c_str());
                }
                else if (ret == ResponseHelper::ERROR_FILE_NOT_FOUND)
                {
@@ -65,7 +65,7 @@ namespace smartcard_service_api
                        ret = selectFromEFDIR();
                        if (ret >= SCARD_ERROR_OK)
                        {
-                               _DBG("response : %s", selectResponse.toString());
+                               _DBG("response : %s", selectResponse.toString().c_str());
                        }
                        else
                        {
@@ -90,7 +90,7 @@ namespace smartcard_service_api
                if (ret >= SCARD_ERROR_OK)
                {
                        path = dir.getPathByAID(PKCS15_AID);
-                       if (path.getLength() > 0)
+                       if (path.size() > 0)
                        {
                                ret = PKCS15Object::select(path, false);
                                if (ret < SCARD_ERROR_OK)
index 2c5c6d2..9177a02 100644 (file)
@@ -34,11 +34,11 @@ namespace smartcard_service_api
                {
                        ByteArray dodfData, extra;
 
-                       _DBG("response : %s", selectResponse.toString());
+                       _DBG("response : %s", selectResponse.toString().c_str());
 
                        if ((ret = readBinary(0, 0, getFCP()->getFileSize(), dodfData)) == 0)
                        {
-                               _DBG("odfData : %s", dodfData.toString());
+                               _DBG("odfData : %s", dodfData.toString().c_str());
 
                                parseData(dodfData);
                        }
@@ -53,7 +53,7 @@ namespace smartcard_service_api
                }
        }
 
-       PKCS15DODF::PKCS15DODF(ByteArray path, Channel *channel) :
+       PKCS15DODF::PKCS15DODF(const ByteArray &path, Channel *channel) :
                PKCS15Object(channel)
        {
                int ret = 0;
@@ -62,11 +62,11 @@ namespace smartcard_service_api
                {
                        ByteArray dodfData, extra;
 
-                       _DBG("response : %s", selectResponse.toString());
+                       _DBG("response : %s", selectResponse.toString().c_str());
 
                        if ((ret = readBinary(0, 0, getFCP()->getFileSize(), dodfData)) == 0)
                        {
-                               _DBG("dodfData : %s", dodfData.toString());
+                               _DBG("dodfData : %s", dodfData.toString().c_str());
 
                                parseData(dodfData);
                        }
@@ -85,7 +85,7 @@ namespace smartcard_service_api
        {
        }
 
-       bool PKCS15DODF::parseData(ByteArray data)
+       bool PKCS15DODF::parseData(const ByteArray &data)
        {
                bool result = false;
                SimpleTLV tlv(data);
@@ -106,7 +106,7 @@ namespace smartcard_service_api
                                break;
 
                        default :
-                               _DBG("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;
                        }
                }
@@ -116,10 +116,10 @@ namespace smartcard_service_api
                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 aa37499..4ca414b 100644 (file)
@@ -35,11 +35,11 @@ namespace smartcard_service_api
                {
                        ByteArray odfData, extra;
 
-                       _DBG("response : %s", selectResponse.toString());
+                       _DBG("response : %s", selectResponse.toString().c_str());
 
                        if ((ret = readBinary(0, 0, getFCP()->getFileSize(), odfData)) == 0)
                        {
-                               _DBG("odfData : %s", odfData.toString());
+                               _DBG("odfData : %s", odfData.toString().c_str());
 
                                parseData(odfData);
                        }
@@ -54,7 +54,7 @@ namespace smartcard_service_api
                }
        }
 
-       PKCS15ODF::PKCS15ODF(Channel *channel, ByteArray selectResponse) :
+       PKCS15ODF::PKCS15ODF(Channel *channel, const ByteArray &selectResponse) :
                PKCS15Object(channel, selectResponse), dodf(NULL)
        {
                int ret = 0;
@@ -62,7 +62,7 @@ namespace smartcard_service_api
 
                if ((ret = readBinary(0, 0, 0, odfData)) == 0)
                {
-                       _DBG("odfData : %s", odfData.toString());
+                       _DBG("odfData : %s", odfData.toString().c_str());
 
                        parseData(odfData);
                }
@@ -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);
@@ -98,7 +98,7 @@ namespace smartcard_service_api
 
                                        dodf = PKCS15Object::getOctetStream(tlv.getValue());
 
-                                       _DBG("path : %s", dodf.toString());
+                                       _DBG("path : %s", dodf.toString().c_str());
 
                                        pair<unsigned int, ByteArray> newPair(tlv.getTag(), dodf);
                                        dataList.insert(newPair);
@@ -113,7 +113,7 @@ namespace smartcard_service_api
 
                                        tokeninfo = PKCS15Object::getOctetStream(tlv.getValue());
 
-                                       _DBG("path : %s", tokeninfo.toString());
+                                       _DBG("path : %s", tokeninfo.toString().c_str());
 
                                        pair<unsigned int, ByteArray> newPair(tlv.getTag(), tokeninfo);
                                        dataList.insert(newPair);
@@ -122,7 +122,7 @@ namespace smartcard_service_api
 
                        default :
                                _DBG("Unknown tlv : t [%X], l [%d], v %s",
-                                       tlv.getTag(), tlv.getLength(), tlv.getValue().toString());
+                                       tlv.getTag(), tlv.size(), tlv.getValue().toString().c_str());
                                break;
                        }
 
index 1b9c10e..088a3fa 100644 (file)
@@ -26,7 +26,7 @@
 
 namespace smartcard_service_api
 {
-       PKCS15OID::PKCS15OID(ByteArray data)
+       PKCS15OID::PKCS15OID(const ByteArray &data)
        {
                parseOID(data);
        }
@@ -35,7 +35,7 @@ namespace smartcard_service_api
        {
        }
 
-       bool PKCS15OID::parseOID(ByteArray data)
+       bool PKCS15OID::parseOID(const ByteArray &data)
        {
                bool result = false;
                SimpleTLV tlv(data);
@@ -47,14 +47,13 @@ namespace smartcard_service_api
                        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();
                                }
@@ -83,7 +82,7 @@ namespace smartcard_service_api
                                        {
                                                oid = tlv.getValue();
 
-                                               _DBG("oid : %s", oid.toString());
+                                               _DBG("oid : %s", oid.toString().c_str());
                                        }
                                        else
                                        {
@@ -95,7 +94,7 @@ namespace smartcard_service_api
                                        {
                                                path = SimpleTLV::getOctetString(tlv.getValue());
 
-                                               _DBG("path : %s", path.toString());
+                                               _DBG("path : %s", path.toString().c_str());
 
                                                result = true;
                                        }
@@ -124,20 +123,4 @@ namespace smartcard_service_api
 
                return result;
        }
-
-       ByteArray PKCS15OID::getOID()
-       {
-               return oid;
-       }
-
-       ByteArray PKCS15OID::getName()
-       {
-               return name;
-       }
-
-       ByteArray PKCS15OID::getPath()
-       {
-               return path;
-       }
-
 } /* namespace smartcard_service_api */
index 25f62fb..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);
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)
        {
        }
 
diff --git a/common/ProviderHelper.cpp b/common/ProviderHelper.cpp
deleted file mode 100644 (file)
index 4ce927f..0000000
+++ /dev/null
@@ -1,53 +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 "ProviderHelper.h"
-
-namespace smartcard_service_api
-{
-//     ProviderHelper::ProviderHelper()
-//     {
-//     }
-
-       ProviderHelper::ProviderHelper(Channel *channel)
-       {
-               this->channel = NULL;
-
-               if (channel == NULL)
-               {
-                       _ERR("invalid channel");
-                       return;
-               }
-
-               this->channel = channel;
-       }
-
-       ProviderHelper::~ProviderHelper()
-       {
-       }
-
-       Channel *ProviderHelper::getChannel()
-       {
-               return channel;
-       }
-
-} /* namespace smartcard_service_api */
diff --git a/common/ReaderHelper.cpp b/common/ReaderHelper.cpp
deleted file mode 100644 (file)
index 1583a9b..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * 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 */
-#include <stdio.h>
-#include <string.h>
-
-/* SLP library header */
-
-/* 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 */
diff --git a/common/SEServiceHelper.cpp b/common/SEServiceHelper.cpp
deleted file mode 100644 (file)
index 383b2fb..0000000
+++ /dev/null
@@ -1,34 +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 */
-#include <stdio.h>
-
-/* SLP library header */
-
-/* local header */
-#include "Debug.h"
-#include "SEServiceHelper.h"
-
-namespace smartcard_service_api
-{
-       SEServiceHelper::~SEServiceHelper()
-       {
-               _BEGIN();
-               _END();
-       }
-
-} /* namespace smartcard_service_api */
diff --git a/common/SessionHelper.cpp b/common/SessionHelper.cpp
deleted file mode 100644 (file)
index fde6560..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * 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 "ReaderHelper.h"
-
-namespace smartcard_service_api
-{
-       SessionHelper::SessionHelper(ReaderHelper *reader) :
-               closed(true)
-       {
-               this->reader = reader;
-       }
-} /* namespace smartcard_service_api */
index 0cbce9c..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>
@@ -44,7 +44,7 @@ namespace smartcard_service_api
                return aul_app_get_pkgname_bypid(pid, package, length);
        }
 
-       ByteArray SignatureHelper::getCertificationHash(const char *packageName)
+       const ByteArray SignatureHelper::getCertificationHash(const char *packageName)
        {
                ByteArray result;
                int ret = 0;
@@ -81,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)
                                                        {
-                                                               _DBG("type [%d] hash [%d] : %s", type, result.getLength(), result.toString());
+                                                               _DBG("type [%d] hash [%d] : %s", type, result.size(), result.toString().c_str());
                                                                break;
                                                        }
                                                }
@@ -105,7 +105,7 @@ namespace smartcard_service_api
                return result;
        }
 
-       ByteArray SignatureHelper::getCertificationHash(int pid)
+       const ByteArray SignatureHelper::getCertificationHash(int pid)
        {
                ByteArray result;
                int error = 0;
@@ -179,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)
                                                                {
-                                                                       _DBG("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);
                                                                }
                                                        }
@@ -227,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)
                {
index 90ffbfe..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;
 
@@ -212,7 +211,7 @@ 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;
index 8d8f08b..2b77288 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()
-       {
-               initialize();
        }
 
-       TLVHelper::TLVHelper(TLVHelper *parent)
+       TLVHelper::TLVHelper(TLVHelper *parent) : currentTLV(this),
+               parentTLV(parent), childTLV(NULL),
+               offset(0), currentT(0), currentL(0)
        {
-               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,9 +58,7 @@ namespace smartcard_service_api
 
        bool TLVHelper::setTLVBuffer(const ByteArray &array, TLVHelper *parent)
        {
-               initialize(parent);
-
-               if (array.getLength() == 0)
+               if (array.size() == 0)
                        return false;
 
                tlvBuffer = array;
@@ -72,7 +66,7 @@ namespace smartcard_service_api
                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 +78,7 @@ namespace smartcard_service_api
 
                currentT = 0;
                currentL = 0;
-               currentV.releaseBuffer();
+               currentV.clear();
 
                if (isEndOfBuffer())
                        return false;
@@ -103,7 +97,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 +112,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 +135,7 @@ namespace smartcard_service_api
                bool result = false;
                TLVHelper *temp = NULL;
 
-               if (getLength() >= 2)
+               if (size() >= 2)
                {
                        temp = currentTLV->getChildTLV(getValue());
 
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 f9aac60..ca1f4af 100644 (file)
@@ -37,12 +37,10 @@ namespace smartcard_service_api
                bool nfcRule;
                vector<pair<ByteArray, ByteArray> > listFilters;
 
-               void printAccessRules();
+               void printAccessRules() const;
 
        public :
-               AccessRule() : apduRule(true), nfcRule(true)
-               {
-               }
+               AccessRule() : apduRule(true), nfcRule(true) {}
 
                inline void setAPDUAccessRule(bool rule) { apduRule = rule; }
                inline void setNFCAccessRule(bool rule) { nfcRule = rule; }
@@ -50,12 +48,12 @@ namespace smartcard_service_api
                void addAPDUAccessRule(const ByteArray &apdu,
                        const ByteArray &mask);
 
-               inline bool isAuthorizedAccess(void)
+               inline bool isAuthorizedAccess(void) const
                {
                        return (apduRule || (listFilters.size() > 0));
                }
-               bool isAuthorizedAPDUAccess(const ByteArray &command);
-               bool isAuthorizedNFCAccess(void);
+               bool isAuthorizedAPDUAccess(const ByteArray &command) const;
+               bool isAuthorizedNFCAccess(void) const;
 
                friend class AccessCondition;
        };
@@ -67,18 +65,15 @@ namespace smartcard_service_api
                ByteArray aid;
                map<ByteArray, AccessRule> mapRules;
 
-               void printAccessConditions();
+               void printAccessConditions() const;
 
        public :
-               AccessCondition() : permission(false)
-               {
-               }
+               AccessCondition() : permission(false) {}
 
                inline void setAID(const ByteArray &aid) { this->aid = aid; }
-               inline ByteArray getAID() { return aid; }
+               inline const ByteArray getAID() const { return aid; }
                inline void setAccessCondition(bool rule) { permission = rule; }
                void addAccessRule(const ByteArray &hash);
-               AccessCondition *getAccessCondition(const ByteArray &hash);
 
                void setAPDUAccessRule(const ByteArray &certHash, bool rule);
                void addAPDUAccessRule(const ByteArray &certHash,
@@ -88,12 +83,14 @@ namespace smartcard_service_api
 
                void setNFCAccessRule(const ByteArray &certHash, bool rule);
 
-               bool isAuthorizedAccess(const ByteArray &certHash);
+               bool isAuthorizedAccess(const ByteArray &certHash) const;
                bool isAuthorizedAPDUAccess(const ByteArray &certHash,
-                       const ByteArray &command);
-               bool isAuthorizedNFCAccess(const ByteArray &certHash);
+                       const ByteArray &command) const;
+               bool isAuthorizedNFCAccess(const ByteArray &certHash) const;
 
                AccessRule *getAccessRule(const ByteArray &certHash);
+               const AccessRule *getAccessRule(const ByteArray &certHash) const;
+
 
                friend class AccessControlList;
        };
index 93c532c..f87e309 100644 (file)
@@ -38,11 +38,11 @@ namespace smartcard_service_api
                map<ByteArray, AccessCondition> mapConditions;
                bool allGranted;
 
-               AccessRule *findAccessRule(const ByteArray &aid,
-                       const ByteArray &hash);
+               const AccessRule *findAccessRule(const ByteArray &aid,
+                       const ByteArray &hash) const;
                AccessCondition &getAccessCondition(const ByteArray &aid);
 
-               void printAccessControlList();
+               void printAccessControlList() const;
 
        public:
                static ByteArray ALL_SE_APPS;
@@ -57,17 +57,17 @@ namespace smartcard_service_api
                int updateACL(Channel *channel) { return loadACL(channel); }
                void releaseACL();
 
-               virtual bool isAuthorizedAccess(ByteArray &aid,
-                       ByteArray &certHash);
-               virtual bool isAuthorizedAccess(unsigned char *aidBuffer,
-                       unsigned int aidLength, unsigned char *certHashBuffer,
-                       unsigned int certHashLength);
-               virtual bool isAuthorizedAccess(ByteArray &aid,
-                       vector<ByteArray> &certHashes);
-               virtual bool isAuthorizedAccess(ByteArray &aid,
-                       vector<ByteArray> &certHashes, ByteArray &command);
-               virtual bool isAuthorizedNFCAccess(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 ee1edf9..72e0054 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();
 
-               uint32_t getLength() const;
-               uint8_t *getBuffer() const;
-               uint8_t *getBuffer(uint32_t offset) const;
+               size_t size() const;
+               inline size_t getLength() const { return size(); }
+               uint8_t *getBuffer();
+               inline const uint8_t *getBuffer() const { return getBuffer(); }
+               uint8_t *getBuffer(size_t offset);
+               inline const uint8_t *getBuffer(size_t offset) const { return getBuffer(offset); }
 
-               uint8_t getAt(uint32_t index) const;
-               uint8_t getReverseAt(uint32_t index) const;
+               uint8_t at(size_t index) const;
+               uint8_t reverseAt(size_t index) const;
 
-               uint32_t copyFromArray(uint8_t *array, uint32_t bufferLen) const;
+               size_t extract(uint8_t *array, size_t size) const;
 
-               ByteArray sub(uint32_t offset, uint32_t size) const;
+               const ByteArray sub(size_t offset, size_t size) const;
 
                /* operator overloading */
                ByteArray &operator =(const ByteArray &T);
@@ -72,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() const { return (buffer == (void *)0 || length == 0); }
-               const char *toString();
+               const string toString() const;
        };
 
 } /* namespace smartcard_service_api */
index 832e29c..e2b6899 100644 (file)
@@ -30,8 +30,8 @@ namespace smartcard_service_api
 {
        class SessionHelper;    /* explicit declaration */
 
-       typedef void (*transmitCallback)(unsigned char *buffer, unsigned int length,
-               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
@@ -44,7 +44,7 @@ namespace smartcard_service_api
                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(closeChannelCallback callback, void *userParam) = 0;
-               virtual int transmit(ByteArray command, transmitCallback callback, void *userData) = 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 2efcb65..355974a 100644 (file)
@@ -18,6 +18,7 @@
 #define DEBUG_H_
 
 /* standard library header */
+#include <iostream>
 
 /* SLP library header */
 #include "dlog.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 4dc4f08..becd584 100644 (file)
 
 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; }
        };
 
index 556cdf6..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:
                EFDIR(Channel *channel);
-               EFDIR(Channel *channel, ByteArray selectResponse);
+               EFDIR(Channel *channel, const ByteArray &selectResponse);
                ~EFDIR();
 
                int select();
 
-               ByteArray getPathByAID(ByteArray &aid);
+               const ByteArray getPathByAID(const ByteArray &aid);
        };
 } /* namespace smartcard_service_api */
 #endif /* EFDIR_H_ */
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 d38105a..1802784 100644 (file)
@@ -62,16 +62,16 @@ namespace smartcard_service_api
                ~FileObject();
 
                void close();
-               inline bool isClosed() { return (opened == false); }
+               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();
 
-               inline ByteArray getSelectResponse() { return selectResponse; }
+               inline const ByteArray getSelectResponse() const { return selectResponse; }
 
-               FCI *getFCI();
-               FCP *getFCP();
+               const FCI *getFCI() const;
+               const FCP *getFCP() const;
 
                int readRecord(unsigned int sfi, unsigned int recordId, Record &result);
                int writeRecord(unsigned int sfi, const Record &record);
index e2033c3..8de47d4 100644 (file)
@@ -35,9 +35,6 @@ namespace smartcard_service_api
        class GDBusHelper
        {
        public :
-               GDBusHelper();
-               ~GDBusHelper();
-
                static void convertVariantToByteArray(GVariant *var,
                        ByteArray &array);
 
index 4754d31..5300dfd 100644 (file)
@@ -41,17 +41,19 @@ namespace smartcard_service_api
 
                int loadACL(Channel *channel);
 
-               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);
-               bool isAuthorizedAccess(ByteArray &aid,
-                       vector<ByteArray> &certHashes, ByteArray &command);
-               bool isAuthorizedNFCAccess(ByteArray &aid,
-                       vector<ByteArray> &certHashes);
+               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 */
index 305f7f9..4038b41 100644 (file)
@@ -39,7 +39,7 @@ namespace smartcard_service_api
                void addCondition(const ByteArray &aid, const ByteArray &hash,
                        const vector<ByteArray> &apduRule, const ByteArray &nfcRule);
 
-               int updateRule(ByteArray &data);
+               int updateRule(const ByteArray &data);
 
        public:
                GPARAACL();
@@ -48,19 +48,23 @@ namespace smartcard_service_api
                int loadACL(Channel *channel);
                int loadACL(GPARAM &aram);
 
-               bool isAuthorizedAccess(GPARAM &aram, ByteArray &aid,
-                       ByteArray &certHash);
-               bool isAuthorizedAccess(GPARAM &aram, ByteArray &aid,
-                       ByteArray &certHash, ByteArray &command);
-               bool isAuthorizedAccess(GPARAM &aram, unsigned char *aidBuffer,
-                       unsigned int aidLength, unsigned char *certHashBuffer,
-                       unsigned int certHashLength);
-               bool isAuthorizedAccess(GPARAM &aram, ByteArray &aid,
-                       vector<ByteArray> &certHashes);
-               bool isAuthorizedAccess(GPARAM &aram, ByteArray &aid,
-                       vector<ByteArray> &certHashes, ByteArray &command);
-               bool isAuthorizedNFCAccess(GPARAM &aram, ByteArray &aid,
-                       vector<ByteArray> &certHashes);
+               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 */
index 00745ad..8761815 100644 (file)
@@ -73,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);
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 4bb6a40..28abd03 100644 (file)
 #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,15 +58,15 @@ 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 */
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 5d6f265..3900f13 100644 (file)
@@ -48,7 +48,7 @@ namespace smartcard_service_api
                int select();
 
                PKCS15ODF *getODF();
-               int getTokenInfo(ByteArray &path);
+               int getTokenInfo(ByteArray &path) const;
        };
 
 } /* namespace smartcard_service_api */
index 24660fe..9364245 100644 (file)
@@ -32,14 +32,14 @@ namespace smartcard_service_api
        private:
                map<ByteArray, PKCS15OID> mapOID;
 
-               bool parseData(ByteArray data);
+               bool parseData(const ByteArray &data);
 
        public:
                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 409ffde..1deb36d 100644 (file)
@@ -33,7 +33,7 @@ namespace smartcard_service_api
        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..f34436c 100644 (file)
@@ -19,6 +19,7 @@
 
 /* standard library header */
 #include <vector>
+#include <string>
 
 /* SLP library header */
 
@@ -37,18 +38,18 @@ namespace smartcard_service_api
        class ReaderHelper : public Synchronous
        {
        protected:
-               char name[30];
+               string name;
                vector<SessionHelper *> sessions;
                SEServiceHelper *seService;
                bool present;
 
-               ReaderHelper();
+               ReaderHelper() : seService(NULL), 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 f436ab8..5d7128a 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,16 +73,16 @@ namespace smartcard_service_api
                        throw(ExceptionBase &, ErrorIO &, ErrorSecurity &,
                        ErrorIllegalState &, ErrorIllegalParameter &) = 0;
 
-               virtual Channel *openBasicChannelSync(ByteArray &aid)
+               virtual Channel *openBasicChannelSync(const ByteArray &aid)
                        throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &) = 0;
 
-               virtual Channel *openBasicChannelSync(unsigned char *aid, unsigned int length)
+               virtual Channel *openBasicChannelSync(const unsigned char *aid, unsigned int length)
                        throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &) = 0;
 
-               virtual Channel *openLogicalChannelSync(ByteArray &aid)
+               virtual Channel *openLogicalChannelSync(const ByteArray &aid)
                        throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &) = 0;
 
-               virtual Channel *openLogicalChannelSync(unsigned char *aid, unsigned int length)
+               virtual Channel *openLogicalChannelSync(const unsigned char *aid, unsigned int length)
                        throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &) = 0;
        };
 
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 c0adb27..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
        {
@@ -50,17 +50,17 @@ namespace smartcard_service_api
 
                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;
        };
 
index 1e58a5f..6fa5796 100644 (file)
@@ -1,7 +1,7 @@
 # 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"
+#%%global test_client "-DTEST_CLIENT=1"
 
 Name:       smartcard-service
 Summary:    Smartcard Service FW
index 8aed081..9d3be5d 100644 (file)
@@ -31,16 +31,16 @@ ENDFOREACH(flag)
 
 MESSAGE("CHECK MODULE in ${PROJECT_NAME} ${pkgs_server_LDFLAGS}")
 
-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")
 
+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")
+
 FIND_PROGRAM(UNAME NAMES uname)
 EXEC_PROGRAM("${UNAME}" ARGS "-m" OUTPUT_VARIABLE "ARCH")
 IF("${ARCH}" MATCHES "^arm.*")
index 93e4857..04f668f 100644 (file)
@@ -86,14 +86,14 @@ namespace smartcard_service_api
        }
 
 #ifndef USE_GDBUS
-       bool ClientInstance::sendMessageToAllServices(int socket, Message &msg)
+       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;
                }
 
index 9765541..a77406d 100644 (file)
@@ -48,13 +48,13 @@ 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);
 
@@ -69,18 +69,19 @@ namespace smartcard_service_api
                        }
                        else
                        {
-                               _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)
                {
@@ -96,17 +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(command);
+               helper.getBuffer(cmd);
 
-               _DBG("command [%d] : %s", command.getLength(), command.toString());
+               _DBG("command [%d] : %s", cmd.size(), cmd.toString().c_str());
 
-               ret = terminal->transmitSync(command, result);
+               ret = terminal->transmitSync(cmd, result);
 
                return ret;
        }
index 2d782d3..178243f 100644 (file)
@@ -136,7 +136,7 @@ namespace smartcard_service_api
                                }
 
                                /* response to client */
-                               ServerIPC::getInstance()->sendMessage(socket, &response);
+                               ServerIPC::getInstance()->sendMessage(socket, response);
                        }
                        break;
 
@@ -151,7 +151,7 @@ namespace smartcard_service_api
                                resource->removeService(socket, msg->param1);
 
                                /* response to client */
-                               ServerIPC::getInstance()->sendMessage(socket, &response);
+                               ServerIPC::getInstance()->sendMessage(socket, response);
                        }
                        break;
 
@@ -186,7 +186,7 @@ namespace smartcard_service_api
                                response.param1 = handle;
 
                                /* response to client */
-                               ServerIPC::getInstance()->sendMessage(socket, &response);
+                               ServerIPC::getInstance()->sendMessage(socket, response);
                        }
                        break;
 
@@ -205,7 +205,7 @@ namespace smartcard_service_api
                                }
 
                                /* response to client */
-                               ServerIPC::getInstance()->sendMessage(socket, &response);
+                               ServerIPC::getInstance()->sendMessage(socket, response);
                        }
                        break;
 
@@ -217,7 +217,7 @@ namespace smartcard_service_api
 
                                response.param1 = IntegerHandle::INVALID_HANDLE;
                                response.param2 = 0;
-                               response.data.releaseBuffer();
+                               response.data.clear();
 
                                try
                                {
@@ -256,7 +256,7 @@ namespace smartcard_service_api
                                }
 
                                /* response to client */
-                               ServerIPC::getInstance()->sendMessage(socket, &response);
+                               ServerIPC::getInstance()->sendMessage(socket, response);
                        }
                        break;
 
@@ -270,7 +270,7 @@ namespace smartcard_service_api
                                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;
 
@@ -288,7 +288,7 @@ namespace smartcard_service_api
                                }
 
                                /* response to client */
-                               ServerIPC::getInstance()->sendMessage(socket, &response);
+                               ServerIPC::getInstance()->sendMessage(socket, response);
                        }
                        break;
 
@@ -332,7 +332,7 @@ namespace smartcard_service_api
                                }
 
                                /* response to client */
-                               ServerIPC::getInstance()->sendMessage(socket, &response);
+                               ServerIPC::getInstance()->sendMessage(socket, response);
                        }
                        break;
 
@@ -366,7 +366,7 @@ namespace smartcard_service_api
                                }
 
                                /* response to client */
-                               ServerIPC::getInstance()->sendMessage(socket, &response);
+                               ServerIPC::getInstance()->sendMessage(socket, response);
                        }
                        break;
 
@@ -387,7 +387,7 @@ namespace smartcard_service_api
                        break;
 
                default :
-                       _DBG("unknown message [%s], socket [%d]", msg->toString(), socket);
+                       _DBG("unknown message [%s], socket [%d]", msg->toString().c_str(), socket);
                        break;
                }
 
index b683375..537034f 100644 (file)
@@ -37,7 +37,7 @@
 
 namespace smartcard_service_api
 {
-       ServerIPC::ServerIPC():IPCHelper()
+       ServerIPC::ServerIPC() : IPCHelper()
        {
                _BEGIN();
 
@@ -71,10 +71,10 @@ namespace smartcard_service_api
                        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)
@@ -209,7 +209,7 @@ ERROR :
                        dispMsg.setPeerSocket(peerSocket);
 
                        /* push to dispatcher */
-                       ServerDispatcher::getInstance()->pushMessage(&dispMsg);
+                       ServerDispatcher::getInstance()->pushMessage(dispMsg);
                }
 
                _END();
@@ -251,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;
 
index 43cd288..4b880d2 100644 (file)
 
 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)
                {
                        _ERR("invalid param");
 
@@ -46,34 +43,12 @@ namespace smartcard_service_api
 
                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)
-               {
-                       _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 GPACE();
-                       if (acList != NULL)
-                       {
-                               acList->loadACL(adminChannel);
-                       }
-                       else
-                       {
-                               _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 bc86a06..ae14a4e 100644 (file)
@@ -172,7 +172,7 @@ namespace smartcard_service_api
                mapClients.clear();
        }
 
-       int ServerResource::getClientCount()
+       int ServerResource::getClientCount() const
        {
                return (int)mapClients.size();
        }
@@ -393,13 +393,15 @@ namespace smartcard_service_api
                }
        }
 #else
-       bool ServerResource::createClient(void *ioChannel, int socket, int watchID, int state, int pid)
+       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));
@@ -456,6 +458,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;
@@ -500,7 +515,7 @@ namespace smartcard_service_api
                mapClients.clear();
        }
 
-       int ServerResource::getClientCount()
+       int ServerResource::getClientCount() const
        {
                return (int)mapClients.size();
        }
@@ -570,7 +585,7 @@ namespace smartcard_service_api
                }
        }
 
-       unsigned int ServerResource::createSession(int socket, unsigned int handle, unsigned int readerID, vector<ByteArray> &certHashes, void *caller)
+       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;
@@ -646,7 +661,7 @@ namespace smartcard_service_api
                }
        }
 
-       unsigned int ServerResource::createChannel(int socket, unsigned int handle, unsigned int sessionID, int channelType, ByteArray aid)
+       unsigned int ServerResource::createChannel(int socket, unsigned int handle, unsigned int sessionID, int channelType, const ByteArray &aid)
                throw(ExceptionBase &)
        {
                unsigned int result = -1;
@@ -738,6 +753,23 @@ namespace smartcard_service_api
                return result;
        }
 
+       const Terminal *ServerResource::getTerminal(unsigned int terminalID) const
+       {
+               const Terminal *result = NULL;
+               map<unsigned int, Terminal *>::const_iterator item;
+
+               if ((item = mapTerminals.find(terminalID)) != mapTerminals.end())
+               {
+                       result = item->second;
+               }
+               else
+               {
+                       _ERR("Terminal doesn't exist [%d]", terminalID);
+               }
+
+               return result;
+       }
+
        Terminal *ServerResource::getTerminal(const char *name)
        {
                Terminal *result = NULL;
@@ -755,26 +787,27 @@ namespace smartcard_service_api
                return result;
        }
 
-       Terminal *ServerResource::getTerminalByIndex(int index)
+       Terminal *ServerResource::getTerminalByReaderID(unsigned int readerID)
        {
-               int count = 0;
                Terminal *result = NULL;
-               map<unsigned int, Terminal *>::iterator item;
+               map<unsigned int, unsigned int>::iterator item;
 
-               for (item = mapTerminals.begin(), count = 0; item != mapTerminals.end(); item++, count++) {
-                       if (count == index) {
-                               result = item->second;
-                               break;
-                       }
+               if ((item = mapReaders.find(readerID)) != mapReaders.end())
+               {
+                       result = getTerminal(item->second);
+               }
+               else
+               {
+                       _ERR("Terminal doesn't exist, reader ID [%d]", readerID);
                }
 
                return result;
        }
 
-       Terminal *ServerResource::getTerminalByReaderID(unsigned int readerID)
+       const Terminal *ServerResource::getTerminalByReaderID(unsigned int readerID) const
        {
-               Terminal *result = NULL;
-               map<unsigned int, unsigned int>::iterator item;
+               const Terminal *result = NULL;
+               map<unsigned int, unsigned int>::const_iterator item;
 
                if ((item = mapReaders.find(readerID)) != mapReaders.end())
                {
@@ -788,14 +821,16 @@ namespace smartcard_service_api
                return result;
        }
 
-       unsigned int ServerResource::getTerminalID(const char *name)
+       unsigned int ServerResource::getTerminalID(const char *name) const
        {
                unsigned int result = IntegerHandle::INVALID_HANDLE;
-               map<unsigned int, Terminal *>::iterator item;
+               map<unsigned int, Terminal *>::const_iterator item;
 
-               for (item = mapTerminals.begin(); item != mapTerminals.end(); item++)
+               for (item = mapTerminals.begin();
+                       item != mapTerminals.end(); item++)
                {
-                       if (strncmp(name, item->second->getName(), strlen(name)) == 0)
+                       if (strncmp(name, item->second->getName(),
+                               strlen(name)) == 0)
                        {
                                result = item->first;
                                break;
@@ -805,7 +840,8 @@ namespace smartcard_service_api
                return result;
        }
 
-       bool ServerResource::_isAuthorizedAccess(ServerChannel *channel, ByteArray aid, vector<ByteArray> &hashes)
+       bool ServerResource::_isAuthorizedAccess(ServerChannel *channel,
+               const ByteArray aid, const vector<ByteArray> &hashes)
        {
                bool result = true;
                AccessControlList *acList = NULL;
@@ -859,7 +895,7 @@ 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);
 
@@ -874,7 +910,7 @@ namespace smartcard_service_api
                }
                else
                {
-                       _ERR("transmitSync failed, rv [%d], length [%d]", rv, response.getLength());
+                       _ERR("transmitSync failed, rv [%d], length [%d]", rv, response.size());
                }
 
                return result;
@@ -890,7 +926,7 @@ 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);
 
@@ -906,13 +942,15 @@ namespace smartcard_service_api
                }
                else
                {
-                       _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;
@@ -1203,15 +1241,15 @@ namespace smartcard_service_api
                }
        }
 
-       bool ServerResource::isValidReaderHandle(unsigned int reader)
+       bool ServerResource::isValidReaderHandle(unsigned int reader) const
        {
                return (getTerminalByReaderID(reader) != NULL);
        }
 
-       void ServerResource::getReaders(vector<pair<unsigned int, string> > &readers)
+       void ServerResource::getReaders(vector<pair<unsigned int, string> > &readers) const
        {
-               Terminal *terminal;
-               map<unsigned int, unsigned int>::iterator item;
+               const Terminal *terminal;
+               map<unsigned int, unsigned int>::const_iterator item;
 
                readers.clear();
 
@@ -1228,7 +1266,7 @@ namespace smartcard_service_api
                }
        }
 
-       int ServerResource::getReadersInformation(ByteArray &info)
+       int ServerResource::getReadersInformation(ByteArray &info) const
        {
                int result = 0;
                unsigned char *buffer = NULL;
@@ -1238,8 +1276,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++)
                        {
@@ -1286,7 +1324,7 @@ namespace smartcard_service_api
                                        }
                                }
 
-                               info.setBuffer(buffer, length);
+                               info.assign(buffer, length);
                                delete []buffer;
                        }
                        else
@@ -1304,15 +1342,17 @@ namespace smartcard_service_api
        }
 
 #ifndef USE_GDBUS
-       bool ServerResource::sendMessageToAllClients(Message &msg)
+       bool ServerResource::sendMessageToAllClients(const Message &msg)
        {
                bool result = true;
 
-               map<int, ClientInstance *>::iterator item;
+               map<int, ClientInstance *>::const_iterator item;
 
-               for (item = mapClients.begin(); item != mapClients.end(); 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;
                }
 
@@ -1320,7 +1360,8 @@ namespace smartcard_service_api
        }
 #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)
        {
                _DBG("terminal [%s], event [%d], error [%d], user_param [%p]", (char *)terminal, event, error, user_param);
 
@@ -1345,7 +1386,8 @@ namespace smartcard_service_api
                                        /* send all client to refresh reader */
                                        msg.message = msg.MSG_NOTIFY_SE_INSERTED;
                                        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
@@ -1362,14 +1404,16 @@ namespace smartcard_service_api
 
                                readerID = instance.getReaderID((char *)terminal);
 #ifdef USE_GDBUS
-                               ServerGDBus::getInstance().emitReaderRemoved(readerID, (const char *)terminal);
+                               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
@@ -1394,16 +1438,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)
                                {
@@ -1426,7 +1472,8 @@ namespace smartcard_service_api
                }
        }
 
-       bool ServerResource::isAuthorizedNFCAccess(Terminal *terminal, ByteArray &aid, vector<ByteArray> &hashes)
+       bool ServerResource::isAuthorizedNFCAccess(Terminal *terminal,
+               const ByteArray &aid, const vector<ByteArray> &hashes)
        {
                bool result = false;
 
index 6c119af..dc878e9 100644 (file)
@@ -97,7 +97,7 @@ namespace smartcard_service_api
 
                                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)
@@ -226,12 +226,12 @@ namespace smartcard_service_api
                }
 
                /* 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)
        {
                switch (event)
                {
@@ -242,7 +242,7 @@ namespace smartcard_service_api
 
                                /* send all client to refresh reader */
                                msg.message = msg.MSG_NOTIFY_SE_INSERTED;
-                               msg.data.setBuffer((unsigned char *)terminal,
+                               msg.data.assign((unsigned char *)terminal,
                                        strlen((char *)terminal) + 1);
 
                                ServerResource::getInstance().sendMessageToAllClients(msg);
@@ -257,7 +257,7 @@ namespace smartcard_service_api
 
                                /* send all client to refresh reader */
                                msg.message = msg.MSG_NOTIFY_SE_REMOVED;
-                               msg.data.setBuffer((unsigned char *)terminal,
+                               msg.data.assign((unsigned char *)terminal,
                                        strlen((char *)terminal) + 1);
 
                                ServerResource::getInstance().sendMessageToAllClients(msg);
index bd587dc..fcbc37a 100644 (file)
@@ -31,7 +31,7 @@
 namespace smartcard_service_api
 {
        ServerSession::ServerSession(ServerReader *reader,
-               vector<ByteArray> &certHashes,
+               const vector<ByteArray> &certHashes,
                void *caller, Terminal *terminal) : SessionHelper(reader)
        {
                this->terminal = NULL;
@@ -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,20 +96,20 @@ 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 &)
        {
                ByteArray temp(aid, length);
@@ -105,7 +117,7 @@ namespace smartcard_service_api
                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 &)
        {
                ByteArray temp(aid, length);
@@ -113,20 +125,20 @@ namespace smartcard_service_api
                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 &)
        {
                ByteArray temp(aid, length);
@@ -134,7 +146,7 @@ namespace smartcard_service_api
                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 &)
        {
                ByteArray temp(aid, length);
index aaff33f..c7c1129 100644 (file)
@@ -42,7 +42,7 @@ namespace smartcard_service_api
                }
        }
 
-       unsigned int ServiceInstance::openSession(Terminal *terminal, vector<ByteArray> &certHashes, void *caller)
+       unsigned int ServiceInstance::openSession(Terminal *terminal, const vector<ByteArray> &certHashes, void *caller)
        {
                unsigned int handle = IntegerHandle::assignHandle();
 
@@ -112,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;
index 581c52b..c8ddc45 100644 (file)
@@ -85,7 +85,7 @@ namespace smartcard_service_api
                void removeService(unsigned int handle);
                void removeServices();
 #ifndef USE_GDBUS
-               bool sendMessageToAllServices(int socket, Message &msg);
+               bool sendMessageToAllServices(int socket, const Message &msg);
 #endif
                void generateCertificationHashes();
 
index 8113e91..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:
@@ -52,7 +52,7 @@ namespace smartcard_service_api
                Terminal *getTerminal() { return terminal; }
 
                int close(closeChannelCallback callback, void *userParam) { return -1; }
-               int transmit(ByteArray command, transmitCallback callback, void *userParam) { return -1; };
+               int transmit(const ByteArray &command, transmitCallback callback, void *userParam) { return -1; };
 
                friend class ServerReader;
                friend class ServerSession;
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 504a5f0..add3ccf 100644 (file)
@@ -83,12 +83,12 @@ 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, 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:
@@ -109,16 +109,17 @@ namespace smartcard_service_api
                void unloadSecureElements();
 
                Terminal *getTerminal(unsigned int terminalID);
+               const Terminal *getTerminal(unsigned int terminalID) const;
                Terminal *getTerminal(const char *name);
-               Terminal *getTerminalByIndex(int index);
                Terminal *getTerminalByReaderID(unsigned int readerID);
-               unsigned int getTerminalID(const char *name);
-               int getReadersInformation(ByteArray &info);
-               void getReaders(vector<pair<unsigned int, string> > &readers);
-               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
@@ -126,7 +127,7 @@ namespace smartcard_service_api
                ClientInstance *getClient(const char *name);
                void removeClient(const char *name);
                void removeClients();
-               int getClientCount();
+               int getClientCount() const;
 
                ServiceInstance *createService(const char *name);
                ServiceInstance *getService(const char *name, unsigned int handle);
@@ -148,24 +149,25 @@ namespace smartcard_service_api
                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);
                void removeClient(int socket);
                void removeClients();
-               int getClientCount();
+               int getClientCount() const;
 
                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 handle, unsigned int readerID, vector<ByteArray> &certHashes, void *caller);
+               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 handle,
-                       unsigned int sessionID, int channelType, ByteArray aid)
+                       unsigned int sessionID, int channelType, const ByteArray &aid)
                        throw(ExceptionBase &);
                Channel *getChannel(int socket, unsigned int handle, unsigned int channelID);
                void removeChannel(int socket, unsigned int handle, unsigned int channelID);
@@ -175,10 +177,10 @@ namespace smartcard_service_api
                AccessControlList *getAccessControlList(Terminal *terminal);
                AccessControlList *getAccessControlList(ServerChannel *channel);
 #ifndef USE_GDBUS
-               bool sendMessageToAllClients(Message &msg);
+               bool sendMessageToAllClients(const Message &msg);
 #endif
-               bool isAuthorizedNFCAccess(Terminal *terminal, ByteArray &aid,
-                       vector<ByteArray> &hashes);
+               bool isAuthorizedNFCAccess(Terminal *terminal, const ByteArray &aid,
+                       const vector<ByteArray> &hashes);
 
                friend void terminalCallback(void *terminal, int event, int error, void *user_param);
        };
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 93396d5..a2f66df 100644 (file)
@@ -41,19 +41,21 @@ namespace smartcard_service_api
                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 &);
@@ -61,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 f31ec4a..a1acaea 100644 (file)
@@ -50,14 +50,14 @@ namespace smartcard_service_api
                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);
 
index c4c2526..27dc303 100644 (file)
@@ -117,11 +117,11 @@ void testConnectedCallback(SEServiceHelper *service, void *userData)
                                {
                                        _ERR("exception....");
                                }
-                               _DBG("atr[%d] : %s", temp.getLength(), temp.toString());
+                               _DBG("atr[%d] : %s", temp.size(), temp.toString().c_str());
 
                                ByteArray aid;
 
-                               aid.setBuffer(buffer, sizeof(buffer));
+                               aid.assign(buffer, sizeof(buffer));
                                try
                                {
                                        ClientChannel *channel = (ClientChannel *)session->openLogicalChannelSync(aid);
@@ -133,16 +133,16 @@ void testConnectedCallback(SEServiceHelper *service, void *userData)
                                                int fid = 0x00003150;
 
                                                response = channel->getSelectResponse();
-                                               _INFO("response : %s", response.toString());
+                                               _INFO("response : %s", response.toString().c_str());
 
                                                _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);
                                                int error = channel->transmitSync(command, response);
 
-                                               _INFO("error : %d, response : %s", error, response.toString());
+                                               _INFO("error : %d, response : %s", error, response.toString().c_str());
 
                                                channel->closeSync();
                                        }
index 29b8077..6397f47 100644 (file)
@@ -126,12 +126,12 @@ void testOpenChannelCallback(Channel *channel, int error, void *userData)
 
                response = channel->getSelectResponse();
 
-               _INFO("response : %s", response.toString());
+               _INFO("response : %s", response.toString().c_str());
 
                _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);
        }
@@ -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;
 
-       _DBG("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);
 }