summaryrefslogtreecommitdiff
path: root/xdelta1/xdeltapriv.h
blob: 9c75f0931e7139ffe86243cd9b1ddcbcd7e30072 (plain)
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
/* -*- Mode: C;-*-
 *
 * This file is part of XDelta - A binary delta generator.
 *
 * Copyright (C) 1997, 1998, 1999  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>
 *
 * $Id: xdeltapriv.h 1.29 Sat, 03 Apr 1999 20:09:14 -0800 jmacd $
 */

#ifndef _XDELTAPRIV_H_
#define _XDELTAPRIV_H_

#if 0
#define DEBUG_CKSUM_UPDATE
#define DEBUG_MATCH_PRINT
#define DEBUG_CKSUM
#define DEBUG_HASH
#define DEBUG_INST
#define CLOBBER_ALGORITHM_C
#define DEBUG_MD5
#define DEBUG_CONT
#define DEBUG_COPY
#define DEBUG_FIND
#define DEBUG_RSYNC_REQUEST
#define DEBUG_CONT
#define DEBUG_CONT2
#define DEBUG_CHECK_CONTROL
#endif

typedef struct _XdeltaPos         XdeltaPos;
typedef struct _RsyncHash         RsyncHash;

#define XPOS(p) (((p).page * (p).page_size) + (p).off)

struct _XdeltaPos {
  guint page;
  guint page_size;
  guint off;

  const guint8* mem;
  guint mem_page;
  guint mem_rem;
};

#define handle_length(x)    ((* (x)->table->table_handle_length) (x))
#define handle_pages(x)     ((* (x)->table->table_handle_pages) (x))
#define handle_pagesize(x)  ((* (x)->table->table_handle_pagesize) (x))
#define handle_map_page(x,y,z)  ((* (x)->table->table_handle_map_page) ((x),(y),(z)))
#define handle_unmap_page(x,y,z) ((* (x)->table->table_handle_unmap_page) ((x),(y),(z)))
#define handle_checksum_md5(x)   ((* (x)->table->table_handle_checksum_md5) (x))
#define handle_close(x,y)        ((* (x)->table->table_handle_close) ((x), (y)))
#define handle_write(x,y,z)      ((* (x)->table->table_handle_write) ((x),(y),(z)))
#define handle_copy(x,y,z,a)     ((* (x)->table->table_handle_copy) ((x),(y),(z),(a)))

struct _XdeltaGenerator
{
  GPtrArray *sources;

  const guint32 *table;
  guint          table_size;

  guint          to_output_pos;
  guint          data_output_pos;

  XdeltaOutStream  *data_out;
  XdeltaOutStream  *control_out;

  XdeltaControl    *control;

  XdeltaSource     *data_source;

#ifdef DEBUG_HASH
  gint hash_conflicts;           /* bucket already used. */
  gint hash_real_conflicts;      /* bucket had different checksum. */
  gint hash_real_real_conflicts; /* bucket had same checksum, different region */
  gint hash_fill;
  gint hash_entries;
#endif

  EdsioMD5Ctx ctx;
};

struct _XdeltaSource
{
  XdeltaStream    *source_in;
  XdeltaPos        source_pos;

  gint                   ck_count; /* number of elts in cksums. */
  const XdeltaChecksum  *cksums;   /* array of cksums. */

  const char *name;

  XdeltaStream    *index_in;
  XdeltaOutStream *index_out;

  gint             source_index;
  gboolean         used;
  gboolean         sequential;
  guint32          position;
};

#define CHEW(x) (single_hash[(guint)x])
#define FLIP_FORWARD(p)  if ((p).off == (p).page_size) { (p).page += 1; (p).off = 0; }

extern const guint16 single_hash[256];

void           init_pos               (XdeltaStream* str, XdeltaPos* pos);
gboolean       unmap_page             (XdeltaStream* stream, XdeltaPos* pos);
gboolean       map_page               (XdeltaStream* stream, XdeltaPos* pos);
gboolean       check_stream_integrity (XdeltaStream* str, const guint8* md5, guint len);
XdeltaControl* control_new            (void);

guint          c_hash                 (const XdeltaChecksum* c);

#endif /* _XDELTAPRIV_H_ */