Commit 7ad38a69 authored by Christophe Massiot's avatar Christophe Massiot Committed by Georgi Chorbadzhiyski

Rework the descriptors API

This is to avoid the hack with the CAT table, which doesn't have a descs
"header". So there are new functions descl_* to handle descriptor lists
without length. This change is backwards compatible for all tables except
CAT.
parent 6ef82dec
......@@ -32,7 +32,7 @@ extern "C"
/*****************************************************************************
* Descriptors list
*****************************************************************************/
static inline void descs_print(uint8_t *p_descs,
static inline void descl_print(uint8_t *p_descl, uint16_t i_length,
f_print pf_print, void *print_opaque,
f_iconv pf_iconv, void *iconv_opaque,
print_type_t i_print_type)
......@@ -41,7 +41,7 @@ static inline void descs_print(uint8_t *p_descs,
uint8_t *p_desc;
uint32_t i_private_data_specifier = 0;
while ((p_desc = descs_get_desc(p_descs, j)) != NULL) {
while ((p_desc = descl_get_desc(p_descl, i_length, j)) != NULL) {
uint8_t i_tag = desc_get_tag(p_desc);
j++;
......@@ -127,6 +127,15 @@ print_end:
}
}
static inline void descs_print(uint8_t *p_descs,
f_print pf_print, void *print_opaque,
f_iconv pf_iconv, void *iconv_opaque,
print_type_t i_print_type)
{
descl_print(p_descs + DESCS_HEADER_SIZE, descs_get_length(p_descs),
pf_print, print_opaque, pf_iconv, iconv_opaque, i_print_type);
}
/*****************************************************************************
* Network Information Table
*****************************************************************************/
......
......@@ -262,6 +262,33 @@ static inline void desc0a_print(uint8_t *p_desc, f_print pf_print,
/*****************************************************************************
* Descriptors list
*****************************************************************************/
static inline uint8_t *descl_get_desc(uint8_t *p_descl, uint16_t i_length,
uint16_t n)
{
uint8_t *p_desc = p_descl;
while (n) {
if (p_desc + DESC_HEADER_SIZE - p_descl > i_length) return NULL;
p_desc += DESC_HEADER_SIZE + desc_get_length(p_desc);
n--;
}
if (p_desc - p_descl >= i_length) return NULL;
return p_desc;
}
static inline bool descl_validate(const uint8_t *p_descl, uint16_t i_length)
{
const uint8_t *p_desc = p_descl;
while (p_desc + DESC_HEADER_SIZE - p_descl <= i_length)
p_desc += DESC_HEADER_SIZE + desc_get_length(p_desc);
return (p_desc - p_descl == i_length);
}
/*****************************************************************************
* Descriptors structure
*****************************************************************************/
#define DESCS_HEADER_SIZE 2
#define DESCS_MAX_SIZE 4095
......@@ -279,27 +306,14 @@ static inline uint16_t descs_get_length(const uint8_t *p_descs)
static inline uint8_t *descs_get_desc(uint8_t *p_descs, uint16_t n)
{
uint8_t *p_desc = p_descs + DESCS_HEADER_SIZE;
uint16_t i_descs_size = descs_get_length(p_descs) + DESCS_HEADER_SIZE;
while (n) {
if (p_desc + DESC_HEADER_SIZE - p_descs > i_descs_size) return NULL;
p_desc += DESC_HEADER_SIZE + desc_get_length(p_desc);
n--;
}
if (p_desc - p_descs >= i_descs_size) return NULL;
return p_desc;
return descl_get_desc(p_descs + DESCS_HEADER_SIZE,
descs_get_length(p_descs), n);
}
static inline bool descs_validate(const uint8_t *p_descs)
{
const uint8_t *p_desc = p_descs + DESCS_HEADER_SIZE;
uint16_t i_descs_size = descs_get_length(p_descs) + DESCS_HEADER_SIZE;
while (p_desc + DESC_HEADER_SIZE - p_descs <= i_descs_size)
p_desc += DESC_HEADER_SIZE + desc_get_length(p_desc);
return (p_desc - p_descs == i_descs_size);
return descl_validate(p_descs + DESCS_HEADER_SIZE,
descs_get_length(p_descs));
}
/*****************************************************************************
......@@ -993,22 +1007,14 @@ static inline uint16_t cat_get_desclength(const uint8_t *p_cat)
return psi_get_length(p_cat) - (CAT_HEADER_SIZE + PSI_CRC_SIZE - PSI_HEADER_SIZE);
}
static inline uint8_t *cat_alloc_descs(uint8_t *p_cat)
static inline uint8_t *cat_get_descl(uint8_t *p_cat)
{
uint16_t i_desc_len = cat_get_desclength(p_cat);
uint8_t *p_buf = malloc(i_desc_len + 2);
if (!p_buf)
return NULL;
memcpy(p_buf + 2, p_cat + 8, i_desc_len);
descs_set_length(p_buf, i_desc_len);
return p_buf;
return p_cat + CAT_HEADER_SIZE;
}
static inline void cat_free_descs(uint8_t *p_cat_descs)
static inline const uint8_t *cat_get_descl_const(const uint8_t *p_cat)
{
free(p_cat_descs);
return p_cat + CAT_HEADER_SIZE;
}
static inline bool cat_validate(const uint8_t *p_cat)
......@@ -1022,13 +1028,13 @@ static inline bool cat_validate(const uint8_t *p_cat)
|| psi_get_tableid(p_cat) != CAT_TABLE_ID)
return false;
if (!psi_check_crc(p_cat))
return false;
if (i_section_size < CAT_HEADER_SIZE
|| i_section_size < CAT_HEADER_SIZE + cat_get_desclength(p_cat))
return false;
if (!descl_validate(cat_get_descl_const(p_cat), cat_get_desclength(p_cat)))
return false;
return true;
}
......
......@@ -54,11 +54,9 @@ static inline void cat_table_print(uint8_t **pp_sections, f_print pf_print,
for (i = 0; i <= i_last_section; i++) {
uint8_t *p_section = psi_table_get_section(pp_sections, i);
uint8_t *p_descs = cat_alloc_descs(p_section);
descs_print(p_descs, pf_print, opaque, NULL, NULL, i_print_type);
cat_free_descs(p_descs);
descl_print(cat_get_descl(p_section), cat_get_desclength(p_section),
pf_print, opaque, NULL, NULL, i_print_type);
}
switch (i_print_type) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment