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
114 if (h->
index != NULL) {
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,
176 memset(((
char *)h)+
sizeof(h->
_item), 0,
sizeof(*h)-
sizeof(h->
_item));
184 (void) memcpy(h->
magic, header_magic,
sizeof(h->
magic));
192 memset(&h->
sb, 0,
sizeof(h->
sb));
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)
243 int rc = ((int)ap->
info.
offset - (
int)bp->info.offset);
248 rc = (((
char *)ap->
data) - ((
char *)bp->data));
250 rc = ((int)ap->
info.
tag - (
int)bp->info.tag);
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))
392 static unsigned char *
tagSwab(
unsigned char * t,
393 const HE_t he,
size_t nb)
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++)
422 assert(he->
p.
ptr != NULL);
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) 484 if (
tagSwab((
unsigned char *)ptr, he, nb) != NULL)
529 unsigned char * dataStart,
530 const unsigned char * dataEnd,
537 unsigned char * tprev = NULL;
538 unsigned char * t = NULL;
543 assert(dataEnd != NULL);
544 assert(entry != NULL);
546 memset(&ieprev, 0,
sizeof(ieprev));
547 for (; il > 0; il--, pe++) {
567 if (dataEnd && t >= dataEnd)
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++) {
721 if (entry->
data == NULL || entry->
length == 0)
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++) {
761 if (entry->
data == NULL || entry->
length == 0)
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) {
830 if (entry->
data == NULL || entry->
length == 0)
853 if (((
unsigned char *)pe) != dataStart)
855 if ((((
unsigned char *)ei)+len) != te)
890 if (h == NULL)
return NULL;
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;
1005 (void) memcpy(h->
magic, hmagic,
sizeof(h->
magic));
1016 memset(&h->
sb, 0,
sizeof(h->
sb));
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);
1174 if (nmagic >
sizeof(h->
magic))
1175 nmagic =
sizeof(h->
magic);
1179 memmove(h->
magic, magic, nmagic);
1186 return (h != NULL ? h->
origin : NULL);
1200 return (h != NULL ? h->
parent : NULL);
1215 return (h != NULL ? h->
baseurl : NULL);
1231 return (h != NULL ? &h->
sb : NULL);
1237 if (h != NULL && st != NULL)
1238 memcpy(&h->
sb, st,
sizeof(h->
sb));
1245 return (h != NULL ? h->
digest : NULL);
1262 return (h != NULL ? h->
rpmdb : NULL);
1277 return (h != NULL ? h->
instance : 0);
1282 uint32_t oinstance = 0;
1292 return (h != NULL ? h->
startoff : 0);
1304 return (h != NULL ? h->
endoff : 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);
1378 size_t pvlen =
sizeof(il) +
sizeof(dl) +
1389 static const int prot = PROT_READ | PROT_WRITE;
1390 static const int flags = MAP_PRIVATE| MAP_ANONYMOUS;
1391 static const int fdno = -1;
1392 static const off_t off = 0;
1393 nuh = mmap(NULL, pvlen, prot, flags, fdno, off);
1394 if (nuh == NULL || nuh == (
void *)-1)
1396 "==> mmap(%p[%u], 0x%x, 0x%x, %d, 0x%x) error(%d): %s\n",
1397 NULL, (
unsigned)pvlen, prot, flags, fdno, (
unsigned)off,
1399 memcpy(nuh, uh, pvlen);
1400 if (mprotect(nuh, pvlen, PROT_READ) != 0)
1401 fprintf(stderr,
"==> mprotect(%p[%u],0x%x) error(%d): %s\n",
1402 nuh, (
unsigned)pvlen, PROT_READ,
1410 if (munmap(nuh, pvlen) != 0)
1411 fprintf(stderr,
"==> munmap(%p[%u]) error(%d): %s\n",
1412 nuh, (
unsigned)pvlen,
errno, strerror(
errno));
1415 nuh = memcpy(
xmalloc(pvlen), uh, pvlen);
1427 static const int map = 1;
1465 unsigned char * dataStart = (
unsigned char *) (pe + ntohl(ei[0]));
1474 count = 2 *
sizeof(*ei) + (ril *
sizeof(*pe)) + rdl;
1488 pe = (
entryInfo) memcpy(ei + 2, pe, (ril *
sizeof(*pe)));
1491 (void) memcpy(pe + ril, dataStart, rdl);
1494 he->
p.
ptr = (!minMem
1499 #if !defined(SUPPORT_I18NSTRING_TYPE) 1509 #if defined(SUPPORT_I18NSTRING_TYPE) 1513 {
const char ** argv;
1514 size_t nb = count *
sizeof(*argv);
1521 t = (
char *) entry->
data;
1524 t = (
char *) &argv[count];
1528 for (i = 0; i < (unsigned) count; i++) {
1544 #if defined(SUPPORT_I18NSTRING_TYPE) 1563 static int headerMatchLocale(
const char *td,
const char *l,
const char *le)
1570 {
const char *s, *ll, *CC, *EE, *dd;
1574 lbuf = (
char *)
alloca(le - l + 1);
1575 for (s = l, ll = t = lbuf; *s; s++, t++) {
1596 for (t = ll; *t; t++) *t = tolower(*t);
1598 for (t = CC; *t; t++) *t = toupper(*t);
1605 if (strlen(td) == (size_t)(le - l) && !strncmp(td, l, (
size_t)(le - l)))
1609 for (fe = l; fe < le && *fe !=
'@'; fe++)
1611 if (fe < le && !strncmp(td, l, (fe - l)))
1615 for (fe = l; fe < le && *fe !=
'.'; fe++)
1617 if (fe < le && !strncmp(td, l, (fe - l)))
1621 for (fe = l; fe < le && *fe !=
'_'; fe++)
1623 if (fe < le && !strncmp(td, l, (fe - l)))
1639 const char *
lang, *l, *le;
1643 if ((lang =
getenv(
"LANGUAGE")) == NULL &&
1644 (lang =
getenv(
"LC_ALL")) == NULL &&
1645 (lang =
getenv(
"LC_MESSAGES")) == NULL &&
1646 (lang =
getenv(
"LANG")) == NULL)
1647 return (
char *) entry->
data;
1651 return (
char *) entry->
data;
1654 for (l = lang; *l !=
'\0'; l = le) {
1656 char *ed, *ed_weak = NULL;
1659 while (*l && *l ==
':')
1663 for (le = l; *le && *le !=
':'; le++)
1667 for (langNum = 0, td = (
const char *)table->
data, ed = (
char *)entry->
data;
1668 langNum < entry->info.count;
1669 langNum++, td += strlen(td) + 1, ed += strlen(ed) + 1)
1671 int match = headerMatchLocale(td, l, le);
1672 if (match == 1)
return (
char *) ed;
1673 else if (match == 2) ed_weak = ed;
1675 if (ed_weak)
return (
char *) ed_weak;
1678 return (
char *) entry->
data;
1700 if (entry == NULL) {
1708 #if defined(SUPPORT_I18NSTRING_TYPE) 1715 he->
p.
str = headerFindI18NString(h, entry);
1727 return (rc == 1 ? 1 : 0);
1743 #if defined(SUPPORT_I18NSTRING_TYPE) 1747 {
const char ** av = he->
p.
argv;
1751 while (cnt-- > 0 && nb > 0) {
1752 if ((s = *av++) != NULL)
1755 }
while (s[-1] && --nb > 0);
1759 if (
tagSwab((
unsigned char *)t, he, nb) == NULL)
1822 if (data.
ptr == NULL || length == 0)
1867 #if !defined(SUPPORT_I18NSTRING_TYPE) 1922 #if defined(SUPPORT_I18NSTRING_TYPE) 1939 if (!table && entry)
1942 if (!table && !entry) {
1943 const char * argv[2];
1946 if (!lang || (lang[0] ==
'C' && lang[1] ==
'\0')) {
1948 p.
argv[count++] =
"C";
1952 p.
argv[count++] =
"C";
1968 if (!lang) lang =
"C";
1970 {
const char * l = (
const char *) table->
data;
1971 for (langNum = 0; langNum < table->
info.
count; langNum++) {
1972 if (!strcmp(l, lang))
break;
1978 length = strlen(lang) + 1;
1986 memmove(((
char *)table->
data) + table->
length, lang, length);
1992 p.
argv = (
const char **)
alloca(
sizeof(*p.
argv) * (langNum + 1));
1994 for (i = 0; i < langNum; i++)
1997 p.
argv[langNum] =
string;
2001 he->
c = langNum + 1;
2006 }
else if (langNum >= entry->
info.
count) {
2009 length = strlen(
string) + 1 + ghosts;
2018 memset(((
char *)entry->
data) + entry->
length, 0, ghosts);
2019 memmove(((
char *)entry->
data) + entry->
length + ghosts,
string, strlen(
string)+1);
2024 char *b, *be, *e, *ee, *t;
2028 b = be = e = ee = (
char *) entry->
data;
2029 for (i = 0; i < table->
info.
count; i++) {
2032 ee += strlen(ee) + 1;
2039 sn = strlen(
string) + 1;
2041 length = bn + sn + en;
2042 t = buf = (
char *)
xmalloc(length);
2048 memcpy(t,
string, sn);
2055 entry->
length -= strlen(be) + 1;
2093 if (newData.
ptr == NULL || length == 0)
2144 assert(hi->
h != NULL);
2158 memset(he, 0,
sizeof(*he));
2160 for (slot = hi->
next_index; slot < h->indexUsed; slot++) {
2161 entry = h->
index + slot;
2166 if (entry == NULL || slot >= h->
indexUsed)
2182 return ((rc == 1) ? 1 : 0);
2208 if (headerFrom == headerTo)
2211 for (tagno = tagstocopy; *tagno != 0; tagno++) {
2231 if (h == NULL || he == NULL)
return 0;
2235 memset(he, 0,
sizeof(*he));
2245 for (ext = exts, extNum = 0; ext != NULL && ext->type != HEADER_EXT_LAST;
2246 ext = (ext->type == HEADER_EXT_MORE ? *ext->u.more : ext+1), extNum++)
2248 if (ext->name == NULL || ext->type != HEADER_EXT_TAG)
2254 if (ext && ext->name != NULL && ext->type == HEADER_EXT_TAG) {
2255 rc = ext->u.tagFunction(h, he);
2265 #if defined(SUPPORT_IMPLICIT_TAG_DATA_TYPES) 2269 tagTypeValidate(he);
2274 if (!((rc == 0 && he->
freeData == 0 && he->
p.
ptr == NULL) ||
2278 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);
2289 #if defined(SUPPORT_IMPLICIT_TAG_DATA_TYPES) 2292 tagTypeValidate(he);
2314 #if defined(SUPPORT_IMPLICIT_TAG_DATA_TYPES) 2317 tagTypeValidate(he);
#define ANNOTATE_BENIGN_RACE(_a, _b)
rpmtime_t rpmswExit(rpmop op, ssize_t rc)
Exit timed operation.
char * getenv(const char *name)
char * xstrdup(const char *str)
#define HEADER_SIGNATURES
struct headerToken_s * Header
#define HEADER_IMAGE
Header private tags.
rpmtime_t rpmswAdd(rpmop to, rpmop from)
Sum statistic counters.
#define DRD_xcalloc(_nmemb, _size)
#define HEADERGET_NOEXTENSION
#define SUPPORT_I18NSTRING_TYPE
Eliminate RPM_I18NSTRING_TYPE.
unsigned short rpmuint16_t
#define HEADERGET_NOI18NSTRING
void * xcalloc(size_t nmemb, size_t size)
rpmioItem rpmioGetPool(rpmioPool pool, size_t size)
Get unused item from pool, or alloc a new item.
unsigned char rpmuint8_t
Private int typedefs to avoid C99 portability issues.
unsigned long long rpmuint64_t
const char * tagName(rpmTag tag)
Return tag name from value.
struct rpmdb_s * rpmdb
Database of headers and tag value indices.
const struct headerSprintfExtension_s * headerSprintfExtension
rpmioItem rpmioPutPool(rpmioItem item)
Put unused item into pool (or free).
int xstrcasecmp(const char *s1, const char *s2)
Locale insensitive strcasecmp(3).
Header headerFree(Header h)
Dereference a header instance.
int rpmswEnter(rpmop op, ssize_t rc)
Enter timed operation.
enum rpmTagType_e rpmTagType
Cumulative statistics for an operation.
Header headerLink(Header h)
Reference a header instance.
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 * _free(const void *p)
Wrapper to free(3), hides const compilation noise, permit NULL, return NULL.
headerSprintfExtension headerCompoundFormats
Supported default header extension/tag output formats.
struct headerIterator_s * HeaderIterator