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:43
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 447 of file XrdOucStream.cc.

448 {
449  int fildes[2], Child_in = -1, Child_out = -1, Child_log = -1;
450 
451  // Create a pipe. Minimize file descriptor leaks.
452  //
453  if (inrd >= 0)
454  {if (pipe(fildes))
455  return Err(Exec, errno, "create input pipe for", parm[0]);
456  else {
457  fcntl(fildes[0], F_SETFD, FD_CLOEXEC);
458  Attach(fildes[0]); Child_out = fildes[1];
459  }
460 
461  if (inrd)
462  {if (pipe(fildes))
463  return Err(Exec, errno, "create output pipe for", parm[0]);
464  else {
465  fcntl(fildes[1], F_SETFD, FD_CLOEXEC);
466  FE = fildes[1]; Child_in = fildes[0];
467  }
468  }
469  } else {Child_out = FD; Child_in = FE;}
470 
471  // Handle the standard error file descriptor
472  //
473  if (!efd) Child_log = (Eroute ? dup(Eroute->logger()->originalFD()) : -1);
474  else if (efd > 0) Child_log = efd;
475  else if (efd == -2){Child_log = Child_out; Child_out = -1;}
476  else if (efd == -3) Child_log = Child_out;
477 
478  // Fork a process first so we can pick up the next request. We also
479  // set the process group in case the child hasn't been able to do so.
480  // Make sure only one fork occurs at any one time (we are the only one).
481  //
482  forkMutex.Lock();
483  if ((child = fork()))
484  {if (child < 0)
485  {close(Child_in); close(Child_out); forkMutex.UnLock();
486  return Err(Exec, errno, "fork request process for", parm[0]);
487  }
488  close(Child_out);
489  if (inrd) close(Child_in );
490  if (!efd && Child_log >= 0) close(Child_log);
491  forkMutex.UnLock();
492  setpgid(child, child);
493  return 0;
494  }
495 
496  /*****************************************************************/
497  /* C h i l d P r o c e s s */
498  /*****************************************************************/
499 
500  // Redirect standard in if so requested
501  //
502  if (Child_in >= 0)
503  {if (inrd)
504  {if (dup2(Child_in, STDIN_FILENO) < 0)
505  {Erx(Exec, errno, "setting up standard in for " <<parm[0]);
506  _exit(255);
507  } else if (Child_in != Child_out) close(Child_in);
508  }
509  }
510 
511  // Reassign the stream to be standard out to capture all of the output.
512  //
513  if (Child_out >= 0)
514  {if (dup2(Child_out, STDOUT_FILENO) < 0)
515  {Erx(Exec, errno, "setting up standard out for " <<parm[0]);
516  _exit(255);
517  } else if (Child_out != Child_log) close(Child_out);
518  }
519 
520  // Redirect stderr of the stream if we can to avoid keeping the logfile open
521  //
522  if (Child_log >= 0)
523  {if (dup2(Child_log, STDERR_FILENO) < 0)
524  {Erx(Exec, errno, "set up standard err for " <<parm[0]);
525  _exit(255);
526  } else close(Child_log);
527  }
528 
529  // Check if we need to set any envornment variables
530  //
531  if (myEnv)
532  {char **envP;
533  int i = 0;
534  if ((envP = (char **)myEnv->GetPtr("XrdEnvars**")))
535  while(envP[i]) {putenv(envP[i]); i++;}
536  }
537 
538  // Set our process group (the parent should have done this by now) then
539  // invoke the command never to return
540  //
541  setpgid(0,0);
542  execv(parm[0], parm);
543  Erx(Exec, errno, "executing " <<parm[0]);
544  _exit(255);
545 }
#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  // Allocate a buffer for the command as we will be modifying it
425  //
426  origcmd = cmd = (char *)malloc(strlen(theCmd)+1);
427  strcpy(cmd, theCmd);
428 
429  // Construct the argv array based on passed command line.
430  //
431  for (j = 0; j < MaxARGC-1 && *cmd; j++)
432  {while(*cmd == ' ') cmd++;
433  if (!(*cmd)) break;
434  parm[j] = cmd;
435  while(*cmd && *cmd != ' ') cmd++;
436  if (*cmd) {*cmd = '\0'; cmd++;}
437  }
438  parm[j] = (char *)0;
439 
440  // Continue with normal processing
441  //
442  j = Exec(parm, inrd, efd);
443  free(origcmd);
444  return j;
445 }
#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 677 of file XrdOucStream.cc.

678 {
679  // If in the middle of a line, flush to the end of the line. Suppress
680  // variable substitution when doing this to avoid errors.
681  //
682  if (xline)
683  {XrdOucEnv *oldEnv = SetEnv(0);
684  while(GetWord(lowcase)) {}
685  SetEnv(oldEnv);
686  }
687  return GetWord(lowcase);
688 }
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 551 of file XrdOucStream.cc.

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

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

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

References GetWord().

+ Here is the call graph for this function:

◆ GetToken() [1/2]

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

Definition at line 654 of file XrdOucStream.cc.

655 {
656  char *tpoint;
657 
658  // Get the next token
659  //
660  if (!(tpoint = GetToken(lowcase))) return tpoint;
661 
662  // Skip to the first non-blank character.
663  //
664  while (*token && *token == ' ') token ++;
665  if (rest) *rest = token;
666 
667 
668  // All done.
669  //
670  return tpoint;
671 }
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 629 of file XrdOucStream.cc.

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

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 743 of file XrdOucStream.cc.

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

859  {
860  int dcnt = dlen, retc;
861 
862  if (flags & XrdOucStream_BUSY) {ecode = ETXTBSY; return -1;}
863 
864  while(dcnt)
865  {do { retc = write(FE, (const void *)data, (size_t)dlen);}
866  while (retc < 0 && errno == EINTR);
867  if (retc >= 0) dcnt -= retc;
868  else {flags |= XrdOucStream_BUSY;
869  Erp(Put, errno, "write to stream", 0);
870  flags &= ~XrdOucStream_BUSY;
871  return -1;
872  }
873  }
874  return 0;
875 }
#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 877 of file XrdOucStream.cc.

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

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 903 of file XrdOucStream.cc.

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

References Attach(), Erq, and XrdOucStream_EOM.

+ Here is the call graph for this function:

◆ RetToken()

void XrdOucStream::RetToken ( )

Definition at line 833 of file XrdOucStream.cc.

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

◆ 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 941 of file XrdOucStream.cc.

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

Referenced by XrdOssSys::MSS_Xeq().

+ Here is the caller graph for this function:

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