11 #define _RPMTAG_INTERNAL
14 #define _RPMEVR_INTERNAL
155 return PyBool_FromLong(isSource);
168 HE_t he = memset(
alloca(
sizeof(*he)), 0,
sizeof(*he));
172 list = PyList_New(0);
183 #if !defined(SUPPORT_I18NSTRING_TYPE)
194 o=PyInt_FromLong(he->
tag);
200 PyList_Append(list, o);
220 static char *kwlist[] = {
"legacyHeader", NULL};
222 if (!PyArg_ParseTupleAndKeywords(args, keywords,
"|i", kwlist, &legacy))
240 if (buf == NULL || nb == 0) {
241 PyErr_SetString(
pyrpmError,
"can't unload bad header\n");
245 rc = PyString_FromStringAndSize(buf, nb);
256 const char * origin = NULL;
261 return Py_BuildValue(
"s", origin);
270 char * kwlist[] = {
"origin", NULL};
271 const char * origin = NULL;
273 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"s:SetOrigin", kwlist, &origin))
276 if (s->
h != NULL && origin != NULL)
291 char * kwlist[] = {
"format", NULL};
293 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"s", kwlist, &fmt))
302 result = Py_BuildValue(
"s", r);
314 {
"keys", (PyCFunction)
hdrKeyList, METH_NOARGS,
316 {
"unload", (PyCFunction)
hdrUnload, METH_VARARGS|METH_KEYWORDS,
320 {
"setorigin", (PyCFunction)
hdrSetOrigin, METH_VARARGS|METH_KEYWORDS,
322 {
"sprintf", (PyCFunction)
hdrSprintf, METH_VARARGS|METH_KEYWORDS,
324 {
"isSource", (PyCFunction)
hdrIsSource, METH_NOARGS,
366 if (PyInt_Check(item)) {
367 return (
rpmTag) PyInt_AsLong(item);
368 }
else if (PyString_Check(item) || PyUnicode_Check(item)) {
369 str = PyString_AsString(item);
372 return (
rpmTag)0xffffffff;
380 HE_t he = memset(
alloca(
sizeof(*he)), 0,
sizeof(*he));
383 PyObject * o, * metao;
385 const struct headerSprintfExtension_s * ext = NULL;
388 if (PyCObject_Check (item))
389 ext = PyCObject_AsVoidPtr(item);
393 if (tag == (
rpmTag)0xffffffff && (PyString_Check(item) || PyUnicode_Check(item))) {
398 str = PyString_AsString(item);
399 while (extensions->name) {
400 if (extensions->type == HEADER_EXT_TAG
405 if (extensions->type == HEADER_EXT_MORE)
406 extensions = *extensions->u.more;
412 ext->u.tagFunction(s->
h, he);
414 if (tag == (
rpmTag)0xffffffff) {
415 PyErr_SetString(PyExc_KeyError,
"unknown header tag");
434 return PyList_New(0);
479 o = PyString_FromStringAndSize(he->
p.
str, he->
c);
483 if (he->
c != 1 || forceArray) {
484 metao = PyList_New(0);
488 for (i = 0; i < he->
c; i++) {
489 o = PyInt_FromLong(he->
p.
ui8p[i]);
494 PyList_Append(metao, o);
499 o = PyInt_FromLong(he->
p.
ui8p[0]);
504 if (he->
c != 1 || forceArray) {
505 metao = PyList_New(0);
509 for (i = 0; i < he->
c; i++) {
510 o = PyInt_FromLong(he->
p.
ui16p[i]);
515 PyList_Append(metao, o);
520 o = PyInt_FromLong(he->
p.
ui16p[0]);
525 if (he->
c != 1 || forceArray) {
526 metao = PyList_New(0);
530 for (i = 0; i < he->
c; i++) {
531 o = PyInt_FromLong(he->
p.
ui32p[i]);
536 PyList_Append(metao, o);
541 o = PyInt_FromLong(he->
p.
ui32p[0]);
546 if (he->
c != 1 || forceArray) {
547 metao = PyList_New(0);
551 for (i = 0; i < he->
c; i++) {
552 o = PyInt_FromLong(he->
p.
ui64p[i]);
557 PyList_Append(metao, o);
562 o = PyInt_FromLong(he->
p.
ui64p[0]);
567 metao = PyList_New(0);
571 for (i = 0; i < he->
c; i++) {
572 o = PyString_FromString(he->
p.
argv[i]);
577 PyList_Append(metao, o);
584 if (he->
p.
str != NULL)
585 o = PyString_FromString(he->
p.
str);
587 o = PyString_FromString(
"");
591 PyErr_SetString(PyExc_TypeError,
"unsupported type in header");
613 res = PyObject_GenericGetAttr((PyObject *)o, n);
622 return PyObject_GenericSetAttr((PyObject *)o, n, v);
634 PyVarObject_HEAD_INIT(&PyType_Type, 0)
655 #if Py_TPFLAGS_HAVE_ITER
692 PyObject *
hdrLoad(PyObject *
self, PyObject * args, PyObject * kwds)
699 char * kwlist[] = {
"headers", NULL};
701 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"s#", kwlist, &obj, &len))
710 memcpy (copy, obj, len);
723 return (PyObject *) hdr;
739 list = PyList_New(0);
743 Py_BEGIN_ALLOW_THREADS
744 {
const char item[] =
"Header";
745 const char * msg = NULL;
752 rpmlog(
RPMLOG_ERR,
"%s: %s: %s : error code: %d\n",
"rpmpkgRead", item, msg, rc);
759 if (PyList_Append(list, (PyObject *) hdr)) {
769 Py_BEGIN_ALLOW_THREADS
770 {
const char item[] =
"Header";
771 const char * msg = NULL;
778 rpmlog(
RPMLOG_ERR,
"%s: %s: %s : error code: %d\n",
"rpmpkgRead", item, msg, rc);
795 char * kwlist[] = {
"fd", NULL};
797 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"i", kwlist, &fileno))
816 char * kwlist[] = {
"file", NULL};
818 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"s", kwlist, &filespec))
821 fd =
Fopen(filespec,
"r.fdio");
845 char * kwlist[] = {
"fd", NULL};
847 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"i", kwlist, &fileno))
850 offset = lseek(fileno, 0,
SEEK_CUR);
859 Py_BEGIN_ALLOW_THREADS
860 {
const char item[] =
"Header";
861 const char * msg = NULL;
868 rpmlog(
RPMLOG_ERR,
"%s: %s: %s : error code: %d\n",
"rpmpkgRead", item, msg, rc);
875 tuple = PyTuple_New(2);
878 PyTuple_SET_ITEM(tuple, 0, (PyObject *)
hdr_Wrap(h));
879 PyTuple_SET_ITEM(tuple, 1, PyLong_FromLong(offset));
885 PyTuple_SET_ITEM(tuple, 0, Py_None);
886 PyTuple_SET_ITEM(tuple, 1, Py_None);
903 for(count = 0; count < PyList_Size(list); count++){
904 Py_BEGIN_ALLOW_THREADS
905 const char item[] =
"Header";
906 const char * msg = NULL;
910 rpmlog(
RPMLOG_ERR,
"%s: %s: %s : error code: %d\n",
"rpmpkgWrite", item, msg, rc);
927 char * kwlist[] = {
"headers",
"fd", NULL};
929 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"Oi", kwlist, &list, &fileno))
949 char * kwlist[] = {
"headers",
"file", NULL};
951 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"Os", kwlist, &list, &filespec))
954 fd =
Fopen(filespec,
"w.fdio");
972 char * kwlist[] = {
"version0",
"version1", NULL};
974 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"O!O!", kwlist, &hdr_Type,
975 &h1, &hdr_Type, &h2))
986 PyObject *aTuple, *bTuple;
988 if (!PyArg_ParseTuple(args,
"OO", &aTuple, &bTuple) ||
989 !PyArg_ParseTuple(aTuple,
"zzz|z",
990 &a->F[RPMEVR_E], &a->F[RPMEVR_V], &a->F[RPMEVR_R], &a->F[RPMEVR_D]) ||
991 !PyArg_ParseTuple(bTuple,
"zzz|z",
992 &b->F[RPMEVR_E], &b->F[RPMEVR_V], &b->F[RPMEVR_R], &b->F[RPMEVR_D]))
1000 if (a->F[RPMEVR_E] == NULL) a->F[RPMEVR_E] =
"0";
1001 if (b->F[RPMEVR_E] == NULL) b->F[RPMEVR_E] =
"0";
1002 if (a->F[RPMEVR_V] == NULL) a->F[RPMEVR_V] =
"";
1003 if (b->F[RPMEVR_V] == NULL) b->F[RPMEVR_V] =
"";
1004 if (a->F[RPMEVR_R] == NULL) a->F[RPMEVR_R] =
"";
1005 if (b->F[RPMEVR_R] == NULL) b->F[RPMEVR_R] =
"";
1006 if (a->F[RPMEVR_D] == NULL) a->F[RPMEVR_D] =
"";
1007 if (b->F[RPMEVR_D] == NULL) b->F[RPMEVR_D] =
"";
1014 return Py_BuildValue(
"i", rc);
1023 char * evr1, * evr2;
1024 char * kwlist[] = {
"evr0",
"evr1", NULL};
1026 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"ss", kwlist, &evr1, &evr2))
1037 return PyLong_FromLong(rc);
1040 PyObject *
evrSplit (PyObject *
self, PyObject * args, PyObject * kwds)
1044 char * kwlist[] = {
"evr", NULL};
1045 PyObject * tuple = NULL;
1047 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"s", kwlist, &evr))
1051 tuple = Py_BuildValue(
"(Isss)", EVR->F[RPMEVR_E] ? atoi(EVR->F[RPMEVR_E]) : 0, EVR->F[RPMEVR_V], EVR->F[RPMEVR_R], EVR->F[RPMEVR_D]);
rpmfiObject * hdr_fiFromHeader(PyObject *s, PyObject *args, PyObject *kwds)
const char const char size_t len
rpmRC rpmpkgWrite(const char *fn, FD_t fd, void *ptr, const char **msg)
Write item onto file descriptor.
rpmdsObject * hdr_dsOfHeader(PyObject *s)
FD_t Fopen(const char *path, const char *_fmode)
fopen(3) clone.
int rpmEVRparse(const char *evrstr, EVR_t evr)
Split EVR string into epoch, version, and release components.
static void rpmlog(int code, const char *fmt,...)
char * headerSprintf(Header h, const char *fmt, headerTagTableEntry tags, headerSprintfExtension exts, errmsg_t *errmsg)
Return formatted output string from header tags.
int rpmEVRcompare(const EVR_t a, const EVR_t b)
Compare EVR containers for equality.
rpmTag tagValue(const char *tagstr)
Return tag value from name.
const char const bson_bool_t v
rpmdsObject * hdr_dsFromHeader(PyObject *s, PyObject *args, PyObject *kwds)
The FD_t File Handle data structure.
int xstrcasecmp(const char *s1, const char *s2)
Locale insensitive strcasecmp(3).
Header headerFree(Header h)
Dereference a header instance.
int Fclose(FD_t fd)
fclose(3) clone.
Header headerLink(Header h)
Reference a header instance.
EVR_t rpmEVRnew(uint32_t Flags, int initialize)
Create a new EVR container.
enum rpmRC_e rpmRC
RPM return codes.
EVR_t rpmEVRfree(EVR_t evr)
Destroy an EVR container.
Methods to handle package elements.
static void * _free(const void *p)
Wrapper to free(3), hides const compilation noise, permit NULL, return NULL.
Structures and prototypes used for an "rpmts" transaction set.
Structure(s) and routine(s) used for EVR parsing and comparison.
rpmRC rpmpkgRead(const char *fn, FD_t fd, void *ptr, const char **msg)
Read item from file descriptor.
int rpmVersionCompare(Header A, Header B)