1 karl 1.40 //%2005////////////////////////////////////////////////////////////////////////
|
2 kumpf 1.1 //
|
3 karl 1.37 // 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.31 // IBM Corp.; EMC Corporation, The Open Group.
|
7 karl 1.37 // 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.40 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
|
11 kumpf 1.1 //
12 // Permission is hereby granted, free of charge, to any person obtaining a copy
13 // 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 // 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 kumpf 1.17 //
|
19 kumpf 1.1 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
20 // 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 // 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 // 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.19 // Modified By: Carol Ann Krug Graves, Hewlett-Packard Company
33 // (carolann_graves@hp.com)
|
34 kumpf 1.33 // Yi Zhou, Hewlett-Packard Company (yi_zhou@hp.com)
35 // Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)
|
36 se.gupta 1.35 // Seema Gupta (gseema@in.ibm.com) for PEP135
|
37 a.arora 1.38 // Josephine Eskaline Joyce (jojustin@in.ibm.com) for PEP101
|
38 a.arora 1.39 // Amit K Arora, IBM (amitarora@in.ibm.com) for Bug#2487
|
39 kumpf 1.1 //
40 //%/////////////////////////////////////////////////////////////////////////////
41
|
42 kumpf 1.11 #include <Pegasus/Common/Constants.h>
|
43 kumpf 1.19 #include <Pegasus/Common/CIMName.h>
|
44 mday 1.14 #include <Pegasus/Common/Tracer.h>
|
45 kumpf 1.1 #include <Pegasus/Common/CIMMessage.h>
46 #include <Pegasus/Common/XmlWriter.h>
|
47 kumpf 1.13 #include <Pegasus/Common/PegasusVersion.h>
|
48 yi.zhou 1.42 #include <Pegasus/Common/Constants.h>
|
49 kumpf 1.1
50 #include "IndicationHandlerService.h"
51
|
52 humberto 1.25 // l10n
53 #include <Pegasus/Common/MessageLoader.h>
|
54 a.arora 1.38 #include <Pegasus/Common/AutoPtr.h>
|
55 kumpf 1.1 PEGASUS_USING_STD;
56 PEGASUS_USING_PEGASUS;
57
58 PEGASUS_NAMESPACE_BEGIN
59
|
60 kumpf 1.2 IndicationHandlerService::IndicationHandlerService(void)
|
61 kumpf 1.11 : Base(PEGASUS_QUEUENAME_INDHANDLERMANAGER)
|
62 kumpf 1.1 {
|
63 kumpf 1.2
|
64 kumpf 1.1 }
65
|
66 kumpf 1.2 IndicationHandlerService::IndicationHandlerService(CIMRepository* repository)
67 : Base("IndicationHandlerService", MessageQueue::getNextQueueId()),
68 _repository(repository)
|
69 kumpf 1.1 {
70 }
71
72 void IndicationHandlerService::_handle_async_request(AsyncRequest *req)
73 {
|
74 kumpf 1.33 if ( req->getType() == async_messages::CIMSERVICE_STOP )
75 {
76 req->op->processing();
77 handle_CimServiceStop(static_cast<CimServiceStop *>(req));
78 }
79 else if ( req->getType() == async_messages::ASYNC_LEGACY_OP_START )
80 {
81 req->op->processing();
|
82 a.arora 1.38 AutoPtr<Message> legacy(static_cast<AsyncLegacyOperationStart *>(req)->get_action()); //PEP 101
|
83 kumpf 1.33 if (legacy->getType() == CIM_HANDLE_INDICATION_REQUEST_MESSAGE)
84 {
|
85 a.arora 1.38 AutoPtr<Message> legacy_response(_handleIndication(
86 (CIMHandleIndicationRequestMessage*) legacy.get())); //PEP 101
87 legacy.release();
88 AutoPtr<AsyncLegacyOperationResult> async_result(new AsyncLegacyOperationResult(
|
89 kumpf 1.33 req->getKey(),
90 req->getRouting(),
91 req->op,
|
92 a.arora 1.38 legacy_response.get())); //PEP 101
93 legacy_response.release();
94 async_result.release();
|
95 kumpf 1.33 _complete_op_node(req->op, ASYNC_OPSTATE_COMPLETE, 0, 0);
96 }
97 else
98 {
99 Tracer::trace(TRC_DISCARDED_DATA, Tracer::LEVEL2,
100 "IndicationHandlerService::_handle_async_request got "
101 "unexpected legacy message type '%u'", legacy->getType());
102 _make_response(req, async_results::CIM_NAK);
103 }
104 }
105 else
106 {
107 Base::_handle_async_request(req);
108 }
|
109 kumpf 1.1 }
110
|
111 mday 1.4 void IndicationHandlerService::handleEnqueue(Message* message)
|
112 kumpf 1.1 {
|
113 kumpf 1.33 if (!message)
114 {
115 return;
116 }
117
|
118 chuck 1.23 // l10n
|
119 kumpf 1.33 // Set the client's requested language into this service thread.
120 // This will allow functions in this service to return messages
121 // in the correct language.
|
122 a.arora 1.38 AutoPtr<CIMMessage> msg(dynamic_cast<CIMMessage *>(message));
123 if (msg.get() != NULL)
|
124 kumpf 1.33 {
125 if (msg->thread_changed())
126 {
|
127 a.arora 1.38 AutoPtr<AcceptLanguages> langs(new AcceptLanguages(((AcceptLanguageListContainer)msg->operationContext.get(AcceptLanguageListContainer::NAME)).getLanguages()));
128 Thread::setLanguages(langs.get());
129 langs.release();
|
130 kumpf 1.33 }
131 }
132 else
133 {
134 Thread::clearLanguages();
135 }
136
137 switch (message->getType())
138 {
139 case CIM_HANDLE_INDICATION_REQUEST_MESSAGE:
|
140 chuck 1.28 {
|
141 a.arora 1.38 AutoPtr<CIMHandleIndicationResponseMessage> response(_handleIndication(
142 (CIMHandleIndicationRequestMessage*) message));
143 SendForget(response.get());
144 response.release();
|
145 kumpf 1.33 break;
|
146 chuck 1.28 }
|
147 chuck 1.23
|
148 kumpf 1.33 default:
149 Tracer::trace(TRC_DISCARDED_DATA, Tracer::LEVEL2,
150 "IndicationHandlerService::handleEnqueue got unexpected "
151 "message type '%u'", message->getType());
152 break;
153 }
154
|
155 kumpf 1.1 }
156
|
157 kumpf 1.3 void IndicationHandlerService::handleEnqueue()
158 {
|
159 a.arora 1.38 AutoPtr<Message> message(dequeue());
|
160 kumpf 1.3
|
161 a.arora 1.38 PEGASUS_ASSERT(message.get() != 0);
162 if (message.get())
|
163 kumpf 1.33 {
|
164 a.arora 1.38 handleEnqueue(message.get());
165 message.release();
|
166 kumpf 1.33 }
|
167 kumpf 1.3 }
168
|
169 kumpf 1.33 // This callback method is currently unused. ExportIndication messages
170 // are passed to the CIMExportRequestDispatcher using SendWait rather than
171 // SendAsync so the responses can be routed correctly.
172 void IndicationHandlerService::_handleIndicationCallBack(AsyncOpNode *op,
173 MessageQueue *q,
174 void *parm)
|
175 mday 1.9 {
|
176 kumpf 1.33 PEGASUS_ASSERT(0);
177 #if 0
|
178 a.arora 1.38 AutoPtr<IndicationHandlerService> service(static_cast<IndicationHandlerService *>(q));
|
179 mday 1.9
|
180 a.arora 1.38 AutoPtr<AsyncRequest> asyncRequest(static_cast<AsyncRequest *>(op->get_request()));
181 AutoPtr<AsyncReply> asyncReply(static_cast<AsyncReply *>(op->get_response()));
182 AutoPtr<CIMRequestMessage> request(reinterpret_cast<CIMRequestMessage *>
183 ((static_cast<AsyncLegacyOperationStart *>(asyncRequest))->get_action()));
184 AutoPtr<CIMResponseMessage> response(reinterpret_cast<CIMResponseMessage *>
185 ((static_cast<AsyncLegacyOperationResult *>(asyncReply))->get_result()));
186 PEGASUS_ASSERT(response.get() != 0);
|
187 mday 1.9 // ensure that the destination queue is in response->dest
|
188 w.otsuka 1.43 #ifdef PEGASUS_POINTER_64BIT
|
189 kumpf 1.10 response->dest = (Uint64)parm;
|
190 dan 1.20 #elif PEGASUS_PLATFORM_AIX_RS_IBMCXX
191 // We cast to unsigned long
192 // because sizeof(void *) == sizeof(unsigned long)
193 response->dest = (unsigned long)parm;
|
194 kumpf 1.10 #else
|
195 mday 1.9 response->dest = (Uint32)parm;
|
196 kumpf 1.10 #endif
|
197 a.arora 1.38 service->SendForget(response.get());
198 response.release();
|
199 mday 1.9 // op->release();
200 // service->return_op(op);
|
201 kumpf 1.33 #endif
|
202 mday 1.9 }
203
204
|
205 tony 1.30 String IndicationHandlerService::_parseDestination(String dest)
206 {
|
207 david 1.34 CString pCString = dest.getCString();
|
208 kumpf 1.33 char* p = const_cast<char*>((const char*) pCString);
|
209 tony 1.30
|
210 kumpf 1.33 static char schemeType[] = "HTTP:";
211 Boolean hasSchemeType = true;
212 for(int i= 0; i<5; i++)
213 {
214 if(::toupper(p[i]) != schemeType[i])
215 {
216 hasSchemeType = false;
217 break;
218 }
219 }
220 if(hasSchemeType)
221 {
222 p += 5;
223 }
224
225 // See if there is a host name begins with "//":
226 if (p[0] == '/' && p[1] == '/')
227 {
228 p += 2;
229 }
230 return String(p);
|
231 tony 1.30 }
232
|
233 kumpf 1.33 CIMHandleIndicationResponseMessage*
234 IndicationHandlerService::_handleIndication(
235 CIMHandleIndicationRequestMessage* request)
|
236 kumpf 1.1 {
|
237 kumpf 1.33 PEG_METHOD_ENTER (TRC_IND_HANDLE,
238 "IndicationHandlerService::_handleIndication");
|
239 tony 1.27
|
240 kumpf 1.33 CIMException cimException =
241 PEGASUS_CIM_EXCEPTION(CIM_ERR_SUCCESS, String::EMPTY);
|
242 kumpf 1.1
|
243 kumpf 1.33 CIMName className = request->handlerInstance.getClassName();
244 CIMNamespaceName nameSpace = request->nameSpace;
|
245 kumpf 1.16
|
246 kumpf 1.33 CIMInstance indication = request->indicationInstance;
247 CIMInstance handler = request->handlerInstance;
248
249 Uint32 pos = PEG_NOT_FOUND;
250
251 if (className.equal (PEGASUS_CLASSNAME_INDHANDLER_CIMXML) ||
252 className.equal (PEGASUS_CLASSNAME_LSTNRDST_CIMXML))
253 {
|
254 yi.zhou 1.42 pos = handler.findProperty(PEGASUS_PROPERTYNAME_LSTNRDST_DESTINATION);
|
255 kumpf 1.1
|
256 yi.zhou 1.42 if (pos == PEG_NOT_FOUND)
|
257 kumpf 1.33 {
258 cimException = PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
259 MessageLoaderParms("HandlerService.IndicationHandlerService."
|
260 yi.zhou 1.42 "CIMXML_HANDLER_WITHOUT_DESTINATION", "CIMXml Handler missing Destination property"));
261 }
262 else
263 {
264 CIMProperty prop = handler.getProperty(pos);
265 String destination = prop.getValue().toString();
266
267 if (destination.size() == 0)
268 {
269 cimException = PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
270 MessageLoaderParms("HandlerService.IndicationHandlerService."
|
271 kumpf 1.33 "INVALID_DESTINATION", "invalid destination"));
|
272 yi.zhou 1.42 }
|
273 kumpf 1.33 //compared index 10 is not :
|
274 yi.zhou 1.42 else if (destination.subString(0, 10) == String("localhost/"))
275 {
276 Array<Uint32> exportServer;
|
277 humberto 1.25
|
278 yi.zhou 1.42 find_services(PEGASUS_QUEUENAME_EXPORTREQDISPATCHER, 0, 0,
|
279 kumpf 1.33 &exportServer);
|
280 kumpf 1.1
|
281 yi.zhou 1.42 // Listener is build with Cimom, so send message to ExportServer
282
283 AutoPtr<CIMExportIndicationRequestMessage> exportmessage(
284 new CIMExportIndicationRequestMessage(
|
285 kumpf 1.33 XmlWriter::getNextMessageId(),
286 destination.subString(21), //taking localhost/CIMListener portion out from reg
287 indication,
288 QueueIdStack(exportServer[0], getQueueId()),
289 String::EMPTY,
|
290 a.arora 1.38 String::EMPTY));
|
291 kumpf 1.33
|
292 yi.zhou 1.42 exportmessage->operationContext.set(
293 request->operationContext.get(
294 ContentLanguageListContainer::NAME));
295 AutoPtr<AsyncOpNode> op( this->get_op());
296
297 AutoPtr<AsyncLegacyOperationStart> asyncRequest(
298 new AsyncLegacyOperationStart(
|
299 kumpf 1.33 get_next_xid(),
|
300 a.arora 1.38 op.get(),
|
301 kumpf 1.33 exportServer[0],
|
302 a.arora 1.38 exportmessage.get(),
303 _queueId));
|
304 yi.zhou 1.42 exportmessage.release();
|
305 kumpf 1.33
|
306 yi.zhou 1.42 PEG_TRACE_STRING(TRC_IND_HANDLE, Tracer::LEVEL4,
307 "Indication handler forwarding message to " +
308 ((MessageQueue::lookup(exportServer[0])) ?
|
309 kumpf 1.33 String( ((MessageQueue::lookup(exportServer[0]))->
310 getQueueName()) ) :
311 String("BAD queue name")));
312
|
313 yi.zhou 1.42 //SendAsync(op,
314 // exportServer[0],
315 // IndicationHandlerService::_handleIndicationCallBack,
316 // this,
317 // (void *)request->queueIds.top());
318 AutoPtr<AsyncReply> asyncReply(SendWait(asyncRequest.get()));
319 asyncRequest.release();
320
321 // Return the ExportIndication results in HandleIndication
322 //response
323 AutoPtr<CIMExportIndicationResponseMessage> exportResponse(
324 reinterpret_cast<CIMExportIndicationResponseMessage *>(
325 (static_cast<AsyncLegacyOperationResult *>(
326 asyncReply.get()))->get_result()));
327 cimException = exportResponse->cimException;
|
328 kumpf 1.33
|
329 yi.zhou 1.42 op->release();
330 this->return_op(op.release());
331 }
332 else
333 {
334 _loadHandler(request, cimException);
335 }
336 }
337 }
338 else if (className.equal (PEGASUS_CLASSNAME_INDHANDLER_SNMP))
339 {
340 pos = handler.findProperty(PEGASUS_PROPERTYNAME_LSTNRDST_TARGETHOST);
|
341 kumpf 1.33
|
342 yi.zhou 1.42 if (pos == PEG_NOT_FOUND)
343 {
344 cimException = PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
345 MessageLoaderParms("HandlerService.IndicationHandlerService."
346 "SNMP_HANDLER_WITHOUT_TARGETHOST", "Snmp Handler missing Targethost property"));
|
347 kumpf 1.33 }
348 else
349 {
|
350 yi.zhou 1.42 CIMProperty prop = handler.getProperty(pos);
351 String destination = prop.getValue().toString();
|
352 tony 1.30
|
353 yi.zhou 1.42 if (destination.size() == 0)
|
354 kumpf 1.33 {
|
355 yi.zhou 1.42 cimException = PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
356 MessageLoaderParms("HandlerService.IndicationHandlerService."
357 "INVALID_TARGETHOST", "invalid targethost"));
|
358 kumpf 1.33 }
|
359 yi.zhou 1.42 else
|
360 kumpf 1.33 {
|
361 yi.zhou 1.42 _loadHandler(request, cimException);
|
362 kumpf 1.33 }
363 }
364 }
|
365 yi.zhou 1.44 else if ((className.equal (PEGASUS_CLASSNAME_LSTNRDST_SYSTEM_LOG)) ||
366 (className.equal (PEGASUS_CLASSNAME_LSTNRDST_EMAIL)))
|
367 yi.zhou 1.42 {
368 _loadHandler(request, cimException);
369 }
370
371 CIMHandleIndicationResponseMessage* response =
372 new CIMHandleIndicationResponseMessage(
|
373 kumpf 1.16 request->messageId,
374 cimException,
|
375 a.arora 1.39 request->queueIds.copyAndPop());
|
376 yi.zhou 1.42
|
377 karl 1.46 delete request;
|
378 kumpf 1.33 return response;
|
379 kumpf 1.1 }
380
|
381 yi.zhou 1.42 void IndicationHandlerService::_loadHandler(
382 CIMHandleIndicationRequestMessage* request,
383 CIMException & cimException)
384 {
385 CIMName className = request->handlerInstance.getClassName();
|
386 yi.zhou 1.49
|
387 yi.zhou 1.48 try
388 {
|
389 yi.zhou 1.49 CIMHandler * handlerLib = _lookupHandlerForClass(className);
|
390 yi.zhou 1.42
|
391 yi.zhou 1.49 if (handlerLib)
|
392 yi.zhou 1.48 {
|
393 yi.zhou 1.42 ContentLanguages langs =
394 ((ContentLanguageListContainer)request->operationContext.
395 get(ContentLanguageListContainer::NAME)).getLanguages();
396
397 handlerLib->handleIndication(
398 request->operationContext,
399 request->nameSpace.getString(),
400 request->indicationInstance,
401 request->handlerInstance,
402 request->subscriptionInstance,
403 langs);
|
404 yi.zhou 1.48 }
405 else
406 {
407 cimException = PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
408 MessageLoaderParms("HandlerService."
409 "IndicationHandlerService.FAILED_TO_LOAD",
410 "Failed to load Handler"));
411 }
412
413 }
414 catch (Exception& e)
415 {
416 cimException =
417 PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, e.getMessage());
|
418 yi.zhou 1.42 }
|
419 yi.zhou 1.48 catch (...)
|
420 yi.zhou 1.42 {
|
421 yi.zhou 1.48 cimException =
422 PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "Exception: Unknown");
|
423 yi.zhou 1.42 }
424 }
425
|
426 kumpf 1.1 CIMHandler* IndicationHandlerService::_lookupHandlerForClass(
|
427 kumpf 1.19 const CIMName& className)
|
428 kumpf 1.1 {
|
429 mday 1.6 String handlerId;
|
430 kumpf 1.1
|
431 tony 1.30 if (className.equal (PEGASUS_CLASSNAME_INDHANDLER_CIMXML)
432 || className.equal (PEGASUS_CLASSNAME_LSTNRDST_CIMXML)
433 )
|
434 humberto 1.45 #ifdef PEGASUS_OS_OS400
|
435 chuck 1.47 {
436 handlerId = LIBRARY_NAME_CIMXML_INDICATION_HNDLR;
437 handlerId.append("/CIMxmlIndicationHandler");
438 }
|
439 humberto 1.45 #else
|
440 kumpf 1.8 handlerId = String("CIMxmlIndicationHandler");
|
441 humberto 1.45 #endif
|
442 kumpf 1.21 else if (className.equal (PEGASUS_CLASSNAME_INDHANDLER_SNMP))
|
443 humberto 1.45 #ifdef PEGASUS_OS_OS400
|
444 chuck 1.47 {
|
445 humberto 1.45 handlerId = LIBRARY_NAME_SNMP_INDICATION_HNDLR;
|
446 chuck 1.47 handlerId.append("/snmpIndicationHandler");
447 }
|
448 humberto 1.45 #else
|
449 kumpf 1.8 handlerId = String("snmpIndicationHandler");
|
450 humberto 1.45 #endif
|
451 yi.zhou 1.42 else if (className.equal (PEGASUS_CLASSNAME_LSTNRDST_SYSTEM_LOG))
452 handlerId = String("SystemLogListenerDestination");
|
453 yi.zhou 1.44 else if (className.equal (PEGASUS_CLASSNAME_LSTNRDST_EMAIL))
454 handlerId = String("EmailListenerDestination");
|
455 kumpf 1.8 else
456 return 0;
|
457 kumpf 1.1
|
458 yi.zhou 1.48 CIMHandler* handler = _handlerTable.getHandler(handlerId, _repository);
|
459 kumpf 1.1
|
460 mday 1.6 return handler;
|
461 kumpf 1.1 }
462
463 PEGASUS_NAMESPACE_END
|
464 tony 1.30
465
|