XRootD
XrdOucStream Class Reference

#include <XrdOucStream.hh>

+ Collaboration diagram for XrdOucStream:

Public Member Functions

 XrdOucStream (XrdSysError *erobj=0, const char *ifname=0, XrdOucEnv *anEnv=0, const char *Pfx=0)
 
 ~XrdOucStream ()
 
int Attach (int FileDescriptor, int bsz=2047)
 
int AttachIO (int infd, int outfd, int bsz=2047)
 
void Close (int hold=0)
 
int Detach ()
 
int Drain ()
 
void Echo ()
 
void Echo (bool capture)
 
int Exec (char **, int inrd=0, int efd=0)
 
int Exec (const char *, int inrd=0, int efd=0)
 
int FDNum ()
 
int FENum ()
 
void Flush ()
 
char * GetFirstWord (int lowcase=0)
 
char * GetLine ()
 
char * GetMyFirstWord (int lowcase=0)
 
int GetRest (char *theBuf, int Blen, int lowcase=0)
 
char * GetToken (char **rest, int lowcase=0)
 
char * GetToken (int lowcase=0)
 
char * GetWord (int lowcase=0)
 
int isAlive ()
 
int LastError ()
 
char * LastLine ()
 
int noEcho ()
 
int Put (const char *data)
 
int Put (const char *data, const int dlen)
 
int Put (const char *data[], const int dlen[])
 
int PutLine (const char *data, int dlen=0)
 
void RetToken ()
 
XrdOucEnvSetEnv (XrdOucEnv *newEnv)
 
void SetEroute (XrdSysError *eroute)
 
void Tabs (int x=1)
 
int Wait4Data (int msMax=-1)
 

Static Public Member Functions

static XrdOucStringCapture ()
 
static void Capture (const char **cVec=0, bool linefeed=true)
 
static XrdOucStringCapture (XrdOucString *cfObj)
 

Detailed Description

Definition at line 46 of file XrdOucStream.hh.

Constructor & Destructor Documentation

◆ XrdOucStream()

XrdOucStream::XrdOucStream ( XrdSysError erobj = 0,
const char *  ifname = 0,
XrdOucEnv anEnv = 0,
const char *  Pfx = 0 
)

Definition at line 187 of file XrdOucStream.cc.

189 {
190  char *cp;
191 
192 
193  if (ifname)
194  {myInst = strdup(ifname);
195  myInfo = new StreamInfo;
196  if (!(cp = index(myInst, ' '))) {cp = myInst; myInfo->myExec = 0;}
197  else {*cp = '\0'; cp++;
198  myInfo->myExec = (*myInst ? myInst : 0);
199  }
200  if ( (myInfo->myHost = index(cp, '@')))
201  {*(myInfo->myHost) = '\0';
202  myInfo->myHost++;
203  myInfo->myName = (*cp ? cp : 0);
204  } else {myInfo->myHost = cp; myInfo->myName = 0;}
205  } else {myInst = 0; myInfo = 0;}
206  myRsv1 = myRsv2 = 0;
207 
208  FD = -1;
209  FE = -1;
210  bsize = 0;
211  buff = 0;
212  bnext = 0;
213  bleft = 0;
214  recp = 0;
215  token = 0;
216  flags = 0;
217  child = 0;
218  ecode = 0;
219  notabs = 0;
220  xcont = 1;
221  xline = 0;
222  Eroute = erobj;
223  myEnv = anEnv;
224  sawif = 0;
225  skpel = 0;
226  if (myEnv && Eroute)
227  {llBuff = (char *)malloc(llBsz);
228  llBcur = llBuff; llBok = 0; llBleft = llBsz; *llBuff = '\0';
229  Verbose= 1;
230  } else {
231  Verbose= 0;
232  llBuff = 0;
233  llBcur = 0;
234  llBleft= 0;
235  llBok = 0;
236  }
237  varVal = (myEnv ? new char[maxVLen+1] : 0);
238  llPrefix = Pfx;
239 }
char * myExec
char * myName
char * myHost

References StreamInfo::myExec, StreamInfo::myHost, and StreamInfo::myName.

◆ ~XrdOucStream()

XrdOucStream::~XrdOucStream ( )
inline

Definition at line 57 of file XrdOucStream.hh.

57  {Close(); if (myInst) free(myInst);
58  if (varVal) delete [] varVal;
59  if (llBuff) free(llBuff);
60  }
void Close(int hold=0)

References Close().

+ Here is the call graph for this function:

Member Function Documentation

◆ Attach()

int XrdOucStream::Attach ( int  FileDescriptor,
int  bsz = 2047 
)

