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

Function string2xml

lib/common/xml.c:555–611  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

553}
554
555xmlNode*
556string2xml(const char *input)
557{
558 xmlNode *xml = NULL;
559 xmlDocPtr output = NULL;
560 xmlParserCtxtPtr ctxt = NULL;
561 xmlErrorPtr last_error = NULL;
562
563 if(input == NULL) {
564 crm_err("Can't parse NULL input");
565 return NULL;
566 }
567
568 /* create a parser context */
569 ctxt = xmlNewParserCtxt();
570 CRM_CHECK(ctxt != NULL, return NULL);
571
572 /* xmlCtxtUseOptions(ctxt, XML_PARSE_NOBLANKS|XML_PARSE_RECOVER); */
573
574 xmlCtxtResetLastError(ctxt);
575 xmlSetGenericErrorFunc(ctxt, crm_xml_err);
576 /* initGenericErrorDefaultFunc(crm_xml_err); */
577 output = xmlCtxtReadDoc(ctxt, (const xmlChar*)input, NULL, NULL, XML_PARSE_NOBLANKS|XML_PARSE_RECOVER);
578 if(output) {
579 xml = xmlDocGetRootElement(output);
580 }
581 last_error = xmlCtxtGetLastError(ctxt);
582 if(last_error && last_error->code != XML_ERR_OK) {
583 /* crm_abort(__FILE__,__PRETTY_FUNCTION__,__LINE__, "last_error->code != XML_ERR_OK", TRUE, TRUE); */
584 /*
585 * http://xmlsoft.org/html/libxml-xmlerror.html#xmlErrorLevel
586 * http://xmlsoft.org/html/libxml-xmlerror.html#xmlParserErrors
587 */
588 crm_warn("Parsing failed (domain=%d, level=%d, code=%d): %s",
589 last_error->domain, last_error->level,
590 last_error->code, last_error->message);
591
592 if(last_error->code == XML_ERR_DOCUMENT_EMPTY) {
593 crm_abort(__FILE__,__PRETTY_FUNCTION__,__LINE__, "Cannot parse an empty string", TRUE, TRUE);
594
595 } else if(last_error->code != XML_ERR_DOCUMENT_END) {
596 crm_err("Couldn't%s parse %d chars: %s", xml?" fully":"", (int)strlen(input), input);
597 if(xml != NULL) {
598 crm_log_xml_err(xml, "Partial");
599 }
600
601 } else {
602 int len = strlen(input);
603 crm_warn("String start: %.50s", input);
604 crm_warn("String start+%d: %s", len-50, input+len-50);
605 crm_abort(__FILE__,__PRETTY_FUNCTION__,__LINE__, "String parsing error", TRUE, TRUE);
606 }
607 }
608
609 xmlFreeParserCtxt(ctxt);
610 return xml;
611}
612

Callers 15

mainFunction · 0.85
mainFunction · 0.85
resource_ipc_callbackFunction · 0.85
attrd_ais_dispatchFunction · 0.85
admin_msg_callbackFunction · 0.85
node_mcp_dispatchFunction · 0.85
mainFunction · 0.85
cib_ais_dispatchFunction · 0.85
get_agent_metadataFunction · 0.85
lrmd_dispatch_internalFunction · 0.85

Calls 1

crm_abortFunction · 0.85

Tested by 1

mainFunction · 0.68