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 //%/////////////////////////////////////////////////////////////////////////////
33
|
34 kumpf 1.11 #include <Pegasus/Common/Constants.h>
|
35 kumpf 1.19 #include <Pegasus/Common/CIMName.h>
|
36 mday 1.14 #include <Pegasus/Common/Tracer.h>
|
37 kumpf 1.1 #include <Pegasus/Common/CIMMessage.h>
38 #include <Pegasus/Common/XmlWriter.h>
|
39 kumpf 1.13 #include <Pegasus/Common/PegasusVersion.h>
|
40 yi.zhou 1.42 #include <Pegasus/Common/Constants.h>
|
41 kumpf 1.61 #include <Pegasus/Common/MessageLoader.h>
42 #include <Pegasus/Common/AutoPtr.h>
|
43 kumpf 1.1
44 #include "IndicationHandlerService.h"
45
46 PEGASUS_USING_STD;
|
47 kumpf 1.61
|
48 kumpf 1.1 PEGASUS_USING_PEGASUS;
49
50 PEGASUS_NAMESPACE_BEGIN
51
|
52 kumpf 1.2 IndicationHandlerService::IndicationHandlerService(CIMRepository* repository)
|
53 kumpf 1.61 : Base("IndicationHandlerService", MessageQueue::getNextQueueId()),
54 _repository(repository)
|
55 kumpf 1.1 {
56 }
57
|
58 kumpf 1.61 void IndicationHandlerService::_handle_async_request(AsyncRequest* req)
|
59 kumpf 1.1 {
|
60 kumpf 1.61 if (req->getType() == async_messages::CIMSERVICE_STOP)
|
61 kumpf 1.33 {
62 req->op->processing();
63 handle_CimServiceStop(static_cast<CimServiceStop *>(req));
64 }
|
65 kumpf 1.61 else if (req->getType() == async_messages::ASYNC_LEGACY_OP_START)
|
66 kumpf 1.33 {
67 req->op->processing();
|
68 kumpf 1.61 AutoPtr<Message> legacy(
69 static_cast<AsyncLegacyOperationStart *>(req)->get_action());
|
70 kumpf 1.33 if (legacy->getType() == CIM_HANDLE_INDICATION_REQUEST_MESSAGE)
71 {
|
72 a.arora 1.38 AutoPtr<Message> legacy_response(_handleIndication(
|
73 kumpf 1.61 (CIMHandleIndicationRequestMessage*) legacy.get()));
|
74 a.arora 1.38 legacy.release();
|
75 kumpf 1.61 AutoPtr<AsyncLegacyOperationResult> async_result(
76 new AsyncLegacyOperationResult(
|
77 kumpf 1.33 req->op,
|
78 kumpf 1.61 legacy_response.get()));
|
79 a.arora 1.38 legacy_response.release();
80 async_result.release();
|
81 kumpf 1.33 _complete_op_node(req->op, ASYNC_OPSTATE_COMPLETE, 0, 0);
82 }
83 else
84 {
85 Tracer::trace(TRC_DISCARDED_DATA, Tracer::LEVEL2,
86 "IndicationHandlerService::_handle_async_request got "
87 "unexpected legacy message type '%u'", legacy->getType());
88 _make_response(req, async_results::CIM_NAK);
89 }
90 }
91 else
92 {
93 Base::_handle_async_request(req);
94 }
|
95 kumpf 1.1 }
96
|
97 mday 1.4 void IndicationHandlerService::handleEnqueue(Message* message)
|
98 kumpf 1.1 {
|
99 carolann.graves 1.58 PEGASUS_ASSERT(message != 0);
|
100 kumpf 1.33
101 // Set the client's requested language into this service thread.
102 // This will allow functions in this service to return messages
103 // in the correct language.
|
104 a.arora 1.38 AutoPtr<CIMMessage> msg(dynamic_cast<CIMMessage *>(message));
105 if (msg.get() != NULL)
|
106 kumpf 1.33 {
107 if (msg->thread_changed())
108 {
|
109 kumpf 1.61 AutoPtr<AcceptLanguageList> langs(new AcceptLanguageList((
110 (AcceptLanguageListContainer)msg->operationContext.get(
111 AcceptLanguageListContainer::NAME)).getLanguages()));
|
112 a.arora 1.38 Thread::setLanguages(langs.get());
113 langs.release();
|
114 kumpf 1.33 }
115 }
116 else
117 {
118 Thread::clearLanguages();
119 }
120
121 switch (message->getType())
122 {
123 case CIM_HANDLE_INDICATION_REQUEST_MESSAGE:
|
124 chuck 1.28 {
|
125 kumpf 1.61 AutoPtr<CIMHandleIndicationResponseMessage> response(
126 _handleIndication(
127 (CIMHandleIndicationRequestMessage*) message));
|
128 a.arora 1.38 SendForget(response.get());
129 response.release();
|
130 kumpf 1.33 break;
|
131 chuck 1.28 }
|
132 chuck 1.23
|
133 kumpf 1.33 default:
|
134 carolann.graves 1.57 PEGASUS_ASSERT(0);
|
135 kumpf 1.33 break;
136 }
137
|
138 kumpf 1.1 }
139
|
140 kumpf 1.3 void IndicationHandlerService::handleEnqueue()
141 {
|
142 a.arora 1.38 AutoPtr<Message> message(dequeue());
|
143 kumpf 1.3
|
144 a.arora 1.38 PEGASUS_ASSERT(message.get() != 0);
145 if (message.get())
|
146 kumpf 1.33 {
|
147 a.arora 1.38 handleEnqueue(message.get());
148 message.release();
|
149 kumpf 1.33 }
|
150 kumpf 1.3 }
151
|
152 kumpf 1.33 CIMHandleIndicationResponseMessage*
153 IndicationHandlerService::_handleIndication(
154 CIMHandleIndicationRequestMessage* request)
|
155 kumpf 1.1 {
|
156 kumpf 1.61 PEG_METHOD_ENTER(TRC_IND_HANDLE,
157 "IndicationHandlerService::_handleIndication");
|
158 tony 1.27
|
159 marek 1.55 Boolean handleIndicationSuccess = true;
|
160 kumpf 1.33 CIMException cimException =
161 PEGASUS_CIM_EXCEPTION(CIM_ERR_SUCCESS, String::EMPTY);
|
162 kumpf 1.1
|
163 kumpf 1.33 CIMName className = request->handlerInstance.getClassName();
164 CIMNamespaceName nameSpace = request->nameSpace;
|
165 kumpf 1.16
|
166 kumpf 1.33 CIMInstance indication = request->indicationInstance;
167 CIMInstance handler = request->handlerInstance;
168
169 Uint32 pos = PEG_NOT_FOUND;
170
171 if (className.equal (PEGASUS_CLASSNAME_INDHANDLER_CIMXML) ||
172 className.equal (PEGASUS_CLASSNAME_LSTNRDST_CIMXML))
173 {
|
174 yi.zhou 1.42 pos = handler.findProperty(PEGASUS_PROPERTYNAME_LSTNRDST_DESTINATION);
|
175 kumpf 1.1
|
176 yi.zhou 1.42 if (pos == PEG_NOT_FOUND)
|
177 kumpf 1.33 {
178 cimException = PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
|
179 kumpf 1.61 MessageLoaderParms(
180 "HandlerService.IndicationHandlerService."
181 "CIMXML_HANDLER_WITHOUT_DESTINATION",
182 "CIMXml Handler missing Destination property"));
|
183 marek 1.55 handleIndicationSuccess = false;
|
184 yi.zhou 1.42 }
185 else
186 {
187 CIMProperty prop = handler.getProperty(pos);
188 String destination = prop.getValue().toString();
189
190 if (destination.size() == 0)
191 {
192 cimException = PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
|
193 kumpf 1.61 MessageLoaderParms(
194 "HandlerService.IndicationHandlerService."
195 "INVALID_DESTINATION",
196 "invalid destination"));
|
197 marek 1.55 handleIndicationSuccess = false;
|
198 yi.zhou 1.42 }
|
199 kumpf 1.33 //compared index 10 is not :
|
200 yi.zhou 1.42 else if (destination.subString(0, 10) == String("localhost/"))
201 {
202 Array<Uint32> exportServer;
|
203 humberto 1.25
|
204 yi.zhou 1.42 find_services(PEGASUS_QUEUENAME_EXPORTREQDISPATCHER, 0, 0,
|
205 kumpf 1.33 &exportServer);
|
206 kumpf 1.1
|
207 yi.zhou 1.42 // Listener is build with Cimom, so send message to ExportServer
208
209 AutoPtr<CIMExportIndicationRequestMessage> exportmessage(
|
210 kumpf 1.61 new CIMExportIndicationRequestMessage(
211 XmlWriter::getNextMessageId(),
212 //taking localhost/CIMListener portion out from reg
213 destination.subString(21),
214 indication,
215 QueueIdStack(exportServer[0], getQueueId()),
216 String::EMPTY,
217 String::EMPTY));
|
218 kumpf 1.33
|
219 denise.eckstein 1.50 exportmessage->operationContext.insert(
220 IdentityContainer(String::EMPTY));
|
221 yi.zhou 1.42 exportmessage->operationContext.set(
|
222 kumpf 1.61 request->operationContext.get(
223 ContentLanguageListContainer::NAME));
|
224 yi.zhou 1.42 AutoPtr<AsyncOpNode> op( this->get_op());
225
226 AutoPtr<AsyncLegacyOperationStart> asyncRequest(
|
227 kumpf 1.61 new AsyncLegacyOperationStart(
|
228 a.arora 1.38 op.get(),
|
229 kumpf 1.33 exportServer[0],
|
230 a.arora 1.38 exportmessage.get(),
231 _queueId));
|
232 yi.zhou 1.42 exportmessage.release();
|
233 kumpf 1.33
|
234 yi.zhou 1.42 PEG_TRACE_STRING(TRC_IND_HANDLE, Tracer::LEVEL4,
|
235 kumpf 1.61 "Indication handler forwarding message to " +
236 ((MessageQueue::lookup(exportServer[0])) ?
237 String(((MessageQueue::lookup(exportServer[0]))->
238 getQueueName())) :
239 String("BAD queue name")));
|
240 kumpf 1.33
|
241 yi.zhou 1.42 //SendAsync(op,
242 // exportServer[0],
243 // IndicationHandlerService::_handleIndicationCallBack,
244 // this,
245 // (void *)request->queueIds.top());
246 AutoPtr<AsyncReply> asyncReply(SendWait(asyncRequest.get()));
|
247 kumpf 1.61 asyncRequest.release();
|
248 yi.zhou 1.42
249 // Return the ExportIndication results in HandleIndication
|
250 kumpf 1.61 //response
|
251 yi.zhou 1.42 AutoPtr<CIMExportIndicationResponseMessage> exportResponse(
|
252 kumpf 1.61 reinterpret_cast<CIMExportIndicationResponseMessage *>(
253 (static_cast<AsyncLegacyOperationResult *>(
254 asyncReply.get()))->get_result()));
|
255 yi.zhou 1.42 cimException = exportResponse->cimException;
|
256 kumpf 1.33
|
257 yi.zhou 1.42 op->release();
258 this->return_op(op.release());
259 }
|
260 kumpf 1.61 else
261 {
|
262 marek 1.55 handleIndicationSuccess = _loadHandler(request, cimException);
|
263 kumpf 1.61 }
|
264 yi.zhou 1.42 }
265 }
266 else if (className.equal (PEGASUS_CLASSNAME_INDHANDLER_SNMP))
267 {
268 pos = handler.findProperty(PEGASUS_PROPERTYNAME_LSTNRDST_TARGETHOST);
|
269 kumpf 1.33
|
270 yi.zhou 1.42 if (pos == PEG_NOT_FOUND)
271 {
272 cimException = PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
|
273 kumpf 1.61 MessageLoaderParms(
274 "HandlerService.IndicationHandlerService."
275 "SNMP_HANDLER_WITHOUT_TARGETHOST",
276 "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 kumpf 1.61 MessageLoaderParms(
288 "HandlerService.IndicationHandlerService."
289 "INVALID_TARGETHOST",
290 "invalid targethost"));
|
291 marek 1.55 handleIndicationSuccess = false;
|
292 kumpf 1.33 }
|
293 kumpf 1.61 else
|
294 kumpf 1.33 {
|
295 marek 1.55 handleIndicationSuccess = _loadHandler(request, cimException);
|
296 kumpf 1.33 }
297 }
298 }
|
299 yi.zhou 1.44 else if ((className.equal (PEGASUS_CLASSNAME_LSTNRDST_SYSTEM_LOG)) ||
|
300 kumpf 1.61 (className.equal (PEGASUS_CLASSNAME_LSTNRDST_EMAIL)))
|
301 yi.zhou 1.42 {
|
302 marek 1.55 handleIndicationSuccess = _loadHandler(request, cimException);
303 }
304
305 // no success to handle indication
306 // somewhere an exception message was build
307 // time to write the error message to the log
308 if (!handleIndicationSuccess)
309 {
|
310 marek 1.62 Logger::put_l(Logger::ERROR_LOG, System::CIMSERVER, Logger::WARNING,
311 "HandlerService.IndicationHandlerService."
312 "INDICATION_DELIVERY_FAILED",
313 "Failed to deliver an indication: $0",
|
314 kumpf 1.61 cimException.getMessage());
|
315 yi.zhou 1.42 }
316
317 CIMHandleIndicationResponseMessage* response =
318 new CIMHandleIndicationResponseMessage(
|
319 kumpf 1.16 request->messageId,
320 cimException,
|
321 a.arora 1.39 request->queueIds.copyAndPop());
|
322 marek 1.55
|
323 karl 1.46 delete request;
|
324 kumpf 1.33 return response;
|
325 kumpf 1.1 }
326
|
327 marek 1.55 Boolean IndicationHandlerService::_loadHandler(
|
328 yi.zhou 1.42 CIMHandleIndicationRequestMessage* request,
|
329 kumpf 1.61 CIMException& cimException)
|
330 yi.zhou 1.42 {
331 CIMName className = request->handlerInstance.getClassName();
|
332 yi.zhou 1.49
|
333 yi.zhou 1.48 try
334 {
|
335 kumpf 1.61 CIMHandler* handlerLib = _lookupHandlerForClass(className);
|
336 yi.zhou 1.42
|
337 yi.zhou 1.49 if (handlerLib)
|
338 yi.zhou 1.48 {
|
339 kumpf 1.61 ContentLanguageList langs =
|
340 yi.zhou 1.42 ((ContentLanguageListContainer)request->operationContext.
341 get(ContentLanguageListContainer::NAME)).getLanguages();
342
343 handlerLib->handleIndication(
344 request->operationContext,
345 request->nameSpace.getString(),
346 request->indicationInstance,
347 request->handlerInstance,
348 request->subscriptionInstance,
349 langs);
|
350 yi.zhou 1.48 }
351 else
352 {
353 cimException = PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
354 MessageLoaderParms("HandlerService."
355 "IndicationHandlerService.FAILED_TO_LOAD",
356 "Failed to load Handler"));
|
357 marek 1.55 return false;
|
358 yi.zhou 1.48 }
359
360 }
361 catch (Exception& e)
362 {
363 cimException =
364 PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, e.getMessage());
|
365 marek 1.55 return false;
|
366 yi.zhou 1.42 }
|
367 yi.zhou 1.48 catch (...)
|
368 yi.zhou 1.42 {
|
369 yi.zhou 1.48 cimException =
370 PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, "Exception: Unknown");
|
371 marek 1.55 return false;
|
372 yi.zhou 1.42 }
|
373 marek 1.55 return true;
|
374 yi.zhou 1.42 }
375
|
376 kumpf 1.1 CIMHandler* IndicationHandlerService::_lookupHandlerForClass(
|
377 kumpf 1.19 const CIMName& className)
|
378 kumpf 1.1 {
|
379 mday 1.6 String handlerId;
|
380 kumpf 1.1
|
381 kumpf 1.61 if (className.equal(PEGASUS_CLASSNAME_INDHANDLER_CIMXML) ||
382 className.equal(PEGASUS_CLASSNAME_LSTNRDST_CIMXML))
383 {
|
384 humberto 1.45 #ifdef PEGASUS_OS_OS400
|
385 chuck 1.47 handlerId = LIBRARY_NAME_CIMXML_INDICATION_HNDLR;
386 handlerId.append("/CIMxmlIndicationHandler");
|
387 humberto 1.45 #else
|
388 kumpf 1.8 handlerId = String("CIMxmlIndicationHandler");
|
389 humberto 1.45 #endif
|
390 kumpf 1.61 }
391 else if (className.equal(PEGASUS_CLASSNAME_INDHANDLER_SNMP))
392 {
|
393 humberto 1.45 #ifdef PEGASUS_OS_OS400
394 handlerId = LIBRARY_NAME_SNMP_INDICATION_HNDLR;
|
395 chuck 1.47 handlerId.append("/snmpIndicationHandler");
|
396 humberto 1.45 #else
|
397 kumpf 1.8 handlerId = String("snmpIndicationHandler");
|
398 humberto 1.45 #endif
|
399 kumpf 1.61 }
400 else if (className.equal(PEGASUS_CLASSNAME_LSTNRDST_SYSTEM_LOG))
|
401 yi.zhou 1.42 handlerId = String("SystemLogListenerDestination");
|
402 kumpf 1.61 else if (className.equal(PEGASUS_CLASSNAME_LSTNRDST_EMAIL))
|
403 yi.zhou 1.44 handlerId = String("EmailListenerDestination");
|
404 carolann.graves 1.59
405 PEGASUS_ASSERT(handlerId.size() != 0);
|
406 kumpf 1.1
|
407 yi.zhou 1.48 CIMHandler* handler = _handlerTable.getHandler(handlerId, _repository);
|
408 kumpf 1.1
|
409 mday 1.6 return handler;
|
410 kumpf 1.1 }
411
412 PEGASUS_NAMESPACE_END
|