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 #ifndef lint
00034 static char copyright[] =
00035 "@(#) Copyright (c) 2002-2004\n\
00036 Netherlands Forensic Institute. All rights reserved.\n";
00037 #endif
00038
00039
00040 #ifdef HAVE_CONFIG_H
00041 #include "config.h"
00042 #endif
00043
00044 #include <stdlib.h>
00045
00046 #include "rdd.h"
00047 #include "writer.h"
00048
00049 int
00050 rdd_new_writer(RDD_WRITER **self, RDD_WRITE_OPS *ops, unsigned statesize)
00051 {
00052 RDD_WRITER *w = 0;
00053 unsigned char *state = 0;
00054 int rc = RDD_OK;
00055
00056 if (self == 0 || ops == 0) {
00057 return RDD_BADARG;
00058 }
00059
00060 if ((w = calloc(1, sizeof(RDD_WRITER))) == 0) {
00061 rc = RDD_NOMEM;
00062 goto error;
00063 }
00064
00065 if ((state = calloc(1, statesize)) == 0) {
00066 rc = RDD_NOMEM;
00067 goto error;
00068 }
00069
00070 w->state = state;
00071 w->ops = ops;
00072
00073 *self = w;
00074 return RDD_OK;
00075
00076 error:
00077 *self = 0;
00078 if (state != 0) {
00079 free(state);
00080 }
00081 if (w != 0) {
00082 free(w);
00083 }
00084 return rc;
00085 }
00086
00087 int
00088 rdd_writer_write(RDD_WRITER *w, const unsigned char *buf, unsigned nbyte)
00089 {
00090
00091 return (*(w->ops->write))(w, buf, nbyte);
00092 }
00093
00094 int
00095 rdd_writer_close(RDD_WRITER *w)
00096 {
00097 int rc;
00098 if (w == 0) {
00099 return RDD_BADARG;
00100 }
00101
00102 rc = (*(w->ops->close))(w);
00103 if (rc != RDD_OK) {
00104 return rc;
00105 }
00106
00107 free(w->state);
00108
00109 free(w);
00110
00111 return RDD_OK;
00112 }
00113
00114
00115 int
00116 rdd_compare_address(RDD_WRITER *w, struct addrinfo * address, int *result)
00117 {
00118 if (w == 0) {
00119 return RDD_BADARG;
00120 }
00121 return (*(w->ops->compare_address))(w, address, result);
00122 }