|
||||
File indexing completed on 2025-01-18 10:15:41
0001 #ifndef __OUC_ENV__ 0002 #define __OUC_ENV__ 0003 /******************************************************************************/ 0004 /* */ 0005 /* X r d O u c E n v . h h */ 0006 /* */ 0007 /* (c) 2003 by the Board of Trustees of the Leland Stanford, Jr., University */ 0008 /* All Rights Reserved */ 0009 /* Produced by Andrew Hanushevsky for Stanford University under contract */ 0010 /* DE-AC02-76-SFO0515 with the Department of Energy */ 0011 /* */ 0012 /* This file is part of the XRootD software suite. */ 0013 /* */ 0014 /* XRootD is free software: you can redistribute it and/or modify it under */ 0015 /* the terms of the GNU Lesser General Public License as published by the */ 0016 /* Free Software Foundation, either version 3 of the License, or (at your */ 0017 /* option) any later version. */ 0018 /* */ 0019 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */ 0020 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */ 0021 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */ 0022 /* License for more details. */ 0023 /* */ 0024 /* You should have received a copy of the GNU Lesser General Public License */ 0025 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */ 0026 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */ 0027 /* */ 0028 /* The copyright holder's institutional names and contributor's names may not */ 0029 /* be used to endorse or promote products derived from this software without */ 0030 /* specific prior written permission of the institution or contributor. */ 0031 /******************************************************************************/ 0032 0033 #include <cstdlib> 0034 #ifndef WIN32 0035 #include <strings.h> 0036 #endif 0037 #include "XrdOuc/XrdOucHash.hh" 0038 0039 class XrdSecEntity; 0040 0041 class XrdOucEnv 0042 { 0043 public: 0044 0045 // Env() returns the full environment string and length passed to the 0046 // constructor. 0047 // 0048 inline char *Env(int &envlen) {envlen = global_len; return global_env;} 0049 0050 // EnvTidy() returns the environment string and length with authorization 0051 // information (ie. authz), if any, removed. 0052 // 0053 char *EnvTidy(int &envlen); 0054 0055 // Export() sets an external environmental variable to the desired value 0056 // using dynamically allocated fixed storage. 0057 // 0058 static int Export(const char *Var, const char *Val); 0059 static int Export(const char *Var, int Val); 0060 0061 // Import() gets a variable from the extended environment and stores 0062 // it in this object 0063 static bool Import( const char *var, char *&val ); 0064 static bool Import( const char *var, long &val ); 0065 0066 // Get() returns the address of the string associated with the variable 0067 // name. If no association exists, zero is returned. 0068 // 0069 char *Get(const char *varname) {return env_Hash.Find(varname);} 0070 0071 // GetInt() returns a long integer value. If the variable varname is not found 0072 // in the hash table, return -999999999. 0073 // 0074 long GetInt(const char *varname); 0075 0076 // GetPtr() returns a pointer as a (void *) value. If the varname is not found 0077 // a nil pointer is returned (i.e. 0). 0078 // 0079 void *GetPtr(const char *varname); 0080 0081 // Put() associates a string value with the a variable name. If one already 0082 // exists, it is replaced. The passed value and variable strings are 0083 // duplicated (value here, variable by env_Hash). 0084 // 0085 void Put(const char *varname, const char *value) 0086 {env_Hash.Rep((char *)varname, strdup(value), 0, Hash_dofree);} 0087 0088 // PutInt() puts a long integer value into the hash. Internally, the value gets 0089 // converted into a char* 0090 // 0091 void PutInt(const char *varname, long value); 0092 0093 // PutPtr() puts a pointer value into the hash. The pointer is accepted as a 0094 // (void *) value. By convention, the variable name should end with 0095 // an asterisk and typically corresponds to it's class name. 0096 // 0097 void PutPtr(const char *varname, void *value); 0098 0099 // Delimit() search for the first occurrence of comma (',') in value and 0100 // replaces it with a null byte. It then returns the address of the 0101 // remaining string. If no comma was found, it returns zero. 0102 // 0103 char *Delimit(char *value); 0104 0105 // secEnv() returns the security environment; which may be a null pointer. 0106 // 0107 inline const XrdSecEntity *secEnv() const {return secEntity;} 0108 0109 // Use the constructor to define the initial variable settings. The passed 0110 // string is duplicated and the copy can be retrieved using Env(). 0111 // 0112 XrdOucEnv(const char *vardata=0, int vardlen=0, 0113 const XrdSecEntity *secent=0); 0114 0115 ~XrdOucEnv() {if (global_env) free((void *)global_env);} 0116 0117 private: 0118 void EnvBuildTidy(); 0119 0120 XrdOucHash<char> env_Hash; 0121 const XrdSecEntity *secEntity; 0122 char *global_env; 0123 int global_len; 0124 }; 0125 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |