RPM Community Forums

Mailing List Message of <rpm-users>

Re: Errors - API for rpm

From: Manoj Palhade <mpalhade@googlemail.com>
Date: Fri 25 Sep 2009 - 06:21:07 CEST
Message-ID: <67f63fb0909242121y2b482b8wa17586cb74c72d16@mail.gmail.com>
Dear Team,

I have following quieres regrading API implementation for RPM


   1. What is the purpose of this  header file “rpm/rpm4compat.h” . Do I
   need to include it in my main program. I tried to include in API Sample
   program but it is throwing lot of errors.
   2. I am maintaining 1 excel sheet for API which conatin mapping of Old
   API(mentioned in Docs pf rpm5.org) to New API. Any help regrading this is
   appricated.
   3. I want trying to implement program for all the basic feature for RPM.
   Do you have any idea about it.
   4. I am trying to run program mentioned in Chapter 21(A Guide to the RPM
   Library API) of “Maximum RPM”. Can you please rewrite this programs. I am
   trying following programs



---------------------------------------- Program 1
-------------------------------------



*int* main(*int* argc, *char **argv[])

{

    HeaderIterator iter;

    Header h, sig;

    int_32 itertag, type, count;

    *void* **p = *NULL*;

    *char* *blather;

    *char* * name;



    *int* fd, stat;



    *if* (argc == 1)

        fd = 0;

    *else*

        fd = open(argv[1], O_RDONLY, 0644);



    *if* (fd < 0)

    {

        perror("open");

        exit(1);

    }



    stat = rpmReadPackageInfo(fd, &sig, &h);

    *if* (stat)

    {

      fprintf(stderr, "rpmReadPackageInfo error status: %d\n%s\n", stat,
strerror(errno));

      exit(stat);

    }

    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);



    printf("Dumping signatures...\n");

    headerDump(sig, stdout, 1);



    rpmFreeSignature(sig);



    printf("Iterating through the header...\n");



    iter = headerInitIterator(h);



    *while* (headerNextIterator(iter, &itertag, &type, p, &count))

    {

      *switch* (itertag)

      {

            *case* RPMTAG_SUMMARY:

            blather = *p;

            printf("The Summary: %s\n", blather);

           *break*;

            *case* RPMTAG_FILENAMES:

            printf("There are %d files in this package\n", count);

            *break*;

      }

    }

    headerFreeIterator(iter);

    headerFree(h);

    *return* EXIT_SUCCESS;

}



---------------------------------------- Program 2
-------------------------------------



*void* main(*int* argc, *char* ** argv)

{

    Header h;

    *int* offset;

    *int* dspBlockNum = 0;

    *int* blockNum = 0;

    int_32 type, count;

    *char* * name;

    rpmdb db;



    printf("The database path is: %s\n", rpmGetVar(RPMVAR_DBPATH) ?
rpmGetVar(RPM_DBPATH) : "(none)");

    //rpmReadConfigFiles(NULL, NULL, NULL, 0);

    rpmReadConfigFiles(*NULL*, *NULL*);//, NULL, 0);

    printf("The database path is: %s\n" , rpmGetVar(RPMVAR_DBPATH) ?
rpmGetVar(RPM_DBPATH) : "(none)");



    *if* (rpmdbOpen("", &db, O_RDONLY, 0644) != 0)

    {

        fprintf(stderr, "cannot open /var/lib/rpm/packages.rpm\n");

        exit(1);

    }

    offset = rpmdbFirstRecNum(db);

    *while* (offset)

    {

        h = rpmdbGetRecord(db, offset);

        *if* (!h)

        {

            fprintf(stderr, "headerRead failed\n" );

            exit(1);

        }

        headerGetEntry(h, RPMTAG_NAME, &type, (*void* **) &name, &count);

        *if* (strcmp(name, argv[1]) == 0)

            headerDump(h, stdout, 1);

        headerFree(h);



        offset = rpmdbNextRecNum(db, offset);

    }

    rpmdbClose(db);

}



---------------------------------------- Program 3
-------------------------------------

*int* main(*int* argc, *char* * argv[])

{

      *int* status = rpmReadConfigFiles( (*const* *char**) *NULL*, (*const*
*char**) *NULL*);

      *if* (status != 0)

      {

            printf("Error reading RC files.\n");

            exit(-1);

      }

      *char* * value = rpmExpand(argv[1], *NULL*, *NULL*);//rpmExpand(argv[1],
(const char*) NULL);

      printf( "Value of macro is [%s]\n", value);

      exit(0);

}

Thanks and Regards,
Manoj Palhade


On 9/18/09, Jeff Johnson <n3npq@mac.com> wrote:
>
>
>  On Sep 18, 2009, at 5:36 AM, Manoj Palhade wrote:
>
>
> Hi,
>
> I am trying to implement sample program mentioned in “Maximum RPM”. My
> understanding is that this content is not update with current version
> of RPM source code.
>
>
>
>
>
> The examples  in "Maximum RPM" won't compile with any version
> of RPM released in the last 5-6 years. The examples were written in 1997,
> lots has changed since.
>
>  1.      In sample program I am getting following error.
>
> undefined reference to `headerDump'
> undefined reference to `headerFreeIterator'
> undefined reference to `headerGetEntry'
> undefined reference to `headerInitIterator'
> undefined reference to `headerNextIterator'
> undefined reference to `rpmFreeSignature'
> undefined reference to `rpmReadPackageInfo'
>
>
>
>
>
> If you post the source I can ttry to rewrite o the current @rpm5.org API.
>
> 2.      Also As mentioned in “Maximum RPM”; I included rpmlib.h but not
> able to find header.h.
>
>
>
>
>
> Yes. Most of what used to be in header.h has moved to <rpmdb/rpmtag.h>.
>
>
> But rpmReadPackageFile() is likely what you are looking for.
>
>
> 73 de Jeff
>
Received on Fri Sep 25 06:26:34 2009
Driven by Jeff Johnson and the RPM project team.
Hosted by OpenPKG and Ralf S. Engelschall.
Powered by FreeBSD and OpenPKG.