XRootD
Loading...
Searching...
No Matches
XrdOucEnv Class Reference

#include <XrdOucEnv.hh>

+ Collaboration diagram for XrdOucEnv:

Public Member Functions

 XrdOucEnv (const char *vardata=0, int vardlen=0, const XrdSecEntity *secent=0)
 
 ~XrdOucEnv ()
 
char * Delimit (char *value)
 
char * Env (int &envlen)
 
char * EnvTidy (int &envlen)
 
char * Get (const char *varname)
 
long GetInt (const char *varname)
 
void * GetPtr (const char *varname)
 
void Put (const char *varname, const char *value)
 
void PutInt (const char *varname, long value)
 
void PutPtr (const char *varname, void *value)
 
const XrdSecEntitysecEnv () const
 

Static Public Member Functions

static int Export (const char *Var, const char *Val)
 
static int Export (const char *Var, int Val)
 
static bool Import (const char *var, char *&val)
 
static bool Import (const char *var, long &val)
 

Detailed Description

Definition at line 41 of file XrdOucEnv.hh.

Constructor & Destructor Documentation

◆ XrdOucEnv()

XrdOucEnv::XrdOucEnv ( const char *  vardata = 0,
int  vardlen = 0,
const XrdSecEntity secent = 0 
)

Definition at line 42 of file XrdOucEnv.cc.

44 : env_Hash(8,13), secEntity(secent)
45{
46 char *vdp, varsave, *varname, *varvalu;
47
48 if (!vardata) {global_env = 0; global_len = 0; return;}
49
50// Get the length of the global information (don't rely on its being correct)
51//
52 if (!varlen) varlen = strlen(vardata);
53
54// We want our env copy to start with a single ampersand
55//
56 while(*vardata == '&' && varlen) {vardata++; varlen--;}
57 if (!varlen) {global_env = 0; global_len = 0; return;}
58 global_env = (char *)malloc(varlen+2);
59 *global_env = '&'; vdp = global_env+1;
60 memcpy((void *)vdp, (const void *)vardata, (size_t)varlen);
61 *(vdp+varlen) = '\0'; global_len = varlen+1;
62
63// scan through the string looking for '&'
64//
65 while(*vdp)
66 {while(*vdp == '&') vdp++;
67 varname = vdp;
68
69 while(*vdp && *vdp != '=' && *vdp != '&') vdp++; // &....=
70 if (!*vdp) break;
71 if (*vdp == '&') continue;
72 *vdp = '\0';
73 varvalu = ++vdp;
74
75 while(*vdp && *vdp != '&') vdp++; // &....=....&
76 varsave = *vdp; *vdp = '\0';
77
78 if (*varname && *varvalu)
79 env_Hash.Rep(varname, strdup(varvalu), 0, Hash_dofree);
80
81 *vdp = varsave; *(varvalu-1) = '=';
82 }
83 return;
84}
@ Hash_dofree
Definition XrdOucHash.hh:56
T * Rep(const char *KeyVal, T *KeyData, const int LifeTime=0, XrdOucHash_Options opt=Hash_default)

References Hash_dofree, and XrdOucHash< T >::Rep().

+ Here is the call graph for this function:

◆ ~XrdOucEnv()

XrdOucEnv::~XrdOucEnv ( )
inline

Definition at line 115 of file XrdOucEnv.hh.

115{if (global_env) free((void *)global_env);}

Member Function Documentation

◆ Delimit()

char * XrdOucEnv::Delimit ( char *  value)

Definition at line 90 of file XrdOucEnv.cc.

91{
92 while(*value) if (*value == ',') {*value = '\0'; return ++value;}
93 else value++;
94 return (char *)0;
95}

◆ Env()

char * XrdOucEnv::Env ( int &  envlen)
inline

Definition at line 48 of file XrdOucEnv.hh.

48{envlen = global_len; return global_env;}

Referenced by XrdHttpExtReq::XrdHttpExtReq(), XrdPssUrlInfo::XrdPssUrlInfo(), XrdHttpReq::appendOpaque(), EnvTidy(), XrdSsiFileResource::Init(), XrdCmsRedirLocal::Locate(), XrdPssFile::Open(), XrdOssSys::Stage_QT(), and XrdOssCsi::tagOpenEnv().

+ Here is the caller graph for this function:

◆ EnvTidy()

char * XrdOucEnv::EnvTidy ( int &  envlen)

Definition at line 142 of file XrdOucEnv.cc.

