Add function for package parser initialization
authorTomas Mlcoch <tmlcoch@redhat.com>
Tue, 17 Jan 2012 15:47:49 +0000 (16:47 +0100)
committerTomas Mlcoch <tmlcoch@redhat.com>
Tue, 17 Jan 2012 15:53:44 +0000 (16:53 +0100)
ctests/parsepkg_test_01.c
parsepkg.c
parsepkg.h

index 4010fe8..42d1926 100644 (file)
@@ -6,8 +6,21 @@
 
 int main() {
     struct XmlStruct res;
+
+    init_package_parser();
+
+    int x;
+    for (x=0; x<1000; x++) {
+        res = xml_from_package_file("icedax-1.1.10-2.fc14.i686.rpm", PKG_CHECKSUM_SHA256, "", "", 4);
+        free(res.primary);
+        free(res.filelists);
+        free(res.other);
+    }
+
     res = xml_from_package_file("icedax-1.1.10-2.fc14.i686.rpm", PKG_CHECKSUM_SHA256, "", "", 4);
 
+    free_package_parser();
+
     printf("Test - Start\n");
     printf("%s\n\n%s\n\n%s\n", res.primary, res.filelists, res.other);
     printf("Test - Done\n");
index e5d2793..3a31620 100644 (file)
@@ -9,6 +9,29 @@
 #include "misc.h"
 #include "parsehdr.h"
 
+short initialized = 0;
+rpmts ts = NULL;
+
+void init_package_parser()
+{
+    initialized = 1;
+    rpmReadConfigFiles(NULL, NULL);
+    ts = rpmtsCreate();
+}
+
+
+
+void free_package_parser()
+{
+    if (ts) {
+        rpmtsFree(ts);
+    }
+
+    rpmFreeMacros(NULL);
+    rpmFreeRpmrc();
+}
+
+
 
 struct XmlStruct xml_from_package_file(const char *filename, ChecksumType checksum_type,
                 const char *location_href, const char *location_base, int changelog_limit)
@@ -18,13 +41,6 @@ struct XmlStruct xml_from_package_file(const char *filename, ChecksumType checks
     result.filelists = NULL;
     result.other     = NULL;
 
-    // Get header
-
-    // Create transaction
-    rpmts ts = NULL;
-    rpmReadConfigFiles(NULL, NULL);
-    ts = rpmtsCreate();
-
     // Open rpm file
     FD_t fd = NULL;
     fd = Fopen(filename, "r.ufdio");
@@ -51,7 +67,6 @@ struct XmlStruct xml_from_package_file(const char *filename, ChecksumType checks
     }
 
     // Cleanup
-    rpmtsFree(ts);
     Fclose(fd);
 
     // Get file stat
@@ -94,8 +109,5 @@ struct XmlStruct xml_from_package_file(const char *filename, ChecksumType checks
     free(checksum);
     headerFree(hdr);
 
-    rpmFreeMacros(NULL);
-    rpmFreeRpmrc();
-
     return result;
 }
index be76ec9..726f249 100644 (file)
@@ -12,6 +12,11 @@ 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);
 */
+
+extern short initialized;
+void init_package_parser();
+void free_package_parser();
+
 struct XmlStruct xml_from_package_file(const char *filename, ChecksumType checksum_type,
                         const char *location_href, const char *location_base,
                         int changelog_limit);