Loading...
Searching...
No Matches
XrdXmlRdrTiny Class Reference

`#include <XrdXmlRdrTiny.hh>`

Inheritance diagram for XrdXmlRdrTiny:
Collaboration diagram for XrdXmlRdrTiny:

## Public Member Functions

| XrdXmlRdrTiny (bool &aOK, const char *fname, const char *enc=0)
| Constructor & Destructor.
virtual | ~XrdXmlRdrTiny ()
virtual bool | GetAttributes (const char **aname, char **aval)
virtual int | GetElement (const char **ename, bool reqd=false)
virtual const char * | GetError (int &ecode)
virtual char * | GetText (const char *ename, bool reqd=false)
Public Member Functions inherited from XrdXmlReader
| XrdXmlReader ()
| Constructor & Destructor.
virtual | ~XrdXmlReader ()

## Static Public Member Functions

static bool | Init ()
Static Public Member Functions inherited from XrdXmlReader
static XrdXmlReader * | GetReader (const char *fname, const char *enc=0, const char *impl=0)
static bool | Init (const char *impl=0)

## Detailed Description

Definition at line 42 of file XrdXmlRdrTiny.hh.

## Constructor & Destructor Documentation

## XrdXmlRdrTiny()

XrdXmlRdrTiny::XrdXmlRdrTiny | ( | bool & | aOK,
|  | const char * | fname,
|  | const char * | enc = 0 )

Constructor & Destructor.

Definition at line 83 of file XrdXmlRdrTiny.cc.

: reader(0) // make sure the pointer is nil initialized otherwise if stat fails the destructor segfaults
{
struct stat Stat;
const char *etext;
// Initialize the standard values
//
curNode = 0;
curElem = 0;
elmNode = 0;
eCode = 0;
*eText = 0;
debug = getenv("XrdXmlDEBUG") != 0;
// Make sure this file exists
//
if (stat(fname, &Stat))
{eCode = errno;
snprintf(eText,sizeof(eText),"%s opening %s", XrdSysE2T(errno), fname);
aOK = false;
return;
}
// Get a file reader
//
reader = new TiXmlDocument(fname);
if (reader->LoadFile())
{curNode = (TiXmlNode *)reader;
curElem = 0;
elmNode = curNode;
aOK = true;
} else {
if (!(etext = reader->ErrorDesc()) || *etext)
{if ((eCode = errno)) etext = XrdSysE2T(errno);
else etext = "Unknown error";
}
snprintf(eText,sizeof(eText),"%s opening %s", etext, fname);
eCode = EINVAL;
aOK = false;
}
}
Stat
struct stat Stat
Definition XrdCks.cc:49
stat
#define stat(a, b)
Definition XrdPosix.hh:101
XrdSysE2T
const char * XrdSysE2T(int errcode)
Definition XrdSysE2T.cc:104

References Stat, stat, and XrdSysE2T().

Here is the call graph for this function:

## ~XrdXmlRdrTiny()

XrdXmlRdrTiny::~XrdXmlRdrTiny | ( |  | ) |

virtual

Definition at line 129 of file XrdXmlRdrTiny.cc.

{
// Tear down the reader
//
if (reader)
{
delete reader;
reader = 0;
}
}

## Member Function Documentation

## GetAttributes()

bool XrdXmlRdrTiny::GetAttributes | ( | const char ** | aname,
|  | char ** | aval )

virtual

Get attributes from an XML tag. GetAttributes() should only be called after a successful GetElement() call.

Parameters

  aname | Pointer to an array of attribute names whose values are to be returned. The last entry in the array must be nil.
  aval | Pointer to an array where the corresponding attribute values are to be placed in 1-to-1 correspondence. The values must be freed using free().

Returns
  true One or more attributes have been returned. false No specified attributes were found.

Implements XrdXmlReader.

Definition at line 161 of file XrdXmlRdrTiny.cc.

{
const char *value;
int i = 0;
bool found = false;
// If we are not at the begining of an element, this is a sequence error
//
if (!curElem)
{snprintf(eText, sizeof(eText),
"Element not fetched when seeking attribute %s",aname[0]);
eCode = EILSEQ;
return false;
}
// Find all the requested attributes
//
while(aname[i])
{if ((value = curElem->Attribute(aname[i])))
{if (aval[i]) free(aval[i]);
aval[i] = strdup(value);
found = true;
}
i++;
}
// All done
//
return found;
}

## GetElement()

int XrdXmlRdrTiny::GetElement | ( | const char ** | ename,
|  | bool | reqd = false )

