Port of RPM2 perl module to RPM 4.6.
Two deprecated functions remain, all tests pass.
Lubomir Rintel <lkundrak@v3.sk>
diff -up RPM2-0.67/Makefile.PL.rpm46 RPM2-0.67/Makefile.PL
--- RPM2-0.67/Makefile.PL.rpm46 2008-12-12 01:07:41.000000000 +0100
+++ RPM2-0.67/Makefile.PL 2008-12-12 01:07:41.000000000 +0100
@@ -27,7 +27,13 @@ $libs .= " -lelf";
my @defines;
# detect which rpm is running. ugly but necessary... for now.
-if (-e '/usr/include/rpm/rpmts.h') {
+# ^^^ (Poor you, if only you knew I'll make it much worse -- lkundrak)
+if (`pkg-config rpm --modversion` =~ /^(\d+)\.(\d+).*/) {
+ my ($major, $minor) = ($1, $2);
+ ($major, $minor) = (4,6) if $major >= 4 and $minor > 6;
+ push @defines, "-DRPM2_RPM$major$minor";
+}
+elsif (-e '/usr/include/rpm/rpmts.h') {
push @defines, '-DRPM2_RPM41';
}
else {
diff -up RPM2-0.67/README.rpm46 RPM2-0.67/README
--- RPM2-0.67/README.rpm46 2006-09-24 19:20:03.000000000 +0200
+++ RPM2-0.67/README 2008-12-12 01:07:41.000000000 +0100
@@ -21,4 +21,4 @@ This module requires these other modules
COPYRIGHT AND LICENCE
Copyright (C) 2006 Chip Turner
-
+Copyright (C) 2008 Lubomir Rintel
diff -up RPM2-0.67/RPM2.pm.rpm46 RPM2-0.67/RPM2.pm
--- RPM2-0.67/RPM2.pm.rpm46 2006-09-24 19:23:15.000000000 +0200
+++ RPM2-0.67/RPM2.pm 2008-12-12 01:07:41.000000000 +0100
@@ -795,6 +795,7 @@ Initial release
=head1 AUTHOR
Chip Turner E<lt>cturner@pattern.net<gt>
+Lubomir Rintel E<lt>lkundrak@v3.sk<gt>
=head1 LICENSE
diff -up RPM2-0.67/RPM2.xs.rpm46 RPM2-0.67/RPM2.xs
--- RPM2-0.67/RPM2.xs.rpm46 2008-12-12 01:07:41.000000000 +0100
+++ RPM2-0.67/RPM2.xs 2008-12-12 01:07:41.000000000 +0100
@@ -2,21 +2,26 @@
#include "rpmlib.h"
#include "rpmcli.h"
-#ifdef RPM2_RPM41
+#ifndef RPM2_RPM40
#include "rpmts.h"
#include "rpmte.h"
#endif
#include "header.h"
#include "rpmdb.h"
+#if defined(RPM2_RPM40) || defined(RPM2_RPM41)
#include "misc.h"
+#else
+#define _RPM_4_4_COMPAT
+#include "rpmlegacy.h"
+#endif
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
-#if !defined(RPM2_RPM41) && !defined(RPM2_RPM40)
-#error Must define one of RPM2_RPM41 or RPM2_RPM40; perhaps Makefile.PL could not guess your RPM API version?
+#if !defined(RPM2_RPM41) && !defined(RPM2_RPM40) && !defined(RPM2_RPM46)
+#error Seems like Makefile.PL could not guess your RPM API version.
#endif
/* Chip, this is somewhat stripped down from the default callback used by
@@ -29,9 +34,14 @@
*/
void * _null_callback(
const void * arg,
- const rpmCallbackType what,
+ const rpmCallbackType what,
+#if defined(RPM2_RPM40) || defined(RPM2_RPM41)
const unsigned long amount,
- const unsigned long total,
+ const unsigned long total,
+#else
+ const rpm_loff_t amount,
+ const rpm_loff_t total,
+#endif
fnpyKey key,
rpmCallbackData data)
{
@@ -129,11 +139,23 @@ void * _null_callback(
void
_populate_header_tags(HV *href)
{
+#if defined(RPM2_RPM40) || defined(RPM2_RPM41)
int i = 0;
for (i = 0; i < rpmTagTableSize; i++) {
hv_store(href, rpmTagTable[i].name, strlen(rpmTagTable[i].name), newSViv(rpmTagTable[i].val), 0);
+#else
+ rpmtd names;
+ const char *name;
+
+ names = rpmtdNew();
+ rpmTagGetNames(names, 1);
+ while ((name = rpmtdNextString(names)) != NULL) {
+ const char *sname = name + strlen("RPMTAG_");
+ hv_store(href, name, strlen(name),
+ newSViv(rpmTagGetValue(name + strlen("RPMTAG_"))), 0);
}
+#endif
}
void
@@ -158,7 +180,7 @@ BOOT:
constants = perl_get_hv("RPM2::constants", TRUE);
/* not the 'standard' way of doing perl constants, but a lot easier to maintain */
-#ifdef RPM2_RPM41
+#ifndef RPM2_RPM40
REGISTER_CONSTANT(RPMVSF_DEFAULT);
REGISTER_CONSTANT(RPMVSF_NOHDRCHK);
REGISTER_CONSTANT(RPMVSF_NEEDPAYLOAD);
@@ -183,10 +205,13 @@ double
rpm_api_version(pkg)
char * pkg
CODE:
-#if defined(RPM2_RPM41) && ! defined(RPM2_RPM40)
+#ifdef RPM2_RPM46
+ RETVAL = (double)4.6;
+#endif
+#ifdef RPM2_RPM41
RETVAL = (double)4.1;
#endif
-#if ! defined(RPM2_RPM41) && defined(RPM2_RPM40)
+#ifdef RPM2_RPM40
RETVAL = (double)4.0;
#endif
OUTPUT:
@@ -229,7 +254,7 @@ _read_package_info(fp, vsflags)
FILE *fp
int vsflags
PREINIT:
-#ifdef RPM2_RPM41
+#ifndef RPM2_RPM40
rpmts ts;
#endif
Header ret;
@@ -237,7 +262,7 @@ _read_package_info(fp, vsflags)
rpmRC rc;
FD_t fd;
PPCODE:
-#ifdef RPM2_RPM41
+#ifndef RPM2_RPM40
ts = rpmtsCreate();
#endif
@@ -249,7 +274,7 @@ _read_package_info(fp, vsflags)
*/
fd = fdDup(fileno(fp));
-#ifdef RPM2_RPM41
+#ifndef RPM2_RPM40
rpmtsSetVSFlags(ts, vsflags);
rc = rpmReadPackageFile(ts, fd, "filename or other identifier", &ret);
#else
@@ -271,7 +296,7 @@ _read_package_info(fp, vsflags)
else {
croak("error reading package");
}
-#ifdef RPM2_RPM41
+#ifndef RPM2_RPM40
ts = rpmtsFree(ts);
#endif
@@ -355,6 +380,11 @@ _init_iterator(db, rpmtag, key, len)
char *key
size_t len
CODE:
+ /* See rpmdbInitIterator() code for explanation of this */
+ if (rpmtag == RPMDBI_PACKAGES) {
+ len = sizeof (key);
+ }
+
RETVAL = rpmdbInitIterator(db, rpmtag, key && *key ? key : NULL, len);
OUTPUT:
RETVAL
@@ -403,7 +433,11 @@ tag_by_id(h, tag)
int tag
PREINIT:
void *ret = NULL;
+#if defined(RPM2_RPM40) || defined(RPM2_RPM41)
int type;
+#else
+ rpmTagType type;
+#endif
int n;
int ok;
PPCODE:
@@ -513,9 +547,18 @@ _header_sprintf(h, format)
PREINIT:
char * s;
PPCODE:
+#if defined(RPM2_RPM40) || defined(RPM2_RPM41)
s = headerSprintf(h, format, rpmTagTable, rpmHeaderFormats, NULL);
+#else
+ s = headerFormat(h, format, NULL);
+#endif
PUSHs(sv_2mortal(newSVpv((char *)s, 0)));
+/* By the way, the #if below is completely useless, free() would work for both */
+#if defined(RPM2_RPM40) || defined(RPM2_RPM41)
s = _free(s);
+#else
+ free(s);
+#endif
MODULE = RPM2 PACKAGE = RPM2::C::Transaction
diff -up RPM2-0.67/test.pl.rpm46 RPM2-0.67/test.pl
--- RPM2-0.67/test.pl.rpm46 2008-12-12 01:07:41.000000000 +0100
+++ RPM2-0.67/test.pl 2008-12-12 01:07:41.000000000 +0100
@@ -126,7 +126,7 @@ ok(RPM2->expand_macro("%rpm2_test_macro"
RPM2->delete_macro("rpm2_test_macro");
ok(RPM2->expand_macro("%rpm2_test_macro") eq "%rpm2_test_macro");
-ok(RPM2->rpm_api_version == 4.1 or RPM2->rpm_api_version == 4.0);
+ok(RPM2->rpm_api_version =~ /4.[016]/);
ok(RPM2->rpm_api_version == 4.0 or RPM2->vsf_nosha1 == 65536);
#