1 /* -*- Mode: C;-*-
2  *
3  * This file is part of XDelta - A binary delta generator.
4  *
5  * Copyright (C) 1997, 1998, 2001  Josh MacDonald
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  *
21  * Author: Josh MacDonald <jmacd@CS.Berkeley.EDU>
22  *
23  * $Id: xdelta.h 1.4.1.8.1.50.1.3 Fri, 29 Jun 2001 06:01:08 -0700 jmacd $
24  */
25 
26 #ifndef _XDELTA_H_
27 #define _XDELTA_H_
28 
29 #include "xd_edsio.h"
30 
31 typedef SerialRsyncIndex          XdeltaRsync;
32 typedef SerialRsyncIndexElt       XdeltaRsyncElt;
33 typedef SerialXdeltaChecksum      XdeltaChecksum;
34 typedef SerialXdeltaIndex         XdeltaIndex;
35 typedef SerialXdeltaSourceInfo    XdeltaSourceInfo;
36 typedef SerialXdeltaControl       XdeltaControl;
37 typedef SerialXdeltaInstruction   XdeltaInstruction;
38 
39 typedef struct _XdeltaGenerator   XdeltaGenerator;
40 typedef struct _XdeltaSource      XdeltaSource;
41 
42 typedef FileHandle XdeltaStream;
43 typedef FileHandle XdeltaOutStream;
44 
45 /* Note: FileHandle is an opaque type, you must define it
46  * to use this library.  See how its done in xdmain.c.
47  */
48 
49 /* $Format: "#define XDELTA_VERSION \"$ReleaseVersion$\"" $ */
50 #define XDELTA_VERSION "1.1.4"
51 
52 /* $Format: "#define XDELTA_MAJOR_VERSION $ReleaseMajorVersion$" $ */
53 #define XDELTA_MAJOR_VERSION 1
54 
55 /* $Format: "#define XDELTA_MINOR_VERSION $ReleaseMinorVersion$" $ */
56 #define XDELTA_MINOR_VERSION 1
57 
58 /* $Format: "#define XDELTA_MICRO_VERSION $ReleaseMicroVersion$" $ */
59 #define XDELTA_MICRO_VERSION 4
60 
61 extern const guint xdelta_major_version;
62 extern const guint xdelta_minor_version;
63 extern const guint xdelta_micro_version;
64 
65 /* copy segments are of length 1<<QUERY_SIZE, this must not be greater
66  * than 6 due to a space assumption, and also limits the number of
67  * sources allowed to (QUERY_SIZE_POW-1).
68  *
69  * The in-core FROM CKSUM table's size is (FROM_LEN bytes * 4 bytes-per-checksum) / (1<<QUERY_SIZE)
70  *
71  * The in-core CKSUM HASH table's size is the same size, each checksum has one 32-bit offset+srcindex
72  *
73  * With the a value of (QUERY_SIZE = 4) gives a 16 byte block size,
74  * gives FROM_LEN/4 bytes for the FROM CKSUM map, and the same for the
75  * CKSUM HASH, giving FROM_LEN/2 bytes, in addition to whatever used
76  * to cache the FROM inputs.
77  **/
78 #define QUERY_SIZE_DEFAULT  4
79 
80 /* The query size has historically been hard coded.  This gains around
81  * 20% in speed, so I've left it the default.  If you're interested in
82  * large files, try undefining this (and using the -s argument to
83  * Xdelta).
84  */
85 #define XDELTA_HARDCODE_SIZE
86 
87 #ifdef XDELTA_HARDCODE_SIZE
88 #define QUERY_SIZE          QUERY_SIZE_DEFAULT
89 #define QUERY_SIZE_POW      (1<<QUERY_SIZE)
90 #define QUERY_SIZE_MASK     (QUERY_SIZE_POW-1)
91 #else
92 extern int QUERY_SIZE;
93 extern int QUERY_SIZE_POW;
94 extern int QUERY_SIZE_MASK;
95 #endif
96 
97 #define XDP_QUERY_HARDCODED -7654
98 #define XDP_QUERY_POW2      -7655
99 
100 /* Returns  if query size is hard coded. */
101 int xdp_set_query_size_pow (int size_pow);
102 int xdp_blocksize          ();
103 
104 /* An xdelta consists of two pieces of information, the control and
105  * data segments.  The control segment consists of instructions,
106  * metadata, and some redundent information for validation.  The data
107  * segment consists of literal data not found in any of the sources.
108  *
109  * The library operates on two types of streams, random access and
110  * non-seekable.  Briefly, you initialize a XdeltaGenerator with one
111  * or more XdeltaSources.  These XdeltaSources contain a random access
112  * stream (a FROM file).
113  *
114  * The generator is initialized with an input stream and an output
115  * stream, these streams are not seekable.
116  *
117  * The creation of a XdeltaSource requires a complete pass through the
118  * file.  This pass pre-computes an index which is used during delta
119  * computation.  This index may be saved and restored to avoid
120  * computing it multiple times.
121  *
122  */
123 
124 #define xdp_generator_new() __xdp_generator_new (XDELTA_VERSION)
125 
126 XdeltaGenerator* __xdp_generator_new      (const char      *version);
127 
128 /* Create a new source.  If non-null, INDEX_IN indicates that the
129  * index was previously computed and may be read from the stream.  If
130  * non-null, INDEX_OUT is a stream to which the the computed index
131  * will be written.  INDEX_OUT is ignored when INDEX_IN is non-null.
132  * Returns the source on success, NULL on failure.
133  */
134 
135 XdeltaSource*    xdp_source_new           (const char      *name,
136 					   XdeltaStream    *source_in,
137 					   XdeltaStream    *index_in,
138 					   XdeltaOutStream *index_out);
139 
140 /* Simply index the source, do not save it in memory.  Returns true on
141  * success, false on failure. */
142 gboolean         xdp_source_index         (XdeltaStream    *source_in,
143 					   XdeltaOutStream *index_out);
144 
145 /* Add SRC to the generator.  The source will then be used for generating
146  * deltas. */
147 void             xdp_source_add           (XdeltaGenerator *gen,
148 					   XdeltaSource    *src);
149 
150 /* Actually generate a delta against the accumulated sources in GEN.
151  * Returns the delta's controller or NULL on failure. */
152 XdeltaControl*   xdp_generate_delta       (XdeltaGenerator *gen,
153 					   XdeltaStream    *in,
154 					   XdeltaOutStream *control_out,
155 					   XdeltaOutStream *data_out);
156 
157 /* Reads a control object from a stream. */
158 XdeltaControl*   xdp_control_read         (XdeltaStream    *cont_in);
159 
160 /* Writes a control object to a stream. */
161 gboolean         xdp_control_write        (XdeltaControl   *cont,
162 					   XdeltaOutStream *cont_out);
163 
164 /* Free the above structures */
165 void             xdp_source_free          (XdeltaSource    *src);
166 void             xdp_generator_free       (XdeltaGenerator *gen);
167 void             xdp_control_free         (XdeltaControl   *con);
168 
169 /* Apply: (simple form) first set the IN field of each
170  * XdeltaSourceInfo in the control, then call this. */
171 
172 gboolean         xdp_apply_delta          (XdeltaControl     *cont,
173 					   XdeltaOutStream   *res);
174 
175 /* Rsync: Undocumented, experimental code.  Have a look.  May not
176  * compile. */
177 
178 XdeltaRsync*     xdp_rsync_index          (XdeltaStream      *file,
179 					   guint              seg_len,
180 					   XdeltaStream      *cache_in,
181 					   XdeltaOutStream   *cache_out);
182 
183 void             xdp_rsync_index_free     (XdeltaRsync       *rsync);
184 
185 GArray*          xdp_rsync_request        (XdeltaStream      *file,
186 					   XdeltaRsync       *rsync);
187 
188 gboolean         xdp_apply_rsync_reply    (XdeltaRsync       *rsync,
189 					   XdeltaStream      *from,
190 					   XdeltaStream      *reply,
191 					   XdeltaStream      *out);
192 
193 const char* xdp_errno (int errval);
194 
195 #endif
196