diff options
author | Andreas Tille <tille@debian.org> | 2016-12-01 16:38:47 +0100 |
---|---|---|
committer | Andreas Tille <tille@debian.org> | 2016-12-01 16:38:47 +0100 |
commit | 9c3449b3f79213138ad1d315580af98e89d8e1b6 (patch) | |
tree | 157d2da8682da6cfb9ee28db762c9c94dcdaa98c /asnlib | |
parent | be323245ea77f0e457e3d42c83b58a82f67ca0f2 (diff) |
New upstream version 6.1.20160908
Diffstat (limited to 'asnlib')
-rw-r--r-- | asnlib/asn.h | 58 | ||||
-rw-r--r-- | asnlib/asncode.c | 9 | ||||
-rw-r--r-- | asnlib/asndebin.c | 47 | ||||
-rw-r--r-- | asnlib/asnenbin.c | 70 | ||||
-rw-r--r-- | asnlib/asnio.c | 147 | ||||
-rw-r--r-- | asnlib/asnlex.c | 80 | ||||
-rw-r--r-- | asnlib/asnprint.c | 13 | ||||
-rw-r--r-- | asnlib/asntool.c | 107 |
8 files changed, 270 insertions, 261 deletions
diff --git a/asnlib/asn.h b/asnlib/asn.h index b5a4cea0..88361877 100644 --- a/asnlib/asn.h +++ b/asnlib/asn.h @@ -29,7 +29,7 @@ * * Version Creation Date: 1/1/91 * -* $Revision: 6.17 $ +* $Revision: 6.22 $ * * File Description: * This header the interface to all the routines in the ASN.1 libraries @@ -100,7 +100,7 @@ typedef struct asnopt { typedef struct asnvaluenode { Int2 valueisa; CharPtr name; /* use for strings and named int */ - Int4 intvalue; /* use for int and boolean */ + Int8 intvalue; /* use for int and boolean */ FloatHi realvalue; struct asnvaluenode PNTR next; AsnOptionPtr aop; /* for comments */ @@ -109,10 +109,10 @@ typedef struct asnvaluenode { /******** AsnType is a node in the AsnTool parse tree *******/ typedef struct asntype { - Int2 isa; + Int2 isa; /* holds types like BOOLEAN_TYPE, etc. You can use the ISA_ macros on it */ CharPtr name; - Uint1 tagclass; - Int2 tagnumber; + Uint1 tagclass; /* holds TAG_UNIVERSAL, TAG_APPLICATION, etc. */ + Int2 tagnumber; /* holds TAG_BOOLEAN, etc. */ unsigned implicit : 1; unsigned optional : 1; unsigned hasdefault : 1; @@ -196,7 +196,7 @@ typedef struct asnio { Int2 linepos; /* current offset in linebuf */ FILE * fp; /* file to write or read to */ BytePtr buf; /* buffer for I/O */ - Int2 bufsize; /* sizeof this buffer */ + Int2 bufsize; /* sizeof this buffer */ Int2 bytes, /* bytes of data available in buf */ offset; /* current offset of processing in buf */ Uint1 tagclass; /* last BER tag-id-len read */ @@ -210,30 +210,34 @@ typedef struct asnio { max_indent, /* current maximum indent levels for first */ state; /* parsing state */ Int2 linelength; /* max line length on output */ - BoolPtr first; /* for first element on indented line for printing */ + BoolPtr first; /* for first element on indented line for printing */ Int4 linenumber; /* for reporting errors */ CharPtr word; /* current word in linebuf */ Int2 wordlen, /* length of word in linebuf */ - token; /* current parsing token for word */ - PstackPtr typestack; /* the parsing stack for input and output */ + token; /* current parsing token for word */ + PstackPtr typestack; /* the parsing stack for input and output */ Int1 type_indent, /* used like indent_level and max_indent, but for */ max_type; /* typestack */ ErrorRetType error_ret; /* user error return */ - Pointer iostruct; /* non-FILE io structure */ - IoFuncType readfunc, /* read/write functions for sockets */ - writefunc; /* open and close MUST be done outside AsnIo */ + Pointer iostruct; /* non-FILE io structure */ + IoFuncType readfunc, /* read/write functions for sockets */ + writefunc; /* open and close MUST be done outside AsnIo */ Boolean read_id; /* for checking AsnReadId AsnReadVal alternation */ CharPtr fname; /* name of file in use */ AsnOptionPtr aop; /* head of options chain */ AsnExpOptPtr aeop; /* exploration options chain */ AsnExpOptStructPtr aeosp; Boolean io_failure; /* set on failed write, or read */ - Uint1 fix_non_print; /* fix non-printing chars in VisibleStrings (see below)*/ + Uint1 fix_non_print; /* fix non-printing chars in VisibleStrings (see below) */ + Boolean utf8_read; /* VisibleString expected but UTF8String encountered */ + Uint1 fix_utf8_in; /* policy on reporting VisibleString/UTF8String mismatches (see below) */ + Boolean utf8_sent; /* UTF8String converted to VisibleString in output */ + Uint1 fix_utf8_out; /* policy on converting UTF8String to VisibleString (see below) */ Boolean scan_for_start; /* if TRUE, scan over garbage in print form */ Int2 spec_version; /* used for filtering between asn.1 spec versions */ Boolean no_newline; /* to suppress internal newlines in long XML strings */ Boolean XMLModuleWritten; /* to put header on first XML DTD only */ - /* the following fields are used for easier ASN.1 comparisons, not normal operations */ + /* the following fields are used for easier ASN.1 comparisons, not normal operations */ Boolean asn_no_newline; /* to suppress internal newlines in long ASN.1 strings */ Boolean asn_alt_struct; /* structure ending braces on separate lines */ } AsnIo, PNTR AsnIoPtr; @@ -264,6 +268,32 @@ typedef struct asnio { *****************************************************************************/ +/***************************************************************************** +* +* fix_utf8_in +* Supported values of fix_utf8_in are: +* +* 0 = (default) do not post any errors, set aip->utf8_read +* 1 = post an error of SEV_WARNING the first time, set aip->utf8_read +* 2 = post an error of SEV_WARNING every time, set aip->utf8_read +* 3 = do not do input conversion +* +*****************************************************************************/ + + +/***************************************************************************** +* +* fix_utf8_out +* Supported values of fix_utf8_out are: +* +* 0 = (default) do not post any errors, set aip->utf8_sent +* 1 = post an error of SEV_WARNING the first time, set aip->utf8_sent +* 2 = post an error of SEV_WARNING every time, set aip->utf8_sent +* 3 = do not do output conversion +* +*****************************************************************************/ + + typedef struct asniomem { /* for AsnIo to and from a memory block */ AsnIoPtr aip; /* the AsnIoPtr for this */ BytePtr buf; /* a buffer for the data */ diff --git a/asnlib/asncode.c b/asnlib/asncode.c index 75bbcd90..711cc714 100644 --- a/asnlib/asncode.c +++ b/asnlib/asncode.c @@ -29,7 +29,7 @@ * * Version Creation Date: 7/8/93 * -* $Revision: 6.19 $ +* $Revision: 6.20 $ * * File Description: * Automatically generate C code from ASN.1 specifications @@ -63,7 +63,7 @@ static Boolean AsnCodeIsEnumType PROTO ((AsnTypePtr atp)); -static char RCS_Rev [] = "$Revision: 6.19 $"; +static char RCS_Rev [] = "$Revision: 6.20 $"; /******************* * Interator structure @@ -3653,7 +3653,7 @@ AsnCodeFunctionWriteFuncChoiceStart (AsnIterPtr iter, Boolean doing_outer_setof_ AsnIterTakeBuf (iter); sprintf (iter->buf, "\ if (anp == NULL) { AsnNullValueMsg(aip, atp); goto erret; }\n\ -\n\ + MemSet ((Pointer) (&av), 0, sizeof (DataVal));\n\ av.ptrvalue = (Pointer)anp;\n"); AsnIterTakeBuf (iter); if (!doing_outer_setof_choice) { @@ -3695,7 +3695,8 @@ AsnCodeFunctionWriteFuncSeqStart (AsnIterPtr iter, Boolean no_write_braces) AsnIterTakeBuf (iter); sprintf (iter->buf, "\ - if (ptr == NULL) { AsnNullValueMsg(aip, atp); goto erret; }\n"); + if (ptr == NULL) { AsnNullValueMsg(aip, atp); goto erret; }\n\ + MemSet ((Pointer) (&av), 0, sizeof (DataVal));\n"); AsnIterTakeBuf (iter); if (! no_write_braces){ diff --git a/asnlib/asndebin.c b/asnlib/asndebin.c index 7e297404..4726db77 100644 --- a/asnlib/asndebin.c +++ b/asnlib/asndebin.c @@ -29,7 +29,7 @@ * * Version Creation Date: 3/4/91 * -* $Revision: 6.10 $ +* $Revision: 6.16 $ * * File Description: * Special binary form (BER) decoder for ASN.1 @@ -48,19 +48,39 @@ static void RelaxVisibleStringUTF8 (AsnIoPtr aip, AsnTypePtr atp) { - Int2 isa; + Int2 isa = 0; + Uint1 fix_utf8_in; - if (aip == NULL || atp == NULL || atp->type == NULL) return; - isa = atp->type->isa; + if (aip == NULL || atp == NULL) return; + if (atp->type != NULL) { + isa = atp->type->isa; + } else { + isa = atp->isa; + } if (! ISA_STRINGTYPE (isa)) return; if (aip->tagclass != atp->tagclass) return; if (aip->tagnumber == atp->tagnumber) return; - /* allow UTF8/VisibleString flexibility */ + /* !!! CXX-3341 temporarily allow UTF8/VisibleString flexibility !!! */ + fix_utf8_in = aip->fix_utf8_in; + if (fix_utf8_in == 3) return; + if (aip->tagnumber == TAG_VISIBLESTRING && atp->tagnumber == TAG_UTF8STRING) { aip->tagnumber = atp->tagnumber; } else if (aip->tagnumber == TAG_UTF8STRING && atp->tagnumber == TAG_VISIBLESTRING) { aip->tagnumber = atp->tagnumber; + + if (fix_utf8_in == 0) { + aip->utf8_read = TRUE; + } else if (fix_utf8_in == 1) { + if (! aip->utf8_read) { + AsnIoErrorMsg(aip, 107); + } + aip->utf8_read = TRUE; + } else if (fix_utf8_in == 2) { + AsnIoErrorMsg(aip, 107); + aip->utf8_read = TRUE; + } } } @@ -685,6 +705,8 @@ NLM_EXTERN Int2 LIBCALL AsnBinReadVal (AsnIoPtr aip, AsnTypePtr atp, DataValPtr valueptr->boolvalue = AsnDeBinReadBoolean(aip, atp); break; case INTEGER_TYPE: + valueptr->intvalue = AsnDeBinReadBigInt(aip, atp); + break; case ENUM_TYPE: valueptr->intvalue = AsnDeBinReadInteger(aip, atp); break; @@ -910,7 +932,9 @@ NLM_EXTERN Int8 AsnDeBinReadBigInt (AsnIoPtr aip, AsnTypePtr atp) Int2 bytes, len; Uint8 number; BytePtr bp; + AsnValxNodePtr avnp; Int8 value; + AsnTypePtr atp2; bytes = aip->bytes - aip->offset; bp = aip->buf + aip->offset; @@ -946,8 +970,17 @@ NLM_EXTERN Int8 AsnDeBinReadBigInt (AsnIoPtr aip, AsnTypePtr atp) /******************** read a named integer value *********/ - /* named value not supported for BigInt ****/ - + atp2 = AsnFindBaseType(atp); + if (atp2->branch != NULL) /* named values */ + { + avnp = (AsnValxNodePtr) atp2->branch; + while (avnp != NULL) + { + if (avnp->intvalue == value) + return value; + avnp = avnp->next; + } + } AsnIoErrorMsg(aip, 12, value, AsnErrGetTypeName(atp->name)); diff --git a/asnlib/asnenbin.c b/asnlib/asnenbin.c index 791c69e1..8448f4e9 100644 --- a/asnlib/asnenbin.c +++ b/asnlib/asnenbin.c @@ -29,7 +29,7 @@ * * Version Creation Date: 3/4/91 * -* $Revision: 6.7 $ +* $Revision: 6.10 $ * * File Description: * Special binary (BER) encoder for ASN.1 @@ -38,49 +38,6 @@ * -------------------------------------------------------------------------- * Date Name Description of modification * ------- ---------- ----------------------------------------------------- -* 3/4/91 Kans Stricter typecasting for GNU C and C++ -* 04-20-93 Schuler LIBCALL calling convention -* -* $Log: asnenbin.c,v $ -* Revision 6.7 2011/09/06 18:18:16 kans -* support for UTF8String in binary ASN.1 -* -* Revision 6.6 2003/11/07 20:57:02 beloslyu -* fix the c++ style comments to a C ones -* -* Revision 6.5 2003/08/01 16:55:24 gouriano -* workaround MSVC++.NET optimization bug -* -* Revision 6.4 2000/12/12 15:56:11 ostell -* added support BigInt -* -* Revision 6.3 1998/06/12 19:27:49 kans -* fixed unix compiler warnings -* -* Revision 6.2 1998/05/02 18:54:25 kans -* for Mac, use %LG instead of %lg, which is not legal C, and not supported by CodeWarrior -* -* Revision 6.1 1998/05/01 23:35:18 kans -* use %lf on Mac, %lg elsewhere, sprintf bug reported -* -* Revision 6.0 1997/08/25 18:09:50 madden -* Revision changed to 6.0 -* -* Revision 5.1 1996/12/03 21:43:48 vakatov -* Adopted for 32-bit MS-Windows DLLs -* - * Revision 5.0 1996/05/28 14:00:29 ostell - * Set to revision 5.0 - * - * Revision 4.1 1996/02/18 16:45:36 ostell - * changed fix_non_print behavior and added option 3 - * - * Revision 4.0 1995/07/26 13:47:38 ostell - * force revision to 4.0 - * - * Revision 2.9 1995/05/15 18:38:28 ostell - * added Log line - * * * ========================================================================== */ @@ -146,6 +103,8 @@ NLM_EXTERN Boolean LIBCALL AsnBinWrite (AsnIoPtr aip, AsnTypePtr atp, DataValPt AsnEnBinBoolean(dvp->boolvalue, aip, atp); break; case INTEGER_TYPE: + AsnEnBinBigInt(dvp->intvalue, aip, atp); + break; case ENUM_TYPE: AsnEnBinInteger(dvp->intvalue, aip, atp); break; @@ -202,6 +161,7 @@ NLM_EXTERN Boolean LIBCALL AsnBinWrite (AsnIoPtr aip, AsnTypePtr atp, DataValPt NLM_EXTERN void AsnEnBinTags (AsnTypePtr atp, AsnIoPtr aip) { int isa, len; + Uint1 fix_utf8_out; Int4 tagnumber; Byte octets[6], bit87, bit6, bit5_1; @@ -222,6 +182,28 @@ NLM_EXTERN void AsnEnBinTags (AsnTypePtr atp, AsnIoPtr aip) if (tagnumber <= 30) /* only need one octet */ { + + /* !!! CXX-3341 temporarily write VisibleString instead of UTF8String for transition !!! */ + if (isa == UTF8STRING_TYPE && tagnumber == TAG_UTF8STRING) { + fix_utf8_out = aip->fix_utf8_out; + if (fix_utf8_out == 0) { + tagnumber = TAG_VISIBLESTRING; + aip->utf8_sent = TRUE; + } else if (fix_utf8_out == 1) { + tagnumber = TAG_VISIBLESTRING; + if (! aip->utf8_sent) { + AsnIoErrorMsg(aip, 108); + } + aip->utf8_sent = TRUE; + } else if (fix_utf8_out == 2) { + tagnumber = TAG_VISIBLESTRING; + AsnIoErrorMsg(aip, 108); + aip->utf8_sent = TRUE; + } else if (fix_utf8_out == 3) { + /* do not convert */ + } + } + bit5_1 = (Byte)(tagnumber) & (Byte)0x0ff; octets[0] = bit87 + bit6 + bit5_1; AsnEnBinBytes(octets, (Uint4)1, aip); diff --git a/asnlib/asnio.c b/asnlib/asnio.c index d7a9a5cb..d967f01a 100644 --- a/asnlib/asnio.c +++ b/asnlib/asnio.c @@ -29,7 +29,7 @@ * * Version Creation Date: 3/4/91 * -* $Revision: 6.14 $ +* $Revision: 6.16 $ * * File Description: * Routines for AsnIo objects. This code has some machine dependencies. @@ -39,102 +39,6 @@ * -------------------------------------------------------------------------- * Date Name Description of modification * ------- ---------- ----------------------------------------------------- -* 3/4/91 Kans Stricter typecasting for GNU C and C++ -* 4/7/91 Ostell Berkely Socket support, block I/O -* 04-20-93 Schuler LIBCALL calling convention -* 01-31-94 Schuler Changed ErrGetOpts/ErrSetOpts to ErrSaveOptions/ErrRestoreOptions -* -* $Log: asnio.c,v $ -* Revision 6.14 2012/03/08 20:30:37 kans -* aip->linelength is now Int2 -* -* Revision 6.13 2011/04/12 21:28:51 lavr -* Fix ASN stream flushing: avoid fflush(NULL) that has an effect of flushing ALL open FILE* streams -* -* Revision 6.12 2005/12/01 20:00:13 lavr -* AsnIoErrorMsg(): Don't insert extra LFs if there was no typestack dumped -* -* Revision 6.11 2002/05/20 23:13:39 ivanov -* Fixed overburn memory AsnIo buf in the AsnPrint*() -- increased -* buffers reserved room -* -* Revision 6.10 2001/10/11 14:39:08 ostell -* added support for XMLModulePrefix -* -* Revision 6.9 2001/03/13 13:11:46 ostell -* made AsnIoBSOpen() and AsnIoMemOpen() XML aware -* -* Revision 6.8 2001/02/02 22:08:47 shavirin -* Fixed case of opening AsnIoPtr in case of XML output for Linux. -* -* Revision 6.7 2000/05/10 03:12:37 ostell -* added support for XML DTD and XML data output -* -* Revision 6.6 1999/07/30 20:34:25 vakatov -* AsnIoGets(): rewritten -- to handle an incremental read -* -* Revision 6.5 1998/02/27 17:22:21 vakatov -* [WIN32 DLL] Declared some functions as NLM_EXTERN(DLL-exportable) -* -* Revision 6.4 1998/01/09 15:51:03 shavirin -* Hash function turned to be external -* -* Revision 6.3 1998/01/09 15:47:52 shavirin -* Added hash calculating functions. -* -* Revision 6.2 1997/12/04 21:41:14 shavirin -* Fixed bug with printing error message -* -* Revision 6.1 1997/10/29 02:41:13 vakatov -* Type castings to pass through the C++ compiler -* -* Revision 6.0 1997/08/25 18:10:00 madden -* Revision changed to 6.0 -* -* Revision 5.4 1997/04/23 15:44:51 ostell -* commented out references to g_asnlib which caused unecessary error messages -* trying to open asnlib.msg file which does not exist. -* - * Revision 5.3 1996/12/03 21:43:48 vakatov - * Adopted for 32-bit MS-Windows DLLs - * - * Revision 5.2 1996/10/07 14:37:28 vakatov - * AsnIoErrorMsg() rearranged to avoid memory corruption when posting - * long (>2048 bytes) error messages - * - * Revision 5.1 1996/06/18 16:07:46 sad - * AsnIoGets errorneously reported that line too long at the end of file, fixed - * - * Revision 5.0 1996/05/28 14:00:29 ostell - * Set to revision 5.0 - * - * Revision 4.6 1996/02/18 18:05:37 kans - * severity is an ErrSev variable - * - * Revision 4.5 1996/02/18 16:45:36 ostell - * changed fix_non_print behavior and added option 3 - * - * Revision 4.4 1995/12/21 14:00:51 ostell - * added AsnIoFree() - * - * Revision 4.3 1995/12/18 21:38:00 epstein - * add diagnostic values in AsnIoWriteBlock error message - * - * Revision 4.2 1995/10/28 15:02:06 ostell - * added casts to quiet DOS compile warnings - * - * Revision 4.1 1995/09/14 20:41:02 sirotkin - * modification to AsnIoErrMsg to give meaningful error codes - * - * Revision 4.0 1995/07/26 13:47:38 ostell - * force revision to 4.0 - * - * Revision 2.24 1995/05/26 22:14:40 ostell - * added spec_version saving to AsnIoReset - * - * Revision 2.23 1995/05/15 18:38:28 ostell - * added Log line - * * * ========================================================================== */ @@ -245,6 +149,11 @@ NLM_EXTERN CharPtr LIBCALL AsnGetXMLmodulePrefix (void) NLM_EXTERN AsnIoPtr LIBCALL AsnIoNew (Int1 type, FILE *fp, Pointer iostruct, IoFuncType readfunc, IoFuncType writefunc) { AsnIoPtr aip; +#ifdef OS_UNIX + CharPtr str; + int val; +#endif + aip = (AsnIoPtr) MemNew(sizeof(AsnIo)); if (aip == NULL) @@ -269,6 +178,30 @@ NLM_EXTERN AsnIoPtr LIBCALL AsnIoNew (Int1 type, FILE *fp, Pointer iostruct, Io aip->first[0] = TRUE; aip->typestack = (PstackPtr) MemNew((sizeof(Pstack) * 10)); aip->max_type = 10; + +#ifdef OS_UNIX + /* !!! CXX-3341 Allow environment variables to set initial policies !!! */ + + str = (CharPtr) getenv ("FIX_NON_PRINT_POLICY"); + if (StringDoesHaveText (str) && sscanf (str, "%d", &val) == 1 && val >= 0 && val <= 3) { + aip->fix_non_print = (Uint1) val; + } + + if ((type & ASNIO_BIN) && (type & ASNIO_IN)) { + str = (CharPtr) getenv ("UTF8_INPUT_POLICY"); + if (StringDoesHaveText (str) && sscanf (str, "%d", &val) == 1 && val >= 0 && val <= 3) { + aip->fix_utf8_in = (Uint1) val; + } + } + + if ((type & ASNIO_BIN) && (type & ASNIO_OUT)) { + str = (CharPtr) getenv ("UTF8_OUTPUT_POLICY"); + if (StringDoesHaveText (str) && sscanf (str, "%d", &val) == 1 && val >= 0 && val <= 3) { + aip->fix_utf8_out = (Uint1) val; + } + } +#endif + return aip; } @@ -793,7 +726,7 @@ NLM_EXTERN Int2 AsnIoWriteBlock (AsnIoPtr aip) return aip->bytes; } -static char * AsnIoErrStr[107] = { +static char * AsnIoErrStr[109] = { #ifdef WIN16 "Sorry. Not supported yet", @@ -902,7 +835,9 @@ static char * AsnIoErrStr[107] = { "Did not AsnReadId before AsnReadVal. line %ld" , "Did not AsnReadVal before AsnReadId. line %ld", "Did not load parse trees for trying to explore them", -"Invalid value(s) [%d] in VisibleString [%Fs ...]" +"Invalid value(s) [%d] in VisibleString [%Fs ...]", +"UTF8String encountered where VisibleString expected", +"UTF8String replaced by VisibleString" #else @@ -1012,7 +947,9 @@ static char * AsnIoErrStr[107] = { "Did not AsnReadId before AsnReadVal. line %ld" , "Did not AsnReadVal before AsnReadId. line %ld", "Did not load parse trees for trying to explore them", -"Invalid value(s) [%d] in VisibleString [%s ...]" +"Invalid value(s) [%d] in VisibleString [%s ...]", +"UTF8String encountered where VisibleString expected", +"UTF8String replaced by VisibleString" #endif }; @@ -1056,6 +993,10 @@ NLM_EXTERN void CDECL AsnIoErrorMsg(AsnIoPtr aip, int errcode, ...) /* non-printing chars in string may not be fatal */ if (errcode == 106 && aip->fix_non_print == 0) severity = SEV_ERROR; + else if (errcode == 107) + severity = SEV_WARNING; + else if (errcode == 108) + severity = SEV_WARNING; else aip->io_failure = TRUE; @@ -1154,6 +1095,8 @@ NLM_EXTERN void LIBCALL AsnIoReset (AsnIoPtr aip) AsnExpOptPtr aeop; /* exploration options chain */ AsnExpOptStructPtr aeosp; Uint1 fix_non_print; + Uint1 fix_utf8_in; + Uint1 fix_utf8_out; Int2 spec_version; if (aip->type & ASNIO_OUT) @@ -1182,6 +1125,8 @@ NLM_EXTERN void LIBCALL AsnIoReset (AsnIoPtr aip) aeop = aip->aeop; aeosp = aip->aeosp; fix_non_print = aip->fix_non_print; + fix_utf8_in = aip->fix_utf8_in; + fix_utf8_out = aip->fix_utf8_out; spec_version = aip->spec_version; MemFill(aip, '\0', sizeof(AsnIo)); /* clear it */ @@ -1207,6 +1152,8 @@ NLM_EXTERN void LIBCALL AsnIoReset (AsnIoPtr aip) aip->aeop = aeop; aip->aeosp = aeosp; aip->fix_non_print = fix_non_print; + aip->fix_utf8_in = fix_utf8_in; + aip->fix_utf8_out = fix_utf8_out; aip->spec_version = spec_version; /* clear stacks and buffers */ MemFill(aip->typestack, '\0', (size_t)(sizeof(Pstack) * aip->max_type)); diff --git a/asnlib/asnlex.c b/asnlib/asnlex.c index abbaaca4..c5c2d99e 100644 --- a/asnlib/asnlex.c +++ b/asnlib/asnlex.c @@ -29,7 +29,7 @@ * * Version Creation Date: 3/4/91 * -* $Revision: 6.6 $ +* $Revision: 6.10 $ * * File Description: * Routines for parsing ASN.1 value nototation (text) messages @@ -38,58 +38,6 @@ * -------------------------------------------------------------------------- * Date Name Description of modification * ------- ---------- ----------------------------------------------------- -* 2/11/91 Ostell AsnTxtReadVal - added check for unresolved base types -* 3/4/91 Kans Stricter typecasting for GNU C and C++ -* 3/4/91 Kans AsnLexReadBoolean returns Boolean -* 04-20-93 Schuler LIBCALL calling convention -* -* $Log: asnlex.c,v $ -* Revision 6.6 2011/09/06 18:03:03 kans -* text ASN.1 support for UTF8String -* -* Revision 6.5 2000/12/12 15:56:12 ostell -* added support BigInt -* -* Revision 6.4 2000/03/10 18:02:05 kans -* increased size of tbuf in AsnLexReadOctets to handle long lines in hand-edited (?) ASN.1 records being submitted -* -* Revision 6.3 1999/12/23 17:25:44 kans -* AsnTxtReadVal checks for NULL atp - same as recent check in AsnBinReadVal -* -* Revision 6.2 1998/06/12 19:27:51 kans -* fixed unix compiler warnings -* -* Revision 6.1 1997/10/29 02:41:31 vakatov -* Type castings to pass through the C++ compiler -* -* Revision 6.0 1997/08/25 18:10:04 madden -* Revision changed to 6.0 -* -* Revision 5.3 1997/04/23 23:03:33 ostell -* just added a typecast -* - * Revision 5.2 1997/04/23 21:23:03 ostell - * changed BitHex reading routine to strip internal spaces and allow for linewraps at - * any spacing. - * - * Revision 5.1 1996/12/03 21:43:48 vakatov - * Adopted for 32-bit MS-Windows DLLs - * - * Revision 5.0 1996/05/28 14:00:29 ostell - * Set to revision 5.0 - * - * Revision 4.2 1996/02/18 16:45:36 ostell - * changed fix_non_print behavior and added option 3 - * - * Revision 4.1 1995/10/28 15:02:06 ostell - * added casts to quiet DOS compile warnings - * - * Revision 4.0 1995/07/26 13:47:38 ostell - * force revision to 4.0 - * - * Revision 2.16 1995/05/15 18:38:28 ostell - * added Log line - * * * ========================================================================== */ @@ -423,6 +371,8 @@ NLM_EXTERN Int2 LIBCALL AsnTxtReadVal (AsnIoPtr aip, AsnTypePtr atp, DataValPtr valueptr->boolvalue = AsnLexReadBoolean(aip, atp); break; case INTEGER_TYPE: + valueptr->intvalue = AsnLexReadBigInt(aip, atp); + break; case ENUM_TYPE: valueptr->intvalue = AsnLexReadInteger(aip, atp); break; @@ -606,6 +556,8 @@ NLM_EXTERN Int4 AsnLexReadInteger (AsnIoPtr aip, AsnTypePtr atp) NLM_EXTERN Int8 AsnLexReadBigInt (AsnIoPtr aip, AsnTypePtr atp) { Int2 token; + AsnValxNodePtr avnp; + AsnTypePtr atp2; token = AsnLexWord(aip); /* read the integer */ @@ -621,7 +573,23 @@ NLM_EXTERN Int8 AsnLexReadBigInt (AsnIoPtr aip, AsnTypePtr atp) } /******************** read a named integer value *********/ - /**** not supported for bigint *****/ + atp2 = AsnFindBaseType(atp); + if (atp2->branch != NULL) /* named values */ + { + avnp = (AsnValxNodePtr) atp2->branch; + while (avnp != NULL) + { + if (StrMatch(avnp->name, aip->word, aip->wordlen)) + return avnp->intvalue; + avnp = avnp->next; + } + } + + if (atp2->type->isa == ENUM_TYPE) /* enumerated MUST match named value */ + { + AsnIoErrorMsg(aip, 40, AsnErrGetTypeName(atp->name), aip->linenumber); + return 0; + } /******************* could it be a previously defined value? ***/ @@ -782,7 +750,7 @@ NLM_EXTERN ByteStorePtr AsnLexReadOctets (AsnIoPtr aip, AsnTypePtr atp) { Int2 token, len; ByteStorePtr ssp = NULL; - Byte tbuf[256]; /* was 101 - changed to handle occasional hand-edited ASN.1? */ + Byte tbuf[500]; /* was 101 - changed to handle occasional hand-edited ASN.1? */ Int4 bytes, left, added; token = AsnLexWord(aip); /* read the start */ @@ -889,7 +857,7 @@ NLM_EXTERN FloatHi AsnLexReadReal (AsnIoPtr aip, AsnTypePtr atp) Int2 token; double mantissa, result; int base, exponent; - char buf[15]; + char buf[100]; result = 0.0; token = AsnLexWord(aip); /* read the { */ diff --git a/asnlib/asnprint.c b/asnlib/asnprint.c index 6379e704..e59230a1 100644 --- a/asnlib/asnprint.c +++ b/asnlib/asnprint.c @@ -29,7 +29,7 @@ * * Version Creation Date: 3/4/91 * -* $Revision: 6.31 $ +* $Revision: 6.35 $ * * File Description: * Routines for printing ASN.1 value notation (text) messages and @@ -427,6 +427,8 @@ NLM_EXTERN Boolean LIBCALL AsnTxtWriteEx (AsnIoPtr aip, AsnTypePtr atp, DataVal AsnPrintCharBlock(">", aip); if (isa == BIGINT_TYPE) AsnPrintBigInt(dvp->bigintvalue, aip); + else if (isa == INTEGER_TYPE) + AsnPrintBigInt(dvp->intvalue, aip); else AsnPrintInteger(dvp->intvalue, aip); if(isXML) AsnXMLTerm(aip, atp); @@ -670,6 +672,7 @@ NLM_EXTERN void AsnPrintType (AsnTypePtr atp, AsnIoPtr aip) break; case INTEGER_TYPE: case ENUM_TYPE: + case BIGINT_TYPE: AsnPrintChar(' ', aip); AsnPrintOpenStruct(aip, atp); avnp = (AsnValxNodePtr)atp->branch; @@ -684,7 +687,7 @@ NLM_EXTERN void AsnPrintType (AsnTypePtr atp, AsnIoPtr aip) AsnPrintString(avnp->name, aip); AsnPrintChar(' ', aip); AsnPrintChar('(', aip); - AsnPrintInteger(avnp->intvalue, aip); + AsnPrintBigInt(avnp->intvalue, aip); AsnPrintChar(')', aip); avnp = avnp->next; } @@ -740,7 +743,7 @@ NLM_EXTERN void AsnPrintType (AsnTypePtr atp, AsnIoPtr aip) AsnPrintBoolean((Boolean)avnp->intvalue, aip); break; case VALUE_ISA_INT: - AsnPrintInteger(avnp->intvalue, aip); + AsnPrintBigInt(avnp->intvalue, aip); break; case VALUE_ISA_REAL: AsnPrintReal(avnp->realvalue, aip); @@ -1843,7 +1846,7 @@ static void AsnXMLElementStart(AsnTypePtr atp, AsnIoPtr aip) } isa = AsnFindBaseIsa(atp); - if ((atp->branch != NULL) && (isa == INTEGER_TYPE) && (isa == ENUM_TYPE)) + if ((atp->branch != NULL) && ((isa == INTEGER_TYPE) || (isa == ENUM_TYPE) || (isa == BIGINT_TYPE))) { for (avnp = (AsnValxNodePtr)(atp->branch); avnp != NULL; @@ -2300,8 +2303,8 @@ NLM_EXTERN void AsnPrintModuleXML (AsnModulePtr amp, AsnIoPtr aip) { AsnPrintTopTypeXML(aip, atp); } + atp = atp->next; } - atp = atp->next; } AsnPrintNewLine(aip); diff --git a/asnlib/asntool.c b/asnlib/asntool.c index 766454f1..ab46f56b 100644 --- a/asnlib/asntool.c +++ b/asnlib/asntool.c @@ -29,7 +29,7 @@ * * Version Creation Date: 1/1/91 * -* $Revision: 6.18 $ +* $Revision: 6.21 $ * * File Description: * Main routine for asntool. Uses the ASN.1 library routines to perform @@ -69,7 +69,7 @@ extern void AsnTxtReadValFile PROTO((AsnModulePtr amp, AsnIoPtr aip, AsnIoPtr ai extern void AsnBinReadValFile PROTO((AsnTypePtr atp, AsnIoPtr aip, AsnIoPtr aipout, AsnIoPtr encode, AsnIoPtr xaipout)); -#define NUMARGS 27 +#define NUMARGS 30 Args asnargs[NUMARGS] = { {"ASN.1 Module File",NULL,NULL,NULL,FALSE,'m',ARG_FILE_IN,0.0,0,NULL}, @@ -87,12 +87,31 @@ Args asnargs[NUMARGS] = { {"Buffer Size","1024","512","10000",TRUE,'b',ARG_INT,0.0,0,NULL}, {"Word length maximum for #defines","31","31","128",TRUE,'w',ARG_INT,0.0,0,NULL}, + {"Fix Non-Printing Characters\n" + " 0 - Replace with #, post ERROR\n" + " 1 - Replace with # silently\n" + " 2 - Pass through silently\n" + " 3 - Replace with #, post FATAL\n","0","0","3",TRUE,'F',ARG_INT,0.0,0,NULL}, + {"UTF8 Input Conversion\n" + " 0 - Convert silently\n" + " 1 - Convert, post WARNING first time\n" + " 2 - Convert, post WARNING each time\n" + " 3 - Do not convert\n","0","0","3",TRUE,'N',ARG_INT,0.0,0,NULL}, + {"UTF8 Output Conversion\n" + " 0 - Convert silently\n" + " 1 - Convert, post WARNING first time\n" + " 2 - Convert, post WARNING each time\n" + " 3 - Do not convert\n","0","0","3",TRUE,'U',ARG_INT,0.0,0,NULL}, + {"Generate object loader .c and .h files, \n\tif used, see below parameters:","F",NULL,NULL,TRUE,'G',ARG_BOOLEAN,0.0,0,NULL}, - {"ASN.1 module filenames, comma separated used for external refs from the \'m\', but no other action taken", NULL, NULL, NULL, TRUE, 'M', ARG_FILE_IN, 0.0, 0, NULL}, + {"ASN.1 module filenames, comma separated used for external refs from the \'m\',\n but no other action taken", NULL, NULL, NULL, TRUE, 'M', ARG_FILE_IN, 0.0, 0, NULL}, {"Base for filename, without extensions, for generated objects and code", NULL, NULL, NULL, TRUE, 'B', ARG_FILE_OUT, 0.0, 0, NULL}, - {"During code generation, debugging level\n 0 - No debugging\n 1 - Shallow debugging\n 2 - Deep", "0", "0", "9", TRUE, 'D', ARG_INT, 0.0, 0, NULL}, + {"During code generation, debugging level\n" + " 0 - No debugging\n" + " 1 - Shallow debugging\n" + " 2 - Deep\n", "0", "0", "9", TRUE, 'D', ARG_INT, 0.0, 0, NULL}, {"Debugging filename", "stderr", NULL, NULL, TRUE, 'S', ARG_FILE_OUT, 0.0, 0, NULL}, {"In generated .c, add #include to this filename", NULL, NULL, NULL, TRUE, 'I', ARG_STRING, 0.0, 0, NULL}, {"Bit twiddle for optional zero value base slots","F",NULL,NULL,TRUE,'Z',ARG_BOOLEAN,0.0,0,NULL}, @@ -107,24 +126,43 @@ Args asnargs[NUMARGS] = { }; -Int2 Main (void) -{ - Int2 m_argModuleIn=0, f_arg_moduleOut=1, - X_argDTDModuleOut=2, T_argTreeDumpOut=3, - v_argPrintFileIn = 4, p_argPrintFileOut = 5, - x_argXMLDataOut=6, d_argBinaryFileIn = 7 - , t_argAsnTypeName = 8, e_argBinaryFileOut = 9 - , o_argHeadFile = 10, l_argLoadFile = 11 - , b_argBufferSize = 12, w_argTokenMax = 13 +typedef enum { + m_argModuleIn = 0, + f_arg_moduleOut, + X_argDTDModuleOut, + T_argTreeDumpOut, + v_argPrintFileIn, + p_argPrintFileOut, + x_argXMLDataOut, + d_argBinaryFileIn, + t_argAsnTypeName, + e_argBinaryFileOut, + o_argHeadFile, + l_argLoadFile, + b_argBufferSize, + w_argTokenMax, + F_argFixPrint, + N_argUtfInput, + U_argUtfOutput, /*--- args below here are capitilized and for code generation, only--*/ /*-- Except for the 'M' arg, which will also affect normal use ---*/ - , G_argGenerateCode = 14, M_argMoreModuleFiles = 15 - , B_argCodeFileName = 16, D_argCodeGenDebugLevel = 17 - , S_argDebugFileName = 18, I_argExtraIncludeName = 19 - , Z_argBitTwiddle = 20, K_argLoadName = 21 - , J_objMgrEntry = 22, L_objMgrLabel = 23, P_argXMLmodulePrefix = 24 - , V_argChoiceStruct = 25, Q_argQuoted = 26; + G_argGenerateCode, + M_argMoreModuleFiles, + B_argCodeFileName, + D_argCodeGenDebugLevel, + S_argDebugFileName, + I_argExtraIncludeName, + Z_argBitTwiddle, + K_argLoadName, + J_objMgrEntry, + L_objMgrLabel, + P_argXMLmodulePrefix, + V_argChoiceStruct, + Q_argQuoted, +} Arguments; +Int2 Main (void) +{ AsnIoPtr aip = NULL, aipout = NULL, xaipout = NULL, @@ -145,18 +183,14 @@ Int2 Main (void) ErrSetMessageLevel(SEV_MIN); asnargs[P_argXMLmodulePrefix].defaultvalue = (const char *)AsnGetXMLmodulePrefix(); - if (! GetArgs("AsnTool 5", NUMARGS, asnargs)) - return 1; + if (! GetArgs("AsnTool 7", NUMARGS, asnargs)) { + return 1; + } + ErrClear(); AsnSetXMLmodulePrefix((CharPtr)(asnargs[P_argXMLmodulePrefix].strvalue)); - /* - if (! GetArgs("AsnTool 4", NUMARGS, asnargs)) - return 1; - ErrClear(); - */ - if (! AsnIoSetBufsize(NULL, (Int2)asnargs[b_argBufferSize].intvalue)) return 1; @@ -172,12 +206,15 @@ Int2 Main (void) acip -> loadname = asnargs[K_argLoadName].strvalue; /* overrides m_argModuleIn, if set */ } - if (asnargs[e_argBinaryFileOut].strvalue != NULL) /* output a binary value file */ - if ((aipencode = AsnIoOpen(asnargs[e_argBinaryFileOut].strvalue, "wb")) == NULL) + if (asnargs[e_argBinaryFileOut].strvalue != NULL) { /* output a binary value file */ + if ((aipencode = AsnIoOpen(asnargs[e_argBinaryFileOut].strvalue, "wb")) == NULL) { - ErrShow(); - return 1; + ErrShow(); + return 1; } + aipencode->fix_non_print = asnargs[F_argFixPrint].intvalue; + aipencode->fix_utf8_out = asnargs[U_argUtfOutput].intvalue; + } /** parse the module(s) ***/ @@ -366,6 +403,8 @@ Int2 Main (void) ErrShow(); return 1; } + aipout->fix_non_print = asnargs[F_argFixPrint].intvalue; + aipout->fix_utf8_out = asnargs[U_argUtfOutput].intvalue; } /* print an XML file */ @@ -376,6 +415,8 @@ Int2 Main (void) ErrShow(); return 1; } + xaipout->fix_non_print = asnargs[F_argFixPrint].intvalue; + xaipout->fix_utf8_out = asnargs[U_argUtfOutput].intvalue; } if (asnargs[v_argPrintFileIn].strvalue != NULL) /* read a printvalue file */ @@ -385,6 +426,8 @@ Int2 Main (void) ErrShow(); return 1; } + aip->fix_non_print = asnargs[F_argFixPrint].intvalue; + aip->fix_utf8_in = asnargs[N_argUtfInput].intvalue; AsnTxtReadValFile(amp, aip, aipout, aipencode, xaipout); ErrShow(); @@ -418,6 +461,8 @@ Int2 Main (void) ErrShow(); return 1; } + aip->fix_non_print = asnargs[F_argFixPrint].intvalue; + aip->fix_utf8_in = asnargs[N_argUtfInput].intvalue; AsnBinReadValFile(atp, aip, aipout, aipencode, xaipout); |