rpm  4.5
Data Structures | Macros | Typedefs | Functions | Variables
header.c File Reference
#include "system.h"
#include <rpmio_internal.h>
#include <header_internal.h>
#include <rpmmacro.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...
 
struct  headerSprintfArgs_s
 

Macros

#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 hdrchkType(_type)   ((_type) < RPM_MIN_TYPE || (_type) > RPM_MAX_TYPE)
 Sanity check on type values.
 
#define hdrchkData(_nbytes)   ((_nbytes) & 0xff000000)
 Sanity check on data size and/or offset and/or count.
 
#define hdrchkAlign(_type, _off)   ((_off) & (typeAlign[_type]-1))
 Sanity check on alignment for data type.
 
#define hdrchkRange(_dl, _off)   ((_off) < 0 || (_off) > (_dl))
 Sanity check on range of data offset.
 
#define isSEP(_c)   ((_c) == ':' || (_c) == '|')
 

Typedefs

typedef struct
headerSprintfArgs_s
headerSprintfArgs
 

Functions

static void * headerGetStats (Header h, int opx)
 Return header stats accumulator structure.
 
static Header headerLink (Header h)
 Reference a header instance.
 
static Header headerUnlink (Header h)
 Dereference a header instance.
 
static Header headerFree (Header h)
 Dereference a header instance.
 
static 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.
 
static unsigned int headerSizeof (Header h, enum hMagic magicp)
 Return size of on-disk header representation in bytes.
 
static int dataLength (rpmTagType type, rpmTagData *p, rpmTagCount count, int onDisk, rpmTagData *pend)
 Return length of entry data.
 
static int regionSwab (indexEntry entry, int il, int dl, entryInfo pe, unsigned char *dataStart, const unsigned char *dataEnd, int regionid)
 Swap int_32 and int_16 arrays within header region.
 
static void * doHeaderUnload (Header h, size_t *lenp)
 
static void * headerUnload (Header h)
 Convert header to on-disk representation.
 
static indexEntry findEntry (Header h, int_32 tag, rpmTagType type)
 Find matching (tag,type) entry in header.
 
static int headerRemoveEntry (Header h, int_32 tag)
 Delete tag in header.
 
static Header headerLoad (void *uh)
 Convert header to in-memory representation.
 
static const char * headerGetOrigin (Header h)
 Return header origin (e.g path or URL).
 
static int headerSetOrigin (Header h, const char *origin)
 Store header origin (e.g path or URL).
 
const char * headerGetBaseURL (Header h)
 Return header base URL (e.g path or URL).
 
int headerSetBaseURL (Header h, const char *baseurl)
 Store header base URL (e.g path or URL).
 
struct stat * headerGetStatbuf (Header h)
 Return header stat(2) buffer (of origin *.rpm file).
 
int headerSetStatbuf (Header h, struct stat *st)
 Copy into header stat(2) buffer (of origin *.rpm file).
 
const char * headerGetDigest (Header h)
 Return digest of origin *.rpm file.
 
int headerSetDigest (Header h, const char *digest)
 Store digest of origin *.rpm file.
 
static uint32_t headerGetInstance (Header h)
 
static uint32_t headerSetInstance (Header h, uint32_t instance)
 
uint32_t headerGetStartOff (Header h)
 Return header starting byte offset.
 
uint32_t headerSetStartOff (Header h, uint32_t startoff)
 Store header starting byte offset.
 
uint32_t headerGetEndOff (Header h)
 Return header ending byte offset.
 
uint32_t headerSetEndOff (Header h, uint32_t endoff)
 Store header ending byte offset.
 
static Header headerReload (Header h, int tag)
 Convert header to on-disk representation, and then reload.
 
static Header headerCopyLoad (const void *uh)
 Make a copy and convert header to in-memory representation.
 
static Header headerRead (void *_fd, enum hMagic magicp)
 Read (and load) header from file handle.
 
static int headerWrite (void *_fd, Header h, enum hMagic magicp)
 Write (with unload) header to file handle.
 
static int headerIsEntry (Header h, int_32 tag)
 Check if tag is in header.
 
static int copyEntry (const indexEntry entry, rpmTagType *type, rpmTagData *p, rpmTagCount *c, 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, int_32 tag, rpmTagType *type, rpmTagData *p, rpmTagCount *c, int minMem)
 Retrieve tag data from header.
 
static void * headerFreeTag (Header h, const void *data, rpmTagType type)
 Free data allocated when retrieved from header.
 
static int headerGetEntry (Header h, int_32 tag, hTYP_t type, void *p, hCNT_t c)
 Retrieve tag value.
 
static int headerGetEntryMinMemory (Header h, int_32 tag, hTYP_t type, void *p, hCNT_t c)
 Retrieve tag value using header internal array.
 
int headerGetRawEntry (Header h, int_32 tag, rpmTagType *type, void *p, rpmTagCount *c)
 Retrieve tag value with type match.
 
static void copyData (rpmTagType type, rpmTagData *dest, rpmTagData *src, rpmTagCount cnt, size_t len)
 
static void * grabData (rpmTagType type, rpmTagData *p, rpmTagCount c, int *lenp)
 Return (malloc'ed) copy of entry data.
 
static int headerAddEntry (Header h, int_32 tag, int_32 type, const void *p, int_32 c)
 Add tag to header.
 
static int headerAppendEntry (Header h, int_32 tag, int_32 type, const void *p, int_32 c)
 Append element to tag array in header.
 
static int headerAddOrAppendEntry (Header h, int_32 tag, int_32 type, const void *p, int_32 c)
 Add or append element to tag array in header.
 
static int headerAddI18NString (Header h, int_32 tag, const char *string, const char *lang)
 Add locale specific tag to header.
 
static int headerModifyEntry (Header h, int_32 tag, int_32 type, const void *p, int_32 c)
 Modify tag in header.
 
static char escapedChar (const char ch)
 
static HE_t rpmheMark (HE_t he)
 Mark a tag container with headerGetEntry() freeData.
 
static HE_t rpmheClean (HE_t he)
 Clean a tag container, free'ing attached malloc's.
 
static sprintfToken freeFormat (sprintfToken format, int num)
 Destroy headerSprintf format array.
 
static HeaderIterator headerFreeIterator (HeaderIterator hi)
 Destroy header tag iterator.
 
static HeaderIterator headerInitIterator (Header h)
 Create header tag iterator.
 
static int headerNextIterator (HeaderIterator hi, hTAG_t tag, hTYP_t type, hPTR_t *p, hCNT_t c)
 Return next tag from header.
 
static Header headerCopy (Header h)
 Duplicate a header.
 
static headerSprintfArgs hsaInit (headerSprintfArgs hsa)
 Initialize an hsa iteration.
 
static sprintfToken hsaNext (headerSprintfArgs hsa)
 Return next hsa iteration item.
 
static headerSprintfArgs hsaFini (headerSprintfArgs hsa)
 Finish an hsa iteration.
 
static char * hsaReserve (headerSprintfArgs hsa, size_t need)
 Reserve sufficient buffer space for next output value.
 
static const char * myTagName (headerTagTableEntry tbl, int val, int *typep)
 Return tag name from value.
 
static int myTagType (headerTagTableEntry tbl, int val)
 
static int myTagValue (headerTagTableEntry tbl, const char *name)
 Return tag value from name.
 
static int findTag (headerSprintfArgs hsa, sprintfToken token, const char *name)
 Search extensions and tags for a name.
 
char * intFormat (HE_t he, const char **av, const char *fmt)
 Convert tag data representation.
 
static char * octFormat (HE_t he, const char **av)
 Return octal formatted data.
 
static char * hexFormat (HE_t he, const char **av)
 Return hex formatted data.
 
static char * decFormat (HE_t he, const char **av)
 Return decimal formatted data.
 
static char * realDateFormat (HE_t he, const char **av, const char *strftimeFormat)
 Return strftime formatted data.
 
static char * dateFormat (HE_t he, const char **av)
 Return date formatted data.
 
static char * dayFormat (HE_t he, const char **av)
 Return day formatted data.
 
static char * shescapeFormat (HE_t he, const char **av)
 Return shell escape formatted data.
 
static int parseExpression (headerSprintfArgs hsa, sprintfToken token, char *str, char **endPtr)
 Parse a headerSprintf expression.
 
static int parseFormat (headerSprintfArgs hsa, char *str, sprintfToken *formatPtr, int *numTokensPtr, char **endPtr, int state)
 Parse a headerSprintf term.
 
static int getExtension (headerSprintfArgs hsa, headerTagTagFunction fn, HE_t he, HE_t ec)
 Call a header extension only once, saving results.
 
static char * formatValue (headerSprintfArgs hsa, sprintfTag tag, int element)
 Format a single item's value.
 
static char * singleSprintf (headerSprintfArgs hsa, sprintfToken token, int element)
 Format a single headerSprintf item.
 
static HE_t rpmecNew (const headerSprintfExtension exts, int *necp)
 Create an extension cache.
 
static HE_t rpmecFree (const headerSprintfExtension exts, HE_t ec)
 Destroy an extension cache.
 
static char * headerSprintf (Header h, const char *fmt, const struct headerTagTableEntry_s *tags, const struct headerSprintfExtension_s *exts, errmsg_t *errmsg)
 Return formatted output string from header tags.
 
static void headerCopyTags (Header headerFrom, Header headerTo, hTAG_t tagstocopy)
 Duplicate tag values from one header into another.
 

Variables

int _hdr_debug = 0
 
int _tagcache = 1
 
static unsigned char header_magic [8]
 
static int typeAlign [16]
 Alignment needed for header data types.
 
static int typeSizes [16]
 Size of header data types.
 
static size_t headerMaxbytes = (32*1024*1024)
 Maximum no.
 
HV_t hdrVec = &hdrVec1
 Header methods for rpm headers.
 
struct headerSprintfExtension_s headerDefaultFormats []
 Supported default header tag output formats.
 
struct headerTagTableEntry_srpmTagTable
 Automatically generated table of tag name/value pairs.
 
static struct HV_s hdrVec1
 

Macro Definition Documentation

#define __HEADER_PROTOTYPES__

Definition at line 13 of file header.c.

#define hdrchkAlign (   _type,
  _off 
)    ((_off) & (typeAlign[_type]-1))

