XRootD
Loading...
Searching...
No Matches
XrdOucEnv.hh
Go to the documentation of this file.
1#ifndef __OUC_ENV__
2#define __OUC_ENV__
3/******************************************************************************/
4/* */
5/* X r d O u c E n v . h h */
6/* */
7/* (c) 2003 by the Board of Trustees of the Leland Stanford, Jr., University */
8/* All Rights Reserved */
9/* Produced by Andrew Hanushevsky for Stanford University under contract */
10/* DE-AC02-76-SFO0515 with the Department of Energy */
11/* */
12/* This file is part of the XRootD software suite. */
13/* */
14/* XRootD is free software: you can redistribute it and/or modify it under */
15/* the terms of the GNU Lesser General Public License as published by the */
16/* Free Software Foundation, either version 3 of the License, or (at your */
17/* option) any later version. */
18/* */
19/* XRootD is distributed in the hope that it will be useful, but WITHOUT */
20/* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
21/* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
22/* License for more details. */
23/* */
24/* You should have received a copy of the GNU Lesser General Public License */
25/* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
26/* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
27/* */
28/* The copyright holder's institutional names and contributor's names may not */
29/* be used to endorse or promote products derived from this software without */
30/* specific prior written permission of the institution or contributor. */
31/******************************************************************************/
32
33#include <cstdlib>
34#ifndef WIN32
35#include <strings.h>
36#endif
37#include "XrdOuc/XrdOucHash.hh"
38
39class XrdSecEntity;
40
42{
43public:
44
45// Env() returns the full environment string and length passed to the
46// constructor.
47//
48inline char *Env(int &envlen) {envlen = global_len; return global_env;}
49
50// EnvTidy() returns the environment string and length with authorization
51// information (ie. authz), if any, removed.
52//
53 char *EnvTidy(int &envlen);
54
55// Export() sets an external environmental variable to the desired value
56// using dynamically allocated fixed storage.
57//
58static int Export(const char *Var, const char *Val);
59static int Export(const char *Var, int Val);
60
61// Import() gets a variable from the extended environment and stores
62// it in this object
63static bool Import( const char *var, char *&val );
64static bool Import( const char *var, long &val );
65
66// Get() returns the address of the string associated with the variable
67// name. If no association exists, zero is returned.
68//
69 char *Get(const char *varname) {return env_Hash.Find(varname);}
70
71// GetInt() returns a long integer value. If the variable varname is not found
72// in the hash table, return -999999999.
73//
74 long GetInt(const char *varname);
75
76// GetPtr() returns a pointer as a (void *) value. If the varname is not found
77// a nil pointer is returned (i.e. 0).
78//
79 void *GetPtr(const char *varname);
80
81// Put() associates a string value with the a variable name. If one already
82// exists, it is replaced. The passed value and variable strings are
83// duplicated (value here, variable by env_Hash).
84//
85 void Put(const char *varname, const char *value)
86 {env_Hash.Rep((char *)varname, strdup(value), 0, Hash_dofree);}
87
88// PutInt() puts a long integer value into the hash. Internally, the value gets
89// converted into a char*
90//
91 void PutInt(const char *varname, long value);
92
93// PutPtr() puts a pointer value into the hash. The pointer is accepted as a
94// (void *) value. By convention, the variable name should end with
95// an asterisk and typically corresponds to it's class name.
96//
97 void PutPtr(const char *varname, void *value);
98
99// Delimit() search for the first occurrence of comma (',') in value and
100// replaces it with a null byte. It then returns the address of the
101// remaining string. If no comma was found, it returns zero.
102//
103 char *Delimit(char *value);
104
105// secEnv() returns the security environment; which may be a null pointer.
106//
107inline const XrdSecEntity *secEnv() const {return secEntity;}
108
109// Use the constructor to define the initial variable settings. The passed
110// string is duplicated and the copy can be retrieved using Env().
111//
112 XrdOucEnv(const char *vardata=0, int vardlen=0,
113 const XrdSecEntity *secent=0);
114
115 ~XrdOucEnv() {if (global_env) free((void *)global_env);}
116
117private:
118void EnvBuildTidy();
119
120XrdOucHash<char> env_Hash;
121const XrdSecEntity *secEntity;
122char *global_env;
123int global_len;
124};
125#endif
@ Hash_dofree
Definition XrdOucHash.hh:56
bool Import
void PutInt(const char *varname, long value)
Definition XrdOucEnv.cc:250
char * Env(int &envlen)
Definition XrdOucEnv.hh:48
long GetInt(const char *varname)
Definition XrdOucEnv.cc:235
char * EnvTidy(int &envlen)
Definition XrdOucEnv.cc:142
const XrdSecEntity * secEnv() const
Definition XrdOucEnv.hh:107
char * Get(const char *varname)
Definition XrdOucEnv.hh:69
static int Export(const char *Var, const char *Val)
Definition XrdOucEnv.cc:170
void * GetPtr(const char *varname)
Definition XrdOucEnv.cc:263
void PutPtr(const char *varname, void *value)
Definition XrdOucEnv.cc:298
void Put(const char *varname, const char *value)
Definition XrdOucEnv.hh:85
char * Delimit(char *value)
Definition XrdOucEnv.cc:90
XrdOucEnv(const char *vardata=0, int vardlen=0, const XrdSecEntity *secent=0)
Definition XrdOucEnv.cc:42