Definition at line 252 of file XrdOucStream.cc.

253 {
254 
255  // Close the current stream. Close will handle unopened streams.
256  //
257  StreamInfo *saveInfo = myInfo; myInfo = 0;
258  Close();
259  myInfo = saveInfo;
260 
261  // Allocate a new buffer for this stream
262  //
263  if (!bsz) buff = 0;
264  else if (!(buff = (char *)malloc(bsz+1)))
265  return Erq(Attach, errno, "allocate stream buffer");
266 
267  // Initialize the stream
268  //
269  FD= FE = FileDescriptor;
270  bnext = buff;
271  bsize = bsz+1;
272  bleft = 0;
273  recp = 0;
274  token = 0;
275  flags = 0;
276  ecode = 0;
277  xcont = 1;
278  xline = 0;
279  sawif = 0;
280  skpel = 0;
281  if (llBuff)
282  {llBcur = llBuff; *llBuff = '\0'; llBleft = llBsz; llBok = 0;}
283  return 0;
284 }
#define Erq(p, a, b)
Definition: XrdOucStream.cc:80
int Attach(int FileDescriptor, int bsz=2047)

References Close(), and Erq.

Referenced by AttachIO(), Macaroons::Handler::Config(), XrdSsiSfsConfig::Configure(), XrdVomsMapfile::Configure(), Exec(), XrdFrcCID::Init(), main(), XrdOssCache::MapDevs(), XrdAccAuthFile::Open(), XrdFrmXfrDaemon::Pong(), PutLine(), XrdOfsEvr::recvEvents(), and XrdFrmXfrAgent::Start().

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

◆ AttachIO()

int XrdOucStream::AttachIO ( int  infd,
int  outfd,
int  bsz = 2047 
)

Definition at line 245 of file XrdOucStream.cc.

246 {
247  if (Attach(infd, bsz)) return -1;
248  FE = outfd;
249  return 0;
250 }

References Attach().

Referenced by XrdXrootdAdmin::Login().

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

◆ Capture() [1/3]

XrdOucString * XrdOucStream::Capture ( )
static

Definition at line 314 of file XrdOucStream.cc.

315 {
316  return theCFG;
317 }

◆ Capture() [2/3]

void XrdOucStream::Capture ( const char **  cVec = 0,
bool  linefeed = true 
)
static

Definition at line 290 of file XrdOucStream.cc.

291 {
292 // Make sure we can handle this
293 //
294  if (theCFG && cVec && cVec[0])
295  {if (linefeed) theCFG->append("\n# ");
296  else theCFG->append("# ");
297  int i = 0;
298  while(cVec[i]) theCFG->append(cVec[i++]);
299  theCFG->append('\n');
300  }
301 }
void append(const int i)

References XrdOucString::append().

Referenced by Macaroons::Handler::Config(), and XrdSsiSfsConfig::Configure().

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

◆ Capture() [3/3]

XrdOucString * XrdOucStream::Capture ( XrdOucString cfObj)
static

Definition at line 305 of file XrdOucStream.cc.

306 {
307  XrdOucString *oldCFG = theCFG;
308  theCFG = newCFG;
309  return oldCFG;
310 }

◆ Close()

void XrdOucStream::Close ( int  hold = 0)

Definition at line 323 of file XrdOucStream.cc.

324 {
325 
326  // Wait for any associated process on this stream
327  //
328  if (!hold && child) Drain();
329  else child = 0;
330 
331  // Close the associated file descriptor if it was open
332  //
333  if (FD >= 0) close(FD);
334  if (FE >= 0 && FE != FD) close(FE);
335 
336  // Release the buffer if it was allocated.
337  //
338  if (buff) free(buff);
339 
340  // Clear all data values by attaching a dummy FD
341  //
342  FD = FE = -1;
343  buff = 0;
344 
345  // Check if we should echo the last line
346  //
347  if (llBuff)
348  {if (Verbose && *llBuff && llBok > 1)
349  {if (Eroute) Eroute->Say(llPrefix, llBuff);
350  if (theCFG) add2CFG(llBuff);
351  }
352  llBok = 0;
353  }
354 
355  // Delete any info object we have allocated
356  //
357  if (myInfo)
358  {delete myInfo;
359  myInfo = 0;
360  }
361 }
#define close(a)
Definition: XrdPosix.hh:48
void Say(const char *text1, const char *text2=0, const char *txt3=0, const char *text4=0, const char *text5=0, const char *txt6=0)
Definition: XrdSysError.cc:141

References close, Drain(), and XrdSysError::Say().

