1
/*___INFO__MARK_BEGIN__*/
2
/*************************************************************************
4
* The Contents of this file are made available subject to the terms of
5
* the Sun Industry Standards Source License Version 1.2
7
* Sun Microsystems Inc., March, 2001
10
* Sun Industry Standards Source License Version 1.2
11
* =================================================
12
* The contents of this file are subject to the Sun Industry Standards
13
* Source License Version 1.2 (the "License"); You may not use this file
14
* except in compliance with the License. You may obtain a copy of the
15
* License at http://gridengine.sunsource.net/Gridengine_SISSL_license.html
17
* Software provided under this License is provided on an "AS IS" basis,
18
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
19
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
20
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
21
* See the License for the specific provisions governing your rights and
22
* obligations concerning the Software.
24
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
26
* Copyright: 2001 by Sun Microsystems, Inc.
28
* All Rights Reserved.
30
************************************************************************/
31
/*___INFO__MARK_END__*/
36
#include "sge_string.h"
37
#include "sge_stdlib.h"
39
#include "sge_mailrec.h"
40
#include "cull_parse_util.h"
44
#include "msg_common.h"
46
/****** sgeobj/mailrec/mailrec_parse() ****************************************
48
* mailrec_parse() -- Parse a list of mail recipients
51
* int mailrec_parse(lList **lpp, const char *mail_str)
54
* Parse a list of mail recipients.
55
* user[@host][,user[@host],...]
58
* lList **lpp - MR_Type list
59
* const char *mail_str - stringlist of mail recipients
67
* sgeobj/mailrec/mailrec_unparse()
70
* MT-NOTE: mailrec_parse() is MT safe
71
*******************************************************************************/
72
int mailrec_parse(lList **lpp, const char *mail_str)
80
struct saved_vars_s *context;
82
DENTER(TOP_LAYER, "mailrec_parse");
89
mail = sge_strdup(NULL, mail_str);
95
str_str = string_list(mail, ",", NULL);
96
if (!str_str || !*str_str) {
104
*lpp = lCreateList("mail_list", MR_Type);
113
for (pstr = str_str; *pstr; pstr++) {
115
user = sge_strtok_r(*pstr, "@", &context);
116
host = sge_strtok_r(NULL, "@", &context);
117
if ((tmp=lGetElemStr(*lpp, MR_user, user))) {
118
if (!sge_strnullcmp(host, lGetHost(tmp, MR_host))) {
119
/* got this mail adress twice */
120
sge_free_saved_vars(context);
125
/* got a new adress - add it */
126
ep = lCreateElem(MR_Type);
127
lSetString(ep, MR_user, user);
129
lSetHost(ep, MR_host, host);
130
lAppendElem(*lpp, ep);
132
sge_free_saved_vars(context);
141
/****** sgeobj/mailrec/mailrec_unparse() **************************************
143
* mailrec_unparse() -- Build a string of mail reipients
146
* int mailrec_unparse(lList *head, char *mail_str,
147
* unsigned int mail_str_len)
150
* Build a string of mail reipients ("user@host,user,...")
153
* lList *head - MR_Type list
154
* char *mail_str - buffer to be filled
155
* unsigned int mail_str_len - size of buffer
163
* sgeobj/mailrec/mailrec_parse()
164
*******************************************************************************/
165
int mailrec_unparse(lList *head, char *mail_str, unsigned int mail_str_len)
168
int comma_needed = 0; /* whether we need to insert a comma */
169
char tmpstr[1000]; /* need 1000 for brain damaged mail addresse(e)s */
175
strcpy(mail_str, MSG_NONE);
181
for_each(elem,head) {
182
if (!(u = lGetString(elem, MR_user)))
185
if (!(h = lGetHost(elem, MR_host)))
186
sprintf(tmpstr, "%s", u);
188
sprintf(tmpstr, "%s@%s", u, h);
190
if (strlen(tmpstr)+len+1+comma_needed > mail_str_len)
191
return 1; /* forgot the rest */
194
strcat(mail_str, ",");
196
comma_needed = 1; /* need comma after first mailaddress */
198
strcat(mail_str, tmpstr);