summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorXavier Roche <xroche@users.noreply.github.com>2013-05-13 14:31:20 +0000
committerXavier Roche <xroche@users.noreply.github.com>2013-05-13 14:31:20 +0000
commitbb4c595810ccd9b849be2d20f5c16d6076d083bb (patch)
treea0443629b2d996f0597f75e8bafee3f8fd13505e /src
parent84c47b0ce10547fdf223f721ef88f7af09af5401 (diff)
Introducing the hts_log_print() logging function
* cleaned up logging
Diffstat (limited to 'src')
-rw-r--r--src/htsback.c375
-rw-r--r--src/htsbase.h32
-rw-r--r--src/htscache.c117
-rw-r--r--src/htscore.c350
-rw-r--r--src/htscore.h12
-rw-r--r--src/htscoremain.c30
-rw-r--r--src/htslib.c64
-rw-r--r--src/htslib.h1
-rw-r--r--src/htsmodules.c6
-rw-r--r--src/htsname.c79
-rw-r--r--src/htsopt.h13
-rw-r--r--src/htsparse.c573
-rwxr-xr-xsrc/htsstrings.h2
-rw-r--r--src/htswizard.c206
-rw-r--r--src/httrack-library.h13
-rw-r--r--src/proxy/proxytrack.c2
-rw-r--r--src/proxy/store.c2
17 files changed, 525 insertions, 1352 deletions
diff --git a/src/htsback.c b/src/htsback.c
index 7da2cf8..2e07121 100644
--- a/src/htsback.c
+++ b/src/htsback.c
@@ -70,9 +70,6 @@ Please visit our Website: http://www.httrack.com
#include "htsmms.h"
#endif
-#undef test_flush
-#define test_flush if (opt->flush) { if (opt->log) { fflush(opt->log); } if (opt->log) { fflush(opt->log); } }
-
#define VT_CLREOL "\33[K"
/* Slot operations */
@@ -203,19 +200,11 @@ static int back_index_ready(httrackp* opt, struct_back* sback, char* adr, char*
freet(itemback);
itemback = NULL;
}
- if (opt->log != NULL) {
- int last_errno = errno;
- HTS_LOG(opt,LOG_INFO); fprintf(opt->log,"engine: warning: unserialize error for %s%s (%s): %s"LF,adr,fil,sav,strerror(last_errno));
- test_flush;
- }
+ hts_log_print(opt, LOG_INFO | LOG_ERRNO, "engine: warning: unserialize error for %s%s (%s)",adr,fil,sav);
}
fclose(fp);
} else {
- if (opt->log != NULL) {
- int last_errno = errno;
- HTS_LOG(opt,LOG_INFO); fprintf(opt->log,"engine: warning: unserialize error for %s%s (%s), file disappeared: %s"LF,adr,fil,sav,strerror(last_errno));
- test_flush;
- }
+ hts_log_print(opt, LOG_INFO | LOG_ERRNO, "engine: warning: unserialize error for %s%s (%s), file disappeared",adr,fil,sav);
}
(void) UNLINK(fileback);
#else
@@ -235,10 +224,7 @@ static int back_index_ready(httrackp* opt, struct_back* sback, char* adr, char*
back_set_locked(sback, q); /* locked */
return q;
} else {
- if (opt->log != NULL) {
- HTS_LOG(opt,LOG_INFO); fprintf(opt->log,"engine: warning: unserialize error for %s%s (%s): no more space to wakeup frozen slots"LF,adr,fil,sav);
- test_flush;
- }
+ hts_log_print(opt, LOG_INFO, "engine: warning: unserialize error for %s%s (%s): no more space to wakeup frozen slots",adr,fil,sav);
}
}
}
@@ -270,13 +256,10 @@ int back_cleanup_background(httrackp* opt,cache_back* cache,struct_back* sback)
/* Security check */
int checkIndex = back_index_ready(opt, sback, back[i].url_adr, back[i].url_fil, back[i].url_sav, 1);
if (checkIndex != -1) {
- if (opt->log) {
- HTS_LOG(opt,LOG_WARNING); fprintf(opt->log,"engine: unexpected duplicate file entry: %s%s -> %s (%d '%s') / %s%s -> %s (%d '%s')"LF,
- back[checkIndex].url_adr, back[checkIndex].url_fil, back[checkIndex].url_sav, back[checkIndex].r.statuscode, back[checkIndex].r.msg,
- back[i].url_adr, back[i].url_fil, back[i].url_sav, back[i].r.statuscode, back[i].r.msg
- );
- test_flush;
- }
+ hts_log_print(opt, LOG_WARNING, "engine: unexpected duplicate file entry: %s%s -> %s (%d '%s') / %s%s -> %s (%d '%s')",
+ back[checkIndex].url_adr, back[checkIndex].url_fil, back[checkIndex].url_sav, back[checkIndex].r.statuscode, back[checkIndex].r.msg,
+ back[i].url_adr, back[i].url_fil, back[i].url_sav, back[i].r.statuscode, back[i].r.msg
+ );
back_delete(NULL, NULL, sback, checkIndex);
#ifdef _DEBUG
/* This should NOT happend! */
@@ -297,10 +280,7 @@ int back_cleanup_background(httrackp* opt,cache_back* cache,struct_back* sback)
}
/* Security check */
if (fexist_utf8(filename)) {
- if (opt->log != NULL) {
- HTS_LOG(opt,LOG_INFO); fprintf(opt->log,"engine: warning: temporary file %s already exists"LF, filename);
- test_flush;
- }
+ hts_log_print(opt, LOG_INFO, "engine: warning: temporary file %s already exists", filename);
}
/* Create file and serialize slot */
if ((fp = filecreate(NULL, filename)) != NULL)
@@ -313,28 +293,16 @@ int back_cleanup_background(httrackp* opt,cache_back* cache,struct_back* sback)
nclean++;
back_clear_entry(&back[i]); /* entry is now recycled */
} else {
- if (opt->log != NULL) {
- int last_errno = errno;
- HTS_LOG(opt,LOG_INFO); fprintf(opt->log,"engine: warning: serialize error for %s%s to %s: write error: %s"LF,back[i].url_adr,back[i].url_fil,filename,strerror(last_errno));
- test_flush;
- }
+ hts_log_print(opt, LOG_INFO | LOG_ERRNO, "engine: warning: serialize error for %s%s to %s: write error",back[i].url_adr,back[i].url_fil,filename);
}
fclose(fp);
} else {
- if (opt->log != NULL) {
- int last_errno = errno;
- HTS_LOG(opt,LOG_INFO); fprintf(opt->log,"engine: warning: serialize error for %s%s to %s: open error: %s (%s, %s)"LF, back[i].url_adr, back[i].url_fil, filename, strerror(last_errno), dir_exists(filename) ? "directory exists" : "directory does NOT exist!", fexist_utf8(filename) ? "file already exists!" : "file does not exist");
- test_flush;
- }
+ hts_log_print(opt, LOG_INFO | LOG_ERRNO, "engine: warning: serialize error for %s%s to %s: open error (%s, %s)", back[i].url_adr, back[i].url_fil, filename, dir_exists(filename) ? "directory exists" : "directory does NOT exist!", fexist_utf8(filename) ? "file already exists!" : "file does not exist");
}
if (filename != NULL)
free(filename);
} else {
- if (opt->log != NULL) {
- int last_errno = errno;
- HTS_LOG(opt,LOG_INFO); fprintf(opt->log,"engine: warning: serialize error for %s%s to %s: memory full: %s"LF,back[i].url_adr,back[i].url_fil,filename,strerror(last_errno));
- test_flush;
- }
+ hts_log_print(opt, LOG_INFO | LOG_ERRNO, "engine: warning: serialize error for %s%s to %s: memory full",back[i].url_adr,back[i].url_fil,filename);
}
}
#else
@@ -462,19 +430,12 @@ int back_finalize(httrackp* opt, cache_back* cache, struct_back* sback, const in
if (back[p].r.totalsize >= 0 && back[p].r.statuscode > 0
&& back[p].r.size != back[p].r.totalsize && ! opt->tolerant) {
if (back[p].status == STATUS_READY) {
- if (opt->log!=NULL) {
- HTS_LOG(opt,LOG_WARNING);
- fprintf(opt->log, "file not stored in cache due to bogus state (broken size, expected "LLintP" got "LLintP"): %s%s"LF,
- back[p].r.totalsize, back[p].r.size, back[p].url_adr,back[p].url_fil);
- }
+ hts_log_print(opt, LOG_WARNING, "file not stored in cache due to bogus state (broken size, expected "LLintP" got "LLintP"): %s%s",
+ back[p].r.totalsize, back[p].r.size, back[p].url_adr,back[p].url_fil);
} else {
- if (opt->log!=NULL) {
- HTS_LOG(opt,LOG_INFO);
- fprintf(opt->log, "incomplete file not yet stored in cache (expected "LLintP" got "LLintP"): %s%s"LF,
- back[p].r.totalsize, back[p].r.size, back[p].url_adr,back[p].url_fil);
- }
+ hts_log_print(opt, LOG_INFO, "incomplete file not yet stored in cache (expected "LLintP" got "LLintP"): %s%s",
+ back[p].r.totalsize, back[p].r.size, back[p].url_adr,back[p].url_fil);
}
- test_flush;
return -1;
}
@@ -687,14 +648,10 @@ int back_finalize(httrackp* opt, cache_back* cache, struct_back* sback, const in
}
if ( (!back[p].r.notmodified) && (opt->is_update) ) {
HTS_STAT.stat_updated_files++; // page modifiée
- if (opt->log!=NULL) {
- HTS_LOG(opt,LOG_INFO);
- if (back[p].is_update) {
- fprintf(opt->log,"engine: transfer-status: link updated: %s%s -> %s"LF,back[p].url_adr,back[p].url_fil,back[p].url_sav);
- } else {
- fprintf(opt->log,"engine: transfer-status: link added: %s%s -> %s"LF,back[p].url_adr,back[p].url_fil,back[p].url_sav);
- }
- test_flush;
+ if (back[p].is_update) {
+ hts_log_print(opt, LOG_INFO, "engine: transfer-status: link updated: %s%s -> %s",back[p].url_adr,back[p].url_fil,back[p].url_sav);
+ } else {
+ hts_log_print(opt, LOG_INFO, "engine: transfer-status: link added: %s%s -> %s",back[p].url_adr,back[p].url_fil,back[p].url_sav);
}
if (cache->txt) {
if (back[p].is_update) {
@@ -704,10 +661,7 @@ int back_finalize(httrackp* opt, cache_back* cache, struct_back* sback, const in
}
}
} else {
- if ( (opt->debug>0) && (opt->log!=NULL) ) {
- HTS_LOG(opt,LOG_INFO); fprintf(opt->log,"engine: transfer-status: link recorded: %s%s -> %s"LF,back[p].url_adr,back[p].url_fil,back[p].url_sav);
- test_flush;
- }
+ hts_log_print(opt, LOG_INFO, "engine: transfer-status: link recorded: %s%s -> %s",back[p].url_adr,back[p].url_fil,back[p].url_sav);
if (cache->txt) {
if (opt->is_update)
state="untouched";
@@ -716,18 +670,13 @@ int back_finalize(httrackp* opt, cache_back* cache, struct_back* sback, const in
}
}
} else {
- if ( (opt->debug>0) && (opt->log!=NULL) ) {
- HTS_LOG(opt,LOG_INFO); fprintf(opt->log,"engine: transfer-status: empty file? (%d, '%s'): %s%s"LF,back[p].r.statuscode,back[p].r.msg,back[p].url_adr,back[p].url_fil);
- test_flush;
- }
+ hts_log_print(opt, LOG_INFO, "engine: transfer-status: empty file? (%d, '%s'): %s%s",back[p].r.statuscode,back[p].r.msg,back[p].url_adr,back[p].url_fil);
if (cache->txt) {
state="empty";
}
}
} else {
- if ( (opt->debug>0) && (opt->log!=NULL) ) {
- HTS_LOG(opt,LOG_INFO); fprintf(opt->log,"engine: transfer-status: link error (%d, '%s'): %s%s"LF,back[p].r.statuscode,back[p].r.msg,back[p].url_adr,back[p].url_fil);
- }
+ hts_log_print(opt, LOG_INFO, "engine: transfer-status: link error (%d, '%s'): %s%s",back[p].r.statuscode,back[p].r.msg,back[p].url_adr,back[p].url_fil);
if (cache->txt) {
state="error";
}
@@ -758,16 +707,12 @@ int back_finalize(httrackp* opt, cache_back* cache, struct_back* sback, const in
} else {
/* error */
if (!HTTP_IS_OK(back[p].r.statuscode)) {
- if ( (opt->debug>0) && (opt->log!=NULL) ) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"redirect to %s%s"LF,back[p].url_adr,back[p].url_fil);
- }
+ hts_log_print(opt, LOG_DEBUG, "redirect to %s%s",back[p].url_adr,back[p].url_fil);
/* Store only header reference */
cache_mayadd(opt,cache,&back[p].r,back[p].url_adr,back[p].url_fil,NULL);
} else {
/* Partial file, but marked as "ok" ? */
- if (opt->log!=NULL) {
- HTS_LOG(opt,LOG_WARNING); fprintf(opt->log,"file not stored in cache due to bogus state (incomplete type with %s (%d), size "LLintP"): %s%s"LF,back[p].r.msg,back[p].r.statuscode,(LLint)back[p].r.size,back[p].url_adr,back[p].url_fil);
- }
+ hts_log_print(opt, LOG_WARNING, "file not stored in cache due to bogus state (incomplete type with %s (%d), size "LLintP"): %s%s",back[p].r.msg,back[p].r.statuscode,(LLint)back[p].r.size,back[p].url_adr,back[p].url_fil);
}
}
@@ -996,11 +941,9 @@ int back_maydelete(httrackp* opt,cache_back* cache,struct_back* sback, const int
if (back_letlive(opt, cache, sback, p)) {
strcpybuff(back[p].url_adr, tmp.url_adr);
back[p].status = STATUS_ALIVE; // alive & waiting
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"(Keep-Alive): successfully saved #%d (%s)"LF,
- back[p].r.debugid,
- back[p].url_adr); test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "(Keep-Alive): successfully saved #%d (%s)",
+ back[p].r.debugid,
+ back[p].url_adr);
return 1;
}
}
@@ -1048,11 +991,9 @@ void back_maydeletehttp(httrackp* opt, cache_back* cache, struct_back* sback, co
back[p].r.soc = INVALID_SOCKET;
strcpybuff(back[q].url_adr, tmp.url_adr); // address
back[q].status = STATUS_ALIVE; // alive & waiting
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"(Keep-Alive): successfully preserved #%d (%s)"LF,
- back[q].r.debugid,
- back[q].url_adr); test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "(Keep-Alive): successfully preserved #%d (%s)",
+ back[q].r.debugid,
+ back[q].url_adr);
} else {
deletehttp(&back[p].r);
back[p].r.soc = INVALID_SOCKET;
@@ -1233,9 +1174,7 @@ int back_delete(httrackp* opt, cache_back* cache, struct_back* sback, const int
&&
(back[p].r.statuscode>0) // not internal error
) {
- if (opt != NULL && opt->debug>1 && opt->log!=NULL) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"File '%s%s' -> %s not yet saved in cache - saving now"LF, back[p].url_adr, back[p].url_fil, back[p].url_sav); test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "File '%s%s' -> %s not yet saved in cache - saving now", back[p].url_adr, back[p].url_fil, back[p].url_sav);
}
if (cache != NULL) {
back_finalize(opt, cache, sback, p);
@@ -1345,23 +1284,17 @@ int back_add(struct_back* sback,httrackp* opt,cache_back* cache,char* adr,char*
#if (defined(_DEBUG) || defined(DEBUG))
if (!test && back_exist(sback,opt,adr,fil,save)) {
int already_there = 0;
- if (opt->log!=NULL) {
- HTS_LOG(opt,LOG_ERROR); fprintf(opt->log,"error: back_add(%s,%s,%s) duplicate"LF, adr, fil, save);
- }
+ hts_log_print(opt, LOG_ERROR, "error: back_add(%s,%s,%s) duplicate", adr, fil, save);
}
#endif
// vérifier cohérence de adr et fil (non vide!)
if (strnotempty(adr)==0) {
- if (opt->log!=NULL) {
- HTS_LOG(opt,LOG_WARNING); fprintf(opt->log,"error: adr is empty for back_add"LF);
- }
+ hts_log_print(opt, LOG_WARNING, "error: adr is empty for back_add");
return -1; // erreur!
}
if (strnotempty(fil)==0) {
- if (opt->log!=NULL) {
- HTS_LOG(opt,LOG_WARNING); fprintf(opt->log,"error: fil is empty for back_add"LF);
- }
+ hts_log_print(opt, LOG_WARNING, "error: fil is empty for back_add");
return -1; // erreur!
}
// FIN vérifier cohérence de adr et fil (non vide!)
@@ -1424,9 +1357,7 @@ int back_add(struct_back* sback,httrackp* opt,cache_back* cache,char* adr,char*
strcpybuff(back[p].r.msg,"mirror stopped by user");
back[p].status=STATUS_READY; // terminé
back_set_finished(sback, p);
- if ((opt->debug>0) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_WARNING); fprintf(opt->log,"File not added due to mirror cancel: %s%s"LF,adr,fil); test_flush;
- }
+ hts_log_print(opt, LOG_WARNING, "File not added due to mirror cancel: %s%s",adr,fil);
return 0;
}
@@ -1508,13 +1439,9 @@ int back_add(struct_back* sback,httrackp* opt,cache_back* cache,char* adr,char*
rename(fconv(catbuff, previous_save), fconv(catbuff2,save));
if (fexist_utf8(fconv(catbuff,save))) {
found = 1;
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"File '%s' has been renamed since last mirror to '%s' ; applying changes"LF, previous_save, save); test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "File '%s' has been renamed since last mirror to '%s' ; applying changes", previous_save, save);
} else {
- if ((opt->debug>0) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_ERROR); fprintf(opt->log,"Could not rename '%s' to '%s' ; will have to retransfer it"LF, previous_save, save); test_flush;
- }
+ hts_log_print(opt, LOG_ERROR, "Could not rename '%s' to '%s' ; will have to retransfer it", previous_save, save);
}
}
}
@@ -1535,14 +1462,10 @@ int back_add(struct_back* sback,httrackp* opt,cache_back* cache,char* adr,char*
if (!fexist_utf8(fconv(catbuff,save))) { // fichier existe pas mais déclaré: on l'a effacé
FILE* fp=FOPEN(fconv(catbuff,save),"wb");
if (fp) fclose(fp);
- if (opt->log!=NULL) {
- HTS_LOG(opt,LOG_WARNING); fprintf(opt->log,"Previous file '%s' not found (erased by user ?), ignoring: %s%s"LF,save,back[p].url_adr,back[p].url_fil); test_flush;
- }
+ hts_log_print(opt, LOG_WARNING, "Previous file '%s' not found (erased by user ?), ignoring: %s%s",save,back[p].url_adr,back[p].url_fil);
}
} else {
- if (opt->log!=NULL) {
- HTS_LOG(opt,LOG_WARNING); fprintf(opt->log,"Previous file '%s' not found (erased by user ?), recatching: %s%s"LF,save,back[p].url_adr,back[p].url_fil); test_flush;
- }
+ hts_log_print(opt, LOG_WARNING, "Previous file '%s' not found (erased by user ?), recatching: %s%s",save,back[p].url_adr,back[p].url_fil);
}
}
} // fsize() <= 0
@@ -1593,12 +1516,10 @@ int back_add(struct_back* sback,httrackp* opt,cache_back* cache,char* adr,char*
}
if (back[p].r.statuscode != -1 || IS_DELAYED_EXT(save)) { // pas d'erreur de lecture ou test retardé
- if ((opt->debug>0) && (opt->log!=NULL)) {
- if (!test) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"File immediately loaded from cache: %s%s"LF,back[p].url_adr,back[p].url_fil); test_flush;
- } else {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"File immediately tested from cache: %s%s"LF,back[p].url_adr,back[p].url_fil); test_flush;
- }
+ if (!test) {
+ hts_log_print(opt, LOG_DEBUG, "File immediately loaded from cache: %s%s",back[p].url_adr,back[p].url_fil);
+ } else {
+ hts_log_print(opt, LOG_DEBUG, "File immediately tested from cache: %s%s",back[p].url_adr,back[p].url_fil);
}
back[p].r.notmodified=1; // fichier non modifié
back[p].status=STATUS_READY; // OK prêt
@@ -1723,9 +1644,7 @@ int back_add(struct_back* sback,httrackp* opt,cache_back* cache,char* adr,char*
#if DEBUGCA
printf("..if unmodified since %s size "LLintP"\n", lastmodified, (LLint)sz);
#endif
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"File partially present ("LLintP" bytes): %s%s"LF,(LLint)sz,back[p].url_adr,back[p].url_fil); test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "File partially present ("LLintP" bytes): %s%s",(LLint)sz,back[p].url_adr,back[p].url_fil);
/* impossible - don't have etag or date
if (strnotempty(back[p].r.etag)) { // ETag (RFC2616)
@@ -1746,22 +1665,11 @@ int back_add(struct_back* sback,httrackp* opt,cache_back* cache,char* adr,char*
back[p].r.req.range_used=1;
back[p].r.req.nocompression=1;
} else {
- if ((opt->debug>0) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_WARNING); fprintf(opt->log,"Could not find timestamp for partially present file, restarting (lost "LLintP" bytes): %s%s"LF,(LLint)sz,back[p].url_adr,back[p].url_fil); test_flush;
- }
+ hts_log_print(opt, LOG_WARNING, "Could not find timestamp for partially present file, restarting (lost "LLintP" bytes): %s%s",(LLint)sz,back[p].url_adr,back[p].url_fil);
}
} else {
- if ((opt->debug>0) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_WARNING);
- /*
- if (opt->http10)
- fprintf(opt->log,"File partially present (%d bytes) retransfered due to HTTP/1.0 settings: %s%s"LF,sz,back[p].url_adr,back[p].url_fil);
- else
- */
- fprintf(opt->log,"File partially present ("LLintP" bytes) retransfered due to lack of cache: %s%s"LF,(LLint)sz,back[p].url_adr,back[p].url_fil);
- test_flush;
- }
+ hts_log_print(opt, LOG_NOTICE, "File partially present ("LLintP" bytes) retransfered due to lack of cache: %s%s",(LLint)sz,back[p].url_adr,back[p].url_fil);
/* Sinon requête normale... */
back[p].http11=0;
}
@@ -1775,11 +1683,7 @@ int back_add(struct_back* sback,httrackp* opt,cache_back* cache,char* adr,char*
return 0;
}
} else {
- if ((opt->debug>0) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_WARNING);
- fprintf(opt->log,"HTML file ("LLintP" bytes) retransfered due to lack of cache: %s%s"LF,(LLint)sz,back[p].url_adr,back[p].url_fil);
- test_flush;
- }
+ hts_log_print(opt, LOG_NOTICE, "HTML file ("LLintP" bytes) retransfered due to lack of cache: %s%s",(LLint)sz,back[p].url_adr,back[p].url_fil);
/* Sinon requête normale... */
back[p].http11=0;
}
@@ -1792,9 +1696,7 @@ int back_add(struct_back* sback,httrackp* opt,cache_back* cache,char* adr,char*
strcpybuff(back[p].r.msg,"mirror stopped by user");
back[p].status=STATUS_READY; // terminé
back_set_finished(sback, p);
- if ((opt->debug>0) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_WARNING); fprintf(opt->log,"File not added due to mirror cancel: %s%s"LF,adr,fil); test_flush;
- }
+ hts_log_print(opt, LOG_WARNING, "File not added due to mirror cancel: %s%s",adr,fil);
return 0;
}
@@ -1829,9 +1731,7 @@ int back_add(struct_back* sback,httrackp* opt,cache_back* cache,char* adr,char*
// mode ftp, court-circuit!
if (strfield(back[p].url_adr,"ftp://")) {
if (back[p].testmode) {
- if (opt->log!=NULL) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"error: forbidden test with ftp link for back_add"LF);
- }
+ hts_log_print(opt, LOG_DEBUG, "error: forbidden test with ftp link for back_add");
return -1; // erreur pas de test permis
}
if (!(back[p].r.req.proxy.active && opt->ftp_proxy)) { // connexion directe, gérée en thread
@@ -1852,13 +1752,11 @@ int back_add(struct_back* sback,httrackp* opt,cache_back* cache,char* adr,char*
else if (strfield(back[p].url_adr,"mms://")) {
MMSDownloadStruct str;
if (back[p].testmode) {
- if (opt->log!=NULL) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"error: forbidden test with mms link for back_add"LF);
- }
+ hts_log_print(opt, LOG_DEBUG, "error: forbidden test with mms link for back_add");
return -1; // erreur pas de test permis
}
if (back[p].r.req.proxy.active) {
- HTS_LOG(opt,LOG_WARNING); fprintf(opt->log,"warning: direct connection for mms links (proxy settings ignored)"LF);
+ hts_log_print(opt, LOG_WARNING, "warning: direct connection for mms links (proxy settings ignored)");
}
back[p].status=STATUS_FTP_TRANSFER; // connexion externe
str.pBack = &back[p];
@@ -1916,11 +1814,9 @@ int back_add(struct_back* sback,httrackp* opt,cache_back* cache,char* adr,char*
} else {
soc = back[p].r.soc;
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"(Keep-Alive): successfully linked #%d (for %s%s)"LF,
- back[p].r.debugid,
- back[p].url_adr, back[p].url_fil); test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "(Keep-Alive): successfully linked #%d (for %s%s)",
+ back[p].r.debugid,
+ back[p].url_adr, back[p].url_fil);
}
if (opt->timeout>0) { // gestion du opt->timeout
@@ -1986,10 +1882,10 @@ printf("Xfopen ok, poll..\n");
return 0;
} else {
if (opt->log!=NULL) {
- HTS_LOG(opt,LOG_WARNING); fprintf(opt->log,"error: no space left in stack for back_add"LF);
+ hts_log_print(opt, LOG_WARNING, "error: no space left in stack for back_add");
if ( ( opt->state.debug_state & 1 ) == 0 ) { /* debug_state<0> == debug 'no space left in stack' */
int i;
- HTS_LOG(opt,LOG_WARNING); fprintf(opt->log,"debug: DUMPING %d BLOCKS"LF, back_max);
+ hts_log_print(opt, LOG_WARNING, "debug: DUMPING %d BLOCKS", back_max);
opt->state.debug_state |= 1; /* once */
/* OUTPUT FULL DEBUG INFORMATION THE FIRST TIME WE SEE THIS VERY ANNOYING BUG,
HOPING THAT SOME USER REPORT WILL QUICKLY SOLVE THIS PROBLEM :p */
@@ -1998,12 +1894,11 @@ printf("Xfopen ok, poll..\n");
int may_clean = slot_can_be_cleaned(&back[i]);
int may_finalize = may_clean && slot_can_be_finalized(opt, &back[i]);
int may_serialize = slot_can_be_cached_on_disk(&back[i]);
- HTS_LOG(opt,LOG_INFO);
- fprintf(opt->log,
- "debug: back[%03d]: may_clean=%d, may_finalize_disk=%d, may_serialize=%d:"LF
+ hts_log_print(opt, LOG_DEBUG,
+ "back[%03d]: may_clean=%d, may_finalize_disk=%d, may_serialize=%d:"LF
"\t" "finalized(%d), status(%d), locked(%d), delayed(%d), test(%d), "LF
"\t" "statuscode(%d), size(%d), is_write(%d), may_hypertext(%d), "LF
- "\t" "contenttype(%s), url(%s%s), save(%s)"LF,
+ "\t" "contenttype(%s), url(%s%s), save(%s)",
i,
may_clean, may_finalize, may_serialize,
back[i].finalized,
@@ -2222,25 +2117,18 @@ void back_clean(httrackp* opt,cache_back* cache,struct_back* sback) {
if (index >= 0) {
opt->hash->liens[index]->pass2 = -1; /* DONE! */
} else {
- if (opt->log != NULL) {
- HTS_LOG(opt,LOG_INFO); fprintf(opt->log,"engine: warning: entry cleaned up, but no trace on heap: %s%s (%s)"LF,back[i].url_adr, back[i].url_fil,back[i].url_sav);
- test_flush;
- }
+ hts_log_print(opt, LOG_INFO, "engine: warning: entry cleaned up, but no trace on heap: %s%s (%s)",back[i].url_adr, back[i].url_fil,back[i].url_sav);
}
}
HTS_STAT.stat_background++;
- if ((opt->debug>0) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_INFO); fprintf(opt->log,"File successfully written in background: %s"LF,back[i].url_sav); test_flush;
- }
+ hts_log_print(opt, LOG_INFO, "File successfully written in background: %s",back[i].url_sav);
back_maydelete(opt,cache,sback,i); // May delete backing entry
} else {
if (!back[i].finalized) {
if (1) {
/* Ensure deleted or recycled socket */
/* BUT DO NOT YET WIPE back[i].r.adr */
- if ( (opt->debug>1) && (opt->log!=NULL) ) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"file %s%s validated (cached, left in memory)"LF,back[i].url_adr,back[i].url_fil); test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "file %s%s validated (cached, left in memory)",back[i].url_adr,back[i].url_fil);
back_maydeletehttp(opt, cache, sback, i);
} else {
/*
@@ -2261,14 +2149,10 @@ void back_clean(httrackp* opt,cache_back* cache,struct_back* sback) {
/* Delete buffer and sockets */
deleteaddr(&back[i].r);
deletehttp(&back[i].r);
- if ( (opt->debug>1) && (opt->log!=NULL) ) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"file %s%s temporarily left in cache to spare memory"LF,back[i].url_adr,back[i].url_fil); test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "file %s%s temporarily left in cache to spare memory",back[i].url_adr,back[i].url_fil);
}
} else {
- if ((opt->debug>0) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_WARNING); fprintf(opt->log,"Unexpected html cache lookup error during back clean"LF); test_flush;
- }
+ hts_log_print(opt, LOG_WARNING, "Unexpected html cache lookup error during back clean");
}
// xxc xxc
}
@@ -2282,12 +2166,9 @@ void back_clean(httrackp* opt,cache_back* cache,struct_back* sback) {
|| back[i].r.keep_alive_max < 1
|| time_local() >= back[i].ka_time_start + back[i].r.keep_alive_t
) {
- if ((opt->debug>0) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"(Keep-Alive): live socket closed #%d (%s)"LF,
+ hts_log_print(opt, LOG_DEBUG, "(Keep-Alive): live socket closed #%d (%s)",
back[i].r.debugid,
back[i].url_adr);
- test_flush;
- }
back_delete(opt,cache,sback, i); // delete backing entry
}
}
@@ -2305,10 +2186,8 @@ void back_clean(httrackp* opt,cache_back* cache,struct_back* sback) {
int max = opt->maxsoc + oneMore;
int curr = back_nsoc_overall(sback);
if (curr > max) {
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"(Keep-Alive): deleting #%d sockets"LF,
- curr - max); test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "(Keep-Alive): deleting #%d sockets",
+ curr - max);
}
for(i = 0 ; i < back_max && curr > max ; i++) {
if (back[i].status == STATUS_ALIVE) {
@@ -2320,9 +2199,8 @@ void back_clean(httrackp* opt,cache_back* cache,struct_back* sback) {
/* transfer ready slots to the storage hashtable */
{
int nxfr = back_cleanup_background(opt,cache,sback);
- if (nxfr > 0 && (opt->debug>0) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"(htsback): %d slots ready moved to background"LF, nxfr);
- test_flush;
+ if (nxfr > 0) {
+ hts_log_print(opt, LOG_DEBUG, "(htsback): %d slots ready moved to background", nxfr);
}
}
}
@@ -2447,9 +2325,7 @@ void back_wait(struct_back* sback,httrackp* opt,cache_back* cache,TStamp stat_ti
strcpybuff(back[i].r.msg,"Receive Error");
back[i].status=STATUS_READY; // terminé
back_set_finished(sback, i);
- if ((opt->debug>0) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_WARNING); fprintf(opt->log,"Unexpected socket error during pre-loop"LF); test_flush;
- }
+ hts_log_print(opt, LOG_WARNING, "Unexpected socket error during pre-loop");
}
}
@@ -2805,26 +2681,19 @@ void back_wait(struct_back* sback,httrackp* opt,cache_back* cache,TStamp stat_ti
if (back[i].r.out==NULL) {
errno = last_errno;
if ((fcheck=check_fatal_io_errno())) {
- HTS_LOG(opt,LOG_ERROR); fprintf(opt->log,"Mirror aborted: disk full or filesystem problems"LF); test_flush;
+ hts_log_print(opt, LOG_ERROR, "Mirror aborted: disk full or filesystem problems");
opt->state.exit_xh=-1; /* fatal error */
}
}
#if HDEBUG
printf("direct-disk: %s\n",back[i].url_sav);
#endif
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"File received from net to disk: %s%s"LF,back[i].url_adr,back[i].url_fil); test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "File received from net to disk: %s%s",back[i].url_adr,back[i].url_fil);
if (back[i].r.out==NULL) {
- if (opt->log) {
- HTS_LOG(opt,LOG_ERROR);
- fprintf(opt->log,"Unable to save file %s : %s"LF,back[i].url_sav, strerror(last_errno));
- if (fcheck) {
- HTS_LOG(opt,LOG_ERROR);
- fprintf(opt->log,"* * Fatal write error, giving up"LF);
- }
- test_flush;
+ hts_log_print(opt, LOG_ERROR | LOG_ERRNO, "Unable to save file %s",back[i].url_sav);
+ if (fcheck) {
+ hts_log_print(opt, LOG_ERROR, "* * Fatal write error, giving up");
}
back[i].r.is_write=0; // erreur, abandonner
} else {
@@ -2834,16 +2703,12 @@ void back_wait(struct_back* sback,httrackp* opt,cache_back* cache,TStamp stat_ti
/* create a temporary reference file in case of broken mirror */
if (back[i].r.out != NULL) {
if (back_serialize_ref(opt, &back[i]) != 0) {
- if (opt->log != NULL) {
- HTS_LOG(opt,LOG_WARNING); fprintf(opt->log, "Could not create temporary reference file for %s%s"LF,back[i].url_adr,back[i].url_fil); test_flush;
- }
+ hts_log_print(opt, LOG_WARNING, "Could not create temporary reference file for %s%s",back[i].url_adr,back[i].url_fil);
}
}
}
} else { // on coupe tout!
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"File cancelled (non HTML): %s%s"LF,back[i].url_adr,back[i].url_fil); test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "File cancelled (non HTML): %s%s",back[i].url_adr,back[i].url_fil);
back[i].status=STATUS_READY; // terminé
back_set_finished(sback, i);
if (!back[i].testmode)
@@ -2977,9 +2842,7 @@ void back_wait(struct_back* sback,httrackp* opt,cache_back* cache,TStamp stat_ti
} else {
//#else
// Un warning suffira..
- if (cache->log!=NULL) {
- fspc(opt,cache->log,"warning"); fprintf(cache->log,"Incorrect length ("LLintP"!="LLintP" expected) for %s%s"LF,(LLint)back[i].r.size,(LLint)back[i].r.totalsize,back[i].url_adr,back[i].url_fil);
- }
+ hts_log_print(opt, LOG_WARNING, "Incorrect length ("LLintP"!="LLintP" expected) for %s%s",(LLint)back[i].r.size,(LLint)back[i].r.totalsize,back[i].url_adr,back[i].url_fil);
//#endif
}
}
@@ -3024,7 +2887,7 @@ void back_wait(struct_back* sback,httrackp* opt,cache_back* cache,TStamp stat_ti
back[i].r.adr=(char*) realloct(back[i].r.adr, (size_t)back[i].r.totalsize + 1);
if (!back[i].r.adr) {
if (cache->log!=NULL) {
- fprintf(cache->log,"Error: Not enough memory ("LLintP") for %s%s"LF,(LLint)back[i].r.totalsize,back[i].url_adr,back[i].url_fil);
+ hts_log_print(opt, LOG_ERROR, "not enough memory ("LLintP") for %s%s",(LLint)back[i].r.totalsize,back[i].url_adr,back[i].url_fil);
}
}
}
@@ -3032,9 +2895,7 @@ void back_wait(struct_back* sback,httrackp* opt,cache_back* cache,TStamp stat_ti
printf("[%d] chunk length: %d - next total "LLintP":\n",(int)back[i].r.soc,(int)chunk_size,(LLint)back[i].r.totalsize);
#endif
} else {
- if (cache->log!=NULL) {
- fprintf(cache->log,"Warning: Illegal chunk (%s) for %s%s"LF,back[i].chunk_adr,back[i].url_adr,back[i].url_fil);
- }
+ hts_log_print(opt, LOG_WARNING, "Illegal chunk (%s) for %s%s",back[i].chunk_adr,back[i].url_adr,back[i].url_fil);
}
} else { /* back[i].status==STATUS_CHUNK_CR : just receiving ending CRLF after data */
if (chunk_data[0] == '\0') {
@@ -3048,18 +2909,14 @@ void back_wait(struct_back* sback,httrackp* opt,cache_back* cache,TStamp stat_ti
printf("[%d] chunk CRLF seen\n", (int)back[i].r.soc);
#endif
} else {
- if (cache->log!=NULL) {
- fprintf(cache->log,"Warning: Illegal chunk CRLF (%s) for %s%s"LF,back[i].chunk_adr,back[i].url_adr,back[i].url_fil);
- }
+ hts_log_print(opt, LOG_WARNING, "illegal chunk CRLF (%s) for %s%s", back[i].chunk_adr,back[i].url_adr,back[i].url_fil);
#if CHUNKDEBUG==1
printf("[%d] chunk CRLF ERROR!! : '%s'\n", (int)back[i].r.soc, chunk_data);
#endif
}
}
} else {
- if (cache->log!=NULL) {
- fprintf(cache->log,"Warning: Chunk too big ("LLintP") for %s%s"LF,(LLint)back[i].chunk_size,back[i].url_adr,back[i].url_fil);
- }
+ hts_log_print(opt, LOG_WARNING, "chunk too big ("LLintP") for %s%s",(LLint)back[i].chunk_size,back[i].url_adr,back[i].url_fil);
}
// ok, continuer sur le body
@@ -3095,9 +2952,7 @@ void back_wait(struct_back* sback,httrackp* opt,cache_back* cache,TStamp stat_ti
back_finalize(opt,cache,sback,i);
} else {
if (back[i].r.statuscode == HTTP_OK) {
- if (cache->log!=NULL) {
- fspc(opt,cache->log,"warning"); fprintf(cache->log,"Unexpected incomplete type with 200 code at %s%s"LF, back[i].url_adr, back[i].url_fil);
- }
+ hts_log_print(opt, LOG_WARNING, "unexpected incomplete type with 200 code at %s%s", back[i].url_adr, back[i].url_fil);
}
}
if (back[i].r.soc!=INVALID_SOCKET) {
@@ -3127,9 +2982,7 @@ void back_wait(struct_back* sback,httrackp* opt,cache_back* cache,TStamp stat_ti
strcpybuff(back[i].r.msg,"Incorrect length");
} else {
// Un warning suffira..
- if (cache->log!=NULL) {
- fspc(opt,cache->log,"warning"); fprintf(cache->log,"Incorrect length ("LLintP"!="LLintP" expected) for %s%s"LF,(LLint)back[i].r.size,(LLint)back[i].r.totalsize,back[i].url_adr,back[i].url_fil);
- }
+ hts_log_print(opt, LOG_WARNING, "Incorrect length ("LLintP"!="LLintP" expected) for %s%s",(LLint)back[i].r.size,(LLint)back[i].r.totalsize,back[i].url_adr,back[i].url_fil);
}
}
}
@@ -3242,9 +3095,7 @@ void back_wait(struct_back* sback,httrackp* opt,cache_back* cache,TStamp stat_ti
int test_head = RUN_CALLBACK6(opt, receivehead,
back[i].r.adr, back[i].url_adr, back[i].url_fil, back[i].referer_adr, back[i].referer_fil, &back[i].r);
if (test_head!=1) {
- if ((opt->debug>0) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_WARNING); fprintf(opt->log,"External wrapper aborted transfer, breaking connection: %s%s"LF,back[i].url_adr,back[i].url_fil); test_flush;
- }
+ hts_log_print(opt, LOG_WARNING, "External wrapper aborted transfer, breaking connection: %s%s",back[i].url_adr,back[i].url_fil);
back[i].status=STATUS_READY; // FINI
back_set_finished(sback, i);
deletehttp(&back[i].r); back[i].r.soc=INVALID_SOCKET;
@@ -3277,9 +3128,7 @@ void back_wait(struct_back* sback,httrackp* opt,cache_back* cache,TStamp stat_ti
back[i].chunk_size=0;
back[i].r.statuscode=STATUSCODE_INVALID;
back[i].r.msg[0]='\0';
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"Status 100 detected for %s%s, continuing headers"LF,back[i].url_adr,back[i].url_fil); test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "Status 100 detected for %s%s, continuing headers",back[i].url_adr,back[i].url_fil);
continue;
}
@@ -3299,9 +3148,7 @@ void back_wait(struct_back* sback,httrackp* opt,cache_back* cache,TStamp stat_ti
back_set_finished(sback, i);
back[i].r.size=back[i].r.totalsize=back[i].range_req_size;
back[i].r.statuscode=HTTP_NOT_MODIFIED; // NOT MODIFIED
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"File seems complete (good 416 message), breaking connection: %s%s"LF,back[i].url_adr,back[i].url_fil); test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "File seems complete (good 416 message), breaking connection: %s%s",back[i].url_adr,back[i].url_fil);
}
}
@@ -3316,9 +3163,7 @@ void back_wait(struct_back* sback,httrackp* opt,cache_back* cache,TStamp stat_ti
if (!opt->delete_old) {
if (HTTP_IS_ERROR(back[i].r.statuscode) && back[i].is_update && !back[i].testmode) {
if (back[i].url_sav[0] && fexist_utf8(back[i].url_sav)) {
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"Error ignored %d (%s) because of 'no purge' option for %s%s"LF,back[i].r.statuscode,back[i].r.msg,back[i].url_adr,back[i].url_fil); test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "Error ignored %d (%s) because of 'no purge' option for %s%s",back[i].r.statuscode,back[i].r.msg,back[i].url_adr,back[i].url_fil);
back[i].r.statuscode = HTTP_NOT_MODIFIED;
deletehttp(&back[i].r); back[i].r.soc=INVALID_SOCKET;
}
@@ -3348,15 +3193,11 @@ void back_wait(struct_back* sback,httrackp* opt,cache_back* cache,TStamp stat_ti
if (len1 == len2) { // tailles identiques
back[i].r.statuscode=HTTP_NOT_MODIFIED; // forcer NOT MODIFIED
deletehttp(&back[i].r); back[i].r.soc=INVALID_SOCKET;
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"File seems complete (same size), breaking connection: %s%s"LF,back[i].url_adr,back[i].url_fil); test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "File seems complete (same size), breaking connection: %s%s",back[i].url_adr,back[i].url_fil);
}
}
} else {
- if (opt->log!=NULL) {
- HTS_LOG(opt,LOG_WARNING); fprintf(opt->log,"File seems complete (same size), but there was a cache read error (%u): %s%s"LF, r.statuscode, back[i].url_adr, back[i].url_fil); test_flush;
- }
+ hts_log_print(opt, LOG_WARNING, "File seems complete (same size), but there was a cache read error (%u): %s%s", r.statuscode, back[i].url_adr, back[i].url_fil);
}
if (r.adr) {
freet(r.adr);
@@ -3383,9 +3224,7 @@ void back_wait(struct_back* sback,httrackp* opt,cache_back* cache,TStamp stat_ti
filenote(&opt->state.strc,back[i].url_sav,NULL);
file_notify(opt,back[i].url_adr, back[i].url_fil, back[i].url_sav, 0, 0, back[i].r.notmodified);
back[i].r.statuscode=HTTP_NOT_MODIFIED; // NOT MODIFIED
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"File seems complete (same size file discovered), breaking connection: %s%s"LF,back[i].url_adr,back[i].url_fil); test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "File seems complete (same size file discovered), breaking connection: %s%s",back[i].url_adr,back[i].url_fil);
}
}
}
@@ -3421,9 +3260,7 @@ void back_wait(struct_back* sback,httrackp* opt,cache_back* cache,TStamp stat_ti
filenote(&opt->state.strc,back[i].url_sav,NULL);
file_notify(opt,back[i].url_adr, back[i].url_fil, back[i].url_sav, 0, 0, back[i].r.notmodified);
back[i].r.statuscode=HTTP_NOT_MODIFIED; // NOT MODIFIED
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"File seems complete (reget failed), breaking connection: %s%s"LF,back[i].url_adr,back[i].url_fil); test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "File seems complete (reget failed), breaking connection: %s%s",back[i].url_adr,back[i].url_fil);
}
}
}
@@ -3462,9 +3299,7 @@ void back_wait(struct_back* sback,httrackp* opt,cache_back* cache,TStamp stat_ti
/* if (back[i].r.soc!=INVALID_SOCKET) { // ok récupérer body? */
// head: terminé
if (back[i].head_request) {
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"Tested file: %s%s"LF,back[i].url_adr,back[i].url_fil); test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "Tested file: %s%s",back[i].url_adr,back[i].url_fil);
#if HTS_DEBUG_CLOSESOCK
DEBUG_W("back_wait(head request): deletehttp\n");
#endif
@@ -3502,9 +3337,7 @@ void back_wait(struct_back* sback,httrackp* opt,cache_back* cache,TStamp stat_ti
back[i].r.is_file=1;
back[i].r.totalsize = back[i].r.size = fsize_utf8(back[i].url_sav);
get_httptype(opt,back[i].r.contenttype, back[i].url_sav, 1);
- if ((opt->debug>0) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"Not-modified status without cache guessed: %s%s"LF,back[i].url_adr,back[i].url_fil); test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "Not-modified status without cache guessed: %s%s",back[i].url_adr,back[i].url_fil);
}
}
@@ -3513,9 +3346,7 @@ void back_wait(struct_back* sback,httrackp* opt,cache_back* cache,TStamp stat_ti
back[i].status=STATUS_READY; // OK prêt
back_set_finished(sback, i);
back[i].r.notmodified=1; // NON modifié!
- if ((opt->debug>0) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"File loaded after test from cache: %s%s"LF,back[i].url_adr,back[i].url_fil); test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "File loaded after test from cache: %s%s",back[i].url_adr,back[i].url_fil);
// finalize
//file_notify(back[i].url_adr, back[i].url_fil, back[i].url_sav, 0, 0, back[i].r.notmodified); // not modified
@@ -3586,9 +3417,7 @@ void back_wait(struct_back* sback,httrackp* opt,cache_back* cache,TStamp stat_ti
fseek(back[i].r.out,0,SEEK_END); // à la fin
/* create a temporary reference file in case of broken mirror */
if (back_serialize_ref(opt, &back[i]) != 0) {
- if (opt->log != NULL) {
- HTS_LOG(opt,LOG_WARNING); fprintf(opt->log, "Could not create temporary reference file for %s%s"LF,back[i].url_adr,back[i].url_fil); test_flush;
- }
+ hts_log_print(opt, LOG_WARNING, "Could not create temporary reference file for %s%s",back[i].url_adr,back[i].url_fil);
}
#if HDEBUG
printf("continue interrupted file\n");
@@ -3833,10 +3662,7 @@ int back_checkmirror(httrackp* opt) {
// Check max size
if ((opt->maxsite>0) && (HTS_STAT.stat_bytes >= opt->maxsite)) {
if (!opt->state.stop) { /* not yet stopped */
- if (opt->log) {
- fprintf(opt->log,"More than "LLintP" bytes have been transfered.. giving up"LF,(LLint)opt->maxsite);
- test_flush;
- }
+ hts_log_print(opt, LOG_ERROR, "More than "LLintP" bytes have been transfered.. giving up",(LLint)opt->maxsite);
/* cancel mirror smoothly */
hts_request_stop(opt, 0);
}
@@ -3847,10 +3673,7 @@ int back_checkmirror(httrackp* opt) {
// Check max time
if ((opt->maxtime>0) && ((time_local()-HTS_STAT.stat_timestart)>opt->maxtime)) {
if (!opt->state.stop) { /* not yet stopped */
- if (opt->log) {
- fprintf(opt->log,"More than %d seconds passed.. giving up"LF,opt->maxtime);
- test_flush;
- }
+ hts_log_print(opt, LOG_ERROR, "More than %d seconds passed.. giving up",opt->maxtime);
/* cancel mirror smoothly */
hts_request_stop(opt, 0);
}
@@ -3983,5 +3806,3 @@ void back_infostr(struct_back* sback,int i,int j,char* s) {
}
// -- backing --
-
-#undef test_flush
diff --git a/src/htsbase.h b/src/htsbase.h
index e144991..ef01eba 100644
--- a/src/htsbase.h
+++ b/src/htsbase.h
@@ -71,9 +71,11 @@ extern "C" {
#ifdef __GNUC__
#define HTS_UNUSED __attribute__ ((unused))
#define HTS_STATIC static __attribute__ ((unused))
+#define HTS_PRINTF_FUN(fmt, arg) __attribute__ ((format (printf, fmt, arg)))
#else
#define HTS_UNUSED
#define HTS_STATIC static
+#define HTS_PRINTF_FUN(fmt, arg)
#endif
#endif
@@ -156,36 +158,6 @@ extern HTSEXT_API t_abortLog abortLog__;
} \
} while(0)
-/* logging */
-typedef enum {
- LOG_DEBUG,
- LOG_INFO,
- LOG_WARNING,
- LOG_ERROR,
- LOG_PANIC
-} HTS_LogType;
-#define HTS_LOG(OPT,TYPE) do { \
- int last_errno = errno; \
- switch(TYPE) { \
- case LOG_DEBUG: \
- fspc(OPT,(OPT)->log, "debug"); \
- break; \
- case LOG_INFO: \
- fspc(OPT,(OPT)->log, "info"); \
- break; \
- case LOG_WARNING: \
- fspc(OPT,(OPT)->log, "warning"); \
- break; \
- case LOG_ERROR: \
- fspc(OPT,(OPT)->log, "error"); \
- break; \
- case LOG_PANIC: \
- fspc(OPT,(OPT)->log, "panic"); \
- break; \
- } \
- errno = last_errno; \
-} while(0)
-
/* regular malloc's() */
#ifndef HTS_TRACE_MALLOC
#define malloct(A) malloc(A)
diff --git a/src/htscache.c b/src/htscache.c
index fc8a5b8..07e2cf7 100644
--- a/src/htscache.c
+++ b/src/htscache.c
@@ -49,9 +49,6 @@ Please visit our Website: http://www.httrack.com
#include "htszlib.h"
/* END specific definitions */
-#undef test_flush
-#define test_flush if (opt->flush) { fflush(opt->log); fflush(opt->log); }
-
// routines de mise en cache
/*
@@ -111,18 +108,14 @@ with
void cache_mayadd(httrackp* opt,cache_back* cache,htsblk* r,const char* url_adr,const char* url_fil,const char* url_save) {
- if ((opt->debug>0) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"File checked by cache: %s"LF,url_adr);
- }
+ hts_log_print(opt, LOG_DEBUG, "File checked by cache: %s",url_adr);
// ---stockage en cache---
// stocker dans le cache?
if (opt->cache) {
if (cache_writable(cache)) {
// ensure not a temporary filename (should not happend ?!)
if (IS_DELAYED_EXT(url_save)) {
- if (opt->log!=NULL) {
- HTS_LOG(opt,LOG_WARNING); fprintf(opt->log, "aborted cache validation: %s%s still has temporary name %s"LF, url_adr, url_fil, url_save);
- }
+ hts_log_print(opt, LOG_WARNING, "aborted cache validation: %s%s still has temporary name %s", url_adr, url_fil, url_save);
return ;
}
@@ -161,9 +154,7 @@ void cache_mayadd(httrackp* opt,cache_back* cache,htsblk* r,const char* url_adr,
strcatbuff(tempo, "\n");
strcatbuff(tempo, r->location);
}
- if ((opt->debug>0) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log, "Cached fast-header response: %s%s is %d"LF, url_adr, url_fil, (int)r->statuscode);
- }
+ hts_log_print(opt, LOG_DEBUG, "Cached fast-header response: %s%s is %d", url_adr, url_fil, (int)r->statuscode);
inthash_add(cache->cached_tests, concat(OPT_GET_BUFF(opt), url_adr, url_fil), (intptr_t)strdupt(tempo));
}
}
@@ -709,9 +700,7 @@ static htsblk cache_readex_new(httrackp* opt,cache_back* cache,const char* adr,c
if (!dataincache) { /* Data are supposed to be on disk */
if (!fexist_utf8(fconv(catbuff, previous_save))) { // un fichier existe déja
if (!opt->norecatch) {
- if ((opt->debug>0) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"Cache: could not find %s"LF, previous_save);
- }
+ hts_log_print(opt, LOG_DEBUG, "Cache: could not find %s", previous_save);
r.statuscode=STATUSCODE_INVALID;
strcpybuff(r.msg, "Previous cache file not found");
}
@@ -748,16 +737,14 @@ static htsblk cache_readex_new(httrackp* opt,cache_back* cache,const char* adr,c
// So far so good
ok=1; // plus rien à faire
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log, "File '%s' has been renamed since last mirror to '%s' ; applying changes"LF, previous_save, target_save); test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "File '%s' has been renamed since last mirror to '%s' ; applying changes", previous_save, target_save);
} else {
r.statuscode=STATUSCODE_INVALID;
strcpybuff(r.msg, "Unable to rename file on disk");
}
}
} else {
- HTS_LOG(opt,LOG_WARNING); fprintf(opt->log, "warning: file size on disk ("LLintP") does not have the expected size ("LLintP"))"LF, (LLint) fsize, (LLint) r.size);
+ hts_log_print(opt, LOG_WARNING, "warning: file size on disk ("LLintP") does not have the expected size ("LLintP"))", (LLint) fsize, (LLint) r.size);
}
}
// File exists with the target name and not previous one ?
@@ -769,7 +756,7 @@ static htsblk cache_readex_new(httrackp* opt,cache_back* cache,const char* adr,c
// So far so good
ok=1; // plus rien à faire
} else {
- HTS_LOG(opt,LOG_WARNING); fprintf(opt->log, "warning: renamed file size on disk ("LLintP") does not have the expected size ("LLintP"))"LF, (LLint) fsize, (LLint) r.size);
+ hts_log_print(opt, LOG_WARNING, "warning: renamed file size on disk ("LLintP") does not have the expected size ("LLintP"))", (LLint) fsize, (LLint) r.size);
}
}
@@ -1278,9 +1265,7 @@ int cache_readdata(cache_back* cache,const char* str1,const char* str2,char** in
}
static int hts_rename(httrackp* opt, const char *a, const char *b) {
- if ((opt->debug>0) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"Cache: rename %s -> %s (%p %p)"LF, a, b, a, b);
- }
+ hts_log_print(opt, LOG_DEBUG, "Cache: rename %s -> %s (%p %p)", a, b, a, b);
return rename(a, b);
}
@@ -1299,9 +1284,7 @@ htsblk* cache_header(httrackp* opt,cache_back* cache,const char* adr,const char*
void cache_init(cache_back* cache,httrackp* opt) {
// ---
// utilisation du cache: renommer ancien éventuel et charger index
- if ((opt->debug>0) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"Cache: enabled=%d, base=%s, ro=%d"LF, (int) opt->cache, fconcat(OPT_GET_BUFF(opt), StringBuff(opt->path_log),"hts-cache/"), (int) cache->ro);
- }
+ hts_log_print(opt, LOG_DEBUG, "Cache: enabled=%d, base=%s, ro=%d", (int) opt->cache, fconcat(OPT_GET_BUFF(opt), StringBuff(opt->path_log),"hts-cache/"), (int) cache->ro);
if (opt->cache) {
#if DEBUGCA
printf("cache init: ");
@@ -1330,23 +1313,15 @@ void cache_init(cache_back* cache,httrackp* opt) {
/* Remove OLD cache */
if (fexist(fconcat(OPT_GET_BUFF(opt), StringBuff(opt->path_log),"hts-cache/old.zip"))) {
if (remove(fconcat(OPT_GET_BUFF(opt), StringBuff(opt->path_log),"hts-cache/old.zip")) != 0) {
- int last_errno = errno;
- if (opt->log!=NULL) {
- HTS_LOG(opt,LOG_WARNING); fprintf(opt->log,"Cache: error while moving previous cache: %s"LF, strerror(last_errno));
- }
+ hts_log_print(opt, LOG_WARNING | LOG_ERRNO, "Cache: error while moving previous cache");
}
}
/* Rename */
if (hts_rename(opt, fconcat(OPT_GET_BUFF(opt), StringBuff(opt->path_log),"hts-cache/new.zip"), fconcat(OPT_GET_BUFF(opt), StringBuff(opt->path_log),"hts-cache/old.zip")) != 0) {
- int last_errno = errno;
- if (opt->log!=NULL) {
- HTS_LOG(opt,LOG_WARNING); fprintf(opt->log,"Cache: error while moving previous cache: %s"LF, strerror(last_errno));
- }
+ hts_log_print(opt, LOG_WARNING | LOG_ERRNO, "Cache: error while moving previous cache");
} else {
- if ((opt->debug>0) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"Cache: successfully renamed"LF);
- }
+ hts_log_print(opt, LOG_DEBUG, "Cache: successfully renamed");
}
}
else if ((fexist(fconcat(OPT_GET_BUFF(opt), StringBuff(opt->path_log),"hts-cache/new.dat"))) && (fexist(fconcat(OPT_GET_BUFF(opt), StringBuff(opt->path_log),"hts-cache/new.ndx")))) { // il existe déja un cache précédent.. renommer
@@ -1370,13 +1345,9 @@ void cache_init(cache_back* cache,httrackp* opt) {
remove(fconcat(OPT_GET_BUFF(opt), StringBuff(opt->path_log),"hts-cache/new.ndx"));
}
} else {
- if ((opt->debug>0) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"Cache: no cache found"LF);
- }
- }
- if ((opt->debug>0) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"Cache: size %d"LF, (int)fsize(fconcat(OPT_GET_BUFF(opt), StringBuff(opt->path_log),"hts-cache/old.zip")));
+ hts_log_print(opt, LOG_DEBUG, "Cache: no cache found");
}
+ hts_log_print(opt, LOG_DEBUG, "Cache: size %d", (int)fsize(fconcat(OPT_GET_BUFF(opt), StringBuff(opt->path_log),"hts-cache/old.zip")));
// charger index cache précédent
if (
@@ -1407,10 +1378,7 @@ void cache_init(cache_back* cache,httrackp* opt) {
} else {
name = fconcat(OPT_GET_BUFF(opt), StringBuff(opt->path_log),"hts-cache/new.zip");
}
- if (opt->log) {
- HTS_LOG(opt,LOG_WARNING); fprintf(opt->log,"Cache: damaged cache, trying to repair"LF);
- fflush(opt->log);
- }
+ hts_log_print(opt, LOG_WARNING, "Cache: damaged cache, trying to repair");
if (unzRepair(name,
fconcat(OPT_GET_BUFF(opt), StringBuff(opt->path_log),"hts-cache/repair.zip"),
fconcat(OPT_GET_BUFF(opt), StringBuff(opt->path_log),"hts-cache/repair.tmp"),
@@ -1419,16 +1387,10 @@ void cache_init(cache_back* cache,httrackp* opt) {
unlink(name);
rename(fconcat(OPT_GET_BUFF(opt), StringBuff(opt->path_log),"hts-cache/repair.zip"), name);
cache->zipInput = unzOpen(name);
- if (opt->log) {
- HTS_LOG(opt,LOG_WARNING); fprintf(opt->log,"Cache: %d bytes successfully recovered in %d entries"LF,
- (int) repairedBytes, (int) repaired);
- fflush(opt->log);
- }
+ hts_log_print(opt, LOG_WARNING, "Cache: %d bytes successfully recovered in %d entries",
+ (int) repairedBytes, (int) repaired);
} else {
- if (opt->log) {
- HTS_LOG(opt,LOG_WARNING); fprintf(opt->log,"Cache: could not repair the cache"LF);
- fflush(opt->log);
- }
+ hts_log_print(opt, LOG_WARNING, "Cache: could not repair the cache");
}
}
@@ -1485,33 +1447,25 @@ void cache_init(cache_back* cache,httrackp* opt) {
else
inthash_add(cache->hashtable, filenameIndex, -pos);
} else {
- if (opt->log!=NULL) {
- HTS_LOG(opt,LOG_WARNING); fprintf(opt->log,"Corrupted cache meta entry #%d"LF, (int)entries);
- }
+ hts_log_print(opt, LOG_WARNING, "Corrupted cache meta entry #%d", (int)entries);
}
} else {
- if (opt->log!=NULL) {
- HTS_LOG(opt,LOG_WARNING); fprintf(opt->log,"Corrupted cache entry #%d"LF, (int)entries);
- }
+ hts_log_print(opt, LOG_WARNING, "Corrupted cache entry #%d", (int)entries);
}
unzCloseCurrentFile((unzFile) cache->zipInput);
} else {
- if (opt->log!=NULL) {
- HTS_LOG(opt,LOG_WARNING); fprintf(opt->log,"Corrupted cache entry #%d"LF, (int)entries);
- }
+ hts_log_print(opt, LOG_WARNING, "Corrupted cache entry #%d", (int)entries);
}
} while( unzGoToNextFile((unzFile) cache->zipInput) == Z_OK );
- if ((opt->debug>0) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"Cache index loaded: %d entries loaded"LF, (int)entries);
- }
+ hts_log_print(opt, LOG_DEBUG, "Cache index loaded: %d entries loaded", (int)entries);
opt->is_update=1; // signaler comme update
} else {
- HTS_LOG(opt,LOG_WARNING); fprintf(opt->log,"Cache: error trying to read the cache: %s"LF, hts_get_zerror(zErr));
+ hts_log_print(opt, LOG_WARNING, "Cache: error trying to read the cache: %s", hts_get_zerror(zErr));
}
} else {
- HTS_LOG(opt,LOG_WARNING); fprintf(opt->log,"Cache: error trying to open the cache"LF);
+ hts_log_print(opt, LOG_WARNING, "Cache: error trying to open the cache");
}
} else if (
@@ -1568,20 +1522,14 @@ void cache_init(cache_back* cache,httrackp* opt) {
a+=cache_brstr(a,firstline);
strcpybuff(cache->lastmodified,firstline);
} else {
- if (opt->log) {
- HTS_LOG(opt,LOG_ERROR); fprintf(opt->log,"Cache: version 1.%d not supported, ignoring current cache"LF,cache->version);
- fflush(opt->log);
- }
+ hts_log_print(opt, LOG_ERROR, "Cache: version 1.%d not supported, ignoring current cache",cache->version);
fclose(cache->olddat);
cache->olddat=NULL;
freet(cache->use);
cache->use=NULL;
}
} else { // non supporté
- if (opt->log) {
- HTS_LOG(opt,LOG_ERROR); fprintf(opt->log,"Cache: %s not supported, ignoring current cache"LF,firstline);
- fflush(opt->log);
- }
+ hts_log_print(opt, LOG_ERROR, "Cache: %s not supported, ignoring current cache",firstline);
fclose(cache->olddat);
cache->olddat=NULL;
freet(cache->use);
@@ -1590,10 +1538,7 @@ void cache_init(cache_back* cache,httrackp* opt) {
/* */
} else { // Vieille version du cache
/* */
- if (opt->log) {
- HTS_LOG(opt,LOG_WARNING); fprintf(opt->log,"Cache: importing old cache format"LF);
- fflush(opt->log);
- }
+ hts_log_print(opt, LOG_WARNING, "Cache: importing old cache format");
cache->version=0; // cache 1.0
strcpybuff(cache->lastmodified,firstline);
}
@@ -1626,9 +1571,7 @@ void cache_init(cache_back* cache,httrackp* opt) {
}
}
} else {
- if ((opt->debug>0) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"Cache: no cache found in %s"LF, fconcat(OPT_GET_BUFF(opt), StringBuff(opt->path_log),"hts-cache/"));
- }
+ hts_log_print(opt, LOG_DEBUG, "Cache: no cache found in %s", fconcat(OPT_GET_BUFF(opt), StringBuff(opt->path_log),"hts-cache/"));
}
#if DEBUGCA
@@ -1738,9 +1681,7 @@ void cache_init(cache_back* cache,httrackp* opt) {
}
} else {
- if ((opt->debug>0) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"Cache: no cache enabled"LF);
- }
+ hts_log_print(opt, LOG_DEBUG, "Cache: no cache enabled");
}
}
diff --git a/src/htscore.c b/src/htscore.c
index 4973479..f77124f 100644
--- a/src/htscore.c
+++ b/src/htscore.c
@@ -114,10 +114,6 @@ int nsocDEBUG=0;
// Début de httpmirror, routines annexes
-// version 1 pour httpmirror
-// flusher si on doit lire peu à peu le fichier
-#define test_flush if (opt->flush) { fflush(opt->log); fflush(opt->log); }
-
// pour alléger la syntaxe, des raccourcis sont créés
#define urladr (liens[ptr]->adr)
#define urlfil (liens[ptr]->fil)
@@ -128,9 +124,7 @@ int nsocDEBUG=0;
// note: partir de liens_max.. vers 0.. sinon erreur de violation de mémoire: les liens suivants
// ne sont plus à nous.. agh! [dur celui-là]
#define HTMLCHECK_UNINIT { \
-if ( (opt->debug>0) && (opt->log!=NULL) ) { \
-HTS_LOG(opt,LOG_INFO); fprintf(opt->log,"engine: end"LF); \
-} \
+hts_log_print(opt, LOG_INFO, "engine: end"); \
RUN_CALLBACK0(opt, end); \
}
@@ -172,8 +166,7 @@ RUN_CALLBACK0(opt, end); \
if (cache.olddat) { fclose(cache.olddat); cache.olddat=NULL; } \
if (cache.lst) { fclose(cache.lst); cache.lst=opt->state.strc.lst=NULL; } \
if (cache.txt) { fclose(cache.txt); cache.txt=NULL; } \
- if (opt->log) fflush(opt->log); \
- if (opt->log) fflush(opt->log);\
+ if (opt->log != NULL) fflush(opt->log); \
if (makestat_fp) { fclose(makestat_fp); makestat_fp=NULL; } \
if (maketrack_fp){ fclose(maketrack_fp); maketrack_fp=NULL; } \
if (opt->accept_cookie) cookie_save(opt->cookie,fconcat(OPT_GET_BUFF(opt),StringBuff(opt->path_log),"cookies.txt")); \
@@ -520,11 +513,8 @@ int httpmirror(char* url1, httrackp* opt) {
opt->maxfilter += HTS_FILTERSINC;
if (filters_init(&filters, opt->maxfilter, HTS_FILTERSINC) == 0) {
printf("PANIC! : Too many filters : >%d [%d]\n",filptr,__LINE__);
- if (opt->log) {
- fprintf(opt->log,LF"Too many filters, giving up..(>%d)"LF,filptr);
- fprintf(opt->log,"To avoid that: use #F option for more filters (example: -#F5000)"LF);
- test_flush;
- }
+ hts_log_print(opt, LOG_PANIC, "Too many filters, giving up..(>%d)",filptr);
+ hts_log_print(opt, LOG_INFO, "To avoid that: use #F option for more filters (example: -#F5000)");
XH_extuninit;
return 0;
}
@@ -592,16 +582,12 @@ int httpmirror(char* url1, httrackp* opt) {
}
}
// fclose(fp);
- if (opt->log!=NULL) {
- HTS_LOG(opt,LOG_INFO); fprintf(opt->log,"%d links added from %s"LF,n,StringBuff(opt->filelist)); test_flush;
- }
+ hts_log_print(opt, LOG_INFO, "%d links added from %s",n,StringBuff(opt->filelist));
// Free buffer
freet(filelist_buff);
} else {
- if (opt->log!=NULL) {
- HTS_LOG(opt,LOG_ERROR); fprintf(opt->log,"Could not include URL list: %s"LF,StringBuff(opt->filelist)); test_flush;
- }
+ hts_log_print(opt, LOG_ERROR, "Could not include URL list: %s",StringBuff(opt->filelist));
}
}
@@ -610,10 +596,7 @@ int httpmirror(char* url1, httrackp* opt) {
liens_record("primary","/primary",fslash(OPT_GET_BUFF(opt),fconcat(OPT_GET_BUFF(opt), StringBuff(opt->path_html_utf8),"index.html")),"","",opt->urlhack);
if (liens[lien_tot]==NULL) { // erreur, pas de place réservée
printf("PANIC! : Not enough memory [%d]\n",__LINE__);
- if (opt->log) {
- fprintf(opt->log,"Not enough memory, can not re-allocate %d bytes"LF,(int)((add_tab_alloc+1)*sizeof(lien_url)));
- test_flush;
- }
+ hts_log_print(opt, LOG_PANIC, "Not enough memory, can not re-allocate %d bytes",(int)((add_tab_alloc+1)*sizeof(lien_url)));
XH_extuninit; // désallocation mémoire & buffers
return 0;
}
@@ -665,16 +648,11 @@ int httpmirror(char* url1, httrackp* opt) {
// --> 1024 entrées + 32 entrées par socket en supplément
sback = back_new(opt->maxsoc*32+1024);
if (sback == NULL) {
- if (opt->log)
- fprintf(opt->log,"Not enough memory, can not allocate %d bytes"LF,(int)((opt->maxsoc+1)*sizeof(lien_back)));
+ hts_log_print(opt, LOG_PANIC, "Not enough memory, can not allocate %d bytes",(int)((opt->maxsoc+1)*sizeof(lien_back)));
return 0;
}
}
-
- // flush
- test_flush;
-
// statistiques
if (opt->makestat) {
makestat_fp=fopen(fconcat(OPT_GET_BUFF(opt), StringBuff(opt->path_log),"hts-stats.txt"),"wb");
@@ -695,9 +673,7 @@ int httpmirror(char* url1, httrackp* opt) {
// on n'a pas de liens!! (exemple: httrack www.* impossible sans départ..)
if (lien_tot<=0) {
- if (opt->log) {
- fprintf(opt->log,"Error! You MUST specify at least one complete URL, and not only wildcards!"LF);
- }
+ hts_log_print(opt, LOG_ERROR, "You MUST specify at least one complete URL, and not only wildcards!");
}
/* Send options to callback functions */
@@ -769,9 +745,7 @@ int httpmirror(char* url1, httrackp* opt) {
}
/* Info for wrappers */
- if ( (opt->debug>0) && (opt->log!=NULL) ) {
- HTS_LOG(opt,LOG_INFO); fprintf(opt->log,"engine: start"LF);
- }
+ hts_log_print(opt, LOG_INFO, "engine: start");
if (!RUN_CALLBACK0(opt, start)) {
XH_extuninit;
return 1;
@@ -821,14 +795,11 @@ int httpmirror(char* url1, httrackp* opt) {
( (liens[ptr]->pass2 == -1) )
)
) { // sauter si lien annulé (ou fil vide)
- if ((opt->debug>1) && (opt->log!=NULL)) {
- if (liens[ptr] != NULL && liens[ptr]->pass2 == -1) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"link #%d is ready, skipping: %s%s.."LF,ptr,((urladr != NULL)?(urladr):(" ")),((urlfil != NULL)?(urlfil):(" ")));
- } else {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"link #%d seems ready, skipping: %s%s.."LF,ptr,((urladr != NULL)?(urladr):(" ")),((urlfil != NULL)?(urlfil):(" ")));
- }
- test_flush;
- }
+ if (liens[ptr] != NULL && liens[ptr]->pass2 == -1) {
+ hts_log_print(opt, LOG_DEBUG, "link #%d is ready, skipping: %s%s..",ptr,((urladr != NULL)?(urladr):(" ")),((urlfil != NULL)?(urlfil):(" ")));
+ } else {
+ hts_log_print(opt, LOG_DEBUG, "link #%d seems ready, skipping: %s%s..",ptr,((urladr != NULL)?(urladr):(" ")),((urlfil != NULL)?(urlfil):(" ")));
+ }
// remove from stats
if (liens[ptr]->pass2 == -1) {
HTS_STAT.stat_background--;
@@ -838,15 +809,12 @@ int httpmirror(char* url1, httrackp* opt) {
}
if (liens[ptr] != NULL) { // on a qq chose à récupérer?
- if ( (opt->debug>1) && (opt->log!=NULL) ) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"Wait get: %s%s"LF,urladr,urlfil);
- test_flush;
+ hts_log_print(opt, LOG_DEBUG, "Wait get: %s%s",urladr,urlfil);
#if DEBUG_ROBOTS
- if (strcmp(urlfil,"/robots.txt") == 0) {
- printf("robots.txt detected\n");
- }
+ if (strcmp(urlfil,"/robots.txt") == 0) {
+ printf("robots.txt detected\n");
+ }
#endif
- }
// ------------------------------------------------------------
// DEBUT --RECUPERATION LIEN---
if (ptr==0) { // premier lien à parcourir: lien primaire construit avant
@@ -957,9 +925,7 @@ int httpmirror(char* url1, httrackp* opt) {
} else { // lien vide..
- if (opt->log && opt->debug > 0) {
- HTS_LOG(opt,LOG_WARNING); fprintf(opt->log,"Warning, link #%d empty"LF,ptr); test_flush;
- }
+ hts_log_print(opt, LOG_WARNING, "Warning, link #%d empty",ptr);
error=1;
goto jump_if_done;
} // test si url existe (non vide!)
@@ -984,10 +950,7 @@ int httpmirror(char* url1, httrackp* opt) {
if ((istoobig(opt,r.totalsize,opt->maxfile_html,opt->maxfile_nonhtml,r.contenttype))
|| (istoobig(opt,r.totalsize,opt->maxfile_html,opt->maxfile_nonhtml,r.contenttype))) {
error=0;
- if (opt->log) {
- HTS_LOG(opt,LOG_WARNING); fprintf(opt->log,"Big file cancelled according to user's preferences: %s%s"LF,urladr,urlfil);
- test_flush;
- }
+ hts_log_print(opt, LOG_WARNING, "Big file cancelled according to user's preferences: %s%s",urladr,urlfil);
}
// // // error=1; // ne pas traiter la suite -- euhh si finalement..
}
@@ -1033,15 +996,9 @@ int httpmirror(char* url1, httrackp* opt) {
is_loaded_from_file = 1; \
r.adr = readfile2(savename, &r.size); \
if (r.adr != NULL) { \
- if ( (opt->debug>0) && (opt->log!=NULL) ) { \
- HTS_LOG(opt,LOG_INFO); fprintf(opt->log,"File successfully loaded for parsing: %s%s (%d bytes)"LF,urladr,urlfil,(int)r.size); \
- test_flush; \
- } \
+ hts_log_print(opt, LOG_INFO, "File successfully loaded for parsing: %s%s (%d bytes)",urladr,urlfil,(int)r.size); \
} else { \
- if ( opt->log != NULL ) { \
- HTS_LOG(opt,LOG_ERROR); fprintf(opt->log,"File could not be loaded for parsing: %s%s"LF,urladr,urlfil); \
- test_flush; \
- } \
+ hts_log_print(opt, LOG_ERROR, "File could not be loaded for parsing: %s%s",urladr,urlfil); \
} \
} \
} while(0)
@@ -1187,10 +1144,7 @@ int httpmirror(char* url1, httrackp* opt) {
CH_ADD_RNG0( unic, 0x80 );
}
}
- if (opt->log) {
- HTS_LOG(opt,LOG_WARNING); fprintf(opt->log,"File %s%s converted from UCS2 to UTF-8 (old size: %d bytes, new size: %d bytes)"LF, urladr, urlfil, (int)r.size, new_offs);
- test_flush;
- }
+ hts_log_print(opt, LOG_WARNING, "File %s%s converted from UCS2 to UTF-8 (old size: %d bytes, new size: %d bytes)", urladr, urlfil, (int)r.size, new_offs);
freet(r.adr);
r.adr = NULL;
r.size = new_offs;
@@ -1203,10 +1157,7 @@ int httpmirror(char* url1, httrackp* opt) {
} else if ((nspec > r.size / 100) && (nspec > 10)) { // too many special characters
is_binary = 1;
strcpybuff(r.contenttype,"application/octet-stream");
- if (opt->log) {
- HTS_LOG(opt,LOG_WARNING); fprintf(opt->log,"File not parsed, looks like binary: %s%s"LF,urladr,urlfil);
- test_flush;
- }
+ hts_log_print(opt, LOG_WARNING, "File not parsed, looks like binary: %s%s",urladr,urlfil);
}
/* This hack allows to avoid problems with parsing '\0' characters */
@@ -1400,18 +1351,12 @@ int httpmirror(char* url1, httrackp* opt) {
if ((!r.notmodified) && (opt->is_update) && (!store_errpage)) { // page modifiée
if (strnotempty(savename)) {
HTS_STAT.stat_updated_files++;
- if (opt->log!=NULL) {
- //if ((opt->debug>0) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_INFO); fprintf(opt->log,"File updated: %s%s"LF,urladr,urlfil);
- test_flush;
- }
+ //if ((opt->debug>0) && (opt->log!=NULL)) {
+ hts_log_print(opt, LOG_INFO, "File updated: %s%s",urladr,urlfil);
}
} else {
if (!store_errpage) {
- if ( (opt->debug>0) && (opt->log!=NULL) ) {
- HTS_LOG(opt,LOG_INFO); fprintf(opt->log,"File recorded: %s%s"LF,urladr,urlfil);
- test_flush;
- }
+ hts_log_print(opt, LOG_INFO, "File recorded: %s%s",urladr,urlfil);
}
}
}
@@ -1471,18 +1416,14 @@ int httpmirror(char* url1, httrackp* opt) {
}
/* Could not detect charset */
if (page_charset[0] == '\0') {
- if ( (opt->debug>0) && (opt->log!=NULL) ) {
- HTS_LOG(opt,LOG_INFO); fprintf(opt->log,"Warning: could not detect encoding for: %s%s"LF,urladr,urlfil);
- }
+ hts_log_print(opt, LOG_INFO, "Warning: could not detect encoding for: %s%s",urladr,urlfil);
/* Fallback to ISO-8859-1 (~== identity) ; accents will look weird */
strcpy(page_charset, "iso-8859-1");
}
}
/* Info for wrappers */
- if ( (opt->debug>0) && (opt->log!=NULL) ) {
- HTS_LOG(opt,LOG_INFO); fprintf(opt->log,"engine: check-html: %s%s"LF,urladr,urlfil);
- }
+ hts_log_print(opt, LOG_INFO, "engine: check-html: %s%s",urladr,urlfil);
{
char BIGSTK buff_err_msg[1024];
htsmoduleStruct BIGSTK str;
@@ -1596,10 +1537,7 @@ int httpmirror(char* url1, httrackp* opt) {
/* Créer message d'erreur ? */
if (create_html_warning) {
char* adr=(char*)malloct(strlen(HTS_DATA_ERROR_HTML)+1100);
- if ( (opt->debug>0) && (opt->log!=NULL) ) {
- HTS_LOG(opt,LOG_INFO); fprintf(opt->log,"Creating HTML warning file (%s)"LF,r.msg);
- test_flush;
- }
+ hts_log_print(opt, LOG_INFO, "Creating HTML warning file (%s)",r.msg);
if (adr) {
if (r.adr) {
freet(r.adr);
@@ -1610,10 +1548,7 @@ int httpmirror(char* url1, httrackp* opt) {
}
} else if (create_gif_warning) {
char* adr=(char*)malloct(HTS_DATA_UNKNOWN_GIF_LEN);
- if ( (opt->debug>0) && (opt->log!=NULL) ) {
- HTS_LOG(opt,LOG_INFO); fprintf(opt->log,"Creating GIF dummy file (%s)"LF,r.msg);
- test_flush;
- }
+ hts_log_print(opt, LOG_INFO, "Creating GIF dummy file (%s)",r.msg);
if (r.adr) {
freet(r.adr);
r.adr=NULL;
@@ -1690,10 +1625,7 @@ int httpmirror(char* url1, httrackp* opt) {
}
#ifdef IGNORE_RESTRICTIVE_ROBOTS
else {
- if (opt->log!=NULL) {
- HTS_LOG(opt,LOG_INFO); fprintf(opt->log,"Note: %s robots.txt rules are too restrictive, ignoring /"LF,urladr);
- test_flush;
- }
+ hts_log_print(opt, LOG_INFO, "Note: %s robots.txt rules are too restrictive, ignoring /",urladr);
}
#endif
}
@@ -1702,16 +1634,8 @@ int httpmirror(char* url1, httrackp* opt) {
} while( (bptr<r.size) && (strlen(buff) < (sizeof(buff) - 32) ) );
if (strnotempty(buff)) {
checkrobots_set(&robots,urladr,buff);
- if (opt->log!=NULL) {
- if (opt->log != opt->log) {
- HTS_LOG(opt,LOG_INFO); fprintf(opt->log,"Note: robots.txt forbidden links for %s are: %s"LF,urladr,infobuff);
- test_flush;
- }
- }
- if (opt->log!=NULL) {
- HTS_LOG(opt,LOG_INFO); fprintf(opt->log,"Note: due to %s remote robots.txt rules, links beginning with these path will be forbidden: %s (see in the options to disable this)"LF,urladr,infobuff);
- test_flush;
- }
+ hts_log_print(opt, LOG_INFO, "Note: robots.txt forbidden links for %s are: %s",urladr,infobuff);
+ hts_log_print(opt, LOG_INFO, "Note: due to %s remote robots.txt rules, links beginning with these path will be forbidden: %s (see in the options to disable this)",urladr,infobuff);
}
}
}
@@ -1763,21 +1687,12 @@ int httpmirror(char* url1, httrackp* opt) {
}
- if ( (opt->debug>0) && (opt->log!=NULL) ) {
- HTS_LOG(opt,LOG_WARNING); fprintf(opt->log,"Warning: store %s without scan: %s"LF,r.contenttype,savename);
- test_flush;
- }
+ hts_log_print(opt, LOG_WARNING, "Warning: store %s without scan: %s",r.contenttype,savename);
} else {
if ((opt->getmode & 2)!=0) { // ok autorisé
- if ( (opt->debug>1) && (opt->log!=NULL) ) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"Store %s: %s"LF,r.contenttype,savename);
- test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "Store %s: %s",r.contenttype,savename);
} else { // lien non autorisé! (ex: cgi-bin en html)
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"non-html file ignored after upload at %s : %s"LF,urladr,urlfil);
- test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "non-html file ignored after upload at %s : %s",urladr,urlfil);
if (r.adr) {
freet(r.adr); r.adr=NULL;
}
@@ -1792,18 +1707,10 @@ int httpmirror(char* url1, httrackp* opt) {
if (filesave(opt,r.adr,(int)r.size,savename,urladr,urlfil)!=0) {
int fcheck;
if ((fcheck=check_fatal_io_errno())) {
- HTS_LOG(opt,LOG_ERROR); fprintf(opt->log,"Mirror aborted: disk full or filesystem problems"LF); test_flush;
+ hts_log_print(opt, LOG_ERROR, "Mirror aborted: disk full or filesystem problems");
opt->state.exit_xh=-1; /* fatal error */
}
- if (opt->log) {
- int last_errno = errno;
- HTS_LOG(opt,LOG_ERROR); fprintf(opt->log,"Unable to save file %s : %s"LF, savename, strerror(last_errno));
- if (fcheck) {
- HTS_LOG(opt,LOG_ERROR);
- fprintf(opt->log,"* * Fatal write error, giving up"LF);
- }
- test_flush;
- }
+ hts_log_print(opt, LOG_ERROR | LOG_ERRNO, "Unable to save file %s", savename);
} else {
/*
if (!ishttperror(r.statuscode))
@@ -1819,9 +1726,7 @@ int httpmirror(char* url1, httrackp* opt) {
/* Parsing of other media types (java, ram..) */
/*
if (strfield2(r.contenttype,"audio/x-pn-realaudio")) {
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"(Real Media): parsing %s"LF,savename); test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "(Real Media): parsing %s",savename);
if (fexist(savename)) { // ok, existe bien!
FILE* fp=FOPEN(savename,"r+b");
if (fp) {
@@ -1829,9 +1734,7 @@ int httpmirror(char* url1, httrackp* opt) {
char BIGSTK line[HTS_URLMAXSIZE*2];
linput(fp,line,HTS_URLMAXSIZE);
if (strnotempty(line)) {
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"(Real Media): detected %s"LF,line); test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "(Real Media): detected %s",line);
}
}
fclose(fp);
@@ -1871,14 +1774,10 @@ int httpmirror(char* url1, httrackp* opt) {
/* Parse if recognized */
switch(hts_parse_externals(&str)) {
case 1:
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"(External module): parsed successfully %s"LF,savename); test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "(External module): parsed successfully %s",savename);
break;
case 0:
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"(External module): couldn't parse successfully %s : %s"LF,savename, str.err_msg); test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "(External module): couldn't parse successfully %s : %s",savename, str.err_msg);
break;
}
}
@@ -1914,10 +1813,7 @@ jump_if_done:
}
if (ptr>=lien_tot) { // fin de boucle
if (!numero_passe) { // première boucle
- if ((opt->debug>1) && (opt->log!=NULL)) {
- fprintf(opt->log,LF"Now getting non-html files..."LF);
- test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "Now getting non-html files...");
numero_passe=1; // seconde boucle
ptr=0;
// prochain pass2
@@ -1937,15 +1833,11 @@ jump_if_done:
if (!back_checkmirror(opt)) {
ptr=lien_tot;
} else if (opt->state.exit_xh) { // sortir
- if (opt->log) {
- HTS_LOG(opt,LOG_INFO);
- if (opt->state.exit_xh==1) {
- fprintf(opt->log,"Exit requested by shell or user"LF);
- } else {
- fprintf(opt->log,"Exit requested by engine"LF);
- }
- test_flush;
- }
+ if (opt->state.exit_xh==1) {
+ hts_log_print(opt, LOG_ERROR, "Exit requested by shell or user");
+ } else {
+ hts_log_print(opt, LOG_ERROR, "Exit requested by engine");
+ }
ptr=lien_tot;
}
} while(ptr<lien_tot);
@@ -1970,10 +1862,7 @@ jump_if_done:
&&
(HTS_STAT.HTS_TOTAL_RECV < 32768) /* should be fine */
) {
- if (opt->log) {
- HTS_LOG(opt,LOG_INFO); fprintf(opt->log,"No data seems to have been transfered during this session! : restoring previous one!"LF);
- test_flush;
- }
+ hts_log_print(opt, LOG_INFO, "No data seems to have been transfered during this session! : restoring previous one!");
XH_uninit;
if ( (fexist(fconcat(OPT_GET_BUFF(opt), StringBuff(opt->path_log),"hts-cache/old.dat"))) && (fexist(fconcat(OPT_GET_BUFF(opt), StringBuff(opt->path_log),"hts-cache/old.ndx"))) ) {
remove(fconcat(OPT_GET_BUFF(opt), StringBuff(opt->path_log),"hts-cache/new.dat"));
@@ -2020,9 +1909,7 @@ jump_if_done:
strcatbuff(file,line+1);
file[strlen(file)-1]='\0';
if (fexist(file)) { // toujours sur disque: virer
- if (opt->log) {
- HTS_LOG(opt,LOG_INFO); fprintf(opt->log,"Purging %s"LF,file);
- }
+ hts_log_print(opt, LOG_INFO, "Purging %s",file);
remove(file); purge=1;
}
}
@@ -2044,7 +1931,7 @@ jump_if_done:
while ((strnotempty(file)) && (rmdir(file)==0)) { // ok, éliminé (existait)
purge=1;
if (opt->log) {
- HTS_LOG(opt,LOG_INFO); fprintf(opt->log,"Purging directory %s/"LF,file);
+ hts_log_print(opt, LOG_INFO, "Purging directory %s/",file);
while(strnotempty(file) && (file[strlen(file)-1]!='/') && (file[strlen(file)-1]!='\\')) {
file[strlen(file)-1]='\0';
}
@@ -2057,9 +1944,7 @@ jump_if_done:
}
//
if (!purge) {
- if (opt->log) {
- fprintf(opt->log,"No files purged"LF);
- }
+ hts_log_print(opt, LOG_INFO, "No files purged");
}
}
freet(adr);
@@ -2135,8 +2020,6 @@ jump_if_done:
zipClose(cache.zipOutput, finalInfo);
cache.zipOutput = NULL;
}
-
- test_flush;
}
#if DEBUG_HASH
// noter les collisions
@@ -2173,10 +2056,6 @@ jump_if_done:
return 1; // OK
}
// version 2 pour le reste
-// flusher si on doit lire peu à peu le fichier
-#undef test_flush
-#define test_flush if (opt->flush) { fflush(opt->log); fflush(opt->log); }
-
// Estimate transfer rate
// a little bit complex, but not too much
@@ -2263,11 +2142,8 @@ void host_ban(httrackp* opt,lien_url** liens,int ptr,int lien_tot,struct_back* s
opt->maxfilter += HTS_FILTERSINC;
if (filters_init(&_FILTERS, opt->maxfilter, HTS_FILTERSINC) == 0) {
printf("PANIC! : Too many filters : >%d [%d]\n",*_FILTERS_PTR,__LINE__);
- if (opt->log) {
- fprintf(opt->log,LF"Too many filters, giving up..(>%d)"LF,*_FILTERS_PTR);
- fprintf(opt->log,"To avoid that: use #F option for more filters (example: -#F5000)"LF);
- fflush(opt->log);
- }
+ hts_log_print(opt, LOG_PANIC, "Too many filters, giving up..(>%d)",*_FILTERS_PTR);
+ hts_log_print(opt, LOG_INFO, "To avoid that: use #F option for more filters (example: -#F5000)");
assertf("too many filters - giving up" == NULL);
}
}
@@ -2285,9 +2161,7 @@ void host_ban(httrackp* opt,lien_url** liens,int ptr,int lien_tot,struct_back* s
if (strlen(host)<=1) { // euhh?? longueur <= 1
if (strcmp(host,"file://")) {
//## if (host[0]!=lOCAL_CHAR) { // pas local
- if (opt->log!=NULL) {
- fprintf(opt->log,"PANIC! HostCancel detected memory leaks [char %d]"LF,host[0]); test_flush;
- }
+ hts_log_print(opt, LOG_PANIC, "PANIC! HostCancel detected memory leaks [char %d]",host[0]);
return; // purée
}
}
@@ -2305,10 +2179,7 @@ void host_ban(httrackp* opt,lien_url** liens,int ptr,int lien_tot,struct_back* s
back[i].r.soc=INVALID_SOCKET;
back[i].r.statuscode=STATUSCODE_TIMEOUT; // timeout (peu importe si c'est un traffic jam)
strcpybuff(back[i].r.msg,"Link Cancelled by host control");
-
- if ((opt->debug>1) && (opt->log!=NULL)) {
- fprintf(opt->log,"Shutdown: %s%s"LF,back[i].url_adr,back[i].url_fil); test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "Shutdown: %s%s",back[i].url_adr,back[i].url_fil);
}
}
@@ -2323,9 +2194,7 @@ void host_ban(httrackp* opt,lien_url** liens,int ptr,int lien_tot,struct_back* s
while((liens[i]->adr[l]) && (l<1020)) l++;
if ((l > 0) && (l<1020)) { // sécurité
if (strfield2(jump_identification(liens[i]->adr),host)) { // host
- if ((opt->debug>1) && (opt->log!=NULL)) {
- fprintf(opt->log,"Cancel: %s%s"LF,liens[i]->adr,liens[i]->fil); test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "Cancel: %s%s",liens[i]->adr,liens[i]->fil);
strcpybuff(liens[i]->adr,"!"); // cancel (invalide hash)
// on efface pas le hash, because si on rencontre le lien, reverif sav..
}
@@ -2334,19 +2203,15 @@ void host_ban(httrackp* opt,lien_url** liens,int ptr,int lien_tot,struct_back* s
char dmp[1040];
dmp[0]='\0';
strncatbuff(dmp,liens[i]->adr,1024);
- fprintf(opt->log,"WARNING! HostCancel detected memory leaks [len %d at %d]"LF,l,i); test_flush;
- fprintf(opt->log,"dump 1024 bytes (address %p): "LF"%s"LF,liens[i]->adr,dmp); test_flush;
+ hts_log_print(opt, LOG_WARNING, "WARNING! HostCancel detected memory leaks [len %d at %d]",l,i);
+ hts_log_print(opt, LOG_WARNING, "dump 1024 bytes (address %p): "LF"%s",liens[i]->adr,dmp);
}
}
} else {
- if (opt->log!=NULL) {
- fprintf(opt->log,"WARNING! HostCancel detected memory leaks [adr at %d]"LF,i); test_flush;
- }
+ hts_log_print(opt, LOG_WARNING, "WARNING! HostCancel detected memory leaks [adr at %d]",i);
}
} else {
- if (opt->log!=NULL) {
- fprintf(opt->log,"WARNING! HostCancel detected memory leaks [null at %d]"LF,i); test_flush;
- }
+ hts_log_print(opt, LOG_WARNING, "WARNING! HostCancel detected memory leaks [null at %d]",i);
}
//}
}
@@ -2400,16 +2265,16 @@ static int mkdir_compat(const char *pathname) {
}
/* path must end with "/" or with the finename (/tmp/bar/ or /tmp/bar/foo.zip) */
+/* Note: preserve errno */
HTSEXT_API int dir_exists(const char* path) {
+ const int err = errno;
STRUCT_STAT st;
char BIGSTK file[HTS_URLMAXSIZE*2];
int i = 0;
if (strnotempty(path) == 0) {
- errno = EINVAL;
return 0;
}
if (strlen(path) > HTS_URLMAXSIZE) {
- errno = EINVAL;
return 0;
}
@@ -2430,11 +2295,10 @@ HTSEXT_API int dir_exists(const char* path) {
/* Check the final dir */
if (STAT(file, &st) == 0 && S_ISDIR(st.st_mode)) {
- errno = 0;
return 1; /* EXISTS */
}
- errno = 0;
- return 0; /* DOES NOT EXISTS */
+ errno = err;
+ return 0; /* DOES NOT EXIST */
}
/* path must end with "/" or with the finename (/tmp/bar/ or /tmp/bar/foo.zip) */
@@ -2814,7 +2678,7 @@ void file_notify(httrackp* opt,const char* adr,const char* fil,const char* save,
// executer commande utilisateur
static void postprocess_file(httrackp* opt, const char* save, const char* adr, const char* fil);
-HTS_INLINE void usercommand(httrackp* opt,int _exe,const char* _cmd,const char* file,const char* adr,const char* fil) {
+void usercommand(httrackp* opt,int _exe,const char* _cmd,const char* file,const char* adr,const char* fil) {
usercommand_strc* strc = &opt->state.usercmd;
/* Callback */
@@ -2904,9 +2768,7 @@ static void postprocess_file(httrackp* opt,const char* save, const char* adr, co
opt->state.mimehtml_created = 1;
} else {
opt->state.mimehtml_created = -1;
- if ( opt->log != NULL ) {
- HTS_LOG(opt,LOG_ERROR); fprintf(opt->log,"unable to create index.mht"LF);
- }
+ hts_log_print(opt, LOG_ERROR, "unable to create index.mht");
}
}
if (opt->state.mimehtml_created == 1 && opt->state.mimefp != NULL) {
@@ -2967,7 +2829,7 @@ static void postprocess_file(httrackp* opt,const char* save, const char* adr, co
}
// écrire n espaces dans fp
-HTS_INLINE int fspc(httrackp *opt,FILE* fp,const char* type) {
+int fspc(httrackp *opt,FILE* fp,const char* type) {
fspc_strc* const strc = ( opt != NULL ) ? &opt->state.fspc : NULL;
if (fp != NULL) {
char s[256];
@@ -3146,10 +3008,7 @@ int back_fill(struct_back* sback,httrackp* opt,cache_back* cache,lien_url** lien
if (ok) {
if (!back_exist(sback, opt, liens[p]->adr,liens[p]->fil,liens[p]->sav)) {
if (back_add(sback,opt,cache,liens[p]->adr,liens[p]->fil,liens[p]->sav,liens[liens[p]->precedent]->adr,liens[liens[p]->precedent]->fil,liens[p]->testmode)==-1) {
- if ( (opt->debug>1) && (opt->log!=NULL) ) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"error: unable to add more links through back_add for back_fill"LF);
- test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "error: unable to add more links through back_add for back_fill");
#if BDEBUG==1
printf("error while adding\n");
#endif
@@ -3200,7 +3059,7 @@ int read_stdin(char* s,int max) {
return i;
}
#ifdef _WIN32
-HTS_INLINE int check_stdin(void) {
+int check_stdin(void) {
#ifndef _WIN32_WCE
return (_kbhit());
#else
@@ -3208,7 +3067,7 @@ HTS_INLINE int check_stdin(void) {
#endif
}
#else
-HTS_INLINE int check_flot(T_SOC s) {
+int check_flot(T_SOC s) {
fd_set fds;
struct timeval tv;
FD_ZERO(&fds);
@@ -3218,7 +3077,7 @@ HTS_INLINE int check_flot(T_SOC s) {
select(s+1,&fds,NULL,NULL,&tv);
return FD_ISSET(s,&fds);
}
-HTS_INLINE int check_stdin(void) {
+int check_stdin(void) {
fflush(stdout); fflush(stdin);
if (check_flot(0))
return 1;
@@ -3227,7 +3086,7 @@ HTS_INLINE int check_stdin(void) {
#endif
#endif
-HTS_INLINE int check_sockerror(T_SOC s) {
+int check_sockerror(T_SOC s) {
fd_set fds;
struct timeval tv;
FD_ZERO(&fds);
@@ -3239,7 +3098,7 @@ HTS_INLINE int check_sockerror(T_SOC s) {
}
/* check incoming data */
-HTS_INLINE int check_sockdata(T_SOC s) {
+int check_sockdata(T_SOC s) {
fd_set fds;
struct timeval tv;
FD_ZERO(&fds);
@@ -3414,6 +3273,7 @@ HTSEXT_API int hts_setpause(httrackp *opt, int p) {
// ask for termination
HTSEXT_API int hts_request_stop(httrackp* opt, int force) {
if (opt != NULL) {
+ hts_log_print(opt, LOG_ERROR, "Exit requested by shell or user");
opt->state.stop = 1;
}
return 0;
@@ -3524,24 +3384,16 @@ int htsAddLink(htsmoduleStruct* str, char* link) {
codebase[0]='\0';
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"(module): adding link : '%s'"LF, link); test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "(module): adding link : '%s'", link);
// recopie de "creer le lien"
//
if (!RUN_CALLBACK1(opt, linkdetected, link)) {
- if (opt->log) {
- HTS_LOG(opt,LOG_ERROR); fprintf(opt->log,"Link %s refused by external wrapper"LF, link);
- test_flush;
- }
+ hts_log_print(opt, LOG_ERROR, "Link %s refused by external wrapper", link);
return 0;
}
if (!RUN_CALLBACK2(opt, linkdetected2, link, NULL)) {
- if (opt->log) {
- HTS_LOG(opt,LOG_ERROR); fprintf(opt->log,"Link %s refused by external wrapper(2)"LF, link);
- test_flush;
- }
+ hts_log_print(opt, LOG_ERROR, "Link %s refused by external wrapper(2)", link);
return 0;
}
@@ -3569,19 +3421,13 @@ int htsAddLink(htsmoduleStruct* str, char* link) {
strcpybuff(tempo,a);
strcpybuff(codebase,tempo); // couper host
} else {
- if (opt->log) {
- fprintf(opt->log,"Unexpected strstr error in base %s"LF,codebase);
- test_flush;
- }
+ hts_log_print(opt, LOG_ERROR, "Unexpected strstr error in base %s",codebase);
}
}
}
if (!((int) strlen(codebase)<HTS_URLMAXSIZE)) { // trop long
- if (opt->log) {
- fprintf(opt->log,"Codebase too long, parsing skipped (%s)"LF,codebase);
- test_flush;
- }
+ hts_log_print(opt, LOG_ERROR, "Codebase too long, parsing skipped (%s)",codebase);
}
{
@@ -3600,10 +3446,7 @@ int htsAddLink(htsmoduleStruct* str, char* link) {
NULL, NULL,
&set_prio_to,
&just_test_it);
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"result for wizard external module link: %d"LF,forbidden_url);
- test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "result for wizard external module link: %d",forbidden_url);
/* Link accepted */
if (!forbidden_url) {
@@ -3633,12 +3476,9 @@ int htsAddLink(htsmoduleStruct* str, char* link) {
if (r != -1 && !forbidden_url) {
if (savename) {
if (lienrelatif(tempo,save,savename)==0) {
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"(module): relative link at %s build with %s and %s: %s"LF,adr,save,savename,tempo);
- test_flush;
- if (str->localLink && str->localLinkSize > (int) strlen(tempo) + 1) {
- strcpybuff(str->localLink, tempo);
- }
+ hts_log_print(opt, LOG_DEBUG, "(module): relative link at %s build with %s and %s: %s",adr,save,savename,tempo);
+ if (str->localLink && str->localLinkSize > (int) strlen(tempo) + 1) {
+ strcpybuff(str->localLink, tempo);
}
}
}
@@ -3646,9 +3486,7 @@ int htsAddLink(htsmoduleStruct* str, char* link) {
}
if (forbidden_url) {
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"(module): file not caught: %s"LF,lien); test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "(module): file not caught: %s",lien);
if (str->localLink && str->localLinkSize > (int) ( strlen(adr) + strlen(fil) + 8 ) ) {
str->localLink[0] = '\0';
if (!link_has_authority(adr))
@@ -3661,9 +3499,7 @@ int htsAddLink(htsmoduleStruct* str, char* link) {
//
if (r != -1) {
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"(module): %s%s -> %s (base %s)"LF,adr,fil,save,codebase); test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "(module): %s%s -> %s (base %s)",adr,fil,save,codebase);
// modifié par rapport à l'autre version (cf prio_fix notamment et save2)
@@ -3688,10 +3524,7 @@ int htsAddLink(htsmoduleStruct* str, char* link) {
liens_record(adr,fil,save,"","",opt->urlhack);
if (liens[lien_tot]==NULL) { // erreur, pas de place réservée
printf("PANIC! : Not enough memory [%d]\n",__LINE__);
- if (opt->log) {
- fprintf(opt->log,"Not enough memory, can not re-allocate %d bytes"LF,(int)((add_tab_alloc+1)*sizeof(lien_url)));
- test_flush;
- }
+ hts_log_print(opt, LOG_PANIC, "Not enough memory, can not re-allocate %d bytes",(int)((add_tab_alloc+1)*sizeof(lien_url)));
opt->state.exit_xh=-1; /* fatal error -> exit */
return 0;
}
@@ -3719,10 +3552,7 @@ int htsAddLink(htsmoduleStruct* str, char* link) {
//strcpybuff(liens[lien_tot]->adr,adr);
//strcpybuff(liens[lien_tot]->fil,fil);
//strcpybuff(liens[lien_tot]->sav,save);
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"(module): OK, NOTE: %s%s -> %s"LF,liens[lien_tot]->adr,liens[lien_tot]->fil,liens[lien_tot]->sav);
- test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "(module): OK, NOTE: %s%s -> %s",liens[lien_tot]->adr,liens[lien_tot]->fil,liens[lien_tot]->sav);
lien_tot++; // UN LIEN DE PLUS
}
diff --git a/src/htscore.h b/src/htscore.h
index 2272327..8f07cf2 100644
--- a/src/htscore.h
+++ b/src/htscore.h
@@ -335,7 +335,7 @@ FILE* fileappend(filenote_strc *strct,const char* s);
int filecreateempty(filenote_strc *strct, const char* filename);
int filenote(filenote_strc *strct,const char* s,filecreate_params* params);
void file_notify(httrackp* opt,const char* adr,const char* fil,const char* save,int create,int modify,int wasupdated);
-HTS_INLINE void usercommand(httrackp* opt,int exe,const char* cmd,const char* file,const char* adr,const char* fil);
+void usercommand(httrackp* opt,int exe,const char* cmd,const char* file,const char* adr,const char* fil);
void usercommand_exe(const char* cmd,const char* file);
int filters_init(char*** ptrfilters, int maxfilter, int filterinc);
#ifndef HTTRACK_DEFLIB
@@ -343,7 +343,7 @@ HTSEXT_API int structcheck(const char* path);
HTSEXT_API int structcheck_utf8(const char* path);
HTSEXT_API int dir_exists(const char* path);
#endif
-HTS_INLINE int fspc(httrackp *opt,FILE* fp,const char* type);
+int fspc(httrackp *opt,FILE* fp,const char* type);
char* next_token(char* p,int flag);
//
char* readfile(char* fil);
@@ -382,12 +382,12 @@ int hts_add_file(char* file,int file_position);
// Polling
#if HTS_POLL
-HTS_INLINE int check_flot(T_SOC s);
-HTS_INLINE int check_stdin(void);
+int check_flot(T_SOC s);
+int check_stdin(void);
int read_stdin(char* s,int max);
#endif
-HTS_INLINE int check_sockerror(T_SOC s);
-HTS_INLINE int check_sockdata(T_SOC s);
+int check_sockerror(T_SOC s);
+int check_sockdata(T_SOC s);
/* external modules */
int htsAddLink(htsmoduleStruct* str, char* link);
diff --git a/src/htscoremain.c b/src/htscoremain.c
index 75c34fe..53baa56 100644
--- a/src/htscoremain.c
+++ b/src/htscoremain.c
@@ -2141,7 +2141,7 @@ HTSEXT_API int hts_main2(int argc, char **argv, httrackp *opt) {
}
// fichier log
- if (opt->log) {
+ if (opt->log) {
int i;
fprintf(opt->log,"HTTrack"HTTRACK_VERSION"%s launched on %s at %s"LF,
hts_get_version_info(opt),
@@ -2186,32 +2186,22 @@ HTSEXT_API int hts_main2(int argc, char **argv, httrackp *opt) {
if (!opt->bypass_limits) {
if (opt->maxsoc <= 0 || opt->maxsoc > 8) {
opt->maxsoc = 8;
- if (opt->log != NULL) {
- HTS_LOG(opt,LOG_WARNING); fprintf(opt->log,"* security warning: maximum number of simultaneous connections limited to %d to avoid server overload"LF, (int)opt->maxsoc);
- }
+ hts_log_print(opt, LOG_WARNING, "* security warning: maximum number of simultaneous connections limited to %d to avoid server overload", (int)opt->maxsoc);
}
if (opt->maxrate <= 0 || opt->maxrate > 250000) {
opt->maxrate = 250000;
- if (opt->log != NULL) {
- HTS_LOG(opt,LOG_WARNING); fprintf(opt->log,"* security warning: maximum bandwidth limited to %d to avoid server overload"LF, (int)opt->maxrate);
- }
+ hts_log_print(opt, LOG_WARNING, "* security warning: maximum bandwidth limited to %d to avoid server overload", (int)opt->maxrate);
}
if (opt->maxconn <= 0 || opt->maxconn > 5.0) {
opt->maxconn = 5.0;
- if (opt->log != NULL) {
- HTS_LOG(opt,LOG_WARNING); fprintf(opt->log,"* security warning: maximum number of connections per second limited to %f to avoid server overload"LF, (float)opt->maxconn);
- }
+ hts_log_print(opt, LOG_WARNING, "* security warning: maximum number of connections per second limited to %f to avoid server overload", (float)opt->maxconn);
}
} else {
- if (opt->log != NULL) {
- HTS_LOG(opt,LOG_WARNING); fprintf(opt->log,"* security warning: !!! BYPASSING SECURITY LIMITS - MONITOR THIS SESSION WITH EXTREME CARE !!!"LF);
- }
+ hts_log_print(opt, LOG_WARNING, "* security warning: !!! BYPASSING SECURITY LIMITS - MONITOR THIS SESSION WITH EXTREME CARE !!!");
}
/* Info for wrappers */
- if ( (opt->debug>0) && (opt->log!=NULL) ) {
- HTS_LOG(opt,LOG_INFO); fprintf(opt->log,"engine: init"LF);
- }
+ hts_log_print(opt, LOG_INFO, "engine: init");
/* Init external */
RUN_CALLBACK_NOARG(opt, init);
@@ -2252,9 +2242,7 @@ HTSEXT_API int hts_main2(int argc, char **argv, httrackp *opt) {
if (a) {
*a='\0';
hts_buildtopindex(opt,rpath,StringBuff(opt->path_bin));
- if (opt->log) {
- HTS_LOG(opt,LOG_INFO); fprintf(opt->log,"Top index rebuilt (done)"LF);
- }
+ hts_log_print(opt, LOG_INFO, "Top index rebuilt (done)");
}
}
@@ -2286,9 +2274,7 @@ HTSEXT_API int hts_main2(int argc, char **argv, httrackp *opt) {
}
/* Info for wrappers */
- if ( (opt->debug>0) && (opt->log!=NULL) ) {
- HTS_LOG(opt,LOG_INFO); fprintf(opt->log,"engine: free"LF);
- }
+ hts_log_print(opt, LOG_INFO, "engine: free");
/* UnInit */
RUN_CALLBACK_NOARG(opt, uninit);
diff --git a/src/htslib.c b/src/htslib.c
index 1a95a67..8b20879 100644
--- a/src/htslib.c
+++ b/src/htslib.c
@@ -76,6 +76,7 @@ Please visit our Website: http://www.httrack.com
#include <string.h>
#include <time.h>
+#include <stdarg.h>
#ifndef _WIN32_WCE
#include <sys/timeb.h>
@@ -4346,29 +4347,39 @@ void fprintfio(FILE* fp,char* buff,char* prefix) {
/* Le fichier existe-t-il? (ou est-il accessible?) */
/* Note: NOT utf-8 */
+/* Note: preserve errno */
int fexist(const char* s) {
char catbuff[CATBUFF_SIZE];
+ const int err = errno;
struct stat st;
memset(&st, 0, sizeof(st));
if (stat(fconv(catbuff,s), &st) == 0) {
if (S_ISREG(st.st_mode)) {
return 1;
+ } else {
+ return 0;
}
}
+ errno = err;
return 0;
}
/* Le fichier existe-t-il? (ou est-il accessible?) */
/* Note: utf-8 */
+/* Note: preserve errno */
int fexist_utf8(const char* s) {
char catbuff[CATBUFF_SIZE];
+ const int err = errno;
STRUCT_STAT st;
memset(&st, 0, sizeof(st));
if (STAT(fconv(catbuff,s), &st) == 0) {
if (S_ISREG(st.st_mode)) {
return 1;
+ } else {
+ return 0;
}
}
+ errno = err;
return 0;
}
@@ -5181,6 +5192,7 @@ HTSEXT_API int hts_uninit_module(void) {
return 1;
}
+// legacy. do not use
HTSEXT_API int hts_log(httrackp *opt, const char* prefix, const char *msg) {
if (opt->log != NULL) {
fspc(opt, opt->log, prefix);
@@ -5190,6 +5202,58 @@ HTSEXT_API int hts_log(httrackp *opt, const char* prefix, const char *msg) {
return 1; /* Error */
}
+HTSEXT_API void hts_log_print(httrackp *opt, int type, const char *format, ...) {
+ assertf(format != NULL);
+ if (opt != NULL && opt->log != NULL) {
+ va_list args;
+ const int save_errno = errno;
+ const char *s_type = "unknown";
+ switch(type & 0xff) {
+ case LOG_DEBUG:
+ // check verbosity
+ if (opt->debug < 2) {
+ return ;
+ }
+ s_type = "debug";
+ break;
+ case LOG_INFO:
+ // check verbosity
+ if (opt->debug < 1) {
+ return ;
+ }
+ s_type = "info";
+ break;
+ case LOG_NOTICE:
+ // check verbosity
+ if (opt->debug < 1) {
+ return ;
+ }
+ /* nobreak; */
+ case LOG_WARNING:
+ s_type = "warning";
+ break;
+ case LOG_ERROR:
+ s_type = "error";
+ break;
+ case LOG_PANIC:
+ s_type = "panic";
+ break;
+ }
+ fspc(opt, opt->log, s_type);
+ va_start(args, format);
+ (void) vfprintf(opt->log, format, args);
+ va_end(args);
+ if ((type & LOG_ERRNO) != 0) {
+ fprintf(opt->log, ": %s", strerror(save_errno));
+ }
+ fputs(LF, opt->log);
+ if (opt->flush) {
+ fflush(opt->log);
+ }
+ errno = save_errno;
+ }
+}
+
HTSEXT_API void set_wrappers(httrackp *opt) { // LEGACY
}
diff --git a/src/htslib.h b/src/htslib.h
index a676af6..cb93367 100644
--- a/src/htslib.h
+++ b/src/htslib.h
@@ -399,6 +399,7 @@ HTSEXT_API char* fconv(char *catbuff, const char* a);
char* fslash(char *catbuff, const char* a);
#ifndef HTTRACK_DEFLIB
HTSEXT_API int hts_log(httrackp *opt, const char* prefix, const char *msg);
+HTSEXT_API void hts_log_print(httrackp *opt, int type, const char *format, ...) HTS_PRINTF_FUN(3, 4);
#endif
char* convtolower(char *catbuff, const char* a);
diff --git a/src/htsmodules.c b/src/htsmodules.c
index ea75a7f..4c37047 100644
--- a/src/htsmodules.c
+++ b/src/htsmodules.c
@@ -362,10 +362,8 @@ void htspe_uninit(void) {
static void htspe_log(htsmoduleStruct* str, const char* msg) {
const char* savename = str->filename;
httrackp* opt = (httrackp*) str->opt;
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"(External module): parsing %s using module %s"LF,
- savename, msg);
- }
+ hts_log_print(opt, LOG_DEBUG, "(External module): parsing %s using module %s",
+ savename, msg);
}
HTSEXT_API const char* hts_is_available(void) {
diff --git a/src/htsname.c b/src/htsname.c
index 16901a3..bfae34a 100644
--- a/src/htsname.c
+++ b/src/htsname.c
@@ -46,9 +46,6 @@ Please visit our Website: http://www.httrack.com
#include "htscharset.h"
#include <ctype.h>
-#undef test_flush
-#define test_flush if (opt->flush) { fflush(opt->log); fflush(opt->log); }
-
#define ADD_STANDARD_PATH \
{ /* ajout nom */\
char BIGSTK buff[HTS_URLMAXSIZE*2];\
@@ -384,10 +381,7 @@ int url_savename2(char* adr_complete, char* fil_complete, char* save,
htsblk r = cache_read_including_broken(opt,cache,adr,fil); // test uniquement
if (r.statuscode != -1) { // pas d'erreur de lecture cache
char s[32]; s[0]='\0';
- if ( (opt->debug>1) && (opt->log!=NULL) ) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"Testing link type (from cache) %s%s"LF,adr_complete,fil_complete);
- test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "Testing link type (from cache) %s%s",adr_complete,fil_complete);
if (strnotempty(r.cdispo)) { /* filename given */
ext_chg=2; /* change filename */
strcpybuff(ext,r.cdispo);
@@ -472,11 +466,8 @@ int url_savename2(char* adr_complete, char* fil_complete, char* save,
/* Rock'in */
curr_adr[0]=curr_fil[0]='\0';
- opt->state. _hts_in_html_parsing=2; // test
- if ( (opt->debug>1) && (opt->log!=NULL) ) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"Testing link type %s%s"LF,adr_complete,fil_complete);
- test_flush;
- }
+ opt->state._hts_in_html_parsing=2; // test
+ hts_log_print(opt, LOG_DEBUG, "Testing link type %s%s",adr_complete,fil_complete);
strcpybuff(curr_adr,adr_complete);
strcpybuff(curr_fil,fil_complete);
// ajouter dans le backing le fichier en mode test
@@ -576,18 +567,12 @@ int url_savename2(char* adr_complete, char* fil_complete, char* save,
methode=BACK_ADD_TEST; // tester avec HEAD
else {
methode=BACK_ADD_TEST2; // tester avec GET
- if ( opt->log!=NULL ) {
- HTS_LOG(opt,LOG_WARNING); fprintf(opt->log,"Loop with HEAD request (during prefetch) at %s%s"LF,curr_adr,curr_fil);
- test_flush;
- }
+ hts_log_print(opt, LOG_WARNING, "Loop with HEAD request (during prefetch) at %s%s",curr_adr,curr_fil);
}
// Ajouter
URLSAVENAME_WAIT_FOR_AVAILABLE_SOCKET();
if (back_add(sback,opt,cache,mov_adr,mov_fil,methode,referer_adr,referer_fil,1)!=-1) { // OK
- if ( (opt->debug>1) && (opt->log!=NULL) ) {
- HTS_LOG(opt,LOG_WARNING); fprintf(opt->log,"(during prefetch) %s (%d) to link %s at %s%s"LF,back[b].r.msg,back[b].r.statuscode,back[b].r.location,curr_adr,curr_fil);
- test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "(during prefetch) %s (%d) to link %s at %s%s",back[b].r.msg,back[b].r.statuscode,back[b].r.location,curr_adr,curr_fil);
// libérer emplacement backing actuel et attendre le prochain
back_maydelete(opt,cache,sback,b);
@@ -599,26 +584,17 @@ int url_savename2(char* adr_complete, char* fil_complete, char* save,
petits_tours++;
//
} else {// sinon on fait rien et on s'en va.. (ftp etc)
- if ( (opt->debug>1) && (opt->log)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"Warning: Savename redirect backing error at %s%s"LF,mov_adr,mov_fil);
- test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "Warning: Savename redirect backing error at %s%s",mov_adr,mov_fil);
}
}
} else {
- if ( opt->log!=NULL ) {
- HTS_LOG(opt,LOG_WARNING); fprintf(opt->log,"Unable to test %s%s (loop to same filename)"LF,adr_complete,fil_complete);
- test_flush;
- }
+ hts_log_print(opt, LOG_WARNING, "Unable to test %s%s (loop to same filename)",adr_complete,fil_complete);
}
}
}
} else{ // arrêter les frais
- if ( opt->log!=NULL ) {
- HTS_LOG(opt,LOG_WARNING); fprintf(opt->log,"Unable to test %s%s (loop)"LF,adr_complete,fil_complete);
- test_flush;
- }
+ hts_log_print(opt, LOG_WARNING, "Unable to test %s%s (loop)",adr_complete,fil_complete);
}
} // ok, leaving
}
@@ -631,13 +607,6 @@ int url_savename2(char* adr_complete, char* fil_complete, char* save,
strcpybuff(back[b].r.contenttype,"text/html"); // message d'erreur en html
// Finalement on, renvoie un erreur, pour ne toucher à rien dans le code
// libérer emplacement backing
- /*if (opt->log!=NULL) {
- fspc(opt->log,0); fprintf(opt->log,"Error: (during prefetch) %s (%d) to link %s at %s%s"LF,back[b].r.msg,back[b].r.statuscode,back[b].r.location,curr_adr,curr_fil);
- test_flush;
- }
- back_delete(opt,cache,sback,b);
- return -1; // ERREUR (404 par exemple)
- */
}
{ // pas d'erreur, changer type?
@@ -687,10 +656,7 @@ int url_savename2(char* adr_complete, char* fil_complete, char* save,
#if BDEBUG==1
printf("error while savename crash adding\n");
#endif
- if (opt->log) {
- HTS_LOG(opt,LOG_ERROR); fprintf(opt->log,"Unexpected savename backing error at %s%s"LF,adr,fil_complete);
- test_flush;
- }
+ hts_log_print(opt, LOG_ERROR, "Unexpected savename backing error at %s%s",adr,fil_complete);
}
// restaurer
@@ -729,12 +695,10 @@ int url_savename2(char* adr_complete, char* fil_complete, char* save,
if (ext_chg) { // changer ext
char* a=fil+strlen(fil)-1;
if ( (opt->debug>1) && (opt->log!=NULL) ) {
- HTS_LOG(opt,LOG_DEBUG);
if (ext_chg==1)
- fprintf(opt->log,"Changing link extension %s%s to .%s"LF,adr_complete,fil_complete,ext);
+ hts_log_print(opt, LOG_DEBUG, "Changing link extension %s%s to .%s",adr_complete,fil_complete,ext);
else
- fprintf(opt->log,"Changing link name %s%s to %s"LF,adr_complete,fil_complete,ext);
- test_flush;
+ hts_log_print(opt, LOG_DEBUG, "Changing link name %s%s to %s",adr_complete,fil_complete,ext);
}
if (ext_chg==1) {
while((a > fil) && (*a!='.') && (*a!='/')) a--;
@@ -1196,10 +1160,7 @@ int url_savename2(char* adr_complete, char* fil_complete, char* save,
if (*a!='.') { // agh pas de point
//strcatbuff(save,".none"); // a éviter
strcatbuff(save,".html"); // préférable!
- if ( (opt->debug>1) && (opt->log!=NULL) ) {
- HTS_LOG(opt,LOG_WARNING); fprintf(opt->log,"Default HTML type set for %s%s => %s"LF,adr_complete,fil_complete,save);
- test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "Default HTML type set for %s%s => %s",adr_complete,fil_complete,save);
}
}
@@ -1348,9 +1309,7 @@ int url_savename2(char* adr_complete, char* fil_complete, char* save,
if (charset != NULL && charset[0] != '\0') {
char *const s = hts_convertStringToUTF8(save, (int) strlen(save), charset);
if (s != NULL) {
- if ( (opt->debug>1) && (opt->log!=NULL) ) {
- HTS_LOG(opt,LOG_INFO); fprintf(opt->log,"engine: save-name: charset conversion from '%s' to '%s'"LF, save, s);
- }
+ hts_log_print(opt, LOG_DEBUG, "engine: save-name: charset conversion from '%s' to '%s'", save, s);
strcpybuff(save, s);
free(s);
}
@@ -1359,10 +1318,7 @@ int url_savename2(char* adr_complete, char* fil_complete, char* save,
/* callback */
RUN_CALLBACK5(opt, savename, adr_complete,fil_complete,referer_adr,referer_fil,save);
- if ( (opt->debug>0) && (opt->log!=NULL) ) {
- HTS_LOG(opt,LOG_INFO); fprintf(opt->log,"engine: save-name: local name: %s%s -> %s"LF,adr,fil,save);
- test_flush;
- }
+ hts_log_print(opt, LOG_INFO, "engine: save-name: local name: %s%s -> %s",adr,fil,save);
/* Ensure that the MANDATORY "temporary" extension is set */
if (ext_chg_delayed) {
@@ -1421,10 +1377,7 @@ int url_savename2(char* adr_complete, char* fil_complete, char* save,
// terminating \0
save[sofar + j] = '\0';
// log in debug
- if ( (opt->debug>1) && (opt->log!=NULL) ) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log, "Too long filename shortened: %s%s => %s"LF, adr_complete, fil_complete, save);
- test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "Too long filename shortened: %s%s => %s", adr_complete, fil_complete, save);
}
#undef MAX_UTF8_SEQ_CHARS
#undef MIN_LAST_SEG_RESERVE
@@ -1635,5 +1588,3 @@ void url_savename_refname_remove(httrackp* opt, const char *adr, const char *fil
char *filename = url_savename_refname_fullpath(opt, adr, fil);
(void) UNLINK(filename);
}
-
-#undef test_flush
diff --git a/src/htsopt.h b/src/htsopt.h
index 9ad8bf7..dfefed7 100644
--- a/src/htsopt.h
+++ b/src/htsopt.h
@@ -167,6 +167,19 @@ struct fspc_strc {
int info;
};
+#ifndef HTS_DEF_DEFSTRUCT_hts_log_type
+#define HTS_DEF_DEFSTRUCT_hts_log_type
+typedef enum hts_log_type {
+ LOG_DEBUG,
+ LOG_INFO,
+ LOG_NOTICE,
+ LOG_WARNING,
+ LOG_ERROR,
+ LOG_PANIC,
+ LOG_ERRNO = 1 << 8
+} hts_log_type;
+#endif
+
/* Structure état du miroir */
#ifndef HTS_DEF_FWSTRUCT_htsoptstatecancel
#define HTS_DEF_FWSTRUCT_htsoptstatecancel
diff --git a/src/htsparse.c b/src/htsparse.c
index 41d1797..5a25d88 100644
--- a/src/htsparse.c
+++ b/src/htsparse.c
@@ -77,8 +77,6 @@ Please visit our Website: http://www.httrack.com
#define relativeurlfil ((!parent_relative)?urlfil:parenturlfil)
#define relativesavename ((!parent_relative)?savename:parentsavename)
-#define test_flush if (opt->flush) { if (opt->log) { fflush(opt->log); } if (opt->log) { fflush(opt->log); } }
-
// does nothing
#define XH_uninit do {} while(0)
@@ -163,10 +161,7 @@ Please visit our Website: http://www.httrack.com
mbuff[mlen]='\0';\
if ((mlen == 32) && (strcmp(((mbuff!=NULL)?mbuff:""),digest)==0)) {\
ok=1;\
- if ( (opt->debug>1) && (opt->log!=NULL) ) {\
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"File not re-written (md5): %s"LF,savename);\
- test_flush;\
- }\
+ hts_log_print(opt, LOG_DEBUG, "File not re-written (md5): %s",savename);\
} else {\
ok=0;\
} \
@@ -182,13 +177,10 @@ Please visit our Website: http://www.httrack.com
opt->state.exit_xh=-1;\
}\
if (opt->log) { \
- int last_errno = errno; \
- HTS_LOG(opt,LOG_ERROR); fprintf(opt->log,"Unable to write HTML file %s: %s"LF, savename, strerror(last_errno));\
+ hts_log_print(opt, LOG_ERROR | LOG_ERRNO, "Unable to write HTML file %s", savename);\
if (fcheck) {\
- HTS_LOG(opt,LOG_ERROR);\
- fprintf(opt->log,"* * Fatal write error, giving up"LF);\
+ hts_log_print(opt, LOG_ERROR, "* * Fatal write error, giving up");\
}\
- test_flush;\
}\
}\
}\
@@ -198,19 +190,12 @@ Please visit our Website: http://www.httrack.com
} else {\
int fcheck;\
if ((fcheck=check_fatal_io_errno())) {\
- HTS_LOG(opt,LOG_ERROR); fprintf(opt->log,"Mirror aborted: disk full or filesystem problems"LF); \
- test_flush; \
+ hts_log_print(opt, LOG_ERROR, "Mirror aborted: disk full or filesystem problems"); \
opt->state.exit_xh=-1;\
}\
- if (opt->log) { \
- int last_errno = errno; \
- HTS_LOG(opt,LOG_ERROR);\
- fprintf(opt->log,"Unable to save file %s : %s"LF, savename, strerror(last_errno));\
- if (fcheck) {\
- HTS_LOG(opt,LOG_ERROR);\
- fprintf(opt->log,"* * Fatal write error, giving up"LF);\
- }\
- test_flush;\
+ hts_log_print(opt, LOG_ERROR | LOG_ERRNO, "Unable to save file %s", savename);\
+ if (fcheck) {\
+ hts_log_print(opt, LOG_ERROR, "* * Fatal write error, giving up");\
}\
}\
} else {\
@@ -413,9 +398,7 @@ int htsparse(htsmoduleStruct* str, htsmoduleStructExtended* stre) {
{
char* cAddr = r->adr;
int cSize = (int) r->size;
- if ( (opt->debug>0) && (opt->log!=NULL) ) {
- HTS_LOG(opt,LOG_INFO); fprintf(opt->log,"engine: preprocess-html: %s%s"LF, urladr, urlfil);
- }
+ hts_log_print(opt, LOG_DEBUG, "engine: preprocess-html: %s%s", urladr, urlfil);
if (RUN_CALLBACK4(opt, preprocess, &cAddr, &cSize, urladr, urlfil) == 1) {
r->adr = cAddr;
r->size = cSize;
@@ -425,22 +408,15 @@ int htsparse(htsmoduleStruct* str, htsmoduleStructExtended* stre) {
FILE* fp=NULL; // fichier écrit localement
char* adr=r->adr; // pointeur (on parcourt)
char* lastsaved; // adresse du dernier octet sauvé + 1
- if ( (opt->debug>1) && (opt->log!=NULL) ) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"scanning file %s%s (%s).."LF, urladr, urlfil, savename); test_flush;
- }
-
+ hts_log_print(opt, LOG_DEBUG, "scanning file %s%s (%s)..", urladr, urlfil, savename);
// Indexing!
#if HTS_MAKE_KEYWORD_INDEX
if (opt->kindex) {
if (index_keyword(r->adr,r->size,r->contenttype,savename,StringBuff(opt->path_html_utf8))) {
- if ( (opt->debug>1) && (opt->log!=NULL) ) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"indexing file..done"LF); test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "indexing file..done");
} else {
- if ( (opt->debug>1) && (opt->log!=NULL) ) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"indexing file..error!"LF); test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "indexing file..error!");
}
}
#endif
@@ -545,9 +521,7 @@ int htsparse(htsmoduleStruct* str, htsmoduleStructExtended* stre) {
inscript_name="script";
intag=1; // because après <script> on y est .. - pas utile
intag_start_valid=0; // OUI car nous sommes dans du code, plus dans du "vrai" tag
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"note: this file is a javascript file"LF); test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "note: this file is a javascript file");
// for javascript only
if (compare_mime(opt,r->contenttype, str->url_file, "application/x-javascript") != 0) {
// all links must be checked against parent, not this link
@@ -1063,7 +1037,7 @@ int htsparse(htsmoduleStruct* str, htsmoduleStructExtended* stre) {
char str[512];
str[0]='\0';
strncatbuff(str,b,minimum((int) (a - b + 1), 32));
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"active code (%s) detected in javascript: %s"LF,(check_this_fking_line==2)?"parse":"pickup",str); test_flush;
+ hts_log_print(opt, LOG_DEBUG, "active code (%s) detected in javascript: %s",(check_this_fking_line==2)?"parse":"pickup",str);
}
}
@@ -1285,10 +1259,7 @@ int htsparse(htsmoduleStruct* str, htsmoduleStructExtended* stre) {
printf("robots.txt meta tag: nofollow in %s%s\n",urladr,urlfil);
#endif
nofollow=1; // NE PLUS suivre liens dans cette page
- if (opt->log) {
- HTS_LOG(opt,LOG_WARNING); fprintf(opt->log,"Link %s%s not scanned (follow robots meta tag)"LF,urladr,urlfil);
- test_flush;
- }
+ hts_log_print(opt, LOG_WARNING, "Link %s%s not scanned (follow robots meta tag)",urladr,urlfil);
}
}
}
@@ -1470,7 +1441,7 @@ int htsparse(htsmoduleStruct* str, htsmoduleStructExtended* stre) {
char str[512];
str[0]='\0';
strncatbuff(str,a,minimum((int) (c - a + 1),32));
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"link detected in javascript: %s"LF,str); test_flush;
+ hts_log_print(opt, LOG_DEBUG, "link detected in javascript: %s",str);
}
p=(int) (a - adr); // p non nul: TRAITER CHAINE COMME FICHIER
if (can_avoid_quotes) {
@@ -1673,9 +1644,7 @@ int htsparse(htsmoduleStruct* str, htsmoduleStructExtended* stre) {
// Forbidden tag
if (nop) {
url_ok=0;
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"dirty parsing: bad tag avoided: %s"LF,hts_nodetect[i-1]); test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "dirty parsing: bad tag avoided: %s",hts_nodetect[i-1]);
}
}
}
@@ -1927,17 +1896,12 @@ int htsparse(htsmoduleStruct* str, htsmoduleStructExtended* stre) {
// 0: autorisé
// 1: interdit (patcher tout de même adresse)
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"link detected in html (tag): %s"LF,lien); test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "link detected in html (tag): %s",lien);
// external check
if (!RUN_CALLBACK1(opt, linkdetected, lien) || !RUN_CALLBACK2(opt, linkdetected2, lien, intag_start)) {
error=1; // erreur
- if (opt->log) {
- HTS_LOG(opt,LOG_ERROR); fprintf(opt->log,"Link %s refused by external wrapper"LF,lien);
- test_flush;
- }
+ hts_log_print(opt, LOG_ERROR, "Link %s refused by external wrapper",lien);
}
#if HTS_STRIP_DOUBLE_SLASH
@@ -1998,9 +1962,7 @@ int htsparse(htsmoduleStruct* str, htsmoduleStructExtended* stre) {
if (archivetag_p) {
if (strchr(lien, ',')) {
error=1; // erreur
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"link rejected (multiple-archive) %s"LF,lien); test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "link rejected (multiple-archive) %s",lien);
}
}
@@ -2131,9 +2093,7 @@ int htsparse(htsmoduleStruct* str, htsmoduleStructExtended* stre) {
// si c'est un chemin, alors vérifier (toto/toto.html -> http://www/toto/)
if (!error) {
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"position link check %s"LF,lien); test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "position link check %s",lien);
if ((p_type==2) || (p_type==-2)) { // code ou codebase
// Vérifier les codebase=applet (au lieu de applet/)
@@ -2222,9 +2182,7 @@ int htsparse(htsmoduleStruct* str, htsmoduleStructExtended* stre) {
break; // base
}
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"code/codebase link %s base %s"LF,lien,base); test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "code/codebase link %s base %s",lien,base);
//printf("base code: %s - %s\n",lien,base);
}
@@ -2250,16 +2208,11 @@ int htsparse(htsmoduleStruct* str, htsmoduleStructExtended* stre) {
strcpybuff(lien,tempo); // patcher en considérant base
// ** vérifier que ../ fonctionne (ne doit pas arriver mais bon..)
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"link modified with code/codebase %s"LF,lien); test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "link modified with code/codebase %s",lien);
}
} else {
error=1; // erreur
- if (opt->log) {
- HTS_LOG(opt,LOG_ERROR); fprintf(opt->log,"Link %s too long with base href"LF,lien);
- test_flush;
- }
+ hts_log_print(opt, LOG_ERROR, "Link %s too long with base href",lien);
}
} else {
char BIGSTK badr[HTS_URLMAXSIZE*2], bfil[HTS_URLMAXSIZE*2];
@@ -2275,15 +2228,10 @@ int htsparse(htsmoduleStruct* str, htsmoduleStructExtended* stre) {
strcatbuff(tempo,lien);
strcpybuff(lien,tempo); // patcher en considérant base
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"link modified with code/codebase %s"LF,lien); test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "link modified with code/codebase %s",lien);
} else {
error=1; // erreur
- if (opt->log) {
- HTS_LOG(opt,LOG_ERROR); fprintf(opt->log,"Link %s too long with base href"LF,lien);
- test_flush;
- }
+ hts_log_print(opt, LOG_ERROR, "Link %s too long with base href",lien);
}
}
}
@@ -2298,30 +2246,19 @@ int htsparse(htsmoduleStruct* str, htsmoduleStructExtended* stre) {
// et un chemin+fichier (adr,fil)
if (!error) {
int reponse;
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"build relative link %s with %s%s"LF,lien,relativeurladr,relativeurlfil); test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "build relative link %s with %s%s",lien,relativeurladr,relativeurlfil);
if ((reponse=ident_url_relatif(lien,relativeurladr,relativeurlfil,adr,fil))<0) {
adr[0]='\0'; // erreur
if (reponse==-2) {
- if (opt->log) {
- HTS_LOG(opt,LOG_WARNING); fprintf(opt->log,"Link %s not caught (unknown protocol)"LF,lien);
- test_flush;
- }
+ hts_log_print(opt, LOG_WARNING, "Link %s not caught (unknown protocol)",lien);
} else {
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"ident_url_relatif failed for %s with %s%s"LF,lien,relativeurladr,relativeurlfil); test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "ident_url_relatif failed for %s with %s%s",lien,relativeurladr,relativeurlfil);
}
} else {
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"built relative link %s with %s%s -> %s%s"LF,lien,relativeurladr,relativeurlfil,adr,fil); test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "built relative link %s with %s%s -> %s%s",lien,relativeurladr,relativeurlfil,adr,fil);
}
} else {
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"link %s not build, error detected before"LF,lien); test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "link %s not build, error detected before",lien);
adr[0]='\0';
}
@@ -2338,36 +2275,24 @@ int htsparse(htsmoduleStruct* str, htsmoduleStructExtended* stre) {
if (ishtml(opt,fil)==-2) { // pas d'extension
char BIGSTK loc[HTS_URLMAXSIZE*2]; // éventuelle nouvelle position
loc[0]='\0';
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"link-check-directory: %s%s"LF,adr,fil);
- test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "link-check-directory: %s%s",adr,fil);
// tester éventuelle nouvelle position
switch (http_location(adr,fil,loc).statuscode) {
case 200: // ok au final
if (strnotempty(loc)) { // a changé d'adresse
- if (opt->log) {
- HTS_LOG(opt,LOG_WARNING); fprintf(opt->log,"Link %s%s has moved to %s for %s%s"LF,adr,fil,loc,urladr,urlfil);
- test_flush;
- }
+ hts_log_print(opt, LOG_WARNING, "Link %s%s has moved to %s for %s%s",adr,fil,loc,urladr,urlfil);
// recalculer adr et fil!
if (ident_url_absolute(loc,adr,fil)==-1) {
adr[0]='\0'; // cancel
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"link-check-dir: %s%s"LF,adr,fil);
- test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "link-check-dir: %s%s",adr,fil);
}
}
break;
case -2: case -3: // timeout ou erreur grave
- if (opt->log) {
- HTS_LOG(opt,LOG_WARNING); fprintf(opt->log,"Connection too slow for testing link %s%s (from %s%s)"LF,adr,fil,urladr,urlfil);
- test_flush;
- }
+ hts_log_print(opt, LOG_WARNING, "Connection too slow for testing link %s%s (from %s%s)",adr,fil,urladr,urlfil);
break;
}
@@ -2381,10 +2306,7 @@ int htsparse(htsmoduleStruct* str, htsmoduleStructExtended* stre) {
// exemple: <FORM ACTION="url_cgi">
if (p_nocatch) {
forbidden_url=1; // interdire récupération du lien
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"link forced external at %s%s"LF,adr,fil);
- test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "link forced external at %s%s",adr,fil);
}
// Tester si un lien doit être accepté ou refusé (wizard)
@@ -2394,19 +2316,13 @@ int htsparse(htsmoduleStruct* str, htsmoduleStructExtended* stre) {
if ((p_type!=2) && (p_type!=-2)) { // tester autorisations?
if (!p_nocatch) {
if (adr[0]!='\0') {
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"wizard link test at %s%s.."LF,adr,fil);
- test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "wizard link test at %s%s..",adr,fil);
forbidden_url=hts_acceptlink(opt,ptr,lien_tot,liens,
adr,fil,
intag_name ? intag_name : NULL, intag_name ? tag_attr_start : NULL,
&set_prio_to,
&just_test_it);
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"result for wizard link test: %d"LF,forbidden_url);
- test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "result for wizard link test: %d",forbidden_url);
}
}
}
@@ -2454,19 +2370,13 @@ int htsparse(htsmoduleStruct* str, htsmoduleStructExtended* stre) {
if ((ptr>0) && (p_type!=2) && (p_type!=-2)) { // tester autorisations?
if (!p_nocatch) {
if (adr[0]!='\0') {
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"wizard moved link retest at %s%s.."LF,adr,fil);
- test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "wizard moved link retest at %s%s..",adr,fil);
forbidden_url=hts_acceptlink(opt,ptr,lien_tot,liens,
adr,fil,
intag_name ? intag_name : NULL, intag_name ? tag_attr_start : NULL,
&set_prio_to,
&just_test_it);
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"result for wizard moved link retest: %d"LF,forbidden_url);
- test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "result for wizard moved link retest: %d",forbidden_url);
}
}
}
@@ -2507,21 +2417,19 @@ int htsparse(htsmoduleStruct* str, htsmoduleStructExtended* stre) {
if (r_sv!=-1) { // pas d'erreur, on continue
/* log */
if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG);
if (forbidden_url!=1) { // le lien va être chargé
if ((p_type==2) || (p_type==-2)) { // base href ou codebase, pas un lien
- fprintf(opt->log,"Code/Codebase: %s%s"LF,adr,fil);
+ hts_log_print(opt, LOG_DEBUG, "Code/Codebase: %s%s",adr,fil);
} else if ((opt->getmode & 4)==0) {
- fprintf(opt->log,"Record: %s%s -> %s"LF,adr,fil,save);
+ hts_log_print(opt, LOG_DEBUG, "Record: %s%s -> %s",adr,fil,save);
} else {
if (!ishtml(opt,fil))
- fprintf(opt->log,"Record after: %s%s -> %s"LF,adr,fil,save);
+ hts_log_print(opt, LOG_DEBUG, "Record after: %s%s -> %s",adr,fil,save);
else
- fprintf(opt->log,"Record: %s%s -> %s"LF,adr,fil,save);
+ hts_log_print(opt, LOG_DEBUG, "Record: %s%s -> %s",adr,fil,save);
}
} else
- fprintf(opt->log,"External: %s%s"LF,adr,fil);
- test_flush;
+ hts_log_print(opt, LOG_DEBUG, "External: %s%s", adr,fil);
}
/* FIN log */
@@ -2734,10 +2642,7 @@ int htsparse(htsmoduleStruct* str, htsmoduleStructExtended* stre) {
}
// if add_class_dots_to_patch, this is because there is a problem!!
if (add_class_dots_to_patch) {
- if (opt->log) {
- HTS_LOG(opt,LOG_WARNING); fprintf(opt->log,"Error: can not rewind java path %s, check html code"LF,tempo);
- test_flush;
- }
+ hts_log_print(opt, LOG_WARNING, "Error: can not rewind java path %s, check html code",tempo);
}
}
@@ -2850,11 +2755,7 @@ int htsparse(htsmoduleStruct* str, htsmoduleStructExtended* stre) {
strcpybuff(tempo, local_save);
free(local_save);
} else {
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG);
- fprintf(opt->log, "Warning: could not build local charset representation of '%s' in '%s'"LF, tempo, str->page_charset_);
- test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "Warning: could not build local charset representation of '%s' in '%s'", tempo, str->page_charset_);
}
}
@@ -2889,10 +2790,7 @@ int htsparse(htsmoduleStruct* str, htsmoduleStructExtended* stre) {
// //escape_uri(tempo); // escape with %xx
//}
}
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"relative link at %s build with %s and %s: %s"LF,adr,save,relativesavename,tempo);
- test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "relative link at %s build with %s and %s: %s",adr,save,relativesavename,tempo);
// lien applet (code) - il faut placer un codebase avant
if (p_type==-1) { // que le nom de fichier
@@ -2913,10 +2811,7 @@ int htsparse(htsmoduleStruct* str, htsmoduleStructExtended* stre) {
}
// if add_class_dots_to_patch, this is because there is a problem!!
if (add_class_dots_to_patch) {
- if (opt->log) {
- HTS_LOG(opt,LOG_WARNING); fprintf(opt->log,"Error: can not rewind java path %s, check html code"LF,tempo);
- test_flush;
- }
+ hts_log_print(opt, LOG_WARNING, "Error: can not rewind java path %s, check html code",tempo);
}
}
@@ -2955,9 +2850,7 @@ int htsparse(htsmoduleStruct* str, htsmoduleStructExtended* stre) {
// free(local_save);
// } else {
// if ((opt->debug>1) && (opt->log!=NULL)) {
- // HTS_LOG(opt,LOG_DEBUG);
// fprintf(opt->log, "Warning: could not build local charset representation of '%s' in '%s'"LF, tempo, str->page_charset_);
- // test_flush;
// }
// }
//}
@@ -2977,10 +2870,7 @@ int htsparse(htsmoduleStruct* str, htsmoduleStructExtended* stre) {
}
lastsaved=eadr-1; // dernier écrit+1 (enfin euh apres on fait un ++ alors hein)
} else {
- if (opt->log) {
- fprintf(opt->log,"Error building relative link %s and %s"LF,save,relativesavename);
- test_flush;
- }
+ hts_log_print(opt, LOG_WARNING, "Error building relative link %s and %s",save,relativesavename);
}
} // sinon le lien sera écrit normalement
@@ -2989,31 +2879,22 @@ int htsparse(htsmoduleStruct* str, htsmoduleStructExtended* stre) {
if (fexist(save)) { // le fichier existe..
adr[0]='\0';
//if ((opt->debug>0) && (opt->log!=NULL)) {
- if (opt->log) {
- HTS_LOG(opt,LOG_WARNING); fprintf(opt->log,"Link has already been written on disk, cancelled: %s"LF,save);
- test_flush;
- }
+ hts_log_print(opt, LOG_WARNING, "Link has already been written on disk, cancelled: %s",save);
}
#endif
/* Security check */
if (strlen(save) >= HTS_URLMAXSIZE) {
adr[0]='\0';
- if (opt->log) {
- HTS_LOG(opt,LOG_WARNING); fprintf(opt->log,"Link is too long: %s"LF,save);
- test_flush;
- }
+ hts_log_print(opt, LOG_WARNING, "Link is too long: %s",save);
}
if ((adr[0]!='\0') && (p_type!=2) && (p_type!=-2) && (forbidden_url!=1) ) { // si le fichier n'existe pas, ajouter à la liste
// n'y a-t-il pas trop de liens?
if (lien_tot+1 >= lien_max-4) { // trop de liens!
printf("PANIC! : Too many URLs : >%d [%d]\n",lien_tot,__LINE__);
- if (opt->log) {
- fprintf(opt->log,LF"Too many URLs, giving up..(>%d)"LF,lien_max);
- fprintf(opt->log,"To avoid that: use #L option for more links (example: -#L1000000)"LF);
- test_flush;
- }
+ hts_log_print(opt, LOG_PANIC, "Too many URLs, giving up..(>%d)",lien_max);
+ hts_log_print(opt, LOG_INFO, "To avoid that: use #L option for more links (example: -#L1000000)");
if ((opt->getmode & 1) && (ptr>0)) { if (fp) { fclose(fp); fp=NULL; } }
XH_uninit; // désallocation mémoire & buffers
return -1;
@@ -3055,8 +2936,7 @@ int htsparse(htsmoduleStruct* str, htsmoduleStructExtended* stre) {
strcmp(adr, liens[i]->adr) != 0
|| strcmp(fil, liens[i]->fil) != 0
) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"merging similar links %s%s and %s%s"LF,adr,fil,liens[i]->adr,liens[i]->fil);
- test_flush;
+ hts_log_print(opt, LOG_DEBUG, "merging similar links %s%s and %s%s",adr,fil,liens[i]->adr,liens[i]->fil);
}
}
liens[i]->depth=maximum(liens[i]->depth,liens[ptr]->depth - 1);
@@ -3092,10 +2972,7 @@ int htsparse(htsmoduleStruct* str, htsmoduleStructExtended* stre) {
liens_record(adr,"/robots.txt","","","");
if (liens[lien_tot]==NULL) { // erreur, pas de place réservée
printf("PANIC! : Not enough memory [%d]\n",__LINE__);
- if (opt->log) {
- fprintf(opt->log,"Not enough memory, can not re-allocate %d bytes"LF,(int)((add_tab_alloc+1)*sizeof(lien_url)));
- test_flush;
- }
+ hts_log_print(opt, LOG_PANIC, "Not enough memory, can not re-allocate %d bytes",(int)((add_tab_alloc+1)*sizeof(lien_url)));
if ((opt->getmode & 1) && (ptr>0)) { if (fp) { fclose(fp); fp=NULL; } }
XH_uninit; // désallocation mémoire & buffers
return -1;
@@ -3111,15 +2988,9 @@ int htsparse(htsmoduleStruct* str, htsmoduleStructExtended* stre) {
#if DEBUG_ROBOTS
printf("robots.txt: added file robots.txt for %s\n",adr);
#endif
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"robots.txt added at %s"LF,adr);
- test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "robots.txt added at %s",adr);
} else {
- if (opt->log) {
- fprintf(opt->log,"Unexpected robots.txt error at %d"LF,__LINE__);
- test_flush;
- }
+ hts_log_print(opt, LOG_ERROR, "Unexpected robots.txt error at %d",__LINE__);
}
}
}
@@ -3132,10 +3003,7 @@ int htsparse(htsmoduleStruct* str, htsmoduleStructExtended* stre) {
liens_record(adr,fil,save,former_adr,former_fil);
if (liens[lien_tot]==NULL) { // erreur, pas de place réservée
printf("PANIC! : Not enough memory [%d]\n",__LINE__);
- if (opt->log) {
- fprintf(opt->log,"Not enough memory, can not re-allocate %d bytes"LF,(int)((add_tab_alloc+1)*sizeof(lien_url)));
- test_flush;
- }
+ hts_log_print(opt, LOG_PANIC, "Not enough memory, can not re-allocate %d bytes",(int)((add_tab_alloc+1)*sizeof(lien_url)));
if ((opt->getmode & 1) && (ptr>0)) { if (fp) { fclose(fp); fp=NULL; } }
XH_uninit; // désallocation mémoire & buffers
return -1;
@@ -3170,21 +3038,15 @@ int htsparse(htsmoduleStruct* str, htsmoduleStructExtended* stre) {
//strcpybuff(liens[lien_tot]->adr,adr);
//strcpybuff(liens[lien_tot]->fil,fil);
//strcpybuff(liens[lien_tot]->sav,save);
- if ((opt->debug>1) && (opt->log!=NULL)) {
- if (!just_test_it) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"OK, NOTE: %s%s -> %s"LF,liens[lien_tot]->adr,liens[lien_tot]->fil,liens[lien_tot]->sav);
- } else {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"OK, TEST: %s%s"LF,liens[lien_tot]->adr,liens[lien_tot]->fil);
- }
- test_flush;
+ if (!just_test_it) {
+ hts_log_print(opt, LOG_DEBUG, "OK, NOTE: %s%s -> %s",liens[lien_tot]->adr,liens[lien_tot]->fil,liens[lien_tot]->sav);
+ } else {
+ hts_log_print(opt, LOG_DEBUG, "OK, TEST: %s%s",liens[lien_tot]->adr,liens[lien_tot]->fil);
}
lien_tot++; // UN LIEN DE PLUS
} else { // if !dejafait
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"link has already been recorded, cancelled: %s"LF,save);
- test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "link has already been recorded, cancelled: %s",save);
}
@@ -3294,10 +3156,7 @@ int htsparse(htsmoduleStruct* str, htsmoduleStructExtended* stre) {
HTS_STAT.nb=back_transfered(HTS_STAT.stat_bytes,sback);
if (!RUN_CALLBACK7(opt, loop, sback->lnk, sback->count, 0,ptr,lien_tot,(int) (time_local()-HTS_STAT.stat_timestart),&HTS_STAT)) {
- if (opt->log) {
- HTS_LOG(opt,LOG_INFO); fprintf(opt->log,"Exit requested by shell or user"LF);
- test_flush;
- }
+ hts_log_print(opt, LOG_ERROR, "Exit requested by shell or user");
*stre->exit_xh_=1; // exit requested
XH_uninit;
return -1;
@@ -3324,9 +3183,7 @@ int htsparse(htsmoduleStruct* str, htsmoduleStructExtended* stre) {
{
char* cAddr = ht_buff;
int cSize = (int) ht_len;
- if ( (opt->debug>0) && (opt->log!=NULL) ) {
- HTS_LOG(opt,LOG_INFO); fprintf(opt->log,"engine: postprocess-html: %s%s"LF, urladr, urlfil);
- }
+ hts_log_print(opt, LOG_DEBUG, "engine: postprocess-html: %s%s", urladr, urlfil);
if (RUN_CALLBACK4(opt, postprocess, &cAddr, &cSize, urladr, urlfil) == 1) {
ht_buff = cAddr;
ht_len = cSize;
@@ -3381,12 +3238,7 @@ int hts_mirror_check_moved(htsmoduleStruct* str, htsmoduleStructExtended* stre)
char *rn=NULL;
// char* p;
- if ( (opt->debug>0) && (opt->log!=NULL) ) {
- //if (opt->log) {
- HTS_LOG(opt,LOG_WARNING); fprintf(opt->log,"%s for %s%s"LF,r->msg,urladr,urlfil);
- test_flush;
- }
-
+ hts_log_print(opt, LOG_WARNING, "%s for %s%s",r->msg,urladr,urlfil);
{
char BIGSTK mov_url[HTS_URLMAXSIZE*2],mov_adr[HTS_URLMAXSIZE*2],mov_fil[HTS_URLMAXSIZE*2];
@@ -3411,10 +3263,7 @@ int hts_mirror_check_moved(htsmoduleStruct* str, htsmoduleStructExtended* stre)
(void) adr_normalized(urladr, pn_adr);
(void) fil_normalized(urlfil, pn_fil);
if (strcasecmp(n_adr, pn_adr) == 0 && strcasecmp(n_fil, pn_fil) == 0) {
- if (opt->log) {
- HTS_LOG(opt,LOG_WARNING); fprintf(opt->log,"Redirected link is identical because of 'URL Hack' option: %s%s and %s%s"LF, urladr, urlfil, mov_adr, mov_fil);
- test_flush;
- }
+ hts_log_print(opt, LOG_WARNING, "Redirected link is identical because of 'URL Hack' option: %s%s and %s%s", urladr, urlfil, mov_adr, mov_fil);
}
}
@@ -3427,20 +3276,14 @@ int hts_mirror_check_moved(htsmoduleStruct* str, htsmoduleStructExtended* stre)
if (strcmp(mov_fil,urlfil)==0) {
error=1;
get_it=-1; // ne rien faire
- if (opt->log) {
- HTS_LOG(opt,LOG_WARNING); fprintf(opt->log,"Can not bear crazy server (%s) for %s%s"LF,r->msg,urladr,urlfil);
- test_flush;
- }
+ hts_log_print(opt, LOG_WARNING, "Can not bear crazy server (%s) for %s%s",r->msg,urladr,urlfil);
} else { // mauvaise casse, effacer entrée dans la pile et rejouer une fois
get_it=1;
}
} else { // adresse différente
if (ishtml(opt,mov_url)==0) { // pas même adresse MAIS c'est un fichier non html (pas de page moved possible)
// -> on prend à cette adresse, le lien sera enregistré avec lien_record() (hash)
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"wizard link test for moved file at %s%s.."LF,mov_adr,mov_fil);
- test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "wizard link test for moved file at %s%s..",mov_adr,mov_fil);
// accepté?
if (hts_acceptlink(opt,ptr,lien_tot,liens,
mov_adr,mov_fil,
@@ -3448,10 +3291,7 @@ int hts_mirror_check_moved(htsmoduleStruct* str, htsmoduleStructExtended* stre)
&set_prio_to,
NULL) != 1) { /* nouvelle adresse non refusée ? */
get_it=1;
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"moved link accepted: %s%s"LF,mov_adr,mov_fil);
- test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "moved link accepted: %s%s",mov_adr,mov_fil);
}
} /* sinon traité normalement */
}
@@ -3460,10 +3300,7 @@ int hts_mirror_check_moved(htsmoduleStruct* str, htsmoduleStructExtended* stre)
if (get_it==1) {
// court-circuiter le reste du traitement
// et reculer pour mieux sauter
- if (opt->log) {
- HTS_LOG(opt,LOG_WARNING); fprintf(opt->log,"Warning moved treated for %s%s (real one is %s%s)"LF,urladr,urlfil,mov_adr,mov_fil);
- test_flush;
- }
+ hts_log_print(opt, LOG_WARNING, "Warning moved treated for %s%s (real one is %s%s)",urladr,urlfil,mov_adr,mov_fil);
// canceller lien actuel
error=1;
strcpybuff(liens[ptr]->adr,"!"); // caractère bidon (invalide hash)
@@ -3494,19 +3331,13 @@ int hts_mirror_check_moved(htsmoduleStruct* str, htsmoduleStructExtended* stre)
lien_tot++;
} else { // oups erreur, plus de mémoire!!
printf("PANIC! : Not enough memory [%d]\n",__LINE__);
- if (opt->log) {
- fprintf(opt->log,"Not enough memory, can not re-allocate %d bytes"LF,(int)((add_tab_alloc+1)*sizeof(lien_url)));
- test_flush;
- }
+ hts_log_print(opt, LOG_PANIC, "Not enough memory, can not re-allocate %d bytes",(int)((add_tab_alloc+1)*sizeof(lien_url)));
//if (opt->getmode & 1) { if (fp) { fclose(fp); fp=NULL; } }
XH_uninit; // désallocation mémoire & buffers
return 0;
}
} else {
- if ( (opt->debug>0) && (opt->log!=NULL) ) {
- HTS_LOG(opt,LOG_WARNING); fprintf(opt->log,"moving %s to an existing file %s"LF,liens[ptr]->fil,urlfil);
- test_flush;
- }
+ hts_log_print(opt, LOG_INFO, "moving %s to an existing file %s",liens[ptr]->fil,urlfil);
}
}
@@ -3523,10 +3354,7 @@ int hts_mirror_check_moved(htsmoduleStruct* str, htsmoduleStructExtended* stre)
if (get_it==0) { // adresse vraiment différente et potentiellement en html (pas de possibilité de bouger la page tel quel à cause des <img src..> et cie)
rn=(char*) calloct(8192,1);
if (rn!=NULL) {
- if (opt->log) {
- HTS_LOG(opt,LOG_WARNING); fprintf(opt->log,"File has moved from %s%s to %s"LF,urladr,urlfil,mov_url);
- test_flush;
- }
+ hts_log_print(opt, LOG_WARNING, "File has moved from %s%s to %s",urladr,urlfil,mov_url);
if (!opt->mimehtml) {
escape_uri(mov_url);
} else {
@@ -3577,11 +3405,7 @@ int hts_mirror_check_moved(htsmoduleStruct* str, htsmoduleStructExtended* stre)
#if HDEBUG
printf("Partial content NOT up-to-date, reget all file for %s\n",liens[ptr]->sav);
#endif
- if ( (opt->debug>1) && (opt->log!=NULL) ) {
- //if (opt->log) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"Partial file reget (%s) for %s%s"LF,r->msg,urladr,urlfil);
- test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "Partial file reget (%s) for %s%s",r->msg,urladr,urlfil);
// enregistrer le MEME lien (MACRO)
liens_record(liens[ptr]->adr,liens[ptr]->fil,liens[ptr]->sav,"","");
if (liens[lien_tot]!=NULL) { // OK, pas d'erreur
@@ -3600,27 +3424,18 @@ int hts_mirror_check_moved(htsmoduleStruct* str, htsmoduleStructExtended* stre)
//
} else { // oups erreur, plus de mémoire!!
printf("PANIC! : Not enough memory [%d]\n",__LINE__);
- if (opt->log) {
- fprintf(opt->log,"Not enough memory, can not re-allocate %d bytes"LF,(int)((add_tab_alloc+1)*sizeof(lien_url)));
- test_flush;
- }
+ hts_log_print(opt, LOG_PANIC, "Not enough memory, can not re-allocate %d bytes",(int)((add_tab_alloc+1)*sizeof(lien_url)));
//if (opt->getmode & 1) { if (fp) { fclose(fp); fp=NULL; } }
XH_uninit; // désallocation mémoire & buffers
return 0;
}
} else {
- if (opt->log!=NULL) {
- HTS_LOG(opt,LOG_ERROR); fprintf(opt->log,"Can not remove old file %s"LF,urlfil);
- test_flush;
- error = 1;
- }
- }
- } else {
- if (opt->log!=NULL) {
- HTS_LOG(opt,LOG_WARNING); fprintf(opt->log,"Unexpected 412/416 error (%s) for %s%s, '%s' could not be found on disk"LF,r->msg,urladr,urlfil,liens[ptr]->sav != NULL ? liens[ptr]->sav : "");
- test_flush;
+ hts_log_print(opt, LOG_ERROR, "Can not remove old file %s",urlfil);
error = 1;
}
+ } else {
+ hts_log_print(opt, LOG_WARNING, "Unexpected 412/416 error (%s) for %s%s, '%s' could not be found on disk",r->msg,urladr,urlfil,liens[ptr]->sav != NULL ? liens[ptr]->sav : "");
+ error = 1;
}
// Error ?
@@ -3641,26 +3456,18 @@ int hts_mirror_check_moved(htsmoduleStruct* str, htsmoduleStructExtended* stre)
case STATUSCODE_TIMEOUT:
if (opt->hostcontrol) { // timeout et retry épuisés
if ((opt->hostcontrol & 1) && (liens[ptr]->retry<=0)) {
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"Link banned: %s%s"LF,urladr,urlfil); test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "Link banned: %s%s",urladr,urlfil);
host_ban(opt,liens,ptr,lien_tot,sback,jump_identification(urladr));
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"Info: previous log - link banned: %s%s"LF,urladr,urlfil); test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "Info: previous log - link banned: %s%s",urladr,urlfil);
} else can_retry=1;
} else can_retry=1;
break;
case STATUSCODE_SLOW:
if ((opt->hostcontrol) && (liens[ptr]->retry<=0)) { // too slow
if (opt->hostcontrol & 2) {
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"Link banned: %s%s"LF,urladr,urlfil); test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "Link banned: %s%s",urladr,urlfil);
host_ban(opt,liens,ptr,lien_tot,sback,jump_identification(urladr));
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"Info: previous log - link banned: %s%s"LF,urladr,urlfil); test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "Info: previous log - link banned: %s%s",urladr,urlfil);
} else can_retry=1;
} else can_retry=1;
break;
@@ -3680,29 +3487,18 @@ int hts_mirror_check_moved(htsmoduleStruct* str, htsmoduleStructExtended* stre)
if ( strcmp(liens[ptr]->fil,"/primary") != 0 ) { // no primary (internal page 0)
if ((liens[ptr]->retry<=0) || (!can_retry) ) { // retry épuisés (ou retry impossible)
- if (opt->log) {
- if ((opt->retry>0) && (can_retry)){
- HTS_LOG(opt,LOG_ERROR);
- fprintf(opt->log,"\"%s\" (%d) after %d retries at link %s%s (from %s%s)"LF,r->msg,r->statuscode,opt->retry,urladr,urlfil,liens[liens[ptr]->precedent]->adr,liens[liens[ptr]->precedent]->fil);
+ if ((opt->retry>0) && (can_retry)){
+ hts_log_print(opt, LOG_ERROR, "\"%s\" (%d) after %d retries at link %s%s (from %s%s)",r->msg,r->statuscode,opt->retry,urladr,urlfil,liens[liens[ptr]->precedent]->adr,liens[liens[ptr]->precedent]->fil);
+ } else {
+ if (r->statuscode==STATUSCODE_TEST_OK) { // test OK
+ hts_log_print(opt, LOG_INFO, "Test OK at link %s%s (from %s%s)",urladr,urlfil,liens[liens[ptr]->precedent]->adr,liens[liens[ptr]->precedent]->fil);
} else {
- if (r->statuscode==STATUSCODE_TEST_OK) { // test OK
- if ((opt->debug>0) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_INFO);
- fprintf(opt->log,"Test OK at link %s%s (from %s%s)"LF,urladr,urlfil,liens[liens[ptr]->precedent]->adr,liens[liens[ptr]->precedent]->fil);
- }
+ if (strcmp(urlfil,"/robots.txt")) { // ne pas afficher d'infos sur robots.txt par défaut
+ hts_log_print(opt, LOG_ERROR, "\"%s\" (%d) at link %s%s (from %s%s)",r->msg,r->statuscode,urladr,urlfil,liens[liens[ptr]->precedent]->adr,liens[liens[ptr]->precedent]->fil);
} else {
- if (strcmp(urlfil,"/robots.txt")) { // ne pas afficher d'infos sur robots.txt par défaut
- HTS_LOG(opt,LOG_ERROR);
- fprintf(opt->log,"\"%s\" (%d) at link %s%s (from %s%s)"LF,r->msg,r->statuscode,urladr,urlfil,liens[liens[ptr]->precedent]->adr,liens[liens[ptr]->precedent]->fil);
- } else {
- if (opt->debug>1) {
- HTS_LOG(opt,LOG_INFO); fprintf(opt->log,"No robots.txt rules at %s"LF,urladr);
- test_flush;
- }
- }
+ hts_log_print(opt, LOG_DEBUG, "No robots.txt rules at %s",urladr);
}
}
- test_flush;
}
// NO error in trop level
@@ -3730,10 +3526,7 @@ int hts_mirror_check_moved(htsmoduleStruct* str, htsmoduleStructExtended* stre)
}
} else { // retry!!
- if (opt->debug>0 && opt->log != NULL) { // on fera un alert si le retry échoue
- HTS_LOG(opt,LOG_WARNING); fprintf(opt->log,"Retry after error %d (%s) at link %s%s (from %s%s)"LF,r->statuscode,r->msg,urladr,urlfil,liens[liens[ptr]->precedent]->adr,liens[liens[ptr]->precedent]->fil);
- test_flush;
- }
+ hts_log_print(opt, LOG_NOTICE, "Retry after error %d (%s) at link %s%s (from %s%s)",r->statuscode,r->msg,urladr,urlfil,liens[liens[ptr]->precedent]->adr,liens[liens[ptr]->precedent]->fil);
// redemander fichier
liens_record(urladr,urlfil,savename,"","");
if (liens[lien_tot]!=NULL) { // OK, pas d'erreur
@@ -3747,23 +3540,14 @@ int hts_mirror_check_moved(htsmoduleStruct* str, htsmoduleStructExtended* stre)
lien_tot++;
} else { // oups erreur, plus de mémoire!!
printf("PANIC! : Not enough memory [%d]\n",__LINE__);
- if (opt->log) {
- HTS_LOG(opt,LOG_PANIC);
- fprintf(opt->log,"Not enough memory, can not re-allocate %d bytes"LF,(int)((add_tab_alloc+1)*sizeof(lien_url)));
- test_flush;
- }
+ hts_log_print(opt, LOG_PANIC, "Not enough memory, can not re-allocate %d bytes",(int)((add_tab_alloc+1)*sizeof(lien_url)));
//if (opt->getmode & 1) { if (fp) { fclose(fp); fp=NULL; } }
XH_uninit; // désallocation mémoire & buffers
return 0;
}
}
} else {
- if (opt->log) {
- if (opt->debug>1) {
- HTS_LOG(opt,LOG_INFO);
- fprintf(opt->log,"Info: no robots.txt at %s%s"LF,urladr,urlfil);
- }
- }
+ hts_log_print(opt, LOG_DEBUG, "Info: no robots.txt at %s%s",urladr,urlfil);
}
if (!store_errpage) {
if (r->adr) { // désalloc
@@ -3822,9 +3606,7 @@ void hts_mirror_process_user_interaction(htsmoduleStruct* str, htsmoduleStructEx
// pause?
if (do_pause) {
- if ( (opt->debug>0) && (opt->log!=NULL) ) {
- HTS_LOG(opt,LOG_INFO); fprintf(opt->log,"engine: pause requested.."LF);
- }
+ hts_log_print(opt, LOG_INFO, "engine: pause requested..");
while (back_nsoc(sback)>0) { // attendre fin des transferts
back_wait(sback,opt,cache,HTS_STAT.stat_timestart);
Sleep(200);
@@ -3845,10 +3627,7 @@ void hts_mirror_process_user_interaction(htsmoduleStruct* str, htsmoduleStructEx
b=0;
if (!RUN_CALLBACK7(opt, loop, sback->lnk, sback->count, b,ptr,lien_tot,(int) (time_local()-HTS_STAT.stat_timestart),&HTS_STAT)
|| !back_checkmirror(opt)) {
- if (opt->log) {
- HTS_LOG(opt,LOG_INFO); fprintf(opt->log,"Exit requested by shell or user"LF);
- test_flush;
- }
+ hts_log_print(opt, LOG_ERROR, "Exit requested by shell or user");
*stre->exit_xh_=1; // exit requested
XH_uninit;
return ;
@@ -3868,9 +3647,7 @@ void hts_mirror_process_user_interaction(htsmoduleStruct* str, htsmoduleStructEx
}
stat_fragment=HTS_STAT.stat_bytes;
/* Info for wrappers */
- if ( (opt->debug>0) && (opt->log!=NULL) ) {
- HTS_LOG(opt,LOG_INFO); fprintf(opt->log,"engine: pause: %s"LF,fconcat(OPT_GET_BUFF(opt), StringBuff(opt->path_log),"hts-paused.lock"));
- }
+ hts_log_print(opt, LOG_INFO, "engine: pause: %s",fconcat(OPT_GET_BUFF(opt), StringBuff(opt->path_log),"hts-paused.lock"));
RUN_CALLBACK1(opt, pause, fconcat(OPT_GET_BUFF(opt), StringBuff(opt->path_log),"hts-paused.lock"));
}
//
@@ -3906,34 +3683,22 @@ void hts_mirror_process_user_interaction(htsmoduleStruct* str, htsmoduleStructEx
liens[lien_tot]->precedent=lien_tot;
lien_tot++;
//
- if ((opt->debug>0) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_INFO); fprintf(opt->log,"Link added by user: %s%s"LF,add_adr,add_fil); test_flush;
- }
+ hts_log_print(opt, LOG_INFO, "Link added by user: %s%s",add_adr,add_fil);
//
} else { // oups erreur, plus de mémoire!!
printf("PANIC! : Not enough memory [%d]\n",__LINE__);
- if (opt->log) {
- fprintf(opt->log,"Not enough memory, can not re-allocate %d bytes"LF,(int)((add_tab_alloc+1)*sizeof(lien_url)));
- test_flush;
- }
+ hts_log_print(opt, LOG_PANIC, "Not enough memory, can not re-allocate %d bytes",(int)((add_tab_alloc+1)*sizeof(lien_url)));
//if (opt->getmode & 1) { if (fp) { fclose(fp); fp=NULL; } }
XH_uninit; // désallocation mémoire & buffers
return ;
}
} else {
- if ( (opt->debug>0) && (opt->log!=NULL) ) {
- HTS_LOG(opt,LOG_WARNING); fprintf(opt->log,"Existing link %s%s not added after user request"LF,add_adr,add_fil);
- test_flush;
- }
+ hts_log_print(opt, LOG_NOTICE, "Existing link %s%s not added after user request",add_adr,add_fil);
}
}
} else {
- if (opt->log) {
- HTS_LOG(opt,LOG_ERROR);
- fprintf(opt->log,"Error during URL decoding for %s"LF,add_url);
- test_flush;
- }
+ hts_log_print(opt, LOG_ERROR, "Error during URL decoding for %s",add_url);
}
// ----Fin Ajout----
opt->state._hts_addurl++; // suivante
@@ -3962,10 +3727,7 @@ void hts_mirror_process_user_interaction(htsmoduleStruct* str, htsmoduleStructEx
HTS_STAT.nb=back_transfered(HTS_STAT.stat_bytes,sback);
if (!RUN_CALLBACK7(opt, loop, sback->lnk, sback->count, b,ptr,lien_tot,(int) (time_local()-HTS_STAT.stat_timestart),&HTS_STAT)) {
- if (opt->log) {
- HTS_LOG(opt,LOG_INFO); fprintf(opt->log,"Exit requested by shell or user"LF);
- test_flush;
- }
+ hts_log_print(opt, LOG_ERROR, "Exit requested by shell or user");
*stre->exit_xh_=1; // exit requested
XH_uninit;
return ;
@@ -3990,7 +3752,7 @@ int hts_mirror_wait_for_next_file(htsmoduleStruct* str, htsmoduleStructExtended*
/* This is not supposed to hapen. */
if (liens[ptr]->pass2 == -1) {
- HTS_LOG(opt, LOG_WARNING); fprintf(opt->log, "Link is already ready %s%s"LF, urladr, urlfil);
+ hts_log_print(opt, LOG_WARNING, "Link is already ready %s%s", urladr, urlfil);
}
/* User interaction */
@@ -4002,9 +3764,7 @@ int hts_mirror_wait_for_next_file(htsmoduleStruct* str, htsmoduleStructExtended*
/* Done while processing user interactions ? */
if (liens[ptr]->pass2 == -1) {
- if ( (opt->debug>0) && (opt->log!=NULL) ) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log, "Link is now ready %s%s"LF, urladr, urlfil);
- }
+ hts_log_print(opt, LOG_DEBUG, "Link is now ready %s%s", urladr, urlfil);
// We are ready
return 2; // goto jump_if_done;
}
@@ -4019,10 +3779,7 @@ int hts_mirror_wait_for_next_file(htsmoduleStruct* str, htsmoduleStructExtended*
#if BDEBUG==1
printf("error while crash adding\n");
#endif
- if (opt->log) {
- HTS_LOG(opt,LOG_ERROR); fprintf(opt->log,"Unexpected backing error for %s%s"LF,urladr,urlfil);
- test_flush;
- }
+ hts_log_print(opt, LOG_ERROR, "Unexpected backing error for %s%s",urladr,urlfil);
}
}
@@ -4074,6 +3831,7 @@ int hts_mirror_wait_for_next_file(htsmoduleStruct* str, htsmoduleStructExtended*
// Stop the mirror
if (!back_checkmirror(opt)) {
+ hts_log_print(opt, LOG_ERROR, "Exit requested by shell or user");
*stre->exit_xh_=1; // exit requested
XH_uninit;
return 0;
@@ -4155,10 +3913,7 @@ int hts_mirror_wait_for_next_file(htsmoduleStruct* str, htsmoduleStructExtended*
HTS_STAT.nb=back_transfered(HTS_STAT.stat_bytes,sback);
if (!RUN_CALLBACK7(opt, loop, sback->lnk, sback->count, b,ptr,lien_tot,(int) (time_local()-HTS_STAT.stat_timestart),&HTS_STAT)) {
- if (opt->log) {
- HTS_LOG(opt,LOG_INFO); fprintf(opt->log,"Exit requested by shell or user"LF);
- test_flush;
- }
+ hts_log_print(opt, LOG_ERROR, "Exit requested by shell or user");
*stre->exit_xh_=1; // exit requested
XH_uninit;
return 0;
@@ -4181,9 +3936,7 @@ int hts_mirror_wait_for_next_file(htsmoduleStruct* str, htsmoduleStructExtended*
else
opt->verbosedisplay=2;
/* Info for wrappers */
- if ( (opt->debug>0) && (opt->log!=NULL) ) {
- HTS_LOG(opt,LOG_INFO); fprintf(opt->log,"engine: change-options"LF);
- }
+ hts_log_print(opt, LOG_INFO, "engine: change-options");
RUN_CALLBACK0(opt, chopt);
}
}
@@ -4241,10 +3994,7 @@ int hts_mirror_wait_for_next_file(htsmoduleStruct* str, htsmoduleStructExtended*
// in background
// Then, skip it and go to the next one
if (b<0) {
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"link #%d is ready, no more on the stack, skipping: %s%s.."LF,ptr,urladr,urlfil);
- test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "link #%d is ready, no more on the stack, skipping: %s%s..",ptr,urladr,urlfil);
// prochain lien
// ptr++;
@@ -4262,14 +4012,9 @@ int hts_mirror_wait_for_next_file(htsmoduleStruct* str, htsmoduleStructExtended*
/* ensure correct location buffer set */
back[b].r.location=back[b].location_buffer;
if (back[b].r.statuscode == STATUSCODE_INVALID) {
- if (opt->log) {
- HTS_LOG(opt,LOG_ERROR); fprintf(opt->log,"Unexpected error: %s%s not found anymore in cache"LF,back[b].url_adr,back[b].url_fil);
- test_flush;
- }
+ hts_log_print(opt, LOG_ERROR, "Unexpected error: %s%s not found anymore in cache",back[b].url_adr,back[b].url_fil);
} else {
- if ( (opt->debug>1) && (opt->log!=NULL) ) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"reclaim file %s%s (%d)"LF,back[b].url_adr,back[b].url_fil,back[b].r.statuscode); test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "reclaim file %s%s (%d)",back[b].url_adr,back[b].url_fil,back[b].r.statuscode);
}
}
#endif
@@ -4288,7 +4033,7 @@ int hts_mirror_wait_for_next_file(htsmoduleStruct* str, htsmoduleStructExtended*
else
printf("%d/%d: %s%s ("LLintP" bytes) - %d\33[K\r",ptr,lien_tot,back[b].url_adr,back[b].url_fil,(LLint)back[b].r.size,back[b].r.statuscode);
} else {
- HTS_LOG(opt,LOG_ERROR); fprintf(opt->log,"Link disappeared");
+ hts_log_print(opt, LOG_ERROR, "Link disappeared");
}
fflush(stdout);
}
@@ -4374,10 +4119,7 @@ int hts_wait_delayed(htsmoduleStruct* str,
{
int loops;
int continue_loop;
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"Waiting for type to be known: %s%s"LF, adr, fil);
- test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "Waiting for type to be known: %s%s", adr, fil);
/* Follow while type is unknown and redirects occurs */
for( loops = 0, continue_loop = 1 ; IS_DELAYED_EXT(save) && continue_loop && loops < 7 ; loops++ ) {
@@ -4394,10 +4136,7 @@ int hts_wait_delayed(htsmoduleStruct* str,
memset(&back, 0, sizeof(back));
back.r = cache_read(opt, cache, adr, fil, NULL, NULL); // test uniquement
if (back.r.statuscode == HTTP_OK && strnotempty(back.r.contenttype)) { // cache found, and aswer is 'OK'
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"Direct type lookup in cache (-%%D1): %s"LF, back.r.contenttype);
- test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "Direct type lookup in cache (-%%D1): %s", back.r.contenttype);
/* Recompute filename with MIME type */
save[0] = '\0';
@@ -4407,16 +4146,10 @@ int hts_wait_delayed(htsmoduleStruct* str,
{
int new_forbidden_url = hts_acceptmime(opt, ptr, lien_tot, liens, adr,fil, back.r.contenttype);
if (new_forbidden_url != -1) {
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"result for wizard mime test: %d"LF,new_forbidden_url);
- test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "result for wizard mime test: %d",new_forbidden_url);
if (new_forbidden_url == 1) {
*forbidden_url = new_forbidden_url;
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"link forbidden because of MIME types restrictions: %s%s"LF, adr, fil);
- test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "link forbidden because of MIME types restrictions: %s%s", adr, fil);
break; // exit loop
}
}
@@ -4430,10 +4163,7 @@ int hts_wait_delayed(htsmoduleStruct* str,
/* Check if the file was recorded already (necessary for redirects) */
if (hash_read(hash,save,"",0,opt->urlhack) >= 0) {
if (loops == 0) { /* Should not happend */
- if ( opt->log!=NULL ) {
- HTS_LOG(opt,LOG_ERROR); fprintf(opt->log, "Duplicate entry in hts_wait_delayed() cancelled: %s%s -> %s"LF,adr,fil,save);
- test_flush;
- }
+ hts_log_print(opt, LOG_ERROR, "Duplicate entry in hts_wait_delayed() cancelled: %s%s -> %s",adr,fil,save);
}
/* Exit loop (we're done) */
continue_loop = 0;
@@ -4475,16 +4205,10 @@ int hts_wait_delayed(htsmoduleStruct* str,
{
int new_forbidden_url = hts_acceptmime(opt, ptr, lien_tot, liens, adr,fil, delayed_back.r.contenttype);
if (new_forbidden_url != -1) {
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"result for wizard mime test: %d"LF,*forbidden_url);
- test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "result for wizard mime test: %d",*forbidden_url);
if (new_forbidden_url == 1) {
*forbidden_url = new_forbidden_url;
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"link forbidden because of MIME types restrictions: %s%s"LF, adr, fil);
- test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "link forbidden because of MIME types restrictions: %s%s", adr, fil);
break; // exit loop
}
}
@@ -4503,10 +4227,7 @@ int hts_wait_delayed(htsmoduleStruct* str,
/* We added the link before the parser recorded it -- the background download MUST NOT clean silently this entry! (Petr Gajdusek) */
back[b].early_add = 1;
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"Type immediately loaded from cache: %s"LF, delayed_back.r.contenttype);
- test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "Type immediately loaded from cache: %s", delayed_back.r.contenttype);
}
/* Wait for headers to be received */
@@ -4603,10 +4324,7 @@ int hts_wait_delayed(htsmoduleStruct* str,
mov_adr[0]=mov_fil[0]='\0';
//
if (ident_url_relatif(mov_url,adr,fil,mov_adr,mov_fil)>=0) {
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"Redirect while resolving type: %s%s -> %s%s"LF, adr, fil, mov_adr, mov_fil);
- test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "Redirect while resolving type: %s%s -> %s%s", adr, fil, mov_adr, mov_fil);
// si non bouclage sur soi même, ou si test avec GET non testé
if (strcmp(mov_adr,adr) != 0 || strcmp(mov_fil,fil) != 0) {
@@ -4629,10 +4347,7 @@ int hts_wait_delayed(htsmoduleStruct* str,
{ /* forbidden */
/* Note: the cache 'cached_tests' system will remember this error, and we'll only issue ONE request */
*forbidden_url = 1; /* Forbidden! */
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"link forbidden because of redirect beyond the mirror scope at %s%s -> %s%s"LF,adr,fil,mov_adr,mov_fil);
- test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "link forbidden because of redirect beyond the mirror scope at %s%s -> %s%s",adr,fil,mov_adr,mov_fil);
strcpybuff(adr,mov_adr);
strcpybuff(fil,mov_fil);
mov_url[0]='\0';
@@ -4660,18 +4375,12 @@ int hts_wait_delayed(htsmoduleStruct* str,
save[0] = '\0';
url_savename2(adr,fil,save,former_adr,former_fil,liens[ptr]->adr,liens[ptr]->fil,opt,liens,lien_tot,sback,cache,hash,ptr,numero_passe,&delayed_back,str->page_charset_);
} else {
- if ( opt->log!=NULL ) {
- HTS_LOG(opt,LOG_WARNING); fprintf(opt->log,"Unable to test %s%s (loop to same filename)"LF,adr,fil);
- test_flush;
- }
+ hts_log_print(opt, LOG_WARNING, "Unable to test %s%s (loop to same filename)",adr,fil);
} // loop to same location
} // ident_url_relatif()
} // location
} // redirect
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"Final type for %s%s: '%s'"LF, adr, fil, delayed_back.r.contenttype);
- test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "Final type for %s%s: '%s'", adr, fil, delayed_back.r.contenttype);
/* If we are done, do additional checks with final type and authorizations */
if (!continue_loop) {
@@ -4683,16 +4392,10 @@ int hts_wait_delayed(htsmoduleStruct* str,
{
int new_forbidden_url = hts_acceptmime(opt, ptr, lien_tot, liens, adr,fil, delayed_back.r.contenttype);
if (new_forbidden_url != -1) {
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"result for wizard mime test: %d"LF,*forbidden_url);
- test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "result for wizard mime test: %d",*forbidden_url);
if (new_forbidden_url == 1) {
*forbidden_url = new_forbidden_url;
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"link forbidden because of MIME types restrictions: %s%s"LF, adr, fil);
- test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "link forbidden because of MIME types restrictions: %s%s", adr, fil);
break; // exit loop
}
}
@@ -4731,13 +4434,10 @@ int hts_wait_delayed(htsmoduleStruct* str,
*/
*forbidden_url = 1; /* Forbidden! */
#endif
- if (opt->log != NULL && opt->debug > 0) {
- if (in_error == STATUSCODE_TOO_BIG) {
- HTS_LOG(opt, LOG_INFO); fprintf(opt->log,"link not taken because of its size (%d bytes) at %s%s"LF,(int)in_error_size,adr,fil);
- } else {
- HTS_LOG(opt, LOG_INFO); fprintf(opt->log,"link not taken because of error (%d '%s') at %s%s"LF,in_error,in_error_msg,adr,fil);
- }
- test_flush;
+ if (in_error == STATUSCODE_TOO_BIG) {
+ hts_log_print(opt, LOG_INFO, "link not taken because of its size (%d bytes) at %s%s",(int)in_error_size,adr,fil);
+ } else {
+ hts_log_print(opt, LOG_INFO, "link not taken because of error (%d '%s') at %s%s",in_error,in_error_msg,adr,fil);
}
}
}
@@ -4746,13 +4446,10 @@ int hts_wait_delayed(htsmoduleStruct* str,
if (*forbidden_url != 1
&& IS_DELAYED_EXT(save)) {
*forbidden_url = 1;
- if (opt->log!=NULL) {
- if (in_error) {
- HTS_LOG(opt,LOG_WARNING); fprintf(opt->log,"link in error (%d '%s'), type unknown, aborting: %s%s"LF, in_error, in_error_msg, adr, fil);
- } else {
- HTS_LOG(opt,LOG_WARNING); fprintf(opt->log,"link is probably looping, type unknown, aborting: %s%s"LF, adr, fil);
- }
- test_flush;
+ if (in_error) {
+ hts_log_print(opt, LOG_WARNING, "link in error (%d '%s'), type unknown, aborting: %s%s", in_error, in_error_msg, adr, fil);
+ } else {
+ hts_log_print(opt, LOG_WARNING, "link is probably looping, type unknown, aborting: %s%s", adr, fil);
}
}
diff --git a/src/htsstrings.h b/src/htsstrings.h
index 514963c..1102219 100755
--- a/src/htsstrings.h
+++ b/src/htsstrings.h
@@ -47,9 +47,11 @@ Please visit our Website: http://www.httrack.com
#ifdef __GNUC__
#define HTS_UNUSED __attribute__ ((unused))
#define HTS_STATIC static __attribute__ ((unused))
+#define HTS_PRINTF_FUN(fmt, arg) __attribute__ ((format (printf, fmt, arg)))
#else
#define HTS_UNUSED
#define HTS_STATIC static
+#define HTS_PRINTF_FUN(fmt, arg)
#endif
#endif
diff --git a/src/htswizard.c b/src/htswizard.c
index 749d6de..ca97bb4 100644
--- a/src/htswizard.c
+++ b/src/htswizard.c
@@ -46,10 +46,6 @@ Please visit our Website: http://www.httrack.com
#include <ctype.h>
/* END specific definitions */
-// version 1 pour httpmirror
-// flusher si on doit lire peu à peu le fichier
-#define test_flush if (opt->flush) { fflush(opt->log); fflush(opt->log); }
-
// pour alléger la syntaxe, des raccourcis sont créés
#define urladr (liens[ptr]->adr)
#define urlfil (liens[ptr]->fil)
@@ -162,10 +158,7 @@ static int hts_acceptlink_(httrackp* opt,
// -------------------- PHASE 0 --------------------
/* Infos */
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"wizard test begins: %s%s"LF,adr,fil);
- test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "wizard test begins: %s%s",adr,fil);
/* Already exists? Then, we know that we knew that this link had to be known */
if (adr[0] != '\0'
@@ -200,10 +193,7 @@ static int hts_acceptlink_(httrackp* opt,
if (!ishtml(opt,fil)) { // non il ne faut pas
//adr[0]='\0'; // ne pas traiter ce lien, pas traiter
forbidden_url=1; // interdire récupération du lien
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"non-html file ignored at %s : %s"LF,adr,fil);
- test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "non-html file ignored at %s : %s",adr,fil);
}
}
@@ -212,10 +202,7 @@ static int hts_acceptlink_(httrackp* opt,
if (ptr>0) {
if ( ( liens[ptr]->depth <= 0 ) || ( liens[ptr]->depth <= 1 && !embedded_triggered ) ) {
forbidden_url=1; // interdire récupération du lien
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"file from too far level ignored at %s : %s"LF,adr,fil);
- test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "file from too far level ignored at %s : %s",adr,fil);
}
}
@@ -229,14 +216,10 @@ static int hts_acceptlink_(httrackp* opt,
// ------------------------------------------------------
// doit-on traiter ce lien?.. vérifier droits de déplacement
meme_adresse=strfield2(adr,urladr);
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG);
- if (meme_adresse)
- fprintf(opt->log,"Compare addresses: %s=%s"LF,adr,urladr);
- else
- fprintf(opt->log,"Compare addresses: %s!=%s"LF,adr,urladr);
- test_flush;
- }
+ if (meme_adresse)
+ hts_log_print(opt, LOG_DEBUG, "Compare addresses: %s=%s",adr,urladr);
+ else
+ hts_log_print(opt, LOG_DEBUG, "Compare addresses: %s!=%s",adr,urladr);
if (meme_adresse) { // même adresse
{ // tester interdiction de descendre
// MODIFIE : en cas de remontée puis de redescente, il se pouvait qu'on ne puisse pas atteindre certains fichiers
@@ -250,10 +233,7 @@ static int hts_acceptlink_(httrackp* opt,
if (lienrelatif(tempo,fil,liens[liens[ptr]->premier]->fil)==0) {
if (lienrelatif(tempo2,fil,liens[ptr]->fil)==0) {
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"build relative links to test: %s %s (with %s and %s)"LF,tempo,tempo2,liens[liens[ptr]->premier]->fil,liens[ptr]->fil);
- test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "build relative links to test: %s %s (with %s and %s)",tempo,tempo2,liens[liens[ptr]->premier]->fil,liens[ptr]->fil);
// si vient de primary, ne pas tester lienrelatif avec (car host "différent")
/*if (liens[liens[ptr]->premier] == 0) { // vient de primary
@@ -272,10 +252,7 @@ static int hts_acceptlink_(httrackp* opt,
) {
if (!liens[ptr]->link_import) { // ne résulte pas d'un 'moved'
forbidden_url=0;
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"same level link authorized: %s%s"LF,adr,fil);
- test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "same level link authorized: %s%s",adr,fil);
}
}
@@ -293,27 +270,18 @@ static int hts_acceptlink_(httrackp* opt,
if ( (test1) && (test2) ) { // on ne peut que descendre
if ((opt->seeker & 1)==0) { // interdiction de descendre
forbidden_url=1;
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"lower link canceled: %s%s"LF,adr,fil);
- test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "lower link canceled: %s%s",adr,fil);
} else { // autorisé à priori - NEW
if (!liens[ptr]->link_import) { // ne résulte pas d'un 'moved'
forbidden_url=0;
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"lower link authorized: %s%s"LF,adr,fil);
- test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "lower link authorized: %s%s",adr,fil);
}
}
} else if ( (test1) || (test2) ) { // on peut descendre pour accéder au lien
if ((opt->seeker & 1)!=0) { // on peut descendre - NEW
if (!liens[ptr]->link_import) { // ne résulte pas d'un 'moved'
forbidden_url=0;
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"lower link authorized: %s%s"LF,adr,fil);
- test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "lower link authorized: %s%s",adr,fil);
}
}
}
@@ -324,43 +292,28 @@ static int hts_acceptlink_(httrackp* opt,
if ( (!strncmp(tempo,"../",3)) && (!strncmp(tempo2,"../",3)) ) { // impossible sans monter
if ((opt->seeker & 2)==0) { // interdiction de monter
forbidden_url=1;
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"upper link canceled: %s%s"LF,adr,fil);
- test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "upper link canceled: %s%s",adr,fil);
} else { // autorisé à monter - NEW
if (!liens[ptr]->link_import) { // ne résulte pas d'un 'moved'
forbidden_url=0;
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"upper link authorized: %s%s"LF,adr,fil);
- test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "upper link authorized: %s%s",adr,fil);
}
}
} else if ( (!strncmp(tempo,"../",3)) || (!strncmp(tempo2,"../",3)) ) { // Possible en montant
if ((opt->seeker & 2)!=0) { // autorisé à monter - NEW
if (!liens[ptr]->link_import) { // ne résulte pas d'un 'moved'
forbidden_url=0;
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"upper link authorized: %s%s"LF,adr,fil);
- test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "upper link authorized: %s%s",adr,fil);
}
} // sinon autorisé en descente
}
} else {
- if (opt->log) {
- fprintf(opt->log,"Error building relative link %s and %s"LF,fil,liens[ptr]->fil);
- test_flush;
- }
+ hts_log_print(opt, LOG_ERROR, "Error building relative link %s and %s",fil,liens[ptr]->fil);
}
} else {
- if (opt->log) {
- fprintf(opt->log,"Error building relative link %s and %s"LF,fil,liens[liens[ptr]->premier]->fil);
- test_flush;
- }
+ hts_log_print(opt, LOG_ERROR, "Error building relative link %s and %s",fil,liens[liens[ptr]->premier]->fil);
}
} // tester interdiction de descendre?
@@ -371,17 +324,10 @@ static int hts_acceptlink_(httrackp* opt,
if (lienrelatif(tempo,fil,liens[liens[ptr]->premier]->fil)==0) {
if (lienrelatif(tempo2,fil,liens[ptr]->fil)==0) {
} else {
- if (opt->log) {
- fprintf(opt->log,"Error building relative link %s and %s"LF,fil,liens[ptr]->fil);
- test_flush;
- }
-
+ hts_log_print(opt, LOG_ERROR, "Error building relative link %s and %s",fil,liens[ptr]->fil);
}
} else {
- if (opt->log) {
- fprintf(opt->log,"Error building relative link %s and %s"LF,fil,liens[liens[ptr]->premier]->fil);
- test_flush;
- }
+ hts_log_print(opt, LOG_ERROR, "Error building relative link %s and %s",fil,liens[liens[ptr]->premier]->fil);
}
} // fin tester interdiction de monter
@@ -412,19 +358,13 @@ static int hts_acceptlink_(httrackp* opt,
if (!opt->wizard) { // mode non wizard
//printf("refused: %s\n",adr);
forbidden_url=1; // pas même domaine
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"foreign domain link canceled: %s%s"LF,adr,fil);
- test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "foreign domain link canceled: %s%s",adr,fil);
}
} else {
if (opt->wizard) { // mode wizard
forbidden_url=0; // même domaine
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"same domain link authorized: %s%s"LF,adr,fil);
- test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "same domain link authorized: %s%s",adr,fil);
}
}
@@ -442,18 +382,12 @@ static int hts_acceptlink_(httrackp* opt,
if (!opt->wizard) { // mode non wizard
//printf("refused: %s\n",adr);
forbidden_url=1; // pas même .xx
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"foreign location link canceled: %s%s"LF,adr,fil);
- test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "foreign location link canceled: %s%s",adr,fil);
}
} else {
if (opt->wizard) { // mode wizard
forbidden_url=0; // même domaine
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"same location link authorized: %s%s"LF,adr,fil);
- test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "same location link authorized: %s%s",adr,fil);
}
}
} else forbidden_url=1;
@@ -478,10 +412,7 @@ static int hts_acceptlink_(httrackp* opt,
//printf("ok %s%s\n",ad,fil);
forbidden_url=0; // autoriser
may_set_prio_to=1+1; // set prio to 1 (parse but skip urls) if near is the winner
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"near link authorized: %s%s"LF,adr,fil);
- test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "near link authorized: %s%s",adr,fil);
}
}
@@ -491,10 +422,7 @@ static int hts_acceptlink_(httrackp* opt,
if (forbidden_url != 0 && embedded_triggered) {
forbidden_url=0; // autoriser
may_set_prio_to=1+1; // set prio to 1 (parse but skip urls) if near is the winner
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"near link authorized (friendly tag): %s%s"LF,adr,fil);
- test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "near link authorized (friendly tag): %s%s",adr,fil);
}
@@ -550,13 +478,10 @@ static int hts_acceptlink_(httrackp* opt,
may_set_prio_to=0; // clear may-set flag
forbidden_url=0; // autorisé
question=0; // résolution auto
- if ((opt->debug>1) && (opt->log!=NULL)) {
- if (question) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"(wizard) ambiguous link accepted (external depth): link %s at %s%s"LF,l,urladr,urlfil);
- } else {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"(wizard) forced to accept link (external depth): link %s at %s%s"LF,l,urladr,urlfil);
- }
- test_flush;
+ if (question) {
+ hts_log_print(opt, LOG_DEBUG, "(wizard) ambiguous link accepted (external depth): link %s at %s%s",l,urladr,urlfil);
+ } else {
+ hts_log_print(opt, LOG_DEBUG, "(wizard) forced to accept link (external depth): link %s at %s%s",l,urladr,urlfil);
}
}
@@ -593,18 +518,12 @@ static int hts_acceptlink_(httrackp* opt,
question=0; // ne pas poser de question, autorisé
forbidden_url=0; // URL autorisée
may_set_prio_to=0; // clear may-set flag
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"(wizard) explicit authorized (%s) link: link %s at %s%s"LF,mdepth,l,urladr,urlfil);
- test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "(wizard) explicit authorized (%s) link: link %s at %s%s",mdepth,l,urladr,urlfil);
} else if (jok == -1) { // forbidden
filters_answer=1; // décision prise par les filtres
question=0; // ne pas poser de question:
forbidden_url=1; // URL interdite
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"(wizard) explicit forbidden (%s) link: link %s at %s%s"LF,mdepth,l,urladr,urlfil);
- test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "(wizard) explicit forbidden (%s) link: link %s at %s%s",mdepth,l,urladr,urlfil);
} // sinon on touche à rien
}
}
@@ -617,10 +536,7 @@ static int hts_acceptlink_(httrackp* opt,
may_set_prio_to=0; // clear may-set flag
question=1; // résolution auto
force_mirror=5; // mirror (5)
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"(wizard) explicit mirror link: link %s at %s%s"LF,l,urladr,urlfil);
- test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "(wizard) explicit mirror link: link %s at %s%s",l,urladr,urlfil);
}
}
}
@@ -631,10 +547,7 @@ static int hts_acceptlink_(httrackp* opt,
if (opt->wizard==2) { // éliminer tous les liens non répertoriés comme autorisés (ou inconnus)
question=0;
forbidden_url=1;
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"(wizard) ambiguous forbidden link: link %s at %s%s"LF,l,urladr,urlfil);
- test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "(wizard) ambiguous forbidden link: link %s at %s%s",l,urladr,urlfil);
}
}
@@ -649,31 +562,22 @@ static int hts_acceptlink_(httrackp* opt,
if ((!question) && (filters_answer) && (opt->robots == 1) && (forbidden_url!=1)) {
r=0; // annuler interdiction des robots
if (!forbidden_url) {
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"Warning link followed against robots.txt: link %s at %s%s"LF,l,adr,fil);
- test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "Warning link followed against robots.txt: link %s at %s%s",l,adr,fil);
}
}
if (r == -1) { // interdire
forbidden_url=1;
question=0;
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"(robots.txt) forbidden link: link %s at %s%s"LF,l,adr,fil);
- test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "(robots.txt) forbidden link: link %s at %s%s",l,adr,fil);
}
}
}
if (!question) {
- if ((opt->debug>1) && (opt->log!=NULL)) {
- if (!forbidden_url) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"(wizard) shared foreign domain link: link %s at %s%s"LF,l,urladr,urlfil);
- } else {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"(wizard) cancelled foreign domain link: link %s at %s%s"LF,l,urladr,urlfil);
- }
- test_flush;
+ if (!forbidden_url) {
+ hts_log_print(opt, LOG_DEBUG, "(wizard) shared foreign domain link: link %s at %s%s",l,urladr,urlfil);
+ } else {
+ hts_log_print(opt, LOG_DEBUG, "(wizard) cancelled foreign domain link: link %s at %s%s",l,urladr,urlfil);
}
#if BDEBUG==3
printf("at %s in %s, wizard says: url %s ",urladr,urlfil,l);
@@ -736,11 +640,8 @@ static int hts_acceptlink_(httrackp* opt,
if (filters_init(&_FILTERS, opt->maxfilter, HTS_FILTERSINC) == 0) {
printf("PANIC! : Too many filters : >%d [%d]\n", (*_FILTERS_PTR),__LINE__);
fflush(stdout);
- if (opt->log) {
- fprintf(opt->log,LF"Too many filters, giving up..(>%d)"LF, (*_FILTERS_PTR) );
- fprintf(opt->log,"To avoid that: use #F option for more filters (example: -#F5000)"LF);
- test_flush;
- }
+ hts_log_print(opt, LOG_PANIC, "Too many filters, giving up..(>%d)", (*_FILTERS_PTR) );
+ hts_log_print(opt, LOG_INFO, "To avoid that: use #F option for more filters (example: -#F5000)");
assertf("too many filters - giving up" == NULL); // wild..
}
}
@@ -881,9 +782,7 @@ static int hts_acceptlink_(httrackp* opt,
) { // PAS ftp!
forbidden_url=1; // oui oui toujours interdit (note: sert à rien car ==1 mais c pour comprendre)
*just_test_it=1; // mais on teste
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"Testing link %s%s"LF,adr,fil);
- }
+ hts_log_print(opt, LOG_DEBUG, "Testing link %s%s",adr,fil);
}
}
}
@@ -921,16 +820,10 @@ int hts_acceptmime(httrackp* opt,
mdepth = _FILTERS[jokDepth];
if (jok == 1) { // autorisé
forbidden_url=0; // URL autorisée
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"(wizard) explicit authorized (%s) link %s%s: mime '%s'"LF,mdepth,adr,fil,mime);
- test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "(wizard) explicit authorized (%s) link %s%s: mime '%s'",mdepth,adr,fil,mime);
} else if (jok == -1) { // forbidden
forbidden_url=1; // URL interdite
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"(wizard) explicit forbidden (%s) link %s%s: mime '%s'"LF,mdepth,adr,fil,mime);
- test_flush;
- }
+ hts_log_print(opt, LOG_DEBUG, "(wizard) explicit forbidden (%s) link %s%s: mime '%s'",mdepth,adr,fil,mime);
} // sinon on touche à rien
}
/* userdef test */
@@ -1001,14 +894,10 @@ int hts_testlinksize(httrackp* opt,
// log
if (jok==1) {
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"File confirmed (size test): %s%s ("LLintP")"LF,adr,fil,(LLint)(size));
- }
+ hts_log_print(opt, LOG_DEBUG, "File confirmed (size test): %s%s ("LLintP")",adr,fil,(LLint)(size));
} else if (jok==-1) {
if (size_flag) { /* interdit à cause de la taille */
- if ((opt->debug>1) && (opt->log!=NULL)) {
- HTS_LOG(opt,LOG_DEBUG); fprintf(opt->log,"File cancelled due to its size: %s%s ("LLintP", limit: "LLintP")"LF,adr,fil,(LLint)(size),(LLint)(sz));
- }
+ hts_log_print(opt, LOG_DEBUG, "File cancelled due to its size: %s%s ("LLintP", limit: "LLintP")",adr,fil,(LLint)(size),(LLint)(sz));
} else {
jok=1;
}
@@ -1018,9 +907,6 @@ int hts_testlinksize(httrackp* opt,
return jok;
}
-
-
-#undef test_flush
#undef urladr
#undef urlfil
diff --git a/src/httrack-library.h b/src/httrack-library.h
index 7654e02..031c7f2 100644
--- a/src/httrack-library.h
+++ b/src/httrack-library.h
@@ -48,6 +48,18 @@ typedef struct httrackp httrackp;
#define HTS_DEF_FWSTRUCT_strc_int2bytes2
typedef struct strc_int2bytes2 strc_int2bytes2;
#endif
+#ifndef HTS_DEF_DEFSTRUCT_hts_log_type
+#define HTS_DEF_DEFSTRUCT_hts_log_type
+typedef enum hts_log_type {
+ LOG_DEBUG,
+ LOG_INFO,
+ LOG_NOTICE,
+ LOG_WARNING,
+ LOG_ERROR,
+ LOG_PANIC,
+ LOG_ERRNO = 1 << 8
+} hts_log_type;
+#endif
/* Helpers for plugging callbacks
requires: htsdefines.h */
@@ -96,6 +108,7 @@ HTSEXT_API int plug_wrapper(httrackp *opt, const char *moduleName, const char* a
/* Logging */
HTSEXT_API int hts_log(httrackp *opt, const char* prefix, const char *msg);
+HTSEXT_API void hts_log_print(httrackp *opt, int type, const char *format, ...);
/* Infos */
HTSEXT_API const char* hts_get_version_info(httrackp *opt);
diff --git a/src/proxy/proxytrack.c b/src/proxy/proxytrack.c
index 6de5f40..82bf7b1 100644
--- a/src/proxy/proxytrack.c
+++ b/src/proxy/proxytrack.c
@@ -792,8 +792,6 @@ static PT_Element proxytrack_process_HTTP_List(PT_Indexes indexes, const char *
static void proxytrack_process_HTTP(PT_Indexes indexes, T_SOC soc_c) {
int timeout=30;
- int retour=0;
- int willexit=0;
int buffer_size = 32768;
char * buffer = (char*)malloc(buffer_size);
int line1Size = 1024;
diff --git a/src/proxy/store.c b/src/proxy/store.c
index 2be2257..d63c1f2 100644
--- a/src/proxy/store.c
+++ b/src/proxy/store.c
@@ -1413,7 +1413,7 @@ static int PT_LoadCache__Old(PT_Index index_, const char *filename) {
/* */
} else { // Vieille version du cache
/* */
- // HTS_LOG(opt,LOG_WARNING); fprintf(opt->log,"Cache: importing old cache format"LF);
+ // hts_log_print(opt, LOG_WARNING, "Cache: importing old cache format");
cache->version=0; // cache 1.0
strcpy(cache->lastmodified,firstline);
}