Skip to content

Commit

Permalink
Remove C API for cr_xml_parse_main_metadata_together
Browse files Browse the repository at this point in the history
It is obsoleted by cr_PkgIterator_new and its API.
It also converts some of the tests to using cr_PkgIterator.
  • Loading branch information
kontura authored and Conan-Kudo committed Mar 29, 2022
1 parent a5a5cf6 commit dc45424
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 309 deletions.
38 changes: 0 additions & 38 deletions src/xml_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,44 +278,6 @@ cr_xml_parse_updateinfo(const char *path,
void *warningcb_data,
GError **err);

/** Parse all 3 main metadata types (primary, filelists and other) at the same time.
* Once a package is fully parsed pkgcb is called, if a cr_Package wasn't provided using
* newpkgcb new cr_Package is created and its ownership is transferred to the user by the
* pkgcb call.
* This means we don't have store all the packages in memory at the same time, which
* significantly reduces the memory footprint.
* Input metadata files can be compressed.
* Metadata primary, filelists and other have to have the packages in the same order.
* @param primary_path Path to a primary xml file.
* @param filelists_path Path to a filelists xml file.
* @param other_path Path to an other xml file.
* @param newpkgcb Callback for a new package. Called when the new package
* xml chunk is found and a package object to store the data
* is needed. If this callback is used, the user has full
* ownership of the package, it will not be freed if the
* parsing is interrupted or there is an error.
* @param newpkgcb_data User data for the newpkgcb.
* @param pkgcb Package callback. Called when a package is completely
* parsed containing information from all 3 main metadata
* files. Could be NULL if newpkgcb is not NULL.
* @param pkgcb_data User data for the pkgcb.
* @param warningcb Callback for warning messages.
* @param warningcb_data User data for the warningcb.
* @param err GError **
* @return cr_Error code.
*/
int
cr_xml_parse_main_metadata_together(const char *primary_path,
const char *filelists_path,
const char *other_path,
cr_XmlParserNewPkgCb newpkgcb,
void *newpkgcb_data,
cr_XmlParserPkgCb pkgcb,
void *pkgcb_data,
cr_XmlParserWarningCb warningcb,
void *warningcb_data,
GError **err);

typedef struct _cr_PkgIterator cr_PkgIterator;

cr_PkgIterator *
Expand Down
59 changes: 0 additions & 59 deletions src/xml_parser_main_metadata_together.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,65 +319,6 @@ parse_next_section(CR_FILE *target_file, const char *path, cr_ParserData *pd, GE

//TODO(amatej): there is quite some overlap with this and cr_load_xml_files,
// consider using this api to implement cr_load_xml_files?
int cr_xml_parse_main_metadata_together(const char *primary_path,
const char *filelists_path,
const char *other_path,
cr_XmlParserNewPkgCb newpkgcb,
void *newpkgcb_data,
cr_XmlParserPkgCb pkgcb,
void *pkgcb_data,
cr_XmlParserWarningCb warningcb,
void *warningcb_data,
GError **err)
{
assert(pkgcb || newpkgcb);
cr_PkgIterator* pkg_iterator = cr_PkgIterator_new(
primary_path, filelists_path, other_path, newpkgcb, newpkgcb_data, warningcb, warningcb_data, err
);

if (*err) {
return (*err)->code;
}

assert(pkg_iterator);
cr_Package* package = NULL;
GError* tmp_err = NULL;

while (package = cr_PkgIterator_parse_next(pkg_iterator, err)) {
if (pkgcb) {
// call user package callback
// pkgcb() destroys the package!!
if (pkgcb(package, pkgcb_data, &tmp_err)) {
// Error condition
if (tmp_err) {
g_propagate_prefixed_error(err, tmp_err, "Parsing interrupted: ");
} else {
g_set_error(err, ERR_DOMAIN, CRE_CBINTERRUPTED, "Parsing interrupted");
}
cr_PkgIterator_free(pkg_iterator, err);
return CRE_CBINTERRUPTED;
} else {
// If callback return CRE_OK but it simultaneously set
// the tmp_err then it's a programming error.
assert(tmp_err == NULL);
}
} else {
// Free the package if there is no external callback to do so and we have no newpkgcb
if (!newpkgcb) {
cr_package_free(package);
}
}
}

cr_PkgIterator_free(pkg_iterator, err);

if (*err) {
return (*err)->code;
} else {
return CRE_OK;
}
}

// TODO: maybe whether or not individual files are parsed could be controlled by NULL paths? I think cr_load_xml_files
// already works that way.
cr_PkgIterator *
Expand Down
Loading

0 comments on commit dc45424

Please sign in to comment.