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// Export() sets an external environmental variable to the desired value
51// using dynamically allocated fixed storage.
52//
53static int Export(const char *Var, const char *Val);
54static int Export(const char *Var, int Val);
55
56// Import() gets a variable from the extended environment and stores
57// it in this object
58static bool Import( const char *var, char *&val );
59static bool Import( const char *var, long &val );
60
61// Get() returns the address of the string associated with the variable
62// name. If no association exists, zero is returned.
63//
64 char *Get(const char *varname) {return env_Hash.Find(varname);}
65
66// GetInt() returns a long integer value. If the variable varname is not found
67// in the hash table, return -999999999.
68//
69 long GetInt(const char *varname);
70
71// GetPtr() returns a pointer as a (void *) value. If the varname is not found
72// a nil pointer is returned (i.e. 0).
73//
74 void *GetPtr(const char *varname);
75
76// Put() associates a string value with the a variable name. If one already
77// exists, it is replaced. The passed value and variable strings are
78// duplicated (value here, variable by env_Hash).
79//
80 void Put(const char *varname, const char *value)
81 {env_Hash.Rep((char *)varname, strdup(value), 0, Hash_dofree);}
82
83// PutInt() puts a long integer value into the hash. Internally, the value gets
84// converted into a char*
85//
86 void PutInt(const char *varname, long value);
87
88// PutPtr() puts a pointer value into the hash. The pointer is accepted as a
89// (void *) value. By convention, the variable name should end with
90// an asterisk and typically corresponds to it's class name.
91//
92 void PutPtr(const char *varname, void *value);
93
94// Delimit() search for the first occurrence of comma (',') in value and
95// replaces it with a null byte. It then returns the address of the
96// remaining string. If no comma was found, it returns zero.
97//
98 char *Delimit(char *value);
99
100// secEnv() returns the security environment; which may be a null pointer.
101//
102inline const XrdSecEntity *secEnv() const {return secEntity;}
103
104// Use the constructor to define the initial variable settings. The passed
105// string is duplicated and the copy can be retrieved using Env().
106//
107 XrdOucEnv(const char *vardata=0, int vardlen=0,
108 const XrdSecEntity *secent=0);
109
110 ~XrdOucEnv() {if (global_env) free((void *)global_env);}
111
112private:
113
118};
119#endif
@ Hash_dofree
Definition XrdOucHash.hh:56
Definition XrdOucEnv.hh:42
void PutInt(const char *varname, long value)
char * Env(int &envlen)
Definition XrdOucEnv.hh:48
long GetInt(const char *varname)
static int Export(const char *Var, const char *Val)
XrdOucHash< char > env_Hash
Definition XrdOucEnv.hh:114
static int Export(const char *Var, int Val)
const XrdSecEntity * secEnv() const
Definition XrdOucEnv.hh:102
char * Get(const char *varname)
Definition XrdOucEnv.hh:64
void * GetPtr(const char *varname)
const XrdSecEntity * secEntity
Definition XrdOucEnv.hh:115
~XrdOucEnv()
Definition XrdOucEnv.hh:110
char * global_env
Definition XrdOucEnv.hh:116
void PutPtr(const char *varname, void *value)
int global_len
Definition XrdOucEnv.hh:117
void Put(const char *varname, const char *value)
Definition XrdOucEnv.hh:80
static bool Import(const char *var, char *&val)
char * Delimit(char *value)
static bool Import(const char *var, long &val)
XrdOucEnv(const char *vardata=0, int vardlen=0, const XrdSecEntity *secent=0)
Definition XrdOucHash.hh:128
T * Rep(const char *KeyVal, T *KeyData, const int LifeTime=0, XrdOucHash_Options opt=Hash_default)
Definition XrdOucHash.hh:166
T * Find(const char *KeyVal, time_t *KeyTime=0)
Definition XrdSecEntity.hh:65