143{
144 char *tidyEnv;
145 int tries = 1;
146
147// Check if there is no env
148//
149 if ((envlen = global_len) == 0 || global_env == 0) return 0;
150
151// Check if we have produced a tidy version. If noo build one and try again.
152//
153do{if ((tidyEnv = Get(TIDY_ENVVAR)))
154 {if (*tidyEnv == 0) break;
155 envlen = strlen(tidyEnv);
156 return tidyEnv;
157 }
158 EnvBuildTidy();
159 } while(tries--);
160
161// Return standard env
162//
163 return Env(envlen);
164}
#define TIDY_ENVVAR
Definition XrdOucEnv.cc:101
char * Env(int &envlen)
Definition XrdOucEnv.hh:48
char * Get(const char *varname)
Definition XrdOucEnv.hh:69

References Env(), Get(), and TIDY_ENVVAR.

Referenced by XrdCmsFinderRMT::Forward(), and XrdCmsFinderRMT::Locate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Export() [1/2]

int XrdOucEnv::Export ( const char *  Var,
const char *  Val 
)
static

Definition at line 170 of file XrdOucEnv.cc.

171{
172 int vLen = strlen(Var);
173 char *eBuff;
174
175// If this is a null value then substitute a null string
176//
177 if (!Val) Val = "";
178
179// Allocate memory. Note that this memory will appear to be lost.
180//
181 eBuff = (char *)malloc(vLen+strlen(Val)+2); // +2 for '=' and '\0'
182
183// Set up envar
184//
185 strcpy(eBuff, Var);
186 *(eBuff+vLen) = '=';
187 strcpy(eBuff+vLen+1, Val);
188 return putenv(eBuff);
189}

Referenced by XrdOucPsx::ClientConfig(), XrdPfc::Cache::Config(), XrdOfs::Config_Display(), XrdOucLogging::configLog(), XrdXrootdProtocol::Configure(), XrdSecServer::Configure(), XrdCmsClientConfig::Configure(), XrdConfig::Configure(), XrdFrmConfig::Configure(), XrdOfs::Configure(), XrdThrottle::FileSystem::Configure(), XrdCmsConfig::Configure1(), XrdXrootdMonitor::Defaults(), Export(), XrdOfsTPC::Init(), XrdOssSpace::Init(), XrdOfsEvr::Init(), XrdOucN2NLoader::Load(), main(), XrdOucSiteName::Set(), XrdCmsSecurity::setSystemID(), XrdOfsTPC::Start(), and XrdXrootdloadFileSystem().

+ Here is the caller graph for this function:

◆ Export() [2/2]

int XrdOucEnv::Export ( const char *  Var,
int  Val 
)
static

Definition at line 193 of file XrdOucEnv.cc.

194{
195 char buff[32];
196 sprintf(buff, "%d", Val);
197 return Export(Var, buff);
198}
static int Export(const char *Var, const char *Val)
Definition XrdOucEnv.cc:170

References Export().

+ Here is the call graph for this function:

◆ Get()

◆ GetInt()

long XrdOucEnv::GetInt ( const char *  varname)

Definition at line 235 of file XrdOucEnv.cc.

236{
237 char *cP;
238
239// Retrieve a char* value from the Hash table and convert it into a long.
240// Return -999999999 if the varname does not exist
241//
242 if ((cP = env_Hash.Find(varname)) == NULL) return -999999999;
243 return atol(cP);
244}

References XrdOucHash< T >::Find().

Referenced by XrdXrootdProtocol::Configure(), and XrdSsiSfsConfig::Configure().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetPtr()

void * XrdOucEnv::GetPtr ( const char *  varname)

Definition at line 263 of file XrdOucEnv.cc.

264{
265 void *Valp;
266 char *cP, *Value = (char *)&Valp;
267 int cLen, n, i = 0, Odd = 0;
268
269// Retrieve the variable from the hash
270//
271 if ((cP = env_Hash.Find(varname)) == NULL) return (void *)0;
272
273// Verify that the string is not too long or too short
274//
275 if ((cLen = strlen(cP)) != (int)sizeof(void *)*2) return (void *)0;
276
277// Now convert the hex string back to its pointer value
278//
279 while(cLen--)
280 { if (*cP >= '0' && *cP <= '9') n = *cP-48;
281 else if (*cP >= 'a' && *cP <= 'f') n = *cP-87;
282 else if (*cP >= 'A' && *cP <= 'F') n = *cP-55;
283 else return (void *)0;
284 if (Odd) Value[i++] |= n;
285 else Value[i ] = n << 4;
286 cP++; Odd = ~Odd;
287 }
288
289// All done, return the actual pointer value
290//
291 return Valp;
292}

