1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262
|
/* -*- Mode: C;-*-
*
* This file is part of XDelta - A binary delta generator.
*
* Copyright (C) 1997, 1998 Josh MacDonald
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* Author: Josh MacDonald <jmacd@CS.Berkeley.EDU>
*
* xdelta.h,v 1.10 1998/10/03 02:32:09 jmacd Exp
*/
#ifndef _XDELTA_H_
#define _XDELTA_H_
#include "xdser.h"
typedef SerialRsyncIndex XdeltaRsync;
typedef SerialRsyncIndexElt XdeltaRsyncElt;
typedef SerialXdeltaChecksum XdeltaChecksum;
typedef SerialXdeltaIndex XdeltaIndex;
typedef SerialXdeltaSourceInfo XdeltaSourceInfo;
typedef SerialXdeltaControl XdeltaControl;
typedef SerialXdeltaInstruction XdeltaInstruction;
typedef struct _XdeltaMD5Table XdeltaMD5Table;
typedef struct _XdeltaGenerator XdeltaGenerator;
typedef struct _XdeltaSource XdeltaSource;
typedef FileHandle XdeltaStream;
typedef FileHandle XdeltaOutStream;
typedef enum _XdpError XdpError;
#ifdef _WIN32
#define MSEXPORT __declspec(dllexport)
#else
#define MSEXPORT
#endif
/* $Format: "#define XDELTA_VERSION \"$LibCurrent$.$LibRevision$.$LibAge$\"" $ */
#define XDELTA_VERSION "1.0.0"
#define QUERY_SIZE 4 /* segments are of length 1<<QUERY_SIZE */
#define QUERY_SIZE_POW (1<<QUERY_SIZE)
#define QUERY_SIZE_MASK (QUERY_SIZE_POW-1)
#define XDELTA_MAX_FILE_LEN (1<<(32-QUERY_SIZE-2))
enum _XdpError {
XDP_StreamMapFailed = -1,
XDP_StreamUnmapFailed = -2,
XDP_StreamWriteFailed = -3,
XDP_StreamCloseFailed = -4,
XDP_TooManySources = -5,
XDP_SourceTooLong = -6,
XDP_TooFewSources = -7,
XDP_ControlEof = -8,
XDP_IllegalInstruction = -9,
XDP_MismatchedFromMD5 = -10,
XDP_MismatchedToMD5 = -11,
XDP_BadDataMD5 = -12,
XDP_BadControlMagic = -13,
XDP_UnrecognizedControlSeq = -14,
XDP_BadDataLength = -15,
XDP_BadSrcControl = -16,
XDP_CannotNormalize = -17,
XDP_CallbackFailed = -18,
XDP_CallbackShort = -19,
XDP_InvalidChecksumCache = -20,
XDP_BadLength = -21,
XDP_InvalidRsyncCache = -22,
XDP_StreamSerializeFailed = -23,
XDP_InvalidStream = -24,
XDP_StreamTooLong = -25
};
struct _XdeltaMD5Table
{
void (* table_md5_init) (gpointer);
void (* table_md5_update) (gpointer, const guint8 *, guint);
void (* table_md5_final) (guint8*, gpointer);
guint table_md5_ctx_size;
};
/* An xdelta consists of two pieces of information, the control and
* data segments. The control segment consists of instructions,
* metadata, and redundency check information. The data segment
* consists of literal data not found in any of the sources.
*
* The library operates on two types of streams, random access and
* non-seekable. Briefly, you initialize a XdeltaGenerator with one
* or more XdeltaSources. These XdeltaSources contain a random access
* stream. If these XdeltaSources are themselves the data segment of
* another delta, the control segment for that delta should be
* supplied as well for the creation of normalized deltas.
*
* The generator is initialized with an input stream and an output
* stream, these streams are not seekable.
*
* The creation of a XdeltaSource requires a complete pass through the
* file. This pass pre-computes an index which is used during delta
* computation. This index may be saved and restored to avoid
* computing it multiple times.
*/
/* Create a new generator. One of these must be used for all other
* Xdelta transactions. */
#define xdp_generator_new(t,m) __xdp_generator_new (t,m,XDELTA_VERSION)
XdeltaGenerator* MSEXPORT __xdp_generator_new (const HandleFuncTable *table,
const XdeltaMD5Table *md5,
const char *version);
/* Clear any state assocated with the object. */
void MSEXPORT xdp_generator_reset (XdeltaGenerator *gen);
/* Create a new source. If non-null, DELTA_CONTROL_IN indicates
* that SOURCE_IN is the data segment of another delta--the delta
* produced will be normalized accordingly. If non-null, INDEX_IN
* indicates that the index was previously computed and may be read
* from the stream. If non-null, INDEX_OUT is a stream to which the
* the computed index will be written. INDEX_OUT is ignored when
* INDEX_IN is non-null. Returns the source on success, NULL on
* failure, setting xdp_errno in the generator. */
XdeltaSource* MSEXPORT xdp_source_new (XdeltaGenerator *gen,
XdeltaControl *delta_control_in,
XdeltaStream *source_in,
XdeltaStream *index_in,
XdeltaOutStream *index_out);
/* Simply index the source, do not save it in memory. Returns true on
* success, false on failure, setting xdp_errno in the generator. */
gboolean MSEXPORT xdp_source_index (XdeltaGenerator *gen,
XdeltaStream *source_in,
XdeltaOutStream *index_out);
/* Add SRC to the generator. The source will then be used for generating
* deltas. */
void MSEXPORT xdp_source_add (XdeltaGenerator *gen,
XdeltaSource *src);
/* Actually generate a delta against the accumulated sources in GEN.
* Returns the delta's controller or NULL on failure after setting
* xdp_errno. */
XdeltaControl* MSEXPORT xdp_generate_delta (XdeltaGenerator *gen,
XdeltaStream *in,
gboolean normalize,
XdeltaOutStream *control_out,
XdeltaOutStream *data_out);
/* Returns the last error code generated, one of the enumerated
* constants XDP_ERRNO_XXXXX. */
gint MSEXPORT xdp_errno (XdeltaGenerator *gen);
const char* MSEXPORT xdp_strerror (gint e);
/* Reads a control object from a stream. */
XdeltaControl* MSEXPORT xdp_control_read (XdeltaGenerator *gen,
XdeltaStream *cont_in);
/* Writes a control object to a stream. */
gboolean MSEXPORT xdp_control_write (XdeltaGenerator *gen,
XdeltaControl *cont,
XdeltaOutStream *cont_out);
/* Returns the number of files this delta depends on. */
gint MSEXPORT xdp_control_depends_on_count (XdeltaControl *cont);
/* Returns the MD5 checksum of the i-th file this delta depends on. */
const guint8* MSEXPORT xdp_control_depends_on (XdeltaControl *cont, guint i);
/* Returns the MD5 checksum of the i-th normalized file this delta depends on. */
const guint8* MSEXPORT xdp_control_depends_on_normalized (XdeltaControl *cont, guint i);
void MSEXPORT xdp_source_free (XdeltaSource *src);
void MSEXPORT xdp_generator_free (XdeltaGenerator *gen);
void MSEXPORT xdp_control_free (XdeltaControl *con);
/* To apply these patches... */
/* This callback is called when the apply step requires a data source.
* USER_DATA is the argument provided to xdp_apply_delta.
* REQUIRED is true iff the range is for a normalize instruction
* or a regular instruction when a normalized instruction is not
* available (in other words, failure is guaranteed if this
* function fails while REQUIRED is true).
* OFFSET and LENGTH are the range to write to WRITE_TO using the
* function WRITE
*/
typedef gboolean (XdpSourceCallback) (XdeltaGenerator *gen,
void *user_data,
const guint8 *expected_md5,
gboolean required,
guint offset,
guint length,
XdeltaOutStream *write_to);
gboolean MSEXPORT xdp_apply_delta (XdeltaGenerator *gen,
XdeltaControl *cont,
XdeltaStream *data,
XdpSourceCallback *call,
void *user_data,
XdeltaOutStream *res);
/* For use in (especially recursive) callbacks, this function results
* in the library calling CALL appropriately to write length LEN at
* offset OFF from the file constructed by the delta CONT (without
* actually constructing it). WRITE and USER_DATA are passed to CALL.
* Conceptually, this is just like xdp_apply_delta for an offset and
* length. Using this recursively in CALL allows application of
* multiple deltas without constructing intermediate files. */
gboolean MSEXPORT xdp_copy_delta_region (XdeltaGenerator *gen,
XdeltaControl *cont,
XdeltaStream *data,
XdpSourceCallback *call,
guint off,
guint len,
void *user_data,
XdeltaOutStream *write);
/* Forward, backward annotation. Can it be done well at this level? */
/* @@@ */
/* Rsync. */
XdeltaRsync* MSEXPORT xdp_rsync_index (XdeltaGenerator *gen,
XdeltaStream *file,
guint seg_len,
XdeltaStream *cache_in,
XdeltaOutStream *cache_out);
void MSEXPORT xdp_rsync_index_free (XdeltaRsync *rsync);
/* Returns an array of the needed chunks. */
GArray* MSEXPORT xdp_rsync_reqest (XdeltaGenerator *gen,
XdeltaStream *file,
XdeltaRsync *rsync);
gboolean MSEXPORT xdp_apply_rsync_reply (XdeltaGenerator *gen,
XdeltaRsync *rsync,
XdeltaStream *from,
XdeltaStream *reply,
XdeltaStream *out);
#endif
|