Add changelog
[platform/core/connectivity/smartcard-service.git] / server / ServerReader.cpp
1 /*
2  * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 /* standard library header */
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <string.h>
21 #include <dlfcn.h>
22
23 /* SLP library header */
24
25 /* local header */
26 #include "Debug.h"
27 #include "ServerSEService.h"
28 #include "ServerReader.h"
29 #include "GPSEACL.h"
30
31 namespace smartcard_service_api
32 {
33         ServerReader::ServerReader(ServerSEService *seService, char *name, Terminal *terminal) :
34                 ReaderHelper()
35         {
36                 unsigned int length = 0;
37
38                 acList = NULL;
39
40                 if (seService == NULL || name == NULL || strlen(name) == 0 || terminal == NULL)
41                 {
42                         SCARD_DEBUG_ERR("invalid param");
43
44                         return;
45                 }
46
47                 this->terminal = terminal;
48                 this->seService = seService;
49
50                 length = strlen(name);
51                 length = (length < sizeof(this->name)) ? length : sizeof(this->name);
52                 memcpy(this->name, name, length);
53
54                 /* open admin channel */
55                 adminChannel = new ServerChannel(NULL, NULL, 0, terminal);
56                 if (adminChannel == NULL)
57                 {
58                         SCARD_DEBUG_ERR("alloc failed");
59                 }
60         }
61
62         ServerReader::~ServerReader()
63         {
64                 closeSessions();
65
66                 if (acList != NULL)
67                 {
68                         delete acList;
69                         acList = NULL;
70                 }
71
72                 if (adminChannel != NULL)
73                 {
74                         delete adminChannel;
75                         adminChannel = NULL;
76                 }
77         }
78
79         void ServerReader::closeSessions()
80                 throw(ErrorIO &, ErrorIllegalState &)
81         {
82                 size_t i;
83
84                 for (i = 0; i < sessions.size(); i++)
85                 {
86                         if (sessions[i] != NULL)
87                                 ((ServerSession *)sessions[i])->closeSync();
88                 }
89
90                 sessions.clear();
91         }
92
93         AccessControlList *ServerReader::getAccessControlList()
94         {
95                 if (acList == NULL)
96                 {
97                         /* load access control */
98                         acList = new GPSEACL();
99                         if (acList != NULL)
100                         {
101                                 acList->loadACL(adminChannel);
102                         }
103                         else
104                         {
105                                 SCARD_DEBUG_ERR("alloc failed");
106                         }
107                 }
108
109                 return acList;
110         }
111
112         ServerSession *ServerReader::openSessionSync()
113                 throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &)
114         {
115                 vector<ByteArray> temp;
116
117                 return openSessionSync(temp, NULL);
118         }
119
120         ServerSession *ServerReader::openSessionSync(vector<ByteArray> &certHashes, void *caller)
121                 throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &)
122         {
123                 ServerSession *session = NULL;
124
125                 session = new ServerSession(this, certHashes, caller, terminal);
126                 if (session == NULL)
127                         return session;
128
129                 sessions.push_back(session);
130
131                 return session;
132         }
133
134 } /* namespace smartcard_service_api */