Blame lib/header.h

2ff057
#ifndef H_HEADER
2ff057
#define H_HEADER
2ff057
2ff057
/** \ingroup header
2ff057
 * \file lib/header.h
2ff057
 *
2ff057
 * An rpm header carries all information about a package. A header is
2ff057
 * a collection of data elements called tags. Each tag has a data type,
2ff057
 * and includes 1 or more values.
2ff057
 * 
2ff057
 */
2ff057
2ff057
/* RPM - Copyright (C) 1995-2001 Red Hat Software */
2ff057
2ff057
#include <rpm/rpmio.h>
2ff057
#include <rpm/rpmtypes.h>
2ff057
#include <rpm/rpmtd.h>
2ff057
#include <rpm/rpmutil.h>
2ff057
2ff057
#ifdef __cplusplus
2ff057
extern "C" {
2ff057
#endif
2ff057
2ff057
/** \ingroup header 
2ff057
 * Header magic value
2ff057
 */ 
2ff057
extern const unsigned char rpm_header_magic[8];
2ff057
2ff057
/** \ingroup header
2ff057
 * Include calculation for 8 bytes of (magic, 0)?
2ff057
 */
2ff057
enum hMagic {
2ff057
    HEADER_MAGIC_NO		= 0,
2ff057
    HEADER_MAGIC_YES		= 1
2ff057
};
2ff057
2ff057
/** \ingroup header
2ff057
 * Create new (empty) header instance.
2ff057
 * @return		header
2ff057
 */
2ff057
Header headerNew(void);
2ff057
2ff057
/** \ingroup header
2ff057
 * Dereference a header instance.
2ff057
 * @param h		header
2ff057
 * @return		NULL always
2ff057
 */
2ff057
Header headerFree( Header h);
2ff057
2ff057
/** \ingroup header
2ff057
 * Reference a header instance.
2ff057
 * @param h		header
2ff057
 * @return		new header reference
2ff057
 */
2ff057
Header headerLink(Header h);
2ff057
2ff057
/** \ingroup header
2ff057
 * Return size of on-disk header representation in bytes.
2ff057
 * @param h		header
2ff057
 * @param magicp	include size of 8 bytes for (magic, 0)?
2ff057
 * @return		size of on-disk header
2ff057
 */
2ff057
unsigned int headerSizeof(Header h, int magicp);
2ff057
2ff057
/** \ingroup header
2ff057
 * Convert header to on-disk representation.
2ff057
 * @deprecated		Use headerExport() instead
2ff057
 * @param h		header (with pointers)
2ff057
 * @return		on-disk header blob (i.e. with offsets)
2ff057
 */
2ff057
void * headerUnload(Header h);
2ff057
2ff057
/** \ingroup header
2ff057
 * Export header to on-disk representation.
2ff057
 * @param h		header (with pointers)
2ff057
 * @retval bsize	on-disk header blob size in bytes
2ff057
 * @return		on-disk header blob (i.e. with offsets)
2ff057
 */
2ff057
void * headerExport(Header h, unsigned int * bsize);
2ff057
2ff057
/** \ingroup header
2ff057
 * Convert header to on-disk representation, and then reload.
2ff057
 * This is used to insure that all header data is in one chunk.
2ff057
 * @param h		header (with pointers)
2ff057
 * @param tag		region tag
2ff057
 * @return		on-disk header (with offsets)
2ff057
 */
2ff057
Header headerReload(Header h, rpmTagVal tag);
2ff057
2ff057
/** \ingroup header
2ff057
 * Duplicate a header.
2ff057
 * @param h		header
2ff057
 * @return		new header instance
2ff057
 */
2ff057
Header headerCopy(Header h);
2ff057
2ff057
/** \ingroup header
2ff057
 * Convert header to in-memory representation.
2ff057
 * @deprecated		Use headerImport() instead
2ff057
 * @param uh		on-disk header blob (i.e. with offsets)
2ff057
 * @return		header
2ff057
 */
2ff057
Header headerLoad(void * uh);
2ff057
2ff057
/** \ingroup header
2ff057
 * Make a copy and convert header to in-memory representation.
2ff057
 * @deprecated		Use headerImport() instead
2ff057
 * @param uh		on-disk header blob (i.e. with offsets)
2ff057
 * @return		header
2ff057
 */
2ff057
Header headerCopyLoad(const void * uh);
2ff057
2ff057
enum headerImportFlags_e {
2ff057
    HEADERIMPORT_COPY		= (1 << 0), /* Make copy of blob on import? */
2ff057
    HEADERIMPORT_FAST		= (1 << 1), /* Faster but less safe? */
2ff057
};
2ff057
2ff057
typedef rpmFlags headerImportFlags;
2ff057
2ff057
/** \ingroup header
2ff057
 * Import header to in-memory representation.
2ff057
 * @param blob		on-disk header blob (i.e. with offsets)
2ff057
 * @param bsize		on-disk header blob size in bytes (0 if unknown)
2ff057
 * @param flags		flags to control operation
2ff057
 * @return		header
2ff057
 */
2ff057
Header headerImport(void *blob, unsigned int bsize, headerImportFlags flags);
2ff057
2ff057
/** \ingroup header
2ff057
 * Read (and load) header from file handle.
2ff057
 * @param fd		file handle
2ff057
 * @param magicp	read (and verify) 8 bytes of (magic, 0)?
2ff057
 * @return		header (or NULL on error)
2ff057
 */
2ff057
Header headerRead(FD_t fd, int magicp);
2ff057
2ff057
/** \ingroup header
2ff057
 * Write (with unload) header to file handle.
2ff057
 * @param fd		file handle
2ff057
 * @param h		header
2ff057
 * @param magicp	prefix write with 8 bytes of (magic, 0)?
2ff057
 * @return		0 on success, 1 on error
2ff057
 */
2ff057
int headerWrite(FD_t fd, Header h, int magicp);
2ff057
2ff057
/** \ingroup header
2ff057
 * Check if tag is in header.
2ff057
 * @param h		header
2ff057
 * @param tag		tag
2ff057
 * @return		1 on success, 0 on failure
2ff057
 */
2ff057
int headerIsEntry(Header h, rpmTagVal tag);
2ff057
2ff057
/** \ingroup header
2ff057
 * Modifier flags for headerGet() operation.
2ff057
 * For consistent behavior you'll probably want to use ALLOC to ensure
2ff057
 * the caller owns the data, but MINMEM is useful for avoiding extra
2ff057
 * copy of data when you are sure the header wont go away.
2ff057
 * Most of the time you'll probably want EXT too, but note that extensions 
2ff057
 * tags don't generally honor the other flags, MINMEM, RAW, ALLOC and ARGV 
2ff057
 * are only relevant for non-extension data.
2ff057
 */
2ff057
enum headerGetFlags_e {
2ff057
    HEADERGET_DEFAULT	= 0,	    /* legacy headerGetEntry() behavior */
2ff057
    HEADERGET_MINMEM 	= (1 << 0), /* pointers can refer to header memory */
2ff057
    HEADERGET_EXT 	= (1 << 1), /* lookup extension types too */
2ff057
    HEADERGET_RAW 	= (1 << 2), /* return raw contents (no i18n lookups) */
2ff057
    HEADERGET_ALLOC	= (1 << 3), /* always allocate memory for all data */
2ff057
    HEADERGET_ARGV	= (1 << 4), /* return string arrays NULL-terminated */
2ff057
};
2ff057
2ff057
typedef rpmFlags headerGetFlags;
2ff057
2ff057
/** \ingroup header
2ff057
 * Retrieve tag value.
2ff057
 * @param h		header
2ff057
 * @param tag		tag
2ff057
 * @retval td		tag data container
2ff057
 * @param flags		retrieval modifier flags
2ff057
 * @return		1 on success, 0 on failure
2ff057
 */
2ff057
int headerGet(Header h, rpmTagVal tag, rpmtd td, headerGetFlags flags);
2ff057
2ff057
2ff057
enum headerPutFlags_e {
2ff057
    HEADERPUT_DEFAULT	= 0,
2ff057
    HEADERPUT_APPEND 	= (1 << 0),
2ff057
};
2ff057
2ff057
typedef rpmFlags headerPutFlags;
2ff057
2ff057
/** \ingroup header
2ff057
 * Add or append tag to header.
2ff057
 *
2ff057
 * @param h		header
2ff057
 * @param td		tag data container
2ff057
 * @param flags		flags to control operation
2ff057
 * @return		1 on success, 0 on failure
2ff057
 */
2ff057
int headerPut(Header h, rpmtd td, headerPutFlags flags);
2ff057
2ff057
/** \ingroup header 
2ff057
 * @{
2ff057
 * Type-safe methods for inserting tag data to header.
2ff057
 * Tag data type is validated to match the function type, ie things like
2ff057
 * headerPutUint32(h, RPMTAG_NAME, ...) will return failure. For non-array
2ff057
 * types size must equal 1, and data is checked to be non-NULL. For array
2ff057
 * types, add-or-append mode is always used.
2ff057
 *
2ff057
 * headerPutString() can be used on both RPM_STRING_TYPE and 
2ff057
 * RPM_STRING_ARRAY_TYPE (to add a single string into the array) tags,
2ff057
 * for others the type must match exactly.
2ff057
 *
2ff057
 * These are intended to "do the right thing" in the common case, if you 
2ff057
 * need more fine grained control use headerPut() & friends instead.
2ff057
 * @todo		Make doxygen group these meaningfully.
2ff057
 *
2ff057
 * @param h		header
2ff057
 * @param tag		tag to insert
2ff057
 * @param val		pointer to value(s)
2ff057
 * @param size		number of items in array (1 or larger)
2ff057
 * @return		1 on success, 0 on failure
2ff057
 * 
2ff057
 */
2ff057
int headerPutBin(Header h, rpmTagVal tag, const uint8_t *val, rpm_count_t size);
2ff057
int headerPutString(Header h, rpmTagVal tag, const char *val);
2ff057
int headerPutStringArray(Header h, rpmTagVal tag, const char **val, rpm_count_t size);
2ff057
int headerPutChar(Header h, rpmTagVal tag, const char *val, rpm_count_t size);
2ff057
int headerPutUint8(Header h, rpmTagVal tag, const uint8_t *val, rpm_count_t size);
2ff057
int headerPutUint16(Header h, rpmTagVal tag, const uint16_t *val, rpm_count_t size);
2ff057
int headerPutUint32(Header h, rpmTagVal tag, const uint32_t *val, rpm_count_t size);
2ff057
int headerPutUint64(Header h, rpmTagVal tag, const uint64_t *val, rpm_count_t size);
2ff057
/** @} */
2ff057
2ff057
/** \ingroup header
2ff057
 * Add locale specific tag to header.
2ff057
 * A NULL lang is interpreted as the C locale. Here are the rules:
2ff057
 * \verbatim
2ff057
 *	- If the tag isn't in the header, it's added with the passed string
2ff057
 *	   as new value.
2ff057
 *	- If the tag occurs multiple times in entry, which tag is affected
2ff057
 *	   by the operation is undefined.
2ff057
 *	- If the tag is in the header w/ this language, the entry is
2ff057
 *	   *replaced* (like headerMod()).
2ff057
 * \endverbatim
2ff057
 * This function is intended to just "do the right thing". If you need
2ff057
 * more fine grained control use headerPut() and headerMod().
2ff057
 *
2ff057
 * @param h		header
2ff057
 * @param tag		tag
2ff057
 * @param string	tag value
2ff057
 * @param lang		locale
2ff057
 * @return		1 on success, 0 on failure
2ff057
 */
2ff057
int headerAddI18NString(Header h, rpmTagVal tag, const char * string,
2ff057
		const char * lang);
2ff057
2ff057
/** \ingroup header
2ff057
 * Modify tag in header.
2ff057
 * If there are multiple entries with this tag, the first one gets replaced.
2ff057
 * @param h		header
2ff057
 * @param td		tag data container
2ff057
 * @return		1 on success, 0 on failure
2ff057
 */
2ff057
int headerMod(Header h, rpmtd td);
2ff057
2ff057
/** \ingroup header
2ff057
 * Delete tag in header.
2ff057
 * Removes all entries of type tag from the header, returns 1 if none were
2ff057
 * found.
2ff057
 *
2ff057
 * @param h		header
2ff057
 * @param tag		tag
2ff057
 * @return		0 on success, 1 on failure (INCONSISTENT)
2ff057
 */
2ff057
int headerDel(Header h, rpmTagVal tag);
2ff057
2ff057
/** \ingroup header
2ff057
 * Return formatted output string from header tags.
2ff057
 * The returned string must be free()d.
2ff057
 *
2ff057
 * @param h		header
2ff057
 * @param fmt		format to use
2ff057
 * @retval errmsg	error message (if any)
2ff057
 * @return		formatted output string (malloc'ed)
2ff057
 */
2ff057
char * headerFormat(Header h, const char * fmt, errmsg_t * errmsg);
2ff057
2ff057
/** \ingroup header
2ff057
 * Duplicate tag values from one header into another.
2ff057
 * @param headerFrom	source header
2ff057
 * @param headerTo	destination header
2ff057
 * @param tagstocopy	array of tags that are copied
2ff057
 */
2ff057
void headerCopyTags(Header headerFrom, Header headerTo, 
2ff057
		    const rpmTagVal * tagstocopy);
2ff057
2ff057
/** \ingroup header
2ff057
 * Destroy header tag iterator.
2ff057
 * @param hi		header tag iterator
2ff057
 * @return		NULL always
2ff057
 */
2ff057
HeaderIterator headerFreeIterator(HeaderIterator hi);
2ff057
2ff057
/** \ingroup header
2ff057
 * Create header tag iterator.
2ff057
 * @param h		header
2ff057
 * @return		header tag iterator
2ff057
 */
2ff057
HeaderIterator headerInitIterator(Header h);
2ff057
2ff057
/** \ingroup header
2ff057
 * Return next tag contents from header.
2ff057
 * @param hi		header tag iterator
2ff057
 * @retval td		tag data container
2ff057
 * @return		1 on success, 0 on failure
2ff057
 */
2ff057
int headerNext(HeaderIterator hi, rpmtd td);
2ff057
2ff057
/** \ingroup header
2ff057
 * Return next tag number from header.
2ff057
 * @param hi		header tag iterator
2ff057
 * @return		next tag, RPMTAG_NOT_FOUND to stop iteration
2ff057
 */
2ff057
rpmTagVal headerNextTag(HeaderIterator hi);
2ff057
2ff057
/** \ingroup header
2ff057
 * Return any non-array tag from header, converted to string
2ff057
 * @param h		header
2ff057
 * @param tag		tag to retrieve
2ff057
 * @return 		string pointer (malloced) or NULL on failure
2ff057
 */
2ff057
char * headerGetAsString(Header h, rpmTagVal tag);
2ff057
2ff057
/** \ingroup header
2ff057
 * Return a simple string tag from header
2ff057
 * @param h		header
2ff057
 * @param tag		tag to retrieve
2ff057
 * @return		string pointer (to header memory) or NULL on failure
2ff057
 */
2ff057
const char * headerGetString(Header h, rpmTagVal tag);
2ff057
2ff057
/* \ingroup header
2ff057
 * Return a simple number tag (or extension) from header
2ff057
 * @param h		header
2ff057
 * @param tag		tag to retrieve
2ff057
 * @return		numeric tag value or 0 on failure
2ff057
 */
2ff057
uint64_t headerGetNumber(Header h, rpmTagVal tag);
2ff057
2ff057
/** \ingroup header
2ff057
 * Check if header is a source or binary package header
2ff057
 * @param h		header
2ff057
 * @return		0 == binary, 1 == source
2ff057
 */
2ff057
int headerIsSource(Header h);
2ff057
2ff057
/** \ingroup header
2ff057
 * Return header instance, ie is the header from rpmdb.
2ff057
 * @param h		header
2ff057
 * @return		rpmdb record number or 0
2ff057
 */
2ff057
unsigned int headerGetInstance(Header h);
2ff057
2ff057
typedef enum headerConvOps_e {
2ff057
    HEADERCONV_EXPANDFILELIST	= 0,
2ff057
    HEADERCONV_COMPRESSFILELIST = 1,
2ff057
    HEADERCONV_RETROFIT_V3	= 2,
2ff057
} headerConvOps;
2ff057
2ff057
/** \ingroup header
2ff057
 * Convert header to/from (legacy) data presentation
2ff057
 * @param h		header
2ff057
 * @param op		one of headerConvOps operations
2ff057
 * @return		1 on success, 0 on failure
2ff057
 */
2ff057
int headerConvert(Header h, int op);
2ff057
2ff057
#ifdef __cplusplus
2ff057
}
2ff057
#endif
2ff057
2ff057
#endif	/* H_HEADER */