Commit 58617799 authored by Jean-Paul Saman's avatar Jean-Paul Saman

PSI: add dvbpsi_CheckPSISection() utility function

All PSI table check the same common things before accepting a section as
being a valid section. Centralize these checks into a single function.
parent caed81f6
...@@ -30,6 +30,8 @@ ...@@ -30,6 +30,8 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdbool.h> #include <stdbool.h>
#include <assert.h>
#if defined(HAVE_INTTYPES_H) #if defined(HAVE_INTTYPES_H)
#include <inttypes.h> #include <inttypes.h>
#elif defined(HAVE_STDINT_H) #elif defined(HAVE_STDINT_H)
...@@ -84,6 +86,50 @@ void dvbpsi_DeletePSISections(dvbpsi_psi_section_t *p_section) ...@@ -84,6 +86,50 @@ void dvbpsi_DeletePSISections(dvbpsi_psi_section_t *p_section)
free(p_section); free(p_section);
p_section = p_next; p_section = p_next;
} }
p_section = NULL;
}
/*****************************************************************************
* dvbpsi_CheckPSISection
*****************************************************************************
* Check if PSI section has the expected table_id and it the syntax indicator
* is true.
*****************************************************************************/
bool dvbpsi_CheckPSISection(dvbpsi_t *p_dvbpsi, dvbpsi_psi_section_t *p_section,
const uint8_t table_id, const char *psz_table_name)
{
assert(p_dvbpsi);
assert(p_section);
if (p_section->i_table_id != table_id)
{
/* Invalid table_id value */
dvbpsi_error(p_dvbpsi, psz_table_name,
"invalid section (table_id == 0x%02x)",
p_section->i_table_id);
goto error;
}
if (!p_section->b_syntax_indicator)
{
/* Invalid section_syntax_indicator */
dvbpsi_error(p_dvbpsi, psz_table_name,
"invalid section (section_syntax_indicator == 0)");
goto error;
}
/* FIXME: Do we need to check the CRC for ALL tables? */
dvbpsi_debug(p_dvbpsi, psz_table_name,
"Table version %2d, " "i_extension %5d, "
"section %3d up to %3d, " "current %1d",
p_section->i_version, p_section->i_extension,
p_section->i_number, p_section->i_last_number,
p_section->b_current_next);
return true;
error:
return false;
} }
/***************************************************************************** /*****************************************************************************
......
...@@ -118,6 +118,23 @@ dvbpsi_psi_section_t * dvbpsi_NewPSISection(int i_max_size); ...@@ -118,6 +118,23 @@ dvbpsi_psi_section_t * dvbpsi_NewPSISection(int i_max_size);
*/ */
void dvbpsi_DeletePSISections(dvbpsi_psi_section_t * p_section); void dvbpsi_DeletePSISections(dvbpsi_psi_section_t * p_section);
/*****************************************************************************
* dvbpsi_CheckPSISection
*****************************************************************************/
/*!
* \fn bool dvbpsi_CheckPSISection(dvbpsi_t *p_dvbpsi, dvbpsi_psi_section_t *p_section,
const uint8_t table_id, const char *psz_table_name)
* \brief Check if PSI section has the expected table_id and it the syntax indicator
* is true.
* \param p_dvbpsi pointer to dvbpsi library handle
* \param p_section pointer to the PSI section structure
* \param table_id expected table id
* \param psz_table_name table name to use when reporting errors.
* \return boolean value (false if the section did not pass the tests).
*/
bool dvbpsi_CheckPSISection(dvbpsi_t *p_dvbpsi, dvbpsi_psi_section_t *p_section,
const uint8_t table_id, const char *psz_table_name);
/***************************************************************************** /*****************************************************************************
* dvbpsi_ValidPSISection * dvbpsi_ValidPSISection
*****************************************************************************/ *****************************************************************************/
......
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