LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-17-2004, 09:39 PM   #1
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Costa Rica
Distribution: Kubuntu, Debian, Knoppix
Posts: 2,092
Blog Entries: 1

Rep: Reputation: 90
Question 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?
 
Old 01-18-2004, 08:05 AM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 110Reputation: 110
http://library.n0i.net/programming/rpm/rp-mapi/
 
Old 01-18-2004, 04:49 PM   #3
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Costa Rica
Distribution: Kubuntu, Debian, Knoppix
Posts: 2,092

Original Poster
Blog Entries: 1

Rep: Reputation: 90
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!
 
Old 01-18-2004, 06:43 PM   #4
Strike
Member
 
Registered: Jun 2001
Location: Houston, TX, USA
Distribution: Debian
Posts: 569

Rep: Reputation: 31
http://www.rpm.org/max-rpm/ch-rpm-rpmlib.html This is the official documentation.
 
Old 01-18-2004, 11:15 PM   #5
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Costa Rica
Distribution: Kubuntu, Debian, Knoppix
Posts: 2,092

Original Poster
Blog Entries: 1

Rep: Reputation: 90
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!
 
Old 01-19-2004, 12:52 PM   #6
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Costa Rica
Distribution: Kubuntu, Debian, Knoppix
Posts: 2,092

Original Poster
Blog Entries: 1

Rep: Reputation: 90
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?
 
Old 01-19-2004, 02:26 PM   #7
yarrow
LQ Newbie
 
Registered: Jan 2004
Posts: 5

Rep: Reputation: 0
I recall this happening on gentoo. Maybe the libarys are corrupted?
 
Old 01-19-2004, 02:40 PM   #8
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Costa Rica
Distribution: Kubuntu, Debian, Knoppix
Posts: 2,092

Original Poster
Blog Entries: 1

Rep: Reputation: 90
ManĚ... I just registered to the rpm-devel mail list... as soon as I get info, I'll be posting it here, OK?
 
Old 01-19-2004, 04:50 PM   #9
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Costa Rica
Distribution: Kubuntu, Debian, Knoppix
Posts: 2,092

Original Poster
Blog Entries: 1

Rep: Reputation: 90
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?

Last edited by eantoranz; 01-19-2004 at 04:52 PM.
 
Old 01-21-2004, 12:11 AM   #10
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Costa Rica
Distribution: Kubuntu, Debian, Knoppix
Posts: 2,092

Original Poster
Blog Entries: 1

Rep: Reputation: 90
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
 
Old 01-21-2004, 01:18 AM   #11
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Costa Rica
Distribution: Kubuntu, Debian, Knoppix
Posts: 2,092

Original Poster
Blog Entries: 1

Rep: Reputation: 90
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!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Easy application management digitalangel78 Linux - Distributions 4 01-29-2005 01:26 AM
Image Management Application wasabi Fedora 8 08-03-2004 01:02 AM
Bandwidth Management Application In Linux? shrike_912 Programming 5 06-05-2004 09:20 AM
Application / memory management cyberfunk Linux - General 2 03-17-2004 05:14 PM
Writing a simple KDE application yapp Programming 1 12-10-2003 04:39 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:01 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration