Objective Systems, Inc.  

ooasn1.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 1997-2009 by Objective Systems, Inc.
00003  *
00004  * This software is furnished under an open source license and may be
00005  * used and copied only in accordance with the terms of this license.
00006  * The text of the license may generally be found in the root
00007  * directory of this installation in the COPYING file.  It
00008  * can also be viewed online at the following URL:
00009  *
00010  *   http://www.obj-sys.com/open/license.html
00011  *
00012  * Any redistributions of this file including modified versions must
00013  * maintain this copyright notice.
00014  *
00015  *****************************************************************************/
00022 #ifndef _OOASN1_H_
00023 #define _OOASN1_H_
00024 
00025 #include <limits.h>
00026 #include <stdio.h>
00027 #include <string.h>
00028 #include <stddef.h>
00029 #include "dlist.h"
00030 #include "ootrace.h"
00036 /* Error Code Constants */
00037 
00038 #define ASN_OK            0      /* normal completion status             */
00039 #define ASN_OK_FRAG       2      /* message fragment detected            */
00040 #define ASN_E_BUFOVFLW   -1      /* encode buffer overflow               */
00041 #define ASN_E_ENDOFBUF   -2      /* unexpected end of buffer on decode   */
00042 #define ASN_E_IDNOTFOU   -3      /* identifer not found                  */
00043 #define ASN_E_INVOBJID   -4      /* invalid object identifier            */
00044 #define ASN_E_INVLEN     -5      /* invalid field length                 */
00045 #define ASN_E_INVENUM    -6      /* enumerated value not in defined set  */
00046 #define ASN_E_SETDUPL    -7      /* duplicate element in set             */
00047 #define ASN_E_SETMISRQ   -8      /* missing required element in set      */
00048 #define ASN_E_NOTINSET   -9      /* element not part of set              */
00049 #define ASN_E_SEQOVFLW   -10     /* sequence of field overflow           */
00050 #define ASN_E_INVOPT     -11     /* invalid option encountered in choice */
00051 #define ASN_E_NOMEM      -12     /* no dynamic memory available          */
00052 #define ASN_E_INVHEXS    -14     /* invalid hex string                   */
00053 #define ASN_E_INVBINS    -15     /* invalid binary string                */
00054 #define ASN_E_INVREAL    -16     /* invalid real value                   */
00055 #define ASN_E_STROVFLW   -17     /* octet or bit string field overflow   */
00056 #define ASN_E_BADVALUE   -18     /* invalid value specification          */
00057 #define ASN_E_UNDEFVAL   -19     /* no def found for ref'd defined value */
00058 #define ASN_E_UNDEFTYP   -20     /* no def found for ref'd defined type  */
00059 #define ASN_E_BADTAG     -21     /* invalid tag value                    */
00060 #define ASN_E_TOODEEP    -22     /* nesting level is too deep            */
00061 #define ASN_E_CONSVIO    -23     /* value constraint violation           */
00062 #define ASN_E_RANGERR    -24     /* invalid range (lower > upper)        */
00063 #define ASN_E_ENDOFFILE  -25     /* end of file on file decode           */
00064 #define ASN_E_INVUTF8    -26     /* invalid UTF-8 encoding               */
00065 #define ASN_E_CONCMODF   -27     /* Concurrent list modification         */
00066 #define ASN_E_ILLSTATE   -28     /* Illegal state error                  */
00067 #define ASN_E_OUTOFBND   -29     /* out of bounds (of array, etc)        */
00068 #define ASN_E_INVPARAM   -30     /* invalid parameter                    */
00069 #define ASN_E_INVFORMAT  -31     /* invalid time string format           */
00070 #define ASN_E_NOTINIT    -32     /* not initialized                      */
00071 #define ASN_E_TOOBIG     -33     /* value is too big for given data type */
00072 #define ASN_E_INVCHAR    -34     /* invalid character (not in char set)  */
00073 #define ASN_E_XMLSTATE   -35     /* XML state error                      */
00074 #define ASN_E_XMLPARSE   -36     /* XML parse error                      */
00075 #define ASN_E_SEQORDER   -37     /* SEQUENCE elements not in order       */
00076 #define ASN_E_INVINDEX   -38     /* invalid index for TC id              */
00077 #define ASN_E_INVTCVAL   -39     /* invalid value for TC field           */
00078 #define ASN_E_FILNOTFOU  -40     /* file not found                       */
00079 #define ASN_E_FILEREAD   -41     /* error occurred reading file          */
00080 #define ASN_E_FILEWRITE  -42     /* error occurred writing file          */
00081 #define ASN_E_INVBASE64  -43     /* invalid base64 encoding              */
00082 #define ASN_E_INVSOCKET  -44     /* invalid socket operation             */
00083 #define ASN_E_XMLLIBNFOU -45     /* XML library is not found             */
00084 #define ASN_E_XMLLIBINV  -46     /* XML library is invalid               */
00085 #define ASN_E_NOTSUPP    -99     /* non-supported ASN construct          */
00086 #define ASN_K_INDEFLEN   -9999   /* indefinite length message indicator  */
00087 
00088 /* universal built-in type ID code value constants */
00089 
00090 #define ASN_ID_EOC      0       /* end of contents              */
00091 #define ASN_ID_BOOL     1       /* boolean                      */
00092 #define ASN_ID_INT      2       /* integer                      */
00093 #define ASN_ID_BITSTR   3       /* bit string                   */
00094 #define ASN_ID_OCTSTR   4       /* byte (octet) string          */
00095 #define ASN_ID_NULL     5       /* null                         */
00096 #define ASN_ID_OBJID    6       /* object ID                    */
00097 #define ASN_ID_OBJDSC   7       /* object descriptor            */
00098 #define ASN_ID_EXTERN   8       /* external type                */
00099 #define ASN_ID_REAL     9       /* real                         */
00100 #define ASN_ID_ENUM     10      /* enumerated value             */
00101 #define ASN_ID_EPDV     11      /* EmbeddedPDV type             */
00102 #define ASN_ID_RELOID   13      /* relative object ID           */
00103 #define ASN_ID_SEQ      16      /* sequence, sequence of        */
00104 #define ASN_ID_SET      17      /* set, set of                  */
00105 
00106 #define ASN_SEQ_TAG     0x30    /* SEQUENCE universal tag byte  */
00107 #define ASN_SET_TAG     0x31    /* SET universal tag byte       */
00108 
00109 /* Restricted character string type ID's */
00110 
00111 #define ASN_ID_NumericString    18
00112 #define ASN_ID_PrintableString  19
00113 #define ASN_ID_TeletexString    20
00114 #define ASN_ID_T61String        ASN_ID_TeletexString
00115 #define ASN_ID_VideotexString   21
00116 #define ASN_ID_IA5String        22
00117 #define ASN_ID_UTCTime          23
00118 #define ASN_ID_GeneralTime      24
00119 #define ASN_ID_GraphicString    25
00120 #define ASN_ID_VisibleString    26
00121 #define ASN_ID_GeneralString    27
00122 #define ASN_ID_UniversalString  28
00123 #define ASN_ID_BMPString        30
00124 
00125 /* flag mask values */
00126 
00127 #define XM_SEEK         0x01    /* seek match until found or end-of-buf */
00128 #define XM_ADVANCE      0x02    /* advance pointer to contents on match */
00129 #define XM_DYNAMIC      0x04    /* alloc dyn mem for decoded variable   */
00130 #define XM_SKIP         0x08    /* skip to next field after parsing tag */
00131 
00132 /* Sizing Constants */
00133 
00134 #define ASN_K_MAXDEPTH  32      /* maximum nesting depth for messages   */
00135 #define ASN_K_MAXSUBIDS 128     /* maximum sub-id's in an object ID     */
00136 #define ASN_K_MAXENUM   100     /* maximum enum values in an enum type  */
00137 #define ASN_K_MAXERRP   5       /* maximum error parameters             */
00138 #define ASN_K_MAXERRSTK 8       /* maximum levels on error ctxt stack   */
00139 #define ASN_K_ENCBUFSIZ 2*1024 /* dynamic encode buffer extent size    */
00140 #define ASN_K_MEMBUFSEG 1024    /* memory buffer extent size            */
00141 
00142 /* Canonical character set definitions */
00143 
00144 #define NUM_ABITS  4
00145 #define NUM_UBITS  4
00146 #define NUM_CANSET \
00147 " 0123456789"
00148 
00149 #define PRN_ABITS  8
00150 #define PRN_UBITS  7
00151 #define PRN_CANSET \
00152 " '()+,-./0123456789:=?ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
00153 
00154 #define VIS_ABITS  8
00155 #define VIS_UBITS  7
00156 #define VIS_CANSET \
00157 " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]"\
00158 "^_`abcdefghijklmnopqrstuvwxyz{|}~"
00159 
00160 #define T61_ABITS  8
00161 #define T61_UBITS  7
00162 #define T61_CANSET \
00163 " !\"%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]"\
00164 "_abcdefghijklmnopqrstuvwxyz"
00165 
00166 #define IA5_ABITS  8
00167 #define IA5_UBITS  7
00168 #define IA5_CANSET \
00169 "\000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017"\
00170 "\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037"\
00171 " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]"\
00172 "^_`abcdefghijklmnopqrstuvwxyz{|}~"
00173 
00174 #define IA5_RANGE1_LOWER 0
00175 #define IA5_RANGE2_LOWER 0x5f
00176 
00177 #define GEN_ABITS  8
00178 #define GEN_UBITS  7
00179 #define GEN_CANSET \
00180 "\000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017"\
00181 "\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037"\
00182 " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_"\
00183 "`abcdefghijklmnopqrstuvwxyz{|}~\177\200\201\202\203\204\205\206\207"\
00184 "\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237"\
00185 "\240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257"\
00186 "\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277"\
00187 "\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317"\
00188 "\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337"\
00189 "\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357"\
00190 "\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377"
00191 
00192 #define BMP_ABITS  16
00193 #define BMP_UBITS  16
00194 #define BMP_FIRST  0
00195 #define BMP_LAST   0xffff
00196 
00197 #define UCS_ABITS  32
00198 #define UCS_UBITS  32
00199 #define UCS_FIRST  0
00200 #define UCS_LAST   0xfffffffful
00201 
00202 /* ASN.1 Primitive Type Definitions */
00203 
00204 typedef char            ASN1CHAR;
00205 typedef unsigned char   ASN1OCTET;
00206 typedef ASN1OCTET       ASN1BOOL;
00207 typedef signed char     ASN1INT8;
00208 typedef unsigned char   ASN1UINT8;
00209 typedef int             ASN1INT;
00210 typedef unsigned int    ASN1UINT;
00211 typedef ASN1INT         ASN1ENUM;
00212 typedef double          ASN1REAL;
00213 
00214 typedef short           ASN1SINT;
00215 typedef unsigned short  ASN1USINT;
00216 typedef ASN1UINT        ASN1TAG;
00217 #define ASN1TAG_LSHIFT  24
00218 typedef ASN1USINT       ASN116BITCHAR;
00219 typedef ASN1UINT        ASN132BITCHAR;
00220 typedef void*           ASN1ANY;
00221 
00222 #define ASN1UINT_MAX    4294967295U
00223 #define ASN1INT_MAX     ((ASN1INT)2147483647L)
00224 #define ASN1INT_MIN     ((ASN1INT)(-ASN1INT_MAX-1))
00225 
00226 #define ASN1UINTCNT(val) val##u
00227 
00228 
00229 #ifndef ASN1INT64
00230 
00231 #if defined(_MSC_VER) || defined(__BORLANDC__) || defined(__WATCOMC__) || \
00232 defined(_WIN32)
00233 #define ASN1INT64 __int64
00234 
00235 #elif defined(__IBMC__) || defined(__GNUC__) || defined(__SUNPRO_C) || \
00236 defined(__SUNPRO_CC) || defined(__CC_ARM) || \
00237 defined(__HPUX_CC__) || defined(__HP_aCC)
00238 #define ASN1INT64 long long
00239 
00240 #else  /* !MSC_VER && !__IBMC__ etc */
00241 #define ASN1INT64 long
00242 
00243 #endif
00244 #endif /* ASN1INT64 */
00245 
00246 #ifndef FALSE
00247 #define FALSE           0
00248 #define TRUE            1
00249 #endif
00250 
00251 typedef struct {        /* object identifier */
00252    ASN1UINT     numids;
00253    ASN1UINT     subid[ASN_K_MAXSUBIDS];
00254 } ASN1OBJID;
00255 
00256 typedef struct {        /* generic octet string structure */
00257    ASN1UINT     numocts;
00258    ASN1OCTET    data[1];
00259 } ASN1OctStr;
00260 
00261 typedef struct {        /* generic octet string structure (dynamic) */
00262    ASN1UINT     numocts;
00263    const ASN1OCTET* data;
00264 } ASN1DynOctStr;
00265 
00266 typedef struct {        /* generic bit string structure (dynamic) */
00267    ASN1UINT     numbits;
00268    const ASN1OCTET* data;
00269 } ASN1DynBitStr;
00270 
00271 typedef struct {  /* fixed-size bit string that can hold up to 32 bits */
00272    ASN1UINT     numbits;
00273    ASN1OCTET    data[4];
00274 } ASN1BitStr32;
00275 
00276 typedef struct {                /* generic sequence of structure        */
00277    ASN1UINT     n;
00278    void*        elem;
00279 } ASN1SeqOf;
00280 
00281 typedef struct {                /* sequence of OCTET STRING             */
00282    ASN1UINT     n;
00283    ASN1DynOctStr* elem;
00284 } ASN1SeqOfOctStr;
00285 
00286 typedef struct {                /* generic open type data structure     */
00287    ASN1UINT     numocts;
00288    const ASN1OCTET* data;
00289 } ASN1OpenType;
00290 
00291 /* ASN.1 useful type definitions */
00292 
00293 typedef struct {
00294    ASN1UINT       nchars;
00295    ASN116BITCHAR* data;
00296 } Asn116BitCharString;
00297 
00298 typedef struct {
00299    ASN1UINT       nchars;
00300    ASN132BITCHAR* data;
00301 } Asn132BitCharString;
00302 
00303 typedef const char*   ASN1GeneralizedTime;
00304 typedef const char*   ASN1GeneralString;
00305 typedef const char*   ASN1GraphicString;
00306 typedef const char*   ASN1IA5String;
00307 typedef const char*   ASN1ISO646String;
00308 typedef const char*   ASN1NumericString;
00309 typedef const char*   ASN1ObjectDescriptor;
00310 typedef const char*   ASN1PrintableString;
00311 typedef const char*   ASN1TeletexString;
00312 typedef const char*   ASN1T61String;
00313 typedef const char*   ASN1UTCTime;
00314 typedef const char*   ASN1UTF8String;
00315 typedef const char*   ASN1VideotexString;
00316 typedef const char*   ASN1VisibleString;
00317 
00318 typedef Asn116BitCharString ASN1BMPString;
00319 typedef Asn132BitCharString ASN1UniversalString;
00320 
00321 /* ASN.1 constrained string structures */
00322 
00323 typedef struct {
00324    int          nchars;
00325    char         data[255];
00326 } Asn1CharArray;
00327 
00328 typedef struct {
00329    Asn1CharArray charSet;
00330    const char* canonicalSet;
00331    int          canonicalSetSize;
00332    unsigned     canonicalSetBits;
00333    unsigned     charSetUnalignedBits;
00334    unsigned     charSetAlignedBits;
00335 } Asn1CharSet;
00336 
00337 typedef struct {
00338    Asn116BitCharString charSet;
00339    ASN1USINT    firstChar, lastChar;
00340    unsigned     unalignedBits;
00341    unsigned     alignedBits;
00342 } Asn116BitCharSet;
00343 
00344 /* ASN.1 size constraint structure */
00345 
00346 typedef struct _Asn1SizeCnst {
00347    ASN1BOOL     extended;
00348    ASN1UINT     lower;
00349    ASN1UINT     upper;
00350    struct _Asn1SizeCnst* next;
00351 } Asn1SizeCnst;
00352 
00353 /* ASN.1 encode/decode buffer info structure */
00354 
00355 typedef struct {
00356    ASN1OCTET*   data;           /* pointer to start of data buffer      */
00357    ASN1UINT     byteIndex;      /* byte index                           */
00358    ASN1UINT     size;           /* current buffer size                  */
00359    ASN1SINT     bitOffset;      /* current bit offset (8 - 1)           */
00360    ASN1BOOL     dynamic;        /* is buffer dynamic?                   */
00361 } ASN1BUFFER;
00362 
00363 /* This structure is used to save the current state of the buffer */
00364 
00365 typedef struct {
00366    ASN1UINT     byteIndex;      /* byte index                           */
00367    ASN1SINT     bitOffset;      /* current bit offset (8 - 1)           */
00368    ASN1USINT    flags;          /* flag bits                            */
00369 } ASN1BUFSAVE;
00370 
00371 /* ASN.1 run-time error info structures */
00372 
00373 typedef struct {
00374    const char* module;
00375    int          lineno;
00376 } ASN1ErrLocn;
00377 
00378 typedef struct {
00379    ASN1ErrLocn  stack[ASN_K_MAXERRSTK];
00380    int          stkx;
00381    int          status;
00382    int          parmcnt;
00383    const char* parms[ASN_K_MAXERRP];
00384 } ASN1ErrInfo;
00385 
00386 #define XM_K_MEMBLKSIZ  (4*1024)
00387 
00388 /* Flag mask constant values */
00389 
00390 #define ASN1DYNCTXT     0x8000
00391 #define ASN1INDEFLEN    0x4000
00392 #define ASN1TRACE       0x2000
00393 #define ASN1LASTEOC     0x1000
00394 #define ASN1FASTCOPY    0x0800  /* turns on the "fast copy" mode        */
00395 #define ASN1CONSTAG     0x0400  /* form of last parsed tag              */
00396 #define ASN1CANXER      0x0200  /* canonical XER                        */
00397 #define ASN1SAVEBUF     0x0100  /* do not free dynamic encode buffer    */
00398 #define ASN1OPENTYPE    0x0080  /* item is an open type field           */
00399 
00400 /* ASN.1 encode/decode context block structure */
00401 
00402 struct EventHandler;
00403 
00404 typedef struct OOCTXT {         /* context block                        */
00405    void*        pMsgMemHeap;    /* internal message memory heap         */
00406    void*        pTypeMemHeap;   /* memory heap                          */
00407    ASN1BUFFER   buffer;         /* data buffer                          */
00408    ASN1ErrInfo  errInfo;        /* run-time error info                  */
00409    Asn1SizeCnst* pSizeConstraint;  /* Size constraint list              */
00410    const char* pCharSet;        /* String of permitted characters       */
00411    struct EventHandler* pEventHandler; /* event handler object          */
00412    ASN1USINT    flags;          /* flag bits                            */
00413    ASN1OCTET    spare[2];
00414 } OOCTXT;
00415 
00416 /* macros and function prototypes */
00417 
00418 #ifndef ASN1MAX
00419 #define ASN1MAX(a,b)        (((a)>(b))?(a):(b))
00420 #endif
00421 
00422 #ifndef ASN1MIN
00423 #define ASN1MIN(a,b)        (((a)<(b))?(a):(b))
00424 #endif
00425 
00445 #define ALLOC_ASN1ARRAY(pctxt,pseqof,type) do {\
00446 if (sizeof(type)*(pseqof)->n < (pseqof)->n) return ASN_E_NOMEM; \
00447 if (((pseqof)->elem = (type*) memHeapAlloc \
00448 (&(pctxt)->pTypeMemHeap, sizeof(type)*(pseqof)->n)) == 0) return ASN_E_NOMEM; \
00449 } while (0)
00450 
00458 #define ALLOC_ASN1ELEM(pctxt,type) \
00459 (type*) memHeapAllocZ (&(pctxt)->pTypeMemHeap, sizeof(type))
00460 
00471 #define ASN1MALLOC(pctxt,nbytes) \
00472 memHeapAlloc(&(pctxt)->pTypeMemHeap, nbytes)
00473 
00482 #define ASN1MEMFREE(pctxt) \
00483 memHeapFreeAll(&(pctxt)->pTypeMemHeap)
00484 
00496 #define ASN1MEMFREEPTR(pctxt,pmem)  \
00497 memHeapFreePtr(&(pctxt)->pTypeMemHeap, (void*)pmem)
00498 
00502 #define ASN1BUFCUR(cp)          (cp)->buffer.data[(cp)->buffer.byteIndex]
00503 #define ASN1BUFPTR(cp)          &(cp)->buffer.data[(cp)->buffer.byteIndex]
00504 
00505 #ifdef __cplusplus
00506 extern "C" {
00507 #endif
00508 
00509 #ifndef EXTERN
00510 #ifdef MAKE_DLL
00511 #define EXTERN __declspec(dllexport)
00512 #elif defined (USEASN1DLL)
00513 #define EXTERN __declspec(dllimport)
00514 #else
00515 #define EXTERN
00516 #endif /* MAKE_DLL */
00517 #endif /* EXTERN */
00518 
00519 #ifndef _NO_MALLOC
00520 #define ASN1CRTMALLOC0(nbytes)       malloc(nbytes)
00521 #define ASN1CRTFREE0(ptr)            free(ptr)
00522 #else
00523 
00524 #ifdef _NO_THREADS
00525 extern EXTERN OOCTXT g_ctxt;
00526 
00527 #define ASN1CRTMALLOC0(nbytes)       memAlloc(&g_ctxt,(nbytes))
00528 #define ASN1CRTFREE0(ptr)            memFreePtr(&g_ctxt,(ptr))
00529 #else
00530 #define ASN1CRTMALLOC0(nbytes)       (void*)0
00531 #define ASN1CRTFREE0(ptr)            (void*)0
00532 
00533 #endif /* _NO_THREADS */
00534 #endif /* _NO_MALLOC */
00535 
00536 #define ASN1CRTMALLOC memHeapAlloc
00537 #define ASN1CRTFREE   ASN1MEMFREEPTR
00538 
00539 /* Function prototypes */
00540 
00541 #define encodeIA5String(pctxt,value,permCharSet) \
00542 encodeConstrainedStringEx (pctxt, value, permCharSet, 8, 7, 7)
00543 
00544 #define encodeGeneralizedTime   encodeIA5String
00545 
00546 #define decodeIA5String(pctxt,pvalue,permCharSet) \
00547 decodeConstrainedStringEx (pctxt, pvalue, permCharSet, 8, 7, 7)
00548 
00549 #define decodeGeneralizedTime   decodeIA5String
00550 
00551 /* run-time error and diagnostic functions */
00552 
00553 /* Context management functions */
00554 
00587 EXTERN int initContextBuffer
00588 (OOCTXT* pctxt, const ASN1OCTET* bufaddr, ASN1UINT bufsiz);
00589 
00603 EXTERN int initContext (OOCTXT* pctxt);
00604 
00612 EXTERN void freeContext (OOCTXT* pctxt);
00613 
00622 EXTERN OOCTXT* newContext (void);
00623 
00624 EXTERN void copyContext (OOCTXT* pdest, OOCTXT* psrc);
00625 EXTERN int  initSubContext (OOCTXT* pctxt, OOCTXT* psrc);
00626 EXTERN void setCtxtFlag (OOCTXT* pctxt, ASN1USINT mask);
00627 EXTERN void clearCtxtFlag (OOCTXT* pctxt, ASN1USINT mask);
00628 
00629 EXTERN int setPERBuffer
00630 (OOCTXT* pctxt, ASN1OCTET* bufaddr, ASN1UINT bufsiz, ASN1BOOL aligned);
00631 
00632 EXTERN int setPERBufferUsingCtxt (OOCTXT* pTarget, OOCTXT* pSource);
00633 
00634 #define ZEROCONTEXT(pctxt) memset(pctxt,0,sizeof(OOCTXT))
00635 
00661 EXTERN int errAddIntParm (ASN1ErrInfo* pErrInfo, int errParm);
00662 
00677 EXTERN int errAddStrParm (ASN1ErrInfo* pErrInfo,
00678                             const char* errprm_p);
00679 
00694 EXTERN int errAddUIntParm (ASN1ErrInfo* pErrInfo, unsigned int errParm);
00695 
00696 
00697 EXTERN int errCopyData (ASN1ErrInfo* pSrcErrInfo,
00698                         ASN1ErrInfo* pDestErrInfo);
00699 
00713 EXTERN void  errFreeParms (ASN1ErrInfo* pErrInfo);
00714 
00715 
00716 EXTERN char* errFmtMsg (ASN1ErrInfo* pErrInfo, char* bufp);
00717 
00723 EXTERN char* errGetText (OOCTXT* pctxt);
00724 
00737 EXTERN void errPrint (ASN1ErrInfo* pErrInfo);
00738 
00748 EXTERN int errReset (ASN1ErrInfo* pErrInfo);
00749 
00773 EXTERN int errSetData (ASN1ErrInfo* pErrInfo, int status,
00774                        const char* module, int lno);
00775 
00776 #ifndef _COMPACT
00777 #define LOG_ASN1ERR(ctxt,stat) \
00778 errSetData(&(ctxt)->errInfo,stat,__FILE__,__LINE__)
00779 #else
00780 #define LOG_ASN1ERR(ctxt,stat) \
00781 ((ctxt)->errInfo.status = stat, stat)
00782 #endif
00783 
00784 #define LOG_ASN1ERR_AND_FREE(pctxt,stat,lctxt) \
00785 freeContext ((lctxt)), LOG_ASN1ERR(pctxt, stat)
00786 
00790 #define RT_MH_DONTKEEPFREE 0x1
00791 
00792 #define OSRTMH_PROPID_DEFBLKSIZE   1
00793 #define OSRTMH_PROPID_SETFLAGS     2
00794 #define OSRTMH_PROPID_CLEARFLAGS   3
00795 
00796 #define OSRTMH_PROPID_USER         10
00797 
00811 #define memAlloc(pctxt,nbytes) \
00812 memHeapAlloc(&(pctxt)->pTypeMemHeap,nbytes)
00813 
00823 #define memAllocZ(pctxt,nbytes) \
00824 memHeapAllocZ(&(pctxt)->pTypeMemHeap,nbytes)
00825 
00835 #define memAllocType(pctxt,ctype) \
00836 (ctype*)memHeapAlloc(&(pctxt)->pTypeMemHeap,sizeof(ctype))
00837 
00847 #define memAllocTypeZ(pctxt,ctype) \
00848 (ctype*)memHeapAllocZ(&(pctxt)->pTypeMemHeap,sizeof(ctype))
00849 
00864 #define memRealloc(pctxt,mem_p,nbytes) \
00865 memHeapRealloc(&(pctxt)->pTypeMemHeap, (void*)mem_p, nbytes)
00866 
00878 #define memFreePtr(pctxt,mem_p) \
00879 if (memHeapCheckPtr (&(pctxt)->pTypeMemHeap, (void*)mem_p)) \
00880 memHeapFreePtr(&(pctxt)->pTypeMemHeap, (void*)mem_p)
00881 
00890 #define memFree(pctxt) \
00891 memHeapFreeAll(&(pctxt)->pTypeMemHeap)
00892 
00907 #define memReset(pctxt) \
00908 memHeapReset(&(pctxt)->pTypeMemHeap)
00909 
00910 /* Alias for __cdecl modifier; if __cdecl keyword is not supported,
00911  * redefine it as empty macro. */
00912 
00913 #if !defined(OSCDECL)
00914 #if defined(_MSC_VER) || defined(__BORLANDC__)
00915 #define OSCDECL __cdecl
00916 #else
00917 #define OSCDECL
00918 #endif
00919 #endif /* OSCDECL */
00920 
00921 /* Pointers to C Run-Time memory allocation functions *
00922  * (See memSetAllocFuncs)                           */
00923 
00924 typedef void *(OSCDECL *OSMallocFunc ) (size_t size);
00925 typedef void *(OSCDECL *OSReallocFunc) (void *ptr, size_t size);
00926 typedef void  (OSCDECL *OSFreeFunc   ) (void *ptr);
00927 
00928 EXTERN void  memHeapAddRef (void** ppvMemHeap);
00929 EXTERN void* memHeapAlloc (void** ppvMemHeap, int nbytes);
00930 EXTERN void* memHeapAllocZ (void** ppvMemHeap, int nbytes);
00931 EXTERN int   memHeapCheckPtr (void** ppvMemHeap, void* mem_p);
00932 EXTERN int   memHeapCreate (void** ppvMemHeap);
00933 EXTERN void  memHeapFreeAll (void** ppvMemHeap);
00934 EXTERN void  memHeapFreePtr (void** ppvMemHeap, void* mem_p);
00935 EXTERN void* memHeapRealloc (void** ppvMemHeap, void* mem_p, int nbytes_);
00936 EXTERN void  memHeapRelease (void** ppvMemHeap);
00937 EXTERN void  memHeapReset (void** ppvMemHeap);
00938 
00939 EXTERN void* memHeapMarkSaved
00940 (void** ppvMemHeap, const void* mem_p, ASN1BOOL saved);
00941 
00942 EXTERN void  memHeapSetProperty
00943 (void** ppvMemHeap, ASN1UINT propId, void* pProp);
00944 
00945 
00961 EXTERN void  memSetAllocFuncs (OSMallocFunc malloc_func,
00962                                OSReallocFunc realloc_func,
00963                                OSFreeFunc free_func);
00964 
00965 EXTERN void  memFreeOpenSeqExt (OOCTXT* pctxt, DList *pElemList);
00966 
00967 /*
00968  * This function sets flags to a heap. May be used to control the heap's
00969  * behavior.
00970  *
00971  * @param pctxt        Pointer to a memory block structure that contains the
00972  *                     list of dynamic memory block maintained by these
00973  *                     functions.
00974  * @param flags        The flags.
00975  */
00976 EXTERN void  memHeapSetFlags (OOCTXT* pctxt, ASN1UINT flags);
00977 
00978 /*
00979  * This function clears memory heap flags.
00980  *
00981  * @param pctxt        Pointer to a memory block structure that contains the
00982  *                     list of dynamic memory block maintained by these
00983  *                     functions.
00984  * @param flags        The flags
00985  */
00986 EXTERN void  memHeapClearFlags (OOCTXT* pctxt, ASN1UINT flags);
00987 
01001 EXTERN void  memHeapSetDefBlkSize (OOCTXT* pctxt, ASN1UINT blkSize);
01002 
01008 EXTERN ASN1UINT memHeapGetDefBlkSize (OOCTXT* pctxt);
01009 
01010 #ifdef _STATIC_HEAP
01011 EXTERN void memSetStaticBuf (void* memHeapBuf, ASN1UINT blkSize);
01012 #endif
01013 
01017 /* PER encode/decode related items */
01018 
01019 #define INCRBITIDX(pctxt) \
01020 ((--(pctxt)->buffer.bitOffset < 0) ? \
01021 ((++(pctxt)->buffer.byteIndex >= (pctxt)->buffer.size) ? ASN_E_ENDOFBUF : \
01022 ((pctxt)->buffer.bitOffset = 7, ASN_OK)) : ASN_OK)
01023 
01024 #define DECODEBIT(pctxt,pvalue) \
01025 ((INCRBITIDX (pctxt) != ASN_OK) ? ((*(pvalue) = 0), ASN_E_ENDOFBUF) : \
01026 ((*(pvalue) = (((pctxt)->buffer.data[(pctxt)->buffer.byteIndex]) & \
01027 (1 << (pctxt)->buffer.bitOffset)) != 0), ASN_OK))
01028 
01029 /*
01030 #define SETCHARSET(csetvar, canset, abits, ubits) \
01031 csetvar.charSet.nchars = 0; \
01032 csetvar.canonicalSet = canset; \
01033 csetvar.canonicalSetSize = sizeof(canset)-1; \
01034 csetvar.canonicalSetBits = getUIntBitCount(csetvar.canonicalSetSize); \
01035 csetvar.charSetUnalignedBits = ubits; \
01036 csetvar.charSetAlignedBits = abits;
01037 */
01038 
01054 EXTERN int decodeBits
01055 (OOCTXT* pctxt, ASN1UINT* pvalue, ASN1UINT nbits);
01056 
01077 EXTERN int decodeBitString
01078 (OOCTXT* pctxt, ASN1UINT* numbits_p, ASN1OCTET* buffer,
01079  ASN1UINT bufsiz);
01080 
01081 EXTERN int decodeBitString32
01082 (OOCTXT* pctxt, ASN1BitStr32* pvalue, ASN1UINT lower, ASN1UINT upper);
01083 
01108 EXTERN int decodeBMPString
01109 (OOCTXT* pctxt, ASN1BMPString* pvalue, Asn116BitCharSet* permCharSet);
01110 
01122 EXTERN int decodeByteAlign (OOCTXT* pctxt);
01123 
01136 EXTERN int decodeConsInteger
01137 (OOCTXT* pctxt, ASN1INT* pvalue, ASN1INT lower, ASN1INT upper);
01138 
01152 EXTERN int decodeConsUnsigned
01153 (OOCTXT* pctxt, ASN1UINT* pvalue, ASN1UINT lower, ASN1UINT upper);
01154 
01168 EXTERN int decodeConsUInt8 (OOCTXT* pctxt,
01169                             ASN1UINT8* pvalue, ASN1UINT lower, ASN1UINT upper);
01170 
01184 EXTERN int decodeConsUInt16
01185 (OOCTXT* pctxt, ASN1USINT* pvalue, ASN1UINT lower, ASN1UINT upper);
01186 
01204 EXTERN int decodeConsWholeNumber
01205 (OOCTXT* pctxt, ASN1UINT* padjusted_value, ASN1UINT range_value);
01206 
01226 EXTERN int decodeConstrainedStringEx
01227 (OOCTXT* pctxt, const char** string, const char* charSet,
01228  ASN1UINT abits, ASN1UINT ubits, ASN1UINT canSetBits);
01229 
01252 EXTERN int decodeDynBitString (OOCTXT* pctxt, ASN1DynBitStr* pBitStr);
01253 
01270 EXTERN int decodeDynOctetString
01271 (OOCTXT* pctxt, ASN1DynOctStr* pOctStr);
01272 
01286 EXTERN int decodeLength (OOCTXT* pctxt, ASN1UINT* pvalue);
01287 
01298 EXTERN int moveBitCursor (OOCTXT* pctxt, int bitOffset);
01299 
01312 EXTERN int decodeObjectIdentifier (OOCTXT* pctxt, ASN1OBJID* pvalue);
01313 
01332 EXTERN int decodeOctetString
01333 (OOCTXT* pctxt, ASN1UINT* numocts_p, ASN1OCTET* buffer,
01334  ASN1UINT bufsiz);
01335 
01353 EXTERN int decodeOpenType
01354 (OOCTXT* pctxt, const ASN1OCTET** object_p2, ASN1UINT* numocts_p);
01355 
01371 EXTERN int decodeSmallNonNegWholeNumber
01372 (OOCTXT* pctxt, ASN1UINT* pvalue);
01373 
01385 EXTERN int decodeSemiConsInteger
01386    (OOCTXT* pctxt, ASN1INT* pvalue, ASN1INT lower);
01387 
01400 EXTERN int decodeSemiConsUnsigned
01401    (OOCTXT* pctxt, ASN1UINT* pvalue, ASN1UINT lower);
01402 
01412 #define decodeUnconsInteger(pctxt,pvalue) \
01413 decodeSemiConsInteger(pctxt, pvalue, ASN1INT_MIN)
01414 
01425 #define decodeUnconsUnsigned(pctxt,pvalue) \
01426 decodeSemiConsUnsigned(pctxt, pvalue, 0U)
01427 
01428 EXTERN int decodeVarWidthCharString (OOCTXT* pctxt, const char** pvalue);
01429 
01439 EXTERN int encodeBit (OOCTXT* pctxt, ASN1BOOL value);
01440 
01451 EXTERN int encodeBits
01452 (OOCTXT* pctxt, ASN1UINT value, ASN1UINT nbits);
01453 
01467 EXTERN int encodeBitString
01468 (OOCTXT* pctxt, ASN1UINT numocts, const ASN1OCTET* data);
01469 
01470 EXTERN int encodeBitString32
01471 (OOCTXT* pctxt, ASN1BitStr32* pvalue, ASN1UINT lower, ASN1UINT upper);
01472 
01496 EXTERN int encodeBMPString
01497 (OOCTXT* pctxt, ASN1BMPString value, Asn116BitCharSet* permCharSet);
01498 
01510 EXTERN int encodeByteAlign (OOCTXT* pctxt);
01511 
01527 EXTERN int encodeCheckBuffer (OOCTXT* pctxt, ASN1UINT nbytes);
01528 
01546 EXTERN int encodeConstrainedStringEx
01547 (OOCTXT* pctxt, const char* string, const char* charSet,
01548  ASN1UINT abits, ASN1UINT ubits, ASN1UINT canSetBits);
01549 
01562 EXTERN int encodeConsInteger
01563 (OOCTXT* pctxt, ASN1INT value, ASN1INT lower, ASN1INT upper);
01564 
01580 EXTERN int encodeConsUnsigned
01581 (OOCTXT* pctxt, ASN1UINT value, ASN1UINT lower, ASN1UINT upper);
01582 
01598 EXTERN int encodeConsWholeNumber
01599 (OOCTXT* pctxt, ASN1UINT adjusted_value, ASN1UINT range_value);
01600 
01614 EXTERN int encodeExpandBuffer (OOCTXT* pctxt, ASN1UINT nbytes);
01615 
01634 EXTERN ASN1OCTET* encodeGetMsgPtr (OOCTXT* pctxt, int* pLength);
01635 
01647 EXTERN int encodeLength (OOCTXT* pctxt, ASN1UINT value);
01648 
01661 EXTERN int encodeObjectIdentifier (OOCTXT* pctxt, ASN1OBJID* pvalue);
01662 
01663 
01674 EXTERN int encodeBitsFromOctet (OOCTXT* pctxt, ASN1OCTET value, ASN1UINT nbits);
01675 
01689 EXTERN int encodeOctets
01690 (OOCTXT* pctxt, const ASN1OCTET* pvalue, ASN1UINT nbits);
01691 
01704 EXTERN int encodeOctetString
01705 (OOCTXT* pctxt, ASN1UINT numocts, const ASN1OCTET* data);
01706 
01722 EXTERN int encodeOpenType
01723 (OOCTXT* pctxt, ASN1UINT numocts, const ASN1OCTET* data);
01724 
01743 EXTERN int encodeOpenTypeExt
01744 (OOCTXT* pctxt, DList* pElemList);
01745 
01746 EXTERN int encodeOpenTypeExtBits
01747 (OOCTXT* pctxt, DList* pElemList);
01748 
01763 EXTERN int encodeSmallNonNegWholeNumber (OOCTXT* pctxt, ASN1UINT value);
01764 
01776 EXTERN int encodeSemiConsInteger
01777    (OOCTXT* pctxt, ASN1INT value, ASN1INT lower);
01778 
01790 EXTERN int encodeSemiConsUnsigned
01791    (OOCTXT* pctxt, ASN1UINT value, ASN1UINT lower);
01792 
01802 #define encodeUnconsInteger(pctxt,value) \
01803 encodeSemiConsInteger(pctxt,value,ASN1INT_MIN)
01804 
01805 EXTERN int encodeUnconsUnsigned (OOCTXT* pctxt, ASN1UINT value);
01806 
01807 EXTERN int encodeVarWidthCharString (OOCTXT* pctxt, const char* value);
01808 
01809 EXTERN int addSizeConstraint (OOCTXT* pctxt, Asn1SizeCnst* pSize);
01810 
01811 EXTERN ASN1BOOL alignCharStr
01812 (OOCTXT* pctxt, ASN1UINT len, ASN1UINT nbits, Asn1SizeCnst* pSize);
01813 
01814 EXTERN int bitAndOctetStringAlignmentTest
01815 (Asn1SizeCnst* pSizeList, ASN1UINT itemCount,
01816  ASN1BOOL bitStrFlag, ASN1BOOL* pAlignFlag);
01817 
01818 EXTERN int getPERMsgLen (OOCTXT* pctxt);
01819 
01820 EXTERN int addSizeConstraint (OOCTXT* pctxt, Asn1SizeCnst* pSize);
01821 
01822 EXTERN Asn1SizeCnst* getSizeConstraint (OOCTXT* pctxt, ASN1BOOL extbit);
01823 
01824 EXTERN int checkSizeConstraint(OOCTXT* pctxt, int size);
01825 EXTERN ASN1UINT getUIntBitCount (ASN1UINT value);
01826 
01827 EXTERN Asn1SizeCnst* checkSize
01828 (Asn1SizeCnst* pSizeList, ASN1UINT value, ASN1BOOL* pExtendable);
01829 
01830 EXTERN void init16BitCharSet
01831 (Asn116BitCharSet* pCharSet, ASN116BITCHAR first,
01832  ASN116BITCHAR last, ASN1UINT abits, ASN1UINT ubits);
01833 
01834 EXTERN ASN1BOOL isExtendableSize (Asn1SizeCnst* pSizeList);
01835 
01836 EXTERN void set16BitCharSet
01837 (OOCTXT* pctxt, Asn116BitCharSet* pCharSet, Asn116BitCharSet* pAlphabet);
01838 
01843 #ifdef __cplusplus
01844 }
01845 #endif
01846 
01847 #endif

This file was last modified on 28 May 2010.
Objective Open H.323 Stack, 0.9.1