1 karl 1.52 //%2006////////////////////////////////////////////////////////////////////////
|
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 karl 1.52 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
12 // EMC Corporation; Symantec Corporation; The Open Group.
|
13 kumpf 1.1 //
14 // Permission is hereby granted, free of charge, to any person obtaining a copy
15 // of this software and associated documentation files (the "Software"), to
16 // deal in the Software without restriction, including without limitation the
17 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
18 // sell copies of the Software, and to permit persons to whom the Software is
19 // furnished to do so, subject to the following conditions:
|
20 kumpf 1.17 //
|
21 kumpf 1.1 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
22 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
23 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
24 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
25 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
27 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30 //==============================================================================
31 //
32 // Author: Nitin Upasani, Hewlett-Packard Company (Nitin_Upasani@hp.com)
33 //
|
34 kumpf 1.19 // Modified By: Carol Ann Krug Graves, Hewlett-Packard Company
35 // (carolann_graves@hp.com)
|
36 kumpf 1.33 // Yi Zhou, Hewlett-Packard Company (yi_zhou@hp.com)
37 // Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)
|
38 se.gupta 1.35 // Seema Gupta (gseema@in.ibm.com) for PEP135
|
39 a.arora 1.38 // Josephine Eskaline Joyce (jojustin@in.ibm.com) for PEP101
|
40 a.arora 1.39 // Amit K Arora, IBM (amitarora@in.ibm.com) for Bug#2487
|
41 kumpf 1.1 //
42 //%/////////////////////////////////////////////////////////////////////////////
43
|
44 kumpf 1.11 #include <Pegasus/Common/Constants.h>
|
45 kumpf 1.19 #include <Pegasus/Common/CIMName.h>
|
46 mday 1.14 #include <Pegasus/Common/Tracer.h>
|
47 kumpf 1.1 #include <Pegasus/Common/CIMMessage.h>
48 #include <Pegasus/Common/XmlWriter.h>
|
49 kumpf 1.13 #include <Pegasus/Common/PegasusVersion.h>
|
50 yi.zhou 1.42 #include <Pegasus/Common/Constants.h>
|
51 kumpf 1.1
52 #include "IndicationHandlerService.h"
53
|
54 humberto 1.25 // l10n
55 #include <Pegasus/Common/MessageLoader.h>
|
56 a.arora 1.38 #include <Pegasus/Common/AutoPtr.h>
|
57 kumpf 1.1 PEGASUS_USING_STD;
58 PEGASUS_USING_PEGASUS;
59
60 PEGASUS_NAMESPACE_BEGIN
61
|
62 kumpf 1.2 IndicationHandlerService::IndicationHandlerService(CIMRepository* repository)
63 : Base("IndicationHandlerService", MessageQueue::getNextQueueId()),
64 _repository(repository)
|
65 kumpf 1.1 {
66 }
67
68 void IndicationHandlerService::_handle_async_request(AsyncRequest *req)
69 {
|
70 kumpf 1.33 if ( req->getType() == async_messages::CIMSERVICE_STOP )
71 {
72 req->op->processing();
73 handle_CimServiceStop(static_cast<CimServiceStop *>(req));
74 }
75 else if ( req->getType() == async_messages::ASYNC_LEGACY_OP_START )
76 {
77 req->op->processing();
|
78 a.arora 1.38 AutoPtr<Message> legacy(static_cast<AsyncLegacyOperationStart *>(req)->get_action()); //PEP 101
|
79 kumpf 1.33 if (legacy->getType() == CIM_HANDLE_INDICATION_REQUEST_MESSAGE)
80 {
|
81 a.arora 1.38 AutoPtr<Message> legacy_response(_handleIndication(
82 (CIMHandleIndicationRequestMessage*) legacy.get())); //PEP 101
83 legacy.release();
84 AutoPtr<AsyncLegacyOperationResult> async_result(new AsyncLegacyOperationResult(
|
85 kumpf 1.33 req->op,
|
86 a.arora 1.38 legacy_response.get())); //PEP 101
87 legacy_response.release();
88 async_result.release();
|
89 kumpf 1.33 _complete_op_node(req->op, ASYNC_OPSTATE_COMPLETE, 0, 0);
90 }
91 else
92 {
93 Tracer::trace(TRC_DISCARDED_DATA, Tracer::LEVEL2,
94 "IndicationHandlerService::_handle_async_request got "
95 "unexpected legacy message type '%u'", legacy->getType());
96 _make_response(req, async_results::CIM_NAK);
97 }
98 }
99 else
100 {
101 Base::_handle_async_request(req);
102 }
|
103 kumpf 1.1 }
104
|
105 mday 1.4 void IndicationHandlerService::handleEnqueue(Message* message)
|
106 kumpf 1.1 {
|
107 carolann.graves 1.58 PEGASUS_ASSERT(message != 0);
|
108 kumpf 1.33
|
109 chuck 1.23 // l10n
|
110 kumpf 1.33 // Set the client's requested language into this service thread.
111 // This will allow functions in this service to return messages
112 // in the correct language.
|
113 a.arora 1.38 AutoPtr<CIMMessage> msg(dynamic_cast<CIMMessage *>(message));
114 if (msg.get() != NULL)
|
115 kumpf 1.33 {
116 if (msg->thread_changed())
117 {
|
118 kumpf 1.51 AutoPtr<AcceptLanguageList> langs(new AcceptLanguageList(((AcceptLanguageListContainer)msg->operationContext.get(AcceptLanguageListContainer::NAME)).getLanguages()));
|
119 a.arora 1.38 Thread::setLanguages(langs.get());
120 langs.release();
|
121 kumpf 1.33 }
122 }
123 else
124 {
125 Thread::clearLanguages();
126 }
127
128 switch (message->getType())
129 {
130 case CIM_HANDLE_INDICATION_REQUEST_MESSAGE:
|
131 chuck 1.28 {
|
132 a.arora 1.38 AutoPtr<CIMHandleIndicationResponseMessage> response(_handleIndication(
133 (CIMHandleIndicationRequestMessage*) message));
134 SendForget(response.get());
135 response.release();
|
136 kumpf 1.33 break;
|
137 chuck 1.28 }
|
138 chuck 1.23
|
139 kumpf 1.33 default:
|
140 carolann.graves 1.57 PEGASUS_ASSERT(0);
|
141 kumpf 1.33 break;
142 }
143
|
144 kumpf 1.1 }
145
|
146 kumpf 1.3 void IndicationHandlerService::handleEnqueue()
147 {
|
148 a.arora 1.38 AutoPtr<Message> message(dequeue());
|
149 kumpf 1.3
|
150 a.arora 1.38 PEGASUS_ASSERT(message.get() != 0);
151 if (message.get())
|
152 kumpf 1.33 {
|
153 a.arora 1.38 handleEnqueue(message.get());
154 message.release();
|
155 kumpf 1.33 }
|
156 kumpf 1.3 }
157
|
158 kumpf 1.33 CIMHandleIndicationResponseMessage*
159 IndicationHandlerService::_handleIndication(
160 CIMHandleIndicationRequestMessage* request)
|
161 kumpf 1.1 {
|
162 kumpf 1.33 PEG_METHOD_ENTER (TRC_IND_HANDLE,
163 "IndicationHandlerService::_handleIndication");
|
164 tony 1.27
|
165 marek 1.55 Boolean handleIndicationSuccess = true;
|
166 kumpf 1.33 CIMException cimException =
167 PEGASUS_CIM_EXCEPTION(CIM_ERR_SUCCESS, String::EMPTY);
|
168 kumpf 1.1
|
169 kumpf 1.33 CIMName className = request->handlerInstance.getClassName();
170 CIMNamespaceName nameSpace = request->nameSpace;
|
171 kumpf 1.16
|
172 kumpf 1.33 CIMInstance indication = request->indicationInstance;
173 CIMInstance handler = request->handlerInstance;
174
175 Uint32 pos = PEG_NOT_FOUND;
176
177 if (className.equal (PEGASUS_CLASSNAME_INDHANDLER_CIMXML) ||
178 className.equal (PEGASUS_CLASSNAME_LSTNRDST_CIMXML))
179 {
|
180 yi.zhou 1.42 pos = handler.findProperty(PEGASUS_PROPERTYNAME_LSTNRDST_DESTINATION);
|
181 kumpf 1.1
|
182 yi.zhou 1.42 if (pos == PEG_NOT_FOUND)
|
183 kumpf 1.33 {
184 cimException = PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
185 MessageLoaderParms("HandlerService.IndicationHandlerService."
|
186 yi.zhou 1.42 "CIMXML_HANDLER_WITHOUT_DESTINATION", "CIMXml Handler missing Destination property"));
|
187 marek 1.55 handleIndicationSuccess = false;
|
188 yi.zhou 1.42 }
189 else
190 {
191 CIMProperty prop = handler.getProperty(pos);
192 String destination = prop.getValue().toString();
193
194 if (destination.size() == 0)
195 {
196 cimException = PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
197 MessageLoaderParms("HandlerService.IndicationHandlerService."
|
198 kumpf 1.33 "INVALID_DESTINATION", "invalid destination"));
|
199 marek 1.55 handleIndicationSuccess = false;
|
200 yi.zhou 1.42 }
|
201 kumpf 1.33 //compared index 10 is not :
|
202 yi.zhou 1.42 else if (destination.subString(0, 10) == String("localhost/"))
203 {
204 Array<Uint32> exportServer;
|
205 humberto 1.25
|
206 yi.zhou 1.42 find_services(PEGASUS_QUEUENAME_EXPORTREQDISPATCHER, 0, 0,
|
207 kumpf 1.33 &exportServer);
|
208 kumpf 1.1
|
209 yi.zhou 1.42 // Listener is build with Cimom, so send message to ExportServer
210
211 AutoPtr<CIMExportIndicationRequestMessage> exportmessage(
212 new CIMExportIndicationRequestMessage(
|
213 kumpf 1.33 XmlWriter::getNextMessageId(),
214 destination.subString(21), //taking localhost/CIMListener portion out from reg
215 indication,
216 QueueIdStack(exportServer[0], getQueueId()),
217 String::EMPTY,
|
218 a.arora 1.38 String::EMPTY));
|
219 kumpf 1.33
|
220 denise.eckstein 1.50 exportmessage->operationContext.insert(
221 IdentityContainer(String::EMPTY));
|
222 yi.zhou 1.42 exportmessage->operationContext.set(
223 request->operationContext.get(
224 ContentLanguageListContainer::NAME));
225 AutoPtr<AsyncOpNode> op( this->get_op());
226
227 AutoPtr<AsyncLegacyOperationStart> asyncRequest(
228 new AsyncLegacyOperationStart(
|
229 a.arora 1.38 op.get(),
|
230 kumpf 1.33 exportServer[0],
|
231 a.arora 1.38 exportmessage.get(),
232 _queueId));
|
233 yi.zhou 1.42 exportmessage.release();
|
234 kumpf 1.33
|
235 yi.zhou 1.42 PEG_TRACE_STRING(TRC_IND_HANDLE, Tracer::LEVEL4,
236 "Indication handler forwarding message to " +
237 ((MessageQueue::lookup(exportServer[0])) ?
|
238 kumpf 1.33 String( ((MessageQueue::lookup(exportServer[0]))->
239 getQueueName()) ) :
240 String("BAD queue name")));
241
|
242 yi.zhou 1.42 //SendAsync(op,
243 // exportServer[0],
244 // IndicationHandlerService::_handleIndicationCallBack,
245 // this,
246 // (void *)request->queueIds.top());
247 AutoPtr<AsyncReply> asyncReply(SendWait(asyncRequest.get()));
248 asyncRequest.release();
249
250 // Return the ExportIndication results in HandleIndication
251 //response
252 AutoPtr<CIMExportIndicationResponseMessage> exportResponse(
253 reinterpret_cast<CIMExportIndicationResponseMessage *>(
254 (static_cast<AsyncLegacyOperationResult *>(
255 asyncReply.get()))->get_result()));
256 cimException = exportResponse->cimException;
|
257 kumpf 1.33
|
258 yi.zhou 1.42 op->release();
259 this->return_op(op.release());
|
260 marek 1.55
|
261 yi.zhou 1.42 }
262 else
263 {
|
264 marek 1.55 handleIndicationSuccess = _loadHandler(request, cimException);
|
265 yi.zhou 1.42 }
266 }
267 }
268 else if (className.equal (PEGASUS_CLASSNAME_INDHANDLER_SNMP))
269 {
270 pos = handler.findProperty(PEGASUS_PROPERTYNAME_LSTNRDST_TARGETHOST);
|
271 kumpf 1.33
|
272 yi.zhou 1.42 if (pos == PEG_NOT_FOUND)
273 {
274 cimException = PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
275 MessageLoaderParms("HandlerService.IndicationHandlerService."
276 "SNMP_HANDLER_WITHOUT_TARGETHOST", "Snmp Handler missing Targethost property"));
|
277 marek 1.55 handleIndicationSuccess = false;
|
278 kumpf 1.33 }
279 else
280 {
|
281 yi.zhou 1.42 CIMProperty prop = handler.getProperty(pos);
282 String destination = prop.getValue().toString();
|
283 tony 1.30
|
284 yi.zhou 1.42 if (destination.size() == 0)
|
285 kumpf 1.33 {
|
286 yi.zhou 1.42 cimException = PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
287 MessageLoaderParms("HandlerService.IndicationHandlerService."
288 "INVALID_TARGETHOST", "invalid targethost"));
|
289 marek 1.55 handleIndicationSuccess = false;
|
290 kumpf 1.33 }
|
291 yi.zhou 1.42 else
|
292 kumpf 1.33 {
|
293 marek 1.55 handleIndicationSuccess = _loadHandler(request, cimException);
|
294 kumpf 1.33 }
295 }
296 }
|
297 yi.zhou 1.44 else if ((className.equal (PEGASUS_CLASSNAME_LSTNRDST_SYSTEM_LOG)) ||
298 (className.equal (PEGASUS_CLASSNAME_LSTNRDST_EMAIL)))
|
299 yi.zhou 1.42 {
|
300 marek 1.55 handleIndicationSuccess = _loadHandler(request, cimException);
301 }
302
303 // no success to handle indication
304 // somewhere an exception message was build
305 // time to write the error message to the log
306 if (!handleIndicationSuccess)
307 {
|
308 yi.zhou 1.60 Logger::put(Logger::ERROR_LOG, System::CIMSERVER, Logger::WARNING,
|
309 marek 1.55 MessageLoaderParms("HandlerService.IndicationHandlerService."
310 "INDICATION_DELIVERY_FAILED",
311 "Failed to deliver an indication. Reason: "
312 ).toString()+ cimException.getMessage());
|
313 yi.zhou 1.42 }
314
315 CIMHandleIndicationResponseMessage* response =
316 new CIMHandleIndicationResponseMessage(
|
317 kumpf 1.16 request->messageId,
318 cimException,
|
319 a.arora 1.39 request->queueIds.copyAndPop());
|
320 marek 1.55
|
321 karl 1.46 delete request;
|
322 kumpf 1.33 return response;
|
323 kumpf 1.1 }
324
|
325 marek 1.55 Boolean IndicationHandlerService::_loadHandler(
|
326 yi.zhou 1.42 CIMHandleIndicationRequestMessage* request,
327 CIMException & cimException)
328 {
329 CIMName className = request->handlerInstance.getClassName();
|
330 yi.zhou 1.49
|
331 yi.zhou 1.48 try
332 {
|
333 yi.zhou 1.49 CIMHandler * handlerLib = _lookupHandlerForClass(className);
|
334 yi.zhou 1.42
|
335 yi.zhou 1.49 if (handlerLib)
|
336 yi.zhou 1.48 {
|
337 kumpf 1.51 ContentLanguageList langs =
|
338 yi.zhou 1.42 ((ContentLanguageListContainer)request->operationContext.
339 get(ContentLanguageListContainer::NAME)).getLanguages();
340
341 handlerLib->handleIndication(
342 request->operationContext,
343 request->nameSpace.getString(),
344 request->indicationInstance,
345 request->handlerInstance,
346 request->subscriptionInstance,
347 langs);
|
348 yi.zhou 1.48 }
349 else
350 {
351 cimException = PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
352 MessageLoaderParms("HandlerService."
353 "IndicationHandlerService.FAILED_TO_LOAD",
354 "Failed to load Handler"));
|
355 marek 1.55 return false;
|
356 yi.zhou 1.48 }
357
358 }
359 catch (Exception& e)
360 {
361 cimException =
362 PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, e.getMessage());
|
363 marek 1.55 return false;
|
364 yi.zhou 1.42 }
|
365 yi.zhou 1.48 catch (...)
|
366 yi.zhou 1.42 {
|
367 yi.zhou 1.48 cimException =
368 PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "Exception: Unknown");
|
369 marek 1.55 return false;
|
370 yi.zhou 1.42 }
|
371 marek 1.55 return true;
|
372 yi.zhou 1.42 }
373
|
374 kumpf 1.1 CIMHandler* IndicationHandlerService::_lookupHandlerForClass(
|
375 kumpf 1.19 const CIMName& className)
|
376 kumpf 1.1 {
|
377 mday 1.6 String handlerId;
|
378 kumpf 1.1
|
379 tony 1.30 if (className.equal (PEGASUS_CLASSNAME_INDHANDLER_CIMXML)
380 || className.equal (PEGASUS_CLASSNAME_LSTNRDST_CIMXML)
381 )
|
382 humberto 1.45 #ifdef PEGASUS_OS_OS400
|
383 chuck 1.47 {
384 handlerId = LIBRARY_NAME_CIMXML_INDICATION_HNDLR;
385 handlerId.append("/CIMxmlIndicationHandler");
386 }
|
387 humberto 1.45 #else
|
388 kumpf 1.8 handlerId = String("CIMxmlIndicationHandler");
|
389 humberto 1.45 #endif
|
390 kumpf 1.21 else if (className.equal (PEGASUS_CLASSNAME_INDHANDLER_SNMP))
|
391 humberto 1.45 #ifdef PEGASUS_OS_OS400
|
392 chuck 1.47 {
|
393 humberto 1.45 handlerId = LIBRARY_NAME_SNMP_INDICATION_HNDLR;
|
394 chuck 1.47 handlerId.append("/snmpIndicationHandler");
395 }
|
396 humberto 1.45 #else
|
397 kumpf 1.8 handlerId = String("snmpIndicationHandler");
|
398 humberto 1.45 #endif
|
399 yi.zhou 1.42 else if (className.equal (PEGASUS_CLASSNAME_LSTNRDST_SYSTEM_LOG))
400 handlerId = String("SystemLogListenerDestination");
|
401 yi.zhou 1.44 else if (className.equal (PEGASUS_CLASSNAME_LSTNRDST_EMAIL))
402 handlerId = String("EmailListenerDestination");
|
403 carolann.graves 1.59
404 PEGASUS_ASSERT(handlerId.size() != 0);
|
405 kumpf 1.1
|
406 yi.zhou 1.48 CIMHandler* handler = _handlerTable.getHandler(handlerId, _repository);
|
407 kumpf 1.1
|
408 mday 1.6 return handler;
|
409 kumpf 1.1 }
410
411 PEGASUS_NAMESPACE_END
|
412 tony 1.30
413
|