librsync  2.3.4
librsync.h
Go to the documentation of this file.
1/*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*-
2 *
3 * librsync -- library for network deltas
4 *
5 * Copyright 2000, 2001, 2014, 2015 by Martin Pool <mbp@sourcefrog.net>
6 * Copyright (C) 2003 by Donovan Baarda <abo@minkirri.apana.org.au>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation; either version 2.1 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 /*=
24 | You should never wear your best
25 | trousers when you go out to fight for
26 | freedom and liberty.
27 | -- Henrik Ibsen
28 */
29
30/** \file librsync.h
31 * Public header for librsync. */
32#ifndef LIBRSYNC_H
33# define LIBRSYNC_H
34
35# include <stdio.h>
36# include <stdint.h>
37# include <time.h>
38# include "librsync_export.h"
39
40# ifdef __cplusplus
41extern "C" {
42# endif
43
44/** Library version string.
45 *
46 * \sa \ref page_versioning */
47LIBRSYNC_EXPORT extern char const rs_librsync_version[];
48
49typedef uint8_t rs_byte_t;
50typedef intmax_t rs_long_t;
51
52 /*=
53 | "The IETF already has more than enough
54 | RFCs that codify the obvious, make
55 | stupidity illegal, support truth,
56 | justice, and the IETF way, and generally
57 | demonstrate the author is a brilliant and
58 | valuable Contributor to The Standards
59 | Process."
60 | -- Vernon Schryver
61 */
62
63/** A uint32 magic number, emitted in bigendian/network order at the start of
64 * librsync files. */
65typedef enum {
66 /** A delta file.
67 *
68 * At present, there's only one delta format.
69 *
70 * The four-byte literal \c "rs\x026". */
71 RS_DELTA_MAGIC = 0x72730236,
72
73 /** A signature file with MD4 signatures.
74 *
75 * Backward compatible with librsync < 1.0, but strongly deprecated because
76 * it creates a security vulnerability on files containing partly untrusted
77 * data. See <https://github.com/librsync/librsync/issues/5>.
78 *
79 * The four-byte literal \c "rs\x016".
80 *
81 * \sa rs_sig_begin() */
82 RS_MD4_SIG_MAGIC = 0x72730136,
83
84 /** A signature file using the BLAKE2 hash. Supported from librsync 1.0.
85 *
86 * The four-byte literal \c "rs\x017".
87 *
88 * \sa rs_sig_begin() */
89 RS_BLAKE2_SIG_MAGIC = 0x72730137,
90
91 /** A signature file with RabinKarp rollsum and MD4 hash.
92 *
93 * Uses a faster/safer rollsum, but still strongly discouraged because of
94 * MD4's security vulnerability. Supported since librsync 2.2.0.
95 *
96 * The four-byte literal \c "rs\x01F".
97 *
98 * \sa rs_sig_begin() */
99 RS_RK_MD4_SIG_MAGIC = 0x72730146,
100
101 /** A signature file with RabinKarp rollsum and BLAKE2 hash.
102 *
103 * Uses a faster/safer rollsum together with the safer BLAKE2 hash. This is
104 * the recommended default supported since librsync 2.2.0.
105 *
106 * The four-byte literal \c "rs\x01G".
107 *
108 * \sa rs_sig_begin() */
110
112
113/** Log severity levels.
114 *
115 * These are the same as syslog, at least in glibc.
116 *
117 * \sa rs_trace_set_level() \sa \ref api_trace */
118typedef enum {
119 RS_LOG_EMERG = 0, /**< System is unusable */
120 RS_LOG_ALERT = 1, /**< Action must be taken immediately */
121 RS_LOG_CRIT = 2, /**< Critical conditions */
122 RS_LOG_ERR = 3, /**< Error conditions */
123 RS_LOG_WARNING = 4, /**< Warning conditions */
124 RS_LOG_NOTICE = 5, /**< Normal but significant condition */
125 RS_LOG_INFO = 6, /**< Informational */
126 RS_LOG_DEBUG = 7 /**< Debug-level messages */
128
129/** Callback to write out log messages.
130 *
131 * \param level a syslog level.
132 *
133 * \param msg message to be logged.
134 *
135 * \sa \ref api_trace */
136typedef void rs_trace_fn_t(rs_loglevel level, char const *msg);
137
138/** Set the least important message severity that will be output.
139 *
140 * \sa \ref api_trace */
141LIBRSYNC_EXPORT void rs_trace_set_level(rs_loglevel level);
142
143/** Set trace callback.
144 *
145 * \sa \ref api_trace */
146LIBRSYNC_EXPORT void rs_trace_to(rs_trace_fn_t *);
147
148/** Default trace callback that writes to stderr.
149 *
150 * Implements ::rs_trace_fn_t, and may be passed to rs_trace_to().
151 *
152 * \sa \ref api_trace */
153LIBRSYNC_EXPORT void rs_trace_stderr(rs_loglevel level, char const *msg);
154
155/** Check whether the library was compiled with debugging trace.
156 *
157 * \returns True if the library contains trace code; otherwise false.
158 *
159 * If this returns false, then trying to turn trace on will achieve nothing.
160 *
161 * \sa \ref api_trace */
162LIBRSYNC_EXPORT int rs_supports_trace(void);
163
164/** Convert \p from_len bytes at \p from_buf into a hex representation in \p
165 * to_buf, which must be twice as long plus one byte for the null terminator. */
166LIBRSYNC_EXPORT void rs_hexify(char *to_buf, void const *from_buf,
167 int from_len);
168
169/** Decode a base64 buffer in place.
170 *
171 * \returns The number of binary bytes. */
172LIBRSYNC_EXPORT size_t rs_unbase64(char *s);
173
174/** Encode a buffer as base64. */
175LIBRSYNC_EXPORT void rs_base64(unsigned char const *buf, int n, char *out);
176
177/** Return codes from nonblocking rsync operations.
178 *
179 * \sa rs_strerror() \sa api_callbacks */
180typedef enum rs_result {
181 RS_DONE = 0, /**< Completed successfully. */
182 RS_BLOCKED = 1, /**< Blocked waiting for more data. */
183 RS_RUNNING = 2, /**< The job is still running, and not yet
184 * finished or blocked. (This value should
185 * never be seen by the application.) */
186 RS_TEST_SKIPPED = 77, /**< Test neither passed or failed. */
187 RS_IO_ERROR = 100, /**< Error in file or network IO. */
188 RS_SYNTAX_ERROR = 101, /**< Command line syntax error. */
189 RS_MEM_ERROR = 102, /**< Out of memory. */
190 RS_INPUT_ENDED = 103, /**< Unexpected end of input file, perhaps due
191 * to a truncated file or dropped network
192 * connection. */
193 RS_BAD_MAGIC = 104, /**< Bad magic number at start of stream.
194 * Probably not a librsync file, or possibly
195 * the wrong kind of file or from an
196 * incompatible library version. */
197 RS_UNIMPLEMENTED = 105, /**< Author is lazy. */
198 RS_CORRUPT = 106, /**< Unbelievable value in stream. */
199 RS_INTERNAL_ERROR = 107, /**< Probably a library bug. */
200 RS_PARAM_ERROR = 108 /**< Bad value passed in to library, probably
201 * an application bug. */
203
204/** Return an English description of a ::rs_result value. */
205LIBRSYNC_EXPORT char const *rs_strerror(rs_result r);
206
207/** Performance statistics from a librsync encoding or decoding operation.
208 *
209 * \sa api_stats \sa rs_format_stats() \sa rs_log_stats() */
210typedef struct rs_stats {
211 char const *op; /**< Human-readable name of current operation.
212 * For example, "delta". */
213 int lit_cmds; /**< Number of literal commands. */
214 rs_long_t lit_bytes; /**< Number of literal bytes. */
215 rs_long_t lit_cmdbytes; /**< Number of bytes used in literal command
216 * headers. */
217
218 rs_long_t copy_cmds, copy_bytes, copy_cmdbytes;
219 rs_long_t sig_cmds, sig_bytes;
220 int false_matches;
221
222 rs_long_t sig_blocks; /**< Number of blocks described by the
223 * signature. */
224
225 size_t block_len;
226
227 rs_long_t in_bytes; /**< Total bytes read from input. */
228 rs_long_t out_bytes; /**< Total bytes written to output. */
229
230 time_t start, end;
232
233/** MD4 message-digest accumulator.
234 *
235 * \sa rs_mdfour(), rs_mdfour_begin(), rs_mdfour_update(), rs_mdfour_result() */
236typedef struct rs_mdfour rs_mdfour_t;
237
238LIBRSYNC_EXPORT extern const int RS_MD4_SUM_LENGTH, RS_BLAKE2_SUM_LENGTH;
239
240# define RS_MAX_STRONG_SUM_LENGTH 32
241
242typedef uint32_t rs_weak_sum_t;
243typedef unsigned char rs_strong_sum_t[RS_MAX_STRONG_SUM_LENGTH];
244
245LIBRSYNC_EXPORT void rs_mdfour(unsigned char *out, void const *in, size_t);
246LIBRSYNC_EXPORT void rs_mdfour_begin( /* @out@ */ rs_mdfour_t *md);
247
248/** Feed some data into the MD4 accumulator.
249 *
250 * \param md MD4 accumulator.
251 *
252 * \param in_void Data to add.
253 *
254 * \param n Number of bytes fed in. */
255LIBRSYNC_EXPORT void rs_mdfour_update(rs_mdfour_t *md, void const *in_void,
256 size_t n);
257LIBRSYNC_EXPORT void rs_mdfour_result(rs_mdfour_t *md, unsigned char *out);
258
259/** Return a human-readable representation of statistics.
260 *
261 * The string is truncated if it does not fit. 100 characters should be
262 * sufficient space.
263 *
264 * \param stats Statistics from an encoding or decoding operation.
265 *
266 * \param buf Buffer to receive result.
267 *
268 * \param size Size of buffer.
269 *
270 * \return \p buf.
271 *
272 * \sa \ref api_stats */
273LIBRSYNC_EXPORT char *rs_format_stats(rs_stats_t const *stats, char *buf,
274 size_t size);
275
276/** Write statistics into the current log as text.
277 *
278 * \sa \ref api_stats \sa \ref api_trace */
279LIBRSYNC_EXPORT int rs_log_stats(rs_stats_t const *stats);
280
281/** The signature datastructure type. */
283
284/** Log the rs_signature_delta match stats. */
285LIBRSYNC_EXPORT void rs_signature_log_stats(rs_signature_t const *sig);
286
287/** Deep deallocation of checksums. */
288LIBRSYNC_EXPORT void rs_free_sumset(rs_signature_t *);
289
290/** Dump signatures to the log. */
291LIBRSYNC_EXPORT void rs_sumset_dump(rs_signature_t const *);
292
293/** Description of input and output buffers.
294 *
295 * On each call to ::rs_job_iter(), the caller can make available
296 *
297 * - #avail_in bytes of input data at #next_in
298 *
299 * - #avail_out bytes of output space at #next_out
300 *
301 * - or some of both
302 *
303 * Buffers must be allocated and passed in by the caller.
304 *
305 * On input, the buffers structure must contain the address and length of the
306 * input and output buffers. The library updates these values to indicate the
307 * amount of \b remaining buffer. So, on return, #avail_out is not the amount
308 * of output data produced, but rather the amount of output buffer space still
309 * available.
310 *
311 * This means that the values on return are consistent with the values on
312 * entry, and suitable to be passed in on a second call, but they don't
313 * directly tell you how much output data was produced.
314 *
315 * If the input buffer was large enough, it will be processed directly,
316 * otherwise the data can be copied and accumulated into an internal buffer for
317 * processing. This means using larger buffers can be much more efficient.
318 *
319 * Note also that if #avail_in is nonzero on return, then not all of the input
320 * data has been consumed. This can happen either because it ran out of output
321 * buffer space, or because it processed as much data as possible directly from
322 * the input buffer and needs more input to proceed without copying into
323 * internal buffers. The caller should provide more output buffer space and/or
324 * pack the remaining input data into another buffer with more input before
325 * calling rs_job_iter() again.
326 *
327 * \sa rs_job_iter() */
329 /** Next input byte.
330 *
331 * References a pointer which on entry should point to the start of the
332 * data to be encoded. Updated to point to the byte after the last one
333 * consumed. */
334 char *next_in;
335
336 /** Number of bytes available at next_in.
337 *
338 * References the length of available input. Updated to be the number of
339 * unused data bytes, which will be zero if all the input was consumed. May
340 * be zero if there is no new input, but the caller just wants to drain
341 * output. */
342 size_t avail_in;
343
344 /** True if there is no more data after this. */
346
347 /** Next output byte should be put there.
348 *
349 * References a pointer which on entry points to the start of the output
350 * buffer. Updated to point to the byte after the last one filled. */
351 char *next_out;
352
353 /** Remaining free space at next_out.
354 *
355 * References the size of available output buffer. Updated to the size of
356 * unused output buffer. */
357 size_t avail_out;
358};
359
360/** \sa ::rs_buffers_s */
362
363/** Default block length, if not determined by any other factors.
364 *
365 * The 2K default assumes a typical file is about 4MB and should be OK for
366 * files up to 32G with more than 1GB ram. */
367# define RS_DEFAULT_BLOCK_LEN 2048
368
369/** Default minimum strong sum length, if the filesize is unknown.
370 *
371 * This is conservative, and should be safe for files less than 45TB with a 2KB
372 * block_len, assuming no collision attack with crafted data. */
373# define RS_DEFAULT_MIN_STRONG_LEN 12
374
375/** Job of work to be done.
376 *
377 * Created by functions such as rs_sig_begin(), and then iterated over by
378 * rs_job_iter().
379 *
380 * The contents are opaque to the application, and instances are always
381 * allocated by the library.
382 *
383 * \sa \ref api_streaming \sa rs_job */
384typedef struct rs_job rs_job_t;
385
386/** Run a ::rs_job state machine until it blocks (::RS_BLOCKED), returns an
387 * error, or completes (::RS_DONE).
388 *
389 * \param job Description of job state.
390 *
391 * \param buffers Pointer to structure describing input and output buffers.
392 *
393 * \return The ::rs_result that caused iteration to stop.
394 *
395 * \c buffers->eof_in should be true if there is no more data after what's in
396 * the input buffer. The final block checksum will run across whatever's in
397 * there, without trying to accumulate anything else.
398 *
399 * \sa \ref api_streaming */
400LIBRSYNC_EXPORT rs_result rs_job_iter(rs_job_t *job, rs_buffers_t *buffers);
401
402/** Type of application-supplied function for rs_job_drive().
403 *
404 * \sa \ref api_pull */
406 void *opaque);
407
408/** Actively process a job, by making callbacks to fill and empty the buffers
409 * until the job is done. */
410LIBRSYNC_EXPORT rs_result rs_job_drive(rs_job_t *job, rs_buffers_t *buf,
411 rs_driven_cb in_cb, void *in_opaque,
412 rs_driven_cb out_cb, void *out_opaque);
413
414/** Return a pointer to the statistics in a job. */
415LIBRSYNC_EXPORT const rs_stats_t *rs_job_statistics(rs_job_t *job);
416
417/** Deallocate job state. */
418LIBRSYNC_EXPORT rs_result rs_job_free(rs_job_t *);
419
420/** Get or check signature arguments for a given file size.
421 *
422 * This can be used to get the recommended arguments for generating a
423 * signature. On calling, old_fsize should be set to the old file size or -1
424 * for "unknown". The magic and block_len arguments should be set to a valid
425 * value or 0 for "recommended". The strong_len input should be set to a valid
426 * value, 0 for "maximum", or -1 for "miniumum". Use strong_len=0 for the best
427 * protection against active hash collision attacks for the given magic type.
428 * Use strong_len=-1 for the smallest signature size that is safe against
429 * random hash collisions for the block_len and old_fsize. Use strong_len=20
430 * for something probably good enough against attacks with smaller signatures.
431 * On return the 0 or -1 input args will be set to recommended values and the
432 * returned result will indicate if any inputs were invalid.
433 *
434 * \param old_fsize - the original file size (-1 for "unknown").
435 *
436 * \param *magic - the magic type to use (0 for "recommended").
437 *
438 * \param *block_len - the block length to use (0 for "recommended").
439 *
440 * \param *strong_len - the strongsum length to use (0 for "maximum", -1 for
441 * "minimum").
442 *
443 * \return RS_DONE if all arguments are valid, otherwise an error code. */
444LIBRSYNC_EXPORT rs_result rs_sig_args(rs_long_t old_fsize,
445 rs_magic_number * magic,
446 size_t *block_len, size_t *strong_len);
447
448/** Start generating a signature.
449 *
450 * It's recommended you use rs_sig_args() to get the recommended arguments for
451 * this based on the original file size.
452 *
453 * \return A new rs_job_t into which the old file data can be passed.
454 *
455 * \param sig_magic Signature file format to generate (0 for "recommended").
456 * See ::rs_magic_number.
457 *
458 * \param block_len Checksum block size to use (0 for "recommended"). Larger
459 * values make the signature shorter, and the delta longer.
460 *
461 * \param strong_len Strongsum length in bytes to use (0 for "maximum", -1 for
462 * "minimum"). Smaller values make the signature shorter but increase the risk
463 * of corruption from hash collisions.
464 *
465 * \sa rs_sig_file() */
466LIBRSYNC_EXPORT rs_job_t *rs_sig_begin(size_t block_len, size_t strong_len,
467 rs_magic_number sig_magic);
468
469/** Prepare to compute a streaming delta.
470 *
471 * \todo Add a version of this that takes a ::rs_magic_number controlling the
472 * delta format. */
473LIBRSYNC_EXPORT rs_job_t *rs_delta_begin(rs_signature_t *);
474
475/** Read a signature from a file into an ::rs_signature structure in memory.
476 *
477 * Once there, it can be used to generate a delta to a newer version of the
478 * file.
479 *
480 * \note After loading the signatures, you must call \ref rs_build_hash_table()
481 * before you can use them. */
482LIBRSYNC_EXPORT rs_job_t *rs_loadsig_begin(rs_signature_t **);
483
484/** Call this after loading a signature to index it.
485 *
486 * Use rs_free_sumset() to release it after use. */
487LIBRSYNC_EXPORT rs_result rs_build_hash_table(rs_signature_t *sums);
488
489/** Callback used to retrieve parts of the basis file.
490 *
491 * \param opaque The opaque object to execute the callback with. Often the file
492 * to read from.
493 *
494 * \param pos Position where copying should begin.
495 *
496 * \param len On input, the amount of data that should be retrieved. Updated to
497 * show how much is actually available, but should not be greater than the
498 * input value.
499 *
500 * \param buf On input, a buffer of at least \p *len bytes. May be updated to
501 * point to a buffer allocated by the callback if it prefers. */
502typedef rs_result rs_copy_cb(void *opaque, rs_long_t pos, size_t *len,
503 void **buf);
504
505/** Apply a \a delta to a \a basis file to recreate the \a new file.
506 *
507 * This gives you back a ::rs_job_t object, which can be cranked by calling
508 * rs_job_iter() and updating the stream pointers. When finished, call
509 * rs_job_free() to dispose of it.
510 *
511 * \param copy_cb Callback used to retrieve content from the basis file.
512 *
513 * \param copy_arg Opaque environment pointer passed through to the callback.
514 *
515 * \todo As output is produced, accumulate the MD4 checksum of the output. Then
516 * if we find a CHECKSUM command we can check it's contents against the output.
517 *
518 * \todo Implement COPY commands.
519 *
520 * \sa rs_patch_file() \sa \ref api_streaming */
521LIBRSYNC_EXPORT rs_job_t *rs_patch_begin(rs_copy_cb * copy_cb, void *copy_arg);
522
523# ifndef RSYNC_NO_STDIO_INTERFACE
524# include <stdio.h>
525
526/** Open a file with special handling for stdin or stdout.
527 *
528 * This provides a platform independent way to open large binary files. A
529 * filename "" or "-" means use stdin for reading, or stdout for writing.
530 *
531 * \param filename - The filename to open.
532 *
533 * \param mode - fopen style mode string.
534 *
535 * \param force - bool to force overwriting of existing files. */
536LIBRSYNC_EXPORT FILE *rs_file_open(char const *filename, char const *mode,
537 int force);
538
539/** Close a file with special handling for stdin or stdout.
540 *
541 * This will not actually close the file if it is stdin or stdout.
542 *
543 * \param file - the stdio file to close. */
544LIBRSYNC_EXPORT int rs_file_close(FILE *file);
545
546/** Get the size of a file.
547 *
548 * This provides a platform independent way to get the size of large files. It
549 * will return -1 if the size cannot be determined because it is not a regular
550 * file.
551 *
552 * \param file - the stdio file to get the size of. */
553LIBRSYNC_EXPORT rs_long_t rs_file_size(FILE *file);
554
555/** ::rs_copy_cb that reads from a stdio file. */
556LIBRSYNC_EXPORT rs_result rs_file_copy_cb(void *arg, rs_long_t pos, size_t *len,
557 void **buf);
558
559/** Buffer sizes for file IO.
560 *
561 * The default 0 means use the recommended buffer size for the operation being
562 * performed, any other value will override the recommended sizes. You probably
563 * only need to change these in testing. */
564LIBRSYNC_EXPORT extern int rs_inbuflen, rs_outbuflen;
565
566/** Generate the signature of a basis file, and write it out to another.
567 *
568 * It's recommended you use rs_sig_args() to get the recommended arguments for
569 * this based on the original file size.
570 *
571 * \param old_file Stdio readable file whose signature will be generated.
572 *
573 * \param sig_file Writable stdio file to which the signature will be written./
574 *
575 * \param block_len Checksum block size to use (0 for "recommended"). Larger
576 * values make the signature shorter, and the delta longer.
577 *
578 * \param strong_len Strongsum length in bytes to use (0 for "maximum", -1 for
579 * "minimum"). Smaller values make the signature shorter but increase the risk
580 * of corruption from hash collisions.
581 *
582 * \param sig_magic Signature file format to generate (0 for "recommended").
583 * See ::rs_magic_number.
584 *
585 * \param stats Optional pointer to receive statistics.
586 *
587 * \sa \ref api_whole */
588LIBRSYNC_EXPORT rs_result rs_sig_file(FILE *old_file, FILE *sig_file,
589 size_t block_len, size_t strong_len,
590 rs_magic_number sig_magic,
592
593/** Load signatures from a signature file into memory.
594 *
595 * \param sig_file Readable stdio file from which the signature will be read.
596 *
597 * \param sumset on return points to the newly allocated structure.
598 *
599 * \param stats Optional pointer to receive statistics.
600 *
601 * \sa \ref api_whole */
602LIBRSYNC_EXPORT rs_result rs_loadsig_file(FILE *sig_file,
603 rs_signature_t **sumset,
605
606/** Generate a delta between a signature and a new file into a delta file.
607 *
608 * \sa \ref api_whole */
609LIBRSYNC_EXPORT rs_result rs_delta_file(rs_signature_t *, FILE *new_file,
610 FILE *delta_file, rs_stats_t *);
611
612/** Apply a patch, relative to a basis, into a new file.
613 *
614 * \sa \ref api_whole */
615LIBRSYNC_EXPORT rs_result rs_patch_file(FILE *basis_file, FILE *delta_file,
616 FILE *new_file, rs_stats_t *);
617# endif /* !RSYNC_NO_STDIO_INTERFACE */
618
619# ifdef __cplusplus
620} /* extern "C" */
621# endif
622
623#endif /* !LIBRSYNC_H */
LIBRSYNC_EXPORT void rs_trace_to(rs_trace_fn_t *)
Set trace callback.
Definition: trace.c:57
LIBRSYNC_EXPORT rs_job_t * rs_patch_begin(rs_copy_cb *copy_cb, void *copy_arg)
Apply a delta to a basis file to recreate the new file.
Definition: patch.c:221
LIBRSYNC_EXPORT rs_result rs_build_hash_table(rs_signature_t *sums)
Call this after loading a signature to index it.
Definition: sumset.c:274
LIBRSYNC_EXPORT void rs_base64(unsigned char const *buf, int n, char *out)
Encode a buffer as base64.
Definition: base64.c:60
LIBRSYNC_EXPORT rs_job_t * rs_sig_begin(size_t block_len, size_t strong_len, rs_magic_number sig_magic)
Start generating a signature.
Definition: mksum.c:110
LIBRSYNC_EXPORT int rs_file_close(FILE *file)
Close a file with special handling for stdin or stdout.
Definition: fileutil.c:120
LIBRSYNC_EXPORT rs_result rs_job_free(rs_job_t *)
Deallocate job state.
Definition: job.c:58
LIBRSYNC_EXPORT rs_result rs_sig_file(FILE *old_file, FILE *sig_file, size_t block_len, size_t strong_len, rs_magic_number sig_magic, rs_stats_t *stats)
Generate the signature of a basis file, and write it out to another.
Definition: whole.c:67
LIBRSYNC_EXPORT FILE * rs_file_open(char const *filename, char const *mode, int force)
Open a file with special handling for stdin or stdout.
Definition: fileutil.c:81
LIBRSYNC_EXPORT void rs_signature_log_stats(rs_signature_t const *sig)
Log the rs_signature_delta match stats.
Definition: sumset.c:256
LIBRSYNC_EXPORT rs_result rs_sig_args(rs_long_t old_fsize, rs_magic_number *magic, size_t *block_len, size_t *strong_len)
Get or check signature arguments for a given file size.
Definition: sumset.c:113
LIBRSYNC_EXPORT size_t rs_unbase64(char *s)
Decode a base64 buffer in place.
Definition: base64.c:30
LIBRSYNC_EXPORT int rs_supports_trace(void)
Check whether the library was compiled with debugging trace.
Definition: trace.c:102
LIBRSYNC_EXPORT void rs_mdfour_update(rs_mdfour_t *md, void const *in_void, size_t n)
Feed some data into the MD4 accumulator.
Definition: mdfour.c:273
LIBRSYNC_EXPORT void rs_free_sumset(rs_signature_t *)
Deep deallocation of checksums.
Definition: sumset.c:294
LIBRSYNC_EXPORT char const * rs_strerror(rs_result r)
Return an English description of a rs_result value.
Definition: msg.c:46
LIBRSYNC_EXPORT rs_long_t rs_file_size(FILE *file)
Get the size of a file.
Definition: fileutil.c:127
struct rs_stats rs_stats_t
Performance statistics from a librsync encoding or decoding operation.
LIBRSYNC_EXPORT rs_job_t * rs_loadsig_begin(rs_signature_t **)
Read a signature from a file into an rs_signature structure in memory.
Definition: readsums.c:135
LIBRSYNC_EXPORT void rs_trace_stderr(rs_loglevel level, char const *msg)
Default trace callback that writes to stderr.
LIBRSYNC_EXPORT rs_result rs_delta_file(rs_signature_t *, FILE *new_file, FILE *delta_file, rs_stats_t *)
Generate a delta between a signature and a new file into a delta file.
Definition: whole.c:108
LIBRSYNC_EXPORT rs_result rs_loadsig_file(FILE *sig_file, rs_signature_t **sumset, rs_stats_t *stats)
Load signatures from a signature file into memory.
Definition: whole.c:90
LIBRSYNC_EXPORT rs_job_t * rs_delta_begin(rs_signature_t *)
Prepare to compute a streaming delta.
Definition: delta.c:396
void rs_trace_fn_t(rs_loglevel level, char const *msg)
Callback to write out log messages.
Definition: librsync.h:136
LIBRSYNC_EXPORT rs_result rs_patch_file(FILE *basis_file, FILE *delta_file, FILE *new_file, rs_stats_t *)
Apply a patch, relative to a basis, into a new file.
Definition: whole.c:124
rs_result
Return codes from nonblocking rsync operations.
Definition: librsync.h:180
@ RS_TEST_SKIPPED
Test neither passed or failed.
Definition: librsync.h:186
@ RS_MEM_ERROR
Out of memory.
Definition: librsync.h:189
@ RS_RUNNING
The job is still running, and not yet finished or blocked.
Definition: librsync.h:183
@ RS_UNIMPLEMENTED
Author is lazy.
Definition: librsync.h:197
@ RS_DONE
Completed successfully.
Definition: librsync.h:181
@ RS_PARAM_ERROR
Bad value passed in to library, probably an application bug.
Definition: librsync.h:200
@ RS_CORRUPT
Unbelievable value in stream.
Definition: librsync.h:198
@ RS_INPUT_ENDED
Unexpected end of input file, perhaps due to a truncated file or dropped network connection.
Definition: librsync.h:190
@ RS_SYNTAX_ERROR
Command line syntax error.
Definition: librsync.h:188
@ RS_BAD_MAGIC
Bad magic number at start of stream.
Definition: librsync.h:193
@ RS_INTERNAL_ERROR
Probably a library bug.
Definition: librsync.h:199
@ RS_BLOCKED
Blocked waiting for more data.
Definition: librsync.h:182
@ RS_IO_ERROR
Error in file or network IO.
Definition: librsync.h:187
LIBRSYNC_EXPORT rs_result rs_job_drive(rs_job_t *job, rs_buffers_t *buf, rs_driven_cb in_cb, void *in_opaque, rs_driven_cb out_cb, void *out_opaque)
Actively process a job, by making callbacks to fill and empty the buffers until the job is done.
Definition: job.c:139
rs_loglevel
Log severity levels.
Definition: librsync.h:118
@ RS_LOG_EMERG
System is unusable.
Definition: librsync.h:119
@ RS_LOG_DEBUG
Debug-level messages.
Definition: librsync.h:126
@ RS_LOG_ERR
Error conditions.
Definition: librsync.h:122
@ RS_LOG_NOTICE
Normal but significant condition.
Definition: librsync.h:124
@ RS_LOG_WARNING
Warning conditions.
Definition: librsync.h:123
@ RS_LOG_ALERT
Action must be taken immediately.
Definition: librsync.h:120
@ RS_LOG_CRIT
Critical conditions.
Definition: librsync.h:121
@ RS_LOG_INFO
Informational.
Definition: librsync.h:125
rs_magic_number
A uint32 magic number, emitted in bigendian/network order at the start of librsync files.
Definition: librsync.h:65
@ RS_BLAKE2_SIG_MAGIC
A signature file using the BLAKE2 hash.
Definition: librsync.h:89
@ RS_MD4_SIG_MAGIC
A signature file with MD4 signatures.
Definition: librsync.h:82
@ RS_DELTA_MAGIC
A delta file.
Definition: librsync.h:71
@ RS_RK_BLAKE2_SIG_MAGIC
A signature file with RabinKarp rollsum and BLAKE2 hash.
Definition: librsync.h:109
@ RS_RK_MD4_SIG_MAGIC
A signature file with RabinKarp rollsum and MD4 hash.
Definition: librsync.h:99
LIBRSYNC_EXPORT rs_result rs_file_copy_cb(void *arg, rs_long_t pos, size_t *len, void **buf)
rs_copy_cb that reads from a stdio file.
Definition: fileutil.c:135
LIBRSYNC_EXPORT void rs_sumset_dump(rs_signature_t const *)
Dump signatures to the log.
Definition: sumset.c:300
LIBRSYNC_EXPORT int rs_log_stats(rs_stats_t const *stats)
Write statistics into the current log as text.
Definition: stats.c:31
LIBRSYNC_EXPORT int rs_inbuflen
Buffer sizes for file IO.
Definition: whole.c:41
LIBRSYNC_EXPORT const rs_stats_t * rs_job_statistics(rs_job_t *job)
Return a pointer to the statistics in a job.
Definition: job.c:134
rs_result rs_driven_cb(rs_job_t *job, rs_buffers_t *buf, void *opaque)
Type of application-supplied function for rs_job_drive().
Definition: librsync.h:405
LIBRSYNC_EXPORT void rs_trace_set_level(rs_loglevel level)
Set the least important message severity that will be output.
Definition: trace.c:62
LIBRSYNC_EXPORT char const rs_librsync_version[]
Library version string.
Definition: version.c:25
LIBRSYNC_EXPORT rs_result rs_job_iter(rs_job_t *job, rs_buffers_t *buffers)
Run a rs_job state machine until it blocks (RS_BLOCKED), returns an error, or completes (RS_DONE).
Definition: job.c:85
LIBRSYNC_EXPORT char * rs_format_stats(rs_stats_t const *stats, char *buf, size_t size)
Return a human-readable representation of statistics.
Definition: stats.c:40
LIBRSYNC_EXPORT void rs_hexify(char *to_buf, void const *from_buf, int from_len)
Convert from_len bytes at from_buf into a hex representation in to_buf, which must be twice as long p...
Definition: hex.c:23
rs_result rs_copy_cb(void *opaque, rs_long_t pos, size_t *len, void **buf)
Callback used to retrieve parts of the basis file.
Definition: librsync.h:502
Description of input and output buffers.
Definition: librsync.h:328
char * next_in
Next input byte.
Definition: librsync.h:334
size_t avail_in
Number of bytes available at next_in.
Definition: librsync.h:342
int eof_in
True if there is no more data after this.
Definition: librsync.h:345
size_t avail_out
Remaining free space at next_out.
Definition: librsync.h:357
char * next_out
Next output byte should be put there.
Definition: librsync.h:351
The contents of this structure are private.
Definition: job.h:47
rs_copy_cb * copy_cb
Callback used to copy data from the basis into the output.
Definition: job.h:120
rs_stats_t stats
Encoding statistics.
Definition: job.h:93
The rs_mdfour state type.
Definition: mdfour.h:46
Signature of a whole file.
Definition: sumset.h:44
Performance statistics from a librsync encoding or decoding operation.
Definition: librsync.h:210
int lit_cmds
Number of literal commands.
Definition: librsync.h:213
rs_long_t lit_cmdbytes
Number of bytes used in literal command headers.
Definition: librsync.h:215
char const * op
Human-readable name of current operation.
Definition: librsync.h:211
rs_long_t sig_blocks
Number of blocks described by the signature.
Definition: librsync.h:222
rs_long_t out_bytes
Total bytes written to output.
Definition: librsync.h:228
rs_long_t lit_bytes
Number of literal bytes.
Definition: librsync.h:214
rs_long_t in_bytes
Total bytes read from input.
Definition: librsync.h:227