### rs_sig_begin() Source: https://librsync.github.io/mksum_8c.html Starts generating a signature. It is recommended to use rs_sig_args() to get the recommended arguments based on the original file size. Returns a new rs_job_t into which the old file data can be passed. ```APIDOC ## rs_sig_begin() ### Description Starts generating a signature. It is recommended to use rs_sig_args() to get the recommended arguments based on the original file size. ### Function Signature rs_job_t * rs_sig_begin(size_t block_len, size_t strong_len, rs_magic_number sig_magic) ### Parameters - **sig_magic** (rs_magic_number) - Required - Signature file format to generate (0 for "recommended"). See rs_magic_number. - **block_len** (size_t) - Required - Checksum block size to use (0 for "recommended"). Larger values make the signature shorter, and the delta longer. - **strong_len** (size_t) - Required - Strongsum length in bytes to use (0 for "maximum", -1 for "minimum"). Smaller values make the signature shorter but increase the risk of corruption from hash collisions. ### Returns A new rs_job_t into which the old file data can be passed. ### See Also rs_sig_file() ``` -------------------------------- ### Install librsync with sudo make install Source: https://librsync.github.io/page_install.html Install librsync and rdiff system-wide using sudo make install. ```bash $ sudo make install ``` -------------------------------- ### Install libpopt on Windows via vcpkg Source: https://librsync.github.io/md_CONTRIBUTING.html Commands to update vcpkg and install the libpopt library for native Windows development. ```bash $ vcpkg update $ vcpkg --triplet x64-windows install libpopt ``` -------------------------------- ### rs_sig_begin Source: https://librsync.github.io/mksum_8c_source.html Starts generating a signature for a file. ```APIDOC ## rs_sig_begin ### Description Start generating a signature. This function initializes a new signature job. ### Function Signature `rs_job_t * rs_sig_begin(size_t block_len, size_t strong_len, rs_magic_number sig_magic)` ### Parameters - **block_len** (size_t) - Required - The block length for the signature. - **strong_len** (size_t) - Required - The strong sum length. - **sig_magic** (rs_magic_number) - Required - The magic number for the signature. ### Returns - **rs_job_t \*** - A new signature job. ### Definition mksum.c:110 ``` -------------------------------- ### Install libpopt on MacOS via Homebrew Source: https://librsync.github.io/md_CONTRIBUTING.html Commands to update Homebrew and install the popt library. ```bash $ brew update $ brew install popt ``` -------------------------------- ### Install development dependencies on Debian/Ubuntu Source: https://librsync.github.io/md_CONTRIBUTING.html Commands to update package lists, install required development libraries and tools, and set up the tidyc utility. ```bash $ apt-get update $ apt-get install libpopt-dev libb2-dev doxygen graphviz indent clang-tidy iwyu $ git clone https://github.com/dbaarda/tidyc.git $ cp tidyc/tidyc ~/bin ``` -------------------------------- ### Basic hashtable usage with ENTRY and KEY macros Source: https://librsync.github.io/hashtable_8h.html Shows how to define a custom entry type and configure the hashtable using the ENTRY and KEY macros. The example creates a hashtable, adds an entry, finds it, iterates, and frees it. ```c typedef ... mykey_t; int mykey_hash(mykey_t const *e); int mykey_cmp(mykey_t *e, mykey_t const *o); typedef struct myentry { mykey_t key; // Inherit from mykey_t. ...extra entry value data... } myentry_t; void myentry_init(myentry_t *e, ...); #define ENTRY myentry #define KEY mykey #include "hashtable.h" hashtable_t *t; myentry_t entries[300]; mykey_t k; myentry_t *e; t = myentry_hashtable_new(300); myentry_init(&entries[5], ...); myentry_hashtable_add(t, &entries[5]); k = ...; e = myentry_hashtable_find(t, &k); int i; for (e = myentry_hashtable_iter(t, &i); e != NULL; e = myentry_hashtable_next(t, &i)) ... myentry_hashtable_free(t); ``` -------------------------------- ### rdiff_show_version function start Source: https://librsync.github.io/rdiff_8c_source.html Function rdiff_show_version begins by declaring empty strings for bzlib, zlib, and trace, then enters a preprocessor block that is disabled with #if 0. The function is incomplete in the source. ```c static void rdiff_show_version(void) { char const *bzlib = "", *zlib = "", *trace = ""; #if 0 ``` -------------------------------- ### rs_sig_args function (partial) Source: https://librsync.github.io/sumset_8c_source.html Starts the rs_sig_args function, which calculates recommended block and strong lengths based on the old file size. The snippet is incomplete as shown in the source. ```c rs_result rs_sig_args(rs_long_t old_fsize, rs_magic_number * magic, size_t *block_len, size_t *strong_len) { size_t rec_block_len; /* the recomended block_len for the given old_fsize. */ size_t min_strong_len; /* the minimum strong_len for the given ``` -------------------------------- ### Begin loading signature Source: https://librsync.github.io/readsums_8c_source.html Initializes the job for loading a signature. ```c rs_job_t *rs_loadsig_begin(rs_signature_t **signature) { rs_job_t *job; ``` -------------------------------- ### Build documentation with make doc Source: https://librsync.github.io/page_install.html Run make doc to build the documentation (requires Doxygen). ```bash $ make doc ``` -------------------------------- ### rs_scoop_nextbuf Source: https://librsync.github.io/scoop_8h_source.html Get the next iteration of contiguous data buffers from the scoop. Advances the scoop for the previous iteration and gets the next iteration. ```APIDOC ## rs_scoop_nextbuf ### Description Get the next iteration of contiguous data buffers from the scoop. Advances the scoop for the previous iteration and gets the next iteration. ### Function Signature static void *rs_scoop_nextbuf(rs_job_t *job, size_t *len, size_t *ilen) ### Parameters - **job** (rs_job_t *) - Required - The job instance to use. - **len** (size_t *) - Required - The size_t amount of data to iterate over. - **ilen** (size_t *) - Required - The size_t amount of data in the current iteration. ### Return Value void * - A pointer to data in the current iteration. ### Definition scoop.h:175 ``` -------------------------------- ### Enable compression with ENABLE_COMPRESSION=ON Source: https://librsync.github.io/page_install.html Compression support is disabled by default; set ENABLE_COMPRESSION to ON to enable it. ```bash $ cmake -D ENABLE_COMPRESSION=ON . ``` -------------------------------- ### rs_signature_strongsum_kind Source: https://librsync.github.io/sumset_8h.html Gets the strongsum kind for a signature. ```APIDOC ## rs_signature_strongsum_kind ### Description Gets the strongsum kind for a signature. ### Function Signature static strongsum_kind_t rs_signature_strongsum_kind(rs_signature_t const *sig) ### Parameters - **sig** (rs_signature_t const *) - Required - Pointer to the signature instance. ### Return Value - **strongsum_kind_t** - The strongsum kind. ``` -------------------------------- ### Build and run tests with make check Source: https://librsync.github.io/page_install.html Run make check to build and run the test suite. ```bash $ make check ``` -------------------------------- ### rs_signature_weaksum_kind Source: https://librsync.github.io/sumset_8h.html Gets the weaksum kind for a signature. ```APIDOC ## rs_signature_weaksum_kind ### Description Gets the weaksum kind for a signature. ### Function Signature static weaksum_kind_t rs_signature_weaksum_kind(rs_signature_t const *sig) ### Parameters - **sig** (rs_signature_t const *) - Required - Pointer to the signature instance. ### Return Value - **weaksum_kind_t** - The weaksum kind. ``` -------------------------------- ### Use Ninja as the build tool Source: https://librsync.github.io/page_install.html Generate Ninja build files and run the check target with ninja. ```bash $ cmake -G Ninja . $ ninja check ``` -------------------------------- ### rs_emit_delta_header Source: https://librsync.github.io/emit_8h.html Writes the magic for the start of a delta. ```APIDOC ## rs_emit_delta_header ### Description Writes the magic for the start of a delta. ### Function Signature void rs_emit_delta_header(rs_job_t *job) ### Parameters - **job** (rs_job_t *) - Required - Pointer to the job context. ### Returns void ``` -------------------------------- ### rs_delta_begin function Source: https://librsync.github.io/delta_8c_source.html Initializes a new delta encoding job, optionally setting up a signature for matching. ```c 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 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); job->signature = sig; weaksum_init(&job->weak_sum, rs_signature_weaksum_kind(sig)); } return job; } ``` -------------------------------- ### rs_scoop_buf Source: https://librsync.github.io/scoop_8h_source.html Get a pointer to the next input in the scoop. ```APIDOC ## rs_scoop_buf ### Description Get a pointer to the next input in the scoop. ### Function Signature static inline void *rs_scoop_buf(rs_job_t *job) ### Parameters - **job** (rs_job_t *) - Required - The job instance to use. ### Return Value void * - Pointer to the next input data. ### Definition scoop.h:106 ``` -------------------------------- ### rs_scoop_avail Source: https://librsync.github.io/scoop_8h_source.html Get the amount of data available in the scoop. ```APIDOC ## rs_scoop_avail ### Description Get the amount of data available in the scoop. ### Function Signature static inline size_t rs_scoop_avail(rs_job_t *job) ### Parameters - **job** (rs_job_t *) - Required - The job instance to use. ### Return Value size_t - The number of bytes available. ### Definition scoop.h:94 ``` -------------------------------- ### main function for rdiff Source: https://librsync.github.io/rdiff_8c_source.html Initializes the popt context, parses command-line options, and executes the requested rdiff action. ```c int main(const int argc, const char *argv[]) { /* Initialize opts at runtime to avoid unknown address values. */ 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}, {"rollsum", 'R', POPT_ARG_STRING, &rs_rollsum_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}, {0} }; poptContext opcon; rs_result result; opcon = poptGetContext("rdiff", argc, argv, opts, 0); rdiff_options(opcon); result = rdiff_action(opcon); if (result != RS_DONE) fprintf(stderr, "rdiff: Failed, %s.\n", rs_strerror(result)); poptFreeContext(opcon); return result; } ``` -------------------------------- ### rs_scoop_len Source: https://librsync.github.io/scoop_8h_source.html Get the contiguous length of the next input in the scoop. ```APIDOC ## rs_scoop_len ### Description Get the contiguous length of the next input in the scoop. ### Function Signature static inline size_t rs_scoop_len(rs_job_t *job) ### Parameters - **job** (rs_job_t *) - Required - The job instance to use. ### Return Value size_t - The contiguous length of the next input. ### Definition scoop.h:113 ``` -------------------------------- ### rs_file_size Source: https://librsync.github.io/fileutil_8c_source.html Gets the size of a file. Returns the size as a rs_long_t. ```APIDOC ## rs_file_size ### Description Gets the size of a file. ### Signature `LIBRSYNC_EXPORT rs_long_t rs_file_size(FILE *file)` ### Parameters - **file** (FILE*) - Required - The file stream to query. ### Returns - **rs_long_t** - The size of the file. ### Definition fileutil.c:127 ``` -------------------------------- ### Perform a custom Release build with Ninja Source: https://librsync.github.io/md_CONTRIBUTING.html Configure a build in a separate directory using specific compiler, build type, and library settings, followed by the build and test command. ```bash $ cmake -B build -G Ninja -D CMAKE_C_COMPILER=clang \ -D CMAKE_BUILD_TYPE=Release \ -D BUILD_SHARED_LIBS=OFF \ -D USE_LIBB2=ON \ -D ENABLE_TRACE=ON $ cmake --build build --config Release --target check ``` -------------------------------- ### C++ example for Doxygen graph legend Source: https://librsync.github.io/graph_legend.html C++ class definitions used to illustrate Doxygen graph conventions. The example includes documented, undocumented, and truncated classes, plus public, protected, and private inheritance, a template class, and a usage relation. The resulting graph is shown below the code. ```cpp /*! Invisible class because of truncation */ class Invisible { }; /*! Truncated class, inheritance relation is hidden */ class Truncated : public Invisible { }; /* Class not documented with doxygen comments */ class Undocumented { }; /*! Class that is inherited using public inheritance */ class PublicBase : public Truncated { }; /*! A template class */ template class Templ { }; /*! Class that is inherited using protected inheritance */ class ProtectedBase { }; /*! Class that is inherited using private inheritance */ class PrivateBase { }; /*! Class that is used by the Inherited class */ class Used { }; /*! Super class that inherits a number of other classes */ class Inherited : public PublicBase, protected ProtectedBase, private PrivateBase, public Undocumented, public Templ { private: Used *m_usedClass; }; ``` -------------------------------- ### Build librsync with make Source: https://librsync.github.io/page_install.html After generating the Makefile, run make to build librsync and rdiff. ```bash $ make ``` -------------------------------- ### rs_magic_number Source: https://librsync.github.io/librsync_8h_source.html A uint32 magic number, emitted in bigendian/network order at the start of librsync files. ```APIDOC ## rs_magic_number ### Description A uint32 magic number, emitted in bigendian/network order at the start of librsync files. ### Values - **RS_DELTA_MAGIC** - A delta file. - **RS_MD4_SIG_MAGIC** - A signature file with MD4 signatures. - **RS_BLAKE2_SIG_MAGIC** - A signature file using the BLAKE2 hash. - **RS_RK_MD4_SIG_MAGIC** - A signature file with RabinKarp rollsum and MD4 hash. - **RS_RK_BLAKE2_SIG_MAGIC** - A signature file with RabinKarp rollsum and BLAKE2 hash. ``` -------------------------------- ### rs_file_size Source: https://librsync.github.io/librsync_8h_source.html Gets the size of a file in a platform-independent way. Returns -1 if the size cannot be determined because it is not a regular file. ```APIDOC ## rs_file_size ### Description Gets the size of a file in a platform-independent way. Returns -1 if the size cannot be determined because it is not a regular file. ### Function Signature rs_long_t rs_file_size(FILE *file) ### Parameters - **file** (FILE *) - Required - The stdio file to get the size of. ### Returns rs_long_t - The file size, or -1 if not a regular file. ``` -------------------------------- ### NAME_new Source: https://librsync.github.io/hashtable_8h_source.html Initializes a new hashtable instance with a specified minimum size. ```c static inline hashtable_t *NAME_new(int size) { return _hashtable_new(size); } ``` -------------------------------- ### Non-docbook comment styles Source: https://librsync.github.io/md_CONTRIBUTING.html Examples of preferred formatting for non-docbook comments, including block and inline styles. ```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 */ ``` -------------------------------- ### NAME_next() Source: https://librsync.github.io/hashtable_8h.html Gets the next entry from a hashtable iterator or NULL when finished. Works together with NAME_iter() for iterating through all entries. ```APIDOC ## NAME_next() ### Description Gets the next entry from a hashtable iterator or NULL when finished. Works together with NAME_iter() for iterating through all entries. ### Function Signature static ENTRY_t * NAME_next(hashtable_t *t, int *i) ### Parameters - **t** (hashtable_t *) - Required - The hashtable to iterate over. - **i** (int *) - Required - The int iterator index to use. ### Returns The next entry or NULL if the iterator is finished. ``` -------------------------------- ### rs_loadsig_begin() Source: https://librsync.github.io/api_streaming.html Loads a signature into memory. This function initiates a load signature job. ```APIDOC ## rs_loadsig_begin() ### Description Loads a signature into memory. This function initiates a load signature job. ### Method Function ### Endpoint rs_loadsig_begin() ### Parameters None explicitly documented. ### Request Example No request body. ### Response #### Success Response Returns a rs_job_t object. #### Response Example No response body example provided. ``` -------------------------------- ### rs_sig_begin() Source: https://librsync.github.io/api_streaming.html Calculates the signature of a file. This function initiates a signature job. ```APIDOC ## rs_sig_begin() ### Description Calculates the signature of a file. This function initiates a signature job. ### Method Function ### Endpoint rs_sig_begin() ### Parameters None explicitly documented. ### Request Example No request body. ### Response #### Success Response Returns a rs_job_t object. #### Response Example No response body example provided. ``` -------------------------------- ### Copy command format Source: https://librsync.github.io/page_formats.html Encoding of a copy command in a delta file: a command byte (0x45-0x54), a start offset, and a length, all big-endian. ```c u8 command; // in the range 0x45 through 0x54 inclusive u8[arg1_len] start; // offset in the basis to begin copying data u8[arg2_len] length; // number of bytes to copy from the basis ``` -------------------------------- ### Configure build interactively Source: https://librsync.github.io/md_CONTRIBUTING.html Use the ccmake tool to interactively configure the project in a separate build directory. ```bash $ ccmake -B build ``` -------------------------------- ### rs_sig_args() Source: https://librsync.github.io/api_streaming.html Gets the recommended signature arguments from the input file's size. This helper function can be used to obtain recommended signature arguments. ```APIDOC ## rs_sig_args() ### Description Gets the recommended signature arguments from the input file's size. This helper function can be used to obtain recommended signature arguments. ### Method Function ### Endpoint rs_sig_args() ### Parameters None explicitly documented. ### Request Example No request body. ### Response #### Success Response Returns the recommended signature arguments. #### Response Example No response body example provided. ``` -------------------------------- ### Configure CMake for vcpkg on Windows Source: https://librsync.github.io/md_CONTRIBUTING.html Required flag to add to the cmake command line to ensure CMake locates libraries installed via vcpkg. ```bash -D CMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake ``` -------------------------------- ### Perform a default Debug build Source: https://librsync.github.io/md_CONTRIBUTING.html The minimal sequence of commands to clone, configure, and test the project using default settings. ```bash $ git clone https://github.com/librsync/librsync.git $ cd librsync $ cmake . $ make check ``` -------------------------------- ### rs_scoop_getbuf Source: https://librsync.github.io/scoop_8h_source.html Get the next contiguous buffer of data available in the scoop. Returns a pointer to the data and reduces len to the amount of contiguous data available. ```APIDOC ## rs_scoop_getbuf ### Description Get the next contiguous buffer of data available in the scoop. Returns a pointer to the data and reduces len to the amount of contiguous data available. ### Function Signature static void *rs_scoop_getbuf(rs_job_t *job, size_t *len) ### Parameters - **job** (rs_job_t *) - Required - The job instance to use. - **len** (size_t *) - Required - The amount of data desired, updated to the amount available. ### Return Value void * - A pointer to the data. ### Definition scoop.h:128 ``` -------------------------------- ### rs_delta_begin Source: https://librsync.github.io/librsync_8h_source.html Prepares to compute a streaming delta. ```APIDOC ## rs_delta_begin ### Description Prepares to compute a streaming delta. ### Function Signature rs_job_t *rs_delta_begin(rs_signature_t *) ### Parameters - **signature** (rs_signature_t*) - Required - The signature to use for delta computation. ### Return Value - **rs_job_t*** - A new job for delta computation. ### Notes - Todo: Add a version of this that takes a ::rs_magic_number controlling the delta format. ``` -------------------------------- ### trace.c: librsync trace module implementation Source: https://librsync.github.io/trace_8c_source.html Complete source of trace.c, implementing the trace callback system, severity levels, and message formatting. Includes the default stderr callback and a compile-time check for trace support. ```c /*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- * * librsync -- library for network deltas * * Copyright (C) 2000, 2001 by Martin Pool * * 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. */ /*= | Finality is death. | Perfection is finality. | Nothing is perfect. | There are lumps in it. */ #include "config.h" /* IWYU pragma: keep */ #include #include #include "librsync.h" #include "trace.h" #include "util.h" rs_trace_fn_t *rs_trace_impl = rs_trace_stderr; int rs_trace_level = RS_LOG_INFO; #define MY_NAME "librsync" 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. */ static const char *rs_severities[] = { "EMERGENCY! ", "ALERT! ", "CRITICAL! ", "ERROR: ", "Warning: ", "", "", "" }; /** 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. * * \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) { rs_trace_level = level; } 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[1040]; vsnprintf(buf, sizeof(buf), fmt, va); if (flags & RS_LOG_NONAME || !(*fn)) { snprintf(full_buf, sizeof(full_buf), "%s: %s%s\n", MY_NAME, rs_severities[level], buf); } else { snprintf(full_buf, sizeof(full_buf), "%s: %s(%s) %s\n", MY_NAME, rs_severities[level], fn, buf); } rs_trace_impl(level, full_buf); } } /* 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_start(va, fmt); rs_log_va(level, fn, fmt, va); va_end(va); } void rs_trace_stderr(rs_loglevel UNUSED(level), char const *msg) { fputs(msg, stderr); } int rs_supports_trace(void) { #ifdef DO_RS_TRACE return 1; #else return 0; #endif /* !DO_RS_TRACE */ } ``` -------------------------------- ### Configure CMake with options Source: https://librsync.github.io/page_install.html Use this command to pass custom options to CMake during the configure step. ```bash $ cmake -D = . ```