References XrdOucHash< T >::Find().

Referenced by TPC::TPCHandler::TPCHandler(), XrdPfc::Cache::Config(), XrdPfcFSctl::Configure(), XrdCmsFinderRMT::Configure(), XrdConfig::Configure(), XrdSsiSfsConfig::Configure(), XrdOfs::Configure(), XrdThrottle::FileSystem::Configure(), XrdPosixConfig::EnvInfo(), XrdPssSys::EnvInfo(), XrdOucStream::Exec(), XrdOssCsi::Init(), XrdPssSys::Init(), XrdHttpGetExtHandler(), XrdOfsgetPrepare(), and XrdOucGetCache().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Import() [1/2]

bool XrdOucEnv::Import ( const char *  var,
char *&  val 
)
static

Definition at line 204 of file XrdOucEnv.cc.

205{
206 char *value = getenv( var );
207 if( !value || !*value )
208 return false;
209
210 val = value;
211 return true;
212}

Referenced by XrdVomsMapfile::Configure().

+ Here is the caller graph for this function:

◆ Import() [2/2]

bool XrdOucEnv::Import ( const char *  var,
long &  val 
)
static

Definition at line 217 of file XrdOucEnv.cc.

218{
219 char *value;
220 if( !Import( var, value ) )
221 return false;
222
223 char *status;
224 val = strtol( value, &status, 0 );
225
226 if( *status != 0 )
227 return false;
228 return true;
229}
bool Import

References Import.

◆ Put()

void XrdOucEnv::Put ( const char *  varname,
const char *  value 
)
inline

Definition at line 85 of file XrdOucEnv.hh.

86 {env_Hash.Rep((char *)varname, strdup(value), 0, Hash_dofree);}

References Hash_dofree, and XrdOucHash< T >::Rep().

Referenced by XrdPosixXrootd::XrdPosixXrootd(), XrdSecPinInfo::XrdSecPinInfo(), XrdTcpMonInfo::XrdTcpMonInfo(), XrdPfc::Cache::Config(), XrdPfc::Cache::ExecuteCommandUrl(), XrdOfs::fsctl(), XrdFrcCID::Get(), XrdPssFile::Open(), XrdOfsTPC::Validate(), and XrdOssGetSS().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ PutInt()

void XrdOucEnv::PutInt ( const char *  varname,
long  value 
)

Definition at line 250 of file XrdOucEnv.cc.

251{
252// Convert the long into a char* and the put it into the hash table
253//
254 char stringValue[24];
255 sprintf(stringValue, "%ld", value);
256 env_Hash.Rep(varname, strdup(stringValue), 0, Hash_dofree);
257}

References Hash_dofree, and XrdOucHash< T >::Rep().

Referenced by XrdConfig::Configure(), and XrdOfs::FAttr().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ PutPtr()

void XrdOucEnv::PutPtr ( const char *  varname,
void *  value 
)

Definition at line 298 of file XrdOucEnv.cc.

299{
300 static char hv[] = "0123456789abcdef";
301 char Buff[sizeof(void *)*2+1], *Value = (char *)&value;
302 int i, j = 0;
303
304// Convert the pointer value to a hex string
305//
306 if (value) for (i = 0; i <(int)sizeof(void *); i++)
307 {Buff[j++] = hv[(Value[i] >> 4) & 0x0f];
308 Buff[j++] = hv[ Value[i] & 0x0f];
309 }
310 Buff[j] = '\0';
311
312// Replace the value in he hash
313//
314 env_Hash.Rep(varname, strdup(Buff), 0, Hash_dofree);
315}

References Hash_dofree, and XrdOucHash< T >::Rep().

Referenced by XrdOssSys::ConfigStatLib(), XrdXrootdProtocol::Configure(), XrdOssSys::Configure(), XrdCmsFinderTRG::Configure(), XrdConfig::Configure(), XrdOfs::Configure(), XrdCmsConfig::Configure0(), XrdOucN2NLoader::Load(), XrdOucProg::Run(), and XrdOucGetCache().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ secEnv()

const XrdSecEntity * XrdOucEnv::secEnv ( ) const
inline

Definition at line 107 of file XrdOucEnv.hh.

107{return secEntity;}

Referenced by XrdPssUrlInfo::XrdPssUrlInfo(), XrdPssSys::Connect(), XrdPssSys::Disc(), XrdSsiFileResource::Init(), XrdCmsRedirLocal::Locate(), XrdPssFile::Open(), and XrdOssCsi::tagOpenEnv().

+ Here is the caller graph for this function:

The documentation for this class was generated from the following files: