📄 icxmlnode.c
字号:
/* Copyright 2003-2006, Voltage Security, all rights reserved.
*/
#include "vibe.h"
#include "environment.h"
#include "base.h"
#include "libctx.h"
#include "icStringBuffer.h"
#include "icInputStream.h"
#include "icTable.h"
#include "icStack.h"
#include "icXmlNode.h"
#include "stringutil.h"
#include "errorctx.h"
int icXmlNodeCreate (
icXmlNode **node,
int node_type,
VoltLibCtx *libCtx
)
{
int status;
icXmlNode *newNode = (icXmlNode *)0;
VOLT_DECLARE_FNCT_LINE (fnctLine)
*node = (icXmlNode *)0;
do
{
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_MEMORY;
newNode = (icXmlNode *)Z3Malloc (sizeof (icXmlNode));
if (newNode == (icXmlNode *)0)
break;
Z2Memset (newNode, 0, sizeof (icXmlNode));
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_INPUT;
if ( (node_type != IC_XML_NODE_TAG) && (node_type != IC_XML_NODE_TEXT) )
break;
newNode->node_type = node_type;
*node = newNode;
status = 0;
} while (0);
if (status == 0)
return (0);
/* If there was an error, free memory we allocated.
*/
if (newNode != (icXmlNode *)0)
Z2Free (newNode);
VOLT_LOG_ERROR (
(VtLibCtx)libCtx, status, VT_ERROR_TYPE_PRIMARY, fnctLine,
"icXmlNodeCreate", (char *)0)
return (status);
}
void icXmlNodeFree (
icXmlNode **node,
VoltLibCtx *libCtx
)
{
int index;
icXmlNode *theNode;
/* Anything to free?
*/
if (node == (icXmlNode **)0)
return;
if (*node == (icXmlNode *)0)
return;
theNode = *node;
if (theNode->node_type == IC_XML_NODE_TEXT)
{
if (theNode->text != (char *)0)
Z2Free (theNode->text);
}
else
{
if (theNode->tag_name != (char *)0)
Z2Free (theNode->tag_name);
for (index = 0; index < theNode->num_children; ++index)
icXmlNodeFree (&(theNode->children[index]), libCtx);
icTableFree (&(theNode->attributes), libCtx);
if (theNode->children != (icXmlNode **)0)
Z2Free (theNode->children);
}
Z2Free (*node);
*node = (icXmlNode *)0;
}
int icXmlNodeAddChild (
icXmlNode *parent,
icXmlNode *child,
VoltLibCtx *libCtx
)
{
int status, index;
unsigned int bufferSize;
icXmlNode **newArray = (icXmlNode **)0;
VOLT_DECLARE_FNCT_LINE (fnctLine)
do
{
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_NULL_ARG;
if ( (parent == (icXmlNode *)0) || (child == (icXmlNode *)0) )
break;
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_MEMORY;
bufferSize = parent->num_children + 1;
bufferSize *= sizeof (icXmlNode *);
newArray = (icXmlNode **)Z3Malloc (bufferSize);
if (newArray == (icXmlNode **)0)
break;
Z2Memset (newArray, 0, bufferSize);
/* Copy the old into the new.
*/
for (index = 0; index < parent->num_children; ++index)
newArray[index] = parent->children[index];
/* Free the old.
*/
if (parent->children != (icXmlNode **)0)
Z2Free (parent->children);
/* Set the parent with the new.
*/
parent->children = newArray;
/* Add this child to the parent's array.
*/
parent->children[parent->num_children] = child;
parent->num_children++;
status = 0;
} while (0);
VOLT_LOG_ERROR_COMPARE (
status, (VtLibCtx)libCtx, status, VT_ERROR_TYPE_PRIMARY, fnctLine,
"icXmlNodeAddChild", (char *)0)
return (status);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -