BER/DER C File Functions.
[BER Runtime Library Functions.]

Functions

int xdf_tag (FILE *fp, ASN1TAG *ptag, OSOCTET *buffer, int *pbufidx)
int xdf_len (FILE *fp, OSINT32 *plen, OSOCTET *buffer, int *pbufidx)
int xdf_TagAndLen (FILE *fp, ASN1TAG *ptag, OSINT32 *plen, OSOCTET *buffer, int *pbufidx)
int xdf_ReadPastEOC (FILE *fp, OSOCTET *buffer, int bufsiz, int *pbufidx)
int xdf_ReadContents (FILE *fp, int len, OSOCTET *buffer, int bufsiz, int *pbufidx)

Detailed Description

The BER/DER file decode functions allow decode operations to be performed directly on encoded entities within a binary file as opposed to in memory. This makes it possible to parse tag and length variables to determine when pieces of a message can be read into memory. The "tap3batch" sample program provides a good illustration of how these functions are used. They can be applied to a TAP3 batch file to get at the call-detail records for sequential processing without having to read the entire file into memory.

These functions all begin with the prefix "xdf_" to distinguish them from the other decode functions. The following is a description of the various functions that make up this package.


Function Documentation

int xdf_len ( FILE *  fp,
OSINT32 *  plen,
OSOCTET *  buffer,
int *  pbufidx 
)

This function decodes the ASN.1 length from a file stream.

Parameters:
fp The file pointer of the binary file to be decoded. It is expected that the current file position is at the first byte of the tag to be decoded.
plen A pointer to an integer to receive the decoded length value.
buffer The buffer to receive the parsed data.
pbufidx The pointer to the current buffer index containing offset to the location where the decoded bytes should be copied in the output buffer. The updated buffer index set to point at the first free byte after the tag is parsed and copied into the buffer.
Returns:
Completion status of operation:
  • 0 (0) = success,
  • negative return value is error.
int xdf_ReadContents ( FILE *  fp,
int  len,
OSOCTET *  buffer,
int  bufsiz,
int *  pbufidx 
)

This routine reads the contents of a BER tag-length-value (TLV) into the given buffer. The TLV can be of indefinite length.

Parameters:
fp A file pointer of a binary file to be decoded. It is expected that the current file position is the first byte following an indefinite length marker (0x80 byte).
len The length of data to be read from the file. This can be the indefinite constant (ASN_K_INDEFLEN) indicating all data up to the corresponding end-of-context (EOC) marker should be read.
buffer The buffer to receive the parsed data.
bufsiz The size of the buffer to receive the parsed data.
pbufidx The pointer to the current buffer index containing offset to the location where the decoded bytes should be copied in the output buffer. The updated buffer index set to point at the first free byte index after the parsed data is copied to the buffer.
Returns:
Completion status of operation:
  • 0 (0) = success,
  • negative return value is error.
int xdf_ReadPastEOC ( FILE *  fp,
OSOCTET *  buffer,
int  bufsiz,
int *  pbufidx 
)

This function consumes bytes from the file stream until a matching end-of-context (EOC) maker is found. The bytes read from the file are stored in the given buffer for later processing. An indefinite marker is assumed to have been parsed prior to calling this function.

Parameters:
fp A file pointer of a binary file to be decoded. It is expected that the current file position is the first byte following an indefinite length marker (0x80 byte).
buffer The buffer to receive the parsed data.
bufsiz The size of the buffer to receive the parsed data.
pbufidx The pointer to the current buffer index containing offset to the location where the decoded bytes should be copied in the output buffer. The updated buffer index set to point at the first free byte index after the parsed data is copied to the buffer.
Returns:
Completion status of operation:
  • 0 (0) = success,
  • negative return value is error.
int xdf_tag ( FILE *  fp,
ASN1TAG *  ptag,
OSOCTET *  buffer,
int *  pbufidx 
)

This function decodes ASN.1 tag from a file stream into a standard 32-bit ASN.1 tag structure.

Parameters:
fp The file pointer of the binary file to be decoded. It is expected that the current file position is at the first byte of the tag to be decoded.
ptag A pointer to an ASN.1 tag structure to receive the decoded tag.
buffer The buffer to receive the parsed data.
pbufidx The pointer to the current buffer index containing offset to the location where the decoded bytes should be copied in the output buffer. The updated buffer index set to point at the first free byte after the tag is parsed and copied into the buffer.
Returns:
Completion status of operation:
  • 0 (0) = success,
  • negative return value is error.
int xdf_TagAndLen ( FILE *  fp,
ASN1TAG *  ptag,
OSINT32 *  plen,
OSOCTET *  buffer,
int *  pbufidx 
)

This function decodes an ASN.1 tag and length pair from a file stream.

Parameters:
fp The file pointer of the binary file to be decoded. It is expected that the current file position is at the first byte of the tag to be decoded.
ptag A pointer to an ASN1TAG variable to receive parsed the tag value.
plen A pointer to an integer to receive the decoded length value.
buffer The buffer to receive the parsed data.
pbufidx The pointer to the current buffer index containing offset to the location where the decoded bytes should be copied in the output buffer. The updated buffer index set to point at the first free byte after the tag is parsed and copied into the buffer.
Returns:
Completion status of operation:
  • 0 (0) = success,
  • negative return value is error.