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-AC02-76-SFO0515 with the Department of Energy              */
00011 /*                                                                            */
00012 /* This file is part of the XRootD software suite.                            */
00013 /*                                                                            */
00014 /* XRootD is free software: you can redistribute it and/or modify it under    */
00015 /* the terms of the GNU Lesser General Public License as published by the     */
00016 /* Free Software Foundation, either version 3 of the License, or (at your     */
00017 /* option) any later version.                                                 */
00018 /*                                                                            */
00019 /* XRootD is distributed in the hope that it will be useful, but WITHOUT      */
00020 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or      */
00021 /* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public       */
00022 /* License for more details.                                                  */
00023 /*                                                                            */
00024 /* You should have received a copy of the GNU Lesser General Public License   */
00025 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file  */
00026 /* COPYING (GPL license).  If not, see <http://www.gnu.org/licenses/>.        */
00027 /*                                                                            */
00028 /* The copyright holder's institutional names and contributor's names may not */
00029 /* be used to endorse or promote products derived from this software without  */
00030 /* specific prior written permission of the institution or contributor.       */
00031 /******************************************************************************/
00032 
00033 #include <stdlib.h>
00034 #ifndef WIN32
00035 #include <strings.h>
00036 #endif
00037 #include "XrdOuc/XrdOucHash.hh"
00038 
00039 class XrdSecEntity;
00040 
00041 class XrdOucEnv
00042 {
00043 public:
00044 
00045 // Env() returns the full environment string and length passed to the
00046 //       constructor.
00047 //
00048 inline char *Env(int &envlen) {envlen = global_len; return global_env;}
00049 
00050 // Export() sets an external environmental variable to the desired value
00051 //          using dynamically allocated fixed storage.
00052 //
00053 static int   Export(const char *Var, const char *Val);
00054 static int   Export(const char *Var, int         Val);
00055 
00056 // Import() gets a variable from the extended environment and stores
00057 //          it in this object
00058 static bool  Import( const char *var, char *&val );
00059 static bool  Import( const char *var, long  &val );
00060 
00061 // Get() returns the address of the string associated with the variable
00062 //       name. If no association exists, zero is returned.
00063 //
00064        char *Get(const char *varname) {return env_Hash.Find(varname);}
00065 
00066 // GetInt() returns a long integer value. If the variable varname is not found
00067 //           in the hash table, return -999999999.       
00068 //
00069        long  GetInt(const char *varname);
00070 
00071 // GetPtr() returns a pointer as a (void *) value. If the varname is not found
00072 //          a nil pointer is returned (i.e. 0).
00073 //
00074        void *GetPtr(const char *varname);
00075 
00076 // Put() associates a string value with the a variable name. If one already
00077 //       exists, it is replaced. The passed value and variable strings are
00078 //       duplicated (value here, variable by env_Hash).
00079 //
00080        void  Put(const char *varname, const char *value)
00081                 {env_Hash.Rep((char *)varname, strdup(value), 0, Hash_dofree);}
00082 
00083 // PutInt() puts a long integer value into the hash. Internally, the value gets
00084 //          converted into a char*
00085 //
00086        void  PutInt(const char *varname, long value);
00087 
00088 // PutPtr() puts a pointer value into the hash. The pointer is accepted as a
00089 //          (void *) value. By convention, the variable name should end with
00090 //          an asterisk and typically corresponds to it's class name.
00091 //
00092        void PutPtr(const char *varname, void *value);
00093 
00094 // Delimit() search for the first occurrence of comma (',') in value and
00095 //           replaces it with a null byte. It then returns the address of the
00096 //           remaining string. If no comma was found, it returns zero.
00097 //
00098        char *Delimit(char *value);
00099 
00100 // secEnv() returns the security environment; which may be a null pointer.
00101 //
00102 inline const XrdSecEntity *secEnv() const {return secEntity;}
00103 
00104 // Use the constructor to define the initial variable settings. The passed
00105 // string is duplicated and the copy can be retrieved using Env().
00106 //
00107        XrdOucEnv(const char *vardata=0, int vardlen=0, 
00108                  const XrdSecEntity *secent=0);
00109 
00110       ~XrdOucEnv() {if (global_env) free((void *)global_env);}
00111 
00112 private:
00113 
00114 XrdOucHash<char> env_Hash;
00115 const XrdSecEntity *secEntity;
00116 char *global_env;
00117 int   global_len;
00118 };
00119 #endif

Generated on 12 Dec 2014 for xrootd by  doxygen 1.4.7