Referenced by XrdOfsEvr::~XrdOfsEvr(), ~XrdOucStream(), XrdCmsFinderTRG::Added(), Attach(), XrdAccAuthFile::Close(), XrdSsiSfsConfig::Configure(), XrdFrcCID::Init(), XrdCmsFinderTRG::PutInfo(), XrdCmsFinderTRG::Removed(), XrdCmsFinderTRG::Resume(), XrdCmsFinderTRG::Start(), and XrdCmsFinderTRG::Suspend().

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

◆ Detach()

int XrdOucStream::Detach ( )
inline

Definition at line 76 of file XrdOucStream.hh.

76 {int oldFD = FD; FD = FE = -1; return oldFD;}

◆ Drain()

int XrdOucStream::Drain ( )

Definition at line 367 of file XrdOucStream.cc.

368 {
369  int Status = 0;
370 
371  // Drain any outstanding processes (i.e., kill the process group)
372  //
373 #ifndef WIN32
374  int retc;
375  if (child) {kill(-child, 9);
376  do {retc = waitpid(child, &Status, 0);}
377  while(retc > 0 || (retc == -1 && errno == EINTR));
378  child = 0;
379  }
380 #else
381  if (child) {
382  TerminateProcess((HANDLE)child, 0);
383  child = 0;
384  }
385 #endif
386  return Status;
387 }

Referenced by XrdOfsTPCProg::Cancel(), Close(), XrdCmsMeter::Report(), and XrdOucProg::RunDone().

+ Here is the caller graph for this function:

◆ Echo() [1/2]

void XrdOucStream::Echo ( )

Definition at line 393 of file XrdOucStream.cc.

394 {
395  if (llBok > 1 && Verbose && llBuff)
396  {if (Eroute) Eroute->Say(llPrefix,llBuff);
397  if (theCFG) add2CFG(llBuff);
398  }
399  llBok = 0;
400 }

References XrdSysError::Say().

Referenced by Macaroons::Handler::Config(), XrdSsiSfsConfig::Configure(), XrdCmsConfig::ConfigXeq(), and GetMyFirstWord().

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

◆ Echo() [2/2]

void XrdOucStream::Echo ( bool  capture)

Definition at line 406 of file XrdOucStream.cc.

407 {
408  if (llBok && Verbose && llBuff)
409  {if (Eroute) Eroute->Say(llPrefix,llBuff);
410  if (capture && theCFG) add2CFG(llBuff);
411  }
412  llBok = 0;
413 }

References XrdSysError::Say().

+ Here is the call graph for this function:

◆ Exec() [1/2]

int XrdOucStream::Exec ( char **  parm,
int  inrd = 0,
int  efd = 0 
)

Definition at line 450 of file XrdOucStream.cc.

