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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2