dnxXml.c File Reference

Implements DNX XML functionality. More...

#include "dnxXml.h"
#include "dnxProtocol.h"
#include "dnxError.h"
#include "dnxDebug.h"
#include "dnxLogging.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <syslog.h>
#include <assert.h>

Go to the source code of this file.

Defines

#define DNX_XML_MIN_HEADER   32

Functions

static int dnxXmlEscapeStr (char *outstr, char *instr, int maxbuf)
 Escape the text within XML strings - compliant with W3C.
static int dnxXmlUnescapeStr (char *outstr, char *instr, int maxbuf)
 Un-Escape the text within XML strings - compliant with W3C.
static int dnxXmlToString (DnxXmlType xType, void *xData, char *buf, int size)
 Convert an opaque pointer to C data into a dnx xml string format.
static int dnxXmlGetTagValue (DnxXmlBuf *xbuf, char *xTag, DnxXmlType xType, char *buf, int size)
 Locate and return an xml string element by tag value.
int dnxXmlOpen (DnxXmlBuf *xbuf, char *tag)
 Open and write header information to a dnx xml buffer.
int dnxXmlAdd (DnxXmlBuf *xbuf, char *xTag, DnxXmlType xType, void *xData)
 Add an XML data element to a dnx xml buffer.
int dnxXmlGet (DnxXmlBuf *xbuf, char *xTag, DnxXmlType xType, void *xData)
 Return the C data typed value associated with a specified tag.
int dnxXmlCmpStr (DnxXmlBuf *xbuf, char *xTag, char *cmpstr)
 Compare a string with an XML node text value.
int dnxXmlClose (DnxXmlBuf *xbuf)
 Validate and close a dnx xml buffer.


Detailed Description

Implements DNX XML functionality.

Author:
Robert W. Ingraham (dnx-devel@lists.sourceforge.net)
Attention:
Please submit patches to http://dnx.sourceforge.net

Definition in file dnxXml.c.


Define Documentation

#define DNX_XML_MIN_HEADER   32

Definition at line 42 of file dnxXml.c.

Referenced by dnxXmlAdd().


Function Documentation

int dnxXmlAdd ( DnxXmlBuf xbuf,
char *  xTag,
DnxXmlType  xType,
void *  xData 
)

Add an XML data element to a dnx xml buffer.

Parameters:
[out] xbuf - the dnx xml buffer to be appended to.
[in] xTag - the xml tag to use for this new data element.
[in] xType - the C data type of the xml element data.
[in] xData - an opaque pointer to a C data variable to be expressed in xml in xbuf.
Returns:
Zero on success, or a non-zero error value.

Definition at line 409 of file dnxXml.c.

References DnxXmlBuf::buf, DNX_ERR_CAPACITY, DNX_MAX_MSG, DNX_OK, DNX_XML_MIN_HEADER, dnxXmlToString(), and DnxXmlBuf::size.

Referenced by dnxSendJob(), dnxSendMgmtReply(), dnxSendMgmtRequest(), dnxSendNodeRequest(), and dnxSendResult().

int dnxXmlClose ( DnxXmlBuf xbuf  ) 

Validate and close a dnx xml buffer.

Parameters:
[in,out] xbuf - the buffer to be validated and closed.
Returns:
Zero on success, or a non-zero error value.

Definition at line 616 of file dnxXml.c.

References DnxXmlBuf::buf, DNX_ERR_CAPACITY, DNX_MAX_MSG, DNX_OK, and DnxXmlBuf::size.

Referenced by dnxSendJob(), dnxSendMgmtReply(), dnxSendMgmtRequest(), dnxSendNodeRequest(), and dnxSendResult().

int dnxXmlCmpStr ( DnxXmlBuf xbuf,
char *  xTag,
char *  cmpstr 
)

Compare a string with an XML node text value.

Parameters:
[in,out] xbuf - the buffer to be validated and closed.
[in] xTag - the tag for which to search in xbuf.
[in] cmpstr - the comparison string to match.
Returns:
Zero on match; non-zero on not found, or no match.

Definition at line 596 of file dnxXml.c.

References DNX_ERR_SYNTAX, DNX_MAX_MSG, DNX_OK, DNX_XML_STR, and dnxXmlGetTagValue().

Referenced by dnxWaitForJob(), dnxWaitForMgmtReply(), dnxWaitForMgmtRequest(), dnxWaitForNodeRequest(), and dnxWaitForResult().

static int dnxXmlEscapeStr ( char *  outstr,
char *  instr,
int  maxbuf 
) [static]

Escape the text within XML strings - compliant with W3C.

Todo:
Implement int dnxXmlTypeSize(DnxXmlType).
Routine donated by William Leibzon. Thanks William!

