rrt_section.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * section and descriptor parser
  3. *
  4. * Copyright (C) 2005 Kenneth Aafloy (kenneth@linuxtv.org)
  5. * Copyright (C) 2005 Andrew de Quincey (adq_dvb@lidskialf.net)
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  20. */
  21. #include <libucsi/atsc/rrt_section.h>
  22. struct atsc_rrt_section *atsc_rrt_section_codec(struct atsc_section_psip *psip)
  23. {
  24. uint8_t * buf = (uint8_t *) psip;
  25. size_t pos = 0;
  26. size_t len = section_ext_length(&(psip->ext_head));
  27. int idx;
  28. int vidx;
  29. struct atsc_rrt_section *rrt = (struct atsc_rrt_section *) psip;
  30. if (len < sizeof(struct atsc_rrt_section))
  31. return NULL;
  32. pos += sizeof(struct atsc_rrt_section);
  33. if (len < (pos + rrt->rating_region_name_length))
  34. return NULL;
  35. if (atsc_text_validate(buf+pos, rrt->rating_region_name_length))
  36. return NULL;
  37. pos += rrt->rating_region_name_length;
  38. if (len < (pos + sizeof(struct atsc_rrt_section_part2)))
  39. return NULL;
  40. struct atsc_rrt_section_part2 *rrtpart2 = (struct atsc_rrt_section_part2 *) (buf+pos);
  41. pos += sizeof(struct atsc_rrt_section_part2);
  42. for(idx =0; idx < rrtpart2->dimensions_defined; idx++) {
  43. if (len < (pos + sizeof(struct atsc_rrt_dimension)))
  44. return NULL;
  45. struct atsc_rrt_dimension *dimension = (struct atsc_rrt_dimension *) (buf+pos);
  46. pos += sizeof(struct atsc_rrt_dimension);
  47. if (len < (pos + dimension->dimension_name_length))
  48. return NULL;
  49. if (atsc_text_validate(buf+pos, dimension->dimension_name_length))
  50. return NULL;
  51. pos += dimension->dimension_name_length;
  52. if (len < (pos + sizeof(struct atsc_rrt_dimension_part2)))
  53. return NULL;
  54. struct atsc_rrt_dimension_part2 *dpart2 = (struct atsc_rrt_dimension_part2 *) (buf+pos);
  55. pos += sizeof(struct atsc_rrt_dimension_part2);
  56. for(vidx =0; vidx < dpart2->values_defined; vidx++) {
  57. if (len < (pos + sizeof(struct atsc_rrt_dimension_value)))
  58. return NULL;
  59. struct atsc_rrt_dimension_value *value = (struct atsc_rrt_dimension_value *) (buf+pos);
  60. pos += sizeof(struct atsc_rrt_dimension_value);
  61. if (len < (pos + value->abbrev_rating_value_length))
  62. return NULL;
  63. if (atsc_text_validate(buf+pos, value->abbrev_rating_value_length))
  64. return NULL;
  65. pos += value->abbrev_rating_value_length;
  66. if (len < (pos + sizeof(struct atsc_rrt_dimension_value_part2)))
  67. return NULL;
  68. struct atsc_rrt_dimension_value_part2 *vpart2 =
  69. (struct atsc_rrt_dimension_value_part2 *) (buf+pos);
  70. pos += sizeof(struct atsc_rrt_dimension_value_part2);
  71. if (len < (pos + vpart2->rating_value_length))
  72. return NULL;
  73. if (atsc_text_validate(buf+pos, vpart2->rating_value_length))
  74. return NULL;
  75. pos+= vpart2->rating_value_length;
  76. }
  77. }
  78. if (len < (pos + sizeof(struct atsc_rrt_section_part3)))
  79. return NULL;
  80. struct atsc_rrt_section_part3 *part3 = (struct atsc_rrt_section_part3 *) (buf+pos);
  81. pos += sizeof(struct atsc_rrt_section_part3);
  82. if (len < (pos + part3->descriptors_length))
  83. return NULL;
  84. if (verify_descriptors(buf + pos, part3->descriptors_length))
  85. return NULL;
  86. pos += part3->descriptors_length;
  87. if (pos != len)
  88. return NULL;
  89. return (struct atsc_rrt_section *) psip;
  90. }