xrootd
XrdOucEnv.hh
Go to the documentation of this file.
00001 #ifndef __OUC_ENV__
00002 #define __OUC_ENV__
00003 /******************************************************************************/
00004 /*                                                                            */
00005 /*                          X r d O u c E n v . h h                           */
00006 /*                                                                            */
00007 /* (c) 2003 by the Board of Trustees of the Leland Stanford, Jr., University  */
00008 /*                            All Rights Reserved                             */
00009 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
00010 /*              DE-AC03-76-SFO0515 with the Department of Energy              */
00011 /******************************************************************************/
00012 
00013 #include <stdlib.h>
00014 #ifndef WIN32
00015 #include <strings.h>
00016 #endif
00017 #include "XrdOuc/XrdOucHash.hh"
00018 
00019 class XrdSecEntity;
00020 
00021 class XrdOucEnv
00022 {
00023 public:
00024 
00025 // Env() returns the full environment string and length passed to the
00026 //       constructor.
00027 //
00028 inline char *Env(int &envlen) {envlen = global_len; return global_env;}
00029 
00030 // Export() sets an external environmental variable to the desired value
00031 //          using dynamically allocated fixed storage.
00032 //
00033 static int   Export(const char *Var, const char *Val);
00034 static int   Export(const char *Var, int         Val);
00035 
00036 // Import() gets a variable from the extended environment and stores
00037 //          it in this object
00038 static bool  Import( const char *var, char *&val );
00039 static bool  Import( const char *var, long  &val );
00040 
00041 // Get() returns the address of the string associated with the variable
00042 //       name. If no association exists, zero is returned.
00043 //
00044        char *Get(const char *varname) {return env_Hash.Find(varname);}
00045 
00046 // GetInt() returns a long integer value. If the variable varname is not found
00047 //           in the hash table, return -999999999.       
00048 //
00049        long  GetInt(const char *varname);
00050 
00051 // GetPtr() returns a pointer as a (void *) value. If the varname is not found
00052 //          a nil pointer is returned (i.e. 0).
00053 //
00054        void *GetPtr(const char *varname);
00055 
00056 // Put() associates a string value with the a variable name. If one already
00057 //       exists, it is replaced. The passed value and variable strings are
00058 //       duplicated (value here, variable by env_Hash).
00059 //
00060        void  Put(const char *varname, const char *value)
00061                 {env_Hash.Rep((char *)varname, strdup(value), 0, Hash_dofree);}
00062 
00063 // PutInt() puts a long integer value into the hash. Internally, the value gets
00064 //          converted into a char*
00065 //
00066        void  PutInt(const char *varname, long value);
00067 
00068 // PutPtr() puts a pointer value into the hash. The pointer is accepted as a
00069 //          (void *) value. By convention, the variable name should end with
00070 //          an asterisk and typically corresponds to it's class name.
00071 //
00072        void PutPtr(const char *varname, void *value);
00073 
00074 // Delimit() search for the first occurrence of comma (',') in value and
00075 //           replaces it with a null byte. It then returns the address of the
00076 //           remaining string. If no comma was found, it returns zero.
00077 //
00078        char *Delimit(char *value);
00079 
00080 // secEnv() returns the security environment; which may be a null pointer.
00081 //
00082 inline const XrdSecEntity *secEnv() {return secEntity;}
00083 
00084 // Use the constructor to define the initial variable settings. The passed
00085 // string is duplicated and the copy can be retrieved using Env().
00086 //
00087        XrdOucEnv(const char *vardata=0, int vardlen=0, 
00088                  const XrdSecEntity *secent=0);
00089 
00090       ~XrdOucEnv() {if (global_env) free((void *)global_env);}
00091 
00092 private:
00093 
00094 XrdOucHash<char> env_Hash;
00095 const XrdSecEntity *secEntity;
00096 char *global_env;
00097 int   global_len;
00098 };
00099 #endif