From e5325b7cc7669ab6365f17ce98387e6ca9ee4936 Mon Sep 17 00:00:00 2001 From: Tomas Mlcoch Date: Thu, 9 May 2013 10:19:01 +0200 Subject: [PATCH] parsehdr: Add GError support. --- src/parsehdr.c | 76 +++++++++++++++++++++++++++++++++++++++++++++------------- src/parsehdr.h | 8 +++++-- src/parsepkg.c | 4 ++-- 3 files changed, 67 insertions(+), 21 deletions(-) diff --git a/src/parsehdr.c b/src/parsehdr.c index 5f694bb..a5db476 100644 --- a/src/parsehdr.c +++ b/src/parsehdr.c @@ -104,11 +104,18 @@ cr_Package * cr_package_from_header(Header hdr, gint64 mtime, gint64 size, const char *checksum, const char *checksum_type, const char *location_href, const char *location_base, - int changelog_limit, gint64 hdr_start, gint64 hdr_end) + int changelog_limit, gint64 hdr_start, gint64 hdr_end, + GError **err) { + cr_Package *pkg; + + assert(hdr); + assert(!err || *err == NULL); + + CR_UNUSED(err); // In fact, GError is not used in this function yet. + // Create new package structure - cr_Package *pkg = NULL; pkg = cr_package_new(); @@ -524,24 +531,59 @@ cr_package_from_header(Header hdr, gint64 mtime, gint64 size, struct cr_XmlStruct -cr_xml_from_header(Header hdr, gint64 mtime, gint64 size, - const char *checksum, - const char *checksum_type, - const char *location_href, - const char *location_base, - int changelog_limit, - gint64 hdr_start, gint64 hdr_end) +cr_xml_from_header(Header hdr, + gint64 mtime, + gint64 size, + const char *checksum, + const char *checksum_type, + const char *location_href, + const char *location_base, + int changelog_limit, + gint64 hdr_start, + gint64 hdr_end, + GError **err) { - cr_Package *pkg = cr_package_from_header(hdr, mtime, size, checksum, checksum_type, - location_href, location_base, - changelog_limit, hdr_start, hdr_end); - + cr_Package *pkg; struct cr_XmlStruct result; - result.primary = cr_xml_dump_primary(pkg, NULL); - result.filelists = cr_xml_dump_filelists(pkg, NULL); - result.other = cr_xml_dump_other(pkg, NULL); + GError *tmp_err = NULL; + + assert(hdr); + assert(!err || *err == NULL); + + result.primary = NULL; + result.filelists = NULL; + result.other = NULL; + + pkg = cr_package_from_header(hdr, mtime, size, checksum, checksum_type, + location_href, location_base, + changelog_limit, hdr_start, hdr_end, &tmp_err); + if (tmp_err) { + g_propagate_error(err, tmp_err); + goto cleanup; + } + + result.primary = cr_xml_dump_primary(pkg, &tmp_err); + if (tmp_err) { + g_propagate_error(err, tmp_err); + goto cleanup; + } + + result.filelists = cr_xml_dump_filelists(pkg, &tmp_err); + if (tmp_err) { + result.primary = NULL; + g_propagate_error(err, tmp_err); + goto cleanup; + } + + result.other = cr_xml_dump_other(pkg, &tmp_err); + if (tmp_err) { + result.primary = NULL; + result.filelists = NULL; + g_propagate_error(err, tmp_err); + goto cleanup; + } - // Cleanup +cleanup: cr_package_free(pkg); return result; diff --git a/src/parsehdr.h b/src/parsehdr.h index 7a3608a..0c94f8c 100644 --- a/src/parsehdr.h +++ b/src/parsehdr.h @@ -46,6 +46,7 @@ extern "C" { * @param changelog_limit number of changelog entries * @param hdr_start start byte of header * @param hdr_end last byte of header + * @param err GError ** * @return cr_Package */ cr_Package *cr_package_from_header(Header hdr, @@ -57,7 +58,8 @@ cr_Package *cr_package_from_header(Header hdr, const char *location_base, int changelog_limit, gint64 hdr_start, - gint64 hdr_end); + gint64 hdr_end, + GError **err); /** Read data from header and return struct cr_XmlStruct. * All const char * params could be NULL. @@ -71,6 +73,7 @@ cr_Package *cr_package_from_header(Header hdr, * @param changelog_limit number of changelog entries * @param hdr_start start byte of header * @param hdr_end last byte of header + * @param err GError ** * @return XML chunks for primary, filelists and other * (in struct cr_XmlStruct) */ @@ -83,7 +86,8 @@ struct cr_XmlStruct cr_xml_from_header(Header hdr, const char *location_base, int changelog_limit, gint64 hdr_start, - gint64 hdr_end); + gint64 hdr_end, + GError **err); /** @} */ diff --git a/src/parsepkg.c b/src/parsepkg.c index b782142..cf2a601 100644 --- a/src/parsepkg.c +++ b/src/parsepkg.c @@ -169,7 +169,7 @@ cr_package_from_rpm(const char *filename, result = cr_package_from_header(hdr, mtime, size, checksum, checksum_type_str, location_href, location_base, changelog_limit, - hdr_r.start, hdr_r.end); + hdr_r.start, hdr_r.end, NULL); // Cleanup @@ -287,7 +287,7 @@ cr_xml_from_rpm(const char *filename, result = cr_xml_from_header(hdr, mtime, size, checksum, checksum_type_str, location_href, location_base, changelog_limit, - hdr_r.start, hdr_r.end); + hdr_r.start, hdr_r.end, NULL); // Cleanup -- 2.7.4