1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
/***************************************************************************
* _______ _______ _______ *
* | ___ |____ | ___ | *
* | | |_| / /| | |_| *
* | |_____ / / | |_____ *
* |_____ | / / |_____ | *
* _ | | / / _ | | *
* | |___| |/ /____| |___| | *
* |_______|_______|_______| *
* *
* Wiimms SZS Tools *
* https://szs.wiimm.de/ *
* *
***************************************************************************
* *
* This file is part of the SZS project. *
* Visit https://szs.wiimm.de/ for project details and sources. *
* *
* Copyright (c) 2011-2024 by Dirk Clemens <wiimm@wiimm.de> *
* *
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* See file gpl-2.0.txt or http://www.gnu.org/licenses/gpl-2.0.txt *
* *
***************************************************************************/
#ifndef SZS_LIB_CHECKSUM_H
#define SZS_LIB_CHECKSUM_H 1
#define _GNU_SOURCE 1
#include "dclib-types.h"
#include "lib-szs-file.h"
#include "lib-ledis.h"
#include "crypt.h"
typedef struct szs_file_t szs_file_t;
//
///////////////////////////////////////////////////////////////////////////////
/////////////// struct sha1_size_hash_t ///////////////
///////////////////////////////////////////////////////////////////////////////
// [[sha1_size_hash_t]]
#define CHECKSUM_DB_SIZE 32
///////////////////////////////////////////////////////////////////////////////
void CreateSS ( cvp data, uint size, sha1_size_hash_t *dest );
void CreateSS64 ( cvp data, uint size, sha1_size_b64_t dest );
// bufsize should be >40
void CreateSSChecksum ( char *buf, uint bufsize, const sha1_size_hash_t *ss );
void CreateSSChecksumBySZS ( char *buf, uint bufsize, const szs_file_t *szs );
// normed DB coding (independent of options)
void CreateSSChecksumDB ( char *buf, uint bufsize, const sha1_size_hash_t *ss );
void CreateSSChecksumDBByData ( char *buf, uint bufsize, cvp data, uint size );
void CreateSSChecksumDBBySZS ( char *buf, uint bufsize, const szs_file_t *szs );
void CreateSSXChecksumDBByData ( char *buf, uint bufsize, cvp data, uint size, file_format_t ff );
void CreateSSXChecksumDBBySZS ( char *buf, uint bufsize, const szs_file_t *szs );
enumError GetSSByFile ( sha1_size_hash_t *ss, ccp path1, ccp path2 );
// slen < 0 => strlen(source)
// returns: 0:fail, 1:SHA1, 2:DB64
// if res != NULL: scanned SHA1
int IsSSChecksum ( sha1_size_hash_t *res, ccp source, int slen );
//
///////////////////////////////////////////////////////////////////////////////
/////////////// szs cache support ///////////////
///////////////////////////////////////////////////////////////////////////////
#define SZS_CACHE_FNAME "cache-content.txt"
extern ccp szs_cache_dir;
extern ParamField_t szs_cache;
///////////////////////////////////////////////////////////////////////////////
void LogCacheActivity ( ccp keyword, ccp format, ... )
__attribute__ ((__format__(__printf__,2,3)));
static inline bool IsSZSCacheEnabled()
{ return szs_cache_dir != 0; }
void SetupSZSCache ( ccp dir_name, bool use_dirname );
void ScanSZSCache ( ccp dir_name, bool purge );
enumError LoadSZSCache(void);
enumError SaveSZSCache ( bool force );
enumError AppendSZSCache(void);
ParamFieldItem_t * StoreSZSCache
(
// return NULL or pointer to cache item
ccp fname, // NULL or filename, only basename(fname) is used
ccp checksum, // DB checksum; if NULL: load file and calc checksum
bool rename_file, // true: rename existing file
bool *r_exists // not NULL: store a status here
// => true: file result->data exists
);
//-----------------------------------------------------------------------------
// [[check_cache_t]]
typedef struct check_cache_t
{
file_format_t fform;
bool found; // true, if file found in cache
char csum[CHECKSUM_DB_SIZE+4];
// checksum with suffix
szs_file_t cache; // file loaded from cache, valid if found==true
}
check_cache_t;
void ResetCheckCache ( check_cache_t *cc );
bool CheckSZSCache
(
// returns true if file found in cache (same as cc->found)
check_cache_t *cc, // initialized by CheckSZSCache()
szs_file_t *szs, // related SZS file
cvp data, // data
uint size, // size of 'data'
file_format_t fform, // compression format
ccp ext // wanted file extension including leading '.'
);
bool CheckSZSCacheSZS
(
// returns true if file found in cache (same as cc->found)
szs_file_t *szs, // related SZS file
file_format_t fform, // compression format
ccp ext, // wanted file extension including leading '.'
bool rm_uncompressed // true: remove uncompressed data if cache is used
);
//
///////////////////////////////////////////////////////////////////////////////
/////////////// END ///////////////
///////////////////////////////////////////////////////////////////////////////
#endif // SZS_LIB_CHECKSUM_H
|