(file) Return to EmailListenerDestination.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Handler / EmailListenerDestination

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2