Works better now.
authorSebastian Hammer <quinn@indexdata.com>
Thu, 9 Feb 1995 15:51:39 +0000 (15:51 +0000)
committerSebastian Hammer <quinn@indexdata.com>
Thu, 9 Feb 1995 15:51:39 +0000 (15:51 +0000)
21 files changed:
asn/proto.c
odr/Makefile
odr/ber_any.c [new file with mode: 0644]
odr/ber_bool.c
odr/ber_int.c
odr/ber_len.c
odr/ber_null.c
odr/ber_tag.c
odr/odr_any.c [new file with mode: 0644]
odr/odr_bit.c
odr/odr_bool.c
odr/odr_choice.c
odr/odr_cons.c
odr/odr_int.c
odr/odr_null.c
odr/odr_oct.c
odr/odr_oid.c
odr/odr_seq.c
odr/odr_use.c
odr/odr_util.c
odr/test.c

index 6cf6d17..1506e58 100644 (file)
@@ -4,7 +4,10 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: proto.c,v $
- * Revision 1.2  1995-02-06 21:26:07  quinn
+ * Revision 1.3  1995-02-09 15:51:39  quinn
+ * Works better now.
+ *
+ * Revision 1.2  1995/02/06  21:26:07  quinn
  * Repaired this evening's damages..
  *
  * Revision 1.1  1995/02/06  16:44:47  quinn
 
 #include <proto.h>
 
-/* ---------------------- INITIALIZE SERVICE ------------------- */
+/* ---------------------- GLOBAL DEFS ------------------- */
 
 int z_ReferenceId(ODR o, Z_ReferenceId **p, int opt)
 {
     return odr_implicit(o, odr_octetstring, (Odr_oct**) p, ODR_CONTEXT, 2, opt);
 }
 
-int z_DatabaseName(Odr o, Z_DatabaseName **p, int opt)
+int z_DatabaseName(ODR o, Z_DatabaseName **p, int opt)
 {
     return odr_implicit(o, odr_visiblestring, (char **) p, ODR_CONTEXT, 105,
        opt);
 }
 
+int z_ResultSetId(ODR o, char **p, int opt)
+{
+    return odr_implicit(o, odr_visiblestring, (char **) p, ODR_CONTEXT, 31,
+       opt);
+}
+
+int z_UserInformationField(ODR o, Z_UserInformationField **p, int opt)
+{
+    return odr_explicit(o, odr_external, (Odr_external **)p, ODR_CONTEXT,
+       11, opt);
+}
+
 /* ---------------------- INITIALIZE SERVICE ------------------- */
 
 int z_InitRequest(ODR o, Z_InitRequest **p, int opt)
@@ -55,6 +70,7 @@ int z_InitRequest(ODR o, Z_InitRequest **p, int opt)
            111, 1) &&
        odr_implicit(o, odr_visiblestring, &pp->implementationVersion,
            ODR_CONTEXT, 112, 1) &&
+       z_UserInformationField(o, &pp->userInformationField, 1) &&
        odr_sequence_end(o);
 }
 
@@ -83,12 +99,13 @@ int z_InitResponse(ODR o, Z_InitResponse **p, int opt)
            111, 1) &&
        odr_implicit(o, odr_visiblestring, &pp->implementationVersion,
            ODR_CONTEXT, 112, 1) &&
+       z_UserInformationField(o, &pp->userInformationField, 1) &&
        odr_sequence_end(o);
 }
 
 /* ------------------------ SEARCH SERVICE ----------------------- */
 
-int z_ElementSetName(ODR o, Z_ElementSetName **p, int opt)
+int z_ElementSetName(ODR o, char **p, int opt)
 {
     return odr_implicit(o, odr_visiblestring, (char**) p, ODR_CONTEXT, 103,
        opt);
@@ -111,7 +128,7 @@ int z_DatabaseSpecificUnit(ODR o, Z_DatabaseSpecificUnit **p, int opt)
 
 int z_DatabaseSpecific(ODR o, Z_DatabaseSpecific **p, int opt)
 {
-    if (o->direction == ODR_DECODE && !*p)
+    if (o->direction == ODR_DECODE)
        *p = nalloc(o, sizeof(**p));
     else if (!*p)
        return opt;
@@ -135,14 +152,14 @@ int z_ElementSetNames(ODR o, Z_ElementSetNames **p, int opt)
        {-1, -1, -1, -1, 0}
     };
 
-    if (!odr_constructed_begin(o, p, ODR_CONTEXT, 19, 0))
+    if (!odr_constructed_begin(o, p, ODR_CONTEXT, 19))
        return opt;
 
-    if (o->direction == ODR_DECODE && !*p)
+    if (o->direction == ODR_DECODE)
        *p = nalloc(o, sizeof(**p));
 
     if (odr_choice(o, arm, &(*p)->u, &(*p)->which) &&
-       odr_constructed_enmd(o))
+       odr_constructed_end(o))
        return 1;
     *p = 0;
     return 0;
@@ -150,18 +167,68 @@ int z_ElementSetNames(ODR o, Z_ElementSetNames **p, int opt)
 
 /* ----------------------- RPN QUERY -----------------------*/
 
