Ejemplo n.º 1
0
static PyObject *rpmtd_new(PyTypeObject *subtype, 
			   PyObject *args, PyObject *kwds)
{
    char *kwlist[] = {"tag", NULL};
    PyObject *pytag;
    rpmTag tag;
    rpmtd td;
    rpmtdObject *self = PyObject_New(rpmtdObject, subtype);

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "O", kwlist, &pytag))
	return NULL;

    tag = tagNumFromPyObject(pytag);
#ifdef	DYING	/* XXX with arbitrary tags, all tags are found. */
    if (tag == RPMTAG_NOT_FOUND) {
	PyErr_SetString(PyExc_TypeError, 
			"can't create container for unknown tag");
	return NULL;
    }
#endif

    td = rpmtdNew();
    td->tag = tag;
    td->type = rpmTagGetType(tag) & RPM_MASK_TYPE;

    self->td = td;
    return (PyObject *)self;
}
Ejemplo n.º 2
0
int headerPutString(Header h, rpmTag tag, const char *val)
{
    rpmTagType type = rpmTagGetType(tag) & RPM_MASK_TYPE;
    const void *sptr = NULL;

    /* string arrays expect char **, arrange that */
    if (type == RPM_STRING_ARRAY_TYPE || type == RPM_I18NSTRING_TYPE) {
	sptr = &val;
    } else if (type == RPM_STRING_TYPE) {
	sptr = val;
    } else {
	return 0;
    }

    return headerPutType(h, tag, type, sptr, 1);
}
Ejemplo n.º 3
0
PyObject *rpmtd_AsPyobj(rpmtd td)
{
    PyObject *res = NULL;
    rpmTagType type = rpmTagGetType(rpmtdTag(td));
    int array = ((type & RPM_MASK_RETURN_TYPE) == RPM_ARRAY_RETURN_TYPE);

    if (!array && rpmtdCount(td) < 1) {
	Py_RETURN_NONE;
    }
    
    if (array) {
	res = PyList_New(0);
        if (!res) {
            return NULL;
        }
	while (rpmtdNext(td) >= 0) {
	    PyList_Append(res, rpmtd_ItemAsPyobj(td));
	}
    } else {
	res = rpmtd_ItemAsPyobj(td);
    }
    return res;
}
Ejemplo n.º 4
0
/*
 * Sanity check data types against tag table before putting. Assume
 * append on all array-types.
 */
static int headerPutType(Header h, rpmTag tag, rpmTagType reqtype,
			rpm_constdata_t data, rpm_count_t size)
{
    struct rpmtd_s td;
    rpmTagType type = rpmTagGetType(tag);
    headerPutFlags flags = HEADERPUT_APPEND; 
    int valid = 1;

    /* Basic sanity checks: type must match and there must be data to put */
    if ((type & RPM_MASK_TYPE) != reqtype 
	|| size < 1 || data == NULL || h == NULL) {
	valid = 0;
    }

    /*
     * Non-array types can't be appended to. Binary types use size
     * for data length, for other non-array types size must be 1.
     */
    if ((type & RPM_MASK_RETURN_TYPE) != RPM_ARRAY_RETURN_TYPE) {
	flags = HEADERPUT_DEFAULT;
	if ((type & RPM_MASK_TYPE) != RPM_BIN_TYPE && size != 1) {
	    valid = 0;
	}
    }

    if (valid) {
	rpmtdReset(&td);
	td.tag = tag;
	td.type = type & RPM_MASK_TYPE;
	td.data = (void *) data;
	td.count = size;

	valid = headerPut(h, &td, flags);
    }

    return valid;
}