Change the authorization sequence
[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):ReaderHelper()
34         {
35                 unsigned int length = 0;
36
37                 acList = NULL;
38
39                 if (seService == NULL || name == NULL || strlen(name) == 0 || terminal == NULL)
40                 {
41                         SCARD_DEBUG_ERR("invalid param");
42
43                         return;
44                 }
45
46                 this->terminal = terminal;
47                 this->seService = seService;
48
49                 length = strlen(name);
50                 length = (length < sizeof(this->name)) ? length : sizeof(this->name);
51                 memcpy(this->name, name, length);
52
53                 /* open admin channel */
54                 adminChannel = new ServerChannel(NULL, NULL, 0, terminal);
55                 if (adminChannel == NULL)
56                 {
57                         SCARD_DEBUG_ERR("alloc failed");
58                 }
59         }
60
61         ServerReader::~ServerReader()
62         {
63                 closeSessions();
64
65                 if (acList != NULL)
66                 {
67                         delete acList;
68                         acList = NULL;
69                 }
70
71                 if (adminChannel != NULL)
72                 {
73                         delete adminChannel;
74                         adminChannel = NULL;
75                 }
76         }
77
78         void ServerReader::closeSessions()
79         {
80                 size_t i;
81
82                 for (i = 0; i < sessions.size(); i++)
83                 {
84                         if (sessions[i] != NULL)
85                                 ((ServerSession *)sessions[i])->closeSync();
86                 }
87
88                 sessions.clear();
89         }
90
91         AccessControlList *ServerReader::getAccessControlList()
92         {
93                 if (acList == NULL)
94                 {
95                         /* load access control */
96                         acList = new GPSEACL();
97                         if (acList != NULL)
98                         {
99                                 acList->loadACL(adminChannel);
100                         }
101                         else
102                         {
103                                 SCARD_DEBUG_ERR("alloc failed");
104                         }
105                 }
106
107                 return acList;
108         }
109
110         ServerSession *ServerReader::openSessionSync()
111         {
112                 vector<ByteArray> temp;
113
114                 return openSessionSync(temp, NULL);
115         }
116
117
118         ServerSession *ServerReader::openSessionSync(vector<ByteArray> &certHashes, void *caller)
119         {
120                 ServerSession *session = NULL;
121
122                 session = new ServerSession(this, certHashes, caller, terminal);
123                 if (session == NULL)
124                         return session;
125
126                 sessions.push_back(session);
127
128                 return session;
129         }
130
131 } /* namespace smartcard_service_api */