-int z_RPNStructure(ODR o, Z_RPNStructure, int opt);
+int z_AttributeElement(ODR o, Z_AttributeElement **p, int opt)
+{
+    if (!odr_sequence_begin(o, p, sizeof(**p)))
+       return opt;
+    return
+       odr_implicit(o, odr_integer, &(*p)->attributeType, ODR_CONTEXT,
+           120, 1) &&
+       odr_implicit(o, odr_integer, &(*p)->attributeValue, ODR_CONTEXT,
+           121, 1) &&
+       odr_sequence_end(o);
+}
+
+int z_AttributesPlusTerm(ODR o, Z_AttributesPlusTerm **p, int opt)
+{
+    if (!(odr_implicit_settag(o, ODR_CONTEXT, 102) &&
+       odr_sequence_begin(o, p, sizeof(**p))))
+       return opt;
+    return
+       odr_implicit_settag(o, ODR_CONTEXT, 44) &&
+       odr_sequence_of(o, z_AttributeElement, &(*p)->attributeList,
+           &(*p)->num_attributes) &&
+       odr_implicit(o, odr_octetstring, &(*p)->term, ODR_CONTEXT, 45, 0) &&
+       odr_sequence_end(o);
+}
+
+int z_Operator(ODR o, Z_Operator **p, int opt)
+{
+    static Odr_arm arm[] =
+    {
+       {ODR_IMPLICIT, ODR_CONTEXT, 0, Z_Operator_and, odr_null},
+       {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_Operator_or, odr_null},
+       {ODR_IMPLICIT, ODR_CONTEXT, 2, Z_Operator_and_not, odr_null},
+       {-1, -1, -1, -1, 0}
+    };
+    int dummy = 999;
+
+    if (!*p && o->direction != ODR_DECODE)
+       return opt;
+    if (!odr_constructed_begin(o, p, ODR_CONTEXT, 46))
+       return opt;
+    if (o->direction == ODR_DECODE)
+       *p = nalloc(o, sizeof(**p));
+    else
+       (*p)->u.and = &dummy;
+
+    if (odr_choice(o, arm, &(*p)->u, &(*p)->which) &&
+       odr_constructed_end(o))
+       return 1;
+    *p = 0;
+    return opt;
+}
 
 int z_Operand(ODR o, Z_Operand **p, int opt)
 {
-    Odr_arm arm[] =
+    static Odr_arm arm[] =
     {
        {-1, -1, -1, Z_Operand_APT, z_AttributesPlusTerm},
        {-1, -1, -1, Z_Operand_resultSetId, z_ResultSetId},
        {-1, -1, -1, -1, 0}
     };
 
-    if (o->direction ==ODR_DECODE && !*p)
+    if (o->direction ==ODR_DECODE)
        *p = nalloc(o, sizeof(**p));
     else if (!*p)
        return opt;
@@ -171,6 +238,8 @@ int z_Operand(ODR o, Z_Operand **p, int opt)
     return opt;
 }
 
+int z_RPNStructure(ODR o, Z_RPNStructure **p, int opt);
+
 int z_Complex(ODR o, Z_Complex **p, int opt)
 {
     if (!odr_sequence_begin(o, p, sizeof(**p)))
@@ -178,20 +247,20 @@ int z_Complex(ODR o, Z_Complex **p, int opt)
     return
        z_RPNStructure(o, &(*p)->s1, 0) &&
        z_RPNStructure(o, &(*p)->s2, 0) &&
-       z_Operator(o, &(*p)->operator) &&
+       z_Operator(o, &(*p)->operator, 0) &&
        odr_sequence_end(o);
 }
 
