├── CREDITS ├── EXPERIMENTAL ├── librsync ├── testsuite │ ├── dot │ ├── delta.input │ │ ├── 01.expect │ │ ├── 01.delta │ │ ├── 02.expect │ │ ├── 02.delta │ │ ├── 03.expect │ │ └── 03.delta │ ├── triple.input │ │ ├── zero.in │ │ └── hello.in │ ├── mdfour.input │ │ ├── 01.data │ │ └── 01.expect │ ├── mksum.input │ │ └── COPYING.sig │ ├── signature.input │ │ └── 01.sig │ ├── isprefix.test │ ├── changes.test │ ├── mksum.test │ ├── signature.test │ ├── delta.test │ ├── sources.test │ ├── triple.test │ ├── mutate.test │ ├── isprefix.driver.c │ ├── Makefile.am │ ├── mutate.pl │ ├── driver.sh │ └── changes.input │ │ └── 02.in ├── configure.msc ├── AUTHORS ├── popt │ ├── Makefile.am │ ├── findme.h │ ├── README │ ├── findme.c │ ├── COPYING │ ├── CHANGES │ ├── system.h │ ├── poptparse.c │ ├── poptint.h │ └── poptconfig.c ├── README.RPM ├── rdiff.magic ├── PCbuild │ ├── PCbuild.dsw │ └── librsync-config.h ├── snprintf.h ├── libversions.txt ├── whole.h ├── fileutil.h ├── isprefix.h ├── version.c ├── search.h ├── emit.h ├── buf.h ├── isprefix.c ├── checksum.h ├── mdfour.h ├── netint.h ├── librsync-config.h.in ├── hex.c ├── util.h ├── types.h ├── util.c ├── command.c ├── protocol.h ├── command.h ├── doc │ ├── rdiff.1 │ ├── Makefile.am │ └── librsync.3 ├── rollsum.c ├── stream.h ├── fileutil.c ├── sumset.h ├── librsync.spec ├── mkinstalldirs ├── sumset.c ├── rollsum.h ├── README ├── Makefile.am ├── autogen.sh ├── checksum.c ├── msg.c ├── base64.c ├── README.CVS ├── THANKS ├── mkprototab.pl ├── job.h ├── stats.c ├── emit.c ├── trace.h ├── mksum.c ├── search.c ├── netint.c ├── configure.ac └── whole.c ├── external_libraries.h ├── tests ├── 002test.png ├── 003test.png ├── 004test.png ├── 005test.png ├── 006test.png ├── 007test.png ├── 004test.patch ├── 007test.patch ├── 003signatur.sig ├── 006signatur.sig ├── 009.phpt ├── 010.phpt ├── 012.phpt ├── 002.phpt ├── 003.phpt ├── 011.phpt ├── 001.phpt ├── 004.phpt ├── 005.phpt ├── 006.phpt ├── 007.phpt ├── 008.phpt ├── 014.phpt └── 013.phpt ├── check_failedTest.sh ├── librsync-0.9.7-vc9-x86.zip ├── TODO ├── README ├── .travis.yml ├── config.w32 ├── .gitignore ├── rsync.php ├── LICENSE ├── examples └── logger.php ├── README.md ├── php_rsync.h ├── config.m4 └── rsync_extension.php /CREDITS: -------------------------------------------------------------------------------- 1 | rsync -------------------------------------------------------------------------------- /EXPERIMENTAL: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /librsync/testsuite/dot: -------------------------------------------------------------------------------- 1 | . -------------------------------------------------------------------------------- /librsync/testsuite/delta.input/01.expect: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /librsync/testsuite/triple.input/zero.in: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /librsync/testsuite/delta.input/01.delta: -------------------------------------------------------------------------------- 1 | rs6 -------------------------------------------------------------------------------- /librsync/testsuite/delta.input/02.expect: -------------------------------------------------------------------------------- 1 | hello -------------------------------------------------------------------------------- /external_libraries.h: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | -------------------------------------------------------------------------------- /librsync/testsuite/delta.input/02.delta: -------------------------------------------------------------------------------- 1 | rs6hello -------------------------------------------------------------------------------- /librsync/testsuite/triple.input/hello.in: -------------------------------------------------------------------------------- 1 | Hello! 2 | -------------------------------------------------------------------------------- /librsync/testsuite/delta.input/03.expect: -------------------------------------------------------------------------------- 1 | hello world 2 | -------------------------------------------------------------------------------- /librsync/testsuite/delta.input/03.delta: -------------------------------------------------------------------------------- 1 | rs6hello world 2 | -------------------------------------------------------------------------------- /librsync/testsuite/mdfour.input/01.data: -------------------------------------------------------------------------------- 1 | Sun Dec 3 17:03:18 PST 2000 2 | -------------------------------------------------------------------------------- /librsync/testsuite/mdfour.input/01.expect: -------------------------------------------------------------------------------- 1 | 0df1847ec72b1683956389cca2477d8e 2 | -------------------------------------------------------------------------------- /librsync/configure.msc: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ./configure CC=cl --prefix='C:/Progra~1/librsync' 3 | -------------------------------------------------------------------------------- /tests/002test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ironpinguin/php_rsync/HEAD/tests/002test.png -------------------------------------------------------------------------------- /tests/003test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ironpinguin/php_rsync/HEAD/tests/003test.png -------------------------------------------------------------------------------- /tests/004test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ironpinguin/php_rsync/HEAD/tests/004test.png -------------------------------------------------------------------------------- /tests/005test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ironpinguin/php_rsync/HEAD/tests/005test.png -------------------------------------------------------------------------------- /tests/006test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ironpinguin/php_rsync/HEAD/tests/006test.png -------------------------------------------------------------------------------- /tests/007test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ironpinguin/php_rsync/HEAD/tests/007test.png -------------------------------------------------------------------------------- /tests/004test.patch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ironpinguin/php_rsync/HEAD/tests/004test.patch -------------------------------------------------------------------------------- /tests/007test.patch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ironpinguin/php_rsync/HEAD/tests/007test.patch -------------------------------------------------------------------------------- /tests/003signatur.sig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ironpinguin/php_rsync/HEAD/tests/003signatur.sig -------------------------------------------------------------------------------- /tests/006signatur.sig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ironpinguin/php_rsync/HEAD/tests/006signatur.sig -------------------------------------------------------------------------------- /check_failedTest.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [ `cat testfailed.txt |wc -c` -ne 0 ]; then 4 | exit 1 5 | fi 6 | -------------------------------------------------------------------------------- /librsync-0.9.7-vc9-x86.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ironpinguin/php_rsync/HEAD/librsync-0.9.7-vc9-x86.zip -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | - Reverte Enginiering the rsync to update the librsync library without change the license from lgpl to gpl. 2 | -------------------------------------------------------------------------------- /librsync/AUTHORS: -------------------------------------------------------------------------------- 1 | Martin Pool 2 | Andrew Tridgell 3 | Donovan Baarda 4 | -------------------------------------------------------------------------------- /librsync/testsuite/mksum.input/COPYING.sig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ironpinguin/php_rsync/HEAD/librsync/testsuite/mksum.input/COPYING.sig -------------------------------------------------------------------------------- /librsync/testsuite/signature.input/01.sig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ironpinguin/php_rsync/HEAD/librsync/testsuite/signature.input/01.sig -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | php extension for librsync. 2 | 3 | include the posibility to php to generate signatur files, patches and patch files with the rsync functionality. 4 | 5 | -------------------------------------------------------------------------------- /tests/009.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test function rsync_patch_file with stream as input and output. 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 9 | --EXPECT-- 10 | -------------------------------------------------------------------------------- /librsync/popt/Makefile.am: -------------------------------------------------------------------------------- 1 | MAINTAINERCLEANFILES = Makefile.in 2 | 3 | EXTRA_LIBRARIES = libpopt.a 4 | 5 | libpopt_a_SOURCES = findme.c findme.h popt.c popt.h poptconfig.c \ 6 | popthelp.c poptint.h poptparse.c system.h 7 | 8 | EXTRA_DIST = COPYING README CHANGES 9 | -------------------------------------------------------------------------------- /tests/010.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test function rsync_patch_file with stream as input and output. 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 10 | --EXPECT-- 11 | -------------------------------------------------------------------------------- /librsync/README.RPM: -------------------------------------------------------------------------------- 1 | librsync now comes with an RPM .spec file contributed by Peter Braam 2 | and Shirish Hemant Phatak that will allow you to build an RPM package. 3 | 4 | To do this, simply execute the command: 5 | 6 | rpm -ta librsync-0.9.3.tar.gz 7 | 8 | $Id: README.RPM,v 1.1 2001/08/08 01:20:53 mbp Exp $ 9 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | compiler: gcc 3 | before_install: 4 | - sudo apt-get update -qq 5 | - sudo apt-get install -qq php5 php5-dev make librsync1 librsync-dev 6 | env: NO_INTERACTION=true TESTS="-w testfailed.txt" 7 | script: "phpize && ./configure --with-rsync && make && make test && ./check_failedTest.sh" 8 | -------------------------------------------------------------------------------- /librsync/popt/findme.h: -------------------------------------------------------------------------------- 1 | /* (C) 1998 Red Hat Software, Inc. -- Licensing details are in the COPYING 2 | file accompanying popt source distributions, available from 3 | ftp://ftp.redhat.com/pub/code/popt */ 4 | 5 | #ifndef H_FINDME 6 | #define H_FINDME 7 | 8 | const char * findProgramPath(const char * argv0); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /config.w32: -------------------------------------------------------------------------------- 1 | // $Id$ 2 | // vim:ft=javascript 3 | 4 | ARG_WITH("rsync", "for rsync support", "no"); 5 | 6 | if (PHP_RSYNC != "no") { 7 | if (CHECK_LIB("rsync.lib", "librsync", PHP_RSYNC) && 8 | CHECK_HEADER_ADD_INCLUDE("librsync.h", "CFLAGS_RSYNC") && 9 | CHECK_HEADER_ADD_INCLUDE("librsync-config.h", "CFLAGS_RSYNC")) { 10 | EXTENSION("rsync", "rsync.c"); 11 | } else { 12 | WARNING( "rsync not enabled; libraries not found" ); 13 | } 14 | } -------------------------------------------------------------------------------- /tests/012.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test the logging stats over php error_log 3 | --SKIPIF-- 4 | 6 | --FILE-- 7 | 15 | --EXPECTF-- 16 | Notice: rsync_generate_signature(): Rsync INFO: signature statistics: signature[3 blocks, 2048 bytes per block] 17 | in %stests/012.php on line %d 18 | -------------------------------------------------------------------------------- /tests/002.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test the rsync_generate_signatur function 3 | --SKIPIF-- 4 | 6 | --FILE-- 7 | 18 | --EXPECT-- 19 | SUCCESS 20 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .deps 2 | .libs/ 3 | Makefile 4 | Makefile.fragments 5 | Makefile.global 6 | Makefile.objects 7 | acinclude.m4 8 | aclocal.m4 9 | autom4te.cache/ 10 | build/ 11 | config.guess 12 | config.h 13 | config.h.in 14 | config.log 15 | config.nice 16 | config.status 17 | config.sub 18 | configure 19 | configure.in 20 | install-sh 21 | librsync/ 22 | *.lo 23 | libtool 24 | ltmain.sh 25 | missing 26 | mkinstalldirs 27 | modules/ 28 | rsync.la 29 | rsync.lo 30 | run-tests.php 31 | tests/*.diff 32 | tests/*.exp 33 | tests/*.log 34 | tests/*.out 35 | tests/*.php 36 | tests/*.sh 37 | testfailed.txt 38 | -------------------------------------------------------------------------------- /rsync.php: -------------------------------------------------------------------------------- 1 | "; 3 | 4 | if(!extension_loaded('rsync')) { 5 | dl('rsync.' . PHP_SHLIB_SUFFIX); 6 | } 7 | $module = 'rsync'; 8 | $functions = get_extension_funcs($module); 9 | echo "Functions available in the test extension:$br\n"; 10 | foreach($functions as $func) { 11 | echo $func."$br\n"; 12 | } 13 | echo "$br\n"; 14 | $function = 'confirm_' . $module . '_compiled'; 15 | if (extension_loaded($module)) { 16 | $str = $function($module); 17 | } else { 18 | $str = "Module $module is not compiled into PHP"; 19 | } 20 | echo "$str\n"; 21 | ?> 22 | -------------------------------------------------------------------------------- /tests/003.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test function rsync_generate_delta 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 17 | --EXPECT-- 18 | SUCCESS 19 | -------------------------------------------------------------------------------- /tests/011.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test the stats logging over callback php function 3 | --SKIPIF-- 4 | 6 | --FILE-- 7 | 19 | --EXPECT-- 20 | 6 signature statistics: signature[3 blocks, 2048 bytes per block] 21 | -------------------------------------------------------------------------------- /tests/001.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Check for rsync presence 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 20 | --EXPECT-- 21 | rsync extension is available 22 | -------------------------------------------------------------------------------- /librsync/rdiff.magic: -------------------------------------------------------------------------------- 1 | # Supplementary magic data for the file(1) command to support 2 | # rdiff(1). The format is described in magic(5). 3 | # 4 | # librsync -- the library for network deltas 5 | # 6 | # Copyright (C) 2001 by Martin Pool. You may do whatever you want with 7 | # this file. 8 | # 9 | # $Id: rdiff.magic,v 1.2 2001/03/05 07:09:35 mbp Exp $ 10 | 11 | 0 belong 0x72730236 rdiff network-delta data 12 | 13 | 0 belong 0x72730136 rdiff network-delta signature data 14 | >4 belong x (block length=%d, 15 | >8 belong x signature strength=%d) 16 | -------------------------------------------------------------------------------- /librsync/PCbuild/PCbuild.dsw: -------------------------------------------------------------------------------- 1 | Microsoft Developer Studio Workspace File, Format Version 6.00 2 | # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! 3 | 4 | ############################################################################### 5 | 6 | Project: "rdiff"=".\rdiff.dsp" - Package Owner=<4> 7 | 8 | Package=<5> 9 | {{{ 10 | }}} 11 | 12 | Package=<4> 13 | {{{ 14 | }}} 15 | 16 | ############################################################################### 17 | 18 | Global: 19 | 20 | Package=<5> 21 | {{{ 22 | }}} 23 | 24 | Package=<3> 25 | {{{ 26 | }}} 27 | 28 | ############################################################################### 29 | 30 | -------------------------------------------------------------------------------- /tests/004.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test function rsync_patch_file 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | 20 | --EXPECT-- 21 | SUCCESS 22 | -------------------------------------------------------------------------------- /tests/005.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test the rsync_generate_signatur function with stream as input and signaturfile output. 3 | --SKIPIF-- 4 | 6 | --FILE-- 7 | 23 | --EXPECT-- 24 | SUCCESS 25 | -------------------------------------------------------------------------------- /librsync/snprintf.h: -------------------------------------------------------------------------------- 1 | /* $Id: snprintf.h,v 1.3 2003/08/03 14:36:09 abo Exp $ */ 2 | 3 | /* Some platforms don't have one or both of these functions. 4 | * MSVC has _snprintf and _vsnprintf functions instead. 5 | * 6 | * XXX: put this into a "common.h" for all platform conditionals and split 7 | * snprintf.c into two seperate autoconf replacement functions. 8 | */ 9 | #ifndef HAVE_SNPRINTF 10 | # ifdef HAVE__SNPRINTF 11 | # define snprintf _snprintf 12 | # else 13 | int snprintf (char *str, size_t count, const char *fmt, ...); 14 | # endif 15 | #endif 16 | #ifndef HAVE_VSNPRINTF 17 | # ifdef HAVE__VSNPRINTF 18 | # define vsnprintf _vsnprintf 19 | # else 20 | int vsnprintf (char *str, size_t count, const char *fmt, va_list arg); 21 | # endif 22 | #endif 23 | -------------------------------------------------------------------------------- /librsync/testsuite/isprefix.test: -------------------------------------------------------------------------------- 1 | #! /bin/sh -pe 2 | 3 | # librsync test case. 4 | # Copyright (C) 2000 by Martin Pool 5 | 6 | # Test the map_ptr input routines, by extracting chunks of a file 7 | # using a known-good Python implementation, and also by passing the 8 | # same parameters to the hsmapread driver. 9 | 10 | # $Id: isprefix.test,v 1.1 2002/01/25 21:08:26 bje Exp $ 11 | 12 | run_test isprefix.driver foo foobar 13 | run_test isprefix.driver '' foobar 14 | run_test isprefix.driver foobar foobar 15 | run_test isprefix.driver f f 16 | run_test isprefix.driver '' '' 17 | run_test isprefix.driver f foobar 18 | 19 | run_test isprefix.driver ! foobar foo 20 | run_test isprefix.driver ! goo foo 21 | run_test isprefix.driver ! foo '' 22 | run_test isprefix.driver ! f g 23 | -------------------------------------------------------------------------------- /tests/006.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test function rsync_generate_delta with stream as input and output. 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 23 | --EXPECT-- 24 | SUCCESS 25 | -------------------------------------------------------------------------------- /librsync/libversions.txt: -------------------------------------------------------------------------------- 1 | libtool versions for librsync 2 | 3 | So, libtool library versions are described by three integers: 4 | 5 | CURRENT 6 | The most recent interface number that this library implements. 7 | 8 | REVISION 9 | The implementation number of the CURRENT interface. 10 | 11 | AGE 12 | The difference between the newest and oldest interfaces that this 13 | library implements. In other words, the library implements all the 14 | interface numbers in the range from number `CURRENT - AGE' to 15 | `CURRENT'. 16 | 17 | RELEASE CURRENT REVISION AGE COMMENTS 18 | 0.5.6 0 0 0 direct-IO api 19 | 0.9.0 1 0 0 zlib-style state machine 20 | 0.9.3 1 1 0 rearrange buffers code 21 | 0.9.4 1 1 0 22 | 0.9.5 1 1 0 23 | 0.9.6 1 2 0 refined and debugged 24 | -------------------------------------------------------------------------------- /tests/007.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test function rsync_patch_file with stream as input and output. 3 | --SKIPIF-- 4 | 7 | --FILE-- 8 | 26 | --EXPECT-- 27 | SUCCESS 28 | -------------------------------------------------------------------------------- /librsync/popt/README: -------------------------------------------------------------------------------- 1 | This is the popt command line option parsing library. While it is similiar 2 | to getopt(3), it contains a number of enhancements, including: 3 | 4 | 1) popt is fully reentrant 5 | 2) popt can parse arbitrary argv[] style arrays while 6 | getopt(2) makes this quite difficult 7 | 3) popt allows users to alias command line arguments 8 | 4) popt provides convience functions for parsting strings 9 | into argv[] style arrays 10 | 11 | popt is used by rpm, the Red Hat install program, and many other Red Hat 12 | utilities, all of which provide excellent examples of how to use popt. 13 | Complete documentation on popt is available in popt.ps (included in this 14 | tarball), which is excerpted with permission from the book "Linux 15 | Application Development" by Michael K. Johnson and Erik Troan (availble 16 | from Addison Wesley in May, 1998). 17 | 18 | Comments on popt should be addressed to ewt@redhat.com. 19 | -------------------------------------------------------------------------------- /librsync/whole.h: -------------------------------------------------------------------------------- 1 | /*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- 2 | * 3 | * librsync -- the library for network deltas 4 | * $Id: whole.h,v 1.4 2001/03/05 07:09:34 mbp Exp $ 5 | * 6 | * Copyright (C) 2001 by Martin Pool 7 | * 8 | * This program is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public License 10 | * as published by the Free Software Foundation; either version 2.1 of 11 | * the License, or (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | * Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 | */ 22 | 23 | 24 | rs_result rs_whole_run(rs_job_t *job, FILE *in_file, FILE *out_file); 25 | -------------------------------------------------------------------------------- /librsync/fileutil.h: -------------------------------------------------------------------------------- 1 | /*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- * 2 | * 3 | * librsync -- library for network deltas 4 | * $Id: fileutil.h,v 1.11 2003/03/19 05:21:50 abo Exp $ 5 | * 6 | * Copyright (C) 2000, 2001 by Martin Pool 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation; either version 2.1 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 | */ 22 | 23 | FILE * rs_file_open(char const *filename, char const * mode); 24 | int rs_file_close(FILE * file); 25 | -------------------------------------------------------------------------------- /librsync/popt/findme.c: -------------------------------------------------------------------------------- 1 | /* (C) 1998 Red Hat Software, Inc. -- Licensing details are in the COPYING 2 | file accompanying popt source distributions, available from 3 | ftp://ftp.redhat.com/pub/code/popt */ 4 | 5 | #include "system.h" 6 | #include "findme.h" 7 | 8 | const char * findProgramPath(const char * argv0) { 9 | char * path = getenv("PATH"); 10 | char * pathbuf; 11 | char * start, * chptr; 12 | char * buf; 13 | 14 | /* If there is a / in the argv[0], it has to be an absolute 15 | path */ 16 | if (strchr(argv0, '/')) 17 | return xstrdup(argv0); 18 | 19 | if (!path) return NULL; 20 | 21 | start = pathbuf = alloca(strlen(path) + 1); 22 | buf = malloc(strlen(path) + strlen(argv0) + 2); 23 | strcpy(pathbuf, path); 24 | 25 | chptr = NULL; 26 | do { 27 | if ((chptr = strchr(start, ':'))) 28 | *chptr = '\0'; 29 | sprintf(buf, "%s/%s", start, argv0); 30 | 31 | if (!access(buf, X_OK)) 32 | return buf; 33 | 34 | if (chptr) 35 | start = chptr + 1; 36 | else 37 | start = NULL; 38 | } while (start && *start); 39 | 40 | free(buf); 41 | 42 | return NULL; 43 | } 44 | -------------------------------------------------------------------------------- /librsync/isprefix.h: -------------------------------------------------------------------------------- 1 | /*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- 2 | * librsync -- dynamic caching and delta update in HTTP 3 | * $Id: isprefix.h,v 1.5 2001/03/05 07:09:37 mbp Exp $ 4 | * 5 | * Copyright (C) 2000, 2001 by Martin Pool 6 | * 7 | * This program is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public License 9 | * as published by the Free Software Foundation; either version 2.1 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, but 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 | */ 21 | 22 | 23 | /* 24 | * Return true if TIP is a prefix of ICEBERG. 25 | */ 26 | int isprefix(char const *tip, char const *iceberg); 27 | -------------------------------------------------------------------------------- /tests/008.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test function rsync_patch_file with stream as input and output. 3 | --SKIPIF-- 4 | 5 | --FILE-- 6 | 22 | --EXPECT-- 23 | OK 24 | blocked waiting for input or output buffers 25 | still running 26 | unexplained problem 27 | IO error 28 | bad command line syntax 29 | out of memory 30 | unexpected end of input 31 | bad magic number at start of stream 32 | unimplemented case 33 | stream corrupt 34 | library internal error 35 | unexplained problem 36 | OK 37 | -------------------------------------------------------------------------------- /librsync/testsuite/changes.test: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | # librsync -- the library for network deltas 4 | # $Id: changes.test,v 1.1 2002/01/25 21:08:26 bje Exp $ 5 | # 6 | # Copyright (C) 2001 by Martin Pool 7 | # 8 | # This program is free software; you can redistribute it and/or 9 | # modify it under the terms of the GNU Lesser General Public License 10 | # as published by the Free Software Foundation; either version 2.1 of 11 | # the License, or (at your option) any later version. 12 | # 13 | # This program is distributed in the hope that it will be useful, but 14 | # WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | # Lesser General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU Lesser General Public 19 | # License along with this program; if not, write to the Free Software 20 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 | 22 | for buf in $bufsizes 23 | do 24 | old=$testdir/01.in 25 | for new in $testdir/*.in 26 | do 27 | triple_test $buf $old $new 28 | triple_test $buf $new $old 29 | done 30 | done 31 | -------------------------------------------------------------------------------- /librsync/testsuite/mksum.test: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | # librsync -- the library for network deltas 4 | # $Id: mksum.test,v 1.2 2003/03/20 15:10:13 abo Exp $ 5 | # 6 | # Copyright (C) 2000, 2001 by Martin Pool 7 | # 8 | # This program is free software; you can redistribute it and/or 9 | # modify it under the terms of the GNU Lesser General Public License 10 | # as published by the Free Software Foundation; either version 2.1 of 11 | # the License, or (at your option) any later version. 12 | # 13 | # This program is distributed in the hope that it will be useful, but 14 | # WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | # Lesser General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU Lesser General Public 19 | # License along with this program; if not, write to the Free Software 20 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 | 22 | sig=$tmpdir/sig.tmp 23 | expect=$testdir/COPYING.sig 24 | input=$srcdir/../COPYING 25 | 26 | for inbuf in $bufsizes 27 | do 28 | cmd="../rdiff -I$inbuf signature $input $sig" 29 | run_test $cmd 30 | check_compare $sig $expect "$cmd" 31 | countdown 32 | done 33 | -------------------------------------------------------------------------------- /librsync/version.c: -------------------------------------------------------------------------------- 1 | /*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- 2 | * 3 | * librsync -- dynamic caching and delta update in HTTP 4 | * $Id: version.c,v 1.10 2003/06/12 05:47:23 wayned Exp $ 5 | * 6 | * Copyright (C) 2000, 2001 by Martin Pool 7 | * 8 | * This program is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public License 10 | * as published by the Free Software Foundation; either version 2.1 of 11 | * the License, or (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | * Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 | */ 22 | 23 | #include 24 | 25 | #include 26 | 27 | #include "librsync.h" 28 | 29 | 30 | /** \brief Library version string. */ 31 | char const rs_librsync_version[] = (PACKAGE " " VERSION); 32 | 33 | 34 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010, Michele Catalano 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 5 | 6 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 7 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 8 | 9 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /librsync/search.h: -------------------------------------------------------------------------------- 1 | /*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- 2 | * 3 | * librsync -- the library for network deltas 4 | * $Id: search.h,v 1.17 2001/03/05 07:09:35 mbp Exp $ 5 | * 6 | * Copyright (C) 1999, 2000 by Martin Pool 7 | * Copyright (C) 1999 by Andrew Tridgell 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as published by 11 | * the Free Software Foundation; either version 2.1 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 22 | */ 23 | 24 | int 25 | rs_search_for_block(rs_weak_sum_t weak_sum, 26 | char const *inbuf, size_t block_len, 27 | rs_signature_t const *sums, rs_stats_t * stats, 28 | rs_long_t * match_where); 29 | 30 | -------------------------------------------------------------------------------- /librsync/emit.h: -------------------------------------------------------------------------------- 1 | /*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- 2 | * 3 | * librsync -- dynamic caching and delta update in HTTP 4 | * $Id: emit.h,v 1.22 2001/03/12 03:28:23 mbp Exp $ 5 | * 6 | * Copyright (C) 2000, 2001 by Martin Pool 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation; either version 2.1 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 | */ 22 | 23 | 24 | /* 25 | * emit.h -- How to emit commands to the client 26 | */ 27 | 28 | 29 | void rs_emit_delta_header(rs_job_t *); 30 | void rs_emit_literal_cmd(rs_job_t *, int len); 31 | void rs_emit_end_cmd(rs_job_t *); 32 | void rs_emit_copy_cmd(rs_job_t *job, rs_long_t where, rs_long_t len); 33 | -------------------------------------------------------------------------------- /librsync/testsuite/signature.test: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | # librsync -- the library for network deltas 4 | # $Id: signature.test,v 1.1 2002/01/25 21:08:26 bje Exp $ 5 | # 6 | # Copyright (C) 2001 by Martin Pool 7 | # 8 | # This program is free software; you can redistribute it and/or 9 | # modify it under the terms of the GNU Lesser General Public License 10 | # as published by the Free Software Foundation; either version 2.1 of 11 | # the License, or (at your option) any later version. 12 | # 13 | # This program is distributed in the hope that it will be useful, but 14 | # WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | # Lesser General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU Lesser General Public 19 | # License along with this program; if not, write to the Free Software 20 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 | 22 | new=$tmpdir/signature 23 | 24 | for input in "$testdir"/*.in 25 | do 26 | for inbuf in $bufsizes 27 | do 28 | expect=`echo $input | sed -e 's/.in$/.sig/'` 29 | run_test ../rdiff -I$inbuf signature "$input" "$new" 30 | cmp "$expect" "$new" || fail_test "signature -I$inbuf $input" 31 | countdown 32 | done 33 | done 34 | -------------------------------------------------------------------------------- /librsync/buf.h: -------------------------------------------------------------------------------- 1 | /*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- 2 | * 3 | * librsync -- the library for network deltas 4 | * $Id: buf.h,v 1.8 2001/03/18 02:05:33 mbp Exp $ 5 | * 6 | * Copyright (C) 2000, 2001 by Martin Pool 7 | * 8 | * This program is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public License 10 | * as published by the Free Software Foundation; either version 2.1 of 11 | * the License, or (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | * Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 | */ 22 | 23 | typedef struct rs_filebuf rs_filebuf_t; 24 | 25 | rs_filebuf_t *rs_filebuf_new(FILE *f, size_t buf_len); 26 | 27 | void rs_filebuf_free(rs_filebuf_t *fb); 28 | 29 | rs_result rs_infilebuf_fill(rs_job_t *, rs_buffers_t *buf, void *fb); 30 | 31 | rs_result rs_outfilebuf_drain(rs_job_t *, rs_buffers_t *, void *fb); 32 | -------------------------------------------------------------------------------- /librsync/isprefix.c: -------------------------------------------------------------------------------- 1 | /*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- 2 | * librsync -- dynamic caching and delta update in HTTP 3 | * $Id: isprefix.c,v 1.5 2001/03/05 07:09:37 mbp Exp $ 4 | * 5 | * Copyright (C) 2000, 2001 by Martin Pool 6 | * 7 | * This program is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public License 9 | * as published by the Free Software Foundation; either version 2.1 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, but 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 | */ 21 | 22 | 23 | #include "isprefix.h" 24 | 25 | /** 26 | * Return true if TIP is a prefix of ICEBERG. 27 | */ 28 | int 29 | isprefix(char const *tip, char const *iceberg) 30 | { 31 | while (*tip) { 32 | if (*tip != *iceberg) 33 | return 0; 34 | tip++; iceberg++; 35 | } 36 | 37 | return 1; 38 | } 39 | -------------------------------------------------------------------------------- /librsync/checksum.h: -------------------------------------------------------------------------------- 1 | /*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- 2 | * 3 | * librsync -- the library for network deltas 4 | * $Id: checksum.h,v 1.17 2001/03/18 10:56:39 mbp Exp $ 5 | * 6 | * Copyright (C) 2000, 2001 by Martin Pool 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation; either version 2.1 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 | */ 22 | 23 | rs_weak_sum_t rs_calc_weak_sum(void const *buf1, int len); 24 | 25 | void rs_calc_strong_sum(void const *buf, size_t buf_len, rs_strong_sum_t *); 26 | 27 | /* We should make this something other than zero to improve the 28 | * checksum algorithm: tridge suggests a prime number. */ 29 | #define RS_CHAR_OFFSET 31 30 | 31 | -------------------------------------------------------------------------------- /librsync/popt/COPYING: -------------------------------------------------------------------------------- 1 | Copyright (c) 1998 Red Hat Software 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 17 | AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | 20 | Except as contained in this notice, the name of the X Consortium shall not be 21 | used in advertising or otherwise to promote the sale, use or other dealings 22 | in this Software without prior written authorization from the X Consortium. 23 | -------------------------------------------------------------------------------- /librsync/testsuite/delta.test: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | # librsync -- the library for network deltas 4 | # $Id: delta.test,v 1.3 2003/03/26 14:41:53 abo Exp $ 5 | # 6 | # Copyright (C) 1999, 2000, 2001 by Martin Pool 7 | # Copyright (C) 1999 by Andrew Tridgell 8 | # 9 | # This program is free software; you can redistribute it and/or 10 | # modify it under the terms of the GNU Lesser General Public License 11 | # as published by the Free Software Foundation; either version 2.1 of 12 | # the License, or (at your option) any later version. 13 | # 14 | # This program is distributed in the hope that it will be useful, but 15 | # WITHOUT ANY WARRANTY; without even the implied warranty of 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | # Lesser General Public License for more details. 18 | # 19 | # You should have received a copy of the GNU Lesser General Public 20 | # License along with this program; if not, write to the Free Software 21 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 22 | 23 | new=$tmpdir/delta.tmp 24 | 25 | for delta in $testdir/*.delta 26 | do 27 | for inbuf in $bufsizes 28 | do 29 | cmd="../rdiff -I$inbuf patch /dev/null $delta $new" 30 | run_test $cmd 31 | expect=$testdir/`basename $delta .delta`.expect 32 | diff $expect $new || fail_test "$cmd" 33 | countdown 34 | done 35 | done 36 | -------------------------------------------------------------------------------- /librsync/popt/CHANGES: -------------------------------------------------------------------------------- 1 | 1.3 -> 2 | - heavy dose of const's 3 | - poptParseArgvString() now NULL terminates the list 4 | 5 | 1.2.3 -> 1.3 6 | - added support for single - 7 | - misc bug fixes 8 | - portability improvements 9 | 10 | 1.2.2 -> 1.2.3 11 | - fixed memset() in help message generation (Dale Hawkins) 12 | - added extern "C" stuff to popt.h for C++ compilers (Dale Hawkins) 13 | - const'ified poptParseArgvString (Jeff Garzik) 14 | 15 | 1.2.1 -> 1.2.2 16 | - fixed bug in chaind alias happens which seems to have only 17 | affected --triggers in rpm 18 | - added POPT_ARG_VAL 19 | - popt.3 installed by default 20 | 21 | 1.2 -> 1.2.1 22 | - added POPT_ARG_INTL_DOMAIN (Elliot Lee) 23 | - updated Makefile's to be more GNUish (Elliot Lee) 24 | 25 | 1.1 -> 1.2 26 | - added popt.3 man page (Robert Lynch) 27 | - don't use mmap anymore (its lack of portability isn't worth the 28 | trouble) 29 | - added test script 30 | - added support for exec 31 | - removed support for *_POPT_ALIASES env variable -- it was a bad 32 | idea 33 | - reorganized into multiple source files 34 | - added automatic help generation, POPT_AUTOHELP 35 | - added table callbacks 36 | - added table inclusion 37 | - updated man page for new features 38 | - added test scripts 39 | 40 | 1.0 -> 1.1 41 | - moved to autoconf (Fred Fish) 42 | - added STRERROR replacement (Norbert Warmuth) 43 | - added const keywords (Bruce Perens) 44 | -------------------------------------------------------------------------------- /librsync/testsuite/sources.test: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | # librsync -- the library for network deltas 4 | # $Id: sources.test,v 1.1 2002/01/25 21:08:26 bje Exp $ 5 | # 6 | # Copyright (C) 2001 by Martin Pool 7 | # 8 | # This program is free software; you can redistribute it and/or 9 | # modify it under the terms of the GNU Lesser General Public License 10 | # as published by the Free Software Foundation; either version 2.1 of 11 | # the License, or (at your option) any later version. 12 | # 13 | # This program is distributed in the hope that it will be useful, but 14 | # WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | # Lesser General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU Lesser General Public 19 | # License along with this program; if not, write to the Free Software 20 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 | 22 | block_len=200 23 | for buf in $bufsizes 24 | do 25 | for old in $srcdir/*.[ch] 26 | do 27 | for new in $old $old*~ 28 | do 29 | test ! -r $new && continue 30 | test ! -r $old && continue 31 | test -n "$stats" && echo $old $new 32 | triple_test $buf $old $new 33 | triple_test $buf $new $old 34 | countdown 35 | done 36 | done 37 | done 38 | -------------------------------------------------------------------------------- /librsync/mdfour.h: -------------------------------------------------------------------------------- 1 | /*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- 2 | * 3 | * librsync -- the library for network deltas 4 | * $Id: mdfour.h,v 1.7 2003/10/17 16:15:21 abo Exp $ 5 | * 6 | * Copyright (C) 2000, 2001 by Martin Pool 7 | * Copyright (C) 2002, 2003 by Donovan Baarda 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU Lesser General Public License 11 | * as published by the Free Software Foundation; either version 2.1 of 12 | * the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, but 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 22 | */ 23 | 24 | #include "types.h" 25 | 26 | struct rs_mdfour { 27 | int A, B, C, D; 28 | #if HAVE_UINT64 29 | uint64_t totalN; 30 | #else 31 | uint32_t totalN_hi, totalN_lo; 32 | #endif 33 | int tail_len; 34 | unsigned char tail[64]; 35 | }; 36 | -------------------------------------------------------------------------------- /librsync/netint.h: -------------------------------------------------------------------------------- 1 | /*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- 2 | * 3 | * librsync -- library for network deltas 4 | * $Id: netint.h,v 1.15 2001/03/05 14:08:36 mbp Exp $ 5 | * 6 | * Copyright (C) 1999, 2000, 2001 by Martin Pool 7 | * Copyright (C) 1999 by Andrew Tridgell 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as published by 11 | * the Free Software Foundation; either version 2.1 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 22 | */ 23 | 24 | rs_result rs_squirt_byte(rs_job_t *, unsigned char d); 25 | rs_result rs_squirt_netint(rs_job_t *, rs_long_t d, int len); 26 | rs_result rs_squirt_n4(rs_job_t *, int val); 27 | 28 | rs_result rs_suck_netint(rs_job_t *, rs_long_t *v, int len); 29 | rs_result rs_suck_byte(rs_job_t *, unsigned char *); 30 | rs_result rs_suck_n4(rs_job_t *, int *); 31 | 32 | int rs_int_len(rs_long_t val); 33 | -------------------------------------------------------------------------------- /librsync/testsuite/triple.test: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | # librsync -- the library for network deltas 4 | # $Id: triple.test,v 1.1 2002/01/25 21:08:26 bje Exp $ 5 | # 6 | # Copyright (C) 2001 by Martin Pool 7 | # 8 | # This program is free software; you can redistribute it and/or 9 | # modify it under the terms of the GNU Lesser General Public License 10 | # as published by the Free Software Foundation; either version 2.1 of 11 | # the License, or (at your option) any later version. 12 | # 13 | # This program is distributed in the hope that it will be useful, but 14 | # WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | # Lesser General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU Lesser General Public 19 | # License along with this program; if not, write to the Free Software 20 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 | 22 | for buf in $bufsizes 23 | do 24 | for old in $testdir/*.in 25 | do 26 | for new in $testdir/*.in 27 | do 28 | run_test ../rdiff $debug -I$buf -O$buf signature $old $tmpdir/sig 29 | run_test ../rdiff $debug -I$buf -O$buf delta $tmpdir/sig $new $tmpdir/delta 30 | run_test ../rdiff $debug -I$buf -O$buf patch $old $tmpdir/delta $tmpdir/new 31 | 32 | check_compare $new $tmpdir/new "triple -I$buf -O$buf $old $new" 33 | 34 | countdown 35 | done 36 | done 37 | done 38 | -------------------------------------------------------------------------------- /librsync/PCbuild/librsync-config.h: -------------------------------------------------------------------------------- 1 | /*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- 2 | * 3 | * librsync -- library for network deltas 4 | * 5 | * Copyright (C) 2000, 2001 by Martin Pool 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation; either version 2.1 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 | */ 21 | 22 | /** \file librsync-config.h 23 | * 24 | * \brief System-specific configuration for librsync.h. 25 | */ 26 | 27 | #ifndef _LIBRSYNC_CONFIG_H 28 | #define _LIBRSYNC_CONFIG_H 29 | 30 | /** 31 | * \brief A long integer type that can handle the largest file 32 | * offsets. 33 | * 34 | * Perhaps this might have to be configured to be 'long long', 'long', 35 | * or something else depending on the platform. On WIN32, many config.h's 36 | * define LONG_LONG as "__int64". 37 | */ 38 | typedef long rs_long_t; 39 | 40 | #endif /* _LIBRSYNC_CONFIG_H */ 41 | -------------------------------------------------------------------------------- /librsync/librsync-config.h.in: -------------------------------------------------------------------------------- 1 | /*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- 2 | * 3 | * librsync -- library for network deltas 4 | * 5 | * Copyright (C) 2000, 2001 by Martin Pool 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation; either version 2.1 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 | */ 21 | 22 | /** \file librsync-config.h 23 | * 24 | * \brief System-specific configuration for librsync.h. 25 | */ 26 | 27 | #ifndef _LIBRSYNC_CONFIG_H 28 | #define _LIBRSYNC_CONFIG_H 29 | 30 | /** 31 | * \brief A long integer type that can handle the largest file 32 | * offsets. 33 | * 34 | * Perhaps this might have to be configured to be 'long long', 'long', 35 | * or something else depending on the platform. On WIN32, many config.h's 36 | * define LONG_LONG as "__int64". 37 | */ 38 | typedef @RS_LONG_T@ rs_long_t; 39 | 40 | #endif /* _LIBRSYNC_CONFIG_H */ 41 | -------------------------------------------------------------------------------- /librsync/popt/system.h: -------------------------------------------------------------------------------- 1 | #ifdef HAVE_CONFIG_H 2 | #include "config.h" 3 | #endif 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #if HAVE_MCHECK_H 11 | #include 12 | #endif 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | #if HAVE_UNISTD_H 19 | #include 20 | #endif 21 | 22 | #ifdef _WIN32 23 | #include 24 | #include 25 | #define getuid() 0 26 | #define geteuid() 0 27 | #endif 28 | 29 | #ifdef __NeXT 30 | /* access macros are not declared in non posix mode in unistd.h - 31 | don't try to use posix on NeXTstep 3.3 ! */ 32 | #include 33 | #endif 34 | 35 | /* AIX requires this to be the first thing in the file. */ 36 | #ifndef __GNUC__ 37 | # if HAVE_ALLOCA_H 38 | # include 39 | # else 40 | # ifdef _AIX 41 | #pragma alloca 42 | # else 43 | # ifndef alloca /* predefined by HP cc +Olibcalls */ 44 | char *alloca (); 45 | # endif 46 | # endif 47 | # endif 48 | #elif defined(__GNUC__) && defined(__STRICT_ANSI__) 49 | #define alloca __builtin_alloca 50 | #endif 51 | 52 | #ifndef X_OK 53 | #define X_OK 1 54 | #endif 55 | 56 | /*@only@*/ char * xstrdup (const char *str); 57 | 58 | #if HAVE_MCHECK_H && defined(__GNUC__) 59 | #define vmefail() (fprintf(stderr, "virtual memory exhausted.\n"), exit(EXIT_FAILURE), NULL) 60 | #define xstrdup(_str) (strcpy((malloc(strlen(_str)+1) ? : vmefail()), (_str))) 61 | #else 62 | #define xstrdup(_str) strdup(_str) 63 | #endif /* HAVE_MCHECK_H && defined(__GNUC__) */ 64 | 65 | 66 | #include "popt.h" 67 | -------------------------------------------------------------------------------- /librsync/hex.c: -------------------------------------------------------------------------------- 1 | /*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- 2 | * rproxy -- dynamic caching and delta update in HTTP 3 | * $Id: hex.c,v 1.19 2003/06/12 05:47:22 wayned Exp $ 4 | * 5 | * Copyright (C) 2000, 2001 by Martin Pool 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation; either version 2.1 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 | */ 21 | 22 | #include 23 | 24 | #include 25 | #include 26 | #ifdef HAVE_INTTYPES_H 27 | #include 28 | #endif 29 | #include 30 | #include 31 | 32 | #include "librsync.h" 33 | 34 | 35 | void 36 | rs_hexify(char *to_buf, void const *from, int from_len) 37 | { 38 | static const char hex_chars[] = "0123456789abcdef"; 39 | unsigned char const *from_buf = (unsigned char const *) from; 40 | 41 | while (from_len-- > 0) { 42 | *(to_buf++) = hex_chars[((*from_buf) >> 4) & 0xf]; 43 | *(to_buf++) = hex_chars[(*from_buf) & 0xf]; 44 | from_buf++; 45 | } 46 | 47 | *to_buf = 0; 48 | } 49 | -------------------------------------------------------------------------------- /librsync/util.h: -------------------------------------------------------------------------------- 1 | /*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- 2 | * 3 | * librsync -- library for network deltas 4 | * $Id: util.h,v 1.14 2001/03/12 02:23:09 mbp Exp $ 5 | * 6 | * Copyright (C) 1999, 2000, 2001 by Martin Pool 7 | * Copyright (C) 1999 by Andrew Tridgell 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU Lesser General Public License 11 | * as published by the Free Software Foundation; either version 2.1 of 12 | * the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, but 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 22 | */ 23 | 24 | 25 | void * rs_alloc(size_t size, char const *name); 26 | void *rs_alloc_struct0(size_t size, char const *name); 27 | 28 | void rs_bzero(void *buf, size_t size); 29 | 30 | 31 | /* 32 | * Allocate and zero-fill an instance of TYPE. 33 | */ 34 | #define rs_alloc_struct(type) \ 35 | ((type *) rs_alloc_struct0(sizeof(type), #type)) 36 | 37 | 38 | #ifdef __GNUC__ 39 | # define UNUSED(x) x __attribute__((unused)) 40 | #elif __LCLINT__ 41 | # define UNUSED(x) /*@unused@*/ x 42 | #else /* !__GNUC__ && !__LCLINT__ */ 43 | # define UNUSED(x) x 44 | #endif /* !__GNUC__ && !__LCLINT__ */ 45 | -------------------------------------------------------------------------------- /librsync/testsuite/mutate.test: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | # librsync -- the library for network deltas 4 | # $Id: mutate.test,v 1.1 2002/01/25 21:08:26 bje Exp $ 5 | # 6 | # Copyright (C) 2001 by Martin Pool 7 | # 8 | # This program is free software; you can redistribute it and/or 9 | # modify it under the terms of the GNU Lesser General Public License 10 | # as published by the Free Software Foundation; either version 2.1 of 11 | # the License, or (at your option) any later version. 12 | # 13 | # This program is distributed in the hope that it will be useful, but 14 | # WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | # Lesser General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU Lesser General Public 19 | # License along with this program; if not, write to the Free Software 20 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 | 22 | old=$srcdir/COPYING 23 | 24 | if which perl >/dev/null 25 | then 26 | : 27 | else 28 | echo "Skipped because perl was not found"; 29 | exit 77; 30 | fi 31 | 32 | old="$tmpdir/old" 33 | cat $srcdir/*.[ch] >"$old" 34 | new="$tmpdir/new" 35 | sig="$tmpdir/sig" 36 | delta="$tmpdir/delta" 37 | out="$tmpdir/out" 38 | i=0 39 | 40 | while test $i -lt 100 41 | do 42 | perl "$srcdir/mutate.pl" $i 5 <"$old" >"$new" 2>>"$tmpdir/mutate.log" 43 | 44 | run_test ../rdiff $debug signature $old $sig 45 | run_test ../rdiff $debug delta $sig $new $delta 46 | run_test ../rdiff $debug patch $old $delta "$out" 47 | 48 | check_compare "$new" "$out" "mutate $i $old $new" 49 | 50 | i=`expr $i + 1` 51 | countdown 52 | done 53 | true 54 | -------------------------------------------------------------------------------- /librsync/testsuite/isprefix.driver.c: -------------------------------------------------------------------------------- 1 | /*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- 2 | * librsync -- dynamic caching and delta update in HTTP 3 | * $Id: isprefix.driver.c,v 1.1 2002/01/25 21:08:26 bje Exp $ 4 | * 5 | * Copyright (C) 2000 by Martin Pool 6 | * 7 | * This program is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public License 9 | * as published by the Free Software Foundation; either version 2.1 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, but 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 | */ 21 | 22 | #include 23 | #include 24 | 25 | #include "isprefix.h" 26 | 27 | static void usage(void) 28 | { 29 | fprintf(stderr, "Usage: isprefix.driver TIP ICEBERG\n"); 30 | exit(2); 31 | } 32 | 33 | /* 34 | * Test driver for isprefix. Compares the two parameters; returns 35 | * true (0) if a prefix, false (1) otherwise. 36 | */ 37 | int main(int argc, char **argv) 38 | { 39 | if (argc < 3) { 40 | usage(); 41 | } 42 | 43 | if (strcmp(argv[1], "!")) { 44 | return !isprefix(argv[1], argv[2]); 45 | } else { 46 | /* inverted */ 47 | if (argc < 4) { 48 | usage(); 49 | } 50 | return isprefix(argv[2], argv[3]); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /examples/logger.php: -------------------------------------------------------------------------------- 1 | logfile = $logfile; 56 | } 57 | 58 | /** 59 | * Logging method where will be register as callback in the 60 | * php_rsync extension. 61 | * 62 | * @param int $level Logging level. 63 | * @param string $message Logging message. 64 | */ 65 | public function log($level, $message) 66 | { 67 | $msg = $level." : ".$message."\n"; 68 | $type = 3; 69 | if ($logfile == null) { 70 | $type = 0; 71 | } 72 | error_log($message, $type, $this->logfile); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /librsync/types.h: -------------------------------------------------------------------------------- 1 | /*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- 2 | * 3 | * librsync -- the library for network deltas 4 | * $Id: types.h,v 1.2 2002/06/29 19:47:42 wayned Exp $ 5 | * 6 | * Copyright (C) 2001 by Martin Pool 7 | * 8 | * This program is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public License 10 | * as published by the Free Software Foundation; either version 2.1 of 11 | * the License, or (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | * Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 | */ 22 | 23 | #define HAVE_UINT64 1 /* assume success, but might be undefined below */ 24 | 25 | #if defined(HAVE_STDINT_H) 26 | # include 27 | #else 28 | # if SIZEOF_UNSIGNED_INT == 4 29 | # define uint32_t unsigned int 30 | # elif SIZEOF_UNSIGNED_LONG == 4 31 | # define uint32_t unsigned long 32 | # elif SIZEOF_UNSIGNED_SHORT == 4 33 | # define uint32_t unsigned short 34 | # else 35 | # error "can't find an appropriate 32-bit integer type" 36 | # endif 37 | # if SIZEOF_UNSIGNED_INT == 8 38 | # define uint64_t unsigned int 39 | # elif SIZEOF_UNSIGNED_LONG == 8 40 | # define uint64_t unsigned long 41 | # elif SIZEOF_UNSIGNED_SHORT == 8 42 | # define uint64_t unsigned short 43 | # elif SIZEOF_LONG_LONG == 8 44 | # define uint64_t unsigned long long 45 | # else 46 | # undef HAVE_UINT64 47 | # endif 48 | #endif 49 | -------------------------------------------------------------------------------- /librsync/util.c: -------------------------------------------------------------------------------- 1 | /*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- 2 | * 3 | * librsync -- the library for network deltas 4 | * $Id: util.c,v 1.20 2003/06/12 05:47:23 wayned Exp $ 5 | * 6 | * Copyright (C) 2000, 2001 by Martin Pool 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation; either version 2.1 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 | */ 22 | 23 | 24 | /* 25 | | On heroin, I have all the answers. 26 | */ 27 | 28 | 29 | #include 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | #include "util.h" 36 | #include "librsync.h" 37 | #include "trace.h" 38 | 39 | void 40 | rs_bzero(void *buf, size_t size) 41 | { 42 | memset(buf, 0, size); 43 | } 44 | 45 | 46 | void * 47 | rs_alloc_struct0(size_t size, char const *name) 48 | { 49 | void *p; 50 | 51 | if (!(p = malloc(size))) { 52 | rs_fatal("couldn't allocate instance of %s", name); 53 | } 54 | rs_bzero(p, size); 55 | return p; 56 | } 57 | 58 | 59 | 60 | void * 61 | rs_alloc(size_t size, char const *name) 62 | { 63 | void *p; 64 | 65 | if (!(p = malloc(size))) { 66 | rs_fatal("couldn't allocate instance of %s", name); 67 | } 68 | 69 | return p; 70 | } 71 | -------------------------------------------------------------------------------- /librsync/command.c: -------------------------------------------------------------------------------- 1 | /*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- 2 | * 3 | * librsync -- the library for network deltas 4 | * $Id: command.c,v 1.8 2003/06/12 05:47:21 wayned Exp $ 5 | * 6 | * Copyright (C) 2000 by Martin Pool 7 | * 8 | * This program is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public License 10 | * as published by the Free Software Foundation; either version 2.1 of 11 | * the License, or (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | * Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 | */ 22 | 23 | 24 | #include 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | #include "librsync.h" 31 | #include "command.h" 32 | 33 | /* For debugging purposes, here are some human-readable forms. */ 34 | struct rs_op_kind_name const rs_op_kind_names[] = { 35 | {"END", RS_KIND_END }, 36 | {"COPY", RS_KIND_COPY }, 37 | {"LITERAL", RS_KIND_LITERAL }, 38 | {"SIGNATURE", RS_KIND_SIGNATURE }, 39 | {"CHECKSUM", RS_KIND_CHECKSUM }, 40 | {"INVALID", RS_KIND_INVALID }, 41 | {NULL, 0 } 42 | }; 43 | 44 | 45 | /* 46 | * Return a human-readable name for KIND. 47 | */ 48 | char const * rs_op_kind_name(enum rs_op_kind kind) 49 | { 50 | const struct rs_op_kind_name *k; 51 | 52 | for (k = rs_op_kind_names; k->kind; k++) { 53 | if (k->kind == kind) { 54 | return k->name; 55 | } 56 | } 57 | 58 | return NULL; 59 | } 60 | 61 | 62 | -------------------------------------------------------------------------------- /librsync/protocol.h: -------------------------------------------------------------------------------- 1 | /*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- 2 | * 3 | * librsync -- library for network deltas 4 | * $Id: protocol.h,v 1.10 2001/03/05 14:08:36 mbp Exp $ 5 | * 6 | * Copyright (C) 1999, 2000, 2001 by Martin Pool 7 | * Copyright (C) 1999 by Andrew Tridgell 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU Lesser General Public License 11 | * as published by the Free Software Foundation; either version 2.1 of 12 | * the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ 22 | 23 | 24 | /* 25 | * TODO: Have a way to copy from the old signature into the new 26 | * one. This will be useful for the case where the files are in fact 27 | * identical, which will be significantly common. 28 | */ 29 | 30 | 31 | /* 32 | | "The IETF already has more than enough 33 | | RFCs that codify the obvious, make 34 | | stupidity illegal, support truth, 35 | | justice, and the IETF way, and generally 36 | | demonstrate the author is a brilliant and 37 | | valuable Contributor to The Standards 38 | | Process." 39 | | -- Vernon Schryver 40 | */ 41 | 42 | 43 | 44 | #define RS_DELTA_MAGIC 0x72730236 /* r s \2 6 */ 45 | #define RS_SIG_MAGIC 0x72730136 /* r s \1 6 */ 46 | -------------------------------------------------------------------------------- /librsync/command.h: -------------------------------------------------------------------------------- 1 | /*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- 2 | * 3 | * librsync -- library for network deltas 4 | * $Id: command.h,v 1.10 2001/03/05 14:08:37 mbp Exp $ 5 | * 6 | * Copyright (C) 1999, 2000, 2001 by Martin Pool 7 | * Copyright (C) 1999 by Andrew Tridgell 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU Lesser General Public License 11 | * as published by the Free Software Foundation; either version 2.1 of 12 | * the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, but 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 22 | */ 23 | 24 | 25 | /* 26 | * command.h -- Types of commands present in the encoding stream. 27 | * 28 | * The vague idea is that eventually this file will be more abstract 29 | * than protocol.h, but it's not clear that will ever be required. 30 | */ 31 | 32 | 33 | /** 34 | * Classes of operation that can be present. Each may have several different 35 | * possible representations. 36 | */ 37 | enum rs_op_kind { 38 | RS_KIND_END = 1000, 39 | RS_KIND_LITERAL, 40 | RS_KIND_SIGNATURE, 41 | RS_KIND_COPY, 42 | RS_KIND_CHECKSUM, 43 | RS_KIND_RESERVED, /* for future expansion */ 44 | 45 | /* This one should never occur in file streams. It's an 46 | * internal marker for invalid commands. */ 47 | RS_KIND_INVALID 48 | }; 49 | 50 | 51 | typedef struct rs_op_kind_name { 52 | char const *name; 53 | enum rs_op_kind const kind; 54 | } rs_op_kind_name_t; 55 | 56 | char const * rs_op_kind_name(enum rs_op_kind); 57 | 58 | 59 | -------------------------------------------------------------------------------- /librsync/doc/rdiff.1: -------------------------------------------------------------------------------- 1 | .\" 2 | .\" librsync -- dynamic caching and delta update in HTTP 3 | .\" $Id: rdiff.1,v 1.1 2002/01/25 21:25:34 bje Exp $ 4 | .\" 5 | .\" Copyright (C) 2000 by Martin Pool 6 | .\" 7 | .\" This program is free software; you can redistribute it and/or 8 | .\" modify it under the terms of the GNU Lesser General Public License 9 | .\" as published by the Free Software Foundation; either version 2.1 of 10 | .\" the License, or (at your option) any later version. 11 | .\" 12 | .\" This program is distributed in the hope that it will be useful, but 13 | .\" WITHOUT ANY WARRANTY; without even the implied warranty of 14 | .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | .\" Lesser General Public License for more details. 16 | .\" 17 | .\" You should have received a copy of the GNU Lesser General Public 18 | .\" License along with this program; if not, write to the Free Software 19 | .\" Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 | .\" 21 | .TH rdiff 1 "$Date: 2002/01/25 21:25:34 $" 22 | .SH NAME 23 | rdiff \- compute and apply signature-based file differences 24 | .SH SYNOPSYS 25 | .nf 26 | \fBrdiff\fP [\fIoptions\fP] \fBsignature\fP \fIold-file signature-file\fP 27 | .PP 28 | \fBrdiff\fP [\fIoptions\fP] \fBdelta\fP \fIsignature-file new-file delta-file\fP 29 | .PP 30 | \fBrdiff\fP [\fIoptions\fP] \fBpatch\fP \fIbasis-file delta-file new-file\fP 31 | .fi 32 | .SH DESCRIPTION 33 | In every case where a filename must be specified, \- may be used 34 | instead to mean either standard input or standard output as 35 | appropriate. 36 | .SH "RETURN VALUE" 37 | 0 for successful completion, 1 for environmental problems (file not 38 | found, invalid options, IO error, etc), 2 for a corrupt file and 3 for 39 | an internal error or unhandled situation in librsync or rdiff. 40 | .SH "SEE ALSO" 41 | .BR librsync "(3)" 42 | .SH "AUTHOR" 43 | Martin Pool 44 | .PP 45 | The original rsync algorithm was discovered by Andrew Tridgell. 46 | .PP 47 | rdiff development has been supported by Linuxcare, Inc and VA Linux 48 | Systems. 49 | -------------------------------------------------------------------------------- /librsync/rollsum.c: -------------------------------------------------------------------------------- 1 | /*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- 2 | * 3 | * rollsum -- the librsync rolling checksum 4 | * $Id: rollsum.c,v 1.17 2003/10/17 16:15:21 abo Exp $ 5 | * 6 | * Copyright (C) 2003 by Donovan Baarda 7 | * based on work, Copyright (C) 2000, 2001 by Martin Pool 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as published by 11 | * the Free Software Foundation; either version 2.1 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 22 | */ 23 | #include "rollsum.h" 24 | 25 | #define DO1(buf,i) {s1 += buf[i]; s2 += s1;} 26 | #define DO2(buf,i) DO1(buf,i); DO1(buf,i+1); 27 | #define DO4(buf,i) DO2(buf,i); DO2(buf,i+2); 28 | #define DO8(buf,i) DO4(buf,i); DO4(buf,i+4); 29 | #define DO16(buf) DO8(buf,0); DO8(buf,8); 30 | #define OF16(off) {s1 += 16*off; s2 += 136*off;} 31 | 32 | void RollsumUpdate(Rollsum *sum,const unsigned char *buf,unsigned int len) { 33 | /* ANSI C says no overflow for unsigned. 34 | zlib's adler 32 goes to extra effort to avoid overflow*/ 35 | unsigned long s1 = sum->s1; 36 | unsigned long s2 = sum->s2; 37 | 38 | sum->count+=len; /* increment sum count */ 39 | while (len >= 16) { 40 | DO16(buf); 41 | OF16(ROLLSUM_CHAR_OFFSET); 42 | buf += 16; 43 | len -= 16; 44 | } 45 | while (len != 0) { 46 | s1 += (*buf++ + ROLLSUM_CHAR_OFFSET); 47 | s2 += s1; 48 | len--; 49 | } 50 | sum->s1=s1; 51 | sum->s2=s2; 52 | } 53 | -------------------------------------------------------------------------------- /librsync/stream.h: -------------------------------------------------------------------------------- 1 | /*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- 2 | * 3 | * librsync -- library for network deltas 4 | * $Id: stream.h,v 1.14 2001/03/12 02:28:33 mbp Exp $ 5 | * 6 | * Copyright (C) 2000, 2001 by Martin Pool 7 | * 8 | * This program is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public License 10 | * as published by the Free Software Foundation; either version 2.1 of 11 | * the License, or (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | * Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 | */ 22 | 23 | /* Two wars in a lifetime bear hard on the little places. 24 | * In winter when storms come rushing out of the dark, 25 | * And the bay boils like a cauldron of sharks, 26 | * The old remember the trenches at Paschendale 27 | * And sons who died on the Burma Railway. */ 28 | 29 | 30 | int rs_buffers_is_empty(rs_buffers_t *stream); 31 | int rs_buffers_copy(rs_buffers_t *stream, int len); 32 | 33 | int rs_tube_catchup(rs_job_t *); 34 | void rs_tube_write(rs_job_t *, void const *buf, size_t len); 35 | void rs_tube_copy(rs_job_t *, int len); 36 | int rs_tube_is_idle(rs_job_t const *); 37 | void rs_check_tube(rs_job_t *); 38 | 39 | void rs_buffers_check_exit(rs_buffers_t const *); 40 | 41 | void rs_scoop_advance(rs_job_t *, size_t len); 42 | rs_result rs_scoop_readahead(rs_job_t *, size_t len, void **ptr); 43 | rs_result rs_scoop_read(rs_job_t *, size_t len, void **ptr); 44 | rs_result rs_scoop_read_rest(rs_job_t *, size_t *len, void **ptr); 45 | size_t rs_scoop_total_avail(rs_job_t *job); 46 | void rs_scoop_input(rs_job_t *job, size_t len); 47 | -------------------------------------------------------------------------------- /librsync/testsuite/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake to produce Makefile.in 2 | 3 | # Copyright (C) 2002 by Ben Elliston 4 | # $Id: Makefile.am,v 1.4 2003/03/20 15:10:13 abo Exp $ 5 | 6 | # This program is free software; you can redistribute it and/or 7 | # modify it under the terms of the GNU Lesser General Public License 8 | # as published by the Free Software Foundation; either version 2.1 of 9 | # the License, or (at your option) any later version. 10 | # 11 | # This program is distributed in the hope that it will be useful, but 12 | # WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public 17 | # License along with this program; if not, write to the Free Software 18 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 | 20 | MAINTAINERCLEANFILES = Makefile.in 21 | 22 | check_PROGRAMS = isprefix.driver 23 | 24 | INCLUDES = -I $(srcdir)/.. 25 | isprefix_driver_SOURCES = isprefix.driver.c 26 | isprefix_driver_LDADD = ../isprefix.o # XXX: should link replaced functions 27 | 28 | # NB: tests should exit with code 77 if they can't be run but haven't 29 | # failed. Generally these tests should be ordered so that more basic 30 | # tests are run first. 31 | 32 | TESTS_ENVIRONMENT = $(SH) $(srcdir)/driver.sh 33 | 34 | TESTS = \ 35 | signature.test mutate.test sources.test isprefix.test \ 36 | delta.test mksum.test triple.test changes.test 37 | 38 | noinst_SCRIPTS = driver.sh mutate.pl $(TESTS) 39 | 40 | test_data = dot \ 41 | changes.input/01.in changes.input/02.in \ 42 | changes.input/03.in changes.input/04.in \ 43 | delta.input/01.delta delta.input/01.expect \ 44 | delta.input/02.delta delta.input/02.expect \ 45 | delta.input/03.delta delta.input/03.expect \ 46 | mdfour.input/01.expect mdfour.input/01.data \ 47 | mksum.input/COPYING.sig \ 48 | triple.input/copying.in triple.input/half.in \ 49 | triple.input/hello.in triple.input/zero.in \ 50 | signature.input/01.in signature.input/01.sig 51 | 52 | EXTRA_DIST = $(noinst_SCRIPTS) $(test_data) 53 | -------------------------------------------------------------------------------- /librsync/testsuite/mutate.pl: -------------------------------------------------------------------------------- 1 | #! /usr/bin/perl -w 2 | 3 | # librsync -- the library for network deltas 4 | # $Id: mutate.pl,v 1.1 2002/01/25 21:08:25 bje Exp $ 5 | # 6 | # Copyright (C) 1999, 2000 by Martin Pool 7 | # Copyright (C) 1999 by Andrew Tridgell 8 | # 9 | # This program is free software; you can redistribute it and/or 10 | # modify it under the terms of the GNU Lesser General Public License 11 | # as published by the Free Software Foundation; either version 2.1 of 12 | # the License, or (at your option) any later version. 13 | # 14 | # This program is distributed in the hope that it will be useful, but 15 | # WITHOUT ANY WARRANTY; without even the implied warranty of 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | # Lesser General Public License for more details. 18 | # 19 | # You should have received a copy of the GNU Lesser General Public 20 | # License along with this program; if not, write to the Free Software 21 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 22 | 23 | # mutate: makes a random smalll change to an input file and writes it 24 | # to stdout. 25 | 26 | use strict; 27 | 28 | if ($#ARGV != 1) { 29 | print STDERR "usage: mutate.pl SEED MUTATIONS ; 38 | 39 | printf STDERR "%d mutations\n", $n_muts; 40 | 41 | while ($n_muts-- > 0) { 42 | my $in_len = length($corpus); 43 | 44 | my $from_off = int rand $in_len; 45 | my $from_len = int(rand(1.0) * rand($in_len)); 46 | my $to_off = int rand $in_len; 47 | my $to_len = int(rand(1.0) * rand($in_len)); 48 | 49 | my $op = rand 3; 50 | if ($op < 1.0) { 51 | printf STDERR "copy and overwrite"; 52 | substr($corpus, $to_off, $to_len) = substr($corpus, $from_off, $from_len); 53 | } elsif ($op < 2.0) { 54 | print STDERR "copy and insert"; 55 | substr($corpus, $to_off, 0) = substr($corpus, $from_off, $from_len); 56 | } else { 57 | print STDERR "delete"; 58 | substr($corpus, $to_off, $to_len) = ''; 59 | } 60 | 61 | printf STDERR " (%d, %d) -> (%d, %d)\n", $from_off, $from_len, $to_off, $to_len; 62 | } 63 | 64 | print $corpus; 65 | 66 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # php extension for librsync # 2 | [![Build Status](https://secure.travis-ci.org/ironpinguin/php_rsync.png)](http://travis-ci.org/ironpinguin/php_rsync) 3 | 4 | The [PECL/rsync][pecl] extension provides a binding too the librsync c library. 5 | The librsync library is a opensource implementing of the rsync version 1 algoritmus to exchange data differences form on side to the other (over net or local). 6 | 7 | The librsync library itself can be found at [librsync] and implements rsync remote-delta algorithm ([Rsync Algoritm][rsync]). 8 | 9 | This algorithm is using a rolling check-sum and a md4 check-sum for blocks of the file to generate a signature file. The signature file is used to generate a diff from the file on the remote site. This diff can be used on the local site to patch the file. 10 | 11 | The Algorithm is from rsync 1.x and not compatible with rsync 2.x. 12 | 13 | The main function is to have file a in one location and file b in a other. With the extension you can get the diffrent between the files and patch on file with the changes from the other. 14 | 15 | ## Install ## 16 | 17 | ### Prerequirement ### 18 | You need the [librsync] and php5 devel packet on your system. 19 | 20 | ### Steps ### 21 | 1. Install extension 22 | 23 | 1.a. Install with one commando 24 | 25 | sudo pecl install rsync 26 | 1.b. Install manualy: 27 | 28 | wget http://pecl.php.net/get/rsync-0.1.0.tgz 29 | tar xzf rsync-0.1.0.tgz 30 | cd rsync-0.1.0 31 | phpize 32 | ./configure --with-rsync 33 | make 34 | sudo make install 35 | 2. Add `extension=rsync.so` to your `php.ini` 36 | 37 | ## Workflow ## 38 | 39 | ### Prerequirements ### 40 | * __Side/Directory 1__ -> file a.txt 41 | * __Side/Directory 2__ -> file b.txt 42 | 43 | ### Steps ### 44 | 1. __Side 1__ 45 | 46 | `rsync_generate_signature("a.txt", "a.signature");` 47 | 2. Transfer "a.signature" to Side 2 48 | 3. __Side 2__ 49 | 50 | `rsync_generate_delta("a.signature", "b.txt", "patch_a_with_b.patch");` 51 | 4. Transfer "patch_a_with_b.patch" to Side 1 52 | 5. __Side 1__ 53 | 54 | `rsync_patch_file("a.txt", "patch_a_with_b.patch", "new_a.txt");` 55 | 6. replace "a.txt" with "new_a.txt" 56 | 57 | [pecl]: http://pecl.php.net/package/rsync "PECL/rsync" 58 | [librsync]: http://librsync.sourceforge.net/ "librsync" 59 | [rsync]: http://rsync.samba.org/tech_report "Rsync Algoritm" 60 | -------------------------------------------------------------------------------- /librsync/fileutil.c: -------------------------------------------------------------------------------- 1 | /*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- 2 | * 3 | * librsync -- library for network deltas 4 | * $Id: fileutil.c,v 1.24 2003/06/12 05:47:22 wayned Exp $ 5 | * 6 | * Copyright (C) 1999, 2000, 2001 by Martin Pool 7 | * Copyright (C) 1999 by Andrew Tridgell 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as published by 11 | * the Free Software Foundation; either version 2.1 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 22 | */ 23 | 24 | #include 25 | 26 | #include 27 | #include 28 | #ifdef HAVE_UNISTD_H 29 | #include 30 | #endif 31 | #include 32 | #ifdef HAVE_FCNTL_H 33 | #include 34 | #endif 35 | #ifdef HAVE_SYS_FILE_H 36 | #include 37 | #endif 38 | #include 39 | #include 40 | 41 | #include "librsync.h" 42 | #include "fileutil.h" 43 | #include "trace.h" 44 | 45 | 46 | 47 | /** 48 | * \brief Open a file, with special handling for `-' or unspecified 49 | * parameters on input and output. 50 | * 51 | * \param fopen-style mode string. 52 | */ 53 | FILE * 54 | rs_file_open(char const *filename, char const *mode) 55 | { 56 | FILE *f; 57 | int is_write; 58 | 59 | is_write = mode[0] == 'w'; 60 | 61 | if (!filename || !strcmp("-", filename)) { 62 | if (is_write) 63 | return stdout; 64 | else 65 | return stdin; 66 | } 67 | 68 | if (!(f = fopen(filename, mode))) { 69 | rs_error("Error opening \"%s\" for %s: %s", filename, 70 | is_write ? "write" : "read", 71 | strerror(errno)); 72 | exit(RS_IO_ERROR); 73 | } 74 | 75 | return f; 76 | } 77 | 78 | int rs_file_close(FILE * f) 79 | { 80 | if ((f == stdin) || (f == stdout)) return 0; 81 | return fclose(f); 82 | } 83 | -------------------------------------------------------------------------------- /tests/014.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test RsyncFileIoException 3 | --SKIPIF-- 4 | 6 | --FILE-- 7 | getMessage(); 18 | } 19 | 20 | @unlink($notexists); 21 | @unlink($nosense); 22 | 23 | try { 24 | rsync_generate_signature($exists0, $notexists); 25 | } catch (RsyncFileIoException $e) { 26 | $out[] = $e->getMessage(); 27 | } 28 | 29 | @unlink($notexists); 30 | @unlink($nosense); 31 | 32 | try { 33 | rsync_generate_delta($notexists, $nosense, $nosense); 34 | } catch (RsyncFileIoException $e) { 35 | $out[] = $e->getMessage(); 36 | } 37 | 38 | @unlink($notexists); 39 | @unlink($nosense); 40 | 41 | try { 42 | rsync_generate_delta($sigfile, $notexists, $nosense); 43 | } catch (RsyncFileIoException $e) { 44 | $out[] = $e->getMessage(); 45 | } 46 | 47 | @unlink($notexists); 48 | @unlink($nosense); 49 | 50 | try { 51 | rsync_generate_delta($sigfile, $exists0, $notexists); 52 | } catch (RsyncFileIoException $e) { 53 | $out[] = $e->getMessage(); 54 | } 55 | 56 | @unlink($notexists); 57 | @unlink($nosense); 58 | 59 | try { 60 | rsync_patch_file($notexists, $nosense, $nosense); 61 | } catch (RsyncFileIoException $e) { 62 | $out[] = $e->getMessage(); 63 | } 64 | 65 | @unlink($notexists); 66 | @unlink($nosense); 67 | 68 | try { 69 | rsync_patch_file($sigfile, $notexists, $nosense); 70 | } catch (RsyncFileIoException $e) { 71 | $out[] = $e->getMessage(); 72 | } 73 | 74 | @unlink($notexists); 75 | @unlink($nosense); 76 | 77 | print implode("\n", $out) . "\n"; 78 | ?> 79 | --EXPECTF-- 80 | Could not open "./tests/not exists" for read: No such file or directory 81 | Could not open "./tests/not exists" for read: No such file or directory 82 | Could not open "./tests/not exists" for read: No such file or directory 83 | Could not open "./tests/not exists" for read: No such file or directory 84 | Could not open "./tests/not exists" for read: No such file or directory 85 | -------------------------------------------------------------------------------- /librsync/doc/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake to produce Makefile.in 2 | 3 | # Copyright (C) 2002 by Ben Elliston 4 | # $Id: Makefile.am,v 1.2 2003/03/20 09:19:13 abo Exp $ 5 | 6 | # This program is free software; you can redistribute it and/or 7 | # modify it under the terms of the GNU Lesser General Public License 8 | # as published by the Free Software Foundation; either version 2.1 of 9 | # the License, or (at your option) any later version. 10 | # 11 | # This program is distributed in the hope that it will be useful, but 12 | # WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public 17 | # License along with this program; if not, write to the Free Software 18 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 | 20 | MAINTAINERCLEANFILES = Makefile.in 21 | 22 | man_MANS = rdiff.1 librsync.3 23 | EXTRA_DIST = $(man_MANS) 24 | 25 | # Doxygen API documentation 26 | 27 | sites=front.linuxcare.com.au:/var/www/projects/rproxy \ 28 | rproxy.sourceforge.net:/home/groups/rproxy/htdocs \ 29 | rproxy.samba.org:/space/httpd/rproxy/htdocs 30 | 31 | .PHONY: do-doxy upload-doxy 32 | 33 | html latex do-doxy: Doxyfile 34 | doxygen 35 | 36 | refman.pdf refman.ps.gz: latex 37 | cd latex && make refman.ps refman.pdf && gzip -9vf refman.ps 38 | 39 | upload-doxy: html refman.pdf refman.ps.gz 40 | for i in $(sites); do \ 41 | rsync -avz --delete --exclude '*~' \ 42 | html/ latex/refman.pdf latex/refman.ps.gz \ 43 | $(srcdir)/rproxy-small-logo.png $$i/doxygen/librsync; \ 44 | done 45 | 46 | converted_men = man_librsync_3.html man_librsync_3.ps \ 47 | man_rdiff_1.html man_rdiff_1.ps 48 | 49 | man_%_1.ps: %.1 50 | groff -mandoc -Tps $< >$@ 51 | 52 | man_%_3.ps: %.3 53 | groff -mandoc -Tps $< >$@ 54 | 55 | man_%_1.html: %.1 56 | groff -mandoc -Thtml $< >$@ 57 | 58 | man_%_3.html: %.3 59 | groff -mandoc -Thtml $< >$@ 60 | 61 | man_%_1.txt: %.1 62 | groff -mandoc -Tlatin1 $< >$@ 63 | 64 | man_%_3.txt: %.3 65 | groff -mandoc -Tlatin1 $< >$@ 66 | 67 | upload-men: $(converted_men) 68 | for i in $(sites); do \ 69 | rsync -avz --delete $(converted_men) $(man_MANS) $$i/man; \ 70 | done 71 | 72 | upload-news: NEWS 73 | for i in $(sites); do \ 74 | rsync -avz --delete $(srcdir)/NEWS $$i/librsync-NEWS; \ 75 | done 76 | -------------------------------------------------------------------------------- /librsync/sumset.h: -------------------------------------------------------------------------------- 1 | /*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- 2 | * 3 | * librsync -- the library for network deltas 4 | * $Id: sumset.h,v 1.20 2001/03/18 10:49:27 mbp Exp $ 5 | * 6 | * Copyright (C) 1999, 2000, 2001 by Martin Pool 7 | * Copyright (C) 1999 by Andrew Tridgell 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU Lesser General Public License 11 | * as published by the Free Software Foundation; either version 2.1 of 12 | * the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, but 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 22 | */ 23 | 24 | 25 | /* 26 | * TODO: These structures are not terribly useful. Perhaps we need a 27 | * splay tree or something that will let us smoothly grow as data is 28 | * read in. 29 | */ 30 | 31 | 32 | /** 33 | * \brief Description of the match described by a signature. 34 | */ 35 | typedef struct rs_target { 36 | unsigned short t; 37 | int i; 38 | } rs_target_t; 39 | 40 | typedef struct rs_block_sig rs_block_sig_t; 41 | 42 | /* 43 | * This structure describes all the sums generated for an instance of 44 | * a file. It incorporates some redundancy to make it easier to 45 | * search. 46 | */ 47 | struct rs_signature { 48 | rs_long_t flength; /* total file length */ 49 | int count; /* how many chunks */ 50 | int remainder; /* flength % block_length */ 51 | int block_len; /* block_length */ 52 | int strong_sum_len; 53 | rs_block_sig_t *block_sigs; /* points to info for each chunk */ 54 | int *tag_table; 55 | rs_target_t *targets; 56 | }; 57 | 58 | 59 | /* 60 | * All blocks are the same length in the current algorithm except for 61 | * the last block which may be short. 62 | */ 63 | struct rs_block_sig { 64 | int i; /* index of this chunk */ 65 | rs_weak_sum_t weak_sum; /* simple checksum */ 66 | rs_strong_sum_t strong_sum; /* checksum */ 67 | }; 68 | -------------------------------------------------------------------------------- /librsync/librsync.spec: -------------------------------------------------------------------------------- 1 | Summary: Rsync libraries 2 | Name: librsync 3 | Version: 0.9.6 4 | Release: 1 5 | Copyright: LGPL 6 | Group: System Environment/Libraries 7 | Source: http://prdownloads.sourceforge.net/librsync/librsync-0.9.6.tar.gz?download 8 | URL: http://www.sourceforge.net/projects/librsync 9 | BuildRoot: %{_tmppath}/%{name}-%{version}-root 10 | 11 | %description 12 | librsync implements the "rsync" algorithm, which allows remote 13 | differencing of binary files. librsync computes a delta relative to a 14 | file's checksum, so the two files need not both be present to generate 15 | a delta. 16 | 17 | This library was previously known as libhsync up to version 0.9.0. 18 | 19 | The current version of this package does not implement the rsync 20 | network protocol and uses a delta format slightly more efficient than 21 | and incompatible with rsync 2.4.6. 22 | 23 | %package devel 24 | Summary: Headers and development libraries for librsync 25 | Group: Development/Libraries 26 | Requires: %{name} = %{version} 27 | 28 | %description devel 29 | librsync implements the "rsync" algorithm, which allows remote 30 | differencing of binary files. librsync computes a delta relative to a 31 | file's checksum, so the two files need not both be present to generate 32 | a delta. 33 | 34 | This library was previously known as libhsync up to version 0.9.0. 35 | 36 | The current version of this package does not implement the rsync 37 | network protocol and uses a delta format slightly more efficient than 38 | and incompatible with rsync 2.4.6. 39 | 40 | This package contains header files necessary for developing programs 41 | based on librsync. 42 | 43 | %prep 44 | %setup 45 | # The next line is only needed if there are any non-upstream patches. In 46 | # this distribution there are none. 47 | #%patch 48 | %build 49 | libtoolize --force 50 | aclocal 51 | autoheader 52 | automake Makefile popt/Makefile 53 | autoconf 54 | ./configure --prefix=/usr --mandir=/usr/share/man/ 55 | make CFLAGS="$RPM_OPT_FLAGS" 56 | 57 | %install 58 | rm -rf $RPM_BUILD_ROOT 59 | make DESTDIR=$RPM_BUILD_ROOT install 60 | 61 | %clean 62 | rm -rf $RPM_BUILD_ROOT 63 | 64 | %post -p /sbin/ldconfig 65 | 66 | %postun -p /sbin/ldconfig 67 | 68 | %files 69 | %defattr(-,root,root) 70 | %doc AUTHORS COPYING COPYING NEWS README 71 | %{_libdir}/librsync.la 72 | %{_bindir}/rdiff 73 | %{_mandir}/man3/librsync.3.gz 74 | %{_mandir}/man1/rdiff.1.gz 75 | 76 | %files devel 77 | %defattr(-,root,root) 78 | %{_prefix}/include/* 79 | %{_libdir}/librsync.a 80 | 81 | %changelog 82 | -------------------------------------------------------------------------------- /librsync/mkinstalldirs: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # mkinstalldirs --- make directory hierarchy 3 | # Author: Noah Friedman 4 | # Created: 1993-05-16 5 | # Public domain 6 | 7 | errstatus=0 8 | dirmode="" 9 | 10 | usage="\ 11 | Usage: mkinstalldirs [-h] [--help] [-m mode] dir ..." 12 | 13 | # process command line arguments 14 | while test $# -gt 0 ; do 15 | case $1 in 16 | -h | --help | --h*) # -h for help 17 | echo "$usage" 1>&2 18 | exit 0 19 | ;; 20 | -m) # -m PERM arg 21 | shift 22 | test $# -eq 0 && { echo "$usage" 1>&2; exit 1; } 23 | dirmode=$1 24 | shift 25 | ;; 26 | --) # stop option processing 27 | shift 28 | break 29 | ;; 30 | -*) # unknown option 31 | echo "$usage" 1>&2 32 | exit 1 33 | ;; 34 | *) # first non-opt arg 35 | break 36 | ;; 37 | esac 38 | done 39 | 40 | for file 41 | do 42 | if test -d "$file"; then 43 | shift 44 | else 45 | break 46 | fi 47 | done 48 | 49 | case $# in 50 | 0) exit 0 ;; 51 | esac 52 | 53 | case $dirmode in 54 | '') 55 | if mkdir -p -- . 2>/dev/null; then 56 | echo "mkdir -p -- $*" 57 | exec mkdir -p -- "$@" 58 | fi 59 | ;; 60 | *) 61 | if mkdir -m "$dirmode" -p -- . 2>/dev/null; then 62 | echo "mkdir -m $dirmode -p -- $*" 63 | exec mkdir -m "$dirmode" -p -- "$@" 64 | fi 65 | ;; 66 | esac 67 | 68 | for file 69 | do 70 | set fnord `echo ":$file" | sed -ne 's/^:\//#/;s/^://;s/\// /g;s/^#/\//;p'` 71 | shift 72 | 73 | pathcomp= 74 | for d 75 | do 76 | pathcomp="$pathcomp$d" 77 | case $pathcomp in 78 | -*) pathcomp=./$pathcomp ;; 79 | esac 80 | 81 | if test ! -d "$pathcomp"; then 82 | echo "mkdir $pathcomp" 83 | 84 | mkdir "$pathcomp" || lasterr=$? 85 | 86 | if test ! -d "$pathcomp"; then 87 | errstatus=$lasterr 88 | else 89 | if test ! -z "$dirmode"; then 90 | echo "chmod $dirmode $pathcomp" 91 | lasterr="" 92 | chmod "$dirmode" "$pathcomp" || lasterr=$? 93 | 94 | if test ! -z "$lasterr"; then 95 | errstatus=$lasterr 96 | fi 97 | fi 98 | fi 99 | fi 100 | 101 | pathcomp="$pathcomp/" 102 | done 103 | done 104 | 105 | exit $errstatus 106 | 107 | # Local Variables: 108 | # mode: shell-script 109 | # sh-indentation: 2 110 | # End: 111 | # mkinstalldirs ends here 112 | -------------------------------------------------------------------------------- /librsync/popt/poptparse.c: -------------------------------------------------------------------------------- 1 | /* (C) 1998 Red Hat Software, Inc. -- Licensing details are in the COPYING 2 | file accompanying popt source distributions, available from 3 | ftp://ftp.redhat.com/pub/code/popt */ 4 | 5 | #include "system.h" 6 | 7 | #define POPT_ARGV_ARRAY_GROW_DELTA 5 8 | 9 | int poptDupArgv(int argc, const char **argv, 10 | int * argcPtr, const char *** argvPtr) 11 | { 12 | size_t nb = (argc + 1) * sizeof(*argv); 13 | const char ** argv2; 14 | char * dst; 15 | int i; 16 | 17 | for (i = 0; i < argc; i++) { 18 | if (argv[i] == NULL) 19 | return POPT_ERROR_NOARG; 20 | nb += strlen(argv[i]) + 1; 21 | } 22 | 23 | dst = malloc(nb); 24 | argv2 = (void *) dst; 25 | dst += (argc + 1) * sizeof(*argv); 26 | 27 | for (i = 0; i < argc; i++) { 28 | argv2[i] = dst; 29 | dst += strlen(strcpy(dst, argv[i])) + 1; 30 | } 31 | argv2[argc] = NULL; 32 | 33 | *argvPtr = argv2; 34 | *argcPtr = argc; 35 | return 0; 36 | } 37 | 38 | int poptParseArgvString(const char * s, int * argcPtr, const char *** argvPtr) 39 | { 40 | const char * src; 41 | char quote = '\0'; 42 | int argvAlloced = POPT_ARGV_ARRAY_GROW_DELTA; 43 | const char ** argv = malloc(sizeof(*argv) * argvAlloced); 44 | int argc = 0; 45 | int buflen = strlen(s) + 1; 46 | char * buf = memset(alloca(buflen), 0, buflen); 47 | 48 | argv[argc] = buf; 49 | 50 | for (src = s; *src; src++) { 51 | if (quote == *src) { 52 | quote = '\0'; 53 | } else if (quote) { 54 | if (*src == '\\') { 55 | src++; 56 | if (!*src) { 57 | free(argv); 58 | return POPT_ERROR_BADQUOTE; 59 | } 60 | if (*src != quote) *buf++ = '\\'; 61 | } 62 | *buf++ = *src; 63 | } else if (isspace(*src)) { 64 | if (*argv[argc]) { 65 | buf++, argc++; 66 | if (argc == argvAlloced) { 67 | argvAlloced += POPT_ARGV_ARRAY_GROW_DELTA; 68 | argv = realloc(argv, sizeof(*argv) * argvAlloced); 69 | } 70 | argv[argc] = buf; 71 | } 72 | } else switch (*src) { 73 | case '"': 74 | case '\'': 75 | quote = *src; 76 | break; 77 | case '\\': 78 | src++; 79 | if (!*src) { 80 | free(argv); 81 | return POPT_ERROR_BADQUOTE; 82 | } 83 | /*@fallthrough@*/ 84 | default: 85 | *buf++ = *src; 86 | break; 87 | } 88 | } 89 | 90 | if (strlen(argv[argc])) { 91 | argc++, buf++; 92 | } 93 | 94 | (void) poptDupArgv(argc, argv, argcPtr, argvPtr); 95 | 96 | free(argv); 97 | 98 | return 0; 99 | } 100 | -------------------------------------------------------------------------------- /librsync/sumset.c: -------------------------------------------------------------------------------- 1 | /*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- 2 | * 3 | * librsync -- library for network deltas 4 | * $Id: sumset.c,v 1.22 2003/06/12 05:47:23 wayned Exp $ 5 | * 6 | * Copyright (C) 1999, 2000, 2001 by Martin Pool 7 | * Copyright (C) 1999 by Andrew Tridgell 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as published by 11 | * the Free Software Foundation; either version 2.1 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 22 | */ 23 | 24 | #include 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | #include "librsync.h" 31 | #include "sumset.h" 32 | #include "util.h" 33 | #include "trace.h" 34 | 35 | 36 | /** 37 | * Deep deallocation of checksums. 38 | */ 39 | void 40 | rs_free_sumset(rs_signature_t * psums) 41 | { 42 | if (psums->block_sigs) 43 | free(psums->block_sigs); 44 | 45 | if (psums->tag_table) 46 | free(psums->tag_table); 47 | 48 | if (psums->targets) 49 | free(psums->targets); 50 | 51 | rs_bzero(psums, sizeof *psums); 52 | free(psums); 53 | } 54 | 55 | 56 | 57 | /** 58 | * Dump signatures to the log. 59 | */ 60 | void 61 | rs_sumset_dump(rs_signature_t const *sums) 62 | { 63 | int i; 64 | char strong_hex[RS_MD4_LENGTH * 3]; 65 | 66 | rs_log(RS_LOG_INFO, 67 | "sumset info: block_len=%d, file length=%lu, " 68 | "number of chunks=%d, remainder=%d", 69 | sums->block_len, 70 | (unsigned long) sums->flength, sums->count, 71 | sums->remainder); 72 | 73 | for (i = 0; i < sums->count; i++) { 74 | rs_hexify(strong_hex, sums->block_sigs[i].strong_sum, 75 | sums->strong_sum_len); 76 | rs_log(RS_LOG_INFO, 77 | "sum %6d: weak=%08x, strong=%s", 78 | i, sums->block_sigs[i].weak_sum, strong_hex); 79 | } 80 | } 81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /tests/013.phpt: -------------------------------------------------------------------------------- 1 | --TEST-- 2 | Test RsyncInvalidArgumentException 3 | --SKIPIF-- 4 | 6 | --FILE-- 7 | getMessage(); 19 | } 20 | 21 | try { 22 | rsync_generate_signature($exists0, 42); 23 | } catch (RsyncInvalidArgumentException $e) { 24 | $out[] = $e->getMessage(); 25 | } 26 | 27 | try { 28 | rsync_generate_delta(42, $nosense, $nosense); 29 | } catch (RsyncInvalidArgumentException $e) { 30 | $out[] = $e->getMessage(); 31 | } 32 | 33 | try { 34 | rsync_generate_delta($sigfile, 42, $nosense); 35 | } catch (RsyncInvalidArgumentException $e) { 36 | $out[] = $e->getMessage(); 37 | } 38 | 39 | try { 40 | rsync_generate_delta($sigfile, $exists0, 42); 41 | } catch (RsyncInvalidArgumentException $e) { 42 | $out[] = $e->getMessage(); 43 | } 44 | 45 | try { 46 | rsync_patch_file(42, $nosense, $nosense); 47 | } catch (RsyncInvalidArgumentException $e) { 48 | $out[] = $e->getMessage(); 49 | } 50 | 51 | try { 52 | rsync_patch_file($sigfile, 42, $nosense); 53 | } catch (RsyncInvalidArgumentException $e) { 54 | $out[] = $e->getMessage(); 55 | } 56 | 57 | try { 58 | rsync_patch_file($sigfile, $exists0, 42); 59 | } catch (RsyncInvalidArgumentException $e) { 60 | $out[] = $e->getMessage(); 61 | } 62 | 63 | try { 64 | rsync_set_log_level(42); 65 | } catch (RsyncInvalidArgumentException $e) { 66 | $out[] = $e->getMessage(); 67 | } 68 | 69 | @unlink("." . DIRECTORY_SEPARATOR . "tests" . DIRECTORY_SEPARATOR . "no sense"); 70 | @unlink("no sense"); 71 | @unlink("." . DIRECTORY_SEPARATOR . "tests" . DIRECTORY_SEPARATOR . "not exists"); 72 | @unlink("not exists"); 73 | 74 | print implode("\n", $out) . "\n"; 75 | ?> 76 | --EXPECTF-- 77 | Expected string or stream, "42" was given 78 | Expected string or stream, "42" was given 79 | Expected string or stream, "42" was given 80 | Expected string or stream, "42" was given 81 | Expected string or stream, "42" was given 82 | Expected string or stream, "42" was given 83 | Expected string or stream, "42" was given 84 | Expected string or stream, "42" was given 85 | Invalid log level value 86 | -------------------------------------------------------------------------------- /librsync/popt/poptint.h: -------------------------------------------------------------------------------- 1 | /* (C) 1998 Red Hat Software, Inc. -- Licensing details are in the COPYING 2 | file accompanying popt source distributions, available from 3 | ftp://ftp.redhat.com/pub/code/popt */ 4 | 5 | #ifndef H_POPTINT 6 | #define H_POPTINT 7 | 8 | /* Bit mask macros. */ 9 | typedef unsigned int __pbm_bits; 10 | #define __PBM_NBITS (8 * sizeof (__pbm_bits)) 11 | #define __PBM_IX(d) ((d) / __PBM_NBITS) 12 | #define __PBM_MASK(d) ((__pbm_bits) 1 << ((d) % __PBM_NBITS)) 13 | typedef struct { 14 | __pbm_bits bits[1]; 15 | } pbm_set; 16 | #define __PBM_BITS(set) ((set)->bits) 17 | 18 | #define PBM_ALLOC(d) calloc(__PBM_IX (d) + 1, sizeof(__pbm_bits)) 19 | #define PBM_FREE(s) free(s); 20 | #define PBM_SET(d, s) (__PBM_BITS (s)[__PBM_IX (d)] |= __PBM_MASK (d)) 21 | #define PBM_CLR(d, s) (__PBM_BITS (s)[__PBM_IX (d)] &= ~__PBM_MASK (d)) 22 | #define PBM_ISSET(d, s) ((__PBM_BITS (s)[__PBM_IX (d)] & __PBM_MASK (d)) != 0) 23 | 24 | struct optionStackEntry { 25 | int argc; 26 | /*@only@*/ const char ** argv; 27 | /*@only@*/ pbm_set * argb; 28 | int next; 29 | /*@only@*/ const char * nextArg; 30 | /*@keep@*/ const char * nextCharArg; 31 | /*@dependent@*/ struct poptAlias * currAlias; 32 | int stuffed; 33 | }; 34 | 35 | struct execEntry { 36 | const char * longName; 37 | char shortName; 38 | const char * script; 39 | }; 40 | 41 | struct poptContext_s { 42 | struct optionStackEntry optionStack[POPT_OPTION_DEPTH]; 43 | /*@dependent@*/ struct optionStackEntry * os; 44 | /*@owned@*/ const char ** leftovers; 45 | int numLeftovers; 46 | int nextLeftover; 47 | /*@keep@*/ const struct poptOption * options; 48 | int restLeftover; 49 | /*@only@*/ const char * appName; 50 | /*@only@*/ struct poptAlias * aliases; 51 | int numAliases; 52 | int flags; 53 | struct execEntry * execs; 54 | int numExecs; 55 | /*@only@*/ const char ** finalArgv; 56 | int finalArgvCount; 57 | int finalArgvAlloced; 58 | /*@dependent@*/ struct execEntry * doExec; 59 | /*@only@*/ const char * execPath; 60 | int execAbsolute; 61 | /*@only@*/ const char * otherHelp; 62 | pbm_set * arg_strip; 63 | }; 64 | 65 | #define xfree(_a) free((void *)_a) 66 | 67 | #ifdef HAVE_LIBINTL_H 68 | #include 69 | #endif 70 | 71 | #if defined(HAVE_GETTEXT) && !defined(__LCLINT__) 72 | #define _(foo) gettext(foo) 73 | #else 74 | #define _(foo) (foo) 75 | #endif 76 | 77 | #if defined(HAVE_DGETTEXT) && !defined(__LCLINT__) 78 | #define D_(dom, str) dgettext(dom, str) 79 | #define POPT_(foo) D_("popt", foo) 80 | #else 81 | #define POPT_(foo) (foo) 82 | #define D_(dom, str) (str) 83 | #endif 84 | 85 | #define N_(foo) (foo) 86 | 87 | #endif 88 | -------------------------------------------------------------------------------- /librsync/rollsum.h: -------------------------------------------------------------------------------- 1 | /*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- 2 | * 3 | * rollsum -- the librsync rolling checksum 4 | * $Id: rollsum.h,v 1.18 2003/10/17 16:15:21 abo Exp $ 5 | * 6 | * Copyright (C) 2003 by Donovan Baarda 7 | * based on work, Copyright (C) 2000, 2001 by Martin Pool 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as published by 11 | * the Free Software Foundation; either version 2.1 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 22 | */ 23 | #ifndef _ROLLSUM_H_ 24 | #define _ROLLSUM_H_ 25 | 26 | /* We should make this something other than zero to improve the 27 | * checksum algorithm: tridge suggests a prime number. */ 28 | #define ROLLSUM_CHAR_OFFSET 31 29 | 30 | /* the Rollsum struct type*/ 31 | typedef struct _Rollsum { 32 | unsigned long count; /* count of bytes included in sum */ 33 | unsigned long s1; /* s1 part of sum */ 34 | unsigned long s2; /* s2 part of sum */ 35 | } Rollsum; 36 | 37 | void RollsumUpdate(Rollsum *sum,const unsigned char *buf,unsigned int len); 38 | /* The following are implemented as macros. 39 | void RollsumInit(Rollsum *sum); 40 | void RollsumRotate(Rollsum *sum,unsigned char out, unsigned char in); 41 | void RollsumRollin(Rollsum *sum,unsigned char c); 42 | void RollsumRollout(Rollsum *sum,unsigned char c); 43 | unsigned long RollsumDigest(Rollsum *sum); 44 | */ 45 | 46 | /* macro implementations of simple routines */ 47 | #define RollsumInit(sum) { \ 48 | (sum)->count=(sum)->s1=(sum)->s2=0; \ 49 | } 50 | 51 | #define RollsumRotate(sum,out,in) { \ 52 | (sum)->s1 += (unsigned char)(in) - (unsigned char)(out); \ 53 | (sum)->s2 += (sum)->s1 - (sum)->count*((unsigned char)(out)+ROLLSUM_CHAR_OFFSET); \ 54 | } 55 | 56 | #define RollsumRollin(sum,c) { \ 57 | (sum)->s1 += ((unsigned char)(c)+ROLLSUM_CHAR_OFFSET); \ 58 | (sum)->s2 += (sum)->s1; \ 59 | (sum)->count++; \ 60 | } 61 | 62 | #define RollsumRollout(sum,c) { \ 63 | (sum)->s1 -= ((unsigned char)(c)+ROLLSUM_CHAR_OFFSET); \ 64 | (sum)->s2 -= (sum)->count*((unsigned char)(c)+ROLLSUM_CHAR_OFFSET); \ 65 | (sum)->count--; \ 66 | } 67 | 68 | #define RollsumDigest(sum) (((sum)->s2 << 16) | ((sum)->s1 & 0xffff)) 69 | 70 | #endif /* _ROLLSUM_H_ */ 71 | -------------------------------------------------------------------------------- /librsync/README: -------------------------------------------------------------------------------- 1 | README for librsync 2 | ------------------- 3 | 4 | librsync implements the rolling-checksum algorithm of remote file 5 | synchronization that was popularized by the rsync utility and is used in 6 | rproxy. This algorithm transfers the differences between 2 files without 7 | needing both files on the same system. 8 | 9 | It was originaly developed as part of rproxy, but is now used by other 10 | applications and has its own project on sourceforge. 11 | 12 | http://librsync.sourceforge.net/ 13 | 14 | This library was previously known as libhsync up to version 0.9.0. 15 | 16 | To use anonymous CVS, see the file README.CVS in this directory. 17 | 18 | >> Requirements 19 | 20 | To build librsync you will need: 21 | 22 | * A C compiler and appropriate headers and libraries 23 | 24 | * Make 25 | 26 | * popt -- command line parsing library 27 | 28 | Available from ftp://ftp.redhat.com/pub/redhat/code/popt 29 | 30 | A cut-down version of popt1.5 is included and will be used 31 | automatically if there is no popt library on your build host. 32 | 33 | >> Compiling 34 | 35 | To build and test librsync from the extracted distribution do; 36 | 37 | $ ./configure 38 | $ make all check 39 | 40 | >> Note for RedHat 7.0 41 | 42 | RedHat 7.0 (Guiness) ships with a buggy version of GCC 2.96 that 43 | produces many warnings while compiling librsync. These are harmless 44 | -- the library seems to work anyhow. You can avoid the warnings by 45 | using the 'kgcc' version of the compiler: 46 | 47 | $ export CC=kgcc 48 | $ ./autogen.sh 49 | $ make all check 50 | 51 | >> Note for Windows 52 | 53 | With cygwin you can build using gcc as under a normal unix system. It 54 | is also possible to compile under cygwin using MSVC++. You must have 55 | environment variables needed by MSCV set using the Vcvars32.bat 56 | script. With these variables set, you just do; 57 | 58 | $ ./configure.msc 59 | $ make all check 60 | 61 | The PCbuild directory contains a project and pre-generated config 62 | files for use with the MSVC++ IDE. This should be enought to compile 63 | rdiff.exe without requiring cygwin. 64 | 65 | >> Library Versions 66 | 67 | librsync uses the GNU libtool library versioning system, so the filename 68 | does not correspond to the librsync release. To show the library release 69 | and version, use the librsyncinfo tool. See libversions.txt for more 70 | information. 71 | 72 | >> Platforms 73 | 74 | librsync is known to run on: 75 | 76 | GNU Linux Debian 3.0 x86 77 | 78 | SUNWspro: (use -v for more warnings) 79 | 80 | mips-sgi-irix6.5: works, but you must use GNU Make rather than the default 81 | SGI Make. I used gcc. 82 | 83 | windows32: see above. 84 | 85 | >> API Documentation 86 | 87 | librsync contains markup for automatic API documentation generation using 88 | the Doxygen tool: 89 | 90 | http://www.doxygen.org/ 91 | 92 | $Id: README,v 1.16 2003/08/03 15:13:45 abo Exp $ 93 | -------------------------------------------------------------------------------- /librsync/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake to produce Makefile.in 2 | # $Id: Makefile.am,v 1.126 2003/10/17 16:15:20 abo Exp $ 3 | 4 | # Copyright (C) 2000, 2001, 2002 by Martin Pool 5 | # Copyright (C) 2003 by Donovan Baarda 6 | 7 | # This program is free software; you can redistribute it and/or 8 | # modify it under the terms of the GNU Lesser General Public License 9 | # as published by the Free Software Foundation; either version 2.1 of 10 | # the License, or (at your option) any later version. 11 | # 12 | # This program is distributed in the hope that it will be useful, but 13 | # WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | # Lesser General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU Lesser General Public 18 | # License along with this program; if not, write to the Free Software 19 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 | 21 | AUTOMAKE_OPTIONS = foreign 22 | SUBDIRS = doc popt testsuite 23 | 24 | MAINTAINERCLEANFILES = Makefile.in \ 25 | aclocal.m4 config.guess config.h.in config.sub configure \ 26 | depcomp install-sh ltmain.sh missing mkinstalldirs \ 27 | prototab.c prototab.h ChangeLog 28 | 29 | EXTRA_DIST = autogen.sh configure.msc $(noinst_SCRIPTS) rdiff.magic \ 30 | librsync.spec README.CVS README.RPM libversions.txt ChangeLog \ 31 | PCbuild/rdiff.dsp PCbuild/PCbuild.dsw PCbuild/config.h \ 32 | PCbuild/librsync-config.h 33 | 34 | include_HEADERS = librsync.h librsync-config.h 35 | 36 | lib_LTLIBRARIES = librsync.la 37 | 38 | librsync_la_SOURCES = prototab.c prototab.h \ 39 | base64.c buf.c buf.h checksum.c checksum.h command.c \ 40 | command.h delta.c emit.c emit.h fileutil.c fileutil.h \ 41 | hex.c job.c job.h mdfour.c mdfour.h mksum.c msg.c netint.c netint.h \ 42 | patch.c protocol.h readsums.c librsync.h librsync-config.h \ 43 | rollsum.c rollsum.h \ 44 | scoop.c search.c search.h stats.c stream.c stream.h sumset.c \ 45 | sumset.h trace.c trace.h tube.c types.h util.c util.h \ 46 | version.c whole.c whole.h snprintf.h 47 | 48 | librsync_la_LIBADD = @LIBOBJS@ 49 | 50 | librsync_la_LDFLAGS = -version-info @librsync_libversion@ 51 | 52 | # This is the default for any programs that don't specify a preference. 53 | LDADD = librsync.la 54 | 55 | # This is the rdiff application 56 | bin_PROGRAMS = rdiff 57 | 58 | rdiff_SOURCES = rdiff.c isprefix.c isprefix.h librsync.h librsync-config.h \ 59 | trace.h 60 | 61 | rdiff_LDADD = @BUILD_POPT@ librsync.la 62 | 63 | rdiff_DEPENDENCIES = @BUILD_POPT@ librsync.la 64 | 65 | # this script is used to build prototab.[ch] 66 | noinst_SCRIPTS = mkprototab.pl 67 | 68 | # Autogenerated by a script. 69 | prototab.c prototab.h: $(srcdir)/mkprototab.pl 70 | perl $(srcdir)/mkprototab.pl prototab.c prototab.h 71 | 72 | # Rule to build popt if needed. 73 | popt/libpopt.a: 74 | (cd popt && $(MAKE) $(AM_MAKEFLAGS) libpopt.a) 75 | 76 | # Autogenerated by cvs2cl from CVS commits. 77 | ChangeLog: 78 | cvs2cl -g "-z6" 79 | -------------------------------------------------------------------------------- /librsync/autogen.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | # Copyright (C) 2000, 2001 by Martin Pool 4 | # $Id: autogen.sh,v 1.18 2003/06/12 05:50:00 wayned Exp $ 5 | 6 | # This program is free software; you can redistribute it and/or 7 | # modify it under the terms of the GNU Lesser General Public License 8 | # as published by the Free Software Foundation; either version 2.1 of 9 | # the License, or (at your option) any later version. 10 | # 11 | # This program is distributed in the hope that it will be useful, but 12 | # WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public 17 | # License along with this program; if not, write to the Free Software 18 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 | 20 | 21 | # This script generates everything necessary to build librsync from 22 | # CVS. It is based on the file of the same name in glib. It is not 23 | # needed for distributed versions, because all the necessary files are 24 | # included in the tarball by autoconf. 25 | 26 | srcdir=`dirname $0` 27 | test -z "$srcdir" && srcdir=. 28 | 29 | ORIGDIR=`pwd` 30 | cd $srcdir 31 | PROJECT=librsync 32 | TEST_TYPE=-f 33 | FILE=librsync.h 34 | 35 | DIE=0 36 | 37 | cache="$srcdir/autom4te.cache" 38 | test -d "$cache" && { 39 | echo "Deleting $cache" 40 | rm -Rf "$cache" 41 | } 42 | 43 | # ChangeLog is autogenerated, and must be deleted otherwise automake makes 44 | # assumptions about its existance. 45 | changelog="$srcdir/ChangeLog" 46 | test -f "$changelog" && { 47 | echo "Deleting $changelog" 48 | rm -Rf "$changelog" 49 | } 50 | 51 | (autoconf --version) < /dev/null > /dev/null 2>&1 || { 52 | echo 53 | echo "You must have autoconf installed to compile $PROJECT." 54 | echo "Download the appropriate package for your distribution," 55 | echo "or get the source tarball at ftp://ftp.gnu.org/pub/gnu/" 56 | DIE=1 57 | } 58 | 59 | (automake --version) < /dev/null > /dev/null 2>&1 || { 60 | echo 61 | echo "You must have automake installed to compile $PROJECT." 62 | echo "Download the appropriate package for your distribution," 63 | echo "or get ftp://sourceware.cygnus.com/pub/automake/automake-1.4.tar.gz" 64 | echo "(or a newer version if it is available)" 65 | DIE=1 66 | } 67 | 68 | (libtool --version) < /dev/null > /dev/null 2>&1 || { 69 | echo 70 | echo "You must have libtool installed to compile $PROJECT." 71 | echo "Download the appropriate package for your distribution," 72 | echo "or go to http://www.gnu.org/software/libtool/" 73 | DIE=1 74 | } 75 | 76 | if test "$DIE" -eq 1; then 77 | exit 1 78 | fi 79 | 80 | test $TEST_TYPE $FILE || { 81 | echo "You must run this script in the top-level $PROJECT directory" 82 | exit 1 83 | } 84 | 85 | case $CC in 86 | *xlc | *xlc\ * | *lcc | *lcc\ *) am_opt=--include-deps;; 87 | esac 88 | 89 | set -x 90 | aclocal $ACLOCAL_FLAGS 91 | libtoolize --force 92 | autoheader 93 | automake -a --foreign $am_opt 94 | autoconf 95 | set +x 96 | cd $ORIGDIR 97 | -------------------------------------------------------------------------------- /librsync/checksum.c: -------------------------------------------------------------------------------- 1 | /*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- 2 | * 3 | * librsync -- the library for network deltas 4 | * $Id: checksum.c,v 1.35 2003/06/12 05:47:21 wayned Exp $ 5 | * 6 | * Copyright (C) 1999, 2000, 2001 by Martin Pool 7 | * Copyright (C) 1996 by Andrew Tridgell 8 | * Copyright (C) 1996 by Paul Mackerras 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU Lesser General Public License as published by 12 | * the Free Software Foundation; either version 2.1 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU Lesser General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU Lesser General Public License 21 | * along with this program; if not, write to the Free Software 22 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 23 | */ 24 | 25 | #include 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | #include "librsync.h" 32 | #include "checksum.h" 33 | 34 | 35 | /* This can possibly be used to restart the checksum system in the 36 | * case where we detected corruption. I'm not sure yet how to make 37 | * this useful in librsync. */ 38 | int checksum_seed = 0; 39 | 40 | /* 41 | * A simple 32 bit checksum that can be updated from either end 42 | * (inspired by Mark Adler's Adler-32 checksum) 43 | */ 44 | unsigned int rs_calc_weak_sum(void const *p, int len) 45 | { 46 | int i; 47 | unsigned s1, s2; 48 | unsigned char const *buf = (unsigned char const *) p; 49 | 50 | s1 = s2 = 0; 51 | for (i = 0; i < (len - 4); i += 4) { 52 | s2 += 4 * (s1 + buf[i]) + 3 * buf[i + 1] + 53 | 2 * buf[i + 2] + buf[i + 3] + 10 * RS_CHAR_OFFSET; 54 | s1 += (buf[i + 0] + buf[i + 1] + buf[i + 2] + buf[i + 3] + 55 | 4 * RS_CHAR_OFFSET); 56 | } 57 | for (; i < len; i++) { 58 | s1 += (buf[i] + RS_CHAR_OFFSET); 59 | s2 += s1; 60 | } 61 | return (s1 & 0xffff) + (s2 << 16); 62 | } 63 | 64 | 65 | /** 66 | * Calculate and store into SUM a strong MD4 checksum of the file 67 | * blocks seen so far. 68 | * 69 | * In plain rsync, the checksum is perturbed by a seed value. This is 70 | * used when retrying a failed transmission: we've discovered that the 71 | * hashes collided at some point, so we're going to try again with 72 | * different hashes to see if we can get it right. (Check tridge's 73 | * thesis for details and to see if that's correct.) 74 | * 75 | * Since we can't retry a web transaction I'm not sure if it's very 76 | * useful in rproxy. 77 | */ 78 | void rs_calc_strong_sum(void const *buf, size_t len, rs_strong_sum_t *sum) 79 | { 80 | rs_mdfour((unsigned char *) sum, buf, len); 81 | } 82 | -------------------------------------------------------------------------------- /librsync/doc/librsync.3: -------------------------------------------------------------------------------- 1 | .\" 2 | .\" librsync -- dynamic caching and delta update in HTTP 3 | .\" $Id: librsync.3,v 1.2 2003/06/12 06:03:32 wayned Exp $ 4 | .\" 5 | .\" Copyright (C) 2000, 2001 by Martin Pool 6 | .\" 7 | .\" This program is free software; you can redistribute it and/or 8 | .\" modify it under the terms of the GNU Lesser General Public License 9 | .\" as published by the Free Software Foundation; either version 2.1 of 10 | .\" the License, or (at your option) any later version. 11 | .\" 12 | .\" This program is distributed in the hope that it will be useful, but 13 | .\" WITHOUT ANY WARRANTY; without even the implied warranty of 14 | .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | .\" Lesser General Public License for more details. 16 | .\" 17 | .\" You should have received a copy of the GNU Lesser General Public 18 | .\" License along with this program; if not, write to the Free Software 19 | .\" Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 | .\" 21 | .TH librsync 3 "$Date: 2003/06/12 06:03:32 $" "Martin Pool" 22 | .SH NAME 23 | librsync \- library for delta compression of streams 24 | .SH SYNOPSYS 25 | #include \fB\fP 26 | .br 27 | #include \fB\fP 28 | .br 29 | #include \fB\fP 30 | 31 | cc ... \fB-lrsync\fP 32 | 33 | .SH DESCRIPTION 34 | The \fBlibrsync\fP library implements network delta-compression of 35 | streams and files. The algorithm is similar to that used in the 36 | \fBrsync(1)\fP and \fBxdelta(2)\fP programs, but specialized for 37 | transfer of arbitrary-length octet streams. Unlike most diff 38 | programs, \fBlibrsync\fP does not require access to both of the files 39 | on the same machine, but rather only a short ``signature'' of the old 40 | file and the complete contents of the new file. 41 | .PP 42 | The canonical use of \fBlibrsync\fP is in the \fBrproxy(8)\fP 43 | reference implementation of the \fIrsync\fP proposed extension to 44 | HTTP. It may be useful to other programs which wish to do 45 | delta-compression in HTTP, or within their own protocol. There are 46 | HTTP-specific utility functions within \fBlibrsync\fP, but they need 47 | not be used. 48 | .PP 49 | A number of tools such as \fBrdiff(1)\fP provide command-line and 50 | scriptable access to rsync functions. 51 | .SH "SEE ALSO" 52 | .BR rdiff "(1)" 53 | .PP 54 | .I rdiff and librsync Manual 55 | .PP 56 | \fIhttp://rproxy.sourceforge.net/\fP or \fIhttp://linuxcare.com.au/rproxy/\fP. 57 | .PP 58 | \fIdraft-pool-rsync\fP 59 | .SH BUGS 60 | The rsync protocol is still evolving. There may be bugs in the 61 | implementation. The interface may change in the future, but it is 62 | becoming more stable. 63 | .PP 64 | Many routines will panic in case of error rather than returning an 65 | error code to the caller. Patches to fix this are welcome, but at the 66 | current state of development aborting seems as useful as trusting to 67 | possibly-incomplete checking in the client. 68 | .SH "AUTHOR" 69 | Martin Pool , with Andrew Tridgell . 70 | .PP 71 | rdiff development has been supported by Linuxcare, Inc and VA Linux 72 | Systems. 73 | -------------------------------------------------------------------------------- /librsync/msg.c: -------------------------------------------------------------------------------- 1 | /*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- 2 | * 3 | * librsync -- the library for network deltas 4 | * $Id: msg.c,v 1.15 2003/06/12 05:47:22 wayned Exp $ 5 | * 6 | * Copyright (C) 2000, 2001 by Martin Pool 7 | * 8 | * This program is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public License 10 | * as published by the Free Software Foundation; either version 2.1 of 11 | * the License, or (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | * Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 | */ 22 | 23 | 24 | /* 25 | | Welcome to Arco AM/PM Mini-Market. We 26 | | would like to advise our customers 27 | | that any individual who offers to 28 | | pump gas, wash windows or solicit 29 | | products is not employed by or 30 | | associated with this facility. We 31 | | discourage any contact with these 32 | | individuals and ask that you report 33 | | any problems to uniformed personal 34 | | inside. Thankyou for shopping at 35 | | Arco, and have a nice day. 36 | */ 37 | 38 | #include 39 | 40 | #include 41 | #include 42 | 43 | #include "librsync.h" 44 | 45 | /* 46 | * TODO: (Suggestion by tridge) Add a function which outputs a 47 | * complete text description of a job, including only the fields 48 | * relevant to the current encoding function. 49 | */ 50 | 51 | 52 | /** \brief Translate from rs_result to human-readable messages. */ 53 | char const *rs_strerror(rs_result r) 54 | { 55 | switch (r) { 56 | case RS_DONE: 57 | return "OK"; 58 | case RS_RUNNING: 59 | return "still running"; 60 | case RS_BLOCKED: 61 | return "blocked waiting for input or output buffers"; 62 | case RS_BAD_MAGIC: 63 | return "bad magic number at start of stream"; 64 | case RS_INPUT_ENDED: 65 | return "unexpected end of input"; 66 | case RS_CORRUPT: 67 | return "stream corrupt"; 68 | case RS_UNIMPLEMENTED: 69 | return "unimplemented case"; 70 | case RS_MEM_ERROR: 71 | return "out of memory"; 72 | case RS_IO_ERROR: 73 | return "IO error"; 74 | case RS_SYNTAX_ERROR: 75 | return "bad command line syntax"; 76 | case RS_INTERNAL_ERROR: 77 | return "library internal error"; 78 | 79 | default: 80 | return "unexplained problem"; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /php_rsync.h: -------------------------------------------------------------------------------- 1 | /* 2 | +--------------------------------------------------------------------+ 3 | | PECL :: rsync | 4 | +--------------------------------------------------------------------+ 5 | | Redistribution and use in source and binary forms, with or without | 6 | | modification, are permitted provided that the conditions mentioned | 7 | | in the accompanying LICENSE file are met. | 8 | +--------------------------------------------------------------------+ 9 | | Copyright (c) 2010 Michele Catalano | 10 | | Anatoliy Belsky | 11 | +--------------------------------------------------------------------+ 12 | */ 13 | 14 | /* $Id: header 252479 2008-02-07 19:39:50Z iliaa $ */ 15 | 16 | #ifndef PHP_RSYNC_H 17 | #define PHP_RSYNC_H 18 | 19 | #define PHP_RSYNC_EXTNAME "rsync" 20 | #define PHP_RSYNC_EXTVER "0.1.0" 21 | 22 | extern zend_module_entry rsync_module_entry; 23 | #define phpext_rsync_ptr &rsync_module_entry 24 | 25 | #ifdef PHP_WIN32 26 | # define PHP_RSYNC_API __declspec(dllexport) 27 | #elif defined(__GNUC__) && __GNUC__ >= 4 28 | # define PHP_RSYNC_API __attribute__ ((visibility("default"))) 29 | #else 30 | # define PHP_RSYNC_API 31 | #endif 32 | 33 | #ifdef ZTS 34 | #include "TSRM.h" 35 | #endif 36 | 37 | #define RSYNC_HAVE_PHP_53 ZEND_MODULE_API_NO >= 20071006 38 | 39 | #include "external_libraries.h" 40 | 41 | PHP_MINIT_FUNCTION(rsync); 42 | PHP_MSHUTDOWN_FUNCTION(rsync); 43 | PHP_RINIT_FUNCTION(rsync); 44 | PHP_RSHUTDOWN_FUNCTION(rsync); 45 | PHP_MINFO_FUNCTION(rsync); 46 | 47 | PHP_FUNCTION(rsync_generate_signature); 48 | PHP_FUNCTION(rsync_generate_delta); 49 | PHP_FUNCTION(rsync_patch_file); 50 | PHP_FUNCTION(rsync_set_log_callback); 51 | PHP_FUNCTION(rsync_set_log_level); 52 | PHP_FUNCTION(rsync_error); 53 | 54 | PHP_METHOD(Rsync, __construct); 55 | PHP_METHOD(Rsync, generateSignature); 56 | PHP_METHOD(Rsync, generateDelta); 57 | PHP_METHOD(Rsync, patchFile); 58 | PHP_METHOD(Rsync, setLogCallback); 59 | PHP_METHOD(Rsync, setLogLevel); 60 | PHP_METHOD(Rsync, getError); 61 | 62 | 63 | 64 | ZEND_BEGIN_MODULE_GLOBALS(rsync) 65 | char *tmp_dir; 66 | long block_length; 67 | long strong_length; 68 | rs_stats_t stats; 69 | rs_result ret; 70 | struct php_rsync_log_callback { 71 | zend_fcall_info fci; 72 | zend_fcall_info_cache fcc; 73 | } log_cb; 74 | int error; 75 | int has_log_cb; 76 | long log_stats; 77 | ZEND_END_MODULE_GLOBALS(rsync) 78 | 79 | struct ze_rsync_main_obj { 80 | zend_object zo; 81 | long block_length; 82 | long strong_length; 83 | rs_stats_t stats; 84 | rs_result ret; 85 | }; 86 | #ifdef ZTS 87 | #define RSYNC_G(v) TSRMG(rsync_globals_id, zend_rsync_globals *, v) 88 | #else 89 | #define RSYNC_G(v) (rsync_globals.v) 90 | #endif 91 | 92 | //extern zend_object_value php_rsync_object_init(zend_class_entry *ze TSRMLS_CC); 93 | 94 | #endif /* PHP_RSYNC_H */ 95 | 96 | 97 | /* 98 | * Local variables: 99 | * tab-width: 4 100 | * c-basic-offset: 4 101 | * End: 102 | * vim600: noet sw=4 ts=4 fdm=marker 103 | * vim<600: noet sw=4 ts=4 104 | */ 105 | -------------------------------------------------------------------------------- /config.m4: -------------------------------------------------------------------------------- 1 | dnl $Id$ 2 | dnl config.m4 for extension rsync 3 | 4 | dnl Comments in this file start with the string 'dnl'. 5 | 6 | PHP_ARG_WITH(rsync, for rsync support, 7 | [ --with-rsync Include rsync support]) 8 | 9 | if test "$PHP_RSYNC" != "no"; then 10 | dnl # --with-rsync -> check with-path 11 | SEARCH_PATH="/usr/local /usr" 12 | SEARCH_FOR="include/librsync.h" 13 | if test -r $PHP_RSYNC/$SEARCH_FOR; then # path given as parameter 14 | RSYNC_DIR=$PHP_RSYNC 15 | else 16 | AC_MSG_CHECKING([for rsync library to use]) 17 | AC_MSG_RESULT([bundled]) 18 | if test -d librsync; then 19 | dnl doing the bundled librsync config 20 | cd librsync 21 | ./configure 22 | cd .. 23 | 24 | librsync_sources="librsync/prototab.c librsync/base64.c librsync/buf.c \ 25 | librsync/checksum.c librsync/command.c librsync/delta.c librsync/emit.c \ 26 | librsync/fileutil.c librsync/hex.c librsync/job.c librsync/mdfour.c \ 27 | librsync/mksum.c librsync/msg.c librsync/netint.c \ 28 | librsync/patch.c librsync/readsums.c \ 29 | librsync/rollsum.c librsync/scoop.c librsync/search.c librsync/stats.c \ 30 | librsync/stream.c librsync/sumset.c librsync/trace.c librsync/tube.c \ 31 | librsync/util.c librsync/version.c librsync/whole.c" 32 | PHP_NEW_EXTENSION(rsync, $librsync_sources rsync.c, $ext_shared,,-I./librsync) 33 | 34 | PHP_ADD_BUILD_DIR($ext_builddir/librsync) 35 | dnl PHP_INSTALL_HEADERS([ext/rsync], [php_rsync.h rsync/]) 36 | AC_DEFINE(HAVE_BUNDLED_RSYNC, 1, [ ]) 37 | AC_CHECK_FUNCS([snprintf vsnprintf], [], []) 38 | 39 | dnl AC_CHECK_HEADERS([librsync/prototab.h librsync/buf.h librsync/checksum.h librsync/command.h librsync/emit.h librsync/fileutil.h librsync/job.h librsync/mdfour.h librsync/netint.h librsync/protocol.h librsync/librsync.h librsync/librsync-config.h librsync/rollsum.h librsync/search.h librsync/stream.h librsync/sumset.h librsync/trace.h librsync/types.h librsync/util.h librsync/whole.h librsync/snprintf.h], [], []) 40 | else 41 | AC_MSG_RESULT([not found]) 42 | # search default path list 43 | AC_MSG_CHECKING([for librsync files in default path]) 44 | for i in $SEARCH_PATH ; do 45 | if test -r $i/$SEARCH_FOR; then 46 | RSYNC_DIR=$i 47 | AC_MSG_RESULT(found in $i) 48 | fi 49 | done 50 | if test -z "$RSYNC_DIR"; then 51 | AC_MSG_RESULT([not found]) 52 | AC_MSG_ERROR([Please install librsync or put source unter librsync directory here]) 53 | fi 54 | fi 55 | fi 56 | 57 | if ! test -z "$RSYNC_DIR"; then 58 | dnl set the infos to the externel lib 59 | 60 | dnl # --with-rsync -> check for lib and symbol presence 61 | LIBNAME=rsync 62 | LIBSYMBOL=rs_librsync_version 63 | 64 | PHP_CHECK_LIBRARY($LIBNAME,$LIBSYMBOL, 65 | [ 66 | PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, $RSYNC_DIR/lib, RSYNC_SHARED_LIBADD) 67 | AC_DEFINE(HAVE_RSYNCLIB,1,[ ]) 68 | ],[ 69 | AC_MSG_ERROR([wrong librsync version or lib not found]) 70 | ],[ 71 | -L$RSYNC_DIR/lib -lm 72 | ]) 73 | 74 | PHP_NEW_EXTENSION(rsync, rsync.c, $ext_shared) 75 | fi 76 | 77 | dnl # --with-rsync -> add include path 78 | PHP_ADD_INCLUDE($RSYNC_DIR/include) 79 | 80 | dnl 81 | PHP_SUBST(RSYNC_SHARED_LIBADD) 82 | 83 | fi 84 | -------------------------------------------------------------------------------- /librsync/base64.c: -------------------------------------------------------------------------------- 1 | /*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- 2 | * 3 | * librsync -- the library for network deltas 4 | * $Id: base64.c,v 1.10 2003/06/12 05:47:21 wayned Exp $ 5 | * 6 | * Copyright (C) 2000 by Martin Pool 7 | * 8 | * This program is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public License 10 | * as published by the Free Software Foundation; either version 2.1 of 11 | * the License, or (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | * Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 | */ 22 | 23 | 24 | #include 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | #include "librsync.h" 31 | 32 | /* 33 | * Decode a base64 string in-place - simple and slow algorithm 34 | * 35 | * See RFC1521 for the specification of base64. 36 | */ 37 | size_t rs_unbase64(char *s) 38 | { 39 | char const *b64 = 40 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; 41 | int bit_offset, byte_offset, idx, i, n; 42 | unsigned char *d = (unsigned char *) s; 43 | char *p; 44 | 45 | n = i = 0; 46 | 47 | while (*s && (p = strchr(b64, *s))) { 48 | idx = (int) (p - b64); 49 | byte_offset = (i * 6) / 8; 50 | bit_offset = (i * 6) % 8; 51 | d[byte_offset] &= ~((1 << (8 - bit_offset)) - 1); 52 | if (bit_offset < 3) { 53 | d[byte_offset] |= (idx << (2 - bit_offset)); 54 | n = byte_offset + 1; 55 | } else { 56 | d[byte_offset] |= (idx >> (bit_offset - 2)); 57 | d[byte_offset + 1] = 0; 58 | d[byte_offset + 1] |= (idx << (8 - (bit_offset - 2))) & 0xFF; 59 | n = byte_offset + 2; 60 | } 61 | s++; 62 | i++; 63 | } 64 | 65 | return n; 66 | } 67 | 68 | /* 69 | * Encode a buffer as base64 - simple and slow algorithm. 70 | */ 71 | void 72 | rs_base64(unsigned char const *buf, int n, char *out) 73 | { 74 | char const *b64 = 75 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; 76 | int bytes, i; 77 | 78 | /* work out how many bytes of output there are */ 79 | bytes = ((n * 8) + 5) / 6; 80 | 81 | for (i = 0; i < bytes; i++) { 82 | int byte = (i * 6) / 8; 83 | int bit = (i * 6) % 8; 84 | 85 | if (bit < 3) { 86 | if (byte >= n) 87 | abort(); 88 | *out = b64[(buf[byte] >> (2 - bit)) & 0x3F]; 89 | } else { 90 | if (byte + 1 == n) { 91 | *out = b64[(buf[byte] << (bit - 2)) & 0x3F]; 92 | } else { 93 | *out = b64[(buf[byte] << (bit - 2) | 94 | buf[byte + 1] >> (10 - bit)) & 0x3F]; 95 | } 96 | } 97 | out++; 98 | } 99 | *out = 0; 100 | } 101 | 102 | -------------------------------------------------------------------------------- /librsync/README.CVS: -------------------------------------------------------------------------------- 1 | CVS Instructions for librsync 2 | ----------------------------- 3 | 4 | If you're building from CVS, things are slightly more complicated than 5 | usual. I hope these instructions will tell you all you need to know. 6 | Please mail if they are unclear 7 | or incorrect. Also read HACKING for a description of development 8 | conventions used by the project. 9 | 10 | The librsync project is currently hosted on sourceforge. Everything, 11 | including CVS, can be found at; 12 | 13 | http://sourceforge.net/projects/librsync/ 14 | 15 | 16 | >> Requirements 17 | 18 | To build from CVS you will probably need at least automake 1.7, autoconf 19 | 2.53, and libtool 1.4.3, plus a compiler, make and so on. You might get away 20 | with earlier versions of the autotools stuff, but these versions are known 21 | to work. On Debian, you can simply say 22 | 23 | # apt-get install automake1.7 autoconf libtool 24 | 25 | To generate API documentation, you will need Doxygen, Latex and GhostView: 26 | 27 | # apt-get install doxygen gs tetex 28 | 29 | To generate the ChangeLog needed when creating a distribution, you will need 30 | cvs2cl; 31 | 32 | # apt-get install cvs2cl 33 | 34 | 35 | >> Downloading 36 | 37 | $ cvs -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/librsync login 38 | [When prompted for a password, simply press the Enter key] 39 | $ cvs -z3 -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/librsync \ 40 | -d YOUR_DIRECTORY co librsync 41 | 42 | You can choose the name of the directory that will hold the source here. If 43 | you have no opinion, just omit the `-d YOUR_DIRECTORY' and it will go into 44 | `librsync'. For more details, see the web site. 45 | 46 | 47 | >> Building 48 | 49 | $ cd YOUR_DIRECTORY 50 | $ ./autogen.sh [OPTIONS] 51 | $ ./configure 52 | $ make all check 53 | 54 | You can pass all the ./configure options to autogen, including --help. 55 | 56 | 57 | >> Debugging 58 | 59 | If you are using GNU libc, you might like to use 60 | 61 | MALLOC_CHECK_=2 ./rdiff 62 | 63 | to detect some allocation bugs. Report any bugs you find to the bug tracker. 64 | 65 | 66 | >> Sending patches 67 | 68 | If you make a change to the source and would like to contribute it back, do 69 | this: 70 | 71 | $ cvs diff -u -N >/tmp/my.librsync.patch 72 | 73 | and submit to the patch tracker. 74 | 75 | 76 | >> Releasing 77 | 78 | Make sure you have cvs2cl installed to generate ChangeLog. Before a 79 | formal release, make sure that the following files have been updated 80 | to reflect the new version: 81 | 82 | * AUTHORS - make sure all significant authors are included. 83 | 84 | * NEWS - make sure the top "Changes in X.Y.Z" is correct. 85 | 86 | * THANKS - make sure the bottom "Contributors for X.Y.Z" is correct. 87 | 88 | * configure.ac - make sure AC_INIT and librsync_libversion are right. 89 | 90 | * libversions.txt - make sure libversion is added. 91 | 92 | * librsync.spec - make sure version and URL are right. 93 | 94 | * PCBuild/config.h,librsync-config.h - update using configure.msc 95 | using cygwin. 96 | 97 | Do a complete configure and distcheck to ensure everything is properly 98 | configured, built, and tested: 99 | 100 | $ ./autogen.sh [OPTIONS] 101 | $ ./configure 102 | $ make distcheck 103 | 104 | $Id: README.CVS,v 1.16 2003/12/15 06:18:07 abo Exp $ 105 | -------------------------------------------------------------------------------- /librsync/THANKS: -------------------------------------------------------------------------------- 1 | -*- text -*- 2 | Originators and Contributors up to 0.9.5 3 | --------------------------------------- 4 | 5 | Andrew Tridgell and Paulus Mackerras started this whole mess. Luke 6 | Leighton was a tremendous help in sorting out the combined 7 | encoding/signature algorithm. 8 | 9 | Thanks to Linuxcare, Inc, for their support of this project. 10 | 11 | Neale Banks : the first known user outside of 12 | OzLabs. 13 | 14 | Paul `Rusty' Russell 15 | Andrew Tridgell 16 | Paulus Mackerras 17 | Peter Barker 18 | Neale Banks 19 | Luke Kenneth Casson Leighton 20 | Tim Potter 21 | Hugh Blemings 22 | David Gibson 23 | 24 | 25 | Contributors by release 26 | ----------------------- 27 | 28 | The following is a list of contributors for each release. It is 29 | possible we have missed some contributors. If you know of anyone who 30 | has been omitted and deserves to be included, please send the details 31 | so they can be added. 32 | 33 | Contributors for 0.9.6 34 | 35 | * Wayne Davison 36 | - librsync sf project admin 37 | - sf project creation, import cvs etc 38 | - many cvs commits of submitted patches 39 | - rsync.h -> librsync.h rename 40 | - librsync-conf.h addition and config.h issue resolution 41 | 42 | * Martin Pool 43 | - sf project admin 44 | - sf project developers setup 45 | 46 | * Donovan Baarda 47 | - librsync sf project admin 48 | - sf project tracker and lists setup 49 | - MSVC6 and cygwin compiling patch and updates 50 | - mdfour optimisations and cleanups patch 51 | - autconf/autmake cleanups 52 | - large file debugging and fixes 53 | - build and release 54 | 55 | * Ben Escoto 56 | - librsync sf project admin 57 | 58 | * Ben Elliston 59 | - many cvs commits before migrating to sf 60 | 61 | * Robert Weber 62 | - bigendian and >512M mdfour patch 63 | 64 | * Skip Montanaro 65 | - librsync on MacOSX patch 66 | 67 | * Diego Liziero 68 | - memory leak patches 69 | - again rdiff cosmetic patch 70 | 71 | * Berkan Eskikaya 72 | - Control files for librsync debian packages patch 73 | 74 | * Mark Moraes 75 | - cygwin testsuite fixes email patch 76 | 77 | * Robert Collins 78 | - autoconf/automake cleanups email (old patch) 79 | 80 | * Paul Green 81 | - large file testing and debugging 82 | 83 | 84 | Contributors for 0.9.7 (release pending) 85 | 86 | * Donovan Baarda 87 | - librsync sf project admin 88 | - delta refactor patch 89 | - bug resolution 90 | 91 | * Martin Pool 92 | - sf project admin 93 | - documentation updates. 94 | - bug fixes 95 | 96 | * John Goerzen 97 | - Debian package maintainence 98 | 99 | * Dave Coombs 100 | - C++ wrapper patch 101 | 102 | * Eran Tromer 103 | - [#855477] buf.c incorrect header order, and fix. 104 | 105 | - [#1022764] Reported and diagnosed nasty corruption bug with large 106 | files. 107 | 108 | * Simon Law 109 | - [#879763] Fixed problems with unaligned access in mdfour. 110 | -------------------------------------------------------------------------------- /librsync/popt/poptconfig.c: -------------------------------------------------------------------------------- 1 | /* (C) 1998 Red Hat Software, Inc. -- Licensing details are in the COPYING 2 | file accompanying popt source distributions, available from 3 | ftp://ftp.redhat.com/pub/code/popt */ 4 | 5 | #include "system.h" 6 | #include "poptint.h" 7 | 8 | static void configLine(poptContext con, char * line) { 9 | int nameLength = strlen(con->appName); 10 | char * opt; 11 | struct poptAlias alias; 12 | char * entryType; 13 | char * longName = NULL; 14 | char shortName = '\0'; 15 | 16 | if (strncmp(line, con->appName, nameLength)) return; 17 | line += nameLength; 18 | if (!*line || !isspace(*line)) return; 19 | while (*line && isspace(*line)) line++; 20 | entryType = line; 21 | 22 | while (!*line || !isspace(*line)) line++; 23 | *line++ = '\0'; 24 | while (*line && isspace(*line)) line++; 25 | if (!*line) return; 26 | opt = line; 27 | 28 | while (!*line || !isspace(*line)) line++; 29 | *line++ = '\0'; 30 | while (*line && isspace(*line)) line++; 31 | if (!*line) return; 32 | 33 | if (opt[0] == '-' && opt[1] == '-') 34 | longName = opt + 2; 35 | else if (opt[0] == '-' && !opt[2]) 36 | shortName = opt[1]; 37 | 38 | if (!strcmp(entryType, "alias")) { 39 | if (poptParseArgvString(line, &alias.argc, &alias.argv)) return; 40 | alias.longName = longName, alias.shortName = shortName; 41 | poptAddAlias(con, alias, 0); 42 | } else if (!strcmp(entryType, "exec")) { 43 | con->execs = realloc(con->execs, 44 | sizeof(*con->execs) * (con->numExecs + 1)); 45 | if (longName) 46 | con->execs[con->numExecs].longName = xstrdup(longName); 47 | else 48 | con->execs[con->numExecs].longName = NULL; 49 | 50 | con->execs[con->numExecs].shortName = shortName; 51 | con->execs[con->numExecs].script = xstrdup(line); 52 | 53 | con->numExecs++; 54 | } 55 | } 56 | 57 | int poptReadConfigFile(poptContext con, const char * fn) { 58 | char * file, * chptr, * end; 59 | char * buf, * dst; 60 | int fd, rc; 61 | int fileLength; 62 | 63 | fd = open(fn, O_RDONLY); 64 | if (fd < 0) { 65 | if (errno == ENOENT) 66 | return 0; 67 | else 68 | return POPT_ERROR_ERRNO; 69 | } 70 | 71 | fileLength = lseek(fd, 0, SEEK_END); 72 | (void) lseek(fd, 0, 0); 73 | 74 | file = alloca(fileLength + 1); 75 | if (read(fd, file, fileLength) != fileLength) { 76 | rc = errno; 77 | close(fd); 78 | errno = rc; 79 | return POPT_ERROR_ERRNO; 80 | } 81 | close(fd); 82 | 83 | dst = buf = alloca(fileLength + 1); 84 | 85 | chptr = file; 86 | end = (file + fileLength); 87 | while (chptr < end) { 88 | switch (*chptr) { 89 | case '\n': 90 | *dst = '\0'; 91 | dst = buf; 92 | while (*dst && isspace(*dst)) dst++; 93 | if (*dst && *dst != '#') { 94 | configLine(con, dst); 95 | } 96 | chptr++; 97 | break; 98 | case '\\': 99 | *dst++ = *chptr++; 100 | if (chptr < end) { 101 | if (*chptr == '\n') 102 | dst--, chptr++; 103 | /* \ at the end of a line does not insert a \n */ 104 | else 105 | *dst++ = *chptr++; 106 | } 107 | break; 108 | default: 109 | *dst++ = *chptr++; 110 | break; 111 | } 112 | } 113 | 114 | return 0; 115 | } 116 | 117 | int poptReadDefaultConfig(poptContext con, /*@unused@*/ int useEnv) { 118 | char * fn, * home; 119 | int rc; 120 | 121 | if (!con->appName) return 0; 122 | 123 | rc = poptReadConfigFile(con, "/etc/popt"); 124 | if (rc) return rc; 125 | if (getuid() != geteuid()) return 0; 126 | 127 | if ((home = getenv("HOME"))) { 128 | fn = alloca(strlen(home) + 20); 129 | strcpy(fn, home); 130 | strcat(fn, "/.popt"); 131 | rc = poptReadConfigFile(con, fn); 132 | if (rc) return rc; 133 | } 134 | 135 | return 0; 136 | } 137 | 138 | -------------------------------------------------------------------------------- /librsync/mkprototab.pl: -------------------------------------------------------------------------------- 1 | #! /usr/bin/perl -w 2 | 3 | use strict; 4 | 5 | # librsync -- the library for network deltas 6 | # $Id: mkprototab.pl,v 1.6 2003/06/12 06:01:26 wayned Exp $ 7 | # 8 | # Copyright (C) 2000, 2001 by Martin Pool 9 | # 10 | # This program is free software; you can redistribute it and/or 11 | # modify it under the terms of the GNU Lesser General Public License 12 | # as published by the Free Software Foundation; either version 2.1 of 13 | # the License, or (at your option) any later version. 14 | # 15 | # This program is distributed in the hope that it will be useful, but 16 | # WITHOUT ANY WARRANTY; without even the implied warranty of 17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 | # Lesser General Public License for more details. 19 | # 20 | # You should have received a copy of the GNU Lesser General Public 21 | # License along with this program; if not, write to the Free Software 22 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 23 | 24 | 25 | # I think if you've ordered 26 | # somebody to do something you 27 | # should probably resist the urge 28 | # to thank them. 29 | # -- http://abc.net.au/thegames/ 30 | 31 | 32 | $#ARGV == 1 or die "Usage: mkprototab.pl TABLE HEADER"; 33 | 34 | open(TABLE, ">$ARGV[0]") or die "Can't open table $ARGV[0]: $!"; 35 | open(HEADER, ">$ARGV[1]") or die "Can't open header $ARGV[1]: $!"; 36 | 37 | 38 | my $cmd_byte = 0; 39 | 40 | 41 | sub emit_cmd { 42 | my ($kind, $lit_val, $len1, $len2) = @_; 43 | my $op; 44 | 45 | if ($cmd_byte) { 46 | # not first 47 | print TABLE ",\n"; 48 | print HEADER ",\n"; 49 | } 50 | 51 | if ($len2) { 52 | $op = sprintf "RS_OP_%s_N%d_N%d", $kind, $len1, $len2; 53 | } elsif ($len1) { 54 | $op = sprintf "RS_OP_%s_N%d", $kind, $len1; 55 | } elsif ($lit_val) { 56 | $op = sprintf "RS_OP_%s_%d", $kind, $lit_val; 57 | } else { 58 | $op = sprintf "RS_OP_%s", $kind; 59 | } 60 | 61 | push(@_, 0) while @_ < 4; # Avoid run-time warnings. 62 | printf TABLE " {RS_KIND_%-10s, %3d, %d, %d } ", @_; 63 | printf TABLE " /* %20s = %#4x */", $op, $cmd_byte; 64 | printf HEADER " %20s = %#4x", $op, $cmd_byte; 65 | $cmd_byte++; 66 | } 67 | 68 | 69 | print TABLE < 73 | 74 | #include 75 | #include 76 | 77 | #include "librsync.h" 78 | #include 79 | #include 80 | #include 81 | 82 | /* This file defines an array mapping command IDs to the operation kind, 83 | * implied literal value, and length of the first and second parameters. 84 | * The implied value is only used 85 | * if the first parameter length is zero. */ 86 | 87 | const struct rs_prototab_ent rs_prototab[] = { 88 | EOT 89 | 90 | 91 | print HEADER < 7 | * 8 | * This program is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public License 10 | * as published by the Free Software Foundation; either version 2.1 of 11 | * the License, or (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | * Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 | */ 22 | 23 | #include "mdfour.h" 24 | #include "rollsum.h" 25 | 26 | struct rs_job { 27 | int dogtag; 28 | 29 | /** Human-readable job operation name. */ 30 | const char *job_name; 31 | 32 | rs_buffers_t *stream; 33 | 34 | /** Callback for each processing step. */ 35 | rs_result (*statefn)(rs_job_t *); 36 | 37 | /** Final result of processing job. Used by rs_job_s_failed(). */ 38 | rs_result final_result; 39 | 40 | /* XXX: These next two are redundant with their equivalents in the 41 | * signature field. Perhaps we should get rid of them, but 42 | * they're also used in the mksum operation. */ 43 | int block_len; 44 | int strong_sum_len; 45 | 46 | /** Signature that's either being read in, or used for 47 | * generating a delta. */ 48 | rs_signature_t *signature; 49 | 50 | /** Command byte currently being processed, if any. */ 51 | unsigned char op; 52 | 53 | /** The weak signature digest used by readsums.c */ 54 | rs_weak_sum_t weak_sig; 55 | 56 | /** The rollsum weak signature accumulator used by delta.c */ 57 | Rollsum weak_sum; 58 | 59 | /** Lengths of expected parameters. */ 60 | rs_long_t param1, param2; 61 | 62 | struct rs_prototab_ent const *cmd; 63 | rs_mdfour_t output_md4; 64 | 65 | /** Encoding statistics. */ 66 | rs_stats_t stats; 67 | 68 | /** 69 | * Buffer of data in the scoop. Allocation is 70 | * scoop_buf[0..scoop_alloc], and scoop_next[0..scoop_avail] contains 71 | * data yet to be processed. scoop_next[scoop_pos..scoop_avail] is the 72 | * data yet to be scanned. */ 73 | char *scoop_buf; /* the allocation pointer */ 74 | char *scoop_next; /* the data pointer */ 75 | size_t scoop_alloc; /* the allocation size */ 76 | size_t scoop_avail; /* the data size */ 77 | size_t scoop_pos; /* the scan position */ 78 | 79 | /** If USED is >0, then buf contains that much write data to 80 | * be sent out. */ 81 | char write_buf[20]; 82 | int write_len; 83 | 84 | /** If \p copy_len is >0, then that much data should be copied 85 | * through from the input. */ 86 | rs_long_t copy_len; 87 | 88 | /** Copy from the basis position. */ 89 | rs_long_t basis_pos, basis_len; 90 | 91 | /** Callback used to copy data from the basis into the output. */ 92 | rs_copy_cb *copy_cb; 93 | void *copy_arg; 94 | }; 95 | 96 | 97 | rs_job_t * rs_job_new(const char *, rs_result (*statefn)(rs_job_t *)); 98 | 99 | void rs_job_check(rs_job_t *job); 100 | 101 | int rs_job_input_is_ending(rs_job_t *job); 102 | -------------------------------------------------------------------------------- /librsync/stats.c: -------------------------------------------------------------------------------- 1 | /*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- 2 | * 3 | * $Id: stats.c,v 1.34 2004/09/10 02:48:58 mbp Exp $ 4 | * 5 | * Copyright (C) 2000, 2001 by Martin Pool 6 | * 7 | * This program is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU Lesser General Public License as published by 9 | * the Free Software Foundation; either version 2.1 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public License 18 | * along with this program; if not, write to the Free Software 19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 | */ 21 | 22 | 23 | #include 24 | 25 | #include 26 | #include 27 | #include 28 | #ifdef HAVE_UNISTD_H 29 | #include 30 | #endif 31 | #ifdef HAVE_SYS_FILE_H 32 | #include 33 | #endif 34 | #include 35 | 36 | #include "librsync.h" 37 | #include "trace.h" 38 | #include "snprintf.h" 39 | 40 | /* 41 | * TODO: Other things to show in statistics: 42 | * 43 | * Number of input and output bytes. 44 | * 45 | * Number of times we blocked waiting for input or output. 46 | * 47 | * Number of blocks. 48 | */ 49 | 50 | int 51 | rs_log_stats(rs_stats_t const *stats) 52 | { 53 | char buf[1000]; 54 | 55 | rs_format_stats(stats, buf, sizeof buf - 1); 56 | rs_log(RS_LOG_INFO|RS_LOG_NONAME, "%s", buf); 57 | return 0; 58 | } 59 | 60 | 61 | 62 | /** 63 | * \brief Return a human-readable representation of statistics. 64 | * 65 | * The string is truncated if it does not fit. 100 characters should 66 | * be sufficient space. 67 | * 68 | * \param stats Statistics from an encoding or decoding operation. 69 | * 70 | * \param buf Buffer to receive result. 71 | * \param size Size of buffer. 72 | * \return buf 73 | */ 74 | char * 75 | rs_format_stats(rs_stats_t const * stats, 76 | char *buf, size_t size) 77 | { 78 | char const *op = stats->op; 79 | int len; 80 | 81 | if (!op) 82 | op = "noop"; 83 | 84 | len = snprintf(buf, size, "%s statistics: ", op); 85 | 86 | if (stats->lit_cmds) { 87 | len += snprintf(buf+len, size-len, 88 | "literal[%d cmds, " PRINTF_FORMAT_U64 " bytes, " PRINTF_FORMAT_U64 " cmdbytes] ", 89 | stats->lit_cmds, 90 | PRINTF_CAST_U64(stats->lit_bytes), 91 | PRINTF_CAST_U64(stats->lit_cmdbytes)); 92 | } 93 | 94 | if (stats->sig_cmds) { 95 | len += snprintf(buf+len, size-len, 96 | "in-place-signature[" PRINTF_FORMAT_U64 " cmds, " PRINTF_FORMAT_U64 " bytes] ", 97 | PRINTF_CAST_U64(stats->sig_cmds), 98 | PRINTF_CAST_U64(stats->sig_bytes)); 99 | } 100 | 101 | if (stats->copy_cmds || stats->false_matches) { 102 | len += snprintf(buf+len, size-len, 103 | "copy[" PRINTF_FORMAT_U64 " cmds, " PRINTF_FORMAT_U64 " bytes, " PRINTF_FORMAT_U64 " false, " PRINTF_FORMAT_U64 " cmdbytes]", 104 | PRINTF_CAST_U64(stats->copy_cmds), 105 | PRINTF_CAST_U64(stats->copy_bytes), 106 | PRINTF_CAST_U64(stats->false_matches), 107 | PRINTF_CAST_U64(stats->copy_cmdbytes)); 108 | } 109 | 110 | 111 | if (stats->sig_blocks) { 112 | len += snprintf(buf+len, size-len, 113 | "signature[" PRINTF_FORMAT_U64 " blocks, " PRINTF_FORMAT_U64 " bytes per block]", 114 | PRINTF_CAST_U64(stats->sig_blocks), 115 | PRINTF_CAST_U64(stats->block_len)); 116 | } 117 | 118 | return buf; 119 | } 120 | -------------------------------------------------------------------------------- /librsync/emit.c: -------------------------------------------------------------------------------- 1 | /*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- 2 | * 3 | * librsync -- dynamic caching and delta update in HTTP 4 | * $Id: emit.c,v 1.49 2004/09/10 02:48:58 mbp Exp $ 5 | * 6 | * Copyright (C) 2000, 2001, 2004 by Martin Pool 7 | * 8 | * This program is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public License 10 | * as published by the Free Software Foundation; either version 2.1 of 11 | * the License, or (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | * Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 | */ 22 | 23 | 24 | /* 25 | * TODO: Pluggable encoding formats: 26 | * 27 | * - gdiff-style 28 | * - rsync 24 29 | * - ed (text) 30 | * - Delta HTTP 31 | */ 32 | 33 | 34 | #include 35 | 36 | #include 37 | #include 38 | #include 39 | 40 | #include "librsync.h" 41 | #include "command.h" 42 | #include "protocol.h" 43 | #include "trace.h" 44 | #include "emit.h" 45 | #include "prototab.h" 46 | #include "netint.h" 47 | #include "sumset.h" 48 | #include "job.h" 49 | 50 | 51 | /* 52 | * Write the magic for the start of a delta. 53 | */ 54 | void 55 | rs_emit_delta_header(rs_job_t *job) 56 | { 57 | rs_trace("emit DELTA magic"); 58 | rs_squirt_n4(job, RS_DELTA_MAGIC); 59 | } 60 | 61 | 62 | 63 | /* Write a LITERAL command. */ 64 | void 65 | rs_emit_literal_cmd(rs_job_t *job, int len) 66 | { 67 | int cmd; 68 | int param_len; 69 | 70 | switch (param_len = rs_int_len(len)) { 71 | case 1: 72 | cmd = RS_OP_LITERAL_N1; 73 | break; 74 | case 2: 75 | cmd = RS_OP_LITERAL_N2; 76 | break; 77 | case 4: 78 | cmd = RS_OP_LITERAL_N4; 79 | break; 80 | default: 81 | rs_fatal("What?"); 82 | } 83 | 84 | rs_trace("emit LITERAL_N%d(len=%d), cmd_byte=%#x", param_len, len, cmd); 85 | rs_squirt_byte(job, cmd); 86 | rs_squirt_netint(job, len, param_len); 87 | 88 | job->stats.lit_cmds++; 89 | job->stats.lit_bytes += len; 90 | job->stats.lit_cmdbytes += 1 + param_len; 91 | } 92 | 93 | 94 | /** Write a COPY command for given offset and length. 95 | * 96 | * There is a choice of variable-length encodings, depending on the 97 | * size of representation for the parameters. */ 98 | void 99 | rs_emit_copy_cmd(rs_job_t *job, rs_long_t where, rs_long_t len) 100 | { 101 | int cmd; 102 | rs_stats_t *stats = &job->stats; 103 | const int where_bytes = rs_int_len(where); 104 | const int len_bytes = rs_int_len(len); 105 | 106 | /* Commands ascend (1,1), (1,2), ... (8, 8) */ 107 | if (where_bytes == 8) 108 | cmd = RS_OP_COPY_N8_N1; 109 | else if (where_bytes == 4) 110 | cmd = RS_OP_COPY_N4_N1; 111 | else if (where_bytes == 2) 112 | cmd = RS_OP_COPY_N2_N1; 113 | else if (where_bytes == 1) 114 | cmd = RS_OP_COPY_N1_N1; 115 | else { 116 | rs_fatal("can't encode copy command with where_bytes=%d", 117 | where_bytes); 118 | } 119 | 120 | if (len_bytes == 1) 121 | ; 122 | else if (len_bytes == 2) 123 | cmd += 1; 124 | else if (len_bytes == 4) 125 | cmd += 2; 126 | else if (len_bytes == 8) 127 | cmd += 3; 128 | else { 129 | rs_fatal("can't encode copy command with len_bytes=%d", 130 | len_bytes); 131 | } 132 | 133 | rs_trace("emit COPY_N%d_N%d(where=" PRINTF_FORMAT_U64 134 | ", len=" PRINTF_FORMAT_U64 "), cmd_byte=%#x", 135 | where_bytes, len_bytes, PRINTF_CAST_U64(where), PRINTF_CAST_U64(len), cmd); 136 | rs_squirt_byte(job, cmd); 137 | rs_squirt_netint(job, where, where_bytes); 138 | rs_squirt_netint(job, len, len_bytes); 139 | 140 | stats->copy_cmds++; 141 | stats->copy_bytes += len; 142 | stats->copy_cmdbytes += 1 + where_bytes + len_bytes; 143 | 144 | /* TODO: All the stats */ 145 | } 146 | 147 | 148 | /** Write an END command. */ 149 | void 150 | rs_emit_end_cmd(rs_job_t *job) 151 | { 152 | int cmd = RS_OP_END; 153 | 154 | rs_trace("emit END, cmd_byte=%#x", cmd); 155 | rs_squirt_byte(job, cmd); 156 | } 157 | -------------------------------------------------------------------------------- /librsync/trace.h: -------------------------------------------------------------------------------- 1 | /*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- 2 | * 3 | * librsync -- generate and apply network deltas 4 | * $Id: trace.h,v 1.28 2004/09/10 02:48:58 mbp Exp $ 5 | * 6 | * Copyright (C) 2000, 2001, 2004 by Martin Pool 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU Lesser General Public License as published by 10 | * the Free Software Foundation; either version 2.1 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 | */ 22 | 23 | 24 | /* 25 | * TODO: A function like perror that includes strerror output. Apache 26 | * does this by adding flags as well as the severity level which say 27 | * whether such information should be included. 28 | */ 29 | 30 | 31 | /* 32 | * trace may be turned off. 33 | * 34 | * error is always on, but you can return and continue in some way 35 | * 36 | * fatal terminates the whole process 37 | */ 38 | 39 | 40 | 41 | /* There is no portable way in C99 to printf 64-bit types. Many 42 | * platforms do have a format which will do it, but it's not 43 | * standardized. Therefore these macros. 44 | * 45 | * Not all platforms using gnu C necessarily have a corresponding 46 | * printf, but it's probably a good starting point. Most unix systems 47 | * seem to use %ll. 48 | */ 49 | #if SIZEOF_LONG == 8 50 | # define PRINTF_CAST_U64(x) ((unsigned long) (x)) 51 | # define PRINTF_FORMAT_U64 "%lu" 52 | #elif defined(__GNUC__) 53 | # define PRINTF_CAST_U64(x) ((unsigned long long) (x)) 54 | # define PRINTF_FORMAT_U64 "%llu" 55 | #else 56 | /* This conversion works everywhere, but it's probably pretty slow. 57 | * 58 | * Note that 'f' takes a double vararg, not a float. */ 59 | # define PRINTF_CAST_U64(x) ((double) (x)) 60 | # define PRINTF_FORMAT_U64 "%.0f" 61 | #endif 62 | 63 | 64 | #if defined(HAVE_VARARG_MACROS) && defined(__GNUC__) 65 | /* 66 | * TODO: Don't assume this is a gcc thing; rather test in autoconf for 67 | * support for __FUNCTION__. One simple way might just be to try compiling 68 | * the definition of one of these functions! 69 | * 70 | * TODO: Also look for the C9X predefined identifier `_function', or 71 | * whatever it's called. 72 | */ 73 | 74 | void rs_log0(int level, char const *fn, char const *fmt, ...) 75 | __attribute__ ((format(printf, 3, 4))); 76 | 77 | #ifdef DO_RS_TRACE 78 | # define rs_trace(fmt, arg...) \ 79 | do { rs_log0(RS_LOG_DEBUG, __FUNCTION__, fmt , ##arg); \ 80 | } while (0) 81 | #else 82 | # define rs_trace(fmt, arg...) 83 | #endif /* !DO_RS_TRACE */ 84 | 85 | #define rs_log(l, s, str...) do { \ 86 | rs_log0((l), __FUNCTION__, (s) , ##str); \ 87 | } while (0) 88 | 89 | 90 | #define rs_error(s, str...) do { \ 91 | rs_log0(RS_LOG_ERR, __FUNCTION__, (s) , ##str); \ 92 | } while (0) 93 | 94 | 95 | #define rs_fatal(s, str...) do { \ 96 | rs_log0(RS_LOG_CRIT, __FUNCTION__, \ 97 | (s) , ##str); \ 98 | abort(); \ 99 | } while (0) 100 | 101 | 102 | #else /************************* ! __GNUC__ */ 103 | # define rs_trace rs_trace0 104 | # define rs_fatal rs_fatal0 105 | # define rs_error rs_error0 106 | # define rs_log rs_log0_nofn 107 | #endif /* ! __GNUC__ */ 108 | 109 | void rs_trace0(char const *s, ...); 110 | void rs_fatal0(char const *s, ...); 111 | void rs_error0(char const *s, ...); 112 | void rs_log0(int level, char const *fn, char const *fmt, ...); 113 | void rs_log0_nofn(int level, char const *fmt, ...); 114 | 115 | enum { 116 | RS_LOG_PRIMASK = 7, /**< Mask to extract priority 117 | part. \internal */ 118 | 119 | RS_LOG_NONAME = 8 /**< \b Don't show function name in 120 | message. */ 121 | }; 122 | 123 | 124 | /** 125 | * \macro rs_trace_enabled() 126 | * 127 | * Call this before putting too much effort into generating trace 128 | * messages. 129 | */ 130 | 131 | extern int rs_trace_level; 132 | 133 | #ifdef DO_RS_TRACE 134 | # define rs_trace_enabled() ((rs_trace_level & RS_LOG_PRIMASK) >= RS_LOG_DEBUG) 135 | #else 136 | # define rs_trace_enabled() 0 137 | #endif 138 | -------------------------------------------------------------------------------- /rsync_extension.php: -------------------------------------------------------------------------------- 1 | &2 96 | exit 1 97 | ;; 98 | esac 99 | done 100 | 101 | if test -z "$srcdir" 102 | then 103 | srcdir=`dirname $0` 104 | fi 105 | srcdir=`cd $srcdir; pwd` 106 | builddir=`pwd` 107 | 108 | PATH=$builddir:$srcdir:$PATH 109 | export PATH 110 | 111 | testdir=$srcdir/$test_base.input 112 | tmpdir=$builddir/$test_base.tmp 113 | if test ! -d $tmpdir 114 | then 115 | mkdir $tmpdir || exit 2 116 | fi 117 | 118 | test_skipped () { 119 | echo $test_name: skipped; exit 77 120 | } 121 | 122 | fail_test () { 123 | result=$1 124 | shift 125 | echo "$test_name: returned $result: $@" >&2 126 | exit 2 127 | } 128 | 129 | check_compare() { 130 | if cmp "$1" "$2" 131 | then 132 | : 133 | else 134 | echo "$test_name: comparison failed from command: $3" >&2 135 | exit 2 136 | fi 137 | } 138 | 139 | run_test () { 140 | if test -n "$VERBOSE" 141 | then 142 | echo " $@" >&2 143 | fi 144 | 145 | "$@" || fail_test "$?" "$@" 146 | } 147 | 148 | triple_test () { 149 | buf="$1" 150 | old="$2" 151 | new="$3" 152 | 153 | run_test ../rdiff $debug -I$buf -O$buf $stats signature --block-size=$block_len \ 154 | $old $tmpdir/sig 155 | run_test ../rdiff $debug -I$buf -O$buf $stats delta $tmpdir/sig $new $tmpdir/delta 156 | run_test ../rdiff $debug -I$buf -O$buf $stats patch $old $tmpdir/delta $tmpdir/new 157 | check_compare $new $tmpdir/new "triple -I$buf -O$buf $old $new" 158 | } 159 | 160 | # more than this many on any one test gets boring 161 | ntests=150 162 | countdown () { 163 | if ntests=`expr $ntests - 1` 164 | then 165 | cat $srcdir/dot 166 | else 167 | echo OK 168 | exit 0 169 | fi 170 | } 171 | 172 | make_input () { 173 | cat $srcdir/COPYING 174 | } 175 | 176 | echo "$test_name: " | tr -d '/\n/' 177 | 178 | . $test_script "$@" 179 | 180 | echo OK 181 | 182 | rm -f $tmpdir/* 183 | rmdir $tmpdir 184 | 185 | # If nothing failed, then 186 | exit 0 187 | -------------------------------------------------------------------------------- /librsync/mksum.c: -------------------------------------------------------------------------------- 1 | /*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- 2 | * 3 | * librsync -- library for network deltas 4 | * $Id: mksum.c,v 1.35 2004/09/10 01:37:56 mbp Exp $ 5 | * 6 | * Copyright (C) 1999, 2000, 2001 by Martin Pool 7 | * Copyright (C) 1999 by Andrew Tridgell 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as published by 11 | * the Free Software Foundation; either version 2.1 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 22 | */ 23 | 24 | 25 | /* 26 | * mksum.c -- Generate file signatures. 27 | * 28 | * Generating checksums is pretty easy, since we can always just 29 | * process whatever data is available. When a whole block has 30 | * arrived, or we've reached the end of the file, we write the 31 | * checksum out. 32 | */ 33 | 34 | /* TODO: Perhaps force blocks to be a multiple of 64 bytes, so that we 35 | * can be sure checksum generation will be more efficient. I guess it 36 | * will be OK at the moment, though, because tails are only used if 37 | * necessary. */ 38 | 39 | #include 40 | 41 | #include 42 | #include 43 | #include 44 | 45 | #include "librsync.h" 46 | #include "stream.h" 47 | #include "util.h" 48 | #include "sumset.h" 49 | #include "job.h" 50 | #include "protocol.h" 51 | #include "netint.h" 52 | #include "trace.h" 53 | #include "checksum.h" 54 | 55 | 56 | /* Possible state functions for signature generation. */ 57 | static rs_result rs_sig_s_header(rs_job_t *); 58 | static rs_result rs_sig_s_generate(rs_job_t *); 59 | 60 | 61 | 62 | /** 63 | * State of trying to send the signature header. 64 | */ 65 | static rs_result rs_sig_s_header(rs_job_t *job) 66 | { 67 | rs_squirt_n4(job, RS_SIG_MAGIC); 68 | rs_squirt_n4(job, job->block_len); 69 | rs_squirt_n4(job, job->strong_sum_len); 70 | rs_trace("sent header (magic %#x, block len = %d, strong sum len = %d)", 71 | RS_SIG_MAGIC, (int) job->block_len, (int) job->strong_sum_len); 72 | job->stats.block_len = job->block_len; 73 | 74 | job->statefn = rs_sig_s_generate; 75 | return RS_RUNNING; 76 | } 77 | 78 | 79 | /** 80 | * Generate the checksums for a block and write it out. Called when 81 | * we already know we have enough data in memory at \p block. 82 | */ 83 | static rs_result 84 | rs_sig_do_block(rs_job_t *job, const void *block, size_t len) 85 | { 86 | unsigned int weak_sum; 87 | rs_strong_sum_t strong_sum; 88 | 89 | weak_sum = rs_calc_weak_sum(block, len); 90 | 91 | rs_calc_strong_sum(block, len, &strong_sum); 92 | 93 | rs_squirt_n4(job, weak_sum); 94 | rs_tube_write(job, strong_sum, job->strong_sum_len); 95 | 96 | if (rs_trace_enabled()) { 97 | char strong_sum_hex[RS_MD4_LENGTH * 2 + 1]; 98 | rs_hexify(strong_sum_hex, strong_sum, job->strong_sum_len); 99 | rs_trace("sent weak sum 0x%08x and strong sum %s", weak_sum, 100 | strong_sum_hex); 101 | } 102 | 103 | job->stats.sig_blocks++; 104 | 105 | return RS_RUNNING; 106 | } 107 | 108 | 109 | /* 110 | * State of reading a block and trying to generate its sum. 111 | */ 112 | static rs_result 113 | rs_sig_s_generate(rs_job_t *job) 114 | { 115 | rs_result result; 116 | size_t len; 117 | void *block; 118 | 119 | /* must get a whole block, otherwise try again */ 120 | len = job->block_len; 121 | result = rs_scoop_read(job, len, &block); 122 | 123 | /* unless we're near eof, in which case we'll accept 124 | * whatever's in there */ 125 | if ((result == RS_BLOCKED && rs_job_input_is_ending(job))) { 126 | result = rs_scoop_read_rest(job, &len, &block); 127 | } else if (result == RS_INPUT_ENDED) { 128 | return RS_DONE; 129 | } else if (result != RS_DONE) { 130 | rs_trace("generate stopped: %s", rs_strerror(result)); 131 | return result; 132 | } 133 | 134 | rs_trace("got %ld byte block", (long) len); 135 | 136 | return rs_sig_do_block(job, block, len); 137 | } 138 | 139 | 140 | /** \brief Set up a new encoding job. 141 | * 142 | * \sa rs_sig_file() 143 | */ 144 | rs_job_t * rs_sig_begin(size_t new_block_len, size_t strong_sum_len) 145 | { 146 | rs_job_t *job; 147 | 148 | job = rs_job_new("signature", rs_sig_s_header); 149 | job->block_len = new_block_len; 150 | 151 | assert(strong_sum_len > 0 && strong_sum_len <= RS_MD4_LENGTH); 152 | job->strong_sum_len = strong_sum_len; 153 | 154 | return job; 155 | } 156 | -------------------------------------------------------------------------------- /librsync/search.c: -------------------------------------------------------------------------------- 1 | /*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- 2 | * 3 | * librsync -- the library for network deltas 4 | * $Id: search.c,v 1.36 2003/08/05 08:28:21 abo Exp $ 5 | * 6 | * Copyright (C) 1999, 2000, 2001 by Martin Pool 7 | * Copyright (C) 1999 by Andrew Tridgell 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU Lesser General Public License as published by 11 | * the Free Software Foundation; either version 2.1 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 22 | */ 23 | 24 | /* 25 | * This file contains code for searching the sumset for matching 26 | * values. 27 | */ 28 | 29 | /* 30 | * TODO: The common case is that the next block in both streams 31 | * match. Can we make that a bit faster at all? We'd need to perhaps 32 | * add a link forward between blocks in the sum_struct corresponding 33 | * to the order they're found in the input; then before doing a search 34 | * we can just check that pointer. 35 | */ 36 | 37 | #include 38 | 39 | #include 40 | #include 41 | #include 42 | #include 43 | 44 | #include "librsync.h" 45 | #include "trace.h" 46 | #include "util.h" 47 | #include "sumset.h" 48 | #include "search.h" 49 | #include "checksum.h" 50 | 51 | 52 | #define TABLESIZE (1<<16) 53 | #define NULL_TAG (-1) 54 | 55 | 56 | #define gettag2(s1,s2) (((s1) + (s2)) & 0xFFFF) 57 | #define gettag(sum) gettag2((sum)&0xFFFF,(sum)>>16) 58 | 59 | 60 | static int 61 | rs_compare_targets(rs_target_t const *t1, rs_target_t const *t2) 62 | { 63 | return ((int) t1->t - (int) t2->t); 64 | } 65 | 66 | 67 | rs_result 68 | rs_build_hash_table(rs_signature_t * sums) 69 | { 70 | int i; 71 | 72 | sums->tag_table = calloc(TABLESIZE, sizeof sums->tag_table[0]); 73 | if (!sums->tag_table) 74 | return RS_MEM_ERROR; 75 | 76 | if (sums->count > 0) { 77 | sums->targets = calloc(sums->count, sizeof(rs_target_t)); 78 | if (!sums->targets) 79 | return RS_MEM_ERROR; 80 | 81 | for (i = 0; i < sums->count; i++) { 82 | sums->targets[i].i = i; 83 | sums->targets[i].t = gettag(sums->block_sigs[i].weak_sum); 84 | } 85 | 86 | /* FIXME: Perhaps if this operating system has comparison_fn_t 87 | * like GNU, then use it in the cast. But really does anyone 88 | * care? */ 89 | qsort(sums->targets, sums->count, 90 | sizeof(sums->targets[0]), 91 | (int (*)(const void *, const void *)) rs_compare_targets); 92 | } 93 | 94 | for (i = 0; i < TABLESIZE; i++) 95 | sums->tag_table[i] = NULL_TAG; 96 | 97 | for (i = sums->count - 1; i >= 0; i--) { 98 | sums->tag_table[sums->targets[i].t] = i; 99 | } 100 | 101 | rs_trace("done"); 102 | return RS_DONE; 103 | } 104 | 105 | 106 | 107 | /* 108 | * See if there is a match for the specified block INBUF..BLOCK_LEN in 109 | * the checksum set, using precalculated WEAK_SUM. 110 | * 111 | * If we don't find a match on the weak checksum, then we just give 112 | * up. If we do find a weak match, then we proceed to calculate the 113 | * strong checksum for the current block, and see if it will match 114 | * anything. 115 | */ 116 | int 117 | rs_search_for_block(rs_weak_sum_t weak_sum, 118 | char const *inbuf, size_t block_len, 119 | rs_signature_t const *sig, rs_stats_t * stats, 120 | rs_long_t * match_where) 121 | { 122 | int hash_tag = gettag(weak_sum); 123 | int j = sig->tag_table[hash_tag]; 124 | rs_strong_sum_t strong_sum; 125 | int got_strong = 0; 126 | 127 | if (j == NULL_TAG) { 128 | return 0; 129 | } 130 | 131 | for (; j < sig->count && sig->targets[j].t == hash_tag; j++) { 132 | int i = sig->targets[j].i; 133 | int token; 134 | 135 | if (weak_sum != sig->block_sigs[i].weak_sum) 136 | continue; 137 | 138 | token = sig->block_sigs[i].i; 139 | 140 | rs_trace("found weak match for %08x in token %d", weak_sum, token); 141 | 142 | if (!got_strong) { 143 | rs_calc_strong_sum(inbuf, block_len, &strong_sum); 144 | got_strong = 1; 145 | } 146 | 147 | /* FIXME: Use correct dynamic sum length! */ 148 | if (memcmp(strong_sum, sig->block_sigs[i].strong_sum, 149 | sig->strong_sum_len) == 0) { 150 | /* XXX: This is a remnant of rsync: token number 1 is the 151 | * block at offset 0. It would be good to clear this 152 | * up. */ 153 | *match_where = (rs_long_t)(token - 1) * sig->block_len; 154 | return 1; 155 | } else { 156 | rs_trace("this was a false positive, the strong sig doesn't match"); 157 | stats->false_matches++; 158 | } 159 | } 160 | 161 | return 0; 162 | } 163 | -------------------------------------------------------------------------------- /librsync/netint.c: -------------------------------------------------------------------------------- 1 | /*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- 2 | * 3 | * librsync -- library for network deltas 4 | * $Id: netint.c,v 1.27 2004/09/10 02:48:58 mbp Exp $ 5 | * 6 | * Copyright (C) 1999, 2000, 2001 by Martin Pool 7 | * Copyright (C) 1999 by Andrew Tridgell 8 | * 9 | * This program is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU Lesser General Public License 11 | * as published by the Free Software Foundation; either version 2.1 of 12 | * the License, or (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 22 | */ 23 | 24 | /* 25 | | Ummm, well, OK. The network's the 26 | | network, the computer's the 27 | | computer. Sorry for the confusion. 28 | | -- Sun Microsystems 29 | */ 30 | 31 | /* 32 | * Network-byte-order output to the tube. 33 | * 34 | * All the `suck' routines return a result code. The most common 35 | * values are RS_DONE if they have enough data, or RS_BLOCKED if there 36 | * is not enough input to proceed. 37 | * 38 | * All the netint operations are done in a fairly simpleminded way, 39 | * since we don't want to rely on stdint types that may not be 40 | * available on some platforms. 41 | */ 42 | 43 | /* 44 | * TODO: If we don't have (or perhaps even if we do), 45 | * determine endianness and integer size by hand and use that to do 46 | * our own conversion routines. We possibly need this anyhow to do 47 | * 64-bit integers, since there seems to be no ntohs() analog. 48 | */ 49 | 50 | #include 51 | 52 | #include 53 | #include 54 | #include 55 | #include 56 | #include 57 | 58 | #include "librsync.h" 59 | 60 | #include "job.h" 61 | #include "netint.h" 62 | #include "trace.h" 63 | #include "stream.h" 64 | 65 | #define RS_MAX_INT_BYTES 8 66 | 67 | 68 | /** 69 | * \brief Write a single byte to a stream output. 70 | */ 71 | rs_result 72 | rs_squirt_byte(rs_job_t *job, unsigned char d) 73 | { 74 | rs_tube_write(job, &d, 1); 75 | return RS_DONE; 76 | } 77 | 78 | 79 | /** 80 | * \brief Write a variable-length integer to a stream. 81 | * 82 | * \param job Job of data. 83 | * 84 | * \param d Datum to write out. 85 | * 86 | * \param len Length of integer, in bytes. 87 | */ 88 | rs_result 89 | rs_squirt_netint(rs_job_t *job, rs_long_t d, int len) 90 | { 91 | unsigned char buf[RS_MAX_INT_BYTES]; 92 | int i; 93 | 94 | if (len <= 0 || len > RS_MAX_INT_BYTES) { 95 | rs_error("Illegal integer length %d", len); 96 | return RS_INTERNAL_ERROR; 97 | } 98 | 99 | /* Fill the output buffer with a bigendian representation of the 100 | * number. */ 101 | for (i = len-1; i >=0; i--) { 102 | buf[i] = d; /* truncated */ 103 | d >>= 8; 104 | } 105 | 106 | rs_tube_write(job, buf, len); 107 | 108 | return RS_DONE; 109 | } 110 | 111 | 112 | 113 | rs_result 114 | rs_squirt_n4(rs_job_t *job, int val) 115 | { 116 | return rs_squirt_netint(job, val, 4); 117 | } 118 | 119 | 120 | 121 | rs_result 122 | rs_suck_netint(rs_job_t *job, rs_long_t *v, int len) 123 | { 124 | unsigned char *buf; 125 | int i; 126 | rs_result result; 127 | 128 | if (len <= 0 || len > RS_MAX_INT_BYTES) { 129 | rs_error("Illegal integer length %d", len); 130 | return RS_INTERNAL_ERROR; 131 | } 132 | 133 | if ((result = rs_scoop_read(job, len, (void **) &buf)) != RS_DONE) 134 | return result; 135 | 136 | *v = 0; 137 | 138 | for (i = 0; i < len; i++) { 139 | *v = *v<<8 | buf[i]; 140 | } 141 | 142 | return RS_DONE; 143 | } 144 | 145 | 146 | rs_result 147 | rs_suck_byte(rs_job_t *job, unsigned char *v) 148 | { 149 | void *inb; 150 | rs_result result; 151 | 152 | if ((result = rs_scoop_read(job, 1, &inb)) == RS_DONE) 153 | *v = *((unsigned char *) inb); 154 | 155 | return result; 156 | } 157 | 158 | 159 | rs_result 160 | rs_suck_n4(rs_job_t *job, int *v) 161 | { 162 | rs_result result; 163 | rs_long_t d; 164 | 165 | result = rs_suck_netint(job, &d, 4); 166 | *v = d; 167 | return result; 168 | } 169 | 170 | 171 | int rs_int_len(rs_long_t val) 172 | { 173 | if (!(val & ~(rs_long_t)0xff)) 174 | return 1; 175 | else if (!(val & ~(rs_long_t)0xffff)) 176 | return 2; 177 | else if (!(val & ~(rs_long_t)0xffffffff)) 178 | return 4; 179 | else if (!(val & ~(rs_long_t)0xffffffffffffffff)) 180 | return 8; 181 | else { 182 | rs_fatal("can't encode integer " PRINTF_FORMAT_U64 " yet", PRINTF_CAST_U64(val)); 183 | } 184 | } 185 | -------------------------------------------------------------------------------- /librsync/configure.ac: -------------------------------------------------------------------------------- 1 | # -*- Autoconf -*- 2 | # Process this file with autoconf to produce a configure script. 3 | 4 | AC_PREREQ(2.53) 5 | AC_INIT([librsync],[0.9.7]) 6 | AC_REVISION([$Revision: 1.12 $]) 7 | AC_COPYRIGHT([Copyright (C) 1999, 2000, 01, 02, 04 by Martin Pool ]) 8 | AC_CONFIG_SRCDIR([trace.c]) 9 | AM_CONFIG_HEADER(config.h) 10 | AM_INIT_AUTOMAKE 11 | 12 | # GNU library versioning: This is NOT the librsync release number. 13 | # See libversions.txt and the libtool manual for an explanation of the 14 | # library versioning 15 | librsync_libversion=1:2:0 16 | 17 | # Disable shared libs by default. 18 | AC_DISABLE_SHARED 19 | 20 | # Checks for programs. 21 | AC_GNU_SOURCE 22 | AC_PROG_CC 23 | AC_ISC_POSIX 24 | AC_PROG_CPP 25 | AC_PROG_INSTALL 26 | AC_PROG_MAKE_SET 27 | AC_PROG_LIBTOOL 28 | 29 | # Checks for libraries. 30 | AC_CHECK_LIB(z, deflate) 31 | AC_CHECK_LIB(bz2, BZ2_bzCompress) 32 | AC_CHECK_LIB(popt, poptGetContext,,[BUILD_POPT='popt/libpopt.a'; CFLAGS="$CFLAGS -I$srcdir/popt"]) 33 | 34 | # Checks for header files. 35 | AC_FUNC_ALLOCA 36 | AC_HEADER_STDC 37 | AC_CHECK_HEADERS([mcheck.h bzlib.h zlib.h]) 38 | AC_CHECK_HEADERS([fcntl.h inttypes.h libintl.h limits.h malloc.h stdint.h stdlib.h string.h sys/file.h unistd.h]) 39 | 40 | # Checks for typedefs, structures, and compiler characteristics. 41 | AC_C_CONST 42 | AC_C_BIGENDIAN 43 | AC_TYPE_SIZE_T 44 | AC_TYPE_OFF_T 45 | AC_SYS_LARGEFILE 46 | 47 | AC_CHECK_SIZEOF([unsigned char], 1) 48 | if test "$ac_cv_sizeof_unsigned_char" -ne 1; then 49 | AC_MSG_WARN(unsigned char seems to be $ac_cv_sizeof_unsigned_char bytes. Expect trouble.) 50 | fi 51 | AC_CHECK_SIZEOF(short) 52 | AC_CHECK_SIZEOF([unsigned short]) 53 | AC_CHECK_SIZEOF(int) 54 | AC_CHECK_SIZEOF([unsigned int]) 55 | AC_CHECK_SIZEOF(long) 56 | AC_CHECK_SIZEOF([unsigned long]) 57 | AC_CHECK_SIZEOF([long long]) 58 | AC_CHECK_SIZEOF(off_t) 59 | AC_CHECK_SIZEOF(size_t) 60 | 61 | #XXX: is this really the best way to do it? I think the limitation on 62 | # rs_long_t is that we need to be able to seek to it, which relates to 63 | # long file support. With fseeko, rs_long_t should be off_t, otherwise 64 | # it should be long. 65 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM( 66 | [[#include 67 | #ifndef LONG_LONG 68 | #error not defined 69 | #endif]], 70 | [;])], 71 | [ RS_LONG_T='LONG_LONG' ], 72 | [ case "$ac_cv_sizeof_long_long" in 73 | 0) RS_LONG_T='long' ;; 74 | *) RS_LONG_T='long long' ;; 75 | esac ]) 76 | AC_SUBST(RS_LONG_T) 77 | 78 | # Checks for library functions. 79 | #AC_FUNC_MALLOC #XXX: needs malloc.c replacement 80 | #AC_FUNC_MEMCMP #XXX: needs memcmp.c replacement 81 | #AC_FUNC_REALLOC #XXX: needs realloc.c replacement 82 | AC_FUNC_FSEEKO 83 | AC_CHECK_FUNCS([memmove memset strchr strerror strtol]) 84 | AC_CHECK_FUNCS([gettext dgettext]) 85 | AC_CHECK_FUNC(setreuid, [], 86 | [ AC_CHECK_LIB(ucb, setreuid, 87 | [ if echo $LIBS | grep -- -lucb >/dev/null ;then :; 88 | else LIBS="$LIBS -lc -lucb"; USEUCB=y;fi]) 89 | ]) 90 | # supply a snprintf and vsnprintf if the system doesn't have one. 91 | # if missing, check MSVC _xxx varients, otherwise use snprintf.c 92 | # replacement. 93 | AC_CHECK_FUNCS(snprintf,,[AC_CHECK_FUNCS(_snprintf)]) 94 | AC_CHECK_FUNCS(vsnprintf,,[AC_CHECK_FUNCS(_vsnprintf,,[AC_LIBOBJ(snprintf)])]) 95 | 96 | # Test if the compiler has the GNU feature of putting argv[0] into a global 97 | AC_MSG_CHECKING([for program_invocation_short_name]) 98 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM( 99 | [[#include ]], 100 | [[strlen(program_invocation_short_name)]])], 101 | [ AC_DEFINE(HAVE_PROGRAM_INVOCATION_NAME,, 102 | [GNU extension of saving argv[0] to program_invocation_short_name]) 103 | AC_MSG_RESULT(yes) ], 104 | [ AC_MSG_RESULT(no) ]) 105 | 106 | # Test if the preprocessor understands vararg macros 107 | AC_MSG_CHECKING([for vararg macro support]) 108 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM( 109 | [#define func(a, b...) do {} while (0)], 110 | [func("a", "b", "c");func("a")])], 111 | [ AC_DEFINE(HAVE_VARARG_MACROS, , [Define if your cpp has vararg macros]) 112 | AC_MSG_RESULT(yes) ], 113 | [ AC_MSG_RESULT(no) ]) 114 | 115 | if test "$GCC" = "yes"; then # GCC 116 | CFLAGS="-Wall -Wshadow -Wundef -Wwrite-strings -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes -Wpointer-arith -Wcast-qual -Wcast-align $CFLAGS" 117 | elif test "$CC" = "cl"; then # MSVC 118 | CFLAGS="-Z7 -Od -MD $CFLAGS" 119 | fi 120 | # TODO: Similar conditions for other known compilers. For SUNWspro, use `-v'. 121 | 122 | AC_ARG_ENABLE(ccmalloc, 123 | AC_HELP_STRING([--enable-ccmalloc],[use ccmalloc debugger (default no)]), 124 | [ LIBS="$LIBS -lccmalloc -ldl" ]) 125 | 126 | AC_ARG_ENABLE(trace, 127 | AC_HELP_STRING([--disable-trace],[turn off library tracing]), 128 | [enable_trace=$enableval],[enable_trace=yes]) 129 | if test "$enable_trace" = "yes"; then 130 | AC_DEFINE(DO_RS_TRACE,,[Define this to enable trace code]) 131 | fi 132 | 133 | AC_DEFINE_UNQUOTED(RS_LIBVERSION, "$librsync_libversion",[Version of the libtool interface.]) 134 | AC_DEFINE_UNQUOTED(RS_CANONICAL_HOST, "$host",[Canonical GNU hostname]) 135 | 136 | AC_SUBST(librsync_libversion) 137 | AC_SUBST(BUILD_POPT) 138 | 139 | AC_CONFIG_FILES([ 140 | Makefile 141 | doc/Makefile 142 | doc/Doxyfile 143 | popt/Makefile 144 | testsuite/Makefile 145 | librsync-config.h]) 146 | AC_OUTPUT 147 | -------------------------------------------------------------------------------- /librsync/whole.c: -------------------------------------------------------------------------------- 1 | /*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- 2 | * 3 | * librsync -- the library for network deltas 4 | * $Id: whole.c,v 1.23 2003/06/12 05:47:23 wayned Exp $ 5 | * 6 | * Copyright (C) 2000, 2001 by Martin Pool 7 | * 8 | * This program is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public License 10 | * as published by the Free Software Foundation; either version 2.1 of 11 | * the License, or (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, but 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | * Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 | */ 22 | 23 | /* 24 | | Is it possible that software is not 25 | | like anything else, that it is meant 26 | | to be discarded: that the whole point 27 | | is to always see it as a soap bubble? 28 | | -- Alan Perlis 29 | */ 30 | 31 | 32 | 33 | #include 34 | 35 | #include 36 | #include 37 | #ifdef HAVE_UNISTD_H 38 | #include 39 | #endif 40 | #include 41 | #include 42 | #include 43 | 44 | #include "librsync.h" 45 | 46 | #include "trace.h" 47 | #include "fileutil.h" 48 | #include "sumset.h" 49 | #include "job.h" 50 | #include "buf.h" 51 | #include "whole.h" 52 | #include "util.h" 53 | 54 | /** 55 | * Run a job continuously, with input to/from the two specified files. 56 | * The job should already be set up, and must be free by the caller 57 | * after return. 58 | * 59 | * Buffers of ::rs_inbuflen and ::rs_outbuflen are allocated for 60 | * temporary storage. 61 | * 62 | * \param in_file Source of input bytes, or NULL if the input buffer 63 | * should not be filled. 64 | * 65 | * \return RS_DONE if the job completed, or otherwise an error result. 66 | */ 67 | rs_result 68 | rs_whole_run(rs_job_t *job, FILE *in_file, FILE *out_file) 69 | { 70 | rs_buffers_t buf; 71 | rs_result result; 72 | rs_filebuf_t *in_fb = NULL, *out_fb = NULL; 73 | 74 | if (in_file) 75 | in_fb = rs_filebuf_new(in_file, rs_inbuflen); 76 | 77 | if (out_file) 78 | out_fb = rs_filebuf_new(out_file, rs_outbuflen); 79 | 80 | result = rs_job_drive(job, &buf, 81 | in_fb ? rs_infilebuf_fill : NULL, in_fb, 82 | out_fb ? rs_outfilebuf_drain : NULL, out_fb); 83 | 84 | if (in_fb) 85 | rs_filebuf_free(in_fb); 86 | 87 | if (out_fb) 88 | rs_filebuf_free(out_fb); 89 | 90 | return result; 91 | } 92 | 93 | 94 | 95 | /** 96 | * Generate the signature of a basis file, and write it out to 97 | * another. 98 | * 99 | * \param new_block_len block size for signature generation, in bytes 100 | * 101 | * \param strong_len truncated length of strong checksums, in bytes 102 | * 103 | * \sa rs_sig_begin() 104 | */ 105 | rs_result 106 | rs_sig_file(FILE *old_file, FILE *sig_file, size_t new_block_len, 107 | size_t strong_len, rs_stats_t *stats) 108 | { 109 | rs_job_t *job; 110 | rs_result r; 111 | 112 | job = rs_sig_begin(new_block_len, strong_len); 113 | r = rs_whole_run(job, old_file, sig_file); 114 | if (stats) 115 | memcpy(stats, &job->stats, sizeof *stats); 116 | rs_job_free(job); 117 | 118 | return r; 119 | } 120 | 121 | 122 | /** 123 | * Load signatures from a signature file into memory. Return a 124 | * pointer to the newly allocated structure in SUMSET. 125 | * 126 | * \sa rs_readsig_begin() 127 | */ 128 | rs_result 129 | rs_loadsig_file(FILE *sig_file, rs_signature_t **sumset, rs_stats_t *stats) 130 | { 131 | rs_job_t *job; 132 | rs_result r; 133 | 134 | job = rs_loadsig_begin(sumset); 135 | r = rs_whole_run(job, sig_file, NULL); 136 | if (stats) 137 | memcpy(stats, &job->stats, sizeof *stats); 138 | rs_job_free(job); 139 | 140 | return r; 141 | } 142 | 143 | 144 | 145 | rs_result 146 | rs_delta_file(rs_signature_t *sig, FILE *new_file, FILE *delta_file, 147 | rs_stats_t *stats) 148 | { 149 | rs_job_t *job; 150 | rs_result r; 151 | 152 | job = rs_delta_begin(sig); 153 | 154 | r = rs_whole_run(job, new_file, delta_file); 155 | 156 | if (stats) 157 | memcpy(stats, &job->stats, sizeof *stats); 158 | 159 | rs_job_free(job); 160 | 161 | return r; 162 | } 163 | 164 | 165 | 166 | rs_result rs_patch_file(FILE *basis_file, FILE *delta_file, FILE *new_file, 167 | rs_stats_t *stats) 168 | { 169 | rs_job_t *job; 170 | rs_result r; 171 | 172 | job = rs_patch_begin(rs_file_copy_cb, basis_file); 173 | 174 | r = rs_whole_run(job, delta_file, new_file); 175 | 176 | if (stats) 177 | memcpy(stats, &job->stats, sizeof *stats); 178 | 179 | rs_job_free(job); 180 | 181 | return r; 182 | } 183 | -------------------------------------------------------------------------------- /librsync/testsuite/changes.input/02.in: -------------------------------------------------------------------------------- 1 | Well, I'm on the right planet---everyone looks like me!!! 2 | 3 | Why do you say that? 4 | 5 | Are we THERE yet?! 6 | 7 | What makes you believe are you there yet? 8 | 9 | .. Now I think I just reached the state of HYPERTENSION that comes 10 | JUST BEFORE you see the TOTAL at the SAFEWAY CHECKOUT COUNTER! 11 | 12 | Is it because comes just before I see the total at the safeway 13 | checkout counter that you came to me? 14 | 15 | Do you guys know we just passed thru a BLACK HOLE in space? 16 | 17 | Maybe your plans have something to do with this. 18 | 19 | I am NOT a nut.... 20 | 21 | Is it because of your life that you say you are not a nut? 22 | 23 | Okay, BARBRA STREISAND, I recognize you now!! Also EFREM ZIMBALIST, 24 | JUNIOR!! And BEAUMONT NEWHALL!! Everybody into th' BATHROOM! 25 | 26 | Earlier you said comes just before I see the total at the safeway 27 | checkout counter? 28 | 29 | I know how to get the hostesses released! Give them their own 30 | television series! 31 | 32 | Is it because of the people you hang around with that you are going 33 | through all this? 34 | 35 | I request a weekend in Havana with Phil Silvers! 36 | 37 | I don't understand. 38 | 39 | Why is it that when you DIE, you can't take your 40 | HOME ENTERTAINMENT CENTER with you?? 41 | 42 | Does it bother you that is it that when I die me cannot take my home 43 | entertainment center with me? 44 | 45 | HUMAN REPLICAS are inserted into VATS of NUTRITIONAL YEAST... 46 | 47 | You mentioned that comes just before I see the total at the safeway 48 | checkout counter? 49 | 50 | How's the wife? Is she at home enjoying capitalism? 51 | 52 | How do you reconcile problems at school? 53 | 54 | .. I think I'll KILL myself by leaping out of this 55 | 14th STOREY WINDOW while reading ERICA JONG'S poetry!! 56 | 57 | This is not a healthy way of thinking. 58 | 59 | RELAX!! ... This is gonna be a HEALING EXPERIENCE!! Besides, 60 | I work for DING DONGS! 61 | 62 | When did you first know that you work for ding dongs? 63 | 64 | Yow! I'm having a quadraphonic sensation of two winos 65 | alone in a steel mill! 66 | 67 | Perhaps this has something to do with any hobbies you have? 68 | 69 | Awright, which one of you hid my PENIS ENVY? 70 | 71 | Are you sure that is it that when I die me cannot take my home 72 | entertainment center with me? 73 | 74 | My EARS are GONE!! 75 | 76 | Possibly your sex life are related to this. 77 | 78 | It's the land of DONNY AND MARIE as promised in TV GUIDE! 79 | 80 | Are you afraid of that? 81 | 82 | My TOYOTA is built like a ... BAGEL with CREAM CHEESE!! 83 | 84 | Do you really think built might want to have this bagel? 85 | 86 | I wonder if I could ever get started in the credit world? 87 | 88 | Earlier you said comes just before I see the total at the safeway 89 | checkout counter? 90 | 91 | TATTOOED MIDGETS are using ALFREDO in their SALAMI FACTORY! 92 | 93 | Is it because of hangups you have that you are going through all this? 94 | 95 | I LIKE Aisle 7a. 96 | 97 | What makes you think you like aisle 7a? 98 | 99 | Youth of today! Join me in a mass rally for traditional mental attitudes! 100 | 101 | You mentioned that you work for ding dongs? 102 | 103 | Yow! Did something bad happen or am I in a drive-in movie?? 104 | 105 | How do you reconcile your inhibitions? 106 | 107 | Vote for ME -- I'm well-tapered, half-cocked, ill-conceived and 108 | TAX-DEFERRED! 109 | 110 | Why do you say that? 111 | 112 | Are we THERE yet?! 113 | 114 | What makes you believe is it that when I die me cannot take my home 115 | entertainment center with me? 116 | 117 | Is it FUN to be a MIDGET? 118 | 119 | Maybe this is related to some problems in your childhood? 120 | 121 | I left my WALLET in the BATHROOM!! 122 | 123 | Is it because of some problems at home that you say you left your 124 | wallet in the bathroom? 125 | 126 | Spreading peanut butter reminds me of opera!! I wonder why? 127 | 128 | Can you elaborate on that? 129 | 130 | Dizzy, are we "REAL PEOPLE" or "AMAZING ANIMALS"? 131 | 132 | Earlier you said built would like to have this bagel? 133 | 134 | My LESLIE GORE record is BROKEN.. 135 | 136 | Perhaps your plans could have caused this. 137 | 138 | With YOU, I can be MYSELF.. We don't NEED Dan Rather.. 139 | 140 | Are you sure that you do not need dan rather? 141 | 142 | Yow! 143 | 144 | Yow! Are we interactive yet? 145 | 146 | You must be a CUB SCOUT!! Have you made your MONEY-DROP today?? 147 | 148 | You mentioned that comes just before I see the total at the safeway 149 | checkout counter? 150 | 151 | It's the RINSE CYCLE!! They've ALL IGNORED the RINSE CYCLE!! 152 | 153 | Is it because of your life that you are going through all this? 154 | 155 | There's a little picture of ED MCMAHON doing BAD THINGS to JOAN RIVERS 156 | in a $200,000 MALIBU BEACH HOUSE!! 157 | 158 | I don't understand. 159 | 160 | FISH-NET-FISH-NET-FISH-NET-FISH-NET-FISH!! 161 | 162 | Do you really think you work for ding dongs? 163 | 164 | NATHAN... your PARENTS were in a CARCRASH!! 165 | They're VOIDED - They COLLAPSED 166 | They had no CHAINSAWS... They had no MONEY MACHINES... 167 | They did PILLS in SKIMPY GRASS SKIRTS... 168 | Nathan, I EMULATED them... but they were OFF-KEY... 169 | 170 | Is the fact that they were off key the real reason? 171 | 172 | I want you to MEMORIZE the collected poems of EDNA ST VINCENT MILLAY.. 173 | BACKWARDS!! 174 | 175 | I would appreciate it if you would continue. 176 | 177 | Now KEN is having a MENTAL CRISIS beacuse his "R.V." PAYMENTS are 178 | OVER-DUE!! 179 | 180 | --------------------------------------------------------------------------------