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 //         $Id: XrdOucEnv.hh 38011 2011-02-08 18:35:57Z ganis $
00014 
00015 #include <stdlib.h>
00016 #ifndef WIN32
00017 #include <strings.h>
00018 #endif
00019 #include "XrdOuc/XrdOucHash.hh"
00020 
00021 class XrdSecEntity;
00022 
00023 class XrdOucEnv
00024 {
00025 public:
00026 
00027 // Env() returns the full environment string and length passed to the
00028 //       constructor.
00029 //
00030 inline char *Env(int &envlen) {envlen = global_len; return global_env;}
00031 
00032 // Export() sets an external environmental variable to the desired value
00033 //          using dynamically allocated fixed storage.
00034 //
00035 static int   Export(const char *Var, const char *Val);
00036 static int   Export(const char *Var, int         Val);
00037 
00038 // Import() gets a variable from the extended environment and stores
00039 //          it in this object
00040 static bool  Import( const char *var, char *&val );
00041 static bool  Import( const char *var, long  &val );
00042 
00043 // Get() returns the address of the string associated with the variable
00044 //       name. If no association exists, zero is returned.
00045 //
00046        char *Get(const char *varname) {return env_Hash.Find(varname);}
00047 
00048 // GetInt() returns a long integer value. If the variable varname is not found
00049 //           in the hash table, return -999999999.       
00050 //
00051        long  GetInt(const char *varname);
00052 
00053 // Put() associates a string value with the a variable name. If one already
00054 //       exists, it is replaced. The passed value and variable strings are
00055 //       duplicated (value here, variable by env_Hash).
00056 //
00057        void  Put(const char *varname, const char *value)
00058                 {env_Hash.Rep((char *)varname, strdup(value), 0, Hash_dofree);}
00059 
00060 // PutInt() puts a long integer value into the hash. Internally, the value gets
00061 //          converted into a char*
00062 //
00063        void  PutInt(const char *varname, long value);
00064 
00065 // Delimit() search for the first occurrence of comma (',') in value and
00066 //           replaces it with a null byte. It then returns the address of the
00067 //           remaining string. If no comma was found, it returns zero.
00068 //
00069        char *Delimit(char *value);
00070 
00071 // secEnv() returns the security environment; which may be a null pointer.
00072 //
00073 inline const XrdSecEntity *secEnv() {return secEntity;}
00074 
00075 // Use the constructor to define the initial variable settings. The passed
00076 // string is duplicated and the copy can be retrieved using Env().
00077 //
00078        XrdOucEnv(const char *vardata=0, int vardlen=0, 
00079                  const XrdSecEntity *secent=0);
00080 
00081       ~XrdOucEnv() {if (global_env) free((void *)global_env);}
00082 
00083 private:
00084 
00085 XrdOucHash<char> env_Hash;
00086 const XrdSecEntity *secEntity;
00087 char *global_env;
00088 int   global_len;
00089 };
00090 #endif

Generated on Tue Jul 5 14:46:48 2011 for ROOT_528-00b_version by  doxygen 1.5.1