-int z_RPNStructure(ODR o, Z_RPNStructure, int opt)
+int z_RPNStructure(ODR o, Z_RPNStructure **p, int opt)
 {
-    Odr_arm arm[] = 
+    static Odr_arm arm[] = 
     {
-       {ODR_IMPLICIT, ODR_CONTEXT, 0, Z_RPNStructure_simple, z_Operand),
+       {ODR_EXPLICIT, ODR_CONTEXT, 0, Z_RPNStructure_simple, z_Operand},
        {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_RPNStructure_complex, z_Complex},
        {-1 -1, -1, -1, 0}
     };
 
-    if (o->direction == ODR_DECODE && !*p)
+    if (o->direction == ODR_DECODE)
        *p = nalloc(o, sizeof(**p));
     else if (!*p)
        return opt;
@@ -203,7 +272,7 @@ int z_RPNStructure(ODR o, Z_RPNStructure, int opt)
 
 int z_RPNQuery(ODR o, Z_RPNQuery **p, int opt)
 {
-    if (!odr_sequence_begin(o, p, sizeof(**p))
+    if (!odr_sequence_begin(o, p, sizeof(**p)))
        return opt;
     return
        odr_oid(o, &(*p)->attributeSetId, 0) &&
@@ -215,15 +284,15 @@ int z_RPNQuery(ODR o, Z_RPNQuery **p, int opt)
 
 int z_Query(ODR o, Z_Query **p, int opt)
 {
-    Odr_arm arm[] = 
+    static Odr_arm arm[] = 
     {
        {ODR_IMPLICIT, ODR_CONTEXT, 1, Z_Query_type_1, z_RPNQuery},
-       {ODR_IMPLICIT, ODR_CONTEXT, 2, Z_Query_type_2, odr_oct},
+       {ODR_IMPLICIT, ODR_CONTEXT, 2, Z_Query_type_2, odr_octetstring},
        {-1, -1, -1, -1, 0}
     };
 
-    if (o->direction == ODR_DECODE && !*p)
-       *p = nalloc(o, sizeof(**p);
+    if (o->direction == ODR_DECODE)
+       *p = nalloc(o, sizeof(**p));
     else if (!*p)
        return opt;
     if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
@@ -250,27 +319,179 @@ int z_SearchRequest(ODR o, Z_SearchRequest **p, int opt)
        odr_implicit(o, odr_bool, &pp->replaceIndicator, ODR_CONTEXT, 16, 1) &&
        odr_implicit(o, odr_visiblestring, &pp->resultSetName, ODR_CONTEXT,
            17, 9) &&
+       odr_implicit_settag(o, ODR_CONTEXT, 18) &&
+       odr_sequence_of(o, z_DatabaseName, &pp->databaseNames,
+           &pp->num_databaseNames) &&
        odr_implicit(o, z_ElementSetNames, &pp->smallSetElementSetNames,
            ODR_CONTEXT, 100, 1) &&
        odr_implicit(o, z_ElementSetNames, &pp->mediumSetElementSetNames,
            ODR_CONTEXT, 101, 1) &&
        z_PreferredRecordSyntax(o, &pp->preferredRecordSyntax, 1) &&
-       odr_explicit(o, z_query, ODR_CONTEXT, 21, 0) &&
+       odr_explicit(o, z_Query, &pp->query, ODR_CONTEXT, 21, 0) &&
+       odr_sequence_end(o);
+}
+
+/* ------------------------ RECORD ------------------------- */
+
+int z_DatabaseRecord(ODR o, Z_DatabaseRecord **p, int opt)
+{
+    return odr_external(o, (Odr_external **) p, opt);
+}
+
+int z_DiagRec(ODR o, Z_DiagRec **p, int opt)
+{
+    if (!odr_sequence_begin(o, p, sizeof(**p)))
+       return opt;
+    return
+       odr_oid(o, &(*p)->diagnosticSetId, 1) &&       /* SHOULD NOT BE OPT */
+       odr_integer(o, &(*p)->condition, 0) &&
+       (odr_visiblestring(o, &(*p)->addinfo, 0) ||
+       odr_implicit(o, odr_cstring, &(*p)->addinfo, ODR_CONTEXT, ODR_VISIBLESTRING, 1)) &&
+       odr_sequence_end(o);
+}
+
+int z_NamePlusRecord(ODR o, Z_NamePlusRecord **p, int opt)
+{
+    static Odr_arm arm[] =
+    {
+       {ODR_EXPLICIT, ODR_CONTEXT, 1, Z_NamePlusRecord_databaseRecord,
+           z_DatabaseRecord},
+       {ODR_EXPLICIT, ODR_CONTEXT, 2, Z_NamePlusRecord_surrogateDiagnostic,
+           z_DiagRec},
+       {-1, -1, -1, -1, 0}
+    };
+
+    if (!odr_sequence_begin(o, p, sizeof(**p)))
+       return opt;
+    return
+       odr_implicit(o, z_DatabaseName, &(*p)->databaseName, ODR_CONTEXT,
+           0, 1) &&
+       odr_constructed_begin(o, &(*p)->u, ODR_CONTEXT, 1) &&
+       odr_choice(o, arm, &(*p)->u, &(*p)->which) &&
+       odr_constructed_end(o) &&
        odr_sequence_end(o);
 }
 
+int z_NamePlusRecordList(ODR o, Z_NamePlusRecordList **p, int opt)
+{
+    if (o->direction == ODR_DECODE)
+       *p = nalloc(o, sizeof(**p));
+    if (odr_sequence_of(o, z_NamePlusRecordList, &(*p)->records,
+       &(*p)->num_records))
+       return 1;
+    *p = 0;
+    return 0;
+}
+
+int z_Records(ODR o, Z_Records **p, int opt)
+{
+    Odr_arm arm[] = 
+    {
+       {ODR_IMPLICIT, ODR_CONTEXT, 28, Z_Records_DBOSD, z_NamePlusRecordList},
+       {ODR_IMPLICIT, ODR_CONTEXT, 130, Z_Records_NSD, z_DiagRec},
+       {-1, -1, -1, -1, 0}
+    };
+
+    if (o->direction == ODR_DECODE)
+       *p = nalloc(o, sizeof(**p));
+    else if (!*p)
+       return opt;
+    if (odr_choice(o, arm, &(*p)->u, &(*p)->which))
+       return 1;
+    *p = 0;
+    return opt;
+}
+
+/* ------------------------ SEARCHRESPONSE ----------------*/
+
+int z_NumberOfRecordsReturned(ODR o, int **p, int opt)
+{
+    return odr_implicit(o, odr_integer, p, ODR_CONTEXT, 24, opt);
+}
+
+int z_NextResultSetPosition(ODR o, int **p, int opt)
+{
+    return odr_implicit(o, odr_integer, p, ODR_CONTEXT, 25, opt);
+}
+
+int z_PresentStatus(ODR o, int **p, int opt)
+{
+    return odr_implicit(o, odr_integer, p, ODR_CONTEXT, 27, opt);
+}
+
+int z_SearchResponse(ODR o, Z_SearchResponse **p, int opt)
+{
+    Z_SearchResponse *pp;
+
+    if (!odr_sequence_begin(o, p, sizeof(**p)))
+       return opt;
+    pp = *p;
+    return
+       z_ReferenceId(o, &pp->referenceId, 1) &&
+       odr_implicit(o, odr_integer, &pp->resultCount, ODR_CONTEXT, 23, 0) &&
+       z_NumberOfRecordsReturned(o, &pp->numberOfRecordsReturned, 0) &&
+       z_NextResultSetPosition(o, &pp->nextResultSetPosition, 0) &&
+       odr_implicit(o, odr_bool, &pp->searchStatus, ODR_CONTEXT, 22, 0) &&
+       odr_implicit(o, odr_integer, &pp->resultSetStatus, ODR_CONTEXT, 26, 1) &&
+       z_PresentStatus(o, &pp->presentStatus, 1) &&
+       z_Records(o, &pp->records, 1) &&
+       odr_sequence_end(o);
+}
+
+/* --------------------- PRESENT SERVICE ---------------------- */
+
+int z_PresentRequest(ODR o, Z_PresentRequest **p, int opt)
+{
+    Z_PresentRequest *pp;
+
+    if (!odr_sequence_begin(o, p, sizeof(**p)))
+       return opt;
+    pp = *p;
+    return
+       z_ReferenceId(o, &pp->referenceId, 1) &&
+       z_ResultSetId(o, &pp->resultSetId, 0) &&
+       odr_implicit(o, odr_integer, &pp->resultSetStartPoint, ODR_CONTEXT,
+           30, 0) &&
+       odr_implicit(o, odr_integer, &pp->numberOfRecordsRequested, ODR_CONTEXT,
+           29, 0) &&
+       z_ElementSetNames(o, &pp->elementSetNames, 1) &&
+       z_PreferredRecordSyntax(o, &pp->preferredRecordSyntax, 1) &&
+       odr_sequence_end(o);
+}
+
+int z_PresentResponse(ODR o, Z_PresentResponse **p, int opt)
+{
+    Z_PresentResponse *pp;
+
+    if (!odr_sequence_begin(o, p, sizeof(**p)))
+       return opt;
+    pp = *p;
+    return
+       z_ReferenceId(o, &pp->referenceId, 1) &&
+       z_NumberOfRecordsReturned(o, &pp->numberOfRecordsReturned, 0) &&
+       z_NextResultSetPosition(o, &pp->nextResultSetPosition, 0) &&
+       z_PresentStatus(o, &pp->presentStatus, 0) &&
+       z_Records(o, &pp->records, 1) &&
+       odr_sequence_end(o);
+}
+
+/* ------------------------ APDU ------------------------- */
+
 int z_APDU(ODR o, Z_APDU **p, int opt)
 {
     static Odr_arm arm[] =
     {
-       {ODR_IMPLICIT, ODR_CONTEXT, 20, Z_APDU_InitRequest, z_InitRequest},
-       {ODR_IMPLICIT, ODR_CONTEXT, 21, Z_APDU_InitResponse, z_InitResponse},
-       {ODR_IMPLICIT, ODR_CONTEXT, 22, Z_APDU_SearchRequest, z_SearchRequest},
+       {ODR_IMPLICIT, ODR_CONTEXT, 20, Z_APDU_initRequest, z_InitRequest},
+       {ODR_IMPLICIT, ODR_CONTEXT, 21, Z_APDU_initResponse, z_InitResponse},
+       {ODR_IMPLICIT, ODR_CONTEXT, 22, Z_APDU_searchRequest, z_SearchRequest},
+       {ODR_IMPLICIT, ODR_CONTEXT, 23, Z_APDU_searchResponse, z_SearchResponse},
+       {ODR_IMPLICIT, ODR_CONTEXT, 24, Z_APDU_presentRequest, z_PresentRequest},
+       {ODR_IMPLICIT, ODR_CONTEXT, 25, Z_APDU_presentResponse, z_PresentResponse},
 
        {-1, -1, -1, -1, 0}
     };
 
-    if (o->direction == ODR_DECODE && !*p)
+    if (o->direction == ODR_DECODE)
        *p = nalloc(o, sizeof(**p));
     if (!odr_choice(o, arm, &(*p)->u, &(*p)->which))
     {
index 8b5a4a8..8472c5b 100644 (file)
@@ -1,23 +1,23 @@
 # Copyright (C) 1994, Index Data I/S 
 # All rights reserved.
 # Sebastian Hammer, Adam Dickmeiss
-# $Id: Makefile,v 1.1 1995-02-07 17:53:43 quinn Exp $
+# $Id: Makefile,v 1.2 1995-02-09 15:51:45 quinn Exp $
 
 SHELL=/bin/sh
 INCLUDE=-I../include -I.
-CFLAGS=-g -Wall -pedantic
+CFLAGS= -g -Wall -pedantic -ansi -DODR_DEBUG
 DEFS=$(INCLUDE)
 LIB=odr.a
 PO = odr_bool.o ber_bool.o ber_len.o ber_tag.o odr_util.o odr_null.o \
        ber_null.o odr_int.o ber_int.o odr_tag.o odr_cons.o odr_seq.o\
        odr_oct.o ber_oct.o odr_bit.o ber_bit.o odr_oid.o ber_oid.o odr_use.o \
-       odr_choice.o
+       odr_choice.o odr_any.o ber_any.o
 CPP=cc -E
 
 all: $(LIB) test
 
 test: test.o $(LIB)
-       cc $(CFLAGS) $(INCLUDE) -o test test.o $(LIB)
+       $(CC) $(CFLAGS) $(INCLUDE) -o test test.o $(LIB)
 
 alll:
 
diff --git a/odr/ber_any.c b/odr/ber_any.c
new file mode 100644 (file)
index 0000000..8c661f0
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 1994, Index Data I/S 
+ * All rights reserved.
+ * Sebastian Hammer, Adam Dickmeiss
+ *
+ * $Log: ber_any.c,v $
+ * Revision 1.1  1995-02-09 15:51:45  quinn
+ * Works better now.
+ *
+ */
+
+#include <odr.h>
+
+int ber_any(ODR o, Odr_any **p)
+{
+    int res;
+
+    switch (o->direction)
+    {
+       case ODR_DECODE:
+           if ((res = completeBER(o->bp, o->left)) <= 0)
+               return 0;
+           (*p)->buf = nalloc(o, res);
+           memcpy((*p)->buf, o->bp, res);
+           (*p)->len = (*p)->size = res;
+           o->bp += res;
+           o->left -= res;
+           return 1;
+       case ODR_ENCODE:
+           if ((*p)->len > o->left)
+               return 0;
+           memcpy(o->bp , (*p)->buf, (*p)->len);
+           o->bp += (*p)->len;
+           o->left -= (*p)->len;
+           return 1;
+       default: return 0;
+    }
+}
+
+/*
+ * Return length of BER-package or -1.
+ */
+int completeBER(unsigned char *buf, int len)
+{
+    int res, ll, class, tag, cons;
+    unsigned char *b = buf;
+    
+    if (!buf[0] && !buf[1])
+       return -1;
+    if ((res = ber_dectag(b, &class, &tag, &cons)) <= 0)
+       return 0;
+    if (res > len)
+       return -1;
+    b += res;
+    len -= res;
+    if ((res = ber_declen(b, &ll)) <= 0)
+       return -1;
+    if (res > len)
+       return -1;
+    b += res;
+    len -= res;
+    if (ll >= 0)
+       return (len >= ll ? len + (b-buf) : -1);
+    if (!cons)
+       return -1;    
+    while (1)
+    {
+       if ((res = completeBER(b, len)) < 0)
+           return -1;
+       b += res;
+       len -= res;
+       if (len < 2)
+           return -1;
+       if (*b == 0 && *(b + 1) == 0)
+           return (b - buf) + 2;
+    }
+}
index f50fdb6..205854a 100644 (file)
@@ -4,7 +4,10 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: ber_bool.c,v $
- * Revision 1.1  1995-02-02 16:21:51  quinn
+ * Revision 1.2  1995-02-09 15:51:45  quinn
+ * Works better now.
+ *
+ * Revision 1.1  1995/02/02  16:21:51  quinn
  * First kick.
  *
  */
@@ -26,7 +29,9 @@ int ber_boolean(ODR o, int *val)
            o->bp++;
            o->left--;
            *(o->bp++) = (unsigned char) *val;
+#ifdef ODR_DEBUG
            fprintf(stderr, "[val=%d]\n", *val);
+#endif
            o->left--;
            return 1;
        case ODR_DECODE:
@@ -39,7 +44,9 @@ int ber_boolean(ODR o, int *val)
            *val = *b;
            o->bp++;
            o->left--;
+#ifdef ODR_DEBUG
            fprintf(stderr, "[val=%d]\n", *val);
+#endif
            return 1;
        case ODR_PRINT:
            return 1;
index b262781..a5a8805 100644 (file)
@@ -4,7 +4,10 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: ber_int.c,v $
- * Revision 1.2  1995-02-07 17:52:58  quinn
+ * Revision 1.3  1995-02-09 15:51:46  quinn
+ * Works better now.
+ *
+ * Revision 1.2  1995/02/07  17:52:58  quinn
  * A damn mess, but now things work, I think.
  *
  * Revision 1.1  1995/02/02  16:21:52  quinn
@@ -66,7 +69,9 @@ int ber_encinteger(unsigned char *buf, int val, int maxlen)
     b += len;
     if (ber_enclen(lenpos, len, 1, 1) != 1)
        return -1;
+#ifdef ODR_DEBUG
     fprintf(stderr, "[val=%d]", val);
+#endif
     return b - buf;
 }
 
@@ -95,6 +100,8 @@ int ber_decinteger(unsigned char *buf, int *val)
     *val = ntohl(tmp.i);
 
     b += len;
+#ifdef ODR_DEBUG
     fprintf(stderr, "[val=%d]", *val);
+#endif
     return b - buf;
 }
index 44b0f6a..e8bf070 100644 (file)
@@ -15,11 +15,15 @@ int ber_enclen(unsigned char *buf, int len, int lenlen, int exact)
     unsigned char octs[sizeof(int)];
     int n = 0;
 
+#ifdef ODR_DEBUG
     fprintf(stderr, "[len=%d]", len);
+#endif
     if (len < 0)      /* Indefinite */
     {
        *b = 0X80;
+#ifdef ODR_DEBUG
        fprintf(stderr, "[indefinite]");
+#endif
        return 0;
     }
     if (len <= 127 && (lenlen == 1 || !exact)) /* definite short form */
@@ -65,13 +69,17 @@ int ber_declen(unsigned char *buf, int *len)
     if (*b == 0X80)     /* Indefinite */
     {
        *len = -1;
+#ifdef ODR_DEBUG
        fprintf(stderr, "[len=%d]", *len);
+#endif
        return 1;
     }
     if (!(*b & 0X80))   /* Definite short form */
     {
        *len = (int) *b;
+#ifdef ODR_DEBUG
        fprintf(stderr, "[len=%d]", *len);
+#endif
        return 1;
     }
     if (*b == 0XFF)     /* reserved value */
@@ -85,6 +93,8 @@ int ber_declen(unsigned char *buf, int *len)
        *len <<= 8;
        *len |= *(b++);
     }
+#ifdef ODR_DEBUG
     fprintf(stderr, "[len=%d]", *len);
+#endif
     return (b - buf);
 }
index b650c87..8543f7f 100644 (file)
@@ -4,7 +4,10 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: ber_null.c,v $
- * Revision 1.1  1995-02-02 16:21:52  quinn
+ * Revision 1.2  1995-02-09 15:51:46  quinn
+ * Works better now.
+ *
+ * Revision 1.1  1995/02/02  16:21:52  quinn
  * First kick.
  *
  */
@@ -21,13 +24,17 @@ int ber_null(ODR o, int *val)
        case ODR_ENCODE:
            *(o->bp++) = 0X00;
            o->left--;
+#ifdef ODR_DEBUG
            fprintf(stderr, "[NULL]\n");
+#endif
            return 1;
        case ODR_DECODE:
            if (*(o->bp++) != 0X00)
                return 0;
            o->left--;
+#ifdef ODR_DEBUG
            fprintf(stderr, "[NULL]\n");
+#endif
            return 1;
        case ODR_PRINT: return 1;
        default: return 0;
index 8c524c0..fd23a96 100644 (file)
@@ -4,7 +4,10 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: ber_tag.c,v $
- * Revision 1.2  1995-02-07 17:52:59  quinn
+ * Revision 1.3  1995-02-09 15:51:46  quinn
+ * Works better now.
+ *
+ * Revision 1.2  1995/02/07  17:52:59  quinn
  * A damn mess, but now things work, I think.
  *
  * Revision 1.1  1995/02/02  16:21:53  quinn
@@ -30,6 +33,8 @@ int ber_tag(ODR o, const void *p, int class, int tag, int *constructed)
     int rd;
 
     o->t_class = -1;
+    if (o->buf == o->bp)   /* This is insurance. It shouldn't be necessary */
+       lclass = -1;
     switch (o->direction)
     {
        case ODR_ENCODE:
@@ -40,16 +45,20 @@ int ber_tag(ODR o, const void *p, int class, int tag, int *constructed)
                return -1;
            o->bp += rd;
            o->left -= rd;
+#ifdef ODR_DEBUG
            fprintf(stderr, "\n[class=%d,tag=%d,cons=%d]", class, tag,
                *constructed);
+#endif
            return 1;
        case ODR_DECODE:
            if (lclass < 0)
            {
                if ((br = ber_dectag(o->bp, &lclass, &ltag, &lcons)) <= 0)
                    return -1;
+#ifdef ODR_DEBUG
                fprintf(stderr, "\n[class=%d,tag=%d,cons=%d]", lclass, ltag,
                    lcons);
+#endif
            }
            if (class == lclass && tag == ltag)
            {
diff --git a/odr/odr_any.c b/odr/odr_any.c
new file mode 100644 (file)
index 0000000..018c8e5
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 1994, Index Data I/S 
+ * All rights reserved.
+ * Sebastian Hammer, Adam Dickmeiss
+ *
+ * $Log: odr_any.c,v $
+ * Revision 1.1  1995-02-09 15:51:47  quinn
+ * Works better now.
+ *
+ */
+
+#include <odr.h>
+
+/*
+ * This is a catch-all type. It stuffs a random ostring (assumed to be properly
+ * encoded) into the stream, or reads a full data element. Implicit tagging
+ * does not work, and neither does the optional flag, unless the element
+ * is the last in a sequence.
+ */
+int odr_any(ODR o, Odr_any **p, int opt)
+{
+    if (o->direction == ODR_ENCODE && !*p)
+       return opt;
+    if (o->direction == ODR_PRINT)
+    {
+       fprintf(o->print, "%sANY (len=%d)\n", odr_indent(o), (*p)->len);
+       return 1;
+    }
+    if (o->direction == ODR_DECODE)
+       *p = nalloc(o, sizeof(**p));
+    if (ber_any(o, p))
+       return 1;
+    *p = 0;
+    return opt;
+}    
index aba4f3b..b3dacbd 100644 (file)
@@ -4,7 +4,10 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: odr_bit.c,v $
- * Revision 1.3  1995-02-07 14:13:45  quinn
+ * Revision 1.4  1995-02-09 15:51:47  quinn
+ * Works better now.
+ *
+ * Revision 1.3  1995/02/07  14:13:45  quinn
  * Bug fixes.
  *
  * Revision 1.2  1995/02/03  17:04:37  quinn
@@ -32,6 +35,8 @@ int odr_bitstring(ODR o, Odr_bitmask **p, int opt)
        o->t_class = ODR_UNIVERSAL;
        o->t_tag = ODR_BITSTRING;
     }
+    if (o->direction == ODR_DECODE)
+       *p = 0;
     if ((res = ber_tag(o, *p, o->t_class, o->t_tag, &cons)) < 0)
        return 0;
     if (!res)
@@ -41,7 +46,7 @@ int odr_bitstring(ODR o, Odr_bitmask **p, int opt)
     }
     if (o->direction == ODR_PRINT)
     {
-       fprintf(o->print, "BITSTRING(len=%d)\n", (*p)->top + 1);
+       fprintf(o->print, "%sBITSTRING(len=%d)\n", odr_indent(o), (*p)->top + 1);
        return 1;
     }
     if (o->direction == ODR_DECODE)
index e16bf52..bc21834 100644 (file)
@@ -4,7 +4,10 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: odr_bool.c,v $
- * Revision 1.1  1995-02-02 16:21:53  quinn
+ * Revision 1.2  1995-02-09 15:51:47  quinn
+ * Works better now.
+ *
+ * Revision 1.1  1995/02/02  16:21:53  quinn
  * First kick.
  *
  */
@@ -25,6 +28,8 @@ int odr_bool(ODR o, int **p, int opt)
        o->t_class = ODR_UNIVERSAL;
        o->t_tag = ODR_BOOLEAN;
     }
+    if (o->direction == ODR_DECODE)
+       *p = 0;
     if ((res = ber_tag(o, *p, o->t_class, o->t_tag, &cons)) < 0)
        return 0;
     if (!res)
index 0866311..f54711a 100644 (file)
@@ -4,7 +4,10 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: odr_choice.c,v $
- * Revision 1.1  1995-02-07 17:52:59  quinn
+ * Revision 1.2  1995-02-09 15:51:48  quinn
+ * Works better now.
+ *
+ * Revision 1.1  1995/02/07  17:52:59  quinn
  * A damn mess, but now things work, I think.
  *
  */
@@ -15,7 +18,7 @@ int odr_choice(ODR o, Odr_arm arm[], void *p, int *which)
 {
     int i, cl = -1, tg, cn;
 
-    if (o->direction != ODR_DECODE && !*(char*)p)
+    if (o->direction != ODR_DECODE && !*(char**)p)
        return 0;
     for (i = 0; arm[i].fun; i++)
     {
index 608ee65..3fdae22 100644 (file)
@@ -4,7 +4,10 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: odr_cons.c,v $
- * Revision 1.2  1995-02-07 17:52:59  quinn
+ * Revision 1.3  1995-02-09 15:51:48  quinn
+ * Works better now.
+ *
+ * Revision 1.2  1995/02/07  17:52:59  quinn
  * A damn mess, but now things work, I think.
  *
  * Revision 1.1  1995/02/02  16:21:53  quinn
@@ -24,6 +27,8 @@ int odr_constructed_begin(ODR o, void *p, int class, int tag)
        o->t_class = class;
        o->t_tag = tag;
     }
+    if (o->direction == ODR_DECODE)
+       *(char**)p = 0;
     if ((res = ber_tag(o, *(char**)p, o->t_class, o->t_tag, &cons)) < 0)
        return 0;
     if (!res || !cons)
index ffb41af..5b303b6 100644 (file)
@@ -4,7 +4,10 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: odr_int.c,v $
- * Revision 1.2  1995-02-07 14:13:45  quinn
+ * Revision 1.3  1995-02-09 15:51:48  quinn
+ * Works better now.
+ *
+ * Revision 1.2  1995/02/07  14:13:45  quinn
  * Bug fixes.
  *
  * Revision 1.1  1995/02/02  16:21:53  quinn
@@ -27,6 +30,8 @@ int odr_integer(ODR o, int **p, int opt)
        o->t_class = ODR_UNIVERSAL;
        o->t_tag = ODR_INTEGER;
     }
+    if (o->direction == ODR_DECODE)
+       *p =0;
     if ((res = ber_tag(o, *p, o->t_class, o->t_tag, &cons)) < 0)
     {
        *p = 0;
@@ -39,7 +44,7 @@ int odr_integer(ODR o, int **p, int opt)
     }
     if (o->direction == ODR_PRINT)
     {
-       fprintf(o->print, "%d\n", **p);
+       fprintf(o->print, "%s%d\n", odr_indent(o), **p);
        return 1;
     }
     if (cons)
index a6985f2..2db7952 100644 (file)
@@ -4,7 +4,10 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: odr_null.c,v $
- * Revision 1.1  1995-02-02 16:21:54  quinn
+ * Revision 1.2  1995-02-09 15:51:49  quinn
+ * Works better now.
+ *
+ * Revision 1.1  1995/02/02  16:21:54  quinn
  * First kick.
  *
  */
@@ -25,6 +28,8 @@ int odr_null(ODR o, int **p, int opt)
        o->t_class = ODR_UNIVERSAL;
        o->t_tag = ODR_NULL;
     }
