Home > Support > Documentation

asn1ber.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 1997-2006 Objective Systems, Inc.
00003  *
00004  * This software is furnished under a license and may be used and copied
00005  * only in accordance with the terms of such license and with the
00006  * inclusion of the above copyright notice. This software or any other
00007  * copies thereof may not be provided or otherwise made available to any
00008  * other person. No title to and ownership of the software is hereby
00009  * transferred.
00010  *
00011  * The information in this software is subject to change without notice
00012  * and should not be construed as a commitment by Objective Systems, Inc.
00013  *
00014  * PROPRIETARY NOTICE
00015  *
00016  * This software is an unpublished work subject to a confidentiality agreement
00017  * and is protected by copyright and trade secret law.  Unauthorized copying,
00018  * redistribution or other use of this work is prohibited.
00019  *
00020  * The above notice of copyright on this source code product does not indicate
00021  * any actual or intended publication of such source code.
00022  *
00023  *****************************************************************************/
00024 /*
00025 // CHANGE LOG
00026 // Date         Init    Description
00027 // 05/03/02     AB      Initial issue
00028 // 05/06/02     AB      More only-BER things moved
00029 // 05/10/02     AB      RELATIVE-OID
00030 // 10/17/02     ED      Inline buffer save and restore macros
00031 // 10/26/02     AB      UInt64 encode/decode funcs added
00032 // 01/18/03     ED      Added more Doxygen comments
00033 // 10/29/03     CZ      Added doxygen code for mainpage text.
00034 //
00036 */
00084 #ifndef _ASN1BER_H_
00085 #define _ASN1BER_H_
00086 
00087 #include "rtsrc/asn1type.h"
00088 
00089 #define ASN_K_INDEFLEN   -9999   /* indefinite length message indicator  */
00090 
00091 #define XU_DUMP(msg)           xu_dump(msg,0,0)
00092 #define xd_resetp(pctxt)       rtxResetContext(pctxt)
00093 
00094 #define ASN1TAG2BYTE(tag) \
00095 ((OSOCTET)(((tag)&TM_B_IDCODE)|((tag)>>ASN1TAG_LSHIFT)))
00096 
00101 typedef struct _Asn1BufLocDescr {
00102    OSUINT32 numocts;
00103    OSINT32  offset;
00104 } Asn1BufLocDescr;
00105 
00106 #ifdef __cplusplus
00107 extern "C" {
00108 
00109 #endif
00110 
00111 #ifndef EXTERNBER
00112 #ifdef BUILDASN1BERDLL
00113 #define EXTERNBER __declspec(dllexport)
00114 #elif defined (USEASN1BERDLL)
00115 #define EXTERNBER __declspec(dllimport)
00116 #else
00117 #define EXTERNBER
00118 #endif /* BUILDASN1BERDLL */
00119 #endif /* EXTERNBER */
00120 
00121 /* decode functions */
00154 EXTERNBER int xd_tag (OSCTXT* pctxt, ASN1TAG *tag_p);
00155 
00176 EXTERNBER int xd_tag_len (OSCTXT *pctxt, ASN1TAG *tag_p, 
00177                           int *len_p, OSOCTET flags);
00178 
00203 EXTERNBER int xd_match (OSCTXT *pctxt, ASN1TAG tag, 
00204                         int *len_p, OSOCTET flags);
00205 
00231 EXTERNBER int xd_boolean (OSCTXT *pctxt, OSBOOL *object_p, 
00232                           ASN1TagType tagging, int length);
00233 
00257 EXTERNBER int xd_integer (OSCTXT *pctxt, OSINT32 *object_p, 
00258                           ASN1TagType tagging, int length);
00259 
00277 EXTERNBER int xd_int8 (OSCTXT *pctxt, OSINT8 *object_p, 
00278                        ASN1TagType tagging, int length);
00279 
00297 EXTERNBER int xd_int16 (OSCTXT *pctxt, OSINT16 *object_p, 
00298                         ASN1TagType tagging, int length); 
00299 
00324 EXTERNBER int xd_unsigned (OSCTXT *pctxt, OSUINT32 *object_p, 
00325                            ASN1TagType tagging, int length);
00326 
00345 EXTERNBER int xd_uint8 (OSCTXT *pctxt, OSUINT8 *object_p, 
00346                         ASN1TagType tagging, int length); 
00347 
00366 EXTERNBER int xd_uint16 (OSCTXT *pctxt, OSUINT16 *object_p, 
00367                          ASN1TagType tagging, int length); 
00368 
00389 EXTERNBER int xd_int64 (OSCTXT *pctxt, OSINT64 *object_p, 
00390                         ASN1TagType tagging, int length);
00391 
00413 EXTERNBER int xd_uint64 (OSCTXT *pctxt, OSUINT64 *object_p, 
00414                          ASN1TagType tagging, int length);
00415 
00443 EXTERNBER int xd_bigint (OSCTXT *pctxt, const char** object_p, 
00444                          ASN1TagType tagging, int length);
00445 
00473 EXTERNBER int xd_bitstr_s (OSCTXT *pctxt, OSOCTET* object_p, 
00474                            OSUINT32* numbits_p, ASN1TagType tagging, 
00475                            int length);
00476 
00499 EXTERNBER int xd_bitstr (OSCTXT *pctxt, const OSOCTET** object_p2, 
00500                          OSUINT32* numbits_p, ASN1TagType tagging, int length);
00501 
00521 EXTERNBER int xd_octstr_s (OSCTXT *pctxt, OSOCTET* object_p, 
00522                            OSUINT32* pnumocts, ASN1TagType tagging, 
00523                            int length);
00524 
00544 EXTERNBER int xd_octstr (OSCTXT *pctxt, const OSOCTET** object_p2, 
00545                          OSUINT32* pnumocts, ASN1TagType tagging, int length);
00546 
00568 EXTERNBER int xd_charstr (OSCTXT* pctxt, const char** object_p, 
00569                           ASN1TagType tagging, ASN1TAG tag, int length);
00570 
00591 #define xd_utf8str(pctxt,object_p,tagging,length) \
00592 xd_charstr (pctxt, (const char**)object_p, tagging, ASN_ID_UTF8String, length)
00593 
00616 EXTERNBER int xd_16BitCharStr (OSCTXT* pctxt, Asn116BitCharString* object_p,
00617                                ASN1TagType tagging, ASN1TAG tag, int length);
00618 
00641 EXTERNBER int xd_32BitCharStr (OSCTXT* pctxt, Asn132BitCharString* object_p,
00642                                ASN1TagType tagging, ASN1TAG tag, int length);
00643 
00658 EXTERNBER int xd_null (OSCTXT *pctxt, ASN1TagType tagging);
00659 
00676 EXTERNBER int xd_objid (OSCTXT *pctxt, ASN1OBJID *object_p, 
00677                         ASN1TagType tagging, int length);
00678 
00696 EXTERNBER int xd_oid64 (OSCTXT *pctxt, ASN1OID64 *object_p, 
00697                         ASN1TagType tagging, int length);
00698 
00715 EXTERNBER int xd_reloid (OSCTXT *pctxt, ASN1OBJID *object_p, 
00716                          ASN1TagType tagging, int length);
00717 
00733 EXTERNBER int xd_real (OSCTXT *pctxt, OSREAL *object_p, 
00734                        ASN1TagType tagging, int length);
00735 
00751 EXTERNBER int xd_enum (OSCTXT *pctxt, OSINT32 *object_p, 
00752                        ASN1TagType tagging, int length);
00753 
00769 EXTERNBER int xd_OpenType (OSCTXT *pctxt, const OSOCTET** object_p2, 
00770                            OSUINT32* pnumocts);
00771 
00791 EXTERNBER int xd_OpenTypeExt (OSCTXT* pctxt, ASN1CCB* ccb_p, ASN1TAG tag, 
00792                               OSRTDList *pElemList);
00793 
00806 EXTERNBER int xd_OpenTypeAppend (OSCTXT *pctxt, OSRTDList *pElemList);
00807 
00823 EXTERNBER int xd_real10 (OSCTXT *pctxt, const char** object_p, 
00824                          ASN1TagType tagging, int length);
00825 
00856 EXTERNBER int xd_setp (OSCTXT *pctxt, const OSOCTET* msg_p, 
00857                        int msglen, ASN1TAG *tag_p, int *len_p);
00858 
00866 EXTERNBER int xd_indeflen_ex (const OSOCTET* msg_p, int bufSize);
00867 
00868 /* Backward compatibility macro */
00869 #define xd_indeflen(m) xd_indeflen_ex(m, INT_MAX)
00870 
00882 EXTERNBER int xd_len (OSCTXT *pctxt, int *len_p);
00883 
00898 EXTERNBER int xd_chkend (OSCTXT *pctxt, ASN1CCB* ccb_p);
00899 
00911 EXTERNBER int xd_count (OSCTXT *pctxt, int length, int *count_p);
00912 
00921 EXTERNBER int xd_NextElement (OSCTXT* pctxt);
00922 
00937 EXTERNBER int xd_Tag1AndLen (OSCTXT* pctxt, OSINT32* len_p);
00938 
00939 /* internal decode function to do memory copies */
00954 EXTERNBER int xd_memcpy (OSCTXT* pctxt, OSOCTET *object_p, int length) ;
00955 
00974 EXTERNBER int xd_match1 (OSCTXT *pctxt, OSOCTET tag, int *len_p);
00975 
00976 
00979 /* file decode functions */
00980 
01016 EXTERNBER int xdf_tag (FILE* fp, ASN1TAG* ptag, OSOCTET* buffer, int* pbufidx);
01017 
01036 EXTERNBER int xdf_len (FILE* fp, OSINT32* plen, OSOCTET* buffer, int* pbufidx);
01037 
01058 EXTERNBER int xdf_TagAndLen (FILE* fp, ASN1TAG* ptag, OSINT32* plen, 
01059                              OSOCTET* buffer, int* pbufidx);
01060 
01082 EXTERNBER int xdf_ReadPastEOC (FILE* fp, OSOCTET* buffer, 
01083                                int bufsiz, int* pbufidx);
01084 
01108 EXTERNBER int xdf_ReadContents (FILE* fp, int len, OSOCTET* buffer,
01109                                 int bufsiz, int* pbufidx);
01114 /* encode functions */
01162 EXTERNBER int xe_tag_len (OSCTXT *pctxt, ASN1TAG tag, int length) ;
01163 
01187 EXTERNBER int xe_boolean (OSCTXT* pctxt, OSBOOL* object_p, 
01188                           ASN1TagType tagging);
01189 
01210 EXTERNBER int xe_integer (OSCTXT* pctxt, int *object_p, ASN1TagType tagging);
01211 
01233 EXTERNBER int xe_unsigned (OSCTXT* pctxt, OSUINT32 *object_p, 
01234                            ASN1TagType tagging);
01235 
01256 EXTERNBER int xe_int8 (OSCTXT* pctxt, OSINT8 *object_p, ASN1TagType tagging);
01257 
01278 EXTERNBER int xe_int16 (OSCTXT* pctxt, OSINT16 *object_p, ASN1TagType tagging);
01279 
01302 EXTERNBER int xe_int64 (OSCTXT* pctxt, OSINT64 *object_p, 
01303                         ASN1TagType tagging);
01304 
01328 EXTERNBER int xe_uint64 (OSCTXT* pctxt, OSUINT64 *object_p, 
01329                          ASN1TagType tagging);
01330 
01352 EXTERNBER int xe_uint8 (OSCTXT* pctxt, OSUINT8 *object_p, ASN1TagType tagging);
01353 
01375 EXTERNBER int xe_uint16 (OSCTXT* pctxt, OSUINT16 *object_p, ASN1TagType tagging);
01376 
01402 EXTERNBER int xe_bigint (OSCTXT* pctxt, const char* object_p, 
01403                          ASN1TagType tagging);
01404 
01426 EXTERNBER int xe_bitstr (OSCTXT* pctxt, const OSOCTET* object_p, 
01427                          OSUINT32 numbits, ASN1TagType tagging);
01428 
01451 EXTERNBER int xe_octstr (OSCTXT* pctxt, const OSOCTET* object_p, 
01452                          OSUINT32 numocts, ASN1TagType tagging);
01453 
01480 EXTERNBER int xe_charstr (OSCTXT* pctxt, const char* object_p, 
01481                           ASN1TagType tagging, ASN1TAG tag);
01482  
01502 #define xe_utf8str(pctxt,object_p,tagging) \
01503 xe_charstr (pctxt, (const char*)object_p, tagging, ASN_ID_UTF8String)
01504 
01534 EXTERNBER int xe_16BitCharStr (OSCTXT* pctxt, Asn116BitCharString* object_p, 
01535                                ASN1TagType tagging, ASN1TAG tag);
01536 
01566 EXTERNBER int xe_32BitCharStr (OSCTXT* pctxt, Asn132BitCharString* object_p, 
01567                                ASN1TagType tagging, ASN1TAG tag);
01568 
01585 EXTERNBER int xe_null (OSCTXT* pctxt, ASN1TagType tagging);
01586 
01604 EXTERNBER int xe_objid (OSCTXT* pctxt, ASN1OBJID *object_p, 
01605                         ASN1TagType tagging);
01606 
01625 EXTERNBER int xe_oid64 (OSCTXT* pctxt, ASN1OID64 *object_p, 
01626                         ASN1TagType tagging);
01627 
01645 EXTERNBER int xe_reloid (OSCTXT* pctxt, ASN1OBJID *object_p, 
01646                          ASN1TagType tagging);
01647 
01668 EXTERNBER int xe_enum (OSCTXT* pctxt, OSINT32 *object_p, ASN1TagType tagging);
01669 
01694 EXTERNBER int xe_real (OSCTXT* pctxt, OSREAL *object_p, ASN1TagType tagging);
01695 
01715 EXTERNBER int xe_OpenType (OSCTXT* pctxt, const OSOCTET* object_p, 
01716                            OSUINT32 numocts);
01717 
01724 EXTERNBER int xe_OpenTypeExt (OSCTXT* pctxt, OSRTDList* pElemList);
01725 
01744 EXTERNBER int xe_real10 (OSCTXT *pctxt, const char* object_p, 
01745                          ASN1TagType tagging);
01746 
01765 EXTERNBER int xe_derReal10 (OSCTXT *pctxt, const char* object_p, 
01766                             ASN1TagType tagging);
01767 
01785 EXTERNBER int xe_setp (OSCTXT* pctxt, OSOCTET *buf_p, int bufsiz);
01786 
01800 EXTERNBER OSOCTET* xe_getp (OSCTXT* pctxt);
01801 
01819 EXTERNBER void xe_free (OSCTXT* pctxt);
01820 
01844 EXTERNBER int xe_expandBuffer (OSCTXT *pctxt, size_t length);
01845 
01866 EXTERNBER int xe_memcpy (OSCTXT *pctxt, const OSOCTET* object_p, 
01867                          size_t length) ;
01868 
01882 EXTERNBER int xe_len (OSCTXT *pctxt, int length) ;
01883 
01902 EXTERNBER int xe_derCanonicalSort (OSCTXT* pctxt, OSRTSList* pList);
01903 
01919 EXTERNBER int xe_TagAndIndefLen (OSCTXT *pctxt, ASN1TAG tag, int length) ;
01920 
01928 EXTERNBER void xe_getBufLocDescr (OSCTXT *pctxt, OSUINT32 length, 
01929                                   Asn1BufLocDescr* pDescr);
01930 
01950 EXTERNBER int derEncBitString 
01951 (OSCTXT* pctxt, const OSOCTET* pvalue, OSUINT32 numbits, 
01952  ASN1TagType tagging);
01953 
01956 /* utility functions */
01957 
01977 EXTERNBER OSBOOL berErrAddTagParm (OSCTXT* pctxt, ASN1TAG tag);
01978 
01979 /* Note: this definition is deprecated.  Calls to xu_addTagErrParm      */
01980 /* should be replaced with berErrAddTagParm.                            */
01981 #define xu_addTagErrParm berErrAddTagParm
01982 
01983 #ifndef _COMPACT
01984 
01993 EXTERNBER int berErrUnexpTag (OSCTXT* pctxt, ASN1TAG exptag);
01994 #else
01995 #define berErrUnexpTag(pctxt,exptag) RTERR_IDNOTFOU
01996 #endif
01997 
02007 EXTERNBER const char* berTagToString 
02008 (ASN1TAG tag, char* buffer, size_t bufsiz);
02009 
02020 EXTERNBER const char* berTagToDynStr (OSCTXT* pctxt, ASN1TAG tag);
02021 
02022 EXTERNBER int xu_verify_len (OSOCTET *msg_p);
02023 EXTERNBER void *xu_parse_mmbuf (
02024   OSOCTET **buf_p2, int *buflen_p, OSOCTET *start_p, int bufsiz);
02025 
02049 EXTERNBER void xu_alloc_array (
02050   OSCTXT* pctxt, ASN1SeqOf* seqOf_p, int recSize, int recCount);
02051 
02052 EXTERNBER void xu_octscpy_s (
02053   OSUINT32* nocts_p, OSOCTET *data_p, char *cstr, char zterm);
02054 
02055 EXTERNBER void xu_octscpy_ss (ASN1OctStr *octStr_p, char *cstring, char zterm);
02056 
02057 EXTERNBER void xu_octscpy_d (
02058   OSCTXT* pctxt, OSUINT32* nocts_p, const OSOCTET** data_p2, 
02059   char* cstring, char zterm);
02060 
02061 EXTERNBER void xu_octscpy_ds (
02062   OSCTXT* pctxt, ASN1DynOctStr *octStr_p, char *cstring, char zterm);
02063 
02064 EXTERNBER void xu_octmcpy_s (ASN1OctStr *octStr_p, void* data_p, int datalen);
02065 
02066 EXTERNBER void xu_octmcpy_d (
02067   OSCTXT* pctxt, ASN1DynOctStr *octStr_p, void* data_p, int datalen);
02068 
02069 EXTERNBER char* xu_fetchstr (int numocts, char *data);
02070 
02071 EXTERNBER int xu_hexstrcpy (char *data, char *hstring);
02072 EXTERNBER int xu_binstrcpy (char *data, char *bstring);
02073 
02099 EXTERNBER int xu_dump (OSOCTET *msgptr, ASN1DumpCbFunc cb, void* cbArg_p);
02100 
02112 EXTERNBER int xu_fdump (FILE *file_p, OSOCTET *msgptr);
02113 
02129 EXTERNBER void xu_hex_dump (OSOCTET *data, int numocts, OSBOOL hdrflg);
02130 
02131 EXTERNBER void xu_fmt_tag (
02132   ASN1TAG *tag_p, char *class_p, char *form_p, char *id_code);
02133 
02134 EXTERNBER char* xu_fmt_contents (OSCTXT* pctxt, int len, int *count);
02135 
02136 EXTERNBER int  xu_fread (FILE* fp, OSOCTET* bufp, int bufsiz);
02137 
02144 EXTERNBER void xu_SaveBufferState (OSCTXT* pCtxt, OSRTBufSave* pSavedInfo);
02145 
02153 EXTERNBER void xu_RestoreBufferState (OSCTXT* pCtxt, OSRTBufSave* pSavedInfo);
02154 
02158 /* This macro will fetch the next byte in the input stream.  A test is  */
02159 /* done for buffer overrun.                                             */
02160 
02161 #define XD_MEMCPY1(pctxt, object_p) \
02162 ((ASN1BUF_INDEFLEN(pctxt) || \
02163 ((pctxt)->buffer.byteIndex < (pctxt)->buffer.size)) ? \
02164 (*object_p = *OSRTBUFPTR(pctxt), (pctxt)->buffer.byteIndex ++, 0) : \
02165 RTERR_ENDOFBUF)
02166 
02167 /* This macro will fetch the next byte in the input stream.  No test is */
02168 /* done for buffer overrun..                                            */
02169 
02170 #define XD_FETCH1(pctxt) ((pctxt)->buffer.data[(pctxt)->buffer.byteIndex++])
02171 
02172 /* This macro will match a single-byte tag. It does not advance the     */
02173 /* decode cursor.                                                       */
02174 
02175 #define XD_PEEKTAG(pctxt, tag) \
02176 (((pctxt)->buffer.data[(pctxt)->buffer.byteIndex] & (~0x20)) == (tag & (~0x20)))
02177 
02178 /* This macro returns true if the next tag is constructed.              */
02179 /* It does not advance the decode cursor.                               */
02180 
02181 #define XD_PEEKPC(pctxt) \
02182 (((pctxt)->buffer.data[(pctxt)->buffer.byteIndex] & 0x20) == 0x20)
02183 
02184 /* This macro will test for an EOC (end-of-context) marker */
02185 
02186 #define XD_MATCHEOC(pctxt) \
02187 ( ( (pctxt)->buffer.byteIndex + 2 <= (pctxt)->buffer.size ) && \
02188 ( (pctxt)->buffer.data[(pctxt)->buffer.byteIndex] == 0 ) && \
02189 ( (pctxt)->buffer.data[(pctxt)->buffer.byteIndex + 1] == 0 ) )
02190 
02191 /* These macros will test a series of bytes in the decode buffer for a  */
02192 /* match.                                                               */
02193 #define XD_MATCHBYTES1(pctxt, b1) \
02194 ((pctxt)->buffer.data[(pctxt)->buffer.byteIndex] == b1)
02195 
02196 #define XD_MATCHBYTES2(pctxt, b1, b2) \
02197 (((pctxt)->buffer.data[(pctxt)->buffer.byteIndex] == b1) && \
02198  ((pctxt)->buffer.data[(pctxt)->buffer.byteIndex+1] == b2))
02199 
02200 #define XD_MATCHBYTES3(pctxt, b1, b2, b3) \
02201 (((pctxt)->buffer.data[(pctxt)->buffer.byteIndex] == b1) && \
02202  ((pctxt)->buffer.data[(pctxt)->buffer.byteIndex+1] == b2) && \
02203  ((pctxt)->buffer.data[(pctxt)->buffer.byteIndex+2] == b3))
02204 
02205 #define XD_MATCHBYTES4(pctxt, b1, b2, b3, b4) \
02206 (((pctxt)->buffer.data[(pctxt)->buffer.byteIndex] == b1) && \
02207  ((pctxt)->buffer.data[(pctxt)->buffer.byteIndex+1] == b2) && \
02208  ((pctxt)->buffer.data[(pctxt)->buffer.byteIndex+2] == b3) && \
02209  ((pctxt)->buffer.data[(pctxt)->buffer.byteIndex+3] == b4))
02210 
02211 #define XD_MATCHBYTES5(pctxt, b1, b2, b3, b4, b5) \
02212 (((pctxt)->buffer.data[(pctxt)->buffer.byteIndex] == b1) && \
02213  ((pctxt)->buffer.data[(pctxt)->buffer.byteIndex+1] == b2) && \
02214  ((pctxt)->buffer.data[(pctxt)->buffer.byteIndex+2] == b3) && \
02215  ((pctxt)->buffer.data[(pctxt)->buffer.byteIndex+3] == b4) && \
02216  ((pctxt)->buffer.data[(pctxt)->buffer.byteIndex+4] == b5))
02217 
02218 /* This macro will advance the decode buffer index by the given number  */
02219 /* number of bytes.                                                     */
02220 
02221 #define XD_BUMPIDX(pctxt, nbytes) ((pctxt)->buffer.byteIndex += nbytes)
02222 
02223 /* This macro will test for buffer overrun */
02224 
02225 #define XD_CHKBUFEND(pctxt) \
02226 (((ASN1BUF_INDEFLEN(pctxt)) || \
02227 ((pctxt)->buffer.byteIndex <= (pctxt)->buffer.size)) ? 0 : RTERR_ENDOFBUF)
02228 
02229 /* This macro will test if the given length value is within the current */
02230 /* bounds of the message buffer.  The given length value is assumed to  */
02231 /* be a definite length (i.e != ASN_K_INDEFLEN)..                       */
02232 
02233 #define XD_CHKDEFLEN(pctxt,len) \
02234 (((ASN1BUF_INDEFLEN(pctxt)) || \
02235 (((pctxt)->buffer.byteIndex + len) <= (pctxt)->buffer.size)) ? \
02236 0 : RTERR_ENDOFBUF)
02237 
02238 /* This macro will test for EOB */
02239 
02240 #define XD_CHKEOB(pctxt) \
02241 (((pctxt)->buffer.byteIndex + 2 > (pctxt)->buffer.size) ? TRUE : \
02242 (((pctxt)->buffer.data[(pctxt)->buffer.byteIndex] == 0 && \
02243 (pctxt)->buffer.data[(pctxt)->buffer.byteIndex + 1] == 0 ) ? \
02244 TRUE : FALSE))
02245 
02246 /* This macro will test for CCB overrun */
02247 
02248 #define XD_CHKEND(pctxt,ccb_p) \
02249 (((ccb_p)->len == ASN_K_INDEFLEN) ? XD_CHKEOB(pctxt) : \
02250 ((OSRTBUFPTR(pctxt) - (ccb_p)->ptr >= (ccb_p)->len) || \
02251 ((pctxt)->buffer.byteIndex >= (pctxt)->buffer.size)))
02252 
02253 /* This macro will check if the given amount of space is available      */
02254 /* in the encode buffer and attempt tp expand the buffer if necessary   */
02255 
02256 #define XE_CHKBUF(pctxt,len) \
02257 if (len > (pctxt)->buffer.byteIndex) { \
02258 int stat = xe_expandBuffer (pctxt, len); \
02259 if (stat != 0) return stat; }
02260 
02261 /* This macro will put one byte into the encode buffer.  It is assumed  */
02262 /* that there is enough space available for the byte.                   */
02263 
02264 #define XE_PUT1(pctxt,ch) \
02265 (pctxt)->buffer.data[--(pctxt)->buffer.byteIndex] = ch;
02266 
02267 /* This macro will put two bytes into the encode buffer.  It is assumed */
02268 /* that there is enough space available for the bytes.                  */
02269 
02270 #define XE_PUT2(pctxt,ch1,ch2) \
02271 (pctxt)->buffer.byteIndex -= 2; \
02272 (pctxt)->buffer.data[(pctxt)->buffer.byteIndex] = ch1; \
02273 (pctxt)->buffer.data[(pctxt)->buffer.byteIndex+1] = ch2;
02274 
02275 /*
02276  * This macro will put one byte into the encode buffer.  It will first
02277  * check to see if enough space is available for the byte and attempt
02278  * to expand the buffer if necessary.
02279 */
02280 #define XE_SAFEPUT1(pctxt,ch) \
02281 XE_CHKBUF(pctxt,1); (pctxt)->buffer.data[--(pctxt)->buffer.byteIndex] = ch;
02282 
02283 #ifdef __cplusplus
02284 }
02285 #endif
02286 
02287 #endif /* _OSRTBER_H_ */