/[pdpsoft]/trunk/grid-mw-security/cgul/environ/environ.h
ViewVC logotype

Contents of /trunk/grid-mw-security/cgul/environ/environ.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2087 - (show annotations) (download) (as text)
Thu Nov 11 15:33:33 2010 UTC (11 years, 8 months ago) by msalle
File MIME type: text/x-csrc
File size: 6460 byte(s)
Bringing environ back in sync with glexec: 
- new function int cgul_unsetenv_dst() needed to remove an entry from an 'saved'
  environment.

1 /**
2 * Copyright (c) Members of the EGEE Collaboration. 2010.
3 * See http://www.eu-egee.org/partners/ for details on the copyright
4 * holders.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 * Authors: Oscar Koeroo, Mischa Sall\'e, Aram Verstegen
19 * NIKHEF Amsterdam, the Netherlands
20 * <grid-mw-security@nikhef.nl>
21 */
22
23 #ifndef _ENVIRON_H_
24 #define _ENVIRON_H_
25
26 #include <unistd.h>
27 extern char **environ;
28
29 /* Define environment list type: note that we CANNOT initialize it as
30 * env_t myenv={"..","..",NULL} etc. */
31 typedef char **env_t;
32
33 #ifndef MAXENVVARNAMELEN
34 #define MAXENVVARNAMELEN 16384
35 #endif
36
37 /**
38 * returns number of entries in NULL terminated string array, such as argv and
39 * environ(7). In case list is NULL it also returns 0.
40 */
41 size_t cgul_strarrlen(const char **list);
42
43 /**
44 * returns the number of entries in list which start with pattern. If pattern of
45 * list is NULL it also returns 0.
46 */
47 size_t cgul_patternentries(env_t list, const char *pattern);
48
49 /**
50 * Returns the length of the name part of the var=value pair or -1 when there is
51 * no '=' sign.
52 */
53 int cgul_getvarnamelen(const char *varname);
54
55 /**
56 * Finds name for given var=value pair in namevalue. varname is a buffer
57 * which will contain the result and has space for maxvarnamelen chars.
58 * Returns integer, negative on error, -1 on no '=' sign, -2 name too long;
59 * 0 success
60 */
61 int cgul_getvarname(char *varname,const int maxvarnamelen,
62 const char *namevalue);
63
64 /**
65 * Finds index in **src matching variable name, in case of no match (including
66 * env==NULL) returns -1
67 */
68 int cgul_getvarindex(const env_t src, const char *varname);
69
70 /**
71 * Finds the value of varname in src list. Returns NULL when no match, incl.
72 * NULL valued src or varname.
73 */
74 char *cgul_getenv_src(const env_t src, char *varname);
75
76 /**
77 * As unsetenv(3) but using var=value pair, specified in namevalue. The maximum
78 * var length is MAXVARNAMELEN. See also putenv(3).
79 * Returns integer, 0 on success, negative on error.
80 */
81 int cgul_unsetenvpair(const char *namevalue);
82
83 /**
84 * Clears the entire environment
85 * Returns integer, -1 on error, 0 on success
86 */
87 int cgul_clear_env(void);
88
89 /*
90 * Clears the environment of all variables starting with pattern, case
91 * INsensitive.
92 * Returns number of cleaned entries, -1 on error.
93 */
94 int cgul_clear_env_pattern(const char *pattern);
95
96 /**
97 * Creates a duplicate of src. In case *dst!=NULL it will be used and should be
98 * big enough. Otherwise space is malloc-ed. dst is only updated upon success.
99 * Returns -1 upon error, 0 on success.
100 */
101 int cgul_copy_env(env_t *dst,const env_t src);
102
103 /**
104 * Same as copy_env() but first unsets all environment variables starting with
105 * MALLOC, case INsensitive. dst is again only updated upon success.
106 * Returns -1 upon error, 0 on success.
107 */
108 int cgul_safe_copy_env(env_t *dst,const env_t src);
109
110 /**
111 * Creates a list of the var=value pairs from src which have varname in list.
112 * If it fails NULL is returned. This can also be done using add_src_list()
113 * using dst==NULL, but this is more efficiently coded. All new entries are
114 * strdup-ed from those in src.
115 */
116 env_t cgul_copy_src_list(const env_t src,const char *list[]);
117
118 /**
119 * Adds to dst the var=value pairs from src which have varname in list.
120 * All entries will be strdup-ed from those in src.
121 * If *dst is NULL, it will be malloc-ed, otherwise it will be realloc-ed.
122 * Upon success returns 0. On error -1 is returned. If part of the environment
123 * has been successfully copied, they will stay part of the environment.
124 * See also copy_src_list() which is more efficient when dst is NULL !
125 */
126 int cgul_add_src_list(env_t *dst,const env_t src,const char **list);
127
128 /**
129 * Adds to dst the var=value pairs from src which start with pattern.
130 * All entries will be strdup-ed from those in src.
131 * If *dst is NULL, it will be malloc-ed, otherwise it will be realloc-ed.
132 * Upon success returns the number of matches. On error -1 is returned, and dst
133 * of the environment has been successfully copied, they will stay part of the
134 * environment.
135 * An empty pattern (either "" or NULL) or src is NOT considered error.
136 * See also cgul_add_src_list()
137 */
138 int cgul_add_src_pattern(env_t *dst,const env_t src,const char *pattern);
139
140 /**
141 * adds var=value pair to dst. If the variable already exists, it's entry is
142 * replaced. Otherwise *dst is realloc-ed and a new entry is added, the
143 * resulting array is returned.
144 * Upon success returns 0. In case of error -1 is returned and dst remains
145 * unchanged. namevalue is strdup-ed into dst and hence can be freed by the
146 * caller (unlike putenv(3p) )
147 */
148 int cgul_add_namevalue(env_t *dst,const char *namevalue);
149
150 /**
151 * adds name=value pair to dst, as in setenv() with a 'external environment' .
152 * If the variable already exists, it's entry is replaced. Otherwise *dst is
153 * realloc-ed and a new entry is added.
154 * Upon success returns 0. In case of error -1 is returned and dst remains
155 * unchanged. name and value can be freed by the caller (unlike putenv(3p) )
156 */
157 int cgul_setenv_dst(env_t *dst,const char *name, const char *value);
158
159 /**
160 * Removes a variable from dst as in unsetenv() with a 'external environment'.
161 */
162 int cgul_unsetenv_dst(env_t *dst,const char *name);
163
164 /**
165 * Adds to the current environment the var=value pairs from src which have
166 * varname in list. Returns number of entries added or -1 on error.
167 * NOTE: we do a strdup before the actual putenv, so even though putenv doesn't
168 * reserve new memory, we stil can free src !
169 */
170 int cgul_putenv_src_list(env_t src,const char **list);
171
172 /**
173 * Adds to the current environment the var=value pairs from src which start with
174 * pattern. Returns number of entries added or -1 on error.
175 * NOTE: we do a strdup before the actual putenv, so even though putenv doesn't
176 * reserve new memory, we stil can free src !
177 */
178 int cgul_putenv_src_pattern(env_t src,const char *pattern);
179
180 #endif

grid.support@nikhef.nl
ViewVC Help
Powered by ViewVC 1.1.28