From 8b85cbcbee33558d79ca290ab98c7540ddf2874b Mon Sep 17 00:00:00 2001 From: Tomas Mlcoch Date: Tue, 10 Jan 2012 16:46:57 +0100 Subject: [PATCH] Add parsepkg module --- Makefile | 9 +++++++- parsepkg.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ parsepkg.h | 18 +++++++++++++++ parsepkg.i | 11 +++++++++ 4 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 parsepkg.c create mode 100644 parsepkg.h create mode 100644 parsepkg.i diff --git a/Makefile b/Makefile index d464724..91984a8 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ SWIG=/usr/bin/swig CFLAGS=-DDEBUG -I/usr/include/python2.7/ `pkg-config --cflags glib-2.0` `xml2-config --cflags` LINKFLAGS=`pkg-config --libs glib-2.0` `xml2-config --libs` -lrpm -all: package.so xml_dump.so parsehdr.so +all: package.so xml_dump.so parsehdr.so parsepkg.so test: main @@ -25,6 +25,10 @@ parsehdr.o parsehdr_wrap.o: parsehdr.c parsehdr.h $(SWIG) -python -Wall parsehdr.i gcc $(CFLAGS) -c parsehdr.c parsehdr_wrap.c +parsepkg.o parsepkg_wrap.o: parsepkg.c parsepkg.h + $(SWIG) -python -Wall parsepkg.i + gcc $(CFLAGS) -c parsepkg.c parsepkg_wrap.c + # Object files misc.o: misc.c misc.h @@ -48,6 +52,9 @@ xml_dump.so: package.o xml_dump_wrap.o xml_dump.o xml_dump_primary.o xml_dump_fi parsehdr.so: parsehdr_wrap.o parsehdr.o package.o xml_dump.o misc.o ld $(LINKFLAGS) -shared misc.o parsehdr_wrap.o parsehdr.o package.o xml_dump.o xml_dump_primary.o xml_dump_filelists.o xml_dump_other.o -o _parsehdr.so +parsepkg.so: parsepkg_wrap.o parsepkg.o parsehdr.o package.o xml_dump.o misc.o + ld $(LINKFLAGS) -shared misc.o parsepkg_wrap.o parsepkg.o parsehdr.o package.o xml_dump.o xml_dump_primary.o xml_dump_filelists.o xml_dump_other.o -o _parsepkg.so + # Main main: package.o xml_dump.o xml_dump_primary.o xml_dump_filelists.o xml_dump_other.o diff --git a/parsepkg.c b/parsepkg.c new file mode 100644 index 0000000..46ab0b7 --- /dev/null +++ b/parsepkg.c @@ -0,0 +1,76 @@ +#include +#include +#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 result; + result.primary = NULL; + 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"); + if (!fd) { + perror("Fopen"); + return result; + } + + // Read package + Header hdr; + int rc = rpmReadPackageFile(ts, fd, NULL, &hdr); + if (rc != RPMRC_OK) { + switch (rc) { + case RPMRC_NOKEY: + //printf("rpmReadpackageFile: Public key is unavaliable\n"); + break; + case RPMRC_NOTTRUSTED: + //printf("rpmReadpackageFile: Signature is OK, but key is not trusted\n"); + break; + default: + perror("rpmReadPackageFile"); + return result; + } + } + + // + // Get file stat + // + + gint64 mtime = 0; + gint64 size = 0; + char *checksum = "abcdefghijklmnop"; + //char *location_href = NULL; + //char *location_base = NULL; + //int changelog_limit = 5; + //gint64 hdr_start = 10; + //gint64 hdr_end = 22; + + // + // Gen XML + // + + Package *pkg = parse_header(hdr, mtime, size, checksum, checksum_type, location_href, + location_base, changelog_limit, hdr_start, hdr_end); + + result.primary = xml_dump_primary(pkg, NULL); + result.filelists = xml_dump_filelists(pkg, NULL); + result.other = xml_dump_other(pkg, NULL); + return result; +} diff --git a/parsepkg.h b/parsepkg.h new file mode 100644 index 0000000..7d65492 --- /dev/null +++ b/parsepkg.h @@ -0,0 +1,18 @@ +#ifndef __PARSEPKG__ +#define __PARSEPKG__ + +#include +#include +#include "package.h" +#include "xml_dump.h" + +/* +Package *parse_package(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); +*/ +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); + +#endif /* __PARSEPKG__ */ diff --git a/parsepkg.i b/parsepkg.i new file mode 100644 index 0000000..da18b89 --- /dev/null +++ b/parsepkg.i @@ -0,0 +1,11 @@ +%module parsepkg + +%include + +%{ +#include "package.h" +#include "parsepkg.h" +%} + +%include "xml_dump.h" +%include "parsepkg.h" -- 2.7.4