1 martin 1.10 //%LICENSE////////////////////////////////////////////////////////////////
|
2 martin 1.11 //
|
3 martin 1.10 // Licensed to The Open Group (TOG) under one or more contributor license
4 // agreements. Refer to the OpenPegasusNOTICE.txt file distributed with
5 // this work for additional information regarding copyright ownership.
6 // Each contributor licenses this file to you under the OpenPegasus Open
7 // Source License; you may not use this file except in compliance with the
8 // License.
|
9 martin 1.11 //
|
10 martin 1.10 // Permission is hereby granted, free of charge, to any person obtaining a
11 // copy of this software and associated documentation files (the "Software"),
12 // to deal in the Software without restriction, including without limitation
13 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 // and/or sell copies of the Software, and to permit persons to whom the
15 // Software is furnished to do so, subject to the following conditions:
|
16 martin 1.11 //
|
17 martin 1.10 // The above copyright notice and this permission notice shall be included
18 // in all copies or substantial portions of the Software.
|
19 martin 1.11 //
|
20 martin 1.10 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
21 martin 1.11 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
22 martin 1.10 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
27 martin 1.11 //
|
28 martin 1.10 //////////////////////////////////////////////////////////////////////////
|
29 a.arora 1.2 //
30 //%/////////////////////////////////////////////////////////////////////////////
31
32 #include "CIMDefaultClientConnectionManager.h"
33
34 PEGASUS_NAMESPACE_BEGIN
35
36 // class constructor
37 CIMDefaultClientConnectionManager::CIMDefaultClientConnectionManager()
38 {
|
39 kumpf 1.12
|
40 a.arora 1.2 }
|
41 kumpf 1.12
|
42 a.arora 1.2 // virtual class destructor has to be implemented by specific implementation
43 CIMDefaultClientConnectionManager::~CIMDefaultClientConnectionManager()
44 {
|
45 marek 1.8 CIMClientConnection *remvPointer;
46 for (Uint32 i=0;i<_cccm_container.size();i++)
47 {
48 remvPointer = (CIMClientConnection*) _cccm_container[i];
49 delete remvPointer;
50 }
51 _cccm_container.clear();
|
52 a.arora 1.2 }
53
54 // this function returns the specified connection
55 CIMClientRep* CIMDefaultClientConnectionManager::getConnection(
|
56 marek 1.8 const String& host,
57 const String& port,
58 const CIMNamespaceName& nameSpace)
|
59 a.arora 1.2
60 {
|
61 marek 1.8 char requestedIP[PEGASUS_INET6_ADDRSTR_LEN];
62 Uint32 requestedPort;
|
63 a.arora 1.2
|
64 dave.sudlik 1.7 int af;
|
65 marek 1.9 System::acquireIP((const char*)host.getCString(), &af, requestedIP);
|
66 dave.sudlik 1.7 if (System::isLoopBack(af, requestedIP))
|
67 marek 1.8 {
68 // localhost or ip address of 127.0.0.1
69 // still for compare we need the real ip address
|
70 marek 1.9 System::acquireIP((const char *)
|
71 dave.sudlik 1.7 System::getHostName().getCString(), &af, requestedIP);
|
72 marek 1.8 }
|
73 kumpf 1.12
|
74 marek 1.8 requestedPort = strtoul((const char*) port.getCString(), NULL, 0);
75
76 CIMClientConnection *ccc;
77 CIMClientRep *returnedConnectionHandle;
78
79 // rotate through list to find correct connection
80 for (Uint32 i=0;i<_cccm_container.size();i++)
81 {
82 ccc = _cccm_container[i];
83 if (ccc->equals(requestedIP, af, port))
84 {
85 // okay, we found the correct connection
86 // in case it isn't already connected,
87 // lets connect and return the connection to caller
88 returnedConnectionHandle = ccc->getConnectionHandle();
89 if (returnedConnectionHandle != 0)
90 {
91 // connecting in case we aren't already connected
92 if (!returnedConnectionHandle->isConnected())
93 {
94 // is this a ssl connection ?
95 marek 1.8 if (ccc->getSSLContext() == 0)
96 {
97 // no, we connect without ssl
98 returnedConnectionHandle->connect(
99 host,
100 requestedPort,
101 ccc->getUser(),
102 ccc->getPass());
103 } else
104 {
105 // yes, ssl is enabled
106 returnedConnectionHandle->connect(
107 host,
108 requestedPort,
109 *ccc->getSSLContext(),
110 ccc->getUser(),
111 ccc->getPass());
112 }
|
113 kumpf 1.12 }
|
114 marek 1.8 } else {
115 // in case no fitting connection could be found
116 // a return of NULL shall be returned
117 return 0;
118 }
|
119 kumpf 1.12 // at this stage we found an applicable connection
|
120 marek 1.8 // and also connected already
121 // thus we return the connection handle CIMClientRep
122 return returnedConnectionHandle;
123 }
124 }
125 return 0;
|
126 a.arora 1.2 }
127
|
128 marek 1.8 void CIMDefaultClientConnectionManager::addConnection(
129 const String& host,
130 const String& port,
131 const String& userid,
132 const String& passwd)
|
133 a.arora 1.2 {
|
134 marek 1.8 CIMClientConnection *newConnPointer;
135 newConnPointer = new CIMClientConnection(host, port, userid, passwd);
136 _cccm_container.append(newConnPointer);
|
137 a.arora 1.2 }
138
|
139 marek 1.8 void CIMDefaultClientConnectionManager::addConnection(
140 const String& host,
141 const String& port,
142 const String& userid,
143 const String& passwd,
144 const SSLContext& sslcontext)
|
145 a.arora 1.2 {
|
146 marek 1.8 CIMClientConnection *newConnPointer;
147 newConnPointer = new CIMClientConnection(
148 host,
149 port,
150 userid,
151 passwd,
152 sslcontext);
153
154 _cccm_container.append(newConnPointer);
|
155 a.arora 1.2 }
156
157
158 PEGASUS_NAMESPACE_END
|