BUG#: 5743
authorcarson.hovey <carson.hovey>
Fri, 27 Oct 2006 18:27:18 +0000 (18:27 +0000)
committercarson.hovey <carson.hovey>
Fri, 27 Oct 2006 18:27:18 +0000 (18:27 +0000)
TITLE: OpenVMS - 2.5.4 - Add support for EmailListenerDestination handler

DESCRIPTION: Port changes in 5412 for main branch to 2.5.4 stream

src/Pegasus/Handler/EmailListenerDestination/EmailListenerDestination.cpp
src/Pegasus/Handler/EmailListenerDestination/EmailListenerDestination.h

index 06410eaab3db9f5e4f7097b756fef4ad8d3b3b57..0bbf5ea8f289819c8630b12228e8f5625cb7ae96 100644 (file)
 //
 //==============================================================================
 //
-// Author: Yi Zhou, Hewlett-Packard Company (yi.zhou@hp.com)
-//
-// Modified By:
-//
 //%/////////////////////////////////////////////////////////////////////////////
 
 #include <Pegasus/Common/Config.h>
 #include <Pegasus/Common/IndicationFormatter.h>
 #include <Pegasus/IndicationService/IndicationConstants.h>
 
-#if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_OS_LINUX)
+#if defined(PEGASUS_OS_VMS)
+#include <unistd>
+#include <stdio>
+#include <descrip>
+#include <ssdef>
+#include <maildef>
+#include <mail$routines>
+#include <nam>
+#include <starlet>
+#endif
+
+#if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_OS_LINUX) && \
+    !defined(PEGASUS_OS_VMS)
 # error "Unsupported Platform" 
 #endif
 
@@ -155,13 +163,15 @@ void EmailListenerDestination::_sendViaEmail(
     PEG_METHOD_ENTER (TRC_IND_HANDLER,
        "EmailListenerDestination::_sendViaEmail");
 
-#if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_OS_LINUX)
+#if defined(PEGASUS_OS_HPUX) || defined(PEGASUS_OS_LINUX) || \
+    defined(PEGASUS_OS_VMS)
 
     String exceptionStr;
     FILE * mailFilePtr;
     FILE * filePtr;
     char mailFile[TEMP_NAME_LEN];
 
+#ifndef PEGASUS_OS_VMS
     // Check for proper execute permissions for sendmail
     if (access(SENDMAIL_CMD, X_OK) < 0)
     {
@@ -184,6 +194,7 @@ void EmailListenerDestination::_sendViaEmail(
 
        return;
     }
+#endif
 
     // open a temporary file to hold the indication mail message
     _openFile(&filePtr, mailFile);
@@ -209,6 +220,23 @@ void EmailListenerDestination::_sendViaEmail(
 
     try
     {
+#ifdef PEGASUS_OS_VMS
+    //
+    // Start mail send process
+    //
+    status = mail$send_begin(&send_context, &nulllist, &nulllist);
+    if (status != SS$_NORMAL)
+    {
+      PEG_TRACE_STRING(TRC_IND_HANDLER, Tracer::LEVEL4,
+                     "Routine mail$send_begin failed.");
+      PEG_METHOD_EXIT();
+
+      throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
+                   MessageLoaderParms("Handler.EmailListenerDestination."
+       "EmailListenerDestination.ROUTINE_MAIL_SEND_BEGIN_FAILED.PEGASUS_OS_VMS",
+                            "Routine mail$send_begin failed."));
+    }
+#endif
        // send the message
        _sendMsg(mailFile);
     }
@@ -261,6 +289,60 @@ void EmailListenerDestination::_buildMailHeader(
            "Do not have an e-mail address."));
     }
 
+#ifdef PEGASUS_OS_VMS
+
+  //
+  // Add cc destination to message.
+  //
+
+  String mailCcStr = _buildMailAddrCcStr(mailCc);
+
+  //
+  // Write the mailSubject string
+  //
+
+  String mailSubjectStr = String::EMPTY;
+  mailSubjectStr.append(mailSubject);
+  CString foo = mailSubjectStr.getCString();
+
+  attribute_itmlst[0].buffer_length = strlen(foo);
+  attribute_itmlst[0].buffer_address = (long &)foo;
+
+  status = mail$send_add_attribute(&send_context, attribute_itmlst, &nulllist);
+  if (status != SS$_NORMAL)
+  {
+    PEG_TRACE_STRING(TRC_IND_HANDLER, Tracer::LEVEL4,
+                     "Routine mail$send_add_attribute failed.");
+    PEG_METHOD_EXIT();
+
+    throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
+                   MessageLoaderParms("Handler.EmailListenerDestination."
+       "EmailListenerDestination.ROUTINE_MAIL_SEND_ADD_ATTRIBUTE_FAILED.PEGASUS_OS_VMS",
+                            "Routine mail$send_add_attribute failed."));
+  }
+
+  //
+  // Add filename to bodypart of the message
+  //
+
+  bodypart_itmlst[0].buffer_length = strlen(mailFileVms);
+  bodypart_itmlst[0].buffer_address = (long &)mailFileVms;
+
+  status = mail$send_add_bodypart(&send_context, bodypart_itmlst, 0);
+  if (status != SS$_NORMAL)
+  {
+    PEG_TRACE_STRING(TRC_IND_HANDLER, Tracer::LEVEL4,
+                     "Routine mail$send_add_bodypart failed..");
+    PEG_METHOD_EXIT();
+
+    throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
+                   MessageLoaderParms("Handler.EmailListenerDestination."
+       "EmailListenerDestination.ROUTINE_MAIL_SEND_ADD_BODYPART_FAILED.PEGASUS_OS_VMS",
+                            "Routine mail$send_add_bodypart failed."));
+  }
+
+#else
+
     String mailHdrStr = String::EMPTY;
 
     // Write the mailToStr to file
@@ -292,6 +374,7 @@ void EmailListenerDestination::_buildMailHeader(
     mailSubjectStr.append("Subject: ");
     mailSubjectStr.append(mailSubject);
     _writeStrToFile(mailSubjectStr, filePtr);
+#endif
 
     PEG_METHOD_EXIT();
 }
@@ -307,18 +390,81 @@ String EmailListenerDestination::_buildMailAddrStr(
 
     for (Uint32 i=0; i < mailAddrSize; i++)
     {
+#if defined(PEGASUS_OS_VMS)
+
+    CString mailAddrVms = mailAddr[i].getCString();
+    //
+    // Add destination to message
+    //
+    address_itmlst[0].buffer_length = strlen(mailAddrVms);
+    address_itmlst[0].buffer_address = (long &)mailAddrVms;
+
+    status = mail$send_add_address(&send_context, address_itmlst, &nulllist);
+    if (status != SS$_NORMAL)
+    {
+      PEG_TRACE_STRING(TRC_IND_HANDLER, Tracer::LEVEL4,
+                     "Routine mail$send_add_address failed.");
+      PEG_METHOD_EXIT();
+
+      throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
+                   MessageLoaderParms("Handler.EmailListenerDestination."
+       "EmailListenerDestination.ROUTINE_MAIL_SEND_ADD_ADDRESS_FAILED.PEGASUS_OS_VMS",
+                            "Routine mail$send_add_address failed."));
+    }
+    mailAddrStr = "VMS";
+#else
        mailAddrStr.append(mailAddr[i]);
 
        if (i < (mailAddrSize - 1))
        {
            mailAddrStr.append(",");
        }
+#endif
     }
 
     PEG_METHOD_EXIT();
     return (mailAddrStr);
 }
 
+#ifdef PEGASUS_OS_VMS
+String EmailListenerDestination::_buildMailAddrCcStr(
+                                        const Array < String > &mailAddr)
+{
+  PEG_METHOD_ENTER(TRC_IND_HANDLER,
+                   "EmailListenerDestination::_buildMailAddrCcStr");
+
+  String mailAddrStr = String::EMPTY;
+  Uint32 mailAddrSize = mailAddr.size();
+
+  for (Uint32 i = 0; i < mailAddrSize; i++)
+  {
+    CString mailAddrCcVms = mailAddr[i].getCString();
+    //
+    // Add cc destination to message
+    //
+    address_cc_itmlst[0].buffer_length = strlen(mailAddrCcVms);
+    address_cc_itmlst[0].buffer_address = (long &)mailAddrCcVms;
+
+    status = mail$send_add_address(&send_context, address_cc_itmlst, &nulllist);
+    if (status != SS$_NORMAL)
+    {
+      PEG_TRACE_STRING(TRC_IND_HANDLER, Tracer::LEVEL4,
+                     "Routine mail$send_add_address failed (cc).");
+      PEG_METHOD_EXIT();
+
+      throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
+                   MessageLoaderParms("Handler.EmailListenerDestination."
+       "EmailListenerDestination.ROUTINE_MAIL_SEND_ADD_ADDRESS_FAILED_CC.PEGASUS_OS_VMS",
+                            "Routine mail$send_add_address failed (cc)."));
+    }
+  }
+
+  PEG_METHOD_EXIT();
+  return (mailAddrStr);
+}
+
+#endif
+
 void EmailListenerDestination::_writeStrToFile(
     const String & mailHdrStr,
     FILE * filePtr)
@@ -423,6 +569,41 @@ void EmailListenerDestination::_sendMsg(
         throw PEGASUS_CIM_EXCEPTION (CIM_ERR_FAILED, exceptionStr);
     }
 
