1
0
mirror of https://gitlab.xiph.org/xiph/icecast-server.git synced 2024-09-22 04:15:54 -04:00

Feature: Added a way to find a node by attribute (useful for IDs).

This commit is contained in:
Philipp Schafft 2018-06-27 10:00:21 +00:00
parent 32a410bdd6
commit 86a62889d2
2 changed files with 44 additions and 0 deletions

View File

@ -217,6 +217,14 @@ reportxml_node_t * reportxml_get_root_node(reportxml_t *report)
return report->root;
}
reportxml_node_t * reportxml_get_node_by_attribute(reportxml_t *report, const char *key, const char *value, int include_definitions)
{
if (!report || !key || !value)
return NULL;
return reportxml_node_get_child_by_attribute(report->root, key, value, include_definitions);
}
reportxml_t * reportxml_parse_xmldoc(xmlDocPtr doc)
{
reportxml_node_t *root;
@ -652,6 +660,40 @@ reportxml_node_t * reportxml_node_get_child(reportxml_node_t *node, size_t
return node->childs[idx];
}
reportxml_node_t * reportxml_node_get_child_by_attribute(reportxml_node_t *node, const char *key, const char *value, int include_definitions)
{
reportxml_node_t *ret;
xmlChar *k;
size_t i;
if (!node || !key ||!value)
return NULL;
k = xmlGetProp(node->xmlnode, XMLSTR(key));
if (k != NULL) {
if (strcmp((const char*)k, value) == 0) {
xmlFree(k);
if (refobject_ref(node) != 0)
return NULL;
return node;
}
xmlFree(k);
}
if (node->type == REPORTXML_NODE_TYPE_DEFINITION && !include_definitions)
return NULL;
for (i = 0; i < node->childs_len; i++) {
ret = reportxml_node_get_child_by_attribute(node->childs[i], key, value, include_definitions);
if (ret != NULL)
return ret;
}
return NULL;
}
int reportxml_node_set_content(reportxml_node_t *node, const char *value)
{
const struct nodedef *nodedef;

View File

@ -36,6 +36,7 @@ typedef enum {
reportxml_t * reportxml_new(void);
reportxml_node_t * reportxml_get_root_node(reportxml_t *report);
reportxml_node_t * reportxml_get_node_by_attribute(reportxml_t *report, const char *key, const char *value, int include_definitions);
reportxml_t * reportxml_parse_xmldoc(xmlDocPtr doc);
xmlDocPtr reportxml_render_xmldoc(reportxml_t *report);
@ -49,6 +50,7 @@ char * reportxml_node_get_attribute(reportxml_node_t *node, con
int reportxml_node_add_child(reportxml_node_t *node, reportxml_node_t *child);
ssize_t reportxml_node_count_child(reportxml_node_t *node);
reportxml_node_t * reportxml_node_get_child(reportxml_node_t *node, size_t idx);
reportxml_node_t * reportxml_node_get_child_by_attribute(reportxml_node_t *node, const char *key, const char *value, int include_definitions);
int reportxml_node_set_content(reportxml_node_t *node, const char *value);
char * reportxml_node_get_content(reportxml_node_t *node);