OLD | NEW |
1 /*- | 1 // Copyright 2003, 2004 Colin Percival |
2 * Copyright 2003,2004 Colin Percival | 2 // All rights reserved |
3 * All rights reserved | 3 // |
4 * | 4 // Redistribution and use in source and binary forms, with or without |
5 * Redistribution and use in source and binary forms, with or without | 5 // modification, are permitted providing that the following conditions |
6 * modification, are permitted providing that the following conditions | 6 // are met: |
7 * are met: | 7 // 1. Redistributions of source code must retain the above copyright |
8 * 1. Redistributions of source code must retain the above copyright | 8 // notice, this list of conditions and the following disclaimer. |
9 * notice, this list of conditions and the following disclaimer. | 9 // 2. Redistributions in binary form must reproduce the above copyright |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 // notice, this list of conditions and the following disclaimer in the |
11 * notice, this list of conditions and the following disclaimer in the | 11 // documentation and/or other materials provided with the distribution. |
12 * documentation and/or other materials provided with the distribution. | 12 // |
13 * | 13 // For the terms under which this work may be distributed, please see |
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | 14 // the adjoining file "LICENSE". |
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 15 // |
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 16 // Changelog: |
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY | 17 // 2005-04-26 - Define the header as a C structure, add a CRC32 checksum to |
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 18 // the header, and make all the types 32-bit. |
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 19 // --Benjamin Smedberg <benjamin@smedbergs.us> |
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 20 // 2009-03-31 - Change to use Streams. Move CRC code to crc.{h,cc} |
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | 21 // Changed status to an enum, removed unused status codes. |
22 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | 22 // --Stephen Adams <sra@chromium.org> |
23 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 23 // 2013-04-10 - Added wrapper to apply a patch directly to files. |
24 * POSSIBILITY OF SUCH DAMAGE. | 24 // --Joshua Pawlicki <waffles@chromium.org> |
25 * | 25 |
26 * Changelog: | 26 // Copyright 2016 The Chromium Authors. All rights reserved. |
27 * 2005-04-26 - Define the header as a C structure, add a CRC32 checksum to | 27 // Use of this source code is governed by a BSD-style license that can be |
28 * the header, and make all the types 32-bit. | 28 // found in the LICENSE file. |
29 * --Benjamin Smedberg <benjamin@smedbergs.us> | |
30 * 2009-03-31 - Change to use Streams. Move CRC code to crc.{h,cc} | |
31 * Changed status to an enum, removed unused status codes. | |
32 * --Stephen Adams <sra@chromium.org> | |
33 * 2013-04-10 - Added wrapper to apply a patch directly to files. | |
34 * --Joshua Pawlicki <waffles@chromium.org> | |
35 */ | |
36 | 29 |
37 #ifndef COURGETTE_THIRD_PARTY_BSDIFF_BSDIFF_H_ | 30 #ifndef COURGETTE_THIRD_PARTY_BSDIFF_BSDIFF_H_ |
38 #define COURGETTE_THIRD_PARTY_BSDIFF_BSDIFF_H_ | 31 #define COURGETTE_THIRD_PARTY_BSDIFF_BSDIFF_H_ |
39 | 32 |
40 #include <stdint.h> | 33 #include <stdint.h> |
41 | 34 |
42 #include "base/files/file_util.h" | 35 #include "base/files/file_util.h" |
43 | 36 |
44 namespace courgette { | 37 namespace courgette { |
| 38 class SourceStream; |
| 39 class SinkStream; |
| 40 } // namespace courgette |
| 41 |
| 42 namespace bsdiff { |
45 | 43 |
46 enum BSDiffStatus { | 44 enum BSDiffStatus { |
47 OK = 0, | 45 OK = 0, |
48 MEM_ERROR = 1, | 46 MEM_ERROR = 1, |
49 CRC_ERROR = 2, | 47 CRC_ERROR = 2, |
50 READ_ERROR = 3, | 48 READ_ERROR = 3, |
51 UNEXPECTED_ERROR = 4, | 49 UNEXPECTED_ERROR = 4, |
52 WRITE_ERROR = 5 | 50 WRITE_ERROR = 5 |
53 }; | 51 }; |
54 | 52 |
55 class SourceStream; | |
56 class SinkStream; | |
57 | |
58 // Creates a binary patch. | 53 // Creates a binary patch. |
59 // | 54 // |
60 BSDiffStatus CreateBinaryPatch(SourceStream* old_stream, | 55 BSDiffStatus CreateBinaryPatch(courgette::SourceStream* old_stream, |
61 SourceStream* new_stream, | 56 courgette::SourceStream* new_stream, |
62 SinkStream* patch_stream); | 57 courgette::SinkStream* patch_stream); |
63 | 58 |
64 // Applies the given patch file to a given source file. This method validates | 59 // Applies the given patch file to a given source file. This method validates |
65 // the CRC of the original file stored in the patch file, before applying the | 60 // the CRC of the original file stored in the patch file, before applying the |
66 // patch to it. | 61 // patch to it. |
67 // | 62 // |
68 BSDiffStatus ApplyBinaryPatch(SourceStream* old_stream, | 63 BSDiffStatus ApplyBinaryPatch(courgette::SourceStream* old_stream, |
69 SourceStream* patch_stream, | 64 courgette::SourceStream* patch_stream, |
70 SinkStream* new_stream); | 65 courgette::SinkStream* new_stream); |
71 | 66 |
72 // As above, but simply takes the file paths. | 67 // As above, but simply takes the file paths. |
73 BSDiffStatus ApplyBinaryPatch(const base::FilePath& old_stream, | 68 BSDiffStatus ApplyBinaryPatch(const base::FilePath& old_stream, |
74 const base::FilePath& patch_stream, | 69 const base::FilePath& patch_stream, |
75 const base::FilePath& new_stream); | 70 const base::FilePath& new_stream); |
76 | 71 |
77 // The following declarations are common to the patch-creation and | 72 // The following declarations are common to the patch-creation and |
78 // patch-application code. | 73 // patch-application code. |
79 | 74 |
80 // The patch stream starts with a MBSPatchHeader. | 75 // The patch stream starts with a MBSPatchHeader. |
81 typedef struct MBSPatchHeader_ { | 76 typedef struct MBSPatchHeader_ { |
82 char tag[8]; // Contains MBS_PATCH_HEADER_TAG. | 77 char tag[8]; // Contains MBS_PATCH_HEADER_TAG. |
83 uint32_t slen; // Length of the file to be patched. | 78 uint32_t slen; // Length of the file to be patched. |
84 uint32_t scrc32; // CRC32 of the file to be patched. | 79 uint32_t scrc32; // CRC32 of the file to be patched. |
85 uint32_t dlen; // Length of the result file. | 80 uint32_t dlen; // Length of the result file. |
86 } MBSPatchHeader; | 81 } MBSPatchHeader; |
87 | 82 |
88 // This is the value for the tag field. Must match length exactly, not counting | 83 // This is the value for the tag field. Must match length exactly, not counting |
89 // null at end of string. | 84 // null at end of string. |
90 #define MBS_PATCH_HEADER_TAG "GBSDIF42" | 85 #define MBS_PATCH_HEADER_TAG "GBSDIF42" |
91 | 86 |
92 } // namespace | 87 } // namespace bsdiff |
| 88 |
93 #endif // COURGETTE_THIRD_PARTY_BSDIFF_BSDIFF_H_ | 89 #endif // COURGETTE_THIRD_PARTY_BSDIFF_BSDIFF_H_ |
OLD | NEW |