RT1815: More const'ness improvements
[openssl.git] / crypto / asn1 / tasn_prn.c
index 1c0379564a22b5d16ea53328ade22f937c11ab8a..424d395aa4b1eb09c7ad1630a9401e7ae8923c81 100644 (file)
@@ -1,5 +1,5 @@
 /* tasn_prn.c */
-/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
+/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
  * project 2000.
  */
 /* ====================================================================
@@ -58,6 +58,7 @@
 
 
 #include <stddef.h>
+#include "cryptlib.h"
 #include <openssl/asn1.h>
 #include <openssl/asn1t.h>
 #include <openssl/objects.h>
@@ -66,8 +67,6 @@
 #include <openssl/x509v3.h>
 #include "asn1_locl.h"
 
-#include <string.h>
-
 /* Print routines.
  */
 
@@ -196,12 +195,25 @@ static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
        const ASN1_TEMPLATE *tt;
        const ASN1_EXTERN_FUNCS *ef;
        ASN1_VALUE **tmpfld;
+       const ASN1_AUX *aux = it->funcs;
+       ASN1_aux_cb *asn1_cb;
+       ASN1_PRINT_ARG parg;
        int i;
+       if (aux && aux->asn1_cb)
+               {
+               parg.out = out;
+               parg.indent = indent;
+               parg.pctx = pctx;
+               asn1_cb = aux->asn1_cb;
+               }
+       else asn1_cb = 0;
+
        if(*fld == NULL)
                {
                if (pctx->flags & ASN1_PCTX_FLAGS_SHOW_ABSENT)
                        {
-                       if (!nohdr && !asn1_print_fsname(out, indent, fname, sname, pctx))
+                       if (!nohdr && !asn1_print_fsname(out, indent,
+                                                       fname, sname, pctx))
                                return 0;
                        if (BIO_puts(out, "<ABSENT>\n") <= 0)
                                return 0;
@@ -283,6 +295,15 @@ static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
                                }
                        }
 
+               if (asn1_cb)
+                       {
+                       i = asn1_cb(ASN1_OP_PRINT_PRE, fld, it, &parg);
+                       if (i == 0)
+                               return 0;
+                       if (i == 2)
+                               return 1;
+                       }
+
                /* Print each field entry */
                for(i = 0, tt = it->templates; i < it->tcount; i++, tt++)
                        {
@@ -298,6 +319,13 @@ static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
                        if (BIO_printf(out, "%*s}\n", indent, "") < 0)
                                return 0;
                        }
+
+               if (asn1_cb)
+                       {
+                       i = asn1_cb(ASN1_OP_PRINT_POST, fld, it, &parg);
+                       if (i == 0)
+                               return 0;
+                       }
                break;
 
                default:
@@ -315,7 +343,7 @@ int asn1_template_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
        const char *sname, *fname;
        flags = tt->flags;
        if(pctx->flags & ASN1_PCTX_FLAGS_SHOW_FIELD_STRUCT_NAME)
-               sname = tt->item->sname;
+               sname = ASN1_ITEM_ptr(tt->item)->sname;
        else
                sname = NULL;
        if(pctx->flags & ASN1_PCTX_FLAGS_NO_FIELD_NAME)
@@ -326,6 +354,8 @@ int asn1_template_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
                {
                char *tname;
                ASN1_VALUE *skitem;
+               STACK_OF(ASN1_VALUE) *stack;
+
                /* SET OF, SEQUENCE OF */
                if (fname)
                        {
@@ -343,14 +373,15 @@ int asn1_template_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
                                        fname) <= 0)
                                return 0;
                        }