+    if (o->direction == ODR_DECODE)
+       *p =0;
     if ((res = ber_tag(o, *p, o->t_class, o->t_tag, &cons)) < 0)
        return 0;
     if (!res)
@@ -34,7 +39,7 @@ int odr_null(ODR o, int **p, int opt)
     }
     if (o->direction == ODR_PRINT)
     {
-       fprintf(o->print, "NULL\n");
+       fprintf(o->print, "%sNULL\n", odr_indent(o));
        return 1;
     }
     if (cons)
index 63f203c..7ff12e1 100644 (file)
@@ -4,7 +4,10 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: odr_oct.c,v $
- * Revision 1.4  1995-02-07 14:13:46  quinn
+ * Revision 1.5  1995-02-09 15:51:49  quinn
+ * Works better now.
+ *
+ * Revision 1.4  1995/02/07  14:13:46  quinn
  * Bug fixes.
  *
  * Revision 1.3  1995/02/03  17:04:38  quinn
@@ -33,6 +36,8 @@ int odr_octetstring(ODR o, Odr_oct **p, int opt)
        o->t_class = ODR_UNIVERSAL;
        o->t_tag = ODR_OCTETSTRING;
     }
+    if (o->direction == ODR_DECODE)
+       *p = 0;
     if ((res = ber_tag(o, *p, o->t_class, o->t_tag, &cons)) < 0)
     {
        *p = 0;
@@ -45,7 +50,7 @@ int odr_octetstring(ODR o, Odr_oct **p, int opt)
     }
     if (o->direction == ODR_PRINT)
     {
-       fprintf(o->print, "OCTETSTRING(len=%d)\n", (*p)->len);
+       fprintf(o->print, "%sOCTETSTRING(len=%d)\n", odr_indent(o), (*p)->len);
        return 1;
     }
     if (o->direction == ODR_DECODE)
