A filter is an object that reads a data stream. A filter can perform computations using the data stream's contents, but it is _not_ allowed to modify the data stream that is passed to it. The data that is sent to one filter may later be passed to another filter.
Two types of filters are distinguished: stream filters and block filters. Both filters receive their input through successive calls to their input() routine. Block filters must also supply a block size B and a block() routine. The block routine is called after every B bytes of input data. These B bytes, however, may be passed to the filter through multiple calls to the filter's input() routine.
Definition in file filter.h.
#include <stdio.h>
#include "rdd.h"
#include "writer.h"
Go to the source code of this file.
Data Structures | |
struct | _RDD_FILTER |
struct | _RDD_FILTER_OPS |
Typedefs | |
typedef struct _RDD_FILTER | RDD_FILTER |
typedef struct _RDD_FILTER_OPS | RDD_FILTER_OPS |
typedef int(* | rdd_fltr_block_fun )(struct _RDD_FILTER *f, unsigned nbyte) |
typedef int(* | rdd_fltr_close_fun )(struct _RDD_FILTER *f) |
typedef void(* | rdd_fltr_error_fun )(rdd_count_t pos, rdd_checksum_t expected, rdd_checksum_t computed, void *env) |
typedef int(* | rdd_fltr_free_fun )(struct _RDD_FILTER *f) |
typedef int(* | rdd_fltr_input_fun )(struct _RDD_FILTER *f, const unsigned char *buf, unsigned nbyte) |
typedef int(* | rdd_fltr_rslt_fun )(struct _RDD_FILTER *f, unsigned char *buf, unsigned pos) |
Functions | |
int | rdd_filter_close (RDD_FILTER *f) |
Closes a filter for input. | |
int | rdd_filter_free (RDD_FILTER *f) |
Deallocates a filter and its resources. | |
int | rdd_filter_get_result (RDD_FILTER *f, unsigned char *buf, unsigned nbyte) |
Obtains a filter's result. | |
int | rdd_filter_push (RDD_FILTER *f, const unsigned char *buf, unsigned nbyte) |
Pushes a data buffer into a filter. | |
int | rdd_new_adler32_blockfilter (RDD_FILTER **f, unsigned blocksize, const char *outpath, int overwrite) |
int | rdd_new_crc32_blockfilter (RDD_FILTER **f, unsigned blocksize, const char *outpath, int overwrite) |
int | rdd_new_filter (RDD_FILTER **f, RDD_FILTER_OPS *ops, unsigned statesize, unsigned blocksize) |
int | rdd_new_md5_blockfilter (RDD_FILTER **f, unsigned blocksize, const char *outpath, int overwrite) |
int | rdd_new_md5_streamfilter (RDD_FILTER **f) |
int | rdd_new_sha1_streamfilter (RDD_FILTER **f) |
int | rdd_new_sha256_streamfilter (RDD_FILTER **f) |
int | rdd_new_sha384_streamfilter (RDD_FILTER **f) |
int | rdd_new_sha512_streamfilter (RDD_FILTER **f) |
int | rdd_new_stats_blockfilter (RDD_FILTER **f, unsigned blocksize, const char *outpath, int overwrite) |
int | rdd_new_verify_adler32_blockfilter (RDD_FILTER **f, FILE *fp, unsigned blocksize, int swap, rdd_fltr_error_fun err, void *env) |
int | rdd_new_verify_crc32_blockfilter (RDD_FILTER **f, FILE *fp, unsigned blocksize, int swap, rdd_fltr_error_fun err, void *env) |
int | rdd_new_write_streamfilter (RDD_FILTER **f, RDD_WRITER *writer) |
typedef struct _RDD_FILTER RDD_FILTER |
typedef struct _RDD_FILTER_OPS RDD_FILTER_OPS |
typedef int(* rdd_fltr_block_fun)(struct _RDD_FILTER *f, unsigned nbyte) |
typedef int(* rdd_fltr_close_fun)(struct _RDD_FILTER *f) |
typedef void(* rdd_fltr_error_fun)(rdd_count_t pos, rdd_checksum_t expected, rdd_checksum_t computed, void *env) |
typedef int(* rdd_fltr_free_fun)(struct _RDD_FILTER *f) |
typedef int(* rdd_fltr_input_fun)(struct _RDD_FILTER *f, const unsigned char *buf, unsigned nbyte) |
typedef int(* rdd_fltr_rslt_fun)(struct _RDD_FILTER *f, unsigned char *buf, unsigned pos) |
int rdd_filter_close | ( | RDD_FILTER * | f | ) |
Closes a filter for input.
f | the filter |
RDD_OK
on success.rdd_filter_push()
).
Definition at line 160 of file filter.c.
References _RDD_FILTER_OPS::block, _RDD_FILTER_OPS::close, is_block_filter, _RDD_FILTER::ops, _RDD_FILTER::pos, and RDD_OK.
int rdd_filter_free | ( | RDD_FILTER * | f | ) |
Deallocates a filter and its resources.
f | the filter |
RDD_OK
on success.Definition at line 193 of file filter.c.
References _RDD_FILTER_OPS::free, _RDD_FILTER::ops, RDD_OK, and _RDD_FILTER::state.
int rdd_filter_get_result | ( | RDD_FILTER * | f, | |
unsigned char * | buf, | |||
unsigned | nbyte | |||
) |
Obtains a filter's result.
f | the filter | |
buf | the client's result buffer | |
nbyte | the size of the client's result buffer |
RDD_OK
on success.Definition at line 181 of file filter.c.
References _RDD_FILTER_OPS::get_result, _RDD_FILTER::ops, RDD_BADARG, and RDD_NOTFOUND.
int rdd_filter_push | ( | RDD_FILTER * | f, | |
const unsigned char * | buf, | |||
unsigned | nbyte | |||
) |
Pushes a data buffer into a filter.
f | the filter | |
buf | the data buffer | |
nbyte | the size in bytes of data buffer buf |
RDD_OK
on success.buf
into filter f
. The filter must not modify buffer buf
. The filter will process the buffer as it sees fit.Passes a buffer of nbyte bytes to a filter. If the filter is a stream filter it will simply pass the buffer to the client's handler. If the filter is a block filter, it processes the buffer block by block, calling the client's block handler at each block boundary.
Definition at line 149 of file filter.c.
References block_filter_push(), is_stream_filter, and stream_filter_push().
int rdd_new_adler32_blockfilter | ( | RDD_FILTER ** | f, | |
unsigned | blocksize, | |||
const char * | outpath, | |||
int | overwrite | |||
) |
Definition at line 238 of file checksumblockfilter.c.
References new_checksum_blockfilter(), and RDD_ADLER32.
int rdd_new_crc32_blockfilter | ( | RDD_FILTER ** | f, | |
unsigned | blocksize, | |||
const char * | outpath, | |||
int | overwrite | |||
) |
Definition at line 246 of file checksumblockfilter.c.
References new_checksum_blockfilter(), and RDD_CRC32.
int rdd_new_filter | ( | RDD_FILTER ** | self, | |
RDD_FILTER_OPS * | ops, | |||
unsigned | statesize, | |||
unsigned | blocksize | |||
) |
This is a convenience routine that can (and should) be used by filter implementations to initialize the 'base' filter.
Definition at line 63 of file filter.c.
References _RDD_FILTER_OPS::block, _RDD_FILTER::blocksize, _RDD_FILTER::ops, _RDD_FILTER::pos, RDD_BADARG, RDD_NOMEM, RDD_OK, and _RDD_FILTER::state.
int rdd_new_md5_blockfilter | ( | RDD_FILTER ** | f, | |
unsigned | blocksize, | |||
const char * | outpath, | |||
int | overwrite | |||
) |
Definition at line 87 of file md5blockfilter.c.
References error(), _RDD_BLOCKHASH_FILTER::md5_state, _RDD_BLOCKHASH_FILTER::path, _RDD_BLOCKHASH_FILTER::printer, rdd_mp_open_file_printer(), rdd_new_filter(), RDD_NOMEM, RDD_OK, and _RDD_FILTER::state.
int rdd_new_md5_streamfilter | ( | RDD_FILTER ** | f | ) |
Definition at line 79 of file md5streamfilter.c.
References _RDD_MD5_STREAM_FILTER::md5_state, RDD_BADARG, rdd_new_filter(), RDD_OK, and _RDD_FILTER::state.
int rdd_new_sha1_streamfilter | ( | RDD_FILTER ** | f | ) |
Definition at line 79 of file sha1streamfilter.c.
References RDD_BADARG, rdd_new_filter(), RDD_OK, _RDD_SHA1_STREAM_FILTER::sha1_state, and _RDD_FILTER::state.
int rdd_new_sha256_streamfilter | ( | RDD_FILTER ** | f | ) |
Definition at line 72 of file sha256streamfilter.c.
References RDD_BADARG, rdd_new_filter(), RDD_OK, _RDD_SHA256_STREAM_FILTER::sha256_state, and _RDD_FILTER::state.
int rdd_new_sha384_streamfilter | ( | RDD_FILTER ** | f | ) |
Definition at line 72 of file sha384streamfilter.c.
References RDD_BADARG, rdd_new_filter(), RDD_OK, _RDD_SHA384_STREAM_FILTER::sha384_state, and _RDD_FILTER::state.
int rdd_new_sha512_streamfilter | ( | RDD_FILTER ** | f | ) |
Definition at line 72 of file sha512streamfilter.c.
References RDD_BADARG, rdd_new_filter(), RDD_OK, _RDD_SHA512_STREAM_FILTER::sha512_state, and _RDD_FILTER::state.
int rdd_new_stats_blockfilter | ( | RDD_FILTER ** | f, | |
unsigned | blocksize, | |||
const char * | outpath, | |||
int | overwrite | |||
) |
Definition at line 89 of file statsblockfilter.c.
References _RDD_STATS_BLOCKFILTER::blocknum, error(), _RDD_STATS_BLOCKFILTER::histogram, _RDD_STATS_BLOCKFILTER::maxbyte, _RDD_STATS_BLOCKFILTER::minbyte, NUM_BYTE_VAL, _RDD_STATS_BLOCKFILTER::path, _RDD_STATS_BLOCKFILTER::printer, rdd_mp_open_file_printer(), rdd_new_filter(), RDD_NOMEM, RDD_OK, and _RDD_FILTER::state.
int rdd_new_verify_adler32_blockfilter | ( | RDD_FILTER ** | f, | |
FILE * | fp, | |||
unsigned | blocksize, | |||
int | swap, | |||
rdd_fltr_error_fun | err, | |||
void * | env | |||
) |
Definition at line 246 of file verifyblockfilter.c.
References new_verify_checksum_blockfilter(), and RDD_ADLER32.
int rdd_new_verify_crc32_blockfilter | ( | RDD_FILTER ** | f, | |
FILE * | fp, | |||
unsigned | blocksize, | |||
int | swap, | |||
rdd_fltr_error_fun | err, | |||
void * | env | |||
) |
Definition at line 255 of file verifyblockfilter.c.
References new_verify_checksum_blockfilter(), and RDD_CRC32.
int rdd_new_write_streamfilter | ( | RDD_FILTER ** | f, | |
RDD_WRITER * | writer | |||
) |
Definition at line 83 of file writestreamfilter.c.
References rdd_new_filter(), RDD_OK, _RDD_FILTER::state, and _RDD_WRITE_STREAM_FILTER::writer.