dccsct_section.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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/dccsct_section.h>
  22. struct atsc_dccsct_section *atsc_dccsct_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. if (len < sizeof(struct atsc_dccsct_section))
  29. return NULL;
  30. struct atsc_dccsct_section *dccsct = (struct atsc_dccsct_section *) psip;
  31. pos += sizeof(struct atsc_dccsct_section);
  32. for(idx =0; idx < dccsct->updates_defined; idx++) {
  33. if (len < (pos + sizeof(struct atsc_dccsct_update)))
  34. return NULL;
  35. struct atsc_dccsct_update *update = (struct atsc_dccsct_update *) (buf+pos);
  36. pos += sizeof(struct atsc_dccsct_update);
  37. if (len < (pos + update->update_data_length))
  38. return NULL;
  39. switch(update->update_type) {
  40. case ATSC_DCCST_UPDATE_NEW_GENRE: {
  41. int sublen = sizeof(struct atsc_dccsct_update_new_genre);
  42. if (update->update_data_length < sublen)
  43. return NULL;
  44. if (atsc_text_validate(buf+pos+sublen, update->update_data_length - sublen))
  45. return NULL;
  46. break;
  47. }
  48. case ATSC_DCCST_UPDATE_NEW_STATE: {
  49. int sublen = sizeof(struct atsc_dccsct_update_new_state);
  50. if (update->update_data_length < sublen)
  51. return NULL;
  52. if (atsc_text_validate(buf+pos+sublen, update->update_data_length - sublen))
  53. return NULL;
  54. break;
  55. }
  56. case ATSC_DCCST_UPDATE_NEW_COUNTY: {
  57. int sublen = sizeof(struct atsc_dccsct_update_new_county);
  58. if (update->update_data_length < sublen)
  59. return NULL;
  60. bswap16(buf+pos+1);
  61. if (atsc_text_validate(buf+pos+sublen, update->update_data_length - sublen))
  62. return NULL;
  63. break;
  64. }
  65. }
  66. pos += update->update_data_length;
  67. if (len < (pos + sizeof(struct atsc_dccsct_update_part2)))
  68. return NULL;
  69. struct atsc_dccsct_update_part2 *part2 = (struct atsc_dccsct_update_part2 *) buf + pos;
  70. bswap16(buf+pos);
  71. pos += sizeof(struct atsc_dccsct_update_part2);
  72. if (len < (pos + part2->descriptors_length))
  73. return NULL;
  74. if (verify_descriptors(buf + pos, part2->descriptors_length))
  75. return NULL;
  76. pos += part2->descriptors_length;
  77. }
  78. if (len < (pos + sizeof(struct atsc_dccsct_section_part2)))
  79. return NULL;
  80. struct atsc_dccsct_section_part2 *part2 = (struct atsc_dccsct_section_part2 *) (buf+pos);
  81. bswap16(buf+pos);
  82. pos += sizeof(struct atsc_dccsct_section_part2);
  83. if (len < (pos + part2->descriptors_length))
  84. return NULL;
  85. if (verify_descriptors(buf + pos, part2->descriptors_length))
  86. return NULL;
  87. pos += part2->descriptors_length;
  88. if (pos != len)
  89. return NULL;
  90. return (struct atsc_dccsct_section *) psip;
  91. }