1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/mozapps/update/updater/bspatch.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,93 @@ 1.4 +/*- 1.5 + * Copyright 2003,2004 Colin Percival 1.6 + * All rights reserved 1.7 + * 1.8 + * Redistribution and use in source and binary forms, with or without 1.9 + * modification, are permitted providing that the following conditions 1.10 + * are met: 1.11 + * 1. Redistributions of source code must retain the above copyright 1.12 + * notice, this list of conditions and the following disclaimer. 1.13 + * 2. Redistributions in binary form must reproduce the above copyright 1.14 + * notice, this list of conditions and the following disclaimer in the 1.15 + * documentation and/or other materials provided with the distribution. 1.16 + * 1.17 + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 1.18 + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 1.19 + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1.20 + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 1.21 + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1.22 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 1.23 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 1.24 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 1.25 + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 1.26 + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 1.27 + * POSSIBILITY OF SUCH DAMAGE. 1.28 + * 1.29 + * Changelog: 1.30 + * 2005-04-26 - Define the header as a C structure, add a CRC32 checksum to 1.31 + * the header, and make all the types 32-bit. 1.32 + * --Benjamin Smedberg <benjamin@smedbergs.us> 1.33 + */ 1.34 + 1.35 +#ifndef bspatch_h__ 1.36 +#define bspatch_h__ 1.37 + 1.38 +#include <stdint.h> 1.39 +#include <stdio.h> 1.40 + 1.41 +typedef struct MBSPatchHeader_ { 1.42 + /* "MBDIFF10" */ 1.43 + char tag[8]; 1.44 + 1.45 + /* Length of the file to be patched */ 1.46 + uint32_t slen; 1.47 + 1.48 + /* CRC32 of the file to be patched */ 1.49 + uint32_t scrc32; 1.50 + 1.51 + /* Length of the result file */ 1.52 + uint32_t dlen; 1.53 + 1.54 + /* Length of the control block in bytes */ 1.55 + uint32_t cblen; 1.56 + 1.57 + /* Length of the diff block in bytes */ 1.58 + uint32_t difflen; 1.59 + 1.60 + /* Length of the extra block in bytes */ 1.61 + uint32_t extralen; 1.62 + 1.63 + /* Control block (MBSPatchTriple[]) */ 1.64 + /* Diff block (binary data) */ 1.65 + /* Extra block (binary data) */ 1.66 +} MBSPatchHeader; 1.67 + 1.68 +/** 1.69 + * Read the header of a patch file into the MBSPatchHeader structure. 1.70 + * 1.71 + * @param fd Must have been opened for reading, and be at the beginning 1.72 + * of the file. 1.73 + */ 1.74 +int MBS_ReadHeader(FILE* file, MBSPatchHeader *header); 1.75 + 1.76 +/** 1.77 + * Apply a patch. This method does not validate the checksum of the original 1.78 + * file: client code should validate the checksum before calling this method. 1.79 + * 1.80 + * @param patchfd Must have been processed by MBS_ReadHeader 1.81 + * @param fbuffer The original file read into a memory buffer of length 1.82 + * header->slen. 1.83 + * @param filefd Must have been opened for writing. Should be truncated 1.84 + * to header->dlen if it is an existing file. The offset 1.85 + * should be at the beginning of the file. 1.86 + */ 1.87 +int MBS_ApplyPatch(const MBSPatchHeader *header, FILE* patchFile, 1.88 + unsigned char *fbuffer, FILE* file); 1.89 + 1.90 +typedef struct MBSPatchTriple_ { 1.91 + uint32_t x; /* add x bytes from oldfile to x bytes from the diff block */ 1.92 + uint32_t y; /* copy y bytes from the extra block */ 1.93 + int32_t z; /* seek forwards in oldfile by z bytes */ 1.94 +} MBSPatchTriple; 1.95 + 1.96 +#endif // bspatch_h__