File: private.h

package info (click to toggle)
libhsync 0.5.7-1.2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 1,060 kB
  • ctags: 543
  • sloc: sh: 7,944; ansic: 5,413; makefile: 154
file content (199 lines) | stat: -rw-r--r-- 5,564 bytes parent folder | download
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
/*				       	-*- c-file-style: "bsd" -*-
 * rproxy -- dynamic caching and delta update in HTTP
 * $Id: private.h,v 1.46 2000/08/06 12:50:36 mbp Exp $
 * 
 * Copyright (C) 2000 by Martin Pool <mbp@humbug.org.au>
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */


/* ========================================

   Nice macros */

#undef	MAX
#define MAX(a, b)  (((a) > (b)) ? (a) : (b))

#undef	MIN
#define MIN(a, b)  (((a) < (b)) ? (a) : (b))

#undef	ABS
#define ABS(a)	   (((a) < 0) ? -(a) : (a))

#undef	CLAMP
#define CLAMP(x, low, high)  (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))


#ifdef __GNUC__
#  define UNUSED(x) x __attribute__((unused))
#elif __LCLINT__
#  define UNUSED(x) /*@unused@*/ x
#else				/* !__GNUC__ && !__LCLINT__ */
#  define UNUSED(x) x
#endif				/* !__GNUC__ && !__LCLINT__ */


void           *_hs_alloc_struct0(size_t size, char const *name);

#define _hs_alloc_struct(type)				\
        ((type *) _hs_alloc_struct0(sizeof(type), #type))


#include "netio.h"

/* ========================================

   Literal output buffer.

   Data queued for output is now held in a MEMBUF IO pipe, and copied from
   there into the real output stream when necessary.  */
ssize_t
_hs_push_literal_buf(hs_membuf_t * litbuf,
		     hs_write_fn_t write_fn, void *write_priv,
		     hs_stats_t * stats, int kind);


void            _hs_check_blocksize(int block_len);


/* ========================================

   Memory buffers */


/* An HS_MEMBUF grows dynamically.  BUF points to an array of ALLOC bytes, of 
   which LENGTH contain data.  The cursor is at position OFS.  If BUF is
   null, then no memory has been allocated yet. */
struct hs_membuf {
    int             dogtag;
    byte_t         *buf;
    off_t        ofs;
    ssize_t         length;
    size_t          alloc;
};

/* hs_ptrbuf_t: Memory is provided by the caller, and they retain
   responsibility for it.  BUF points to an array of LENGTH bytes. The cursor 
   is currently at OFS. */
struct hs_ptrbuf {
    int             dogtag;
    byte_t         *buf;
    off_t        ofs;
    size_t          length;
};

/* ========================================

   _hs_inbuf_t: a buffer of new data waiting to be digested.

 */

/* 
   Buffer of new data waiting to be digested and encoded.  This is like a
   map_ptr, but more suitable for reading from a socket, where we can't seek, 
   and therefore can't skip forwards or rewind. Therefore we must be prepared 
   to give up any amount of memory rather than seek.

   The inbuf covers a particular part of the file with an in-memory buffer.
   The file is addressed by absolute position,

   inbuf[0..inbufamount-1] is valid, inbufamount <= inbuflen, cursor <=
   inbufamount is the next one to be processed.

   0 <= abspos is the absolute position in the input file of the start of the 
   buffer.  We need this to generate new signatures at the right positions. */
struct _hs_inbuf {
    int             tag;
    int             len;
    byte_t           *buf;
    int             amount;
    int             cursor;
    int             abspos;
};

typedef struct _hs_inbuf _hs_inbuf_t;

int             _hs_fill_inbuf(_hs_inbuf_t *, hs_read_fn_t read_fn,

			       void *readprivate);

_hs_inbuf_t    *_hs_new_inbuf(void);
void            _hs_free_inbuf(_hs_inbuf_t *);
int             _hs_slide_inbuf(_hs_inbuf_t *);



/***********************************************************************
 * Checksums
 ***********************************************************************/

#define MD4_LENGTH 16
#define DEFAULT_SUM_LENGTH 8

/* We should make this something other than zero to improve the checksum
   algorithm: tridge suggests a prime number. */
#define CHAR_OFFSET 31

typedef uint32_t hs_weak_sum_t;
typedef byte_t   hs_strong_sum_t[MD4_LENGTH];

typedef struct hs_rollsum hs_rollsum_t;

#include "checksum.h"


/* ========================================

   queue of outgoing copy commands */

typedef struct _hs_copyq {
    off_t           start;
    size_t          len;
} _hs_copyq_t;

int             _hs_queue_copy(hs_write_fn_t write_fn, void *write_priv,
			       _hs_copyq_t * copyq, off_t start, size_t len,
			       hs_stats_t * stats);
int             _hs_copyq_push(hs_write_fn_t write_fn, void *write_priv,
			       _hs_copyq_t * copyq, hs_stats_t * stats);


int             _hs_append_literal(hs_membuf_t * litbuf, byte_t value);


int             _hs_check_sig_version(hs_read_fn_t, void *);


/* =======================================

   gd01 protocol. */

int
                _hs_read_blocksize(hs_read_fn_t sigread_fn, void *sigreadprivate,

				   int *block_len);

int
                _hs_littok_header(hs_write_fn_t write_fn, void *write_priv);

int
                _hs_newsig_header(int new_block_len,

				  hs_write_fn_t write_fn, void *writeprivate);


#include "fileutil.h"