MCPcopy Create free account
hub / github.com/ClusterLabs/pacemaker / filename2xml

Function filename2xml

lib/common/xml.c:727–789  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

725}
726
727xmlNode *
728filename2xml(const char *filename)
729{
730 xmlNode *xml = NULL;
731 xmlDocPtr output = NULL;
732 const char *match = NULL;
733 xmlParserCtxtPtr ctxt = NULL;
734 xmlErrorPtr last_error = NULL;
735 static int xml_options = XML_PARSE_NOBLANKS|XML_PARSE_RECOVER;
736
737 /* create a parser context */
738 ctxt = xmlNewParserCtxt();
739 CRM_CHECK(ctxt != NULL, return NULL);
740
741 /* xmlCtxtUseOptions(ctxt, XML_PARSE_NOBLANKS|XML_PARSE_RECOVER); */
742
743 xmlCtxtResetLastError(ctxt);
744 xmlSetGenericErrorFunc(ctxt, crm_xml_err);
745 /* initGenericErrorDefaultFunc(crm_xml_err); */
746
747 if(filename) {
748 match = strstr(filename, ".bz2");
749 }
750
751 if(filename == NULL) {
752 /* STDIN_FILENO == fileno(stdin) */
753 output = xmlCtxtReadFd(ctxt, STDIN_FILENO, "unknown.xml", NULL, xml_options);
754
755 } else if(match == NULL || match[4] != 0) {
756 output = xmlCtxtReadFile(ctxt, filename, NULL, xml_options);
757
758 } else {
759 char *input = decompress_file(filename);
760 output = xmlCtxtReadDoc(ctxt, (const xmlChar*)input, NULL, NULL, xml_options);
761 free(input);
762 }
763
764 if(output && (xml = xmlDocGetRootElement(output))) {
765 strip_text_nodes(xml);
766 }
767
768 last_error = xmlCtxtGetLastError(ctxt);
769 if(last_error && last_error->code != XML_ERR_OK) {
770 /* crm_abort(__FILE__,__PRETTY_FUNCTION__,__LINE__, "last_error->code != XML_ERR_OK", TRUE, TRUE); */
771 /*
772 * http://xmlsoft.org/html/libxml-xmlerror.html#xmlErrorLevel
773 * http://xmlsoft.org/html/libxml-xmlerror.html#xmlParserErrors
774 */
775 crm_err("Parsing failed (domain=%d, level=%d, code=%d): %s",
776 last_error->domain, last_error->level,
777 last_error->code, last_error->message);
778
779 if(last_error && last_error->code != XML_ERR_OK) {
780 crm_err("Couldn't%s parse %s", xml?" fully":"", filename);
781 if(xml != NULL) {
782 crm_log_xml_err(xml, "Partial");
783 }
784 }

Callers 15

mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
setup_inputFunction · 0.85
profile_oneFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
validate_on_disk_cibFunction · 0.85
retrieveCibFunction · 0.85

Calls 2

decompress_fileFunction · 0.85
strip_text_nodesFunction · 0.85

Tested by 1

mainFunction · 0.68