ooasn1.h

来自「一个非常美妙的proxy。功能强大。基于sip的协议。如果还要的话」· C头文件 代码 · 共 1,600 行 · 第 1/5 页

H
1,600
字号
typedef struct {   ASN1UINT       nchars;   ASN116BITCHAR* data;} Asn116BitCharString;typedef struct {   ASN1UINT       nchars;   ASN132BITCHAR* data;} Asn132BitCharString;typedef const char*   ASN1GeneralizedTime;typedef const char*   ASN1GeneralString;typedef const char*   ASN1GraphicString;typedef const char*   ASN1IA5String;typedef const char*   ASN1ISO646String;typedef const char*   ASN1NumericString;typedef const char*   ASN1ObjectDescriptor;typedef const char*   ASN1PrintableString;typedef const char*   ASN1TeletexString;typedef const char*   ASN1T61String;typedef const char*   ASN1UTCTime;typedef const char*   ASN1UTF8String;typedef const char*   ASN1VideotexString;typedef const char*   ASN1VisibleString;typedef Asn116BitCharString ASN1BMPString;typedef Asn132BitCharString ASN1UniversalString;/* ASN.1 constrained string structures */typedef struct {   int          nchars;   char         data[255];} Asn1CharArray;typedef struct {   Asn1CharArray charSet;   const char* canonicalSet;   int          canonicalSetSize;   unsigned     canonicalSetBits;   unsigned     charSetUnalignedBits;   unsigned     charSetAlignedBits;} Asn1CharSet;typedef struct {   Asn116BitCharString charSet;   ASN1USINT    firstChar, lastChar;   unsigned     unalignedBits;   unsigned     alignedBits;} Asn116BitCharSet;/* ASN.1 size constraint structure */typedef struct _Asn1SizeCnst {   ASN1BOOL     extended;   ASN1UINT     lower;   ASN1UINT     upper;   struct _Asn1SizeCnst* next;} Asn1SizeCnst;/* ASN.1 encode/decode buffer info structure */typedef struct {   ASN1OCTET*   data;           /* pointer to start of data buffer      */   ASN1UINT     byteIndex;      /* byte index                           */   ASN1UINT     size;           /* current buffer size                  */   ASN1SINT     bitOffset;      /* current bit offset (8 - 1)           */   ASN1BOOL     dynamic;        /* is buffer dynamic?                   */} ASN1BUFFER;/* This structure is used to save the current state of the buffer */typedef struct {   ASN1UINT     byteIndex;      /* byte index                           */   ASN1SINT     bitOffset;      /* current bit offset (8 - 1)           */   ASN1USINT    flags;          /* flag bits                            */} ASN1BUFSAVE;/* ASN.1 run-time error info structures */typedef struct {   const char* module;   int          lineno;} ASN1ErrLocn;typedef struct {   ASN1ErrLocn  stack[ASN_K_MAXERRSTK];   int          stkx;   int          status;   int          parmcnt;   const char* parms[ASN_K_MAXERRP];} ASN1ErrInfo;#define XM_K_MEMBLKSIZ  (4*1024)/* Flag mask constant values */#define ASN1DYNCTXT     0x8000#define ASN1INDEFLEN    0x4000#define ASN1TRACE       0x2000#define ASN1LASTEOC     0x1000#define ASN1FASTCOPY    0x0800  /* turns on the "fast copy" mode        */#define ASN1CONSTAG     0x0400  /* form of last parsed tag              */#define ASN1CANXER      0x0200  /* canonical XER                        */#define ASN1SAVEBUF     0x0100  /* do not free dynamic encode buffer    */#define ASN1OPENTYPE    0x0080  /* item is an open type field           *//* ASN.1 encode/decode context block structure */struct EventHandler;typedef struct OOCTXT {         /* context block                        */   void*        pMsgMemHeap;    /* internal message memory heap         */   void*        pTypeMemHeap;   /* memory heap                          */   ASN1BUFFER   buffer;         /* data buffer                          */   ASN1ErrInfo  errInfo;        /* run-time error info                  */   Asn1SizeCnst* pSizeConstraint;  /* Size constraint list              */   const char* pCharSet;        /* String of permitted characters       */   struct EventHandler* pEventHandler; /* event handler object          */   ASN1USINT    flags;          /* flag bits                            */   ASN1OCTET    spare[2];} OOCTXT;/* macros and function prototypes */#ifndef ASN1MAX#define ASN1MAX(a,b)        (((a)>(b))?(a):(b))#endif#ifndef ASN1MIN#define ASN1MIN(a,b)        (((a)<(b))?(a):(b))#endif/** * @defgroup mem Memory Allocation Macros and Functions  * @ingroup cruntime * * Memory allocation functions and macros handle memory management for the * ASN1C run-time. Special algorithms are used for allocation and deallocation * of memory to improve the run-time performance. @{ *//** * Allocate a dynamic array. This macro allocates a dynamic array of records of * the given type. This version of the macro will return the ASN_E_NOMEM error * status if the memory request cannot be fulfilled. * * @param pctxt        - Pointer to a context block * @param pseqof       - Pointer to a generated SEQUENCE OF array structure. *                       The <i>n</i> member variable must be set to the number *                       of records to allocate. * @param type         - Data type of an array record */#define ALLOC_ASN1ARRAY(pctxt,pseqof,type) do {\if (sizeof(type)*(pseqof)->n < (pseqof)->n) return ASN_E_NOMEM; \if (((pseqof)->elem = (type*) memHeapAlloc \(&(pctxt)->pTypeMemHeap, sizeof(type)*(pseqof)->n)) == 0) return ASN_E_NOMEM; \} while (0)/** * Allocate and zero an ASN.1 element. This macro allocates and zeros a single * element of the given type. * * @param pctxt        - Pointer to a context block * @param type         - Data type of record to allocate */#define ALLOC_ASN1ELEM(pctxt,type) \(type*) memHeapAllocZ (&(pctxt)->pTypeMemHeap, sizeof(type))/** * Allocate memory. This macro allocates the given number of bytes. It is * similar to the C \c malloc run-time function. * * @param pctxt        - Pointer to a context block * @param nbytes       - Number of bytes of memory to allocate * @return             - Void pointer to allocated memory or NULL if *                       insufficient memory was available to fulfill the *                       request. */#define ASN1MALLOC(pctxt,nbytes) \memHeapAlloc(&(pctxt)->pTypeMemHeap, nbytes)/** * Free memory associated with a context. This macro frees all memory held * within a context. This is all memory allocated using the ASN1MALLOC (and * similar macros) and the mem memory allocation functions using the given * context variable. * * @param pctxt        - Pointer to a context block */#define ASN1MEMFREE(pctxt) \memHeapFreeAll(&(pctxt)->pTypeMemHeap)/** * Free memory pointer. This macro frees memory at the given pointer. The * memory must have been allocated using the ASN1MALLOC (or similar) macros or * the mem memory allocation functions. This macro is similar to the C \c * free function. * * @param pctxt        - Pointer to a context block * @param pmem         - Pointer to memory block to free. This must have been *                       allocated using the ASN1MALLOC macro or the *                       memHeapAlloc function. */#define ASN1MEMFREEPTR(pctxt,pmem)  \memHeapFreePtr(&(pctxt)->pTypeMemHeap, (void*)pmem)/** * @} */#define ASN1BUFCUR(cp)          (cp)->buffer.data[(cp)->buffer.byteIndex]#define ASN1BUFPTR(cp)          &(cp)->buffer.data[(cp)->buffer.byteIndex]#ifdef __cplusplusextern "C" {#endif#ifndef EXTERN#ifdef MAKE_DLL#define EXTERN __declspec(dllexport)#elif defined (USEASN1DLL)#define EXTERN __declspec(dllimport)#else#define EXTERN#endif /* MAKE_DLL */#endif /* EXTERN */#ifndef _NO_MALLOC#define ASN1CRTMALLOC0(nbytes)       malloc(nbytes)#define ASN1CRTFREE0(ptr)            free(ptr)#else#ifdef _NO_THREADSextern EXTERN OOCTXT g_ctxt;#define ASN1CRTMALLOC0(nbytes)       memAlloc(&g_ctxt,(nbytes))#define ASN1CRTFREE0(ptr)            memFreePtr(&g_ctxt,(ptr))#else#define ASN1CRTMALLOC0(nbytes)       (void*)0#define ASN1CRTFREE0(ptr)            (void*)0#endif /* _NO_THREADS */#endif /* _NO_MALLOC */#define ASN1CRTMALLOC memHeapAlloc#define ASN1CRTFREE   ASN1MEMFREEPTR/* Function prototypes */#define DE_INCRBITIDX(pctxt) \((--(pctxt)->buffer.bitOffset < 0) ? \((++(pctxt)->buffer.byteIndex >= (pctxt)->buffer.size) ? ASN_E_ENDOFBUF : \((pctxt)->buffer.bitOffset = 7, ASN_OK)) : ASN_OK)#define DE_BIT(pctxt,pvalue) \((DE_INCRBITIDX (pctxt) != ASN_OK) ? ASN_E_ENDOFBUF : ((pvalue) ? \((*(pvalue) = (((pctxt)->buffer.data[(pctxt)->buffer.byteIndex]) & \(1 << (pctxt)->buffer.bitOffset)) != 0), ASN_OK) : ASN_OK ))#define encodeIA5String(pctxt,value,permCharSet) \encodeConstrainedStringEx (pctxt, value, permCharSet, 8, 7, 7)#define encodeGeneralizedTime   encodeIA5String#define decodeIA5String(pctxt,pvalue,permCharSet) \decodeConstrainedStringEx (pctxt, pvalue, permCharSet, 8, 7, 7)#define decodeGeneralizedTime   decodeIA5String/* run-time error and diagnostic functions *//* Context management functions *//** * @defgroup cmfun Context Management Functions  * @{ * * Context initialization functions handle the allocation, initialization, and * destruction of ASN.1 context variables (variables of type OOCTXT). These * variables hold all of the working data used during the process of encoding * or decoding a message. The context provides thread safe operation by * isolating what would otherwise be global variables within this structure. * The context variable is passed from function to function as a message is * encoded or decoded and maintains state information on the encoding or * decoding process. *//** * This function assigns a buffer to a context block. The block should have * been previously initialized by initContext. * * @param pctxt        The pointer to the context structure variable to be *                     initialized. * @param bufaddr      For encoding, the address of a memory buffer to receive *                     and encode a message. For decoding the address of a *                     buffer that contains the message data to be decoded. *                     This address will be stored within the context *                     structure. For encoding it might be zero, the dynamic *                     buffer will be used in this case. * @param bufsiz       The size of the memory buffer. For encoding, it might be *                     zero; the dynamic buffer will be used in this case. * @return             Completion status of operation: *                     - 0 (ASN_OK) = success, *                     - negative return value is error. */EXTERN int initContextBuffer (OOCTXT* pctxt, const ASN1OCTET* bufaddr, ASN1UINT bufsiz);/** * This function initializes a context block. It makes sure that if the block * was not previosly initialized, that all key working parameters are set to * thier correct initial state values (i.e. declared within a function as a * normal working variable), it is required that they invoke this function * before using it. * * @param pctxt        The pointer to the context structure variable to be *                     initialized. * @return             Completion status of operation: *                     - 0 (ASN_OK) = success,

⌨️ 快捷键说明

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