xrootd
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-AC03-76-SFO0515 with the Department of Energy */
11 /******************************************************************************/
12 
13 #include <stdlib.h>
14 #ifndef WIN32
15 #include <strings.h>
16 #endif
17 #include "XrdOuc/XrdOucHash.hh"
18 
19 class XrdSecEntity;
20 
21 class XrdOucEnv
22 {
23 public:
24 
25 // Env() returns the full environment string and length passed to the
26 // constructor.
27 //
28 inline char *Env(int &envlen) {envlen = global_len; return global_env;}
29 
30 // Export() sets an external environmental variable to the desired value
31 // using dynamically allocated fixed storage.
32 //
33 static int Export(const char *Var, const char *Val);
34 static int Export(const char *Var, int Val);
35 
36 // Import() gets a variable from the extended environment and stores
37 // it in this object
38 static bool Import( const char *var, char *&val );
39 static bool Import( const char *var, long &val );
40 
41 // Get() returns the address of the string associated with the variable
42 // name. If no association exists, zero is returned.
43 //
44  char *Get(const char *varname) {return env_Hash.Find(varname);}
45 
46 // GetInt() returns a long integer value. If the variable varname is not found
47 // in the hash table, return -999999999.
48 //
49  long GetInt(const char *varname);
50 
51 // GetPtr() returns a pointer as a (void *) value. If the varname is not found
52 // a nil pointer is returned (i.e. 0).
53 //
54  void *GetPtr(const char *varname);
55 
56 // Put() associates a string value with the a variable name. If one already
57 // exists, it is replaced. The passed value and variable strings are
58 // duplicated (value here, variable by env_Hash).
59 //
60  void Put(const char *varname, const char *value)
61  {env_Hash.Rep((char *)varname, strdup(value), 0, Hash_dofree);}
62 
63 // PutInt() puts a long integer value into the hash. Internally, the value gets
64 // converted into a char*
65 //
66  void PutInt(const char *varname, long value);
67 
68 // PutPtr() puts a pointer value into the hash. The pointer is accepted as a
69 // (void *) value. By convention, the variable name should end with
70 // an asterisk and typically corresponds to it's class name.
71 //
72  void PutPtr(const char *varname, void *value);
73 
74 // Delimit() search for the first occurrence of comma (',') in value and
75 // replaces it with a null byte. It then returns the address of the
76 // remaining string. If no comma was found, it returns zero.
77 //
78  char *Delimit(char *value);
79 
80 // secEnv() returns the security environment; which may be a null pointer.
81 //
82 inline const XrdSecEntity *secEnv() {return secEntity;}
83 
84 // Use the constructor to define the initial variable settings. The passed
85 // string is duplicated and the copy can be retrieved using Env().
86 //
87  XrdOucEnv(const char *vardata=0, int vardlen=0,
88  const XrdSecEntity *secent=0);
89 
90  ~XrdOucEnv() {if (global_env) free((void *)global_env);}
91 
92 private:
93 
96 char *global_env;
98 };
99 #endif