[Rpm-maint] rpm tag query and headerSprintf

Vento Neicapelli lascoscazzato at hotmail.com
Fri Dec 14 18:37:18 UTC 2007




 
Dear All,
 
I'm trying to use the librpm in a custom application, I use rpm 4.4.2.1 and I need your help about tag querying...
 
1) Have you got any snip of code to use the headerSprintf probably I'm doing it wrong...
2)  given the  prototype:
char * headerSprintf(Header h, const char * fmt, const struct headerTagTableEntry_s * tags, const struct headerSprintfExtension_s * extensions, /*@null@*/ /*@out@*/ errmsg_t * errmsg)
if I understand the tag fmt should have the same format of the rpm tool (cli version) with  --queryformat switch....or not?
 
Below you find the code I wrote just to get familiar with rpmlib functions: it tries to search a package (by name) and then prints some tags....
 
Thx for your help
 
vento
 
 
----
 
int dumpPkgHeader(const char *pkgName){
    Header h;
    rpmdb db;
    int rc;
 
    rpmReadConfigFiles( NULL, NULL );
 
    if( rpmdbOpen( "", &db, O_RDONLY, 0644 ) != 0 ) {
        fprintf( stderr, "cannot open RPM database.\n" );
        return ( -1 );
    }
   
    rpmdbMatchIterator mi = rpmdbInitIterator(db, RPMTAG_NAME, pkgName, 0);
    while( (h=rpmdbNextIterator(mi) )!=NULL ) {
        char *name;
        char *ver;
        char *rel;
        char *sResult;
        char *errMsg=NULL;
       
        const char * qfmt = "[%{*:xml}\n]";
        struct headerTagTableEntry_s hTTE;
        struct headerSprintfExtension_s hSE;
        sResult = headerSprintf(h, qfmt, &hTTE, &hSE, &errMsg);
        printf("ALLTAGS:\n %s",sResult);
        free(sResult); sResult=NULL; errMsg=NULL;
       
        const char *qSummary="%{NAME}";
        sResult = headerSprintf(h, qSummary, &hTTE, &hSE, &errMsg);
   
        if(!errMsg){
            if(sResult){
                printf("NAME:\n %s",sResult);
                free(sResult); sResult=NULL; errMsg=NULL;
            }
        }else printf("ERROR: %s\n",errMsg);
       
        const char *qFiles="[%{DIRNAMES}%{BASENAMES}\n]";
       
        sResult = headerSprintf(h, qFiles, &hTTE, &hSE, &errMsg);
        if(!errMsg){
            printf("FILES:\n %s",sResult);
            free(sResult); sResult=NULL; errMsg=NULL;
        }else printf("ERROR: %s\n",errMsg);
               
        headerNVR(h,(const char **)&name, (const char **)&ver, (const char **) &rel );
        printf("Name %s; Version %s; Release %s", name, ver ,rel);
       
        (hdrVec->hdrfree)(h);
    }
   
    //rpmdbFreeIterator(mi);
    rpmdbClose( db );
 
    return 0;
}
 
-----
 
_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/


More information about the Rpm-maint mailing list