# lib/header.c File Reference

More...

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

Go to the source code of this file.

## Data Structures

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

## Defines

#define | __HEADER_PROTOTYPES__
#define | PARSER_BEGIN 0
#define | PARSER_IN_ARRAY 1
#define | PARSER_IN_EXPR 2
#define | hdrchkTags(_ntags) ((_ntags) & 0xffff0000)
| Sanity check on no.
#define | hdrchkData(_nbytes) ((_nbytes) & 0xff000000)
| Sanity check on data size and/or offset.

## Functions

const char *const | tagName (int tag)
void * | _free (const void *p)
| Wrapper to free(3), hides const compilation noise, permit NULL, return NULL.
int | indexCmp (const void *avp, const void *bvp)
int | offsetCmp (const void *avp, const void *bvp)
int | dataLength (int_32 type, hPTR_t p, int_32 count, int onDisk)
| Return length of entry data.
int | regionSwab (indexEntry entry, int il, int dl, entryInfo pe, char *dataStart, int regionid)
void * | doHeaderUnload (Header h, int *lengthPtr)
indexEntry | findEntry (Header h, int_32 tag, int_32 type)
| Find matching (tag,type) entry in header.
int | copyEntry (const indexEntry entry, hTYP_t type, hPTR_t *p, hCNT_t c, int minMem)
int | headerMatchLocale (const char *td, const char *l, const char *le)
| Does locale match entry in header i18n table?
char * | headerFindI18NString (Header h, indexEntry entry)
| Return i18n string from header that matches locale.
int | intGetEntry (Header h, int_32 tag, hTAG_t type, hPTR_t *p, hCNT_t c, int minMem)
| Retrieve tag data from header.
int | headerGetRawEntry (Header h, int_32 tag, int_32 *type, hPTR_t *p, int_32 *c)
void | copyData (int_32 type, void *dstPtr, const void *srcPtr, int_32 c, int dataLength)
void * | grabData (int_32 type, hPTR_t p, int_32 c, int *lengthPtr)
| Return (malloc'ed) copy of entry data.
char | escapedChar (const char ch)
sprintfToken | freeFormat (sprintfToken format, int num)
| Destroy headerSprintf format array.
void | findTag (char *name, const headerTagTableEntry tags, const headerSprintfExtension extensions, headerTagTableEntry *tagMatch, headerSprintfExtension *extMatch)
int | parseExpression (sprintfToken token, char *str, const headerTagTableEntry tags, const headerSprintfExtension extensions, char **endPtr, errmsg_t *errmsg)
int | parseFormat (char *str, const headerTagTableEntry tags, const headerSprintfExtension extensions, sprintfToken *formatPtr, int *numTokensPtr, char **endPtr, int state, errmsg_t *errmsg)
int | getExtension (Header h, headerTagTagFunction fn, hTYP_t typeptr, hPTR_t *data, hCNT_t countptr, extensionCache ext)
char * | formatValue (sprintfTag tag, Header h, const headerSprintfExtension extensions, extensionCache extCache, int element)
const char * | singleSprintf (Header h, sprintfToken token, const headerSprintfExtension extensions, extensionCache extCache, int element)
extensionCache | allocateExtensionCache (const headerSprintfExtension extensions)
extensionCache | freeExtensionCache (const headerSprintfExtension extensions, extensionCache cache)
char * | octalFormat (int_32 type, hPTR_t data, char *formatPrefix, int padding, int element)
char * | hexFormat (int_32 type, hPTR_t data, char *formatPrefix, int padding, int element)
char * | realDateFormat (int_32 type, hPTR_t data, char *formatPrefix, int padding, int element, const char *strftimeFormat)
char * | dateFormat (int_32 type, hPTR_t data, char *formatPrefix, int padding, int element)
char * | dayFormat (int_32 type, hPTR_t data, char *formatPrefix, int padding, int element)
char * | shescapeFormat (int_32 type, hPTR_t data, char *formatPrefix, int padding, int element)

## Variables

unsigned char | header_magic [8]
size_t | headerMaxbytes = (32*1024*1024)
int | typeSizes []
HV_t | hdrVec = &hdrVec1
const struct headerSprintfExtension_s | headerDefaultFormats []
HV_s | hdrVec1

## Detailed Description

Definition in file header.c.

## Define Documentation

#define __HEADER_PROTOTYPES__

| Definition at line 13 of file header.c.

#define hdrchkData | ( | _nbytes |  | ) | ((_nbytes) & 0xff000000)

| Sanity check on data size and/or offset. This check imposes a limit of 16Mb, more than enough. Definition at line 58 of file header.c. Referenced by doHeaderUnload().

#define hdrchkTags | ( | _ntags |  | ) | ((_ntags) & 0xffff0000)

| Sanity check on no. of tags. This check imposes a limit of 65K tags, more than enough. Definition at line 52 of file header.c. Referenced by doHeaderUnload().

#define PARSER_BEGIN 0

| Definition at line 31 of file header.c.

#define PARSER_IN_ARRAY 1

| Definition at line 32 of file header.c. Referenced by parseFormat().

#define PARSER_IN_EXPR 2

| Definition at line 33 of file header.c. Referenced by parseExpression(), and parseFormat().

## Function Documentation

void* _free | ( | const void * | p | ) | `[inline, static]`

Wrapper to free(3), hides const compilation noise, permit NULL, return NULL.

Parameters:

  p | memory to free

Returns:
  NULL always

Definition at line 86 of file header.c.

extensionCache allocateExtensionCache | ( | const headerSprintfExtension | extensions | ) | `[static]`

| Definition at line 2809 of file header.c. References HEADER_EXT_LAST, HEADER_EXT_MORE, headerSprintfExtension, headerSprintfExtension_s::type, headerSprintfExtension_s::u, and xcalloc().

void copyData | ( | int_32 | type,
|  | void * | dstPtr,
|  | const void * | srcPtr,
|  | int_32 | c,
|  | int | dataLength
| ) | `[static]`

| Definition at line 1632 of file header.c. References dataLength(), int_32, RPM_I18NSTRING_TYPE, and RPM_STRING_ARRAY_TYPE. Referenced by grabData().

int dataLength | ( | int_32 | type,
|  | hPTR_t | p,
|  | int_32 | count,
|  | int | onDisk
| ) | `[static]`

Return length of entry data.

Todo:
  Remove sanity check exit's.

Parameters:

  type | entry data type
  p | entry data
  count | entry item count
  onDisk | data is concatenated strings (with NUL's))?

Returns:
  no. bytes in data

Definition at line 319 of file header.c.

References _, EXIT_FAILURE, hPTR_t, int_32, RPM_I18NSTRING_TYPE, RPM_STRING_ARRAY_TYPE, RPM_STRING_TYPE, and typeSizes.

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

char* dateFormat | ( | int_32 | type,
|  | hPTR_t | data,
|  | char * | formatPrefix,
|  | int | padding,
|  | int | element
| ) | `[static]`

| Definition at line 3005 of file header.c. References hPTR_t, int_32, and realDateFormat().

char* dayFormat | ( | int_32 | type,
|  | hPTR_t | data,
|  | char * | formatPrefix,
|  | int | padding,
|  | int | element
| ) | `[static]`

| Definition at line 3014 of file header.c. References hPTR_t, int_32, and realDateFormat().

char escapedChar | ( | const char | ch | ) | `[static]`

| Definition at line 2003 of file header.c. Referenced by parseFormat().

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

Find matching (tag,type) entry in header.

Parameters:

  h | header
  tag | entry tag
  type | entry type

Returns:
  header entry

Definition at line 771 of file header.c.

References headerToken::flags, Header, HEADERFLAG_SORTED, headerSort(), headerToken::index, indexCmp(), headerToken::indexUsed, indexEntry::info, int_32, RPM_NULL_TYPE, entryInfo::tag, and entryInfo::type.

void findTag | ( | char * | name,
|  | const headerTagTableEntry | tags,
|  | const headerSprintfExtension | extensions,
|  | headerTagTableEntry * | tagMatch,
|  | headerSprintfExtension * | extMatch
| ) | `[static]`

| Definition at line 2058 of file header.c. References alloca(), HEADER_EXT_LAST, HEADER_EXT_MORE, HEADER_EXT_TAG, headerSprintfExtension, headerTagTableEntry, headerTagTableEntry_s::name, headerSprintfExtension_s::name, stpcpy(), headerSprintfExtension_s::type, headerSprintfExtension_s::u, and xstrcasecmp(). Referenced by parseExpression(), and parseFormat().

char* formatValue | ( | sprintfTag | tag,
|  | Header | h,
|  | const headerSprintfExtension | extensions,
|  | extensionCache | extCache,
|  | int | element
| ) | `[static]`

Definition at line 2515 of file header.c.

References _, _free(), sprintfTag::arrayCount, sprintfTag::ext, sprintfTag::extNum, sprintfTag::format, getExtension(), Header, HEADER_EXT_FORMAT, HEADER_EXT_LAST, HEADER_EXT_MORE, headerFreeData(), headerGetEntry(), headerSprintfExtension, headerTagFormatFunction, hPTR_t, int_32, int_8, headerSprintfExtension_s::name, sprintfTag::pad, RPM_BIN_TYPE, RPM_CHAR_TYPE, RPM_INT16_TYPE, RPM_INT32_TYPE, RPM_INT8_TYPE, RPM_STRING_ARRAY_TYPE, RPM_STRING_TYPE, stpcpy(), sprintfTag::tag, headerSprintfExtension_s::type, sprintfTag::type, headerSprintfExtension_s::u, uint_16, xmalloc(), and xstrdup().

Referenced by singleSprintf().

extensionCache freeExtensionCache | ( | const headerSprintfExtension | extensions,
|  | extensionCache | cache
| ) | `[static]`

Returns:
  NULL always

Definition at line 2832 of file header.c.

References _free(), extensionCache::data, extensionCache::freeit, HEADER_EXT_LAST, HEADER_EXT_MORE, headerSprintfExtension, headerSprintfExtension_s::type, and headerSprintfExtension_s::u.

sprintfToken freeFormat | ( | sprintfToken | format,
|  | int | num
| ) | `[static]`

Destroy headerSprintf format array.

Parameters:

  format | sprintf format array
  num | number of elements

Returns:
  NULL always

Definition at line 2024 of file header.c.

References _free(), sprintfToken::array, sprintfToken::cond, sprintfToken::type, and sprintfToken::u.

Referenced by parseExpression(), and parseFormat().

int getExtension | ( | Header | h,
|  | headerTagTagFunction | fn,
|  | hTYP_t | typeptr,
|  | hPTR_t * | data,
|  | hCNT_t | countptr,
|  | extensionCache | ext
| ) | `[static]`

Returns:
  0 on success, 1 on failure

Definition at line 2493 of file header.c.

References extensionCache::avail, extensionCache::count, extensionCache::data, extensionCache::freeit, hCNT_t, Header, headerTagTagFunction, hPTR_t, hTYP_t, and extensionCache::type.

Referenced by formatValue(), and singleSprintf().

void* grabData | ( | int_32 | type,
|  | hPTR_t | p,
|  | int_32 | c,
|  | int * | lengthPtr
| ) | `[static]`

Return (malloc'ed) copy of entry data.

Parameters:

  type | entry data type
  p | entry data
  c | entry item count

Return values:

  lengthPtr | no. bytes in returned data

Returns:
  (malloc'ed) copy of entry data

Definition at line 1671 of file header.c.

References copyData(), dataLength(), hPTR_t, int_32, and xmalloc().

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 1445 of file header.c.

References entryInfo::count, indexEntry::data, findEntry(), getenv(), Header, HEADER_I18NTABLE, headerMatchLocale(), indexEntry::info, and RPM_STRING_ARRAY_TYPE.

Referenced by intGetEntry().

int headerGetRawEntry | ( | Header | h,
|  | int_32 | tag,
|  | int_32 * | type,
|  | hPTR_t * | p,
|  | int_32 * | c
| ) |

| Definition at line 1606 of file header.c. References copyEntry(), findEntry(), Header, headerIsEntry(), hPTR_t, int_32, and RPM_NULL_TYPE.

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 1372 of file header.c.

References alloca().

Referenced by headerFindI18NString().

char* hexFormat | ( | int_32 | type,
|  | hPTR_t | data,
|  | char * | formatPrefix,
|  | int | padding,
|  | int | element
| ) | `[static]`

| Definition at line 2951 of file header.c. References _, hPTR_t, int_32, RPM_INT32_TYPE, xmalloc(), and xstrdup().

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

| Definition at line 188 of file header.c. References indexEntry::info, and entryInfo::tag. Referenced by findEntry().

int intGetEntry | ( | Header | h,
|  | int_32 | tag,
|  | hTAG_t | type,
|  | hPTR_t * | p,
|  | hCNT_t | c,
|  | int | minMem
| ) | `[static]`

Retrieve tag data from header.

Parameters:

  h | header
  tag | tag to retrieve

Return values:

  type | address of type (or NULL)
  p | address of data (or NULL)
  c | address of count (or NULL)

Parameters:

  minMem | string pointers reference header memory?

Returns:
  1 on success, 0 on not found

Definition at line 1499 of file header.c.

References copyEntry(), findEntry(), hCNT_t, Header, headerFindI18NString(), hPTR_t, hTAG_t, indexEntry::info, int_32, RPM_I18NSTRING_TYPE, RPM_NULL_TYPE, RPM_STRING_TYPE, and entryInfo::type.

char* octalFormat | ( | int_32 | type,
|  | hPTR_t | data,
|  | char * | formatPrefix,
|  | int | padding,
|  | int | element
| ) | `[static]`

| Definition at line 2930 of file header.c. References _, hPTR_t, int_32, RPM_INT32_TYPE, xmalloc(), and xstrdup().

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

| Definition at line 212 of file header.c. References indexEntry::data, indexEntry::info, entryInfo::offset, and entryInfo::tag.

int parseExpression | ( | sprintfToken | token,
|  | char * | str,
|  | const headerTagTableEntry | tags,
|  | const headerSprintfExtension | extensions,
|  | char ** | endPtr,
|  | errmsg_t * | errmsg
| ) | `[static]`

| Definition at line 2367 of file header.c. References _, errmsg_t, findTag(), freeFormat(), headerSprintfExtension, headerTagTableEntry, parseFormat(), PARSER_IN_EXPR, sprintfToken::type, headerSprintfExtension_s::u, sprintfToken::u, headerTagTableEntry_s::val, and xstrdup(). Referenced by parseFormat().

int parseFormat | ( | char * | str,
|  | const headerTagTableEntry | tags,
|  | const headerSprintfExtension | extensions,
|  | sprintfToken * | formatPtr,
|  | int * | numTokensPtr,
|  | char ** | endPtr,
|  | int | state,
|  | errmsg_t * | errmsg
| ) | `[static]`

| Definition at line 2117 of file header.c. References _, errmsg_t, escapedChar(), findTag(), freeFormat(), headerSprintfExtension, headerTagTableEntry, parseExpression(), PARSER_IN_ARRAY, PARSER_IN_EXPR, headerSprintfExtension_s::u, headerTagTableEntry_s::val, xcalloc(), and xisdigit(). Referenced by parseExpression().

char* realDateFormat | ( | int_32 | type,
|  | hPTR_t | data,
|  | char * | formatPrefix,
|  | int | padding,
|  | int | element,
|  | const char * | strftimeFormat
| ) | `[static]`

| Definition at line 2972 of file header.c. References _, hPTR_t, int_32, RPM_INT32_TYPE, xmalloc(), and xstrdup(). Referenced by dateFormat(), and dayFormat().

char* shescapeFormat | ( | int_32 | type,
|  | hPTR_t | data,
|  | char * | formatPrefix,
|  | int | padding,
|  | int | element
| ) | `[static]`

| Definition at line 3024 of file header.c. References alloca(), hPTR_t, int_32, RPM_INT32_TYPE, and xmalloc().

const char* singleSprintf | ( | Header | h,
|  | sprintfToken | token,
|  | const headerSprintfExtension | extensions,
|  | extensionCache | extCache,
|  | int | element
| ) | `[static]`

| Definition at line 2691 of file header.c. References _free(), formatValue(), getExtension(), Header, headerFreeData(), headerGetEntry(), headerIsEntry(), headerSprintfExtension, sprintfToken::type, sprintfToken::u, xmalloc(), xrealloc(), and xstrdup().

const char* const tagName | ( | int | tag | ) |

| Definition at line 10 of file tagName.c. Referenced by handlePreambleTag().

## Variable Documentation

struct HV_s hdrVec1 `[static]`

| Definition at line 3214 of file header.c.