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

📄 peroid.c

📁 基于h323协议的软phone
💻 C
字号:
#ifdef __cplusplus
extern "C" {
#endif



/*
***********************************************************************************

NOTICE:
This document contains information that is proprietary to RADVISION LTD..
No part of this publication may be reproduced in any form whatsoever without
written prior approval by RADVISION LTD..

RADVISION LTD. reserves the right to revise this publication and make changes
without obligation to notify any person of such revisions or changes.

***********************************************************************************
*/

/*
  perOID.c

  Ron S.
  16 May 1996


  ____________________________________________________________________________
  ___________________________OBJECT IDENTIFIER________________________________
  ____________________________________________________________________________


  format:

  +--------+-----------+
  | length | BER - OID |
  +--------+-----------+

  */


#include <stdio.h>
#include <perintr.h>


/*___________________________________________________________________________*/
/*________________________________Object_Identifier__________________________*/
/*___________________________________________________________________________*/
/*
  Desc: Encodes an object identifier into TAIL of buffer.
  clause '21'

  */
int
perEncodeOID(IN  HPER hPer,
         IN  int synParent,
         IN  int valParent, /* this is me */
         IN  RvInt32 fieldId)
{
    perStruct *per = (perStruct *)hPer;
    RvInt32 length=0;
    char *data=(char*)per->buf->buffer;
    if(synParent);

    RV_UNUSED_ARG(fieldId);

    pvtGet(per->hVal, valParent, NULL, NULL, &length, NULL);
    if (length < 0)
    {
        RvLogError(&rvPerErrLogSource, (&rvPerErrLogSource,
            "perEncodeOID: %s: buffer allocation error.",
            pstGetFieldNamePtr(per->hSyn, fieldId)));
        return RV_ERROR_UNKNOWN;
    }

    pvtGetString(per->hVal, valParent,length,data);
    if (bbFreeBytes(per->hBB) < length)
    {
        RvLogError(&rvPerErrLogSource, (&rvPerErrLogSource,
            "perEncodeOID: %s: buffer allocation error.",
            pstGetFieldNamePtr(per->hSyn, fieldId)));
        return RV_ERROR_UNKNOWN;
    }

    /* with length determinant: 16.8 */
    perEncodeLen(perLenTypeUNCONSTRAINED, length, 0, 0, per->hBB);
    return bbAddTail(per->hBB, (RvUint8 *)data, length*8, RV_TRUE);
}


/*
  Desc: Decodes an object identifier from buffer (at position).
  Returns: RV_ERROR_UNKNOWN in case of fault or positive number.
  Note: Currently an octet string.
  */
int
perDecodeOID(IN  HPER hPer,
         IN  int synParent, /* parent in syntax tree */
         IN  int valParent, /* field parent in value tree */
         IN  RvInt32 fieldId)   /* enum of current field */
{
  perStruct *per = (perStruct *)hPer;
  RvUint32 length=0;
  RvUint32 dec = 0; /* decoded bits */

  int vtPath;
  char *data=(char*)per->buf->buffer;
  if(synParent);

  /* -- get length: 16.8 */
  if (perDecodeLen(perLenTypeUNCONSTRAINED, &length, 0, 0, hPer, per->decodingPosition, &dec) <0)
    return RV_ERROR_UNKNOWN;
  per->decodingPosition+=dec;

  if (length>0x1fffffff || per->decodingPosition+length*8 > (RvUint32)bbBitsInUse(per->hBB))
  {
      RvLogError(&rvPerErrLogSource, (&rvPerErrLogSource,
          "per:DecodeOID: Object Identifier too large to decode from buffer [len=%ld]",
          length*8));
      return RV_ERROR_UNKNOWN;
  }




  /* -- add value node */
  vtPath=valParent;
  if (fieldId!=RV_ERROR_UNKNOWN)
  {
      if ((vtPath=pvtAdd(per->hVal, valParent, fieldId, (RvInt32)length, (char*)"", NULL)) <0)
      {
          RvLogError(&rvPerErrLogSource, (&rvPerErrLogSource,
              "perDecodeOID: cannot add string to value tree [%s:%d].",
              pstGetFieldNamePtr(per->hSyn, fieldId), length));
        return RV_ERROR_UNKNOWN;
      }
  }

  per->decodingPosition += bbAlignBits(per->hBB, (RvInt32)(per->decodingPosition)); /* alignment */
  if(bbGet2Left(hPer, per->decodingPosition, length*8, (RvUint8 *)data)<0)
    return RV_ERROR_UNKNOWN;

  if (pvtSet(per->hVal, vtPath, -1, (RvInt32)length, data) <0)
  {
    RvLogError(&rvPerErrLogSource, (&rvPerErrLogSource,
        "perDecodeOID: cannot add string to value tree [%s:%d].",
        pstGetFieldNamePtr(per->hSyn, fieldId), length));
    return RV_ERROR_UNKNOWN;
  }
  per->decodingPosition += (length*8);
  return RV_TRUE;
}

#ifdef __cplusplus
}
#endif



⌨️ 快捷键说明

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