@@ -55,7 +60,10 @@ int odr_octetstring(ODR o, Odr_oct **p, int opt)
        (*p)->len = 0;
        (*p)->buf = 0;
     }
-    return ber_octetstring(o, *p, cons);
+    if (ber_octetstring(o, *p, cons))
+       return 1;
+    *p = 0;
+    return 0;
 }
 
 /*
@@ -71,6 +79,8 @@ int odr_cstring(ODR o, char **p, int opt)
        o->t_class = ODR_UNIVERSAL;
        o->t_tag = ODR_OCTETSTRING;
     }
+    if (o->direction == ODR_DECODE)
+       *p = 0;
     if ((res = ber_tag(o, *p, o->t_class, o->t_tag, &cons)) < 0)
        return 0;
     if (!res)
@@ -80,7 +90,7 @@ int odr_cstring(ODR o, char **p, int opt)
     }
     if (o->direction == ODR_PRINT)
     {
-       fprintf(o->print, "'%s'\n", *p);
+       fprintf(o->print, "%s'%s'\n", odr_indent(o), *p);
        return 1;
     }
     t = nalloc(o, sizeof(Odr_oct));   /* wrapper for octstring */
index 780cbdd..44d88ca 100644 (file)
@@ -4,7 +4,10 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: odr_oid.c,v $
- * Revision 1.2  1995-02-07 14:13:46  quinn
+ * Revision 1.3  1995-02-09 15:51:49  quinn
+ * Works better now.
+ *
+ * Revision 1.2  1995/02/07  14:13:46  quinn
  * Bug fixes.
  *
  * Revision 1.1  1995/02/03  17:04:38  quinn