-               for(i = 0; i < sk_num((STACK *)*fld); i++)
+               stack = (STACK_OF(ASN1_VALUE) *)*fld;
+               for(i = 0; i < sk_ASN1_VALUE_num(stack); i++)
                        {
                        if ((i > 0) && (BIO_puts(out, "\n") <= 0))
                                return 0;
 
-                       skitem = (ASN1_VALUE *)sk_value((STACK *)*fld, i);
+                       skitem = sk_ASN1_VALUE_value(stack, i);
                        if (!asn1_item_print_ctx(out, &skitem, indent + 2,
-                                       tt->item, NULL, NULL, 1, pctx))
+                               ASN1_ITEM_ptr(tt->item), NULL, NULL, 1, pctx))
                                return 0;
                        }
                if (!i && BIO_printf(out, "%*s<EMPTY>\n", indent + 2, "") <= 0)
@@ -362,7 +393,7 @@ int asn1_template_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
                        }
                return 1;
                }
-       return asn1_item_print_ctx(out, fld, indent, tt->item,
+       return asn1_item_print_ctx(out, fld, indent, ASN1_ITEM_ptr(tt->item),
                                                        fname, sname, 0, pctx);
        }
 
@@ -370,8 +401,8 @@ static int asn1_print_fsname(BIO *out, int indent,
                        const char *fname, const char *sname,
                        const ASN1_PCTX *pctx)
        {
-       static char spaces[] = "                    ";
-       const int nspaces = sizeof(spaces) - 1;
+       static const char spaces[] = "                    ";
+       static const int nspaces = sizeof(spaces) - 1;
 
 #if 0
        if (!sname && !fname)
@@ -415,11 +446,11 @@ static int asn1_print_fsname(BIO *out, int indent,
        return 1;
        }
 
-static int asn1_print_boolean_ctx(BIO *out, const int bool,
+static int asn1_print_boolean_ctx(BIO *out, int boolval,
                                                        const ASN1_PCTX *pctx)
        {
        const char *str;
-       switch (bool)
+       switch (boolval)
                {
                case -1:
                str = "BOOL ABSENT";
@@ -478,7 +509,8 @@ static int asn1_print_obstring_ctx(BIO *out, ASN1_STRING *str, int indent,
                }
        else if (BIO_puts(out, "\n") <= 0)
                return 0;
-       if (BIO_dump_indent(out, (char *)str->data, str->length,
+       if ((str->length > 0)
+               && BIO_dump_indent(out, (char *)str->data, str->length,
                                indent + 2) <= 0)
                return 0;
        return 1;
@@ -493,8 +525,12 @@ static int asn1_primitive_print(BIO *out, ASN1_VALUE **fld,
        ASN1_STRING *str;
        int ret = 1, needlf = 1;
        const char *pname;
+       const ASN1_PRIMITIVE_FUNCS *pf;
+       pf = it->funcs;
        if (!asn1_print_fsname(out, indent, fname, sname, pctx))
                        return 0;
+       if (pf && pf->prim_print)
+               return pf->prim_print(out, fld, it, indent, pctx);
        str = (ASN1_STRING *)*fld;
        if (it->itype == ASN1_ITYPE_MSTRING)
                utype = str->type & ~V_ASN1_NEG;
@@ -504,7 +540,7 @@ static int asn1_primitive_print(BIO *out, ASN1_VALUE **fld,
                {
                ASN1_TYPE *atype = (ASN1_TYPE *)*fld;
                utype = atype->type;
-               fld = (ASN1_VALUE **)&atype->value.ptr;
+               fld = &atype->value.asn1_value;
                str = (ASN1_STRING *)*fld;
                if (pctx->flags & ASN1_PCTX_FLAGS_NO_ANY_TYPE)
                        pname = NULL;
@@ -538,10 +574,10 @@ static int asn1_primitive_print(BIO *out, ASN1_VALUE **fld,
                {
                case V_ASN1_BOOLEAN:
                        {
-                       int bool = *(int *)fld;
-                       if (bool == -1)
-                               bool = it->size;
-                       ret = asn1_print_boolean_ctx(out, bool, pctx);
+                       int boolval = *(int *)fld;
+                       if (boolval == -1)
+                               boolval = it->size;
+                       ret = asn1_print_boolean_ctx(out, boolval, pctx);
                        }
                break;