From a83cfce188a4545756a8fa5791f3b9cbe20190ed Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Tue, 13 May 2008 11:02:45 +0300 Subject: [PATCH] New "tag data" container struct + some basic methods to deal with it - to be used for passing around header and extension data - inspired by similar changes in rpm5.org, details and implementation differ --- Makefile.am | 1 + lib/Makefile.am | 2 +- lib/header.h | 1 + lib/rpmtd.c | 47 ++++++++++++++++++++++++++++++++++++++++++++ lib/rpmtd.h | 52 +++++++++++++++++++++++++++++++++++++++++++++++++ lib/rpmtypes.h | 2 ++ preinstall.am | 4 ++++ 7 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 lib/rpmtd.c create mode 100644 lib/rpmtd.h diff --git a/Makefile.am b/Makefile.am index 368b38ae2..c89c31b3b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -65,6 +65,7 @@ pkginclude_HEADERS += lib/rpmfi.h pkginclude_HEADERS += lib/rpmgi.h pkginclude_HEADERS += lib/rpmps.h pkginclude_HEADERS += lib/rpmtag.h +pkginclude_HEADERS += lib/rpmtd.h pkginclude_HEADERS += lib/rpmte.h pkginclude_HEADERS += lib/rpmts.h pkginclude_HEADERS += lib/rpmtypes.h diff --git a/lib/Makefile.am b/lib/Makefile.am index 13abdeddf..b40a2f7d0 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -24,7 +24,7 @@ librpm_la_SOURCES = \ backend/dbconfig.c backend/db3.c \ hdrNVR.c header.c headerfmt.c header_internal.c header_internal.h \ poptDB.c rpmhash.c rpmhash.h rpmdb.c rpmdb_internal.h \ - fprint.c fprint.h tagname.c tagtbl.c \ + fprint.c fprint.h tagname.c tagtbl.c rpmtd.c \ cpio.c cpio.h depends.c formats.c fs.c fsm.c fsm.h \ manifest.c manifest.h misc.c package.c \ poptALL.c poptI.c poptQV.c psm.c psm.h query.c \ diff --git a/lib/header.h b/lib/header.h index 0f0dcfafc..68a27d532 100644 --- a/lib/header.h +++ b/lib/header.h @@ -14,6 +14,7 @@ #include #include +#include #include #ifdef __cplusplus diff --git a/lib/rpmtd.c b/lib/rpmtd.c new file mode 100644 index 000000000..50d2b0800 --- /dev/null +++ b/lib/rpmtd.c @@ -0,0 +1,47 @@ +#include "system.h" + +#include +#include + +#include "debug.h" + +rpmtd rpmtdNew(void) +{ + rpmtd td = xmalloc(sizeof(*td)); + rpmtdReset(td); + return td; +} + +rpmtd rpmtdFree(rpmtd td) +{ + /* permit free on NULL td */ + if (td != NULL) { + /* XXX should we free data too - a flag maybe? */ + free(td); + } + return NULL; +} + +void rpmtdReset(rpmtd td) +{ + assert(td != NULL); + + memset(td, 0, sizeof(*td)); + td->ix = -1; +} + +void rpmtdFreeData(rpmtd td) +{ + assert(td != NULL); + + if (td->freeData) { + free(td->data); + } + rpmtdReset(td); +} + +rpm_count_t rpmtdCount(rpmtd td) +{ + assert(td != NULL); + return td->count; +} diff --git a/lib/rpmtd.h b/lib/rpmtd.h new file mode 100644 index 000000000..fd1f07793 --- /dev/null +++ b/lib/rpmtd.h @@ -0,0 +1,52 @@ +#ifndef _RPMTD_H +#define _RPMTD_H + +#include + +/** \ingroup rpmtd + * Container for rpm tag data (from headers or extensions). + */ +struct rpmtd_s { + rpmTag tag; /* rpm tag of this data entry*/ + rpmTagType type; /* data type */ + rpm_count_t count; /* number of entries */ + rpm_data_t data; /* pointer to actual data */ + int freeData; /* was data malloced */ + int ix; /* iteration index */ +}; + +/** \ingroup rpmtd + * Create new tag data container + * ®return New, initialized tag data container. + */ +rpmtd rpmtdNew(void); + +/** \ingroup rpmtd + * Destroy tag data container. + * @param td Tag data container + * @return NULL always + */ +rpmtd rpmtdFree(rpmtd td); + +/** \ingroup rpmtd + * (Re-)initialize tag data container. Contents will be zeroed out + * and iteration index reset. + * @param td Tag data container + */ +void rpmtdReset(rpmtd td); + +/** \ingroup rpmtd + * Free contained data. This is always safe to call as the container knows + * if data was malloc'ed or not. Container is reinitialized. + * @param td Tag data container + */ +void rpmtdFreeData(rpmtd td); + +/** \ingroup rpmtd + * Retrieve number of entries in the container. + * @param td Tag data container + * @return Number of entries in contained data. + */ +rpm_count_t rpmtdCount(rpmtd td); + +#endif /* _RPMTD_H */ diff --git a/lib/rpmtypes.h b/lib/rpmtypes.h index 175e1e914..af04c74b7 100644 --- a/lib/rpmtypes.h +++ b/lib/rpmtypes.h @@ -32,6 +32,8 @@ typedef uint32_t rpm_count_t; typedef void * rpm_data_t; typedef const void * rpm_constdata_t; +typedef struct rpmtd_s * rpmtd; + typedef uint32_t rpm_color_t; typedef uint32_t rpm_flag_t; typedef int32_t rpm_tid_t; diff --git a/preinstall.am b/preinstall.am index dedabba46..d6795853d 100644 --- a/preinstall.am +++ b/preinstall.am @@ -90,6 +90,10 @@ include/rpm/rpmtag.h: lib/rpmtag.h include/rpm/$(dirstamp) $(INSTALL_DATA) $(top_srcdir)/lib/rpmtag.h include/rpm/rpmtag.h BUILT_SOURCES += include/rpm/rpmtag.h CLEANFILES += include/rpm/rpmtag.h +include/rpm/rpmtd.h: lib/rpmtd.h include/rpm/$(dirstamp) + $(INSTALL_DATA) $(top_srcdir)/lib/rpmtd.h include/rpm/rpmtd.h +BUILT_SOURCES += include/rpm/rpmtd.h +CLEANFILES += include/rpm/rpmtd.h include/rpm/rpmte.h: lib/rpmte.h include/rpm/$(dirstamp) $(INSTALL_DATA) $(top_srcdir)/lib/rpmte.h include/rpm/rpmte.h BUILT_SOURCES += include/rpm/rpmte.h