@@ -28,6 +31,8 @@ int odr_oid(ODR o, Odr_oid **p, int opt)
        o->t_class = ODR_UNIVERSAL;
        o->t_tag = ODR_OID;
     }
+    if (o->direction == ODR_DECODE)
+       *p =0;
     if ((res = ber_tag(o, *p, o->t_class, o->t_tag, &cons)) < 0)
     {
        *p = 0;
@@ -40,7 +45,7 @@ int odr_oid(ODR o, Odr_oid **p, int opt)
     }
     if (o->direction == ODR_PRINT)
     {
-       fprintf(o->print, "OID\n");
+       fprintf(o->print, "%sOID\n", odr_indent(o));
        return 1;
     }
     if (o->direction == ODR_DECODE)
index 48e4298..f135d85 100644 (file)
@@ -4,7 +4,10 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: odr_seq.c,v $
- * Revision 1.4  1995-02-07 17:53:00  quinn
+ * Revision 1.5  1995-02-09 15:51:49  quinn
+ * Works better now.
+ *
+ * Revision 1.4  1995/02/07  17:53:00  quinn
  * A damn mess, but now things work, I think.
  *
  * Revision 1.3  1995/02/07  14:13:46  quinn
@@ -19,6 +22,7 @@
  */
 
 #include <odr.h>
