version 1.6.2.1, 2006/10/27 18:27:18
|
version 1.7, 2006/08/15 17:24:21
|
|
|
#include <Pegasus/Common/IndicationFormatter.h> | #include <Pegasus/Common/IndicationFormatter.h> |
#include <Pegasus/IndicationService/IndicationConstants.h> | #include <Pegasus/IndicationService/IndicationConstants.h> |
| |
#if defined(PEGASUS_OS_VMS) |
#if !defined(PEGASUS_OS_HPUX) && !defined(PEGASUS_OS_LINUX) |
#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" | # error "Unsupported Platform" |
#endif | #endif |
| |
|
|
PEG_METHOD_ENTER (TRC_IND_HANDLER, | PEG_METHOD_ENTER (TRC_IND_HANDLER, |
"EmailListenerDestination::_sendViaEmail"); | "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; | String exceptionStr; |
FILE * mailFilePtr; | FILE * mailFilePtr; |
FILE * filePtr; | FILE * filePtr; |
char mailFile[TEMP_NAME_LEN]; | char mailFile[TEMP_NAME_LEN]; |
| |
#ifndef PEGASUS_OS_VMS |
|
// Check for proper execute permissions for sendmail | // Check for proper execute permissions for sendmail |
if (access(SENDMAIL_CMD, X_OK) < 0) | if (access(SENDMAIL_CMD, X_OK) < 0) |
{ | { |
|
|
| |
return; | return; |
} | } |
#endif |
|
| |
// open a temporary file to hold the indication mail message | // open a temporary file to hold the indication mail message |
_openFile(&filePtr, mailFile); | _openFile(&filePtr, mailFile); |
|
|
| |
try | 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 | // send the message |
_sendMsg(mailFile); | _sendMsg(mailFile); |
} | } |
|
|
"Do not have an e-mail address.")); | "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; | String mailHdrStr = String::EMPTY; |
| |
// Write the mailToStr to file | // Write the mailToStr to file |
|
|
mailSubjectStr.append("Subject: "); | mailSubjectStr.append("Subject: "); |
mailSubjectStr.append(mailSubject); | mailSubjectStr.append(mailSubject); |
_writeStrToFile(mailSubjectStr, filePtr); | _writeStrToFile(mailSubjectStr, filePtr); |
#endif |
|
| |
PEG_METHOD_EXIT(); | PEG_METHOD_EXIT(); |
} | } |
|
|
| |
for (Uint32 i=0; i < mailAddrSize; i++) | 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]); | mailAddrStr.append(mailAddr[i]); |
| |
if (i < (mailAddrSize - 1)) | if (i < (mailAddrSize - 1)) |
{ | { |
mailAddrStr.append(","); | 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(); | PEG_METHOD_EXIT(); |
return (mailAddrStr); | return (mailAddrStr); |
} | } |
| |
#endif |
|
|
|
void EmailListenerDestination::_writeStrToFile( | void EmailListenerDestination::_writeStrToFile( |
const String & mailHdrStr, | const String & mailHdrStr, |
FILE * filePtr) | FILE * filePtr) |
|
|
throw PEGASUS_CIM_EXCEPTION (CIM_ERR_FAILED, exceptionStr); | 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, | sprintf(sendmailCmd, "%s %s %s", SENDMAIL_CMD, |
SENDMAIL_CMD_OPTS, mailFile); | SENDMAIL_CMD_OPTS, mailFile); |
| |
|
|
| |
throw PEGASUS_CIM_EXCEPTION (CIM_ERR_FAILED, exceptionStr); | throw PEGASUS_CIM_EXCEPTION (CIM_ERR_FAILED, exceptionStr); |
} | } |
#endif |
|
|
|
PEG_METHOD_EXIT(); | PEG_METHOD_EXIT(); |
} | } |
| |
|
|
String exceptionStr; | String exceptionStr; |
| |
*filePtr = fopen(tmpnam(mailFile), "w"); | *filePtr = fopen(tmpnam(mailFile), "w"); |
#ifdef PEGASUS_OS_VMS |
|
strcpy(mailFileVms, mailFile); |
|
#endif |
|
if (*filePtr == NULL) | if (*filePtr == NULL) |
{ | { |
Tracer::trace(TRC_IND_HANDLER, Tracer::LEVEL4, | Tracer::trace(TRC_IND_HANDLER, Tracer::LEVEL4, |
|
|
PEG_METHOD_EXIT(); | PEG_METHOD_EXIT(); |
} | } |
| |
// This is the dynamic entry point into this dynamic module. The name of |
PEGASUS_NAMESPACE_END |
// this handler is "EmailListenerDestination" which is appended to "PegasusCreateHandler_" |
|
// to form a symbol name. This function is called by the HandlerTable |
|
// to load this handler. |
|
| |
extern "C" PEGASUS_EXPORT CIMHandler* |
PEGASUS_USING_PEGASUS; |
PegasusCreateHandler_EmailListenerDestination() { |
|
|
// This is the entry point into this dynamic module. |
|
|
|
extern "C" PEGASUS_EXPORT CIMHandler* PegasusCreateHandler( |
|
const String& handlerName) |
|
{ |
|
if (handlerName == "EmailListenerDestination") |
|
{ |
return new EmailListenerDestination; | return new EmailListenerDestination; |
} | } |
| |
PEGASUS_NAMESPACE_END |
return 0; |
|
} |