Home | History | Annotate | Line # | Download | only in asn1
      1 /*	$NetBSD: symbol.h,v 1.2 2017/01/28 21:31:45 christos Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1997 - 2005 Kungliga Tekniska Hgskolan
      5  * (Royal Institute of Technology, Stockholm, Sweden).
      6  * All rights reserved.
      7  *
      8  * Redistribution and use in source and binary forms, with or without
      9  * modification, are permitted provided that the following conditions
     10  * are met:
     11  *
     12  * 1. Redistributions of source code must retain the above copyright
     13  *    notice, this list of conditions and the following disclaimer.
     14  *
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  *
     19  * 3. Neither the name of the Institute nor the names of its contributors
     20  *    may be used to endorse or promote products derived from this software
     21  *    without specific prior written permission.
     22  *
     23  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
     24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
     27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33  * SUCH DAMAGE.
     34  */
     35 
     36 /* Id */
     37 
     38 #ifndef _SYMBOL_H
     39 #define _SYMBOL_H
     40 
     41 #include "asn1_queue.h"
     42 
     43 enum typetype {
     44     TBitString,
     45     TBoolean,
     46     TChoice,
     47     TEnumerated,
     48     TGeneralString,
     49     TTeletexString,
     50     TGeneralizedTime,
     51     TIA5String,
     52     TInteger,
     53     TNull,
     54     TOID,
     55     TOctetString,
     56     TPrintableString,
     57     TSequence,
     58     TSequenceOf,
     59     TSet,
     60     TSetOf,
     61     TTag,
     62     TType,
     63     TUTCTime,
     64     TUTF8String,
     65     TBMPString,
     66     TUniversalString,
     67     TVisibleString
     68 };
     69 
     70 typedef enum typetype Typetype;
     71 
     72 struct type;
     73 
     74 struct value {
     75     enum { booleanvalue,
     76 	   nullvalue,
     77 	   integervalue,
     78 	   stringvalue,
     79 	   objectidentifiervalue
     80     } type;
     81     union {
     82 	int booleanvalue;
     83 	int64_t integervalue;
     84 	char *stringvalue;
     85 	struct objid *objectidentifiervalue;
     86     } u;
     87 };
     88 
     89 struct member {
     90     char *name;
     91     char *gen_name;
     92     char *label;
     93     int val;
     94     int optional;
     95     int ellipsis;
     96     struct type *type;
     97     ASN1_TAILQ_ENTRY(member) members;
     98     struct value *defval;
     99 };
    100 
    101 typedef struct member Member;
    102 
    103 ASN1_TAILQ_HEAD(memhead, member);
    104 
    105 struct symbol;
    106 
    107 struct tagtype {
    108     int tagclass;
    109     int tagvalue;
    110     enum { TE_IMPLICIT, TE_EXPLICIT } tagenv;
    111 };
    112 
    113 struct range {
    114     /*
    115      * We can't represent unsigned 64-bit ranges because max might be
    116      * negative...
    117      */
    118     int64_t min;
    119     int64_t max;
    120 };
    121 
    122 enum ctype { CT_CONTENTS, CT_USER } ;
    123 
    124 struct constraint_spec;
    125 
    126 struct type {
    127     Typetype type;
    128     struct memhead *members;
    129     struct symbol *symbol;
    130     struct type *subtype;
    131     struct tagtype tag;
    132     struct range *range;
    133     struct constraint_spec *constraint;
    134     unsigned long id;
    135 };
    136 
    137 typedef struct type Type;
    138 
    139 struct constraint_spec {
    140     enum ctype ctype;
    141     union {
    142 	struct {
    143 	    Type *type;
    144 	    struct value *encoding;
    145 	} content;
    146     } u;
    147 };
    148 
    149 struct objid {
    150     const char *label;
    151     int value;
    152     struct objid *next;
    153 };
    154 
    155 struct symbol {
    156     char *name;
    157     char *gen_name;
    158     enum { SUndefined, SValue, Stype } stype;
    159     struct value *value;
    160     Type *type;
    161 };
    162 
    163 typedef struct symbol Symbol;
    164 
    165 void initsym (void);
    166 Symbol *addsym (char *);
    167 void output_name (char *);
    168 int checkundefined(void);
    169 #endif
    170