+#include <assert.h>
 
 int odr_sequence_begin(ODR o, void *p, int size)
 {
@@ -30,10 +34,17 @@ int odr_sequence_begin(ODR o, void *p, int size)
        o->t_tag = ODR_SEQUENCE;
     }
 
+    if (o->direction == ODR_DECODE)
+       *pp = 0;
     if (odr_constructed_begin(o, p, o->t_class, o->t_tag))
     {
        if (o->direction == ODR_DECODE && size)
            *pp = nalloc(o, size);
+       if (o->direction == ODR_PRINT)
+       {
+           fprintf(o->print, "%s{\n", odr_indent(o));
+           o->indent++;
+       }
        return 1;
     }
     else
@@ -42,6 +53,12 @@ int odr_sequence_begin(ODR o, void *p, int size)
 
 int odr_sequence_end(ODR o)
 {
+    if (o->direction == ODR_PRINT)
+    {
+       assert(o->indent > 0);
+       o->indent--;
+       fprintf(o->print, "%s}\n", odr_indent(o));
+    }
     return odr_constructed_end(o);    
 }
 
@@ -59,7 +76,7 @@ int odr_sequence_of(ODR o, Odr_fun type, void *p, int *num)
 {
     char ***pp = (char***) p;  /* for dereferencing */
     char **tmp;
-    char *dummy;
+    char *dummy = "Nothing";
     int size = 0, i;
 
     if (!odr_sequence_begin(o, &dummy, 0))
@@ -92,12 +109,11 @@ int odr_sequence_of(ODR o, Odr_fun type, void *p, int *num)
                (*num)++;
            }
            break;
