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
+# FIXME: There must be -O option in cflags or we get: _parsepkg.so: undefined symbol: stat
+# link option -lc should solves this problem but it seems to be doesn't working
+
+CFLAGS=-O -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 -lrpmio -lc
all: package.so xml_dump.so parsehdr.so parsepkg.so
+
+ctests: parsepkg_test_01
test: main
$(SWIG) -python -Wall parsehdr.i
gcc $(CFLAGS) -c parsehdr.c parsehdr_wrap.c
-parsepkg.o parsepkg_wrap.o: parsepkg.c parsepkg.h
+parsepkg.o parsepkg_wrap.o: parsepkg.c parsepkg.h constants.h
$(SWIG) -python -Wall parsepkg.i
gcc $(CFLAGS) -c parsepkg.c parsepkg_wrap.c
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
+# Tests
+
+parsepkg_test_01: parsepkg.o parsehdr.o package.o xml_dump.o xml_dump_primary.o xml_dump_filelists.o xml_dump_other.o misc.o
+ gcc $(LINKFLAGS) $(CFLAGS) parsepkg.o parsehdr.o package.o xml_dump.o xml_dump_primary.o xml_dump_filelists.o xml_dump_other.o misc.o ctests/parsepkg_test_01.c -o ctests/parsepkg_test_01
+
# Main
main: package.o xml_dump.o xml_dump_primary.o xml_dump_filelists.o xml_dump_other.o
--- /dev/null
+#include <stdio.h>
+#include "../xml_dump.h"
+#include "../package.h"
+#include "../parsepkg.h"
+
+int main() {
+ struct XmlStruct res;
+ res = xml_from_package_file("icedax-1.1.10-2.fc14.i686.rpm", "", "", "", 4, 10,12);
+
+ printf("Test - Start\n");
+ printf("%s\n\n%s\n\n%s\n", res.primary, res.filelists, res.other);
+ printf("Test - Done\n");
+ return 0;
+}
\ No newline at end of file
#include <glib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
#include <rpm/rpmfi.h>
#include "parsehdr.h"
#include "xml_dump.h"
}
}
+ // Cleanup
+ rpmtsFree(ts);
+ Fclose(fd);
+
//
// Get file stat
//
- gint64 mtime = 0;
- gint64 size = 0;
+ 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;
+
+ //
+ // Compute checksum
+ //
+
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,
+ result = xml_from_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);
+ headerFree(hdr); // ???
+
return result;
}