summaryrefslogtreecommitdiff
path: root/support/dktools/Dk4FcsThread.cpp
blob: 5afedd672011abc3f570ac5852bf653699b3ec59 (plain)
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
/*
	WARNING: This file was generated by dkct.
	Changes you make here will be lost if dkct is run again!
	You should modify the original source and run dkct on it.
	Original source: Dk4FcsThread.cpt
*/

/*
Copyright (C) 2015, Dirk Krause

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice,
  this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above opyright notice,
  this list of conditions and the following disclaimer in the documentation
  and/or other materials provided with the distribution.
* Neither the name of the author nor the names of contributors may be used
  to endorse or promote products derived from this software without specific
  prior written permission.

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 OWNER 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.
*/

/**	@file Dk4FcsThread.cpp The Dk4FcsThread module.
*/


#line 108 "Dk4FcsThread.cpt"


#include "dk4mem.h"
#include "wxdkfcs.h"



static
void
ctx_collection_init(dk4fcs_ctx_t *ptr)
{
  dk4mem_reset(ptr, sizeof(dk4fcs_ctx_t), NULL);
#if DK4_HAVE_OPENSSL_MD5_H
  MD5_Init(&(ptr->md5));
#endif
#if DK4_HAVE_OPENSSL_RIPEMD_H
  RIPEMD160_Init(&(ptr->ripemd160));
#endif
#if DK4_HAVE_OPENSSL_SHA_H
  SHA1_Init(&(ptr->sha1));
#if DK4_HAVE_SHA224
  SHA224_Init(&(ptr->sha224));
#endif
#if DK4_HAVE_SHA256
  SHA256_Init(&(ptr->sha256));
#endif
#if DK4_HAVE_SHA384
  SHA384_Init(&(ptr->sha384));
#endif
#if DK4_HAVE_SHA512
  SHA512_Init(&(ptr->sha512));
#endif
#endif
}



static
void
ctx_collection_add(dk4fcs_ctx_t *ptr, void *data, size_t sz)
{
#if DK4_HAVE_OPENSSL_MD5_H
  MD5_Update(&(ptr->md5), data, sz);
#endif
#if DK4_HAVE_OPENSSL_RIPEMD_H
  RIPEMD160_Update(&(ptr->ripemd160), data, sz);
#endif
#if DK4_HAVE_OPENSSL_SHA_H
  SHA1_Update(&(ptr->sha1), data, sz);
#if DK4_HAVE_SHA224
  SHA224_Update(&(ptr->sha224), data, sz);
#endif
#if DK4_HAVE_SHA256
  SHA256_Update(&(ptr->sha256), data, sz);
#endif
#if DK4_HAVE_SHA384
  SHA384_Update(&(ptr->sha384), data, sz);
#endif
#if DK4_HAVE_SHA512
  SHA512_Update(&(ptr->sha512), data, sz);
#endif
#endif
}



static
void
ctx_collection_finish(dk4fcs_ctx_t *ptr)
{
#if DK4_HAVE_OPENSSL_MD5_H
  MD5_Final(&(ptr->md5bytes[0]), &(ptr->md5));
#endif
#if DK4_HAVE_OPENSSL_RIPEMD_H
  RIPEMD160_Final(&(ptr->ripemd160bytes[0]), &(ptr->ripemd160));
#endif
#if DK4_HAVE_OPENSSL_SHA_H
  SHA1_Final(&(ptr->sha1bytes[0]), &(ptr->sha1));
#if DK4_HAVE_SHA224
  SHA224_Final(&(ptr->sha224bytes[0]), &(ptr->sha224));
#endif
#if DK4_HAVE_SHA256
  SHA256_Final(&(ptr->sha256bytes[0]), &(ptr->sha256));
#endif
#if DK4_HAVE_SHA384
  SHA384_Final(&(ptr->sha384bytes[0]), &(ptr->sha384));
#endif
#if DK4_HAVE_SHA512
  SHA512_Final(&(ptr->sha512bytes[0]), &(ptr->sha512));
#endif
#endif
}



Dk4FcsThread::Dk4FcsThread(
  wxFile			*wxf,
  Dk4WxProcessingController	*proCo,
  dk4fcs_ctx_t			*ctx
)
{
  pWxFile = wxf;
  pProCo = proCo;
  pCtx = ctx;
}



void *
Dk4FcsThread::Entry()
{
  unsigned char	 buf[4096];
  void		*back		= NULL;
  wxFileOffset	 fileSize	= (wxFileOffset)0UL;
  wxFileOffset	 summary	= (wxFileOffset)0UL;
  size_t	 rdb		= 0;
  int		 gv		= 0;
  int		 ogv		= 0;
  bool		 cc		= true;		// Flag: Can continue
  bool		 succ		= true;		// Flag: Success

  

#line 230 "Dk4FcsThread.cpt"
  /*	Initialize variables.
  */
  fileSize = pWxFile->Length();
  ctx_collection_init(pCtx);
  

#line 235 "Dk4FcsThread.cpt"
  /*	Run in a loop.
  */
  do {
    if (pProCo->canContinue()) {		

#line 239 "Dk4FcsThread.cpt"
      rdb = pWxFile->Read(buf, sizeof(buf));
      if (0 < rdb) {				

#line 241 "Dk4FcsThread.cpt"
        ctx_collection_add(pCtx, buf, rdb);	

#line 242 "Dk4FcsThread.cpt"
        summary += (wxFileOffset)rdb;
	if ((wxFileOffset)0UL < fileSize) {
	  if (summary < fileSize) {
	    gv = (int)((1000.0 * (double)summary) / (double)fileSize);
	  } else {
	    gv = 1000;
	  }
	} else {
	  gv = 1000;
	}
	if (gv != ogv) {			

#line 253 "Dk4FcsThread.cpt"
	  pProCo->setGaugeValue(gv);
	  ogv = gv;
	}
      } else {					

#line 257 "Dk4FcsThread.cpt"
        if (summary != fileSize) {
	  succ = false;				

#line 259 "Dk4FcsThread.cpt"
	}
	cc = false;
      }
    } else {					

#line 263 "Dk4FcsThread.cpt"
      cc = false;
      succ = false;			// Aborted by user.
    }
  } while(cc);
  

#line 268 "Dk4FcsThread.cpt"
  /*	Finish contexts.
  */
  ctx_collection_finish(pCtx);
  

#line 272 "Dk4FcsThread.cpt"
  /*	End processsing
  */
  pProCo->endProcessing(succ);
  

#line 276 "Dk4FcsThread.cpt"
  return back;
}



void
Dk4FcsThread::OnExit()
{

}