virtual

Find an XML tag element.

Parameters

  ename | Pointer to an array of tag names any of which should be searched for. The last entry in the array must be nil. The first element of the array should contain the name of the context tag. Elements are searched only within the scope of that tag. When searching for the first desired tag, use a null string to indicate document scope.
  reqd | When true one of the tag elements listed in ename must be found otherwise an error is generated.

Returns
  =0 No specified tag was found. Note that this corresponds to encountering the tag present in ename[0], i.e. scope end. >0 A tag was found, the return value is the index into ename that corresponds to the tag's name.

Implements XrdXmlReader.

Definition at line 196 of file XrdXmlRdrTiny.cc.

{
TiXmlNode *theChild;
const char *name = (curNode ? curNode->Value() : 0);
int i;
// If we are positioned either at the current node or the last node we returned
// Complain if that is not the case.
//
if (*ename[0])
{if (name && strcmp(name, ename[0]))
{if (curElem && !strcmp(elmNode->Value(),ename[0])) curNode = elmNode;
else {snprintf(eText, sizeof(eText),
"Current context '%s' does not match stated scope '%s'",
(name ? name : ""), ename[0]);
eCode = EILSEQ;
return false;
}
}
}
// Sequence to the next node at appropriate level.
//
if (curNode == elmNode ) theChild = curNode->FirstChild();
else if (elmNode) theChild = elmNode->NextSibling();
else theChild = curNode->NextSibling();
// Scan over to the first wanted element
//
while(theChild)
{if ((name = theChild->Value()) && theChild->Type() == ntElmBeg)
{i = 1;
while(ename[i] && strcmp(name, ename[i])) i++;
if (ename[i])
{if (debug) Debug("getelem:",ename[i],name,ename[0],ntElmBeg);
curElem = theChild->ToElement();
elmNode = theChild;
return i;
}
}
theChild = theChild->NextSibling();
}
// We didn't find any wanted tag here in this scope. Transition to the element's
// parent we finished the tag
//
if (debug) Debug("getelem:",ename[1],ename[0],ename[0],ntElmEnd);
elmNode = curNode;
curNode = curNode->Parent();
curElem = 0;
return 0;
// This is an error if this element was required
//
if (reqd)
{snprintf(eText,sizeof(eText),"Required element '%s' not found in '%s'",
(ename[1] ? ename[1] : "???"), ename[0]);
eCode = ESRCH;
}
return 0;
}
Debug
bool Debug
Definition XrdSecgsiProxy.cc:95

References Debug.

## GetError()

virtual const char * XrdXmlRdrTiny::GetError | ( | int & | ecode | ) |

inline virtual

Get the description of the last error encountered.

Parameters

  ecode | The error code associated with the error.

Returns
  Pointer to text describing the error. The text may be destroyed on a subsequent call to any other method. Otherwise it is stable. A nil pointer indicates that no error is present.

Implements XrdXmlReader.

Definition at line 51 of file XrdXmlRdrTiny.hh.

{return ((ecode = eCode) ? eText : 0);}

## GetText()

char * XrdXmlRdrTiny::GetText | ( | const char * | ename,
|  | bool | reqd = false )

virtual

Get the text portion of an XML tag element. GetText() should only be called after a successful call to GetElement() with a possibly intervening call to GetAttributes().

Parameters

  ename | Pointer to the corresponding tag name.
  reqd | When true text must exist and not be null. Otherwise, an error is generated if the text is missing or null.

Returns
  =0 No text found.
  !0 Pointer to the tag's text field. It must be free using free().

Implements XrdXmlReader.

Definition at line 263 of file XrdXmlRdrTiny.cc.

{
const char *value;
char *sP;
// If we are not at the begining of an element, this is a sequence error
//
if (!curElem)
{snprintf(eText, sizeof(eText),
"Illegal position seeking text for tag %s",ename);
eCode = EILSEQ;
return 0;
}
// Get the text associated with element (simple text only)
//
value = curElem->GetText();
// We did not find a value. If not required return.
//
if (value || !reqd)
{if (!value) return 0;
sP = strdup(value);
return sP;
}
// Create error message
//
snprintf(eText, sizeof(eText), "Required %s tag value not found", ename);
eCode = ENOMSG;
return 0;
}

## Init()

bool XrdXmlRdrTiny::Init | ( |  | ) |

static

Definition at line 300 of file XrdXmlRdrTiny.cc.

{return true;}

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

- XrdXmlRdrTiny.hh
- XrdXmlRdrTiny.cc