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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
|
/* ------------------------------------------------------------ */
/*
HTTrack Website Copier, Offline Browser for Windows and Unix
Copyright (C) Xavier Roche and other contributors
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 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.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Important notes:
- We hereby ask people using this source NOT to use it in purpose of grabbing
emails addresses, or collecting any other private information on persons.
This would disgrace our work, and spoil the many hours we spent on it.
Please visit our Website: http://www.httrack.com
*/
/* ------------------------------------------------------------ */
/* File: htsshow.c console progress info */
/* Author: Xavier Roche */
/* ------------------------------------------------------------ */
#ifndef HTSTOOLS_DEFH
#define HTSTOOLS_DEFH
#if HTS_ANALYSTE_CONSOLE
#include "htsglobal.h"
#include "htscore.h"
typedef struct {
char name[1024];
char file[1024];
char state[256];
char BIGSTK url_sav[HTS_URLMAXSIZE*2]; // pour cancel
char BIGSTK url_adr[HTS_URLMAXSIZE*2];
char BIGSTK url_fil[HTS_URLMAXSIZE*2];
LLint size;
LLint sizetot;
int offset;
//
int back;
//
int actived; // pour disabled
} t_StatsBuffer;
typedef struct {
int ask_refresh;
int refresh;
LLint stat_bytes;
int stat_time;
int lien_n;
int lien_tot;
int stat_nsocket;
int rate;
int irate;
int ft;
LLint stat_written;
int stat_updated;
int stat_errors;
int stat_warnings;
int stat_infos;
TStamp stat_timestart;
int stat_back;
} t_InpInfo;
// wrappers
static void __cdecl htsshow_init(void);
static void __cdecl htsshow_uninit(void);
static int __cdecl htsshow_start(httrackp* opt);
static int __cdecl htsshow_chopt(httrackp* opt);
static int __cdecl htsshow_end(void);
static int __cdecl htsshow_preprocesshtml(char** html,int* len,char* url_adresse,char* url_fichier);
static int __cdecl htsshow_postprocesshtml(char** html,int* len,char* url_adresse,char* url_fichier);
static int __cdecl htsshow_checkhtml(char* html,int len,char* url_adresse,char* url_fichier);
static int __cdecl htsshow_loop(lien_back* back,int back_max,int back_index,int lien_n,int lien_tot,int stat_time,hts_stat_struct* stats);
static char* __cdecl htsshow_query(char* question);
static char* __cdecl htsshow_query2(char* question);
static char* __cdecl htsshow_query3(char* question);
static int __cdecl htsshow_check(char* adr,char* fil,int status);
static void __cdecl htsshow_pause(char* lockfile);
static void __cdecl htsshow_filesave(char* file);
static int __cdecl htsshow_linkdetected(char* link);
static int __cdecl htsshow_linkdetected2(char* link, char* start_tag);
static int __cdecl htsshow_xfrstatus(lien_back* back);
static int __cdecl htsshow_savename(char* adr_complete,char* fil_complete,char* referer_adr,char* referer_fil,char* save);
static int __cdecl htsshow_sendheader(char* buff, char* adr, char* fil, char* referer_adr, char* referer_fil, htsblk* outgoing);
static int __cdecl htsshow_receiveheader(char* buff, char* adr, char* fil, char* referer_adr, char* referer_fil, htsblk* incoming);
int main(int argc, char **argv);
static void vt_color(int text,int back);
static void vt_clear(void);
static void vt_home(void);
#endif
/* */
// Engine internal variables
typedef void (* htsErrorCallback)(char* msg, char* file, int line);
extern HTSEXT_API htsErrorCallback htsCallbackErr;
extern HTSEXT_API int htsMemoryFastXfr;
/* */
extern HTSEXT_API hts_stat_struct HTS_STAT;
extern int _DEBUG_HEAD;
extern FILE* ioinfo;
// from htsbase.h
/* protected strcat, strncat and strcpy - definitely useful */
#define strcatbuff(A, B) do { \
assertf( (A) != NULL ); \
if ( ! (B) ) { assertf( 0 ); } \
if (htsMemoryFastXfr) { \
if (sizeof(A) != sizeof(char*)) { \
(A)[sizeof(A) - 1] = '\0'; \
} \
strcat(A, B); \
if (sizeof(A) != sizeof(char*)) { \
assertf((A)[sizeof(A) - 1] == '\0'); \
} \
} else { \
unsigned int sz = (unsigned int) strlen(A); \
unsigned int szf = (unsigned int) strlen(B); \
if (sizeof(A) != sizeof(char*)) { \
assertf(sz + szf + 1 < sizeof(A)); \
if (szf > 0) { \
if (sz + szf + 1 < sizeof(A)) { \
memcpy((A) + sz, (B), szf + 1); \
} \
} \
} else if (szf > 0) { \
memcpybuff((A) + sz, (B), szf + 1); \
} \
} \
} while(0)
#define strncatbuff(A, B, N) do { \
assertf( (A) != NULL ); \
if ( ! (B) ) { assertf( 0 ); } \
if (htsMemoryFastXfr) { \
if (sizeof(A) != sizeof(char*)) { \
(A)[sizeof(A) - 1] = '\0'; \
} \
strncat(A, B, N); \
if (sizeof(A) != sizeof(char*)) { \
assertf((A)[sizeof(A) - 1] == '\0'); \
} \
} else { \
unsigned int sz = (unsigned int) strlen(A); \
unsigned int szf = (unsigned int) strlen(B); \
if (szf > (unsigned int) (N)) szf = (unsigned int) (N); \
if (sizeof(A) != sizeof(char*)) { \
assertf(sz + szf + 1 < sizeof(A)); \
if (szf > 0) { \
if (sz + szf + 1 < sizeof(A)) { \
memcpy((A) + sz, (B), szf); \
* ( (A) + sz + szf) = '\0'; \
} \
} \
} else if (szf > 0) { \
memcpybuff((A) + sz, (B), szf); \
* ( (A) + sz + szf) = '\0'; \
} \
} \
} while(0)
#define strcpybuff(A, B) do { \
assertf( (A) != NULL ); \
if ( ! (B) ) { assertf( 0 ); } \
if (htsMemoryFastXfr) { \
if (sizeof(A) != sizeof(char*)) { \
(A)[sizeof(A) - 1] = '\0'; \
} \
strcpy(A, B); \
if (sizeof(A) != sizeof(char*)) { \
assertf((A)[sizeof(A) - 1] == '\0'); \
} \
} else { \
unsigned int szf = (unsigned int) strlen(B); \
if (sizeof(A) != sizeof(char*)) { \
assertf(szf + 1 < sizeof(A)); \
if (szf > 0) { \
if (szf + 1 < sizeof(A)) { \
memcpy((A), (B), szf + 1); \
} else { \
* (A) = '\0'; \
} \
} else { \
* (A) = '\0'; \
} \
} else { \
memcpybuff((A), (B), szf + 1); \
} \
} \
} while(0)
#define strncpybuff(A, B, N) do { \
assertf( (A) != NULL ); \
if ( ! (B) ) { assertf( 0 ); } \
if (htsMemoryFastXfr) { \
if (sizeof(A) != sizeof(char*)) { \
(A)[sizeof(A) - 1] = '\0'; \
} \
strncpy(A, B, N); \
if (sizeof(A) != sizeof(char*)) { \
assertf((A)[sizeof(A) - 1] == '\0'); \
} \
} else { \
unsigned int szf = (unsigned int) strlen(B); \
if (szf > (unsigned int) (N)) szf = (unsigned int) (N); \
if (sizeof(A) != sizeof(char*)) { \
assertf(szf + 1 < sizeof(A)); \
if (szf > 0) { \
if (szf + 1 < sizeof(A)) { \
memcpy((A), (B), szf); \
} \
} \
} else { \
memcpybuff((A), (B), szf); \
} \
} \
} while(0)
// emergency log
typedef void (*t_abortLog)(char* msg, char* file, int line);
extern HTSEXT_API t_abortLog abortLog__;
#define abortLog(a) abortLog__(a, __FILE__, __LINE__)
#define abortLogFmt(a) do { \
FILE* fp = fopen("CRASH.TXT", "wb"); \
if (!fp) fp = fopen("/tmp/CRASH.TXT", "wb"); \
if (!fp) fp = fopen("C:\\CRASH.TXT", "wb"); \
if (fp) { \
fprintf(fp, "HTTrack " HTTRACK_VERSIONID " closed at '" __FILE__ "', line %d\r\n", __LINE__); \
fprintf(fp, "Reason:\r\n"); \
fprintf(fp, a); \
fprintf(fp, "\r\n"); \
fflush(fp); \
fclose(fp); \
} \
} while(0)
#define _ ,
#define abortLogFmt(a) do { \
FILE* fp = fopen("CRASH.TXT", "wb"); \
if (!fp) fp = fopen("/tmp/CRASH.TXT", "wb"); \
if (!fp) fp = fopen("C:\\CRASH.TXT", "wb"); \
if (fp) { \
fprintf(fp, "HTTrack " HTTRACK_VERSIONID " closed at '" __FILE__ "', line %d\r\n", __LINE__); \
fprintf(fp, "Reason:\r\n"); \
fprintf(fp, a); \
fprintf(fp, "\r\n"); \
fflush(fp); \
fclose(fp); \
} \
} while(0)
#define assertf(exp) do { \
if (! ( exp ) ) { \
abortLog("assert failed: " #exp); \
if (htsCallbackErr != NULL) { \
htsCallbackErr("assert failed: " #exp, __FILE__ , __LINE__ ); \
} \
assert(exp); \
abort(); \
} \
} while(0)
/* non-fatal assert */
#define assertnf(exp) do { \
if (! ( exp ) ) { \
abortLog("assert failed: " #exp); \
if (htsCallbackErr != NULL) { \
htsCallbackErr("assert failed: " #exp, __FILE__ , __LINE__ ); \
} \
} \
} while(0)
//
#define malloct(A) malloc(A)
#define calloct(A,B) calloc((A), (B))
#define freet(A) do { assertnf((A) != NULL); if ((A) != NULL) { free(A); (A) = NULL; } } while(0)
#define strdupt(A) strdup(A)
#define realloct(A,B) ( ((A) != NULL) ? realloc((A), (B)) : malloc(B) )
#define memcpybuff(A, B, N) memcpy((A), (B), (N))
#endif
|