Sanity check on alignment for data type.

Definition at line 117 of file header.c.

Referenced by regionSwab().

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

Sanity check on data size and/or offset and/or count.

This check imposes a limit of 16Mb, more than enough.

Definition at line 112 of file header.c.

Referenced by doHeaderUnload(), headerAddEntry(), headerCopyLoad(), headerLoad(), headerRead(), and regionSwab().

#define hdrchkRange (   _dl,
  _off 
)    ((_off) < 0 || (_off) > (_dl))

Sanity check on range of data offset.

Definition at line 122 of file header.c.

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

Referenced by doHeaderUnload(), headerCopyLoad(), headerLoad(), and headerRead().

#define hdrchkType (   _type)    ((_type) < RPM_MIN_TYPE || (_type) > RPM_MAX_TYPE)

Sanity check on type values.

Definition at line 106 of file header.c.

Referenced by headerAddEntry(), headerLoad(), and regionSwab().

#define isSEP (   _c)    ((_c) == ':' || (_c) == '|')

Referenced by parseFormat().

#define PARSER_BEGIN   0

Definition at line 34 of file header.c.

Referenced by headerSprintf().

#define PARSER_IN_ARRAY   1

Definition at line 35 of file header.c.

Referenced by parseFormat().

#define PARSER_IN_EXPR   2

Definition at line 36 of file header.c.

Referenced by parseExpression(), and parseFormat().

Typedef Documentation

Function Documentation

static void copyData ( rpmTagType  type,
rpmTagData dest,
rpmTagData src,
rpmTagCount  cnt,
size_t  len 
)
static

Definition at line 1924 of file header.c.

References RPM_I18NSTRING_TYPE, and RPM_STRING_ARRAY_TYPE.

Referenced by grabData(), and headerAppendEntry().

static int dataLength ( rpmTagType  type,
rpmTagData p,
rpmTagCount  count,
int  onDisk,
rpmTagData pend 
)
static

Return length of entry data.

Parameters
typeentry data type
*ptag container data
countentry item count
onDiskdata is concatenated strings (with NUL's))?
*pendpointer to end of tag container data (or NULL)
Returns
no. bytes in data, -1 on failure

Definition at line 389 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 char* dateFormat ( HE_t  he,
const char **  av 
)
static

Return date formatted data.

Parameters
hetag container
avparameter array (or NULL)
Returns
formatted string

Definition at line 2953 of file header.c.

References _, and realDateFormat().

static char* dayFormat ( HE_t  he,
const char **  av 
)
static

Return day formatted data.

Parameters
hetag container
avparameter array (or NULL)
Returns
formatted string

Definition at line 2965 of file header.c.

References _, and realDateFormat().

static char* decFormat ( HE_t  he,
const char **  av 
)
static

Return decimal formatted data.

Parameters
hetag container
avparameter array (or NULL)
Returns
formatted string

Definition at line 2908 of file header.c.

References intFormat().

static char escapedChar ( const char  ch)
static

Definition at line 2318 of file header.c.

References _hdr_debug.

Referenced by parseFormat().

static indexEntry findEntry ( Header  h,
int_32  tag,
rpmTagType  type 
)
static
static int findTag ( headerSprintfArgs  hsa,
sprintfToken  token,
const char *  name 
)
static
static char* formatValue ( headerSprintfArgs  hsa,
sprintfTag  tag,
int  element 
)
static
static sprintfToken freeFormat ( sprintfToken  format,
int  num 
)
static

Destroy headerSprintf format array.

Parameters
formatsprintf format array
numnumber of elements
Returns
NULL always

Definition at line 2380 of file header.c.

References _free(), _tagcache, argvFree(), sprintfToken_s::array, sprintfTag_s::av, sprintfToken_s::cond, sprintfTag_s::fmtfuncs, sprintfTag_s::he, sprintfTag_s::params, rpmheClean(), sprintfToken_s::tag, and sprintfToken_s::u.

Referenced by headerSprintf(), parseExpression(), and parseFormat().

static int getExtension ( headerSprintfArgs  hsa,
headerTagTagFunction  fn,
HE_t  he,
HE_t  ec 
)
static

Call a header extension only once, saving results.

Parameters
hsaheaderSprintf args
fnfunction
Return values
hetag container
ecextension cache
Returns
0 on success, 1 on failure

Definition at line 3490 of file header.c.

References _HE_s::avail, _HE_s::freeData, headerSprintfArgs_s::h, and rpmheClean().

Referenced by formatValue(), and singleSprintf().

static void* grabData ( rpmTagType  type,
rpmTagData p,
rpmTagCount  c,
int *  lenp 
)
static

Return (malloc'ed) copy of entry data.

Parameters
typeentry data type
*ptag container data
centry item count
Return values
*lenpno. bytes in returned data
Returns
(malloc'ed) copy of entry data, NULL on error

Definition at line 1959 of file header.c.

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

Referenced by headerAddEntry(), and headerModifyEntry().

static int headerAddEntry ( Header  h,
int_32  tag,
int_32  type,
const void *  p,
int_32  c 
)
static

Add tag to header.

Duplicate tags are okay, but only defined for iteration (with the exceptions noted below). While you are allowed to add i18n string arrays through this function, you probably don't mean to. See headerAddI18NString() instead.

Parameters
hheader
tagtag
typetag value data type
ppointer to tag value(s)
cnumber of values
Returns
1 on success, 0 on failure

Definition at line 1992 of file header.c.

References entryInfo_s::count, indexEntry_s::data, headerToken_s::flags, grabData(), hdrchkData, hdrchkType, HEADERFLAG_SORTED, headerToken_s::index, INDEX_MALLOC_SIZE, headerToken_s::indexAlloced, headerToken_s::indexUsed, indexEntry_s::info, indexEntry_s::length, entryInfo_s::offset, rpmDataType_u::ptr, entryInfo_s::tag, entryInfo_s::type, and xrealloc().

Referenced by headerAddI18NString(), headerAddOrAppendEntry(), headerCopy(), and headerCopyTags().

static int headerAddI18NString ( Header  h,
int_32  tag,
const char *  string,
const char *  lang 
)
static

Add locale specific tag to header.

A NULL lang is interpreted as the C locale. Here are the rules:

*       - If the tag isn't in the header, it's added with the passed string
*          as new value.
*       - If the tag occurs multiple times in entry, which tag is affected
*          by the operation is undefined.
*       - If the tag is in the header w/ this language, the entry is
*          *replaced* (like headerModifyEntry()).
* 

This function is intended to just "do the right thing". If you need more fine grained control use headerAddEntry() and headerModifyEntry().

Parameters
hheader
tagtag
stringtag value
langlocale
Returns
1 on success, 0 on failure

Definition at line 2132 of file header.c.

References _free(), alloca(), rpmDataType_u::argv, entryInfo_s::count, indexEntry_s::data, ENTRY_IN_REGION, findEntry(), HEADER_I18NTABLE, headerAddEntry(), indexEntry_s::info, lang, indexEntry_s::length, entryInfo_s::offset, rpmDataType_u::ptr, RPM_I18NSTRING_TYPE, RPM_STRING_ARRAY_TYPE, xmalloc(), and xrealloc().

static int headerAddOrAppendEntry ( Header  h,
int_32  tag,
int_32  type,
const void *  p,
int_32  c 
)
static

Add or append element to tag array in header.

Parameters
hheader
tagtag
typetag value data type
ppointer to tag value(s)
cnumber of values
Returns
1 on success, 0 on failure

Definition at line 2102 of file header.c.

References findEntry(), headerAddEntry(), and headerAppendEntry().

static int headerAppendEntry ( Header  h,
int_32  tag,
int_32  type,
const void *  p,
int_32  c 
)
static

Append element to tag array in header.

Appends item p to entry w/ tag and type as passed. Won't work on RPM_STRING_TYPE. Any pointers into header memory returned from headerGetEntryMinMemory() for this entry are invalid after this call has been made!

Parameters
hheader
tagtag
typetag value data type
ppointer to tag value(s)
cnumber of values
Returns
1 on success, 0 on failure

Definition at line 2051 of file header.c.

References copyData(), entryInfo_s::count, indexEntry_s::data, dataLength(), ENTRY_IN_REGION, findEntry(), indexEntry_s::info, indexEntry_s::length, entryInfo_s::offset, rpmDataType_u::ptr, RPM_I18NSTRING_TYPE, RPM_STRING_TYPE, xmalloc(), and xrealloc().

Referenced by headerAddOrAppendEntry().

static Header headerCopy ( Header  h)
static

Duplicate a header.

Parameters
hheader
Returns
new header instance

Definition at line 2526 of file header.c.

References alloca(), _HE_s::c, HEADER_IMAGE, headerAddEntry(), headerFreeData(), headerFreeIterator(), headerInitIterator(), headerNew(), headerNextIterator(), headerReload(), _HE_s::p, rpmDataType_u::ptr, _HE_s::t, and _HE_s::tag.

static Header headerCopyLoad ( const void *  uh)
static

Make a copy and convert header to in-memory representation.

Parameters
uhon-disk header blob (i.e. with offsets)
Returns
header

Definition at line 1353 of file header.c.

References _free(), headerToken_s::flags, hdrchkData, hdrchkTags, HEADERFLAG_ALLOCATED, headerLoad(), headerMaxbytes, and xmalloc().

static void headerCopyTags ( Header  headerFrom,
Header  headerTo,
hTAG_t  tagstocopy 
)
static

Duplicate tag values from one header into another.

Parameters
headerFromsource header
headerTodestination header
tagstocopyarray of tags that are copied

Definition at line 4099 of file header.c.

References headerAddEntry(), headerFreeData(), headerGetEntryMinMemory(), headerIsEntry(), and rpmDataType_u::ptr.

static char* headerFindI18NString ( Header  h,
indexEntry  entry 
)
static

Return i18n string from header that matches locale.

Parameters
hheader
entryi18n string data
Returns
matching i18n string (or 1st string if no match)

Definition at line 1720 of file header.c.

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

Referenced by intGetEntry().

static Header headerFree ( Header  h)
static
static HeaderIterator headerFreeIterator ( HeaderIterator  hi)
static

Destroy header tag iterator.

Parameters
hiheader tag iterator
Returns
NULL always

Definition at line 2440 of file header.c.

References _free(), headerIterator_s::h, and headerFree().

Referenced by headerCopy(), and hsaFini().

static void* headerFreeTag ( Header  h,
const void *  data,
rpmTagType  type 
)
static

Free data allocated when retrieved from header.

Parameters
hheader
datadata (or NULL)
typetype of data (or -1 to force free)
Returns
NULL always

Definition at line 1822 of file header.c.

References _free(), RPM_ASN1_TYPE, RPM_BIN_TYPE, RPM_I18NSTRING_TYPE, RPM_OPENPGP_TYPE, and RPM_STRING_ARRAY_TYPE.

static int headerGetEntry ( Header  h,
int_32  tag,
hTYP_t  type,
void *  p,
hCNT_t  c 
)
static

Retrieve tag value.

Will never return RPM_I18NSTRING_TYPE! RPM_STRING_TYPE elements with RPM_I18NSTRING_TYPE equivalent entries are translated (if HEADER_I18NTABLE entry is present).

Parameters
hheader
tagtag
Return values
*typetag value data type (or NULL)
*ppointer to tag value(s) (or NULL)
*cnumber of values (or NULL)
Returns
1 on success, 0 on failure

Definition at line 1852 of file header.c.

References headerGetStats(), intGetEntry(), rpmswEnter(), and rpmswExit().

Referenced by formatValue(), and singleSprintf().

static int headerGetEntryMinMemory ( Header  h,
int_32  tag,
hTYP_t  type,
void *  p,
hCNT_t  c 
)
static

Retrieve tag value using header internal array.

Get an entry using as little extra RAM as possible to return the tag value. This is only an issue for RPM_STRING_ARRAY_TYPE.

Parameters
hheader
tagtag
Return values
*typetag value data type (or NULL)
*ptag value(s) (or NULL)
*cnumber of values (or NULL)
Returns
1 on success, 0 on failure

Definition at line 1882 of file header.c.

References headerGetStats(), intGetEntry(), rpmswEnter(), and rpmswExit().

Referenced by headerCopyTags().

static uint32_t headerGetInstance ( Header  h)
static

Definition at line 1248 of file header.c.

References headerToken_s::instance.

static const char* headerGetOrigin ( Header  h)
static

Return header origin (e.g path or URL).

Parameters
hheader
Returns
header origin

Definition at line 1178 of file header.c.

References headerToken_s::origin.

static HeaderIterator headerInitIterator ( Header  h)
static

Create header tag iterator.

Parameters
hheader
Returns
header tag iterator

Definition at line 2456 of file header.c.

References headerIterator_s::h, headerLink(), headerSort(), headerIterator_s::next_index, and xmalloc().

Referenced by headerCopy(), and hsaInit().

static int headerIsEntry ( Header  h,
int_32  tag 
)
static

Check if tag is in header.

Parameters
hheader
tagtag
Returns
1 on success, 0 on failure

Definition at line 1507 of file header.c.

References findEntry(), and RPM_NULL_TYPE.

Referenced by headerCopyTags(), headerGetRawEntry(), and singleSprintf().

static Header headerLink ( Header  h)
static

Reference a header instance.

Parameters
hheader
Returns
referenced header instance

Definition at line 147 of file header.c.

References _hdr_debug, and headerToken_s::nrefs.

Referenced by headerInitIterator(), headerLoad(), headerNew(), and headerSprintf().

static Header headerLoad ( void *  uh)
static
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
tdheader i18n table data, NUL terminated
lstart of locale to match
leend of locale to match
Returns
1 on match, 0 on no match

Definition at line 1647 of file header.c.

References alloca().

Referenced by headerFindI18NString().

static int headerModifyEntry ( Header  h,
int_32  tag,
int_32  type,
const void *  p,
int_32  c 
)
static

Modify tag in header.

If there are multiple entries with this tag, the first one gets replaced.

Parameters
hheader
tagtag
typetag value data type
ppointer to tag value(s)
cnumber of values
Returns
1 on success, 0 on failure

Definition at line 2275 of file header.c.

References _free(), entryInfo_s::count, indexEntry_s::data, ENTRY_IN_REGION, findEntry(), grabData(), headerToken_s::index, indexEntry_s::info, indexEntry_s::length, entryInfo_s::offset, rpmDataType_u::ptr, entryInfo_s::tag, and entryInfo_s::type.

static Header headerNew ( void  )
static
static int headerNextIterator ( HeaderIterator  hi,
hTAG_t  tag,
hTYP_t  type,
hPTR_t p,
hCNT_t  c 
)
static

Return next tag from header.

Parameters
hiheader tag iterator
Return values
*tagtag
*typetag value data type
*ppointer to tag value(s)
*cnumber of values
Returns
1 on success, 0 on failure

Definition at line 2478 of file header.c.

References copyEntry(), ENTRY_IS_REGION, headerIterator_s::h, headerGetStats(), headerToken_s::index, headerToken_s::indexUsed, indexEntry_s::info, headerIterator_s::next_index, rpmswEnter(), rpmswExit(), and entryInfo_s::tag.

Referenced by headerCopy(), and hsaNext().

static Header headerRead ( void *  _fd,
enum hMagic  magicp 
)
static

Read (and load) header from file handle.

Parameters
_fdfile handle
magicpread (and verify) 8 bytes of (magic, 0)?
Returns
header (or NULL on error)

Definition at line 1384 of file header.c.

References _fd, _free(), block(), fdGetOPath(), headerToken_s::flags, hdrchkData, hdrchkTags, header_magic, HEADER_MAGIC_YES, HEADERFLAG_ALLOCATED, headerLoad(), headerMaxbytes, headerSetOrigin(), timedRead(), and xmalloc().

static Header headerReload ( Header  h,
int  tag 
)
static

Convert header to on-disk representation, and then reload.

This is used to insure that all header data is in one chunk.

Parameters
hheader (with pointers)
tagregion tag
Returns
on-disk header (with offsets)

Definition at line 1299 of file header.c.

References _free(), headerToken_s::baseurl, headerToken_s::digest, doHeaderUnload(), ENTRY_IS_REGION, headerToken_s::flags, HEADER_IMMUTABLE, HEADER_SIGNATURES, HEADERFLAG_ALLOCATED, headerFree(), headerLoad(), headerSetBaseURL(), headerSetDigest(), headerSetInstance(), headerSetOrigin(), headerToken_s::index, indexEntry_s::info, headerToken_s::instance, headerToken_s::origin, headerToken_s::sb, entryInfo_s::tag, and xstrdup().

Referenced by headerCopy().

static int headerRemoveEntry ( Header  h,
int_32  tag 
)
static

Delete tag in header.

Removes all entries of type tag from the header, returns 1 if none were found.

Parameters
hheader
tagtag
Returns
0 on success, 1 on failure (INCONSISTENT)

Definition at line 953 of file header.c.

References _free(), indexEntry_s::data, ENTRY_IN_REGION, findEntry(), headerToken_s::index, headerToken_s::indexUsed, indexEntry_s::info, indexEntry_s::length, RPM_NULL_TYPE, and entryInfo_s::tag.

Referenced by headerLoad().

static uint32_t headerSetInstance ( Header  h,
uint32_t  instance 
)
static

Definition at line 1255 of file header.c.

References headerToken_s::instance.

Referenced by headerReload().

static int headerSetOrigin ( Header  h,
const char *  origin 
)
static

Store header origin (e.g path or URL).

Parameters
hheader
originnew header origin
Returns
0 always

Definition at line 1191 of file header.c.

References _free(), headerToken_s::origin, and xstrdup().

Referenced by headerRead(), and headerReload().

static unsigned int headerSizeof ( Header  h,
enum hMagic  magicp 
)
static

Return size of on-disk header representation in bytes.

Parameters
hheader
magicpinclude size of 8 bytes for (magic, 0)?
Returns
size of on-disk header

Definition at line 318 of file header.c.

References entryInfo_s::count, ENTRY_IS_REGION, headerToken_s::flags, header_magic, HEADER_MAGIC_NO, HEADER_MAGIC_YES, HEADERFLAG_LEGACY, headerSort(), headerToken_s::index, indexEntry_s::info, indexEntry_s::length, entryInfo_s::offset, entryInfo_s::type, and typeSizes.

static void headerSort ( Header  h)
static

Sort tags in header.

Parameters
hheader

Definition at line 272 of file header.c.

References headerToken_s::flags, HEADERFLAG_SORTED, headerToken_s::index, indexCmp(), and headerToken_s::indexUsed.

Referenced by doHeaderUnload(), findEntry(), headerInitIterator(), headerLoad(), and headerSizeof().

static char* headerSprintf ( Header  h,
const char *  fmt,
const struct headerTagTableEntry_s tags,
const struct headerSprintfExtension_s exts,
errmsg_t errmsg 
)
static
static Header headerUnlink ( Header  h)
static

Dereference a header instance.

Parameters
hheader
Returns
NULL always

Definition at line 171 of file header.c.

References _hdr_debug, and headerToken_s::nrefs.

Referenced by headerFree().

static void* headerUnload ( Header  h)
static

Convert header to on-disk representation.

Parameters
hheader (with pointers)
Returns
on-disk header blob (i.e. with offsets)

Definition at line 889 of file header.c.

References doHeaderUnload(), and indexEntry_s::length.

static void headerUnsort ( Header  h)
static

Restore tags in header to original ordering.

Parameters
hheader

Definition at line 305 of file header.c.

References headerToken_s::index, headerToken_s::indexUsed, and offsetCmp().

Referenced by doHeaderUnload().

static int headerWrite ( void *  _fd,
Header  h,
enum hMagic  magicp 
)
static

Write (with unload) header to file handle.

Parameters
_fdfile handle
hheader
magicpprefix write with 8 bytes of (magic, 0)?
Returns
0 on success, 1 on error

Definition at line 1465 of file header.c.

References _fd, _free(), doHeaderUnload(), Fwrite(), header_magic, HEADER_MAGIC_NO, and HEADER_MAGIC_YES.

static char* hexFormat ( HE_t  he,
const char **  av 
)
static

Return hex formatted data.

Parameters
hetag container
avparameter array (or NULL)
Returns
formatted string

Definition at line 2896 of file header.c.

References intFormat().

static headerSprintfArgs hsaFini ( headerSprintfArgs  hsa)
static

Finish an hsa iteration.

Parameters
hsaheaderSprintf args
Returns
headerSprintf args

Definition at line 2637 of file header.c.

References headerFreeIterator(), headerSprintfArgs_s::hi, and headerSprintfArgs_s::i.

Referenced by headerSprintf().

static headerSprintfArgs hsaInit ( headerSprintfArgs  hsa)
static

Initialize an hsa iteration.

Parameters
hsaheaderSprintf args
Returns
headerSprintf args

Definition at line 2573 of file header.c.

References sprintfToken_s::array, headerSprintfArgs_s::format, headerSprintfArgs_s::h, headerInitIterator(), headerSprintfArgs_s::hi, headerSprintfArgs_s::i, sprintfToken_s::tag, sprintfTag_s::tagno, sprintfToken_s::type, and sprintfToken_s::u.

Referenced by headerSprintf().

static sprintfToken hsaNext ( headerSprintfArgs  hsa)
static
static char* hsaReserve ( headerSprintfArgs  hsa,
size_t  need 
)
static

Reserve sufficient buffer space for next output value.

Parameters
hsaheaderSprintf args
needno. of bytes to reserve
Returns
pointer to reserved space

Definition at line 2656 of file header.c.

References headerSprintfArgs_s::alloced, headerSprintfArgs_s::val, headerSprintfArgs_s::vallen, and xrealloc().

Referenced by formatValue(), headerSprintf(), and singleSprintf().

static int indexCmp ( const void *  avp,
const void *  bvp 
)
static

Definition at line 258 of file header.c.

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

Referenced by findEntry(), and headerSort().

char* intFormat ( HE_t  he,
const char **  av,
const char *  fmt 
)

Convert tag data representation.

Parameters
hetag container
avparameter array (or NULL)
fmtoutput radix (NULL or "" assumes d)
Returns
formatted string

Definition at line 2809 of file header.c.

References _, alloca(), rpmDataType_u::argv, _HE_s::c, rpmDataType_u::i32p, rpmDataType_u::i64p, rpmDataType_u::i8p, _HE_s::ix, _HE_s::p, RPM_ASN1_TYPE, RPM_BIN_TYPE, RPM_CHAR_TYPE, RPM_INT16_TYPE, RPM_INT32_TYPE, RPM_INT64_TYPE, RPM_INT8_TYPE, RPM_OPENPGP_TYPE, RPM_STRING_ARRAY_TYPE, RPM_STRING_TYPE, snprintf(), rpmDataType_u::str, _HE_s::t, rpmDataType_u::ui16p, and xstrdup().

Referenced by decFormat(), formatValue(), hexFormat(), octFormat(), and rpnFormat().

static int intGetEntry ( Header  h,
int_32  tag,
rpmTagType type,
rpmTagData p,
rpmTagCount c,
int  minMem 
)
static

Retrieve tag data from header.

Parameters
hheader
tagtag to retrieve
Return values
*typetype (or NULL)
*pdata (or NULL)
*ccount (or NULL)
Parameters
minMemstring pointers reference header memory?
Returns
1 on success, 0 on not found

Definition at line 1775 of file header.c.

References copyEntry(), findEntry(), headerFindI18NString(), indexEntry_s::info, RPM_I18NSTRING_TYPE, RPM_NULL_TYPE, RPM_STRING_TYPE, and entryInfo_s::type.

Referenced by headerGetEntry(), and headerGetEntryMinMemory().

static const char* myTagName ( headerTagTableEntry  tbl,
int  val,
int *  typep 
)
static

Return tag name from value.

Todo:
bsearch on sorted value table.
Parameters
tbltag table
valtag value to find
Return values
*typeptag type (or NULL)
Returns
tag name, NULL on not found

Definition at line 2677 of file header.c.

References name, headerTagTableEntry_s::name, headerTagTableEntry_s::type, headerTagTableEntry_s::val, and xtolower().

Referenced by singleSprintf().

static int myTagType ( headerTagTableEntry  tbl,
int  val 
)
static
static int myTagValue ( headerTagTableEntry  tbl,
const char *  name 
)
static

Return tag value from name.

Todo:
bsearch on sorted name table.
Parameters
tbltag table
nametag name to find
Returns
tag value, 0 on not found

Definition at line 2719 of file header.c.

References headerTagTableEntry_s::name, headerTagTableEntry_s::val, and xstrcasecmp().

Referenced by findTag().

static char* octFormat ( HE_t  he,
const char **  av 
)
static

Return octal formatted data.

Parameters
hetag container
avparameter array (or NULL)
Returns
formatted string

Definition at line 2884 of file header.c.

References intFormat().

static int offsetCmp ( const void *  avp,
const void *  bvp 
)
static

Definition at line 283 of file header.c.

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

Referenced by headerUnsort().

static int parseExpression ( headerSprintfArgs  hsa,
sprintfToken  token,
char *  str,
char **  endPtr 
)
static

Parse a headerSprintf expression.

Parameters
hsaheaderSprintf args
token
str
Return values
*endPtr
Returns
0 on success

Definition at line 3379 of file header.c.

References _, _hdr_debug, sprintfToken_s::cond, headerSprintfArgs_s::errmsg, findTag(), freeFormat(), parseFormat(), PARSER_IN_EXPR, sprintfToken_s::type, and sprintfToken_s::u.

Referenced by parseFormat().

static int parseFormat ( headerSprintfArgs  hsa,
char *  str,
sprintfToken formatPtr,
int *  numTokensPtr,
char **  endPtr,
int  state 
)
static
static char* realDateFormat ( HE_t  he,
const char **  av,
const char *  strftimeFormat 
)
static

Return strftime formatted data.

Parameters
hetag container
avparameter array (or NULL)
strftimeFormatstrftime(3) format
Returns
formatted string

Definition at line 2921 of file header.c.

References _, _HE_s::p, rpmDataType_u::ptr, RPM_INT64_TYPE, _HE_s::t, rpmDataType_u::ui64p, and xstrdup().

Referenced by dateFormat(), and dayFormat().

static HE_t rpmecFree ( const headerSprintfExtension  exts,
HE_t  ec 
)
static

Destroy an extension cache.

Parameters
extsheaderSprintf extensions
ecextension cache
Returns
NULL always

Definition at line 3958 of file header.c.

References _free(), HEADER_EXT_LAST, HEADER_EXT_MORE, headerSprintfExtension_s::more, rpmheClean(), headerSprintfExtension_s::type, and headerSprintfExtension_s::u.

Referenced by headerSprintf().

static HE_t rpmecNew ( const headerSprintfExtension  exts,
int *  necp 
)
static

Create an extension cache.

Parameters
extsheaderSprintf extensions
Return values
*necpno. of elements (or NULL)
Returns
new extension cache

Definition at line 3932 of file header.c.

References HEADER_EXT_LAST, HEADER_EXT_MORE, headerSprintfExtension_s::more, headerSprintfExtension_s::type, headerSprintfExtension_s::u, and xcalloc().

Referenced by headerSprintf().

static HE_t rpmheClean ( HE_t  he)
static

Clean a tag container, free'ing attached malloc's.

Parameters
hetag container

Definition at line 2362 of file header.c.

References _free(), _HE_s::freeData, _HE_s::p, and rpmDataType_u::ptr.

Referenced by formatValue(), freeFormat(), getExtension(), hsaNext(), rpmecFree(), and singleSprintf().

static HE_t rpmheMark ( HE_t  he)
static

Mark a tag container with headerGetEntry() freeData.

Parameters
hetag container

Definition at line 2340 of file header.c.

References _HE_s::freeData, RPM_BIN_TYPE, RPM_I18NSTRING_TYPE, RPM_STRING_ARRAY_TYPE, and _HE_s::t.

Referenced by formatValue(), hsaNext(), and singleSprintf().

static char* shescapeFormat ( HE_t  he,
const char **  av 
)
static

Return shell escape formatted data.

Parameters
hetag container
avparameter array (or NULL)
Returns
formatted string

Definition at line 2977 of file header.c.

References _, rpmDataType_u::i32p, rpmDataType_u::i64p, _HE_s::p, RPM_INT32_TYPE, RPM_INT64_TYPE, RPM_STRING_TYPE, snprintf(), rpmDataType_u::str, _HE_s::t, xmalloc(), and xstrdup().

static char* singleSprintf ( headerSprintfArgs  hsa,
sprintfToken  token,
int  element 
)
static

Variable Documentation

int _hdr_debug = 0
int _tagcache = 1

Definition at line 25 of file header.c.

Referenced by formatValue(), freeFormat(), and singleSprintf().

struct HV_s hdrVec1
static

Definition at line 4121 of file header.c.

struct headerTagTableEntry_s* rpmTagTable

Automatically generated table of tag name/value pairs.

Definition at line 205 of file tagtbl.c.