From 11980a42f28feddf33c0b2c74b6424b217404263 Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Tue, 13 May 2008 16:11:28 +0300 Subject: Add methods to construct tag containers from argv and argi arrays - basic type checking done based on tag (return) type --- lib/rpmtd.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'lib/rpmtd.c') diff --git a/lib/rpmtd.c b/lib/rpmtd.c index 5d46bf916..dfb86285a 100644 --- a/lib/rpmtd.c +++ b/lib/rpmtd.c @@ -52,6 +52,12 @@ rpmTag rpmtdTag(rpmtd td) return td->tag; } +rpmTagType rpmtdType(rpmtd td) +{ + assert(td != NULL); + return td->type; +} + int rpmtdInit(rpmtd td) { assert(td != NULL); @@ -91,3 +97,38 @@ const char * rpmtdGetString(rpmtd td) } return str; } + +int rpmtdFromArgv(rpmtd td, rpmTag tag, ARGV_t argv) +{ + int count = argvCount(argv); + rpmTagType type = rpmTagGetType(tag) & RPM_MASK_TYPE; + + if (type != RPM_STRING_ARRAY_TYPE || count < 1) + return 0; + + assert(td != NULL); + rpmtdReset(td); + td->type = type; + td->tag = tag; + td->count = count; + td->data = argv; + return 1; +} + +int rpmtdFromArgi(rpmtd td, rpmTag tag, ARGI_t argi) +{ + int count = argiCount(argi); + rpmTagType type = rpmTagGetType(tag) & RPM_MASK_TYPE; + rpmTagReturnType retype = rpmTagGetType(tag) & RPM_MASK_RETURN_TYPE; + + if (type != RPM_INT32_TYPE || retype != RPM_ARRAY_RETURN_TYPE || count < 1) + return 0; + + assert(td != NULL); + rpmtdReset(td); + td->type = type; + td->tag = tag; + td->count = count; + td->data = argiData(argi); + return 1; +} -- cgit v1.2.3