Exemplo n.º 1
0
Arquivo: rpmtd.c Projeto: akozumpl/rpm
int rpmtdSetTag(rpmtd td, rpmTagVal tag)
{
    assert(td != NULL);
    rpmTagType newtype = rpmTagGetTagType(tag);
    int rc = 0;

    /* 
     * Sanity checks: 
     * - is the new tag valid at all
     * - if changing tag of non-empty container, require matching type 
     */
    if (newtype == RPM_NULL_TYPE)
	goto exit;

    if (td->data || td->count > 0) {
	if (rpmTagGetTagType(td->tag) != rpmTagGetTagType(tag)) {
	    goto exit;
	}
    } 

    td->tag = tag;
    td->type = newtype;
    rc = 1;
    
exit:
    return rc;
}
Exemplo n.º 2
0
Arquivo: rpmtd.c Projeto: akozumpl/rpm
int rpmtdFromUint8(rpmtd td, rpmTagVal tag, uint8_t *data, rpm_count_t count)
{
    rpmTagType type = rpmTagGetTagType(tag);
    rpmTagReturnType retype = rpmTagGetReturnType(tag);
    
    if (count < 1)
	return 0;

    /*
     * BIN type is really just an uint8_t array internally, it's just
     * treated specially otherwise.
     */
    switch (type) {
    case RPM_CHAR_TYPE:
    case RPM_INT8_TYPE:
	if (retype != RPM_ARRAY_RETURN_TYPE && count > 1) 
	    return 0;
	/* fallthrough */
    case RPM_BIN_TYPE:
	break;
    default:
	return 0;
    }
    
    return rpmtdSet(td, tag, type, data, count);
}
Exemplo n.º 3
0
static int hdrPutTag(Header h, rpmTagVal tag, PyObject *value)
{
    rpmTagType type = rpmTagGetTagType(tag);
    rpmTagReturnType retype = rpmTagGetReturnType(tag);
    int rc = 0;

    /* XXX this isn't really right (i18n strings etc) but for now ... */
    if (headerIsEntry(h, tag)) {
	PyErr_SetString(PyExc_TypeError, "tag already exists");
	return rc;
    }

    /* validate all data before trying to insert */
    if (!validData(tag, type, retype, value)) { 
	PyErr_SetString(PyExc_TypeError, "invalid type for tag");
	return 0;
    }

    if (retype == RPM_SCALAR_RETURN_TYPE) {
	rc = hdrAppendItem(h, tag, type, value);
    } else if (retype == RPM_ARRAY_RETURN_TYPE && PyList_Check(value)) {
	Py_ssize_t len = PyList_Size(value);
	for (Py_ssize_t i = 0; i < len; i++) {
	    PyObject *item = PyList_GetItem(value, i);
	    rc = hdrAppendItem(h, tag, type, item);
	}
    } else {
	PyErr_SetString(PyExc_RuntimeError, "cant happen, right?");
    }

    return rc;
}
Exemplo n.º 4
0
Arquivo: rpmtd.c Projeto: akozumpl/rpm
int rpmtdFromArgv(rpmtd td, rpmTagVal tag, ARGV_t argv)
{
    int count = argvCount(argv);
    rpmTagType type = rpmTagGetTagType(tag);

    if (type != RPM_STRING_ARRAY_TYPE || count < 1)
	return 0;

    return rpmtdSet(td, tag, type, argv, count);
}
Exemplo n.º 5
0
Arquivo: rpmtd.c Projeto: akozumpl/rpm
int rpmtdFromStringArray(rpmtd td, rpmTagVal tag, const char **data, rpm_count_t count)
{
    rpmTagType type = rpmTagGetTagType(tag);
    if (type != RPM_STRING_ARRAY_TYPE || count < 1)
	return 0;
    if (type == RPM_STRING_TYPE && count != 1)
	return 0;

    return rpmtdSet(td, tag, type, data, count);
}
Exemplo n.º 6
0
Arquivo: rpmtd.c Projeto: akozumpl/rpm
int rpmtdFromArgi(rpmtd td, rpmTagVal tag, ARGI_t argi)
{
    int count = argiCount(argi);
    rpmTagType type = rpmTagGetTagType(tag);
    rpmTagReturnType retype = rpmTagGetReturnType(tag);

    if (type != RPM_INT32_TYPE || retype != RPM_ARRAY_RETURN_TYPE || count < 1)
	return 0;

    return rpmtdSet(td, tag, type, argiData(argi), count);
}
Exemplo n.º 7
0
Arquivo: rpmtd.c Projeto: akozumpl/rpm
int rpmtdFromUint64(rpmtd td, rpmTagVal tag, uint64_t *data, rpm_count_t count)
{
    rpmTagType type = rpmTagGetTagType(tag);
    rpmTagReturnType retype = rpmTagGetReturnType(tag);
    if (type != RPM_INT64_TYPE || count < 1) 
	return 0;
    if (retype != RPM_ARRAY_RETURN_TYPE && count > 1) 
	return 0;
    
    return rpmtdSet(td, tag, type, data, count);
}
Exemplo n.º 8
0
Arquivo: rpmtd.c Projeto: akozumpl/rpm
int rpmtdFromString(rpmtd td, rpmTagVal tag, const char *data)
{
    rpmTagType type = rpmTagGetTagType(tag);
    int rc = 0;

    if (type == RPM_STRING_TYPE) {
	rc = rpmtdSet(td, tag, type, data, 1);
    } else if (type == RPM_STRING_ARRAY_TYPE) {
	rc = rpmtdSet(td, tag, type, &data, 1);
    }

    return rc;
}
Exemplo n.º 9
0
int headerPutString(Header h, rpmTagVal tag, const char *val)
{
    rpmTagType type = rpmTagGetTagType(tag);
    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);
}
Exemplo n.º 10
0
/*
 * Sanity check data types against tag table before putting. Assume
 * append on all array-types.
 */
static int headerPutType(Header h, rpmTagVal tag, rpmTagType reqtype,
			rpm_constdata_t data, rpm_count_t size)
{
    struct rpmtd_s td;
    rpmTagType type = rpmTagGetTagType(tag);
    rpmTagReturnType retype = rpmTagGetReturnType(tag);
    headerPutFlags flags = HEADERPUT_APPEND; 
    int valid = 1;

    /* Basic sanity checks: type must match and there must be data to put */
    if (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 (retype != RPM_ARRAY_RETURN_TYPE) {
	flags = HEADERPUT_DEFAULT;
	if (type != RPM_BIN_TYPE && size != 1) {
	    valid = 0;
	}
    }

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

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

    return valid;
}
Exemplo n.º 11
0
rpmTagClass rpmTagGetClass(rpmTagVal tag)
{
    return rpmTagTypeGetClass(rpmTagGetTagType(tag));
}