3 /* Copyright (C) 2009 Trend Micro Inc.
6 * This program is a free software; you can redistribute it
7 * and/or modify it under the terms of the GNU General Public
8 * License (version 2) as published by the FSF - Free Software
13 * Available at http://www.ossec.net/
25 * Clear the Node structure
27 void OS_ClearNode(xml_node **node)
36 free(node[i]->element);
40 free(node[i]->content);
42 if(node[i]->attributes)
45 while(node[i]->attributes[j])
47 free(node[i]->attributes[j]);
50 free(node[i]->attributes);
55 while(node[i]->values[j])
57 free(node[i]->values[j]);
60 free(node[i]->values);
63 node[i]->element=NULL;
64 node[i]->content=NULL;
65 node[i]->attributes=NULL;
77 /** xml_node **OS_GetElementsbyNode(OS_XML *_lxml, xml_node *node)
78 * Get the elements by node.
80 xml_node **OS_GetElementsbyNode(OS_XML *_lxml, xml_node *node)
97 for(;i<_lxml->cur;i++)
99 if(_lxml->tp[i] == XML_ELEM)
101 if((_lxml->rl[i] == j+1) && (_lxml->el[i] != NULL))
104 /* Allocating for xml_node ** */
105 ret = (xml_node**)realloc(ret,(k+1)*sizeof(xml_node*));
109 /* Allocating for the xml_node * */
110 ret[k] = (xml_node *)calloc(1,sizeof(xml_node));
114 ret[k]->element = NULL;
115 ret[k]->content = NULL;
116 ret[k]->attributes = NULL;
117 ret[k]->values = NULL;
119 /* Getting the element */
120 ret[k]->element=strdup(_lxml->el[i]);
121 if(ret[k]->element == NULL)
127 /* Getting the content */
130 ret[k]->content=strdup(_lxml->ct[i]);
131 if(ret[k]->content == NULL)
134 /* Assigning the key */
137 /* Getting attributes */
138 while(l < _lxml->cur)
140 if((_lxml->tp[l] == XML_ATTR)&&(_lxml->rl[l] == j+1)&&
141 (_lxml->el[l]) && (_lxml->ct[l]))
144 (char**)realloc(ret[k]->attributes,
145 (l-i+1)*sizeof(char*));
147 (char**)realloc(ret[k]->values,
148 (l-i+1)*sizeof(char*));
149 if(!(ret[k]->attributes) ||
152 ret[k]->attributes[l-i-1]=strdup(_lxml->el[l]);
153 ret[k]->values[l-i-1] = strdup(_lxml->ct[l]);
154 if(!(ret[k]->attributes[l-i-1]) ||
155 !(ret[k]->values[l-i-1]))
164 if(ret[k]->attributes)
166 ret[k]->attributes[l-i-1] = NULL;
167 ret[k]->values[l-i-1] = NULL;
173 if((_lxml->tp[i] == XML_ELEM)&&(j+1 > _lxml->rl[i]))
185 ret = (xml_node **)realloc(ret,(k+1)*sizeof(xml_node *));