Update to rpm-4.0.x API.
CVS patchset: 5307 CVS date: 2002/02/09 20:08:32
This commit is contained in:
parent
8ddeef05cd
commit
65d033ec86
|
@ -5,17 +5,33 @@
|
|||
# (or whatever database library rpm was compiled with).
|
||||
|
||||
|
||||
CFLAGS= -O2 -Wall -I/usr/include/rpm
|
||||
VER = 4.0.4
|
||||
|
||||
LDADD= -lrpm-$(VER) -lrpmdb-$(VER) -lrpmio-$(VER) -lpopt -lz
|
||||
|
||||
COMPILE = $(CC) $(CFLAGS)
|
||||
LINK = $(CC)
|
||||
|
||||
all: dumprpm showdb showdb2
|
||||
|
||||
dumprpm: dumprpm.c
|
||||
gcc -Wall dumprpm.c -lrpm -lintl -lgz -o dumprpm
|
||||
dumprpm: dumprpm.o
|
||||
$(LINK) -o $@ $< $(LDADD)
|
||||
|
||||
showdb: showdb.c
|
||||
gcc -Wall showdb.c -lrpm -lintl -ldb1 -lgz -o showdb
|
||||
showdb: showdb.o
|
||||
$(LINK) -o $@ $< $(LDADD)
|
||||
|
||||
showdb2: showdb2.c
|
||||
gcc -Wall showdb2.c -lrpm -lintl -ldb1 -lgz -o showdb2
|
||||
showdb2: showdb2.o
|
||||
$(LINK) -o $@ $< $(LDADD)
|
||||
|
||||
clean:
|
||||
rm -f dumprpm showdb showdb2
|
||||
rm -f *.o *.lo dumprpm showdb showdb2
|
||||
|
||||
dumprpm.o: dumprpm.c
|
||||
$(COMPILE) -o $@ -c dumprpm.c
|
||||
|
||||
showdb.o: showdb.c
|
||||
$(COMPILE) -o $@ -c showdb.c
|
||||
|
||||
showdb2.o: showdb2.c
|
||||
$(COMPILE) -o $@ -c showdb2.c
|
||||
|
|
|
@ -10,96 +10,100 @@
|
|||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <rpm/rpmlib.h>
|
||||
#include <rpmlib.h>
|
||||
|
||||
#ifndef HEADER_DUMP_INLINE
|
||||
/**
|
||||
* Dump a header in human readable format (for debugging).
|
||||
* @param h header
|
||||
* @param flags 0 or HEADER_DUMP_INLINE
|
||||
* @param tags array of tag name/value pairs
|
||||
*/
|
||||
void headerDump(Header h, FILE *f, int flags,
|
||||
const struct headerTagTableEntry_s * tags)
|
||||
/*@globals fileSystem @*/
|
||||
/*@modifies f, fileSystem @*/;
|
||||
#define HEADER_DUMP_INLINE 1
|
||||
#endif
|
||||
|
||||
static const struct headerTagTableEntry_s rpmSigTagTbl[] = {
|
||||
{ "RPMSIGTAG_SIZE", RPMSIGTAG_SIZE, },
|
||||
{ "RPMSIGTAG_PGP", RPMSIGTAG_PGP, },
|
||||
{ "RPMSIGTAG_MD5", RPMSIGTAG_MD5, },
|
||||
{ "RPMSIGTAG_GPG", RPMSIGTAG_GPG, },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
HeaderIterator iter;
|
||||
Header h, sig;
|
||||
int_32 itertag, type, count;
|
||||
void *p = NULL;
|
||||
char *name;
|
||||
FD_t fd;
|
||||
int stat;
|
||||
HeaderIterator hi;
|
||||
Header h, sig;
|
||||
int_32 tag, type, count;
|
||||
void * p = NULL;
|
||||
char * name;
|
||||
FD_t fd;
|
||||
int rc;
|
||||
|
||||
if( argc == 1 ) {
|
||||
fd = fdDup( STDIN_FILENO );
|
||||
} else {
|
||||
fd = fdOpen( argv[1], O_RDONLY, 0644 );
|
||||
}
|
||||
if( argc == 1 )
|
||||
fd = Fopen("-", "r.ufdio" );
|
||||
else
|
||||
fd = Fopen( argv[1], "r.ufdio" );
|
||||
|
||||
if( !fdValid(fd) ) {
|
||||
perror( "open" );
|
||||
exit( 1 );
|
||||
}
|
||||
if( fd == NULL || Ferror(fd) ) {
|
||||
fprintf(stderr, "cannot open %s: %s\n",
|
||||
(argc == 1 ? "<stdin>" : argv[1]), Fstrerror(fd));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
stat = rpmReadPackageInfo( fd, &sig, &h );
|
||||
if( stat ) {
|
||||
fprintf( stderr, "rpmReadPackageInfo error status: %d\n%s\n",
|
||||
stat, strerror(errno) );
|
||||
exit( stat );
|
||||
}
|
||||
rc = rpmReadPackageInfo( fd, &sig, &h );
|
||||
if ( rc ) {
|
||||
fprintf( stderr, "rpmReadPackageInfo error status: %d\n\n", rc );
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
headerGetEntry( h, RPMTAG_NAME, &type, (void**)&name, &count );
|
||||
headerGetEntry( h, RPMTAG_NAME, &type, (void**)&name, &count );
|
||||
|
||||
if( headerIsEntry(h,RPMTAG_PREIN) ) {
|
||||
printf( "There is a preinstall script for %s\n", name );
|
||||
}
|
||||
if( headerIsEntry(h,RPMTAG_POSTIN) ) {
|
||||
printf( "There is a postinstall script for %s\n", name );
|
||||
}
|
||||
if( headerIsEntry(h,RPMTAG_PREIN) ) {
|
||||
printf( "There is a preinstall script for %s\n", name );
|
||||
}
|
||||
if( headerIsEntry(h,RPMTAG_POSTIN) ) {
|
||||
printf( "There is a postinstall script for %s\n", name );
|
||||
}
|
||||
|
||||
|
||||
/* NOTE:
|
||||
* This is actually rather a ridiculous thing to do, since headerDump
|
||||
* will incorrectly assume header types (RPMTAG_NAME, RPMTAG_RELEASE,
|
||||
* RPMTAG_SUMMARY). Since we're passing a signature, the correct types
|
||||
* would be (RPMSIGTAG_SIZE, RPMSIGTAG_PGP, and RPMSIGTAG_MD5).
|
||||
* TO FIX:
|
||||
* I think rpm's tagtable.c should define an rpmSigTable global var.
|
||||
* This is the perfect dual to rpmTagTable and would be passed to
|
||||
* headerDump when appropriate. It looks like someone intended to do
|
||||
* this at one time, but never finished it?
|
||||
*/
|
||||
printf( "Dumping signatures...\n" );
|
||||
/* Use HEADER_DUMP_INLINE to include inline dumps of header items */
|
||||
headerDump( sig, stdout, HEADER_DUMP_INLINE, rpmSigTagTbl );
|
||||
|
||||
printf( "Dumping signatures...\n" );
|
||||
/* Use HEADER_DUMP_INLINE to include inline dumps of header items */
|
||||
headerDump( sig, stdout, HEADER_DUMP_INLINE, rpmTagTable );
|
||||
rpmFreeSignature( sig );
|
||||
|
||||
rpmFreeSignature( sig );
|
||||
printf( "Iterating through the header...\n" );
|
||||
hi = headerInitIterator( h );
|
||||
while( headerNextIterator( hi, &tag, &type, &p, &count ) ) {
|
||||
/* printf( "tag=%04d, type=%08lX, p=%08lX, c=%08lX\n",
|
||||
(int)tag, (long)type, (long)p, (long)count ); */
|
||||
|
||||
printf( "Iterating through the header...\n" );
|
||||
iter = headerInitIterator( h );
|
||||
while( headerNextIterator( iter, &itertag, &type, &p, &count ) ) {
|
||||
/* printf( "itertag=%04d, type=%08lX, p=%08lX, c=%08lX\n",
|
||||
(int)itertag, (long)type, (long)p, (long)count ); */
|
||||
|
||||
switch( itertag ) {
|
||||
case RPMTAG_SUMMARY:
|
||||
if( type == RPM_I18NSTRING_TYPE ) {
|
||||
/* We'll only print out the first string if there's an array */
|
||||
printf( "The Summary: \"%s\"\n", *(char**)p );
|
||||
}
|
||||
if( type == RPM_STRING_TYPE ) {
|
||||
printf( "The Summary: \"%s\"\n", (char*)p );
|
||||
}
|
||||
break;
|
||||
case RPMTAG_FILENAMES:
|
||||
printf( "There are %d files in %s\n", count, name );
|
||||
break;
|
||||
switch( tag ) {
|
||||
case RPMTAG_SUMMARY:
|
||||
if( type == RPM_I18NSTRING_TYPE ) {
|
||||
/* We'll only print out the first string if there's an array */
|
||||
printf( "The Summary: \"%s\"\n", *(char**)p );
|
||||
}
|
||||
|
||||
/* rpmlib allocates a buffer to return these two values... */
|
||||
if( type == RPM_STRING_ARRAY_TYPE || type == RPM_I18NSTRING_TYPE ) {
|
||||
free( p );
|
||||
if( type == RPM_STRING_TYPE ) {
|
||||
printf( "The Summary: \"%s\"\n", (char*)p );
|
||||
}
|
||||
break;
|
||||
case RPMTAG_BASENAMES:
|
||||
printf( "There are %d files in %s\n", count, name );
|
||||
break;
|
||||
}
|
||||
|
||||
headerFreeIterator( iter );
|
||||
headerFree( h );
|
||||
/* rpmlib allocates a buffer to return these two values... */
|
||||
headerFreeData(p, type);
|
||||
}
|
||||
|
||||
return 0;
|
||||
headerFreeIterator( hi );
|
||||
headerFree( h );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -15,45 +15,54 @@
|
|||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <rpm/rpmlib.h>
|
||||
#include <rpmlib.h>
|
||||
|
||||
#ifndef HEADER_DUMP_INLINE
|
||||
/**
|
||||
* Dump a header in human readable format (for debugging).
|
||||
* @param h header
|
||||
* @param flags 0 or HEADER_DUMP_INLINE
|
||||
* @param tags array of tag name/value pairs
|
||||
*/
|
||||
void headerDump(Header h, FILE *f, int flags,
|
||||
const struct headerTagTableEntry_s * tags)
|
||||
/*@globals fileSystem @*/
|
||||
/*@modifies f, fileSystem @*/;
|
||||
#define HEADER_DUMP_INLINE 1
|
||||
#endif
|
||||
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
Header h;
|
||||
int offset;
|
||||
int_32 type, count;
|
||||
char *name;
|
||||
rpmdb db;
|
||||
rpmdbMatchIterator mi;
|
||||
Header h;
|
||||
int_32 type, count;
|
||||
char *name;
|
||||
rpmdb db;
|
||||
|
||||
rpmReadConfigFiles( NULL, NULL );
|
||||
rpmReadConfigFiles( NULL, NULL );
|
||||
|
||||
printf( "Calling rpmdbOpen\n" );
|
||||
if( rpmdbOpen( "", &db, O_RDONLY, 0644 ) != 0 ) {
|
||||
fprintf( stderr, "cannot open database!\n" );
|
||||
exit( 1 );
|
||||
}
|
||||
printf( "rpmdbOpen done.\n" );
|
||||
if( rpmdbOpen( "", &db, O_RDONLY, 0644 ) != 0 ) {
|
||||
fprintf( stderr, "cannot open database!\n" );
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
offset = rpmdbFirstRecNum( db );
|
||||
while( offset ) {
|
||||
h = rpmdbGetRecord( db, offset );
|
||||
if( !h ) {
|
||||
fprintf( stderr, "Header Read Failed!\n" );
|
||||
exit( 1 );
|
||||
}
|
||||
mi = rpmdbInitIterator(db, RPMDBI_PACKAGES, NULL, 0);
|
||||
while ((h = rpmdbNextIterator(mi)) != NULL) {
|
||||
|
||||
headerGetEntry( h, RPMTAG_NAME, &type, (void**)&name, &count );
|
||||
if( strcmp(name,argv[1]) == 0 ) {
|
||||
headerDump( h, stdout, 1, rpmTagTable );
|
||||
}
|
||||
headerGetEntry( h, RPMTAG_NAME, &type, (void**)&name, &count );
|
||||
if( strcmp(name,argv[1]) == 0 )
|
||||
headerDump( h, stdout, HEADER_DUMP_INLINE, rpmTagTable );
|
||||
|
||||
headerFree( h );
|
||||
offset = rpmdbNextRecNum( db, offset );
|
||||
}
|
||||
/*
|
||||
* Note that the header reference is "owned" by the iterator,
|
||||
* so no headerFree() is necessary.
|
||||
*/
|
||||
|
||||
rpmdbClose( db );
|
||||
}
|
||||
mi = rpmdbFreeIterator(mi);
|
||||
|
||||
return 0;
|
||||
rpmdbClose( db );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -15,44 +15,54 @@
|
|||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <rpm/rpmlib.h>
|
||||
#include <rpmlib.h>
|
||||
|
||||
#ifndef HEADER_DUMP_INLINE
|
||||
/**
|
||||
* Dump a header in human readable format (for debugging).
|
||||
* @param h header
|
||||
* @param flags 0 or HEADER_DUMP_INLINE
|
||||
* @param tags array of tag name/value pairs
|
||||
*/
|
||||
void headerDump(Header h, FILE *f, int flags,
|
||||
const struct headerTagTableEntry_s * tags)
|
||||
/*@globals fileSystem @*/
|
||||
/*@modifies f, fileSystem @*/;
|
||||
#define HEADER_DUMP_INLINE 1
|
||||
#endif
|
||||
|
||||
int main( int argc, char **argv )
|
||||
{
|
||||
Header h;
|
||||
int stat;
|
||||
rpmdb db;
|
||||
dbiIndexSet matches;
|
||||
rpmdbMatchIterator mi;
|
||||
Header h;
|
||||
rpmdb db;
|
||||
|
||||
if( argc != 2 ) {
|
||||
fprintf( stderr, "usage: showdb2 <search term>\n" );
|
||||
exit( 1 );
|
||||
}
|
||||
if( argc != 2 ) {
|
||||
fprintf( stderr, "usage: showdb2 <search term>\n" );
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
rpmReadConfigFiles( NULL, NULL );
|
||||
rpmReadConfigFiles( NULL, NULL );
|
||||
|
||||
if( rpmdbOpen( "", &db, O_RDONLY, 0644 ) != 0 ) {
|
||||
fprintf( stderr, "cannot open RPM database.\n" );
|
||||
exit( 1 );
|
||||
}
|
||||
if( rpmdbOpen( "", &db, O_RDONLY, 0644 ) != 0 ) {
|
||||
fprintf( stderr, "cannot open RPM database.\n" );
|
||||
exit( 1 );
|
||||
}
|
||||
|
||||
stat = rpmdbFindPackage( db, argv[1], &matches );
|
||||
printf( "Status is: %d\n", stat );
|
||||
if( stat == 0 ) {
|
||||
if( matches.count ) {
|
||||
printf( "Number of matches: %d\n", matches.count );
|
||||
h = rpmdbGetRecord( db, matches.recs[0].recOffset );
|
||||
if( h ) {
|
||||
headerDump( h, stdout, HEADER_DUMP_INLINE, rpmTagTable );
|
||||
headerFree( h );
|
||||
}
|
||||
}
|
||||
dbiFreeIndexRecord( matches );
|
||||
}
|
||||
mi = rpmdbInitIterator(db, RPMTAG_BASENAMES, argv[1], 0);
|
||||
while ((h = rpmdbNextIterator(mi)) != NULL) {
|
||||
|
||||
rpmdbClose( db );
|
||||
headerDump( h, stdout, HEADER_DUMP_INLINE, rpmTagTable );
|
||||
|
||||
return 0;
|
||||
/*
|
||||
* Note that the header reference is "owned" by the iterator,
|
||||
* so no headerFree() is necessary.
|
||||
*/
|
||||
}
|
||||
mi = rpmdbFreeIterator(mi);
|
||||
|
||||
rpmdbClose( db );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue