1 /* @(#) $Id: ./src/os_xml/os_xml_node_access.c, 2011/09/08 dcid Exp $
4 /* Copyright (C) 2009 Trend Micro Inc.
7 * This program is a free software; you can redistribute it
8 * and/or modify it under the terms of the GNU General Public
9 * License (version 2) as published by the FSF - Free Software
14 * Available at http://www.ossec.net/
26 * Clear the Node structure
28 void OS_ClearNode(xml_node **node)
37 free(node[i]->element);
41 free(node[i]->content);
43 if(node[i]->attributes)
46 while(node[i]->attributes[j])
48 free(node[i]->attributes[j]);
51 free(node[i]->attributes);
56 while(node[i]->values[j])
58 free(node[i]->values[j]);
61 free(node[i]->values);
64 node[i]->element=NULL;
65 node[i]->content=NULL;
66 node[i]->attributes=NULL;
78 /** xml_node **OS_GetElementsbyNode(OS_XML *_lxml, xml_node *node)
79 * Get the elements by node.
81 xml_node **OS_GetElementsbyNode(OS_XML *_lxml, xml_node *node)
98 for(;i<_lxml->cur;i++)
100 if(_lxml->tp[i] == XML_ELEM)
102 if((_lxml->rl[i] == j+1) && (_lxml->el[i] != NULL))
105 /* Allocating for xml_node ** */
106 ret = (xml_node**)realloc(ret,(k+1)*sizeof(xml_node*));
110 /* Allocating for the xml_node * */
111 ret[k] = (xml_node *)calloc(1,sizeof(xml_node));
115 ret[k]->element = NULL;
116 ret[k]->content = NULL;
117 ret[k]->attributes = NULL;
118 ret[k]->values = NULL;
120 /* Getting the element */
121 ret[k]->element=strdup(_lxml->el[i]);
122 if(ret[k]->element == NULL)
128 /* Getting the content */
131 ret[k]->content=strdup(_lxml->ct[i]);
132 if(ret[k]->content == NULL)
135 /* Assigning the key */
138 /* Getting attributes */
139 while(l < _lxml->cur)
141 if((_lxml->tp[l] == XML_ATTR)&&(_lxml->rl[l] == j+1)&&
142 (_lxml->el[l]) && (_lxml->ct[l]))
145 (char**)realloc(ret[k]->attributes,
146 (l-i+1)*sizeof(char*));
148 (char**)realloc(ret[k]->values,
149 (l-i+1)*sizeof(char*));
150 if(!(ret[k]->attributes) ||
153 ret[k]->attributes[l-i-1]=strdup(_lxml->el[l]);
154 ret[k]->values[l-i-1] = strdup(_lxml->ct[l]);
155 if(!(ret[k]->attributes[l-i-1]) ||
156 !(ret[k]->values[l-i-1]))
165 if(ret[k]->attributes)
167 ret[k]->attributes[l-i-1] = NULL;
168 ret[k]->values[l-i-1] = NULL;
174 if((_lxml->tp[i] == XML_ELEM)&&(j+1 > _lxml->rl[i]))
186 ret = (xml_node **)realloc(ret,(k+1)*sizeof(xml_node *));