15 #define _RPMTAG_INTERNAL
34 #if defined(SUPPORT_IMPLICIT_TAG_DATA_TYPES)
35 extern void tagTypeValidate(
HE_t he)
47 0x8e, 0xad, 0xe8, 0x01, 0x00, 0x00, 0x00, 0x00
118 for (i = 0; i < h->
indexUsed; i++, entry++) {
122 if ((ei - 2) == h->
blob) {
126 "==> munmap(%p[%u]) error(%d): %s\n",
169 if (_headerPool ==
NULL) {
171 _headerPool =
rpmioNewPool(
"h",
sizeof(*h), -1, _hdr_debug,
213 static int indexCmp(
const void * avp,
const void * bvp)
219 return ((
int)ap->
info.
tag - (
int)bp->info.tag);
238 static int offsetCmp(
const void * avp,
const void * bvp)
248 rc = (((
char *)ap->
data) - ((
char *)bp->data));
284 for (i = 0, entry = h->
index; i < h->indexUsed; i++, entry++) {
305 if (typeSizes[type] > 1) {
306 diff = typeSizes[
type] - (size % typeSizes[
type]);
307 if ((
int)diff != typeSizes[
type]) {
314 size +=
sizeof(
struct entryInfo_s) + entry->length;
334 const unsigned char *
s = (
unsigned char *) (*p).ui8p;
335 const unsigned char *
se = (
unsigned char *) (pend ? (*pend).
ui8p :
NULL);
339 #if !defined(SUPPORT_I18NSTRING_TYPE)
346 while (*s++ !=
'\0') {
355 #if defined(SUPPORT_I18NSTRING_TYPE)
362 while (*s++ !=
'\0') {
369 const char **
av = (*p).argv;
372 length += strlen(*av++) + 1;
377 if (typeSizes[type] == -1)
379 length = typeSizes[(type & 0xf)] * count;
380 if ((
se && (s + length) >
se))
401 assert(nb == (2 * he->
c *
sizeof(*tt)));
402 for (i = 0; i < he->
c; i++) {
411 assert(nb == (he->
c *
sizeof(*tt)));
412 for (i = 0; i < he->
c; i++)
417 assert(nb == (he->
c *
sizeof(*tt)));
418 for (i = 0; i < he->
c; i++)
423 if ((
void *)t != he->
p.
ptr && nb)
424 memcpy(t, he->
p.
ptr, nb);
453 nb = he->
c *
sizeof(*he->
p.
ui8p);
456 nb = he->
c *
sizeof(*he->
p.
ui16p);
459 nb = he->
c *
sizeof(*he->
p.
ui32p);
462 nb = he->
c *
sizeof(*he->
p.
ui64p);
464 #if !defined(SUPPORT_I18NSTRING_TYPE)
470 nb = strlen(he->
p.
str) + 1;
474 #if defined(SUPPORT_I18NSTRING_TYPE)
529 unsigned char * dataStart,
530 const unsigned char * dataEnd,
537 unsigned char * tprev =
NULL;
538 unsigned char *
t =
NULL;
546 memset(&ieprev, 0,
sizeof(ieprev));
547 for (; il > 0; il--, pe++) {
567 if (dataEnd && t >= dataEnd)
596 if (typeSizes[type] > 1) {
597 size_t diff = typeSizes[
type] - (dl % typeSizes[
type]);
598 if ((
int)diff != typeSizes[
type]) {
606 tdel = (tprev ? (t - tprev) : 0);
626 if (dataEnd && (dataStart + dl) > dataEnd)
return 0;
631 tdel = (tprev ? (t - tprev) : 0);
653 unsigned char * dataStart;
676 drlen = ndribbles = driplen = ndrips = 0;
677 for (i = 0, entry = h->
index; i < h->indexUsed; i++, entry++) {
701 if (typeSizes[type] > 1) {
702 size_t diff = typeSizes[
type] - (dl % typeSizes[
type]);
703 if ((
int)diff != typeSizes[
type]) {
726 if (typeSizes[type] > 1) {
727 size_t diff = typeSizes[
type] - (dl % typeSizes[
type]);
728 if ((
int)diff != typeSizes[
type]) {
746 len =
sizeof(il) +
sizeof(dl) + (il *
sizeof(*pe)) + dl;
753 dataStart = te = (
unsigned char *) (pe + il);
756 for (i = 0, entry = h->
index; i < h->indexUsed; i++, entry++) {
780 src = (
char *)entry->
data;
781 rdlen = entry->
rdlen;
788 memcpy(pe+1, src, rdl);
789 memcpy(te, src + rdl, rdlen);
804 memcpy(pe+1, src +
sizeof(*pe), ((ril-1) *
sizeof(*pe)));
805 memcpy(te, src + (ril *
sizeof(*pe)), rdlen+entry->
info.
count+drlen);
812 ? htonl(te - dataStart) : htonl(off));
819 while (i < h->indexUsed && entry->
info.
offset <= rid+1) {
835 if (typeSizes[type] > 1) {
837 diff = typeSizes[
type] - ((te - dataStart) % typeSizes[type]);
838 if ((
int)diff != typeSizes[type]) {
853 if (((
unsigned char *)pe) != dataStart)
855 if ((((
unsigned char *)ei)+len) != te)
905 entry > h->
index) entry--;
913 entry2 < last) entry2++;
940 if (!entry)
return 1;
943 while (entry > h->
index && (entry - 1)->
info.
tag == tag)
947 for (first = entry; first < last; first++) {
959 ne = (first - entry);
964 memmove(entry, first, (ne *
sizeof(*entry)));
977 size_t pvlen =
sizeof(il) +
sizeof(dl) +
983 unsigned char * dataStart;
984 unsigned char * dataEnd;
997 dataStart = (
unsigned char *) (pe + il);
998 dataEnd = dataStart + dl;
1037 entry->
info.
offset = ((
unsigned char *)pe - dataStart);
1042 entry->
length = pvlen -
sizeof(il) -
sizeof(dl);
1048 entry->
rdlen = rdlen;
1077 memcpy(
alloca(nb), dataStart + off,
nb);
1096 entry->
length = pvlen -
sizeof(il) -
sizeof(dl);
1100 entry->
rdlen = rdlen;
1109 dataStart, dataEnd, rid);
1119 for (j = 0; j <
ne; j++, newEntry++) {
1128 (ne *
sizeof(*entry)));
1166 *magicp = (h ? h->
magic : hmagic);
1168 *nmagicp = (h ?
sizeof(h->
magic) :
sizeof(header_magic));
1174 if (nmagic >
sizeof(h->
magic))
1175 nmagic =
sizeof(h->
magic);
1179 memmove(h->
magic, magic, nmagic);
1238 memcpy(&h->
sb, st,
sizeof(h->
sb));
1282 uint32_t oinstance = 0;
1322 struct stat sb = h->
sb;
1345 if (origin !=
NULL) {
1347 origin =
_free(origin);
1349 if (parent !=
NULL) {
1351 parent =
_free(parent);
1353 if (baseurl !=
NULL) {
1355 baseurl =
_free(baseurl);
1357 if (digest !=
NULL) {
1359 digest =
_free(digest);
1367 fprintf(stderr,
"--> h %p ==== %s: blob %p[%u] flags 0x%x\n", nh, __FUNCTION__, nh->
blob, (
unsigned)nh->
bloblen, nh->
flags);
1371 digest =
_free(digest);
1372 baseurl =
_free(baseurl);
1373 parent =
_free(parent);
1374 origin =
_free(origin);
1385 size_t pvlen =
sizeof(il) +
sizeof(dl) +
1396 static const int prot = PROT_READ | PROT_WRITE;
1397 static const int flags = MAP_PRIVATE| MAP_ANONYMOUS;
1398 static const int fdno = -1;
1399 static const off_t off = 0;
1400 nuh = mmap(
NULL, pvlen, prot, flags, fdno, off);
1401 if (nuh ==
NULL || nuh == (
void *)-1)
1403 "==> mmap(%p[%u], 0x%x, 0x%x, %d, 0x%x) error(%d): %s\n",
1404 NULL, (
unsigned)pvlen, prot, flags, fdno, (
unsigned)off,
1406 memcpy(nuh, uh, pvlen);
1407 if (mprotect(nuh, pvlen, PROT_READ) != 0)
1408 fprintf(stderr,
"==> mprotect(%p[%u],0x%x) error(%d): %s\n",
1409 nuh, (
unsigned)pvlen, PROT_READ,
1417 if (munmap(nuh, pvlen) != 0)
1418 fprintf(stderr,
"==> munmap(%p[%u]) error(%d): %s\n",
1419 nuh, (
unsigned)pvlen,
errno, strerror(
errno));
1422 nuh = memcpy(
xmalloc(pvlen), uh, pvlen);
1434 static const int map = 1;
1472 unsigned char * dataStart = (
unsigned char *) (pe + ntohl(ei[0]));
1481 count = 2 *
sizeof(*ei) + (ril *
sizeof(*pe)) + rdl;
1495 pe = (
entryInfo) memcpy(ei + 2, pe, (ril *
sizeof(*pe)));
1498 (
void) memcpy(pe + ril, dataStart, rdl);
1501 he->
p.
ptr = (!minMem
1506 #if !defined(SUPPORT_I18NSTRING_TYPE)
1516 #if defined(SUPPORT_I18NSTRING_TYPE)
1520 {
const char **
argv;
1521 size_t nb = count *
sizeof(*argv);
1528 t = (
char *) entry->
data;
1531 t = (
char *) &argv[count];
1535 for (i = 0; i < (
unsigned) count; i++) {
1551 #if defined(SUPPORT_I18NSTRING_TYPE)
1570 static int headerMatchLocale(
const char *td,
const char *l,
const char *le)
1577 {
const char *
s, *ll, *CC, *EE, *dd;
1581 lbuf = (
char *)
alloca(le - l + 1);
1582 for (s = l, ll =
t = lbuf; *
s; s++,
t++) {
1603 for (
t = ll; *
t;
t++) *
t = tolower(*
t);
1605 for (
t = CC; *
t;
t++) *
t = toupper(*
t);
1612 if (strlen(td) == (size_t)(le - l) && !strncmp(td, l, (
size_t)(le - l)))
1616 for (fe = l; fe < le && *fe !=
'@'; fe++)
1618 if (fe < le && !strncmp(td, l, (fe - l)))
1622 for (fe = l; fe < le && *fe !=
'.'; fe++)
1624 if (fe < le && !strncmp(td, l, (fe - l)))
1628 for (fe = l; fe < le && *fe !=
'_'; fe++)
1630 if (fe < le && !strncmp(td, l, (fe - l)))
1646 const char *
lang, *l, *le;
1654 return (
char *) entry->
data;
1658 return (
char *) entry->
data;
1661 for (l = lang; *l !=
'\0'; l = le) {
1663 char *ed, *ed_weak =
NULL;
1666 while (*l && *l ==
':')
1670 for (le = l; *le && *le !=
':'; le++)
1674 for (langNum = 0, td = (
const char *)table->
data, ed = (
char *)entry->
data;
1675 langNum < entry->info.count;
1676 langNum++, td += strlen(td) + 1, ed += strlen(ed) + 1)
1678 int match = headerMatchLocale(td, l, le);
1679 if (match == 1)
return (
char *) ed;
1680 else if (match == 2) ed_weak = ed;
1682 if (ed_weak)
return (
char *) ed_weak;
1686 return ((entry->
data !=
NULL) && *(
char*)(entry->
data)) ?
_(entry->
data) : (char *) entry->data;
1708 if (entry ==
NULL) {
1716 #if defined(SUPPORT_I18NSTRING_TYPE)
1723 he->
p.
str = headerFindI18NString(h, entry);
1735 return (rc == 1 ? 1 : 0);
1751 #if defined(SUPPORT_I18NSTRING_TYPE)
1755 {
const char **
av = he->
p.
argv;
1759 while (cnt-- > 0 && nb > 0) {
1760 if ((s = *av++) !=
NULL)
1763 }
while (s[-1] && --nb > 0);
1829 data.
ptr = grabData(he, &length);
1830 if (data.
ptr ==
NULL || length == 0)
1875 #if !defined(SUPPORT_I18NSTRING_TYPE)
1930 #if defined(SUPPORT_I18NSTRING_TYPE)
1947 if (!table && entry)
1950 if (!table && !entry) {
1951 const char *
argv[2];
1954 if (!lang || (lang[0] ==
'C' && lang[1] ==
'\0')) {
1956 p.
argv[count++] =
"C";
1960 p.
argv[count++] =
"C";
1976 if (!lang) lang =
"C";
1978 {
const char * l = (
const char *) table->
data;
1979 for (langNum = 0; langNum < table->
info.
count; langNum++) {
1980 if (!
strcmp(l, lang))
break;
1986 length = strlen(lang) + 1;
1994 memmove(((
char *)table->
data) + table->
length, lang, length);
2000 p.
argv = (
const char **)
alloca(
sizeof(*p.
argv) * (langNum + 1));
2002 for (i = 0; i < langNum; i++)
2005 p.
argv[langNum] =
string;
2009 he->
c = langNum + 1;
2014 }
else if (langNum >= entry->
info.
count) {
2017 length = strlen(
string) + 1 + ghosts;
2027 memmove(((
char *)entry->
data) + entry->
length + ghosts,
string, strlen(
string)+1);
2032 char *
b, *
be, *e, *ee, *
t;
2036 b = be = e = ee = (
char *) entry->
data;
2040 ee += strlen(ee) + 1;
2047 sn = strlen(
string) + 1;
2049 length = bn + sn + en;
2050 t = buf = (
char *)
xmalloc(length);
2056 memcpy(t,
string, sn);
2063 entry->
length -= strlen(be) + 1;
2100 newData.
ptr = grabData(he, &length);
2101 if (newData.
ptr ==
NULL || length == 0)
2166 memset(he, 0,
sizeof(*he));
2168 for (slot = hi->
next_index; slot < h->indexUsed; slot++) {
2169 entry = h->
index + slot;
2190 return ((rc == 1) ? 1 : 0);
2216 if (headerFrom == headerTo)
2219 for (tagno = tagstocopy; *tagno != 0; tagno++) {
2239 if (h ==
NULL || he ==
NULL)
return 0;
2243 memset(he, 0,
sizeof(*he));
2253 for (ext = exts, extNum = 0; ext !=
NULL && ext->type != HEADER_EXT_LAST;
2254 ext = (ext->type == HEADER_EXT_MORE ? *ext->u.more : ext+1), extNum++)
2256 if (ext->name ==
NULL || ext->type != HEADER_EXT_TAG)
2262 if (ext && ext->name !=
NULL && ext->type == HEADER_EXT_TAG) {
2263 rc = ext->u.tagFunction(h, he);
2273 #if defined(SUPPORT_IMPLICIT_TAG_DATA_TYPES)
2277 tagTypeValidate(he);
2286 fprintf(stderr,
"==> %s(%u) %u %p[%u] free %u rc %d\n", name, (
unsigned) he->
tag, (
unsigned) he->
t, he->
p.
ptr, (
unsigned) he->
c, he->
freeData, rc);
2297 #if defined(SUPPORT_IMPLICIT_TAG_DATA_TYPES)
2300 tagTypeValidate(he);
2322 #if defined(SUPPORT_IMPLICIT_TAG_DATA_TYPES)
2325 tagTypeValidate(he);
qsort(mc->macroTable, mc->firstFree, sizeof(mc->macroTable[0]), compareMacroName)
#define ANNOTATE_BENIGN_RACE(_a, _b)
struct rpmdb_s * rpmdb
Database of headers and tag value indices.
char * getenv(const char *name)
rpmtime_t rpmswAdd(rpmop to, rpmop from)
Sum statistic counters.
static PyObject *int type
for(i=0;i< st->st_ntags;i++)
char * xstrdup(const char *str)
#define HEADER_SIGNATURES
static char *size_t nb
fgets(3) analogue that reads \ continuations.
#define HEADER_IMAGE
Header private tags.
#define DRD_xcalloc(_nmemb, _size)
#define HEADERGET_NOEXTENSION
#define SUPPORT_I18NSTRING_TYPE
Eliminate RPM_I18NSTRING_TYPE.
unsigned short rpmuint16_t
#define HEADERGET_NOI18NSTRING
unsigned char rpmuint8_t
Private int typedefs to avoid C99 portability issues.
memset(_r, 0, sizeof(*_r))
void * xcalloc(size_t nmemb, size_t size)
assert(key->size==sizeof(hdrNum))
rpmioItem rpmioGetPool(rpmioPool pool, size_t size)
Get unused item from pool, or alloc a new item.
fprintf(stderr,"--> %s(%p,%p,%p) sig %p sigp %p\n", __FUNCTION__, dig, t, rsactx, sig, sigp)
const char * tagName(rpmTag tag)
Return tag name from value.
rpmioItem rpmioPutPool(rpmioItem item)
Put unused item into pool (or free).
Cumulative statistics for an operation.
return strcmp(ame->name, bme->name)
int xstrcasecmp(const char *s1, const char *s2)
Locale insensitive strcasecmp(3).
rpmioPool rpmioNewPool(const char *name, size_t size, int limit, int flags, char *(*dbg)(void *item), void(*init)(void *item), void(*fini)(void *item))
Create a memory pool.
static void
Print copy of spec file, filling in Group/Description/Summary from specspo.
char * buf
Parse (and execute) macro undefinition.
int
Save source and expand field into target.
static void * _free(const void *p)
Wrapper to free(3), hides const compilation noise, permit NULL, return NULL.
int _hdr_stats
Global header stats enabler.
const unsigned char * digest