return pkg;
}
-
-
-
-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,
- GError **err)
-{
- cr_Package *pkg;
- struct cr_XmlStruct result;
- 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:
- cr_package_free(pkg);
-
- return result;
-}
gint64 hdr_end,
GError **err);
-/** Read data from header and return struct cr_XmlStruct.
- * All const char * params could be NULL.
- * @param hdr Header
- * @param mtime mtime of rpm file
- * @param size size of rpm file (in bytes)
- * @param checksum checksum of rpm file
- * @param checksum_type used checksum algorithm
- * @param location_href location of package inside repository
- * @param location_base location (url) of repository
- * @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)
- */
-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,
- GError **err);
-
/** @} */
#ifdef __cplusplus
struct stat *stat_buf,
GError **err)
{
- const char *checksum_type_str;
+ cr_Package *pkg;
struct cr_XmlStruct result;
- GError *tmp_err = NULL;
assert(filename);
assert(!err || *err == NULL);
result.filelists = NULL;
result.other = NULL;
- checksum_type_str = cr_checksum_name_str(checksum_type);
-
-
- // Read header
-
- Header hdr;
- read_header(filename, &hdr, &tmp_err);
- if (tmp_err) {
- g_propagate_error(err, tmp_err);
- return result;
- }
-
-
- // Get file stat
-
- gint64 mtime;
- gint64 size;
-
- if (!stat_buf) {
- struct stat stat_buf_own;
- if (stat(filename, &stat_buf_own) == -1) {
- g_warning("%s: stat() error (%s)", __func__, strerror(errno));
- g_set_error(err, CR_PARSEPKG_ERROR, CRE_IO, "stat() failed");
- headerFree(hdr);
- return result;
- }
- mtime = stat_buf_own.st_mtime;
- size = stat_buf_own.st_size;
- } else {
- mtime = stat_buf->st_mtime;
- size = stat_buf->st_size;
- }
-
-
- // Compute checksum
-
- char *checksum = cr_checksum_file(filename, checksum_type, &tmp_err);
- if (!checksum) {
- g_propagate_prefixed_error(err, tmp_err,
- "Error while checksum calculation: ");
- headerFree(hdr);
+ pkg = cr_package_from_rpm(filename,
+ checksum_type,
+ location_href,
+ location_base,
+ changelog_limit,
+ stat_buf,
+ err);
+ if (!pkg)
return result;
- }
-
-
- // Get header range
-
- struct cr_HeaderRangeStruct hdr_r = cr_get_header_byte_range(filename,
- &tmp_err);
- if (tmp_err) {
- g_propagate_prefixed_error(err, tmp_err,
- "Error while determinig header range: ");
- free(checksum);
- return result;
- }
-
-
- // Gen XML
-
- result = cr_xml_from_header(hdr, mtime, size, checksum, checksum_type_str,
- location_href, location_base, changelog_limit,
- hdr_r.start, hdr_r.end, &tmp_err);
- free(checksum);
- headerFree(hdr);
-
- if (tmp_err) {
- g_propagate_prefixed_error(err, tmp_err,
- "Error while checksum calculation:");
- return result;
- }
+ result = cr_xml_dump(pkg, err);
+ cr_package_free(pkg);
return result;
}