1 /*************************************************************************** 2 begin : Wed Jun 22 2011 3 copyright : (C) 2011 by Martin Preuss 4 email : martin@libchipcard.de 5 6 *************************************************************************** 7 * * 8 * This library is free software; you can redistribute it and/or * 9 * modify it under the terms of the GNU Lesser General Public * 10 * License as published by the Free Software Foundation; either * 11 * version 2.1 of the License, or (at your option) any later version. * 12 * * 13 * This library 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 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 library; if not, write to the Free Software * 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * 21 * MA 02111-1307 USA * 22 * * 23 ***************************************************************************/ 24 25 26 #ifndef GWEN_SAR_P_H 27 #define GWEN_SAR_P_H 28 29 #include <gwenhywfar/sar.h> 30 #include <gwenhywfar/syncio.h> 31 #include <gwenhywfar/buffer.h> 32 #include <gwenhywfar/mdigest.h> 33 34 #include <inttypes.h> 35 36 37 #define GWEN_SAR_HEADER_VERSION ((uint32_t)0x01000000) 38 39 40 #define GWEN_SAR_TAG_HEADER 0x01 41 # define GWEN_SAR_TAG_HEADER_VERSION 0x01 42 # define GWEN_SAR_TAG_HEADER_STATUS 0x02 43 # define GWEN_SAR_TAG_HEADER_FLAGS 0x03 44 # define GWEN_SAR_TAG_HEADER_PATH 0x04 45 # define GWEN_SAR_TAG_HEADER_TYPE 0x05 46 # define GWEN_SAR_TAG_HEADER_PERM 0x06 47 # define GWEN_SAR_TAG_HEADER_ATIME 0x07 48 # define GWEN_SAR_TAG_HEADER_MTIME 0x08 49 # define GWEN_SAR_TAG_HEADER_CTIME 0x09 50 # define GWEN_SAR_TAG_HEADER_SIZE 0x0a 51 52 #define GWEN_SAR_TAG_FILE 0x02 53 #define GWEN_SAR_TAG_HASH 0x03 54 #define GWEN_SAR_TAG_SIGNATURE 0x04 55 56 57 58 enum { 59 GWEN_Sar_OpenMode_Closed=0, 60 GWEN_Sar_OpenMode_Created, 61 GWEN_Sar_OpenMode_Opened 62 }; 63 64 65 struct GWEN_SAR { 66 char *archiveName; 67 GWEN_SYNCIO *archiveSio; 68 uint64_t archiveSize; 69 70 GWEN_SAR_FILEHEADER_LIST *headers; 71 72 uint64_t signaturePos; 73 uint64_t signatureSize; 74 75 int openMode; 76 int refCount; 77 }; 78 79 80 static uint64_t GWEN_Sar_ReadUint64(const uint8_t *p, uint32_t bs); 81 static int GWEN_Sar_FileHeaderToTlv(const GWEN_SAR_FILEHEADER *fh, GWEN_BUFFER *tbuf); 82 static int GWEN_Sar_TlvToFileHeader(GWEN_BUFFER *mbuf, GWEN_SAR_FILEHEADER *fh); 83 84 static int GWEN_Sar_AddAndDigestFile(GWEN_SAR *sr, const GWEN_SAR_FILEHEADER *fh, GWEN_MDIGEST *md); 85 static int GWEN_Sar_AddAndDigestFileReg(GWEN_SAR *sr, const GWEN_SAR_FILEHEADER *fh, GWEN_MDIGEST *md); 86 static int GWEN_Sar_AddAndDigestFileLink(GWEN_SAR *sr, const GWEN_SAR_FILEHEADER *fh, GWEN_MDIGEST *md); 87 88 static int GWEN_Sar_ExtractAndDigestFile(GWEN_SAR *sr, const GWEN_SAR_FILEHEADER *fh, int checkOnly); 89 static int GWEN_Sar_ExtractAndDigestFileReg(GWEN_SAR *sr, const GWEN_SAR_FILEHEADER *fh, int checkOnly); 90 static int GWEN_Sar_ExtractAndDigestFileLink(GWEN_SAR *sr, const GWEN_SAR_FILEHEADER *fh, int checkOnly); 91 static int GWEN_Sar_ExtractAndDigestFileDir(GWEN_SAR *sr, const GWEN_SAR_FILEHEADER *fh, int checkOnly); 92 93 94 static int GWEN_Sar_ScanFile(GWEN_SAR *sr); 95 96 static int GWEN_Sar__UnpackArchive(const char *inFile, const char *where); 97 98 99 #endif 100 101 102 103 104 105