eit_section.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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/eit_section.h>
  22. struct atsc_eit_section *atsc_eit_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_eit_section))
  29. return NULL;
  30. struct atsc_eit_section *eit = (struct atsc_eit_section *) psip;
  31. pos += sizeof(struct atsc_eit_section);
  32. for(idx =0; idx < eit->num_events_in_section; idx++) {
  33. if (len < (pos + sizeof(struct atsc_eit_event)))
  34. return NULL;
  35. struct atsc_eit_event *event = (struct atsc_eit_event *) (buf+pos);
  36. bswap16(buf+pos);
  37. bswap32(buf+pos+2);
  38. bswap32(buf+pos+6);
  39. pos += sizeof(struct atsc_eit_event);
  40. if (len < (pos + event->title_length))
  41. return NULL;
  42. if (atsc_text_validate(buf+pos, event->title_length))
  43. return NULL;
  44. pos += event->title_length;
  45. if (len < (pos + sizeof(struct atsc_eit_event_part2)))
  46. return NULL;
  47. struct atsc_eit_event_part2 *part2 = (struct atsc_eit_event_part2 *) (buf+pos);
  48. bswap16(buf+pos);
  49. pos += sizeof(struct atsc_eit_event_part2);
  50. if (len < (pos + part2->descriptors_length))
  51. return NULL;
  52. if (verify_descriptors(buf + pos, part2->descriptors_length))
  53. return NULL;
  54. pos += part2->descriptors_length;
  55. }
  56. if (pos != len)
  57. return NULL;
  58. return (struct atsc_eit_section *) psip;
  59. }