451 {
452  int fildes[2], Child_in = -1, Child_out = -1, Child_log = -1;
453 
454  // Create a pipe. Minimize file descriptor leaks.
455  //
456  if (inrd >= 0)
457  {if (pipe(fildes))
458  return Err(Exec, errno, "create input pipe for", parm[0]);
459  else {
460  fcntl(fildes[0], F_SETFD, FD_CLOEXEC);
461  Attach(fildes[0]); Child_out = fildes[1];
462  }
463 
464  if (inrd)
465  {if (pipe(fildes))
466  return Err(Exec, errno, "create output pipe for", parm[0]);
467  else {
468  fcntl(fildes[1], F_SETFD, FD_CLOEXEC);
469  FE = fildes[1]; Child_in = fildes[0];
470  }
471  }
472  } else {Child_out = FD; Child_in = FE;}
473 
474  // Handle the standard error file descriptor
475  //
476  if (!efd) Child_log = (Eroute ? dup(Eroute->logger()->originalFD()) : -1);
477  else if (efd > 0) Child_log = efd;
478  else if (efd == -2){Child_log = Child_out; Child_out = -1;}
479  else if (efd == -3) Child_log = Child_out;
480 
481  // Fork a process first so we can pick up the next request. We also
482  // set the process group in case the child hasn't been able to do so.
483  // Make sure only one fork occurs at any one time (we are the only one).
484  //
485  forkMutex.Lock();
486  if ((child = fork()))
487  {if (child < 0)
488  {close(Child_in); close(Child_out); forkMutex.UnLock();
489  return Err(Exec, errno, "fork request process for", parm[0]);
490  }
491  close(Child_out);
492  if (inrd) close(Child_in );
493  if (!efd && Child_log >= 0) close(Child_log);
494  forkMutex.UnLock();
495  setpgid(child, child);
496  return 0;
497  }
498 
499  /*****************************************************************/
500  /* C h i l d P r o c e s s */
501  /*****************************************************************/
502 
503  // Redirect standard in if so requested
504  //
505  if (Child_in >= 0)
506  {if (inrd)
507  {if (dup2(Child_in, STDIN_FILENO) < 0)
508  {Erx(Exec, errno, "setting up standard in for " <<parm[0]);
509  _exit(255);
510  } else if (Child_in != Child_out) close(Child_in);
511  }
512  }
513 
514  // Reassign the stream to be standard out to capture all of the output.
515  //
516  if (Child_out >= 0)
517  {if (dup2(Child_out, STDOUT_FILENO) < 0)
518  {Erx(Exec, errno, "setting up standard out for " <<parm[0]);
519  _exit(255);
520  } else if (Child_out != Child_log) close(Child_out);
521  }
522 
523  // Redirect stderr of the stream if we can to avoid keeping the logfile open
524  //
525  if (Child_log >= 0)
526  {if (dup2(Child_log, STDERR_FILENO) < 0)
527  {Erx(Exec, errno, "set up standard err for " <<parm[0]);
528  _exit(255);
529  } else close(Child_log);
530  }
531 
532  // Check if we need to set any envornment variables
533  //
534  if (myEnv)
535  {char **envP;
536  int i = 0;
537  if ((envP = (char **)myEnv->GetPtr("XrdEnvars**")))
538  while(envP[i]) {putenv(envP[i]); i++;}
539  }
540 
541  // Set our process group (the parent should have done this by now) then
542  // invoke the command never to return
543  //
544  setpgid(0,0);
545  execv(parm[0], parm);
546  Erx(Exec, errno, "executing " <<parm[0]);
547  _exit(255);
548 }
#define Erx(p, a, b)
Definition: XrdOucStream.cc:86
#define Err(p, a, b, c)
Definition: XrdOucStream.cc:81
int fcntl(int fd, int cmd,...)
void * GetPtr(const char *varname)
Definition: XrdOucEnv.cc:281
int Exec(const char *, int inrd=0, int efd=0)
XrdSysLogger * logger(XrdSysLogger *lp=0)
Definition: XrdSysError.hh:141
XrdOucEnv * envP
Definition: XrdPss.cc:109

References Attach(), close, XrdProxy::envP, Err, Erx, Exec(), fcntl(), XrdOucEnv::GetPtr(), XrdSysError::logger(), and XrdSysLogger::originalFD().

+ Here is the call graph for this function:

◆ Exec() [2/2]

int XrdOucStream::Exec ( const char *  theCmd,
int  inrd = 0,
int  efd = 0 
)

Definition at line 419 of file XrdOucStream.cc.

420 {
421  int j;
422  char *cmd, *origcmd, *parm[MaxARGC];
423 
424  if (!theCmd)
425  return EINVAL;
426 
427  // Allocate a buffer for the command as we will be modifying it
428  //
429  origcmd = cmd = (char *)malloc(strlen(theCmd)+1);
430  strcpy(cmd, theCmd);
431 
432  // Construct the argv array based on passed command line.
433  //
434  for (j = 0; j < MaxARGC-1 && *cmd; j++)
435  {while(*cmd == ' ') cmd++;
436  if (!(*cmd)) break;
437  parm[j] = cmd;
438  while(*cmd && *cmd != ' ') cmd++;
439  if (*cmd) {*cmd = '\0'; cmd++;}
440  }
441  parm[j] = (char *)0;
442 
443  // Continue with normal processing
444  //
445  int ret = j > 0 ? Exec(parm, inrd, efd) : EINVAL;
446  free(origcmd);
447  return ret;
448 }
#define MaxARGC
Definition: XrdOucStream.cc:71

References MaxARGC.

Referenced by Exec(), XrdCmsMeter::Run(), and XrdOucProg::Run().

+ Here is the caller graph for this function:

◆ FDNum()

int XrdOucStream::FDNum ( )
inline

Definition at line 110 of file XrdOucStream.hh.

110 {return FD;}

Referenced by XrdCmsFinderTRG::Start().

+ Here is the caller graph for this function:

◆ FENum()

int XrdOucStream::FENum ( )
inline

Definition at line 111 of file XrdOucStream.hh.

111 {return FE;}

◆ Flush()

void XrdOucStream::Flush ( )
inline

Definition at line 115 of file XrdOucStream.hh.

115 {fsync(FD); if (FE != FD) fsync(FE);}
int fsync(int fildes)

References fsync().

