Add some more rpmtd access methods
- rpmtdGetUint() for 16 and 32 bit integer types, similar to rpmtdGetString() (equally usable with scalar types and arrays) - rpmtdToString() which converts "any" header data into string presentation
This commit is contained in:
parent
e7ec2339b4
commit
30c4e29d33
61
lib/rpmtd.c
61
lib/rpmtd.c
|
@ -82,6 +82,31 @@ int rpmtdNext(rpmtd td)
|
|||
return i;
|
||||
}
|
||||
|
||||
uint16_t * rpmtdGetUint16(rpmtd td)
|
||||
{
|
||||
uint16_t *res = NULL;
|
||||
|
||||
assert(td != NULL);
|
||||
|
||||
if (td->type == RPM_INT16_TYPE) {
|
||||
int ix = (td->ix >= 0 ? td->ix : 0);
|
||||
res = (uint16_t *) td->data + ix;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
uint32_t * rpmtdGetUint32(rpmtd td)
|
||||
{
|
||||
uint32_t *res = NULL;
|
||||
|
||||
assert(td != NULL);
|
||||
|
||||
if (td->type == RPM_INT32_TYPE) {
|
||||
int ix = (td->ix >= 0 ? td->ix : 0);
|
||||
res = (uint32_t *) td->data + ix;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
const char * rpmtdGetString(rpmtd td)
|
||||
{
|
||||
const char *str = NULL;
|
||||
|
@ -98,6 +123,42 @@ const char * rpmtdGetString(rpmtd td)
|
|||
return str;
|
||||
}
|
||||
|
||||
char *rpmtdToString(rpmtd td)
|
||||
{
|
||||
char *res = NULL;
|
||||
|
||||
switch (td->type) {
|
||||
case RPM_STRING_TYPE:
|
||||
case RPM_STRING_ARRAY_TYPE: {
|
||||
const char *s = rpmtdGetString(td);
|
||||
if (s) {
|
||||
res = xstrdup(s);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case RPM_INT16_TYPE: {
|
||||
uint16_t *num = rpmtdGetUint16(td);
|
||||
if (num) {
|
||||
rasprintf(&res, "%hd", *num);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case RPM_INT32_TYPE: {
|
||||
uint32_t *num = rpmtdGetUint32(td);
|
||||
if (num) {
|
||||
rasprintf(&res, "%d", *num);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case RPM_BIN_TYPE: {
|
||||
/* XXX TODO: convert to hex presentation */
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
int rpmtdFromArgv(rpmtd td, rpmTag tag, ARGV_t argv)
|
||||
{
|
||||
int count = argvCount(argv);
|
||||
|
|
31
lib/rpmtd.h
31
lib/rpmtd.h
|
@ -78,6 +78,26 @@ int rpmtdInit(rpmtd td);
|
|||
*/
|
||||
int rpmtdNext(rpmtd td);
|
||||
|
||||
/** \ingroup rpmtd
|
||||
* Return uint16_t data from tag container.
|
||||
* For scalar return type, just return pointer to the integer. On array
|
||||
* types, return pointer to current iteration index. If the tag container
|
||||
* is not for int16 type, NULL is returned.
|
||||
* @param td Tag data container
|
||||
* @return Pointer to uint16_t, NULL on error
|
||||
*/
|
||||
uint16_t * rpmtdGetUint16(rpmtd td);
|
||||
|
||||
/** \ingroup rpmtd
|
||||
* Return uint32_t data from tag container.
|
||||
* For scalar return type, just return pointer to the integer. On array
|
||||
* types, return pointer to current iteration index. If the tag container
|
||||
* is not for int32 type, NULL is returned.
|
||||
* @param td Tag data container
|
||||
* @return Pointer to uint32_t, NULL on error
|
||||
*/
|
||||
uint32_t * rpmtdGetUint32(rpmtd td);
|
||||
|
||||
/** \ingroup rpmtd
|
||||
* Return string data from tag container.
|
||||
* For string types, just return the string. On string array types,
|
||||
|
@ -88,6 +108,17 @@ int rpmtdNext(rpmtd td);
|
|||
*/
|
||||
const char * rpmtdGetString(rpmtd td);
|
||||
|
||||
/** \ingroup rpmtd
|
||||
* Return data from tag container in string presentation.
|
||||
* Return malloced string presentation of current data in container,
|
||||
* converting from integers etc as necessary. On array types, data from
|
||||
* current iteration index is returned.
|
||||
* @param td Tag data container
|
||||
* @return String representation of current data (malloc'ed),
|
||||
* NULL on error
|
||||
*/
|
||||
char *rpmtdToString(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
|
||||
|
|
Loading…
Reference in New Issue