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