1 martin 1.21 //%LICENSE////////////////////////////////////////////////////////////////
|
2 martin 1.22 //
|
3 martin 1.21 // Licensed to The Open Group (TOG) under one or more contributor license
4 // agreements. Refer to the OpenPegasusNOTICE.txt file distributed with
5 // this work for additional information regarding copyright ownership.
6 // Each contributor licenses this file to you under the OpenPegasus Open
7 // Source License; you may not use this file except in compliance with the
8 // License.
|
9 martin 1.22 //
|
10 martin 1.21 // Permission is hereby granted, free of charge, to any person obtaining a
11 // copy of this software and associated documentation files (the "Software"),
12 // to deal in the Software without restriction, including without limitation
13 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 // and/or sell copies of the Software, and to permit persons to whom the
15 // Software is furnished to do so, subject to the following conditions:
|
16 martin 1.22 //
|
17 martin 1.21 // The above copyright notice and this permission notice shall be included
18 // in all copies or substantial portions of the Software.
|
19 martin 1.22 //
|
20 martin 1.21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
21 martin 1.22 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
22 martin 1.21 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
27 martin 1.22 //
|
28 martin 1.21 //////////////////////////////////////////////////////////////////////////
|
29 yi.zhou 1.1 //
30 //%/////////////////////////////////////////////////////////////////////////////
31
32 #include <Pegasus/Common/Config.h>
33 #include <Pegasus/Common/PegasusVersion.h>
34
35 #include <iostream>
36 #include <Pegasus/Handler/CIMHandler.h>
37 #include <Pegasus/Repository/CIMRepository.h>
38 #include <Pegasus/Common/Tracer.h>
39 #include <Pegasus/Common/MessageLoader.h>
40 #include <Pegasus/Common/System.h>
41 #include <Pegasus/Common/CIMType.h>
|
42 carson.hovey 1.9 #include <Pegasus/IndicationService/IndicationConstants.h>
|
43 yi.zhou 1.1
|
44 thilo.boehm 1.23 #include <Pegasus/General/IndicationFormatter.h>
45
|
46 carson.hovey 1.9 #if defined(PEGASUS_OS_VMS)
47 #include <unistd>
48 #include <stdio>
49 #include <descrip>
50 #include <ssdef>
51 #include <maildef>
52 #include <mail$routines>
53 #include <nam>
54 #include <starlet>
55 #endif
56
57 #if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_OS_LINUX) && \
58 !defined(PEGASUS_OS_VMS)
59 #error "Unsupported Platform"
|
60 yi.zhou 1.2 #endif
61
|
62 yi.zhou 1.1 #include "EmailListenerDestination.h"
63
64 PEGASUS_NAMESPACE_BEGIN
65
66 PEGASUS_USING_STD;
67
|
68 kumpf 1.10 void EmailListenerDestination::initialize(CIMRepository* repository)
|
69 yi.zhou 1.1 {
70 }
71
72 void EmailListenerDestination::handleIndication(
|
73 kumpf 1.10 const OperationContext& context,
74 const String nameSpace,
75 CIMInstance& indication,
76 CIMInstance& handler,
77 CIMInstance& subscription,
78 ContentLanguageList& contentLanguages)
|
79 yi.zhou 1.1 {
|
80 kumpf 1.10 PEG_METHOD_ENTER(TRC_IND_HANDLER,
81 "EmailListenerDestination::handleIndication");
|
82 carson.hovey 1.9
|
83 kumpf 1.10 String indicationText;
|
84 carson.hovey 1.9
|
85 kumpf 1.10 try
86 {
|
87 marek 1.17 PEG_TRACE ((TRC_INDICATION_GENERATION, Tracer::LEVEL4,
|
88 w.otsuka 1.15 "EmailListenerDestination %s:%s.%s processing %s Indication",
89 (const char*)(nameSpace.getCString()),
90 (const char*)(handler.getClassName().getString().getCString()),
91 (const char*)(handler.getProperty(
92 handler.findProperty(PEGASUS_PROPERTYNAME_NAME)).
93 getValue().toString().getCString()),
94 (const char*)(indication.getClassName().getString().
95 getCString())));
96
|
97 kumpf 1.10 // gets formatted indication message
98 indicationText = IndicationFormatter::getFormattedIndText(
99 subscription, indication, contentLanguages);
100
101 // get MailTo from handler instance
102 Array < String > mailTo;
103 handler.getProperty(handler.findProperty(
104 PEGASUS_PROPERTYNAME_LSTNRDST_MAILTO)).getValue().get(mailTo);
105
106 // get MailSubject from handler instance
|
107 kumpf 1.14 String mailSubject;
|
108 kumpf 1.10 handler.getProperty(handler.findProperty(
109 PEGASUS_PROPERTYNAME_LSTNRDST_MAILSUBJECT)).getValue().get(
110 mailSubject);
111
112 // get MailCc from handler instance
113 CIMValue mailCcValue;
114 Array<String> mailCc;
115
116 Uint32 posMailCc = handler.findProperty(
117 PEGASUS_PROPERTYNAME_LSTNRDST_MAILCC);
118
119 if (posMailCc != PEG_NOT_FOUND)
120 {
121 mailCcValue = handler.getProperty(posMailCc).getValue();
122 }
123
124 if (!mailCcValue.isNull())
125 {
126 if ((mailCcValue.getType() == CIMTYPE_STRING) &&
127 (mailCcValue.isArray()))
128 {
129 kumpf 1.10 mailCcValue.get(mailCc);
130 }
131 }
|
132 yi.zhou 1.1
|
133 kumpf 1.10 // Sends the formatted indication to the specified recipients
134 _sendViaEmail(mailTo, mailCc, mailSubject, indicationText);
135 }
136 catch (CIMException& c)
137 {
|
138 thilo.boehm 1.20 PEG_TRACE((TRC_IND_HANDLER, Tracer::LEVEL1, "CIMException: %s",
139 (const char*)c.getMessage().getCString()));
|
140 kumpf 1.10 PEG_METHOD_EXIT();
141 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, c.getMessage());
142 }
143 catch (Exception& e)
|
144 yi.zhou 1.1 {
|
145 thilo.boehm 1.20 PEG_TRACE((TRC_IND_HANDLER, Tracer::LEVEL1, "Exception: %s",
146 (const char*)e.getMessage().getCString()));
|
147 kumpf 1.10 PEG_METHOD_EXIT();
148 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, e.getMessage());
|
149 yi.zhou 1.1 }
|
150 kumpf 1.10 catch (...)
|
151 yi.zhou 1.1 {
|
152 marek 1.17 PEG_TRACE_CSTRING(TRC_IND_HANDLER, Tracer::LEVEL1,
|
153 kumpf 1.10 "Failed to deliver indication via e-mail.");
154 PEG_METHOD_EXIT();
155 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms(
156 "Handler.EmailListenerDestination.EmailListenerDestination."
157 "FAILED_TO_DELIVER_INDICATION_VIA_EMAIL",
158 "Failed to deliver indication via e-mail."));
|
159 yi.zhou 1.1 }
160
|
161 carson.hovey 1.9 PEG_METHOD_EXIT();
|
162 yi.zhou 1.1 }
163
164 void EmailListenerDestination::_sendViaEmail(
|
165 kumpf 1.10 const Array<String>& mailTo,
166 const Array<String>& mailCc,
167 const String& mailSubject,
168 const String& formattedText)
|
169 yi.zhou 1.1 {
|
170 kumpf 1.10 PEG_METHOD_ENTER(TRC_IND_HANDLER,
171 "EmailListenerDestination::_sendViaEmail");
|
172 carson.hovey 1.9
173 #if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_OS_LINUX) || \
174 defined(PEGASUS_OS_VMS)
|
175 yi.zhou 1.1
|
176 kumpf 1.10 String exceptionStr;
177 FILE* filePtr;
178 char mailFile[TEMP_NAME_LEN];
|
179 carson.hovey 1.9
180 #ifndef PEGASUS_OS_VMS
|
181 kumpf 1.10 // Check for proper execute permissions for sendmail
182 if (access(SENDMAIL_CMD, X_OK) < 0)
183 {
|
184 kumpf 1.18 Logger::put_l(Logger::STANDARD_LOG, System::CIMSERVER, Logger::WARNING,
|
185 kumpf 1.19 MessageLoaderParms(
186 "Handler.EmailListenerDestination.EmailListenerDestination."
187 "_MSG_EXECUTE_ACCESS_FAILED",
188 "Cannot execute $0: $1",
189 SENDMAIL_CMD,
190 strerror(errno)));
|
191 kumpf 1.10
192 PEG_METHOD_EXIT();
193 return;
194 }
|
195 carson.hovey 1.9 #endif
196
|
197 kumpf 1.10 // open a temporary file to hold the indication mail message
198 _openFile(&filePtr, mailFile);
199
200 try
201 {
202 _buildMailHeader(mailTo, mailCc, mailSubject, filePtr);
203
204 // write indication text to the file
205 _writeStrToFile(formattedText, filePtr);
|
206 carson.hovey 1.9
|
207 kumpf 1.10 fclose(filePtr);
208 }
|
209 kumpf 1.16 catch (CIMException&)
|
210 kumpf 1.10 {
211 fclose(filePtr);
212 unlink(mailFile);
|
213 yi.zhou 1.1
|
214 kumpf 1.10 PEG_METHOD_EXIT();
215 return;
216 }
|
217 yi.zhou 1.1
|
218 kumpf 1.10 try
219 {
|
220 carson.hovey 1.9 #ifdef PEGASUS_OS_VMS
|
221 kumpf 1.10 //
222 // Start mail send process
223 //
224 status = mail$send_begin(&send_context, &nulllist, &nulllist);
225 if (status != SS$_NORMAL)
226 {
|
227 marek 1.17 PEG_TRACE_CSTRING(TRC_IND_HANDLER, Tracer::LEVEL1,
|
228 kumpf 1.10 "Routine mail$send_begin failed.");
229 PEG_METHOD_EXIT();
230
231 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms(
232 "Handler.EmailListenerDestination.EmailListenerDestination."
233 "ROUTINE_MAIL_SEND_BEGIN_FAILED.PEGASUS_OS_VMS",
234 "Routine mail$send_begin failed."));
235 }
236 #endif
237 // send the message
238 _sendMsg(mailFile);
239 }
|
240 kumpf 1.16 catch (CIMException&)
|
241 carson.hovey 1.9 {
|
242 kumpf 1.10 unlink(mailFile);
243
244 PEG_METHOD_EXIT();
245 return;
|
246 yi.zhou 1.1 }
|
247 kumpf 1.10
|
248 carson.hovey 1.9 unlink(mailFile);
249
|
250 kumpf 1.10 #else
|
251 yi.zhou 1.1
|
252 marek 1.17 PEG_TRACE_CSTRING(TRC_IND_HANDLER, Tracer::LEVEL1,
|
253 kumpf 1.10 "sendmail is not supported.");
254 PEG_METHOD_EXIT();
|
255 yi.zhou 1.1
|
256 kumpf 1.10 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_NOT_SUPPORTED, MessageLoaderParms(
257 "Handler.EmailListenerDestination.EmailListenerDestination."
258 "UNSUPPORTED_OPERATION",
259 "sendmail is not supported."));
|
260 carson.hovey 1.9 #endif
|
261 yi.zhou 1.1
|
262 kumpf 1.10 PEG_METHOD_EXIT();
|
263 carson.hovey 1.9 }
|
264 yi.zhou 1.1
|
265 carson.hovey 1.9 void EmailListenerDestination::_buildMailHeader(
|
266 kumpf 1.10 const Array<String>& mailTo,
267 const Array<String>& mailCc,
268 const String& mailSubject,
269 FILE* filePtr)
|
270 carson.hovey 1.9 {
|
271 kumpf 1.10 PEG_METHOD_ENTER(TRC_IND_HANDLER,
272 "EmailListenerDestination::_buildMailHeader");
|
273 yi.zhou 1.1
|
274 kumpf 1.10 String exceptionStr;
|
275 yi.zhou 1.1
|
276 kumpf 1.10 String mailToStr = _buildMailAddrStr(mailTo);
|
277 yi.zhou 1.1
|
278 kumpf 1.10 if (mailToStr == String::EMPTY)
279 {
280 PEG_METHOD_EXIT();
281 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms(
282 "Handler.EmailListenerDestination.EmailListenerDestination."
283 "DO_NOT_HAVE_EMAIL_ADDRESS",
284 "Do not have an e-mail address."));
285 }
|
286 w.otsuka 1.15 PEG_TRACE ((TRC_INDICATION_GENERATION, Tracer::LEVEL3,
287 "EmailListenerDestination sending Indication via email to %s",
288 (const char*)(mailToStr.getCString())));
|
289 carson.hovey 1.9
290 #ifdef PEGASUS_OS_VMS
291
|
292 kumpf 1.10 //
293 // Add cc destination to message.
294 //
295
296 String mailCcStr = _buildMailAddrCcStr(mailCc);
297
298 //
299 // Write the mailSubject string
300 //
301
|
302 kumpf 1.14 String mailSubjectStr;
|
303 kumpf 1.10 mailSubjectStr.append(mailSubject);
304 CString foo = mailSubjectStr.getCString();
305
306 attribute_itmlst[0].buffer_length = strlen(foo);
307 attribute_itmlst[0].buffer_address = (long &)foo;
308
309 status = mail$send_add_attribute(
310 &send_context,
311 attribute_itmlst,
312 &nulllist);
313 if (status != SS$_NORMAL)
314 {
|
315 marek 1.17 PEG_TRACE_CSTRING(TRC_IND_HANDLER, Tracer::LEVEL1,
|
316 kumpf 1.10 "Routine mail$send_add_attribute failed.");
317 PEG_METHOD_EXIT();
318
319 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms(
320 "Handler.EmailListenerDestination.EmailListenerDestination."
321 "ROUTINE_MAIL_SEND_ADD_ATTRIBUTE_FAILED.PEGASUS_OS_VMS",
322 "Routine mail$send_add_attribute failed."));
323 }
324
325 //
326 // Add filename to bodypart of the message
327 //
|
328 yi.zhou 1.1
|
329 kumpf 1.10 bodypart_itmlst[0].buffer_length = strlen(mailFileVms);
330 bodypart_itmlst[0].buffer_address = (long &)mailFileVms;
|
331 yi.zhou 1.1
|
332 kumpf 1.10 status = mail$send_add_bodypart(&send_context, bodypart_itmlst, 0);
333 if (status != SS$_NORMAL)
334 {
|
335 marek 1.17 PEG_TRACE_CSTRING(TRC_IND_HANDLER, Tracer::LEVEL1,
|
336 kumpf 1.10 "Routine mail$send_add_bodypart failed..");
337 PEG_METHOD_EXIT();
338
339 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms(
340 "Handler.EmailListenerDestination.EmailListenerDestination."
341 "ROUTINE_MAIL_SEND_ADD_BODYPART_FAILED.PEGASUS_OS_VMS",
342 "Routine mail$send_add_bodypart failed."));
343 }
|
344 carson.hovey 1.9
345 #else
346
|
347 kumpf 1.14 String mailHdrStr;
|
348 carson.hovey 1.9
|
349 kumpf 1.10 // Write the mailToStr to file
350 mailHdrStr.append("To: ");
351 mailHdrStr.append(mailToStr);
352 _writeStrToFile(mailHdrStr, filePtr);
353
354 String mailCcStr = _buildMailAddrStr(mailCc);
355
356 // Write the mailCcStr to file
357 mailHdrStr = String::EMPTY;
358
359 mailHdrStr.append("Cc: ");
360 mailHdrStr.append(mailCcStr);
361 _writeStrToFile(mailHdrStr, filePtr);
362
363 // build from string
|
364 kumpf 1.14 String fromStr;
|
365 kumpf 1.10 fromStr.append("From: ");
366 fromStr.append(System::getEffectiveUserName());
367 fromStr.append("@");
368 fromStr.append(System::getFullyQualifiedHostName());
369
370 // Write the fromStr to file
371 _writeStrToFile(fromStr, filePtr);
372
373 // Write the mailSubject string to file
|
374 kumpf 1.14 String mailSubjectStr;
|
375 kumpf 1.10 mailSubjectStr.append("Subject: ");
376 mailSubjectStr.append(mailSubject);
377 _writeStrToFile(mailSubjectStr, filePtr);
|
378 yi.zhou 1.1 #endif
379
|
380 kumpf 1.10 PEG_METHOD_EXIT();
|
381 yi.zhou 1.1 }
382
|
383 carson.hovey 1.9 String EmailListenerDestination::_buildMailAddrStr(
|
384 kumpf 1.10 const Array<String>& mailAddr)
|
385 yi.zhou 1.1 {
|
386 kumpf 1.10 PEG_METHOD_ENTER(TRC_IND_HANDLER,
387 "EmailListenerDestination::_buildMailAddrStr");
|
388 yi.zhou 1.1
|
389 kumpf 1.14 String mailAddrStr;
|
390 kumpf 1.10 Uint32 mailAddrSize = mailAddr.size();
|
391 yi.zhou 1.1
|
392 kumpf 1.10 for (Uint32 i = 0; i < mailAddrSize; i++)
393 {
|
394 carson.hovey 1.9 #if defined(PEGASUS_OS_VMS)
395
|
396 kumpf 1.10 CString mailAddrVms = mailAddr[i].getCString();
397 //
398 // Add destination to message
399 //
400 address_itmlst[0].buffer_length = strlen(mailAddrVms);
401 address_itmlst[0].buffer_address = (long &)mailAddrVms;
402
403 status = mail$send_add_address(
404 &send_context,
405 address_itmlst,
406 &nulllist);
407 if (status != SS$_NORMAL)
408 {
|
409 marek 1.17 PEG_TRACE_CSTRING(TRC_IND_HANDLER, Tracer::LEVEL1,
|
410 kumpf 1.10 "Routine mail$send_add_address failed.");
411 PEG_METHOD_EXIT();
412
413 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms(
414 "Handler.EmailListenerDestination.EmailListenerDestination."
415 "ROUTINE_MAIL_SEND_ADD_ADDRESS_FAILED.PEGASUS_OS_VMS",
416 "Routine mail$send_add_address failed."));
417 }
418 mailAddrStr = "VMS";
|
419 carson.hovey 1.9 #else
|
420 kumpf 1.10 mailAddrStr.append(mailAddr[i]);
|
421 yi.zhou 1.1
|
422 kumpf 1.10 if (i < (mailAddrSize - 1))
423 {
424 mailAddrStr.append(",");
425 }
426 #endif
|
427 yi.zhou 1.1 }
428
|
429 kumpf 1.10 PEG_METHOD_EXIT();
430 return mailAddrStr;
|
431 yi.zhou 1.1 }
432
|
433 carson.hovey 1.9 #ifdef PEGASUS_OS_VMS
434 String EmailListenerDestination::_buildMailAddrCcStr(
|
435 kumpf 1.10 const Array<String>& mailAddr)
|
436 yi.zhou 1.1 {
|
437 kumpf 1.10 PEG_METHOD_ENTER(TRC_IND_HANDLER,
438 "EmailListenerDestination::_buildMailAddrCcStr");
|
439 yi.zhou 1.1
|
440 kumpf 1.14 String mailAddrStr;
|
441 kumpf 1.10 Uint32 mailAddrSize = mailAddr.size();
|
442 yi.zhou 1.1
|
443 kumpf 1.10 for (Uint32 i = 0; i < mailAddrSize; i++)
|
444 carson.hovey 1.9 {
|
445 kumpf 1.10 CString mailAddrCcVms = mailAddr[i].getCString();
446 //
447 // Add cc destination to message
448 //
449 address_cc_itmlst[0].buffer_length = strlen(mailAddrCcVms);
450 address_cc_itmlst[0].buffer_address = (long &)mailAddrCcVms;
451
452 status = mail$send_add_address(
453 &send_context,
454 address_cc_itmlst,
455 &nulllist);
456 if (status != SS$_NORMAL)
457 {
|
458 marek 1.17 PEG_TRACE_CSTRING(TRC_IND_HANDLER, Tracer::LEVEL1,
|
459 kumpf 1.10 "Routine mail$send_add_address failed (cc).");
460 PEG_METHOD_EXIT();
461
462 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms(
463 "Handler.EmailListenerDestination.EmailListenerDestination."
464 "ROUTINE_MAIL_SEND_ADD_ADDRESS_FAILED_CC.PEGASUS_OS_VMS",
465 "Routine mail$send_add_address failed (cc)."));
466 }
|
467 yi.zhou 1.1 }
468
|
469 kumpf 1.10 PEG_METHOD_EXIT();
470 return mailAddrStr;
|
471 yi.zhou 1.1 }
472
|
473 carson.hovey 1.9 #endif
474
|
475 yi.zhou 1.1 void EmailListenerDestination::_writeStrToFile(
|
476 kumpf 1.10 const String& mailHdrStr,
477 FILE* filePtr)
|
478 yi.zhou 1.1 {
|
479 kumpf 1.10 PEG_METHOD_ENTER(TRC_IND_HANDLER,
480 "EmailListenerDestination::_writeStrToFile");
|
481 yi.zhou 1.1
|
482 kumpf 1.10 String exceptionStr;
|
483 yi.zhou 1.1
|
484 kumpf 1.10 if (fprintf(filePtr, "%s\n", (const char *) mailHdrStr.getCString()) < 0)
485 {
|
486 marek 1.17 PEG_TRACE((TRC_IND_HANDLER, Tracer::LEVEL1,
|
487 kumpf 1.10 "Failed to write the %s to the file: %s.",
488 (const char *) mailHdrStr.getCString(),
|
489 marek 1.12 strerror(errno)));
|
490 kumpf 1.10
491 MessageLoaderParms parms(
492 "Handler.EmailListenerDestination.EmailListenerDestination."
493 "_MSG_WRITE_TO_THE_FILE_FAILED",
494 "Failed to write the $0 to the file: $1.",
495 mailHdrStr,
496 strerror(errno));
|
497 yi.zhou 1.1
|
498 kumpf 1.10 exceptionStr.append(MessageLoader::getMessage(parms));
|
499 yi.zhou 1.1
|
500 kumpf 1.10 PEG_METHOD_EXIT();
|
501 yi.zhou 1.1
|
502 kumpf 1.10 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, exceptionStr);
503 }
|
504 yi.zhou 1.1
|
505 kumpf 1.10 PEG_METHOD_EXIT();
|
506 yi.zhou 1.1 }
507
|
508 yi.zhou 1.4 void EmailListenerDestination::_sendMsg(
|
509 kumpf 1.10 char* mailFile)
|
510 yi.zhou 1.1 {
|
511 kumpf 1.10 PEG_METHOD_ENTER(TRC_IND_HANDLER, "EmailListenerDestination::_sendMsg");
|
512 yi.zhou 1.1
|
513 kumpf 1.10 String exceptionStr;
514 char sendmailCmd[MAX_SENDMAIL_CMD_LEN];
515 FILE* sendmailPtr;
516 struct stat statBuf;
517
518 // Checks the existence of the temp mail file
519 if (!System::exists(mailFile))
520 {
|
521 marek 1.17 PEG_TRACE((TRC_IND_HANDLER, Tracer::LEVEL1,
|
522 kumpf 1.10 "File %s does not exist: %s.",
523 mailFile,
|
524 marek 1.12 strerror(errno)));
|
525 kumpf 1.10
526 MessageLoaderParms parms(
527 "Handler.EmailListenerDestination.EmailListenerDestination."
528 "_MSG_FILE_DOES_NOT_EXIST",
529 "File $0 does not exist: $1.",
530 mailFile,
531 strerror(errno));
|
532 yi.zhou 1.1
|
533 kumpf 1.10 exceptionStr.append(MessageLoader::getMessage(parms));
|
534 yi.zhou 1.1
|
535 kumpf 1.10 PEG_METHOD_EXIT();
536
537 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, exceptionStr);
538 }
|
539 yi.zhou 1.1
|
540 kumpf 1.10 // Checks the length of the file since a zero length file causes
541 // problems for sendmail()
542 if (stat(mailFile, &statBuf) != 0)
543 {
|
544 marek 1.17 PEG_TRACE((TRC_IND_HANDLER, Tracer::LEVEL1,
|
545 kumpf 1.10 "Can not get file %s status: %s.",
546 mailFile,
|
547 marek 1.12 strerror(errno)));
|
548 kumpf 1.10
549 MessageLoaderParms parms(
550 "Handler.EmailListenerDestination.EmailListenerDestination."
551 "_MSG_CAN_NOT_GET_FILE_STATUS",
552 "Can not get file $0 status: $1.",
553 mailFile,
554 strerror(errno));
|
555 yi.zhou 1.1
|
556 kumpf 1.10 exceptionStr.append(MessageLoader::getMessage(parms));
|
557 yi.zhou 1.1
|
558 kumpf 1.10 PEG_METHOD_EXIT();
|
559 yi.zhou 1.1
|
560 kumpf 1.10 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, exceptionStr);
561 }
|
562 yi.zhou 1.1
|
563 kumpf 1.10 if (statBuf.st_size == 0)
564 {
|
565 marek 1.17 PEG_TRACE((TRC_IND_HANDLER, Tracer::LEVEL1,
|
566 kumpf 1.10 "File %s does not contain any data.",
|
567 marek 1.12 mailFile));
|
568 yi.zhou 1.1
|
569 kumpf 1.10 MessageLoaderParms parms(
570 "Handler.EmailListenerDestination.EmailListenerDestination."
571 "_MSG_FILE_DOES_NOT_CONTAIN_DATA",
572 "File $0 does not contain any data.",
573 mailFile);
|
574 yi.zhou 1.1
|
575 kumpf 1.10 exceptionStr.append(MessageLoader::getMessage(parms));
|
576 yi.zhou 1.1
|
577 kumpf 1.10 PEG_METHOD_EXIT();
|
578 yi.zhou 1.1
|
579 kumpf 1.10 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, exceptionStr);
580 }
|
581 yi.zhou 1.1
|
582 carson.hovey 1.9 #ifdef PEGASUS_OS_VMS
|
583 kumpf 1.10 //
584 // Send the mail message
585 //
586 status = mail$send_message(&send_context, nulllist, nulllist);
587 if (status != SS$_NORMAL)
588 {
|
589 marek 1.17 PEG_TRACE_CSTRING(TRC_IND_HANDLER, Tracer::LEVEL1,
|
590 kumpf 1.10 "Routine mail$send_message failed.");
591 PEG_METHOD_EXIT();
592
593 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms(
594 "Handler.EmailListenerDestination.EmailListenerDestination."
595 "ROUTINE_MAIL_SEND_MESSAGE_FAILED.PEGASUS_OS_VMS",
596 "Routine mail$send_message failed."));
597 }
598
599 //
600 // End mail send process
601 //
602 status = mail$send_end(&send_context, nulllist, nulllist);
603 if (status != SS$_NORMAL)
604 {
|
605 marek 1.17 PEG_TRACE_CSTRING(TRC_IND_HANDLER, Tracer::LEVEL1,
|
606 kumpf 1.10 "Routine mail$send_end failed.");
607 PEG_METHOD_EXIT();
608
609 throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED, MessageLoaderParms(
610 "Handler.EmailListenerDestination.EmailListenerDestination."
611 "ROUTINE_MAIL_SEND_END_FAILED.PEGASUS_OS_VMS",
612 "Routine mail$send_end failed."));
613 }
|
614 yi.zhou 1.1
|
615 kumpf 1.10 #else
616 sprintf(sendmailCmd, "%s %s %s", SENDMAIL_CMD, SENDMAIL_CMD_OPTS, mailFile);
|
617 yi.zhou 1.1
|
618 kumpf 1.10 // Open the pipe to send the message
619 if ((sendmailPtr = popen(sendmailCmd, "r")) == NULL)
620 {
|
621 marek 1.17 PEG_TRACE_CSTRING(TRC_IND_HANDLER, Tracer::LEVEL1,
|
622 kumpf 1.10 "popen of sendmail failed.");
|
623 yi.zhou 1.1
|
624 kumpf 1.10 MessageLoaderParms parms(
625 "Handler.EmailListenerDestination.EmailListenerDestination."
626 "_MSG_POPEN_OF_SENDMAIL_FAILED",
627 "popen of sendmail failed.");
|
628 yi.zhou 1.1
|
629 kumpf 1.10 exceptionStr.append(MessageLoader::getMessage(parms));
|
630 yi.zhou 1.1
|
631 kumpf 1.10 PEG_METHOD_EXIT();
|
632 yi.zhou 1.1
|
633 kumpf 1.10 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, exceptionStr);
634 }
|
635 yi.zhou 1.1
|
636 kumpf 1.10 // Close the pipe
637 Sint32 retCode = pclose(sendmailPtr);
638 if (retCode < 0)
639 {
|
640 marek 1.17 PEG_TRACE_CSTRING(TRC_IND_HANDLER, Tracer::LEVEL1,
|
641 kumpf 1.10 "No associated stream with this popen command.");
|
642 yi.zhou 1.1
|
643 kumpf 1.10 MessageLoaderParms parms(
644 "Handler.EmailListenerDestination.EmailListenerDestination."
645 "_MSG_NO_ASSOCIATED_STREAM",
646 "No associated stream with this popen command.");
|
647 yi.zhou 1.1
|
648 kumpf 1.10 exceptionStr.append(MessageLoader::getMessage(parms));
|
649 yi.zhou 1.1
|
650 kumpf 1.10 PEG_METHOD_EXIT();
|
651 yi.zhou 1.1
|
652 kumpf 1.10 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, exceptionStr);
653 }
654 else if (retCode == SH_EXECUTE_FAILED)
655 {
|
656 marek 1.17 PEG_TRACE_CSTRING(TRC_IND_HANDLER, Tracer::LEVEL1,
|
657 kumpf 1.10 "/usr/bin/sh could not be executed.");
|
658 yi.zhou 1.1
|
659 kumpf 1.10 MessageLoaderParms parms(
660 "Handler.EmailListenerDestination.EmailListenerDestination."
661 "_MSG_SHELL_CAN_NOT_BE_EXECUTED",
662 "/usr/bin/sh could not be executed.");
|
663 yi.zhou 1.1
|
664 kumpf 1.10 exceptionStr.append(MessageLoader::getMessage(parms));
|
665 yi.zhou 1.1
|
666 kumpf 1.10 PEG_METHOD_EXIT();
|
667 yi.zhou 1.1
|
668 kumpf 1.10 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, exceptionStr);
669 }
|
670 carson.hovey 1.9 #endif
|
671 yi.zhou 1.1
|
672 kumpf 1.10 PEG_METHOD_EXIT();
|
673 yi.zhou 1.1 }
674
|
675 yi.zhou 1.4 void EmailListenerDestination::_openFile(
|
676 kumpf 1.10 FILE** filePtr,
677 char* mailFile)
|
678 yi.zhou 1.4 {
|
679 kumpf 1.10 PEG_METHOD_ENTER(TRC_IND_HANDLER,
680 "EmailListenerDestination::_openFile");
|
681 yi.zhou 1.4
|
682 kumpf 1.10 String exceptionStr;
|
683 yi.zhou 1.4
|
684 kumpf 1.10 *filePtr = fopen(tmpnam(mailFile), "w");
|
685 carson.hovey 1.9 #ifdef PEGASUS_OS_VMS
|
686 kumpf 1.10 strcpy(mailFileVms, mailFile);
|
687 carson.hovey 1.9 #endif
|
688 kumpf 1.10 if (*filePtr == NULL)
689 {
|
690 marek 1.17 PEG_TRACE((TRC_IND_HANDLER, Tracer::LEVEL1,
|
691 kumpf 1.10 "fopen of %s failed: %s.", mailFile,
|
692 marek 1.12 strerror(errno)));
|
693 kumpf 1.10
694 MessageLoaderParms parms(
695 "Handler.EmailListenerDestination.EmailListenerDestination."
696 "_MSG_FAILED_TO_OPEN_THE_FILE",
697 "fopen of $0 failed: $1.",
698 mailFile,
699 strerror(errno));
|
700 yi.zhou 1.4
|
701 kumpf 1.10 exceptionStr.append(MessageLoader::getMessage(parms));
|
702 yi.zhou 1.4
|
703 kumpf 1.10 PEG_METHOD_EXIT();
|
704 yi.zhou 1.4
|
705 kumpf 1.10 throw PEGASUS_CIM_EXCEPTION(CIM_ERR_FAILED, exceptionStr);
706 }
|
707 yi.zhou 1.4
|
708 kumpf 1.10 PEG_METHOD_EXIT();
|
709 yi.zhou 1.4 }
|
710 yi.zhou 1.1
|
711 kumpf 1.7 PEGASUS_NAMESPACE_END
712
713 PEGASUS_USING_PEGASUS;
714
715 // This is the entry point into this dynamic module.
716
|
717 kumpf 1.10 extern "C" PEGASUS_EXPORT CIMHandler* PegasusCreateHandler(
718 const String& handlerName)
|
719 kumpf 1.7 {
|
720 kumpf 1.10 if (handlerName == "EmailListenerDestination")
721 {
722 return new EmailListenerDestination;
723 }
|
724 kumpf 1.7
|
725 kumpf 1.10 return 0;
|
726 yi.zhou 1.1 }
|