LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   writing a RPM management application (https://www.linuxquestions.org/questions/programming-9/writing-a-rpm-management-application-135881/)

eantoranz 01-17-2004 08:39 PM

writing a RPM management application
 
Hi, guys!

Can anybody give me a little help here?

I want to write a small rpm management application. I installed rpm-devel rpm in my mandrake system. I have the .h files right there.... however, where do I find documentation about the RPM API?

I've being looking around, but found nothing useful. :(

Any ideas?

Hko 01-18-2004 07:05 AM

http://library.n0i.net/programming/rpm/rp-mapi/

eantoranz 01-18-2004 03:49 PM

Well, I took a look at that... it's anything BUT comprehensive. :(

Is there a guide to start one application? I liked this much better: http://linux.tnc.edu.tw/techdoc/maxi...k/node503.html

However, I'm writing the example # 1 and I'm getting compiler errors (undefined stuff and so on).

I'd like to download one single compressed file to be able to study everything without being on-line... is there anything like that? :(

And last, but not least.. thanks Hko!

Strike 01-18-2004 05:43 PM

http://www.rpm.org/max-rpm/ch-rpm-rpmlib.html This is the official documentation.

eantoranz 01-18-2004 10:15 PM

I'll take a look at that... seems like the information provided by the link I suplied..... it's just that I only download a single page with the whole stuff in this new link.... ;) Thanx, man!

eantoranz 01-19-2004 11:52 AM

I'm trying example # 2.

I commented a section of the code because the variables weren't defined:

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

rpmReadConfigFiles(NULL, NULL, NULL, 0);

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

After that, it went a fine... however (there's always a however)
When I try to buid I get error messages (linker related).. here I go:

[antoranz@galileo src]$ gcc rpm2.c -o rpm2 -lrpm
rpm2.c: In function `main':
rpm2.c:69: warning: assignment makes pointer from integer without a cast
/home/antoranz/tmp/ccNOHRFg.o(.text+0x61): In function `main':
: undefined reference to `rpmdbFirstRecNum'
/home/antoranz/tmp/ccNOHRFg.o(.text+0x80): In function `main':
: undefined reference to `rpmdbGetRecord'
/home/antoranz/tmp/ccNOHRFg.o(.text+0x117): In function `main':
: undefined reference to `rpmdbNextRecNum'
collect2: ld returned 1 exit status

Any ideas now? What library should I recall?

yarrow 01-19-2004 01:26 PM

I recall this happening on gentoo. Maybe the libarys are corrupted?:confused:

eantoranz 01-19-2004 01:40 PM

Man·... I just registered to the rpm-devel mail list... as soon as I get info, I'll be posting it here, OK?

eantoranz 01-19-2004 03:50 PM

Update:

I opened a different thread (http://www.linuxquestions.org/questi...hreadid=136460) because the problem is getting more specific. I found out (by trial aand error) that the documentation where the examples are is (seemingly) not up-to-date. For example:

int rpmReadConfigFiles(char * file, char * arch, char * os, int building) seems to be deprecated.... so I had to check in rpm/rpmlib.h and found this:

int rpmReadConfigFiles(/*@null@*/ const char * file, /*@null@*/ const char * target)

Thererore, the code is now: rpmReadConfigFiles(NULL, NULL);

It works just fine like that.

i was able to open the database.

However, when i try to use the database traversion functions, I get this message:
gcc rpm4.c -o rpm4 -lrpm
rpm4.c: In function `main':
rpm4.c:32: warning: assignment makes pointer from integer without a cast
/home/antoranz/tmp/cctmhgcw.o(.text+0x91): In function `main':
: undefined reference to `rpmdbFirstRecNum'
/home/antoranz/tmp/cctmhgcw.o(.text+0xad): In function `main':
: undefined reference to `rpmdbGetRecord'
/home/antoranz/tmp/cctmhgcw.o(.text+0xc1): In function `main':
: undefined reference to `rpmdbGetNextRecNum'
collect2: ld returned 1 exit status

which is very similar to the messages I was getting earlier.... but at least i think I'm closer to the "Problem"... maybe just a couple of inches. :)

What do you think?

eantoranz 01-20-2004 11:11 PM

Guys.. I just founf out that the RPM API apapently doesn't support rpmdbFirstRecNum, rpmdbGetRecord, rpmdbGetNextErcNum since RPM 4.0 .... but one has to implement Iterators instead. Take a look here:
http://www.rpm.org/rpmapi-4.1/group__rpmdb.html#a18

eantoranz 01-21-2004 12:18 AM

After having spent some hours moving back and forth... here is the code:

#include <fcntl.h>

#include <rpm/rpmlib.h>

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

rpmdb * pdb;

rpmReadConfigFiles(NULL, NULL);
printf("Config files read\n");

int dbStatus = rpmdbOpen("", &pdb, O_RDONLY, 0644);

if (dbStatus) {
// error opening
printf("Error on opening RPM Database: (%d) %s\n", rpmErrorCode(), rpmErrorString());
exit;
} else {
printf("RPM Database opened!\n");
}

rpmdbMatchIterator mi = rpmdbInitIterator(pdb, RPMDBI_PACKAGES, NULL, 0);
printf("Iterator initialized!\n");
Header header;
HeaderIterator hi;

int_32 type, count;
char * name;
while (header = rpmdbNextIterator(mi)) {
headerGetEntry(header, RPMTAG_NAME, &type, (void **) &name, &count);
printf("%s\n", strdup(name));

}
printf("Finished Iteration!\n");

rpmdbFreeIterator(mi);
printf("Iterator Finished!\n");
rpmdbClose(pdb);
printf("RPM Database closed!\n");
}

Now I have to figure out what I did. ;)

Have fun!


All times are GMT -5. The time now is 06:12 AM.