[Rpm-maint] rpm tag query and headerSprintf

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

Dear All,

I'm trying to use the librpm in a custom application, I use rpm 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



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);
                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);
            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);
    rpmdbClose( db );

    return 0;


Express yourself instantly with MSN Messenger! Download today it's FREE!

More information about the Rpm-maint mailing list