+ Here is the call graph for this function:

◆ GetFirstWord()

char * XrdOucStream::GetFirstWord ( int  lowcase = 0)

Definition at line 680 of file XrdOucStream.cc.

681 {
682  // If in the middle of a line, flush to the end of the line. Suppress
683  // variable substitution when doing this to avoid errors.
684  //
685  if (xline)
686  {XrdOucEnv *oldEnv = SetEnv(0);
687  while(GetWord(lowcase)) {}
688  SetEnv(oldEnv);
689  }
690  return GetWord(lowcase);
691 }
char * GetWord(int lowcase=0)
XrdOucEnv * SetEnv(XrdOucEnv *newEnv)

References GetWord(), and SetEnv().

Referenced by GetMyFirstWord().

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

◆ GetLine()

char * XrdOucStream::GetLine ( )

Definition at line 554 of file XrdOucStream.cc.

555 {
556  int bcnt, retc;
557  char *bp;
558 
559 // Check if end of message has been reached.
560 //
561  if (flags & XrdOucStream_EOM) return (char *)NULL;
562 
563 // Find the next record in the buffer
564 //
565  if (bleft > 0)
566  {recp = bnext; bcnt = bleft;
567  for (bp = bnext; bcnt--; bp++)
568  if (!*bp || *bp == '\n')
569  {if (!*bp) flags |= XrdOucStream_EOM;
570  *bp = '\0';
571  bnext = ++bp;
572  bleft = bcnt;
573  token = recp;
574  return recp;
575  }
576  else if (notabs && *bp == '\t') *bp = ' ';
577 
578  // There is no next record, so move up data in the buffer.
579  //
580  strncpy(buff, bnext, bleft);
581  bnext = buff + bleft;
582  }
583  else bnext = buff;
584 
585 // Prepare to read in more data.
586 //
587  bcnt = bsize - (bnext - buff) -1;
588  bp = bnext;
589 
590 // Read up to the maximum number of bytes. Stop reading should we see a
591 // new-line character or a null byte -- the end of a record.
592 //
593  recp = token = buff; // This will always be true at this point
594  while(bcnt)
595  {do { retc = read(FD, (void *)bp, (size_t)bcnt); }
596  while (retc < 0 && errno == EINTR);
597 
598  if (retc < 0) {Erp(GetLine,errno,"read request",0); return (char *)0;}
599  if (!retc)
600  {*bp = '\0';
601  flags |= XrdOucStream_EOM;
602  bnext = ++bp;
603  bleft = 0;
604  return buff;
605  }
606 
607  bcnt -= retc;
608  while(retc--)
609  if (!*bp || *bp == '\n')
610  {if (!*bp) flags |= XrdOucStream_EOM;
611  else *bp = '\0';
612  bnext = ++bp;
613  bleft = retc;
614  return buff;
615  } else {
616  if (notabs && *bp == '\t') *bp = ' ';
617  bp++;
618  }
619  }
620 
621 // All done, force an end of record.
622 //
623  Erp(GetLine, EMSGSIZE, "read full message", 0);
624  buff[bsize-1] = '\0';
625  return buff;
626 }
#define XrdOucStream_EOM
Definition: XrdOucStream.cc:72
#define Erp(p, a, b, c)
Definition: XrdOucStream.cc:82
ssize_t read(int fildes, void *buf, size_t nbyte)
char * GetLine()

References Erp, read(), and XrdOucStream_EOM.

Referenced by XrdXrootdJob2Do::DoIt(), GetWord(), XrdFrcCID::Init(), XrdXrootdAdmin::Login(), main(), XrdOssCache::MapDevs(), XrdOssSys::MSS_Readdir(), XrdOssSys::MSS_Xeq(), XrdFrmXfrDaemon::Pong(), XrdOfsEvr::recvEvents(), XrdCmsMeter::Run(), XrdOucProg::Run(), XrdOfsPrepGPIReal::PrepGRun::Run(), XrdFrmXfrAgent::Start(), and XrdOfsTPCProg::Xeq().

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

◆ GetMyFirstWord()

char * XrdOucStream::GetMyFirstWord ( int  lowcase = 0)

Definition at line 697 of file XrdOucStream.cc.

