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__*/
37
#include "sge_string.h"
38
#include "sge_uidgid.h"
41
#include "cull_list.h"
43
#include "sge_answer.h"
46
#include "msg_common.h"
47
#include "msg_sgeobjlib.h"
49
#define STR_LAYER BASIS_LAYER
51
/****** sgeobj/str/str_list_append_to_dstring() *******************************
53
* str_list_append_to_dstring() -- append strings to dstring
57
* str_list_append_to_dstring(const lList *this_list,
59
* const char delimiter)
62
* Append the strings contained in "this_list" to the dstring
63
* "string". Separate them by the character contained in
65
* If "this_list" is NULL or conaines no elements, "NONE" will
66
* be added to the dstring.
69
* const lList *this_list - ST_Type list
70
* dstring *string - dynamic string
71
* const char delimiter - delimiter
74
* const char * - pointer to the given "string"-buffer
77
* sgeobj/str/str_list_parse_from_string()
78
*******************************************************************************/
80
str_list_append_to_dstring(const lList *this_list, dstring *string,
83
const char *ret = NULL;
85
DENTER(STR_LAYER, "str_list_append_to_dstring");
87
lListElem *elem = NULL;
90
for_each(elem, this_list) {
91
sge_dstring_append(string, lGetString(elem, ST_name));
92
if (lNext(elem) != NULL) {
93
sge_dstring_sprintf_append(string, "%c", delimiter);
98
sge_dstring_append(string, "NONE");
100
ret = sge_dstring_get_string(string);
105
/****** sgeobj/str/str_list_parse_from_string() *******************************
107
* str_list_parse_from_string() -- Parse a list of strings
111
* str_list_parse_from_string(lList **this_list,
112
* const char *string,
113
* const char *delimitor)
116
* Parse a list of strings from "string". The strings have to be
117
* separated by a token contained in "delimitor". for each string
118
* an element of type ST_Type will be added to "this_list".
121
* lList **this_list - ST_Type list
122
* const char *string - string to be parsed
123
* const char *delimitor - delimitor string
131
* sgeobj/str/str_list_append_to_dstring()
134
* MT-NOTE: str_list_parse_from_string() is MT safe
135
*******************************************************************************/
137
str_list_parse_from_string(lList **this_list,
138
const char *string, const char *delimitor)
142
DENTER(STR_LAYER, "str_list_parse_from_dstring");
143
if (this_list != NULL && string != NULL && delimitor != NULL) {
144
struct saved_vars_s *context = NULL;
147
token = sge_strtok_r(string, delimitor, &context);
148
while (token != NULL) {
149
lAddElemStr(this_list, ST_name, token, ST_Type);
150
token = sge_strtok_r(NULL, delimitor, &context);
152
sge_free_saved_vars(context);
157
/****** sgeobj/str/str_list_is_valid() ****************************************
159
* str_list_is_valid() -- Are all strings valid
163
* str_list_is_valid(const lList *this_list, lList **answer_list)
166
* Does each element in "this_list" contain a valid string (!= NULL).
169
* const lList *this_list - ST_Type list
170
* lList **answer_list - AN_Type list
174
* true - all strings are != NULL
175
* false - at least one entry is NULL
176
*******************************************************************************/
178
str_list_is_valid(const lList *this_list, lList **answer_list)
182
DENTER(STR_LAYER, "str_list_is_valid");
183
if (this_list != NULL) {
186
for_each(elem, this_list) {
187
if (lGetString(elem, ST_name) == NULL) {
188
answer_list_add(answer_list, MSG_STR_INVALIDSTR,
189
STATUS_ENOKEY, ANSWER_QUALITY_ERROR);
198
str_list_transform_user_list(lList **this_list, lList **answer_list, const char *username)
202
DENTER(STR_LAYER, "str_list_transform_user_list");
203
if (this_list != NULL && *this_list != NULL) {
206
for_each(elem, *this_list) {
207
const char *string = lGetString(elem, ST_name);
209
if (string != NULL) {
211
* '$user' will be replaced by the current unix username
212
* '*' empty the remove the list
214
if (strcasecmp(string, "$user") == 0) {
215
lSetString(elem, ST_name, username);
216
} else if (strcmp(string, "*") == 0) {
217
lFreeList(this_list);
223
lAddElemStr(this_list, ST_name, username, ST_Type);