From bec117e6019b9fbb4b02f8f0328971db55f1a19c Mon Sep 17 00:00:00 2001 From: hummypkg Date: Thu, 2 Jun 2011 15:21:56 +0000 Subject: [PATCH] complete addition of descriptor types --- descriptor.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++--- descriptor.h | 23 ++++++++++++++-- lint.h | 1 + main.c | 13 +++++---- util.c | 13 ++++++++- 5 files changed, 113 insertions(+), 11 deletions(-) diff --git a/descriptor.c b/descriptor.c index 54d3d39..a854f62 100644 --- a/descriptor.c +++ b/descriptor.c @@ -31,8 +31,6 @@ string_to_end(struct epg *epg, struct descriptor *d, int sofar, int rest = d->len - sofar; char *str; -printf("string_to_end(%d, %d, %d)\n", d->len, sofar, rest); - *len = rest; if (rest <= 0) @@ -75,8 +73,47 @@ read_descriptor(struct epg *epg, struct descriptor *d) &d->content.d80.textlen); break; + case DS_USER_DEFINED: + d->content.d137.textlen = epg->bin[epg->offset++]; + d->content.d137.text = read_string_len(epg->bin + epg->offset, + d->content.d137.textlen); + epg->offset += d->content.d137.textlen; + + memcpy(d->content.d137.lang, epg->bin + epg->offset, 3); + epg->offset += 3; + d->content.d137.warning = string_to_end(epg, d, + 4 + d->content.d137.textlen, + &d->content.d137.warninglen); + break; + + case DS_CONTENT_IDENTIFIER: + memcpy(&d->content.d118, epg->bin + epg->offset, 1); + epg->offset++; + d->content.d118.cridlen = d->content.d118.ref = 0; + switch (d->content.d118.location) + { + case 0: + d->content.d118.cridlen = epg->bin[epg->offset++]; + d->content.d118.crid = read_string_len( + epg->bin + epg->offset, d->content.d118.cridlen); + epg->offset += d->content.d118.cridlen; + break; + + case 1: + d->content.d118.ref = + _swap16((uint16_t)epg->bin[epg->offset]); + /* Not safe to use post increment in macro */ + epg->offset++; + break; + default: + printf("Unknown CRID location - %d\n", + d->content.d118.location); + } + break; + default: - epg->offset += d->len; + d->content.unknown.text = string_to_end(epg, d, 0, + &d->content.unknown.textlen); break; } } @@ -102,7 +139,19 @@ free_descriptor(struct descriptor *d) if (d->content.d80.text) free(d->content.d80.text); break; + case DS_USER_DEFINED: + if (d->content.d137.text) + free(d->content.d137.text); + if (d->content.d137.warning) + free(d->content.d137.warning); + break; + case DS_CONTENT_IDENTIFIER: + if (d->content.d118.crid) + free(d->content.d118.crid); + break; default: + if (d->content.unknown.text) + free(d->content.unknown.text); break; } } @@ -158,7 +207,26 @@ dump_descriptor(struct descriptor *d, int content) DUMPHEX(d, content.d80.text, d->content.d80.textlen); break; + case DS_USER_DEFINED: + DUMPINT(d, content.d137.textlen); + DUMPNSTR(d, content.d137.lang, 3); + DUMPHEX(d, content.d137.text, d->content.d137.textlen); + DUMPHEX(d, content.d137.warning, d->content.d137.warninglen); + break; + + case DS_CONTENT_IDENTIFIER: + DUMPINT(d, content.d118.location); + DUMPINT(d, content.d118.type); + DUMPINT(d, content.d118.cridlen); + if (d->content.d118.cridlen) + DUMPHEX(d, content.d118.crid, d->content.d118.cridlen); + DUMPINT(d, content.d118.ref); + break; + default: + if (d->content.unknown.textlen) + DUMPHEX(d, content.unknown.text, + d->content.unknown.textlen); break; } } diff --git a/descriptor.h b/descriptor.h index bcdd429..79d56b1 100644 --- a/descriptor.h +++ b/descriptor.h @@ -17,7 +17,7 @@ struct descriptor { unsigned int textlen:8; char *name; char *text; - } d77; + } d77; /* SHORT_EVENT */ struct { unsigned int stream_content:4; unsigned int reserved:4; @@ -26,7 +26,26 @@ struct descriptor { char lang[3]; char *text; unsigned int textlen; - } d80; + } d80; /* COMPONENT */ + struct { + unsigned int textlen:8; + char *text; + char lang[3]; + char *warning; + unsigned int warninglen; + } d137; /* USER_DEFINED - content warnings? */ + struct { + unsigned int location:2; + unsigned int type:6; + unsigned int cridlen:8; + char *crid; + unsigned int ref:16; + } d118; /* CONTENT_IDENTIFIER */ + struct { + char *text; + unsigned int textlen; + } unknown; /* 74, 84, 95, 126, ... */ + } content; }; diff --git a/lint.h b/lint.h index c15097b..749e096 100644 --- a/lint.h +++ b/lint.h @@ -27,4 +27,5 @@ struct descriptor *read_descriptor_header(struct epg *); void read_descriptor(struct epg *, struct descriptor *); void skip_descriptor(struct epg *, struct descriptor *); void dump_descriptor(struct descriptor *, int); +void free_descriptor(struct descriptor *); diff --git a/main.c b/main.c index 28035ff..28557db 100644 --- a/main.c +++ b/main.c @@ -38,6 +38,7 @@ main(int argc, char **argv) { struct section *h; struct epg *epg; + int i = 0; if (!(epg = open_file("../epg.dat"))) return 0; @@ -48,7 +49,7 @@ main(int argc, char **argv) if (!(h = read_section(epg))) break; - dump_section(h); + //dump_section(h); send = epg->offset - 11 + h->u1.u.length - 4; @@ -59,7 +60,7 @@ main(int argc, char **argv) if (!(d = read_data(epg))) break; - dump_data(d); + //dump_data(d); dend = epg->offset + d->u1.u.descriptors_loop_length; while (epg->offset < dend) @@ -68,7 +69,11 @@ main(int argc, char **argv) ds = read_descriptor_header(epg); read_descriptor(epg, ds); - dump_descriptor(ds, 1); + + if (ds->tag == DS_CONTENT_IDENTIFIER) + dump_descriptor(ds, 1); + + free_descriptor(ds); } } @@ -78,8 +83,6 @@ main(int argc, char **argv) /* Skip padding bytes... */ while (epg->bin[epg->offset] == 'U') epg->offset++; - - break; } close_file(epg); diff --git a/util.c b/util.c index b512ca3..3852d6b 100644 --- a/util.c +++ b/util.c @@ -101,15 +101,17 @@ char * hexstr(uint8_t *s, uint32_t len) { static char buf[0x1000]; + static char buf2[0x1000]; uint16_t off; if (!s) - return; + return ""; if (!len) len = strlen((char *)s); memset(buf, '\0', sizeof(buf)); + memset(buf2, '\0', sizeof(buf)); for (off = 0; off < len; off += 16) { uint32_t i; @@ -117,9 +119,18 @@ hexstr(uint8_t *s, uint32_t len) for (i = off; i - off < 16; i++) { if (i < len) + { sprintf(buf + i * 3, "%02x ", s[i] & 0xff); + if (isprint(s[i] & 0xff)) + buf2[i] = s[i]; + else + buf2[i] = '.'; + } } } + strcat(buf, " ("); + strcat(buf, buf2); + strcat(buf, ")"); return buf; }