Parameters:
[out] outstr - escaped string is returned in this buffer.
[in] instr - string to be escaped is passed in this buffer.
[in] maxbuf - the maximum number of bytes in outstr on entry.
Returns:
Zero on success, or a non-zero error code.

Definition at line 60 of file dnxXml.c.

References DNX_ERR_CAPACITY, and DNX_OK.

Referenced by dnxXmlToString().

int dnxXmlGet ( DnxXmlBuf xbuf,
char *  xTag,
DnxXmlType  xType,
void *  xData 
)

Return the C data typed value associated with a specified tag.

Parameters:
[in] xbuf - the dnx xml buffer from which to extract a value.
[in] xTag - the tag for which to search in xbuf.
[in] xType - the C data type of the specified tag.
[out] xData - the address of storage for the returned C data value. Note that xData must be large enough to hold an element of the specified C data type. In the case of a string, xData actually accepts a char pointer, not character data of a specified length. Note also that the caller is responsible for freeing the memory returned if xType is DNX_XML_STR.
Returns:
Zero on success, or a non-zero error value.

Definition at line 447 of file dnxXml.c.

References DNX_ERR_INVALID, DNX_ERR_MEMORY, DNX_ERR_SYNTAX, DNX_MAX_MSG, DNX_OK, DNX_XML_INT, DNX_XML_LONG, DNX_XML_SHORT, DNX_XML_STR, DNX_XML_STR_UNESCAPED, DNX_XML_UINT, DNX_XML_ULONG, DNX_XML_USHORT, DNX_XML_XID, dnxXmlGetTagValue(), dnxXmlUnescapeStr(), and xstrdup.

Referenced by dnxWaitForJob(), dnxWaitForMgmtReply(), dnxWaitForMgmtRequest(), dnxWaitForNodeRequest(), and dnxWaitForResult().

static int dnxXmlGetTagValue ( DnxXmlBuf xbuf,
char *  xTag,
DnxXmlType  xType,
char *  buf,
int  size 
) [static]

Locate and return an xml string element by tag value.

Parameters:
[in] xbuf - the dnx xml buffer to search for xTag.
[in] xTag - the tag to search xbuf for.
[in] xType - the C data type of the element - not used.
[out] buf - the address of storage for the xml element matching the xml tag in xTag.
[in] size - the maximum number of bytes that may be written to buf.
Returns:
Zero on success, or a non-zero error value.

Definition at line 302 of file dnxXml.c.

References DnxXmlBuf::buf, DNX_ERR_SYNTAX, and DNX_OK.

Referenced by dnxXmlCmpStr(), and dnxXmlGet().

int dnxXmlOpen ( DnxXmlBuf xbuf,
char *  tag 
)

Open and write header information to a dnx xml buffer.

Parameters:
[out] xbuf - the dnx xml buffer to be opened.
[in] tag - the major xml request tag to write to xbuf.
Returns:
Always returns zero.

Definition at line 387 of file dnxXml.c.

References DnxXmlBuf::buf, DNX_OK, and DnxXmlBuf::size.

Referenced by dnxSendJob(), dnxSendMgmtReply(), dnxSendMgmtRequest(), dnxSendNodeRequest(), and dnxSendResult().

static int dnxXmlToString ( DnxXmlType  xType,
void *  xData,
char *  buf,
int  size 
) [static]

Convert an opaque pointer to C data into a dnx xml string format.

Parameters:
[in] xType - the C data type to be converted to an xml string.
[in] xData - an opaque pointer to the C data to be converted.
[out] buf - the address of storage for the returned xml string.
[in] size - the maximum number of bytes that may be written to buf.
Returns:
Zero on success, or a non-zero error value.

Definition at line 231 of file dnxXml.c.

References DNX_ERR_INVALID, DNX_OK, DNX_XML_INT, DNX_XML_LONG, DNX_XML_SHORT, DNX_XML_STR, DNX_XML_STR_UNESCAPED, DNX_XML_UINT, DNX_XML_ULONG, DNX_XML_USHORT, DNX_XML_XID, and dnxXmlEscapeStr().

Referenced by dnxXmlAdd().

static int dnxXmlUnescapeStr ( char *  outstr,
char *  instr,
int  maxbuf 
) [static]

Un-Escape the text within XML strings - compliant with W3C.

Routine donated by William Leibzon. Thanks William!

Parameters:
[out] outstr - unescaped string is returned in this buffer.
[in] instr - string to be unescaped is passed in this buffer.
[in] maxbuf - the maximum number of bytes in outstr on entry.
Returns:
Zero on success, or a non-zero error code.

Definition at line 143 of file dnxXml.c.

References DNX_ERR_CAPACITY, DNX_ERR_SYNTAX, DNX_OK, and dnxDebug().

Referenced by dnxXmlGet().


Generated on Tue Apr 13 15:48:08 2010 for DNX by  doxygen 1.5.6