Add methods to construct tag containers from argv and argi arrays
- basic type checking done based on tag (return) type
This commit is contained in:
parent
ae218d25ae
commit
11980a42f2
41
lib/rpmtd.c
41
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;
|
||||
}
|
||||
|
|
30
lib/rpmtd.h
30
lib/rpmtd.h
|
@ -2,6 +2,7 @@
|
|||
#define _RPMTD_H
|
||||
|
||||
#include <rpm/rpmtypes.h>
|
||||
#include <rpm/argv.h>
|
||||
|
||||
/** \ingroup rpmtd
|
||||
* Container for rpm tag data (from headers or extensions).
|
||||
|
@ -56,6 +57,13 @@ rpm_count_t rpmtdCount(rpmtd td);
|
|||
*/
|
||||
rpmTag rpmtdTag(rpmtd td);
|
||||
|
||||
/** \ingroup rpmtd
|
||||
* Retrieve type of the container.
|
||||
* @param td Tag data container
|
||||
* @return Rpm tag type.
|
||||
*/
|
||||
rpmTagType rpmtdType(rpmtd td);
|
||||
|
||||
/** \ingroup rpmtd
|
||||
* Initialize tag container for iteration
|
||||
* @param td Tag data container
|
||||
|
@ -80,4 +88,26 @@ int rpmtdNext(rpmtd td);
|
|||
*/
|
||||
const char * rpmtdGetString(rpmtd td);
|
||||
|
||||
/** \ingroup rpmtd
|
||||
* Construct tag container from ARGV_t array.
|
||||
* Tag type is checked to be of string array type and array is checked
|
||||
* to be non-empty.
|
||||
* @param td Tag data container
|
||||
* @param tag Rpm tag to construct
|
||||
* @param argv ARGV array
|
||||
* @return 1 on success, 0 on error (eg wrong type)
|
||||
*/
|
||||
int rpmtdFromArgv(rpmtd td, rpmTag tag, ARGV_t argv);
|
||||
|
||||
/** \ingroup rpmtd
|
||||
* Construct tag container from ARGI_t array.
|
||||
* Tag type is checked to be of integer array type and array is checked
|
||||
* to be non-empty.
|
||||
* @param td Tag data container
|
||||
* @param tag Rpm tag to construct
|
||||
* @param argi ARGI array
|
||||
* @return 1 on success, 0 on error (eg wrong type)
|
||||
*/
|
||||
int rpmtdFromArgi(rpmtd td, rpmTag tag, ARGI_t argi);
|
||||
|
||||
#endif /* _RPMTD_H */
|
||||
|
|
Loading…
Reference in New Issue