15 #define _RPMEVR_INTERNAL
158 static int dncmp(
const void * a,
const void * b)
161 const char *
const * first = a;
162 const char *
const * second = b;
163 return strcmp(*first, *second);
176 const char ** fileNames = NULL;
183 if (fileNames == NULL || count <= 0)
187 fileNames =
_free(fileNames);
209 const char ** dirNames;
210 const char ** baseNames;
230 if (fileNames == NULL || count <= 0)
233 dirNames =
alloca(
sizeof(*dirNames) * count);
234 baseNames =
alloca(
sizeof(*dirNames) * count);
235 dirIndexes =
alloca(
sizeof(*dirIndexes) * count);
237 if (fileNames[0][0] !=
'/') {
240 dirNames[dirIndex] =
"";
241 for (i = 0; i < count; i++) {
242 dirIndexes[i] = dirIndex;
243 baseNames[i] = fileNames[i];
249 for (i = 0; i < count; i++) {
250 const char ** needle;
255 if (fileNames[i] == NULL)
257 baseName = strrchr(fileNames[i],
'/') + 1;
258 len = baseName - fileNames[i];
260 savechar = *baseName;
264 (needle = bsearch(&fileNames[i], dirNames, dirIndex + 1,
sizeof(dirNames[0]),
dncmp)) == NULL) {
265 char *s =
alloca(len + 1);
266 memcpy(s, fileNames[i], len + 1);
268 dirIndexes[i] = ++dirIndex;
269 dirNames[dirIndex] = s;
271 dirIndexes[i] = needle - dirNames;
274 *baseName = savechar;
275 baseNames[i] = baseName;
285 dirNames, dirIndex + 1);
288 fileNames = hfd(fileNames, fnt);
299 const char ** fileNames = NULL;
309 if (fileNames == NULL || count <= 0)
316 fileNames =
_free(fileNames);
328 const char *
name, *version, *release;
333 const char ** provides = NULL;
334 const char ** providesEVR = NULL;
336 int_32 * provideFlags = NULL;
342 xx =
headerNVR(h, &name, &version, &release);
343 if (!(name && version && release))
345 pEVR = p =
alloca(21 + strlen(version) + 1 + strlen(release) + 1);
348 sprintf(p,
"%d:", *epoch);
365 for (i = 0; i < providesCount; i++) {
379 if (provides && providesEVR && provideFlags)
380 for (i = 0; i < providesCount; i++) {
381 if (!(provides[i] && providesEVR[i]))
384 !strcmp(name, provides[i]) && !strcmp(pEVR, providesEVR[i])))
392 provides = hfd(provides, pnt);
393 providesEVR = hfd(providesEVR, pvt);
419 list = PyList_New(0);
436 PyList_Append(list, o=PyInt_FromLong(tag));
454 static char *kwlist[] = {
"legacyHeader", NULL};
456 if (!PyArg_ParseTupleAndKeywords(args, keywords,
"|i", kwlist, &legacy))
469 if (buf == NULL || len == 0) {
470 PyErr_SetString(
pyrpmError,
"can't unload bad header\n");
474 rc = PyString_FromStringAndSize(buf, len);
507 const char * origin = NULL;
512 return Py_BuildValue(
"s", origin);
522 char * kwlist[] = {
"origin", NULL};
523 const char * origin = NULL;
525 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"s:SetOrigin", kwlist, &origin))
528 if (s->
h != NULL && origin != NULL)
555 char * kwlist[] = {
"format", NULL};
557 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"s", kwlist, &fmt))
566 result = Py_BuildValue(
"s", r);
578 {
"keys", (PyCFunction)
hdrKeyList, METH_NOARGS,
580 {
"unload", (PyCFunction)
hdrUnload, METH_VARARGS|METH_KEYWORDS,
592 {
"sprintf", (PyCFunction)
hdrSprintf, METH_VARARGS|METH_KEYWORDS,
638 if (PyInt_Check(item)) {
639 return PyInt_AsLong(item);
640 }
else if (PyString_Check(item) || PyUnicode_Check(item)) {
641 str = PyString_AsString(item);
668 {
const char ** fl = NULL;
694 *p = (
void *) msgstr;
716 int type, count, i, tag = -1;
718 PyObject * o, * metao;
726 if (PyCObject_Check (item))
727 ext = PyCObject_AsVoidPtr(item);
730 if (tag == -1 && (PyString_Check(item) || PyUnicode_Check(item))) {
733 str = PyString_AsString(item);
734 while (extensions->
name) {
745 HE_t he = memset(
alloca(
sizeof(*he)), 0,
sizeof(*he));
753 PyErr_SetString(PyExc_KeyError,
"unknown header tag");
769 return PyList_New(0);
819 o = PyString_FromStringAndSize(data, count);
823 if (count != 1 || forceArray) {
824 metao = PyList_New(0);
825 for (i = 0; i < count; i++) {
826 o = PyInt_FromLong(((
long long *) data)[i]);
827 PyList_Append(metao, o);
832 o = PyInt_FromLong(*((
long long *) data));
836 if (count != 1 || forceArray) {
837 metao = PyList_New(0);
838 for (i = 0; i < count; i++) {
839 o = PyInt_FromLong(((
int *) data)[i]);
840 PyList_Append(metao, o);
845 o = PyInt_FromLong(*((
int *) data));
851 if (count != 1 || forceArray) {
852 metao = PyList_New(0);
853 for (i = 0; i < count; i++) {
854 o = PyInt_FromLong(((
char *) data)[i]);
855 PyList_Append(metao, o);
860 o = PyInt_FromLong(*((
char *) data));
865 if (count != 1 || forceArray) {
866 metao = PyList_New(0);
867 for (i = 0; i < count; i++) {
868 o = PyInt_FromLong(((
short *) data)[i]);
869 PyList_Append(metao, o);
874 o = PyInt_FromLong(*((
short *) data));
881 metao = PyList_New(0);
882 for (i = 0; i < count; i++) {
883 o = PyString_FromString(stringArray[i]);
884 PyList_Append(metao, o);
892 if (count != 1 || forceArray) {
895 metao = PyList_New(0);
896 for (i=0; i < count; i++) {
897 o = PyString_FromString(stringArray[i]);
898 PyList_Append(metao, o);
903 o = PyString_FromString(data);
910 PyErr_SetString(PyExc_TypeError,
"unsupported type in header");
920 PyObject * res = PyObject_GenericGetAttr(o, n);
929 return PyObject_GenericSetAttr(o, n, v);
950 PyObject_HEAD_INIT(&PyType_Type)
972 #if Py_TPFLAGS_HAVE_ITER
1012 PyObject *
hdrLoad(PyObject *
self, PyObject * args, PyObject * kwds)
1019 char * kwlist[] = {
"headers", NULL};
1021 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"s#", kwlist, &obj, &len))
1027 PyErr_SetString(
pyrpmError,
"out of memory");
1030 memcpy (copy, obj, len);
1044 return (PyObject *) hdr;
1060 list = PyList_New(0);
1061 Py_BEGIN_ALLOW_THREADS
1063 Py_END_ALLOW_THREADS
1069 if (PyList_Append(list, (PyObject *) hdr)) {
1078 Py_BEGIN_ALLOW_THREADS
1080 Py_END_ALLOW_THREADS
1093 char * kwlist[] = {
"fd", NULL};
1095 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"i", kwlist, &fileno))
1113 char * kwlist[] = {
"file", NULL};
1115 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"s", kwlist, &filespec))
1118 fd =
Fopen(filespec,
"r.fdio");
1146 Py_BEGIN_ALLOW_THREADS
1148 Py_END_ALLOW_THREADS
1152 PyErr_SetString(
pyrpmError,
"match tag missing in new header");
1156 hdr = (
hdrObject *) PyList_GetItem(list, count++);
1160 PyErr_SetString(
pyrpmError,
"match tag missing in new header");
1164 if (*newMatch != *oldMatch) {
1165 PyErr_SetString(
pyrpmError,
"match tag mismatch");
1185 Py_BEGIN_ALLOW_THREADS
1187 Py_END_ALLOW_THREADS
1201 char * kwlist[] = {
"list",
"fd",
"matchTag", NULL};
1203 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"Oii", kwlist, &list,
1204 &fileno, &matchTag))
1207 if (!PyList_Check(list)) {
1208 PyErr_SetString(PyExc_TypeError,
"first parameter must be a list");
1235 char * kwlist[] = {
"fd", NULL};
1237 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"i", kwlist, &fileno))
1240 offset = lseek(fileno, 0,
SEEK_CUR);
1249 Py_BEGIN_ALLOW_THREADS
1251 Py_END_ALLOW_THREADS
1255 tuple = PyTuple_New(2);
1258 PyTuple_SET_ITEM(tuple, 0, (PyObject *)
hdr_Wrap(h));
1259 PyTuple_SET_ITEM(tuple, 1, PyLong_FromLong(offset));
1264 PyTuple_SET_ITEM(tuple, 0, Py_None);
1265 PyTuple_SET_ITEM(tuple, 1, Py_None);
1276 char * kwlist[] = {
"version0",
"version1", NULL};
1278 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"O!O!", kwlist, &hdr_Type,
1279 &h1, &hdr_Type, &h2))
1287 EVR_t A = memset(
alloca(
sizeof(*A)), 0,
sizeof(*A));
1288 EVR_t B = memset(
alloca(
sizeof(*B)), 0,
sizeof(*B));
1291 if (!PyArg_ParseTuple(args,
"(zzz)(zzz)",
1292 &A->E, &A->V, &A->R, &B->E, &B->V, &B->R))
1295 if (A->E == NULL) A->E =
"0";
1296 if (B->E == NULL) B->E =
"0";
1297 if (A->V == NULL) A->E =
"";
1298 if (B->V == NULL) B->E =
"";
1299 if (A->R == NULL) A->E =
"";
1300 if (B->R == NULL) B->E =
"";
1304 return Py_BuildValue(
"i", rc);