# rpmdb/header.c File Reference

`#include "system.h"`
`#include <rpmio.h>`
`#include <header_internal.h>`
`#include "debug.h"`

Include dependency graph for header.c:

Go to the source code of this file.

## Data Structures

struct | headerIterator_s
| Header tag iterator data structure. More...

## Defines

#define | _RPMTAG_INTERNAL

## Functions

void * | headerGetStats (Header h, int opx)
| Return header stats accumulator structure.
Header | headerLink (Header h)
| Reference a header instance.
Header | headerUnlink (Header h)
| Dereference a header instance.
Header | headerFree (Header h)
| Dereference a header instance.
Header | headerNew (void)
| Create new (empty) header instance.
static int | indexCmp (const void *avp, const void *bvp)
static void | headerSort (Header h)
| Sort tags in header.
static int | offsetCmp (const void *avp, const void *bvp)
static void | headerUnsort (Header h)
| Restore tags in header to original ordering.
size_t | headerSizeof (Header h)
| Return size of on-disk header representation in bytes.
static size_t | dataLength (rpmTagType type, rpmTagData *p, rpmTagCount count, int onDisk, rpmTagData *pend)
| Return length of entry data.
static uint32_t | regionSwab (indexEntry entry, uint32_t il, uint32_t dl, entryInfo pe, unsigned char *dataStart, const unsigned char *dataEnd, int32_t regionid)
| Swap uint32_t and uint16_t arrays within header region.
void * | headerUnload (Header h, size_t *lenp)
static indexEntry | findEntry (Header h, rpmTag tag, rpmTagType type)
| Find matching (tag,type) entry in header.
static int | headerRemoveEntry (Header h, rpmTag tag)
| Delete tag in header.
Header | headerLoad (void *uh)
| Convert header to in-memory representation.
int | headerGetMagic (Header h, unsigned char **magicp, size_t *nmagicp)
| Return header magic.
int | headerSetMagic (Header h, unsigned char *magic, size_t nmagic)
| Store header magic.
const char * | headerGetOrigin (Header h)
| Return header origin (e.g path or URL).
int | headerSetOrigin (Header h, const char *origin)
| Store header origin (e.g path or URL).
uint32_t | headerGetInstance (Header h)
| Return header instance (if from rpmdb).
uint32_t | headerSetInstance (Header h, uint32_t instance)
| Store header instance (e.g path or URL).
Header | headerReload (Header h, int tag)
| Convert header to on-disk representation, and then reload.
Header | headerCopyLoad (const void *uh)
| Make a copy and convert header to in-memory representation.
int | headerIsEntry (Header h, rpmTag tag)
| Check if tag is in header.
static int | copyEntry (const indexEntry entry, HE_t he, int minMem)
| Retrieve data from header entry.
static int | headerMatchLocale (const char *td, const char *l, const char *le)
| Does locale match entry in header i18n table?
static char * | headerFindI18NString (Header h, indexEntry entry)
| Return i18n string from header that matches locale.
static int | intGetEntry (Header h, HE_t he, int flags)
| Retrieve tag data from header.
static void | copyData (rpmTagType type, rpmTagData *dest, rpmTagData *src, rpmTagCount cnt, size_t len)
static void * | grabData (rpmTagType type, rpmTagData *p, rpmTagCount c, size_t *lenp)
| Return (malloc'ed) copy of entry data.
static int | headerAddEntry (Header h, HE_t he)
| Add tag to header.
static int | headerAppendEntry (Header h, HE_t he)
| Append element to tag array in header.
static int | headerAddOrAppendEntry (Header h, HE_t he)
| Add or append element to tag array in header.
int | headerAddI18NString (Header h, rpmTag tag, const char *string, const char *lang)
| Add locale specific tag to header.
static int | headerModifyEntry (Header h, HE_t he)
| Modify tag in header.
static int | rpmheRealloc (HE_t he)
| Always realloc HE_t memory.
HeaderIterator | headerFini (HeaderIterator hi)
| Destroy header tag container iterator.
HeaderIterator | headerInit (Header h)
| Create header tag iterator.
int | headerNext (HeaderIterator hi, HE_t he, unsigned int flags)
| Return next tag from header.
Header | headerCopy (Header h)
| Duplicate a header.
void | headerCopyTags (Header headerFrom, Header headerTo, rpmTag *tagstocopy)
| Duplicate tag values from one header into another.
int | headerGet (Header h, HE_t he, unsigned int flags)
| Retrieve extension or tag value from a header.
int | headerPut (Header h, HE_t he, unsigned int flags)
| Add or append tag container to header.
int | headerDel (Header h, HE_t he, unsigned int flags)
| Remove tag container from header.
int | headerMod (Header h, HE_t he, unsigned int flags)
| Modify tag container in header.

## Variables

int | _hdr_debug = 0
static unsigned char | header_magic [8]
static int | typeSizes [16]
| Size of header data types.
static size_t | headerMaxbytes = (1024*1024*1024)
| Maximum no.
int | _hdr_stats = 0
| Global header stats enabler.
static struct rpmop_s | hdr_loadops
rpmop | _hdr_loadops = &hdr_loadops
static struct rpmop_s | hdr_getops
rpmop | _hdr_getops = &hdr_getops

## Detailed Description

Definition in file header.c.

## Define Documentation

#define _RPMTAG_INTERNAL

Definition at line 14 of file header.c.

## Function Documentation

static void copyData | ( | rpmTagType | type,
|  | rpmTagData * | dest,
|  | rpmTagData * | src,
|  | rpmTagCount | cnt,
|  | size_t | len |
| ) |  |  | `[static]`

Definition at line 1480 of file header.c.

References RPM_I18NSTRING_TYPE, and RPM_STRING_ARRAY_TYPE.

Referenced by grabData(), and headerAppendEntry().

static size_t dataLength | ( | rpmTagType | type,
|  | rpmTagData * | p,
|  | rpmTagCount | count,
|  | int | onDisk,
|  | rpmTagData * | pend |
| ) |  |  | `[static]`

Return length of entry data.

Parameters:

  | type | entry data type
  | *p | tag container data
  | count | entry item count
  | onDisk | data is concatenated strings (with NUL's))?
  | *pend | pointer to end of tag container data (or NULL)

Returns:
  no. bytes in data, 0 on failure

Definition at line 307 of file header.c.

References RPM_I18NSTRING_TYPE, RPM_STRING_ARRAY_TYPE, RPM_STRING_TYPE, typeSizes, and rpmDataType_u::ui8p.

Referenced by grabData(), headerAppendEntry(), and regionSwab().

static indexEntry findEntry | ( | Header | h,
|  | rpmTag | tag,
|  | rpmTagType | type |
| ) |  |  | `[static]`

Find matching (tag,type) entry in header.

Parameters:

  | h | header
  | tag | entry tag
  | type | entry type

Returns:
  header entry

Definition at line 818 of file header.c.

References headerToken_s::flags, HEADERFLAG_SORTED, headerSort(), headerToken_s::index, indexCmp(), headerToken_s::indexUsed, indexEntry_s::info, entryInfo_s::tag, and entryInfo_s::type.

Referenced by addMacro(), delMacro(), expandMacro(), headerAddI18NString(), headerAddOrAppendEntry(), headerAppendEntry(), headerFindI18NString(), headerIsEntry(), headerModifyEntry(), headerRemoveEntry(), htGetEntry(), htHasEntry(), and intGetEntry().

static void* grabData | ( | rpmTagType | type,
|  | rpmTagData * | p,
|  | rpmTagCount | c,
|  | size_t * | lenp |
| ) |  |  | `[static]`

Return (malloc'ed) copy of entry data.

Parameters:

  | type | entry data type
  | *p | tag container data
  | c | entry item count

Return values:

  | *lenp | no. bytes in returned data

Returns:
  (malloc'ed) copy of entry data, NULL on error

Definition at line 1515 of file header.c.

References copyData(), dataLength(), rpmDataType_u::ptr, and xmalloc().

Referenced by headerAddEntry(), and headerModifyEntry().

static char* headerFindI18NString | ( | Header | h,
|  | indexEntry | entry |
| ) |  |  | `[static]`

Return i18n string from header that matches locale.

Parameters:

  | h | header
  | entry | i18n string data

Returns:
  matching i18n string (or 1st string if no match)

Definition at line 1388 of file header.c.

References indexEntry_s::data, findEntry(), getenv(), HEADER_I18NTABLE, headerMatchLocale(), lang, and RPM_STRING_ARRAY_TYPE.

Referenced by intGetEntry().

static int headerMatchLocale | ( | const char * | td,
|  | const char * | l,
|  | const char * | le |
| ) |  |  | `[static]`

Does locale match entry in header i18n table?

     * The range [l,le) contains the next locale to match:
     *    ll[_CC][.EEEEE][@dddd]
     * where
     *    ll	ISO language code (in lowercase).
     *    CC	(optional) ISO coutnry code (in uppercase).
     *    EEEEE	(optional) encoding (not really standardized).
     *    dddd	(optional) dialect.
     *

Parameters:

  | td | header i18n table data, NUL terminated
  | l | start of locale to match
  | le | end of locale to match

Returns:
  1 on match, 0 on no match

Definition at line 1315 of file header.c.

References alloca().

Referenced by headerFindI18NString().

static int indexCmp | ( | const void * | avp,
|  | const void * | bvp |
| ) |  |  | `[static]`

Definition at line 190 of file header.c.

References indexEntry_s::info, and entryInfo_s::tag.

Referenced by findEntry(), and headerSort().

static int intGetEntry | ( | Header | h,
|  | HE_t | he,
|  | int | flags |
| ) |  |  | `[static]`

Retrieve tag data from header.

Parameters:

  | h | header
  | he | tag container
  | flags | headerGet flags

Returns:
  1 on success, 0 on not found

Definition at line 1439 of file header.c.

References _HE_s::c, copyEntry(), findEntry(), headerFindI18NString(), HEADERGET_NOI18NSTRING, indexEntry_s::info, _HE_s::p, rpmDataType_u::ptr, RPM_I18NSTRING_TYPE, RPM_STRING_TYPE, rpmDataType_u::str, _HE_s::t, _HE_s::tag, and entryInfo_s::type.

Referenced by headerGet().

static int offsetCmp | ( | const void * | avp,
|  | const void * | bvp |
| ) |  |  | `[static]`

Definition at line 215 of file header.c.

References indexEntry_s::data, indexEntry_s::info, entryInfo_s::offset, and entryInfo_s::tag.

Referenced by headerUnsort().

static int rpmheRealloc | ( | HE_t | he | ) | `[static]`

Always realloc HE_t memory.

Parameters:

  | he | tag container

Returns:
  1 on success, 0 on failure

Definition at line 1854 of file header.c.

References _HE_s::c, _HE_s::freeData, _HE_s::p, rpmDataType_u::ptr, RPM_BIN_TYPE, RPM_I18NSTRING_TYPE, RPM_STRING_ARRAY_TYPE, RPM_STRING_TYPE, RPM_UINT16_TYPE, RPM_UINT32_TYPE, RPM_UINT64_TYPE, RPM_UINT8_TYPE, rpmDataType_u::str, _HE_s::t, rpmDataType_u::ui16p, rpmDataType_u::ui32p, rpmDataType_u::ui64p, rpmDataType_u::ui8p, and xmalloc().

Referenced by headerGet(), and headerNext().

## Variable Documentation

int _hdr_debug = 0

Definition at line 20 of file header.c.

Referenced by escapedChar(), headerLink(), headerSprintf(), headerUnlink(), parseExpression(), and parseFormat().

rpmop _hdr_getops = &hdr_getops

Definition at line 82 of file header.c.

rpmop _hdr_loadops = &hdr_loadops

Definition at line 78 of file header.c.

int _hdr_stats = 0

Global header stats enabler.

Definition at line 72 of file header.c.

Referenced by headerFree(), headerGetStats(), and rpmcliInit().

struct rpmop_s hdr_getops `[static]`

Definition at line 80 of file header.c.

struct rpmop_s hdr_loadops `[static]`

Definition at line 76 of file header.c.