1 karl 1.21 //%2003////////////////////////////////////////////////////////////////////////
|
2 mike 1.2 //
|
3 karl 1.21 // Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Development
4 // Company, L. P., IBM Corp., The Open Group, Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L. P.;
6 // IBM Corp.; EMC Corporation, The Open Group.
|
7 mike 1.2 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
|
9 kumpf 1.8 // of this software and associated documentation files (the "Software"), to
10 // deal in the Software without restriction, including without limitation the
11 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
12 mike 1.2 // sell copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
|
15 kumpf 1.8 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
|
16 mike 1.2 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
17 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
18 kumpf 1.8 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
19 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
21 mike 1.2 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 //
24 //==============================================================================
25 //
26 // Author: Nitin Upasani, Hewlett-Packard Company (Nitin_Upasani@hp.com)
27 //
|
28 kumpf 1.10 // Modified By: Carol Ann Krug Graves, Hewlett-Packard Company
29 // (carolann_graves@hp.com)
|
30 kumpf 1.13 // Nag Boranna, Hewlett-Packard Company (nagaraja_boranna@hp.com)
|
31 kumpf 1.16 // Yi Zhou, Hewlett-Packard Company (yi_zhou@hp.com)
|
32 dj.gorey 1.22 // Dan Gorey, IBM (djgorey@us.ibm.com)
|
33 mike 1.2 //
34 //%/////////////////////////////////////////////////////////////////////////////
35
36 #include <Pegasus/ExportClient/CIMExportClient.h>
37 #include <Pegasus/Handler/CIMHandler.h>
38 #include <Pegasus/Repository/CIMRepository.h>
|
39 kumpf 1.15 #include <Pegasus/Config/ConfigManager.h>
|
40 kumpf 1.20 #include <Pegasus/Common/Config.h>
41 #include <Pegasus/Common/PegasusVersion.h>
|
42 kumpf 1.16 #include <Pegasus/Common/Constants.h>
|
43 kumpf 1.20 #include <Pegasus/Common/SSLContext.h>
|
44 kumpf 1.16 #include <Pegasus/Common/System.h>
|
45 kumpf 1.20 #include <Pegasus/Common/Tracer.h>
|
46 mike 1.2
47 PEGASUS_NAMESPACE_BEGIN
48
49 PEGASUS_USING_STD;
50
51
|
52 kumpf 1.13 static Boolean verifyListenerCertificate(SSLCertificateInfo &certInfo)
53 {
54 // ATTN: Add code to handle listener certificate verification.
55 //
56 return true;
57 }
58
59
|
60 mike 1.2 class PEGASUS_HANDLER_LINKAGE CIMxmlIndicationHandler: public CIMHandler
61 {
62 public:
63
64 CIMxmlIndicationHandler()
65 {
|
66 kumpf 1.20 PEG_METHOD_ENTER (TRC_IND_HANDLER,
67 "CIMxmlIndicationHandler::CIMxmlIndicationHandler");
68 PEG_METHOD_EXIT();
|
69 mike 1.2 }
70
71 virtual ~CIMxmlIndicationHandler()
72 {
|
73 kumpf 1.20 PEG_METHOD_ENTER (TRC_IND_HANDLER,
74 "CIMxmlIndicationHandler::~CIMxmlIndicationHandler");
75 PEG_METHOD_EXIT();
|
76 mike 1.2 }
77
78 void initialize(CIMRepository* repository)
79 {
|
80 kumpf 1.20
|
81 mike 1.2 }
82
83 void terminate()
84 {
|
85 kumpf 1.20
|
86 mike 1.2 }
87
|
88 chuck 1.14 // l10n
|
89 mike 1.2 void handleIndication(
|
90 kumpf 1.20 const OperationContext& context,
91 CIMInstance& indicationHandlerInstance,
92 CIMInstance& indicationInstance,
93 String nameSpace,
94 ContentLanguages& contentLanguages)
|
95 mike 1.2 {
|
96 kumpf 1.20 PEG_METHOD_ENTER (TRC_IND_HANDLER,
97 "CIMxmlIndicationHandler::handleIndication");
98
99 //get destination for the indication
100 Uint32 pos = indicationHandlerInstance.findProperty(CIMName ("destination"));
|
101 mike 1.2 if (pos == PEG_NOT_FOUND)
102 {
|
103 kumpf 1.20 String msg = _getMalformedExceptionMsg();
104
105 PEG_TRACE_STRING(TRC_IND_HANDLER, Tracer::LEVEL4, msg);
106
107 PEG_METHOD_EXIT();
108 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, msg);
|
109 mike 1.2 }
110
|
111 kumpf 1.20 CIMProperty prop = indicationHandlerInstance.getProperty(pos);
|
112 mike 1.2
113 String dest;
114 try
115 {
116 prop.getValue().get(dest);
117 }
|
118 kumpf 1.9 catch (TypeMismatchException& e)
|
119 mike 1.2 {
|
120 kumpf 1.20 MessageLoaderParms param(
121 "Handler.CIMxmlIndicationHandler.CIMxmlIndicationHandler.ERROR",
122 "CIMxmlIndicationHandler Error: ");
123
124 String msg = String(MessageLoader::getMessage(param) + e.getMessage());
125
126 PEG_TRACE_STRING(TRC_IND_HANDLER, Tracer::LEVEL4, msg);
127
128 PEG_METHOD_EXIT();
129 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, msg);
|
130 mike 1.2 }
|
131 kumpf 1.20
132 try
|
133 mike 1.2 {
|
134 kumpf 1.13 static String PROPERTY_NAME__SSLCERT_FILEPATH = "sslCertificateFilePath";
135 static String PROPERTY_NAME__SSLKEY_FILEPATH = "sslKeyFilePath";
136
137 //
138 // Get the sslCertificateFilePath property from the Config Manager.
139 //
|
140 kumpf 1.20 ConfigManager* configManager = ConfigManager::getInstance();
|
141 kumpf 1.15
|
142 kumpf 1.13 String certPath;
|
143 kumpf 1.15 certPath = configManager->getCurrentValue(
|
144 kumpf 1.13 PROPERTY_NAME__SSLCERT_FILEPATH);
145
146 //
147 // Get the sslKeyFilePath property from the Config Manager.
148 //
149 String keyPath;
|
150 kumpf 1.15 keyPath = configManager->getCurrentValue(
|
151 kumpf 1.13 PROPERTY_NAME__SSLKEY_FILEPATH);
152
153 String trustPath = String::EMPTY;
154
155 String randFile = String::EMPTY;
156
157 #ifdef PEGASUS_SSL_RANDOMFILE
158 randFile = ConfigManager::getHomedPath(PEGASUS_SSLSERVER_RANDOMFILE);
159 #endif
160
|
161 kumpf 1.20 SSLContext sslcontext(trustPath, certPath, keyPath,
162 verifyListenerCertificate, randFile);
|
163 kumpf 1.13
|
164 dj.gorey 1.23 #ifdef PEGASUS_USE_23HTTPMONITOR_CLIENT
|
165 kumpf 1.20 Monitor monitor;
166 HTTPConnector httpConnector( &monitor);
|
167 dj.gorey 1.22 #else
168 monitor_2 monitor;
169 HTTPConnector2 httpConnector( &monitor);
170 #endif
171
|
172 kumpf 1.20 CIMExportClient exportclient( &monitor, &httpConnector);
|
173 kumpf 1.11 Uint32 colon = dest.find (":");
174 Uint32 portNumber = 0;
|
175 kumpf 1.13 Boolean useHttps = false;
176 String destStr = dest;
|
177 kumpf 1.20 String hostName;
|
178 kumpf 1.13
179 //
|
180 kumpf 1.16 // If the URL has https (https://hostname:port/... or
|
181 kumpf 1.20 // https://hostname/...) then use SSL for Indication delivery.
182 // If it has http (http://hostname:port/...
183 // or http://hostname/...) then do not use SSL.
|
184 kumpf 1.13 //
|
185 kumpf 1.16 if (colon != PEG_NOT_FOUND)
|
186 kumpf 1.13 {
187 String httpStr = dest.subString(0, colon);
188 if (String::equalNoCase(httpStr, "https"))
189 {
190 useHttps = true;
191 }
|
192 kumpf 1.16 else if (String::equalNoCase(httpStr, "http"))
193 {
194 useHttps = false;
195 }
|
196 kumpf 1.20 else
197 {
198 String msg = _getMalformedExceptionMsg();
199
200 PEG_TRACE_STRING(TRC_IND_HANDLER, Tracer::LEVEL4, msg + dest);
201
202 PEG_METHOD_EXIT();
203 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_SUPPORTED, msg + dest);
204 }
205 }
206 else
207 {
208 String msg = _getMalformedExceptionMsg();
209
210 PEG_TRACE_STRING(TRC_IND_HANDLER, Tracer::LEVEL4, msg + dest);
211
212 PEG_METHOD_EXIT();
213 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_SUPPORTED, msg + dest);
214 }
215
216 String doubleSlash = dest.subString(colon + 1, 2);
217 kumpf 1.20
218 if (String::equalNoCase(doubleSlash, "//"))
219 {
220 destStr = dest.subString(colon + 3, PEG_NOT_FOUND);
221 }
222 else
223 {
224 String msg = _getMalformedExceptionMsg();
225
226 PEG_TRACE_STRING(TRC_IND_HANDLER, Tracer::LEVEL4, msg + dest);
227
228 PEG_METHOD_EXIT();
229 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_NOT_SUPPORTED, msg + dest);
|
230 kumpf 1.13 }
231
232 colon = destStr.find (":");
233
|
234 kumpf 1.20 //
235 // get hostname and port number from destination string
236 //
237 if (colon != PEG_NOT_FOUND)
238 {
239 hostName = destStr.subString (0, colon);
240 destStr = destStr.subString(colon + 1, PEG_NOT_FOUND);
241
242 Uint32 slash = destStr.find ("/");
243 String portStr;
244
245 if (slash != PEG_NOT_FOUND)
246 {
247 portStr = destStr.subString (0, slash);
248 }
249 else
250 {
251 portStr = destStr.subString (0, PEG_NOT_FOUND);
252 }
253
254 sscanf (portStr.getCString (), "%u", &portNumber);
255 kumpf 1.20 }
256 //
257 // There is no port number in the destination string,
258 // get port number from system
259 //
260 else
261 {
262 Uint32 slash = destStr.find ("/");
263 if (slash != PEG_NOT_FOUND)
264 {
265 hostName = destStr.subString (0, slash);
266 }
267 else
268 {
269 hostName = destStr.subString (0, PEG_NOT_FOUND);
270 }
271 if (useHttps)
272 {
273 portNumber = System::lookupPort(WBEM_HTTPS_SERVICE_NAME,
274 WBEM_DEFAULT_HTTPS_PORT);
275 }
276 kumpf 1.20 else
277 {
278 portNumber = System::lookupPort(WBEM_HTTP_SERVICE_NAME,
279 WBEM_DEFAULT_HTTP_PORT);
280 }
281 }
|
282 kumpf 1.13
283 if (useHttps)
284 {
285 #ifdef PEGASUS_HAS_SSL
|
286 kumpf 1.16 exportclient.connect (hostName, portNumber, sslcontext);
|
287 kumpf 1.13 #else
|
288 humberto 1.18 //l10n 485
|
289 kumpf 1.20 MessageLoaderParms param(
290 "Handler.CIMxmlIndicationHandler.CIMxmlIndicationHandler.ERROR",
291 "CIMxmlIndicationHandler Error: ");
292 MessageLoaderParms param1(
293 "Handler.CIMxmlIndicationHandler.CIMxmlIndicationHandler.CANNOT_DO_HTTPS_CONNECTION",
294 "Cannot do https connection.");
295
296 PEG_TRACE_STRING(TRC_IND_HANDLER, Tracer::LEVEL3,
297 MessageLoader::getMessage(param) + MessageLoader::getMessage(param1));
298
299 String msg = String(MessageLoader::getMessage(param) +
300 MessageLoader::getMessage(param1));
301
302 PEG_METHOD_EXIT();
303 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, msg);
|
304 kumpf 1.13 #endif
305 }
306 else
307 {
|
308 kumpf 1.16 exportclient.connect (hostName, portNumber);
|
309 kumpf 1.13 }
310
|
311 humberto 1.18 // l10n
|
312 kumpf 1.24 // check destStr, if no path is specified, use "/" for the URI
313 Uint32 slash = destStr.find ("/");
314 if (slash != PEG_NOT_FOUND)
315 {
316 exportclient.exportIndication(
317 destStr.subString(slash), indicationInstance,
318 contentLanguages);
319 }
320 else
321 {
322 exportclient.exportIndication(
323 "/", indicationInstance, contentLanguages);
324 }
|
325 kumpf 1.20 }
326 catch(Exception& e)
|
327 mike 1.2 {
|
328 kumpf 1.13 //ATTN: Catch specific exceptions and log the error message
329 // as Indication delivery failed.
|
330 humberto 1.18 //l10n 485
|
331 kumpf 1.20 MessageLoaderParms param(
332 "Handler.CIMxmlIndicationHandler.CIMxmlIndicationHandler.ERROR",
333 "CIMxmlIndicationHandler Error: ");
334
335 String msg = String(MessageLoader::getMessage(param) + e.getMessage());
336
337 PEG_METHOD_EXIT();
338 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, msg);
|
339 mike 1.2 }
|
340 kumpf 1.20
341 PEG_METHOD_EXIT();
342 }
343
344 private:
345 String _getMalformedExceptionMsg()
346 {
347 MessageLoaderParms param(
348 "Handler.CIMxmlIndicationHandler.CIMxmlIndicationHandler.ERROR",
349 "CIMxmlIndicationHandler Error: ");
350
351 MessageLoaderParms param1(
352 "Handler.CIMxmlIndicationHandler.CIMxmlIndicationHandler.MALFORMED_HANDLER_INSTANCE",
353 "Malformed handler instance.");
354
355 return ( String(MessageLoader::getMessage(param) +
356 MessageLoader::getMessage(param1)) );
|
357 mike 1.2 }
|
358 kumpf 1.20
|
359 mike 1.2 };
360
361 // This is the dynamic entry point into this dynamic module. The name of
362 // this handler is "CIMxmlIndicationHandler" which is appened to "PegasusCreateHandler_"
363 // to form a symbol name. This function is called by the HandlerTable
364 // to load this handler.
365
366 extern "C" PEGASUS_EXPORT CIMHandler*
367 PegasusCreateHandler_CIMxmlIndicationHandler() {
368 return new CIMxmlIndicationHandler;
369 }
370
371 PEGASUS_NAMESPACE_END
|