00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifdef HAVE_CONFIG_H
00034 #include "config.h"
00035 #endif
00036
00037 #include <stdio.h>
00038 #include <stdlib.h>
00039
00040 #include "rdd.h"
00041 #include "rdd_internals.h"
00042 #include "reader.h"
00043 #include "writer.h"
00044 #include "filter.h"
00045 #include "filterset.h"
00046 #include "copier.h"
00047
00048 int
00049 rdd_new_copier(RDD_COPIER **self, RDD_COPY_OPS *ops, unsigned statesize)
00050 {
00051 RDD_COPIER *c = 0;
00052 unsigned char *state = 0;
00053 int rc;
00054
00055 if (self == 0 || ops == 0) {
00056 return RDD_BADARG;
00057 }
00058
00059 if ((c = calloc(1, sizeof(RDD_COPIER))) == 0) {
00060 return RDD_NOMEM;
00061 }
00062
00063 if ((state = calloc(1, statesize)) == 0) {
00064 free(c);
00065 return RDD_NOMEM;
00066 }
00067 c->state = state;
00068 c->ops = ops;
00069
00070 *self = c;
00071 return RDD_OK;
00072 }
00073
00074 int
00075 rdd_copy_exec(RDD_COPIER *c, RDD_READER *r, RDD_FILTERSET *fset,
00076 RDD_COPIER_RETURN *ret)
00077 {
00078 RDD_COPY_OPS *ops = c->ops;
00079
00080 return (*ops->exec)(c, r, fset, ret);
00081 }
00082
00083 int
00084 rdd_copy_free(RDD_COPIER *c)
00085 {
00086 RDD_COPY_OPS *ops = c->ops;
00087 int rc;
00088
00089 if (ops->free != 0) {
00090 rc = (*ops->free)(c);
00091 if (rc != RDD_OK) {
00092 return rc;
00093 }
00094 }
00095
00096 free(c->state);
00097 c->state = 0;
00098 free(c);
00099
00100 return RDD_OK;
00101 }