complete addition of descriptor types

This commit is contained in:
hummypkg 2011-06-02 15:21:56 +00:00 committed by HummyPkg
parent edbc4aedea
commit bec117e601
5 changed files with 113 additions and 11 deletions

View File

@ -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;
}
}

View File

@ -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;
};

1
lint.h
View File

@ -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 *);

13
main.c
View File

@ -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);

13
util.c
View File

@ -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;
}