redbutton-devel Mailing List for RedButton MHEG Engine (Page 9)
Brought to you by:
skilvington
You can subscribe to this list here.
| 2006 |
Jan
(1) |
Feb
(4) |
Mar
(27) |
Apr
(6) |
May
(46) |
Jun
(45) |
Jul
(7) |
Aug
(4) |
Sep
(7) |
Oct
(5) |
Nov
(10) |
Dec
(11) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2007 |
Jan
(49) |
Feb
(29) |
Mar
(35) |
Apr
(43) |
May
(23) |
Jun
(4) |
Jul
(1) |
Aug
(58) |
Sep
(66) |
Oct
(27) |
Nov
(15) |
Dec
(1) |
| 2008 |
Jan
(11) |
Feb
|
Mar
(8) |
Apr
|
May
|
Jun
(30) |
Jul
(1) |
Aug
(1) |
Sep
(1) |
Oct
|
Nov
(3) |
Dec
(6) |
| 2009 |
Jan
(6) |
Feb
(1) |
Mar
(2) |
Apr
(5) |
May
(2) |
Jun
(1) |
Jul
(7) |
Aug
|
Sep
(2) |
Oct
(2) |
Nov
|
Dec
(6) |
| 2010 |
Jan
(6) |
Feb
|
Mar
(4) |
Apr
|
May
|
Jun
|
Jul
|
Aug
(6) |
Sep
(4) |
Oct
|
Nov
(11) |
Dec
(4) |
| 2011 |
Jan
|
Feb
(11) |
Mar
(8) |
Apr
|
May
|
Jun
(3) |
Jul
|
Aug
|
Sep
(4) |
Oct
|
Nov
(2) |
Dec
|
| 2012 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: <ski...@us...> - 2007-10-15 08:50:55
|
Revision: 436
http://redbutton.svn.sourceforge.net/redbutton/?rev=436&view=rev
Author: skilvington
Date: 2007-10-15 01:50:51 -0700 (Mon, 15 Oct 2007)
Log Message:
-----------
initial import of mhegd (opposite of mhegc) not finished yet
Modified Paths:
--------------
redbutton-author/trunk/Makefile
redbutton-author/trunk/asn1tag.h
redbutton-author/trunk/ccc.y
Added Paths:
-----------
redbutton-author/trunk/der_decode.c
redbutton-author/trunk/der_decode.h
redbutton-author/trunk/mhegd.c
Modified: redbutton-author/trunk/Makefile
===================================================================
--- redbutton-author/trunk/Makefile 2007-10-15 08:49:09 UTC (rev 435)
+++ redbutton-author/trunk/Makefile 2007-10-15 08:50:51 UTC (rev 436)
@@ -4,6 +4,8 @@
# for vasprintf
DEFS=-D_GNU_SOURCE
+LIBS=
+
LEX=flex
YACC=bison
#LEX=lex
@@ -11,18 +13,29 @@
DESTDIR=/usr/local
-OBJS= mhegc.o \
- lex.parser.o \
- parser.o \
- der_encode.o \
- asn1tag.o \
- utils.o
+MHEGC_OBJS= mhegc.o \
+ lex.parser.o \
+ parser.o \
+ der_encode.o \
+ asn1tag.o \
+ utils.o
+MHEGD_OBJS= mhegd.o \
+ asn1decode.o \
+ der_decode.o \
+ asn1tag.o \
+ utils.o
+
TARDIR=`basename ${PWD}`
-mhegc: parser.h ${OBJS}
- ${CC} ${CFLAGS} ${DEFS} -o mhegc ${OBJS} ${LIBS}
+all: mhegc mhegd
+mhegc: parser.h ${MHEGC_OBJS}
+ ${CC} ${CFLAGS} ${DEFS} -o mhegc ${MHEGC_OBJS} ${LIBS}
+
+mhegd: asn1decode.h ${MHEGD_OBJS}
+ ${CC} ${CFLAGS} ${DEFS} -o mhegd ${MHEGD_OBJS} ${LIBS}
+
ccc: ccc.y ccc.l asn1type.o
${LEX} -i -t ccc.l > lex.ccc.c
${YACC} -b ccc -d ccc.y
@@ -32,17 +45,21 @@
cat grammar | ./ccc -l parser.l -p parser.c -h parser.h -t tokens.h
${LEX} -i -t parser.l > lex.parser.c
+asn1decode.c asn1decode.h: asn1decode.c.* asn1decode.h.* grammar asn1tag.h ccc
+ cat grammar | ./ccc -d asn1decode.c -e asn1decode.h
+
.c.o:
${CC} ${CFLAGS} ${DEFS} -c $<
berdecode: berdecode.c
${CC} ${CFLAGS} ${DEFS} -o berdecode berdecode.c
-install: mhegc
+install: mhegc mhegd
install -m 755 mhegc ${DESTDIR}/bin
+ install -m 755 mhegd ${DESTDIR}/bin
clean:
- rm -f mhegc ccc lex.ccc.c ccc.tab.[ch] lex.parser.c parser.[lch] tokens.h *.o berdecode core
+ rm -f mhegc mhegd ccc lex.ccc.c ccc.tab.[ch] lex.parser.c parser.[lch] tokens.h asn1decode.[ch] *.o berdecode core
tar:
make clean
Modified: redbutton-author/trunk/asn1tag.h
===================================================================
--- redbutton-author/trunk/asn1tag.h 2007-10-15 08:49:09 UTC (rev 435)
+++ redbutton-author/trunk/asn1tag.h 2007-10-15 08:50:51 UTC (rev 436)
@@ -589,6 +589,8 @@
#define ASN1TAGCLASS_ENUMERATED ((ASN1CLASS_UNIVERSAL << 24) | ASN1TAG_ENUMERATED)
#define ASN1TAGCLASS_SEQUENCE ((ASN1CLASS_UNIVERSAL << 24) | ASN1TAG_SEQUENCE)
#define ASN1TAGCLASS_SET ((ASN1CLASS_UNIVERSAL << 24) | ASN1TAG_SET)
+/* alias */
+#define ASN1TAGCLASS_Null ASN1TAGCLASS_NULL
/* the ASN1 types in the grammar that are not CONTEXT class types */
#define ASN1TAGCLASS_JointIsoItuIdentifier ASN1TAGCLASS_INTEGER
Modified: redbutton-author/trunk/ccc.y
===================================================================
--- redbutton-author/trunk/ccc.y 2007-10-15 08:49:09 UTC (rev 435)
+++ redbutton-author/trunk/ccc.y 2007-10-15 08:50:51 UTC (rev 436)
@@ -58,6 +58,9 @@
struct buf parse_hdr; /* parse_Xxx() prototypes for the parser */
struct buf parse_enum_hdr; /* parse_Xxx() prototypes for enum values */
struct buf is_hdr; /* is_Xxx() prototypes for the parser */
+ struct buf decode_fns; /* asn1decode_Xxx() C functions for mhegd */
+ struct buf decode_is_fns; /* is_Xxx() C functions for mhegd */
+ struct buf decode_hdr; /* asn1decode_Xxx() prototypes for mhegd */
} state;
/* header for files we generate */
@@ -191,12 +194,14 @@
char *parser_name = NULL;
char *header_name = NULL;
char *tokens_name = NULL;
+ char *decode_name = NULL;
+ char *decode_hdr_name = NULL;
int arg;
struct str_list *t;
char header[PATH_MAX];
char footer[PATH_MAX];
- while((arg = getopt(argc, argv, "l:p:h:t:")) != EOF)
+ while((arg = getopt(argc, argv, "l:p:h:t:d:e:")) != EOF)
{
switch(arg)
{
@@ -216,6 +221,14 @@
tokens_name = optarg;
break;
+ case 'd':
+ decode_name = optarg;
+ break;
+
+ case 'e':
+ decode_hdr_name = optarg;
+ break;
+
default:
usage(prog_name);
break;
@@ -234,6 +247,9 @@
buf_init(&state.parse_hdr);
buf_init(&state.parse_enum_hdr);
buf_init(&state.is_hdr);
+ buf_init(&state.decode_fns);
+ buf_init(&state.decode_is_fns);
+ buf_init(&state.decode_hdr);
yyparse();
@@ -312,13 +328,46 @@
fclose(tokens_file);
}
+ /* output ASN1 decoder file */
+ if(decode_name != NULL)
+ {
+ FILE *decode_file = safe_fopen(decode_name, "w");
+ fprintf(decode_file, STANDARD_HEADER);
+ /* output the header if there is one */
+ snprintf(header, sizeof(header), "%s.header", decode_name);
+ file_append(decode_file, header);
+ /* output our stuff */
+ fprintf(decode_file, "%s", state.decode_fns.str);
+ fprintf(decode_file, "%s", state.decode_is_fns.str);
+ /* output the footer if there is one */
+ snprintf(footer, sizeof(footer), "%s.footer", decode_name);
+ file_append(decode_file, footer);
+ fclose(decode_file);
+ }
+
+ /* output ASN1 decoder header file */
+ if(decode_hdr_name != NULL)
+ {
+ FILE *decode_hdr_file = safe_fopen(decode_hdr_name, "w");
+ fprintf(decode_hdr_file, STANDARD_HEADER);
+ /* output the header if there is one */
+ snprintf(header, sizeof(header), "%s.header", decode_hdr_name);
+ file_append(decode_hdr_file, header);
+ /* output our stuff */
+ fprintf(decode_hdr_file, "%s", state.decode_hdr.str);
+ /* output the footer if there is one */
+ snprintf(footer, sizeof(footer), "%s.footer", decode_hdr_name);
+ file_append(decode_hdr_file, footer);
+ fclose(decode_hdr_file);
+ }
+
return EXIT_SUCCESS;
}
void
usage(char *prog_name)
{
- fprintf(stderr, "Syntax: %s [-l <lexer-file>] [-p <parser-c-file>] [-h <parser-h-file>] [-t <tokens-file>]\n", prog_name);
+ fprintf(stderr, "Syntax: %s [-l <lexer-file>] [-p <parser-c-file>] [-h <parser-h-file>] [-t <tokens-file>] [-d <decode-c-file>] [-e <decode-h-file>]\n", prog_name);
exit(EXIT_FAILURE);
}
@@ -371,6 +420,7 @@
struct item *next;
unsigned int nitems;
unsigned int enum_val;
+ bool first;
/* prototype for the parse_Xxx function */
buf_append(&state.parse_hdr, "void parse_%s(struct node *);\n", name);
@@ -727,6 +777,217 @@
}
buf_append(&state.is_fns, "}\n\n");
+ /* ASN1 decode prototypes */
+ buf_append(&state.decode_hdr, "int asn1decode_%s(FILE *, FILE *, int);\n", name);
+ buf_append(&state.decode_hdr, "bool is_%s(unsigned char, unsigned int);\n\n", name);
+
+ /* ASN1 decode_Xxx() functions */
+ buf_append(&state.decode_fns, "int asn1decode_%s(FILE *der, FILE *out, int length)\n{\n", name);
+ buf_append(&state.decode_fns, "\tint left = length;\n");
+ buf_append(&state.decode_fns, "\tint sublen;\n");
+ buf_append(&state.decode_fns, "\tstruct der_tag tag;\n\n");
+ buf_append(&state.decode_fns, "\tverbose(\"<%s>\\n\");\n\n", name);
+
+ /* ASN1 is_Xxx() functions */
+ buf_append(&state.decode_is_fns, "bool is_%s(unsigned char class, unsigned int number)\n{\n", name);
+
+ /* count how many non-literal items there are */
+ nitems = 0;
+ for(item=state.items; item; item=item->next)
+ if(item->type != IT_LITERAL)
+ nitems ++;
+
+ /* is it the special case */
+ if(strcmp(name, "OctetString") == 0)
+ {
+ /* decode_Xxx() function */
+ buf_append(&state.decode_fns, "\tif((sublen = der_decode_Tag(der, &tag)) < 0)\n");
+ buf_append(&state.decode_fns, "\t\treturn der_error(\"%s\");\n", name);
+ buf_append(&state.decode_fns, "\tleft -= sublen;\n\n");
+ buf_append(&state.decode_fns, "\tif(is_%s(tag.class, tag.number))\n\t{\n", name);
+ buf_append(&state.decode_fns, "\t\tder_decode_%s(der, out, tag.length);\n", name);
+ buf_append(&state.decode_fns, "\t\tleft -= tag.length;\n");
+ buf_append(&state.decode_fns, "\t}\n\telse\n");
+ buf_append(&state.decode_fns, "\t{\n\t\treturn der_error(\"%s\");\n\t}\n\n", name);
+ /* is_Xxx() function */
+ buf_append(&state.decode_is_fns, "\treturn MATCH_TAGCLASS(class, number, ASN1TAGCLASS_OCTETSTRING);\n");
+ }
+ /* has it got only 1 non-literal item */
+ else if(nitems == 1)
+ {
+ /* output any literals at the start */
+ for(item=state.items; item && item->type==IT_LITERAL; item=item->next)
+ buf_append(&state.decode_fns, "\tfprintf(out, \"%%s \", %s);\n\n", item->name);
+ /* decode the item */
+ buf_append(&state.decode_fns, "\tif((sublen = der_decode_Tag(der, &tag)) < 0)\n");
+ buf_append(&state.decode_fns, "\t\treturn der_error(\"%s\");\n", name);
+ buf_append(&state.decode_fns, "\tleft -= sublen;\n\n");
+ buf_append(&state.decode_fns, "\tif(is_%s(tag.class, tag.number))\n\t{\n", item->name);
+ buf_append(&state.decode_fns, "\t\tasn1decode_%s(der, out, tag.length);\n", item->name);
+ buf_append(&state.decode_fns, "\t\tleft -= tag.length;\n");
+ buf_append(&state.decode_fns, "\t}\n\telse\n");
+ buf_append(&state.decode_fns, "\t{\n\t\treturn der_error(\"%s\");\n\t}\n\n", name);
+ /* is_Xxx() function */
+ buf_append(&state.decode_is_fns, "\treturn is_%s(class, number);\n", item->name);
+ /* output any literals at the end */
+ item = item->next;
+ while(item)
+ {
+ /* assert */
+ if(item->type != IT_LITERAL)
+ fatal("Trailing non-literal");
+ buf_append(&state.decode_fns, "\tfprintf(out, %s);\n\n", item->name);
+ item = item->next;
+ }
+ }
+ /* is it a SEQUENCE or SET */
+ else if(state.and_items)
+ {
+ /* output any literals at the start */
+ for(item=state.items; item && item->type==IT_LITERAL; item=item->next)
+ buf_append(&state.decode_fns, "\tfprintf(out, \"%%s \", %s);\n\n", item->name);
+ /* items must be in the order they are defined for SEQUENCE types */
+ switch(asn1type(name))
+ {
+ case ASN1TYPE_SEQUENCE:
+ /* assert */
+ if(item->type != IT_IDENTIFIER)
+ fatal("not Identifier");
+ /* is_Xxx() - just match the first item */
+ buf_append(&state.decode_is_fns, "\treturn is_%s(class, number);\n", item->name);
+ /* decode_Xxx() - examine each non-literal item in turn */
+ while(item && item->type != IT_LITERAL)
+ {
+/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
+ item = item->next;
+ }
+ break;
+
+ case ASN1TYPE_SET:
+ /* while there is data left in the current object */
+ buf_append(&state.decode_fns, "\twhile(left > 0)\n\t{\n");
+ /* decode the next tag */
+ buf_append(&state.decode_fns, "\t\tif((sublen = der_decode_Tag(der, &tag)) < 0)\n");
+ buf_append(&state.decode_fns, "\t\t\treturn der_error(\"%s\");\n", name);
+ buf_append(&state.decode_fns, "\t\tleft -= sublen;\n");
+ /* the non-literal items may appear in any order */
+ first = true;
+ while(item && item->type != IT_LITERAL)
+ {
+ /* is_Xxx() */
+ if(first)
+ buf_append(&state.decode_is_fns, "\treturn ");
+ else
+ buf_append(&state.decode_is_fns, "\t || ");
+ buf_append(&state.decode_is_fns, "is_%s(class, number)", item->name);
+ /* is it the last */
+ if(item->next == NULL || item->next->type == IT_LITERAL)
+ buf_append(&state.decode_is_fns, ";");
+ buf_append(&state.decode_is_fns, "\n");
+ /* decode_Xxx() */
+ if(first)
+ buf_append(&state.decode_fns, "\t\t");
+ else
+ buf_append(&state.decode_fns, "\t\telse ");
+ first = false;
+ buf_append(&state.decode_fns, "if(is_%s(tag.class, tag.number))\n\t\t{\n", item->name);
+ buf_append(&state.decode_fns, "\t\t\tasn1decode_%s(der, out, tag.length);\n", item->name);
+ buf_append(&state.decode_fns, "\t\t\tleft -= tag.length;\n");
+ buf_append(&state.decode_fns, "\t\t}\n");
+ item = item->next;
+ }
+ /* decode_Xxx() */
+ buf_append(&state.decode_fns, "\t\telse\n");
+ buf_append(&state.decode_fns, "\t\t{\n\t\t\treturn der_error(\"%s: unexpected tag [%%s %%u]\", asn1class_name(tag.class), tag.number);\n\t}\n", name);
+ buf_append(&state.decode_fns, "\t\t}\n\n");
+ break;
+
+ default:
+ /* assert */
+ fatal("and_items set but not a SEQUENCE or SET");
+ break;
+ }
+ /* output any literals at the end */
+ while(item)
+ {
+ /* assert */
+ if(item->type != IT_LITERAL)
+ fatal("Trailing non-literal");
+ buf_append(&state.decode_fns, "\tfprintf(out, %s);\n\n", item->name);
+ item = item->next;
+ }
+ }
+ /* is it ENUMERATED */
+ else if(asn1type(name) == ASN1TYPE_ENUMERATED)
+ {
+ /* an ENUMERATED type */
+ buf_append(&state.decode_fns, "\t/* ENUMERATED */\n");
+ buf_append(&state.decode_fns, "\tchar *enum_names[] = {\n");
+ enum_val = 0;
+ for(item=state.items; item; item=item->next)
+ {
+ buf_append(&state.decode_fns, "\t\t%s,\n", item->name);
+ enum_val ++;
+ }
+ buf_append(&state.decode_fns, "\t};\n\n");
+ buf_append(&state.decode_fns, "\tif((sublen = der_decode_Tag(der, &tag)) < 0)\n");
+ buf_append(&state.decode_fns, "\t\treturn der_error(\"%s\");\n", name);
+ buf_append(&state.decode_fns, "\tleft -= sublen;\n\n");
+ /* the ENUMERATED value is encoded as an INTEGER */
+ buf_append(&state.decode_fns, "\tif(is_%s(tag.class, tag.number))\n\t{\n", name);
+ buf_append(&state.decode_fns, "\t\tder_decode_ENUMERATED(der, out, tag.length, %u, enum_names);\n", enum_val);
+ buf_append(&state.decode_fns, "\t\tleft -= tag.length;\n");
+ buf_append(&state.decode_fns, "\t}\n\telse\n");
+ buf_append(&state.decode_fns, "\t{\n\t\treturn der_error(\"%s\");\n\t}\n\n", name);
+ /* is_Xxx() function */
+ buf_append(&state.decode_is_fns, "\treturn MATCH_TAGCLASS(class, number, ASN1TAGCLASS_ENUMERATED);\n");
+ }
+ /* must be a CHOICE */
+ else
+ {
+ /* a CHOICE type */
+ buf_append(&state.decode_fns, "\t/* CHOICE */\n");
+ buf_append(&state.decode_fns, "\tif((sublen = der_decode_Tag(der, &tag)) < 0)\n");
+ buf_append(&state.decode_fns, "\t\treturn der_error(\"%s\");\n", name);
+ buf_append(&state.decode_fns, "\tleft -= sublen;\n\n");
+ /* see which item we chose */
+ for(item=state.items; item; item=item->next)
+ {
+ /* is_Xxx() function */
+ if(item == state.items)
+ buf_append(&state.decode_is_fns, "\treturn ");
+ else
+ buf_append(&state.decode_is_fns, "\t || ");
+ buf_append(&state.decode_is_fns, "MATCH_TAGCLASS(class, number, ASN1TAGCLASS_%s)", item->name);
+ /* is it the last */
+ if(item->next == NULL)
+ buf_append(&state.decode_is_fns, ";");
+ buf_append(&state.decode_is_fns, "\n");
+ /* decode_Xxx() function */
+ if(item == state.items)
+ buf_append(&state.decode_fns, "\t");
+ else
+ buf_append(&state.decode_fns, "\telse ");
+ buf_append(&state.decode_fns, "if(MATCH_TAGCLASS(tag.class, tag.number, ASN1TAGCLASS_%s))\n\t{\n", item->name);
+ buf_append(&state.decode_fns, "\t\tif((sublen = asn1decode_%s(der, out, tag.length)) < 0)\n", item->name);
+ buf_append(&state.decode_fns, "\t\t\treturn der_error(\"%s\");\n", name);
+ buf_append(&state.decode_fns, "\t\tleft -= sublen;\n");
+ buf_append(&state.decode_fns, "\t}\n");
+ }
+ buf_append(&state.decode_fns, "\telse\n");
+ buf_append(&state.decode_fns, "\t{\n\t\treturn der_error(\"%s\");\n\t}\n\n", name);
+ }
+
+ /* end decode_Xxx() function */
+ buf_append(&state.decode_fns, "\tfprintf(out, \"\\n\");\n\n");
+ buf_append(&state.decode_fns, "\tif(left != 0)\n");
+ buf_append(&state.decode_fns, "\t\treturn der_error(\"%s: %%d bytes left\", left);\n\n", name);
+ buf_append(&state.decode_fns, "\tverbose(\"</%s>\\n\");\n\n", name);
+ buf_append(&state.decode_fns, "\treturn length;\n}\n\n");
+
+ /* end is_Xxx() function */
+ buf_append(&state.decode_is_fns, "}\n\n");
+
/* free the items */
item = state.items;
while(item)
@@ -850,6 +1111,9 @@
if((b->str = malloc(b->nalloced)) == NULL)
fatal("Out of memory");
+ /* in case it never gets any data put in it */
+ b->str[0] = '\0';
+
return;
}
Added: redbutton-author/trunk/der_decode.c
===================================================================
--- redbutton-author/trunk/der_decode.c (rev 0)
+++ redbutton-author/trunk/der_decode.c 2007-10-15 08:50:51 UTC (rev 436)
@@ -0,0 +1,240 @@
+/*
+ * der_decode.c
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <ctype.h>
+
+#include "der_decode.h"
+
+void verbose(char *, ...);
+char hexdigit(unsigned char);
+
+/* DER does not allow indefinite lengths */
+
+int
+der_decode_Tag(FILE *der, struct der_tag *tag)
+{
+ unsigned int type;
+ unsigned int len;
+ unsigned char byte;
+ unsigned int longtype;
+ int nlens;
+ int nbytes = 0;
+
+ /* type */
+ if(der_read_file(der, 1, &byte) != 1)
+ return der_error("DER tag");
+ nbytes ++;
+ type = byte;
+ longtype = 0;
+ if((type & 0x1f) == 0x1f)
+ {
+ /* multi byte type */
+ do
+ {
+ if(der_read_file(der, 1, &byte) != 1)
+ return der_error("DER tag");
+ nbytes ++;
+ longtype <<= 7;
+ longtype += byte & 0x7f;
+ }
+ while((byte & 0x80) != 0);
+ }
+ tag->class = type & 0xc0;
+ tag->number = ((type & 0x1f) == 0x1f) ? longtype : type & 0x1f;
+
+ /* length */
+ if(der_read_file(der, 1, &byte) != 1)
+ return der_error("DER tag");
+ nbytes ++;
+ len = byte;
+ if(len == 0 && type == 0)
+ {
+ return der_error("Found EOC; indefinite lengths not allowed in DER");
+ }
+ else if(len == 0x80)
+ {
+ return der_error("Indefinite lengths not allowed in DER");
+ }
+ else if((len & 0x80) == 0x80)
+ {
+ /* multibyte length field */
+ nlens = len & 0x7f;
+ len = 0;
+ while(nlens > 0)
+ {
+ if(der_read_file(der, 1, &byte) != 1)
+ return der_error("DER tag");
+ nbytes ++;
+ len <<= 8;
+ len += byte;
+ nlens --;
+ }
+ }
+ tag->length = len;
+
+ return nbytes;
+}
+
+int
+der_decode_BOOLEAN(FILE *der, FILE *out, int length)
+{
+ unsigned char val;
+
+ if(length != 1)
+ return der_error("Boolean: length=%d", length);
+
+ if(der_read_file(der, length, &val) < 0)
+ return der_error("Boolean");
+
+ verbose("<Boolean value=\"%s\"/>\n", val ? "true" : "false");
+
+ fprintf(out, "%s", val ? "true" : "false");
+
+ return length;
+}
+
+int
+der_decode_INTEGER(FILE *der, FILE *out, int length)
+{
+ int val = get_der_int(der, length);
+
+ verbose("<Integer value=\"%d\"/>\n", val);
+
+ fprintf(out, "%d", val);
+
+ return length;
+}
+
+/* DER does not allow constructed OCTET-STRINGs */
+
+int
+der_decode_OctetString(FILE *der, FILE *out, int length)
+{
+ int left = length;
+ unsigned char byte;
+
+ verbose("<OctetString size=\"%d\">\n", length);
+
+ fprintf(out, "'");
+ while(left > 0)
+ {
+ if(der_read_file(der, 1, &byte) < 0)
+ return der_error("OctetString");
+ if(byte != '\'' && byte >= 0x20 && byte < 0x7f)
+ fprintf(out, "%c", byte);
+ else
+ fprintf(out, "=%c%c", hexdigit((byte >> 4) & 0xf), hexdigit(byte & 0xf));
+ left --;
+ }
+ fprintf(out, "'");
+
+ verbose("</OctetString>\n");
+
+ return length;
+}
+
+int
+der_decode_Null(FILE *der, FILE *out, int length)
+{
+ if(length != 0)
+ return der_error("Null: length=%d", length);
+
+ verbose("<Null/>");
+
+ return length;
+}
+
+int
+der_decode_ENUMERATED(FILE *der, FILE *out, int length, unsigned int max, char *names[])
+{
+ int val = get_der_int(der, length);
+
+ if(val < 1 || val > max)
+ return der_error("Enumerated: %d; not in range 1-%d", val, max);
+
+ verbose("<Enumerated value=\"%d\"/>\n", val);
+
+ fprintf(out, "%s", names[val - 1]);
+
+ return length;
+}
+
+char
+hexdigit(unsigned char nibble)
+{
+ if(nibble < 10)
+ return '0' + nibble;
+ else if(nibble < 16)
+ return 'a' + nibble;
+ else
+ return '?';
+}
+
+int
+get_der_int(FILE *der, int length)
+{
+ unsigned char byte;
+ unsigned int uval;
+ int val;
+ bool negative;
+ int i;
+
+ if(length > sizeof(int))
+ fatal("Integer: length=%d", length);
+
+ /* is it -ve */
+ if(der_read_file(der, 1, &byte) < 0)
+ fatal("Integer: EOF");
+ negative = ((byte & 0x80) == 0x80);
+
+ /* big endian */
+ uval = byte;
+ for(i=1; i<length; i++)
+ {
+ if(der_read_file(der, 1, &byte) < 0)
+ fatal("Integer: EOF");
+ uval <<= 8;
+ uval += byte;
+ }
+
+ /* sign extend if negative */
+ if(negative)
+ {
+ /* byte order neutral */
+ for(i=length; i<sizeof(int); i++)
+ uval += (0xff << (i * 8));
+ }
+
+ val = (int) uval;
+
+ return val;
+}
+
+int
+der_read_file(FILE *in, unsigned int nbytes, void *buf)
+{
+ int nread;
+
+ if((nread = fread(buf, 1, nbytes, in)) != nbytes)
+ return der_error("Unexpected EOF");
+
+ return nread;
+}
+
+int
+der_error(char *fmt, ...)
+{
+ va_list args;
+
+ va_start(args, fmt);
+ vfprintf(stderr, fmt, args);
+ fprintf(stderr, "\n");
+ va_end(args);
+
+ return -1;
+}
+
Added: redbutton-author/trunk/der_decode.h
===================================================================
--- redbutton-author/trunk/der_decode.h (rev 0)
+++ redbutton-author/trunk/der_decode.h 2007-10-15 08:50:51 UTC (rev 436)
@@ -0,0 +1,47 @@
+/*
+ * der_decode.h
+ */
+
+#ifndef __DER_DECODE_H__
+#define __DER_DECODE_H__
+
+#include <stdio.h>
+#include <stdarg.h>
+
+#include "utils.h"
+
+#define der_alloc(N) safe_malloc(N)
+#define der_realloc(P, N) safe_realloc(P, N)
+#define der_free(P) safe_free(P)
+
+struct der_tag
+{
+ unsigned char class;
+ unsigned int number;
+ unsigned int length;
+};
+
+#define DER_CLASS_UNIVERSAL 0x00
+#define DER_CLASS_APPLICATION 0x40
+#define DER_CLASS_CONTEXT 0x80
+#define DER_CLASS_PRIVATE 0xc0
+
+/* top 8 bits are class, bottom 24 are the tag number */
+#define MATCH_TAGCLASS(CLASS, NUMBER, TAGCLASS) ((CLASS == ((TAGCLASS >> 24) & 0xff)) && (NUMBER == (TAGCLASS & 0xffffff)))
+
+int der_decode_Tag(FILE *, struct der_tag *);
+
+int der_decode_BOOLEAN(FILE *, FILE *, int);
+int der_decode_INTEGER(FILE *, FILE *, int);
+int der_decode_OctetString(FILE *, FILE *, int);
+int der_decode_Null(FILE *, FILE *, int);
+int der_decode_ENUMERATED(FILE *, FILE *, int, unsigned int, char **);
+
+int get_der_int(FILE *, int);
+
+int der_read_file(FILE *, unsigned int, void *);
+
+int der_error(char *, ...);
+
+#endif /* __DER_DECODE_H__ */
+
Added: redbutton-author/trunk/mhegd.c
===================================================================
--- redbutton-author/trunk/mhegd.c (rev 0)
+++ redbutton-author/trunk/mhegd.c 2007-10-15 08:50:51 UTC (rev 436)
@@ -0,0 +1,131 @@
+/*
+ * mhegd.c
+ */
+
+/*
+ * Copyright (C) 2007, Simon Kilvington
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <unistd.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#include "asn1decode.h"
+#include "der_decode.h"
+#include "utils.h"
+
+void verbose(const char *, ...);
+void vverbose(const char *, ...);
+
+void usage(char *);
+
+static int _verbose = 0;
+
+int
+main(int argc, char *argv[])
+{
+ char *prog_name = argv[0];
+ int arg;
+ FILE *in_file;
+ FILE *out_file = stdout;
+ int filesize;
+
+ while((arg = getopt(argc, argv, "o:v")) != EOF)
+ {
+ switch(arg)
+ {
+ case 'o':
+ if((out_file = fopen(optarg, "w")) == NULL)
+ fatal("Unable to write '%s': %s", optarg, strerror(errno));
+ break;
+
+ case 'v':
+ _verbose ++;
+ break;
+
+ default:
+ usage(prog_name);
+ break;
+ }
+ }
+
+ /* the single param is the name of a DER file */
+ if(optind != argc - 1)
+ usage(prog_name);
+
+ if((in_file = fopen(argv[optind], "r")) == NULL)
+ fatal("Unable to open '%s': %s", argv[optind], strerror(errno));
+
+ verbose("Reading '%s':\n", argv[optind]);
+
+ /* see how long the file is */
+ fseek(in_file, 0, SEEK_END);
+ filesize = (int) ftell(in_file);
+ rewind(in_file);
+
+ /* write text form of DER encoded in_file to out_file */
+ if(asn1decode_InterchangedObject(in_file, out_file, filesize) != filesize)
+ fatal("Unexpected data after InterchangedObject");
+
+ return EXIT_SUCCESS;
+}
+
+/*
+ * verbose functions send output to stderr so error messages get interleaved correctly
+ */
+
+void
+verbose(const char *fmt, ...)
+{
+ va_list ap;
+
+ if(_verbose)
+ {
+ va_start(ap, fmt);
+ vfprintf(stderr, fmt, ap);
+ va_end(ap);
+ }
+
+ return;
+}
+
+void
+vverbose(const char *fmt, ...)
+{
+ va_list ap;
+
+ if(_verbose > 1)
+ {
+ va_start(ap, fmt);
+ vfprintf(stderr, fmt, ap);
+ va_end(ap);
+ }
+
+ return;
+}
+
+void
+usage(char *prog_name)
+{
+ fprintf(stderr, "Usage: %s [-vv] [-o <output_file>] <input_file>\n", prog_name);
+
+ exit(EXIT_FAILURE);
+}
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ski...@us...> - 2007-10-15 08:49:13
|
Revision: 435
http://redbutton.svn.sourceforge.net/redbutton/?rev=435&view=rev
Author: skilvington
Date: 2007-10-15 01:49:09 -0700 (Mon, 15 Oct 2007)
Log Message:
-----------
this error obviously never happens
Modified Paths:
--------------
redbutton-browser/trunk/der_decode.c
Modified: redbutton-browser/trunk/der_decode.c
===================================================================
--- redbutton-browser/trunk/der_decode.c 2007-09-28 15:20:57 UTC (rev 434)
+++ redbutton-browser/trunk/der_decode.c 2007-10-15 08:49:09 UTC (rev 435)
@@ -134,7 +134,7 @@
int i;
if(length > sizeof(int))
- der_error("Integer: length=%d", length);
+ return der_error("Integer: length=%d", length);
/* is it -ve */
if(der_read_file(der, 1, &byte) < 0)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ski...@us...> - 2007-09-28 15:20:59
|
Revision: 434
http://redbutton.svn.sourceforge.net/redbutton/?rev=434&view=rev
Author: skilvington
Date: 2007-09-28 08:20:57 -0700 (Fri, 28 Sep 2007)
Log Message:
-----------
Tagged download release 20070928
Added Paths:
-----------
redbutton-download/tags/redbutton-download-20070928/
Copied: redbutton-download/tags/redbutton-download-20070928 (from rev 433, redbutton-download/trunk)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ski...@us...> - 2007-09-28 15:18:51
|
Revision: 433
http://redbutton.svn.sourceforge.net/redbutton/?rev=433&view=rev
Author: skilvington
Date: 2007-09-28 08:17:44 -0700 (Fri, 28 Sep 2007)
Log Message:
-----------
describe the -v flag
Modified Paths:
--------------
www/index.html
Modified: www/index.html
===================================================================
--- www/index.html 2007-09-28 14:53:06 UTC (rev 432)
+++ www/index.html 2007-09-28 15:17:44 UTC (rev 433)
@@ -228,6 +228,8 @@
Will convert the <input_file> (or stdin if no filename is given) from the MHEG text form into the ASN1 form.
The DER encoded ASN1 object will be stored in the given output file (or in a file named "a" if no -o option is given).
<P>
+The -v flag enables debug mode and will print details about the ASN1 object it creates. Use -vv for even more info.
+<P>
The redbutton-author package contains a "Hello World" example from
<a href="http://www.digvid.info/mheg5/hello_world.php">http://www.digvid.info/mheg5/hello_world.php</a>.
To compile the Hello World example, do this:
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ski...@us...> - 2007-09-28 14:53:24
|
Revision: 432
http://redbutton.svn.sourceforge.net/redbutton/?rev=432&view=rev
Author: skilvington
Date: 2007-09-28 07:53:06 -0700 (Fri, 28 Sep 2007)
Log Message:
-----------
describe mhegc on the web page
Modified Paths:
--------------
www/index.html
Modified: www/index.html
===================================================================
--- www/index.html 2007-09-28 14:40:24 UTC (rev 431)
+++ www/index.html 2007-09-28 14:53:06 UTC (rev 432)
@@ -13,7 +13,9 @@
Both rb-download and rb-browser can be run on the same host,
or rb-download can be run on a host with a DVB card and rb-browser can be run on a remote frontend without a DVB card.
<P>
-The source for both is released under the GPL and can be
+If you want to write your own MHEG applications, you can use the mhegc compiler to generate the ASN1 format files rb-browser expects.
+<P>
+The source is released under the GPL and can be
<A HREF="http://sourceforge.net/project/showfiles.php?group_id=158629">downloaded here.</A>
<P>
Just un-tar them and type 'make'.
@@ -218,6 +220,25 @@
<P>
If the Tiresias Screenfont is not available, rb-browser first tries to use the FreeSans font instead. If this is also not available, rb-browser uses whatever scalable font Xft returns for "sans".
Note that these fonts will have different metrics and so may not fit into the spaces in the MHEG apps designed for Tiresias.
+<H2>mhegc</H2>
+Usage:
+<PRE>
+mhegc [-vv] [-o <output_file>] [<input_file>]
+</PRE>
+Will convert the <input_file> (or stdin if no filename is given) from the MHEG text form into the ASN1 form.
+The DER encoded ASN1 object will be stored in the given output file (or in a file named "a" if no -o option is given).
+<P>
+The redbutton-author package contains a "Hello World" example from
+<a href="http://www.digvid.info/mheg5/hello_world.php">http://www.digvid.info/mheg5/hello_world.php</a>.
+To compile the Hello World example, do this:
+<PRE>
+mhegc -o helloworld/startup helloworld/startup.txt
+mhegc -o helloworld/hello.mhg helloworld/hello.mhg.txt
+</PRE>
+Then to run it:
+<PRE>
+rb-browser helloworld/
+</PRE>
<H2>Contact Details</H2>
I can be contacted here: s.kilvington at eris dot qinetiq com.
</BODY>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ski...@us...> - 2007-09-28 14:40:26
|
Revision: 431
http://redbutton.svn.sourceforge.net/redbutton/?rev=431&view=rev
Author: skilvington
Date: 2007-09-28 07:40:24 -0700 (Fri, 28 Sep 2007)
Log Message:
-----------
Tagged author release 20070928
Added Paths:
-----------
redbutton-author/tags/redbutton-author-20070928/
Copied: redbutton-author/tags/redbutton-author-20070928 (from rev 430, redbutton-author/trunk)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ski...@us...> - 2007-09-28 14:40:09
|
Revision: 430
http://redbutton.svn.sourceforge.net/redbutton/?rev=430&view=rev
Author: skilvington
Date: 2007-09-28 07:40:07 -0700 (Fri, 28 Sep 2007)
Log Message:
-----------
HOWTO use the compiler
Added Paths:
-----------
redbutton-author/trunk/HOWTO-helloworld
Added: redbutton-author/trunk/HOWTO-helloworld
===================================================================
--- redbutton-author/trunk/HOWTO-helloworld (rev 0)
+++ redbutton-author/trunk/HOWTO-helloworld 2007-09-28 14:40:07 UTC (rev 430)
@@ -0,0 +1,9 @@
+To compile the helloworld example:
+
+mhegc -o helloworld/startup helloworld/startup.txt
+mhegc -o helloworld/hello.mhg helloworld/hello.mhg.txt
+
+To run it:
+
+rb-browser helloworld/
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ski...@us...> - 2007-09-28 14:29:08
|
Revision: 429
http://redbutton.svn.sourceforge.net/redbutton/?rev=429&view=rev
Author: skilvington
Date: 2007-09-28 07:29:05 -0700 (Fri, 28 Sep 2007)
Log Message:
-----------
Tagged browser release 20070928
Added Paths:
-----------
redbutton-browser/tags/redbutton-browser-20070928/
Copied: redbutton-browser/tags/redbutton-browser-20070928 (from rev 428, redbutton-browser/trunk)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ski...@us...> - 2007-09-28 12:44:16
|
Revision: 428
http://redbutton.svn.sourceforge.net/redbutton/?rev=428&view=rev
Author: skilvington
Date: 2007-09-28 05:44:10 -0700 (Fri, 28 Sep 2007)
Log Message:
-----------
berdecode is more useful here
Modified Paths:
--------------
redbutton-author/trunk/Makefile
redbutton-browser/trunk/Makefile
Added Paths:
-----------
redbutton-author/trunk/berdecode.c
Removed Paths:
-------------
redbutton-browser/trunk/berdecode.c
Modified: redbutton-author/trunk/Makefile
===================================================================
--- redbutton-author/trunk/Makefile 2007-09-27 13:23:43 UTC (rev 427)
+++ redbutton-author/trunk/Makefile 2007-09-28 12:44:10 UTC (rev 428)
@@ -35,11 +35,14 @@
.c.o:
${CC} ${CFLAGS} ${DEFS} -c $<
+berdecode: berdecode.c
+ ${CC} ${CFLAGS} ${DEFS} -o berdecode berdecode.c
+
install: mhegc
install -m 755 mhegc ${DESTDIR}/bin
clean:
- rm -f mhegc ccc lex.ccc.c ccc.tab.[ch] lex.parser.c parser.[lch] tokens.h *.o core
+ rm -f mhegc ccc lex.ccc.c ccc.tab.[ch] lex.parser.c parser.[lch] tokens.h *.o berdecode core
tar:
make clean
Copied: redbutton-author/trunk/berdecode.c (from rev 321, redbutton-browser/trunk/berdecode.c)
===================================================================
--- redbutton-author/trunk/berdecode.c (rev 0)
+++ redbutton-author/trunk/berdecode.c 2007-09-28 12:44:10 UTC (rev 428)
@@ -0,0 +1,414 @@
+/*
+ * berdecode [<filename>]
+ *
+ * not a proper decoder, just a quick hack
+ * if no filename is given, read from stdin
+ *
+ * Simon Kilvington, 2/10/2005
+ */
+
+#include <stdio.h>
+#include <stdarg.h>
+#include <string.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <errno.h>
+
+/* how we know when we have got to the end of a BER type */
+#define WANT_EOF -2 /* continue until End-Of-File */
+#define WANT_EOC -1 /* continue until End-Of-Contents octets (00,00) */
+/* 0 or +ve values are the number of bytes until the end of the type */
+
+/* global buffer to read file contents into */
+static char buf[64 * 1024];
+
+int print_next(FILE *, int, int);
+void print_indent(int);
+void print_boolean(FILE *);
+void print_integer(FILE *, unsigned int);
+void print_oid(FILE *, unsigned int);
+
+unsigned int read_file(FILE *, unsigned int, void *);
+
+unsigned int type_number(unsigned int, unsigned int);
+char *universal_typename(unsigned int);
+void hexdump(unsigned char *, size_t);
+
+void usage(char *);
+void fatal(char *, ...);
+
+int
+main(int argc, char *argv[])
+{
+ FILE *in = NULL;
+ int filelen;
+
+ if(argc == 1)
+ {
+ in = stdin;
+ }
+ else if(argc == 2)
+ {
+ if((in = fopen(argv[1], "r")) == NULL)
+ fatal("Unable to open file '%s': %s", argv[1], strerror(errno));
+ }
+ else
+ {
+ usage(argv[0]);
+ }
+
+ filelen = print_next(in, 0, WANT_EOF);
+
+ printf("file length=%d\n", filelen);
+
+ return EXIT_SUCCESS;
+}
+
+int
+print_next(FILE *in, int indent, int wanted)
+{
+ unsigned int type;
+ unsigned int len;
+ unsigned char byte;
+ unsigned int longtype;
+ int nlens;
+ int nbytes = 0;
+
+ do
+ {
+ /* type */
+ nbytes += read_file(in, 1, &byte);
+ type = byte;
+ longtype = 0;
+ if((type & 0x1f) == 0x1f)
+ {
+ /* multi byte type */
+ do
+ {
+ nbytes += read_file(in, 1, &byte);
+ longtype <<= 7;
+ longtype += byte & 0x7f;
+ }
+ while((byte & 0x80) != 0);
+ }
+ if(type != 0)
+ print_indent(indent);
+ switch(type & 0xc0)
+ {
+ case 0x00:
+ //printf("UNIVERSAL");
+ if(type != 0)
+ printf("%s", universal_typename(type));
+ break;
+
+ case 0x40:
+ printf("[APPLICATION %u]", type_number(type, longtype));
+ break;
+
+ case 0x80:
+ printf("[CONTEXT %u]", type_number(type, longtype));
+ break;
+
+ case 0xc0:
+ printf("[PRIVATE %u]", type_number(type, longtype));
+ break;
+ }
+
+ /* length */
+ nbytes += read_file(in, 1, &byte);
+ len = byte;
+ if(len == 0 && type == 0)
+ {
+ /* check we want EOC */
+ if(wanted != WANT_EOC)
+ fatal("Unexpected End-Of-Contents");
+ return nbytes;
+ }
+ else if(len == 0x80)
+ {
+ /* indefinite length */
+ len = WANT_EOC;
+ }
+ else if((len & 0x80) == 0x80)
+ {
+ /* multibyte length field */
+ nlens = len & 0x7f;
+ len = 0;
+ while(nlens > 0)
+ {
+ nbytes += read_file(in, 1, &byte);
+ len <<= 8;
+ len += byte;
+ nlens --;
+ }
+ }
+ if(type == 0 && len != 0)
+ fatal("type=0x%x (%u) len=0x%x (%u)", type, type, len, len);
+
+ /* value */
+ if((type & 0x20) == 0x20)
+ {
+ /* constructed */
+ printf(" {\n");
+ len = print_next(in, indent+1, len);
+ print_indent(indent);
+ printf("}\n");
+ }
+ else if(len == 0)
+ {
+ printf(" value=default\n");
+ }
+ else if(len > 0)
+ {
+ if(len > sizeof(buf))
+ fatal("Value too long (%u)", len);
+ /* BOOLEAN */
+ if(type == 1 && len == 1)
+ print_boolean(in);
+ /* INTEGER */
+ else if(type == 2 && len <= sizeof(int))
+ print_integer(in, len);
+ /* OBJECT IDENTIFIER */
+ else if(type == 6)
+ print_oid(in, len);
+ /* ENUMERATED */
+ else if(type == 10 && len <= sizeof(int))
+ print_integer(in, len);
+ /* default: hexdump the contents */
+ else if(type != 0)
+ {
+ (void) read_file(in, len, buf);
+ printf(" value=(%u bytes):\n", len);
+ hexdump(buf, len);
+ }
+ }
+
+ if(len > 0)
+ nbytes += len;
+
+ if(wanted >= 0 && nbytes > wanted)
+ fatal("Unexpected EOF");
+ }
+ while(nbytes != wanted && !feof(in));
+
+ return nbytes;
+}
+
+void
+print_indent(int indent)
+{
+ indent *= 2;
+
+ for(; indent>0; indent--)
+ printf(" ");
+
+ return;
+}
+
+void
+print_boolean(FILE *in)
+{
+ unsigned char val;
+
+ read_file(in, 1, &val);
+ printf(" value=%s (%u)\n", (val == 0) ? "false" : "true", val);
+
+ return;
+}
+
+void
+print_integer(FILE *in, unsigned int len)
+{
+ int integer;
+ unsigned char byte;
+ unsigned int uval;
+ int negative;
+ int i;
+
+ /* is it -ve */
+ read_file(in, 1, &byte);
+ negative = ((byte & 0x80) == 0x80);
+
+ /* big endian */
+ uval = byte;
+ for(i=1; i<len; i++)
+ {
+ read_file(in, 1, &byte);
+ uval <<= 8;
+ uval += byte;
+ }
+
+ /* sign extend if negative */
+ if(negative)
+ {
+ /* byte order neutral */
+ for(i=len; i<sizeof(int); i++)
+ uval += (0xff << (i * 8));
+ }
+
+ integer = (int) uval;
+
+ printf(" value=%d\n", integer);
+
+ return;
+}
+
+void
+print_oid(FILE *in, unsigned int len)
+{
+ int oid;
+ int oid1, oid2;
+ int i;
+
+ read_file(in, len, buf);
+
+ if((buf[0] & 0x80) == 0x80)
+ fatal("OID with top-bit set");
+ oid1 = buf[0] / 40;
+ oid2 = buf[0] % 40;
+ printf(" value=%u.%u", oid1, oid2);
+
+ i = 1;
+ while(i < len)
+ {
+ if((buf[i] & 0x80) == 0)
+ {
+ oid = buf[i];
+ i ++;
+ }
+ else
+ {
+ oid = 0;
+ while(((buf[i] & 0x80) == 0x80) && i < len)
+ {
+ oid <<= 7;
+ oid += buf[i] & 0x7f;
+ i ++;
+ }
+ oid <<= 7;
+ oid += buf[i];
+ i ++;
+ }
+ printf(".%d", oid);
+ }
+ printf("\n");
+
+ return;
+}
+
+
+unsigned int
+read_file(FILE *in, unsigned int nbytes, void *buf)
+{
+ if(fread(buf, 1, nbytes, in) != nbytes)
+ fatal("EOF");
+
+ return nbytes;
+}
+
+unsigned int
+type_number(unsigned int type, unsigned int longtype)
+{
+ return ((type & 0x1f) == 0x1f) ? longtype : type & 0x1f;
+}
+
+char *
+universal_typename(unsigned int type)
+{
+ type &= 0x1f;
+
+ if(type == 1) return "BOOLEAN";
+ else if(type == 2) return "INTEGER";
+ else if(type == 3) return "BIT-STRING";
+ else if(type == 4) return "OCTET-STRING";
+ else if(type == 5) return "NULL";
+ else if(type == 6) return "OBJECT-IDENTIFIER";
+ else if(type == 7) return "ObjectDescriptor";
+ else if(type == 8) return "EXTERNAL";
+ else if(type == 9) return "REAL";
+ else if(type == 10) return "ENUMERATED";
+ else if(type == 11) return "EMBEDDED-PDV";
+ else if(type == 12) return "UTF8String";
+ else if(type == 16) return "SEQUENCE";
+ else if(type == 17) return "SET";
+ else if(type == 18) return "NumericString";
+ else if(type == 19) return "PrintableString";
+ else if(type == 20) return "T61String";
+ else if(type == 21) return "VideotexString";
+ else if(type == 22) return "IA5String";
+ else if(type == 23) return "UTCTime";
+ else if(type == 24) return "GeneralizedTime";
+ else if(type == 25) return "GraphicString";
+ else if(type == 26) return "VisibleString";
+ else if(type == 27) return "GeneralString";
+ else if(type == 28) return "UniversalString";
+ else if(type == 30) return "BMPString";
+
+ fatal("Unknown UNIVERSAL type %u", type);
+
+ return NULL;
+}
+
+/* number of bytes per line */
+#define HEXDUMP_WIDTH 16
+
+void
+hexdump(unsigned char *data, size_t nbytes)
+{
+ size_t nout;
+ int i;
+
+ nout = 0;
+ while(nout < nbytes)
+ {
+ /* byte offset at start of line */
+ if((nout % HEXDUMP_WIDTH) == 0)
+ printf("0x%.8x ", nout);
+ /* the byte value in hex */
+ printf("%.2x ", data[nout]);
+ /* the ascii equivalent at the end of the line */
+ if((nout % HEXDUMP_WIDTH) == (HEXDUMP_WIDTH - 1))
+ {
+ printf(" ");
+ for(i=HEXDUMP_WIDTH-1; i>=0; i--)
+ printf("%c", isprint(data[nout - i]) ? data[nout - i] : '.');
+ printf("\n");
+ }
+ nout ++;
+ }
+
+ /* the ascii equivalent if we haven't just done it */
+ if((nout % HEXDUMP_WIDTH) != 0)
+ {
+ /* pad to the start of the ascii equivalent */
+ for(i=(nout % HEXDUMP_WIDTH); i<HEXDUMP_WIDTH; i++)
+ printf(" ");
+ printf(" ");
+ /* print the ascii equivalent */
+ nout --;
+ for(i=(nout % HEXDUMP_WIDTH); i>=0; i--)
+ printf("%c", isprint(data[nout - i]) ? data[nout - i] : '.');
+ printf("\n");
+ }
+
+ return;
+}
+
+void
+usage(char *progname)
+{
+ fatal("Usage: %s [<file>]", progname);
+}
+
+void
+fatal(char *fmt, ...)
+{
+ va_list args;
+
+ va_start(args, fmt);
+ vfprintf(stdout, fmt, args);
+ fprintf(stdout, "\n");
+ va_end(args);
+
+ exit(EXIT_FAILURE);
+}
Modified: redbutton-browser/trunk/Makefile
===================================================================
--- redbutton-browser/trunk/Makefile 2007-09-27 13:23:43 UTC (rev 427)
+++ redbutton-browser/trunk/Makefile 2007-09-28 12:44:10 UTC (rev 428)
@@ -123,7 +123,7 @@
install -m 755 rb-keymap ${DESTDIR}/bin
clean:
- rm -f rb-browser rb-keymap xsd2c dertest dertest-mheg.[ch] berdecode *.o ISO13522-MHEG-5.[ch] clone.[ch] rtti.h gmon.out core
+ rm -f rb-browser rb-keymap xsd2c dertest dertest-mheg.[ch] *.o ISO13522-MHEG-5.[ch] clone.[ch] rtti.h gmon.out core
TARDIR=`basename ${PWD}`
Deleted: redbutton-browser/trunk/berdecode.c
===================================================================
--- redbutton-browser/trunk/berdecode.c 2007-09-27 13:23:43 UTC (rev 427)
+++ redbutton-browser/trunk/berdecode.c 2007-09-28 12:44:10 UTC (rev 428)
@@ -1,414 +0,0 @@
-/*
- * berdecode [<filename>]
- *
- * not a proper decoder, just a quick hack
- * if no filename is given, read from stdin
- *
- * Simon Kilvington, 2/10/2005
- */
-
-#include <stdio.h>
-#include <stdarg.h>
-#include <string.h>
-#include <stdlib.h>
-#include <ctype.h>
-#include <errno.h>
-
-/* how we know when we have got to the end of a BER type */
-#define WANT_EOF -2 /* continue until End-Of-File */
-#define WANT_EOC -1 /* continue until End-Of-Contents octets (00,00) */
-/* 0 or +ve values are the number of bytes until the end of the type */
-
-/* global buffer to read file contents into */
-static char buf[64 * 1024];
-
-int print_next(FILE *, int, int);
-void print_indent(int);
-void print_boolean(FILE *);
-void print_integer(FILE *, unsigned int);
-void print_oid(FILE *, unsigned int);
-
-unsigned int read_file(FILE *, unsigned int, void *);
-
-unsigned int type_number(unsigned int, unsigned int);
-char *universal_typename(unsigned int);
-void hexdump(unsigned char *, size_t);
-
-void usage(char *);
-void fatal(char *, ...);
-
-int
-main(int argc, char *argv[])
-{
- FILE *in = NULL;
- int filelen;
-
- if(argc == 1)
- {
- in = stdin;
- }
- else if(argc == 2)
- {
- if((in = fopen(argv[1], "r")) == NULL)
- fatal("Unable to open file '%s': %s", argv[1], strerror(errno));
- }
- else
- {
- usage(argv[0]);
- }
-
- filelen = print_next(in, 0, WANT_EOF);
-
- printf("file length=%d\n", filelen);
-
- return EXIT_SUCCESS;
-}
-
-int
-print_next(FILE *in, int indent, int wanted)
-{
- unsigned int type;
- unsigned int len;
- unsigned char byte;
- unsigned int longtype;
- int nlens;
- int nbytes = 0;
-
- do
- {
- /* type */
- nbytes += read_file(in, 1, &byte);
- type = byte;
- longtype = 0;
- if((type & 0x1f) == 0x1f)
- {
- /* multi byte type */
- do
- {
- nbytes += read_file(in, 1, &byte);
- longtype <<= 7;
- longtype += byte & 0x7f;
- }
- while((byte & 0x80) != 0);
- }
- if(type != 0)
- print_indent(indent);
- switch(type & 0xc0)
- {
- case 0x00:
- //printf("UNIVERSAL");
- if(type != 0)
- printf("%s", universal_typename(type));
- break;
-
- case 0x40:
- printf("[APPLICATION %u]", type_number(type, longtype));
- break;
-
- case 0x80:
- printf("[CONTEXT %u]", type_number(type, longtype));
- break;
-
- case 0xc0:
- printf("[PRIVATE %u]", type_number(type, longtype));
- break;
- }
-
- /* length */
- nbytes += read_file(in, 1, &byte);
- len = byte;
- if(len == 0 && type == 0)
- {
- /* check we want EOC */
- if(wanted != WANT_EOC)
- fatal("Unexpected End-Of-Contents");
- return nbytes;
- }
- else if(len == 0x80)
- {
- /* indefinite length */
- len = WANT_EOC;
- }
- else if((len & 0x80) == 0x80)
- {
- /* multibyte length field */
- nlens = len & 0x7f;
- len = 0;
- while(nlens > 0)
- {
- nbytes += read_file(in, 1, &byte);
- len <<= 8;
- len += byte;
- nlens --;
- }
- }
- if(type == 0 && len != 0)
- fatal("type=0x%x (%u) len=0x%x (%u)", type, type, len, len);
-
- /* value */
- if((type & 0x20) == 0x20)
- {
- /* constructed */
- printf(" {\n");
- len = print_next(in, indent+1, len);
- print_indent(indent);
- printf("}\n");
- }
- else if(len == 0)
- {
- printf(" value=default\n");
- }
- else if(len > 0)
- {
- if(len > sizeof(buf))
- fatal("Value too long (%u)", len);
- /* BOOLEAN */
- if(type == 1 && len == 1)
- print_boolean(in);
- /* INTEGER */
- else if(type == 2 && len <= sizeof(int))
- print_integer(in, len);
- /* OBJECT IDENTIFIER */
- else if(type == 6)
- print_oid(in, len);
- /* ENUMERATED */
- else if(type == 10 && len <= sizeof(int))
- print_integer(in, len);
- /* default: hexdump the contents */
- else if(type != 0)
- {
- (void) read_file(in, len, buf);
- printf(" value=(%u bytes):\n", len);
- hexdump(buf, len);
- }
- }
-
- if(len > 0)
- nbytes += len;
-
- if(wanted >= 0 && nbytes > wanted)
- fatal("Unexpected EOF");
- }
- while(nbytes != wanted && !feof(in));
-
- return nbytes;
-}
-
-void
-print_indent(int indent)
-{
- indent *= 2;
-
- for(; indent>0; indent--)
- printf(" ");
-
- return;
-}
-
-void
-print_boolean(FILE *in)
-{
- unsigned char val;
-
- read_file(in, 1, &val);
- printf(" value=%s (%u)\n", (val == 0) ? "false" : "true", val);
-
- return;
-}
-
-void
-print_integer(FILE *in, unsigned int len)
-{
- int integer;
- unsigned char byte;
- unsigned int uval;
- int negative;
- int i;
-
- /* is it -ve */
- read_file(in, 1, &byte);
- negative = ((byte & 0x80) == 0x80);
-
- /* big endian */
- uval = byte;
- for(i=1; i<len; i++)
- {
- read_file(in, 1, &byte);
- uval <<= 8;
- uval += byte;
- }
-
- /* sign extend if negative */
- if(negative)
- {
- /* byte order neutral */
- for(i=len; i<sizeof(int); i++)
- uval += (0xff << (i * 8));
- }
-
- integer = (int) uval;
-
- printf(" value=%d\n", integer);
-
- return;
-}
-
-void
-print_oid(FILE *in, unsigned int len)
-{
- int oid;
- int oid1, oid2;
- int i;
-
- read_file(in, len, buf);
-
- if((buf[0] & 0x80) == 0x80)
- fatal("OID with top-bit set");
- oid1 = buf[0] / 40;
- oid2 = buf[0] % 40;
- printf(" value=%u.%u", oid1, oid2);
-
- i = 1;
- while(i < len)
- {
- if((buf[i] & 0x80) == 0)
- {
- oid = buf[i];
- i ++;
- }
- else
- {
- oid = 0;
- while(((buf[i] & 0x80) == 0x80) && i < len)
- {
- oid <<= 7;
- oid += buf[i] & 0x7f;
- i ++;
- }
- oid <<= 7;
- oid += buf[i];
- i ++;
- }
- printf(".%d", oid);
- }
- printf("\n");
-
- return;
-}
-
-
-unsigned int
-read_file(FILE *in, unsigned int nbytes, void *buf)
-{
- if(fread(buf, 1, nbytes, in) != nbytes)
- fatal("EOF");
-
- return nbytes;
-}
-
-unsigned int
-type_number(unsigned int type, unsigned int longtype)
-{
- return ((type & 0x1f) == 0x1f) ? longtype : type & 0x1f;
-}
-
-char *
-universal_typename(unsigned int type)
-{
- type &= 0x1f;
-
- if(type == 1) return "BOOLEAN";
- else if(type == 2) return "INTEGER";
- else if(type == 3) return "BIT-STRING";
- else if(type == 4) return "OCTET-STRING";
- else if(type == 5) return "NULL";
- else if(type == 6) return "OBJECT-IDENTIFIER";
- else if(type == 7) return "ObjectDescriptor";
- else if(type == 8) return "EXTERNAL";
- else if(type == 9) return "REAL";
- else if(type == 10) return "ENUMERATED";
- else if(type == 11) return "EMBEDDED-PDV";
- else if(type == 12) return "UTF8String";
- else if(type == 16) return "SEQUENCE";
- else if(type == 17) return "SET";
- else if(type == 18) return "NumericString";
- else if(type == 19) return "PrintableString";
- else if(type == 20) return "T61String";
- else if(type == 21) return "VideotexString";
- else if(type == 22) return "IA5String";
- else if(type == 23) return "UTCTime";
- else if(type == 24) return "GeneralizedTime";
- else if(type == 25) return "GraphicString";
- else if(type == 26) return "VisibleString";
- else if(type == 27) return "GeneralString";
- else if(type == 28) return "UniversalString";
- else if(type == 30) return "BMPString";
-
- fatal("Unknown UNIVERSAL type %u", type);
-
- return NULL;
-}
-
-/* number of bytes per line */
-#define HEXDUMP_WIDTH 16
-
-void
-hexdump(unsigned char *data, size_t nbytes)
-{
- size_t nout;
- int i;
-
- nout = 0;
- while(nout < nbytes)
- {
- /* byte offset at start of line */
- if((nout % HEXDUMP_WIDTH) == 0)
- printf("0x%.8x ", nout);
- /* the byte value in hex */
- printf("%.2x ", data[nout]);
- /* the ascii equivalent at the end of the line */
- if((nout % HEXDUMP_WIDTH) == (HEXDUMP_WIDTH - 1))
- {
- printf(" ");
- for(i=HEXDUMP_WIDTH-1; i>=0; i--)
- printf("%c", isprint(data[nout - i]) ? data[nout - i] : '.');
- printf("\n");
- }
- nout ++;
- }
-
- /* the ascii equivalent if we haven't just done it */
- if((nout % HEXDUMP_WIDTH) != 0)
- {
- /* pad to the start of the ascii equivalent */
- for(i=(nout % HEXDUMP_WIDTH); i<HEXDUMP_WIDTH; i++)
- printf(" ");
- printf(" ");
- /* print the ascii equivalent */
- nout --;
- for(i=(nout % HEXDUMP_WIDTH); i>=0; i--)
- printf("%c", isprint(data[nout - i]) ? data[nout - i] : '.');
- printf("\n");
- }
-
- return;
-}
-
-void
-usage(char *progname)
-{
- fatal("Usage: %s [<file>]", progname);
-}
-
-void
-fatal(char *fmt, ...)
-{
- va_list args;
-
- va_start(args, fmt);
- vfprintf(stdout, fmt, args);
- fprintf(stdout, "\n");
- va_end(args);
-
- exit(EXIT_FAILURE);
-}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ski...@us...> - 2007-09-27 13:23:48
|
Revision: 427
http://redbutton.svn.sourceforge.net/redbutton/?rev=427&view=rev
Author: skilvington
Date: 2007-09-27 06:23:43 -0700 (Thu, 27 Sep 2007)
Log Message:
-----------
ASN1 tags are unsigned
Modified Paths:
--------------
redbutton-author/trunk/mhegc.c
Modified: redbutton-author/trunk/mhegc.c
===================================================================
--- redbutton-author/trunk/mhegc.c 2007-09-26 16:33:48 UTC (rev 426)
+++ redbutton-author/trunk/mhegc.c 2007-09-27 13:23:43 UTC (rev 427)
@@ -148,7 +148,7 @@
if(show_node)
{
print_indent(indent);
- fprintf(stderr, "[%s %d]\n", asn1class_name(n->asn1class), n->asn1tag);
+ fprintf(stderr, "[%s %u]\n", asn1class_name(n->asn1class), n->asn1tag);
if(show_kids && n->children)
{
print_indent(indent);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ski...@us...> - 2007-09-26 16:34:00
|
Revision: 426
http://redbutton.svn.sourceforge.net/redbutton/?rev=426&view=rev
Author: skilvington
Date: 2007-09-26 09:33:48 -0700 (Wed, 26 Sep 2007)
Log Message:
-----------
done that
Modified Paths:
--------------
redbutton-author/trunk/TODO
Modified: redbutton-author/trunk/TODO
===================================================================
--- redbutton-author/trunk/TODO 2007-09-26 16:33:24 UTC (rev 425)
+++ redbutton-author/trunk/TODO 2007-09-26 16:33:48 UTC (rev 426)
@@ -3,9 +3,5 @@
---
-convert_BASE64() function
-
----
-
clean up ccc.y
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ski...@us...> - 2007-09-26 16:33:30
|
Revision: 425
http://redbutton.svn.sourceforge.net/redbutton/?rev=425&view=rev
Author: skilvington
Date: 2007-09-26 09:33:24 -0700 (Wed, 26 Sep 2007)
Log Message:
-----------
encode base64 octet strings
Modified Paths:
--------------
redbutton-author/trunk/der_encode.c
Modified: redbutton-author/trunk/der_encode.c
===================================================================
--- redbutton-author/trunk/der_encode.c 2007-09-25 11:59:39 UTC (rev 424)
+++ redbutton-author/trunk/der_encode.c 2007-09-26 16:33:24 UTC (rev 425)
@@ -256,14 +256,112 @@
return;
}
+/*
+ * enclosed in `
+ * base 64 encoded as described in RFC 1521
+ * line breaks in the input can be ignored
+ */
+
+unsigned char next_base64_char(unsigned char **);
+
void
convert_BASE64(unsigned char **out, unsigned int *len, const unsigned char *str)
{
-/* TODO */
-printf("TODO: convert_BASE64\n");
+ const unsigned char *whole_str = str;
+ unsigned char *p;
+ bool err;
+
+ /* max size it could be */
+ *out = safe_malloc(strlen(str));
+
+ /* skip the initial ` */
+ str ++;
+ p = *out;
+ err = false;
+ while(!err && *str != '`')
+ {
+ /* need 4 chars */
+ unsigned char v1 = next_base64_char((unsigned char **) &str);
+ unsigned char v2 = next_base64_char((unsigned char **) &str);
+ unsigned char v3 = next_base64_char((unsigned char **) &str);
+ unsigned char v4 = next_base64_char((unsigned char **) &str);
+ /* how many chars are valid */
+ if(v1 < 64 && v2 < 64 && v3 < 64 && v4 < 64)
+ {
+ /* 4 chars => 24 bits */
+ p[0] = (v1 << 2) | (v2 >> 4);
+ p[1] = (v2 << 4) | (v3 >> 2);
+ p[2] = (v3 << 6) | v4;
+ p += 3;
+ }
+ else if(v1 < 64 && v2 < 64 && v3 < 64 && v4 == 64)
+ {
+ /* 3 chars => 16 bits */
+ p[0] = (v1 << 2) | (v2 >> 4);
+ p[1] = (v2 << 4) | (v3 >> 2);
+ p += 2;
+ }
+ else if(v1 < 64 && v2 < 64 && v3 == 64 && v4 == 64)
+ {
+ /* 2 chars => 8 bits */
+ p[0] = (v1 << 2) | (v2 >> 4);
+ p += 1;
+ }
+ else
+ {
+ parse_error("Invalid BASE64 string: %s", whole_str);
+ err = true;
+ }
+ }
+
+ /* check we got to the closing quote */
+ if(!err && *(str + 1) != '\0')
+ {
+ parse_error("Unexpected ` in BASE64: %s", whole_str);
+ err = true;
+ }
+
+ if(!err)
+ {
+ /* return the length (note: no \0 terminator) */
+ *len = (p - *out);
+ }
+ else
+ {
+ /* clean up */
+ safe_free(*out);
+ *out = NULL;
+ *len = 0;
+ }
+
+ return;
}
/*
+ * updates *in
+ */
+
+unsigned char
+next_base64_char(unsigned char **in)
+{
+ /* would be faster with a 256 byte lookup table */
+ unsigned char *alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
+ unsigned char *pos;
+ unsigned char out;
+
+ while(**in != '`')
+ {
+ out = **in;
+ (*in) ++;
+ if((pos = strchr(alphabet, out)) != NULL)
+ return (pos - alphabet);
+ }
+
+ /* EOF, return (strchr(alphabet, '=') - alphabet) */
+ return 64;
+}
+
+/*
* recursively generate the DER tag/length header for the tree of nodes
*/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ski...@us...> - 2007-09-25 11:59:43
|
Revision: 424
http://redbutton.svn.sourceforge.net/redbutton/?rev=424&view=rev
Author: skilvington
Date: 2007-09-25 04:59:39 -0700 (Tue, 25 Sep 2007)
Log Message:
-----------
report line number if STRINGs or QPRINTABLEs are invalid
Modified Paths:
--------------
redbutton-author/trunk/TODO
redbutton-author/trunk/der_encode.c
Modified: redbutton-author/trunk/TODO
===================================================================
--- redbutton-author/trunk/TODO 2007-09-24 18:35:05 UTC (rev 423)
+++ redbutton-author/trunk/TODO 2007-09-25 11:59:39 UTC (rev 424)
@@ -7,9 +7,5 @@
---
-change fatal()'s to parse_error()'s in convert_STRING() et al.
-
----
-
clean up ccc.y
Modified: redbutton-author/trunk/der_encode.c
===================================================================
--- redbutton-author/trunk/der_encode.c 2007-09-24 18:35:05 UTC (rev 423)
+++ redbutton-author/trunk/der_encode.c 2007-09-25 11:59:39 UTC (rev 424)
@@ -127,6 +127,7 @@
{
const unsigned char *whole_str = str;
unsigned char *p;
+ bool err;
/* max size it could be */
*out = safe_malloc(strlen(str));
@@ -134,11 +135,13 @@
/* skip the initial " */
str ++;
p = *out;
- while(*str != '"')
+ err = false;
+ while(!err && *str != '"')
{
if(*str < 0x20 || *str > 0x7e)
{
- fatal("Invalid character (0x%02x) in STRING: %s", *str, whole_str);
+ parse_error("Invalid character (0x%02x) in STRING: %s", *str, whole_str);
+ err = true;
}
else if(*str != '\\')
{
@@ -160,17 +163,30 @@
}
else
{
- /* TODO: show the line number */
- fatal("Invalid escape sequence in STRING: %s", whole_str);
+ parse_error("Invalid escape sequence in STRING: %s", whole_str);
+ err = true;
}
}
/* check we got to the closing quote */
- if(*(str + 1) != '\0')
- fatal("Unquoted \" in STRING: %s", whole_str);
+ if(!err && *(str + 1) != '\0')
+ {
+ parse_error("Unquoted \" in STRING: %s", whole_str);
+ err = true;
+ }
- /* return the length (note: no \0 terminator) */
- *len = (p - *out);
+ if(!err)
+ {
+ /* return the length (note: no \0 terminator) */
+ *len = (p - *out);
+ }
+ else
+ {
+ /* clean up */
+ safe_free(*out);
+ *out = NULL;
+ *len = 0;
+ }
return;
}
@@ -187,6 +203,7 @@
{
const unsigned char *whole_str = str;
unsigned char *p;
+ bool err;
/* max size it could be */
*out = safe_malloc(strlen(str));
@@ -194,7 +211,8 @@
/* skip the initial ' */
str ++;
p = *out;
- while(*str != '\'')
+ err = false;
+ while(!err && *str != '\'')
{
if(*str != '=')
{
@@ -210,17 +228,30 @@
}
else
{
- /* TODO: show the line number */
- fatal("Invalid escape sequence in QPRINTABLE: %s", whole_str);
+ parse_error("Invalid escape sequence in QPRINTABLE: %s", whole_str);
+ err = true;
}
}
/* check we got to the closing quote */
- if(*(str + 1) != '\0')
- fatal("Unquoted ' in QPRINTABLE: %s", whole_str);
+ if(!err && *(str + 1) != '\0')
+ {
+ parse_error("Unquoted ' in QPRINTABLE: %s", whole_str);
+ err = true;
+ }
- /* return the length (note: no \0 terminator) */
- *len = (p - *out);
+ if(!err)
+ {
+ /* return the length (note: no \0 terminator) */
+ *len = (p - *out);
+ }
+ else
+ {
+ /* clean up */
+ safe_free(*out);
+ *out = NULL;
+ *len = 0;
+ }
return;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ski...@us...> - 2007-09-24 18:36:02
|
Revision: 423
http://redbutton.svn.sourceforge.net/redbutton/?rev=423&view=rev
Author: skilvington
Date: 2007-09-24 11:35:05 -0700 (Mon, 24 Sep 2007)
Log Message:
-----------
don't print synthetic nodes in the DER dump in -vv mode
Modified Paths:
--------------
redbutton-author/trunk/mhegc.c
Modified: redbutton-author/trunk/mhegc.c
===================================================================
--- redbutton-author/trunk/mhegc.c 2007-09-24 16:29:26 UTC (rev 422)
+++ redbutton-author/trunk/mhegc.c 2007-09-24 18:35:05 UTC (rev 423)
@@ -184,23 +184,32 @@
print_indent(indent);
fprintf(stderr, "[%s %u]\n", asn1class_name(n->asn1class), n->asn1tag);
hexdump(stderr, n->hdr_value, n->hdr_length);
+ if(has_real_children(n))
+ {
+ print_indent(indent);
+ fprintf(stderr, "{\n");
+ indent ++;
+ }
}
/* and our value */
- if(has_real_children(n))
+ if(n->children)
{
- print_indent(indent);
- fprintf(stderr, "{\n");
for(kid=n->children; kid; kid=kid->siblings)
- print_der(kid, indent + 1);
- print_indent(indent);
- fprintf(stderr, "}\n");
+ print_der(kid, indent);
}
else
{
hexdump(stderr, n->value, n->length);
}
+ if(!is_synthetic(n->asn1tag) && has_real_children(n))
+ {
+ indent --;
+ print_indent(indent);
+ fprintf(stderr, "}\n");
+ }
+
return;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ski...@us...> - 2007-09-24 16:29:30
|
Revision: 422
http://redbutton.svn.sourceforge.net/redbutton/?rev=422&view=rev
Author: skilvington
Date: 2007-09-24 09:29:26 -0700 (Mon, 24 Sep 2007)
Log Message:
-----------
fix NewReferencedContent Null issue. In theory the compiler is now fully working.
Modified Paths:
--------------
redbutton-author/trunk/TODO
redbutton-author/trunk/ccc.y
redbutton-author/trunk/parser.c.header
redbutton-author/trunk/parser.h.header
Modified: redbutton-author/trunk/TODO
===================================================================
--- redbutton-author/trunk/TODO 2007-09-24 16:15:46 UTC (rev 421)
+++ redbutton-author/trunk/TODO 2007-09-24 16:29:26 UTC (rev 422)
@@ -1,7 +1,3 @@
-NewReferencedContent Null is in the wrong place
-
----
-
output filename should default to App/Scene GroupIdentifier rather than "a"
(but warn if file exists - stops accidental overwrite of source!)
Modified: redbutton-author/trunk/ccc.y
===================================================================
--- redbutton-author/trunk/ccc.y 2007-09-24 16:15:46 UTC (rev 421)
+++ redbutton-author/trunk/ccc.y 2007-09-24 16:29:26 UTC (rev 422)
@@ -597,7 +597,7 @@
else if(item->type == IT_IDENTORNULL)
{
buf_append(&state.parse_fns, "\telse\n");
- buf_append(&state.parse_fns, "\t\t(void) add_child(parent, ASN1TAGCLASS_NULL);\n");
+ buf_append(&state.parse_fns, "\t\tadd_null_child(parent, ASN1TAGCLASS_%s);\n", item->name);
}
/* else { optional - don't care if it is not present } */
}
Modified: redbutton-author/trunk/parser.c.header
===================================================================
--- redbutton-author/trunk/parser.c.header 2007-09-24 16:15:46 UTC (rev 421)
+++ redbutton-author/trunk/parser.c.header 2007-09-24 16:29:26 UTC (rev 422)
@@ -93,6 +93,20 @@
}
/*
+ * add this child and add a Null below it
+ */
+
+void
+add_null_child(struct node *parent, uint32_t asn1tagclass)
+{
+ parent = add_child(parent, asn1tagclass);
+
+ (void) add_child(parent, ASN1TAGCLASS_NULL);
+
+ return;
+}
+
+/*
* return true if any of the node's descendants are not synthetic
*/
Modified: redbutton-author/trunk/parser.h.header
===================================================================
--- redbutton-author/trunk/parser.h.header 2007-09-24 16:15:46 UTC (rev 421)
+++ redbutton-author/trunk/parser.h.header 2007-09-24 16:29:26 UTC (rev 422)
@@ -46,6 +46,9 @@
/* add a child to a node */
struct node *add_child(struct node *, uint32_t);
+/* add a Null ASN1 object child to a node */
+void add_null_child(struct node *, uint32_t);
+
/* return true if any of the node's descendants are not synthetic */
bool has_real_children(struct node *);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ski...@us...> - 2007-09-24 16:15:51
|
Revision: 421
http://redbutton.svn.sourceforge.net/redbutton/?rev=421&view=rev
Author: skilvington
Date: 2007-09-24 09:15:46 -0700 (Mon, 24 Sep 2007)
Log Message:
-----------
fix ConnectionTag Null issue
Modified Paths:
--------------
redbutton-author/trunk/TODO
redbutton-author/trunk/ccc.l
redbutton-author/trunk/ccc.y
redbutton-author/trunk/grammar
Modified: redbutton-author/trunk/TODO
===================================================================
--- redbutton-author/trunk/TODO 2007-09-24 16:03:05 UTC (rev 420)
+++ redbutton-author/trunk/TODO 2007-09-24 16:15:46 UTC (rev 421)
@@ -1,14 +1,5 @@
-NewContentSize param in NewReferencedContent should compile to:
-[CONTEXT 234] { ... [UNIVERSAL 5] ... }
-not just [CONTEXT 234] { ... nothing ... }
-- ie need to add an explicit Null child node
+NewReferencedContent Null is in the wrong place
-same with ConnectionTag param in TransitionTo
-
-temp fix - add "Null" to the relevent 2 places in the grammar?
-real fix - add "Identifier?" to the grammar => optional, but adds a Null if not
- present (or perhaps "<Identifier>")
-
---
output filename should default to App/Scene GroupIdentifier rather than "a"
Modified: redbutton-author/trunk/ccc.l
===================================================================
--- redbutton-author/trunk/ccc.l 2007-09-24 16:03:05 UTC (rev 420)
+++ redbutton-author/trunk/ccc.l 2007-09-24 16:15:46 UTC (rev 421)
@@ -13,6 +13,7 @@
"[" return LBRACKET;
"]" return RBRACKET;
"+" return ONEORMORE;
+"?" return IDENTORNULL;
"." return ENDCLAUSE;
[\n\r\f] yylineno ++;
[ \t]+ /* ignore whitespace */
Modified: redbutton-author/trunk/ccc.y
===================================================================
--- redbutton-author/trunk/ccc.y 2007-09-24 16:03:05 UTC (rev 420)
+++ redbutton-author/trunk/ccc.y 2007-09-24 16:15:46 UTC (rev 421)
@@ -19,7 +19,8 @@
IT_LITERAL, /* "LiteralString" */
IT_IDENTIFIER, /* NormalIdentifier */
IT_OPTIONAL, /* [OptionalIdentifier] */
- IT_ONEORMORE /* OneOrMoreIdentifier+ */
+ IT_ONEORMORE, /* OneOrMoreIdentifier+ */
+ IT_IDENTORNULL /* IdentifierOrNull? */
};
struct item
@@ -109,6 +110,7 @@
%token LBRACKET
%token RBRACKET
%token ONEORMORE
+%token IDENTORNULL
%token ENDCLAUSE
%token INVALID
@@ -172,6 +174,11 @@
{
add_item(IT_ONEORMORE, $1);
}
+ |
+ IDENTIFIER IDENTORNULL
+ {
+ add_item(IT_IDENTORNULL, $1);
+ }
;
%%
@@ -565,8 +572,8 @@
for(item=state.items; item; item=item->next)
{
/* assert */
- if(item->type != IT_IDENTIFIER && item->type != IT_LITERAL && item->type != IT_OPTIONAL)
- fatal("SEQUENCE but not Identifier, Literal or Optional");
+ if(item->type == IT_ONEORMORE)
+ fatal("SEQUENCE contains OneOrMore+");
/* eat literals, parse [optional] identifiers */
buf_append(&state.parse_fns, "\n\t/* %s */\n", item->name);
if(item->type == IT_LITERAL)
@@ -580,11 +587,19 @@
buf_append(&state.parse_fns, "\tnext = peek_token();\n");
buf_append(&state.parse_fns, "\tif(is_%s(next))\n", item->name);
buf_append(&state.parse_fns, "\t\tparse_%s(parent);\n", item->name);
- if(item->type != IT_OPTIONAL)
+ /* not optional => generate an error if it is not present */
+ if(item->type == IT_IDENTIFIER)
{
buf_append(&state.parse_fns, "\telse\n");
buf_append(&state.parse_fns, "\t\tparse_error(\"Expecting %s\");\n", item->name);
}
+ /* not optional - if it is not present, add a Null instead */
+ else if(item->type == IT_IDENTORNULL)
+ {
+ buf_append(&state.parse_fns, "\telse\n");
+ buf_append(&state.parse_fns, "\t\t(void) add_child(parent, ASN1TAGCLASS_NULL);\n");
+ }
+ /* else { optional - don't care if it is not present } */
}
}
break;
Modified: redbutton-author/trunk/grammar
===================================================================
--- redbutton-author/trunk/grammar 2007-09-24 16:03:05 UTC (rev 420)
+++ redbutton-author/trunk/grammar 2007-09-24 16:15:46 UTC (rev 421)
@@ -729,7 +729,7 @@
ComparisonValue ")" .
Toggle ::= ":Toggle" "(" Target ")" .
ToggleItem ::= ":ToggleItem" "(" Target ItemIndex ")" .
-TransitionTo ::= ":TransitionTo" "(" Target [ConnectionTag]
+TransitionTo ::= ":TransitionTo" "(" Target ConnectionTag?
[TransitionEffect] ")" .
Unload ::= ":Unload" "(" Target ")" .
UnlockScreen ::= ":UnlockScreen" "(" Target ")" .
@@ -820,7 +820,7 @@
NewPaletteRef ::= GenericObjectReference .
NewPortion ::= GenericInteger .
NewReferencedContent ::= ":NewRefContent" "(" GenericContentReference
- [NewContentSize]
+ NewContentSize?
[NewContentCachePriority] ")" .
NewSliderValue ::= GenericInteger .
NewSpeed ::= Rational .
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ski...@us...> - 2007-09-24 16:03:20
|
Revision: 420
http://redbutton.svn.sourceforge.net/redbutton/?rev=420&view=rev
Author: skilvington
Date: 2007-09-24 09:03:05 -0700 (Mon, 24 Sep 2007)
Log Message:
-----------
output the DER file
Modified Paths:
--------------
redbutton-author/trunk/der_encode.c
redbutton-author/trunk/der_encode.h
redbutton-author/trunk/mhegc.c
redbutton-author/trunk/utils.c
redbutton-author/trunk/utils.h
Added Paths:
-----------
redbutton-author/trunk/TODO
Added: redbutton-author/trunk/TODO
===================================================================
--- redbutton-author/trunk/TODO (rev 0)
+++ redbutton-author/trunk/TODO 2007-09-24 16:03:05 UTC (rev 420)
@@ -0,0 +1,28 @@
+NewContentSize param in NewReferencedContent should compile to:
+[CONTEXT 234] { ... [UNIVERSAL 5] ... }
+not just [CONTEXT 234] { ... nothing ... }
+- ie need to add an explicit Null child node
+
+same with ConnectionTag param in TransitionTo
+
+temp fix - add "Null" to the relevent 2 places in the grammar?
+real fix - add "Identifier?" to the grammar => optional, but adds a Null if not
+ present (or perhaps "<Identifier>")
+
+---
+
+output filename should default to App/Scene GroupIdentifier rather than "a"
+(but warn if file exists - stops accidental overwrite of source!)
+
+---
+
+convert_BASE64() function
+
+---
+
+change fatal()'s to parse_error()'s in convert_STRING() et al.
+
+---
+
+clean up ccc.y
+
Modified: redbutton-author/trunk/der_encode.c
===================================================================
--- redbutton-author/trunk/der_encode.c 2007-09-24 12:47:39 UTC (rev 419)
+++ redbutton-author/trunk/der_encode.c 2007-09-24 16:03:05 UTC (rev 420)
@@ -274,7 +274,7 @@
* the big-endian tag value is encoded in the bottom 7-bits
*/
n->hdr_value[0] = n->asn1class;
- if(n->children)
+ if(has_real_children(n))
n->hdr_value[0] |= 0x20;
if(n->asn1tag < 31)
{
@@ -292,7 +292,7 @@
}
else if(n->asn1tag <= 0x3fff)
{
- n->hdr_value[1] = (n->asn1tag >> 7) & 0x7f;
+ n->hdr_value[1] = 0x80 | ((n->asn1tag >> 7) & 0x7f);
n->hdr_value[2] = n->asn1tag & 0x7f;
n->hdr_length = 3;
}
@@ -345,3 +345,26 @@
return n->hdr_length + val_length;
}
+void
+write_der_object(FILE *out, struct node *n)
+{
+ struct node *kid;
+
+ /* write our tag/length header */
+ if(!is_synthetic(n->asn1tag))
+ write_all(out, n->hdr_value, n->hdr_length);
+
+ /* and our value */
+ if(n->children)
+ {
+ for(kid=n->children; kid; kid=kid->siblings)
+ write_der_object(out, kid);
+ }
+ else
+ {
+ write_all(out, n->value, n->length);
+ }
+
+ return;
+}
+
Modified: redbutton-author/trunk/der_encode.h
===================================================================
--- redbutton-author/trunk/der_encode.h 2007-09-24 12:47:39 UTC (rev 419)
+++ redbutton-author/trunk/der_encode.h 2007-09-24 16:03:05 UTC (rev 420)
@@ -43,5 +43,7 @@
unsigned int gen_der_header(struct node *);
+void write_der_object(FILE *, struct node *);
+
#endif /* __DER_ENCODE_H__ */
Modified: redbutton-author/trunk/mhegc.c
===================================================================
--- redbutton-author/trunk/mhegc.c 2007-09-24 12:47:39 UTC (rev 419)
+++ redbutton-author/trunk/mhegc.c 2007-09-24 16:03:05 UTC (rev 420)
@@ -24,14 +24,20 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
+#include <string.h>
#include <strings.h>
+#include <errno.h>
#include "parser.h"
#include "der_encode.h"
#include "asn1tag.h"
#include "utils.h"
+/* default output name is 'a' */
+#define DEFAULT_OUT_NAME "a"
+
void print_node(struct node *, unsigned int);
+void print_der(struct node *, unsigned int);
void print_indent(unsigned int);
void usage(char *);
@@ -43,14 +49,20 @@
{
char *prog_name = argv[0];
int arg;
+ char *out_name = DEFAULT_OUT_NAME;
struct node asn1obj;
unsigned int nerrs;
unsigned int filesize;
+ FILE *out_file;
- while((arg = getopt(argc, argv, "v")) != EOF)
+ while((arg = getopt(argc, argv, "o:v")) != EOF)
{
switch(arg)
{
+ case 'o':
+ out_name = optarg;
+ break;
+
case 'v':
_verbose ++;
break;
@@ -100,6 +112,19 @@
filesize = gen_der_header(&asn1obj);
verbose("\nDER Object size: %u bytes\n", filesize);
+ /* write the output file */
+ if((out_file = fopen(out_name, "w")) == NULL)
+ fatal("Unable to open output file '%s': %s", out_name, strerror(errno));
+ verbose("Writing '%s'\n", out_name);
+ write_der_object(out_file, &asn1obj);
+ fclose(out_file);
+
+ if(_verbose > 1)
+ {
+ vverbose("\nDER file:\n");
+ print_der(&asn1obj, 0);
+ }
+
return EXIT_SUCCESS;
}
@@ -149,6 +174,37 @@
}
void
+print_der(struct node *n, unsigned int indent)
+{
+ struct node *kid;
+
+ /* write our tag/length header */
+ if(!is_synthetic(n->asn1tag))
+ {
+ print_indent(indent);
+ fprintf(stderr, "[%s %u]\n", asn1class_name(n->asn1class), n->asn1tag);
+ hexdump(stderr, n->hdr_value, n->hdr_length);
+ }
+
+ /* and our value */
+ if(has_real_children(n))
+ {
+ print_indent(indent);
+ fprintf(stderr, "{\n");
+ for(kid=n->children; kid; kid=kid->siblings)
+ print_der(kid, indent + 1);
+ print_indent(indent);
+ fprintf(stderr, "}\n");
+ }
+ else
+ {
+ hexdump(stderr, n->value, n->length);
+ }
+
+ return;
+}
+
+void
print_indent(unsigned int indent)
{
while(indent > 0)
@@ -193,7 +249,7 @@
void
usage(char *prog_name)
{
- fprintf(stderr, "Usage: %s [-vv] [<input_file>]\n", prog_name);
+ fprintf(stderr, "Usage: %s [-vv] [-o <output_file>] [<input_file>]\n", prog_name);
exit(EXIT_FAILURE);
}
Modified: redbutton-author/trunk/utils.c
===================================================================
--- redbutton-author/trunk/utils.c 2007-09-24 12:47:39 UTC (rev 419)
+++ redbutton-author/trunk/utils.c 2007-09-24 16:03:05 UTC (rev 420)
@@ -24,9 +24,20 @@
#include <stdlib.h>
#include <stdarg.h>
#include <ctype.h>
+#include <string.h>
+#include <errno.h>
#include "utils.h"
+void
+write_all(FILE *out, unsigned char *buf, size_t len)
+{
+ if(fwrite(buf, 1, len, out) != len)
+ fatal("Error writing to file: %s", strerror(errno));
+
+ return;
+}
+
/*
* returns 15 for 'f' etc
*/
Modified: redbutton-author/trunk/utils.h
===================================================================
--- redbutton-author/trunk/utils.h 2007-09-24 12:47:39 UTC (rev 419)
+++ redbutton-author/trunk/utils.h 2007-09-24 16:03:05 UTC (rev 420)
@@ -27,6 +27,8 @@
#include <stdarg.h>
#include <stdio.h>
+void write_all(FILE *, unsigned char *, size_t);
+
unsigned int char2hex(unsigned char);
void *safe_malloc(size_t);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ski...@us...> - 2007-09-24 12:47:40
|
Revision: 419
http://redbutton.svn.sourceforge.net/redbutton/?rev=419&view=rev
Author: skilvington
Date: 2007-09-24 05:47:39 -0700 (Mon, 24 Sep 2007)
Log Message:
-----------
generate the DER type/length header
Modified Paths:
--------------
redbutton-author/trunk/der_encode.c
redbutton-author/trunk/der_encode.h
Modified: redbutton-author/trunk/der_encode.c
===================================================================
--- redbutton-author/trunk/der_encode.c 2007-09-24 11:09:12 UTC (rev 418)
+++ redbutton-author/trunk/der_encode.c 2007-09-24 12:47:39 UTC (rev 419)
@@ -261,7 +261,85 @@
/* we don't need a header if we are a synthetic object */
if(!is_synthetic(n->asn1tag))
{
-printf("TODO: gen_der_header: tag=%u class=%s len=%u\n", n->asn1tag, asn1class_name(n->asn1class), val_length);
+ /* allocate more than we will need */
+ n->hdr_value = safe_malloc(MAX_DER_HDR_LENGTH);
+ /*
+ * first DER type byte is:
+ * AABCCCCC
+ * AA = ASN1 class (UNIVERSAL, CONTEXT, etc)
+ * B = 1 if it is a constructed type (ie has children)
+ * CCCCC = tag value (0-30)
+ * if the tag is set to 31, then:
+ * while the next byte has its top-bit set,
+ * the big-endian tag value is encoded in the bottom 7-bits
+ */
+ n->hdr_value[0] = n->asn1class;
+ if(n->children)
+ n->hdr_value[0] |= 0x20;
+ if(n->asn1tag < 31)
+ {
+ n->hdr_value[0] |= n->asn1tag;
+ n->hdr_length = 1;
+ }
+ else
+ {
+ n->hdr_value[0] |= 0x1f;
+ /* cheat - we know it is < 0x3fff (16383) */
+ if(n->asn1tag <= 0x7f)
+ {
+ n->hdr_value[1] = n->asn1tag & 0x7f;
+ n->hdr_length = 2;
+ }
+ else if(n->asn1tag <= 0x3fff)
+ {
+ n->hdr_value[1] = (n->asn1tag >> 7) & 0x7f;
+ n->hdr_value[2] = n->asn1tag & 0x7f;
+ n->hdr_length = 3;
+ }
+ else
+ {
+ /* assert */
+ fatal("gen_der_header: tag=%u class=%s", n->asn1tag, asn1class_name(n->asn1class));
+ }
+ }
+ /*
+ * if DER length is <128, then it is encoded as:
+ * 0LLLLLLL, where LLLLLLL is the 7-bit length
+ * if DER length is >=128, then it is encoded as:
+ * 1LLLLLLL, where LLLLLLL are the number of following bytes
+ * encoding the big-endian length
+ */
+ if(val_length < 128)
+ {
+ n->hdr_value[n->hdr_length] = val_length;
+ n->hdr_length ++;
+ }
+ else
+ {
+ unsigned int nlens = 1;
+ unsigned int len = val_length;
+ unsigned int i;
+ while(len > 255)
+ {
+ len >>= 8;
+ nlens ++;
+ }
+ /* assert */
+ if(n->hdr_length + nlens > MAX_DER_HDR_LENGTH)
+ fatal("gen_der_header: tag=%u class=%s nlens=%u", n->asn1tag, asn1class_name(n->asn1class), nlens);
+ n->hdr_value[n->hdr_length] = 0x80 | nlens;
+ n->hdr_length ++;
+ for(i=nlens; i>0; i--)
+ {
+ n->hdr_value[n->hdr_length] = (val_length >> ((i - 1) * 8)) & 0xff;
+ n->hdr_length ++;
+ }
+ }
+ /*
+ * this header is followed by the DER encoded value
+ * the value of constructed types is one or more DER types
+ * ie one or more DER header/value pairs
+ */
}
return n->hdr_length + val_length;
Modified: redbutton-author/trunk/der_encode.h
===================================================================
--- redbutton-author/trunk/der_encode.h 2007-09-24 11:09:12 UTC (rev 418)
+++ redbutton-author/trunk/der_encode.h 2007-09-24 12:47:39 UTC (rev 419)
@@ -27,6 +27,12 @@
#include <stdbool.h>
+/*
+ * max size a DER tag/length header could be
+ * (this is not the theoretical max, but it is big enough for us)
+ */
+#define MAX_DER_HDR_LENGTH 16
+
void der_encode_BOOLEAN(unsigned char **, unsigned int *, bool);
void der_encode_INTEGER(unsigned char **, unsigned int *, int);
void der_encode_OctetString(unsigned char **, unsigned int *, const unsigned char *);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ski...@us...> - 2007-09-24 11:09:27
|
Revision: 418
http://redbutton.svn.sourceforge.net/redbutton/?rev=418&view=rev
Author: skilvington
Date: 2007-09-24 04:09:12 -0700 (Mon, 24 Sep 2007)
Log Message:
-----------
keep RMS happy
Modified Paths:
--------------
redbutton-author/trunk/asn1tag.c
redbutton-author/trunk/asn1tag.h
redbutton-author/trunk/asn1type.c
redbutton-author/trunk/asn1type.h
redbutton-author/trunk/der_encode.c
redbutton-author/trunk/der_encode.h
redbutton-author/trunk/parser.c.header
redbutton-author/trunk/parser.h.header
redbutton-author/trunk/tokens.h.header
Added Paths:
-----------
redbutton-author/trunk/COPYING
Added: redbutton-author/trunk/COPYING
===================================================================
--- redbutton-author/trunk/COPYING (rev 0)
+++ redbutton-author/trunk/COPYING 2007-09-24 11:09:12 UTC (rev 418)
@@ -0,0 +1,340 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+ 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.) You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of Sections
+ 1 and 2 above on a medium customarily used for software interchange; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+ 5. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+ Gnomovision version 69, Copyright (C) year name of author
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+ <signature of Ty Coon>, 1 April 1989
+ Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs. If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library. If this is what you want to do, use the GNU Library General
+Public License instead of this License.
Modified: redbutton-author/trunk/asn1tag.c
===================================================================
--- redbutton-author/trunk/asn1tag.c 2007-09-23 20:45:27 UTC (rev 417)
+++ redbutton-author/trunk/asn1tag.c 2007-09-24 11:09:12 UTC (rev 418)
@@ -2,6 +2,24 @@
* asn1tag.c
*/
+/*
+ * Copyright (C) 2007, Simon Kilvington
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
#include "asn1tag.h"
char *
Modified: redbutton-author/trunk/asn1tag.h
===================================================================
--- redbutton-author/trunk/asn1tag.h 2007-09-23 20:45:27 UTC (rev 417)
+++ redbutton-author/trunk/asn1tag.h 2007-09-24 11:09:12 UTC (rev 418)
@@ -2,6 +2,24 @@
* asn1tag.h
*/
+/*
+ * Copyright (C) 2007, Simon Kilvington
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
#ifndef __ASN1TAG_H__
#define __ASN1TAG_H__
Modified: redbutton-author/trunk/asn1type.c
===================================================================
--- redbutton-author/trunk/asn1type.c 2007-09-23 20:45:27 UTC (rev 417)
+++ redbutton-author/trunk/asn1type.c 2007-09-24 11:09:12 UTC (rev 418)
@@ -2,6 +2,24 @@
* asn1type.c
*/
+/*
+ * Copyright (C) 2007, Simon Kilvington
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Modified: redbutton-author/trunk/asn1type.h
===================================================================
--- redbutton-author/trunk/asn1type.h 2007-09-23 20:45:27 UTC (rev 417)
+++ redbutton-author/trunk/asn1type.h 2007-09-24 11:09:12 UTC (rev 418)
@@ -2,6 +2,24 @@
* asn1type.h
*/
+/*
+ * Copyright (C) 2007, Simon Kilvington
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
#ifndef __ASN1TYPE_H__
#define __ASN1TYPE_H__
Modified: redbutton-author/trunk/der_encode.c
===================================================================
--- redbutton-author/trunk/der_encode.c 2007-09-23 20:45:27 UTC (rev 417)
+++ redbutton-author/trunk/der_encode.c 2007-09-24 11:09:12 UTC (rev 418)
@@ -2,6 +2,24 @@
* der_encode.c
*/
+/*
+ * Copyright (C) 2007, Simon Kilvington
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
#include <stdbool.h>
#include <string.h>
#include <ctype.h>
Modified: redbutton-author/trunk/der_encode.h
===================================================================
--- redbutton-author/trunk/der_encode.h 2007-09-23 20:45:27 UTC (rev 417)
+++ redbutton-author/trunk/der_encode.h 2007-09-24 11:09:12 UTC (rev 418)
@@ -2,6 +2,24 @@
* der_encode.h
*/
+/*
+ * Copyright (C) 2007, Simon Kilvington
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
#ifndef __DER_ENCODE_H__
#define __DER_ENCODE_H__
Modified: redbutton-author/trunk/parser.c.header
===================================================================
--- redbutton-author/trunk/parser.c.header 2007-09-23 20:45:27 UTC (rev 417)
+++ redbutton-author/trunk/parser.c.header 2007-09-24 11:09:12 UTC (rev 418)
@@ -1,3 +1,21 @@
+/*
+ * Copyright (C) 2007, Simon Kilvington
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
#include <stdio.h>
#include <string.h>
Modified: redbutton-author/trunk/parser.h.header
===================================================================
--- redbutton-author/trunk/parser.h.header 2007-09-23 20:45:27 UTC (rev 417)
+++ redbutton-author/trunk/parser.h.header 2007-09-24 11:09:12 UTC (rev 418)
@@ -1,3 +1,21 @@
+/*
+ * Copyright (C) 2007, Simon Kilvington
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
#ifndef __PARSER_H__
#define __PARSER_H__
Modified: redbutton-author/trunk/tokens.h.header
===================================================================
--- redbutton-author/trunk/tokens.h.header 2007-09-23 20:45:27 UTC (rev 417)
+++ redbutton-author/trunk/tokens.h.header 2007-09-24 11:09:12 UTC (rev 418)
@@ -1,3 +1,21 @@
+/*
+ * Copyright (C) 2007, Simon Kilvington
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
#define END_OF_SRC 0 /* must be 0 */
#define COMMENT 1
#define UNKNOWN_WORD 2
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ski...@us...> - 2007-09-23 20:45:30
|
Revision: 417
http://redbutton.svn.sourceforge.net/redbutton/?rev=417&view=rev
Author: skilvington
Date: 2007-09-23 13:45:27 -0700 (Sun, 23 Sep 2007)
Log Message:
-----------
definitely don't need this anymore
Modified Paths:
--------------
redbutton-author/trunk/ccc.y
Modified: redbutton-author/trunk/ccc.y
===================================================================
--- redbutton-author/trunk/ccc.y 2007-09-23 20:38:15 UTC (rev 416)
+++ redbutton-author/trunk/ccc.y 2007-09-23 20:45:27 UTC (rev 417)
@@ -462,8 +462,6 @@
/* add a child ASN1 object */
if(asn1type(name) == ASN1TYPE_CHOICE)
buf_append(&state.parse_fns, "\tparent = add_child(parent, ASN1TAG_CHOICE);\n\n");
-// else
-// buf_append(&state.parse_fns, "\tparent = add_child(parent, ASN1TAGCLASS_ENUMERATED);\n\n");
/* peek at the next token */
buf_append(&state.parse_fns, "\tnext = peek_token();\n\n");
buf_append(&state.parse_fns, "\t/* CHOICE or ENUMERATED */\n");
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ski...@us...> - 2007-09-23 20:38:16
|
Revision: 416
http://redbutton.svn.sourceforge.net/redbutton/?rev=416&view=rev
Author: skilvington
Date: 2007-09-23 13:38:15 -0700 (Sun, 23 Sep 2007)
Log Message:
-----------
spot misspelt {:tags
Modified Paths:
--------------
redbutton-author/trunk/parser.l.footer
Modified: redbutton-author/trunk/parser.l.footer
===================================================================
--- redbutton-author/trunk/parser.l.footer 2007-09-23 19:16:23 UTC (rev 415)
+++ redbutton-author/trunk/parser.l.footer 2007-09-23 20:38:15 UTC (rev 416)
@@ -1,4 +1,4 @@
-[a-z0-9:]+ return UNKNOWN_WORD;
+[{:a-z0-9]+ return UNKNOWN_WORD;
. return INVALID_CHAR;
%%
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ski...@us...> - 2007-09-23 19:16:36
|
Revision: 415
http://redbutton.svn.sourceforge.net/redbutton/?rev=415&view=rev
Author: skilvington
Date: 2007-09-23 12:16:23 -0700 (Sun, 23 Sep 2007)
Log Message:
-----------
pull out whole unknown words, rather than a char at a time
Modified Paths:
--------------
redbutton-author/trunk/parser.l.footer
redbutton-author/trunk/tokens.h.header
Modified: redbutton-author/trunk/parser.l.footer
===================================================================
--- redbutton-author/trunk/parser.l.footer 2007-09-22 18:35:40 UTC (rev 414)
+++ redbutton-author/trunk/parser.l.footer 2007-09-23 19:16:23 UTC (rev 415)
@@ -1,4 +1,5 @@
-. return INVALID;
+[a-z0-9:]+ return UNKNOWN_WORD;
+. return INVALID_CHAR;
%%
void
Modified: redbutton-author/trunk/tokens.h.header
===================================================================
--- redbutton-author/trunk/tokens.h.header 2007-09-22 18:35:40 UTC (rev 414)
+++ redbutton-author/trunk/tokens.h.header 2007-09-23 19:16:23 UTC (rev 415)
@@ -1,9 +1,10 @@
#define END_OF_SRC 0 /* must be 0 */
#define COMMENT 1
-#define INVALID 2
-#define INTEGER 3
-#define BOOLEAN 4
-#define STRING 5
-#define QPRINTABLE 6
-#define BASE64 7
-#define Null 8
+#define UNKNOWN_WORD 2
+#define INVALID_CHAR 3
+#define INTEGER 4
+#define BOOLEAN 5
+#define STRING 6
+#define QPRINTABLE 7
+#define BASE64 8
+#define Null 9
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ski...@us...> - 2007-09-22 18:35:43
|
Revision: 414
http://redbutton.svn.sourceforge.net/redbutton/?rev=414&view=rev
Author: skilvington
Date: 2007-09-22 11:35:40 -0700 (Sat, 22 Sep 2007)
Log Message:
-----------
OCTET STRINGs could be 0 length
Modified Paths:
--------------
redbutton-author/trunk/der_encode.c
Modified: redbutton-author/trunk/der_encode.c
===================================================================
--- redbutton-author/trunk/der_encode.c 2007-09-22 18:16:46 UTC (rev 413)
+++ redbutton-author/trunk/der_encode.c 2007-09-22 18:35:40 UTC (rev 414)
@@ -237,9 +237,6 @@
}
else
{
- /* assert */
- if(n->length == 0 && !(n->asn1tag == ASN1TAG_NULL && n->asn1class == ASN1CLASS_UNIVERSAL))
- fatal("Type [%s %u] has 0 length", asn1class_name(n->asn1class), n->asn1tag);
val_length = n->length;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ski...@us...> - 2007-09-22 18:17:04
|
Revision: 413
http://redbutton.svn.sourceforge.net/redbutton/?rev=413&view=rev
Author: skilvington
Date: 2007-09-22 11:16:46 -0700 (Sat, 22 Sep 2007)
Log Message:
-----------
do everything apart from actually encode the DER tag and length
Modified Paths:
--------------
redbutton-author/trunk/der_encode.c
Modified: redbutton-author/trunk/der_encode.c
===================================================================
--- redbutton-author/trunk/der_encode.c 2007-09-22 16:57:02 UTC (rev 412)
+++ redbutton-author/trunk/der_encode.c 2007-09-22 18:16:46 UTC (rev 413)
@@ -221,9 +221,34 @@
unsigned int
gen_der_header(struct node *n)
{
-/* TODO */
-printf("TODO: gen_der_header\n");
+ unsigned int val_length;
+ struct node *kid;
- return n->hdr_length + n->length;
+ /* if it is a constructed type, sum the length of its children */
+ if(n->children)
+ {
+ /* assert */
+ if(n->length != 0)
+ fatal("Constructed type [%s %u] has a value", asn1class_name(n->asn1class), n->asn1tag);
+ /* recursively generate the DER headers for our child nodes */
+ val_length = 0;
+ for(kid=n->children; kid; kid=kid->siblings)
+ val_length += gen_der_header(kid);
+ }
+ else
+ {
+ /* assert */
+ if(n->length == 0 && !(n->asn1tag == ASN1TAG_NULL && n->asn1class == ASN1CLASS_UNIVERSAL))
+ fatal("Type [%s %u] has 0 length", asn1class_name(n->asn1class), n->asn1tag);
+ val_length = n->length;
+ }
+
+ /* we don't need a header if we are a synthetic object */
+ if(!is_synthetic(n->asn1tag))
+ {
+printf("TODO: gen_der_header: tag=%u class=%s len=%u\n", n->asn1tag, asn1class_name(n->asn1class), val_length);
+ }
+
+ return n->hdr_length + val_length;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ski...@us...> - 2007-09-22 16:57:04
|
Revision: 412
http://redbutton.svn.sourceforge.net/redbutton/?rev=412&view=rev
Author: skilvington
Date: 2007-09-22 09:57:02 -0700 (Sat, 22 Sep 2007)
Log Message:
-----------
don't print too many {}'s
Modified Paths:
--------------
redbutton-author/trunk/mhegc.c
Modified: redbutton-author/trunk/mhegc.c
===================================================================
--- redbutton-author/trunk/mhegc.c 2007-09-22 16:55:38 UTC (rev 411)
+++ redbutton-author/trunk/mhegc.c 2007-09-22 16:57:02 UTC (rev 412)
@@ -124,7 +124,7 @@
{
print_indent(indent);
fprintf(stderr, "[%s %d]\n", asn1class_name(n->asn1class), n->asn1tag);
- if(show_kids)
+ if(show_kids && n->children)
{
print_indent(indent);
fprintf(stderr, "{\n");
@@ -138,7 +138,7 @@
for(kid=n->children; kid; kid=kid->siblings)
print_node(kid, indent);
- if(show_node && show_kids)
+ if(show_node && show_kids && n->children)
{
indent --;
print_indent(indent);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|