📄 asn.cpp
字号:
/*****************************************************************************
File: asn.C
Contents: Low-level routines
System: ASN development.
Created:
Author: Charles W. Gardiner <gardiner@bbn.com>
Remarks:
COPYRIGHT 1995 BBN Systems and Technologies, A Division of Bolt Beranek and
Newman Inc.
150 CambridgePark Drive
Cambridge, Ma. 02140
617-873-4000
*****************************************************************************/
#ifndef lint
const char rcsid[]="$Header: /nfs/sub-rosa/u2/IOS_Project/ASN/Dev/rcs/lib/asn_obj/asn.C,v 1.23 1995/09/08 21:16:45 gardiner Exp $";
const char sfcsid[] = "@(#)asn.C 276P";
#endif
#include "includes.h"
#include "asn_error.h"
#ifndef __ASN_OBJ_H
#include "asn_obj.h"
#endif
ushort _mos[] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304,
334, 365, 366}; /* last is for leap year */
static struct asn_errors
{
int num;
char *msg;
} asn_errors[] =
{
{ ASN_MATCH_ERR, "Stream doesn't match template" },
{ ASN_MEM_ERR, "Error getting memory"},
{ ASN_GEN_ERR, "Error in asn_gen's code"},
{ ASN_CHOICE_ERR, "Can't write to a CHOICE"},
{ ASN_OF_ERR, "Tags not consistent in SET/SEQ OF"},
{ ASN_MANDATORY_ERR, "Mandatory field is not filled in" },
{ ASN_NOT_OF_ERR, "Not a SET/SEQ OF"},
{ ASN_OF_BOUNDS_ERR, "Out of bounds in SET/SEQ OF"},
{ ASN_EMPTY_ERR, "Source is empty"},
{ ASN_DEFINER_ERR, "Definer not in table"},
{ ASN_NO_DEF_ERR, "DEFINED BY not defined yet"},
{ ASN_BOUNDS_ERR, "Size out of bounds"},
{ ASN_TYPE_ERR, "Invalid operation for this type"},
{ ASN_TIME_ERR, "Invalid time field"},
{ ASN_CODING_ERR, "Improper ASN.1 string"},
{ ASN_NULL_PTR, "Null pointer passed to AsnObj member function" },
{ ASN_NONE_ERR, "Can't write to a NONE"},
{ ASN_UNDEF_VALUE, "Trying to write an undefined value" },
{ ASN_NO_CHOICE_ERR, "Character string not valid for any of CHOICE" },
{ ASN_MASK_ERR, "Invalid character at [-(value returned)]"},
{ ASN_DEFINED_ERR, "Error trying to find DEFINED BY" },
{ ASN_LENGTH_ERR, "Invalid length field" },
{ ASN_FILE_ERR, "Didn't use all of file" },
{ 0, "Unknown error" },
};
int asn_obj_err(int num)
{
struct asn_errors *errp;
for (errp = asn_errors; errp->num && errp->num != num; errp++);
asn_error(errp->num, errp->msg);
asn_errno = num;
return -1;
}
ulong decode_asn_lth(const uchar **s)
{
ulong lth = 0;
const uchar *from = *s;
int ansr;
if (((lth = *from++) & ASN_INDEF_LTH))
{
if ((ansr = (lth &= (uchar)~ASN_INDEF_LTH)))
{
for (lth = 0; ansr--; lth = (lth << 8) + *from++);
}
}
*s = from;
return lth;
}
ulong decode_asn_tag(const uchar **s)
{
ulong typ = 0;
const uchar *from = *s;
if (((typ = *from++) & ASN_XT_TAG) == ASN_XT_TAG)
{
while ((*from & ASN_INDEF_LTH)) typ = (typ <<= 8) + *from++;
typ = (typ <<= 8) + *from++;
}
*s = from;
return typ;
}
void stuff(int map_num)
{
char *b, *c, buf[12];
int tmp, lth;
map_num++; /* one-based */
for (b = buf, tmp = map_num; tmp; tmp /= 10, b++);
lth = (b - buf);
if (*asn_map_string)
{
lth++; /* 1 for the dot */
*b = '.';
b[1] = 0;
}
else *b = 0;
for (tmp = map_num; tmp; tmp /= 10) *(--b) = (tmp % 10) + '0';
for (c = asn_map_string; *c; c++);
for (b = &c[lth]; c >= asn_map_string; *b-- = *c--);
for (b = buf, c = asn_map_string; *b; *c++ = *b++);
}
/*
static void write_err(char *c)
{
fprintf (stderr, "Illegal %s operator\007\n", c);
}
*/
void multi_stuff(int map_num, const AsnObj *top, const AsnObj *low)
//void multi_stuff(int map_num, AsnObj *top, AsnObj *low)
{
int i, j;
stuff(map_num);
if ((top->_flags & ASN_POINTER_FLAG) && ((AsnPtr *)top)->_ptr)
top = ((AsnPtr *)top)->_ptr;
if (top == low) return;
i = j = -1;
if ((top->_flags & ASN_DEFINED_FLAG))
{
for (top = top->_sub; top && !(top->_flags & ASN_CHOSEN_FLAG);
top = top->_next, i++);
}
if (top->_type == ASN_CHOICE && (top->_flags & ASN_FILLED_FLAG))
{
for (top = top->_sub; top && !(top->_flags & ASN_FILLED_FLAG);
top = top->_next, j++);
}
if (j >= 0) stuff(j);
if (i >= 0) stuff(i);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -