XRootD
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)
Definition: XrdOucHash.hh:166

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 160 of file XrdOucEnv.cc.

161 {
162  char *tidyEnv;
163  int tries = 1;
164 
165 // Check if there is no env
166 //
167  if ((envlen = global_len) == 0 || global_env == 0) return 0;
168 
169 // Check if we have produced a tidy version. If noo build one and try again.
170 //
171 do{if ((tidyEnv = Get(TIDY_ENVVAR)))
172  {if (*tidyEnv == 0) break;
173  envlen = strlen(tidyEnv);
174  return tidyEnv;
175  }
176  EnvBuildTidy();
177  } while(tries--);
178 
179 // Return standard env
180 //
181  return Env(envlen);
182 }
#define TIDY_ENVVAR
Definition: XrdOucEnv.cc:101
char * Get(const char *varname)
Definition: XrdOucEnv.hh:69
char * Env(int &envlen)
Definition: XrdOucEnv.hh:48

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 188 of file XrdOucEnv.cc.

189 {
190  int vLen = strlen(Var);
191  char *eBuff;
192 
193 // If this is a null value then substitute a null string
194 //
195  if (!Val) Val = "";
196 
197 // Allocate memory. Note that this memory will appear to be lost.
198 //
199  eBuff = (char *)malloc(vLen+strlen(Val)+2); // +2 for '=' and '\0'
200 
201 // Set up envar
202 //
203  strcpy(eBuff, Var);
204  *(eBuff+vLen) = '=';
205  strcpy(eBuff+vLen+1, Val);
206  return putenv(eBuff);
207 }

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 211 of file XrdOucEnv.cc.

212 {
213  char buff[32];
214  sprintf(buff, "%d", Val);
215  return Export(Var, buff);
216 }
static int Export(const char *Var, const char *Val)
Definition: XrdOucEnv.cc:188

References Export().

+ Here is the call graph for this function:

◆ Get()

◆ GetInt()

long XrdOucEnv::GetInt ( const char *  varname)

Definition at line 253 of file XrdOucEnv.cc.

254 {
255  char *cP;
256 
257 // Retrieve a char* value from the Hash table and convert it into a long.
258 // Return -999999999 if the varname does not exist
259 //
260  if ((cP = env_Hash.Find(varname)) == NULL) return -999999999;
261  return atol(cP);
262 }

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 281 of file XrdOucEnv.cc.

282 {
283  void *Valp;
284  char *cP, *Value = (char *)&Valp;
285  int cLen, n, i = 0, Odd = 0;
286 
287 // Retrieve the variable from the hash
288 //
289  if ((cP = env_Hash.Find(varname)) == NULL) return (void *)0;
290 
291 // Verify that the string is not too long or too short
292 //
293  if ((cLen = strlen(cP)) != (int)sizeof(void *)*2) return (void *)0;
294 
295 // Now convert the hex string back to its pointer value
296 //
297  while(cLen--)
298  { if (*cP >= '0' && *cP <= '9') n = *cP-48;
299  else if (*cP >= 'a' && *cP <= 'f') n = *cP-87;
300  else if (*cP >= 'A' && *cP <= 'F') n = *cP-55;
301  else return (void *)0;
302  if (Odd) Value[i++] |= n;
303  else Value[i ] = n << 4;
304  cP++; Odd = ~Odd;
305  }
306 
307 // All done, return the actual pointer value
308 //
309  return Valp;
310 }

References XrdOucHash< T >::Find().

Referenced by StatsFileSystem::StatsFileSystem(), TPC::TPCHandler::TPCHandler(), XrdPfc::Cache::Config(), XrdPfcFSctl::Configure(), XrdCmsFinderRMT::Configure(), XrdConfig::Configure(), XrdSsiSfsConfig::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 222 of file XrdOucEnv.cc.

223 {
224  char *value = getenv( var );
225  if( !value || !*value )
226  return false;
227 
228  val = value;
229  return true;
230 }

Referenced by XrdVomsMapfile::Configure(), and Import().

+ Here is the caller graph for this function:

◆ Import() [2/2]

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

Definition at line 235 of file XrdOucEnv.cc.

236 {
237  char *value;
238  if( !Import( var, value ) )
239  return false;
240 
241  char *status;
242  val = strtol( value, &status, 0 );
243 
244  if( *status != 0 )
245  return false;
246  return true;
247 }
static bool Import(const char *var, char *&val)
Definition: XrdOucEnv.cc:222

References Import().

+ Here is the call graph for this function:

◆ 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(), XrdHttpReq::ProcessHTTPReq(), XrdOfsTPC::Validate(), XrdPfc::DataFsSnapshot::write_json_file(), 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 268 of file XrdOucEnv.cc.

269 {
270 // Convert the long into a char* and the put it into the hash table
271 //
272  char stringValue[24];
273  sprintf(stringValue, "%ld", value);
274  env_Hash.Rep(varname, strdup(stringValue), 0, Hash_dofree);
275 }

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 316 of file XrdOucEnv.cc.

317 {
318  static char hv[] = "0123456789abcdef";
319  char Buff[sizeof(void *)*2+1], *Value = (char *)&value;
320  int i, j = 0;
321 
322 // Convert the pointer value to a hex string
323 //
324  if (value) for (i = 0; i <(int)sizeof(void *); i++)
325  {Buff[j++] = hv[(Value[i] >> 4) & 0x0f];
326  Buff[j++] = hv[ Value[i] & 0x0f];
327  }
328  Buff[j] = '\0';
329 
330 // Replace the value in he hash
331 //
332  env_Hash.Rep(varname, strdup(Buff), 0, Hash_dofree);
333 }

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: