[Redbutton-devel] SF.net SVN: redbutton: [381] redbutton-author/trunk
Brought to you by:
skilvington
|
From: <ski...@us...> - 2007-09-14 16:12:24
|
Revision: 381
http://redbutton.svn.sourceforge.net/redbutton/?rev=381&view=rev
Author: skilvington
Date: 2007-09-14 09:12:22 -0700 (Fri, 14 Sep 2007)
Log Message:
-----------
build the whole ASN1 object tree
Modified Paths:
--------------
redbutton-author/trunk/Makefile
redbutton-author/trunk/asn1tag.h
redbutton-author/trunk/ccc.y
redbutton-author/trunk/mhegc.c
redbutton-author/trunk/parser.c.header
Added Paths:
-----------
redbutton-author/trunk/asn1tag.c
redbutton-author/trunk/der_encode.c
redbutton-author/trunk/der_encode.h
Modified: redbutton-author/trunk/Makefile
===================================================================
--- redbutton-author/trunk/Makefile 2007-09-14 15:06:29 UTC (rev 380)
+++ redbutton-author/trunk/Makefile 2007-09-14 16:12:22 UTC (rev 381)
@@ -14,6 +14,8 @@
OBJS= mhegc.o \
lex.parser.o \
parser.o \
+ der_encode.o \
+ asn1tag.o \
utils.o
TARDIR=`basename ${PWD}`
Added: redbutton-author/trunk/asn1tag.c
===================================================================
--- redbutton-author/trunk/asn1tag.c (rev 0)
+++ redbutton-author/trunk/asn1tag.c 2007-09-14 16:12:22 UTC (rev 381)
@@ -0,0 +1,17 @@
+/*
+ * asn1tag.c
+ */
+
+#include "asn1tag.h"
+
+char *
+asn1class_name(unsigned int c)
+{
+ if(c == ASN1CLASS_UNIVERSAL) return "UNIVERSAL";
+ if(c == ASN1CLASS_APPLICATION) return "APPLICATION";
+ if(c == ASN1CLASS_CONTEXT) return "CONTEXT";
+ if(c == ASN1CLASS_PRIVATE) return "PRIVATE";
+
+ return "ILLEGAL-ASN1-CLASS-NUMBER";
+}
+
Modified: redbutton-author/trunk/asn1tag.h
===================================================================
--- redbutton-author/trunk/asn1tag.h 2007-09-14 15:06:29 UTC (rev 380)
+++ redbutton-author/trunk/asn1tag.h 2007-09-14 16:12:22 UTC (rev 381)
@@ -11,6 +11,8 @@
#define ASN1CLASS_CONTEXT 0x80
#define ASN1CLASS_PRIVATE 0xc0
+char *asn1class_name(unsigned int);
+
/*
* a synthetic object created as a result of the grammar definition
* eg TextBody etc
@@ -34,35 +36,13 @@
#define ASN1TAGCLASS_TokenManager ASN1TAG_SYNTHETIC
/* tokens synthesised by the grammar */
+#define ASN1TAGCLASS_ObjectIdentifier ASN1TAG_SYNTHETIC
#define ASN1TAGCLASS_TokenGroupBody ASN1TAG_SYNTHETIC
#define ASN1TAGCLASS_LineArtBody ASN1TAG_SYNTHETIC
#define ASN1TAGCLASS_TextBody ASN1TAG_SYNTHETIC
#define ASN1TAGCLASS_PushButtonBody ASN1TAG_SYNTHETIC
-/* start TODO */
-#define ASN1TAG_FIXME 99999
-/* TODO: need to look at these - have different values in different places */
-#define ASN1TAGCLASS_ReferencedContent ASN1TAG_FIXME
-#define ASN1TAGCLASS_XYPosition ASN1TAG_FIXME
-#define ASN1TAGCLASS_Point ASN1TAG_FIXME
-/* TODO: as above, but only used once */
-#define ASN1TAGCLASS_Rational ASN1TAG_FIXME
-#define ASN1TAGCLASS_ExternalReference ASN1TAG_FIXME
-#define ASN1TAGCLASS_NewReferencedContent ASN1TAG_FIXME
-#define ASN1TAGCLASS_NextScene ASN1TAG_FIXME
-#define ASN1TAGCLASS_TokenGroupItem ASN1TAG_FIXME
-/* TODO: an INTEGER ie class=UNIVERSAL, tag=2 */
-#define ASN1TAGCLASS_Movement ASN1TAG_FIXME
-/* TODO: sequences */
-#define ASN1TAGCLASS_ActionSlots ASN1TAG_FIXME
-#define ASN1TAGCLASS_InVariables ASN1TAG_FIXME
-#define ASN1TAGCLASS_OutVariables ASN1TAG_FIXME
-#define ASN1TAGCLASS_ActionClass ASN1TAG_FIXME
-#define ASN1TAGCLASS_Parameters ASN1TAG_FIXME
-#define ASN1TAGCLASS_PointList ASN1TAG_FIXME
-/* end TODO */
-
-/* ASN1 tags */
+/* ASN1 CONTEXT tag values */
#define ASN1TAG_ApplicationClass 0
#define ASN1TAG_SceneClass 1
#define ASN1TAG_StandardIdentifier 2
@@ -562,5 +542,183 @@
#define ASN1TAGCLASS_GetBitmapDecodeOffset ((ASN1CLASS_CONTEXT << 24) | ASN1TAG_GetBitmapDecodeOffset)
#define ASN1TAGCLASS_SetSliderParameters ((ASN1CLASS_CONTEXT << 24) | ASN1TAG_SetSliderParameters)
+/* ASN1 UNIVERSAL tag values */
+#define ASN1TAG_BOOLEAN 1
+#define ASN1TAG_INTEGER 2
+#define ASN1TAG_OctetString 4
+/* and with the class included */
+#define ASN1TAGCLASS_BOOLEAN ((ASN1CLASS_UNIVERSAL << 24) | ASN1TAG_BOOLEAN)
+#define ASN1TAGCLASS_INTEGER ((ASN1CLASS_UNIVERSAL << 24) | ASN1TAG_INTEGER)
+#define ASN1TAGCLASS_OctetString ((ASN1CLASS_UNIVERSAL << 24) | ASN1TAG_OctetString)
+
+/* UNIVERSAL ASN1 types in the grammar */
+#define ASN1TAGCLASS_JointIsoItuIdentifier ASN1TAGCLASS_INTEGER
+#define ASN1TAGCLASS_MHEGStandardIdentifier ASN1TAGCLASS_INTEGER
+
+/* start TODO */
+#define ASN1TAG_FIXME 99999
+#define ASN1TAGCLASS_Font ASN1TAG_FIXME
+#define ASN1TAGCLASS_DirectFont ASN1TAG_FIXME
+#define ASN1TAGCLASS_IndirectFont ASN1TAG_FIXME
+#define ASN1TAGCLASS_XScene ASN1TAG_FIXME
+#define ASN1TAGCLASS_YScene ASN1TAG_FIXME
+#define ASN1TAGCLASS_Width ASN1TAG_FIXME
+#define ASN1TAGCLASS_Height ASN1TAG_FIXME
+#define ASN1TAGCLASS_SceneRef ASN1TAG_FIXME
+#define ASN1TAGCLASS_SceneWeight ASN1TAG_FIXME
+#define ASN1TAGCLASS_IncludedContent ASN1TAG_FIXME
+#define ASN1TAGCLASS_EventSource ASN1TAG_FIXME
+#define ASN1TAGCLASS_EventType ASN1TAG_FIXME
+#define ASN1TAGCLASS_EventData ASN1TAG_FIXME
+#define ASN1TAGCLASS_ObjectReferenceValue ASN1TAG_FIXME
+#define ASN1TAGCLASS_ContentReferenceValue ASN1TAG_FIXME
+#define ASN1TAGCLASS_Presentable ASN1TAG_FIXME
+#define ASN1TAGCLASS_TargetElement ASN1TAG_FIXME
+#define ASN1TAGCLASS_AVisible ASN1TAG_FIXME
+#define ASN1TAGCLASS_Position ASN1TAG_FIXME
+#define ASN1TAGCLASS_OriginalBoxSize ASN1TAG_FIXME
+#define ASN1TAGCLASS_XLength ASN1TAG_FIXME
+#define ASN1TAGCLASS_YLength ASN1TAG_FIXME
+#define ASN1TAGCLASS_OriginalLineStyle ASN1TAG_FIXME
+#define ASN1TAGCLASS_AbsoluteTime ASN1TAG_FIXME
+#define ASN1TAGCLASS_Address ASN1TAG_FIXME
+#define ASN1TAGCLASS_Answer ASN1TAG_FIXME
+#define ASN1TAGCLASS_AppendValue ASN1TAG_FIXME
+#define ASN1TAGCLASS_ArcAngle ASN1TAG_FIXME
+#define ASN1TAGCLASS_AvailabilityStatusVar ASN1TAG_FIXME
+#define ASN1TAGCLASS_CallSucceeded ASN1TAG_FIXME
+#define ASN1TAGCLASS_CellIndex ASN1TAG_FIXME
+#define ASN1TAGCLASS_CloneRefVar ASN1TAG_FIXME
+#define ASN1TAGCLASS_ConnectionTag ASN1TAG_FIXME
+#define ASN1TAGCLASS_Denominator ASN1TAG_FIXME
+#define ASN1TAGCLASS_EllipseHeight ASN1TAG_FIXME
+#define ASN1TAGCLASS_EllipseWidth ASN1TAG_FIXME
+#define ASN1TAGCLASS_EmulatedEventSource ASN1TAG_FIXME
+#define ASN1TAGCLASS_EmulatedEventType ASN1TAG_FIXME
+#define ASN1TAGCLASS_EntryPointVar ASN1TAG_FIXME
+#define ASN1TAGCLASS_ForkSucceeded ASN1TAG_FIXME
+#define ASN1TAGCLASS_Feature ASN1TAG_FIXME
+#define ASN1TAGCLASS_FillColourVar ASN1TAG_FIXME
+#define ASN1TAGCLASS_FirstItemVar ASN1TAG_FIXME
+#define ASN1TAGCLASS_HighlightStatusVar ASN1TAG_FIXME
+#define ASN1TAGCLASS_Index ASN1TAG_FIXME
+#define ASN1TAGCLASS_InFileName ASN1TAG_FIXME
+#define ASN1TAGCLASS_InteractionStatusVar ASN1TAG_FIXME
+#define ASN1TAGCLASS_ItemIndex ASN1TAG_FIXME
+#define ASN1TAGCLASS_ItemRefVar ASN1TAG_FIXME
+#define ASN1TAGCLASS_ItemStatusVar ASN1TAG_FIXME
+#define ASN1TAGCLASS_ItemsToScroll ASN1TAG_FIXME
+#define ASN1TAGCLASS_LabelVar ASN1TAG_FIXME
+#define ASN1TAGCLASS_LastAnchorFiredVar ASN1TAG_FIXME
+#define ASN1TAGCLASS_LineColourVar ASN1TAG_FIXME
+#define ASN1TAGCLASS_LineStyleVar ASN1TAG_FIXME
+#define ASN1TAGCLASS_LineWidthVar ASN1TAG_FIXME
+#define ASN1TAGCLASS_MovementIdentifier ASN1TAG_FIXME
+#define ASN1TAGCLASS_NbOfSteps ASN1TAG_FIXME
+#define ASN1TAGCLASS_NewCachePriority ASN1TAG_FIXME
+#define ASN1TAGCLASS_NewCounterEndPosition ASN1TAG_FIXME
+#define ASN1TAGCLASS_NewCounterPosition ASN1TAG_FIXME
+#define ASN1TAGCLASS_NewCounterValue ASN1TAG_FIXME
+#define ASN1TAGCLASS_NewCursorShape ASN1TAG_FIXME
+#define ASN1TAGCLASS_NewEntryPoint ASN1TAG_FIXME
+#define ASN1TAGCLASS_NewFirstItem ASN1TAG_FIXME
+#define ASN1TAGCLASS_NewGenericOctetString ASN1TAG_FIXME
+#define ASN1TAGCLASS_NewHighlightStatus ASN1TAG_FIXME
+#define ASN1TAGCLASS_NewIncludedContent ASN1TAG_FIXME
+#define ASN1TAGCLASS_NewInteractionStatus ASN1TAG_FIXME
+#define ASN1TAGCLASS_NewLabel ASN1TAG_FIXME
+#define ASN1TAGCLASS_NewLineStyle ASN1TAG_FIXME
+#define ASN1TAGCLASS_NewLineWidth ASN1TAG_FIXME
+#define ASN1TAGCLASS_NewOverwriteMode ASN1TAG_FIXME
+#define ASN1TAGCLASS_NewPaletteRef ASN1TAG_FIXME
+#define ASN1TAGCLASS_NewPortion ASN1TAG_FIXME
+#define ASN1TAGCLASS_NewSliderValue ASN1TAG_FIXME
+#define ASN1TAGCLASS_NewSpeed ASN1TAG_FIXME
+#define ASN1TAGCLASS_NewTransparency ASN1TAG_FIXME
+#define ASN1TAGCLASS_NewVolume ASN1TAG_FIXME
+#define ASN1TAGCLASS_NewXPosition ASN1TAG_FIXME
+#define ASN1TAGCLASS_NewYPosition ASN1TAG_FIXME
+#define ASN1TAGCLASS_Numerator ASN1TAG_FIXME
+#define ASN1TAGCLASS_OpenSucceeded ASN1TAG_FIXME
+#define ASN1TAGCLASS_Operator ASN1TAG_FIXME
+#define ASN1TAGCLASS_OutFileName ASN1TAG_FIXME
+#define ASN1TAGCLASS_OverwriteModeVar ASN1TAG_FIXME
+#define ASN1TAGCLASS_PortionVar ASN1TAG_FIXME
+#define ASN1TAGCLASS_Protocol ASN1TAG_FIXME
+#define ASN1TAGCLASS_ReadSucceeded ASN1TAG_FIXME
+#define ASN1TAGCLASS_ReferenceVisible ASN1TAG_FIXME
+#define ASN1TAGCLASS_RunningStatusVar ASN1TAG_FIXME
+#define ASN1TAGCLASS_SelectionStatusVar ASN1TAG_FIXME
+#define ASN1TAGCLASS_SizeVar ASN1TAG_FIXME
+#define ASN1TAGCLASS_SliderValueVar ASN1TAG_FIXME
+#define ASN1TAGCLASS_StartAngle ASN1TAG_FIXME
+#define ASN1TAGCLASS_StoreSucceeded ASN1TAG_FIXME
+#define ASN1TAGCLASS_Target ASN1TAG_FIXME
+#define ASN1TAGCLASS_TextContentVar ASN1TAG_FIXME
+#define ASN1TAGCLASS_TextDataVar ASN1TAG_FIXME
+#define ASN1TAGCLASS_TimerID ASN1TAG_FIXME
+#define ASN1TAGCLASS_TimerValue ASN1TAG_FIXME
+#define ASN1TAGCLASS_TokenPositionVar ASN1TAG_FIXME
+#define ASN1TAGCLASS_TransitionEffect ASN1TAG_FIXME
+#define ASN1TAGCLASS_TriggerIdentifier ASN1TAG_FIXME
+#define ASN1TAGCLASS_Value ASN1TAG_FIXME
+#define ASN1TAGCLASS_VisibleReference ASN1TAG_FIXME
+#define ASN1TAGCLASS_VolumeVar ASN1TAG_FIXME
+#define ASN1TAGCLASS_X ASN1TAG_FIXME
+#define ASN1TAGCLASS_X1 ASN1TAG_FIXME
+#define ASN1TAGCLASS_X2 ASN1TAG_FIXME
+#define ASN1TAGCLASS_XBoxSizeVar ASN1TAG_FIXME
+#define ASN1TAGCLASS_XCursor ASN1TAG_FIXME
+#define ASN1TAGCLASS_XNewBoxSize ASN1TAG_FIXME
+#define ASN1TAGCLASS_XOut ASN1TAG_FIXME
+#define ASN1TAGCLASS_XPositionVar ASN1TAG_FIXME
+#define ASN1TAGCLASS_XScale ASN1TAG_FIXME
+#define ASN1TAGCLASS_Y ASN1TAG_FIXME
+#define ASN1TAGCLASS_Y1 ASN1TAG_FIXME
+#define ASN1TAGCLASS_Y2 ASN1TAG_FIXME
+#define ASN1TAGCLASS_YBoxSizeVar ASN1TAG_FIXME
+#define ASN1TAGCLASS_YCursor ASN1TAG_FIXME
+#define ASN1TAGCLASS_YNewBoxSize ASN1TAG_FIXME
+#define ASN1TAGCLASS_YOut ASN1TAG_FIXME
+#define ASN1TAGCLASS_YPositionVar ASN1TAG_FIXME
+#define ASN1TAGCLASS_YScale ASN1TAG_FIXME
+#define ASN1TAGCLASS_XOffsetVar ASN1TAG_FIXME
+#define ASN1TAGCLASS_YOffsetVar ASN1TAG_FIXME
+#define ASN1TAGCLASS_NewXOffset ASN1TAG_FIXME
+#define ASN1TAGCLASS_NewYOffset ASN1TAG_FIXME
+#define ASN1TAGCLASS_FocusPositionVar ASN1TAG_FIXME
+#define ASN1TAGCLASS_NewFocusPosition ASN1TAG_FIXME
+#define ASN1TAGCLASS_NewMinValue ASN1TAG_FIXME
+#define ASN1TAGCLASS_NewMaxValue ASN1TAG_FIXME
+#define ASN1TAGCLASS_NewStepSize ASN1TAG_FIXME
+#define ASN1TAGCLASS_InternalReference ASN1TAG_FIXME
+#define ASN1TAGCLASS_GroupIdentifier ASN1TAG_FIXME
+#define ASN1TAGCLASS_ObjectNumber ASN1TAG_FIXME
+#define ASN1TAGCLASS_DirectReference ASN1TAG_FIXME
+#define ASN1TAGCLASS_ColourIndex ASN1TAG_FIXME
+#define ASN1TAGCLASS_AbsoluteColour ASN1TAG_FIXME
+#define ASN1TAGCLASS_XPosition ASN1TAG_FIXME
+#define ASN1TAGCLASS_YPosition ASN1TAG_FIXME
+/* TODO: need to look at these - have different values in different places */
+#define ASN1TAGCLASS_ReferencedContent ASN1TAG_FIXME
+#define ASN1TAGCLASS_XYPosition ASN1TAG_FIXME
+#define ASN1TAGCLASS_Point ASN1TAG_FIXME
+/* TODO: as above, but only used once */
+#define ASN1TAGCLASS_Rational ASN1TAG_FIXME
+#define ASN1TAGCLASS_ExternalReference ASN1TAG_FIXME
+#define ASN1TAGCLASS_NewReferencedContent ASN1TAG_FIXME
+#define ASN1TAGCLASS_NextScene ASN1TAG_FIXME
+#define ASN1TAGCLASS_TokenGroupItem ASN1TAG_FIXME
+/* TODO: an INTEGER ie class=UNIVERSAL, tag=2 */
+#define ASN1TAGCLASS_Movement ASN1TAG_FIXME
+/* TODO: sequences */
+#define ASN1TAGCLASS_ActionSlots ASN1TAG_FIXME
+#define ASN1TAGCLASS_InVariables ASN1TAG_FIXME
+#define ASN1TAGCLASS_OutVariables ASN1TAG_FIXME
+#define ASN1TAGCLASS_ActionClass ASN1TAG_FIXME
+#define ASN1TAGCLASS_Parameters ASN1TAG_FIXME
+#define ASN1TAGCLASS_PointList ASN1TAG_FIXME
+/* end TODO */
+
#endif /* __ASN1TAG_H__ */
Modified: redbutton-author/trunk/ccc.y
===================================================================
--- redbutton-author/trunk/ccc.y 2007-09-14 15:06:29 UTC (rev 380)
+++ redbutton-author/trunk/ccc.y 2007-09-14 16:12:22 UTC (rev 381)
@@ -389,6 +389,8 @@
/* a single item (not including literals) */
if(nitems == 1)
{
+ /* add a child ASN1 object */
+ buf_append(&state.parse_fns, "\tparent = add_child(parent, ASN1TAGCLASS_%s);\n\n", name);
/* eat literals at the start */
item = state.items;
while(item && item->type == IT_LITERAL)
@@ -403,11 +405,6 @@
buf_append(&state.parse_fns, "\tnext = peek_token();\n\n");
if(item->type == IT_IDENTIFIER)
{
-#if 0
- /* add a child ASN1 object */
- buf_append(&state.parse_fns, "\tparent = add_child(parent, ASN1TAGCLASS_%s);\n\n", name);
- /* read the item */
-#endif
buf_append(&state.parse_fns, "\t/* %s */\n", item->name);
buf_append(&state.parse_fns, "\tif(is_%s(next))\n", item->name);
buf_append(&state.parse_fns, "\t\tparse_%s(parent);\n", item->name);
@@ -416,18 +413,12 @@
}
else if(item->type == IT_OPTIONAL)
{
- /* add a child ASN1 object */
- buf_append(&state.parse_fns, "\tparent = add_child(parent, ASN1TAGCLASS_%s);\n\n", name);
- /* read the item */
buf_append(&state.parse_fns, "\t/* [%s] */\n", item->name);
buf_append(&state.parse_fns, "\tif(is_%s(next))\n", item->name);
buf_append(&state.parse_fns, "\t\tparse_%s(parent);\n", item->name);
}
else if(item->type == IT_ONEORMORE)
{
- /* add a child ASN1 object */
- buf_append(&state.parse_fns, "\tparent = add_child(parent, ASN1TAGCLASS_%s);\n\n", name);
- /* read the item */
buf_append(&state.parse_fns, "\t/* %s+ */\n", item->name);
buf_append(&state.parse_fns, "\twhile(is_%s(next))\n", item->name);
buf_append(&state.parse_fns, "\t{\n");
@@ -504,6 +495,7 @@
buf_append(&state.parse_enum_fns, "void parse_%s(struct node *parent)\n{\n", tok_name);
buf_append(&state.parse_enum_fns, "\texpect_token(%s, %s);\n", tok_name, item->name);
buf_append(&state.parse_enum_fns, "\n\tverbose(\"<ENUM name=\\\"\"%s\"\\\" value=%u/>\\n\");\n", item->name, enum_val);
+ buf_append(&state.parse_enum_fns, "\n\tder_encode_INTEGER(&parent->value, &parent->length, %u);\n", enum_val);
buf_append(&state.parse_enum_fns, "\n\treturn;\n}\n\n");
free(tok_name);
enum_val ++;
@@ -557,8 +549,8 @@
while(item && item->type == IT_LITERAL)
{
char *tok_name = unquote(item->name);
- buf_append(&state.parse_fns, "\t/* %s */\n", item->name);
- buf_append(&state.parse_fns, "\texpect_token(%s, %s);\n\n", tok_name, item->name);
+ buf_append(&state.parse_fns, "\n\t/* %s */\n", item->name);
+ buf_append(&state.parse_fns, "\texpect_token(%s, %s);\n", tok_name, item->name);
free(tok_name);
item = item->next;
}
Added: redbutton-author/trunk/der_encode.c
===================================================================
--- redbutton-author/trunk/der_encode.c (rev 0)
+++ redbutton-author/trunk/der_encode.c 2007-09-14 16:12:22 UTC (rev 381)
@@ -0,0 +1,38 @@
+/*
+ * der_encode.c
+ */
+
+#include <stdbool.h>
+
+#include "utils.h"
+
+void
+der_encode_BOOLEAN(unsigned char **out, unsigned int *len, bool val)
+{
+ /* assert */
+ if(*out != NULL || *len != 0)
+ fatal("der_encode_BOOLEAN: length already %u", *len);
+
+ return;
+}
+
+void
+der_encode_INTEGER(unsigned char **out, unsigned int *len, int val)
+{
+ /* assert */
+ if(*out != NULL || *len != 0)
+ fatal("der_encode_INTEGER: length already %u", *len);
+
+ return;
+}
+
+void
+der_encode_OctetString(unsigned char **out, unsigned int *len, const char *str)
+{
+ /* assert */
+ if(*out != NULL || *len != 0)
+ fatal("der_encode_OctetString: length already %u", *len);
+
+ return;
+}
+
Added: redbutton-author/trunk/der_encode.h
===================================================================
--- redbutton-author/trunk/der_encode.h (rev 0)
+++ redbutton-author/trunk/der_encode.h 2007-09-14 16:12:22 UTC (rev 381)
@@ -0,0 +1,15 @@
+/*
+ * der_encode.h
+ */
+
+#ifndef __DER_ENCODE_H__
+#define __DER_ENCODE_H__
+
+#include <stdbool.h>
+
+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 char *);
+
+#endif /* __DER_ENCODE_H__ */
+
Modified: redbutton-author/trunk/mhegc.c
===================================================================
--- redbutton-author/trunk/mhegc.c 2007-09-14 15:06:29 UTC (rev 380)
+++ redbutton-author/trunk/mhegc.c 2007-09-14 16:12:22 UTC (rev 381)
@@ -27,7 +27,12 @@
#include <strings.h>
#include "parser.h"
+#include "asn1tag.h"
+#include "utils.h"
+void print_node(struct node *, unsigned int);
+void print_indent(unsigned int);
+
void usage(char *);
static int _verbose = 0;
@@ -69,6 +74,16 @@
if(next_token())
parse_error("Unexpected text after InterchangedObject");
+ /* assert */
+ if(asn1obj.siblings != NULL)
+ fatal("Top level object has siblings");
+
+ if(_verbose)
+ {
+ verbose("\nASN1 object tree:\n");
+ print_node(&asn1obj, 0);
+ }
+
return EXIT_SUCCESS;
}
@@ -77,6 +92,39 @@
*/
void
+print_node(struct node *n, unsigned int indent)
+{
+ struct node *kid;
+
+ print_indent(indent);
+ fprintf(stderr, "[%s %d]\n", asn1class_name(n->asn1class), n->asn1tag);
+
+ if(n->children)
+ {
+ print_indent(indent);
+ fprintf(stderr, "{\n");
+ for(kid=n->children; kid; kid=kid->siblings)
+ print_node(kid, indent + 1);
+ print_indent(indent);
+ fprintf(stderr, "}\n");
+ }
+
+ return;
+}
+
+void
+print_indent(unsigned int indent)
+{
+ while(indent > 0)
+ {
+ fprintf(stderr, " ");
+ indent --;
+ }
+
+ return;
+}
+
+void
verbose(const char *fmt, ...)
{
va_list ap;
Modified: redbutton-author/trunk/parser.c.header
===================================================================
--- redbutton-author/trunk/parser.c.header 2007-09-14 15:06:29 UTC (rev 380)
+++ redbutton-author/trunk/parser.c.header 2007-09-14 16:12:22 UTC (rev 381)
@@ -1,7 +1,9 @@
#include <stdio.h>
+#include <string.h>
#include "parser.h"
#include "tokens.h"
+#include "der_encode.h"
#include "utils.h"
/*
@@ -60,27 +62,31 @@
* parser functions for the predefined types
*/
-void parse_INTEGER(struct node *parent)
+void parse_BOOLEAN(struct node *parent)
{
- if(next_token() != INTEGER)
- parse_error("Unexpected token '%s'; expecting an integer", token_text());
+ if(next_token() != BOOLEAN)
+ parse_error("Unexpected token '%s'; expecting 'true' or 'false'", token_text());
- verbose("<INTEGER value=%s/>\n", token_text());
+ verbose("<BOOLEAN value=%s/>\n", token_text());
+ der_encode_BOOLEAN(&parent->value, &parent->length, strcmp(token_text(), "false"));
+
return;
}
-void parse_BOOLEAN(struct node *parent)
+
+void parse_INTEGER(struct node *parent)
{
- if(next_token() != BOOLEAN)
- parse_error("Unexpected token '%s'; expecting 'true' or 'false'", token_text());
+ if(next_token() != INTEGER)
+ parse_error("Unexpected token '%s'; expecting an integer", token_text());
- verbose("<BOOLEAN value=%s/>\n", token_text());
+ verbose("<INTEGER value=%s/>\n", token_text());
+ der_encode_INTEGER(&parent->value, &parent->length, strtol(token_text(), NULL, 0));
+
return;
}
-
void parse_STRING(struct node *parent)
{
if(next_token() != STRING)
@@ -88,6 +94,8 @@
verbose("<STRING value=%s/>\n", token_text());
+ der_encode_OctetString(&parent->value, &parent->length, token_text());
+
return;
}
@@ -99,6 +107,8 @@
verbose("<QPRINTABLE value=%s/>\n", token_text());
+ der_encode_OctetString(&parent->value, &parent->length, token_text());
+
return;
}
@@ -110,6 +120,8 @@
verbose("<BASE64 value=%s/>\n", token_text());
+ der_encode_OctetString(&parent->value, &parent->length, token_text());
+
return;
}
@@ -121,6 +133,10 @@
verbose("<Null/>\n");
+ /* assert */
+ if(parent->length != 0)
+ fatal("Null: length=%u", parent->length);
+
return;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|