static PyObject * hdrKeyList(hdrObject * s) { PyObject * keys; HeaderIterator hi; rpmTagVal tag; keys = PyList_New(0); if (!keys) { return NULL; } hi = headerInitIterator(s->h); while ((tag = headerNextTag(hi)) != RPMTAG_NOT_FOUND) { PyObject *to = PyInt_FromLong(tag); if (!to) { headerFreeIterator(hi); Py_DECREF(keys); return NULL; } PyList_Append(keys, to); Py_DECREF(to); } headerFreeIterator(hi); return keys; }
static PyObject * hdr_iternext(hdrObject *s) { PyObject *res = NULL; rpmTagVal tag; if (s->hi == NULL) s->hi = headerInitIterator(s->h); if ((tag = headerNextTag(s->hi)) != RPMTAG_NOT_FOUND) { res = PyInt_FromLong(tag); } else { s->hi = headerFreeIterator(s->hi); } return res; }
/** * Check that no duplicate tags are present in header. * @param h header * @param NVR package name-version-release * @return RPMRC_OK if OK */ static int checkForDuplicates(Header h, const char * NVR) { int res = RPMRC_OK; rpmTagVal tag, lastTag = RPMTAG_NOT_FOUND; HeaderIterator hi = headerInitIterator(h); while ((tag = headerNextTag(hi)) != RPMTAG_NOT_FOUND) { if (tag == lastTag) { rpmlog(RPMLOG_ERR, _("Duplicate %s entries in package: %s\n"), rpmTagGetName(tag), NVR); res = RPMRC_FAIL; } lastTag = tag; } headerFreeIterator(hi); return res; }
rpmRC checkForEncoding(Header h, int addtag) { rpmRC rc = RPMRC_OK; #if HAVE_ICONV const char *encoding = "utf-8"; rpmTagVal tag; iconv_t ic = (iconv_t) -1; char *dest = NULL; size_t destlen = 0; int strict = rpmExpandNumeric("%{_invalid_encoding_terminates_build}"); HeaderIterator hi = headerInitIterator(h); ic = iconv_open(encoding, encoding); if (ic == (iconv_t) -1) { rpmlog(RPMLOG_WARNING, _("encoding %s not supported by system\n"), encoding); goto exit; } while ((tag = headerNextTag(hi)) != RPMTAG_NOT_FOUND) { struct rpmtd_s td; const char *src = NULL; if (rpmTagGetClass(tag) != RPM_STRING_CLASS) continue; headerGet(h, tag, &td, (HEADERGET_RAW|HEADERGET_MINMEM)); while ((src = rpmtdNextString(&td)) != NULL) { size_t srclen = strlen(src); size_t outlen, inlen = srclen; char *out, *in = (char *) src; if (destlen < srclen) { destlen = srclen * 2; dest = xrealloc(dest, destlen); } out = dest; outlen = destlen; /* reset conversion state */ iconv(ic, NULL, &inlen, &out, &outlen); if (iconv(ic, &in, &inlen, &out, &outlen) == (size_t) -1) { rpmlog(strict ? RPMLOG_ERR : RPMLOG_WARNING, _("Package %s: invalid %s encoding in %s: %s - %s\n"), headerGetString(h, RPMTAG_NAME), encoding, rpmTagGetName(tag), src, strerror(errno)); rc = RPMRC_FAIL; } } rpmtdFreeData(&td); } /* Stomp "known good utf" mark in header if requested */ if (rc == RPMRC_OK && addtag) headerPutString(h, RPMTAG_ENCODING, encoding); if (!strict) rc = RPMRC_OK; exit: if (ic != (iconv_t) -1) iconv_close(ic); headerFreeIterator(hi); free(dest); #endif /* HAVE_ICONV */ return rc; }