summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt76
-rw-r--r--CONTRIBUTING.md65
-rw-r--r--NEWS.md101
-rw-r--r--TODO.md104
-rw-r--r--cmake/FindPOPT.cmake2
-rw-r--r--src/base64.c44
-rw-r--r--src/buf.c79
-rw-r--r--src/buf.h8
-rw-r--r--src/checksum.c26
-rw-r--r--src/command.c44
-rw-r--r--src/command.h37
-rw-r--r--src/delta.c358
-rw-r--r--src/emit.c79
-rw-r--r--src/emit.h14
-rw-r--r--src/fileutil.c63
-rw-r--r--src/fileutil.h12
-rw-r--r--src/hashtable.h256
-rw-r--r--src/hex.c22
-rw-r--r--src/isprefix.c23
-rw-r--r--src/isprefix.h13
-rw-r--r--src/job.c146
-rw-r--r--src/job.h100
-rw-r--r--src/librsync.h650
-rw-r--r--src/mdfour.c194
-rw-r--r--src/mdfour.h14
-rw-r--r--src/mksum.c92
-rw-r--r--src/msg.c16
-rw-r--r--src/netint.c106
-rw-r--r--src/netint.h8
-rw-r--r--src/patch.c100
-rw-r--r--src/rdiff.c181
-rw-r--r--src/readsums.c57
-rw-r--r--src/rollsum.h20
-rw-r--r--src/scoop.c232
-rw-r--r--src/stats.c73
-rw-r--r--src/stream.c154
-rw-r--r--src/stream.h21
-rw-r--r--src/sumset.c84
-rw-r--r--src/sumset.h18
-rw-r--r--src/trace.c125
-rw-r--r--src/trace.h80
-rw-r--r--src/tube.c178
-rw-r--r--src/util.c30
-rw-r--r--src/util.h13
-rw-r--r--src/version.c1
-rw-r--r--src/whole.c84
-rw-r--r--src/whole.h4
-rw-r--r--tests/changes.input/06.in0
-rw-r--r--tests/dot1
-rw-r--r--tests/hashtable_test.c122
-rwxr-xr-xtests/largefile.test7
-rw-r--r--tests/testcommon.sh2
52 files changed, 1930 insertions, 2409 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7fe1eda..14936b5 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -20,10 +20,11 @@ project(librsync C)
cmake_minimum_required(VERSION 2.6)
INCLUDE(CMakeDependentOption)
+include(GNUInstallDirs)
set(LIBRSYNC_MAJOR_VERSION 2)
set(LIBRSYNC_MINOR_VERSION 0)
-set(LIBRSYNC_PATCH_VERSION 1)
+set(LIBRSYNC_PATCH_VERSION 2)
set(LIBRSYNC_VERSION
${LIBRSYNC_MAJOR_VERSION}.${LIBRSYNC_MINOR_VERSION}.${LIBRSYNC_PATCH_VERSION})
@@ -107,9 +108,14 @@ check_type_size ( "unsigned int" SIZEOF_UNSIGNED_INT )
check_type_size ( "unsigned long" SIZEOF_UNSIGNED_LONG )
check_type_size ( "unsigned short" SIZEOF_UNSIGNED_SHORT )
-# Check for printf "%zu" size_t formating support.
-include(CheckCSourceRuns)
-check_c_source_runs("#include <stdio.h>\nint main(){char o[8];sprintf(o, \"%zu\", (size_t)7);return o[0] != '7';}" HAVE_PRINTF_Z)
+# Check for printf "%zu" size_t formatting support.
+if(CMAKE_CROSSCOMPILING)
+ set(HAVE_PRINTF_Z ON)
+ message (STATUS "Cross compiling - assuming printf \"%zu\" size_t formatting support")
+else()
+ include(CheckCSourceRuns)
+ check_c_source_runs("#include <stdio.h>\nint main(){char o[8];sprintf(o, \"%zu\", (size_t)7);return o[0] != '7';}" HAVE_PRINTF_Z)
+endif()
include (TestBigEndian)
TEST_BIG_ENDIAN(WORDS_BIGENDIAN)
@@ -124,11 +130,11 @@ if(APPLE)
set(CMAKE_MACOSX_RPATH ON)
set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
- set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
+ set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
- list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir)
+ list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}" isSystemDir)
if("${isSystemDir}" STREQUAL "-1")
- set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
+ set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
endif()
endif()
@@ -192,17 +198,6 @@ endif (LIBB2_FOUND)
# reference implementation is currently faster.
cmake_dependent_option(USE_LIBB2 "Use the libb2 blake2 implementation." OFF "LIBB2_FOUND" OFF)
-# Doxygen doc generator
-find_package(Doxygen)
-if(DOXYGEN_FOUND)
- configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doc/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/doc/Doxyfile @ONLY)
- add_custom_target(doc
- ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/doc/Doxyfile
- WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
- COMMENT "Generating API documentation with Doxygen" VERBATIM
- )
-endif(DOXYGEN_FOUND)
-
if (USE_LIBB2)
message (STATUS "Using libb2 blake2 implementation.")
include_directories(${LIBB2_INCLUDE_DIRS})
@@ -213,6 +208,45 @@ else (USE_LIBB2)
set(blake2_SRCS src/blake2/blake2b-ref.c)
endif (USE_LIBB2)
+# Doxygen doc generator.
+find_package(Doxygen)
+if(DOXYGEN_FOUND)
+ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/doc/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/doc/Doxyfile @ONLY)
+ add_custom_target(doc
+ ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/doc/Doxyfile
+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+ COMMENT "Generating API documentation with Doxygen" VERBATIM
+ )
+endif(DOXYGEN_FOUND)
+
+# Code tidy target to reformat code with indent.
+file(GLOB tidy_SRCS src/*.[ch])
+set(TYPE_RE "(\\w+_t)")
+set(CAST_RE "(\\(${TYPE_RE}( \\*+)?\\))")
+add_custom_target(tidy
+ COMMENT "Reformatting all code to preferred coding style."
+ # Note indent requires all userdefined types to be specified with '-T <type>' args to
+ # format them correctly. Rather than do that, we just postprocess with sed.
+ #
+ # Hide the enclosing 'extern "C" {...}' block for indenting in librsync.h
+ COMMAND sed -r -i "s:^(extern \"C\") \\{:\\1;:; s:^\\}(\\s+/\\* extern \"C\" \\*/):;\\1:" src/librsync.h
+ # Linux format with no tabs, indent 4, preproc indent 2, 80 columns, format comments, swallow blank lines.
+ COMMAND indent -linux -nut -i4 -ppi2 -l80 -lc80 -fc1 -fca -sob -T FILE -T Rollsum -T rs_result ${tidy_SRCS}
+ # Remove space between * or & and identifier after userdefined types,
+ # remove space after type cast for userdefined types like indent -ncs,
+ #and remove trailing whitespace.
+ COMMAND sed -r -i "s:((${TYPE_RE}|${CAST_RE}) (&|\\*+)) :\\1:g; s:(${CAST_RE}) :\\1:g; s:\\s+$::" ${tidy_SRCS}
+ # Restore the enclosing 'extern "C" {...}' block in librsync.h
+ COMMAND sed -r -i "s:^(extern \"C\");:\\1 {:; s:^;(\\s+/\\* extern \"C\" \\*/):}\\1:" src/librsync.h
+ VERBATIM
+)
+# Code tidyc target to reformat all code and comments with https://github.com/dbaarda/tidyc.
+add_custom_target(tidyc
+ COMMENT "Reformatting all code and comments to preferred coding style."
+ # Recomended format, reformat linebreaks, reformat comments, 80 columns.
+ COMMAND tidyc -R -C -l80 -T FILE -T Rollsum -T rs_result ${tidy_SRCS}
+ VERBATIM
+)
# Generate prototab.c/h
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/src)
@@ -332,7 +366,7 @@ endif (ENABLE_COMPRESSION)
set_target_properties(rsync PROPERTIES VERSION ${LIBRSYNC_VERSION}
SOVERSION ${LIBRSYNC_MAJOR_VERSION})
-install(TARGETS rsync ${INSTALL_TARGETS_DEFAULT_ARGS} DESTINATION lib)
+install(TARGETS rsync ${INSTALL_TARGETS_DEFAULT_ARGS} DESTINATION ${CMAKE_INSTALL_LIBDIR})
########### next target ###############
@@ -349,7 +383,7 @@ if (BUILD_RDIFF)
message (WARNING "Popt library is required for rdiff target")
endif (POPT_FOUND)
- install(TARGETS rdiff ${INSTALL_TARGETS_DEFAULT_ARGS} DESTINATION bin)
+ install(TARGETS rdiff ${INSTALL_TARGETS_DEFAULT_ARGS} DESTINATION ${CMAKE_INSTALL_BINDIR})
endif (BUILD_RDIFF)
@@ -357,7 +391,7 @@ endif (BUILD_RDIFF)
install(FILES
src/librsync.h
- DESTINATION include)
+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
message (STATUS "CMAKE_C_FLAGS = ${CMAKE_C_FLAGS}")
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 3596af3..7b466af 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -3,6 +3,71 @@
Instructions and conventions for people wanting to work on librsync. Please
consider these guidelines even if you're doing your own fork.
+## Code Style
+
+The prefered style for code is equivalent to using GNU indent with the
+following arguments;
+
+```Shell
+$ indent -linux -nut -i4 -ppi2 -l80 -lc80 -fc1 -fca -sob
+```
+
+The preferred style for non-docbook comments are as follows;
+
+```C
+
+ /*=
+ | A short poem that
+ | shall never ever be
+ | reformated or reindented
+ */
+
+ /* Single line comment indented to match code indenting. */
+
+ /* Blank line delimited paragraph multi-line comments.
+
+ Without leading stars, or blank line comment delimiters. */
+
+ int a; /* code line comments */
+```
+
+The preferred style for docbook comments is javadoc with autobrief as
+follows;
+
+```C
+/** \file file.c Brief summary paragraph.
+ *
+ * With blank line paragraph delimiters and leading stars.
+ *
+ * \param foo parameter descriptions...
+ *
+ * \param bar ...in separate blank-line delimited paragraphs.
+ *
+ * Example:\code
+ * code blocks that will never be reformated.
+ * \endcode
+ *
+ * Without blank-line comment delimiters. */
+
+ int a; /**< brief attribute description */
+ int b; /**< multiline attribute description
+ *
+ * With blank line delimited paragraphs.*/
+```
+
+There is a `make tidy` target that will use GNU indent to reformat all
+code and non-docbook comments, doing some pre/post processing with sed
+to handle some corner cases indent doesn't handle well.
+
+There is also a `make tidyc` target that will reformat all code and
+comments with https://github.com/dbaarda/tidyc. This will also
+correctly reformat all docbook comments, equivalent to running tidyc
+with the following arguments;
+
+```Shell
+$ tidyc -R -C -l80
+```
+
## Pull requests
Fixes or improvements in pull requests are welcome. Please:
diff --git a/NEWS.md b/NEWS.md
index c101ab4..e097d8c 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -1,25 +1,41 @@
# librsync NEWS
-## librsync 2.0.1
+## librsync 2.0.2
NOT RELEASED YET
+ * Improve CMake install paths configuration (wRAR,
+ https://github.com/librsync/librsync/pull/133) and platform support
+ checking when cross-compiling (fornwall,
+ https://github.com/librsync/librsync/pull/136).
+
+ * Fix Unaligned memory access for rs_block_sig_init() (dbaarda,
+ https://github.com/librsync/librsync/issues/135).
+
+ * Fix hashtable_test.c name collision for key_t in sys/types.h on some
+ platforms (dbaarda, https://github.com/librsync/librsync/issues/134)
+
+ * Format code with consistent style, adding `make tidy` and `make
+ tidyc` targets for reformating code and comments. (dbaarda,
+ https://github.com/librsync/librsync/issues/125)
+
+## librsync 2.0.1
+
+Released 2017-10-17
+
* Extensively reworked Doxygen documentation, now available at
- http://librsync.sourcefrog.net/
- (Martin Pool)
+ http://librsync.sourcefrog.net/ (Martin Pool)
* Removed some declarations from librsync.h that were unimplemented or no
- longer ever useful: `rs_work_options`, `rs_accum_value`.
- Remove declaration of unimplemented `rs_mdfour_file()`.
- (Martin Pool)
+ longer ever useful: `rs_work_options`, `rs_accum_value`. Remove
+ declaration of unimplemented `rs_mdfour_file()`. (Martin Pool)
* Remove shipped `snprintf` code: no longer acutally linked after changing to
CMake, and since it's part of C99 it should be widely available.
(Martin Pool)
* Document that Ninja (http://ninja-build.org/) is supported under CMake.
- It's a bit faster and nicer than Make.
- (Martin Pool)
+ It's a bit faster and nicer than Make. (Martin Pool)
* `make check` (or `ninja check` etc) will now build and run the tests.
Previously due to a CMake limitation, `make test` would only run existing
@@ -27,8 +43,7 @@ NOT RELEASED YET
(Martin Pool, https://github.com/librsync/librsync/issues/49)
* Added cmake options to exclude rdiff target and compression from build.
- See install documentation for details.
- Thanks to Michele Bertasi.
+ See install documentation for details. Thanks to Michele Bertasi.
* `popt` is only needed when `rdiff` is being built. (gulikoza)
@@ -37,23 +52,61 @@ NOT RELEASED YET
`_fstati64`), and `fileno` (`_fileno`). (dbaarda, charlievieth,
gulikoza, marius-nicolae)
- * `rdiff -s` option now shows bytes read/written and speed. (gulikoza)
+ * `rdiff -s` option now shows bytes read/written and speed. (gulikoza).
+ For delta operations it also shows hashtable match statistics. (dbaarda)
* Running rdiff should not overwrite existing files (signatures, deltas and
new patched files) by default. If the destination file exists, rdiff will
- now exit with an error. (gulikoza)
- Add new option -f (--force) to overwrite existing files.
-
- * Improve signature memory allocation (doubling size instead of
- calling realloc for every sig block) and added support for
- preallocation. See streaming.md job->estimated_signature_count for
- usage when using the library. `rdiff` uses this by default if
- possible.
-
- * `stdint.h` and `inttypes.h` from C99 is now required.
-
- * New open addressing hashtable implementation that significantly
- speeds up delta operations, particularly for large files.
+ now exit with an error. Add new option -f (--force) to overwrite existing
+ files. (gulikoza)
+
+ * Improve signature memory allocation (doubling size instead of calling
+ realloc for every sig block) and added support for preallocation. See
+ streaming.md job->estimated_signature_count for usage when using the
+ library. `rdiff` uses this by default if possible. (gulikoza, dbaarda)
+
+ * Significantly tidied signature handling code and testing, resulting in more
+ consistent error handling behaviour, and making it easier to plug in
+ alternative weak and strong sum implementations. Also fixed "slack delta"
+ support for delta calculation with no signature. (dbaarda)
+
+ * `stdint.h` and `inttypes.h` from C99 is now required. Removed redundant
+ librsync-config.h header file. (dbaarda)
+
+ * Lots of small fixes for windows platforms and building with MSVC.
+ (lasalvavida, mbrt, dbaarda)
+
+ * New open addressing hashtable implementation that significantly speeds up
+ delta operations, particularly for large files. Also fixed degenerate
+ behaviour with large number of duplicate blocks like runs of zeros
+ in sparse files. (dbaarda)
+
+ * Optional support with cmake option for using libb2 blake2 implementation.
+ Also updated included reference blake2 implementation with bug fixes
+ (dbaarda).
+
+ * Improved default values for input and output buffer sizes. The defaults are
+ now --input-size=0 and --output-size=0, which will choose recommended
+ default sizes based on the --block-size and the operation being performed.
+ (dbaarda)
+
+ * Fixed hanging for truncated input files. It will now correctly report an
+ error indicating an unexpected EOF was encountered. (dbaarda,
+ https://github.com/librsync/librsync/issues/32)
+
+ * Fixed #13 so that faster slack delta's are used for signatures of
+ empty files. (dbaarda,
+ https://github.com/librsync/librsync/issues/13)
+
+ * Fixed #33 so rs_job_iter() doesn't need calling twice with eof=1.
+ Also tidied and optimized it a bit. (dbaarda,
+ https://github.com/librsync/librsync/issues/33)
+
+ * Fixed #55 remove excessive rs_fatal() calls, replacing checks for
+ programming errors with assert statements. Now rs_fatal() will only
+ be called for rare unrecoverable fatal errors like malloc failures or
+ impossibly large inputs. (dbaarda,
+ https://github.com/librsync/librsync/issues/55)
## librsync 2.0.0
diff --git a/TODO.md b/TODO.md
index 17cfb17..e7f4099 100644
--- a/TODO.md
+++ b/TODO.md
@@ -1,74 +1,36 @@
* Fix symbol names:
* Rename all symbols that are intended to be private to `rs__`
-
+
* Rename those that don't match either prefix.
-
+
* We have a few functions to do with reading a netint, stashing
it somewhere, then moving into a different state. Is it worth
writing generic functions for that, or would it be too confusing?
-* Fix up consecutive matches
-
- We often have several consecutive matches, and we can combine them
- into a single COPY command. So far so good.
-
- In some inputs, there might be several identical blocks.
-
- When we're matching, we want to prefer to match a block that comes
- just after the previous match, so that they'll join up nicely into
- a single larger match. rsync does this; librsync doesn't at the
- moment. It does cause a measurable problem.
-
- In fact, we could introduce an additional optimization over rsync.
- Suppose that the block A occurs twice, once followed by B and once
- by C. When we first match it, we'll probably make an arbitrary
- choice of which one to use. But if we next observe C, then it
- might be better to have given the offset of the A that precedes C,
- so that they can be joined into a single copy operation.
-
- This might be a bit complex. You can imagine in fact needing an
- arbitrarily deep lookback.
+* Duplicate block handling. Currently duplicate blocks are included in
+ the signature, but we only put the first duplicate block in the
+ hashtable so the delta only includes references to the first block.
+ This can result in sub-optimal copy commands, breaking single large
+ copies with duplicate blocks into multiple copies referencing the
+ earlier copy of the block. However, this could also make patching use
+ the disk cache more effectively. This solution is probably fine,
+ particularly given how small copy instructions are, but there might be
+ solutions for improving copy commands for long runs of duplicate blocks.
- As a simpler optimization, we might just try to prefer matching
- blocks in the same order that they occur in the input.
-
- But for now we ought to at least check for consecutive blocks.
-
- On the other hand, abo says:
-
- In reality copy's are such a huge gain that merging them efficiently
- is a bit of a non-issue. Each copy command is only a couple of
- bytes... who cares if we output twice as many as we need to... it's
- the misses that take up whole blocks of data that people will notice.
-
- I believe we are already outputing consecutive blocks as a single
- "copy" command, but have you looked at the "search" code? We have far
- more serious problems with the hash-table that need to be fixed first
- :-)
-
- We are not getting all the hits that we could due to a limited
- hash-table, and this is going to make a much bigger difference than
- optimizing the copy commands.
-
* Optimisations and code cleanups;
scoop.c: Scoop needs major refactor. Perhaps the API needs
tweaking?
rsync.h: rs_buffers_s and rs_buffers_t should be one typedef?
-
+
* Just how useful is rs_job_drive anyway?
-
- patch.c: rs_patch_s_copying() does alloc, copy free, when it could
- just copy directly into rs_buffer_t buffer. This _does_ mean the
- callback can't allocate it's own data, though this can be done by
- checking if the callback changed the pointer.
mdfour.c: This code has a different API to the RSA code in libmd
and is coupled with librsync in unhealthy ways (trace?). Recommend
changing to RSA API?
-
+
* Don't use the rs_buffers_t structure.
There's something confusing about the existence of this structure.
@@ -121,10 +83,6 @@
Some are more likely to change than others. We need a chart
showing which source files depend on which variable.
-* Error handling
-
- * What happens if the user terminates the request?
-
* Encoding implementation
* Join up signature commands
@@ -181,21 +139,6 @@
current simple rolling-sum mechanism? Could it let us match
variable-length signatures?
- * Cross-file matches
-
- If the downstream server had many similar URLs, it might be nice
- if it could draw on all of them as a basis. At the moment
- there's no way to express this, and I think the work of sending
- up signatures for all of them may be too hard.
-
- Better just to make sure we choose the best basis if there is
- none present. Perhaps this needs to weigh several factors.
-
- One factor might be that larger files are better because they're
- more likely to have a match. I'm not sure if that's very strong,
- because they'll just bloat the request. Another is that more
- recent files might be more useful.
-
* Support gzip compression of the difference stream. Does this
belong here, or should it be in the client and librsync just have
an interface that lets it cleanly plug in?
@@ -273,8 +216,6 @@
on the network, then it's a security boundary. Make sure that
corrupt input data can't make the program crash or misbehave.
-* Use slprintf not strnprintf, etc.
-
* Long files
* How do we handle the large signatures required to support large
@@ -282,27 +223,8 @@
when the length is unknown? Perhaps we should allow a way for
the signature to scale up as it grows.
- * What do we need to do to compile in support for this?
-
- * On GNU, defining `_LARGEFILE_SOURCE` as we now do should be
- sufficient.
-
- * SCO and similar things on 32-bit platforms may be more
- difficult. Some SCO systems have no 64-bit types at all, so
- there we will have to do without.
-
- * On larger Unix platforms we hope that large file support will
- be the default.
-
* Perhaps make extracted signatures still be wrapped in commands.
What would this lead to?
* We'd know how much signature data we expect to read, rather than
requiring it to be terminated by the caller.
-
-* Only use `inline` if the compiler supports it; perhaps allow it to be
- disabled or even just let the compiler decide?
-
-* Fall back from `uint8_t` to probably `unsigned char` if necessary.
-
-* Don't randomly use chars and longs; use rs_byte_t and rs_size_t.
diff --git a/cmake/FindPOPT.cmake b/cmake/FindPOPT.cmake
index 2753127..1ca452a 100644
--- a/cmake/FindPOPT.cmake
+++ b/cmake/FindPOPT.cmake
@@ -80,7 +80,7 @@ if (NOT POPT_FOUND)
mark_as_advanced (
POPT_ROOT_DIR
- POPT_INCLUDES
+ POPT_INCLUDE_DIRS
POPT_LIBRARIES
)
diff --git a/src/base64.c b/src/base64.c
index 88e1b61..374143f 100644
--- a/src/base64.c
+++ b/src/base64.c
@@ -1,25 +1,24 @@
/*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*-
*
* librsync -- the library for network deltas
- *
+ *
* Copyright (C) 2000 by Martin Pool <mbp@sourcefrog.net>
- *
+ *
* 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.
*/
-
#include "config.h"
#include <string.h>
@@ -28,23 +27,21 @@
#include "librsync.h"
-/*
- * Decode a base64 string in-place - simple and slow algorithm
- *
- * See RFC1521 for the specification of base64.
- */
+/** Decode a base64 string in-place - simple and slow algorithm.
+ *
+ * See RFC1521 for the specification of base64. */
size_t rs_unbase64(char *s)
{
char const *b64 =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
- int bit_offset, byte_offset, idx, i, n;
- unsigned char *d = (unsigned char *) s;
- char *p;
+ int bit_offset, byte_offset, idx, i, n;
+ unsigned char *d = (unsigned char *)s;
+ char *p;
n = i = 0;
while (*s && (p = strchr(b64, *s))) {
- idx = (int) (p - b64);
+ idx = (int)(p - b64);
byte_offset = (i * 6) / 8;
bit_offset = (i * 6) % 8;
d[byte_offset] &= ~((1 << (8 - bit_offset)) - 1);
@@ -64,22 +61,19 @@ size_t rs_unbase64(char *s)
return n;
}
-/*
- * Encode a buffer as base64 - simple and slow algorithm.
- */
-void
-rs_base64(unsigned char const *buf, int n, char *out)
+/** Encode a buffer as base64 - simple and slow algorithm. */
+void rs_base64(unsigned char const *buf, int n, char *out)
{
char const *b64 =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
- int bytes, i;
+ int bytes, i;
/* work out how many bytes of output there are */
bytes = ((n * 8) + 5) / 6;
for (i = 0; i < bytes; i++) {
- int byte = (i * 6) / 8;
- int bit = (i * 6) % 8;
+ int byte = (i * 6) / 8;
+ int bit = (i * 6) % 8;
if (bit < 3) {
if (byte >= n)
@@ -89,12 +83,12 @@ rs_base64(unsigned char const *buf, int n, char *out)
if (byte + 1 == n) {
*out = b64[(buf[byte] << (bit - 2)) & 0x3F];
} else {
- *out = b64[(buf[byte] << (bit - 2) |
- buf[byte + 1] >> (10 - bit)) & 0x3F];
+ *out =
+ b64[(buf[byte] << (bit - 2) | buf[byte + 1] >> (10 - bit)) &
+ 0x3F];
}
}
out++;
}
*out = 0;
}
-
diff --git a/src/buf.c b/src/buf.c
index 5f026a1..30ef508 100644
--- a/src/buf.c
+++ b/src/buf.c
@@ -19,24 +19,22 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
- /*
+ /*=
| Pick a window, Jimmy, you're leaving.
*/
-
-/*
- * buf.c -- Buffers that map between stdio file streams and librsync
- * streams. As the stream consumes input and produces output, it is
- * refilled from appropriate input and output FILEs. A dynamically
- * allocated buffer of configurable size is used as an intermediary.
+/** \file buf.c Buffers that map between stdio file streams and librsync
+ * streams.
*
- * TODO: Perhaps be more efficient by filling the buffer on every call
- * even if not yet completely empty. Check that it's really our
- * buffer, and shuffle remaining data down to the front.
+ * As the stream consumes input and produces output, it is refilled from
+ * appropriate input and output FILEs. A dynamically allocated buffer of
+ * configurable size is used as an intermediary.
*
- * TODO: Perhaps expose a routine for shuffling the buffers.
- */
-
+ * \todo Perhaps be more efficient by filling the buffer on every call even if
+ * not yet completely empty. Check that it's really our buffer, and shuffle
+ * remaining data down to the front.
+ *
+ * \todo Perhaps expose a routine for shuffling the buffers. */
#include "config.h"
#include <sys/types.h>
@@ -54,12 +52,11 @@
#include "util.h"
struct rs_filebuf {
- FILE *f;
- char *buf;
- size_t buf_len;
+ FILE *f;
+ char *buf;
+ size_t buf_len;
};
-
rs_filebuf_t *rs_filebuf_new(FILE *f, size_t buf_len)
{
rs_filebuf_t *pf = rs_alloc_struct(rs_filebuf_t);
@@ -71,29 +68,24 @@ rs_filebuf_t *rs_filebuf_new(FILE *f, size_t buf_len)
return pf;
}
-
void rs_filebuf_free(rs_filebuf_t *fb)
{
- free(fb->buf);
- rs_bzero(fb, sizeof *fb);
- free(fb);
+ free(fb->buf);
+ rs_bzero(fb, sizeof *fb);
+ free(fb);
}
-
-/*
- * If the stream has no more data available, read some from F into
- * BUF, and let the stream use that. On return, SEEN_EOF is true if
- * the end of file has passed into the stream.
- */
-rs_result rs_infilebuf_fill(rs_job_t *job, rs_buffers_t *buf,
- void *opaque)
+/* If the stream has no more data available, read some from F into BUF, and let
+ the stream use that. On return, SEEN_EOF is true if the end of file has
+ passed into the stream. */
+rs_result rs_infilebuf_fill(rs_job_t *job, rs_buffers_t *buf, void *opaque)
{
- size_t len;
- rs_filebuf_t *fb = (rs_filebuf_t *) opaque;
- FILE *f = fb->f;
+ size_t len;
+ rs_filebuf_t *fb = (rs_filebuf_t *)opaque;
+ FILE *f = fb->f;
- /* This is only allowed if either the buf has no input buffer
- * yet, or that buffer could possibly be BUF. */
+ /* This is only allowed if either the buf has no input buffer yet, or that
+ buffer could possibly be BUF. */
if (buf->next_in != NULL) {
assert(buf->avail_in <= fb->buf_len);
assert(buf->next_in >= fb->buf);
@@ -109,8 +101,7 @@ rs_result rs_infilebuf_fill(rs_job_t *job, rs_buffers_t *buf,
}
if (buf->avail_in)
- /* Still some data remaining. Perhaps we should read
- anyhow? */
+ /* Still some data remaining. Perhaps we should read anyhow? */
return RS_DONE;
len = fread(fb->buf, 1, fb->buf_len, f);
@@ -125,7 +116,8 @@ rs_result rs_infilebuf_fill(rs_job_t *job, rs_buffers_t *buf,
rs_error("error filling buf from file: %s", strerror(errno));
return RS_IO_ERROR;
} else {
- rs_error("no error bit, but got "FMT_SIZE" return when trying to read", len);
+ rs_error("no error bit, but got " FMT_SIZE
+ " return when trying to read", len);
return RS_IO_ERROR;
}
}
@@ -137,20 +129,17 @@ rs_result rs_infilebuf_fill(rs_job_t *job, rs_buffers_t *buf,
return RS_DONE;
}
-
-/*
- * The buf is already using BUF for an output buffer, and probably
- * contains some buffered output now. Write this out to F, and reset
- * the buffer cursor.
+/* The buf is already using BUF for an output buffer, and probably contains
+ some buffered output now. Write this out to F, and reset the buffer cursor.
*/
rs_result rs_outfilebuf_drain(rs_job_t *job, rs_buffers_t *buf, void *opaque)
{
int present;
- rs_filebuf_t *fb = (rs_filebuf_t *) opaque;
+ rs_filebuf_t *fb = (rs_filebuf_t *)opaque;
FILE *f = fb->f;
- /* This is only allowed if either the buf has no output buffer
- * yet, or that buffer could possibly be BUF. */
+ /* This is only allowed if either the buf has no output buffer yet, or that
+ buffer could possibly be BUF. */
if (buf->next_out == NULL) {
assert(buf->avail_out == 0);
diff --git a/src/buf.h b/src/buf.h
index 78f4d3d..331e9a9 100644
--- a/src/buf.h
+++ b/src/buf.h
@@ -1,19 +1,19 @@
/*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*-
*
* librsync -- the library for network deltas
- *
+ *
* Copyright (C) 2000, 2001 by Martin Pool <mbp@sourcefrog.net>
- *
+ *
* 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.
diff --git a/src/checksum.c b/src/checksum.c
index 87a71ce..0149ef4 100644
--- a/src/checksum.c
+++ b/src/checksum.c
@@ -32,8 +32,7 @@
#include "rollsum.h"
#include "blake2.h"
-
-/* A simple 32bit checksum that can be incrementally updated. */
+/** A simple 32bit checksum that can be incrementally updated. */
rs_weak_sum_t rs_calc_weak_sum(void const *buf, size_t len)
{
Rollsum sum;
@@ -43,23 +42,20 @@ rs_weak_sum_t rs_calc_weak_sum(void const *buf, size_t len)
return RollsumDigest(&sum);
}
-
-/**
- * Calculate and store into SUM a strong MD4 checksum of the file
- * blocks seen so far.
+/** Calculate and store into SUM a strong MD4 checksum of the file blocks seen
+ * so far.
*
- * In plain rsync, the checksum is perturbed by a seed value. This is
- * used when retrying a failed transmission: we've discovered that the
- * hashes collided at some point, so we're going to try again with
- * different hashes to see if we can get it right. (Check tridge's
- * thesis for details and to see if that's correct.)
+ * In plain rsync, the checksum is perturbed by a seed value. This is used
+ * when retrying a failed transmission: we've discovered that the hashes
+ * collided at some point, so we're going to try again with different hashes to
+ * see if we can get it right. (Check tridge's thesis for details and to see
+ * if that's correct.)
*
- * Since we can't retry a web transaction I'm not sure if it's very
- * useful in rproxy.
- */
+ * Since we can't retry a web transaction I'm not sure if it's very useful in
+ * rproxy. */
void rs_calc_md4_sum(void const *buf, size_t len, rs_strong_sum_t *sum)
{
- rs_mdfour((unsigned char *) sum, buf, len);
+ rs_mdfour((unsigned char *)sum, buf, len);
}
void rs_calc_blake2_sum(void const *buf, size_t len, rs_strong_sum_t *sum)
diff --git a/src/command.c b/src/command.c
index b5180c0..7c6c81c 100644
--- a/src/command.c
+++ b/src/command.c
@@ -1,25 +1,24 @@
/*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*-
*
* librsync -- the library for network deltas
- *
+ *
* Copyright (C) 2000 by Martin Pool <mbp@sourcefrog.net>
- *
+ *
* 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.
*/
-
#include "config.h"
#include <assert.h>
@@ -31,30 +30,25 @@
/* For debugging purposes, here are some human-readable forms. */
struct rs_op_kind_name const rs_op_kind_names[] = {
- {"END", RS_KIND_END },
- {"COPY", RS_KIND_COPY },
- {"LITERAL", RS_KIND_LITERAL },
- {"SIGNATURE", RS_KIND_SIGNATURE },
- {"CHECKSUM", RS_KIND_CHECKSUM },
- {"INVALID", RS_KIND_INVALID },
- {NULL, 0 }
+ {"END", RS_KIND_END},
+ {"COPY", RS_KIND_COPY},
+ {"LITERAL", RS_KIND_LITERAL},
+ {"SIGNATURE", RS_KIND_SIGNATURE},
+ {"CHECKSUM", RS_KIND_CHECKSUM},
+ {"INVALID", RS_KIND_INVALID},
+ {NULL, 0}
};
-
-/*
- * Return a human-readable name for KIND.
- */
-char const * rs_op_kind_name(enum rs_op_kind kind)
+/** Return a human-readable name for KIND. */
+char const *rs_op_kind_name(enum rs_op_kind kind)
{
- const struct rs_op_kind_name *k;
+ const struct rs_op_kind_name *k;
- for (k = rs_op_kind_names; k->kind; k++) {
- if (k->kind == kind) {
- return k->name;
- }
+ for (k = rs_op_kind_names; k->kind; k++) {
+ if (k->kind == kind) {
+ return k->name;
}
+ }
- return NULL;
+ return NULL;
}
-
-
diff --git a/src/command.h b/src/command.h
index a91cf78..03e0e1d 100644
--- a/src/command.h
+++ b/src/command.h
@@ -1,38 +1,32 @@
/*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*-
*
* librsync -- library for network deltas
- *
+ *
* Copyright (C) 1999, 2000, 2001 by Martin Pool <mbp@sourcefrog.net>
* Copyright (C) 1999 by Andrew Tridgell <tridge@samba.org>
- *
+ *
* 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.
*/
-
-/*
- * command.h -- Types of commands present in the encoding stream.
+/** \file command.h Types of commands present in the encoding stream.
*
- * The vague idea is that eventually this file will be more abstract
- * than protocol.h, but it's not clear that will ever be required.
- */
+ * The vague idea is that eventually this file will be more abstract than
+ * protocol.h, but it's not clear that will ever be required. */
-
-/**
- * Classes of operation that can be present. Each may have several different
- * possible representations.
- */
+/** Classes of operation that can be present. Each may have several different
+ * possible representations. */
enum rs_op_kind {
RS_KIND_END = 1000,
RS_KIND_LITERAL,
@@ -41,17 +35,14 @@ enum rs_op_kind {
RS_KIND_CHECKSUM,
RS_KIND_RESERVED, /* for future expansion */
- /* This one should never occur in file streams. It's an
- * internal marker for invalid commands. */
+ /* This one should never occur in file streams. It's an internal marker
+ for invalid commands. */
RS_KIND_INVALID
};
-
typedef struct rs_op_kind_name {
- char const *name;
- enum rs_op_kind const kind;
+ char const *name;
+ enum rs_op_kind const kind;
} rs_op_kind_name_t;
-char const * rs_op_kind_name(enum rs_op_kind);
-
-
+char const *rs_op_kind_name(enum rs_op_kind);
diff --git a/src/delta.c b/src/delta.c
index f4b9702..417c77d 100644
--- a/src/delta.c
+++ b/src/delta.c
@@ -26,41 +26,66 @@
| MINING!!
*/
-
-/*
- * delta.c -- Generate in streaming mode an rsync delta given a set of
+/** \file delta.c -- Generate in streaming mode an rsync delta given a set of
* signatures, and a new file.
*
- * The size of blocks for signature generation is determined by the
- * block size in the incoming signature.
+ * The size of blocks for signature generation is determined by the block size
+ * in the incoming signature.
*
- * To calculate a signature, we need to be able to see at least one
- * block of the new file at a time. Once we have that, we calculate
- * its weak signature, and see if there is any block in the signature
- * hash table that has the same weak sum. If there is one, then we
- * also compute the strong sum of the new block, and cross check that.
- * If they're the same, then we can assume we have a match.
+ * To calculate a signature, we need to be able to see at least one block of
+ * the new file at a time. Once we have that, we calculate its weak signature,
+ * and see if there is any block in the signature hash table that has the same
+ * weak sum. If there is one, then we also compute the strong sum of the new
+ * block, and cross check that. If they're the same, then we can assume we have
+ * a match.
+ *
+ * The final block of the file has to be handled a little differently, because
+ * it may be a short match. Short blocks in the signature don't include their
+ * length -- we just allow for the final short block of the file to match any
+ * block in the signature, and if they have the same checksum we assume they
+ * must have the same length. Therefore, when we emit a COPY command, we have
+ * to send it with a length that is the same as the block matched, and not the
+ * block length from the signature.
*
- * The final block of the file has to be handled a little differently,
- * because it may be a short match. Short blocks in the signature
- * don't include their length -- we just allow for the final short
- * block of the file to match any block in the signature, and if they
- * have the same checksum we assume they must have the same length.
- * Therefore, when we emit a COPY command, we have to send it with a
- * length that is the same as the block matched, and not the block
- * length from the signature.
- */
-
-/*
* Profiling results as of v1.26, 2001-03-18:
*
- * If everything matches, then we spend almost all our time in
- * rs_mdfour64 and rs_weak_sum, which is unavoidable and therefore a
- * good profile.
+ * If everything matches, then we spend almost all our time in rs_mdfour64 and
+ * rs_weak_sum, which is unavoidable and therefore a good profile.
*
* If nothing matches, it is not so good.
- */
-
+ *
+ * 2002-06-26: Donovan Baarda
+ *
+ * The following is based entirely on pysync. It is much cleaner than the
+ * previous incarnation of this code. It is slightly complicated because in
+ * this case the output can block, so the main delta loop needs to stop when
+ * this happens.
+ *
+ * In pysync a 'last' attribute is used to hold the last miss or match for
+ * extending if possible. In this code, basis_len and scoop_pos are used
+ * instead of 'last'. When basis_len > 0, last is a match. When basis_len = 0
+ * and scoop_pos is > 0, last is a miss. When both are 0, last is None (ie,
+ * nothing).
+ *
+ * Pysync is also slightly different in that a 'flush' method is available to
+ * force output of accumulated data. This 'flush' is use to finalise delta
+ * calculation. In librsync input is terminated with an eof flag on the input
+ * stream. I have structured this code similar to pysync with a seperate flush
+ * function that is used when eof is reached. This allows for a flush style API
+ * if one is ever needed. Note that flush in pysync can be used for more than
+ * just terminating delta calculation, so a flush based API can in some ways be
+ * more flexible...
+ *
+ * The input data is first scanned, then processed. Scanning identifies input
+ * data as misses or matches, and emits the instruction stream. Processing the
+ * data consumes it off the input scoop and outputs the processed miss data
+ * into the tube.
+ *
+ * The scoop contains all data yet to be processed. The scoop_pos is an index
+ * into the scoop that indicates the point scanned to. As data is scanned,
+ * scoop_pos is incremented. As data is processed, it is removed from the scoop
+ * and scoop_pos adjusted. Everything gets complicated because the tube can
+ * block. When the tube is blocked, no data can be processed. */
#include "config.h"
@@ -77,43 +102,6 @@
#include "trace.h"
#include "rollsum.h"
-/**
- * 2002-06-26: Donovan Baarda
- *
- * The following is based entirely on pysync. It is much cleaner than the
- * previous incarnation of this code. It is slightly complicated because in
- * this case the output can block, so the main delta loop needs to stop
- * when this happens.
- *
- * In pysync a 'last' attribute is used to hold the last miss or match for
- * extending if possible. In this code, basis_len and scoop_pos are used
- * instead of 'last'. When basis_len > 0, last is a match. When basis_len =
- * 0 and scoop_pos is > 0, last is a miss. When both are 0, last is None
- * (ie, nothing).
- *
- * Pysync is also slightly different in that a 'flush' method is available
- * to force output of accumulated data. This 'flush' is use to finalise
- * delta calculation. In librsync input is terminated with an eof flag on
- * the input stream. I have structured this code similar to pysync with a
- * seperate flush function that is used when eof is reached. This allows
- * for a flush style API if one is ever needed. Note that flush in pysync
- * can be used for more than just terminating delta calculation, so a flush
- * based API can in some ways be more flexible...
- *
- * The input data is first scanned, then processed. Scanning identifies
- * input data as misses or matches, and emits the instruction stream.
- * Processing the data consumes it off the input scoop and outputs the
- * processed miss data into the tube.
- *
- * The scoop contains all data yet to be processed. The scoop_pos is an
- * index into the scoop that indicates the point scanned to. As data is
- * scanned, scoop_pos is incremented. As data is processed, it is removed
- * from the scoop and scoop_pos adjusted. Everything gets complicated
- * because the tube can block. When the tube is blocked, no data can be
- * processed.
- *
- */
-
/* used by rdiff, but now redundant */
int rs_roll_paranoia = 0;
@@ -121,60 +109,64 @@ static rs_result rs_delta_s_scan(rs_job_t *job);
static rs_result rs_delta_s_flush(rs_job_t *job);
static rs_result rs_delta_s_end(rs_job_t *job);
static inline void rs_getinput(rs_job_t *job);
-static inline int rs_findmatch(rs_job_t *job, rs_long_t *match_pos, size_t *match_len);
-static inline rs_result rs_appendmatch(rs_job_t *job, rs_long_t match_pos, size_t match_len);
+static inline int rs_findmatch(rs_job_t *job, rs_long_t *match_pos,
+ size_t *match_len);
+static inline rs_result rs_appendmatch(rs_job_t *job, rs_long_t match_pos,
+ size_t match_len);
static inline rs_result rs_appendmiss(rs_job_t *job, size_t miss_len);
static inline rs_result rs_appendflush(rs_job_t *job);
static inline rs_result rs_processmatch(rs_job_t *job);
static inline rs_result rs_processmiss(rs_job_t *job);
-/**
- * \brief Get a block of data if possible, and see if it matches.
+/** Get a block of data if possible, and see if it matches.
*
- * On each call, we try to process all of the input data available on the
- * scoop and input buffer. */
+ * On each call, we try to process all of the input data available on the scoop
+ * and input buffer. */
static rs_result rs_delta_s_scan(rs_job_t *job)
{
- const size_t block_len = job->signature->block_len;
- rs_long_t match_pos;
- size_t match_len;
- rs_result result;
- Rollsum test;
+ const size_t block_len = job->signature->block_len;
+ rs_long_t match_pos;
+ size_t match_len;
+ rs_result result;
+ Rollsum test;
rs_job_check(job);
/* read the input into the scoop */
rs_getinput(job);
/* output any pending output from the tube */
- result=rs_tube_catchup(job);
+ result = rs_tube_catchup(job);
/* while output is not blocked and there is a block of data */
- while ((result==RS_DONE) &&
- ((job->scoop_pos + block_len) < job->scoop_avail)) {
+ while ((result == RS_DONE)
+ && ((job->scoop_pos + block_len) < job->scoop_avail)) {
/* check if this block matches */
- if (rs_findmatch(job,&match_pos,&match_len)) {
+ if (rs_findmatch(job, &match_pos, &match_len)) {
/* append the match and reset the weak_sum */
- result=rs_appendmatch(job,match_pos,match_len);
+ result = rs_appendmatch(job, match_pos, match_len);
RollsumInit(&job->weak_sum);
} else {
/* rotate the weak_sum and append the miss byte */
RollsumRotate(&job->weak_sum, job->scoop_next[job->scoop_pos],
job->scoop_next[job->scoop_pos + block_len]);
- result=rs_appendmiss(job,1);
+ result = rs_appendmiss(job, 1);
if (rs_roll_paranoia) {
RollsumInit(&test);
- RollsumUpdate(&test, job->scoop_next + job->scoop_pos, block_len);
+ RollsumUpdate(&test, job->scoop_next + job->scoop_pos,
+ block_len);
if (RollsumDigest(&test) != RollsumDigest(&job->weak_sum)) {
- rs_fatal("mismatch between rolled sum "FMT_WEAKSUM" and check "FMT_WEAKSUM"",
- RollsumDigest(&job->weak_sum), RollsumDigest(&test));
+ rs_fatal("mismatch between rolled sum " FMT_WEAKSUM
+ " and check " FMT_WEAKSUM "",
+ RollsumDigest(&job->weak_sum),
+ RollsumDigest(&test));
}
}
}
}
/* if we completed OK */
- if (result==RS_DONE) {
+ if (result == RS_DONE) {
/* if we reached eof, we can flush the last fragment */
if (job->stream->eof_in) {
- job->statefn=rs_delta_s_flush;
+ job->statefn = rs_delta_s_flush;
return RS_RUNNING;
} else {
/* we are blocked waiting for more data */
@@ -184,159 +176,153 @@ static rs_result rs_delta_s_scan(rs_job_t *job)
return result;
}
-
static rs_result rs_delta_s_flush(rs_job_t *job)
{
- rs_long_t match_pos;
- size_t match_len;
- rs_result result;
+ rs_long_t match_pos;
+ size_t match_len;
+ rs_result result;
rs_job_check(job);
/* read the input into the scoop */
rs_getinput(job);
/* output any pending output */
- result=rs_tube_catchup(job);
+ result = rs_tube_catchup(job);
/* while output is not blocked and there is any remaining data */
- while ((result==RS_DONE) && (job->scoop_pos < job->scoop_avail)) {
+ while ((result == RS_DONE) && (job->scoop_pos < job->scoop_avail)) {
/* check if this block matches */
- if (rs_findmatch(job,&match_pos,&match_len)) {
+ if (rs_findmatch(job, &match_pos, &match_len)) {
/* append the match and reset the weak_sum */
- result=rs_appendmatch(job,match_pos,match_len);
+ result = rs_appendmatch(job, match_pos, match_len);
RollsumInit(&job->weak_sum);
} else {
/* rollout from weak_sum and append the miss byte */
- RollsumRollout(&job->weak_sum,job->scoop_next[job->scoop_pos]);
- rs_trace("block reduced to "FMT_SIZE"", job->weak_sum.count);
- result=rs_appendmiss(job,1);
+ RollsumRollout(&job->weak_sum, job->scoop_next[job->scoop_pos]);
+ rs_trace("block reduced to " FMT_SIZE "", job->weak_sum.count);
+ result = rs_appendmiss(job, 1);
}
}
/* if we are not blocked, flush and set end statefn. */
- if (result==RS_DONE) {
- result=rs_appendflush(job);
- job->statefn=rs_delta_s_end;
+ if (result == RS_DONE) {
+ result = rs_appendflush(job);
+ job->statefn = rs_delta_s_end;
}
- if (result==RS_DONE) {
+ if (result == RS_DONE) {
return RS_RUNNING;
}
return result;
}
-
static rs_result rs_delta_s_end(rs_job_t *job)
{
rs_emit_end_cmd(job);
return RS_DONE;
}
-
-static inline void rs_getinput(rs_job_t *job) {
+static inline void rs_getinput(rs_job_t *job)
+{
size_t len;
- len=rs_scoop_total_avail(job);
+ len = rs_scoop_total_avail(job);
if (job->scoop_avail < len) {
- rs_scoop_input(job,len);
+ rs_scoop_input(job, len);
}
}
-
-/**
- * find a match at scoop_pos, returning the match_pos and match_len.
- * Note that this will calculate weak_sum if required. It will also
- * determine the match_len.
+/** find a match at scoop_pos, returning the match_pos and match_len.
*
- * Note that this routine could be modified to do xdelta style matches that
- * would extend matches past block boundaries by matching backwards and
- * forwards beyond the block boundaries. Extending backwards would require
- * decrementing scoop_pos as appropriate.
- */
-static inline int rs_findmatch(rs_job_t *job, rs_long_t *match_pos, size_t *match_len) {
+ * Note that this will calculate weak_sum if required. It will also determine
+ * the match_len.
+ *
+ * This routine could be modified to do xdelta style matches that would extend
+ * matches past block boundaries by matching backwards and forwards beyond the
+ * block boundaries. Extending backwards would require decrementing scoop_pos
+ * as appropriate. */
+static inline int rs_findmatch(rs_job_t *job, rs_long_t *match_pos,
+ size_t *match_len)
+{
const size_t block_len = job->signature->block_len;
/* calculate the weak_sum if we don't have one */
if (job->weak_sum.count == 0) {
/* set match_len to min(block_len, scan_avail) */
- *match_len=job->scoop_avail - job->scoop_pos;
+ *match_len = job->scoop_avail - job->scoop_pos;
if (*match_len > block_len) {
*match_len = block_len;
}
/* Update the weak_sum */
- RollsumUpdate(&job->weak_sum,job->scoop_next+job->scoop_pos,*match_len);
- rs_trace("calculate weak sum from scratch length "FMT_SIZE"",job->weak_sum.count);
+ RollsumUpdate(&job->weak_sum, job->scoop_next + job->scoop_pos,
+ *match_len);
+ rs_trace("calculate weak sum from scratch length " FMT_SIZE "",
+ job->weak_sum.count);
} else {
/* set the match_len to the weak_sum count */
- *match_len=job->weak_sum.count;
+ *match_len = job->weak_sum.count;
}
- *match_pos = rs_signature_find_match(job->signature,
- RollsumDigest(&job->weak_sum),
- job->scoop_next+job->scoop_pos,
- *match_len);
+ *match_pos =
+ rs_signature_find_match(job->signature, RollsumDigest(&job->weak_sum),
+ job->scoop_next + job->scoop_pos, *match_len);
return *match_pos != -1;
}
-
-/**
- * Append a match at match_pos of length match_len to the delta, extending
- * a previous match if possible, or flushing any previous miss/match. */
-static inline rs_result rs_appendmatch(rs_job_t *job, rs_long_t match_pos, size_t match_len)
+/** Append a match at match_pos of length match_len to the delta, extending a
+ * previous match if possible, or flushing any previous miss/match. */
+static inline rs_result rs_appendmatch(rs_job_t *job, rs_long_t match_pos,
+ size_t match_len)
{
- rs_result result=RS_DONE;
+ rs_result result = RS_DONE;
/* if last was a match that can be extended, extend it */
if (job->basis_len && (job->basis_pos + job->basis_len) == match_pos) {
- job->basis_len+=match_len;
+ job->basis_len += match_len;
} else {
/* else appendflush the last value */
- result=rs_appendflush(job);
+ result = rs_appendflush(job);
/* make this the new match value */
- job->basis_pos=match_pos;
- job->basis_len=match_len;
+ job->basis_pos = match_pos;
+ job->basis_len = match_len;
}
/* increment scoop_pos to point at next unscanned data */
- job->scoop_pos+=match_len;
+ job->scoop_pos += match_len;
/* we can only process from the scoop if output is not blocked */
- if (result==RS_DONE) {
- /* process the match data off the scoop*/
- result=rs_processmatch(job);
+ if (result == RS_DONE) {
+ /* process the match data off the scoop */
+ result = rs_processmatch(job);
}
return result;
}
-
-/**
- * Append a miss of length miss_len to the delta, extending a previous miss
+/** Append a miss of length miss_len to the delta, extending a previous miss
* if possible, or flushing any previous match.
*
- * This also breaks misses up into 4*block_len segments to avoid accumulating
- * too much in memory. */
+ * This also breaks misses up into 32KB segments to avoid accumulating too much
+ * in memory. */
static inline rs_result rs_appendmiss(rs_job_t *job, size_t miss_len)
{
- const size_t max_miss = 4 * job->signature->block_len;
- rs_result result=RS_DONE;
+ const size_t max_miss = 32768; /* For 0.01% 3 command bytes overhead. */
+ rs_result result = RS_DONE;
/* If last was a match, or max_miss misses, appendflush it. */
if (job->basis_len || (job->scoop_pos >= max_miss)) {
- result=rs_appendflush(job);
+ result = rs_appendflush(job);
}
/* increment scoop_pos */
- job->scoop_pos+=miss_len;
+ job->scoop_pos += miss_len;
return result;
}
-
-/**
- * Flush any accumulating hit or miss, appending it to the delta.
- */
+/** Flush any accumulating hit or miss, appending it to the delta. */
static inline rs_result rs_appendflush(rs_job_t *job)
{
/* if last is a match, emit it and reset last by resetting basis_len */
if (job->basis_len) {
- rs_trace("matched "FMT_LONG" bytes at "FMT_LONG"!", job->basis_len, job->basis_pos);
+ rs_trace("matched " FMT_LONG " bytes at " FMT_LONG "!", job->basis_len,
+ job->basis_pos);
rs_emit_copy_cmd(job, job->basis_pos, job->basis_len);
- job->basis_len=0;
+ job->basis_len = 0;
return rs_processmatch(job);
- /* else if last is a miss, emit and process it*/
+ /* else if last is a miss, emit and process it */
} else if (job->scoop_pos) {
- rs_trace("got "FMT_SIZE" bytes of literal data", job->scoop_pos);
+ rs_trace("got " FMT_SIZE " bytes of literal data", job->scoop_pos);
rs_emit_literal_cmd(job, job->scoop_pos);
return rs_processmiss(job);
}
@@ -344,58 +330,54 @@ static inline rs_result rs_appendflush(rs_job_t *job)
return RS_DONE;
}
-
-/**
+/** Process matching data in the scoop.
+ *
* The scoop contains match data at scoop_next of length scoop_pos. This
- * function processes that match data, returning RS_DONE if it completes,
- * or RS_BLOCKED if it gets blocked. After it completes scoop_pos is reset
- * to still point at the next unscanned data.
+ * function processes that match data, returning RS_DONE if it completes, or
+ * RS_BLOCKED if it gets blocked. After it completes scoop_pos is reset to
+ * still point at the next unscanned data.
*
* This function currently just removes data from the scoop and adjusts
- * scoop_pos appropriately. In the future this could be used for something
- * like context compressing of miss data. Note that it also calls
- * rs_tube_catchup to output any pending output. */
+ * scoop_pos appropriately. In the future this could be used for something like
+ * context compressing of miss data. Note that it also calls rs_tube_catchup to
+ * output any pending output. */
static inline rs_result rs_processmatch(rs_job_t *job)
{
- job->scoop_avail-=job->scoop_pos;
- job->scoop_next+=job->scoop_pos;
- job->scoop_pos=0;
+ job->scoop_avail -= job->scoop_pos;
+ job->scoop_next += job->scoop_pos;
+ job->scoop_pos = 0;
return rs_tube_catchup(job);
}
-/**
+/** Process miss data in the scoop.
+ *
* The scoop contains miss data at scoop_next of length scoop_pos. This
* function processes that miss data, returning RS_DONE if it completes, or
* RS_BLOCKED if it gets blocked. After it completes scoop_pos is reset to
* still point at the next unscanned data.
*
- * This function uses rs_tube_copy to queue copying from the scoop into
- * output. and uses rs_tube_catchup to do the copying. This automaticly
- * removes data from the scoop, but this can block. While rs_tube_catchup
- * is blocked, scoop_pos does not point at legit data, so scanning can also
- * not proceed.
+ * This function uses rs_tube_copy to queue copying from the scoop into output.
+ * and uses rs_tube_catchup to do the copying. This automaticly removes data
+ * from the scoop, but this can block. While rs_tube_catchup is blocked,
+ * scoop_pos does not point at legit data, so scanning can also not proceed.
*
- * In the future this could do compression of miss data before outputing
- * it. */
+ * In the future this could do compression of miss data before outputing it. */
static inline rs_result rs_processmiss(rs_job_t *job)
{
rs_tube_copy(job, job->scoop_pos);
- job->scoop_pos=0;
+ job->scoop_pos = 0;
return rs_tube_catchup(job);
}
-
-/**
- * \brief State function that does a slack delta containing only
- * literal data to recreate the input.
- */
+/** State function that does a slack delta containing only literal data to
+ * recreate the input. */
static rs_result rs_delta_s_slack(rs_job_t *job)
{
- rs_buffers_t * const stream = job->stream;
+ rs_buffers_t *const stream = job->stream;
size_t avail = stream->avail_in;
if (avail) {
- rs_trace("emit slack delta for "FMT_SIZE" available bytes", avail);
+ rs_trace("emit slack delta for " FMT_SIZE " available bytes", avail);
rs_emit_literal_cmd(job, avail);
rs_tube_copy(job, avail);
return RS_RUNNING;
@@ -406,10 +388,7 @@ static rs_result rs_delta_s_slack(rs_job_t *job)
return RS_BLOCKED;
}
-
-/**
- * State function for writing out the header of the encoding job.
- */
+/** State function for writing out the header of the encoding job. */
static rs_result rs_delta_s_header(rs_job_t *job)
{
rs_emit_delta_header(job);
@@ -422,14 +401,13 @@ static rs_result rs_delta_s_header(rs_job_t *job)
return RS_RUNNING;
}
-
rs_job_t *rs_delta_begin(rs_signature_t *sig)
{
rs_job_t *job;
job = rs_job_new("delta", rs_delta_s_header);
- /* Caller can pass NULL sig for "slack deltas". */
- if (sig) {
+ /* Caller can pass NULL sig or empty sig for "slack deltas". */
+ if (sig && sig->count > 0) {
rs_signature_check(sig);
/* Caller must have called rs_build_hash_table() by now. */
assert(sig->hashtable);
diff --git a/src/emit.c b/src/emit.c
index 03cc5d1..0060896 100644
--- a/src/emit.c
+++ b/src/emit.c
@@ -19,16 +19,10 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-
-/*
- * TODO: Pluggable encoding formats:
+/** \file emit.c encoding output routines.
*
- * - gdiff-style
- * - rsync 24
- * - ed (text)
- * - Delta HTTP
- */
-
+ * \todo Pluggable encoding formats: gdiff-style, rsync 24, ed (text), Delta
+ * HTTP. */
#include "config.h"
@@ -45,38 +39,26 @@
#include "sumset.h"
#include "job.h"
-
-/*
- * Write the magic for the start of a delta.
- */
-void
-rs_emit_delta_header(rs_job_t *job)
+/** Write the magic for the start of a delta. */
+void rs_emit_delta_header(rs_job_t *job)
{
rs_trace("emit DELTA magic");
rs_squirt_n4(job, RS_DELTA_MAGIC);
}
-
-
-/* Write a LITERAL command. */
-void
-rs_emit_literal_cmd(rs_job_t *job, int len)
+/** Write a LITERAL command. */
+void rs_emit_literal_cmd(rs_job_t *job, int len)
{
int cmd;
- int param_len;
+ int param_len = rs_int_len(len);
- switch (param_len = rs_int_len(len)) {
- case 1:
+ if (param_len == 1)
cmd = RS_OP_LITERAL_N1;
- break;
- case 2:
+ else if (param_len == 2)
cmd = RS_OP_LITERAL_N2;
- break;
- case 4:
+ else {
+ assert(param_len == 4);
cmd = RS_OP_LITERAL_N4;
- break;
- default:
- rs_fatal("What?");
}
rs_trace("emit LITERAL_N%d(len=%d), cmd_byte=%#04x", param_len, len, cmd);
@@ -88,18 +70,16 @@ rs_emit_literal_cmd(rs_job_t *job, int len)
job->stats.lit_cmdbytes += 1 + param_len;
}
-
/** Write a COPY command for given offset and length.
*
- * There is a choice of variable-length encodings, depending on the
- * size of representation for the parameters. */
-void
-rs_emit_copy_cmd(rs_job_t *job, rs_long_t where, rs_long_t len)
+ * There is a choice of variable-length encodings, depending on the size of
+ * representation for the parameters. */
+void rs_emit_copy_cmd(rs_job_t *job, rs_long_t where, rs_long_t len)
{
- int cmd;
- rs_stats_t *stats = &job->stats;
+ int cmd;
+ rs_stats_t *stats = &job->stats;
const int where_bytes = rs_int_len(where);
- const int len_bytes = rs_int_len(len);
+ const int len_bytes = rs_int_len(len);
/* Commands ascend (1,1), (1,2), ... (8, 8) */
if (where_bytes == 8)
@@ -108,26 +88,23 @@ rs_emit_copy_cmd(rs_job_t *job, rs_long_t where, rs_long_t len)
cmd = RS_OP_COPY_N4_N1;
else if (where_bytes == 2)
cmd = RS_OP_COPY_N2_N1;
- else if (where_bytes == 1)
- cmd = RS_OP_COPY_N1_N1;
else {
- rs_fatal("can't encode copy command with where_bytes=%d", where_bytes);
+ assert(where_bytes == 1);
+ cmd = RS_OP_COPY_N1_N1;
}
- if (len_bytes == 1)
- ;
+ if (len_bytes == 1) ;
else if (len_bytes == 2)
cmd += 1;
else if (len_bytes == 4)
cmd += 2;
- else if (len_bytes == 8)
- cmd += 3;
else {
- rs_fatal("can't encode copy command with len_bytes=%d", len_bytes);
+ assert(len_bytes == 8);
+ cmd += 3;
}
- rs_trace("emit COPY_N%d_N%d(where="FMT_LONG", len="FMT_LONG"), cmd_byte=%#04x",
- where_bytes, len_bytes, where, len, cmd);
+ rs_trace("emit COPY_N%d_N%d(where=" FMT_LONG ", len=" FMT_LONG
+ "), cmd_byte=%#04x", where_bytes, len_bytes, where, len, cmd);
rs_squirt_byte(job, cmd);
rs_squirt_netint(job, where, where_bytes);
rs_squirt_netint(job, len, len_bytes);
@@ -136,13 +113,11 @@ rs_emit_copy_cmd(rs_job_t *job, rs_long_t where, rs_long_t len)
stats->copy_bytes += len;
stats->copy_cmdbytes += 1 + where_bytes + len_bytes;
- /* TODO: All the stats */
+ /* \todo All the stats */
}
-
/** Write an END command. */
-void
-rs_emit_end_cmd(rs_job_t *job)
+void rs_emit_end_cmd(rs_job_t *job)
{
int cmd = RS_OP_END;
diff --git a/src/emit.h b/src/emit.h
index e3b774c..dd279c8 100644
--- a/src/emit.h
+++ b/src/emit.h
@@ -1,29 +1,25 @@
/*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*-
*
* librsync -- dynamic caching and delta update in HTTP
- *
+ *
* Copyright (C) 2000, 2001 by Martin Pool <mbp@sourcefrog.net>
- *
+ *
* 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.
*/
-
-/*
- * emit.h -- How to emit commands to the client
- */
-
+/** \file emit.h How to emit commands to the client. */
void rs_emit_delta_header(rs_job_t *);
void rs_emit_literal_cmd(rs_job_t *, int len);
diff --git a/src/fileutil.c b/src/fileutil.c
index 5aef743..d394a46 100644
--- a/src/fileutil.c
+++ b/src/fileutil.c
@@ -25,17 +25,17 @@
#include <assert.h>
#include <stdlib.h>
#ifdef HAVE_UNISTD_H
-#include <unistd.h>
+# include <unistd.h>
#endif
#include <stdio.h>
#ifdef HAVE_FCNTL_H
-#include <fcntl.h>
+# include <fcntl.h>
#endif
#ifdef HAVE_SYS_FILE_H
-#include <sys/file.h>
+# include <sys/file.h>
#endif
#ifdef HAVE_SYS_STAT_H
-#include <sys/stat.h>
+# include <sys/stat.h>
#endif
#include <string.h>
#include <errno.h>
@@ -44,7 +44,6 @@
#include "fileutil.h"
#include "trace.h"
-
/* Use fseeko64, _fseeki64, or fseeko for long files if they exist. */
#if defined(HAVE_FSEEKO64) && (SIZEOF_OFF_T < 8)
# define fopen(f, m) fopen64((f), (m))
@@ -74,56 +73,56 @@
# define fileno(f) _fileno((f))
#endif
-
/** Open a file with special handling for '-' or unspecified filenames.
*
* \param filename - The filename to open.
+ *
* \param mode - fopen style mode string.
- * \param force - bool to force overwriting of existing files.
- */
+ *
+ * \param force - bool to force overwriting of existing files. */
FILE *rs_file_open(char const *filename, char const *mode, int force)
{
- FILE *f;
- int is_write;
+ FILE *f;
+ int is_write;
is_write = mode[0] == 'w';
- if (!filename || !strcmp("-", filename)) {
- if (is_write) {
+ if (!filename || !strcmp("-", filename)) {
+ if (is_write) {
#if _WIN32
- _setmode(_fileno(stdout), _O_BINARY);
+ _setmode(_fileno(stdout), _O_BINARY);
#endif
- return stdout;
- } else {
+ return stdout;
+ } else {
#if _WIN32
- _setmode(_fileno(stdin), _O_BINARY);
+ _setmode(_fileno(stdin), _O_BINARY);
#endif
- return stdin;
- }
+ return stdin;
+ }
}
if (!force && is_write) {
- if ((f = fopen(filename, "rb"))) {
- // File exists
- rs_error("File exists \"%s\", aborting!", filename);
- fclose(f);
- exit(RS_IO_ERROR);
- }
+ if ((f = fopen(filename, "rb"))) {
+ // File exists
+ rs_error("File exists \"%s\", aborting!", filename);
+ fclose(f);
+ exit(RS_IO_ERROR);
+ }
}
if (!(f = fopen(filename, mode))) {
- rs_error("Error opening \"%s\" for %s: %s", filename,
- is_write ? "write" : "read",
- strerror(errno));
- exit(RS_IO_ERROR);
+ rs_error("Error opening \"%s\" for %s: %s", filename,
+ is_write ? "write" : "read", strerror(errno));
+ exit(RS_IO_ERROR);
}
return f;
}
-int rs_file_close(FILE * f)
+int rs_file_close(FILE *f)
{
- if ((f == stdin) || (f == stdout)) return 0;
+ if ((f == stdin) || (f == stdout))
+ return 0;
return fclose(f);
}
@@ -137,8 +136,8 @@ void rs_get_filesize(FILE *f, rs_long_t *size)
rs_result rs_file_copy_cb(void *arg, rs_long_t pos, size_t *len, void **buf)
{
- int got;
- FILE *f = (FILE *) arg;
+ int got;
+ FILE *f = (FILE *)arg;
if (fseek(f, pos, SEEK_SET)) {
rs_error("seek failed: %s", strerror(errno));
diff --git a/src/fileutil.h b/src/fileutil.h
index dfea54e..e0beb03 100644
--- a/src/fileutil.h
+++ b/src/fileutil.h
@@ -1,24 +1,24 @@
/*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- *
*
* librsync -- library for network deltas
- *
+ *
* Copyright (C) 2000, 2001 by Martin Pool <mbp@sourcefrog.net>
- *
+ *
* 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.
*/
-FILE * rs_file_open(char const *filename, char const * mode, int force);
-int rs_file_close(FILE * file);
+FILE *rs_file_open(char const *filename, char const *mode, int force);
+int rs_file_close(FILE *file);
void rs_get_filesize(FILE *f, rs_long_t *size);
diff --git a/src/hashtable.h b/src/hashtable.h
index 3fe4975..f1b0b27 100644
--- a/src/hashtable.h
+++ b/src/hashtable.h
@@ -18,121 +18,121 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifndef _HASHTABLE_H_
-#define _HASHTABLE_H_
+# define _HASHTABLE_H_
-#include <assert.h>
-#include <stdlib.h>
+# include <assert.h>
+# include <stdlib.h>
-/** \file hashtable.h
- * A generic open addressing hashtable.
+/** \file hashtable.h A generic open addressing hashtable.
*
- * This is a minimal hashtable containing pointers to arbitrary
- * entries with configurable hashtable size and support for custom
- * hash() and cmp() methods. The cmp() method can either be a simple
- * comparison between two keys, or can be against a special match
- * object containing additional mutable state. This allows for things
- * like deferred and cached evaluation of costly comparison data. The
- * hash() function doesn't need to avoid clustering behaviour.
+ * This is a minimal hashtable containing pointers to arbitrary entries with
+ * configurable hashtable size and support for custom hash() and cmp() methods.
+ * The cmp() method can either be a simple comparison between two keys, or can
+ * be against a special match object containing additional mutable state. This
+ * allows for things like deferred and cached evaluation of costly comparison
+ * data. The hash() function doesn't need to avoid clustering behaviour.
*
* It uses open addressing with quadratic probing for collisions. The
- * MurmurHash3 finalization function is used on the hash() output to
- * avoid clustering. There is no support for removing entries, only
- * adding them. Multiple entries with the same key can be added, and
- * you can use a fancy cmp() function to find particular entries by
- * more than just their key. There is an iterator for iterating
- * through all entries in the hashtable. There are optional
- * hashtable_find() find/match/hashcmp/entrycmp stats counters that
+ * MurmurHash3 finalization function is used on the hash() output to avoid
+ * clustering. There is no support for removing entries, only adding them.
+ * Multiple entries with the same key can be added, and you can use a fancy
+ * cmp() function to find particular entries by more than just their key. There
+ * is an iterator for iterating through all entries in the hashtable. There are
+ * optional hashtable_find() find/match/hashcmp/entrycmp stats counters that
* can be disabled by defining HASHTABLE_NSTATS.
*
- * The types and methods of the hashtable and its contents are
- * specified by using \#define parameters set to their basenames (the
- * prefixes for the *_t type and *_func() methods) before doing
- * \#include "hashtable.h". This produces static inline type-safe
- * methods that are either application optimized for speed or
- * wrappers around void* implementation methods for compactness.
+ * The types and methods of the hashtable and its contents are specified by
+ * using \#define parameters set to their basenames (the prefixes for the *_t
+ * type and *_func() methods) before doing \#include "hashtable.h". This
+ * produces static inline type-safe methods that are either application
+ * optimized for speed or wrappers around void* implementation methods for
+ * compactness.
*
* \param ENTRY - the entry type basename.
+ *
* \param KEY - optional key type basename (default: ENTRY).
+ *
* \param MATCH - optional match type basename (default: KEY).
+ *
* \param NAME - optional hashtable type basename (default: ENTRY_hashtable).
*
* Example: \code
- * typedef ... key_t;
- * int key_hash(const key_t *e);
- * int key_cmp(key_t *e, const key_t *o);
+ * typedef ... mykey_t;
+ * int mykey_hash(const mykey_t *e);
+ * int mykey_cmp(mykey_t *e, const mykey_t *o);
*
- * typedef struct entry {
- * key_t key; // Inherit from key_t.
+ * typedef struct myentry {
+ * mykey_t key; // Inherit from mykey_t.
* ...extra entry value data...
- * } entry_t;
- * void entry_init(entry_t *e, ...);
+ * } myentry_t;
+ * void myentry_init(myentry_t *e, ...);
*
- * #define ENTRY entry
- * #define KEY key
+ * #define ENTRY myentry
+ * #define KEY mykey
* #include "hashtable.h"
*
* hashtable_t *t;
- * entry_t entries[300];
- * key_t k;
- * entry_t *e;
+ * myentry_t entries[300];
+ * mykey_t k;
+ * myentry_t *e;
*
- * t = entry_hashtable_new(300);
- * entry_init(&entries[5], ...);
- * entry_hashtable_add(t, &entries[5]);
+ * t = myentry_hashtable_new(300);
+ * myentry_init(&entries[5], ...);
+ * myentry_hashtable_add(t, &entries[5]);
* k = ...;
- * e = entry_hashtable_find(t, &k);
+ * e = myentry_hashtable_find(t, &k);
*
- * hashtable_iter i;
- * for (e = entry_hashtable_iter(&i, t); e != NULL; e = entry_hashtable_next(&i))
+ * hashtable_iter_t i;
+ * for (e = myentry_hashtable_iter(&i, t); e != NULL;
+ * e = myentry_hashtable_next(&i))
* ...
*
- * entry_hashtable_free(t);
+ * myentry_hashtable_free(t);
* \endcode
*
- * The key_hash() and key_cmp() fuctions will typically take pointers
- * to key/entry instances the same as the pointers stored in the
- * hashtable. However it is also possible for them to take "match
- * objects" that are a "subclass" of the entry type that contain
- * additional state for complicated comparision operations.
+ * The mykey_hash() and mykey_cmp() fuctions will typically take pointers to
+ * mykey/myentry instances the same as the pointers stored in the hashtable.
+ * However it is also possible for them to take "match objects" that are a
+ * "subclass" of the entry type that contain additional state for complicated
+ * comparision operations.
*
* Example: \code
- * typedef struct match {
- * key_t key; // Inherit from key_t;
+ * typedef struct mymatch {
+ * mykey_t key; // Inherit from mykey_t;
* ...extra match criteria and state data...
- * } match_t;
- * int match_cmp(match_t *m, const entry_t *e);
+ * } mymatch_t;
+ * int mymatch_cmp(mymatch_t *m, const myentry_t *e);
*
- * #define ENTRY entry
- * #define KEY key
- * #define MATCH match
+ * #define ENTRY myentry
+ * #define KEY mykey
+ * #define MATCH mymatch
* #include "hashtable.h"
*
* ...
- * match_t m;
+ * mymatch_t m;
*
- * t = entry_hashtable_new(300);
+ * t = myentry_hashtable_new(300);
* ...
* m = ...;
- * e = entry_hashtable_find(t, &m);
+ * e = myentry_hashtable_find(t, &m);
* \endcode
*
- * The match_cmp() function is only called for finding hashtable
- * entries and can mutate the match_t object for doing things like
- * deferred and cached evaluation of expensive match data. It can
- * also access the whole entry_t object to match against more than
- * just the key. */
+ * The mymatch_cmp() function is only called for finding hashtable entries and
+ * can mutate the mymatch_t object for doing things like deferred and cached
+ * evaluation of expensive match data. It can also access the whole myentry_t
+ * object to match against more than just the key. */
/** The hashtable type. */
typedef struct hashtable {
int size; /**< Size of allocated hashtable. */
int count; /**< Number of entries in hashtable. */
-#ifndef HASHTABLE_NSTATS
+# ifndef HASHTABLE_NSTATS
/* The following are for accumulating hashtable_find() stats. */
long find_count; /**< The count of finds tried. */
long match_count; /**< The count of matches found. */
long hashcmp_count; /**< The count of hash compares done. */
long entrycmp_count; /**< The count of entry compares done. */
-#endif
+# endif
void **etable; /**< Table of pointers to entries. */
unsigned ktable[]; /**< Table of hash keys. */
} hashtable_t;
@@ -165,72 +165,69 @@ static inline unsigned mix32(unsigned int h)
/* If ENTRY is defined, define type-dependent static inline methods. */
#ifdef ENTRY
-#define _JOIN2(x, y) x##y
-#define _JOIN(x, y) _JOIN2(x, y)
+# define _JOIN2(x, y) x##y
+# define _JOIN(x, y) _JOIN2(x, y)
-#ifndef KEY
-#define KEY ENTRY
-#endif
+# ifndef KEY
+# define KEY ENTRY
+# endif
-#ifndef MATCH
-#define MATCH KEY
-#endif
+# ifndef MATCH
+# define MATCH KEY
+# endif
-#ifndef NAME
-#define NAME _JOIN(ENTRY, _hashtable)
-#endif
+# ifndef NAME
+# define NAME _JOIN(ENTRY, _hashtable)
+# endif
-#define ENTRY_T _JOIN(ENTRY, _t) /**< The entry type. */
-#define KEY_T _JOIN(KEY, _t) /**< The key type. */
-#define MATCH_T _JOIN(MATCH, _t) /**< The match type. */
+# define ENTRY_T _JOIN(ENTRY, _t) /**< The entry type. */
+# define KEY_T _JOIN(KEY, _t) /**< The key type. */
+# define MATCH_T _JOIN(MATCH, _t) /**< The match type. */
/** The key hash(k) method. */
-#define KEY_HASH(k) _JOIN(KEY, _hash)(k)
+# define KEY_HASH(k) _JOIN(KEY, _hash)(k)
/** The match cmp(m, e) method. */
-#define MATCH_CMP(m, e) _JOIN(MATCH, _cmp)(m, e)
-#define _FUNC(f) _JOIN(NAME, f)
+# define MATCH_CMP(m, e) _JOIN(MATCH, _cmp)(m, e)
+# define _FUNC(f) _JOIN(NAME, f)
/* Loop macro for probing table t for key k, setting hk to the hash for k
- reserving zero for empty buckets, and iterating with index i and entry
- hash h, terminating at an empty bucket. */
-#define _for_probe(t, k, hk, i, h) \
+ reserving zero for empty buckets, and iterating with index i and entry hash
+ h, terminating at an empty bucket. */
+# define _for_probe(t, k, hk, i, h) \
const unsigned mask = t->size - 1;\
unsigned hk = KEY_HASH((KEY_T *)k), i, s, h;\
hk = hk ? hk : -1;\
for (i = mix32(hk) & mask, s = 0; (h = t->ktable[i]); i = (i + ++s) & mask)
/* Conditional macro for incrementing stats counters. */
-#ifndef HASHTABLE_NSTATS
-#define _stats_inc(c) (c++)
-#else
-#define _stats_inc(c)
-#endif
+# ifndef HASHTABLE_NSTATS
+# define _stats_inc(c) (c++)
+# else
+# define _stats_inc(c)
+# endif
/** Allocate and initialize a hashtable instance.
*
- * The provided size is used as an indication of the number of
- * entries you wish to add, but the allocated size will probably be
- * larger depending on the implementation to enable optimisations or
- * avoid degraded performance. It may be possible to fill the table
- * beyond the requested size, but performance can start to degrade
- * badly if it is over filled.
+ * The provided size is used as an indication of the number of entries you wish
+ * to add, but the allocated size will probably be larger depending on the
+ * implementation to enable optimisations or avoid degraded performance. It may
+ * be possible to fill the table beyond the requested size, but performance can
+ * start to degrade badly if it is over filled.
*
* \param size - The desired minimum size of the hash table.
*
* \return The initialized hashtable instance or NULL if it failed. */
-static inline hashtable_t *_FUNC(_new)(int size)
-{
+static inline hashtable_t *_FUNC(_new) (int size) {
return _hashtable_new(size);
}
/** Destroy and free a hashtable instance.
*
* This will free the hashtable, but will not free the entries in the
- * hashtable. If you want to free the entries too, use a hashtable
- * iterator to free the the entries first.
+ * hashtable. If you want to free the entries too, use a hashtable iterator to
+ * free the the entries first.
*
* \param *t - The hashtable to destroy and free. */
-static inline void _FUNC(_free)(hashtable_t *t)
-{
+static inline void _FUNC(_free) (hashtable_t *t) {
_hashtable_free(t);
}
@@ -239,26 +236,24 @@ static inline void _FUNC(_free)(hashtable_t *t)
* This will reset all the stats counters for the hashtable,
*
* \param *t - The hashtable to initializ stats for. */
-static inline void _FUNC(_stats_init)(hashtable_t *t)
-{
-#ifndef HASHTABLE_NSTATS
+static inline void _FUNC(_stats_init) (hashtable_t *t) {
+# ifndef HASHTABLE_NSTATS
t->find_count = t->match_count = t->hashcmp_count = t->entrycmp_count = 0;
-#endif
+# endif
}
/** Add an entry to a hashtable.
*
* This doesn't use MATCH_CMP() or do any checks for existing copies or
* instances, so it will add duplicates. If you want to avoid adding
- * duplicates, use hashtable_find() to check for existing entries
- * first.
+ * duplicates, use hashtable_find() to check for existing entries first.
*
* \param *t - The hashtable to add to.
+ *
* \param *e - The entry object to add.
*
* \return The added entry, or NULL if the table is full. */
-static inline ENTRY_T *_FUNC(_add)(hashtable_t *t, ENTRY_T *e)
-{
+static inline ENTRY_T *_FUNC(_add) (hashtable_t *t, ENTRY_T * e) {
assert(e != NULL);
if (t->count + 1 == t->size)
return NULL;
@@ -270,15 +265,15 @@ static inline ENTRY_T *_FUNC(_add)(hashtable_t *t, ENTRY_T *e)
/** Find an entry in a hashtable.
*
- * Uses MATCH_CMP() to find the first matching entry in the table in the
- * same hash() bucket.
+ * Uses MATCH_CMP() to find the first matching entry in the table in the same
+ * hash() bucket.
*
* \param *t - The hashtable to search.
+ *
* \param *m - The key or match object to search for.
*
* \return The first found entry, or NULL if nothing was found. */
-static inline ENTRY_T *_FUNC(_find)(hashtable_t *t, MATCH_T *m)
-{
+static inline ENTRY_T *_FUNC(_find) (hashtable_t *t, MATCH_T * m) {
assert(m != NULL);
ENTRY_T *e;
@@ -298,8 +293,8 @@ static inline ENTRY_T *_FUNC(_find)(hashtable_t *t, MATCH_T *m)
/** Initialize a hashtable_iter_t and return the first entry.
*
- * This works together with hashtable_next() for iterating through
- * all entries in a hashtable.
+ * This works together with hashtable_next() for iterating through all entries
+ * in a hashtable.
*
* Example: \code
* for (e = hashtable_iter(&i, t); e != NULL; e = hashtable_next(&i))
@@ -307,11 +302,11 @@ static inline ENTRY_T *_FUNC(_find)(hashtable_t *t, MATCH_T *m)
* \endcode
*
* \param *i - the hashtable iterator to initialize.
+ *
* \param *t - the hashtable to iterate over.
*
* \return The first entry or NULL if the hashtable is empty. */
-static inline ENTRY_T *_FUNC(_iter)(hashtable_iter_t *i, hashtable_t *t)
-{
+static inline ENTRY_T *_FUNC(_iter) (hashtable_iter_t *i, hashtable_t *t) {
return _hashtable_iter(i, t);
}
@@ -320,19 +315,18 @@ static inline ENTRY_T *_FUNC(_iter)(hashtable_iter_t *i, hashtable_t *t)
* \param *i - the hashtable iterator to use.
*
* \return The next entry or NULL if the iterator is finished. */
-static inline ENTRY_T *_FUNC(_next)(hashtable_iter_t *i)
-{
+static inline ENTRY_T *_FUNC(_next) (hashtable_iter_t *i) {
return _hashtable_next(i);
}
-#undef ENTRY
-#undef KEY
-#undef MATCH
-#undef NAME
-#undef ENTRY_T
-#undef KEY_T
-#undef MATCH_T
-#undef KEY_HASH
-#undef MATCH_CMP
-#undef _FUNC
+# undef ENTRY
+# undef KEY
+# undef MATCH
+# undef NAME
+# undef ENTRY_T
+# undef KEY_T
+# undef MATCH_T
+# undef KEY_HASH
+# undef MATCH_CMP
+# undef _FUNC
#endif /* ENTRY */
diff --git a/src/hex.c b/src/hex.c
index 88b58cb..220598b 100644
--- a/src/hex.c
+++ b/src/hex.c
@@ -1,17 +1,17 @@
/*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*-
- *
+ *
* Copyright (C) 2000, 2001 by Martin Pool <mbp@sourcefrog.net>
- *
+ *
* 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.
@@ -22,24 +22,22 @@
#include <assert.h>
#include <sys/types.h>
#ifdef HAVE_INTTYPES_H
-#include <inttypes.h>
+# include <inttypes.h>
#endif
#include <stdlib.h>
#include <stdio.h>
#include "librsync.h"
-
-void
-rs_hexify(char *to_buf, void const *from, int from_len)
+void rs_hexify(char *to_buf, void const *from, int from_len)
{
static const char hex_chars[] = "0123456789abcdef";
- unsigned char const *from_buf = (unsigned char const *) from;
+ unsigned char const *from_buf = (unsigned char const *)from;
while (from_len-- > 0) {
- *(to_buf++) = hex_chars[((*from_buf) >> 4) & 0xf];
- *(to_buf++) = hex_chars[(*from_buf) & 0xf];
- from_buf++;
+ *(to_buf++) = hex_chars[((*from_buf) >> 4) & 0xf];
+ *(to_buf++) = hex_chars[(*from_buf) & 0xf];
+ from_buf++;
}
*to_buf = 0;
diff --git a/src/isprefix.c b/src/isprefix.c
index a2f700c..e0fd2b0 100644
--- a/src/isprefix.c
+++ b/src/isprefix.c
@@ -1,36 +1,33 @@
/*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*-
* librsync -- dynamic caching and delta update in HTTP
- *
+ *
* Copyright (C) 2000, 2001 by Martin Pool <mbp@sourcefrog.net>
- *
+ *
* 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.
*/
-
#include "isprefix.h"
-/**
- * Return true if TIP is a prefix of ICEBERG.
- */
-int
-isprefix(char const *tip, char const *iceberg)
+/** Return true if TIP is a prefix of ICEBERG. */
+int isprefix(char const *tip, char const *iceberg)
{
while (*tip) {
- if (*tip != *iceberg)
- return 0;
- tip++; iceberg++;
+ if (*tip != *iceberg)
+ return 0;
+ tip++;
+ iceberg++;
}
return 1;
diff --git a/src/isprefix.h b/src/isprefix.h
index 28d5a6c..e24b193 100644
--- a/src/isprefix.h
+++ b/src/isprefix.h
@@ -1,25 +1,22 @@
/*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*-
* librsync -- dynamic caching and delta update in HTTP
- *
+ *
* Copyright (C) 2000, 2001 by Martin Pool <mbp@sourcefrog.net>
- *
+ *
* 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.
*/
-
-/*
- * Return true if TIP is a prefix of ICEBERG.
- */
+/** Return true if TIP is a prefix of ICEBERG. */
int isprefix(char const *tip, char const *iceberg);
diff --git a/src/job.c b/src/job.c
index a8f8834..f1a9650 100644
--- a/src/job.c
+++ b/src/job.c
@@ -19,28 +19,18 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-
- /*
+ /*=
| The hard, lifeless I covered up the
| warm, pulsing It; protecting and
| sheltering.
*/
-/**
- * \file job.c
- *
- * \brief
- * Generic state-machine interface.
+/** \file job.c Generic state-machine interface.
*
- * The point of this is
- * that we need to be able to suspend and resume processing at any
- * point at which the buffers may block.
+ * The point of this is that we need to be able to suspend and resume
+ * processing at any point at which the buffers may block.
*
- * \see \ref api_streaming
- * \see rs_job_iter()
- * \see ::rs_job
- */
-
+ * \sa \ref api_streaming \sa rs_job_iter() \sa ::rs_job */
#include "config.h"
@@ -56,20 +46,16 @@
#include "job.h"
#include "trace.h"
-
-static const int rs_job_tag = 20010225;
-
static rs_result rs_job_work(rs_job_t *job, rs_buffers_t *buffers);
-
-rs_job_t * rs_job_new(char const *job_name, rs_result (*statefn)(rs_job_t *))
+rs_job_t *rs_job_new(char const *job_name, rs_result (*statefn) (rs_job_t *))
{
rs_job_t *job;
job = rs_alloc_struct(rs_job_t);
job->job_name = job_name;
- job->dogtag = rs_job_tag;
+ job->dogtag = RS_JOB_TAG;
job->statefn = statefn;
job->stats.op = job_name;
@@ -80,142 +66,96 @@ rs_job_t * rs_job_new(char const *job_name, rs_result (*statefn)(rs_job_t *))
return job;
}
-
-void rs_job_check(rs_job_t *job)
-{
- assert(job->dogtag == rs_job_tag);
-}
-
-
rs_result rs_job_free(rs_job_t *job)
{
free(job->scoop_buf);
if (job->job_owns_sig)
- rs_free_sumset(job->signature);
+ rs_free_sumset(job->signature);
rs_bzero(job, sizeof *job);
free(job);
return RS_DONE;
}
-
-
-static rs_result rs_job_s_complete(rs_job_t *job)
-{
- rs_fatal("should not be reached");
- return RS_INTERNAL_ERROR;
-}
-
-
static rs_result rs_job_complete(rs_job_t *job, rs_result result)
{
rs_job_check(job);
+ assert(result != RS_RUNNING && result != RS_BLOCKED);
+ assert(rs_tube_is_idle(job) || result != RS_DONE);
- job->statefn = rs_job_s_complete;
job->final_result = result;
-
+ job->stats.end = time(NULL);
if (result != RS_DONE) {
rs_error("%s job failed: %s", job->job_name, rs_strerror(result));
} else {
rs_trace("%s job complete", job->job_name);
}
-
- job->stats.end = time(NULL);
- if (result == RS_DONE && !rs_tube_is_idle(job))
- /* Processing is finished, but there is still some data
- * waiting to get into the output buffer. */
- return RS_BLOCKED;
- else
- return result;
+ return result;
}
-
rs_result rs_job_iter(rs_job_t *job, rs_buffers_t *buffers)
{
- rs_result result;
- size_t orig_in, orig_out;
+ rs_result result;
+ size_t orig_in, orig_out;
- orig_in = buffers->avail_in;
- orig_out = buffers->avail_out;
+ rs_job_check(job);
+ assert(buffers);
+ orig_in = buffers->avail_in;
+ orig_out = buffers->avail_out;
result = rs_job_work(job, buffers);
-
- if (result == RS_BLOCKED || result == RS_DONE)
- if ((orig_in == buffers->avail_in) && (orig_out == buffers->avail_out)
+ if (result == RS_BLOCKED || result == RS_DONE)
+ if ((orig_in == buffers->avail_in) && (orig_out == buffers->avail_out)
&& orig_in && orig_out) {
- rs_error("internal error: job made no progress "
- "[orig_in="FMT_SIZE", orig_out="FMT_SIZE", final_in="FMT_SIZE", final_out="FMT_SIZE"]",
- orig_in, orig_out, buffers->avail_in, buffers->avail_out);
+ rs_error("internal error: job made no progress " "[orig_in="
+ FMT_SIZE ", orig_out=" FMT_SIZE ", final_in=" FMT_SIZE
+ ", final_out=" FMT_SIZE "]", orig_in, orig_out,
+ buffers->avail_in, buffers->avail_out);
return RS_INTERNAL_ERROR;
}
-
return result;
}
-
-static rs_result
-rs_job_work(rs_job_t *job, rs_buffers_t *buffers)
+static rs_result rs_job_work(rs_job_t *job, rs_buffers_t *buffers)
{
rs_result result;
rs_job_check(job);
+ assert(buffers);
- if (!buffers) {
- rs_error("NULL buffer passed to rs_job_iter");
- return RS_PARAM_ERROR;
- }
job->stream = buffers;
-
while (1) {
result = rs_tube_catchup(job);
- if (result == RS_BLOCKED)
- return result;
- else if (result != RS_DONE)
- return rs_job_complete(job, result);
-
- if (job->statefn == rs_job_s_complete) {
- if (rs_tube_is_idle(job))
- return RS_DONE;
- else
- return RS_BLOCKED;
- } else {
+ if (result == RS_DONE && job->statefn) {
result = job->statefn(job);
- if (result == RS_RUNNING)
+ if (result == RS_DONE) {
+ /* The job is done so clear statefn. */
+ job->statefn = NULL;
+ /* There might be stuff in the tube, so keep running. */
continue;
- else if (result == RS_BLOCKED)
- return result;
- else
- return rs_job_complete(job, result);
+ }
}
+ if (result == RS_BLOCKED)
+ return result;
+ if (result != RS_RUNNING)
+ return rs_job_complete(job, result);
}
-
- /* TODO: Before returning, check that we actually made some
- * progress. If not, and we're not returning an error, this is a
- * bug. */
}
-
-const rs_stats_t *
-rs_job_statistics(rs_job_t *job)
+const rs_stats_t *rs_job_statistics(rs_job_t *job)
{
return &job->stats;
}
-
-int
-rs_job_input_is_ending(rs_job_t *job)
+int rs_job_input_is_ending(rs_job_t *job)
{
return job->stream->eof_in;
}
-
-
-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)
+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)
{
- rs_result result, iores;
+ rs_result result, iores;
rs_bzero(buf, sizeof *buf);
@@ -227,11 +167,11 @@ rs_job_drive(rs_job_t *job, rs_buffers_t *buf,
}
result = rs_job_iter(job, buf);
- if (result != RS_DONE && result != RS_BLOCKED)
+ if (result != RS_DONE && result != RS_BLOCKED)
return result;
if (out_cb) {
- iores = (out_cb)(job, buf, out_opaque);
+ iores = (out_cb) (job, buf, out_opaque);
if (iores != RS_DONE)
return iores;
}
diff --git a/src/job.h b/src/job.h
index c6aa25e..d0206c5 100644
--- a/src/job.h
+++ b/src/job.h
@@ -22,90 +22,92 @@
#include "mdfour.h"
#include "rollsum.h"
-/**
- * \struct rs_job
- * The contents of this structure are private.
- */
+/** \struct rs_job The contents of this structure are private. */
struct rs_job {
- int dogtag;
+ int dogtag;
/** Human-readable job operation name. */
- const char *job_name;
+ const char *job_name;
rs_buffers_t *stream;
/** Callback for each processing step. */
- rs_result (*statefn)(rs_job_t *);
+ rs_result (*statefn) (rs_job_t *);
/** Final result of processing job. Used by rs_job_s_failed(). */
rs_result final_result;
- /* Arguments for initializing the signature used by mksum.c and
- * readsums.c. */
- int sig_magic;
- int sig_block_len;
- int sig_strong_len;
+ /* Arguments for initializing the signature used by mksum.c and readsums.c.
+ */
+ int sig_magic;
+ int sig_block_len;
+ int sig_strong_len;
- /** The size of the signature file if available. Used by loadsums.c
- * when initializing the signature to preallocate memory. */
- rs_long_t sig_fsize;
+ /** The size of the signature file if available. Used by loadsums.c when
+ * initializing the signature to preallocate memory. */
+ rs_long_t sig_fsize;
/** Pointer to the signature that's being used by the operation. */
- rs_signature_t *signature;
+ rs_signature_t *signature;
/** Flag indicating signature should be destroyed with the job. */
- int job_owns_sig;
+ int job_owns_sig;
/** Command byte currently being processed, if any. */
- unsigned char op;
+ unsigned char op;
/** The weak signature digest used by readsums.c */
- rs_weak_sum_t weak_sig;
+ rs_weak_sum_t weak_sig;
/** The rollsum weak signature accumulator used by delta.c */
- Rollsum weak_sum;
+ Rollsum weak_sum;
/** Lengths of expected parameters. */
- rs_long_t param1, param2;
+ rs_long_t param1, param2;
struct rs_prototab_ent const *cmd;
- rs_mdfour_t output_md4;
+ rs_mdfour_t output_md4;
/** Encoding statistics. */
- rs_stats_t stats;
-
- /**
- * Buffer of data in the scoop. Allocation is
- * scoop_buf[0..scoop_alloc], and scoop_next[0..scoop_avail] contains
- * data yet to be processed. scoop_next[scoop_pos..scoop_avail] is the
- * data yet to be scanned. */
- rs_byte_t *scoop_buf; /* the allocation pointer */
- rs_byte_t *scoop_next; /* the data pointer */
- size_t scoop_alloc; /* the allocation size */
- size_t scoop_avail; /* the data size */
- size_t scoop_pos; /* the scan position */
-
- /** If USED is >0, then buf contains that much write data to
- * be sent out. */
- rs_byte_t write_buf[36];
- int write_len;
-
- /** If \p copy_len is >0, then that much data should be copied
- * through from the input. */
- rs_long_t copy_len;
+ rs_stats_t stats;
+
+ /** Buffer of data in the scoop. Allocation is scoop_buf[0..scoop_alloc],
+ * and scoop_next[0..scoop_avail] contains data yet to be processed.
+ * scoop_next[scoop_pos..scoop_avail] is the data yet to be scanned. */
+ rs_byte_t *scoop_buf; /* the allocation pointer */
+ rs_byte_t *scoop_next; /* the data pointer */
+ size_t scoop_alloc; /* the allocation size */
+ size_t scoop_avail; /* the data size */
+ size_t scoop_pos; /* the scan position */
+
+ /** If USED is >0, then buf contains that much write data to be sent out. */
+ rs_byte_t write_buf[36];
+ int write_len;
+
+ /** If \p copy_len is >0, then that much data should be copied through
+ * from the input. */
+ rs_long_t copy_len;
/** Copy from the basis position. */
- rs_long_t basis_pos, basis_len;
+ rs_long_t basis_pos, basis_len;
/** Callback used to copy data from the basis into the output. */
- rs_copy_cb *copy_cb;
- void *copy_arg;
+ rs_copy_cb *copy_cb;
+ void *copy_arg;
};
+rs_job_t *rs_job_new(const char *, rs_result (*statefn) (rs_job_t *));
-rs_job_t * rs_job_new(const char *, rs_result (*statefn)(rs_job_t *));
+int rs_job_input_is_ending(rs_job_t *job);
-void rs_job_check(rs_job_t *job);
+/** Magic job tag number for checking jobs have been initialized. */
+#define RS_JOB_TAG 20010225
-int rs_job_input_is_ending(rs_job_t *job);
+/** Assert that a job is valid.
+ *
+ * We don't use a static inline function here so that assert failure output
+ * points at where rs_job_check() was called from. */
+#define rs_job_check(job) do {\
+ assert(job->dogtag == RS_JOB_TAG);\
+} while (0)
diff --git a/src/librsync.h b/src/librsync.h
index e606a79..e7e513b 100644
--- a/src/librsync.h
+++ b/src/librsync.h
@@ -1,4 +1,4 @@
-/*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*-
+/*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*-
*
* librsync -- library for network deltas
*
@@ -20,45 +20,39 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
- /*
+ /*=
| You should never wear your best
| trousers when you go out to fight for
| freedom and liberty.
| -- Henrik Ibsen
*/
-
-/*!
- * \file librsync.h
- * \brief Public header for librsync.
- */
+/** \file librsync.h Public header for librsync. */
#ifndef _RSYNC_H
-#define _RSYNC_H
+# define _RSYNC_H
-#include <sys/types.h>
-#include <stdio.h>
-#include <stdint.h>
-#include <time.h>
+# include <sys/types.h>
+# include <stdio.h>
+# include <stdint.h>
+# include <time.h>
-#ifdef __cplusplus
+# ifdef __cplusplus
extern "C" {
-#endif
+# endif
/** Library version string.
- * \see \ref versioning
- */
+ *
+ * \sa \ref versioning */
extern char const rs_librsync_version[];
-/** Summary of the licence for librsync.
- */
+/** Summary of the licence for librsync. */
extern char const rs_licence_string[];
typedef uint8_t rs_byte_t;
typedef intmax_t rs_long_t;
-
- /*
+ /*=
| "The IETF already has more than enough
| RFCs that codify the obvious, make
| stupidity illegal, support truth,
@@ -69,338 +63,273 @@ typedef intmax_t rs_long_t;
| -- Vernon Schryver
*/
-
-/**
- * A uint32 magic number, emitted in bigendian/network order at the start of
- * librsync files.
- **/
+/** A uint32 magic number, emitted in bigendian/network order at the start of
+ * librsync files. */
typedef enum {
- /**
- * A delta file.
+ /** A delta file.
*
* At present, there's only one delta format.
*
- * The four-byte literal \c "rs\x026".
- **/
- RS_DELTA_MAGIC = 0x72730236,
+ * The four-byte literal \c "rs\x026". */
+ RS_DELTA_MAGIC = 0x72730236,
- /**
- * A signature file with MD4 signatures.
+ /** A signature file with MD4 signatures.
*
- * Backward compatible with
- * librsync < 1.0, but strongly deprecated because it creates a security
- * vulnerability on files containing partly untrusted data. See
- * <https://github.com/librsync/librsync/issues/5>.
+ * Backward compatible with librsync < 1.0, but strongly deprecated because
+ * it creates a security vulnerability on files containing partly untrusted
+ * data. See <https://github.com/librsync/librsync/issues/5>.
*
* The four-byte literal \c "rs\x016".
*
- * \see rs_sig_begin()
- **/
- RS_MD4_SIG_MAGIC = 0x72730136,
+ * \sa rs_sig_begin() */
+ RS_MD4_SIG_MAGIC = 0x72730136,
- /**
- * A signature file using the BLAKE2 hash. Supported from librsync 1.0.
+ /** A signature file using the BLAKE2 hash. Supported from librsync 1.0.
*
* The four-byte literal \c "rs\x017".
*
- * \see rs_sig_begin()
- **/
- RS_BLAKE2_SIG_MAGIC = 0x72730137
+ * \sa rs_sig_begin() */
+ RS_BLAKE2_SIG_MAGIC = 0x72730137
} rs_magic_number;
-
-/**
- * \brief Log severity levels.
+/** Log severity levels.
*
* These are the same as syslog, at least in glibc.
*
- * \sa rs_trace_set_level()
- * \sa \ref api_trace
- */
+ * \sa rs_trace_set_level() \sa \ref api_trace */
typedef enum {
- RS_LOG_EMERG = 0, /**< System is unusable */
- RS_LOG_ALERT = 1, /**< Action must be taken immediately */
- RS_LOG_CRIT = 2, /**< Critical conditions */
- RS_LOG_ERR = 3, /**< Error conditions */
- RS_LOG_WARNING = 4, /**< Warning conditions */
- RS_LOG_NOTICE = 5, /**< Normal but significant condition */
- RS_LOG_INFO = 6, /**< Informational */
- RS_LOG_DEBUG = 7 /**< Debug-level messages */
+ RS_LOG_EMERG = 0, /**< System is unusable */
+ RS_LOG_ALERT = 1, /**< Action must be taken immediately */
+ RS_LOG_CRIT = 2, /**< Critical conditions */
+ RS_LOG_ERR = 3, /**< Error conditions */
+ RS_LOG_WARNING = 4, /**< Warning conditions */
+ RS_LOG_NOTICE = 5, /**< Normal but significant condition */
+ RS_LOG_INFO = 6, /**< Informational */
+ RS_LOG_DEBUG = 7 /**< Debug-level messages */
} rs_loglevel;
-
-/**
- * \typedef rs_trace_fn_t
- * \brief Callback to write out log messages.
+/** \typedef rs_trace_fn_t Callback to write out log messages.
+ *
* \param level a syslog level.
+ *
* \param msg message to be logged.
- * \sa \ref api_trace
- */
-typedef void rs_trace_fn_t(rs_loglevel level, char const *msg);
+ *
+ * \sa \ref api_trace */
+typedef void rs_trace_fn_t(rs_loglevel level, char const *msg);
-/**
- * Set the least important message severity that will be output.
- * \sa \ref api_trace
- */
-void rs_trace_set_level(rs_loglevel level);
+/** Set the least important message severity that will be output.
+ *
+ * \sa \ref api_trace */
+void rs_trace_set_level(rs_loglevel level);
/** Set trace callback.
- * \sa \ref api_trace
- */
-void rs_trace_to(rs_trace_fn_t *);
+ *
+ * \sa \ref api_trace */
+void rs_trace_to(rs_trace_fn_t *);
-/** Default trace callback that writes to stderr. Implements
- * ::rs_trace_fn_t, and may be passed to rs_trace_to().
- * \sa \ref api_trace
- */
-void rs_trace_stderr(rs_loglevel level, char const *msg);
+/** Default trace callback that writes to stderr.
+ *
+ * Implements ::rs_trace_fn_t, and may be passed to rs_trace_to().
+ *
+ * \sa \ref api_trace */
+void rs_trace_stderr(rs_loglevel level, char const *msg);
-/** Check whether the library was compiled with debugging trace
+/** Check whether the library was compiled with debugging trace.
*
* \returns True if the library contains trace code; otherwise false.
- * If this returns false, then trying to turn trace on will achieve
- * nothing.
- * \sa \ref api_trace
- */
-int rs_supports_trace(void);
+ *
+ * If this returns false, then trying to turn trace on will achieve nothing.
+ *
+ * \sa \ref api_trace */
+int rs_supports_trace(void);
-/**
- * Convert \p from_len bytes at \p from_buf into a hex representation in
- * \p to_buf, which must be twice as long plus one byte for the null
- * terminator.
- */
-void rs_hexify(char *to_buf, void const *from_buf, int from_len);
+/** Convert \p from_len bytes at \p from_buf into a hex representation in \p
+ * to_buf, which must be twice as long plus one byte for the null terminator. */
+void rs_hexify(char *to_buf, void const *from_buf, int from_len);
-/**
- * Decode a base64 buffer in place.
+/** Decode a base64 buffer in place.
*
- * \returns The number of binary bytes.
- */
+ * \returns The number of binary bytes. */
size_t rs_unbase64(char *s);
-
-/**
- * Encode a buffer as base64.
- */
+/** Encode a buffer as base64. */
void rs_base64(unsigned char const *buf, int n, char *out);
-
-/**
- * \enum rs_result
- * \brief Return codes from nonblocking rsync operations.
- * \see rs_strerror()
- * \see api_callbacks
- */
+/** \enum rs_result Return codes from nonblocking rsync operations.
+ *
+ * \sa rs_strerror() \sa api_callbacks */
typedef enum rs_result {
- RS_DONE = 0, /**< Completed successfully. */
- RS_BLOCKED = 1, /**< Blocked waiting for more data. */
-
- /** The job is still running, and not yet finished or blocked.
- * (This value should never be seen by the application.) */
- RS_RUNNING = 2,
-
- RS_TEST_SKIPPED = 77, /**< Test neither passed or failed. */
-
- RS_IO_ERROR = 100, /**< Error in file or network IO. */
- RS_SYNTAX_ERROR = 101, /**< Command line syntax error. */
- RS_MEM_ERROR = 102, /**< Out of memory. */
- /** Unexpected end of input file, perhaps due to a truncated file
- * or dropped network connection. */
- RS_INPUT_ENDED = 103,
- RS_BAD_MAGIC = 104, /**< Bad magic number at start of
- stream. Probably not a librsync
- file, or possibly the wrong kind of
- file or from an incompatible
- library version. */
- RS_UNIMPLEMENTED = 105, /**< Author is lazy. */
- RS_CORRUPT = 106, /**< Unbelievable value in stream. */
+ RS_DONE = 0, /**< Completed successfully. */
+ RS_BLOCKED = 1, /**< Blocked waiting for more data. */
+ RS_RUNNING = 2, /**< The job is still running, and not yet
+ * finished or blocked. (This value should
+ * never be seen by the application.) */
+ RS_TEST_SKIPPED = 77, /**< Test neither passed or failed. */
+ RS_IO_ERROR = 100, /**< Error in file or network IO. */
+ RS_SYNTAX_ERROR = 101, /**< Command line syntax error. */
+ RS_MEM_ERROR = 102, /**< Out of memory. */
+ RS_INPUT_ENDED = 103, /**< Unexpected end of input file, perhaps due
+ * to a truncated file or dropped network
+ * connection. */
+ RS_BAD_MAGIC = 104, /**< Bad magic number at start of stream.
+ * Probably not a librsync file, or possibly
+ * the wrong kind of file or from an
+ * incompatible library version. */
+ RS_UNIMPLEMENTED = 105, /**< Author is lazy. */
+ RS_CORRUPT = 106, /**< Unbelievable value in stream. */
RS_INTERNAL_ERROR = 107, /**< Probably a library bug. */
- RS_PARAM_ERROR = 108 /**< Bad value passed in to library,
- * probably an application bug. */
+ RS_PARAM_ERROR = 108 /**< Bad value passed in to library, probably
+ * an application bug. */
} rs_result;
-
-/**
- * Return an English description of a ::rs_result value.
- */
+/** Return an English description of a ::rs_result value. */
char const *rs_strerror(rs_result r);
-
-/**
- * \brief Performance statistics from a librsync encoding or decoding
- * operation.
+/** Performance statistics from a librsync encoding or decoding operation.
*
- * \sa api_stats
- * \sa rs_format_stats()
- * \sa rs_log_stats()
- */
+ * \sa api_stats \sa rs_format_stats() \sa rs_log_stats() */
typedef struct rs_stats {
- char const *op; /**< Human-readable name of current
- * operation. For example, "delta". */
- int lit_cmds; /**< Number of literal commands. */
- rs_long_t lit_bytes; /**< Number of literal bytes. */
- rs_long_t lit_cmdbytes; /**< Number of bytes used in literal
- * command headers. */
+ char const *op; /**< Human-readable name of current operation.
+ * For example, "delta". */
+ int lit_cmds; /**< Number of literal commands. */
+ rs_long_t lit_bytes; /**< Number of literal bytes. */
+ rs_long_t lit_cmdbytes; /**< Number of bytes used in literal command
+ * headers. */
- rs_long_t copy_cmds, copy_bytes, copy_cmdbytes;
- rs_long_t sig_cmds, sig_bytes;
- int false_matches;
+ rs_long_t copy_cmds, copy_bytes, copy_cmdbytes;
+ rs_long_t sig_cmds, sig_bytes;
+ int false_matches;
- rs_long_t sig_blocks; /**< Number of blocks described by the
- signature. */
+ rs_long_t sig_blocks; /**< Number of blocks described by the
+ * signature. */
- size_t block_len;
+ size_t block_len;
- rs_long_t in_bytes; /**< Total bytes read from input. */
- rs_long_t out_bytes; /**< Total bytes written to output. */
+ rs_long_t in_bytes; /**< Total bytes read from input. */
+ rs_long_t out_bytes; /**< Total bytes written to output. */
- time_t start, end;
+ time_t start, end;
} rs_stats_t;
-
/** \typedef struct rs_mdfour rs_mdfour_t
*
* \brief MD4 message-digest accumulator.
*
- * \sa rs_mdfour(), rs_mdfour_begin(), rs_mdfour_update(),
- * rs_mdfour_result()
- */
+ * \sa rs_mdfour(), rs_mdfour_begin(), rs_mdfour_update(), rs_mdfour_result() */
typedef struct rs_mdfour rs_mdfour_t;
extern const int RS_MD4_SUM_LENGTH, RS_BLAKE2_SUM_LENGTH;
-#define RS_MAX_STRONG_SUM_LENGTH 32
+# define RS_MAX_STRONG_SUM_LENGTH 32
typedef uint32_t rs_weak_sum_t;
typedef unsigned char rs_strong_sum_t[RS_MAX_STRONG_SUM_LENGTH];
-void rs_mdfour(unsigned char *out, void const *in, size_t);
-void rs_mdfour_begin(/* @out@ */ rs_mdfour_t * md);
+void rs_mdfour(unsigned char *out, void const *in, size_t);
+void rs_mdfour_begin( /* @out@ */ rs_mdfour_t *md);
-/**
- * Feed some data into the MD4 accumulator.
+/** Feed some data into the MD4 accumulator.
+ *
+ * \param md MD4 accumulator.
*
- * \param md MD4 accumulator.
* \param in_void Data to add.
- * \param n Number of bytes fed in.
- */
-void rs_mdfour_update(rs_mdfour_t * md, void const *in_void,
- size_t n);
-void rs_mdfour_result(rs_mdfour_t * md, unsigned char *out);
+ *
+ * \param n Number of bytes fed in. */
+void rs_mdfour_update(rs_mdfour_t *md, void const *in_void, size_t n);
+void rs_mdfour_result(rs_mdfour_t *md, unsigned char *out);
-/**
- * \brief Return a human-readable representation of statistics.
+/** Return a human-readable representation of statistics.
*
- * The string is truncated if it does not fit. 100 characters should
- * be sufficient space.
+ * The string is truncated if it does not fit. 100 characters should be
+ * sufficient space.
*
* \param stats Statistics from an encoding or decoding operation.
*
* \param buf Buffer to receive result.
+ *
* \param size Size of buffer.
+ *
* \return \p buf.
- * \see \ref api_stats
- */
+ *
+ * \sa \ref api_stats */
char *rs_format_stats(rs_stats_t const *stats, char *buf, size_t size);
-/**
- * Write statistics into the current log as text.
+/** Write statistics into the current log as text.
*
- * \see \ref api_stats
- * \see \ref api_trace
- */
+ * \sa \ref api_stats \sa \ref api_trace */
int rs_log_stats(rs_stats_t const *stats);
-
-/**
- * \typedef rs_signature_t
- */
+/** \typedef rs_signature_t */
typedef struct rs_signature rs_signature_t;
-/**
- * Deep deallocation of checksums.
- */
+/** Deep deallocation of checksums. */
void rs_free_sumset(rs_signature_t *);
-/**
- * Dump signatures to the log.
- */
+/** Dump signatures to the log. */
void rs_sumset_dump(rs_signature_t const *);
-
-/**
- * Description of input and output buffers.
+/** Description of input and output buffers.
*
* On each call to ::rs_job_iter(), the caller can make available
*
- * - #avail_in bytes of input data at #next_in
- * - #avail_out bytes of output space at #next_out
- * - or some of both
+ * - #avail_in bytes of input data at #next_in
+ *
+ * - #avail_out bytes of output space at #next_out
+ *
+ * - or some of both
*
* Buffers must be allocated and passed in by the caller.
*
- * On input, the buffers structure must contain the address and length of
- * the input and output buffers. The library updates these values to
- * indicate the amount of \b remaining buffer. So, on return,
- * #avail_out is not the amount of output data produced, but rather the
- * amount of output buffer space still available.
- *
- * This means that the values on
- * return are consistent with the values on entry, and suitable to be passed
- * in on a second call, but they don't directly tell you how much output
- * data was produced.
- *
- * Note also that if *#avail_in is nonzero on return, then not all of
- * the input data has been consumed. The caller should either provide
- * more output buffer space and call ::rs_job_iter() again passing the same
- * #next_in and #avail_in, or put the remaining input data into some
- * persistent buffer and call rs_job_iter() with it again when there is
- * more output space.
- *
- * \sa rs_job_iter()
- */
+ * On input, the buffers structure must contain the address and length of the
+ * input and output buffers. The library updates these values to indicate the
+ * amount of \b remaining buffer. So, on return, #avail_out is not the amount
+ * of output data produced, but rather the amount of output buffer space still
+ * available.
+ *
+ * This means that the values on return are consistent with the values on
+ * entry, and suitable to be passed in on a second call, but they don't
+ * directly tell you how much output data was produced.
+ *
+ * Note also that if *#avail_in is nonzero on return, then not all of the input
+ * data has been consumed. The caller should either provide more output buffer
+ * space and call ::rs_job_iter() again passing the same #next_in and
+ * #avail_in, or put the remaining input data into some persistent buffer and
+ * call rs_job_iter() with it again when there is more output space.
+ *
+ * \sa rs_job_iter() */
struct rs_buffers_s {
- /** \brief Next input byte.
- * References a pointer which on entry should point to
- * the start of the data to be encoded. Updated to point to the byte
- * after the last one consumed.
- **/
+ /** Next input byte.
+ *
+ * References a pointer which on entry should point to the start of the
+ * data to be encoded. Updated to point to the byte after the last one
+ * consumed. */
char *next_in;
- /**
- * \brief Number of bytes available at next_in
- * References the length of available input. Updated to
- * be the number of unused data bytes, which will be zero if all the
- * input was consumed. May be zero if there is no new input, but the
- * caller just wants to drain output.
- */
+ /** Number of bytes available at next_in.
+ *
+ * References the length of available input. Updated to be the number of
+ * unused data bytes, which will be zero if all the input was consumed.
+ * May be zero if there is no new input, but the caller just wants to drain
+ * output. */
size_t avail_in;
- /**
- * \brief True if there is no more data after this.
- */
+ /** True if there is no more data after this. */
int eof_in;
- /**
- * \brief Next output byte should be put there
- * References a pointer which on entry points to the
- * start of the output buffer. Updated to point to the byte after the
- * last one filled.
- */
+ /** Next output byte should be put there.
+ *
+ * References a pointer which on entry points to the start of the output
+ * buffer. Updated to point to the byte after the last one filled. */
char *next_out;
- /**
- * \brief Remaining free space at next_out
+ /** Remaining free space at next_out.
*
- * References the size of available output buffer.
- * Updated to the size of unused output buffer.
- */
+ * References the size of available output buffer. Updated to the size of
+ * unused output buffer. */
size_t avail_out;
};
-/**
- * \see ::rs_buffers_s
- */
+/** \sa ::rs_buffers_s */
typedef struct rs_buffers_s rs_buffers_t;
/** Default block length, if not determined by any other factors.
@@ -415,24 +344,19 @@ typedef struct rs_buffers_s rs_buffers_t;
* a 1KB block_len. */
#define RS_DEFAULT_STRONG_LEN 12
-/**
- * \brief Job of work to be done.
+/** Job of work to be done.
*
- * Created by functions such as rs_sig_begin(), and then iterated
- * over by rs_job_iter().
+ * Created by functions such as rs_sig_begin(), and then iterated over by
+ * rs_job_iter().
*
* The contents are opaque to the application, and instances are always
* allocated by the library.
*
- * \see \ref api_streaming
- * \see rs_job
- */
+ * \sa \ref api_streaming \sa rs_job */
typedef struct rs_job rs_job_t;
-
-/**
- * \brief Run a ::rs_job state machine until it blocks
- * (::RS_BLOCKED), returns an error, or completes (::RS_DONE).
+/** Run a ::rs_job state machine until it blocks (::RS_BLOCKED), returns an
+ * error, or completes (::RS_DONE).
*
* \param job Description of job state.
*
@@ -440,39 +364,29 @@ typedef struct rs_job rs_job_t;
*
* \return The ::rs_result that caused iteration to stop.
*
- * \c buffers->eof_in should be true if there is no more data after what's
- * in the
- * input buffer. The final block checksum will run across whatever's
- * in there, without trying to accumulate anything else.
+ * \c buffers->eof_in should be true if there is no more data after what's in
+ * the input buffer. The final block checksum will run across whatever's in
+ * there, without trying to accumulate anything else.
*
- * \see \ref api_streaming.
- */
-rs_result rs_job_iter(rs_job_t *job, rs_buffers_t *buffers);
+ * \sa \ref api_streaming */
+rs_result rs_job_iter(rs_job_t *job, rs_buffers_t *buffers);
-/**
- * Type of application-supplied function for rs_job_drive().
+/** Type of application-supplied function for rs_job_drive().
*
- * \see \ref api_pull.
- **/
+ * \sa \ref api_pull */
typedef rs_result rs_driven_cb(rs_job_t *job, rs_buffers_t *buf,
void *opaque);
-/**
- * Actively process a job, by making callbacks to fill and empty the
- * buffers until the job is done.
- */
-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. */
+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);
-/**
- * Return a pointer to the statistics in a job.
- */
-const rs_stats_t * rs_job_statistics(rs_job_t *job);
+/** Return a pointer to the statistics in a job. */
+const rs_stats_t *rs_job_statistics(rs_job_t *job);
-/** Deallocate job state.
- */
-rs_result rs_job_free(rs_job_t *);
+/** Deallocate job state. */
+rs_result rs_job_free(rs_job_t *);
/** Get or check signature arguments for a given file size.
*
@@ -497,7 +411,6 @@ rs_result rs_sig_args(rs_long_t old_fsize,
size_t *block_len,
size_t *strong_len);
-
/** Start generating a signature.
*
* It's recommended you use rs_sig_args() to get the recommended arguments for
@@ -515,102 +428,73 @@ rs_result rs_sig_args(rs_long_t old_fsize,
* many bytes, to make the signature shorter. It's recommended you leave this
* at zero to get the full strength.
*
- * \sa rs_sig_file()
- */
-rs_job_t *rs_sig_begin(size_t new_block_len,
- size_t strong_sum_len,
+ * \sa rs_sig_file() */
+rs_job_t *rs_sig_begin(size_t new_block_len, size_t strong_sum_len,
rs_magic_number sig_magic);
-/**
- * Prepare to compute a streaming delta.
+/** Prepare to compute a streaming delta.
*
* \todo Add a version of this that takes a ::rs_magic_number controlling the
- * delta format.
- **/
+ * delta format. */
rs_job_t *rs_delta_begin(rs_signature_t *);
-
-/**
- * \brief Read a signature from a file into an ::rs_signature structure
- * in memory.
+/** Read a signature from a file into an ::rs_signature structure in memory.
*
- * Once there, it can be used to generate a delta to a newer version of
- * the file.
+ * Once there, it can be used to generate a delta to a newer version of the
+ * file.
*
- * \note After loading the signatures, you must call
- * \ref rs_build_hash_table() before you can use them.
- */
+ * \note After loading the signatures, you must call \ref rs_build_hash_table()
+ * before you can use them. */
rs_job_t *rs_loadsig_begin(rs_signature_t **);
-
-/**
- * Call this after loading a signature to index it.
+/** Call this after loading a signature to index it.
*
- * Use rs_free_sumset() to release it after use.
- */
-rs_result rs_build_hash_table(rs_signature_t* sums);
-
+ * Use rs_free_sumset() to release it after use. */
+rs_result rs_build_hash_table(rs_signature_t *sums);
-/**
- * \brief Callback used to retrieve parts of the basis file.
+/** Callback used to retrieve parts of the basis file.
*
* \param pos Position where copying should begin.
*
- * \param len On input, the amount of data that should be retrieved.
- * Updated to show how much is actually available, but should not be greater
- * than the input value.
+ * \param len On input, the amount of data that should be retrieved. Updated to
+ * show how much is actually available, but should not be greater than the
+ * input value.
*
- * \param buf On input, a buffer of at least \p *len bytes. May be
- * updated to point to a buffer allocated by the callback if it
- * prefers.
- */
-typedef rs_result rs_copy_cb(void *opaque, rs_long_t pos,
- size_t *len, void **buf);
+ * \param buf On input, a buffer of at least \p *len bytes. May be updated to
+ * point to a buffer allocated by the callback if it prefers. */
+typedef rs_result rs_copy_cb(void *opaque, rs_long_t pos, size_t *len,
+ void **buf);
-
-
-/**
- * \brief Apply a \a delta to a \a basis file to recreate
- * the \a new file.
+/** Apply a \a delta to a \a basis file to recreate the \a new file.
*
- * This gives you back a ::rs_job_t object, which can be cranked by
- * calling rs_job_iter() and updating the stream pointers. When
- * finished, call rs_job_free() to dispose of it.
+ * This gives you back a ::rs_job_t object, which can be cranked by calling
+ * rs_job_iter() and updating the stream pointers. When finished, call
+ * rs_job_free() to dispose of it.
*
- * \param copy_cb Callback used to retrieve content from the basis
- * file.
+ * \param copy_cb Callback used to retrieve content from the basis file.
*
- * \param copy_arg Opaque environment pointer passed through to the
- * callback.
+ * \param copy_arg Opaque environment pointer passed through to the callback.
*
- * \todo As output is produced, accumulate the MD4 checksum of the
- * output. Then if we find a CHECKSUM command we can check it's
- * contents against the output.
+ * \todo As output is produced, accumulate the MD4 checksum of the output.
+ * Then if we find a CHECKSUM command we can check it's contents against the
+ * output.
*
* \todo Implement COPY commands.
*
- * \sa rs_patch_file()
- * \sa \ref api_streaming
- */
-rs_job_t *rs_patch_begin(rs_copy_cb *copy_cb, void *copy_arg);
-
+ * \sa rs_patch_file() \sa \ref api_streaming */
+rs_job_t *rs_patch_begin(rs_copy_cb * copy_cb, void *copy_arg);
-#ifndef RSYNC_NO_STDIO_INTERFACE
-#include <stdio.h>
+# ifndef RSYNC_NO_STDIO_INTERFACE
+# include <stdio.h>
-/**
- * Buffer sizes for file IO.
+/** Buffer sizes for file IO.
*
- * The default 0 means use the recommended buffer size for the
- * operation being performed, any other value will override the
- * recommended sizes. You probably only need to change these in
- * testing. */
+ * The default 0 means use the recommended buffer size for the operation being
+ * performed, any other value will override the recommended sizes. You probably
+ * only need to change these in testing. */
extern int rs_inbuflen, rs_outbuflen;
-
-/**
- * Generate the signature of a basis file, and write it out to
- * another.
+/** Generate the signature of a basis file, and write it out to another.
*
* \param old_file Stdio readable file whose signature will be generated.
*
@@ -620,49 +504,45 @@ extern int rs_inbuflen, rs_outbuflen;
*
* \param strong_len truncated length of strong checksums, in bytes
*
- * \param sig_magic A signature magic number indicating
- * what format to use.
+ * \param sig_magic A signature magic number indicating what format to use.
*
* \param stats Optional pointer to receive statistics.
*
- * \sa \ref api_whole
- */
-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);
+ * \sa \ref api_whole */
+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);
-/**
- * Load signatures from a signature file into memory. Return a
- * pointer to the newly allocated structure in \p sumset.
+/** Load signatures from a signature file into memory.
*
- * \sa \ref api_whole
- */
+ * \param sig_file Readable stdio file from which the signature will be read.
+ *
+ * \param sumset on return points to the newly allocated structure.
+ *
+ * \param stats Optional pointer to receive statistics.
+ *
+ * \sa \ref api_whole */
rs_result rs_loadsig_file(FILE *sig_file, rs_signature_t **sumset,
- rs_stats_t *stats);
+ rs_stats_t *stats);
-/**
- * ::rs_copy_cb that reads from a stdio file.
- **/
+/** ::rs_copy_cb that reads from a stdio file. */
rs_result rs_file_copy_cb(void *arg, rs_long_t pos, size_t *len, void **buf);
+/** Generate a delta between a signature and a new file into a delta file.
+ *
+ * \sa \ref api_whole */
+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, int a delta file.
- * \sa \ref api_whole
- **/
-rs_result rs_delta_file(rs_signature_t *, FILE *new_file, FILE *delta_file, rs_stats_t *);
-
-
-/**
- * Apply a patch, relative to a basis, into a new file.
- * \sa \ref api_whole
- */
-rs_result rs_patch_file(FILE *basis_file, FILE *delta_file, FILE *new_file, rs_stats_t *);
-#endif /* ! RSYNC_NO_STDIO_INTERFACE */
+/** Apply a patch, relative to a basis, into a new file.
+ *
+ * \sa \ref api_whole */
+rs_result rs_patch_file(FILE *basis_file, FILE *delta_file, FILE *new_file,
+ rs_stats_t *);
+# endif /* !RSYNC_NO_STDIO_INTERFACE */
-#ifdef __cplusplus
-}
-#endif
+# ifdef __cplusplus
+} /* extern "C" */
+# endif
-#endif /* ! _RSYNC_H */
+#endif /* !_RSYNC_H */
diff --git a/src/mdfour.c b/src/mdfour.c
index c5fe24d..458d053 100644
--- a/src/mdfour.c
+++ b/src/mdfour.c
@@ -21,24 +21,22 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-/* MD4 message digest algorithm.
+/** \file mdfour.c MD4 message digest algorithm.
*
- * TODO: Perhaps use the MD4 routine from OpenSSL if it's installed.
- * It's probably not worth the trouble.
+ * \todo Perhaps use the MD4 routine from OpenSSL if it's installed. It's
+ * probably not worth the trouble.
*
- * This was originally written by Andrew Tridgell for use in Samba.
- * It was then modified by;
+ * This was originally written by Andrew Tridgell for use in Samba. It was then
+ * modified by;
*
- * 2002-06-xx: Robert Weber <robert.weber@Colorado.edu>
- * optimisations and fixed >512M support.
+ * 2002-06-xx: Robert Weber <robert.weber@Colorado.edu> optimisations and fixed
+ * >512M support.
*
- * 2002-06-27: Donovan Baarda <abo@minkirri.apana.org.au>
- * further optimisations and cleanups.
+ * 2002-06-27: Donovan Baarda <abo@minkirri.apana.org.au> further optimisations
+ * and cleanups.
*
- * 2004-09-09: Simon Law <sfllaw@debian.org>
- * handle little-endian machines that can't do unaligned access
- * (e.g. ia64, pa-risc).
- */
+ * 2004-09-09: Simon Law <sfllaw@debian.org> handle little-endian machines that
+ * can't do unaligned access (e.g. ia64, pa-risc). */
#include "config.h"
@@ -50,7 +48,6 @@
#include "trace.h"
#include "mdfour.h"
-
#define F(X,Y,Z) (((X)&(Y)) | ((~(X))&(Z)))
#define G(X,Y,Z) (((X)&(Y)) | ((X)&(Z)) | ((Y)&(Z)))
#define H(X,Y,Z) ((X)^(Y)^(Z))
@@ -67,31 +64,23 @@ static unsigned char PADDING[64] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
+static void rs_mdfour_block(rs_mdfour_t *md, void const *p);
-static void
-rs_mdfour_block(rs_mdfour_t *md, void const *p);
-
-
-
-/**
- * Update an MD4 accumulator from a 64-byte chunk.
+/** Update an MD4 accumulator from a 64-byte chunk.
*
- * This cannot be used for the last chunk of the file, which must be
- * padded and contain the file length. rs_mdfour_tail() is used for
- * that.
+ * This cannot be used for the last chunk of the file, which must be padded and
+ * contain the file length. rs_mdfour_tail() is used for that.
*
- * \todo Recode to be fast, and to use system integer types. Perhaps
- * if we can find an mdfour implementation already on the system
- * (e.g. in OpenSSL) then we should use it instead of our own?
+ * \todo Recode to be fast, and to use system integer types. Perhaps if we can
+ * find an mdfour implementation already on the system (e.g. in OpenSSL) then
+ * we should use it instead of our own?
*
- * \param X A series of integer, read little-endian from the file.
- */
-static void
-rs_mdfour64(rs_mdfour_t * m, const void *p)
+ * \param X A series of integer, read little-endian from the file. */
+static void rs_mdfour64(rs_mdfour_t *m, const void *p)
{
- uint32_t AA, BB, CC, DD;
- uint32_t A, B, C, D;
- const uint32_t *X = (const uint32_t *) p;
+ uint32_t AA, BB, CC, DD;
+ uint32_t A, B, C, D;
+ const uint32_t *X = (const uint32_t *)p;
A = m->A;
B = m->B;
@@ -164,17 +153,14 @@ rs_mdfour64(rs_mdfour_t * m, const void *p)
m->D = D;
}
-
-/**
- * These next routines are necessary because MD4 is specified in terms of
+/** These next routines are necessary because MD4 is specified in terms of
* little-endian int32s, but we have a byte buffer. On little-endian
* platforms, I think we can just use the buffer pointer directly.
*
* There are some nice endianness routines in glib, including assembler
* variants. If we ever depended on glib, then it could be good to use them
* instead. */
-inline static void
-copy4( /* @out@ */ unsigned char *out, uint32_t const x)
+inline static void copy4( /* @out@ */ unsigned char *out, uint32_t const x)
{
out[0] = x;
out[1] = x >> 8;
@@ -182,12 +168,10 @@ copy4( /* @out@ */ unsigned char *out, uint32_t const x)
out[3] = x >> 24;
}
-
/* We need this if there is a uint64 */
-/* --robert.weber@Colorado.edu */
+/* --robert.weber@Colorado.edu */
#ifdef HAVE_UINT64
-inline static void
-copy8( /* @out@ */ unsigned char *out, uint64_t const x)
+inline static void copy8( /* @out@ */ unsigned char *out, uint64_t const x)
{
out[0] = x;
out[1] = x >> 8;
@@ -198,15 +182,13 @@ copy8( /* @out@ */ unsigned char *out, uint64_t const x)
out[6] = x >> 48;
out[7] = x >> 56;
}
-#endif /* HAVE_UINT64 */
-
+#endif /* HAVE_UINT64 */
/* We only need this if we are big-endian */
#ifdef WORDS_BIGENDIAN
-inline static void
-copy64( /* @out@ */ uint32_t * M, unsigned char const *in)
+inline static void copy64( /* @out@ */ uint32_t *M, unsigned char const *in)
{
- int i=16;
+ int i = 16;
while (i--) {
*M++ = (in[3] << 24) | (in[2] << 16) | (in[1] << 8) | in[0];
@@ -214,60 +196,51 @@ copy64( /* @out@ */ uint32_t * M, unsigned char const *in)
}
}
-
-/**
- * Accumulate a block, making appropriate conversions for bigendian
- * machines.
+/** Accumulate a block, making appropriate conversions for bigendian machines.
*/
-inline static void
-rs_mdfour_block(rs_mdfour_t *md, void const *p)
+inline static void rs_mdfour_block(rs_mdfour_t *md, void const *p)
{
- uint32_t M[16];
+ uint32_t M[16];
copy64(M, p);
rs_mdfour64(md, M);
}
-
-#else /* WORDS_BIGENDIAN */
+#else /* WORDS_BIGENDIAN */
# ifdef __i386__
/* If we are on an IA-32 machine, we can process directly. */
-inline static void
-rs_mdfour_block(rs_mdfour_t *md, void const *p)
+inline static void rs_mdfour_block(rs_mdfour_t *md, void const *p)
{
- rs_mdfour64(md,p);
+ rs_mdfour64(md, p);
}
-# else /* !WORDS_BIGENDIAN && !__i386__ */
+# else /* !WORDS_BIGENDIAN && !__i386__ */
-/* We are little-endian, but not on i386 and therefore may not be able
- * to do unaligned access safely/quickly.
- *
- * So if the input is not already aligned correctly, copy it to an
- * aligned buffer first. */
-inline static void
-rs_mdfour_block(rs_mdfour_t *md, void const *p)
+/* We are little-endian, but not on i386 and therefore may not be able to do
+ unaligned access safely/quickly.
+
+ So if the input is not already aligned correctly, copy it to an aligned
+ buffer first. */
+inline static void rs_mdfour_block(rs_mdfour_t *md, void const *p)
{
- unsigned long ptrval = (unsigned long) p;
+ unsigned long ptrval = (unsigned long)p;
if (ptrval & 3) {
- uint32_t M[16];
+ uint32_t M[16];
memcpy(M, p, 16 * sizeof(uint32_t));
rs_mdfour64(md, M);
} else {
- rs_mdfour64(md, (const uint32_t *) p);
+ rs_mdfour64(md, (const uint32_t *)p);
}
}
-# endif /* ! __i386__ */
-#endif /* WORDS_BIGENDIAN */
+# endif /* !__i386__ */
+#endif /* WORDS_BIGENDIAN */
-
-void
-rs_mdfour_begin(rs_mdfour_t * md)
+void rs_mdfour_begin(rs_mdfour_t *md)
{
memset(md, 0, sizeof(*md));
md->A = 0x67452301;
@@ -281,64 +254,57 @@ rs_mdfour_begin(rs_mdfour_t * md)
#endif
}
-
-/**
- * Handle special behaviour for processing the last block of a file
- * when calculating its MD4 checksum.
+/** Handle special behaviour for processing the last block of a file when
+ * calculating its MD4 checksum.
*
* This must be called exactly once per file.
*
- * Modified by Robert Weber to use uint64 in order that we can sum files
- * > 2^29 = 512 MB.
- * --Robert.Weber@colorado.edu
- */
-static void
-rs_mdfour_tail(rs_mdfour_t * m)
+ * Modified by Robert Weber to use uint64 in order that we can sum files > 2^29
+ * = 512 MB. --Robert.Weber@colorado.edu */
+static void rs_mdfour_tail(rs_mdfour_t *m)
{
#ifdef HAVE_UINT64
- uint64_t b;
-#else /* HAVE_UINT64 */
- uint32_t b[2];
-#endif /* HAVE_UINT64 */
- unsigned char buf[8];
- size_t pad_len;
+ uint64_t b;
+#else /* HAVE_UINT64 */
+ uint32_t b[2];
+#endif /* HAVE_UINT64 */
+ unsigned char buf[8];
+ size_t pad_len;
/* convert the totalN byte count into a bit count buffer */
#ifdef HAVE_UINT64
b = m->totalN << 3;
copy8(buf, b);
-#else /* HAVE_UINT64 */
+#else /* HAVE_UINT64 */
b[0] = m->totalN_lo << 3;
b[1] = ((m->totalN_hi << 3) | (m->totalN_lo >> 29));
copy4(buf, b[0]);
copy4(buf + 4, b[1]);
-#endif /* HAVE_UINT64 */
+#endif /* HAVE_UINT64 */
/* calculate length and process the padding data */
- pad_len=(m->tail_len <56) ? (56 - m->tail_len) : (120 - m->tail_len);
- rs_mdfour_update(m,PADDING,pad_len);
+ pad_len = (m->tail_len < 56) ? (56 - m->tail_len) : (120 - m->tail_len);
+ rs_mdfour_update(m, PADDING, pad_len);
/* process the bit count */
- rs_mdfour_update(m,buf,8);
+ rs_mdfour_update(m, buf, 8);
}
-
-void
-rs_mdfour_update(rs_mdfour_t * md, void const *in_void, size_t n)
+void rs_mdfour_update(rs_mdfour_t *md, void const *in_void, size_t n)
{
- unsigned char const *in = (unsigned char const *) in_void;
+ unsigned char const *in = (unsigned char const *)in_void;
/* increment totalN */
#ifdef HAVE_UINT64
- md->totalN+=n;
-#else /* HAVE_UINT64 */
+ md->totalN += n;
+#else /* HAVE_UINT64 */
if ((md->totalN_lo += n) < n)
- md->totalN_hi++;
-#endif /* HAVE_UINT64 */
+ md->totalN_hi++;
+#endif /* HAVE_UINT64 */
- /* If there's any leftover data in the tail buffer, then first we have
- * to make it up to a whole block to process it. */
+ /* If there's any leftover data in the tail buffer, then first we have to
+ make it up to a whole block to process it. */
if (md->tail_len) {
- size_t tail_gap = 64 - md->tail_len;
+ size_t tail_gap = 64 - md->tail_len;
if (tail_gap <= n) {
memcpy(&md->tail[md->tail_len], in, tail_gap);
rs_mdfour_block(md, md->tail);
@@ -353,16 +319,14 @@ rs_mdfour_update(rs_mdfour_t * md, void const *in_void, size_t n)
in += 64;
n -= 64;
}
- /* Put remaining bytes onto tail*/
+ /* Put remaining bytes onto tail */
if (n) {
memcpy(&md->tail[md->tail_len], in, n);
md->tail_len += n;
}
}
-
-void
-rs_mdfour_result(rs_mdfour_t * md, unsigned char *out)
+void rs_mdfour_result(rs_mdfour_t *md, unsigned char *out)
{
rs_mdfour_tail(md);
@@ -372,11 +336,9 @@ rs_mdfour_result(rs_mdfour_t * md, unsigned char *out)
copy4(out + 12, md->D);
}
-
-void
-rs_mdfour(unsigned char *out, void const *in, size_t n)
+void rs_mdfour(unsigned char *out, void const *in, size_t n)
{
- rs_mdfour_t md;
+ rs_mdfour_t md;
rs_mdfour_begin(&md);
rs_mdfour_update(&md, in, n);
diff --git a/src/mdfour.h b/src/mdfour.h
index e72643e..0871eff 100644
--- a/src/mdfour.h
+++ b/src/mdfour.h
@@ -20,16 +20,14 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-/** \private
- * Internal state while computing an MD4 hash.
- */
+/** \private Internal state while computing an MD4 hash. */
struct rs_mdfour {
- unsigned int A, B, C, D;
+ unsigned int A, B, C, D;
#if HAVE_UINT64
- uint64_t totalN;
+ uint64_t totalN;
#else
- uint32_t totalN_hi, totalN_lo;
+ uint32_t totalN_hi, totalN_lo;
#endif
- int tail_len;
- unsigned char tail[64];
+ int tail_len;
+ unsigned char tail[64];
};
diff --git a/src/mksum.c b/src/mksum.c
index 4f3a105..8e9d56a 100644
--- a/src/mksum.c
+++ b/src/mksum.c
@@ -20,22 +20,15 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-
-/**
- * \file mksum.c Generate file signatures.
- **/
-
-/*
- * Generating checksums is pretty easy, since we can always just
- * process whatever data is available. When a whole block has
- * arrived, or we've reached the end of the file, we write the
- * checksum out.
- */
-
-/* TODO: Perhaps force blocks to be a multiple of 64 bytes, so that we
- * can be sure checksum generation will be more efficient. I guess it
- * will be OK at the moment, though, because tails are only used if
- * necessary. */
+/** \file mksum.c Generate file signatures.
+ *
+ * Generating checksums is pretty easy, since we can always just process
+ * whatever data is available. When a whole block has arrived, or we've
+ * reached the end of the file, we write the checksum out.
+ *
+ * \todo Perhaps force blocks to be a multiple of 64 bytes, so that we can be
+ * sure checksum generation will be more efficient. I guess it will be OK at
+ * the moment, though, because tails are only used if necessary. */
#include "config.h"
@@ -51,24 +44,19 @@
#include "netint.h"
#include "trace.h"
-
/* Possible state functions for signature generation. */
static rs_result rs_sig_s_header(rs_job_t *);
static rs_result rs_sig_s_generate(rs_job_t *);
-
-
-/**
- * State of trying to send the signature header.
- * \private
- */
+/** State of trying to send the signature header. \private */
static rs_result rs_sig_s_header(rs_job_t *job)
{
rs_signature_t *sig = job->signature;
rs_result result;
- if ((result = rs_signature_init(sig, job->sig_magic, job->sig_block_len,
- job->sig_strong_len, 0)) != RS_DONE)
+ if ((result =
+ rs_signature_init(sig, job->sig_magic, job->sig_block_len,
+ job->sig_strong_len, 0)) != RS_DONE)
return result;
rs_squirt_n4(job, sig->magic);
rs_squirt_n4(job, sig->block_len);
@@ -81,67 +69,53 @@ static rs_result rs_sig_s_header(rs_job_t *job)
return RS_RUNNING;
}
-
-/**
- * Generate the checksums for a block and write it out. Called when
- * we already know we have enough data in memory at \p block.
- * \private
- */
-static rs_result
-rs_sig_do_block(rs_job_t *job, const void *block, size_t len)
+/** Generate the checksums for a block and write it out. Called when we
+ * already know we have enough data in memory at \p block. \private */
+static rs_result rs_sig_do_block(rs_job_t *job, const void *block, size_t len)
{
- rs_signature_t *sig = job->signature;
- rs_weak_sum_t weak_sum;
- rs_strong_sum_t strong_sum;
+ rs_signature_t *sig = job->signature;
+ rs_weak_sum_t weak_sum;
+ rs_strong_sum_t strong_sum;
weak_sum = rs_calc_weak_sum(block, len);
rs_signature_calc_strong_sum(sig, block, len, &strong_sum);
rs_squirt_n4(job, weak_sum);
rs_tube_write(job, strong_sum, sig->strong_sum_len);
if (rs_trace_enabled()) {
- char strong_sum_hex[RS_MAX_STRONG_SUM_LENGTH * 2 + 1];
+ char strong_sum_hex[RS_MAX_STRONG_SUM_LENGTH * 2 + 1];
rs_hexify(strong_sum_hex, strong_sum, sig->strong_sum_len);
- rs_trace("sent block: weak="FMT_WEAKSUM", strong=%s", weak_sum, strong_sum_hex);
+ rs_trace("sent block: weak=" FMT_WEAKSUM ", strong=%s", weak_sum,
+ strong_sum_hex);
}
job->stats.sig_blocks++;
return RS_RUNNING;
}
-
-/**
- * State of reading a block and trying to generate its sum.
- * \private
- */
-static rs_result
-rs_sig_s_generate(rs_job_t *job)
+/** State of reading a block and trying to generate its sum. \private */
+static rs_result rs_sig_s_generate(rs_job_t *job)
{
- rs_result result;
- size_t len;
- void *block;
+ rs_result result;
+ size_t len;
+ void *block;
/* must get a whole block, otherwise try again */
len = job->signature->block_len;
result = rs_scoop_read(job, len, &block);
-
- /* unless we're near eof, in which case we'll accept
- * whatever's in there */
- if ((result == RS_BLOCKED && rs_job_input_is_ending(job))) {
+ /* If we are near EOF, get whatever is left. */
+ if (result == RS_INPUT_ENDED)
result = rs_scoop_read_rest(job, &len, &block);
- } else if (result == RS_INPUT_ENDED) {
+ if (result == RS_INPUT_ENDED) {
return RS_DONE;
} else if (result != RS_DONE) {
rs_trace("generate stopped: %s", rs_strerror(result));
return result;
}
-
- rs_trace("got "FMT_SIZE" byte block", len);
-
+ rs_trace("got " FMT_SIZE " byte block", len);
return rs_sig_do_block(job, block, len);
}
-
-rs_job_t * rs_sig_begin(size_t new_block_len, size_t strong_sum_len,
- rs_magic_number sig_magic)
+rs_job_t *rs_sig_begin(size_t new_block_len, size_t strong_sum_len,
+ rs_magic_number sig_magic)
{
rs_job_t *job;
diff --git a/src/msg.c b/src/msg.c
index 505dc13..e75134d 100644
--- a/src/msg.c
+++ b/src/msg.c
@@ -19,8 +19,7 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-
- /*
+ /*=
| Welcome to Arco AM/PM Mini-Market. We
| would like to advise our customers
| that any individual who offers to
@@ -34,6 +33,12 @@
| Arco, and have a nice day.
*/
+/** \file msg.c error messages for re_result values.
+ *
+ * \todo (Suggestion by tridge) Add a function which outputs a complete text
+ * description of a job, including only the fields relevant to the current
+ * encoding function. */
+
#include "config.h"
#include <stdlib.h>
@@ -41,13 +46,6 @@
#include "librsync.h"
-/*
- * TODO: (Suggestion by tridge) Add a function which outputs a
- * complete text description of a job, including only the fields
- * relevant to the current encoding function.
- */
-
-
char const *rs_strerror(rs_result r)
{
switch (r) {
diff --git a/src/netint.c b/src/netint.c
index 2fcf300..20a22c4 100644
--- a/src/netint.c
+++ b/src/netint.c
@@ -1,50 +1,46 @@
/*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*-
*
* librsync -- library for network deltas
- *
+ *
* Copyright (C) 1999, 2000, 2001 by Martin Pool <mbp@sourcefrog.net>
* Copyright (C) 1999 by Andrew Tridgell <tridge@samba.org>
- *
+ *
* 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.
*/
- /*
+ /*=
| Ummm, well, OK. The network's the
| network, the computer's the
| computer. Sorry for the confusion.
| -- Sun Microsystems
*/
-/*
- * Network-byte-order output to the tube.
+/** \file netint.c Network-byte-order output to the tube.
*
- * All the `suck' routines return a result code. The most common
- * values are RS_DONE if they have enough data, or RS_BLOCKED if there
- * is not enough input to proceed.
+ * All the `suck' routines return a result code. The most common values are
+ * RS_DONE if they have enough data, or RS_BLOCKED if there is not enough input
+ * to proceed.
*
- * All the netint operations are done in a fairly simpleminded way,
- * since we don't want to rely on stdint types that may not be
- * available on some platforms.
- */
-
-/*
- * TODO: If we don't have <stdint.h> (or perhaps even if we do),
- * determine endianness and integer size by hand and use that to do
- * our own conversion routines. We possibly need this anyhow to do
- * 64-bit integers, since there seems to be no ntohs() analog.
- */
+ * All the netint operations are done in a fairly simpleminded way, since we
+ * don't want to rely on stdint types that may not be available on some
+ * platforms.
+ *
+ * \todo If we don't have <stdint.h> (or perhaps even if we do), determine
+ * endianness and integer size by hand and use that to do our own conversion
+ * routines. We possibly need this anyhow to do 64-bit integers, since there
+ * seems to be no ntohs() analog. */
#include "config.h"
@@ -63,41 +59,32 @@
#define RS_MAX_INT_BYTES 8
-
-/**
- * \brief Write a single byte to a stream output.
- */
-rs_result
-rs_squirt_byte(rs_job_t *job, unsigned char d)
+/** Write a single byte to a stream output. */
+rs_result rs_squirt_byte(rs_job_t *job, unsigned char d)
{
rs_tube_write(job, &d, 1);
return RS_DONE;
}
-
-/**
- * \brief Write a variable-length integer to a stream.
+/** Write a variable-length integer to a stream.
*
* \param job Job of data.
*
* \param d Datum to write out.
*
- * \param len Length of integer, in bytes.
- */
-rs_result
-rs_squirt_netint(rs_job_t *job, rs_long_t d, int len)
+ * \param len Length of integer, in bytes. */
+rs_result rs_squirt_netint(rs_job_t *job, rs_long_t d, int len)
{
- unsigned char buf[RS_MAX_INT_BYTES];
- int i;
+ unsigned char buf[RS_MAX_INT_BYTES];
+ int i;
if (len <= 0 || len > RS_MAX_INT_BYTES) {
rs_error("Illegal integer length %d", len);
return RS_INTERNAL_ERROR;
}
- /* Fill the output buffer with a bigendian representation of the
- * number. */
- for (i = len-1; i >=0; i--) {
+ /* Fill the output buffer with a bigendian representation of the number. */
+ for (i = len - 1; i >= 0; i--) {
buf[i] = d; /* truncated */
d >>= 8;
}
@@ -107,65 +94,54 @@ rs_squirt_netint(rs_job_t *job, rs_long_t d, int len)
return RS_DONE;
}
-
-
-rs_result
-rs_squirt_n4(rs_job_t *job, int val)
+rs_result rs_squirt_n4(rs_job_t *job, int val)
{
return rs_squirt_netint(job, val, 4);
}
-
-
-rs_result
-rs_suck_netint(rs_job_t *job, rs_long_t *v, int len)
+rs_result rs_suck_netint(rs_job_t *job, rs_long_t *v, int len)
{
- unsigned char *buf;
- int i;
- rs_result result;
+ unsigned char *buf;
+ int i;
+ rs_result result;
if (len <= 0 || len > RS_MAX_INT_BYTES) {
rs_error("Illegal integer length %d", len);
return RS_INTERNAL_ERROR;
}
- if ((result = rs_scoop_read(job, len, (void **) &buf)) != RS_DONE)
+ if ((result = rs_scoop_read(job, len, (void **)&buf)) != RS_DONE)
return result;
*v = 0;
for (i = 0; i < len; i++) {
- *v = *v<<8 | buf[i];
+ *v = *v << 8 | buf[i];
}
return RS_DONE;
}
-
-rs_result
-rs_suck_byte(rs_job_t *job, unsigned char *v)
+rs_result rs_suck_byte(rs_job_t *job, unsigned char *v)
{
void *inb;
rs_result result;
-
+
if ((result = rs_scoop_read(job, 1, &inb)) == RS_DONE)
- *v = *((unsigned char *) inb);
+ *v = *((unsigned char *)inb);
return result;
}
-
-rs_result
-rs_suck_n4(rs_job_t *job, int *v)
+rs_result rs_suck_n4(rs_job_t *job, int *v)
{
- rs_result result;
- rs_long_t d;
+ rs_result result;
+ rs_long_t d;
result = rs_suck_netint(job, &d, 4);
*v = d;
return result;
-}
-
+}
int rs_int_len(rs_long_t val)
{
@@ -178,7 +154,7 @@ int rs_int_len(rs_long_t val)
else if (!(val & ~(rs_long_t)0xffffffffffffffff))
return 8;
else {
- rs_fatal("can't encode integer "FMT_LONG" yet", val);
+ rs_fatal("can't encode integer " FMT_LONG " yet", val);
return -1;
}
}
diff --git a/src/netint.h b/src/netint.h
index e75d268..4f7607a 100644
--- a/src/netint.h
+++ b/src/netint.h
@@ -1,20 +1,20 @@
/*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*-
*
* librsync -- library for network deltas
- *
+ *
* Copyright (C) 1999, 2000, 2001 by Martin Pool <mbp@sourcefrog.net>
* Copyright (C) 1999 by Andrew Tridgell <tridge@samba.org>
- *
+ *
* 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.
diff --git a/src/patch.c b/src/patch.c
index cc95e06..1537795 100644
--- a/src/patch.c
+++ b/src/patch.c
@@ -19,12 +19,10 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-
- /*
+ /*=
| This is Tranquility Base.
*/
-
#include "config.h"
#include <assert.h>
@@ -42,8 +40,6 @@
#include "stream.h"
#include "job.h"
-
-
static rs_result rs_patch_s_cmdbyte(rs_job_t *);
static rs_result rs_patch_s_params(rs_job_t *);
static rs_result rs_patch_s_run(rs_job_t *);
@@ -51,12 +47,8 @@ static rs_result rs_patch_s_literal(rs_job_t *);
static rs_result rs_patch_s_copy(rs_job_t *);
static rs_result rs_patch_s_copying(rs_job_t *);
-
-/**
- * State of trying to read the first byte of a command. Once we've
- * taken that in, we can know how much data to read to get the
- * arguments.
- */
+/** State of trying to read the first byte of a command. Once we've taken
+ * that in, we can know how much data to read to get the arguments. */
static rs_result rs_patch_s_cmdbyte(rs_job_t *job)
{
rs_result result;
@@ -66,7 +58,8 @@ static rs_result rs_patch_s_cmdbyte(rs_job_t *job)
job->cmd = &rs_prototab[job->op];
- rs_trace("got command %#04x (%s), len_1="FMT_SIZE"", job->op, rs_op_kind_name(job->cmd->kind), job->cmd->len_1);
+ rs_trace("got command %#04x (%s), len_1=" FMT_SIZE "", job->op,
+ rs_op_kind_name(job->cmd->kind), job->cmd->len_1);
if (job->cmd->len_1)
job->statefn = rs_patch_s_params;
@@ -78,11 +71,8 @@ static rs_result rs_patch_s_cmdbyte(rs_job_t *job)
return RS_RUNNING;
}
-
-/**
- * Called after reading a command byte to pull in its parameters and
- * then setup to execute the command.
- */
+/** Called after reading a command byte to pull in its parameters and then
+ * setup to execute the command. */
static rs_result rs_patch_s_params(rs_job_t *job)
{
rs_result result;
@@ -110,11 +100,7 @@ static rs_result rs_patch_s_params(rs_job_t *job)
return RS_RUNNING;
}
-
-
-/**
- * Called when we've read in the whole command and we need to execute it.
- */
+/** Called when we've read in the whole command and we need to execute it. */
static rs_result rs_patch_s_run(rs_job_t *job)
{
rs_trace("running command %#04x", job->op);
@@ -138,23 +124,20 @@ static rs_result rs_patch_s_run(rs_job_t *job)
}
}
-
-/**
- * Called when trying to copy through literal data.
- */
+/** Called when trying to copy through literal data. */
static rs_result rs_patch_s_literal(rs_job_t *job)
{
- rs_long_t len = job->param1;
+ rs_long_t len = job->param1;
- rs_trace("LITERAL(len="FMT_LONG")", len);
+ rs_trace("LITERAL(len=" FMT_LONG ")", len);
if (len < 0) {
- rs_error("invalid length="FMT_LONG" on LITERAL command", len);
+ rs_error("invalid length=" FMT_LONG " on LITERAL command", len);
return RS_CORRUPT;
}
job->stats.lit_cmds++;
- job->stats.lit_bytes += len;
+ job->stats.lit_bytes += len;
job->stats.lit_cmdbytes += 1 + job->cmd->len_1;
rs_tube_copy(job, len);
@@ -163,25 +146,23 @@ static rs_result rs_patch_s_literal(rs_job_t *job)
return RS_RUNNING;
}
-
-
static rs_result rs_patch_s_copy(rs_job_t *job)
{
- rs_long_t where, len;
- rs_stats_t *stats;
+ rs_long_t where, len;
+ rs_stats_t *stats;
where = job->param1;
len = job->param2;
- rs_trace("COPY(where="FMT_LONG", len="FMT_LONG")", where, len);
+ rs_trace("COPY(where=" FMT_LONG ", len=" FMT_LONG ")", where, len);
if (len < 0) {
- rs_error("invalid length="FMT_LONG" on COPY command", len);
+ rs_error("invalid length=" FMT_LONG " on COPY command", len);
return RS_CORRUPT;
}
if (where < 0) {
- rs_error("invalid where="FMT_LONG" on COPY command", where);
+ rs_error("invalid where=" FMT_LONG " on COPY command", where);
return RS_CORRUPT;
}
@@ -198,36 +179,35 @@ static rs_result rs_patch_s_copy(rs_job_t *job)
return RS_RUNNING;
}
-
-/**
- * Called when we're executing a COPY command and waiting for all the
- * data to be retrieved from the callback.
- */
+/** Called when we're executing a COPY command and waiting for all the data to
+ * be retrieved from the callback. */
static rs_result rs_patch_s_copying(rs_job_t *job)
{
- rs_result result;
- size_t desired_len, len;
- void *ptr;
- rs_buffers_t *buffs = job->stream;
+ rs_result result;
+ size_t desired_len, len;
+ void *ptr;
+ rs_buffers_t *buffs = job->stream;
- /* copy only as much as will fit in the output buffer, so that we
- * don't have to block or store the input. */
- desired_len = len = (buffs->avail_out < job->basis_len) ? buffs->avail_out : job->basis_len;
+ /* copy only as much as will fit in the output buffer, so that we don't
+ have to block or store the input. */
+ desired_len = len =
+ (buffs->avail_out < job->basis_len) ? buffs->avail_out : job->basis_len;
if (!len)
return RS_BLOCKED;
- rs_trace("copy "FMT_SIZE" bytes from basis at offset "FMT_LONG"", len, job->basis_pos);
+ rs_trace("copy " FMT_SIZE " bytes from basis at offset " FMT_LONG "", len,
+ job->basis_pos);
ptr = buffs->next_out;
- result = (job->copy_cb)(job->copy_arg, job->basis_pos, &len, &ptr);
+ result = (job->copy_cb) (job->copy_arg, job->basis_pos, &len, &ptr);
if (result != RS_DONE)
return result;
else
rs_trace("copy callback returned %s", rs_strerror(result));
- rs_trace("got "FMT_SIZE" bytes back from basis callback", len);
+ rs_trace("got " FMT_SIZE " bytes back from basis callback", len);
if (len > desired_len) {
rs_trace("warning: copy_cb returned more than the requested length.");
@@ -252,34 +232,28 @@ static rs_result rs_patch_s_copying(rs_job_t *job)
return RS_RUNNING;
}
-
-/**
- * Called while we're trying to read the header of the patch.
- */
+/** Called while we're trying to read the header of the patch. */
static rs_result rs_patch_s_header(rs_job_t *job)
{
- int v;
+ int v;
rs_result result;
-
if ((result = rs_suck_n4(job, &v)) != RS_DONE)
return result;
if (v != RS_DELTA_MAGIC) {
- rs_error("got magic number %#x rather than expected value %#x", v, RS_DELTA_MAGIC);
+ rs_error("got magic number %#x rather than expected value %#x", v,
+ RS_DELTA_MAGIC);
return RS_BAD_MAGIC;
} else
rs_trace("got patch magic %#x", v);
-
job->statefn = rs_patch_s_cmdbyte;
return RS_RUNNING;
}
-
-rs_job_t *
-rs_patch_begin(rs_copy_cb *copy_cb, void *copy_arg)
+rs_job_t *rs_patch_begin(rs_copy_cb * copy_cb, void *copy_arg)
{
rs_job_t *job = rs_job_new("patch", rs_patch_s_header);
diff --git a/src/rdiff.c b/src/rdiff.c
index 1ab3ef2..4761e76 100644
--- a/src/rdiff.c
+++ b/src/rdiff.c
@@ -19,31 +19,28 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
- /*
+ /*=
| .. after a year and a day, mourning is
| dangerous to the survivor and troublesome
| to the dead.
| -- Harold Bloom
*/
-/*
- * rdiff.c -- Command-line network-delta tool.
+/** \file rdiff.c -- Command-line network-delta tool.
*
- * TODO: Add a -z option to gzip/gunzip patches. This would be
- * somewhat useful, but more importantly a good test of the streaming
- * API. Also add -I for bzip2.
+ * \todo Add a -z option to gzip/gunzip patches. This would be somewhat
+ * useful, but more importantly a good test of the streaming API. Also add -I
+ * for bzip2.
*
- * If built with debug support and we have mcheck, then turn it on.
+ * \todo If built with debug support and we have mcheck, then turn it on.
* (Optionally?)
*
- * FIXME: popt doesn't handle single dashes very well at the moment:
- * we'd like to use them as arguments to indicate stdin/stdout, but it
- * turns them into options. I sent a patch to the popt maintainers;
- * hopefully it will be fixed in the future.
+ * \todo popt doesn't handle single dashes very well at the moment: we'd like
+ * to use them as arguments to indicate stdin/stdout, but it turns them into
+ * options. I sent a patch to the popt maintainers; hopefully it will be fixed
+ * in the future.
*
- * TODO: Add an option for delta to check whether the files are
- * identical.
- */
+ * \todo Add an option for delta to check whether the files are identical. */
#include "config.h"
@@ -54,11 +51,11 @@
#include <popt.h>
#ifdef HAVE_ZLIB_H
-#include <zlib.h>
+# include <zlib.h>
#endif
#ifdef HAVE_BZLIB_H
-#include <bzlib.h>
+# include <bzlib.h>
#endif
#include "librsync.h"
@@ -68,7 +65,6 @@
#include "isprefix.h"
#include "sumset.h"
-
#define PROGRAM "rdiff"
static size_t block_len = 0;
@@ -77,8 +73,8 @@ static size_t strong_len = 0;
static int show_stats = 0;
static int bzip2_level = 0;
-static int gzip_level = 0;
-static int file_force = 0;
+static int gzip_level = 0;
+static int file_force = 0;
enum {
OPT_GZIP = 1069, OPT_BZIP2
@@ -88,33 +84,30 @@ extern int rs_roll_paranoia;
char *rs_hash_name;
const struct poptOption opts[] = {
- { "verbose", 'v', POPT_ARG_NONE, 0, 'v' },
- { "version", 'V', POPT_ARG_NONE, 0, 'V' },
- { "input-size", 'I', POPT_ARG_INT, &rs_inbuflen },
- { "output-size", 'O', POPT_ARG_INT, &rs_outbuflen },
- { "hash", 'H', POPT_ARG_STRING, &rs_hash_name },
- { "help", '?', POPT_ARG_NONE, 0, 'h' },
- { 0, 'h', POPT_ARG_NONE, 0, 'h' },
- { "block-size", 'b', POPT_ARG_INT, &block_len },
- { "sum-size", 'S', POPT_ARG_INT, &strong_len },
- { "statistics", 's', POPT_ARG_NONE, &show_stats },
- { "stats", 0, POPT_ARG_NONE, &show_stats },
- { "gzip", 'z', POPT_ARG_NONE, 0, OPT_GZIP },
- { "bzip2", 'i', POPT_ARG_NONE, 0, OPT_BZIP2 },
- { "force", 'f', POPT_ARG_NONE, &file_force },
- { "paranoia", 0, POPT_ARG_NONE, &rs_roll_paranoia },
- { 0 }
+ {"verbose", 'v', POPT_ARG_NONE, 0, 'v'},
+ {"version", 'V', POPT_ARG_NONE, 0, 'V'},
+ {"input-size", 'I', POPT_ARG_INT, &rs_inbuflen},
+ {"output-size", 'O', POPT_ARG_INT, &rs_outbuflen},
+ {"hash", 'H', POPT_ARG_STRING, &rs_hash_name},
+ {"help", '?', POPT_ARG_NONE, 0, 'h'},
+ {0, 'h', POPT_ARG_NONE, 0, 'h'},
+ {"block-size", 'b', POPT_ARG_INT, &block_len},
+ {"sum-size", 'S', POPT_ARG_INT, &strong_len},
+ {"statistics", 's', POPT_ARG_NONE, &show_stats},
+ {"stats", 0, POPT_ARG_NONE, &show_stats},
+ {"gzip", 'z', POPT_ARG_NONE, 0, OPT_GZIP},
+ {"bzip2", 'i', POPT_ARG_NONE, 0, OPT_BZIP2},
+ {"force", 'f', POPT_ARG_NONE, &file_force},
+ {"paranoia", 0, POPT_ARG_NONE, &rs_roll_paranoia},
+ {0}
};
-
static void rdiff_usage(const char *error)
{
- fprintf(stderr, "%s\n"
- "Try `%s --help' for more information.\n",
- error, PROGRAM);
+ fprintf(stderr, "%s\n" "Try `%s --help' for more information.\n", error,
+ PROGRAM);
}
-
static void rdiff_no_more_args(poptContext opcon)
{
if (poptGetArg(opcon)) {
@@ -123,20 +116,18 @@ static void rdiff_no_more_args(poptContext opcon)
}
}
-
static void bad_option(poptContext opcon, int error)
{
- fprintf(stderr, "%s: %s: %s",
- PROGRAM, poptStrerror(error), poptBadOption(opcon, 0));
+ fprintf(stderr, "%s: %s: %s", PROGRAM, poptStrerror(error),
+ poptBadOption(opcon, 0));
exit(RS_SYNTAX_ERROR);
}
-
-static void help(void) {
+static void help(void)
+{
printf("Usage: rdiff [OPTIONS] signature [BASIS [SIGNATURE]]\n"
" [OPTIONS] delta SIGNATURE [NEWFILE [DELTA]]\n"
- " [OPTIONS] patch BASIS [DELTA [NEWFILE]]\n"
- "\n"
+ " [OPTIONS] patch BASIS [DELTA [NEWFILE]]\n" "\n"
"Options:\n"
" -v, --verbose Trace internal processing\n"
" -V, --version Show program version\n"
@@ -149,28 +140,25 @@ static void help(void) {
" -b, --block-size=BYTES Signature block size\n"
" -S, --sum-size=BYTES Set signature strength\n"
" --paranoia Verify all rolling checksums\n"
- "IO options:\n"
- " -I, --input-size=BYTES Input buffer size\n"
+ "IO options:\n" " -I, --input-size=BYTES Input buffer size\n"
" -O, --output-size=BYTES Output buffer size\n"
" -z, --gzip[=LEVEL] gzip-compress deltas\n"
- " -i, --bzip2[=LEVEL] bzip2-compress deltas\n"
- );
+ " -i, --bzip2[=LEVEL] bzip2-compress deltas\n");
}
-
static void rdiff_show_version(void)
{
char const *bzlib = "", *zlib = "", *trace = "";
#if 0
/* Compression isn't implemented so don't mention it. */
-#ifdef HAVE_LIBZ
+# ifdef HAVE_LIBZ
zlib = ", gzip";
-#endif
+# endif
-#ifdef HAVE_LIBBZ2
+# ifdef HAVE_LIBBZ2
bzlib = ", bzip2";
-#endif
+# endif
#endif
#ifndef DO_RS_TRACE
@@ -180,22 +168,18 @@ static void rdiff_show_version(void)
printf("rdiff (%s)\n"
"Copyright (C) 1997-2016 by Martin Pool, Andrew Tridgell and others.\n"
"http://librsync.sourcefrog.net/\n"
- "Capabilities: %ld bit files%s%s%s\n"
- "\n"
+ "Capabilities: %ld bit files%s%s%s\n" "\n"
"librsync comes with NO WARRANTY, to the extent permitted by law.\n"
"You may redistribute copies of librsync under the terms of the GNU\n"
"Lesser General Public License. For more information about these\n"
- "matters, see the files named COPYING.\n",
- rs_librsync_version,
- (long) (8 * sizeof(rs_long_t)), zlib, bzlib, trace);
+ "matters, see the files named COPYING.\n", rs_librsync_version,
+ (long)(8 * sizeof(rs_long_t)), zlib, bzlib, trace);
}
-
-
static void rdiff_options(poptContext opcon)
{
- int c;
- char const *a;
+ int c;
+ char const *a;
while ((c = poptGetNextOpt(opcon)) != -1) {
switch (c) {
@@ -222,9 +206,9 @@ static void rdiff_options(poptContext opcon)
bzip2_level = l;
} else {
if (c == OPT_GZIP)
- gzip_level = -1; /* library default */
+ gzip_level = -1; /* library default */
else
- bzip2_level = 9; /* demand the best */
+ bzip2_level = 9; /* demand the best */
}
rs_error("sorry, compression is not really implemented yet");
exit(RS_UNIMPLEMENTED);
@@ -235,16 +219,13 @@ static void rdiff_options(poptContext opcon)
}
}
-
-/**
- * Generate signature from remaining command line arguments.
- */
+/** Generate signature from remaining command line arguments. */
static rs_result rdiff_sig(poptContext opcon)
{
- FILE *basis_file, *sig_file;
- rs_stats_t stats;
- rs_result result;
- rs_long_t sig_magic;
+ FILE *basis_file, *sig_file;
+ rs_stats_t stats;
+ rs_result result;
+ rs_long_t sig_magic;
basis_file = rs_file_open(poptGetArg(opcon), "rb", file_force);
sig_file = rs_file_open(poptGetArg(opcon), "wb", file_force);
@@ -260,8 +241,9 @@ static rs_result rdiff_sig(poptContext opcon)
return RS_PARAM_ERROR;
}
- result = rs_sig_file(basis_file, sig_file, block_len, strong_len,
- sig_magic, &stats);
+ result =
+ rs_sig_file(basis_file, sig_file, block_len, strong_len, sig_magic,
+ &stats);
rs_file_close(sig_file);
rs_file_close(basis_file);
@@ -274,14 +256,13 @@ static rs_result rdiff_sig(poptContext opcon)
return result;
}
-
static rs_result rdiff_delta(poptContext opcon)
{
- FILE *sig_file, *new_file, *delta_file;
- char const *sig_name;
- rs_result result;
- rs_signature_t *sumset;
- rs_stats_t stats;
+ FILE *sig_file, *new_file, *delta_file;
+ char const *sig_name;
+ rs_result result;
+ rs_signature_t *sumset;
+ rs_stats_t stats;
if (!(sig_name = poptGetArg(opcon))) {
rdiff_usage("Usage for delta: "
@@ -321,15 +302,13 @@ static rs_result rdiff_delta(poptContext opcon)
return result;
}
-
-
static rs_result rdiff_patch(poptContext opcon)
{
- /* patch BASIS [DELTA [NEWFILE]] */
- FILE *basis_file, *delta_file, *new_file;
- char const *basis_name;
- rs_stats_t stats;
- rs_result result;
+ /* patch BASIS [DELTA [NEWFILE]] */
+ FILE *basis_file, *delta_file, *new_file;
+ char const *basis_name;
+ rs_stats_t stats;
+ rs_result result;
if (!(basis_name = poptGetArg(opcon))) {
rdiff_usage("Usage for patch: "
@@ -339,7 +318,7 @@ static rs_result rdiff_patch(poptContext opcon)
basis_file = rs_file_open(basis_name, "rb", file_force);
delta_file = rs_file_open(poptGetArg(opcon), "rb", file_force);
- new_file = rs_file_open(poptGetArg(opcon), "wb", file_force);
+ new_file = rs_file_open(poptGetArg(opcon), "wb", file_force);
rdiff_no_more_args(opcon);
@@ -355,15 +334,12 @@ static rs_result rdiff_patch(poptContext opcon)
return result;
}
-
-
static rs_result rdiff_action(poptContext opcon)
{
- const char *action;
+ const char *action;
action = poptGetArg(opcon);
- if (!action)
- ;
+ if (!action) ;
else if (isprefix(action, "signature"))
return rdiff_sig(opcon);
else if (isprefix(action, "delta"))
@@ -371,26 +347,23 @@ static rs_result rdiff_action(poptContext opcon)
else if (isprefix(action, "patch"))
return rdiff_patch(opcon);
- rdiff_usage("rdiff: You must specify an action: `signature', `delta', or `patch'.");
+ rdiff_usage
+ ("rdiff: You must specify an action: `signature', `delta', or `patch'.");
return RS_SYNTAX_ERROR;
}
-
int main(const int argc, const char *argv[])
{
- poptContext opcon;
- rs_result result;
+ poptContext opcon;
+ rs_result result;
opcon = poptGetContext(PROGRAM, argc, argv, opts, 0);
rdiff_options(opcon);
result = rdiff_action(opcon);
if (result != RS_DONE)
- rs_log(RS_LOG_ERR|RS_LOG_NONAME, "%s", rs_strerror(result));
+ rs_log(RS_LOG_ERR | RS_LOG_NONAME, "%s", rs_strerror(result));
poptFreeContext(opcon);
return result;
}
-
-/* vim: et sw=4
- */
diff --git a/src/readsums.c b/src/readsums.c
index a7c72ff..7326714 100644
--- a/src/readsums.c
+++ b/src/readsums.c
@@ -1,4 +1,4 @@
-/*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*-
+/*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*-
*
* librsync -- the library for network deltas
*
@@ -20,11 +20,7 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-
-/**
- * \file readsums.c
- * \brief Load signatures from a file.
- */
+/** \file readsums.c Load signatures from a file. */
#include "config.h"
@@ -41,32 +37,29 @@
#include "util.h"
#include "stream.h"
-
static rs_result rs_loadsig_s_weak(rs_job_t *job);
static rs_result rs_loadsig_s_strong(rs_job_t *job);
-/**
- * Add a just-read-in checksum pair to the signature block.
- */
+/** Add a just-read-in checksum pair to the signature block. */
static rs_result rs_loadsig_add_sum(rs_job_t *job, rs_strong_sum_t *strong)
{
- rs_signature_t *sig = job->signature;
+ rs_signature_t *sig = job->signature;
if (rs_trace_enabled()) {
char hexbuf[RS_MAX_STRONG_SUM_LENGTH * 2 + 2];
rs_hexify(hexbuf, strong, sig->strong_sum_len);
- rs_trace("got block: weak="FMT_WEAKSUM", strong=%s", job->weak_sig, hexbuf);
+ rs_trace("got block: weak=" FMT_WEAKSUM ", strong=%s", job->weak_sig,
+ hexbuf);
}
rs_signature_add_block(job->signature, job->weak_sig, strong);
job->stats.sig_blocks++;
return RS_RUNNING;
}
-
static rs_result rs_loadsig_s_weak(rs_job_t *job)
{
- int l;
- rs_result result;
+ int l;
+ rs_result result;
if ((result = rs_suck_n4(job, &l)) != RS_DONE) {
if (result == RS_INPUT_ENDED) /* ending here is OK */
@@ -78,47 +71,45 @@ static rs_result rs_loadsig_s_weak(rs_job_t *job)
return RS_RUNNING;
}
-
static rs_result rs_loadsig_s_strong(rs_job_t *job)
{
- rs_result result;
- rs_strong_sum_t *strongsum;
+ rs_result result;
+ rs_strong_sum_t *strongsum;
- if ((result = rs_scoop_read(job, job->signature->strong_sum_len, (void **)&strongsum)) != RS_DONE)
+ if ((result =
+ rs_scoop_read(job, job->signature->strong_sum_len,
+ (void **)&strongsum)) != RS_DONE)
return result;
job->statefn = rs_loadsig_s_weak;
return rs_loadsig_add_sum(job, strongsum);
}
-
-
static rs_result rs_loadsig_s_stronglen(rs_job_t *job)
{
- int l;
- rs_result result;
+ int l;
+ rs_result result;
if ((result = rs_suck_n4(job, &l)) != RS_DONE)
return result;
- if (l < 0 || l > RS_MAX_STRONG_SUM_LENGTH) {
+ if (l < 0 || l > RS_MAX_STRONG_SUM_LENGTH) {
rs_error("strong sum length %d is implausible", l);
return RS_CORRUPT;
}
rs_trace("got strong sum length %d", l);
job->sig_strong_len = l;
/* Initialize the signature. */
- if ((result = rs_signature_init(job->signature, job->sig_magic,
- job->sig_block_len, job->sig_strong_len,
- job->sig_fsize)) != RS_DONE)
+ if ((result =
+ rs_signature_init(job->signature, job->sig_magic, job->sig_block_len,
+ job->sig_strong_len, job->sig_fsize)) != RS_DONE)
return result;
job->statefn = rs_loadsig_s_weak;
return RS_RUNNING;
}
-
static rs_result rs_loadsig_s_blocklen(rs_job_t *job)
{
- int l;
- rs_result result;
+ int l;
+ rs_result result;
if ((result = rs_suck_n4(job, &l)) != RS_DONE)
return result;
@@ -133,11 +124,10 @@ static rs_result rs_loadsig_s_blocklen(rs_job_t *job)
return RS_RUNNING;
}
-
static rs_result rs_loadsig_s_magic(rs_job_t *job)
{
- int l;
- rs_result result;
+ int l;
+ rs_result result;
if ((result = rs_suck_n4(job, &l)) != RS_DONE)
return result;
@@ -147,7 +137,6 @@ static rs_result rs_loadsig_s_magic(rs_job_t *job)
return RS_RUNNING;
}
-
rs_job_t *rs_loadsig_begin(rs_signature_t **signature)
{
rs_job_t *job;
diff --git a/src/rollsum.h b/src/rollsum.h
index c63adeb..218e7a8 100644
--- a/src/rollsum.h
+++ b/src/rollsum.h
@@ -20,18 +20,16 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef _ROLLSUM_H_
-#define _ROLLSUM_H_
+# define _ROLLSUM_H_
-#include <stddef.h>
-#include <stdint.h>
+# include <stddef.h>
+# include <stdint.h>
-/* We should make this something other than zero to improve the
- * checksum algorithm: tridge suggests a prime number. */
-#define ROLLSUM_CHAR_OFFSET 31
+/* We should make this something other than zero to improve the checksum
+ algorithm: tridge suggests a prime number. */
+# define ROLLSUM_CHAR_OFFSET 31
-/* the Rollsum struct type*/
-
-/** \private */
+/** The Rollsum struct type \private. */
typedef struct _Rollsum {
size_t count; /* count of bytes included in sum */
uint_fast16_t s1; /* s1 part of sum */
@@ -41,12 +39,14 @@ typedef struct _Rollsum {
void RollsumUpdate(Rollsum *sum, const unsigned char *buf, size_t len);
/* static inline implementations of simple routines */
+
static inline void RollsumInit(Rollsum *sum)
{
sum->count = sum->s1 = sum->s2 = 0;
}
-static inline void RollsumRotate(Rollsum *sum, unsigned char out, unsigned char in)
+static inline void RollsumRotate(Rollsum *sum, unsigned char out,
+ unsigned char in)
{
sum->s1 += in - out;
sum->s2 += sum->s1 - sum->count * (out + ROLLSUM_CHAR_OFFSET);
diff --git a/src/scoop.c b/src/scoop.c
index 064958b..61bd7b7 100644
--- a/src/scoop.c
+++ b/src/scoop.c
@@ -1,4 +1,4 @@
-/*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*-
+/*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*-
*
* librsync -- the library for network deltas
*
@@ -19,44 +19,38 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-/*
- * scoop.c -- This file deals with readahead from caller-supplied
- * buffers.
+ /*=
+ | To walk on water you've gotta sink
+ | in the ice.
+ | -- Shihad, `The General Electric'.
+ */
+
+/** \file scoop.c This file deals with readahead from caller-supplied buffers.
*
* Many functions require a certain minimum amount of input to do their
- * processing. For example, to calculate a strong checksum of a block
- * we need at least a block of input.
+ * processing. For example, to calculate a strong checksum of a block we need
+ * at least a block of input.
*
- * Since we put the buffers completely under the control of the caller,
- * we can't count on ever getting this much data all in one go. We
- * can't simply wait, because the caller might have a smaller buffer
- * than we require and so we'll never get it. For the same reason we
- * must always accept all the data we're given.
+ * Since we put the buffers completely under the control of the caller, we
+ * can't count on ever getting this much data all in one go. We can't simply
+ * wait, because the caller might have a smaller buffer than we require and so
+ * we'll never get it. For the same reason we must always accept all the data
+ * we're given.
*
- * So, stream input data that's required for readahead is put into a
- * special buffer, from which the caller can then read. It's
- * essentially like an internal pipe, which on any given read request
- * may or may not be able to actually supply the data.
+ * So, stream input data that's required for readahead is put into a special
+ * buffer, from which the caller can then read. It's essentially like an
+ * internal pipe, which on any given read request may or may not be able to
+ * actually supply the data.
*
- * As a future optimization, we might try to take data directly from the
- * input buffer if there's already enough there.
- */
-
-/*
- * TODO: We probably know a maximum amount of data that can be scooped
- * up, so we could just avoid dynamic allocation. However that can't
- * be fixed at compile time, because when generating a delta it needs
- * to be large enough to hold one full block. Perhaps we can set it
- * up when the job is allocated? It would be kind of nice to not do
- * any memory allocation after startup, as bzlib does this.
- */
-
-
- /*
- | To walk on water you've gotta sink
- | in the ice.
- | -- Shihad, `The General Electric'.
- */
+ * As a future optimization, we might try to take data directly from the input
+ * buffer if there's already enough there.
+ *
+ * \todo We probably know a maximum amount of data that can be scooped up, so
+ * we could just avoid dynamic allocation. However that can't be fixed at
+ * compile time, because when generating a delta it needs to be large enough to
+ * hold one full block. Perhaps we can set it up when the job is allocated? It
+ * would be kind of nice to not do any memory allocation after startup, as
+ * bzlib does this. */
#include "config.h"
@@ -71,10 +65,7 @@
#include "trace.h"
#include "util.h"
-
-/**
- * Try to accept a from the input buffer to get LEN bytes in the scoop.
- */
+/** Try to accept a from the input buffer to get LEN bytes in the scoop. */
void rs_scoop_input(rs_job_t *job, size_t len)
{
rs_buffers_t *stream = job->stream;
@@ -83,145 +74,119 @@ void rs_scoop_input(rs_job_t *job, size_t len)
assert(len > job->scoop_avail);
if (job->scoop_alloc < len) {
- /* need to allocate a new buffer, too */
+ /* Need to allocate a larger scoop. */
rs_byte_t *newbuf;
- size_t newsize = 2 * len;
+ size_t newsize;
+ for (newsize = 64; newsize < len; newsize <<= 1) ;
newbuf = rs_alloc(newsize, "scoop buffer");
if (job->scoop_avail)
memcpy(newbuf, job->scoop_next, job->scoop_avail);
if (job->scoop_buf)
free(job->scoop_buf);
job->scoop_buf = job->scoop_next = newbuf;
- rs_trace("resized scoop buffer to "FMT_SIZE" bytes from "FMT_SIZE"", newsize, job->scoop_alloc);
+ rs_trace("resized scoop buffer to " FMT_SIZE " bytes from " FMT_SIZE "",
+ newsize, job->scoop_alloc);
job->scoop_alloc = newsize;
- } else {
- /* this buffer size is fine, but move the existing
- * data down to the front. */
+ } else if (job->scoop_buf != job->scoop_next) {
+ /* Move existing data to the front of the scoop. */
+ rs_trace("moving scoop " FMT_SIZE " bytes to reuse " FMT_SIZE " bytes",
+ job->scoop_avail, (size_t)(job->scoop_next - job->scoop_buf));
memmove(job->scoop_buf, job->scoop_next, job->scoop_avail);
job->scoop_next = job->scoop_buf;
}
-
- /* take as much input as is available, to give up to LEN bytes
- * in the scoop. */
+ /* take as much input as is available, to give up to LEN bytes in the
+ scoop. */
tocopy = len - job->scoop_avail;
if (tocopy > stream->avail_in)
tocopy = stream->avail_in;
assert(tocopy + job->scoop_avail <= job->scoop_alloc);
memcpy(job->scoop_next + job->scoop_avail, stream->next_in, tocopy);
- rs_trace("accepted "FMT_SIZE" bytes from input to scoop", tocopy);
+ rs_trace("accepted " FMT_SIZE " bytes from input to scoop", tocopy);
job->scoop_avail += tocopy;
stream->next_in += tocopy;
stream->avail_in -= tocopy;
}
-
-/**
- * Advance the input cursor forward \p len bytes. This is used after
- * doing readahead, when you decide you want to keep it. \p len must
- * be no more than the amount of available data, so you can't cheat.
+/** Advance the input cursor forward \p len bytes.
*
- * So when creating a delta, we require one block of readahead. But
- * after examining that block, we might decide to advance over all of
- * it (if there is a match), or just one byte (if not).
- */
+ * This is used after doing readahead, when you decide you want to keep it. \p
+ * len must be no more than the amount of available data, so you can't cheat.
+ *
+ * So when creating a delta, we require one block of readahead. But after
+ * examining that block, we might decide to advance over all of it (if there is
+ * a match), or just one byte (if not). */
void rs_scoop_advance(rs_job_t *job, size_t len)
{
rs_buffers_t *stream = job->stream;
- /* It never makes sense to advance over a mixture of bytes from
- * the scoop and input, because you couldn't possibly have looked
- * at them all at the same time. */
+ /* It never makes sense to advance over a mixture of bytes from the scoop
+ and input, because you couldn't possibly have looked at them all at the
+ same time. */
if (job->scoop_avail) {
/* reading from the scoop buffer */
- rs_trace("advance over "FMT_SIZE" bytes from scoop", len);
+ rs_trace("advance over " FMT_SIZE " bytes from scoop", len);
assert(len <= job->scoop_avail);
job->scoop_avail -= len;
job->scoop_next += len;
} else {
- rs_trace("advance over "FMT_SIZE" bytes from input buffer", len);
+ rs_trace("advance over " FMT_SIZE " bytes from input buffer", len);
assert(len <= stream->avail_in);
stream->avail_in -= len;
stream->next_in += len;
}
}
-
-
-/**
- * \brief Read from scoop without advancing.
+/** Read from scoop without advancing.
*
- * Ask for LEN bytes of input from the stream. If that much data is
- * available, then return a pointer to it in PTR, advance the stream
- * input pointer over the data, and return RS_DONE. If there's not
- * enough data, then accept whatever is there into a buffer, advance
- * over it, and return RS_BLOCKED.
+ * Ask for LEN bytes of input from the stream. If that much data is available,
+ * then return a pointer to it in PTR, advance the stream input pointer over
+ * the data, and return RS_DONE. If there's not enough data, then accept
+ * whatever is there into a buffer, advance over it, and return RS_BLOCKED.
*
- * The data is not actually removed from the input, so this function
- * lets you do readahead. If you want to keep any of the data, you
- * should also call rs_scoop_advance() to skip over it.
- */
+ * The data is not actually removed from the input, so this function lets you
+ * do readahead. If you want to keep any of the data, you should also call
+ * rs_scoop_advance() to skip over it. */
rs_result rs_scoop_readahead(rs_job_t *job, size_t len, void **ptr)
{
rs_buffers_t *stream = job->stream;
rs_job_check(job);
- if (job->scoop_avail >= len) {
- /* We have enough data queued to satisfy the request,
- * so go straight from the scoop buffer. */
- rs_trace("got "FMT_SIZE" bytes direct from scoop", len);
- *ptr = job->scoop_next;
- return RS_DONE;
- } else if (job->scoop_avail) {
- /* We have some data in the scoop, but not enough to
- * satisfy the request. */
- rs_trace("data is present in the scoop and must be used");
- rs_scoop_input(job, len);
-
- if (job->scoop_avail < len) {
- rs_trace("still have only "FMT_SIZE" bytes in scoop", job->scoop_avail);
- return RS_BLOCKED;
- } else {
- rs_trace("scoop now has "FMT_SIZE" bytes, this is enough", job->scoop_avail);
- *ptr = job->scoop_next;
- return RS_DONE;
- }
- } else if (stream->avail_in >= len) {
- /* There's enough data in the stream's input */
+ if (!job->scoop_avail && stream->avail_in >= len) {
+ /* The scoop is empty and there's enough data in the input. */
*ptr = stream->next_in;
- rs_trace("got "FMT_SIZE" bytes from input buffer", len);
+ rs_trace("got " FMT_SIZE " bytes direct from input", len);
return RS_DONE;
- } else if (stream->avail_in > 0) {
- /* Nothing was queued before, but we don't have enough
- * data to satisfy the request. So queue what little
- * we have, and try again next time. */
- rs_trace("couldn't satisfy request for "FMT_SIZE", scooping "FMT_SIZE" bytes", len, job->scoop_avail);
+ } else if (job->scoop_avail < len && stream->avail_in) {
+ /* There is not enough data in the scoop. */
+ rs_trace("scoop has less than " FMT_SIZE " bytes, scooping from "
+ FMT_SIZE " input bytes", len, stream->avail_in);
rs_scoop_input(job, len);
- return RS_BLOCKED;
+ }
+ if (job->scoop_avail >= len) {
+ /* There is enough data in the scoop now. */
+ rs_trace("scoop has at least " FMT_SIZE " bytes, this is enough",
+ job->scoop_avail);
+ *ptr = job->scoop_next;
+ return RS_DONE;
} else if (stream->eof_in) {
- /* Nothing is queued before, and nothing is in the input
- * buffer at the moment. */
+ /* Not enough input data and at EOF. */
rs_trace("reached end of input stream");
return RS_INPUT_ENDED;
} else {
- /* Nothing queued at the moment. */
- rs_trace("blocked with no data in scoop or input buffer");
+ /* Not enough input data yet. */
+ rs_trace("blocked with insufficient input data");
return RS_BLOCKED;
}
}
-
-
-/**
- * Read LEN bytes if possible, and remove them from the input scoop.
- * If there's not enough data yet, return RS_BLOCKED.
+/** Read LEN bytes if possible, and remove them from the input scoop.
*
- * \param ptr will be updated to point to a read-only buffer holding
- * the data, if enough is available.
+ * \param ptr will be updated to point to a read-only buffer holding the data,
+ * if enough is available.
*
- * \return RS_DONE if all the data was available, RS_BLOCKED if it's
- * not there.
- */
+ * \return RS_DONE if there was enough data, RS_BLOCKED if there was not enough
+ * data yet, or RS_INPUT_ENDED if there was not enough data and at EOF. */
rs_result rs_scoop_read(rs_job_t *job, size_t len, void **ptr)
{
rs_result result;
@@ -229,31 +194,32 @@ rs_result rs_scoop_read(rs_job_t *job, size_t len, void **ptr)
result = rs_scoop_readahead(job, len, ptr);
if (result == RS_DONE)
rs_scoop_advance(job, len);
-
return result;
}
-
-
-/*
- * Read whatever remains in the input stream, assuming that it runs up
- * to the end of the file. Set LEN appropriately.
- */
+/** Read whatever data remains in the input stream.
+ *
+ * \param *len will be updated to the length of the available data.
+ *
+ * \param **ptr will point at the available data.
+ *
+ * \return RS_DONE if there was data, RS_INPUT_ENDED if there was no data and
+ * at EOF, RS_BLOCKED if there was no data and not at EOF. */
rs_result rs_scoop_read_rest(rs_job_t *job, size_t *len, void **ptr)
{
rs_buffers_t *stream = job->stream;
*len = job->scoop_avail + stream->avail_in;
-
- return rs_scoop_read(job, *len, ptr);
+ if (*len)
+ return rs_scoop_read(job, *len, ptr);
+ else if (stream->eof_in)
+ return RS_INPUT_ENDED;
+ else
+ return RS_BLOCKED;
}
-
-
-/**
- * Return the total number of bytes available including the scoop and input
- * buffer.
- */
+/** Return the total number of bytes available including the scoop and input
+ * buffer. */
size_t rs_scoop_total_avail(rs_job_t *job)
{
return job->scoop_avail + job->stream->avail_in;
diff --git a/src/stats.c b/src/stats.c
index 9943a56..ee75153 100644
--- a/src/stats.c
+++ b/src/stats.c
@@ -17,47 +17,36 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
+/** \file stats.c stats reporting functions.
+ *
+ * \todo Other things to show in statistics: number of input and output bytes,
+ * number of times we blocked waiting for input or output, number of blocks. */
#include "config.h"
#include <stdlib.h>
#include <stdio.h>
#ifdef HAVE_UNISTD_H
-#include <unistd.h>
+# include <unistd.h>
#endif
#ifdef HAVE_SYS_FILE_H
-#include <sys/file.h>
+# include <sys/file.h>
#endif
#include <string.h>
#include "librsync.h"
#include "trace.h"
-/*
- * TODO: Other things to show in statistics:
- *
- * Number of input and output bytes.
- *
- * Number of times we blocked waiting for input or output.
- *
- * Number of blocks.
- */
-
-int
-rs_log_stats(rs_stats_t const *stats)
+int rs_log_stats(rs_stats_t const *stats)
{
char buf[1000];
rs_format_stats(stats, buf, sizeof buf - 1);
- rs_log(RS_LOG_INFO|RS_LOG_NONAME, "%s", buf);
+ rs_log(RS_LOG_INFO | RS_LOG_NONAME, "%s", buf);
return 0;
}
-
-
-char *
-rs_format_stats(rs_stats_t const * stats,
- char *buf, size_t size)
+char *rs_format_stats(rs_stats_t const *stats, char *buf, size_t size)
{
char const *op = stats->op;
int len, sec;
@@ -69,38 +58,46 @@ rs_format_stats(rs_stats_t const * stats,
len = snprintf(buf, size, "%s statistics: ", op);
if (stats->lit_cmds) {
- len += snprintf(buf+len, size-len,
- "literal[%d cmds, "FMT_LONG" bytes, "FMT_LONG" cmdbytes] ",
- stats->lit_cmds, stats->lit_bytes, stats->lit_cmdbytes);
+ len +=
+ snprintf(buf + len, size - len,
+ "literal[%d cmds, " FMT_LONG " bytes, " FMT_LONG
+ " cmdbytes] ", stats->lit_cmds, stats->lit_bytes,
+ stats->lit_cmdbytes);
}
if (stats->sig_cmds) {
- len += snprintf(buf+len, size-len,
- "in-place-signature["FMT_LONG" cmds, "FMT_LONG" bytes] ",
- stats->sig_cmds, stats->sig_bytes);
+ len +=
+ snprintf(buf + len, size - len,
+ "in-place-signature[" FMT_LONG " cmds, " FMT_LONG
+ " bytes] ", stats->sig_cmds, stats->sig_bytes);
}
if (stats->copy_cmds || stats->false_matches) {
- len += snprintf(buf+len, size-len,
- "copy["FMT_LONG" cmds, "FMT_LONG" bytes, "FMT_LONG" cmdbytes, %d false]",
- stats->copy_cmds, stats->copy_bytes, stats->copy_cmdbytes, stats->false_matches);
+ len +=
+ snprintf(buf + len, size - len,
+ "copy[" FMT_LONG " cmds, " FMT_LONG " bytes, " FMT_LONG
+ " cmdbytes, %d false]", stats->copy_cmds,
+ stats->copy_bytes, stats->copy_cmdbytes,
+ stats->false_matches);
}
-
if (stats->sig_blocks) {
- len += snprintf(buf+len, size-len,
- "signature["FMT_LONG" blocks, "FMT_SIZE" bytes per block]",
- stats->sig_blocks, stats->block_len);
+ len +=
+ snprintf(buf + len, size - len,
+ "signature[" FMT_LONG " blocks, " FMT_SIZE
+ " bytes per block]", stats->sig_blocks, stats->block_len);
}
sec = (stats->end - stats->start);
- if (sec == 0) sec = 1; // avoid division by zero
+ if (sec == 0)
+ sec = 1; // avoid division by zero
mbps_in = stats->in_bytes / 1e6 / sec;
mbps_out = stats->out_bytes / 1e6 / sec;
- len += snprintf(buf+len, size-len,
- " speed[%.1f MB (%.1f MB/s) in, %.1f MB (%.1f MB/s) out, %d sec]",
- (stats->in_bytes/1e6), mbps_in,
- (stats->out_bytes/1e6), mbps_out, sec);
+ len +=
+ snprintf(buf + len, size - len,
+ " speed[%.1f MB (%.1f MB/s) in, %.1f MB (%.1f MB/s) out, %d sec]",
+ (stats->in_bytes / 1e6), mbps_in, (stats->out_bytes / 1e6),
+ mbps_out, sec);
return buf;
}
diff --git a/src/stream.c b/src/stream.c
index 227ea5d..293b6c1 100644
--- a/src/stream.c
+++ b/src/stream.c
@@ -19,69 +19,62 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
- /*
- * Programming languages should be designed not
- * by piling feature on top of feature, but by
- * removing the weaknesses and restrictions that
- * make additional features appear necessary.
- * -- Revised^5 Report on Scheme
+ /*=
+ | Programming languages should be designed not
+ | by piling feature on top of feature, but by
+ | removing the weaknesses and restrictions that
+ | make additional features appear necessary.
+ | -- Revised^5 Report on Scheme
*/
-
-/*
- * OK, so I'll admit IO here is a little complex. The most important
- * player here is the stream, which is an object for managing filter
- * operations. It has both input and output sides, both of which is
- * just a (pointer,len) pair into a buffer provided by the client.
- * The code controlling the stream handles however much data it wants,
- * and the client provides or accepts however much is convenient.
- *
- * At the same time as being friendly to the client, we also try to be
- * very friendly to the internal code. It wants to be able to ask for
- * arbitrary amounts of input or output and get it without having to
- * keep track of partial completion. So there are functions which
- * either complete, or queue whatever was not sent and return
- * RS_BLOCKED.
- *
- * The output buffer is a little more clever than simply a data
- * buffer. Instead it knows that we can send either literal data, or
- * data copied through from the input of the stream.
- *
- * In buf.c you will find functions that then map buffers onto stdio
- * files.
- *
- * So on return from an encoding function, either the input or the
- * output or possibly both will have no more bytes available.
- */
-
-/*
- * Manage librsync streams of IO. See scoop.c and tube.c for related
- * code for input and output respectively.
- *
- * librsync never does IO or memory allocation, but relies on the
- * caller. This is very nice for integration, but means that we have
- * to be fairly flexible as to when we can `read' or `write' stuff
- * internally.
- *
- * librsync basically does two types of IO. It reads network integers
- * of various lengths which encode command and control information
- * such as versions and signatures. It also does bulk data transfer.
- *
- * IO of network integers is internally buffered, because higher
- * levels of the code need to see them transmitted atomically: it's no
- * good to read half of a uint32. So there is a small and fixed
- * length internal buffer which accumulates these. Unlike previous
- * versions of the library, we don't require that the caller hold the
- * start until the whole thing has arrived, which guarantees that we
- * can always make progress.
- *
- * On each call into a stream iterator, it should begin by trying to
- * flush output. This may well use up all the remaining stream space,
- * in which case nothing else can be done.
- */
-
-/* TODO: Return errors rather than aborting if something goes wrong. */
-
+/** \file stream.c Manage librsync streams of IO.
+ *
+ * See \sa scoop.c and \sa tube.c for related code for input and output
+ * respectively.
+ *
+ * OK, so I'll admit IO here is a little complex. The most important player
+ * here is the stream, which is an object for managing filter operations. It
+ * has both input and output sides, both of which is just a (pointer,len) pair
+ * into a buffer provided by the client. The code controlling the stream
+ * handles however much data it wants, and the client provides or accepts
+ * however much is convenient.
+ *
+ * At the same time as being friendly to the client, we also try to be very
+ * friendly to the internal code. It wants to be able to ask for arbitrary
+ * amounts of input or output and get it without having to keep track of
+ * partial completion. So there are functions which either complete, or queue
+ * whatever was not sent and return RS_BLOCKED.
+ *
+ * The output buffer is a little more clever than simply a data buffer.
+ * Instead it knows that we can send either literal data, or data copied
+ * through from the input of the stream.
+ *
+ * In buf.c you will find functions that then map buffers onto stdio files.
+ *
+ * So on return from an encoding function, either the input or the output or
+ * possibly both will have no more bytes available.
+ *
+ * librsync never does IO or memory allocation, but relies on the caller. This
+ * is very nice for integration, but means that we have to be fairly flexible
+ * as to when we can `read' or `write' stuff internally.
+ *
+ * librsync basically does two types of IO. It reads network integers of
+ * various lengths which encode command and control information such as
+ * versions and signatures. It also does bulk data transfer.
+ *
+ * IO of network integers is internally buffered, because higher levels of the
+ * code need to see them transmitted atomically: it's no good to read half of a
+ * uint32. So there is a small and fixed length internal buffer which
+ * accumulates these. Unlike previous versions of the library, we don't
+ * require that the caller hold the start until the whole thing has arrived,
+ * which guarantees that we can always make progress.
+ *
+ * On each call into a stream iterator, it should begin by trying to flush
+ * output. This may well use up all the remaining stream space, in which case
+ * nothing else can be done.
+ *
+ * \todo Kill this file and move the vestigial code remaining closer to where
+ * it's used. */
#include "config.h"
@@ -95,37 +88,35 @@
#include "util.h"
#include "trace.h"
-
-/**
- * \brief Copy up to \p max_len bytes from input of \b stream to its output.
+/** Copy up to \p max_len bytes from input of \b stream to its output.
*
- * Return the number of bytes actually copied, which may be less than
- * LEN if there is not enough space in one or the other stream.
+ * \return the number of bytes actually copied, which may be less than LEN if
+ * there is not enough space in one or the other stream.
*
* This always does the copy immediately. Most functions should call
- * rs_tube_copy() to cause the copy to happen gradually as space
- * becomes available.
- */
+ * rs_tube_copy() to cause the copy to happen gradually as space becomes
+ * available. */
int rs_buffers_copy(rs_buffers_t *stream, int max_len)
{
int len = max_len;
assert(len > 0);
- if ((unsigned) len > stream->avail_in) {
- rs_trace("copy limited to "FMT_SIZE" available input bytes", stream->avail_in);
+ if ((unsigned)len > stream->avail_in) {
+ rs_trace("copy limited to " FMT_SIZE " available input bytes",
+ stream->avail_in);
len = stream->avail_in;
}
-
- if ((unsigned) len > stream->avail_out) {
- rs_trace("copy limited to "FMT_SIZE" available output bytes", stream->avail_out);
+ if ((unsigned)len > stream->avail_out) {
+ rs_trace("copy limited to " FMT_SIZE " available output bytes",
+ stream->avail_out);
len = stream->avail_out;
}
if (!len)
return 0;
-/* rs_trace("stream copied chunk of %d bytes", len); */
+ /* rs_trace("stream copied chunk of %d bytes", len); */
memcpy(stream->next_out, stream->next_in, len);
@@ -138,13 +129,12 @@ int rs_buffers_copy(rs_buffers_t *stream, int max_len)
return len;
}
-
-/**
- * Whenever a stream processing function exits, it should have done so
- * because it has either consumed all the input or has filled the
- * output buffer. This function checks that simple postcondition.
- */
+/** Assert input is empty or output is full.
+ *
+ * Whenever a stream processing function exits, it should have done so because
+ * it has either consumed all the input or has filled the output buffer. This
+ * function checks that simple postcondition. */
void rs_buffers_check_exit(rs_buffers_t const *stream)
{
- assert(stream->avail_in == 0 || stream->avail_out == 0);
+ assert(stream->avail_in == 0 || stream->avail_out == 0);
}
diff --git a/src/stream.h b/src/stream.h
index fb1f768..b52ac48 100644
--- a/src/stream.h
+++ b/src/stream.h
@@ -1,30 +1,31 @@
/*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*-
*
* librsync -- library for network deltas
- *
+ *
* Copyright (C) 2000, 2001 by Martin Pool <mbp@sourcefrog.net>
- *
+ *
* 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.
*/
- /* Two wars in a lifetime bear hard on the little places.
- * In winter when storms come rushing out of the dark,
- * And the bay boils like a cauldron of sharks,
- * The old remember the trenches at Paschendale
- * And sons who died on the Burma Railway. */
-
+ /*=
+ | Two wars in a lifetime bear hard on the little places.
+ | In winter when storms come rushing out of the dark,
+ | And the bay boils like a cauldron of sharks,
+ | The old remember the trenches at Paschendale
+ | And sons who died on the Burma Railway.
+ */
int rs_buffers_is_empty(rs_buffers_t *stream);
int rs_buffers_copy(rs_buffers_t *stream, int len);
diff --git a/src/sumset.c b/src/sumset.c
index 2c1c814..c209c8a 100644
--- a/src/sumset.c
+++ b/src/sumset.c
@@ -36,11 +36,12 @@
const int RS_MD4_SUM_LENGTH = 16;
const int RS_BLAKE2_SUM_LENGTH = 32;
-static void rs_block_sig_init(rs_block_sig_t *sig, rs_weak_sum_t weak_sum, rs_strong_sum_t *strong_sum, int strong_len)
+static void rs_block_sig_init(rs_block_sig_t *sig, rs_weak_sum_t weak_sum,
+ rs_strong_sum_t *strong_sum, int strong_len)
{
sig->weak_sum = weak_sum;
if (strong_sum)
- memcpy(sig->strong_sum, strong_sum, strong_len);
+ memcpy(sig->strong_sum, strong_sum, strong_len);
}
static inline unsigned rs_block_sig_hash(const rs_block_sig_t *sig)
@@ -55,26 +56,32 @@ typedef struct rs_block_match {
size_t len;
} rs_block_match_t;
-static void rs_block_match_init(rs_block_match_t *match, rs_signature_t *sig, rs_weak_sum_t weak_sum,
- rs_strong_sum_t *strong_sum, const void *buf, size_t len)
+static void rs_block_match_init(rs_block_match_t *match, rs_signature_t *sig,
+ rs_weak_sum_t weak_sum,
+ rs_strong_sum_t *strong_sum, const void *buf,
+ size_t len)
{
- rs_block_sig_init(&match->block_sig, weak_sum, strong_sum, sig->strong_sum_len);
+ rs_block_sig_init(&match->block_sig, weak_sum, strong_sum,
+ sig->strong_sum_len);
match->signature = sig;
match->buf = buf;
match->len = len;
}
-static inline int rs_block_match_cmp(rs_block_match_t *match, const rs_block_sig_t *block_sig)
+static inline int rs_block_match_cmp(rs_block_match_t *match,
+ const rs_block_sig_t *block_sig)
{
/* If buf is not NULL, the strong sum is yet to be calculated. */
if (match->buf) {
#ifndef HASHTABLE_NSTATS
match->signature->calc_strong_count++;
#endif
- rs_signature_calc_strong_sum(match->signature, match->buf, match->len, &(match->block_sig.strong_sum));
+ rs_signature_calc_strong_sum(match->signature, match->buf, match->len,
+ &(match->block_sig.strong_sum));
match->buf = NULL;
}
- return memcmp(&match->block_sig.strong_sum, &block_sig->strong_sum, match->signature->strong_sum_len);
+ return memcmp(&match->block_sig.strong_sum, &block_sig->strong_sum,
+ match->signature->strong_sum_len);
}
/* Instantiate hashtable for rs_block_sig and rs_block_match. */
@@ -86,19 +93,29 @@ static inline int rs_block_match_cmp(rs_block_match_t *match, const rs_block_sig
/* Get the size of a packed rs_block_sig_t. */
static inline size_t rs_block_sig_size(const rs_signature_t *sig)
{
- return offsetof(rs_block_sig_t, strong_sum) + sig->strong_sum_len;
+ /* Round up to next multiple of sizeof(weak_sum) to align memory correctly.
+ */
+ return offsetof(rs_block_sig_t,
+ strong_sum) + ((sig->strong_sum_len +
+ sizeof(rs_weak_sum_t)-
+ 1) / sizeof(rs_weak_sum_t)) *
+ sizeof(rs_weak_sum_t);
}
/* Get the pointer to the block_sig_t from a block index. */
-static inline rs_block_sig_t *rs_block_sig_ptr(const rs_signature_t *sig, int block_idx)
+static inline rs_block_sig_t *rs_block_sig_ptr(const rs_signature_t *sig,
+ int block_idx)
{
- return (rs_block_sig_t*)((char*)sig->block_sigs + block_idx * rs_block_sig_size(sig));
+ return (rs_block_sig_t *)((char *)sig->block_sigs +
+ block_idx * rs_block_sig_size(sig));
}
/* Get the index of a block from a block_sig_t pointer. */
-static inline int rs_block_sig_idx(const rs_signature_t *sig, rs_block_sig_t *block_sig)
+static inline int rs_block_sig_idx(const rs_signature_t *sig,
+ rs_block_sig_t *block_sig)
{
- return ((char *)block_sig - (char *)sig->block_sigs) / rs_block_sig_size(sig);
+ return ((char *)block_sig -
+ (char *)sig->block_sigs) / rs_block_sig_size(sig);
}
rs_result rs_sig_args(rs_long_t old_fsize, rs_magic_number *magic, size_t *block_len, size_t *strong_len)
@@ -171,10 +188,13 @@ rs_result rs_signature_init(rs_signature_t *sig, rs_magic_number magic, size_t b
sig->strong_sum_len = strong_len;
sig->count = 0;
/* Calculate the number of blocks if we have the signature file size. */
- /* Magic+header is 12 bytes, each block thereafter is 4 bytes weak_sum+strong_sum_len bytes */
+ /* Magic+header is 12 bytes, each block thereafter is 4 bytes
+ weak_sum+strong_sum_len bytes */
sig->size = (int)(sig_fsize ? (sig_fsize - 12) / (4 + strong_len) : 0);
if (sig->size)
- sig->block_sigs = rs_alloc(sig->size * rs_block_sig_size(sig), "signature->block_sigs");
+ sig->block_sigs =
+ rs_alloc(sig->size * rs_block_sig_size(sig),
+ "signature->block_sigs");
else
sig->block_sigs = NULL;
sig->hashtable = NULL;
@@ -191,20 +211,25 @@ void rs_signature_done(rs_signature_t *sig)
rs_bzero(sig, sizeof(*sig));
}
-rs_block_sig_t *rs_signature_add_block(rs_signature_t *sig, rs_weak_sum_t weak_sum, rs_strong_sum_t *strong_sum)
+rs_block_sig_t *rs_signature_add_block(rs_signature_t *sig,
+ rs_weak_sum_t weak_sum,
+ rs_strong_sum_t *strong_sum)
{
rs_signature_check(sig);
/* If block_sigs is full, allocate more space. */
if (sig->count == sig->size) {
sig->size = sig->size ? sig->size * 2 : 16;
- sig->block_sigs = rs_realloc(sig->block_sigs, sig->size * rs_block_sig_size(sig), "signature->block_sigs");
+ sig->block_sigs =
+ rs_realloc(sig->block_sigs, sig->size * rs_block_sig_size(sig),
+ "signature->block_sigs");
}
rs_block_sig_t *b = rs_block_sig_ptr(sig, sig->count++);
rs_block_sig_init(b, weak_sum, strong_sum, sig->strong_sum_len);
return b;
}
-rs_long_t rs_signature_find_match(rs_signature_t *sig, rs_weak_sum_t weak_sum, void const *buf, size_t len)
+rs_long_t rs_signature_find_match(rs_signature_t *sig, rs_weak_sum_t weak_sum,
+ void const *buf, size_t len)
{
rs_block_match_t m;
rs_block_sig_t *b;
@@ -222,15 +247,15 @@ void rs_signature_log_stats(rs_signature_t const *sig)
#ifndef HASHTABLE_NSTATS
hashtable_t *t = sig->hashtable;
- rs_log(RS_LOG_INFO|RS_LOG_NONAME,
+ rs_log(RS_LOG_INFO | RS_LOG_NONAME,
"match statistics: signature[%ld searches, %ld (%.3f%%) matches, "
"%ld (%.3fx) weak sum compares, %ld (%.3f%%) strong sum compares, "
- "%ld (%.3f%%) strong sum calcs]",
- t->find_count,
- t->match_count, 100.0 * (double)t->match_count / t->find_count,
- t->hashcmp_count, (double)t->hashcmp_count / t->find_count,
- t->entrycmp_count, 100.0 * (double)t->entrycmp_count / t->find_count,
- sig->calc_strong_count, 100.0 * (double)sig->calc_strong_count / t->find_count);
+ "%ld (%.3f%%) strong sum calcs]", t->find_count, t->match_count,
+ 100.0 * (double)t->match_count / t->find_count, t->hashcmp_count,
+ (double)t->hashcmp_count / t->find_count, t->entrycmp_count,
+ 100.0 * (double)t->entrycmp_count / t->find_count,
+ sig->calc_strong_count,
+ 100.0 * (double)sig->calc_strong_count / t->find_count);
#endif
}
@@ -266,12 +291,15 @@ void rs_sumset_dump(rs_signature_t const *sums)
rs_block_sig_t *b;
char strong_hex[RS_MAX_STRONG_SUM_LENGTH * 3];
- rs_log(RS_LOG_INFO|RS_LOG_NONAME, "sumset info: magic=%#x, block_len=%d, block_num=%d",
- sums->magic, sums->block_len, sums->count);
+ rs_log(RS_LOG_INFO | RS_LOG_NONAME,
+ "sumset info: magic=%#x, block_len=%d, block_num=%d", sums->magic,
+ sums->block_len, sums->count);
for (i = 0; i < sums->count; i++) {
b = rs_block_sig_ptr(sums, i);
rs_hexify(strong_hex, b->strong_sum, sums->strong_sum_len);
- rs_log(RS_LOG_INFO|RS_LOG_NONAME, "sum %6d: weak="FMT_WEAKSUM", strong=%s", i, b->weak_sum, strong_hex);
+ rs_log(RS_LOG_INFO | RS_LOG_NONAME,
+ "sum %6d: weak=" FMT_WEAKSUM ", strong=%s", i, b->weak_sum,
+ strong_hex);
}
}
diff --git a/src/sumset.h b/src/sumset.h
index d450a34..bfc4a22 100644
--- a/src/sumset.h
+++ b/src/sumset.h
@@ -32,8 +32,8 @@ typedef struct rs_block_sig {
/** Signature of a whole file.
*
- * This includes the all the block sums generated for a file and
- * datastructures for fast matching against them. */
+ * This includes the all the block sums generated for a file and datastructures
+ * for fast matching against them. */
struct rs_signature {
int magic; /**< The signature magic value. */
int block_len; /**< The block length. */
@@ -62,16 +62,21 @@ struct rs_signature {
*
* \param sig_fsize signature file size to preallocate required storage for.
* Use 0 if size is unknown. */
-rs_result rs_signature_init(rs_signature_t *sig, rs_magic_number magic, size_t block_len, size_t strong_len, rs_long_t sig_fsize);
+rs_result rs_signature_init(rs_signature_t *sig, rs_magic_number magic,
+ size_t block_len, size_t strong_len,
+ rs_long_t sig_fsize);
/** Destroy an rs_signature instance. */
void rs_signature_done(rs_signature_t *sig);
/** Add a block to an rs_signature instance. */
-rs_block_sig_t *rs_signature_add_block(rs_signature_t *sig, rs_weak_sum_t weak_sum, rs_strong_sum_t *strong_sum);
+rs_block_sig_t *rs_signature_add_block(rs_signature_t *sig,
+ rs_weak_sum_t weak_sum,
+ rs_strong_sum_t *strong_sum);
/** Find a matching block offset in a signature. */
-rs_long_t rs_signature_find_match(rs_signature_t *sig, rs_weak_sum_t weak_sum, void const *buf, size_t len);
+rs_long_t rs_signature_find_match(rs_signature_t *sig, rs_weak_sum_t weak_sum,
+ void const *buf, size_t len);
/** Log the rs_signature_find_match() stats. */
void rs_signature_log_stats(rs_signature_t const *sig);
@@ -98,7 +103,8 @@ void rs_signature_log_stats(rs_signature_t const *sig);
} while (0)
/** Calculate the strong sum of a buffer. */
-static inline void rs_signature_calc_strong_sum(rs_signature_t const *sig, void const *buf, size_t len,
+static inline void rs_signature_calc_strong_sum(rs_signature_t const *sig,
+ void const *buf, size_t len,
rs_strong_sum_t *sum)
{
if (sig->magic == RS_BLAKE2_SIG_MAGIC) {
diff --git a/src/trace.c b/src/trace.c
index 0e5580c..3c8206e 100644
--- a/src/trace.c
+++ b/src/trace.c
@@ -19,29 +19,27 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
- /*
+ /*=
| Finality is death.
| Perfection is finality.
| Nothing is perfect.
| There are lumps in it.
*/
-
-
-/*
- * TODO: Have a bit set in the log level that says not to include the
- * function name.
- */
+/** \file trace.c logging and debugging output.
+ *
+ * \todo Have a bit set in the log level that says not to include the function
+ * name. */
#include "config.h"
#ifdef HAVE_UNISTD_H
-#include <unistd.h>
+# include <unistd.h>
#else
-#define STDERR_FILENO 2
+# define STDERR_FILENO 2
#endif
#include <stdio.h>
#ifdef HAVE_SYS_FILE_H
-#include <sys/file.h>
+# include <sys/file.h>
#endif
#include <string.h>
#include <errno.h>
@@ -53,7 +51,7 @@
#include "util.h"
#include "trace.h"
-rs_trace_fn_t *rs_trace_impl = rs_trace_stderr;
+rs_trace_fn_t *rs_trace_impl = rs_trace_stderr;
int rs_trace_level = RS_LOG_INFO;
@@ -65,109 +63,82 @@ int rs_trace_level = RS_LOG_INFO;
static void rs_log_va(int level, char const *fn, char const *fmt, va_list va);
-
-/**
- * Log severity strings, if any. Must match ordering in
- * ::rs_loglevel.
- */
+/** Log severity strings, if any. Must match ordering in ::rs_loglevel. */
static const char *rs_severities[] = {
"EMERGENCY! ", "ALERT! ", "CRITICAL! ", "ERROR: ", "Warning: ",
"", "", ""
};
-
-
-/**
- * \brief Set the destination of trace information.
+/** Set the destination of trace information.
*
- * The callback scheme allows for use within applications that may
- * have their own particular ways of reporting errors: log files for a
- * web server, perhaps, and an error dialog for a browser.
+ * The callback scheme allows for use within applications that may have their
+ * own particular ways of reporting errors: log files for a web server,
+ * perhaps, and an error dialog for a browser.
*
- * \todo Do we really need such fine-grained control, or just yes/no
- * tracing?
- */
-void
-rs_trace_to(rs_trace_fn_t * new_impl)
+ * \todo Do we really need such fine-grained control, or just yes/no tracing? */
+void rs_trace_to(rs_trace_fn_t *new_impl)
{
rs_trace_impl = new_impl;
}
-
-void
-rs_trace_set_level(rs_loglevel level)
+void rs_trace_set_level(rs_loglevel level)
{
rs_trace_level = level;
}
-
-static void
-rs_log_va(int flags, char const *fn, char const *fmt, va_list va)
+static void rs_log_va(int flags, char const *fn, char const *fmt, va_list va)
{
int level = flags & RS_LOG_PRIMASK;
if (rs_trace_impl && level <= rs_trace_level) {
- char buf[1000];
- char full_buf[1000];
+ char buf[1000];
+ char full_buf[1000];
vsnprintf(buf, sizeof buf - 1, fmt, va);
if (flags & RS_LOG_NONAME) {
- snprintf(full_buf, sizeof full_buf - 1,
- "%s: %s%s\n", MY_NAME, rs_severities[level], buf);
+ snprintf(full_buf, sizeof full_buf - 1, "%s: %s%s\n", MY_NAME,
+ rs_severities[level], buf);
} else {
- snprintf(full_buf, sizeof full_buf - 1,
- "%s: %s(%s) %s\n", MY_NAME, rs_severities[level], fn, buf);
+ snprintf(full_buf, sizeof full_buf - 1, "%s: %s(%s) %s\n", MY_NAME,
+ rs_severities[level], fn, buf);
}
rs_trace_impl(level, full_buf);
}
}
-
-
-/**
- * Called by a macro, used on platforms where we can't determine the
- * calling function name.
- */
-void
-rs_log0_nofn(int level, char const *fmt, ...)
+/* Called by a macro, used on platforms where we can't determine the calling
+ function name. */
+void rs_log0_nofn(int level, char const *fmt, ...)
{
- va_list va;
+ va_list va;
va_start(va, fmt);
rs_log_va(level, PACKAGE, fmt, va);
va_end(va);
}
-
-/* Called by a macro that prepends the calling function name,
- * etc. */
-void
-rs_log0(int level, char const *fn, char const *fmt, ...)
+/* Called by a macro that prepends the calling function name, etc. */
+void rs_log0(int level, char const *fn, char const *fmt, ...)
{
- va_list va;
+ va_list va;
va_start(va, fmt);
rs_log_va(level, fn, fmt, va);
va_end(va);
}
-
-void
-rs_trace_stderr(rs_loglevel UNUSED(level), char const *msg)
+void rs_trace_stderr(rs_loglevel UNUSED(level), char const *msg)
{
/* NOTE NO TRAILING NUL */
write(STDERR_FILENO, msg, strlen(msg));
}
-
-/* This is called directly if the machine doesn't allow varargs
- * macros. */
-void
-rs_fatal0(char const *s, ...)
+/* This is called directly if the machine doesn't allow varargs macros. */
+void rs_fatal0(char const *s, ...)
{
- va_list va;
+ va_list va;
va_start(va, s);
rs_log_va(RS_LOG_CRIT, PACKAGE, s, va);
@@ -175,41 +146,33 @@ rs_fatal0(char const *s, ...)
abort();
}
-
-/* This is called directly if the machine doesn't allow varargs
- * macros. */
-void
-rs_error0(char const *s, ...)
+/* This is called directly if the machine doesn't allow varargs macros. */
+void rs_error0(char const *s, ...)
{
- va_list va;
+ va_list va;
va_start(va, s);
rs_log_va(RS_LOG_ERR, PACKAGE, s, va);
va_end(va);
}
-
-/* This is called directly if the machine doesn't allow varargs
- * macros. */
-void
-rs_trace0(char const *s, ...)
+/* This is called directly if the machine doesn't allow varargs macros. */
+void rs_trace0(char const *s, ...)
{
#ifdef DO_RS_TRACE
- va_list va;
+ va_list va;
va_start(va, s);
rs_log_va(RS_LOG_DEBUG, PACKAGE, s, va);
va_end(va);
-#endif /* !DO_RS_TRACE */
+#endif /* !DO_RS_TRACE */
}
-
-int
-rs_supports_trace(void)
+int rs_supports_trace(void)
{
#ifdef DO_RS_TRACE
return 1;
#else
return 0;
-#endif /* !DO_RS_TRACE */
+#endif /* !DO_RS_TRACE */
}
diff --git a/src/trace.h b/src/trace.h
index f051fbc..726bfed 100644
--- a/src/trace.h
+++ b/src/trace.h
@@ -19,21 +19,17 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-
-/*
- * TODO: A function like perror that includes strerror output. Apache
- * does this by adding flags as well as the severity level which say
- * whether such information should be included.
- */
-
-
-/*
+/** \file trace.h logging functions.
+ *
* trace may be turned off.
*
- * error is always on, but you can return and continue in some way
+ * error is always on, but you can return and continue in some way.
*
- * fatal terminates the whole process
- */
+ * fatal terminates the whole process.
+ *
+ * \todo A function like perror that includes strerror output. Apache does
+ * this by adding flags as well as the severity level which say whether such
+ * information should be included. */
#include <inttypes.h>
/* Printf format patters for standard librsync types. */
@@ -41,52 +37,46 @@
#define FMT_WEAKSUM "%08"PRIx32
/* Old MSVC compilers don't support "%zu" and have "%Iu" instead. */
#ifdef HAVE_PRINTF_Z
-#define FMT_SIZE "%zu"
+# define FMT_SIZE "%zu"
#else
-#define FMT_SIZE "%Iu"
+# define FMT_SIZE "%Iu"
#endif
-
#if defined(__clang__) || defined(__GNUC__)
-/*
- * TODO: Also look for the C9X predefined identifier `_function', or
- * whatever it's called.
- */
+/** \todo Also look for the C9X predefined identifier `_function', or whatever
+ * it's called. */
void rs_log0(int level, char const *fn, char const *fmt, ...)
__attribute__ ((format(printf, 3, 4)));
-#ifdef DO_RS_TRACE
-# define rs_trace(fmt, arg...) \
- do { rs_log0(RS_LOG_DEBUG, __FUNCTION__, fmt , ##arg); \
+# ifdef DO_RS_TRACE
+# define rs_trace(fmt, arg...) \
+ do { rs_log0(RS_LOG_DEBUG, __FUNCTION__, fmt , ##arg); \
} while (0)
-#else
-# define rs_trace(fmt, arg...)
-#endif /* !DO_RS_TRACE */
+# else
+# define rs_trace(fmt, arg...)
+# endif /* !DO_RS_TRACE */
-#define rs_log(l, s, str...) do { \
- rs_log0((l), __FUNCTION__, (s) , ##str); \
+# define rs_log(l, s, str...) do { \
+ rs_log0((l), __FUNCTION__, (s) , ##str); \
} while (0)
-
-#define rs_error(s, str...) do { \
- rs_log0(RS_LOG_ERR, __FUNCTION__, (s) , ##str); \
+# define rs_error(s, str...) do { \
+ rs_log0(RS_LOG_ERR, __FUNCTION__, (s) , ##str); \
} while (0)
-
-#define rs_fatal(s, str...) do { \
- rs_log0(RS_LOG_CRIT, __FUNCTION__, \
- (s) , ##str); \
- abort(); \
+# define rs_fatal(s, str...) do { \
+ rs_log0(RS_LOG_CRIT, __FUNCTION__, \
+ (s) , ##str); \
+ abort(); \
} while (0)
-
-#else /************************* ! __GNUC__ */
+#else /* !__GNUC__ */
# define rs_trace rs_trace0
# define rs_fatal rs_fatal0
# define rs_error rs_error0
# define rs_log rs_log0_nofn
-#endif /* ! __GNUC__ */
+#endif /* !__GNUC__ */
void rs_trace0(char const *s, ...);
void rs_fatal0(char const *s, ...);
@@ -95,20 +85,14 @@ void rs_log0(int level, char const *fn, char const *fmt, ...);
void rs_log0_nofn(int level, char const *fmt, ...);
enum {
- RS_LOG_PRIMASK = 7, /**< Mask to extract priority
- part. \internal */
+ RS_LOG_PRIMASK = 7, /**< Mask to extract priority part. \internal */
- RS_LOG_NONAME = 8 /**< \b Don't show function name in
- message. */
+ RS_LOG_NONAME = 8 /**< \b Don't show function name in message. */
};
-
-/**
- * \macro rs_trace_enabled()
+/** \macro rs_trace_enabled()
*
- * Call this before putting too much effort into generating trace
- * messages.
- */
+ * Call this before putting too much effort into generating trace messages. */
extern int rs_trace_level;
diff --git a/src/tube.c b/src/tube.c
index 39508c1..6ed4662 100644
--- a/src/tube.c
+++ b/src/tube.c
@@ -19,7 +19,7 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
- /*
+ /*=
| Where a calculator on the ENIAC is
| equpped with 18,000 vaccuum tubes and
| weighs 30 tons, computers in the
@@ -29,32 +29,26 @@
| -- Popular Mechanics, March 1949
*/
-
-/* tube: a somewhat elastic but fairly small buffer for data passing
+/** \file tube.c A somewhat elastic but fairly small buffer for data passing
* through a stream.
*
- * In most cases the iter can adjust to send just as much data will
- * fit. In some cases that would be too complicated, because it has
- * to transmit an integer or something similar. So in that case we
- * stick whatever won't fit into a small buffer.
+ * In most cases the iter can adjust to send just as much data will fit. In
+ * some cases that would be too complicated, because it has to transmit an
+ * integer or something similar. So in that case we stick whatever won't fit
+ * into a small buffer.
*
- * A tube can contain some literal data to go out (typically command
- * bytes), and also an instruction to copy data from the stream's
- * input or from some other location. Both literal data and a copy
- * command can be queued at the same time, but only in that order and
- * at most one of each. */
-
-
-/*
- * TODO: As an optimization, write it directly to the stream if
- * possible. But for simplicity don't do that yet.
+ * A tube can contain some literal data to go out (typically command bytes),
+ * and also an instruction to copy data from the stream's input or from some
+ * other location. Both literal data and a copy command can be queued at the
+ * same time, but only in that order and at most one of each.
*
- * TODO: I think our current copy code will lock up if the application
- * only ever calls us with either input or output buffers, and not
- * both. So I guess in that case we might need to copy into some
- * temporary buffer space, and then back out again later.
- */
-
+ * \todo As an optimization, write it directly to the stream if possible. But
+ * for simplicity don't do that yet.
+ *
+ * \todo I think our current copy code will lock up if the application only
+ * ever calls us with either input or output buffers, and not both. So I guess
+ * in that case we might need to copy into some temporary buffer space, and
+ * then back out again later. */
#include "config.h"
@@ -69,7 +63,6 @@
#include "job.h"
#include "stream.h"
-
static void rs_tube_catchup_write(rs_job_t *job)
{
rs_buffers_t *stream = job->stream;
@@ -79,7 +72,7 @@ static void rs_tube_catchup_write(rs_job_t *job)
assert(len > 0);
assert(len > 0);
- if ((size_t) len > stream->avail_out)
+ if ((size_t)len > stream->avail_out)
len = stream->avail_out;
if (!stream->avail_out) {
@@ -92,7 +85,8 @@ static void rs_tube_catchup_write(rs_job_t *job)
stream->avail_out -= len;
remain = job->write_len - len;
- rs_trace("transmitted %d write bytes from tube, %d remain to be sent", len, remain);
+ rs_trace("transmitted %d write bytes from tube, %d remain to be sent", len,
+ remain);
if (remain > 0) {
/* Still something left in the tube... */
@@ -104,19 +98,16 @@ static void rs_tube_catchup_write(rs_job_t *job)
job->write_len = remain;
}
-
-/**
- * Execute a copy command, taking data from the scoop.
+/** Execute a copy command, taking data from the scoop.
*
- * \sa rs_tube_catchup_copy()
- */
-static void
-rs_tube_copy_from_scoop(rs_job_t *job)
+ * \sa rs_tube_catchup_copy() */
+static void rs_tube_copy_from_scoop(rs_job_t *job)
{
- size_t this_len;
+ size_t this_len;
rs_buffers_t *stream = job->stream;
- this_len = job->copy_len < job->scoop_avail ? job->copy_len : job->scoop_avail;
+ this_len =
+ job->copy_len < job->scoop_avail ? job->copy_len : job->scoop_avail;
if (this_len > stream->avail_out) {
this_len = stream->avail_out;
}
@@ -130,97 +121,79 @@ rs_tube_copy_from_scoop(rs_job_t *job)
job->copy_len -= this_len;
- rs_trace("caught up on "FMT_SIZE" copied bytes from scoop, "FMT_SIZE" remain there, "FMT_LONG" remain to be copied",
- this_len, job->scoop_avail, job->copy_len);
+ rs_trace("caught up on " FMT_SIZE " copied bytes from scoop, " FMT_SIZE
+ " remain there, " FMT_LONG " remain to be copied", this_len,
+ job->scoop_avail, job->copy_len);
}
-
-/**
- * Catch up on an outstanding copy command.
+/** Catch up on an outstanding copy command.
*
- * Takes data from the scoop, and the input (in that order), and
- * writes as much as will fit to the output, up to the limit of the
- * outstanding copy.
- */
+ * Takes data from the scoop, and the input (in that order), and writes as much
+ * as will fit to the output, up to the limit of the outstanding copy. */
static void rs_tube_catchup_copy(rs_job_t *job)
{
- rs_buffers_t *stream = job->stream;
-
assert(job->write_len == 0);
assert(job->copy_len > 0);
- if (job->scoop_avail && job->copy_len) {
- /* there's still some data in the scoop, so we should use that. */
+ /* If there's data in the scoop, send that first. */
+ if (job->scoop_avail && job->copy_len) {
rs_tube_copy_from_scoop(job);
}
-
- if (job->copy_len) {
- size_t this_copy;
-
- this_copy = rs_buffers_copy(stream, job->copy_len);
-
+ /* If there's more to copy and we emptied the scoop, send input. */
+ if (job->copy_len && !job->scoop_avail) {
+ size_t this_copy = rs_buffers_copy(job->stream, job->copy_len);
job->copy_len -= this_copy;
-
- rs_trace("copied "FMT_SIZE" bytes from input buffer, "FMT_LONG" remain to be copied", this_copy, job->copy_len);
+ rs_trace("copied " FMT_SIZE " bytes from input buffer, " FMT_LONG
+ " remain to be copied", this_copy, job->copy_len);
}
}
-
-/**
- * Put whatever will fit from the tube into the output of the stream.
- * Return RS_DONE if the tube is now empty and ready to accept another
- * command, RS_BLOCKED if there is still stuff waiting to go out.
- */
+/** Put whatever will fit from the tube into the output of the stream.
+ *
+ * \return RS_DONE if the tube is now empty and ready to accept another
+ * command, RS_BLOCKED if there is still stuff waiting to go out. */
int rs_tube_catchup(rs_job_t *job)
{
- if (job->write_len)
- rs_tube_catchup_write(job);
-
if (job->write_len) {
- /* there is still write data queued, so we can't send
- * anything else. */
- return RS_BLOCKED;
+ rs_tube_catchup_write(job);
+ if (job->write_len)
+ return RS_BLOCKED;
}
- if (job->copy_len)
- rs_tube_catchup_copy(job);
-
if (job->copy_len) {
- if (job->stream->eof_in && !job->stream->avail_in && !job->scoop_avail) {
- rs_error("reached end of file while copying literal data through buffers");
- return RS_INPUT_ENDED;
+ rs_tube_catchup_copy(job);
+ if (job->copy_len) {
+ if (job->stream->eof_in && !job->stream->avail_in
+ && !job->scoop_avail) {
+ rs_error
+ ("reached end of file while copying literal data through buffers");
+ return RS_INPUT_ENDED;
+ }
+ return RS_BLOCKED;
}
-
- return RS_BLOCKED;
}
-
return RS_DONE;
}
+/* Check whether there is data in the tube waiting to go out.
-/* Check whether there is data in the tube waiting to go out. So if true
- * this basically means that the previous command has finished doing all its
- * output. */
+ \return true if the previous command has finished doing all its output. */
int rs_tube_is_idle(rs_job_t const *job)
{
return job->write_len == 0 && job->copy_len == 0;
}
-
-/**
- * Queue up a request to copy through \p len bytes from the input to
- * the output of the stream.
+/** Queue up a request to copy through \p len bytes from the input to the
+ * output of the stream.
*
- * The data is copied from the scoop (if there is anything there) or
- * from the input, on the next call to rs_tube_write().
+ * The data is copied from the scoop (if there is anything there) or from the
+ * input, on the next call to rs_tube_write().
*
- * We can only accept this request if there is no copy command already
- * pending.
- */
-/* TODO: Try to do the copy immediately, and return a result. Then,
- * people can try to continue if possible. Is this really required?
- * Callers can just go out and back in again after flushing the
- * tube. */
+ * We can only accept this request if there is no copy command already pending.
+ *
+ * \todo Try to do the copy immediately, and return a result. Then, people can
+ * try to continue if possible. Is this really required? Callers can just go
+ * out and back in again after flushing the tube. */
void rs_tube_copy(rs_job_t *job, int len)
{
assert(job->copy_len == 0);
@@ -228,22 +201,19 @@ void rs_tube_copy(rs_job_t *job, int len)
job->copy_len = len;
}
-
-/**
- * Push some data into the tube for storage. The tube's never
- * supposed to get very big, so this will just pop loudly if you do
- * that.
+/** Push some data into the tube for storage.
*
- * We can't accept write data if there's already a copy command in the
- * tube, because the write data comes out first.
- */
-void
-rs_tube_write(rs_job_t *job, const void *buf, size_t len)
+ * The tube's never supposed to get very big, so this will just pop loudly if
+ * you do that.
+ *
+ * We can't accept write data if there's already a copy command in the tube,
+ * because the write data comes out first. */
+void rs_tube_write(rs_job_t *job, const void *buf, size_t len)
{
assert(job->copy_len == 0);
if (len > sizeof(job->write_buf) - job->write_len) {
- rs_fatal("tube popped when trying to write "FMT_SIZE" bytes!", len);
+ rs_fatal("tube popped when trying to write " FMT_SIZE " bytes!", len);
}
memcpy(job->write_buf + job->write_len, buf, len);
diff --git a/src/util.c b/src/util.c
index c4aa663..8ab49ec 100644
--- a/src/util.c
+++ b/src/util.c
@@ -19,12 +19,10 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-
- /*
+ /*=
| On heroin, I have all the answers.
*/
-
#include "config.h"
#include <stdlib.h>
#include <string.h>
@@ -33,17 +31,14 @@
#include "util.h"
#include "trace.h"
-void
-rs_bzero(void *buf, size_t size)
+void rs_bzero(void *buf, size_t size)
{
memset(buf, 0, size);
}
-
-void *
-rs_alloc_struct0(size_t size, char const *name)
+void *rs_alloc_struct0(size_t size, char const *name)
{
- void *p;
+ void *p;
if (!(p = malloc(size))) {
rs_fatal("couldn't allocate instance of %s", name);
@@ -52,12 +47,9 @@ rs_alloc_struct0(size_t size, char const *name)
return p;
}
-
-
-void *
-rs_alloc(size_t size, char const *name)
+void *rs_alloc(size_t size, char const *name)
{
- void *p;
+ void *p;
if (!(p = malloc(size))) {
rs_fatal("couldn't allocate instance of %s", name);
@@ -66,16 +58,14 @@ rs_alloc(size_t size, char const *name)
return p;
}
-
-void *
-rs_realloc(void *ptr, size_t size, char const *name)
+void *rs_realloc(void *ptr, size_t size, char const *name)
{
void *p;
if (!(p = realloc(ptr, size))) {
- rs_fatal("couldn't reallocate instance of %s", name);
- }
- return p;
+ rs_fatal("couldn't reallocate instance of %s", name);
+ }
+ return p;
}
diff --git a/src/util.h b/src/util.h
index b930adc..4fbd1c7 100644
--- a/src/util.h
+++ b/src/util.h
@@ -20,8 +20,8 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-void * rs_alloc(size_t size, char const *name);
-void * rs_realloc(void *ptr, size_t size, char const *name);
+void *rs_alloc(size_t size, char const *name);
+void *rs_realloc(void *ptr, size_t size, char const *name);
void *rs_alloc_struct0(size_t size, char const *name);
void rs_bzero(void *buf, size_t size);
@@ -29,17 +29,14 @@ void rs_bzero(void *buf, size_t size);
int rs_long_ln2(rs_long_t v);
int rs_long_sqrt(rs_long_t v);
-/*
- * Allocate and zero-fill an instance of TYPE.
- */
+/** Allocate and zero-fill an instance of TYPE. */
#define rs_alloc_struct(type) \
((type *) rs_alloc_struct0(sizeof(type), #type))
-
#ifdef __GNUC__
# define UNUSED(x) x __attribute__((unused))
#elif defined(__LCLINT__) || defined(S_SPLINT_S)
# define UNUSED(x) /*@unused@*/ x
-#else /* !__GNUC__ && !__LCLINT__ */
+#else /* !__GNUC__ && !__LCLINT__ */
# define UNUSED(x) x
-#endif /* !__GNUC__ && !__LCLINT__ */
+#endif /* !__GNUC__ && !__LCLINT__ */
diff --git a/src/version.c b/src/version.c
index 6e2299f..ec6b8a9 100644
--- a/src/version.c
+++ b/src/version.c
@@ -21,5 +21,4 @@
#include "config.h"
-
char const rs_librsync_version[] = (PACKAGE " " VERSION);
diff --git a/src/whole.c b/src/whole.c
index 50c286a..5439c1c 100644
--- a/src/whole.c
+++ b/src/whole.c
@@ -19,7 +19,7 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
- /*
+ /*=
| Is it possible that software is not
| like anything else, that it is meant
| to be discarded: that the whole point
@@ -27,14 +27,12 @@
| -- Alan Perlis
*/
-
-
#include "config.h"
#include <assert.h>
#include <stdlib.h>
#ifdef HAVE_UNISTD_H
-#include <unistd.h>
+# include <unistd.h>
#endif
#include <stdio.h>
#include <string.h>
@@ -50,18 +48,14 @@
#include "whole.h"
#include "util.h"
-
-/**
- * Whole file IO buffer sizes.
- */
+/** Whole file IO buffer sizes. */
int rs_inbuflen = 0, rs_outbuflen = 0;
-
/** Run a job continuously, with input to/from the two specified files.
*
- * The job should already be set up, and must be freed by the caller
- * after return. If rs_inbuflen or rs_outbuflen are set, they will override
- * the inbuflen and outbuflen arguments.
+ * The job should already be set up, and must be freed by the caller after
+ * return. If rs_inbuflen or rs_outbuflen are set, they will override the
+ * inbuflen and outbuflen arguments.
*
* \param in_file - input file, or NULL if there is no input.
*
@@ -71,14 +65,13 @@ int rs_inbuflen = 0, rs_outbuflen = 0;
*
* \param outbuflen - recommended output buffer size to use.
*
- * \return RS_DONE if the job completed, or otherwise an error result.
- */
-rs_result
-rs_whole_run(rs_job_t *job, FILE *in_file, FILE *out_file, int inbuflen, int outbuflen)
+ * \return RS_DONE if the job completed, or otherwise an error result. */
+rs_result rs_whole_run(rs_job_t *job, FILE *in_file, FILE *out_file,
+ int inbuflen, int outbuflen)
{
- rs_buffers_t buf;
- rs_result result;
- rs_filebuf_t *in_fb = NULL, *out_fb = NULL;
+ rs_buffers_t buf;
+ rs_result result;
+ rs_filebuf_t *in_fb = NULL, *out_fb = NULL;
/* Override buffer sizes if rs_inbuflen or rs_outbuflen are set. */
inbuflen = rs_inbuflen ? rs_inbuflen : inbuflen;
@@ -87,9 +80,9 @@ rs_whole_run(rs_job_t *job, FILE *in_file, FILE *out_file, int inbuflen, int out
in_fb = rs_filebuf_new(in_file, inbuflen);
if (out_file)
out_fb = rs_filebuf_new(out_file, outbuflen);
- result = rs_job_drive(job, &buf,
- in_fb ? rs_infilebuf_fill : NULL, in_fb,
- out_fb ? rs_outfilebuf_drain : NULL, out_fb);
+ result =
+ rs_job_drive(job, &buf, in_fb ? rs_infilebuf_fill : NULL, in_fb,
+ out_fb ? rs_outfilebuf_drain : NULL, out_fb);
if (in_fb)
rs_filebuf_free(in_fb);
if (out_fb)
@@ -97,21 +90,21 @@ rs_whole_run(rs_job_t *job, FILE *in_file, FILE *out_file, int inbuflen, int out
return result;
}
-
-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)
+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)
{
- rs_job_t *job;
- rs_result r;
- rs_long_t old_fsize = 0;
+ rs_job_t *job;
+ rs_result r;
+ rs_long_t old_fsize = 0;
rs_get_filesize(old_file, &old_fsize);
if ((r = rs_sig_args(old_fsize, &sig_magic, &block_len, &strong_len)) != RS_DONE)
- return r;
+ return r;
job = rs_sig_begin(block_len, strong_len, sig_magic);
/* Size inbuf for 4 blocks, outbuf for header + 4 blocksums. */
- r = rs_whole_run(job, old_file, sig_file, 4 * block_len, 12 + 4*(4 + strong_len));
+ r = rs_whole_run(job, old_file, sig_file, 4 * block_len,
+ 12 + 4 * (4 + strong_len));
if (stats)
memcpy(stats, &job->stats, sizeof *stats);
rs_job_free(job);
@@ -119,12 +112,11 @@ rs_sig_file(FILE *old_file, FILE *sig_file, size_t block_len,
return r;
}
-
-rs_result
-rs_loadsig_file(FILE *sig_file, rs_signature_t **sumset, rs_stats_t *stats)
+rs_result rs_loadsig_file(FILE *sig_file, rs_signature_t **sumset,
+ rs_stats_t *stats)
{
- rs_job_t *job;
- rs_result r;
+ rs_job_t *job;
+ rs_result r;
job = rs_loadsig_begin(sumset);
/* Estimate a number of signatures by file size */
@@ -138,33 +130,31 @@ rs_loadsig_file(FILE *sig_file, rs_signature_t **sumset, rs_stats_t *stats)
return r;
}
-
-rs_result
-rs_delta_file(rs_signature_t *sig, FILE *new_file, FILE *delta_file,
- rs_stats_t *stats)
+rs_result rs_delta_file(rs_signature_t *sig, FILE *new_file, FILE *delta_file,
+ rs_stats_t *stats)
{
- rs_job_t *job;
- rs_result r;
+ rs_job_t *job;
+ rs_result r;
job = rs_delta_begin(sig);
/* Size inbuf for 1 block, outbuf for literal cmd + 4 blocks. */
- r = rs_whole_run(job, new_file, delta_file, sig->block_len, 10 + 4*sig->block_len);
+ r = rs_whole_run(job, new_file, delta_file, sig->block_len,
+ 10 + 4 * sig->block_len);
if (stats)
memcpy(stats, &job->stats, sizeof *stats);
rs_job_free(job);
return r;
}
-
rs_result rs_patch_file(FILE *basis_file, FILE *delta_file, FILE *new_file,
rs_stats_t *stats)
{
- rs_job_t *job;
- rs_result r;
+ rs_job_t *job;
+ rs_result r;
job = rs_patch_begin(rs_file_copy_cb, basis_file);
/* Default size inbuf and outbuf 64K. */
- r = rs_whole_run(job, delta_file, new_file, 64*1024, 64*1024);
+ r = rs_whole_run(job, delta_file, new_file, 64 * 1024, 64 * 1024);
if (stats)
memcpy(stats, &job->stats, sizeof *stats);
rs_job_free(job);
diff --git a/src/whole.h b/src/whole.h
index eea49e0..945f568 100644
--- a/src/whole.h
+++ b/src/whole.h
@@ -19,5 +19,5 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-
-rs_result rs_whole_run(rs_job_t *job, FILE *in_file, FILE *out_file, int inbuflen, int outbuflen);
+rs_result rs_whole_run(rs_job_t *job, FILE *in_file, FILE *out_file,
+ int inbuflen, int outbuflen);
diff --git a/tests/changes.input/06.in b/tests/changes.input/06.in
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/changes.input/06.in
diff --git a/tests/dot b/tests/dot
deleted file mode 100644
index 945c9b4..0000000
--- a/tests/dot
+++ /dev/null
@@ -1 +0,0 @@
-. \ No newline at end of file
diff --git a/tests/hashtable_test.c b/tests/hashtable_test.c
index 14326ab..0fd18a8 100644
--- a/tests/hashtable_test.c
+++ b/tests/hashtable_test.c
@@ -27,32 +27,32 @@
#include "hashtable.h"
/* Key type for the hashtable. */
-typedef int key_t;
-void key_init(key_t *k, int i)
+typedef int mykey_t;
+void mykey_init(mykey_t *k, int i)
{
/* This is chosen to cause bad key collisions and clustering. */
*k = (i / 2) * (i / 2);
}
-int key_hash(const key_t *k)
+int mykey_hash(const mykey_t *k)
{
return *k;
}
-int key_cmp(key_t *k, const key_t *o)
+int mykey_cmp(mykey_t *k, const mykey_t *o)
{
return *k - *o;
}
/* Entry type for values in hashtable. */
-typedef struct entry {
- key_t key; /* Inherit from key_t. */
+typedef struct myentry {
+ mykey_t key; /* Inherit from mykey_t. */
int value;
-} entry_t;
+} myentry_t;
-void entry_init(entry_t *e, int i)
+void myentry_init(myentry_t *e, int i)
{
- key_init(&e->key, i);
+ mykey_init(&e->key, i);
e->value = i;
}
@@ -60,22 +60,22 @@ void entry_init(entry_t *e, int i)
*
* This demonstrates using deferred calculation and comparison of the
* expected value only when the key matches. */
-typedef struct match {
- key_t key; /* Inherit from key_t. */
+typedef struct mymatch {
+ mykey_t key; /* Inherit from mykey_t. */
int value;
int source;
-} match_t;
+} mymatch_t;
-void match_init(match_t *m, int i)
+void mymatch_init(mymatch_t *m, int i)
{
- key_init(&m->key, i);
+ mykey_init(&m->key, i);
m->value = 0;
m->source = i;
}
-int match_cmp(match_t *m, const entry_t *e)
+int mymatch_cmp(mymatch_t *m, const myentry_t *e)
{
- int ans = key_cmp(&m->key, &e->key);
+ int ans = mykey_cmp(&m->key, &e->key);
/* Calculate and compare value if key matches */
if (ans == 0) {
if (m->value != m->source)
@@ -86,77 +86,77 @@ int match_cmp(match_t *m, const entry_t *e)
}
-/* Instantiate a simple key_hashtable of keys. */
-#define ENTRY key
+/* Instantiate a simple mykey_hashtable of keys. */
+#define ENTRY mykey
#include "hashtable.h"
-/* Instantiate a fancy hashtable of entrys using a custom match. */
-#define ENTRY entry
-#define KEY key
-#define MATCH match
-#define NAME hashtable
+/* Instantiate a fancy myhashtable of myentrys using a custom match. */
+#define ENTRY myentry
+#define KEY mykey
+#define MATCH mymatch
+#define NAME myhashtable
#include "hashtable.h"
/* Test driver for hashtable. */
int main(int argc, char **argv)
{
- /* Test key_hashtable instance. */
+ /* Test mykey_hashtable instance. */
hashtable_t *kt;
hashtable_iter_t ki;
- key_t k1, k2;
-
- key_init(&k1, 1);
- key_init(&k2, 2);
- assert((kt = key_hashtable_new(16)) != NULL);
- assert(key_hashtable_add(kt, &k1) == &k1);
- assert(key_hashtable_find(kt, &k1) == &k1);
- assert(key_hashtable_find(kt, &k2) == NULL);
- assert(key_hashtable_iter(&ki, kt) == &k1);
- assert(key_hashtable_next(&ki) == NULL);
-
- /* Test hashtable instance. */
+ mykey_t k1, k2;
+
+ mykey_init(&k1, 1);
+ mykey_init(&k2, 2);
+ assert((kt = mykey_hashtable_new(16)) != NULL);
+ assert(mykey_hashtable_add(kt, &k1) == &k1);
+ assert(mykey_hashtable_find(kt, &k1) == &k1);
+ assert(mykey_hashtable_find(kt, &k2) == NULL);
+ assert(mykey_hashtable_iter(&ki, kt) == &k1);
+ assert(mykey_hashtable_next(&ki) == NULL);
+
+ /* Test myhashtable instance. */
hashtable_t *t;
- entry_t entry[256];
- entry_t e;
- match_t m;
+ myentry_t entry[256];
+ myentry_t e;
+ mymatch_t m;
int i;
- entry_init(&e, 0);
+ myentry_init(&e, 0);
for (i = 0; i < 256; i++)
- entry_init(&entry[i], i);
+ myentry_init(&entry[i], i);
- /* Test hashtable_new() */
- t = hashtable_new(256);
+ /* Test myhashtable_new() */
+ t = myhashtable_new(256);
assert(t->size == 512);
assert(t->count == 0);
assert(t->etable != NULL);
assert(t->ktable != NULL);
- /* Test hashtable_add() */
- assert(hashtable_add(t, &e) == &e); /* Added duplicated copy. */
- assert(hashtable_add(t, &entry[0]) == &entry[0]); /* Added duplicated instance. */
+ /* Test myhashtable_add() */
+ assert(myhashtable_add(t, &e) == &e); /* Added duplicated copy. */
+ assert(myhashtable_add(t, &entry[0]) == &entry[0]); /* Added duplicated instance. */
for (i = 0; i < 256; i++)
- assert(hashtable_add(t, &entry[i]) == &entry[i]);
+ assert(myhashtable_add(t, &entry[i]) == &entry[i]);
assert(t->count == 258);
- /* Test hashtable_find() */
- match_init(&m, 0);
- assert(hashtable_find(t, &m) == &e); /* Finds first duplicate added. */
- assert(m.value == m.source); /* match_cmp() updated m.value. */
+ /* Test myhashtable_find() */
+ mymatch_init(&m, 0);
+ assert(myhashtable_find(t, &m) == &e); /* Finds first duplicate added. */
+ assert(m.value == m.source); /* mymatch_cmp() updated m.value. */
for (i = 1; i < 256; i++) {
- match_init(&m, i);
- assert(hashtable_find(t, &m) == &entry[i]);
- assert(m.value == m.source); /* match_cmp() updated m.value. */
+ mymatch_init(&m, i);
+ assert(myhashtable_find(t, &m) == &entry[i]);
+ assert(m.value == m.source); /* mymatch_cmp() updated m.value. */
}
- match_init(&m, 256);
- assert(hashtable_find(t, &m) == NULL); /* Find missing entry. */
- assert(m.value == 0); /* match_cmp() didn't update m.value. */
+ mymatch_init(&m, 256);
+ assert(myhashtable_find(t, &m) == NULL); /* Find missing myentry. */
+ assert(m.value == 0); /* mymatch_cmp() didn't update m.value. */
#ifndef HASHTABLE_NSTATS
assert(t->find_count == 257);
assert(t->match_count == 256);
assert(t->hashcmp_count >= 256);
assert(t->entrycmp_count >= 256);
- hashtable_stats_init(t);
+ myhashtable_stats_init(t);
assert(t->find_count == 0);
assert(t->match_count == 0);
assert(t->hashcmp_count == 0);
@@ -164,15 +164,15 @@ int main(int argc, char **argv)
#endif
/* Test hashtable iterators */
- entry_t *p;
+ myentry_t *p;
hashtable_iter_t iter;
int count = 0;
- for (p = hashtable_iter(&iter, t); p != NULL; p = hashtable_next(&iter)) {
+ for (p = myhashtable_iter(&iter, t); p != NULL; p = myhashtable_next(&iter)) {
assert(p == &e || (&entry[0] <= p && p <= &entry[255]));
count++;
}
assert(count == 258);
- hashtable_free(t);
+ myhashtable_free(t);
return 0;
}
diff --git a/tests/largefile.test b/tests/largefile.test
index 2bb0b49..4d062d4 100755
--- a/tests/largefile.test
+++ b/tests/largefile.test
@@ -39,6 +39,9 @@ blocks=${2:-64K}
datadir=${3:-$tmpdir}
echo "DATADIR $datadir"
+# Use $4 to optionally specify a block size to use.
+blocksize=${4:-1024}
+
old="$datadir/old.$blocks"
new="$datadir/new.$blocks"
sig="$datadir/sig.$blocks"
@@ -54,8 +57,8 @@ if [ ! -f "$old" ]; then
dd bs=$blocks count=256 skip=640 if="$old" >>"$new"
fi
-run_test time $bindir/rdiff $debug -f -b 1024 -S 8 -s signature $old $sig
-run_test time $bindir/rdiff $debug -f -s -I 32768 -O 32768 delta $sig $new $delta
+run_test time $bindir/rdiff $debug -f -s -b $blocksize -S 8 signature $old $sig
+run_test time $bindir/rdiff $debug -f -s delta $sig $new $delta
run_test time $bindir/rdiff $debug -f -s patch $old $delta $out
check_compare $new $out "large files"
true
diff --git a/tests/testcommon.sh b/tests/testcommon.sh
index bd949e1..e59b1ce 100644
--- a/tests/testcommon.sh
+++ b/tests/testcommon.sh
@@ -51,7 +51,7 @@ delta_instr="
10,1:8,4:6,8:4,10:2,12
0,10000:0,10000:0,10000
"
-bufsizes='4096 1 2 3 7 15 100 10000 200000'
+bufsizes='0 1 2 3 7 15 100 10000 200000'
run_test () {
if :|| test -n "$VERBOSE"