diff options
-rw-r--r-- | perl/MANIFEST | 2 | ||||
-rw-r--r-- | perl/Makefile.PL | 13 | ||||
-rwxr-xr-x | perl/check | 23 | ||||
-rw-r--r-- | perl/header.xs | 211 | ||||
-rw-r--r-- | perl/rpm.pm | 8 | ||||
-rw-r--r-- | perl/rpm.xs | 300 | ||||
-rw-r--r-- | perl/transaction.xs | 56 | ||||
-rw-r--r-- | perl/typemap | 9 |
8 files changed, 376 insertions, 246 deletions
diff --git a/perl/MANIFEST b/perl/MANIFEST index 24d9a22a3..9e352e245 100644 --- a/perl/MANIFEST +++ b/perl/MANIFEST @@ -8,3 +8,5 @@ test.pl typemap foo.i386.rpm junk.xs +transaction.xs +header.xs diff --git a/perl/Makefile.PL b/perl/Makefile.PL index dbee47b02..7c9fd4df5 100644 --- a/perl/Makefile.PL +++ b/perl/Makefile.PL @@ -1,11 +1,18 @@ use ExtUtils::MakeMaker; # See lib/ExtUtils/MakeMaker.pm for details of how to influence # the contents of the Makefile that is written. + WriteMakefile( 'NAME' => 'rpm', 'OBJECT' => 'rpm.o constant.o', 'VERSION_FROM' => 'rpm.pm', # finds $VERSION - 'LIBS' => ['-lrpm -lz'], # e.g., '-lm' - 'DEFINE' => '-Wall', # e.g., '-DHAVE_SOMETHING' - 'INC' => '-I/usr/include/rpm', # e.g., '-I/usr/include/other' + 'LIBS' => ['-lrpm -lz -ldb1'], # e.g., '-lm' + 'CCFLAGS' => '-Dbool=char -DHAS_BOOL', + 'OPTIMIZE'=> '-Wall -g', + #'DEFINE' => '', # e.g., '-DHAVE_SOMETHING' + 'INC' => '-I/usr/include/rpm', # e.g., '-I/usr/include/other' + 'depend' => { 'rpm.c' => 'transaction.xs header.xs db.xs' }, ); + +# $self->{'MAP_PRELIBS'} = ['-lnsl -lndbm -lgdbm -ldb1 -ldl -lm -lc -lposix -lcrypt -lrpm -lz']; + diff --git a/perl/check b/perl/check index 9a1cd7416..b9232d813 100755 --- a/perl/check +++ b/perl/check @@ -7,15 +7,19 @@ my $testfile = "foo.i386.rpm"; my $header = rpm::Header($testfile); +print "Test No. 1\n"; if ($header) { my @foo_test = (); my %foo_test = (); my $key; print "call to the header function SUCCEEDED\n"; - @foo_test = $header->ItemByVal(1081); - print "values returned ", @foo_test, "\n\n\n"; + @foo_test = $header->ItemByVal(1027); + print "values returned by ItemByVal(1027) ", join(' ',@foo_test), "\n\n\n"; + @foo_test = $header->ItemByName("Filenames"); + print "values returned by ItemByName(\"Filenames\") ", join(' ',@foo_test), "\n\n\n"; + print "\n\nTest No. 2\n"; %foo_test = $header->List(); foreach $key (sort keys %foo_test) { my $foo_it; @@ -26,8 +30,23 @@ if ($header) { print "\n"; } + print "\n\nTest No. 3\n"; print "The number of header tags is: ", scalar $header->Tags(), "\n"; + print "\n\nTest No. 4\n"; + rpm::Debug(); + my $db = rpm::dbOpen(); + if ($db) { + my $rec = $db->First(); + while ($rec != 0) { + my $hdr = $db->Record($rec); + print "Found header: Name=[", $hdr->ItemByName("Name"), "]\n"; + $rec = $db->Next($rec); + } + $db->Close(); + } else { + print "Could not open the RPM database! Error code: ", rpm::Error(), "\n"; + } } else { print "call to the header function FAILED\n"; } diff --git a/perl/header.xs b/perl/header.xs new file mode 100644 index 000000000..d132a7884 --- /dev/null +++ b/perl/header.xs @@ -0,0 +1,211 @@ + +MODULE = rpm PACKAGE = Header PREFIX = Header + +AV * +HeaderItemByValRef(header, item) + Header header + int item + PREINIT: + int_32 count, type; + int rc; + void * value; + char ** src; + AV * array; + CODE: + rc = headerGetEntry(header, item, &type, &value, &count); + array = newAV(); + if (rc != 0) { + switch(type) { + case RPM_CHAR_TYPE: + while (count-- > 0) { + av_push(array, newSViv((char) (int) value)); + value++; + } + break; + case RPM_INT8_TYPE: + while (count-- > 0) { + av_push(array, newSViv((int_8) (int) value)); + value++; + } + break; + case RPM_INT16_TYPE: + while (count-- > 0) { + av_push(array, newSViv((int_16) (int) value)); + value++; + } + break; + case RPM_INT32_TYPE: + while (count-- > 0) { + av_push(array, newSViv((int_32)value)); + value++; + } + break; + case RPM_STRING_TYPE: + av_push(array, newSVpv((char *)value, 0)); + break; + case RPM_BIN_TYPE: + /* XXX: this looks mostly unused - how do we deal with it? */ + break; + case RPM_STRING_ARRAY_TYPE: + case RPM_I18NSTRING_TYPE: + src = (char **) value; + while (count--) { + av_push(array, newSVpv(*src++, 0)); + } + free(value); + break; + } + } + RETVAL = array; + OUTPUT: + RETVAL + +AV * +HeaderItemByNameRef(header, tag) + Header header + const char * tag + PREINIT: + int_32 count, type, item = -1; + int rc, i; + void * value; + char ** src; + AV * array; + CODE: + /* walk first through the list of items and get the proper value */ + for (i = 0; i < rpmTagTableSize; i++) { + if (rpmTagTable[i].name != NULL && strcasecmp(tag, rpmTagTable[i].name + 7) == 0) { + item = rpmTagTable[i].val; + break; + } + } + rc = headerGetEntry(header, item, &type, &value, &count); + array = newAV(); + if (rc != 0) { + switch(type) { + case RPM_CHAR_TYPE: + while (count-- > 0) { + av_push(array, newSViv((char) (int) value)); + value++; + } + break; + case RPM_INT8_TYPE: + while (count-- > 0) { + av_push(array, newSViv((int_8) (int) value)); + value++; + } + break; + case RPM_INT16_TYPE: + while (count-- > 0) { + av_push(array, newSViv((int_16) (int) value)); + value++; + } + break; + case RPM_INT32_TYPE: + while (count-- > 0) { + av_push(array, newSViv((int_32)value)); + value++; + } + break; + case RPM_STRING_TYPE: + av_push(array, newSVpv((char *)value, 0)); + break; + case RPM_BIN_TYPE: + /* XXX: this looks mostly unused - how do we deal with it? */ + break; + case RPM_STRING_ARRAY_TYPE: + case RPM_I18NSTRING_TYPE: + src = (char **) value; + while (count--) { + av_push(array, newSVpv(*src++, 0)); + } + free(value); + break; + } + } + RETVAL = array; + OUTPUT: + RETVAL + + +HV * +HeaderListRef(header) + Header header + PREINIT: + HeaderIterator iterator; + int_32 tag, type, count; + void *value; + CODE: + RETVAL = newHV(); + iterator = headerInitIterator(header); + while (headerNextIterator(iterator, &tag, &type, &value, &count)) { + SV ** sv; + AV * array; + char ** src; + char * tagStr = tagName(tag); + array = newAV(); + switch(type) { + case RPM_CHAR_TYPE: + while (count-- > 0) { + av_push(array, newSViv((char) (int) value)); + value++; + } + break; + case RPM_INT8_TYPE: + while (count-- > 0) { + av_push(array, newSViv((int_8) (int) value)); + value++; + } + break; + case RPM_INT16_TYPE: + while (count-- > 0) { + av_push(array, newSViv((int_16) (int) value)); + value++; + } + break; + case RPM_INT32_TYPE: + while (count-- > 0) { + av_push(array, newSViv((int_32)value)); + value++; + } + break; + case RPM_STRING_TYPE: + av_push(array, newSVpv((char *)value, 0)); + break; + case RPM_BIN_TYPE: + /* XXX: this looks mostly unused - how do we deal with it? */ + break; + case RPM_STRING_ARRAY_TYPE: + case RPM_I18NSTRING_TYPE: + /* we have to build an array first */ + src = (char **) value; + while (count--) { + av_push(array, newSVpv(*src++, 0)); + } + free(value); + break; + } + sv = hv_store(RETVAL, tagStr, strlen(tagStr), newRV_inc((SV*)array), 0); + } + headerFreeIterator(iterator); + OUTPUT: + RETVAL + +AV * +HeaderTagsRef(header) + Header header + PREINIT: + HeaderIterator iterator; + int_32 tag, type; + void *value; + CODE: + RETVAL = newAV(); + iterator = headerInitIterator(header); + while (headerNextIterator(iterator, &tag, &type, &value, NULL)) { + av_push(RETVAL, newSVpv(tagName(tag), 0)); + if (type == RPM_STRING_ARRAY_TYPE || type == RPM_I18NSTRING_TYPE) + free(value); + } + headerFreeIterator(iterator); + OUTPUT: + RETVAL + diff --git a/perl/rpm.pm b/perl/rpm.pm index 63ee94aef..b86f44f1d 100644 --- a/perl/rpm.pm +++ b/perl/rpm.pm @@ -44,7 +44,7 @@ bootstrap rpm $VERSION; # Preloaded methods go here. -sub HeaderPtr::ItemByName { +sub Header::ItemByName { my $header = shift; my $item = shift; my $item_index = shift; @@ -56,7 +56,7 @@ sub HeaderPtr::ItemByName { } } -sub HeaderPtr::ItemByVal { +sub Header::ItemByVal { my $header = shift; my $item = shift; my $item_index = shift; @@ -68,13 +68,13 @@ sub HeaderPtr::ItemByVal { } } -sub HeaderPtr::List { +sub Header::List { my $header = shift; return %{$header->ListRef()}; } -sub HeaderPtr::Tags { +sub Header::Tags { my $header = shift; return @{$header->TagsRef()}; diff --git a/perl/rpm.xs b/perl/rpm.xs index d4c6573f5..d0870d0df 100644 --- a/perl/rpm.xs +++ b/perl/rpm.xs @@ -1,7 +1,7 @@ /* * Perl interface to rpmlib * - * $Id: rpm.xs,v 1.3 1999/07/14 22:06:21 gafton Exp $ + * $Id: rpm.xs,v 1.4 1999/07/16 08:44:54 gafton Exp $ */ #include "EXTERN.h" @@ -18,8 +18,6 @@ #include <sys/stat.h> #include <fcntl.h> -typedef rpmTransactionSet_s * Transaction; - /* * External functions */ @@ -30,12 +28,19 @@ MODULE = rpm PACKAGE = rpm PROTOTYPES: ENABLE +BOOT: +# The following message will be printed when the +# bootstrap function executes. + if (rpmReadConfigFiles(NULL, NULL) != 0) { + XSRETURN_NO; + } + double constant(name,arg) char * name int arg -Header * +Header Header(package) const char * package PREINIT: @@ -44,10 +49,10 @@ Header(package) int isSource; int had_error = 0; CODE: - New(1,RETVAL,1,Header); + /* New(1,RETVAL,1,Header); */ file_desc = fdOpen(package, O_RDONLY, 0); if (file_desc != NULL && RETVAL != NULL) { - rc = rpmReadPackageHeader(file_desc, RETVAL, &isSource, NULL, NULL); + rc = rpmReadPackageHeader(file_desc, &RETVAL, &isSource, NULL, NULL); if (rc != 0) { had_error++; } @@ -61,255 +66,84 @@ Header(package) if (had_error) { ST(0) = &PL_sv_undef; } else { - sv_setref_pv(ST(0), "HeaderPtr", (void*)RETVAL); + sv_setref_pv(ST(0), "Header", (void*)RETVAL); } -Transaction * +rpmTransactionSet Transaction(header) - Header * header - - -MODULE = rpm PACKAGE = HeaderPtr PREFIX = Header + Header header + CODE: + ST(0) = sv_newmortal(); + ST(0) = &PL_sv_undef; -AV * -HeaderItemByValRef(header, item) - Header * header - int item +rpmdb +dbOpen(root = "", forWrite = 0) + const char * root + int forWrite PREINIT: - int_32 count, type; - int rc; - void * value; - char ** src; - AV * array; -CODE: - rc = headerGetEntry(*header, item, &type, &value, &count); - array = newAV(); - if (rc != 0) { - switch(type) { - case RPM_CHAR_TYPE: - while (count-- > 0) { - av_push(array, newSViv((char) (int) value)); - value++; - } - break; - case RPM_INT8_TYPE: - while (count-- > 0) { - av_push(array, newSViv((int_8) (int) value)); - value++; - } - break; - case RPM_INT16_TYPE: - while (count-- > 0) { - av_push(array, newSViv((int_16) (int) value)); - value++; - } - break; - case RPM_INT32_TYPE: - while (count-- > 0) { - av_push(array, newSViv((int_32)value)); - value++; - } - break; - case RPM_STRING_TYPE: - av_push(array, newSVpv((char *)value, 0)); - break; - case RPM_BIN_TYPE: - /* XXX: this looks mostly unused - how do we deal with it? */ - break; - case RPM_STRING_ARRAY_TYPE: - case RPM_I18NSTRING_TYPE: - src = (char **) value; - while (count--) { - av_push(array, newSVpv(*src++, 0)); - } - free(value); - break; - } + int retval; + CODE: + retval = rpmdbOpen(root, &RETVAL, forWrite ? O_RDWR | O_CREAT : O_RDONLY, 0644); + printf("\nretval is %d\n", retval); + ST(0) = sv_newmortal(); + if (retval != 0) { + ST(0) = &PL_sv_undef; + } else { + sv_setref_pv(ST(0), "rpmdb", (void *)RETVAL); } - RETVAL = array; + + +int +dbInit(root = NULL) + char * root + CODE: + RETVAL = rpmdbInit(root, 0); OUTPUT: RETVAL -AV * -HeaderItemByNameRef(header, tag) - Header * header - const char * tag - PREINIT: - int_32 count, type, item = -1; - int rc, i; - void * value; - char ** src; - AV * array; +int +dbRebuild(root = NULL) + char * root CODE: - /* walk first through the list of items and get the proper value */ - for (i = 0; i < rpmTagTableSize; i++) { - if (strcasecmp(tag, rpmTagTable[i].name) == 0) { - item = rpmTagTable[i].val; - break; - } - } - rc = headerGetEntry(*header, item, &type, &value, &count); - array = newAV(); - if (rc != 0) { - switch(type) { - case RPM_CHAR_TYPE: - while (count-- > 0) { - av_push(array, newSViv((char) (int) value)); - value++; - } - break; - case RPM_INT8_TYPE: - while (count-- > 0) { - av_push(array, newSViv((int_8) (int) value)); - value++; - } - break; - case RPM_INT16_TYPE: - while (count-- > 0) { - av_push(array, newSViv((int_16) (int) value)); - value++; - } - break; - case RPM_INT32_TYPE: - while (count-- > 0) { - av_push(array, newSViv((int_32)value)); - value++; - } - break; - case RPM_STRING_TYPE: - av_push(array, newSVpv((char *)value, 0)); - break; - case RPM_BIN_TYPE: - /* XXX: this looks mostly unused - how do we deal with it? */ - break; - case RPM_STRING_ARRAY_TYPE: - case RPM_I18NSTRING_TYPE: - src = (char **) value; - while (count--) { - av_push(array, newSVpv(*src++, 0)); - } - free(value); - break; - } - } - RETVAL = array; + RETVAL = rpmdbRebuild(root); OUTPUT: RETVAL -HV * -HeaderListRef(header) - Header * header - PREINIT: - HeaderIterator iterator; - int_32 tag, type, count; - void *value; +int +Error() CODE: - RETVAL = newHV(); - iterator = headerInitIterator(*header); - while (headerNextIterator(iterator, &tag, &type, &value, &count)) { - SV ** sv; - AV * array; - char ** src; - char * tagStr = tagName(tag); - array = newAV(); - switch(type) { - case RPM_CHAR_TYPE: - while (count-- > 0) { - av_push(array, newSViv((char) (int) value)); - value++; - } - break; - case RPM_INT8_TYPE: - while (count-- > 0) { - av_push(array, newSViv((int_8) (int) value)); - value++; - } - break; - case RPM_INT16_TYPE: - while (count-- > 0) { - av_push(array, newSViv((int_16) (int) value)); - value++; - } - break; - case RPM_INT32_TYPE: - while (count-- > 0) { - av_push(array, newSViv((int_32)value)); - value++; - } - break; - case RPM_STRING_TYPE: - av_push(array, newSVpv((char *)value, 0)); - break; - case RPM_BIN_TYPE: - /* XXX: this looks mostly unused - how do we deal with it? */ - break; - case RPM_STRING_ARRAY_TYPE: - case RPM_I18NSTRING_TYPE: - /* we have to build an array first */ - src = (char **) value; - while (count--) { - av_push(array, newSVpv(*src++, 0)); - } - free(value); - break; - } - sv = hv_store(RETVAL, tagStr, strlen(tagStr), newRV_inc((SV*)array), 0); - } - headerFreeIterator(iterator); + RETVAL = rpmErrorCode(); OUTPUT: RETVAL -AV * -HeaderTagsRef(header) - Header * header - PREINIT: - HeaderIterator iterator; - int_32 tag, type; - void *value; - CODE: - RETVAL = newAV(); - iterator = headerInitIterator(*header); - while (headerNextIterator(iterator, &tag, &type, &value, NULL)) { - av_push(RETVAL, newSVpv(tagName(tag), 0)); - if (type == RPM_STRING_ARRAY_TYPE || type == RPM_I18NSTRING_TYPE) - free(value); +void +Debug(enable = 1) + int enable + CODE: + if (enable) { + rpmSetVerbosity(RPMMESS_DEBUG); + } else { + rpmSetVerbosity(RPMMESS_QUIET); } - headerFreeIterator(iterator); + +char * +GetVar(var) + int var + CODE: + RETVAL = rpmGetVar(var); OUTPUT: RETVAL -MODULE = rpm PACKAGE = TransactionPtr PREFIX = Trans - -int -TransAdd(trans, header) - Transaction * trans - Header * header - -int -TransDepCheck(trans) - Transaction * trans - -int -TransRun(trans) - Transaction * trans - -Transaction * -TransOrder(trans) - Transaction *trans - -int -TransDealloc(trans) - Transaction * trans +void +SetVar(var, value) + int var + char * value + CODE: + rpmSetVar(var, value); -int -TransGetAttr(trans, name) - Transaction * trans - const char * name +INCLUDE: db.xs +INCLUDE: header.xs +INCLUDE: transaction.xs -int -TransSetAttr(trans, name, val) - Transaction * trans - const char * name - void * val diff --git a/perl/transaction.xs b/perl/transaction.xs new file mode 100644 index 000000000..02aad7021 --- /dev/null +++ b/perl/transaction.xs @@ -0,0 +1,56 @@ + +MODULE = rpm PACKAGE = rpmTransactionSet PREFIX = Transaction + +int +TransactionAdd(trans, header) + rpmTransactionSet trans + Header header + CODE: + ST(0) = sv_newmortal(); + ST(0) = &PL_sv_undef; + +int +TransactionDepCheck(trans) + rpmTransactionSet trans + CODE: + ST(0) = sv_newmortal(); + ST(0) = &PL_sv_undef; + +int +TransactionRun(trans) + rpmTransactionSet trans + CODE: + ST(0) = sv_newmortal(); + ST(0) = &PL_sv_undef; + +rpmTransactionSet +TransactionOrder(trans) + rpmTransactionSet trans + CODE: + ST(0) = sv_newmortal(); + ST(0) = &PL_sv_undef; + +int +TransactionDealloc(trans) + rpmTransactionSet trans + CODE: + ST(0) = sv_newmortal(); + ST(0) = &PL_sv_undef; + +int +TransactionGetAttr(trans, name) + rpmTransactionSet trans + const char * name + CODE: + ST(0) = sv_newmortal(); + ST(0) = &PL_sv_undef; + +int +TransactionSetAttr(trans, name, val) + rpmTransactionSet trans + const char * name + void * val + CODE: + ST(0) = sv_newmortal(); + ST(0) = &PL_sv_undef; + diff --git a/perl/typemap b/perl/typemap index 87037b88e..78ccb99ad 100644 --- a/perl/typemap +++ b/perl/typemap @@ -1,8 +1,9 @@ -/* $Id: typemap,v 1.3 1999/07/14 22:06:21 gafton Exp $ */ +/* $Id: typemap,v 1.4 1999/07/16 08:44:54 gafton Exp $ */ TYPEMAP -Header * T_PTROBJ -const char * T_PV -Transaction * T_PTROBJ +Header T_PTROBJ +rpmTransactionSet T_PTROBJ +rpmdb T_PTROBJ +const char * T_PV |