1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
|
/* -*- C -*-
*
* Copyright (c) 2004-2008 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation. All rights reserved.
* Copyright (c) 2004-2005 The University of Tennessee and The University
* of Tennessee Research Foundation. All rights
* reserved.
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
* University of Stuttgart. All rights reserved.
* Copyright (c) 2004-2005 The Regents of the University of California.
* All rights reserved.
* Copyright (c) 2009 Cisco Systems, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
*
* $HEADER$
*/
/*
* Simple smtp notifier (using libesmtp)
*/
#include "orte_config.h"
#include "opal/mca/base/mca_base_param.h"
#include "orte/constants.h"
#include "orte/util/show_help.h"
#include "notifier_smtp.h"
static int smtp_open(void);
static int smtp_component_query(mca_base_module_t **module, int *priority);
static int smtp_close(void);
static int smtp_register(void);
/*
* Struct of function pointers that need to be initialized
*/
orte_notifier_smtp_component_t mca_notifier_smtp_component = {
{
{
ORTE_NOTIFIER_BASE_VERSION_1_0_0,
"smtp",
ORTE_MAJOR_VERSION,
ORTE_MINOR_VERSION,
ORTE_RELEASE_VERSION,
smtp_open,
smtp_close,
smtp_component_query,
smtp_register,
},
{
/* The component is checkpoint ready */
MCA_BASE_METADATA_PARAM_CHECKPOINT
}
},
/* SMTP server and port */
"localhost",
25,
/* To, from, subject */
NULL,
NULL,
"Open MPI Notifier",
NULL,
"Open MPI notifier",
/* Mail body prefix, suffix */
"The Open MPI SMTP notifier wishes to inform you of the following message:\n\n",
"\n\nSincerely,\nOscar the Open MPI Owl",
/* Struct hostent */
NULL,
/* Priority */
10,
};
static int smtp_register(void)
{
char version[256];
/* Server stuff */
mca_base_param_reg_string(&mca_notifier_smtp_component.super.base_version,
"server",
"SMTP server name or IP address",
false, false,
mca_notifier_smtp_component.server,
&mca_notifier_smtp_component.server);
mca_base_param_reg_int(&mca_notifier_smtp_component.super.base_version,
"port",
"SMTP server port",
false, false,
mca_notifier_smtp_component.port,
&mca_notifier_smtp_component.port);
/* Email stuff */
mca_base_param_reg_string(&mca_notifier_smtp_component.super.base_version,
"to",
"Comma-delimited list of email addresses to send to",
false, false,
mca_notifier_smtp_component.to,
&mca_notifier_smtp_component.to);
mca_base_param_reg_string(&mca_notifier_smtp_component.super.base_version,
"from_addr",
"Email address that messages will be from",
false, false,
mca_notifier_smtp_component.from_addr,
&mca_notifier_smtp_component.from_addr);
mca_base_param_reg_string(&mca_notifier_smtp_component.super.base_version,
"from_name",
"Email name that messages will be from",
false, false,
mca_notifier_smtp_component.from_name,
&mca_notifier_smtp_component.from_name);
mca_base_param_reg_string(&mca_notifier_smtp_component.super.base_version,
"subject",
"Email subject",
false, false,
mca_notifier_smtp_component.subject,
&mca_notifier_smtp_component.subject);
/* Mail body prefix and suffix */
mca_base_param_reg_string(&mca_notifier_smtp_component.super.base_version,
"body_prefix",
"Text to put at the beginning of the mail message",
false, false,
mca_notifier_smtp_component.body_prefix,
&mca_notifier_smtp_component.body_prefix);
mca_base_param_reg_string(&mca_notifier_smtp_component.super.base_version,
"body_suffix",
"Text to put at the beginning of the mail message",
false, false,
mca_notifier_smtp_component.body_suffix,
&mca_notifier_smtp_component.body_suffix);
/* Priority */
mca_base_param_reg_int(&mca_notifier_smtp_component.super.base_version,
"priority",
"Priority of this component",
false, false,
mca_notifier_smtp_component.priority,
&mca_notifier_smtp_component.priority);
/* Libesmtp version */
smtp_version(version, sizeof(version), 0);
version[sizeof(version) - 1] = '\0';
mca_base_param_reg_string(&mca_notifier_smtp_component.super.base_version,
"libesmtp_version",
"Version of libesmtp that this component is linked against",
false, true, version, NULL);
return ORTE_SUCCESS;
}
static int smtp_open(void)
{
/* Nothing to do */
return ORTE_SUCCESS;
}
static int smtp_close(void)
{
if (NULL != mca_notifier_smtp_component.server) {
free(mca_notifier_smtp_component.server);
}
if (NULL != mca_notifier_smtp_component.to) {
free(mca_notifier_smtp_component.to);
}
if (NULL != mca_notifier_smtp_component.from_name) {
free(mca_notifier_smtp_component.from_name);
}
if (NULL != mca_notifier_smtp_component.from_addr) {
free(mca_notifier_smtp_component.from_addr);
}
if (NULL != mca_notifier_smtp_component.subject) {
free(mca_notifier_smtp_component.subject);
}
if (NULL != mca_notifier_smtp_component.body_prefix) {
free(mca_notifier_smtp_component.body_prefix);
}
if (NULL != mca_notifier_smtp_component.body_suffix) {
free(mca_notifier_smtp_component.body_suffix);
}
return ORTE_SUCCESS;
}
static int smtp_component_query(mca_base_module_t **module,
int *priority)
{
*priority = 0;
*module = NULL;
/* If there's no to or from, there's no love */
if (NULL == mca_notifier_smtp_component.to ||
'\0' == mca_notifier_smtp_component.to[0] ||
NULL == mca_notifier_smtp_component.from_addr ||
'\0' == mca_notifier_smtp_component.from_addr[0]) {
orte_show_help("help-orte-notifier-smtp.txt",
"to/from not specified", true);
return ORTE_ERR_NOT_FOUND;
}
/* Sanity checks */
if (NULL == mca_notifier_smtp_component.server ||
'\0' == mca_notifier_smtp_component.server[0]) {
orte_show_help("help-orte-notifier-smtp.txt",
"server not specified", true);
return ORTE_ERR_NOT_FOUND;
}
/* Since we have to open a socket later, try to resolve the IP
address of the server now. Save the result, or abort if we
can't resolve it. */
mca_notifier_smtp_component.server_hostent =
gethostbyname(mca_notifier_smtp_component.server);
if (NULL == mca_notifier_smtp_component.server_hostent) {
orte_show_help("help-orte-notifier-smtp.txt",
"unable to resolve server",
true, mca_notifier_smtp_component.server);
return ORTE_ERR_NOT_FOUND;
}
*priority = 10;
*module = (mca_base_module_t *)&orte_notifier_smtp_module;
return ORTE_SUCCESS;
}
|