⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 encode.c

📁 wm PNE 3.3 source code, running at more than vxworks6.x version.
💻 C
📖 第 1 页 / 共 2 页
字号:
Returns: nothing****************************************************************************/void  A_EncodeLength(ALENGTH_T  leng,		 EHELPER_T *func,		 OCTET_T   *funcparm){if (leng <= (ALENGTH_T)127) {    OCTET_T c;    c = (OCTET_T) leng;    (void)(*func)(funcparm, &c, (ALENGTH_T)sizeof(OCTET_T));    }else {    OCTET_T buff[OCTETS_PER_INT32+1];    OCTET_T reverse[OCTETS_PER_INT32];    OCTET_T *bp = buff;    OCTET_T *rp = reverse;    unsigned short int count = 0; /* Never exceeds OCTETS_PER_INT32 */    ALENGTH_T cnt;    while (leng > 0)	{	*rp++ = (OCTET_T) leng;	/*lint -e704	*/	leng >>= 8;	/*lint +e704	*/	count++;	}    *bp++ = (OCTET_T)(((OCTET_T) count) | (OCTET_T) 0x80);    cnt = count + 1;    while ((count--) > 0)	{	*bp++ = *(--rp);	}    (void)(*func)(funcparm, buff, cnt);  }}/****************************************************************************A_EncodeInt -- generate ASN.1 format of integer (WITH TYPE & LENGTH)PARAMETERS    ATVALUE_T        The type value    OCTET_T          A_IDC_MASK flag values    INT_32_T	     The integer to convert (signed 32 bit)    ALENGTH_T (*f()) Function to be called to take generated data    OCTET_T *	     Parameter to be passed unchanged to the function.Notes:  The function whose address is passed as a parameter is called zeroor more times to take away some accumulated data.  The function is calledwith these parameters:        OCTET_T *   The parameter (funcparm) passed to this routine        OCTET_T *   The buffer where the data resides        ALENGTH_T   The number of octets in the buffer.The function should return the number of octets consumed, type ALENGTH_T.The function should return a zero if it has taken all the data it wants.Returns: nothing****************************************************************************/void  A_EncodeInt(ATVALUE_T	 id,	      OCTET_T	 flags,	      INT_32_T	 value,	      EHELPER_T *func,	      OCTET_T   *funcparm){ALENGTH_T leng;OCTET_T   *rp;OCTET_T	  buff[OCTETS_PER_INT32];leng = A_SizeOfInt(value);A_EncodeType(id, (OCTET_T)(flags & A_IDC_MASK), func, funcparm);A_EncodeLength(leng, func, funcparm);rp = buff + (unsigned short int)leng;for(;;)    {    *(--rp) = (OCTET_T) value;    if (rp == buff) break;    /*lint -e704	*/    value >>= 8;    /*lint +e704	*/    }  (void)(*func)(funcparm, buff, leng);}/****************************************************************************A_EncodeUnsignedInt -- generate ASN.1 format of integer (WITH TYPE & LENGTH)		       where the local form of the integer is unsigned.PARAMETERS    ATVALUE_T        The type value    OCTET_T          A_IDC_MASK flag values    UINT_32_T	     The integer to convert (unsigned 32 bit)    ALENGTH_T (*f()) Function to be called to take generated data    OCTET_T *	     Parameter to be passed unchanged to the function.Notes:  The function whose address is passed as a parameter is called zeroor more times to take away some accumulated data.  The function is calledwith these parameters:        OCTET_T *   The parameter (funcparm) passed to this routine        OCTET_T *   The buffer where the data resides        ALENGTH_T   The number of octets in the buffer.The function should return the number of octets consumed, type ALENGTH_T.The function should return a zero if it has taken all the data it wants.Returns: nothing****************************************************************************/void  A_EncodeUnsignedInt(ATVALUE_T	 id,		      OCTET_T	 flags,		      UINT_32_T	 value,		      EHELPER_T *func,		      OCTET_T   *funcparm){ALENGTH_T leng, xleng;OCTET_T   *rp;OCTET_T	  buff[OCTETS_PER_INT32+1];leng = A_SizeOfUnsignedInt(value);A_EncodeType(id, (OCTET_T)(flags & A_IDC_MASK), func, funcparm);A_EncodeLength(leng, func, funcparm);rp = buff + (unsigned short int)leng;/* If the unsigned number takes 5 octets, the high order octet is merely *//* a zero byte to hold the zero sign.					 */for(xleng = leng; xleng--;)    {    *(--rp) = (OCTET_T) value;    value >>= 8;  /* This better be shifting zeros into the high end!	*/    }  (void)(*func)(funcparm, buff, leng);}/****************************************************************************A_EncodeOctetString -- Generate ASN.1 format of octet string (WITH TYPE &		       LENGTH)PARAMETERS    ATVALUE_T        The type value    OCTET_T          A_IDC_MASK flag values    OCTET_T *	     Address of the string    ALENGTH_T	     Length of the string    ALENGTH_T (*f()) Function to be called to take generated data    OCTET_T *	     Parameter to be passed unchanged to the function.Notes:  The function whose address is passed as a parameter is called zeroor more times to take away some accumulated data.  The function is calledwith these parameters:        OCTET_T *   The parameter (funcparm) passed to this routine        OCTET_T *   The buffer where the data resides        ALENGTH_T   The number of octets in the buffer.The function should return the number of octets consumed, type ALENGTH_T.The function should return a zero if it has taken all the data it wants.****************************************************************************/void  A_EncodeOctetString(ATVALUE_T	 id,		      OCTET_T	 flags,		      OCTET_T   *osp,		      ALENGTH_T	 oslen,		      EHELPER_T	*func,		      OCTET_T   *funcparm){/* Do a primitive encoding */A_EncodeType(id, (OCTET_T)(flags & A_IDC_MASK), func, funcparm);A_EncodeLength(oslen, func, funcparm);if (oslen != 0)     (void)(*func)(funcparm, osp, oslen);}/****************************************************************************A_EncodeSubId -- generate ASN.1 format of a subidentifier from an		 object identifierPARAMETERS    OIDC_T	The subidentifier to encode    ALENGTH_T (*f())	Function to be called to take generated data    OCTET_T *	    	Parameter to be passed unchanged to the function.Notes:  The function whose address is passed as a parameter is called zeroor more times to take away some accumulated data.  The function is calledwith these parameters:        OCTET_T *   The parameter (funcparm) passed to this routine        OCTET_T *   The buffer where the data resides        ALENGTH_T   The number of octets in the buffer.The function should return the number of octets consumed, type ALENGTH_T.The function should return a zero if it has taken all the data it wants.Returns: nothing****************************************************************************/static void  A_EncodeSubId(OIDC_T     value,		EHELPER_T *func,		OCTET_T   *funcparm){ALENGTH_T leng;OCTET_T   *rp;OCTET_T	  buff[OCTETS_PER_INT32+1];OCTET_T   last;leng = A_SizeOfSubId(value);for(rp = buff + leng, last = 0x00; rp != buff;)    {    *(--rp) = (OCTET_T)(value & 0x007F) | last;    value >>= 7;    last = 0x80;    }  (void)(*func)(funcparm, buff, leng);}/****************************************************************************A_EncodeObjectId -- generate ASN.1 format of Object ID (WITH TYPE & LENGTH)PARAMETERS    ATVALUE_T        The type value    OCTET_T          A_IDC_MASK flag values    OBJ_ID_T *	     Pointer to the internal object Id structure    ALENGTH_T (*f()) Function to be called to take generated data    OCTET_T *	     Parameter to be passed unchanged to the function.Notes:  The function whose address is passed as a parameter is called zeroor more times to take away some accumulated data.  The function is calledwith these parameters:        OCTET_T *   The parameter (funcparm) passed to this routine        OCTET_T *   The buffer where the data resides        ALENGTH_T   The number of octets in the buffer.The function should return the number of octets consumed, type ALENGTH_T.The function should return a zero if it has taken all the data it wants.Returns: nothing****************************************************************************/void  A_EncodeObjectId(ATVALUE_T  id,		   OCTET_T    flags,		   OBJ_ID_T  *objp,		   EHELPER_T *func,		   OCTET_T   *funcparm){ALENGTH_T leng;OIDC_T *cp = objp->component_list;int i;leng = A_SizeOfObjectId(objp);A_EncodeType(id, (OCTET_T)(flags & A_IDC_MASK), func, funcparm);A_EncodeLength(leng, func, funcparm);if (leng == 0)     return;/* Merge the first two components of the object identifier to form the	*//* first subidentifier.							*/   {   OIDC_T x;   x = *cp++;   x = x * 40 + *cp++;   A_EncodeSubId(x, func, funcparm);   }/* Handle the remaining components, each as its own subidentifier.	*/for (i = 2; i < objp->num_components; i++)   {   A_EncodeSubId(*cp++, func, funcparm);   }}/* We only inlcude the ui64 function if the type is installed */#if (ENVOY_USE_V2_TYPES)/****************************************************************************A_EncodeUnsignedInt64 -- generate ASN.1 format of integer (WITH TYPE & LENGTH)		         where the local form of the integer is unsigned 64.PARAMETERS    ATVALUE_T        The type value    OCTET_T          A_IDC_MASK flag values    UINT_64_T *	     The integer to convert (unsigned 64 bit)    ALENGTH_T (*f()) Function to be called to take generated data    OCTET_T *	     Parameter to be passed unchanged to the function.Notes:  The function whose address is passed as a parameter is called zeroor more times to take away some accumulated data.  The function is calledwith these parameters:        OCTET_T *   The parameter (funcparm) passed to this routine        OCTET_T *   The buffer where the data resides        ALENGTH_T   The number of octets in the buffer.The function should return the number of octets consumed, type ALENGTH_T.The function should return a zero if it has taken all the data it wants.Returns: nothing****************************************************************************/void  A_EncodeUnsignedInt64(ATVALUE_T  id,			OCTET_T	   flags,			UINT_64_T *value,			EHELPER_T *func,			OCTET_T   *funcparm){ALENGTH_T leng, xleng;OCTET_T   *rp;OCTET_T	  buff[(OCTETS_PER_INT32*2)+1];leng = A_SizeOfUnsignedInt64(value);A_EncodeType(id, (OCTET_T)(flags & A_IDC_MASK), func, funcparm);A_EncodeLength(leng, func, funcparm);rp = buff + (unsigned short int)leng;/* If the unsigned number takes 9 octets, the high order octet is merely *//* a zero byte to hold the zero sign.					 */if (leng <= 4)    for(xleng = leng; xleng--;) {	*(--rp) = (OCTET_T) value->low;	value->low >>= 8;	}else {    for(xleng = 4; xleng--;) {	*(--rp) = (OCTET_T) value->low;	value->low >>= 8;	}    for(xleng = leng - 4; xleng--;) {	*(--rp) = (OCTET_T) value->high;	value->high >>= 8;	}      }  (void)(*func)(funcparm, buff, leng);}#endif /* (ENVOY_USE_V2_TYPES) *//****************************************************************************NAME:  A_EncodeHelperPURPOSE:  Collect encoded data from the ASN.1 encoding routines and	  place it into a buffer.PAREMETERS:        EBUFFER_T * The "opaque" parameter (funcparm) passed to the encoding		    routines.        OCTET_T *   The buffer where the encoded data resides        ALENGTH_T   The number of encoded octets in the buffer.RETURNS:  Returns the number of octets consumed, zero is returned if          no more data is desired.  (This may not, however, prevent	  subsequent calls.)RESTRICTIONS:  	Can not handle length > 64KBUGS:  ****************************************************************************/ALENGTH_T  A_EncodeHelper(PTR_T	    ptr,		 OCTET_T   *bp,		 ALENGTH_T  leng){EBUFFER_T *ebp = ptr;ALENGTH_T actual;actual = min(leng, ebp->remaining);switch (actual)   {   case 0:	break;   case 1:	*(ebp->next_bp++) = *bp;	ebp->remaining--;	break;   case 2:	*(ebp->next_bp++) = *bp++;	*(ebp->next_bp++) = *bp;	ebp->remaining -= 2;	break;   default:	(void) MEMCPY(ebp->next_bp, bp, actual);	ebp->remaining -= actual;	ebp->next_bp += (unsigned short)actual;	break;   }return (actual);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -