1
0
mirror of https://gitlab.xiph.org/xiph/icecast-common.git synced 2024-12-04 14:46:31 -05:00

Feature: Allow working completly instance safe with igloo_reportxml_*()

This commit is contained in:
Philipp Schafft 2019-09-15 08:10:32 +00:00
parent 8baa9de529
commit bbfff1fd49
3 changed files with 16 additions and 16 deletions

View File

@ -86,7 +86,7 @@ igloo_reportxml_node_t * igloo_reportxml_get_node_by_attribute(igloo_report
/* This gets a node by it's type. Otherwise identical to igloo_reportxml_get_node_by_attribute() */ /* This gets a node by it's type. Otherwise identical to igloo_reportxml_get_node_by_attribute() */
igloo_reportxml_node_t * igloo_reportxml_get_node_by_type(igloo_reportxml_t *report, igloo_reportxml_node_type_t type, int include_definitions); igloo_reportxml_node_t * igloo_reportxml_get_node_by_type(igloo_reportxml_t *report, igloo_reportxml_node_type_t type, int include_definitions);
/* This function parses an XML document and returns the parst report XML document */ /* This function parses an XML document and returns the parst report XML document */
igloo_reportxml_t * igloo_reportxml_parse_xmldoc(xmlDocPtr doc); igloo_reportxml_t * igloo_reportxml_parse_xmldoc(xmlDocPtr doc, igloo_ro_t instance);
/* This function renders an report XML document as XML structure */ /* This function renders an report XML document as XML structure */
xmlDocPtr igloo_reportxml_render_xmldoc(igloo_reportxml_t *report); xmlDocPtr igloo_reportxml_render_xmldoc(igloo_reportxml_t *report);
@ -98,9 +98,9 @@ xmlDocPtr igloo_reportxml_render_xmldoc(igloo_reportxml_t *report)
/* This creates a new node of type type. /* This creates a new node of type type.
* It's id, definition, and akindof attributes can be given as parameters. * It's id, definition, and akindof attributes can be given as parameters.
*/ */
igloo_reportxml_node_t * igloo_reportxml_node_new(igloo_reportxml_node_type_t type, const char *id, const char *definition, const char *akindof); igloo_reportxml_node_t * igloo_reportxml_node_new(igloo_reportxml_node_type_t type, const char *id, const char *definition, const char *akindof, igloo_ro_t instance);
/* This parses an XML node and returns the resulting report XML node */ /* This parses an XML node and returns the resulting report XML node */
igloo_reportxml_node_t * igloo_reportxml_node_parse_xmlnode(xmlNodePtr xmlnode); igloo_reportxml_node_t * igloo_reportxml_node_parse_xmlnode(xmlNodePtr xmlnode, igloo_ro_t instance);
/* Copy an report XML node (and it's children) */ /* Copy an report XML node (and it's children) */
igloo_reportxml_node_t * igloo_reportxml_node_copy(igloo_reportxml_node_t *node); igloo_reportxml_node_t * igloo_reportxml_node_copy(igloo_reportxml_node_t *node);
/* Renders an report XML node as XML node */ /* Renders an report XML node as XML node */

View File

@ -257,7 +257,7 @@ static void __report_free(igloo_ro_t self)
static int __report_new(igloo_ro_t self, const igloo_ro_type_t *type, va_list ap) static int __report_new(igloo_ro_t self, const igloo_ro_type_t *type, va_list ap)
{ {
igloo_reportxml_t *ret = igloo_RO_TO_TYPE(self, igloo_reportxml_t); igloo_reportxml_t *ret = igloo_RO_TO_TYPE(self, igloo_reportxml_t);
igloo_reportxml_node_t *root = igloo_reportxml_node_new(igloo_REPORTXML_NODE_TYPE_REPORT, NULL, NULL, NULL); igloo_reportxml_node_t *root = igloo_reportxml_node_new(igloo_REPORTXML_NODE_TYPE_REPORT, NULL, NULL, NULL, self);
if (!root) if (!root)
return -1; return -1;
@ -310,7 +310,7 @@ igloo_reportxml_node_t * igloo_reportxml_get_node_by_type(igloo_reportxml_t
return igloo_reportxml_node_get_child_by_type(report->root, type, include_definitions); return igloo_reportxml_node_get_child_by_type(report->root, type, include_definitions);
} }
igloo_reportxml_t * igloo_reportxml_parse_xmldoc(xmlDocPtr doc) igloo_reportxml_t * igloo_reportxml_parse_xmldoc(xmlDocPtr doc, igloo_ro_t instance)
{ {
igloo_reportxml_node_t *root; igloo_reportxml_node_t *root;
igloo_reportxml_t *ret; igloo_reportxml_t *ret;
@ -323,7 +323,7 @@ igloo_reportxml_t * igloo_reportxml_parse_xmldoc(xmlDocPtr doc)
if (!xmlroot) if (!xmlroot)
return NULL; return NULL;
root = igloo_reportxml_node_parse_xmlnode(xmlroot); root = igloo_reportxml_node_parse_xmlnode(xmlroot, instance);
if (!root) if (!root)
return NULL; return NULL;
@ -384,7 +384,7 @@ static void __report_node_free(igloo_ro_t self)
free(node->xml_childs); free(node->xml_childs);
} }
igloo_reportxml_node_t * igloo_reportxml_node_new(igloo_reportxml_node_type_t type, const char *id, const char *definition, const char *akindof) igloo_reportxml_node_t * igloo_reportxml_node_new(igloo_reportxml_node_type_t type, const char *id, const char *definition, const char *akindof, igloo_ro_t instance)
{ {
igloo_reportxml_node_t *ret; igloo_reportxml_node_t *ret;
const struct nodedef *nodedef = __get_nodedef(type); const struct nodedef *nodedef = __get_nodedef(type);
@ -393,7 +393,7 @@ igloo_reportxml_node_t * igloo_reportxml_node_new(igloo_reportxml_node_type
if (!nodedef) if (!nodedef)
return NULL; return NULL;
ret = igloo_ro_new_raw(igloo_reportxml_node_t, NULL, igloo_RO_NULL, igloo_RO_NULL); ret = igloo_ro_new_raw(igloo_reportxml_node_t, NULL, igloo_RO_NULL, instance);
if (ret == NULL) if (ret == NULL)
return NULL; return NULL;
@ -435,7 +435,7 @@ igloo_reportxml_node_t * igloo_reportxml_node_new(igloo_reportxml_node_type
return ret; return ret;
} }
igloo_reportxml_node_t * igloo_reportxml_node_parse_xmlnode(xmlNodePtr xmlnode) igloo_reportxml_node_t * igloo_reportxml_node_parse_xmlnode(xmlNodePtr xmlnode, igloo_ro_t instance)
{ {
igloo_reportxml_node_t *node; igloo_reportxml_node_t *node;
@ -449,7 +449,7 @@ igloo_reportxml_node_t * igloo_reportxml_node_parse_xmlnode(xmlNodePtr xmln
return NULL; return NULL;
} }
node = igloo_reportxml_node_new(nodedef->type, NULL, NULL, NULL); node = igloo_reportxml_node_new(nodedef->type, NULL, NULL, NULL, instance);
if (!node) if (!node)
return NULL; return NULL;
@ -507,7 +507,7 @@ igloo_reportxml_node_t * igloo_reportxml_node_parse_xmlnode(xmlNodePtr xmln
continue; continue;
} }
child = igloo_reportxml_node_parse_xmlnode(cur); child = igloo_reportxml_node_parse_xmlnode(cur, instance);
if (!child) { if (!child) {
igloo_ro_unref(node); igloo_ro_unref(node);
return NULL; return NULL;
@ -544,7 +544,7 @@ static igloo_reportxml_node_t * __reportxml_node_copy_with_db(igloo_reportx
if (xml_child_count < 0) if (xml_child_count < 0)
return NULL; return NULL;
ret = igloo_reportxml_node_parse_xmlnode(node->xmlnode); ret = igloo_reportxml_node_parse_xmlnode(node->xmlnode, node);
if (!ret) if (!ret)
return NULL; return NULL;
@ -1133,7 +1133,7 @@ static igloo_reportxml_node_t * __reportxml_database_build_node_ext(igloo_r
if (!depth) if (!depth)
return NULL; return NULL;
search = igloo_reportxml_node_new(igloo_REPORTXML_NODE_TYPE_DEFINITION, NULL, NULL, NULL); search = igloo_reportxml_node_new(igloo_REPORTXML_NODE_TYPE_DEFINITION, NULL, NULL, NULL, db);
if (!search) if (!search)
return NULL; return NULL;
@ -1176,7 +1176,7 @@ static igloo_reportxml_node_t * __reportxml_database_build_node_ext(igloo_r
ret = NULL; ret = NULL;
} }
} else { } else {
ret = igloo_reportxml_node_new(igloo_REPORTXML_NODE_TYPE_DEFINITION, NULL, NULL, NULL); ret = igloo_reportxml_node_new(igloo_REPORTXML_NODE_TYPE_DEFINITION, NULL, NULL, NULL, db);
} }
if (!ret) { if (!ret) {
@ -1329,7 +1329,7 @@ igloo_reportxml_t * igloo_reportxml_database_build_report(igloo_report
if (type == igloo_REPORTXML_NODE_TYPE_INCIDENT) { if (type == igloo_REPORTXML_NODE_TYPE_INCIDENT) {
igloo_ro_ref(attach_to = root); igloo_ro_ref(attach_to = root);
} else if (type == igloo_REPORTXML_NODE_TYPE_STATE) { } else if (type == igloo_REPORTXML_NODE_TYPE_STATE) {
attach_to = igloo_reportxml_node_new(igloo_REPORTXML_NODE_TYPE_INCIDENT, NULL, NULL, NULL); attach_to = igloo_reportxml_node_new(igloo_REPORTXML_NODE_TYPE_INCIDENT, NULL, NULL, NULL, db);
if (attach_to) { if (attach_to) {
if (igloo_reportxml_node_add_child(root, attach_to) != 0) { if (igloo_reportxml_node_add_child(root, attach_to) != 0) {
igloo_ro_unref(attach_to); igloo_ro_unref(attach_to);

View File

@ -27,7 +27,7 @@ static void test_create_unref(void)
ctest_test("report created", !igloo_RO_IS_NULL(report)); ctest_test("report created", !igloo_RO_IS_NULL(report));
ctest_test("un-referenced", igloo_ro_unref(report) == igloo_ERROR_NONE); ctest_test("un-referenced", igloo_ro_unref(report) == igloo_ERROR_NONE);
node = igloo_reportxml_node_new(igloo_REPORTXML_NODE_TYPE_REPORT, NULL, NULL, NULL); node = igloo_reportxml_node_new(igloo_REPORTXML_NODE_TYPE_REPORT, NULL, NULL, NULL, igloo_RO_NULL);
ctest_test("node created", !igloo_RO_IS_NULL(node)); ctest_test("node created", !igloo_RO_IS_NULL(node));
ctest_test("un-referenced", igloo_ro_unref(node) == igloo_ERROR_NONE); ctest_test("un-referenced", igloo_ro_unref(node) == igloo_ERROR_NONE);