698 {
699  char *var;
700  int skip2fi = 0;
701 
702  Echo();
703 
704  if (!myInst)
705  {if (!myEnv) return add2llB(GetFirstWord(lowcase), 1);
706  else {while((var = GetFirstWord(lowcase)) && !isSet(var)) {}
707  return add2llB(var, 1);
708  }
709  }
710 
711  do {if (!(var = GetFirstWord(lowcase)))
712  {if (sawif && !ecode)
713  {ecode = EINVAL;
714  if (Eroute) Eroute->Emsg("Stream", "Missing 'fi' for last 'if'.");
715  }
716  return add2llB(var, 1);
717  }
718 
719  add2llB(var, 1);
720 
721  if (!strcmp("continue", var))
722  {if (!docont()) return 0;
723  continue;
724  }
725 
726  if ( !strcmp("if", var)) var = doif();
727  if (var && !strcmp("else", var)) var = doelse();
728  if (var && !strcmp("fi", var))
729  {if (sawif) sawif = skpel = skip2fi = 0;
730  else {if (Eroute)
731  Eroute->Emsg("Stream", "No preceding 'if' for 'fi'.");
732  ecode = EINVAL;
733  }
734  continue;
735  }
736  if (var && (!myEnv || !isSet(var))) return add2llB(var, 1);
737  } while (1);
738 
739  return 0;
740 }
char * GetFirstWord(int lowcase=0)
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
Definition: XrdSysError.cc:95

References Echo(), XrdSysError::Emsg(), and GetFirstWord().

Referenced by Macaroons::Handler::Config(), and XrdVomsMapfile::Configure().

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

◆ GetRest()

int XrdOucStream::GetRest ( char *  theBuf,
int  Blen,
int  lowcase = 0 
)

Definition at line 810 of file XrdOucStream.cc.

811 {
812  char *tp, *myBuff = theBuff;
813  int tlen;
814 
815 // Get remaining tokens
816 //
817  theBuff[0] = '\0';
818  while ((tp = GetWord(lowcase)))
819  {tlen = strlen(tp);
820  if (tlen+1 >= Blen) return 0;
821  if (myBuff != theBuff) {*myBuff++ = ' '; Blen--;}
822  strcpy(myBuff, tp);
823  Blen -= tlen; myBuff += tlen;
824  }
825 
826 // All done
827 //
828  add2llB(0);
829  return 1;
830 }

References GetWord().

+ Here is the call graph for this function:

◆ GetToken() [1/2]

char * XrdOucStream::GetToken ( char **  rest,
int  lowcase = 0 
)

Definition at line 657 of file XrdOucStream.cc.

658 {
659  char *tpoint;
660 
661  // Get the next token
662  //
663  if (!(tpoint = GetToken(lowcase))) return tpoint;
664 
665  // Skip to the first non-blank character.
666  //
667  while (*token && *token == ' ') token ++;
668  if (rest) *rest = token;
669 
670 
671  // All done.
672  //
673  return tpoint;
674 }
char * GetToken(int lowcase=0)

References GetToken().

+ Here is the call graph for this function:

◆ GetToken() [2/2]

char * XrdOucStream::GetToken ( int  lowcase = 0)

Definition at line 632 of file XrdOucStream.cc.

632  {
633  char *tpoint;
634 
635  // Verify that we have a token to return;
636  //
637  if (!token) return (char *)NULL;
638 
639  // Skip to the first non-blank character.
640  //
641  while (*token && *token == ' ') token ++;
642  if (!*token) {token = 0; return 0;}
643  tpoint = token;
644 
645  // Find the end of the token.
646  //
647  if (lowcase) while (*token && *token != ' ')
648  {*token = (char)tolower((int)*token); token++;}
649  else while (*token && *token != ' ') {token++;}
650  if (*token) {*token = '\0'; token++;}
651 
652  // All done here.
653  //
654  return tpoint;
655 }

Referenced by GetToken(), GetWord(), XrdXrootdAdmin::Login(), main(), XrdOssCache::MapDevs(), XrdFrmXfrDaemon::Pong(), XrdFrmXfrAgent::Process(), and XrdOfsEvr::recvEvents().

+ Here is the caller graph for this function:

◆ GetWord()

char * XrdOucStream::GetWord ( int  lowcase = 0)

Definition at line 746 of file XrdOucStream.cc.

747 {
748  char *wp, *ep;
749 
750  // A call means the first token was acceptable and we continuing to
751  // parse, hence the line is echoable.
752  //
753  if (llBok == 1) llBok = 2;
754 
755  // If we have a token, return it
756  //
757  xline = 1;
758  while((wp = GetToken(lowcase)))
759  {if (!myEnv) return add2llB(wp);
760  if ((wp = vSubs(wp)) && *wp) return add2llB(wp);
761  }
762 
763  // If no continuation allowed, return a null (but only once)
764  //
765  if (!xcont) {xcont = 1; xline = 0; return (char *)0;}
766 
767  // Find the next non-blank non-comment line
768  //
769 do {while(GetLine())
770  {// Get the first token (none if it is a blank line)
771  //
772  if (!(wp = GetToken(lowcase))) continue;
773 
774  // If token starts with a pound sign, skip the line
775  //
776  if (*wp == '#') continue;
777 
778  // Process continuations (last non-blank character is a back-slash)
779  //
780  ep = bnext-2;
781  while (ep >= buff && *ep == ' ') ep--;
782  if (ep < buff) continue;
783  if (*ep == '\\') {xcont = 1; *ep = '\0';}
784  else xcont = 0;
785  return add2llB((myEnv ? vSubs(wp) : wp));
786  }
787 
788  if (myInfo && myInfo->fcList)
789  {if (myInfo->itFC == myInfo->fcList->end())
790  {bleft = 0;
791  flags |= XrdOucStream_EOM;
792  break;
793  }
794  const char *path = (*(myInfo->itFC)).c_str();
795  myInfo->itFC++;
796  if (!docontF(path)) break;
797  bleft = 0;
798  flags &= ~XrdOucStream_EOM;
799  } else break;
800  } while(true);
801 
802  xline = 0;
803  return (char *)0;
804 }
std::set< std::string > * fcList
std::set< std::string >::iterator itFC

References StreamInfo::fcList, GetLine(), GetToken(), StreamInfo::itFC, and XrdOucStream_EOM.

Referenced by XrdVomsMapfile::Configure(), GetFirstWord(), XrdAccAuthFile::getID(), XrdAccAuthFile::getPP(), XrdAccAuthFile::getRec(), GetRest(), XrdCmsUtils::ParseManPort(), and xonmissing().

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

◆ isAlive()

int XrdOucStream::isAlive ( )
inline

Definition at line 156 of file XrdOucStream.hh.

156 {return (child ? kill(child,0) == 0 : 0);}

Referenced by XrdCmsPrepare::Add(), XrdCmsPrepare::Del(), and XrdOucProg::Feed().

+ Here is the caller graph for this function:

◆ LastError()

int XrdOucStream::LastError ( )
inline

Definition at line 163 of file XrdOucStream.hh.

163 {int n = ecode; ecode = 0; return n;}

Referenced by XrdSsiSfsConfig::Configure(), XrdOucProg::Feed(), XrdFrcCID::Init(), XrdOssSys::MSS_Readdir(), XrdAccAuthFile::Open(), and XrdOucProg::Run().

+ Here is the caller graph for this function:

◆ LastLine()

char* XrdOucStream::LastLine ( )
inline

Definition at line 167 of file XrdOucStream.hh.

167 {return recp;}

◆ noEcho()

int XrdOucStream::noEcho ( )
inline

Definition at line 171 of file XrdOucStream.hh.

171 {llBok = 0; return 0;}

◆ Put() [1/3]

int XrdOucStream::Put ( const char *  data)
inline

Definition at line 177 of file XrdOucStream.hh.

177 {return Put(data, strlen(data));}
int Put(const char *data, const int dlen)

References Put().

Referenced by Put().

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

◆ Put() [2/3]

int XrdOucStream::Put ( const char *  data,
const int  dlen 
)

Definition at line 862 of file XrdOucStream.cc.

862  {
863  int dcnt = dlen, retc;
864 
865  if (flags & XrdOucStream_BUSY) {ecode = ETXTBSY; return -1;}
866 
867  while(dcnt)
868  {do { retc = write(FE, (const void *)data, (size_t)dlen);}
869  while (retc < 0 && errno == EINTR);
870  if (retc >= 0) dcnt -= retc;
871  else {flags |= XrdOucStream_BUSY;
872  Erp(Put, errno, "write to stream", 0);
873  flags &= ~XrdOucStream_BUSY;
874  return -1;
875  }
876  }
877  return 0;
878 }
#define XrdOucStream_BUSY
Definition: XrdOucStream.cc:73
ssize_t write(int fildes, const void *buf, size_t nbyte)

References Erp, write(), and XrdOucStream_BUSY.

Referenced by XrdCmsPrepare::Add(), XrdCmsFinderTRG::Added(), XrdCmsPrepare::Del(), XrdOucProg::Feed(), Put(), XrdCmsFinderTRG::PutInfo(), XrdCmsFinderTRG::Removed(), XrdCmsFinderTRG::Resume(), XrdOucERoute::Route(), XrdCmsFinderTRG::Start(), and XrdCmsFinderTRG::Suspend().

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

◆ Put() [3/3]

