[Redbutton-devel] SF.net SVN: redbutton: [456] redbutton-author/trunk
Brought to you by:
skilvington
|
From: <ski...@us...> - 2007-10-29 17:11:42
|
Revision: 456
http://redbutton.svn.sourceforge.net/redbutton/?rev=456&view=rev
Author: skilvington
Date: 2007-10-29 10:11:26 -0700 (Mon, 29 Oct 2007)
Log Message:
-----------
simplify asn1decode.c now we can look up ASN1TAGCLASS values in ccc at run time
Modified Paths:
--------------
redbutton-author/trunk/Makefile
redbutton-author/trunk/asn1decode.c.header
redbutton-author/trunk/asn1tag.c
redbutton-author/trunk/asn1tag.h
redbutton-author/trunk/ccc.y
Modified: redbutton-author/trunk/Makefile
===================================================================
--- redbutton-author/trunk/Makefile 2007-10-29 16:44:42 UTC (rev 455)
+++ redbutton-author/trunk/Makefile 2007-10-29 17:11:26 UTC (rev 456)
@@ -36,10 +36,10 @@
mhegd: asn1decode.h ${MHEGD_OBJS}
${CC} ${CFLAGS} ${DEFS} -o mhegd ${MHEGD_OBJS} ${LIBS}
-ccc: ccc.y ccc.l asn1type.o
+ccc: ccc.y ccc.l asn1type.o asn1tag.o
${LEX} -i -t ccc.l > lex.ccc.c
${YACC} -b ccc -d ccc.y
- ${CC} ${CFLAGS} ${DEFS} -o ccc lex.ccc.c ccc.tab.c asn1type.o
+ ${CC} ${CFLAGS} ${DEFS} -o ccc lex.ccc.c ccc.tab.c asn1type.o asn1tag.o
lex.parser.c parser.c parser.h: parser.l.* parser.c.* parser.h.* tokens.h.* grammar asn1tag.h ccc
cat grammar | ./ccc -l parser.l -p parser.c -h parser.h -t tokens.h
Modified: redbutton-author/trunk/asn1decode.c.header
===================================================================
--- redbutton-author/trunk/asn1decode.c.header 2007-10-29 16:44:42 UTC (rev 455)
+++ redbutton-author/trunk/asn1decode.c.header 2007-10-29 17:11:26 UTC (rev 456)
@@ -7,19 +7,6 @@
void verbose(char *, ...);
-bool keep_tag(unsigned int tagclass)
-{
- if(is_synthetic(tagclass)
- || tagclass == ASN1TAGCLASS_BOOLEAN
- || tagclass == ASN1TAGCLASS_INTEGER
- || tagclass == ASN1TAGCLASS_OctetString
- || tagclass == ASN1TAGCLASS_Null
- || tagclass == ASN1TAGCLASS_ENUMERATED)
- return true;
- else
- return false;
-}
-
int asn1decode_BOOLEAN(FILE *der, FILE *out, int length)
{
int left = length;
Modified: redbutton-author/trunk/asn1tag.c
===================================================================
--- redbutton-author/trunk/asn1tag.c 2007-10-29 16:44:42 UTC (rev 455)
+++ redbutton-author/trunk/asn1tag.c 2007-10-29 17:11:26 UTC (rev 456)
@@ -57,6 +57,24 @@
}
/*
+ * return true if we need to pass on the tag for this type in the asn1decode functions
+ */
+
+bool
+keep_tag(unsigned int tagclass)
+{
+ if(is_synthetic(tagclass)
+ || tagclass == ASN1TAGCLASS_BOOLEAN
+ || tagclass == ASN1TAGCLASS_INTEGER
+ || tagclass == ASN1TAGCLASS_OctetString
+ || tagclass == ASN1TAGCLASS_Null
+ || tagclass == ASN1TAGCLASS_ENUMERATED)
+ return true;
+ else
+ return false;
+}
+
+/*
* give access to ASN1TAGCLASS_XXX constants when XXX is not known until run time
*/
Modified: redbutton-author/trunk/asn1tag.h
===================================================================
--- redbutton-author/trunk/asn1tag.h 2007-10-29 16:44:42 UTC (rev 455)
+++ redbutton-author/trunk/asn1tag.h 2007-10-29 17:11:26 UTC (rev 456)
@@ -34,6 +34,7 @@
char *asn1class_name(unsigned int);
bool is_synthetic(unsigned int);
bool needs_tagging(unsigned int, unsigned int);
+bool keep_tag(unsigned int);
unsigned int asn1tagclass(const char *);
/*
Modified: redbutton-author/trunk/ccc.y
===================================================================
--- redbutton-author/trunk/ccc.y 2007-10-29 16:44:42 UTC (rev 455)
+++ redbutton-author/trunk/ccc.y 2007-10-29 17:11:26 UTC (rev 456)
@@ -10,6 +10,7 @@
#include <errno.h>
#include "asn1type.h"
+#include "asn1tag.h"
#define YYSTYPE char *
@@ -853,15 +854,15 @@
buf_append(&state.decode_fns, "\t\tleft -= sublen;\n\n");
buf_append(&state.decode_fns, "\t\tif(is_%s(tag.class, tag.number))\n\t\t{\n", item->name);
/* if it is a synthetic or primitive type, we still need the current tag */
- buf_append(&state.decode_fns, "\t\t\tif(keep_tag(ASN1TAGCLASS_%s))\n", item->name);
- buf_append(&state.decode_fns, "\t\t\t{\n");
- buf_append(&state.decode_fns, "\t\t\t\tfseek(der, -sublen, SEEK_CUR);\n");
- buf_append(&state.decode_fns, "\t\t\t\tasn1decode_%s(der, out, sublen + tag.length);\n", item->name);
- buf_append(&state.decode_fns, "\t\t\t}\n");
- buf_append(&state.decode_fns, "\t\t\telse\n");
- buf_append(&state.decode_fns, "\t\t\t{\n");
- buf_append(&state.decode_fns, "\t\t\t\tasn1decode_%s(der, out, tag.length);\n", item->name);
- buf_append(&state.decode_fns, "\t\t\t}\n");
+ if(keep_tag(asn1tagclass(item->name)))
+ {
+ buf_append(&state.decode_fns, "\t\t\tfseek(der, -sublen, SEEK_CUR);\n");
+ buf_append(&state.decode_fns, "\t\t\tasn1decode_%s(der, out, sublen + tag.length);\n", item->name);
+ }
+ else
+ {
+ 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\t\telse\n");
buf_append(&state.decode_fns, "\t\t{\n\t\t\treturn der_error(\"%s\");\n\t\t}\n", name);
@@ -876,16 +877,16 @@
buf_append(&state.decode_fns, "\t\t\treturn der_error(\"%s\");\n", name);
buf_append(&state.decode_fns, "\t\tif(is_%s(tag.class, tag.number))\n\t\t{\n", item->name);
/* if it is a synthetic or primitive type, we still need the current tag */
- buf_append(&state.decode_fns, "\t\t\tif(keep_tag(ASN1TAGCLASS_%s))\n", item->name);
- buf_append(&state.decode_fns, "\t\t\t{\n");
- buf_append(&state.decode_fns, "\t\t\t\tfseek(der, -sublen, SEEK_CUR);\n");
- buf_append(&state.decode_fns, "\t\t\t\tsublen = asn1decode_%s(der, out, length);\n", item->name);
- buf_append(&state.decode_fns, "\t\t\t}\n");
- buf_append(&state.decode_fns, "\t\t\telse\n");
- buf_append(&state.decode_fns, "\t\t\t{\n");
- buf_append(&state.decode_fns, "\t\t\t\tleft -= sublen;\n");
- buf_append(&state.decode_fns, "\t\t\t\tsublen = asn1decode_%s(der, out, tag.length);\n", item->name);
- buf_append(&state.decode_fns, "\t\t\t}\n");
+ if(keep_tag(asn1tagclass(item->name)))
+ {
+ buf_append(&state.decode_fns, "\t\t\tfseek(der, -sublen, SEEK_CUR);\n");
+ buf_append(&state.decode_fns, "\t\t\tsublen = asn1decode_%s(der, out, length);\n", item->name);
+ }
+ else
+ {
+ buf_append(&state.decode_fns, "\t\t\tleft -= sublen;\n");
+ buf_append(&state.decode_fns, "\t\t\tsublen = asn1decode_%s(der, out, tag.length);\n", item->name);
+ }
buf_append(&state.decode_fns, "\t\t\tif(sublen < 0)\n");
buf_append(&state.decode_fns, "\t\t\t\treturn der_error(\"%s\");\n", name);
buf_append(&state.decode_fns, "\t\t\tleft -= sublen;\n\n");
@@ -936,15 +937,15 @@
/* is it what we expect */
buf_append(&state.decode_fns, "\tif(is_%s(tag.class, tag.number))\n\t{\n", item->name);
/* if it is a synthetic or primitive type, we still need the current tag */
- buf_append(&state.decode_fns, "\t\tif(keep_tag(ASN1TAGCLASS_%s))\n", item->name);
- buf_append(&state.decode_fns, "\t\t{\n");
- buf_append(&state.decode_fns, "\t\t\tfseek(der, -sublen, SEEK_CUR);\n");
- buf_append(&state.decode_fns, "\t\t\tasn1decode_%s(der, out, sublen + tag.length);\n", item->name);
- buf_append(&state.decode_fns, "\t\t}\n");
- buf_append(&state.decode_fns, "\t\telse\n");
- buf_append(&state.decode_fns, "\t\t{\n");
- buf_append(&state.decode_fns, "\t\t\tasn1decode_%s(der, out, tag.length);\n", item->name);
- buf_append(&state.decode_fns, "\t\t}\n");
+ if(keep_tag(asn1tagclass(item->name)))
+ {
+ buf_append(&state.decode_fns, "\t\tfseek(der, -sublen, SEEK_CUR);\n");
+ buf_append(&state.decode_fns, "\t\tasn1decode_%s(der, out, sublen + tag.length);\n", item->name);
+ }
+ else
+ {
+ 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");
/* is it a type that is encoded as a NULL if it is not present */
@@ -980,7 +981,6 @@
/* 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\tlong pretag = ftell(der);\n");
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");
@@ -1006,15 +1006,15 @@
first = false;
buf_append(&state.decode_fns, "if(is_%s(tag.class, tag.number))\n\t\t{\n", item->name);
/* if it is a synthetic or primitive type, we still need the current tag */
- buf_append(&state.decode_fns, "\t\t\tif(keep_tag(ASN1TAGCLASS_%s))\n", item->name);
- buf_append(&state.decode_fns, "\t\t\t{\n");
- buf_append(&state.decode_fns, "\t\t\t\tfseek(der, pretag, SEEK_SET);\n");
- buf_append(&state.decode_fns, "\t\t\t\tasn1decode_%s(der, out, sublen + tag.length);\n", item->name);
- buf_append(&state.decode_fns, "\t\t\t}\n");
- buf_append(&state.decode_fns, "\t\t\telse\n");
- buf_append(&state.decode_fns, "\t\t\t{\n");
- buf_append(&state.decode_fns, "\t\t\t\tasn1decode_%s(der, out, tag.length);\n", item->name);
- buf_append(&state.decode_fns, "\t\t\t}\n");
+ if(keep_tag(asn1tagclass(item->name)))
+ {
+ buf_append(&state.decode_fns, "\t\t\tfseek(der, -sublen, SEEK_CUR);\n");
+ buf_append(&state.decode_fns, "\t\t\tasn1decode_%s(der, out, sublen + tag.length);\n", item->name);
+ }
+ else
+ {
+ 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;
@@ -1070,7 +1070,6 @@
{
/* a CHOICE type */
buf_append(&state.decode_fns, "\t/* CHOICE */\n");
- buf_append(&state.decode_fns, "\tlong pretag = ftell(der);\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");
@@ -1094,15 +1093,15 @@
buf_append(&state.decode_fns, "\telse ");
buf_append(&state.decode_fns, "if(is_%s(tag.class, tag.number))\n\t{\n", item->name);
/* if it is a synthetic or primitive type, we still need the current tag */
- buf_append(&state.decode_fns, "\t\tif(keep_tag(ASN1TAGCLASS_%s))\n", item->name);
- buf_append(&state.decode_fns, "\t\t{\n");
- buf_append(&state.decode_fns, "\t\t\tfseek(der, pretag, SEEK_SET);\n");
- buf_append(&state.decode_fns, "\t\t\tasn1decode_%s(der, out, sublen + tag.length);\n", item->name);
- buf_append(&state.decode_fns, "\t\t}\n");
- buf_append(&state.decode_fns, "\t\telse\n");
- buf_append(&state.decode_fns, "\t\t{\n");
- buf_append(&state.decode_fns, "\t\t\tasn1decode_%s(der, out, tag.length);\n", item->name);
- buf_append(&state.decode_fns, "\t\t}\n");
+ if(keep_tag(asn1tagclass(item->name)))
+ {
+ buf_append(&state.decode_fns, "\t\tfseek(der, -sublen, SEEK_CUR);\n");
+ buf_append(&state.decode_fns, "\t\tasn1decode_%s(der, out, sublen + tag.length);\n", item->name);
+ }
+ else
+ {
+ 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");
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|