Some extensions to the htsmsg API, including fix for single length XML strings and cdata processing (previously in xmltv code).

This commit is contained in:
Adam Sutton 2012-06-19 11:40:08 +01:00
parent 5b9d4311db
commit c8847503b1
4 changed files with 77 additions and 1 deletions

View file

@ -196,6 +196,16 @@ htsmsg_add_s64(htsmsg_t *msg, const char *name, int64_t s64)
f->hmf_s64 = s64;
}
/*
*
*/
void
htsmsg_add_u64(htsmsg_t *msg, const char *name, uint64_t u64)
{
htsmsg_field_t *f = htsmsg_field_add(msg, name, HMF_S64, HMF_NAME_ALLOCED);
f->hmf_s64 = u64;
}
/*
*
*/
@ -306,6 +316,30 @@ htsmsg_get_s64(htsmsg_t *msg, const char *name, int64_t *s64p)
return 0;
}
/**
*
*/
int
htsmsg_get_u64(htsmsg_t *msg, const char *name, uint64_t *u64p)
{
htsmsg_field_t *f;
if((f = htsmsg_field_find(msg, name)) == NULL)
return HTSMSG_ERR_FIELD_NOT_FOUND;
switch(f->hmf_type) {
default:
return HTSMSG_ERR_CONVERSION_IMPOSSIBLE;
case HMF_STR:
*u64p = strtoull(f->hmf_str, NULL, 0);
break;
case HMF_S64:
*u64p = f->hmf_s64;
break;
}
return 0;
}
/*
*

View file

@ -107,6 +107,11 @@ void htsmsg_add_u32(htsmsg_t *msg, const char *name, uint32_t u32);
*/
void htsmsg_add_s32(htsmsg_t *msg, const char *name, int32_t s32);
/**
* Add an integer field where source is unsigned 64 bit.
*/
void htsmsg_add_u64(htsmsg_t *msg, const char *name, uint64_t u64);
/**
* Add an integer field where source is signed 64 bit.
*/
@ -171,6 +176,15 @@ int htsmsg_get_s32(htsmsg_t *msg, const char *name, int32_t *s32p);
*/
int htsmsg_get_s64(htsmsg_t *msg, const char *name, int64_t *s64p);
/**
* Get an integer as an unsigned 64 bit integer.
*
* @return HTSMSG_ERR_FIELD_NOT_FOUND - Field does not exist
* HTSMSG_ERR_CONVERSION_IMPOSSIBLE - Field is not an integer or
* out of range for the requested storage.
*/
int htsmsg_get_u64(htsmsg_t *msg, const char *name, uint64_t *u64p);
/**
* Get pointer to a binary field. No copying of data is performed.
*

View file

@ -693,7 +693,7 @@ htsmsg_xml_parse_cd(xmlparser_t *xp, htsmsg_t *parent, char *src)
}
}
if(y == 1 && c > 1) {
if(y == 1 && c > 0) {
/* One segment UTF-8 (or 7bit ASCII),
use data directly from source */
@ -865,3 +865,29 @@ htsmsg_xml_deserialize(char *src, char *errbuf, size_t errbufsize)
return NULL;
}
/*
* Get cdata string field
*/
const char *
htsmsg_xml_get_cdata_str(htsmsg_t *tags, const char *name)
{
htsmsg_t *sub;
if((sub = htsmsg_get_map(tags, name)) == NULL)
return NULL;
return htsmsg_get_str(sub, "cdata");
}
/*
* Get cdata u32 field
*/
int
htsmsg_xml_get_cdata_u32(htsmsg_t *tags, const char *name, uint32_t *u32)
{
htsmsg_t *sub;
if((sub = htsmsg_get_map(tags, name)) == NULL)
return HTSMSG_ERR_FIELD_NOT_FOUND;
return htsmsg_get_u32(sub, "cdata", u32);
}

View file

@ -23,5 +23,7 @@
#include "htsbuf.h"
htsmsg_t *htsmsg_xml_deserialize(char *src, char *errbuf, size_t errbufsize);
const char *htsmsg_xml_get_cdata_str (htsmsg_t *tags, const char *tag);
int htsmsg_xml_get_cdata_u32 (htsmsg_t *tags, const char *tag, uint32_t *u32);
#endif /* HTSMSG_XML_H_ */