+#ifdef PEGASUS_OS_VMS
+  //
+  // Send the mail message
+  //
+  status = mail$send_message(&send_context, nulllist, nulllist);
+  if (status != SS$_NORMAL)
+  {
+    PEG_TRACE_STRING(TRC_IND_HANDLER, Tracer::LEVEL4,
+                     "Routine mail$send_message failed.");
+    PEG_METHOD_EXIT();
+
+    throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
+                   MessageLoaderParms("Handler.EmailListenerDestination."
+       "EmailListenerDestination.ROUTINE_MAIL_SEND_MESSAGE_FAILED.PEGASUS_OS_VMS",
+                            "Routine mail$send_message failed."));
+  }
+
+  //
+  // End mail send process
+  //
+  status = mail$send_end(&send_context, nulllist, nulllist);
+  if (status != SS$_NORMAL)
+  {
+    PEG_TRACE_STRING(TRC_IND_HANDLER, Tracer::LEVEL4,
+                     "Routine mail$send_end failed.");
+    PEG_METHOD_EXIT();
+
+    throw PEGASUS_CIM_EXCEPTION_L(CIM_ERR_FAILED,
+                   MessageLoaderParms("Handler.EmailListenerDestination."
+       "EmailListenerDestination.ROUTINE_MAIL_SEND_END_FAILED.PEGASUS_OS_VMS",
+                            "Routine mail$send_end failed."));
+  }
+
+#else
+
     sprintf(sendmailCmd, "%s %s %s", SENDMAIL_CMD, 
            SENDMAIL_CMD_OPTS, mailFile);
 
@@ -476,6 +657,8 @@ void EmailListenerDestination::_sendMsg(
 
         throw PEGASUS_CIM_EXCEPTION (CIM_ERR_FAILED, exceptionStr);
     }
+#endif
+
     PEG_METHOD_EXIT();
 }
 
@@ -489,6 +672,9 @@ void EmailListenerDestination::_openFile(
     String exceptionStr;
 
     *filePtr = fopen(tmpnam(mailFile), "w");
+#ifdef PEGASUS_OS_VMS
+  strcpy(mailFileVms, mailFile);
+#endif
     if (*filePtr == NULL)
     {
         Tracer::trace(TRC_IND_HANDLER, Tracer::LEVEL4,
index 71fad3528a673d97fcf3ca8fee3ab52eb7ffa598..17e83ca8d8c3eb8ea600439970e863a01b189e75 100644 (file)
@@ -49,6 +49,55 @@ PEGASUS_USING_STD;
 # define TEMP_NAME_LEN L_tmpnam
 # include <unistd.h>
 #endif
+#if defined(PEGASUS_OS_VMS)
+# define MAX_SENDMAIL_CMD_LEN 100
+# define TEMP_NAME_LEN L_tmpnam
+
+char
+  mailFileVms[TEMP_NAME_LEN];
+
+long
+  file_len = 0,
+  subject_line_len = 0,
+  to_user_len = 0;
+
+int
+  send_context = 0,
+  status = SS$_NORMAL;
+
+typedef struct itmlst
+{
+  short buffer_length;
+  short item_code;
+  long buffer_address;
+  long return_length_address;
+}
+ITMLST;
+
+ITMLST
+  nulllist[] = 
+    { {0, 0, 0, 0} 
+    },
+  address_itmlst[] = 
+    { {0, MAIL$_SEND_USERNAME, 0, 0},
+      {0, MAIL$_SEND_USERNAME_TYPE, MAIL$_TO, 0},
+      {0, 0, 0, 0}
+    },
+  address_cc_itmlst[] =
+    { {0, MAIL$_SEND_USERNAME, 0, 0},
+      {0, MAIL$_SEND_USERNAME_TYPE, MAIL$_CC, 0},
+      {0, 0, 0, 0}
+    },
+  bodypart_itmlst[] =
+    { {0, MAIL$_SEND_FILENAME, 0, 0},
+      {0, 0, 0, 0}
+    },
+  attribute_itmlst[] =
+    { {0, MAIL$_SEND_SUBJECT, 0, 0},
+      {0, 0, 0, 0}
+    };
+
+#endif
 
 class PEGASUS_HANDLER_LINKAGE EmailListenerDestination: public CIMHandler
 {
@@ -121,6 +170,18 @@ private:
     String _buildMailAddrStr(
        const Array<String> & mailAddr);
 
+#ifdef PEGASUS_OS_VMS
+    /**
+        Build the mail cc address string from address array 
+
+        @param  mailAddr       the array of the mail cc addresses 
+
+        @return the string of the mail addresses 
+    */
+    String _buildMailAddrCcStr(
+       const Array<String> & mailAddr);
+
+#endif
     /**
         Write the mail header string to file