Skip to content

Commit

Permalink
domparser: libxml2 deprecation fix
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmanuelP committed Apr 14, 2024
1 parent 934bd75 commit ac715e8
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/arvdomparser.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,52 @@ typedef enum {
ARV_DOM_DOCUMENT_ERROR_INVALID_XML
} ArvDomDocumentError;

#if LIBXML_VERSION >= 21100
static ArvDomDocument *
_parse_memory (ArvDomDocument *document, ArvDomNode *node,
const void *buffer, int size, GError **error)
{
static ArvDomSaxParserState state;
xmlParserCtxt *xml_parser_ctxt;

state.document = document;
if (node != NULL)
state.current_node = node;
else
state.current_node = ARV_DOM_NODE (document);

if (size < 0)
size = strlen (buffer);

xml_parser_ctxt = xmlNewSAXParserCtxt (&sax_handler, &state);
if (xml_parser_ctxt == NULL) {
g_set_error (error,
ARV_DOM_DOCUMENT_ERROR,
ARV_DOM_DOCUMENT_ERROR_INVALID_XML,
"Failed to create parser context");
return NULL;
}

xmlCtxtReadMemory (xml_parser_ctxt, buffer, size, NULL, NULL, 0);

if (!xml_parser_ctxt->wellFormed) {
if (state.document != NULL)
g_object_unref (state.document);
state.document = NULL;

arv_warning_dom ("[DomParser::parse] Invalid document");

g_set_error (error,
ARV_DOM_DOCUMENT_ERROR,
ARV_DOM_DOCUMENT_ERROR_INVALID_XML,
"Invalid document");
}

xmlFreeParserCtxt(xml_parser_ctxt);

return state.document;
}
#else
static ArvDomDocument *
_parse_memory (ArvDomDocument *document, ArvDomNode *node,
const void *buffer, int size, GError **error)
Expand Down Expand Up @@ -252,6 +298,7 @@ _parse_memory (ArvDomDocument *document, ArvDomNode *node,

return state.document;
}
#endif

/**
* arv_dom_document_append_from_memory:
Expand Down

0 comments on commit ac715e8

Please sign in to comment.