Add support for checksums and header range into parsepkg module
authorTomas Mlcoch <tmlcoch@redhat.com>
Wed, 11 Jan 2012 14:21:25 +0000 (15:21 +0100)
committerTomas Mlcoch <tmlcoch@redhat.com>
Wed, 11 Jan 2012 14:21:25 +0000 (15:21 +0100)
parsepkg.c
parsepkg.h
parsepkg.i

index 236ce4e..edb5f89 100644 (file)
@@ -3,24 +3,22 @@
 #include <sys/stat.h>
 #include <unistd.h>
 #include <rpm/rpmfi.h>
+#include "constants.h"
 #include "parsehdr.h"
 #include "xml_dump.h"
 #include "misc.h"
 #include "parsehdr.h"
 
 
-struct XmlStruct xml_from_package_file(const char *filename, const char *checksum_type,
-                const char *location_href, const char *location_base, int changelog_limit,
-                gint64 hdr_start, gint64 hdr_end)
+struct XmlStruct xml_from_package_file(const char *filename, ChecksumType checksum_type,
+                const char *location_href, const char *location_base, int changelog_limit)
 {
     struct XmlStruct result;
     result.primary   = NULL;
     result.filelists = NULL;
     result.other     = NULL;
 
-    //
     // Get header
-    //
 
     // Create transaction
     rpmts ts = NULL;
@@ -56,35 +54,45 @@ struct XmlStruct xml_from_package_file(const char *filename, const char *checksu
     rpmtsFree(ts);
     Fclose(fd);
 
-    //
     // Get file stat
-    //
-
-    gint64 mtime  = 0;
-    gint64 size   = 0;
 
     struct stat stat_buf;
     if (stat(filename, &stat_buf) == -1) {
         perror("stat");
         return result;
     }
-    mtime  = stat_buf.st_mtime;
-    size   = stat_buf.st_size;
+    gint64 mtime  = stat_buf.st_mtime;
+    gint64 size   = stat_buf.st_size;
 
-    //
     // Compute checksum
-    //
 
-    char *checksum = "abcdefghijklmnop";
+    const char *checksum_type_str;
+    switch (checksum_type) {
+        case PKG_CHECKSUM_MD5:
+            checksum_type_str = "md5";
+            break;
+        case PKG_CHECKSUM_SHA1:
+             checksum_type_str = "sha1";
+            break;
+        case PKG_CHECKSUM_SHA256:
+            checksum_type_str = "sha256";
+            break;
+    };
+
+    char *checksum = compute_file_checksum(filename, checksum_type);
+
+    // Get header range
+
+    struct HeaderRangeStruct hdr_r = get_header_byte_range(filename);
 
-    //
     // Gen XML
-    //
 
-    result = xml_from_header(hdr, mtime, size, checksum, checksum_type, location_href,
-                                location_base, changelog_limit, hdr_start, hdr_end);
+    result = xml_from_header(hdr, mtime, size, checksum, checksum_type_str, location_href,
+                                location_base, changelog_limit, hdr_r.start, hdr_r.end);
 
-    headerFree(hdr);   // ???
+    // Cleanup
+    free(checksum);
+    headerFree(hdr);
 
     return result;
 }
index 7d65492..d47c75a 100644 (file)
@@ -11,8 +11,8 @@ Package *parse_package(Header hdr, gint64 mtime, gint64 size, const char *checks
                       const char *location_href, const char *location_base,
                       int changelog_limit, gint64 hdr_start, gint64 hdr_end);
 */
-struct XmlStruct xml_from_package_file(const char *filename, const char *checksum_type,
+struct XmlStruct xml_from_package_file(const char *filename, ChecksumType checksum_type,
                         const char *location_href, const char *location_base,
-                        int changelog_limit, gint64 hdr_start, gint64 hdr_end);
+                        int changelog_limit);
 
 #endif /* __PARSEPKG__ */
index da18b89..86db2c0 100644 (file)
@@ -3,9 +3,11 @@
 %include <typemaps.i>
 
 %{
+#include "constants.h"
 #include "package.h"
 #include "parsepkg.h"
 %}
 
+%include "constants.h"
 %include "xml_dump.h"
 %include "parsepkg.h"