int XrdOucStream::Put ( const char *  data[],
const int  dlen[] 
)

Definition at line 880 of file XrdOucStream.cc.

880  {
881  int i, retc, dlen;
882  const char *data;
883 
884  if (flags & XrdOucStream_BUSY) {ecode = ETXTBSY; return -1;}
885 
886  for (i = 0; datavec[i]; i++)
887  {data = datavec[i]; dlen = dlenvec[i];
888  while(dlen)
889  {do { retc = write(FE, (const void *)data, (size_t)dlen);}
890  while (retc < 0 && errno == EINTR);
891  if (retc >= 0) {data += retc; dlen -= retc;}
892  else {flags |= XrdOucStream_BUSY;
893  Erp(Put, errno, "write to stream",0);
894  flags &= ~XrdOucStream_BUSY;
895  return -1;
896  }
897  }
898  }
899  return 0;
900 }

References Erp, Put(), write(), and XrdOucStream_BUSY.

+ Here is the call graph for this function:

◆ PutLine()

int XrdOucStream::PutLine ( const char *  data,
int  dlen = 0 
)

Definition at line 906 of file XrdOucStream.cc.

907 {
908  static const int plSize = 2048;
909 
910 // Allocate a buffer if one is not allocated
911 //
912  if (!buff)
913  {if (!(buff = (char *)malloc(plSize)))
914  return Erq(Attach, errno, "allocate stream buffer");
915  bsize = plSize;
916  }
917 
918 // Adjust dlen
919 //
920  if (dlen <= 0) dlen = strlen(data);
921  if (dlen >= bsize) dlen = bsize-1;
922 
923 // Simply insert the line into the buffer, truncating if need be
924 //
925  bnext = recp = token = buff; // This will always be true at this point
926  if (dlen <= 0)
927  {*buff = '\0';
928  flags |= XrdOucStream_EOM;
929  bleft = 0;
930  } else {
931  strncpy(buff, data, dlen);
932  *(buff+dlen) = 0;
933  bleft = dlen+1;
934  }
935 // All done
936 //
937  return 0;
938 }

References Attach(), Erq, and XrdOucStream_EOM.

+ Here is the call graph for this function:

◆ RetToken()

void XrdOucStream::RetToken ( )

Definition at line 836 of file XrdOucStream.cc.

837 {
838  // Check if we can back up
839  //
840  if (!token || token == recp) return;
841 
842  // Find the null byte for the token and remove it, if possible
843  //
844  while(*token && token != recp) token--;
845  if (token != recp)
846  {if (token+1 != bnext) *token = ' ';
847  token--;
848  while(*token && *token != ' ' && token != recp) token--;
849  if (token != recp) token++;
850  }
851 
852  // If saving line, we must do the same for the saved line
853  //
854  if (llBuff)
855  while(llBcur != llBuff && *llBcur != ' ') {llBcur--; llBleft++;}
856 }

◆ SetEnv()

XrdOucEnv* XrdOucStream::SetEnv ( XrdOucEnv newEnv)
inline

Definition at line 191 of file XrdOucStream.hh.

192  {XrdOucEnv *oldEnv = myEnv; myEnv = newEnv; return oldEnv;}

Referenced by GetFirstWord(), and XrdOucProg::Run().

+ Here is the caller graph for this function:

◆ SetEroute()

void XrdOucStream::SetEroute ( XrdSysError eroute)
inline

Definition at line 196 of file XrdOucStream.hh.

196 {Eroute = eroute;}

Referenced by XrdXrootdAdmin::Login(), and XrdAccAuthFile::Open().

+ Here is the caller graph for this function:

◆ Tabs()

void XrdOucStream::Tabs ( int  x = 1)
inline

Definition at line 201 of file XrdOucStream.hh.

201 {notabs = !x;}

Referenced by XrdAccAuthFile::Open().

+ Here is the caller graph for this function:

◆ Wait4Data()

int XrdOucStream::Wait4Data ( int  msMax = -1)

Definition at line 944 of file XrdOucStream.cc.

945 {
946  struct pollfd polltab = {FD, POLLIN|POLLRDNORM, 0};
947  int retc;
948 
949 // Wait until we can actually read something
950 //
951  do {retc = poll(&polltab, 1, msMax);} while(retc < 0 && errno == EINTR);
952  if (retc != 1) return (retc ? errno : -1);
953 
954 // Return correct value
955 //
956  return (polltab.revents & (POLLIN|POLLRDNORM) ? 0 : EIO);
957 }

Referenced by XrdOssSys::MSS_Xeq().

+ Here is the caller graph for this function:

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