-       case ODR_ENCODE:
+       case ODR_ENCODE: case ODR_PRINT:
            for (i = 0; i < *num; i++)
                if (!(*type)(o, *pp + i, 0))
                    return 0;
            break;
-       case ODR_PRINT: return 1;
        default: return 0;
     }
     return odr_sequence_end(o);
index 4d69073..d983de2 100644 (file)
@@ -4,7 +4,10 @@
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: odr_use.c,v $
- * Revision 1.1  1995-02-03 17:04:39  quinn
+ * Revision 1.2  1995-02-09 15:51:50  quinn
+ * Works better now.
+ *
+ * Revision 1.1  1995/02/03  17:04:39  quinn
  * Initial revision
  *
  */
 int odr_external(ODR o, Odr_external **p, int opt)
 {
     Odr_external *pp;
-    
+    static Odr_arm arm[] =
+    {
+       {ODR_EXPLICIT, ODR_CONTEXT, 0, ODR_EXTERNAL_single, odr_any},
+       {ODR_IMPLICIT, ODR_CONTEXT, 1, ODR_EXTERNAL_octet, odr_octetstring},
+       {ODR_IMPLICIT, ODR_CONTEXT, 2, ODR_EXTERNAL_arbitrary, odr_bitstring},
+       {-1, -1, -1, -1, 0}
+    };
+
     odr_implicit_settag(o, ODR_UNIVERSAL, ODR_EXTERNAL);
     if (!odr_sequence_begin(o, p, sizeof(Odr_external)))
        return opt;
@@ -24,8 +34,7 @@ int odr_external(ODR o, Odr_external **p, int opt)
        odr_oid(o, &pp->direct_reference, 1) &&
        odr_integer(o, &pp->indirect_reference, 1) &&
        odr_graphicstring(o, &pp->descriptor, 1) &&
-       odr_implicit(o, odr_octetstring, &pp->octet_aligned, ODR_CONTEXT,
-           1, 0) &&
+       odr_choice(o, arm, &pp->u, &pp->which) &&
        odr_sequence_end(o);
 }
 
index af26bae..16dc984 100644 (file)
@@ -2,7 +2,15 @@
 #include <stdlib.h>
 
 void *nalloc(ODR o, int size) { return malloc(size); }
-char *odr_indent(ODR o) {return "";}
+
+char *odr_indent(ODR o)
+{
+    static char buf[512];
+
+    memset(buf, ' ', 512);
+    buf[o->indent * 4] = 0;
+    return buf;
+}
 
 int odp_more_chunks(ODR o, unsigned char *base, int len)
 {
index 6da7b89..77506f9 100644 (file)
@@ -118,11 +118,14 @@ int main()
     o.buf = buf;
     o.bp=o.buf;
     o.left = o.buflen = 1024;
-    o.direction = ODR_ENCODE;
+    o.direction = ODR_PRINT;
+    o.print = stdout;
     o.t_class = -1;
 
     odr_oid(&o, &oidp1, 0);
 
+    exit(0);
+
     o.direction = ODR_DECODE;
     o.bp = o.buf;