Skip to content

Commit

Permalink
Address review comments for new XML file iterator
Browse files Browse the repository at this point in the history
It is now checked if the parser context was created successfully
when initializing or rewinding an iterator.
The word 'pcdata' in comments is replaced with 'cdata' as this appears
to be a typo in the original libxml.
  • Loading branch information
timopollmeier committed Mar 5, 2024
1 parent 3b2adbc commit e3beb48
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
21 changes: 15 additions & 6 deletions util/xmlutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -2748,14 +2748,14 @@ xml_file_iterator_characters (void *ctx, const xmlChar *ch, int len)
}

/**
* @brief XML file iterator parser callback when a pcdata block has
* @brief XML file iterator parser callback when a cdata block has
* been parsed.
*
* This is just a wrapper for the libXML xmlSAX2CDataBlock getting the
* libXML parser context from the iterator struct passed as user data.
*
* @param[in] ctx parser context data / iterator data structure
* @param[in] ch The pcdata content
* @param[in] ch The cdata content
* @param[in] len the block length
*/
static void
Expand Down Expand Up @@ -2807,7 +2807,7 @@ xml_file_iterator_comment (void *ctx, const xmlChar *value)
* @param[in] hdlr The xmlSAXHandler to initialize
*/
static void
xml_file_iterator_init_sax_handler (xmlSAXHandler *hdlr)
xml_file_iterator_init_sax_handler (xmlSAXHandlerPtr hdlr)
{
hdlr->startElementNs = xml_file_iterator_start_element_ns;
hdlr->endElementNs = xml_file_iterator_end_element_ns;
Expand Down Expand Up @@ -2863,7 +2863,8 @@ xml_file_iterator_new (void)
* @param[in] output_depth XML tree depth at which to return elements.
*
* @return -1 error, 0 success, 1 already initialized,
* 2 error opening file (errno is set to reason)
* 2 error opening file (errno is set to reason),
* 3 error creating parser context
*/
int
xml_file_iterator_init_from_file_path (xml_file_iterator_t iterator,
Expand Down Expand Up @@ -2894,6 +2895,8 @@ xml_file_iterator_init_from_file_path (xml_file_iterator_t iterator,
xml_file_iterator_init_sax_handler (&(iterator->sax_handler));
iterator->parser_ctxt = xmlCreatePushParserCtxt (
&(iterator->sax_handler), iterator, NULL, 0, iterator->file_path);
if (iterator->parser_ctxt == NULL)
return 3;

iterator->initialized = 1;

Expand Down Expand Up @@ -2937,12 +2940,14 @@ xml_file_iterator_free (xml_file_iterator_t iterator)
* new XML parser context.
*
* @param[in] iterator The XML file iterator to rewind.
*
* @return 0 success, 1 error creating new parser context
*/
void
int
xml_file_iterator_rewind (xml_file_iterator_t iterator)
{
if (iterator == NULL)
return;
return 0;

if (iterator->file)
{
Expand All @@ -2960,7 +2965,11 @@ xml_file_iterator_rewind (xml_file_iterator_t iterator)
xmlFreeParserCtxt (iterator->parser_ctxt);
iterator->parser_ctxt = xmlCreatePushParserCtxt (
&(iterator->sax_handler), iterator, NULL, 0, iterator->file_path);
if (iterator->parser_ctxt == NULL)
return 1;
}

return 0;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion util/xmlutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ xml_file_iterator_init_from_file_path (xml_file_iterator_t, const char *, int);

void xml_file_iterator_free (xml_file_iterator_t);

void xml_file_iterator_rewind (xml_file_iterator_t);
int xml_file_iterator_rewind (xml_file_iterator_t);

element_t
xml_file_iterator_next (xml_file_iterator_t, gchar **);
Expand Down

0 comments on commit e3beb48

Please sign in to comment.