fix SATIZENVUL-265 issue(SVACE: CPP_ALLOCATION_ERRORS)
[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 "GPACE.h"
30
31 namespace smartcard_service_api
32 {
33         ServerReader::ServerReader(ServerSEService *seService,
34                 const char *name, Terminal *terminal) : ReaderHelper()
35         {
36                 if (seService == NULL || name == NULL ||
37                         strlen(name) == 0 || terminal == NULL)
38                 {
39                         _ERR("invalid param");
40
41                         return;
42                 }
43
44                 this->terminal = terminal;
45                 this->seService = seService;
46                 this->name = name;
47         }
48
49         ServerReader::~ServerReader()
50         {
51                 closeSessions();
52         }
53
54         void ServerReader::closeSessions()
55                 throw(ErrorIO &, ErrorIllegalState &)
56         {
57                 size_t i;
58
59                 for (i = 0; i < sessions.size(); i++)
60                 {
61                         if (sessions[i] != NULL)
62                                 ((ServerSession *)sessions[i])->closeSync();
63                 }
64
65                 sessions.clear();
66         }
67
68         ServerSession *ServerReader::openSessionSync()
69                 throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &)
70         {
71                 vector<ByteArray> temp;
72
73                 return openSessionSync(temp, NULL);
74         }
75
76         ServerSession *ServerReader::openSessionSync(const vector<ByteArray> &certHashes, void *caller)
77                 throw(ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &)
78         {
79                 ServerSession *session = NULL;
80
81                 session = new (std::nothrow) ServerSession(this, certHashes, caller, terminal);
82                 if (session == NULL)
83                         return session;
84
85                 sessions.push_back(session);
86
87                 return session;
88         }
89
90 } /* namespace smartcard_service_api */