v42bis.c File Reference
`#include <stdio.h>`
`#include <stdlib.h>`
`#include <inttypes.h>`
`#include <string.h>`
`#include <errno.h>`
`#include <fcntl.h>`
`#include <ctype.h>`
`#include <assert.h>`
`#include "spandsp/telephony.h"`
`#include "spandsp/logging.h"`
`#include "spandsp/bit_operations.h"`
`#include "spandsp/async.h"`
`#include "spandsp/v42bis.h"`
`#include "spandsp/private/logging.h"`
`#include "spandsp/private/v42bis.h"`

## Macros

#define | V42BIS_N3 8
#define | V42BIS_N4 256
#define | V42BIS_N5 (V42BIS_N4 + V42BIS_N6)
#define | V42BIS_N6 3
#define | V42BIS_ESC_STEP 51
#define | COMPRESSIBILITY_MONITOR (256*V42BIS_N3)
#define | COMPRESSIBILITY_MONITOR_HYSTERESIS 11

## Enumerations

enum | { V42BIS_ETM = 0 , V42BIS_FLUSH = 1 , V42BIS_STEPUP = 2 }
enum | { V42BIS_ECM = 0 , V42BIS_EID = 1 , V42BIS_RESET = 2 }

## Functions

int | v42bis_compress (v42bis_state_t *ss, const uint8_t buf[], int len)
int | v42bis_compress_flush (v42bis_state_t *ss)
int | v42bis_decompress (v42bis_state_t *ss, const uint8_t buf[], int len)
int | v42bis_decompress_flush (v42bis_state_t *ss)
void | v42bis_compression_control (v42bis_state_t *s, int mode)
v42bis_state_t * | v42bis_init (v42bis_state_t *s, int negotiated_p0, int negotiated_p1, int negotiated_p2, put_msg_func_t encode_handler, void *encode_user_data, int max_encode_len, put_msg_func_t decode_handler, void *decode_user_data, int max_decode_len)
int | v42bis_release (v42bis_state_t *s)
int | v42bis_free (v42bis_state_t *s)

## Function Documentation

## v42bis_compress()

int v42bis_compress | ( | v42bis_state_t * | s,
|  | const uint8_t | buf[],
|  | int | len )

Compress a block of octets.

Parameters

  s | The V.42bis context.
  buf | The data to be compressed.
  len | The length of the data buffer.

Returns
  0

References v42bis_state_s::compress, v42bis_comp_state_t::flushed_length, v42bis_comp_state_t::last_added, v42bis_comp_state_t::last_matched, v42bis_comp_state_t::string, v42bis_comp_state_t::string_length, v42bis_comp_state_t::update_at, v42bis_comp_state_t::v42bis_parm_n7, and v42bis_comp_state_t::v42bis_parm_p0.

## v42bis_compress_flush()

int v42bis_compress_flush | ( | v42bis_state_t * | s | ) |

Flush out any data remaining in a compression buffer.

Parameters

  s | The V.42bis context.

Returns
  0

References v42bis_state_s::compress, v42bis_comp_state_t::flushed_length, v42bis_comp_state_t::last_matched, v42bis_comp_state_t::string_length, v42bis_comp_state_t::transparent, and v42bis_comp_state_t::update_at.

## v42bis_compression_control()

void v42bis_compression_control | ( | v42bis_state_t * | s,
|  | int | mode )

Set the compression mode.

Parameters

  s | The V.42bis context.
  mode | One of the V.42bis compression modes - V42BIS_COMPRESSION_MODE_DYNAMIC, V42BIS_COMPRESSION_MODE_ALWAYS, V42BIS_COMPRESSION_MODE_NEVER

References v42bis_state_s::compress, and v42bis_comp_state_t::compression_mode.

## v42bis_decompress()

int v42bis_decompress | ( | v42bis_state_t * | s,
|  | const uint8_t | buf[],
|  | int | len )

Decompress a block of octets.

Parameters

  s | The V.42bis context.
  buf | The data to be decompressed.
  len | The length of the data buffer.

Returns
  0

References v42bis_comp_state_t::bit_buffer, v42bis_comp_state_t::bit_count, v42bis_state_s::decompress, v42bis_comp_state_t::escape_code, v42bis_comp_state_t::escaped, v42bis_comp_state_t::flushed_length, v42bis_comp_state_t::last_added, v42bis_comp_state_t::last_matched, v42bis_state_s::logging, span_log(), v42bis_comp_state_t::string, v42bis_comp_state_t::string_length, v42bis_comp_state_t::transparent, v42bis_comp_state_t::update_at, v42bis_comp_state_t::v42bis_parm_c1, v42bis_comp_state_t::v42bis_parm_c2, v42bis_comp_state_t::v42bis_parm_c3, v42bis_comp_state_t::v42bis_parm_n2, v42bis_comp_state_t::v42bis_parm_n7, and v42bis_comp_state_t::v42bis_parm_p0.

## v42bis_decompress_flush()

int v42bis_decompress_flush | ( | v42bis_state_t * | s | ) |

Flush out any data remaining in the decompression buffer.

Parameters

  s | The V.42bis context.

Returns
  0

References v42bis_state_s::decompress, v42bis_comp_state_t::flushed_length, and v42bis_comp_state_t::string_length.

## v42bis_free()

int v42bis_free | ( | v42bis_state_t * | s | ) |

Free a V.42bis context.

Parameters

  s | The V.42bis context.

Returns
  0 if OK

References v42bis_state_s::compress, and v42bis_state_s::decompress.

## v42bis_init()

v42bis_state_t * v42bis_init | ( | v42bis_state_t * | s,
|  | int | negotiated_p0,
|  | int | negotiated_p1,
|  | int | negotiated_p2,
|  | put_msg_func_t | encode_handler,
|  | void * | encode_user_data,
|  | int | max_encode_len,
|  | put_msg_func_t | decode_handler,
|  | void * | decode_user_data,
|  | int | max_decode_len )

Initialise a V.42bis context.

Parameters

  s | The V.42bis context.
  negotiated_p0 | The negotiated P0 parameter, from the V.42bis spec.
  negotiated_p1 | The negotiated P1 parameter, from the V.42bis spec.
  negotiated_p2 | The negotiated P2 parameter, from the V.42bis spec.
  encode_handler | Encode callback handler.
  encode_user_data | An opaque pointer passed to the encode callback handler.
  max_encode_len | The maximum length that should be passed to the encode handler.
  decode_handler | Decode callback handler.
  decode_user_data | An opaque pointer passed to the decode callback handler.
  max_decode_len | The maximum length that should be passed to the decode handler.

Returns
  The V.42bis context.

References v42bis_state_s::compress, v42bis_state_s::decompress, v42bis_state_s::logging, and v42bis_comp_state_t::v42bis_parm_p0.

## v42bis_release()

int v42bis_release | ( | v42bis_state_t * | s | ) |

Release a V.42bis context.

Parameters

  s | The V.42bis context.

Returns
  0 if OK