summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/htsback.c2
-rw-r--r--src/htscore.c676
-rw-r--r--src/htscore.h47
-rw-r--r--src/htshash.c16
-rw-r--r--src/htshash.h2
-rw-r--r--src/htsmodules.h5
-rw-r--r--src/htsopt.h9
-rw-r--r--src/htsparse.c587
-rw-r--r--src/htsparse.h23
-rw-r--r--src/htsweb.c1
-rw-r--r--src/htswizard.c85
-rw-r--r--src/httrack.c1
12 files changed, 724 insertions, 730 deletions
diff --git a/src/htsback.c b/src/htsback.c
index 80cfb77..098a528 100644
--- a/src/htsback.c
+++ b/src/htsback.c
@@ -1010,7 +1010,7 @@ int back_serialize_ref(httrackp * opt, const lien_back * src) {
}
/* unserialize a reference ; used to store references of files being downloaded in case of broken download */
-int back_unserialize_ref(httrackp * opt, const const char *adr, const const char *fil,
+int back_unserialize_ref(httrackp * opt, const char *adr, const char *fil,
lien_back ** dst) {
const char *filename = url_savename_refname_fullpath(opt, adr, fil);
FILE *fp = FOPEN(filename, "rb");
diff --git a/src/htscore.c b/src/htscore.c
index 6fe302a..61e8a89 100644
--- a/src/htscore.c
+++ b/src/htscore.c
@@ -107,12 +107,6 @@ int longest_hash[3] = { 0, 0, 0 }, hashnumber = 0;
// Début de httpmirror, routines annexes
-// pour alléger la syntaxe, des raccourcis sont créés
-#define urladr (liens[ptr]->adr)
-#define urlfil (liens[ptr]->fil)
-#define savename (liens[ptr]->sav)
-//#define level (liens[ptr]->depth)
-
// au cas où nous devons quitter rapidement xhttpmirror (plus de mémoire, etc)
// 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à]
@@ -122,20 +116,8 @@ RUN_CALLBACK0(opt, end); \
}
#define XH_extuninit do { \
- int i; \
HTMLCHECK_UNINIT \
- if (liens!=NULL) { \
- for(i=lien_max-1;i>=0;i--) { \
- if (liens[i]) { \
- if (liens[i]->firstblock==1) { \
- freet(liens[i]); \
- liens[i]=NULL; \
- } \
- } \
- } \
- freet(liens); \
- liens=NULL; \
- } \
+ hts_record_free(opt); \
if (filters && filters[0]) { \
freet(filters[0]); filters[0]=NULL; \
} \
@@ -175,59 +157,224 @@ RUN_CALLBACK0(opt, end); \
} while(0)
#define XH_uninit do { XH_extuninit; if (r.adr) { freet(r.adr); r.adr=NULL; } } while(0)
-// Enregistrement d'un lien:
-// on calcule la taille nécessaire: taille des 3 chaînes à stocker (taille forcée paire, plus 2 octets de sécurité)
-// puis on vérifie qu'on a assez de marge dans le buffer - sinon on en réalloue un autre
-// enfin on écrit à l'adresse courante du buffer, qu'on incrémente. on décrémente la taille dispo d'autant ensuite
-// codebase: si non nul et si .class stockee on le note pour chemin primaire pour classes
-// FA,FS: former_adr et former_fil, lien original
-#define liens_record_sav_len(A)
-
-#define liens_record(A,F,S,FA,FF,NORM) { \
-int notecode=0; \
-size_t lienurl_len=((sizeof(lien_url)+HTS_ALIGN-1)/HTS_ALIGN)*HTS_ALIGN,\
- adr_len=strlen(A),\
- fil_len=strlen(F),\
- sav_len=strlen(S),\
- cod_len=0,\
- former_adr_len=strlen(FA),\
- former_fil_len=strlen(FF); \
-if (former_adr_len>0) {\
- former_adr_len=(former_adr_len/HTS_ALIGN)*HTS_ALIGN+HTS_ALIGN*2; \
- former_fil_len=(former_fil_len/HTS_ALIGN)*HTS_ALIGN+HTS_ALIGN*2; \
-} else former_adr_len=former_fil_len=0;\
-if (strlen(F)>6) if (strnotempty(codebase)) if (strfield(F+strlen(F)-6,".class")) { notecode=1; \
-cod_len=strlen(codebase); cod_len=(cod_len/HTS_ALIGN)*HTS_ALIGN+HTS_ALIGN*2; } \
-adr_len=(adr_len/HTS_ALIGN)*HTS_ALIGN+HTS_ALIGN*2; fil_len=(fil_len/HTS_ALIGN)*HTS_ALIGN+HTS_ALIGN*2; sav_len=(sav_len/HTS_ALIGN)*HTS_ALIGN+HTS_ALIGN*2; \
-if ((int) lien_size < (int) (adr_len+fil_len+sav_len+cod_len+former_adr_len+former_fil_len+lienurl_len)) { \
-lien_buffer=(char*) ((void*) calloct(add_tab_alloc,1)); \
-lien_size=add_tab_alloc; \
-if (lien_buffer!=NULL) { \
-liens[lien_tot]=(lien_url*) (void*) lien_buffer; lien_buffer+=lienurl_len; lien_size-=lienurl_len; \
-liens[lien_tot]->firstblock=1; \
-} \
-} else { \
-liens[lien_tot]=(lien_url*) (void*) lien_buffer; lien_buffer+=lienurl_len; lien_size-=lienurl_len; \
-liens[lien_tot]->firstblock=0; \
-} \
-if (liens[lien_tot]!=NULL) { \
-liens[lien_tot]->adr=lien_buffer; lien_buffer+=adr_len; lien_size-=adr_len; \
-liens[lien_tot]->fil=lien_buffer; lien_buffer+=fil_len; lien_size-=fil_len; \
-liens[lien_tot]->sav=lien_buffer; lien_buffer+=sav_len; lien_size-=sav_len; \
-liens[lien_tot]->cod=NULL; \
-if (notecode) { liens[lien_tot]->cod=lien_buffer; lien_buffer+=cod_len; lien_size-=cod_len; strcpybuff(liens[lien_tot]->cod,codebase); } \
-if (former_adr_len>0) {\
-liens[lien_tot]->former_adr=lien_buffer; lien_buffer+=former_adr_len; lien_size-=former_adr_len; \
-liens[lien_tot]->former_fil=lien_buffer; lien_buffer+=former_fil_len; lien_size-=former_fil_len; \
-strcpybuff(liens[lien_tot]->former_adr,FA); \
-strcpybuff(liens[lien_tot]->former_fil,FF); \
-}\
-strcpybuff(liens[lien_tot]->adr,A); \
-strcpybuff(liens[lien_tot]->fil,F); \
-strcpybuff(liens[lien_tot]->sav,S); \
-liens_record_sav_len(liens[lien_tot]); \
-hash_write(hashptr,lien_tot); \
-} \
+// Typed array
+#define TypedArray(T) \
+ struct { \
+ T* elts; \
+ size_t size; \
+ size_t capa; \
+ }
+#define EMPTY_TYPED_ARRAY { NULL, 0, 0 }
+
+#define TypedArrayAdd(A, E) do { \
+ if ((A).capa == (A).size) { \
+ (A).capa = (A).capa < 16 ? 16 : (A).capa * 2; \
+ (A).elts = realloct((A).elts, (A).capa*sizeof(*(A).elts)); \
+ } \
+ assertf((A).size < (A).capa); \
+ (A).elts[(A).size++] = (E); \
+} while(0)
+
+#define TypedArrayFree(A) do { \
+ if ((A).elts != NULL) { \
+ freet((A).elts); \
+ (A).elts = NULL; \
+ (A).capa = (A).size = 0; \
+ } \
+} while(0)
+
+struct lien_buffers {
+ /* Main array of pointers.
+ This is the real "lien_url **liens" pointer base. */
+ TypedArray(lien_url*) ptr;
+ /* String pool, chunked. */
+ char *string_buffer;
+ size_t string_buffer_size;
+ size_t string_buffer_capa;
+ TypedArray(char*) string_buffers;
+ /* Structure list, chunked. */
+ lien_url *lien_buffer;
+ size_t lien_buffer_size;
+ size_t lien_buffer_capa;
+ TypedArray(lien_url*) lien_buffers;
+};
+
+// duplicate a string, or return NULL upon error (out-of-memory)
+static char* hts_record_link_strdup_(httrackp *opt, const char *s) {
+ static const size_t block_capa = 256000;
+ lien_buffers *const liensbuf = opt->liensbuf;
+ const size_t len = strlen(s) + 1; /* including terminating \0 */
+ char *s_dup;
+
+ assertf(liensbuf != NULL);
+
+ // not enough capacity ? then create a new chunk
+ if (len + liensbuf->string_buffer_size > liensbuf->string_buffer_capa) {
+ // backup current block pointer for later free
+ if (liensbuf->string_buffer != NULL) {
+ TypedArrayAdd(liensbuf->string_buffers, liensbuf->string_buffer);
+ liensbuf->string_buffer = NULL;
+ liensbuf->string_buffer_size = 0;
+ liensbuf->string_buffer_capa = 0;
+ }
+
+ liensbuf->string_buffer = malloct(block_capa);
+ if (liensbuf->string_buffer == NULL) {
+ return NULL;
+ }
+ liensbuf->string_buffer_capa = block_capa;
+ liensbuf->string_buffer_size = 0;
+ }
+
+ assertf(len + liensbuf->string_buffer_size < liensbuf->string_buffer_capa);
+ s_dup = &liensbuf->string_buffer[liensbuf->string_buffer_size];
+ memcpy(s_dup, s, len);
+ liensbuf->string_buffer_size += len;
+
+ return s_dup;
+}
+
+static char* hts_record_link_strdup(httrackp *opt, const char *s) {
+ assertf(opt != NULL);
+ assertf(s != NULL);
+ return hts_record_link_strdup_(opt, s);
+}
+
+size_t hts_record_link_latest(httrackp *opt) {
+ lien_buffers *const liensbuf = opt->liensbuf;
+
+ assertf(liensbuf->ptr.size != 0);
+ return liensbuf->ptr.size - 1;
+}
+
+// returns a new zeroed lien_url entry,
+// or (size_t) -1 upon error (out-of-memory)
+// the returned index is the osset within opt->liens[]
+static size_t hts_record_link_alloc(httrackp *opt) {
+ static const size_t block_capa = 10000;
+ lien_buffers *const liensbuf = opt->liensbuf;
+ lien_url *link;
+
+ assertf(opt != NULL);
+ assertf(liensbuf != NULL);
+
+ // Create a new chunk of lien_url[]
+ // There are references to item pointers, so we can not just realloc()
+ if (liensbuf->lien_buffer_size == liensbuf->lien_buffer_capa) {
+ TypedArrayAdd(liensbuf->lien_buffers, liensbuf->lien_buffer);
+ liensbuf->lien_buffer_size = 0;
+ liensbuf->lien_buffer_capa = 0;
+
+ liensbuf->lien_buffer = (lien_url*) malloct(block_capa*sizeof(*liensbuf->lien_buffer));
+ if (liensbuf->lien_buffer == NULL) {
+ return (size_t) -1;
+ }
+ liensbuf->lien_buffer_capa = block_capa;
+ liensbuf->lien_buffer_size = 0;
+ }
+
+ // Take next lien_url item
+ assertf(liensbuf->lien_buffer_size < liensbuf->lien_buffer_capa);
+ link = &liensbuf->lien_buffer[liensbuf->lien_buffer_size++];
+ memset(link, 0, sizeof(*link));
+
+ // Add new lien_url pointer to the array of links
+ TypedArrayAdd(liensbuf->ptr, link);
+
+ // Update pointer as it may have changed,
+ // and update heap top index
+ opt->liens = liensbuf->ptr.elts;
+ assertf(liensbuf->ptr.size != 0);
+ assertf(liensbuf->ptr.size < ( (unsigned int) -1 ) / 2);
+ opt->lien_tot = (int) liensbuf->ptr.size;
+
+ // return tail
+ return hts_record_link_latest(opt);
+}
+
+void hts_record_init(httrackp *opt) {
+ if (opt->liensbuf == NULL) {
+ opt->liensbuf = calloct(sizeof(*opt->liensbuf), 1);
+ }
+}
+
+// wipe records
+void hts_record_free(httrackp *opt) {
+ lien_buffers *const liensbuf = opt->liensbuf;
+
+ if (liensbuf != NULL) {
+ size_t i;
+
+ TypedArrayFree(liensbuf->ptr);
+
+ if (liensbuf->string_buffer != NULL) {
+ freet(liensbuf->string_buffer);
+ liensbuf->string_buffer = NULL;
+ liensbuf->string_buffer_size = 0;
+ liensbuf->string_buffer_capa = 0;
+ }
+
+ for(i = 0 ; i < liensbuf->string_buffers.size ; i++) {
+ freet(liensbuf->string_buffers.elts[i]);
+ liensbuf->string_buffers.elts[i] = NULL;
+ }
+ TypedArrayFree(liensbuf->string_buffers);
+
+ if (liensbuf->lien_buffer != NULL) {
+ freet(liensbuf->lien_buffer);
+ liensbuf->lien_buffer = NULL;
+ }
+
+ for(i = 0 ; i < liensbuf->lien_buffers.size ; i++) {
+ freet(liensbuf->lien_buffers.elts[i]);
+ liensbuf->lien_buffers.elts[i] = NULL;
+ }
+ TypedArrayFree(liensbuf->lien_buffers);
+
+ freet(opt->liensbuf);
+ opt->liensbuf = NULL;
+ }
+
+ opt->liens = NULL; // no longer defined
+}
+
+// adds a new link and returns a non-zero value upon success
+int hts_record_link(httrackp * opt,
+ const char *address, const char *file, const char *save,
+ const char *ref_address, const char *ref_file,
+ const char *codebase) {
+ // create a new entry
+ const size_t lien_tot = hts_record_link_alloc(opt);
+ lien_url*const link = lien_tot != (size_t) -1 ? opt->liens[lien_tot] : NULL;
+ if (link == NULL) {
+ return 0;
+ }
+
+ // record string fields
+ if ( (link->adr = hts_record_link_strdup(opt, address)) == NULL
+ || (link->fil = hts_record_link_strdup(opt, file)) == NULL
+ || (link->sav = hts_record_link_strdup(opt, save)) == NULL
+ || (link->former_adr = hts_record_link_strdup(opt, ref_address)) == NULL
+ || (link->former_fil = hts_record_link_strdup(opt, ref_file)) == NULL
+ ) {
+ return 0;
+ }
+
+ // record codebase for java classes
+ if (codebase != NULL) {
+ const size_t len = strlen(file);
+ if (len > 6 && strncmp(&file[len - 6], ".class", 6) == 0) {
+ if ((link->cod = hts_record_link_strdup(opt, codebase)) == NULL) {
+ return 0;
+ }
+ }
+ }
+
+ // add entry in the hashtables
+ hash_write(opt->hash, lien_tot);
+
+ // success
+ return 1;
}
#define HT_INDEX_END do { \
@@ -257,15 +404,9 @@ makeindex_done=1; /* ok c'est fait */ \
// url1 peut être multiple
int httpmirror(char *url1, httrackp * opt) {
char *primary = NULL; // première page, contenant les liens à scanner
- int lien_tot = 0; // nombre de liens pour le moment
- lien_url **liens = NULL; // les pointeurs sur les liens
hash_struct hash; // système de hachage, accélère la recherche dans les liens
hash_struct *const hashptr = &hash;
t_cookie BIGSTK cookie; // gestion des cookies
- int lien_max = 0;
- size_t lien_size = 0; // octets restants dans buffer liens dispo
- char *lien_buffer = NULL; // buffer liens actuel
- int add_tab_alloc = 256000; // +256K de liens à chaque fois
//char* tab_alloc=NULL;
int ptr; // pointeur actuel sur les liens
@@ -430,31 +571,16 @@ int httpmirror(char *url1, httrackp * opt) {
// hash table
opt->hash = &hash;
- // tableau de pointeurs sur les liens
- lien_max = maximum(opt->maxlink, 32);
- liens = (lien_url **) malloct(lien_max * sizeof(lien_url *)); // tableau de pointeurs sur les liens
- if (liens == NULL) {
- printf("PANIC! : Not enough memory [%d]\n", __LINE__);
- //XH_uninit;
- return 0;
- } else {
- int i;
+ // initialize link heap
+ hts_record_init(opt);
- for(i = 0; i < lien_max; i++) {
- liens[i] = NULL;
- }
- }
// initialiser ptr et lien_tot
ptr = 0;
- lien_tot = 0;
// initialiser hachage
hash_init(opt, &hash, opt->urlhack);
// note: we need a cast because of the const
- hash.liens = (const lien_url **) liens;
-
- // we need it
- opt->liens = liens;
+ hash.liens = (const lien_url ***) &opt->liens;
// copier adresse(s) dans liste des adresses
{
@@ -630,32 +756,28 @@ int httpmirror(char *url1, httrackp * opt) {
}
// lien primaire
- liens_record("primary", "/primary",
- fslash(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt),
+ if (!hts_record_link(opt, "primary", "/primary",
+ fslash(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt),
fconcat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt),
- StringBuff(opt->path_html_utf8), "index.html")),
- "", "", opt->urlhack);
- if (liens[lien_tot] == NULL) { // erreur, pas de place réservée
+ StringBuff(opt->path_html_utf8), "index.html")),
+ "", "", NULL)) {
printf("PANIC! : Not enough memory [%d]\n", __LINE__);
- hts_log_print(opt, LOG_PANIC,
- "Not enough memory, can not re-allocate %d bytes",
- (int) ((add_tab_alloc + 1) * sizeof(lien_url)));
+ hts_log_print(opt, LOG_PANIC, "Not enough memory");
XH_extuninit; // désallocation mémoire & buffers
return 0;
}
- liens[lien_tot]->testmode = 0; // pas mode test
- liens[lien_tot]->link_import = 0; // pas mode import
- liens[lien_tot]->depth = opt->depth + 1; // lien de priorité maximale
- liens[lien_tot]->pass2 = 0; // 1ère passe
- liens[lien_tot]->retry = opt->retry; // lien de priorité maximale
- liens[lien_tot]->premier = lien_tot; // premier lien, objet-père=objet
- liens[lien_tot]->precedent = lien_tot; // lien précédent
- lien_tot++;
+ heap_top()->testmode = 0; // pas mode test
+ heap_top()->link_import = 0; // pas mode import
+ heap_top()->depth = opt->depth + 1; // lien de priorité maximale
+ heap_top()->pass2 = 0; // 1ère passe
+ heap_top()->retry = opt->retry; // lien de priorité maximale
+ heap_top()->premier = heap_top_index(); // premier lien, objet-père=objet
+ heap_top()->precedent = heap_top_index(); // lien précédent
// Initialiser cache
{
opt->state._hts_in_html_parsing = 4;
- if (!RUN_CALLBACK7(opt, loop, NULL, 0, 0, 0, lien_tot, 0, NULL)) {
+ if (!RUN_CALLBACK7(opt, loop, NULL, 0, 0, 0, opt->lien_tot, 0, NULL)) {
opt->state.exit_xh = 1; // exit requested
}
cache_init(&cache, opt);
@@ -669,7 +791,7 @@ int httpmirror(char *url1, httrackp * opt) {
int i;
for(i = 0; i < lien_tot; i++) {
- printf("%d>%s%s as %s\n", i, liens[i]->adr, liens[i]->fil, liens[i]->sav);
+ printf("%d>%s%s as %s\n", i, heap(i)->adr, heap(i)->fil, heap(i)->sav);
}
for(i = 0; i < filptr; i++) {
printf("%d>filters=%s\n", i, filters[i]);
@@ -718,7 +840,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->lien_tot <= 0) {
hts_log_print(opt, LOG_ERROR,
"You MUST specify at least one complete URL, and not only wildcards!");
}
@@ -771,11 +893,11 @@ int httpmirror(char *url1, httrackp * opt) {
if (rollover)
r =
- RUN_CALLBACK7(opt, loop, sback->lnk, sback->count, 0, 0, lien_tot,
+ RUN_CALLBACK7(opt, loop, sback->lnk, sback->count, 0, 0, opt->lien_tot,
(int) (opt->waittime - tl + 24 * 3600), NULL);
else
r =
- RUN_CALLBACK7(opt, loop, sback->lnk, sback->count, 0, 0, lien_tot,
+ RUN_CALLBACK7(opt, loop, sback->lnk, sback->count, 0, 0, opt->lien_tot,
(int) (opt->waittime - tl), NULL);
if (!r) {
opt->state.exit_xh = 1; // exit requested
@@ -843,35 +965,35 @@ int httpmirror(char *url1, httrackp * opt) {
if (!error) {
// Skip empty/invalid/done in background
- if (liens[ptr]) {
- while((liens[ptr])
- && ((((urladr != NULL) ? (urladr) : (" "))[0] == '!')
- || (((urlfil != NULL) ? (urlfil) : (" "))[0] == '\0')
- || ((liens[ptr]->pass2 == -1))
+ if (heap(ptr)) {
+ while((heap(ptr))
+ && ((((urladr() != NULL) ? (urladr()) : (" "))[0] == '!')
+ || (((urlfil() != NULL) ? (urlfil()) : (" "))[0] == '\0')
+ || ((heap(ptr)->pass2 == -1))
)
) { // sauter si lien annulé (ou fil vide)
- if (liens[ptr] != NULL && liens[ptr]->pass2 == -1) {
+ if (heap(ptr) != NULL && heap(ptr)->pass2 == -1) {
hts_log_print(opt, LOG_DEBUG, "link #%d is ready, skipping: %s%s..",
- ptr, ((urladr != NULL) ? (urladr) : (" ")),
- ((urlfil != NULL) ? (urlfil) : (" ")));
+ 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) : (" ")));
+ ((urladr() != NULL) ? (urladr()) : (" ")),
+ ((urlfil() != NULL) ? (urlfil()) : (" ")));
}
// remove from stats
- if (liens[ptr]->pass2 == -1) {
+ if (heap(ptr)->pass2 == -1) {
HTS_STAT.stat_background--;
}
ptr++;
}
}
- if (liens[ptr] != NULL) { // on a qq chose à récupérer?
+ if (heap(ptr) != NULL) { // on a qq chose à récupérer?
- hts_log_print(opt, LOG_DEBUG, "Wait get: %s%s", urladr, urlfil);
+ hts_log_print(opt, LOG_DEBUG, "Wait get: %s%s", urladr(), urlfil());
#if DEBUG_ROBOTS
- if (strcmp(urlfil, "/robots.txt") == 0) {
+ if (strcmp(urlfil(), "/robots.txt") == 0) {
printf("robots.txt detected\n");
}
#endif
@@ -886,7 +1008,7 @@ int httpmirror(char *url1, httrackp * opt) {
strcpybuff(r.contenttype, "text/html");
/*} else if (opt->maxsoc<=0) { // fichiers 1 à 1 en attente (pas de backing)
// charger le fichier en mémoire tout bêtement
- r=xhttpget(urladr,urlfil);
+ r=xhttpget(urladr(),urlfil());
//
*/
} else { // backing, multiples sockets
@@ -904,26 +1026,21 @@ int httpmirror(char *url1, httrackp * opt) {
memset(&stre, 0, sizeof(stre));
/* */
str.err_msg = buff_err_msg;
- str.filename = savename;
+ str.filename = savename();
str.mime = r.contenttype;
- str.url_host = urladr;
- str.url_file = urlfil;
+ str.url_host = urladr();
+ str.url_file = urlfil();
str.size = (const int) r.size;
/* */
str.addLink = htsAddLink;
/* */
- str.liens = liens;
str.opt = opt;
str.sback = sback;
str.cache = &cache;
str.hashptr = hashptr;
str.numero_passe = numero_passe;
- str.add_tab_alloc = add_tab_alloc;
/* */
- str.lien_tot_ = &lien_tot;
str.ptr_ = &ptr;
- str.lien_size_ = &lien_size;
- str.lien_buffer_ = &lien_buffer;
/* */
str.page_charset_ = NULL;
/* */
@@ -941,7 +1058,6 @@ int httpmirror(char *url1, httrackp * opt) {
stre.filptr_ = &filptr;
stre.robots_ = &robots;
stre.hash_ = &hash;
- stre.lien_max_ = &lien_max;
/* */
stre.makeindex_done_ = &makeindex_done;
stre.makeindex_fp_ = &makeindex_fp;
@@ -1014,7 +1130,7 @@ int httpmirror(char *url1, httrackp * opt) {
error = 0;
hts_log_print(opt, LOG_WARNING,
"Big file cancelled according to user's preferences: %s%s",
- urladr, urlfil);
+ urladr(), urlfil());
}
// // // error=1; // ne pas traiter la suite -- euhh si finalement..
}
@@ -1032,15 +1148,15 @@ int httpmirror(char *url1, httrackp * opt) {
if (!error) {
if (r.statuscode == HTTP_OK) { // OK (ou 304 en backing)
if (r.adr) { // Written file
- if ((is_hypertext_mime(opt, r.contenttype, urlfil))
+ if ((is_hypertext_mime(opt, r.contenttype, urlfil()))
/* Is HTML or Js, .. */
/* NO - real media is real media, not HTML */
- /*|| (may_be_hypertext_mime(r.contenttype, urlfil) && (r.adr) ) */
+ /*|| (may_be_hypertext_mime(r.contenttype, urlfil()) && (r.adr) ) */
/* Is real media, .. */
) {
if (strnotempty(r.cdispo)) { // Content-disposition set!
- if (ishtml(opt, savename) == 0) { // Non HTML!!
+ if (ishtml(opt, savename()) == 0) { // Non HTML!!
// patch it!
strcpybuff(r.contenttype, "application/octet-stream");
}
@@ -1052,19 +1168,19 @@ int httpmirror(char *url1, httrackp * opt) {
/* Load file if necessary and decode. */
#define LOAD_IN_MEMORY_IF_NECESSARY() do { \
if ( \
- may_be_hypertext_mime(opt,r.contenttype, urlfil) /* Is HTML or Js, .. */ \
- && (liens[ptr]->depth>0) /* Depth > 0 (recurse depth) */ \
+ may_be_hypertext_mime(opt,r.contenttype, urlfil()) /* Is HTML or Js, .. */ \
+ && (heap(ptr)->depth>0) /* Depth > 0 (recurse depth) */ \
&& (r.adr==NULL) /* HTML Data exists */ \
&& (!store_errpage) /* Not an html error page */ \
- && (savename[0]!='\0') /* Output filename exists */ \
+ && (savename()[0]!='\0') /* Output filename exists */ \
) \
{ \
is_loaded_from_file = 1; \
- r.adr = readfile2(savename, &r.size); \
+ r.adr = readfile2(savename(), &r.size); \
if (r.adr != NULL) { \
- hts_log_print(opt, LOG_INFO, "File successfully loaded for parsing: %s%s (%d bytes)",urladr,urlfil,(int)r.size); \
+ hts_log_print(opt, LOG_INFO, "File successfully loaded for parsing: %s%s (%d bytes)",urladr(),urlfil(),(int)r.size); \
} else { \
- hts_log_print(opt, LOG_ERROR, "File could not be loaded for parsing: %s%s",urladr,urlfil); \
+ hts_log_print(opt, LOG_ERROR, "File could not be loaded for parsing: %s%s",urladr(),urlfil()); \
} \
} \
} while(0)
@@ -1074,8 +1190,8 @@ int httpmirror(char *url1, httrackp * opt) {
// ------------------------------------
// BOGUS MIME TYPE HACK II (the revenge)
// Check if we have a bogus MIME type
- if (HTTP_IS_OK(r.statuscode) && (is_hypertext_mime(opt, r.contenttype, urlfil) /* Is HTML or Js, .. */
- ||may_be_hypertext_mime(opt, r.contenttype, urlfil)) /* Is real media, .. */
+ if (HTTP_IS_OK(r.statuscode) && (is_hypertext_mime(opt, r.contenttype, urlfil()) /* Is HTML or Js, .. */
+ ||may_be_hypertext_mime(opt, r.contenttype, urlfil())) /* Is real media, .. */
) {
/* Convert charset to UTF-8 - NOT! (what about links ? remote server side will have troubles with converted names) */
@@ -1212,7 +1328,7 @@ int httpmirror(char *url1, httrackp * opt) {
}
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);
+ urladr(), urlfil(), (int) r.size, new_offs);
freet(r.adr);
r.adr = NULL;
r.size = new_offs;
@@ -1226,8 +1342,8 @@ int httpmirror(char *url1, httrackp * opt) {
is_binary = 1;
strcpybuff(r.contenttype, "application/octet-stream");
hts_log_print(opt, LOG_WARNING,
- "File not parsed, looks like binary: %s%s", urladr,
- urlfil);
+ "File not parsed, looks like binary: %s%s", urladr(),
+ urlfil());
}
/* This hack allows you to avoid problems with parsing '\0' characters */
@@ -1251,12 +1367,12 @@ int httpmirror(char *url1, httrackp * opt) {
//if (!error) {
// if (r.statuscode == HTTP_OK) { // OK (ou 304 en backing)
// if (r.adr==NULL) { // Written file
- // if (may_be_hypertext_mime(r.contenttype, urlfil)) { // to parse!
+ // if (may_be_hypertext_mime(r.contenttype, urlfil())) { // to parse!
// LLint sz;
- // sz=fsize_utf8(savename);
+ // sz=fsize_utf8(savename());
// if (sz>0) { // ok, exists!
// if (sz < 8192) { // ok, small file --> to parse!
- // FILE* fp=FOPEN(savename,"rb");
+ // FILE* fp=FOPEN(savename(),"rb");
// if (fp) {
// r.adr=malloct((int)sz + 2);
// if (r.adr) {
@@ -1274,7 +1390,7 @@ int httpmirror(char *url1, httrackp * opt) {
// fclose(fp);
// fp=NULL;
// // remove (temporary) file!
- // remove(savename);
+ // remove(savename());
// }
// if (fp)
// fclose(fp);
@@ -1292,8 +1408,8 @@ int httpmirror(char *url1, httrackp * opt) {
/*
if (!error) {
if (ptr>0) {
- if (liens[ptr]) {
- xxcache_mayadd(opt,&cache,&r,urladr,urlfil,savename);
+ if (heap(ptr)) {
+ xxcache_mayadd(opt,&cache,&r,urladr(),urlfil(),savename());
} else
error=1;
}
@@ -1316,26 +1432,21 @@ int httpmirror(char *url1, httrackp * opt) {
memset(&stre, 0, sizeof(stre));
/* */
str.err_msg = buff_err_msg;
- str.filename = savename;
+ str.filename = savename();
str.mime = r.contenttype;
- str.url_host = urladr;
- str.url_file = urlfil;
+ str.url_host = urladr();
+ str.url_file = urlfil();
str.size = (int) r.size;
/* */
str.addLink = htsAddLink;
/* */
- str.liens = liens;
str.opt = opt;
str.sback = sback;
str.cache = &cache;
str.hashptr = hashptr;
str.numero_passe = numero_passe;
- str.add_tab_alloc = add_tab_alloc;
/* */
- str.lien_tot_ = &lien_tot;
str.ptr_ = &ptr;
- str.lien_size_ = &lien_size;
- str.lien_buffer_ = &lien_buffer;
/* */
str.page_charset_ = NULL;
/* */
@@ -1353,7 +1464,6 @@ int httpmirror(char *url1, httrackp * opt) {
stre.filptr_ = &filptr;
stre.robots_ = &robots;
stre.hash_ = &hash;
- stre.lien_max_ = &lien_max;
/* */
stre.makeindex_done_ = &makeindex_done;
stre.makeindex_fp_ = &makeindex_fp;
@@ -1417,14 +1527,14 @@ int httpmirror(char *url1, httrackp * opt) {
if (ptr>0) {
// "mis à jour"
if ((!r.notmodified) && (opt->is_update) && (!store_errpage)) { // page modifiée
- if (strnotempty(savename)) {
+ if (strnotempty(savename())) {
HTS_STAT.stat_updated_files++;
//if ((opt->debug>0) && (opt->log!=NULL)) {
- hts_log_print(opt, LOG_INFO, "File updated: %s%s",urladr,urlfil);
+ hts_log_print(opt, LOG_INFO, "File updated: %s%s",urladr(),urlfil());
}
} else {
if (!store_errpage) {
- hts_log_print(opt, LOG_INFO, "File recorded: %s%s",urladr,urlfil);
+ hts_log_print(opt, LOG_INFO, "File recorded: %s%s",urladr(),urlfil());
}
}
}
@@ -1435,14 +1545,14 @@ int httpmirror(char *url1, httrackp * opt) {
// ------------------------------------------------------
// traiter
- if (!is_binary && ((is_hypertext_mime(opt, r.contenttype, urlfil)) /* Is HTML or Js, .. */
- ||(may_be_hypertext_mime(opt, r.contenttype, urlfil) && r.adr != NULL) /* Is real media, .. */
+ if (!is_binary && ((is_hypertext_mime(opt, r.contenttype, urlfil())) /* Is HTML or Js, .. */
+ ||(may_be_hypertext_mime(opt, r.contenttype, urlfil()) && r.adr != NULL) /* Is real media, .. */
)
- && (liens[ptr]->depth > 0) /* Depth > 0 (recurse depth) */
+ && (heap(ptr)->depth > 0) /* Depth > 0 (recurse depth) */
&&(r.adr != NULL) /* HTML Data exists */
&&(r.size > 0) /* And not empty */
&&(!store_errpage) /* Not an html error page */
- &&(savename[0] != '\0') /* Output filename exists */
+ &&(savename()[0] != '\0') /* Output filename exists */
) { // ne traiter que le html si autorisé
// -- -- -- --
// Parsing HTML
@@ -1451,7 +1561,7 @@ int httpmirror(char *url1, httrackp * opt) {
/* Remove file if being processed */
if (is_loaded_from_file) {
- (void) unlink(fconv(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), savename));
+ (void) unlink(fconv(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), savename()));
is_loaded_from_file = 0;
}
@@ -1486,15 +1596,15 @@ int httpmirror(char *url1, httrackp * opt) {
if (page_charset[0] == '\0') {
hts_log_print(opt, LOG_INFO,
"Warning: could not detect encoding for: %s%s",
- urladr, urlfil);
+ urladr(), urlfil());
/* Fallback to ISO-8859-1 (~== identity) ; accents will look weird */
strcpy(page_charset, "iso-8859-1");
}
}
/* Info for wrappers */
- hts_log_print(opt, LOG_INFO, "engine: check-html: %s%s", urladr,
- urlfil);
+ hts_log_print(opt, LOG_INFO, "engine: check-html: %s%s", urladr(),
+ urlfil());
{
char BIGSTK buff_err_msg[1024];
htsmoduleStruct BIGSTK str;
@@ -1505,26 +1615,21 @@ int httpmirror(char *url1, httrackp * opt) {
memset(&stre, 0, sizeof(stre));
/* */
str.err_msg = buff_err_msg;
- str.filename = savename;
+ str.filename = savename();
str.mime = r.contenttype;
- str.url_host = urladr;
- str.url_file = urlfil;
+ str.url_host = urladr();
+ str.url_file = urlfil();
str.size = (int) r.size;
/* */
str.addLink = htsAddLink;
/* */
- str.liens = liens;
str.opt = opt;
str.sback = sback;
str.cache = &cache;
str.hashptr = hashptr;
str.numero_passe = numero_passe;
- str.add_tab_alloc = add_tab_alloc;
/* */
- str.lien_tot_ = &lien_tot;
str.ptr_ = &ptr;
- str.lien_size_ = &lien_size;
- str.lien_buffer_ = &lien_buffer;
/* */
str.page_charset_ = page_charset[0] != '\0' ? page_charset : NULL;
/* */
@@ -1542,7 +1647,6 @@ int httpmirror(char *url1, httrackp * opt) {
stre.filptr_ = &filptr;
stre.robots_ = &robots;
stre.hash_ = &hash;
- stre.lien_max_ = &lien_max;
/* */
stre.makeindex_done_ = &makeindex_done;
stre.makeindex_fp_ = &makeindex_fp;
@@ -1581,18 +1685,18 @@ int httpmirror(char *url1, httrackp * opt) {
// sauver fichier
/* En cas d'erreur, vérifier que fichier d'erreur existe */
- if (strnotempty(savename) == 0) { // chemin de sauvegarde existant
- if (strcmp(urlfil, "/robots.txt") == 0) { // pas robots.txt
+ if (strnotempty(savename()) == 0) { // chemin de sauvegarde existant
+ if (strcmp(urlfil(), "/robots.txt") == 0) { // pas robots.txt
if (store_errpage) { // c'est une page d'erreur
int create_html_warning = 0;
int create_gif_warning = 0;
- switch (ishtml(opt, urlfil)) { /* pas fichier html */
+ switch (ishtml(opt, urlfil())) { /* pas fichier html */
case 0: /* non html */
{
char buff[256];
- guess_httptype(opt, buff, urlfil);
+ guess_httptype(opt, buff, urlfil());
if (strcmp(buff, "image/gif") == 0)
create_gif_warning = 1;
}
@@ -1634,8 +1738,8 @@ int httpmirror(char *url1, httrackp * opt) {
}
}
- if (strnotempty(savename) == 0) { // pas de chemin de sauvegarde
- if (strcmp(urlfil, "/robots.txt") == 0) { // robots.txt
+ if (strnotempty(savename()) == 0) { // pas de chemin de sauvegarde
+ if (strcmp(urlfil(), "/robots.txt") == 0) { // robots.txt
if (r.adr) {
int bptr = 0;
char BIGSTK line[1024];
@@ -1711,7 +1815,7 @@ int httpmirror(char *url1, httrackp * opt) {
else {
hts_log_print(opt, LOG_NOTICE,
"Note: %s robots.txt rules are too restrictive, ignoring /",
- urladr);
+ urladr());
}
#endif
}
@@ -1719,13 +1823,13 @@ int httpmirror(char *url1, httrackp * opt) {
}
} while((bptr < r.size) && (strlen(buff) < (sizeof(buff) - 32)));
if (strnotempty(buff)) {
- checkrobots_set(&robots, urladr, buff);
+ checkrobots_set(&robots, urladr(), buff);
hts_log_print(opt, LOG_INFO,
"Note: robots.txt forbidden links for %s are: %s",
- urladr, infobuff);
+ urladr(), infobuff);
hts_log_print(opt, LOG_NOTICE,
"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);
+ urladr(), infobuff);
}
}
}
@@ -1743,12 +1847,12 @@ int httpmirror(char *url1, httrackp * opt) {
// Si par la suite on doit retraiter ce fichier avec un niveau de récursion plus
// fort, on supprimera le readme, et on scannera le fichier html!
// note: sauté si store_errpage (càd si page d'erreur, non à scanner!)
- if ((is_hypertext_mime(opt, r.contenttype, urlfil)) && (!store_errpage) && (r.size > 0)) { // c'est du html!!
+ if ((is_hypertext_mime(opt, r.contenttype, urlfil())) && (!store_errpage) && (r.size > 0)) { // c'est du html!!
char BIGSTK tempo[HTS_URLMAXSIZE * 2];
FILE *fp;
tempo[0] = '\0';
- strcpybuff(tempo, savename);
+ strcpybuff(tempo, savename());
strcatbuff(tempo, ".readme");
#if HTS_DOSNAME
@@ -1771,7 +1875,7 @@ int httpmirror(char *url1, httrackp * opt) {
HTTRACK_VERSION "%s" CRLF "" CRLF,
hts_get_version_info(opt));
fprintf(fp, "The file %s has not been scanned by HTS" CRLF,
- savename);
+ savename());
fprintf(fp,
"Some links contained in it may be unreachable locally."
CRLF);
@@ -1788,15 +1892,15 @@ int httpmirror(char *url1, httrackp * opt) {
hts_log_print(opt, LOG_WARNING,
"Warning: store %s without scan: %s", r.contenttype,
- savename);
+ savename());
} else {
if ((opt->getmode & 2) != 0) { // ok autorisé
hts_log_print(opt, LOG_DEBUG, "Store %s: %s", r.contenttype,
- savename);
+ savename());
} else { // lien non autorisé! (ex: cgi-bin en html)
hts_log_print(opt, LOG_DEBUG,
"non-html file ignored after upload at %s : %s",
- urladr, urlfil);
+ urladr(), urlfil());
if (r.adr) {
freet(r.adr);
r.adr = NULL;
@@ -1808,8 +1912,8 @@ int httpmirror(char *url1, httrackp * opt) {
// ATTENTION C'EST ICI QU'ON SAUVE LE FICHIER!!
if (r.adr != NULL || r.size == 0) {
- file_notify(opt, urladr, urlfil, savename, 1, 1, r.notmodified);
- if (filesave(opt, r.adr, (int) r.size, savename, urladr, urlfil) !=
+ file_notify(opt, urladr(), urlfil(), savename(), 1, 1, r.notmodified);
+ if (filesave(opt, r.adr, (int) r.size, savename(), urladr(), urlfil()) !=
0) {
int fcheck;
@@ -1819,7 +1923,7 @@ int httpmirror(char *url1, httrackp * opt) {
opt->state.exit_xh = -1; /* fatal error */
}
hts_log_print(opt, LOG_ERROR | LOG_ERRNO,
- "Unable to save file %s", savename);
+ "Unable to save file %s", savename());
} else {
/*
if (!ishttperror(r.statuscode))
@@ -1834,9 +1938,9 @@ int httpmirror(char *url1, httrackp * opt) {
/* Parsing of other media types (java, ram..) */
/*
if (strfield2(r.contenttype,"audio/x-pn-realaudio")) {
- hts_log_print(opt, LOG_DEBUG, "(Real Media): parsing %s",savename);
- if (fexist(savename)) { // ok, existe bien!
- FILE* fp=FOPEN(savename,"r+b");
+ 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) {
if (!fseek(fp,0,SEEK_SET)) {
char BIGSTK line[HTS_URLMAXSIZE*2];
@@ -1852,7 +1956,7 @@ int httpmirror(char *url1, httrackp * opt) {
/* External modules */
if (opt->parsejava && (opt->parsejava & HTSPARSE_NO_CLASS) == 0
- && fexist(savename)) {
+ && fexist(savename())) {
char BIGSTK buff_err_msg[1024];
htsmoduleStruct BIGSTK str;
@@ -1860,37 +1964,32 @@ int httpmirror(char *url1, httrackp * opt) {
memset(&str, 0, sizeof(str));
/* */
str.err_msg = buff_err_msg;
- str.filename = savename;
+ str.filename = savename();
str.mime = r.contenttype;
- str.url_host = urladr;
- str.url_file = urlfil;
+ str.url_host = urladr();
+ str.url_file = urlfil();
str.size = (int) r.size;
/* */
str.addLink = htsAddLink;
/* */
- str.liens = liens;
str.opt = opt;
str.sback = sback;
str.cache = &cache;
str.hashptr = hashptr;
str.numero_passe = numero_passe;
- str.add_tab_alloc = add_tab_alloc;
- /* */
- str.lien_tot_ = &lien_tot;
str.ptr_ = &ptr;
- str.lien_size_ = &lien_size;
- str.lien_buffer_ = &lien_buffer;
+
/* Parse if recognized */
switch (hts_parse_externals(&str)) {
case 1:
hts_log_print(opt, LOG_DEBUG,
"(External module): parsed successfully %s",
- savename);
+ savename());
break;
case 0:
hts_log_print(opt, LOG_DEBUG,
"(External module): couldn't parse successfully %s : %s",
- savename, str.err_msg);
+ savename(), str.err_msg);
break;
}
}
@@ -1898,8 +1997,8 @@ int httpmirror(char *url1, httrackp * opt) {
} // text/html ou autre
/* Post-processing */
- if (fexist(savename)) {
- usercommand(opt, 0, NULL, savename, urladr, urlfil);
+ if (fexist(savename())) {
+ usercommand(opt, 0, NULL, savename(), urladr(), urlfil());
}
} // if !error
@@ -1918,19 +2017,19 @@ int httpmirror(char *url1, httrackp * opt) {
if (opt->getmode & 4) { // sauver les non html après
// sauter les fichiers selon la passe
if (!numero_passe) {
- while((ptr < lien_tot) ? (liens[ptr]->pass2) : 0)
+ while((ptr < opt->lien_tot) ? (heap(ptr)->pass2) : 0)
ptr++;
} else {
- while((ptr < lien_tot) ? (!liens[ptr]->pass2) : 0)
+ while((ptr < opt->lien_tot) ? (!heap(ptr)->pass2) : 0)
ptr++;
}
- if (ptr >= lien_tot) { // fin de boucle
+ if (ptr >= opt->lien_tot) { // fin de boucle
if (!numero_passe) { // première boucle
hts_log_print(opt, LOG_DEBUG, "Now getting non-html files...");
numero_passe = 1; // seconde boucle
ptr = 0;
// prochain pass2
- while((ptr < lien_tot) ? (!liens[ptr]->pass2) : 0)
+ while((ptr < opt->lien_tot) ? (!heap(ptr)->pass2) : 0)
ptr++;
//printf("first link==%d\n");
@@ -1944,16 +2043,16 @@ int httpmirror(char *url1, httrackp * opt) {
//}
// a-t-on dépassé le quota?
if (!back_checkmirror(opt)) {
- ptr = lien_tot;
+ ptr = opt->lien_tot;
} else if (opt->state.exit_xh) { // sortir
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;
+ ptr = opt->lien_tot;
}
- } while(ptr < lien_tot);
+ } while(ptr < opt->lien_tot);
//
//
//
@@ -2155,7 +2254,7 @@ int httpmirror(char *url1, httrackp * opt) {
"HTTrack Website Copier/" HTTRACK_VERSION
" mirror complete in %s : " "%d links scanned, %d files written ("
LLintP " bytes overall)%s " "[" LLintP " bytes received at " LLintP
- " bytes/sec]", htstime, (int) lien_tot - 1,
+ " bytes/sec]", htstime, (int) opt->lien_tot - 1,
(int) HTS_STAT.stat_files, (LLint) HTS_STAT.stat_bytes, infoupdated,
(LLint) HTS_STAT.HTS_TOTAL_RECV, (LLint) n);
@@ -2343,18 +2442,18 @@ void host_ban(httrackp * opt, lien_url ** liens, int ptr, int lien_tot,
// effacer liens
//l=strlen(host);
for(i = 0; i < lien_tot; i++) {
- //if (liens[i]->adr_len==l) { // même taille de chaîne
+ //if (heap(i)->adr_len==l) { // même taille de chaîne
// Calcul de taille sécurisée
- if (liens[i]) {
- if (liens[i]->adr) {
+ if (heap(i)) {
+ if (heap(i)->adr) {
int l = 0;
- while((liens[i]->adr[l]) && (l < 1020))
+ while((heap(i)->adr[l]) && (l < 1020))
l++;
if ((l > 0) && (l < 1020)) { // sécurité
- if (strfield2(jump_identification(liens[i]->adr), host)) { // host
- hts_log_print(opt, LOG_DEBUG, "Cancel: %s%s", liens[i]->adr,
- liens[i]->fil);
+ if (strfield2(jump_identification(heap(i)->adr), host)) { // host
+ hts_log_print(opt, LOG_DEBUG, "Cancel: %s%s", heap(i)->adr,
+ heap(i)->fil);
hash_invalidate_entry(opt->hash, i); // invalidate hashtable entry
// on efface pas le hash, because si on rencontre le lien, reverif sav..
}
@@ -2363,13 +2462,13 @@ void host_ban(httrackp * opt, lien_url ** liens, int ptr, int lien_tot,
char dmp[1040];
dmp[0] = '\0';
- strncatbuff(dmp, liens[i]->adr, 1024);
+ strncatbuff(dmp, heap(i)->adr, 1024);
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);
+ heap(i)->adr, dmp);
}
}
} else {
@@ -3129,8 +3228,8 @@ int backlinks_done(struct_back * sback, lien_url ** liens, int lien_tot,
//Links done and stored in cache
for(i = ptr + 1; i < lien_tot; i++) {
- if (liens[i]) {
- if (liens[i]->pass2 == -1) {
+ if (heap(i)) {
+ if (heap(i)->pass2 == -1) {
n++;
}
}
@@ -3217,7 +3316,7 @@ int back_fill(struct_back * sback, httrackp * opt, cache_back * cache,
int ok = 1;
// on ne met pas le fichier en backing si il doit être traité après ou s'il a déja été traité
- if (liens[p]->pass2) { // 2è passe
+ if (heap(p)->pass2) { // 2è passe
if (numero_passe != 1)
ok = 0;
} else {
@@ -3226,24 +3325,24 @@ int back_fill(struct_back * sback, httrackp * opt, cache_back * cache,
}
// Why in hell did I do that ?
- //if (ok && liens[p]->sav != NULL && liens[p]->sav[0] != '\0'
- // && hash_read(opt->hash,liens[p]->sav,NULL,HASH_STRUCT_FILENAME ) >= 0) // lookup in liens_record
+ //if (ok && heap(p)->sav != NULL && heap(p)->sav[0] != '\0'
+ // && hash_read(opt->hash,heap(p)->sav,NULL,HASH_STRUCT_FILENAME ) >= 0) // lookup in liens_record
//{
// ok = 0;
//}
- if (liens[p]->sav == NULL || liens[p]->sav[0] == '\0'
- || hash_read(opt->hash, liens[p]->sav, NULL, HASH_STRUCT_FILENAME ) < 0) {
+ if (heap(p)->sav == NULL || heap(p)->sav[0] == '\0'
+ || hash_read(opt->hash, heap(p)->sav, NULL, HASH_STRUCT_FILENAME ) < 0) {
ok = 0;
}
// note: si un backing est fini, il reste en mémoire jusqu'à ce que
// le ptr l'atteigne
if (ok) {
if (!back_exist
- (sback, opt, liens[p]->adr, liens[p]->fil, liens[p]->sav)) {
+ (sback, opt, heap(p)->adr, heap(p)->fil, heap(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) {
+ (sback, opt, cache, heap(p)->adr, heap(p)->fil, heap(p)->sav,
+ heap(heap(p)->precedent)->adr, heap(heap(p)->precedent)->fil,
+ heap(p)->testmode) == -1) {
hts_log_print(opt, LOG_DEBUG,
"error: unable to add more links through back_add for back_fill");
#if BDEBUG==1
@@ -3253,7 +3352,7 @@ int back_fill(struct_back * sback, httrackp * opt, cache_back * cache,
} else {
n--;
#if BDEBUG==1
- printf("backing: %s%s\n", liens[p]->adr, liens[p]->fil);
+ printf("backing: %s%s\n", heap(p)->adr, heap(p)->fil);
#endif
}
}
@@ -3634,17 +3733,17 @@ int htsAddLink(htsmoduleStruct * str, char *link) {
}
// adr = c'est la même
// fil et save: save2 et fil2
- prio_fix = maximum(liens[ptr]->depth - 1, 0);
- pass_fix = max(liens[ptr]->pass2, numero_passe);
- if (liens[ptr]->cod)
- strcpybuff(codebase, liens[ptr]->cod); // codebase valable pour tt les classes descendantes
+ prio_fix = maximum(heap(ptr)->depth - 1, 0);
+ pass_fix = max(heap(ptr)->pass2, numero_passe);
+ if (heap(ptr)->cod)
+ strcpybuff(codebase, heap(ptr)->cod); // codebase valable pour tt les classes descendantes
if (strnotempty(codebase) == 0) { // pas de codebase, construire
char *a;
if (str->relativeToHtmlLink == 0)
- strcpybuff(codebase, liens[ptr]->fil);
+ strcpybuff(codebase, heap(ptr)->fil);
else
- strcpybuff(codebase, liens[liens[ptr]->precedent]->fil);
+ strcpybuff(codebase, heap(heap(ptr)->precedent)->fil);
a = codebase + strlen(codebase) - 1;
while((*a) && (*a != '/') && (a > codebase))
a--;
@@ -3678,13 +3777,13 @@ int htsAddLink(htsmoduleStruct * str, char *link) {
if (strnotempty(lien) && strlen(lien) < HTS_URLMAXSIZE) {
// calculer les chemins et noms de sauvegarde
- if (ident_url_relatif(lien, urladr, codebase, adr, fil) >= 0) { // reformage selon chemin
+ if (ident_url_relatif(lien, urladr(), codebase, adr, fil) >= 0) { // reformage selon chemin
int r;
int set_prio_to = 0;
int just_test_it = 0;
forbidden_url =
- hts_acceptlink(opt, ptr, lien_tot, liens, adr, fil, NULL, NULL,
+ hts_acceptlink(opt, ptr, opt->lien_tot, opt->liens, adr, fil, NULL, NULL,
&set_prio_to, &just_test_it);
hts_log_print(opt, LOG_DEBUG,
"result for wizard external module link: %d",
@@ -3702,8 +3801,8 @@ int htsAddLink(htsmoduleStruct * str, char *link) {
opt->savename_83 = 0;
// note: adr,fil peuvent être patchés
r =
- url_savename(adr, fil, save, NULL, NULL, NULL, NULL, opt, liens,
- lien_tot, sback, cache, hashptr, ptr, numero_passe,
+ url_savename(adr, fil, save, NULL, NULL, NULL, NULL, opt, opt->liens,
+ opt->lien_tot, sback, cache, hashptr, ptr, numero_passe,
NULL);
// resolve unresolved type
if (r != -1 && forbidden_url == 0 && IS_DELAYED_EXT(save)
@@ -3720,11 +3819,11 @@ int htsAddLink(htsmoduleStruct * str, char *link) {
opt->savename_type = a;
opt->savename_83 = b;
if (r != -1 && !forbidden_url) {
- if (savename) {
- if (lienrelatif(tempo, save, savename) == 0) {
+ if (savename()) {
+ if (lienrelatif(tempo, save, savename()) == 0) {
hts_log_print(opt, LOG_DEBUG,
"(module): relative link at %s build with %s and %s: %s",
- adr, save, savename, tempo);
+ adr, save, savename(), tempo);
if (str->localLink
&& str->localLinkSize > (int) strlen(tempo) + 1) {
strcpybuff(str->localLink, tempo);
@@ -3763,7 +3862,7 @@ int htsAddLink(htsmoduleStruct * str, char *link) {
int i = hash_read(hashptr, save, NULL, HASH_STRUCT_FILENAME ); // lecture type 0 (sav)
if (i >= 0) {
- liens[i]->depth = maximum(liens[i]->depth, prio_fix);
+ heap(i)->depth = maximum(heap(i)->depth, prio_fix);
dejafait = 1;
}
}
@@ -3773,43 +3872,38 @@ int htsAddLink(htsmoduleStruct * str, char *link) {
// >>>> CREER LE LIEN JAVA <<<<
// enregistrer fichier (MACRO)
- liens_record(adr, fil, save, "", "", opt->urlhack);
- if (liens[lien_tot] == NULL) { // erreur, pas de place réservée
+ if (!hts_record_link(opt, adr, fil, save, "", "", "")) { // erreur, pas de place réservée
printf("PANIC! : Not enough memory [%d]\n", __LINE__);
- hts_log_print(opt, LOG_PANIC,
- "Not enough memory, can not re-allocate %d bytes",
- (int) ((add_tab_alloc + 1) * sizeof(lien_url)));
+ hts_log_print(opt, LOG_PANIC, "Not enough memory");
opt->state.exit_xh = -1; /* fatal error -> exit */
return 0;
}
// mode test?
- liens[lien_tot]->testmode = 0; // pas mode test
-
- liens[lien_tot]->link_import = 0; // pas mode import
+ heap_top()->testmode = 0; // pas mode test
+ heap_top()->link_import = 0; // pas mode import
// écrire autres paramètres de la structure-lien
//if (meme_adresse)
- liens[lien_tot]->premier = liens[ptr]->premier;
+ heap_top()->premier = heap(ptr)->premier;
//else // sinon l'objet père est le précédent lui même
- // liens[lien_tot]->premier=ptr;
+ // heap_top()->premier=ptr;
- liens[lien_tot]->precedent = ptr;
+ heap_top()->precedent = ptr;
// noter la priorité
if (!set_prio_to)
- liens[lien_tot]->depth = prio_fix;
+ heap_top()->depth = prio_fix;
else
- liens[lien_tot]->depth = max(0, min(liens[ptr]->depth - 1, set_prio_to - 1)); // PRIORITE NULLE (catch page)
- liens[lien_tot]->pass2 = max(pass_fix, numero_passe);
- liens[lien_tot]->retry = opt->retry;
+ heap_top()->depth = max(0, min(heap(ptr)->depth - 1, set_prio_to - 1)); // PRIORITE NULLE (catch page)
+ heap_top()->pass2 = max(pass_fix, numero_passe);
+ heap_top()->retry = opt->retry;
- //strcpybuff(liens[lien_tot]->adr,adr);
- //strcpybuff(liens[lien_tot]->fil,fil);
- //strcpybuff(liens[lien_tot]->sav,save);
+ //strcpybuff(heap_top()->adr,adr);
+ //strcpybuff(heap_top()->fil,fil);
+ //strcpybuff(heap_top()->sav,save);
hts_log_print(opt, LOG_DEBUG, "(module): OK, NOTE: %s%s -> %s",
- liens[lien_tot]->adr, liens[lien_tot]->fil,
- liens[lien_tot]->sav);
+ heap_top()->adr, heap_top()->fil,
+ heap_top()->sav);
- lien_tot++; // UN LIEN DE PLUS
}
}
}
diff --git a/src/htscore.h b/src/htscore.h
index 93108cd..6c7d49f 100644
--- a/src/htscore.h
+++ b/src/htscore.h
@@ -135,21 +135,21 @@ typedef struct filecreate_params filecreate_params;
typedef struct lien_url lien_url;
#endif
struct lien_url {
- char firstblock; // flag 1=premier malloc
- char link_import; // lien importé à la suite d'un moved - ne pas appliquer les règles classiques up/down
- int depth; // profondeur autorisée lien ; >0 forte 0=faible
- int pass2; // traiter après les autres, seconde passe. si == -1, lien traité en background
- int premier; // pointeur sur le premier lien qui a donné lieu aux autres liens du domaine
- int precedent; // pointeur sur le lien qui a donné lieu à ce lien précis
- //int moved; // pointeur sur moved
- int retry; // nombre de retry restants
- int testmode; // mode test uniquement, envoyer juste un head!
char *adr; // adresse
char *fil; // nom du fichier distant
char *sav; // nom à sauver sur disque (avec chemin éventuel)
char *cod; // chemin codebase éventuel si classe java
char *former_adr; // adresse initiale (avant éventuel moved), peut être nulle
char *former_fil; // nom du fichier distant initial (avant éventuel moved), peut être nul
+
+ int premier; // pointeur sur le premier lien qui a donné lieu aux autres liens du domaine
+ int precedent; // pointeur sur le lien qui a donné lieu à ce lien précis
+ int depth; // profondeur autorisée lien ; >0 forte 0=faible
+ int pass2; // traiter après les autres, seconde passe. si == -1, lien traité en background
+ char link_import; // lien importé à la suite d'un moved - ne pas appliquer les règles classiques up/down
+ //int moved; // pointeur sur moved
+ int retry; // nombre de retry restants
+ int testmode; // mode test uniquement, envoyer juste un head!
};
// chargement de fichiers en 'arrière plan'
@@ -255,7 +255,7 @@ typedef struct hash_struct hash_struct;
#endif
struct hash_struct {
/* Links big array reference */
- const lien_url **liens;
+ const lien_url ***liens;
/* Savename (case insensitive ; lowercased) */
inthash sav;
/* Address and path */
@@ -278,6 +278,20 @@ struct filecreate_params {
char path[HTS_URLMAXSIZE * 2];
};
+/* Access macros. */
+#define heap(N) (opt->liens[N])
+#define heap_top_index() (opt->lien_tot - 1)
+#define heap_top() (heap(heap_top_index()))
+#define urladr() (heap(ptr)->adr)
+#define urlfil() (heap(ptr)->fil)
+#define savename() (heap(ptr)->sav)
+#define parenturladr() (heap(heap(ptr)->precedent)->adr)
+#define parenturlfil() (heap(heap(ptr)->precedent)->fil)
+#define parentsavename() (heap(heap(ptr)->precedent)->sav)
+#define relativeurladr() ((!parent_relative)?urladr():parenturladr())
+#define relativeurlfil() ((!parent_relative)?urlfil():parenturlfil())
+#define relativesavename() ((!parent_relative)?savename():parentsavename())
+
/* Library internal definictions */
#ifdef HTS_INTERNAL_BYTECODE
@@ -302,7 +316,18 @@ char *hts_cancel_file_pop(httrackp * opt);
#endif
-//
+// add a link on the heap
+int hts_record_link(httrackp * opt,
+ const char *address, const char *file, const char *save,
+ const char *ref_address, const char *ref_file,
+ const char *codebase);
+
+// index of the latest added link
+size_t hts_record_link_latest(httrackp *opt);
+
+// wipe all records
+void hts_record_init(httrackp *opt);
+void hts_record_free(httrackp *opt);
//int httpmirror(char* url,int level,httrackp opt);
int httpmirror(char *url1, httrackp * opt);
diff --git a/src/htshash.c b/src/htshash.c
index ce6e1fa..4e0475f 100644
--- a/src/htshash.c
+++ b/src/htshash.c
@@ -307,25 +307,25 @@ int hash_read(const hash_struct * hash, const char *nom1, const char *nom2,
}
// enregistrement lien lpos dans les 3 tables hash1..3
-void hash_write(hash_struct * hash, int lpos) {
+void hash_write(hash_struct * hash, size_t lpos) {
/* first entry: destination filename (lowercased) */
- inthash_write(hash->sav, hash->liens[lpos]->sav, lpos);
+ inthash_write(hash->sav, (*hash->liens)[lpos]->sav, lpos);
/* second entry: URL address and path */
- inthash_write(hash->adrfil, (char*) hash->liens[lpos], lpos);
+ inthash_write(hash->adrfil, (char*) (*hash->liens)[lpos], lpos);
/* third entry: URL address and path before redirect */
- if (hash->liens[lpos]->former_adr) { // former_adr existe?
- inthash_write(hash->former_adrfil, (char*) hash->liens[lpos], lpos);
+ if ((*hash->liens)[lpos]->former_adr) { // former_adr existe?
+ inthash_write(hash->former_adrfil, (char*) (*hash->liens)[lpos], lpos);
}
}
void hash_invalidate_entry(hash_struct * hash, int lpos) {
- if (inthash_remove(hash->adrfil, (char*) hash->liens[lpos])) {
+ if (inthash_remove(hash->adrfil, (char*) (*hash->liens)[lpos])) {
/* devalidate entry now it is removed from hashtable */
- strcpybuff(hash->liens[lpos]->adr, "!");
+ strcpybuff((*hash->liens)[lpos]->adr, "!");
/* add back */
- inthash_write(hash->adrfil, (char*) hash->liens[lpos], lpos);
+ inthash_write(hash->adrfil, (char*) (*hash->liens)[lpos], lpos);
} else {
assertf(! "error invalidating hash entry");
}
diff --git a/src/htshash.h b/src/htshash.h
index 6a71cba..b6ee417 100644
--- a/src/htshash.h
+++ b/src/htshash.h
@@ -55,7 +55,7 @@ void hash_init(httrackp *opt, hash_struct *hash, int normalized);
void hash_free(hash_struct *hash);
int hash_read(const hash_struct * hash, const char *nom1, const char *nom2,
hash_struct_type type);
-void hash_write(hash_struct * hash, int lpos);
+void hash_write(hash_struct * hash, size_t lpos);
void hash_invalidate_entry(hash_struct * hash, int lpos);
int *hash_calc_chaine(hash_struct * hash, hash_struct_type type, int pos);
unsigned long int hash_cle(const char *nom1, const char *nom2);
diff --git a/src/htsmodules.h b/src/htsmodules.h
index 077a720..f38b4e2 100644
--- a/src/htsmodules.h
+++ b/src/htsmodules.h
@@ -104,17 +104,12 @@ struct htsmoduleStruct {
httrackp *opt;
/* Internal use - please don't touch */
- lien_url **liens;
struct_back *sback;
cache_back *cache;
hash_struct *hashptr;
int numero_passe;
- int add_tab_alloc;
/* */
- int *lien_tot_;
int *ptr_;
- size_t *lien_size_;
- char **lien_buffer_;
const char *page_charset_;
/* Internal use - please don't touch */
diff --git a/src/htsopt.h b/src/htsopt.h
index 4a40420..fc7a4cc 100644
--- a/src/htsopt.h
+++ b/src/htsopt.h
@@ -274,6 +274,11 @@ typedef enum htsparsejava_flags {
HTSPARSE_NO_AGGRESSIVE = 8 // don't aggressively parse .js or .java
} htsparsejava_flags;
+#ifndef HTS_DEF_FWSTRUCT_lien_buffers
+#define HTS_DEF_FWSTRUCT_lien_buffers
+typedef struct lien_buffers lien_buffers;
+#endif
+
// paramètres httrack (options)
#ifndef HTS_DEF_FWSTRUCT_httrackp
#define HTS_DEF_FWSTRUCT_httrackp
@@ -362,7 +367,9 @@ struct httrackp {
String urllist; // fichier liste de filtres à inclure
htsfilters filters; // contient les pointeurs pour les filtres
hash_struct *hash; // hash structure
- lien_url **liens; // liens
+ lien_url **liens; // links
+ int lien_tot; // top index of "links" heap (always out-of-range)
+ lien_buffers *liensbuf; // links buffers
robots_wizard *robotsptr; // robots ptr
String lang_iso; // en, fr ..
String accept; // Accept:
diff --git a/src/htsparse.c b/src/htsparse.c
index a8ee0f3..e49b00f 100644
--- a/src/htsparse.c
+++ b/src/htsparse.c
@@ -60,17 +60,6 @@ Please visit our Website: http://www.httrack.com
#include "htsparse.h"
#include "htsback.h"
-// specific defines
-#define urladr (liens[ptr]->adr)
-#define urlfil (liens[ptr]->fil)
-#define savename (liens[ptr]->sav)
-#define parenturladr (liens[liens[ptr]->precedent]->adr)
-#define parenturlfil (liens[liens[ptr]->precedent]->fil)
-#define parentsavename (liens[liens[ptr]->precedent]->sav)
-#define relativeurladr ((!parent_relative)?urladr:parenturladr)
-#define relativeurlfil ((!parent_relative)?urlfil:parenturlfil)
-#define relativesavename ((!parent_relative)?savename:parentsavename)
-
// does nothing
#define XH_uninit do {} while(0)
@@ -148,25 +137,25 @@ Please visit our Website: http://www.httrack.com
int ok=0;\
if (ht_buff) { \
char digest[32+2];\
- off_t fsize_old = fsize(fconv(OPT_GET_BUFF(opt),OPT_GET_BUFF_SIZE(opt),savename));\
+ off_t fsize_old = fsize(fconv(OPT_GET_BUFF(opt),OPT_GET_BUFF_SIZE(opt),savename()));\
digest[0]='\0';\
domd5mem(ht_buff,ht_len,digest,1);\
if (fsize_old==ht_len) { \
int mlen = 0;\
char* mbuff;\
- cache_readdata(cache,"//[HTML-MD5]//",savename,&mbuff,&mlen);\
+ cache_readdata(cache,"//[HTML-MD5]//",savename(),&mbuff,&mlen);\
if (mlen) \
mbuff[mlen]='\0';\
if ((mlen == 32) && (strcmp(((mbuff!=NULL)?mbuff:""),digest)==0)) {\
ok=1;\
- hts_log_print(opt, LOG_DEBUG, "File not re-written (md5): %s",savename);\
+ hts_log_print(opt, LOG_DEBUG, "File not re-written (md5): %s",savename());\
} else {\
ok=0;\
} \
}\
if (!ok) { \
- file_notify(opt,urladr, urlfil, savename, 1, 1, r->notmodified); \
- fp=filecreate(&opt->state.strc, savename); \
+ file_notify(opt,urladr(), urlfil(), savename(), 1, 1, r->notmodified); \
+ fp=filecreate(&opt->state.strc, savename()); \
if (fp) { \
if (ht_len>0) {\
if (fwrite(ht_buff,1,ht_len,fp) != ht_len) { \
@@ -175,7 +164,7 @@ Please visit our Website: http://www.httrack.com
opt->state.exit_xh=-1;\
}\
if (opt->log) { \
- hts_log_print(opt, LOG_ERROR | LOG_ERRNO, "Unable to write HTML file %s", savename);\
+ hts_log_print(opt, LOG_ERROR | LOG_ERRNO, "Unable to write HTML file %s", savename());\
if (fcheck) {\
hts_log_print(opt, LOG_ERROR, "* * Fatal write error, giving up");\
}\
@@ -184,24 +173,24 @@ Please visit our Website: http://www.httrack.com
}\
fclose(fp); fp=NULL; \
if (strnotempty(r->lastmodified)) \
- set_filetime_rfc822(savename,r->lastmodified); \
+ set_filetime_rfc822(savename(),r->lastmodified); \
} else {\
int fcheck;\
if ((fcheck=check_fatal_io_errno())) {\
hts_log_print(opt, LOG_ERROR, "Mirror aborted: disk full or filesystem problems"); \
opt->state.exit_xh=-1;\
}\
- hts_log_print(opt, LOG_ERROR | LOG_ERRNO, "Unable to save file %s", savename);\
+ 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 {\
- file_notify(opt,urladr, urlfil, savename, 0, 0, r->notmodified); \
- filenote(&opt->state.strc, savename,NULL); \
+ file_notify(opt,urladr(), urlfil(), savename(), 0, 0, r->notmodified); \
+ filenote(&opt->state.strc, savename(),NULL); \
}\
if (cache->ndx)\
- cache_writedata(cache->ndx,cache->dat,"//[HTML-MD5]//",savename,digest,(int)strlen(digest));\
+ cache_writedata(cache->ndx,cache->dat,"//[HTML-MD5]//",savename(),digest,(int)strlen(digest));\
} \
freet(ht_buff); ht_buff=NULL; \
}
@@ -231,74 +220,6 @@ Please visit our Website: http://www.httrack.com
makeindex_done=1; /* ok c'est fait */ \
} while(0)
-// Enregistrement d'un lien:
-// on calcule la taille nécessaire: taille des 3 chaînes à stocker (taille forcée paire, plus 2 octets de sécurité)
-// puis on vérifie qu'on a assez de marge dans le buffer - sinon on en réalloue un autre
-// enfin on écrit à l'adresse courante du buffer, qu'on incrémente. on décrémente la taille dispo d'autant ensuite
-// codebase: si non nul et si .class stockee on le note pour chemin primaire pour classes
-// FA,FS: former_adr et former_fil, lien original
-#define liens_record_sav_len(A)
-
-// COPIE DE HTSCORE.C
-
-#define liens_record(A,F,S,FA,FF) { \
- int notecode=0; \
- size_t lienurl_len=((sizeof(lien_url)+HTS_ALIGN-1)/HTS_ALIGN)*HTS_ALIGN,\
- adr_len=strlen(A),\
- fil_len=strlen(F),\
- sav_len=strlen(S),\
- cod_len=0,\
- former_adr_len=strlen(FA),\
- former_fil_len=strlen(FF); \
- if (former_adr_len>0) {\
- former_adr_len=(former_adr_len/HTS_ALIGN)*HTS_ALIGN+HTS_ALIGN*2; \
- former_fil_len=(former_fil_len/HTS_ALIGN)*HTS_ALIGN+HTS_ALIGN*2; \
- } else \
- former_adr_len=former_fil_len=0;\
- if (strlen(F)>6) if (strnotempty(codebase)) if (strfield(F+strlen(F)-6,".class")) {\
- notecode=1; \
- cod_len=strlen(codebase); \
- cod_len=(cod_len/HTS_ALIGN)*HTS_ALIGN+HTS_ALIGN*2; \
- } \
- adr_len=(adr_len/HTS_ALIGN)*HTS_ALIGN+HTS_ALIGN*2; \
- fil_len=(fil_len/HTS_ALIGN)*HTS_ALIGN+HTS_ALIGN*2; \
- sav_len=(sav_len/HTS_ALIGN)*HTS_ALIGN+HTS_ALIGN*2; \
- if ((int) lien_size < (int) (adr_len+fil_len+sav_len+cod_len+former_adr_len+former_fil_len+lienurl_len)) { \
- lien_buffer=(char*) ((void*) calloct(add_tab_alloc,1)); \
- lien_size=add_tab_alloc; \
- if (lien_buffer!=NULL) { \
- liens[lien_tot]=(lien_url*) (void*) lien_buffer; lien_buffer+=lienurl_len; lien_size-=lienurl_len; \
- liens[lien_tot]->firstblock=1; \
- } \
- } else { \
- liens[lien_tot]=(lien_url*) (void*) lien_buffer; lien_buffer+=lienurl_len; lien_size-=lienurl_len; \
- liens[lien_tot]->firstblock=0; \
- } \
- if (liens[lien_tot]!=NULL) { \
- liens[lien_tot]->adr=lien_buffer; lien_buffer+=adr_len; lien_size-=adr_len; \
- liens[lien_tot]->fil=lien_buffer; lien_buffer+=fil_len; lien_size-=fil_len; \
- liens[lien_tot]->sav=lien_buffer; lien_buffer+=sav_len; lien_size-=sav_len; \
- liens[lien_tot]->cod=NULL; \
- if (notecode) { \
- liens[lien_tot]->cod=lien_buffer; \
- lien_buffer+=cod_len; \
- lien_size-=cod_len; \
- strcpybuff(liens[lien_tot]->cod,codebase); \
- } \
- if (former_adr_len>0) {\
- liens[lien_tot]->former_adr=lien_buffer; lien_buffer+=former_adr_len; lien_size-=former_adr_len; \
- liens[lien_tot]->former_fil=lien_buffer; lien_buffer+=former_fil_len; lien_size-=former_fil_len; \
- strcpybuff(liens[lien_tot]->former_adr,FA); \
- strcpybuff(liens[lien_tot]->former_fil,FF); \
- }\
- strcpybuff(liens[lien_tot]->adr,A); \
- strcpybuff(liens[lien_tot]->fil,F); \
- strcpybuff(liens[lien_tot]->sav,S); \
- liens_record_sav_len(liens[lien_tot]); \
- hash_write(hashptr,lien_tot); \
- } \
-}
-
#define ENGINE_DEFINE_CONTEXT() \
ENGINE_DEFINE_CONTEXT_BASE(); \
/* */ \
@@ -316,7 +237,6 @@ Please visit our Website: http://www.httrack.com
/* */ \
int error = * stre->error_; \
int store_errpage = * stre->store_errpage_; \
- int lien_max = *stre->lien_max_; \
/* */ \
int makeindex_done = *stre->makeindex_done_; \
FILE* makeindex_fp = *stre->makeindex_fp_; \
@@ -331,7 +251,6 @@ Please visit our Website: http://www.httrack.com
/* */ \
error = * stre->error_; \
store_errpage = * stre->store_errpage_; \
- lien_max = *stre->lien_max_; \
/* */ \
makeindex_done = *stre->makeindex_done_; \
makeindex_fp = *stre->makeindex_fp_; \
@@ -349,7 +268,6 @@ Please visit our Website: http://www.httrack.com
/* */ \
* stre->error_ = error; \
* stre->store_errpage_ = store_errpage; \
- * stre->lien_max_ = lien_max; \
/* */ \
*stre->makeindex_done_ = makeindex_done; \
*stre->makeindex_fp_ = makeindex_fp; \
@@ -396,26 +314,26 @@ int htsparse(htsmoduleStruct * str, htsmoduleStructExtended * stre) {
char *cAddr = r->adr;
int cSize = (int) r->size;
- hts_log_print(opt, LOG_DEBUG, "engine: preprocess-html: %s%s", urladr,
- urlfil);
- if (RUN_CALLBACK4(opt, preprocess, &cAddr, &cSize, urladr, urlfil) == 1) {
+ 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;
}
}
- if (RUN_CALLBACK4(opt, check_html, r->adr, (int) r->size, urladr, urlfil)) {
+ if (RUN_CALLBACK4(opt, check_html, r->adr, (int) r->size, urladr(), urlfil())) {
FILE *fp = NULL; // fichier écrit localement
char *adr = r->adr; // pointeur (on parcourt)
char *lastsaved; // adresse du dernier octet sauvé + 1
- hts_log_print(opt, LOG_DEBUG, "scanning file %s%s (%s)..", urladr, urlfil,
- savename);
+ 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,
+ (r->adr, r->size, r->contenttype, savename(),
StringBuff(opt->path_html_utf8))) {
hts_log_print(opt, LOG_DEBUG, "indexing file..done");
} else {
@@ -545,7 +463,7 @@ int htsparse(htsmoduleStruct * str, htsmoduleStructExtended * stre) {
(opt, r->contenttype, str->url_file,
"application/x-javascript") != 0) {
// all links must be checked against parent, not this link
- if (liens[ptr]->precedent != 0) {
+ if (heap(ptr)->precedent != 0) {
parent_relative = 1;
}
}
@@ -633,7 +551,7 @@ int htsparse(htsmoduleStruct * str, htsmoduleStructExtended * stre) {
// Ici on teste si l'on doit construire l'index vers le(s) site(s) miroir(s)
if (!makeindex_done) { // autoriation d'écrire un index
if (!detect_title) {
- if (opt->depth == liens[ptr]->depth) { // on note toujours les premiers liens
+ if (opt->depth == heap(ptr)->depth) { // on note toujours les premiers liens
if (!in_media) {
if (opt->makeindex && (ptr > 0)) {
if (opt->getmode & 1) { // autorisation d'écrire
@@ -694,7 +612,7 @@ int htsparse(htsmoduleStruct * str, htsmoduleStructExtended * stre) {
}
}
if (lienrelatif
- (tempo, liens[ptr]->sav,
+ (tempo, heap(ptr)->sav,
concat(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt),
StringBuff(opt->path_html_utf8),
"index.html")) == 0) {
@@ -740,7 +658,7 @@ int htsparse(htsmoduleStruct * str, htsmoduleStructExtended * stre) {
}
}
- } else if (liens[ptr]->depth < opt->depth) { // on a sauté level1+1 et level1
+ } else if (heap(ptr)->depth < opt->depth) { // on a sauté level1+1 et level1
HT_INDEX_END;
}
} // if (opt->makeindex)
@@ -831,7 +749,7 @@ int htsparse(htsmoduleStruct * str, htsmoduleStructExtended * stre) {
time_gmt_rfc822(gmttime);
strcatbuff(tempo, eol);
sprintf(tempo + strlen(tempo), StringBuff(opt->footer),
- jump_identification(urladr), urlfil, gmttime,
+ jump_identification(urladr()), urlfil(), gmttime,
HTTRACK_VERSIONID, "", "", "", "", "", "", "");
strcatbuff(tempo, eol);
//fwrite(tempo,1,strlen(tempo),fp);
@@ -1328,12 +1246,12 @@ int htsparse(htsmoduleStruct * str, htsmoduleStructExtended * stre) {
#if DEBUG_ROBOTS
printf
("robots.txt meta tag: nofollow in %s%s\n",
- urladr, urlfil);
+ urladr(), urlfil());
#endif
nofollow = 1; // NE PLUS suivre liens dans cette page
hts_log_print(opt, LOG_WARNING,
"Link %s%s not scanned (follow robots meta tag)",
- urladr, urlfil);
+ urladr(), urlfil());
}
}
}
@@ -2314,7 +2232,7 @@ int htsparse(htsmoduleStruct * str, htsmoduleStructExtended * stre) {
if (!link_has_authority(lien)) { // pas de http://
char BIGSTK adr2[HTS_URLMAXSIZE * 2], fil2[HTS_URLMAXSIZE * 2]; // ** euh ident_url_relatif??
- if (ident_url_relatif(lien, urladr, urlfil, adr2, fil2) <
+ if (ident_url_relatif(lien, urladr(), urlfil(), adr2, fil2) <
0) {
error = 1;
} else {
@@ -2335,7 +2253,7 @@ int htsparse(htsmoduleStruct * str, htsmoduleStructExtended * stre) {
}
//char BIGSTK tempo[HTS_URLMAXSIZE*2];
//strcpybuff(tempo,"http://");
- //strcatbuff(tempo,urladr); // host
+ //strcatbuff(tempo,urladr()); // host
//if (*lien!='/')
// strcatbuff(tempo,"/");
//strcatbuff(tempo,lien);
@@ -2402,7 +2320,7 @@ int htsparse(htsmoduleStruct * str, htsmoduleStructExtended * stre) {
HTS_URLMAXSIZE) {
// mailto: and co: do NOT add base
if (ident_url_relatif
- (lien, urladr, urlfil, adr, fil) >= 0) {
+ (lien, urladr(), urlfil(), adr, fil) >= 0) {
char BIGSTK tempo[HTS_URLMAXSIZE * 2];
// base est absolue
@@ -2462,9 +2380,9 @@ int htsparse(htsmoduleStruct * str, htsmoduleStructExtended * stre) {
hts_log_print(opt, LOG_DEBUG,
"build relative link %s with %s%s", lien,
- relativeurladr, relativeurlfil);
+ relativeurladr(), relativeurlfil());
if ((reponse =
- ident_url_relatif(lien, relativeurladr, relativeurlfil,
+ ident_url_relatif(lien, relativeurladr(), relativeurlfil(),
adr, fil)) < 0) {
adr[0] = '\0'; // erreur
if (reponse == -2) {
@@ -2474,12 +2392,12 @@ int htsparse(htsmoduleStruct * str, htsmoduleStructExtended * stre) {
} else {
hts_log_print(opt, LOG_DEBUG,
"ident_url_relatif failed for %s with %s%s",
- lien, relativeurladr, relativeurlfil);
+ lien, relativeurladr(), relativeurlfil());
}
} else {
hts_log_print(opt, LOG_DEBUG,
"built relative link %s with %s%s -> %s%s",
- lien, relativeurladr, relativeurlfil, adr,
+ lien, relativeurladr(), relativeurlfil(), adr,
fil);
}
} else {
@@ -2506,7 +2424,7 @@ int htsparse(htsmoduleStruct * str, htsmoduleStructExtended * stre) {
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,
+ hts_acceptlink(opt, ptr, opt->lien_tot, opt->liens, adr, fil,
intag_name ? intag_name : NULL,
intag_name ? tag_attr_start : NULL,
&set_prio_to, &just_test_it);
@@ -2519,13 +2437,13 @@ int htsparse(htsmoduleStruct * str, htsmoduleStructExtended * stre) {
// calculer meme_adresse
meme_adresse =
strfield2(jump_identification(adr),
- jump_identification(urladr));
+ jump_identification(urladr()));
// Début partie sauvegarde
// ici on forme le nom du fichier à sauver, et on patche l'URL
if (adr[0] != '\0') {
- // savename: simplifier les ../ et autres joyeusetés
+ // savename(): simplifier les ../ et autres joyeusetés
char BIGSTK save[HTS_URLMAXSIZE * 2];
int r_sv = 0;
@@ -2556,8 +2474,8 @@ int htsparse(htsmoduleStruct * str, htsmoduleStructExtended * stre) {
//strcpybuff(last_fil,fil); // ancien chemin
r_sv =
url_savename(adr, fil, save, former_adr, former_fil,
- liens[ptr]->adr, liens[ptr]->fil, opt,
- liens, lien_tot, sback, cache, hash, ptr,
+ heap(ptr)->adr, heap(ptr)->fil, opt,
+ opt->liens, opt->lien_tot, sback, cache, hash, ptr,
numero_passe, NULL);
if (strcmp(jump_identification(last_adr), jump_identification(adr)) != 0) { // a changé
@@ -2573,7 +2491,7 @@ int htsparse(htsmoduleStruct * str, htsmoduleStructExtended * stre) {
"wizard moved link retest at %s%s..",
adr, fil);
forbidden_url =
- hts_acceptlink(opt, ptr, lien_tot, liens, adr,
+ hts_acceptlink(opt, ptr, opt->lien_tot, opt->liens, adr,
fil,
intag_name ? intag_name : NULL,
intag_name ? tag_attr_start :
@@ -2600,8 +2518,8 @@ int htsparse(htsmoduleStruct * str, htsmoduleStructExtended * stre) {
// pas d'erreur, on continue
r_sv =
- hts_wait_delayed(str, adr, fil, save, liens[ptr]->adr,
- liens[ptr]->fil, former_adr, former_fil,
+ hts_wait_delayed(str, adr, fil, save, heap(ptr)->adr,
+ heap(ptr)->fil, former_adr, former_fil,
&forbidden_url);
/* User interaction, because hts_wait_delayed can be slow.. (3.43) */
@@ -2777,7 +2695,7 @@ int htsparse(htsmoduleStruct * str, htsmoduleStructExtended * stre) {
strcpybuff(save, StringBuff(opt->path_html_utf8));
strcatbuff(save, cat_name);
- if (lienrelatif(tempo, save, relativesavename) ==
+ if (lienrelatif(tempo, save, relativesavename()) ==
0) {
/* Never escape high-chars (we don't know the encoding!!) */
inplace_escape_uri_utf(tempo, sizeof(tempo)); // escape with %xx
@@ -3009,7 +2927,7 @@ int htsparse(htsmoduleStruct * str, htsmoduleStructExtended * stre) {
tempo[0] = '\0';
// calculer le lien relatif
- if (lienrelatif(tempo, save, relativesavename) == 0) {
+ if (lienrelatif(tempo, save, relativesavename()) == 0) {
if (!in_media) { // In media (such as real audio): don't patch
/* Never escape high-chars (we don't know the encoding!!) */
inplace_escape_uri_utf(tempo, sizeof(tempo));
@@ -3026,7 +2944,7 @@ int htsparse(htsmoduleStruct * str, htsmoduleStructExtended * stre) {
}
hts_log_print(opt, LOG_DEBUG,
"relative link at %s build with %s and %s: %s",
- adr, save, relativesavename, tempo);
+ adr, save, relativesavename(), tempo);
// lien applet (code) - il faut placer un codebase avant
if (p_type == -1) { // que le nom de fichier
@@ -3115,7 +3033,7 @@ int htsparse(htsmoduleStruct * str, htsmoduleStructExtended * stre) {
} else {
hts_log_print(opt, LOG_WARNING,
"Error building relative link %s and %s",
- save, relativesavename);
+ save, relativesavename());
}
} // sinon le lien sera écrit normalement
@@ -3138,7 +3056,10 @@ int htsparse(htsmoduleStruct * str, htsmoduleStructExtended * stre) {
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!
+ if (0) {
+ // CLEANUP
+#if 0
+ if (opt->lien_tot + 1 >= lien_max - 4) { // trop de liens!
printf("PANIC! : Too many URLs : >%d [%d]\n", lien_tot,
__LINE__);
hts_log_print(opt, LOG_PANIC,
@@ -3154,7 +3075,7 @@ int htsparse(htsmoduleStruct * str, htsmoduleStructExtended * stre) {
}
XH_uninit; // désallocation mémoire & buffers
return -1;
-
+#endif
} else { // noter le lien sur la listes des liens à charger
int pass_fix, dejafait = 0;
@@ -3189,16 +3110,16 @@ int htsparse(htsmoduleStruct * str, htsmoduleStructExtended * stre) {
if (i >= 0) {
if ((opt->debug > 1) && (opt->log != NULL)) {
- if (strcmp(adr, liens[i]->adr) != 0
- || strcmp(fil, liens[i]->fil) != 0) {
+ if (strcmp(adr, heap(i)->adr) != 0
+ || strcmp(fil, heap(i)->fil) != 0) {
hts_log_print(opt, LOG_DEBUG,
"merging similar links %s%s and %s%s",
- adr, fil, liens[i]->adr,
- liens[i]->fil);
+ adr, fil, heap(i)->adr,
+ heap(i)->fil);
}
}
- liens[i]->depth =
- maximum(liens[i]->depth, liens[ptr]->depth - 1);
+ heap(i)->depth =
+ maximum(heap(i)->depth, heap(ptr)->depth - 1);
dejafait = 1;
}
}
@@ -3210,7 +3131,7 @@ int htsparse(htsmoduleStruct * str, htsmoduleStructExtended * stre) {
// >>>> CREER LE LIEN <<<<
//
// enregistrer lien à charger
- //liens[lien_tot]->adr[0]=liens[lien_tot]->fil[0]=liens[lien_tot]->sav[0]='\0';
+ //heap_top()->adr[0]=heap_top()->fil[0]=heap_top()->sav[0]='\0';
// même adresse: l'objet père est l'objet père de l'actuel
// DEBUT ROBOTS.TXT AJOUT
@@ -3224,17 +3145,11 @@ int htsparse(htsmoduleStruct * str, htsmoduleStructExtended * stre) {
checkrobots_set(_ROBOTS, adr, ""); // ajouter entrée vide
if (checkrobots(_ROBOTS, adr, "") == -1) { // robots.txt ?
// enregistrer robots.txt (MACRO)
- liens_record(adr, "/robots.txt", "", "",
- "");
- if (liens[lien_tot] == NULL) { // erreur, pas de place réservée
+ if (!hts_record_link(opt, adr, "/robots.txt", "", "", "", NULL)) {
printf
("PANIC! : Not enough memory [%d]\n",
__LINE__);
- hts_log_print(opt, LOG_PANIC,
- "Not enough memory, can not re-allocate %d bytes",
- (int) ((add_tab_alloc +
- 1) *
- sizeof(lien_url)));
+ hts_log_print(opt, LOG_PANIC, "Not enough memory");
if ((opt->getmode & 1) && (ptr > 0)) {
if (fp) {
fclose(fp);
@@ -3244,15 +3159,13 @@ int htsparse(htsmoduleStruct * str, htsmoduleStructExtended * stre) {
XH_uninit; // désallocation mémoire & buffers
return -1;
}
- liens[lien_tot]->testmode = 0; // pas mode test
- liens[lien_tot]->link_import = 0; // pas mode import
- liens[lien_tot]->premier = lien_tot;
- liens[lien_tot]->precedent = ptr;
- liens[lien_tot]->depth = 0;
- liens[lien_tot]->pass2 =
- max(0, numero_passe);
- liens[lien_tot]->retry = 0;
- lien_tot++; // UN LIEN DE PLUS
+ heap_top()->testmode = 0; // pas mode test
+ heap_top()->link_import = 0; // pas mode import
+ heap_top()->premier = heap_top_index();
+ heap_top()->precedent = ptr;
+ heap_top()->depth = 0;
+ heap_top()->pass2 = max(0, numero_passe);
+ heap_top()->retry = 0;
#if DEBUG_ROBOTS
printf
("robots.txt: added file robots.txt for %s\n",
@@ -3273,15 +3186,11 @@ int htsparse(htsmoduleStruct * str, htsmoduleStructExtended * stre) {
}
// FIN ROBOTS.TXT AJOUT
- // enregistrer (MACRO)
- liens_record(adr, fil, save, former_adr, former_fil);
- if (liens[lien_tot] == NULL) { // erreur, pas de place réservée
+ // enregistrer
+ if (!hts_record_link(opt, adr, fil, save, former_adr, former_fil, codebase)) {
printf("PANIC! : Not enough memory [%d]\n",
__LINE__);
- hts_log_print(opt, LOG_PANIC,
- "Not enough memory, can not re-allocate %d bytes",
- (int) ((add_tab_alloc +
- 1) * sizeof(lien_url)));
+ hts_log_print(opt, LOG_PANIC, "Not enough memory");
if ((opt->getmode & 1) && (ptr > 0)) {
if (fp) {
fclose(fp);
@@ -3293,47 +3202,46 @@ int htsparse(htsmoduleStruct * str, htsmoduleStructExtended * stre) {
}
// mode test?
if (!just_test_it)
- liens[lien_tot]->testmode = 0; // pas mode test
+ heap_top()->testmode = 0; // pas mode test
else
- liens[lien_tot]->testmode = 1; // mode test
+ heap_top()->testmode = 1; // mode test
if (!import_done)
- liens[lien_tot]->link_import = 0; // pas mode import
+ heap_top()->link_import = 0; // pas mode import
else
- liens[lien_tot]->link_import = 1; // mode import
+ heap_top()->link_import = 1; // mode import
// écrire autres paramètres de la structure-lien
if ((meme_adresse) && (!import_done)
- && (liens[ptr]->premier != 0))
- liens[lien_tot]->premier = liens[ptr]->premier;
+ && (heap(ptr)->premier != 0))
+ heap_top()->premier = heap(ptr)->premier;
else // sinon l'objet père est le précédent lui même
- liens[lien_tot]->premier = lien_tot;
- // liens[lien_tot]->premier=ptr;
+ heap_top()->premier = heap_top_index();
+ // heap_top()->premier=ptr;
- liens[lien_tot]->precedent = ptr;
+ heap_top()->precedent = ptr;
// noter la priorité
if (!set_prio_to)
- liens[lien_tot]->depth = liens[ptr]->depth - 1;
+ heap_top()->depth = heap(ptr)->depth - 1;
else
- liens[lien_tot]->depth = max(0, min(liens[ptr]->depth - 1, set_prio_to - 1)); // PRIORITE NULLE (catch page)
+ heap_top()->depth = max(0, min(heap(ptr)->depth - 1, set_prio_to - 1)); // PRIORITE NULLE (catch page)
// noter pass
- liens[lien_tot]->pass2 = pass_fix;
- liens[lien_tot]->retry = opt->retry;
+ heap_top()->pass2 = pass_fix;
+ heap_top()->retry = opt->retry;
- //strcpybuff(liens[lien_tot]->adr,adr);
- //strcpybuff(liens[lien_tot]->fil,fil);
- //strcpybuff(liens[lien_tot]->sav,save);
+ //strcpybuff(heap_top()->adr,adr);
+ //strcpybuff(heap_top()->fil,fil);
+ //strcpybuff(heap_top()->sav,save);
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);
+ heap_top()->adr,
+ heap_top()->fil,
+ heap_top()->sav);
} else {
hts_log_print(opt, LOG_DEBUG, "OK, TEST: %s%s",
- liens[lien_tot]->adr,
- liens[lien_tot]->fil);
+ heap_top()->adr,
+ heap_top()->fil);
}
- lien_tot++; // UN LIEN DE PLUS
} else { // if !dejafait
hts_log_print(opt, LOG_DEBUG,
"link has already been recorded, cancelled: %s",
@@ -3428,7 +3336,7 @@ int htsparse(htsmoduleStruct * str, htsmoduleStructExtended * stre) {
opt->state._hts_in_html_poll = 0;
// temps à attendre, et remplir autant que l'on peut le cache (backing)
back_wait(sback, opt, cache, HTS_STAT.stat_timestart);
- back_fillmax(sback, opt, cache, liens, ptr, numero_passe, lien_tot);
+ back_fillmax(sback, opt, cache, opt->liens, ptr, numero_passe, opt->lien_tot);
// Transfer rate
engine_stats();
@@ -3438,11 +3346,11 @@ int htsparse(htsmoduleStruct * str, htsmoduleStructExtended * stre) {
HTS_STAT.stat_errors = fspc(opt, NULL, "error");
HTS_STAT.stat_warnings = fspc(opt, NULL, "warning");
HTS_STAT.stat_infos = fspc(opt, NULL, "info");
- HTS_STAT.nbk = backlinks_done(sback, liens, lien_tot, ptr);
+ HTS_STAT.nbk = backlinks_done(sback, opt->liens, opt->lien_tot, ptr);
HTS_STAT.nb = back_transferred(HTS_STAT.stat_bytes, sback);
if (!RUN_CALLBACK7
- (opt, loop, sback->lnk, sback->count, 0, ptr, lien_tot,
+ (opt, loop, sback->lnk, sback->count, 0, ptr, opt->lien_tot,
(int) (time_local() - HTS_STAT.stat_timestart), &HTS_STAT)) {
hts_log_print(opt, LOG_ERROR, "Exit requested by shell or user");
*stre->exit_xh_ = 1; // exit requested
@@ -3459,7 +3367,7 @@ int htsparse(htsmoduleStruct * str, htsmoduleStructExtended * stre) {
// refresh the backing system each 2 seconds
if (engine_stats()) {
back_wait(sback, opt, cache, HTS_STAT.stat_timestart);
- back_fillmax(sback, opt, cache, liens, ptr, numero_passe, lien_tot);
+ back_fillmax(sback, opt, cache, opt->liens, ptr, numero_passe, opt->lien_tot);
}
} while((((int) (adr - r->adr))) < r->size);
@@ -3472,8 +3380,8 @@ int htsparse(htsmoduleStruct * str, htsmoduleStructExtended * stre) {
int cSize = (int) ht_len;
hts_log_print(opt, LOG_DEBUG, "engine: postprocess-html: %s%s",
- urladr, urlfil);
- if (RUN_CALLBACK4(opt, postprocess, &cAddr, &cSize, urladr, urlfil) ==
+ urladr(), urlfil());
+ if (RUN_CALLBACK4(opt, postprocess, &cAddr, &cSize, urladr(), urlfil()) ==
1) {
ht_buff = cAddr;
ht_len = cSize;
@@ -3495,8 +3403,8 @@ int htsparse(htsmoduleStruct * str, htsmoduleStructExtended * stre) {
}
}
// sauver fichier
- //structcheck(savename);
- //filesave(opt,r->adr,r->size,savename);
+ //structcheck(savename());
+ //filesave(opt,r->adr,r->size,savename());
} // analyse OK
@@ -3529,7 +3437,7 @@ int hts_mirror_check_moved(htsmoduleStruct * str,
//int i=0;
// char* p;
- hts_log_print(opt, LOG_WARNING, "%s for %s%s", r->msg, urladr, urlfil);
+ 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],
@@ -3546,7 +3454,7 @@ int hts_mirror_check_moved(htsmoduleStruct * str,
// url qque -> adresse+fichier
if ((reponse =
- ident_url_relatif(mov_url, urladr, urlfil, mov_adr,
+ ident_url_relatif(mov_url, urladr(), urlfil(), mov_adr,
mov_fil)) >= 0) {
int set_prio_to = 0; // pas de priotité fixéd par wizard
@@ -3558,27 +3466,27 @@ int hts_mirror_check_moved(htsmoduleStruct * str,
n_adr[0] = n_fil[0] = '\0';
(void) adr_normalized(mov_adr, n_adr);
(void) fil_normalized(mov_fil, n_fil);
- (void) adr_normalized(urladr, pn_adr);
- (void) fil_normalized(urlfil, pn_fil);
+ (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) {
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);
+ urladr(), urlfil(), mov_adr, mov_fil);
}
}
//if (ident_url_absolute(mov_url,mov_adr,mov_fil)!=-1) { // ok URL reconnue
// c'est (en gros) la même URL..
// si c'est un problème de casse dans le host c'est que le serveur est buggé
// ("RFC says.." : host name IS case insensitive)
- if ((strfield2(mov_adr, urladr) != 0) && (strfield2(mov_fil, urlfil) != 0)) { // identique à casse près
+ if ((strfield2(mov_adr, urladr()) != 0) && (strfield2(mov_fil, urlfil()) != 0)) { // identique à casse près
// on tourne en rond
- if (strcmp(mov_fil, urlfil) == 0) {
+ if (strcmp(mov_fil, urlfil()) == 0) {
error = 1;
get_it = -1; // ne rien faire
hts_log_print(opt, LOG_WARNING,
"Can not bear crazy server (%s) for %s%s", r->msg,
- urladr, urlfil);
+ urladr(), urlfil());
} else { // mauvaise casse, effacer entrée dans la pile et rejouer une fois
get_it = 1;
}
@@ -3589,7 +3497,7 @@ int hts_mirror_check_moved(htsmoduleStruct * str,
"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, NULL, NULL, &set_prio_to, NULL) != 1) { /* nouvelle adresse non refusée ? */
+ if (hts_acceptlink(opt, ptr, opt->lien_tot, opt->liens, mov_adr, mov_fil, NULL, NULL, &set_prio_to, NULL) != 1) { /* nouvelle adresse non refusée ? */
get_it = 1;
hts_log_print(opt, LOG_DEBUG, "moved link accepted: %s%s",
mov_adr, mov_fil);
@@ -3597,13 +3505,13 @@ int hts_mirror_check_moved(htsmoduleStruct * str,
} /* sinon traité normalement */
}
- //if ((strfield2(mov_adr,urladr)!=0) && (strfield2(mov_fil,urlfil)!=0)) { // identique à casse près
+ //if ((strfield2(mov_adr,urladr())!=0) && (strfield2(mov_fil,urlfil())!=0)) { // identique à casse près
if (get_it == 1) {
// court-circuiter le reste du traitement
// et reculer pour mieux sauter
hts_log_print(opt, LOG_WARNING,
"Warning moved treated for %s%s (real one is %s%s)",
- urladr, urlfil, mov_adr, mov_fil);
+ urladr(), urlfil(), mov_adr, mov_fil);
// canceller lien actuel
error = 1;
hash_invalidate_entry(hashptr, ptr); // invalidate hashtable entry
@@ -3617,33 +3525,27 @@ int hts_mirror_check_moved(htsmoduleStruct * str,
// calculer lien et éventuellement modifier addresse/fichier
if (url_savename
(mov_adr, mov_fil, mov_sav, NULL, NULL,
- liens[liens[ptr]->precedent]->adr,
- liens[liens[ptr]->precedent]->fil, opt, liens, lien_tot,
+ heap(heap(ptr)->precedent)->adr,
+ heap(heap(ptr)->precedent)->fil, opt, opt->liens, opt->lien_tot,
sback, cache, hash, ptr, numero_passe, NULL) != -1) {
if (hash_read(hash, mov_sav, NULL, HASH_STRUCT_FILENAME) < 0) { // n'existe pas déja
- // enregistrer lien (MACRO) avec SAV IDENTIQUE
- liens_record(mov_adr, mov_fil, liens[ptr]->sav, "", "");
- //liens_record(mov_adr,mov_fil,mov_sav,"","");
- if (liens[lien_tot] != NULL) { // OK, pas d'erreur
+ // enregistrer lien avec SAV IDENTIQUE
+ if (hts_record_link(opt, mov_adr, mov_fil, heap(ptr)->sav, "", "", NULL)) {
// mode test?
- liens[lien_tot]->testmode = liens[ptr]->testmode;
- liens[lien_tot]->link_import = 0; // mode normal
+ heap_top()->testmode = heap(ptr)->testmode;
+ heap_top()->link_import = 0; // mode normal
if (!set_prio_to)
- liens[lien_tot]->depth = liens[ptr]->depth;
+ heap_top()->depth = heap(ptr)->depth;
else
- liens[lien_tot]->depth = max(0, min(set_prio_to - 1, liens[ptr]->depth)); // PRIORITE NULLE (catch page)
- liens[lien_tot]->pass2 =
- max(liens[ptr]->pass2, numero_passe);
- liens[lien_tot]->retry = liens[ptr]->retry;
- liens[lien_tot]->premier = liens[ptr]->premier;
- liens[lien_tot]->precedent = liens[ptr]->precedent;
- lien_tot++;
+ heap_top()->depth = max(0, min(set_prio_to - 1, heap(ptr)->depth)); // PRIORITE NULLE (catch page)
+ heap_top()->pass2 =
+ max(heap(ptr)->pass2, numero_passe);
+ heap_top()->retry = heap(ptr)->retry;
+ heap_top()->premier = heap(ptr)->premier;
+ heap_top()->precedent = heap(ptr)->precedent;
} else { // oups erreur, plus de mémoire!!
printf("PANIC! : Not enough memory [%d]\n", __LINE__);
- hts_log_print(opt, LOG_PANIC,
- "Not enough memory, can not re-allocate %d bytes",
- (int) ((add_tab_alloc +
- 1) * sizeof(lien_url)));
+ hts_log_print(opt, LOG_PANIC, "Not enough memory");
//if (opt->getmode & 1) { if (fp) { fclose(fp); fp=NULL; } }
XH_uninit; // désallocation mémoire & buffers
return 0;
@@ -3651,7 +3553,7 @@ int hts_mirror_check_moved(htsmoduleStruct * str,
} else {
hts_log_print(opt, LOG_INFO,
"moving %s to an existing file %s",
- liens[ptr]->fil, urlfil);
+ heap(ptr)->fil, urlfil());
}
}
@@ -3670,7 +3572,7 @@ int hts_mirror_check_moved(htsmoduleStruct * str,
char *const rn = (char *) malloct(rn_size);
if (rn != NULL) {
hts_log_print(opt, LOG_WARNING, "File has moved from %s%s to %s",
- urladr, urlfil, mov_url);
+ urladr(), urlfil(), mov_url);
if (!opt->mimehtml) {
inplace_escape_uri(mov_url, sizeof(mov_url));
} else {
@@ -3712,33 +3614,30 @@ int hts_mirror_check_moved(htsmoduleStruct * str,
} else if ((r->statuscode == HTTP_PRECONDITION_FAILED)
|| (r->statuscode == HTTP_REQUESTED_RANGE_NOT_SATISFIABLE)
) { // Precondition Failed, c'est à dire pour nous redemander TOUT le fichier
- if (fexist_utf8(liens[ptr]->sav)) {
- remove(liens[ptr]->sav); // Eliminer
+ if (fexist_utf8(heap(ptr)->sav)) {
+ remove(heap(ptr)->sav); // Eliminer
} 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 : "");
+ r->msg, urladr(), urlfil(),
+ heap(ptr)->sav != NULL ? heap(ptr)->sav : "");
}
- if (!fexist_utf8(liens[ptr]->sav)) { // Bien éliminé? (sinon on boucle..)
+ if (!fexist_utf8(heap(ptr)->sav)) { // Bien éliminé? (sinon on boucle..)
#if HDEBUG
printf("Partial content NOT up-to-date, reget all file for %s\n",
- liens[ptr]->sav);
+ heap(ptr)->sav);
#endif
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
- liens[lien_tot]->testmode = liens[ptr]->testmode; // mode test?
- liens[lien_tot]->link_import = 0; // pas mode import
- liens[lien_tot]->depth = liens[ptr]->depth;
- liens[lien_tot]->pass2 = max(liens[ptr]->pass2, numero_passe);
- liens[lien_tot]->retry = liens[ptr]->retry;
- liens[lien_tot]->premier = liens[ptr]->premier;
- liens[lien_tot]->precedent = ptr;
- lien_tot++;
+ r->msg, urladr(), urlfil());
+ // enregistrer le MEME lien
+ if (hts_record_link(opt, heap(ptr)->adr, heap(ptr)->fil, heap(ptr)->sav, "", "", NULL)) {
+ heap_top()->testmode = heap(ptr)->testmode; // mode test?
+ heap_top()->link_import = 0; // pas mode import
+ heap_top()->depth = heap(ptr)->depth;
+ heap_top()->pass2 = max(heap(ptr)->pass2, numero_passe);
+ heap_top()->retry = heap(ptr)->retry;
+ heap_top()->premier = heap(ptr)->premier;
+ heap_top()->precedent = ptr;
//
// canceller lien actuel
error = 1;
@@ -3746,15 +3645,13 @@ int hts_mirror_check_moved(htsmoduleStruct * str,
//
} else { // oups erreur, plus de mémoire!!
printf("PANIC! : Not enough memory [%d]\n", __LINE__);
- hts_log_print(opt, LOG_PANIC,
- "Not enough memory, can not re-allocate %d bytes",
- (int) ((add_tab_alloc + 1) * sizeof(lien_url)));
+ hts_log_print(opt, LOG_PANIC, "Not enough memory");
//if (opt->getmode & 1) { if (fp) { fclose(fp); fp=NULL; } }
XH_uninit; // désallocation mémoire & buffers
return 0;
}
} else {
- hts_log_print(opt, LOG_ERROR, "Can not remove old file %s", urlfil);
+ hts_log_print(opt, LOG_ERROR, "Can not remove old file %s", urlfil());
error = 1;
}
@@ -3775,27 +3672,27 @@ int hts_mirror_check_moved(htsmoduleStruct * str,
//case -1: can_retry=1; break;
case STATUSCODE_TIMEOUT:
if (opt->hostcontrol) { // timeout et retry épuisés
- if ((opt->hostcontrol & 1) && (liens[ptr]->retry <= 0)) {
- 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->hostcontrol & 1) && (heap(ptr)->retry <= 0)) {
+ hts_log_print(opt, LOG_DEBUG, "Link banned: %s%s", urladr(), urlfil());
+ host_ban(opt, opt->liens, ptr, opt->lien_tot, sback,
+ jump_identification(urladr()));
hts_log_print(opt, LOG_DEBUG,
- "Info: previous log - link banned: %s%s", urladr,
- urlfil);
+ "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) && (heap(ptr)->retry <= 0)) { // too slow
if (opt->hostcontrol & 2) {
- hts_log_print(opt, LOG_DEBUG, "Link banned: %s%s", urladr, urlfil);
- host_ban(opt, liens, ptr, lien_tot, sback,
- jump_identification(urladr));
+ hts_log_print(opt, LOG_DEBUG, "Link banned: %s%s", urladr(), urlfil());
+ host_ban(opt, opt->liens, ptr, opt->lien_tot, sback,
+ jump_identification(urladr()));
hts_log_print(opt, LOG_DEBUG,
- "Info: previous log - link banned: %s%s", urladr,
- urlfil);
+ "Info: previous log - link banned: %s%s", urladr(),
+ urlfil());
} else
can_retry = 1;
} else
@@ -3819,29 +3716,29 @@ int hts_mirror_check_moved(htsmoduleStruct * str,
break;
}
- 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 (strcmp(heap(ptr)->fil, "/primary") != 0) { // no primary (internal page 0)
+ if ((heap(ptr)->retry <= 0) || (!can_retry)) { // retry épuisés (ou retry impossible)
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);
+ r->msg, r->statuscode, opt->retry, urladr(), urlfil(),
+ heap(heap(ptr)->precedent)->adr,
+ heap(heap(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);
+ urladr(), urlfil(), heap(heap(ptr)->precedent)->adr,
+ heap(heap(ptr)->precedent)->fil);
} else {
- if (strcmp(urlfil, "/robots.txt")) { // ne pas afficher d'infos sur robots.txt par défaut
+ 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);
+ r->statuscode, urladr(), urlfil(),
+ heap(heap(ptr)->precedent)->adr,
+ heap(heap(ptr)->precedent)->fil);
} else {
hts_log_print(opt, LOG_DEBUG, "No robots.txt rules at %s",
- urladr);
+ urladr());
}
}
}
@@ -3850,13 +3747,13 @@ int hts_mirror_check_moved(htsmoduleStruct * str,
// due to the "no connection -> previous restored" hack
// This prevent the engine from wiping all data if the website has been deleted (or moved)
// since last time (which is quite annoying)
- if (liens[ptr]->precedent != 0) {
+ if (heap(ptr)->precedent != 0) {
// ici on teste si on doit enregistrer la page tout de même
if (opt->errpage) {
store_errpage = 1;
}
} else {
- if (strcmp(urlfil, "/robots.txt") != 0) {
+ if (strcmp(urlfil(), "/robots.txt") != 0) {
/*
This is an error caused by a link entered by the user
That is, link(s) entered by user are invalid (404, 500, connect error, proxy error->.)
@@ -3873,33 +3770,29 @@ int hts_mirror_check_moved(htsmoduleStruct * str,
} else { // retry!!
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);
+ r->statuscode, r->msg, urladr(), urlfil(),
+ heap(heap(ptr)->precedent)->adr,
+ heap(heap(ptr)->precedent)->fil);
// redemander fichier
- liens_record(urladr, urlfil, savename, "", "");
- if (liens[lien_tot] != NULL) { // OK, pas d'erreur
- liens[lien_tot]->testmode = liens[ptr]->testmode; // mode test?
- liens[lien_tot]->link_import = 0; // pas mode import
- liens[lien_tot]->depth = liens[ptr]->depth;
- liens[lien_tot]->pass2 = max(liens[ptr]->pass2, numero_passe);
- liens[lien_tot]->retry = liens[ptr]->retry - 1; // moins 1 retry!
- liens[lien_tot]->premier = liens[ptr]->premier;
- liens[lien_tot]->precedent = liens[ptr]->precedent;
- lien_tot++;
+ if (hts_record_link(opt, urladr(), urlfil(), savename(), "", "", codebase)) {
+ heap_top()->testmode = heap(ptr)->testmode; // mode test?
+ heap_top()->link_import = 0; // pas mode import
+ heap_top()->depth = heap(ptr)->depth;
+ heap_top()->pass2 = max(heap(ptr)->pass2, numero_passe);
+ heap_top()->retry = heap(ptr)->retry - 1; // moins 1 retry!
+ heap_top()->premier = heap(ptr)->premier;
+ heap_top()->precedent = heap(ptr)->precedent;
} else { // oups erreur, plus de mémoire!!
printf("PANIC! : Not enough memory [%d]\n", __LINE__);
- hts_log_print(opt, LOG_PANIC,
- "Not enough memory, can not re-allocate %d bytes",
- (int) ((add_tab_alloc + 1) * sizeof(lien_url)));
+ hts_log_print(opt, LOG_PANIC, "Not enough memory");
//if (opt->getmode & 1) { if (fp) { fclose(fp); fp=NULL; } }
XH_uninit; // désallocation mémoire & buffers
return 0;
}
}
} else {
- hts_log_print(opt, LOG_DEBUG, "Info: no robots.txt at %s%s", 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
@@ -3979,12 +3872,12 @@ void hts_mirror_process_user_interaction(htsmoduleStruct * str,
HTS_STAT.stat_errors = fspc(opt, NULL, "error");
HTS_STAT.stat_warnings = fspc(opt, NULL, "warning");
HTS_STAT.stat_infos = fspc(opt, NULL, "info");
- HTS_STAT.nbk = backlinks_done(sback, liens, lien_tot, ptr);
+ HTS_STAT.nbk = backlinks_done(sback, opt->liens, opt->lien_tot, ptr);
HTS_STAT.nb = back_transferred(HTS_STAT.stat_bytes, sback);
b = 0;
if (!RUN_CALLBACK7
- (opt, loop, sback->lnk, sback->count, b, ptr, lien_tot,
+ (opt, loop, sback->lnk, sback->count, b, ptr, opt->lien_tot,
(int) (time_local() - HTS_STAT.stat_timestart), &HTS_STAT)
|| !back_checkmirror(opt)) {
hts_log_print(opt, LOG_ERROR, "Exit requested by shell or user");
@@ -4044,29 +3937,25 @@ void hts_mirror_process_user_interaction(htsmoduleStruct * str,
// calculer lien et éventuellement modifier addresse/fichier
if (url_savename
- (add_adr, add_fil, add_sav, NULL, NULL, NULL, NULL, opt, liens,
- lien_tot, sback, cache, hash, ptr, numero_passe, NULL) != -1) {
+ (add_adr, add_fil, add_sav, NULL, NULL, NULL, NULL, opt, opt->liens,
+ opt->lien_tot, sback, cache, hash, ptr, numero_passe, NULL) != -1) {
if (hash_read(hash, add_sav, NULL, HASH_STRUCT_FILENAME) < 0) { // n'existe pas déja
- // enregistrer lien (MACRO)
- liens_record(add_adr, add_fil, add_sav, "", "");
- if (liens[lien_tot] != NULL) { // OK, pas d'erreur
- liens[lien_tot]->testmode = 0; // mode test?
- liens[lien_tot]->link_import = 0; // mode normal
- liens[lien_tot]->depth = opt->depth;
- liens[lien_tot]->pass2 = max(0, numero_passe);
- liens[lien_tot]->retry = opt->retry;
- liens[lien_tot]->premier = lien_tot;
- liens[lien_tot]->precedent = lien_tot;
- lien_tot++;
+ // enregistrer lien
+ if (hts_record_link(opt, add_adr, add_fil, add_sav, "", "", NULL)) {
+ heap_top()->testmode = 0; // mode test?
+ heap_top()->link_import = 0; // mode normal
+ heap_top()->depth = opt->depth;
+ heap_top()->pass2 = max(0, numero_passe);
+ heap_top()->retry = opt->retry;
+ heap_top()->premier = heap_top_index();
+ heap_top()->precedent = heap_top_index();
//
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__);
- hts_log_print(opt, LOG_PANIC,
- "Not enough memory, can not re-allocate %d bytes",
- (int) ((add_tab_alloc + 1) * sizeof(lien_url)));
+ hts_log_print(opt, LOG_PANIC, "Not enough memory");
//if (opt->getmode & 1) { if (fp) { fclose(fp); fp=NULL; } }
XH_uninit; // désallocation mémoire & buffers
return;
@@ -4091,7 +3980,7 @@ void hts_mirror_process_user_interaction(htsmoduleStruct * str,
if (opt->state._hts_setpause
|| back_pluggable_sockets_strict(sback, opt) <= 0) {
// index du lien actuel
- int b = back_index(opt, sback, urladr, urlfil, savename);
+ int b = back_index(opt, sback, urladr(), urlfil(), savename());
int prev = opt->state._hts_in_html_parsing;
if (b < 0)
@@ -4108,11 +3997,11 @@ void hts_mirror_process_user_interaction(htsmoduleStruct * str,
HTS_STAT.stat_errors = fspc(opt, NULL, "error");
HTS_STAT.stat_warnings = fspc(opt, NULL, "warning");
HTS_STAT.stat_infos = fspc(opt, NULL, "info");
- HTS_STAT.nbk = backlinks_done(sback, liens, lien_tot, ptr);
+ HTS_STAT.nbk = backlinks_done(sback, opt->liens, opt->lien_tot, ptr);
HTS_STAT.nb = back_transferred(HTS_STAT.stat_bytes, sback);
if (!RUN_CALLBACK7
- (opt, loop, sback->lnk, sback->count, b, ptr, lien_tot,
+ (opt, loop, sback->lnk, sback->count, b, ptr, opt->lien_tot,
(int) (time_local() - HTS_STAT.stat_timestart), &HTS_STAT)) {
hts_log_print(opt, LOG_ERROR, "Exit requested by shell or user");
*stre->exit_xh_ = 1; // exit requested
@@ -4139,9 +4028,9 @@ int hts_mirror_wait_for_next_file(htsmoduleStruct * str,
int n;
/* This is not supposed to hapen. */
- if (liens[ptr]->pass2 == -1) {
- hts_log_print(opt, LOG_WARNING, "Link is already ready %s%s", urladr,
- urlfil);
+ if (heap(ptr)->pass2 == -1) {
+ hts_log_print(opt, LOG_WARNING, "Link is already ready %s%s", urladr(),
+ urlfil());
}
/* User interaction */
@@ -4152,27 +4041,27 @@ int hts_mirror_wait_for_next_file(htsmoduleStruct * str,
ENGINE_SET_CONTEXT();
/* Done while processing user interactions ? */
- if (liens[ptr]->pass2 == -1) {
- hts_log_print(opt, LOG_DEBUG, "Link is now ready %s%s", urladr, urlfil);
+ if (heap(ptr)->pass2 == -1) {
+ hts_log_print(opt, LOG_DEBUG, "Link is now ready %s%s", urladr(), urlfil());
// We are ready
return 2; // goto jump_if_done;
}
// si le fichier n'est pas en backing, le mettre..
- if (!back_exist(str->sback, str->opt, urladr, urlfil, savename)) {
+ if (!back_exist(str->sback, str->opt, urladr(), urlfil(), savename())) {
#if BDEBUG==1
- printf("crash backing: %s%s\n", liens[ptr]->adr, liens[ptr]->fil);
+ printf("crash backing: %s%s\n", heap(ptr)->adr, heap(ptr)->fil);
#endif
if (back_add
- (sback, opt, cache, urladr, urlfil, savename,
- liens[liens[ptr]->precedent]->adr, liens[liens[ptr]->precedent]->fil,
- liens[ptr]->testmode) == -1) {
+ (sback, opt, cache, urladr(), urlfil(), savename(),
+ heap(heap(ptr)->precedent)->adr, heap(heap(ptr)->precedent)->fil,
+ heap(ptr)->testmode) == -1) {
printf("PANIC! : Crash adding error, unexpected error found.. [%d]\n",
__LINE__);
#if BDEBUG==1
printf("error while crash adding\n");
#endif
- hts_log_print(opt, LOG_ERROR, "Unexpected backing error for %s%s", urladr,
- urlfil);
+ hts_log_print(opt, LOG_ERROR, "Unexpected backing error for %s%s", urladr(),
+ urlfil());
}
}
@@ -4188,7 +4077,7 @@ int hts_mirror_wait_for_next_file(htsmoduleStruct * str,
if ((n > 0) && (!opt->state._hts_setpause)) { // si sockets libre et pas en pause, ajouter
// remplir autant que l'on peut le cache (backing)
- back_fillmax(sback, opt, cache, liens, ptr, numero_passe, lien_tot);
+ back_fillmax(sback, opt, cache, opt->liens, ptr, numero_passe, opt->lien_tot);
}
// index du lien actuel
{
@@ -4203,7 +4092,7 @@ int hts_mirror_wait_for_next_file(htsmoduleStruct * str,
ENGINE_SET_CONTEXT();
// index du lien actuel
- b = back_index(opt, sback, urladr, urlfil, savename);
+ b = back_index(opt, sback, urladr(), urlfil(), savename());
#if BDEBUG==1
printf("back index %d, waiting\n", b);
#endif
@@ -4216,7 +4105,7 @@ int hts_mirror_wait_for_next_file(htsmoduleStruct * str,
back_wait(sback, opt, cache, HTS_STAT.stat_timestart);
// Continue to the loop if link still present
- b = back_index(opt, sback, urladr, urlfil, savename);
+ b = back_index(opt, sback, urladr(), urlfil(), savename());
if (b < 0)
break;
@@ -4229,10 +4118,10 @@ int hts_mirror_wait_for_next_file(htsmoduleStruct * str,
}
// And fill the backing stack
if (back[b].status > 0)
- back_fillmax(sback, opt, cache, liens, ptr, numero_passe, lien_tot);
+ back_fillmax(sback, opt, cache, opt->liens, ptr, numero_passe, opt->lien_tot);
// Continue to the loop if link still present
- b = back_index(opt, sback, urladr, urlfil, savename);
+ b = back_index(opt, sback, urladr(), urlfil(), savename());
if (b < 0)
break;
@@ -4248,10 +4137,10 @@ int hts_mirror_wait_for_next_file(htsmoduleStruct * str,
(int) ((HTS_STAT.HTS_TOTAL_RECV -
*stre->makestat_total_) / (l - makestat_time)),
(LLint) HTS_STAT.HTS_TOTAL_RECV,
- (int) lien_tot - *stre->makestat_lnk_, (int) lien_tot);
+ (int) opt->lien_tot - *stre->makestat_lnk_, (int) opt->lien_tot);
fflush(makestat_fp);
*stre->makestat_total_ = HTS_STAT.HTS_TOTAL_RECV;
- *stre->makestat_lnk_ = lien_tot;
+ *stre->makestat_lnk_ = heap_top_index();
}
if (stre->maketrack_fp != NULL) {
int i;
@@ -4308,11 +4197,11 @@ int hts_mirror_wait_for_next_file(htsmoduleStruct * str,
HTS_STAT.stat_errors = fspc(opt, NULL, "error");
HTS_STAT.stat_warnings = fspc(opt, NULL, "warning");
HTS_STAT.stat_infos = fspc(opt, NULL, "info");
- HTS_STAT.nbk = backlinks_done(sback, liens, lien_tot, ptr);
+ HTS_STAT.nbk = backlinks_done(sback, opt->liens, opt->lien_tot, ptr);
HTS_STAT.nb = back_transferred(HTS_STAT.stat_bytes, sback);
if (!RUN_CALLBACK7
- (opt, loop, sback->lnk, sback->count, b, ptr, lien_tot,
+ (opt, loop, sback->lnk, sback->count, b, ptr, opt->lien_tot,
(int) (time_local() - HTS_STAT.stat_timestart), &HTS_STAT)) {
hts_log_print(opt, LOG_ERROR, "Exit requested by shell or user");
*stre->exit_xh_ = 1; // exit requested
@@ -4377,7 +4266,7 @@ int hts_mirror_wait_for_next_file(htsmoduleStruct * str,
(int) (HTS_STAT.HTS_TOTAL_RECV /
(tl - HTS_STAT.stat_timestart)));
fprintf(fp, "SOCKET %d" LF, back_nsoc(sback));
- fprintf(fp, "LINK %d" LF, lien_tot);
+ fprintf(fp, "LINK %d" LF, opt->lien_tot);
{
LLint mem = 0;
@@ -4410,7 +4299,7 @@ int hts_mirror_wait_for_next_file(htsmoduleStruct * str,
if (b < 0) {
hts_log_print(opt, LOG_DEBUG,
"link #%d is ready, no more on the stack, skipping: %s%s..",
- ptr, urladr, urlfil);
+ ptr, urladr(), urlfil());
// prochain lien
// ptr++;
@@ -4451,10 +4340,10 @@ int hts_mirror_wait_for_next_file(htsmoduleStruct * str,
} else if (opt->verbosedisplay == 1) {
if (b >= 0) {
if (back[b].r.statuscode == HTTP_OK)
- printf("%d/%d: %s%s (" LLintP " bytes) - OK\33[K\r", ptr, lien_tot,
+ printf("%d/%d: %s%s (" LLintP " bytes) - OK\33[K\r", ptr, opt->lien_tot,
back[b].url_adr, back[b].url_fil, (LLint) back[b].r.size);
else
- printf("%d/%d: %s%s (" LLintP " bytes) - %d\33[K\r", ptr, lien_tot,
+ printf("%d/%d: %s%s (" LLintP " bytes) - %d\33[K\r", ptr, opt->lien_tot,
back[b].url_adr, back[b].url_fil, (LLint) back[b].r.size,
back[b].r.statuscode);
} else {
@@ -4570,14 +4459,14 @@ int hts_wait_delayed(htsmoduleStruct * str, char *adr, char *fil, char *save,
/* Recompute filename with MIME type */
save[0] = '\0';
- url_savename(adr, fil, save, former_adr, former_fil, liens[ptr]->adr,
- liens[ptr]->fil, opt, liens, lien_tot, sback, cache,
+ url_savename(adr, fil, save, former_adr, former_fil, heap(ptr)->adr,
+ heap(ptr)->fil, opt, opt->liens, opt->lien_tot, sback, cache,
hash, ptr, numero_passe, &back);
/* Recompute authorization with MIME type */
{
int new_forbidden_url =
- hts_acceptmime(opt, ptr, lien_tot, liens, adr, fil,
+ hts_acceptmime(opt, ptr, opt->lien_tot, opt->liens, adr, fil,
back.r.contenttype);
if (new_forbidden_url != -1) {
hts_log_print(opt, LOG_DEBUG, "result for wizard mime test: %d",
@@ -4644,14 +4533,14 @@ int hts_wait_delayed(htsmoduleStruct * str, char *adr, char *fil, char *save,
/* Recompute filename with MIME type */
save[0] = '\0';
- url_savename(adr, fil, save, former_adr, former_fil, liens[ptr]->adr,
- liens[ptr]->fil, opt, liens, lien_tot, sback, cache,
+ url_savename(adr, fil, save, former_adr, former_fil, heap(ptr)->adr,
+ heap(ptr)->fil, opt, opt->liens, opt->lien_tot, sback, cache,
hash, ptr, numero_passe, &delayed_back);
/* Recompute authorization with MIME type */
{
int new_forbidden_url =
- hts_acceptmime(opt, ptr, lien_tot, liens, adr, fil,
+ hts_acceptmime(opt, ptr, opt->lien_tot, opt->liens, adr, fil,
delayed_back.r.contenttype);
if (new_forbidden_url != -1) {
hts_log_print(opt, LOG_DEBUG, "result for wizard mime test: %d",
@@ -4701,7 +4590,7 @@ int hts_wait_delayed(htsmoduleStruct * str, char *adr, char *fil, char *save,
back_wait(sback, opt, cache, 0);
}
if (ptr >= 0) {
- back_fillmax(sback, opt, cache, liens, ptr, numero_passe, lien_tot);
+ back_fillmax(sback, opt, cache, opt->liens, ptr, numero_passe, opt->lien_tot);
}
// on est obligé d'appeler le shell pour le refresh..
{
@@ -4714,11 +4603,11 @@ int hts_wait_delayed(htsmoduleStruct * str, char *adr, char *fil, char *save,
HTS_STAT.stat_errors = fspc(opt, NULL, "error");
HTS_STAT.stat_warnings = fspc(opt, NULL, "warning");
HTS_STAT.stat_infos = fspc(opt, NULL, "info");
- HTS_STAT.nbk = backlinks_done(sback, liens, lien_tot, ptr);
+ HTS_STAT.nbk = backlinks_done(sback, opt->liens, opt->lien_tot, ptr);
HTS_STAT.nb = back_transferred(HTS_STAT.stat_bytes, sback);
if (!RUN_CALLBACK7
- (opt, loop, sback->lnk, sback->count, b, ptr, lien_tot,
+ (opt, loop, sback->lnk, sback->count, b, ptr, opt->lien_tot,
(int) (time_local() - HTS_STAT.stat_timestart), &HTS_STAT)) {
return -1;
} else if (opt->state._hts_cancel || !back_checkmirror(opt)) { // cancel 2 ou 1 (cancel parsing)
@@ -4801,7 +4690,7 @@ int hts_wait_delayed(htsmoduleStruct * str, char *adr, char *fil, char *save,
{
int set_prio_to = 0;
- if (hts_acceptlink(opt, ptr, lien_tot, liens, mov_adr, mov_fil, NULL, NULL, &set_prio_to, NULL) == 1) { /* forbidden */
+ if (hts_acceptlink(opt, ptr, opt->lien_tot, opt->liens, mov_adr, mov_fil, NULL, NULL, &set_prio_to, NULL) == 1) { /* forbidden */
/* Note: the cache 'cached_tests' system will remember this error, and we'll only issue ONE request */
*forbidden_url = 1; /* Forbidden! */
hts_log_print(opt, LOG_DEBUG,
@@ -4829,8 +4718,8 @@ int hts_wait_delayed(htsmoduleStruct * str, char *adr, char *fil, char *save,
/* Recompute filename for hash lookup */
save[0] = '\0';
url_savename(adr, fil, save, former_adr, former_fil,
- liens[ptr]->adr, liens[ptr]->fil, opt, liens,
- lien_tot, sback, cache, hash, ptr, numero_passe,
+ heap(ptr)->adr, heap(ptr)->fil, opt, opt->liens,
+ opt->lien_tot, sback, cache, hash, ptr, numero_passe,
&delayed_back);
} else {
hts_log_print(opt, LOG_WARNING,
@@ -4848,13 +4737,13 @@ int hts_wait_delayed(htsmoduleStruct * str, char *adr, char *fil, char *save,
/* Recompute filename with MIME type */
save[0] = '\0';
url_savename(adr, fil, save, former_adr, former_fil,
- liens[ptr]->adr, liens[ptr]->fil, opt, liens, lien_tot,
+ heap(ptr)->adr, heap(ptr)->fil, opt, opt->liens, opt->lien_tot,
sback, cache, hash, ptr, numero_passe, &delayed_back);
/* Recompute authorization with MIME type */
{
int new_forbidden_url =
- hts_acceptmime(opt, ptr, lien_tot, liens, adr, fil,
+ hts_acceptmime(opt, ptr, opt->lien_tot, opt->liens, adr, fil,
delayed_back.r.contenttype);
if (new_forbidden_url != -1) {
hts_log_print(opt, LOG_DEBUG, "result for wizard mime test: %d",
diff --git a/src/htsparse.h b/src/htsparse.h
index 9a8e649..2d1abd4 100644
--- a/src/htsparse.h
+++ b/src/htsparse.h
@@ -66,7 +66,7 @@ struct htsmoduleStructExtended {
char ***filters_;
robots_wizard *robots_;
hash_struct *hash_;
- int *lien_max_;
+ //int *lien_max_;
/* Base & codebase */
char *base;
@@ -142,7 +142,6 @@ int hts_wait_delayed(htsmoduleStruct * str, char *adr, char *fil, char *save,
/* Context state */
#define ENGINE_DEFINE_CONTEXT_BASE() \
- lien_url** const liens HTS_UNUSED = (lien_url**) str->liens; \
httrackp* const opt HTS_UNUSED = (httrackp*) str->opt; \
struct_back* const sback HTS_UNUSED = (struct_back*) str->sback; \
lien_back* const back HTS_UNUSED = sback->lnk; \
@@ -150,28 +149,18 @@ int hts_wait_delayed(htsmoduleStruct * str, char *adr, char *fil, char *save,
cache_back* const cache HTS_UNUSED = (cache_back*) str->cache; \
hash_struct* const hashptr HTS_UNUSED = (hash_struct*) str->hashptr; \
const int numero_passe HTS_UNUSED = str->numero_passe; \
- const int add_tab_alloc HTS_UNUSED = str->add_tab_alloc; \
/* variable */ \
- int lien_tot = *str->lien_tot_; \
- int ptr = *str->ptr_; \
- size_t lien_size = *str->lien_size_; \
- char* lien_buffer = *str->lien_buffer_
+ int ptr = *str->ptr_
#define ENGINE_SET_CONTEXT_BASE() \
- lien_tot = *str->lien_tot_; \
- ptr = *str->ptr_; \
- lien_size = *str->lien_size_; \
- lien_buffer = *str->lien_buffer_
+ ptr = *str->ptr_
#define ENGINE_LOAD_CONTEXT_BASE() \
ENGINE_DEFINE_CONTEXT_BASE()
#define ENGINE_SAVE_CONTEXT_BASE() \
/* Apply changes */ \
- * str->lien_tot_ = lien_tot; \
- * str->ptr_ = ptr; \
- * str->lien_size_ = lien_size; \
- * str->lien_buffer_ = lien_buffer
+ * str->ptr_ = ptr
#define WAIT_FOR_AVAILABLE_SOCKET() do { \
int prev = opt->state._hts_in_html_parsing; \
@@ -186,10 +175,10 @@ int hts_wait_delayed(htsmoduleStruct * str, char *adr, char *fil, char *save,
HTS_STAT.stat_errors=fspc(opt,NULL,"error"); \
HTS_STAT.stat_warnings=fspc(opt,NULL,"warning"); \
HTS_STAT.stat_infos=fspc(opt,NULL,"info"); \
- HTS_STAT.nbk=backlinks_done(sback,liens,lien_tot,ptr); \
+ HTS_STAT.nbk=backlinks_done(sback,opt->liens,opt->lien_tot,ptr); \
HTS_STAT.nb=back_transferred(HTS_STAT.stat_bytes,sback); \
/* Check */ \
- if (!RUN_CALLBACK7(opt, loop, sback->lnk, sback->count, -1,ptr,lien_tot,(int) (time_local()-HTS_STAT.stat_timestart),&HTS_STAT)) { \
+ if (!RUN_CALLBACK7(opt, loop, sback->lnk, sback->count, -1,ptr,opt->lien_tot,(int) (time_local()-HTS_STAT.stat_timestart),&HTS_STAT)) { \
return -1; \
} \
} \
diff --git a/src/htsweb.c b/src/htsweb.c
index 603d8db..313665d 100644
--- a/src/htsweb.c
+++ b/src/htsweb.c
@@ -264,6 +264,7 @@ static void back_launch_cmd(void *pP) {
/* init */
hts_init();
global_opt = opt = hts_create_opt();
+ assert(opt->size_httrackp == sizeof(httrackp));
/* run */
commandReturn = webhttrack_runmain(opt, argc, argv);
diff --git a/src/htswizard.c b/src/htswizard.c
index e8ea235..7273ce1 100644
--- a/src/htswizard.c
+++ b/src/htswizard.c
@@ -42,10 +42,6 @@ Please visit our Website: http://www.httrack.com
#include <ctype.h>
/* END specific definitions */
-// pour alléger la syntaxe, des raccourcis sont créés
-#define urladr (liens[ptr]->adr)
-#define urlfil (liens[ptr]->fil)
-
// libérer filters[0] pour insérer un élément dans filters[0]
#define HT_INSERT_FILTERS0 do {\
int i;\
@@ -191,8 +187,8 @@ static int hts_acceptlink_(httrackp * opt, int ptr, int lien_tot,
/* Niveau 1: ne pas parser suivant! */
if (ptr > 0) {
- if ((liens[ptr]->depth <= 0)
- || (liens[ptr]->depth <= 1 && !embedded_triggered)) {
+ if ((heap(ptr)->depth <= 0)
+ || (heap(ptr)->depth <= 1 && !embedded_triggered)) {
forbidden_url = 1; // interdire récupération du lien
hts_log_print(opt, LOG_DEBUG,
"file from too far level ignored at %s : %s", adr, fil);
@@ -207,11 +203,11 @@ static int hts_acceptlink_(httrackp * opt, int ptr, int lien_tot,
// ------------------------------------------------------
// doit-on traiter ce lien?.. vérifier droits de déplacement
- meme_adresse = strfield2(adr, urladr);
+ meme_adresse = strfield2(adr, urladr());
if (meme_adresse)
- hts_log_print(opt, LOG_DEBUG, "Compare addresses: %s=%s", adr, urladr);
+ 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);
+ 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
@@ -224,15 +220,15 @@ static int hts_acceptlink_(httrackp * opt, int ptr, int lien_tot,
// note (up/down): on calcule à partir du lien primaire, ET du lien précédent.
// ex: si on descend 2 fois on peut remonter 1 fois
- if (lienrelatif(tempo, fil, liens[liens[ptr]->premier]->fil) == 0) {
- if (lienrelatif(tempo2, fil, liens[ptr]->fil) == 0) {
+ if (lienrelatif(tempo, fil, heap(heap(ptr)->premier)->fil) == 0) {
+ if (lienrelatif(tempo2, fil, heap(ptr)->fil) == 0) {
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);
+ tempo, tempo2, heap(heap(ptr)->premier)->fil,
+ heap(ptr)->fil);
// si vient de primary, ne pas tester lienrelatif avec (car host "différent")
- /*if (liens[liens[ptr]->premier] == 0) { // vient de primary
+ /*if (heap(heap(ptr)->premier) == 0) { // vient de primary
}
*/
@@ -246,7 +242,7 @@ static int hts_acceptlink_(httrackp * opt, int ptr, int lien_tot,
|| (tempo2[0] != '\0' && tempo2[1] != '\0'
&& strchr(tempo2 + 1, '/') == 0)
) {
- if (!liens[ptr]->link_import) { // ne résulte pas d'un 'moved'
+ if (!heap(ptr)->link_import) { // ne résulte pas d'un 'moved'
forbidden_url = 0;
hts_log_print(opt, LOG_DEBUG, "same level link authorized: %s%s",
adr, fil);
@@ -271,7 +267,7 @@ static int hts_acceptlink_(httrackp * opt, int ptr, int lien_tot,
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'
+ if (!heap(ptr)->link_import) { // ne résulte pas d'un 'moved'
forbidden_url = 0;
hts_log_print(opt, LOG_DEBUG, "lower link authorized: %s%s",
adr, fil);
@@ -279,7 +275,7 @@ static int hts_acceptlink_(httrackp * opt, int ptr, int lien_tot,
}
} 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'
+ if (!heap(ptr)->link_import) { // ne résulte pas d'un 'moved'
forbidden_url = 0;
hts_log_print(opt, LOG_DEBUG, "lower link authorized: %s%s",
adr, fil);
@@ -295,7 +291,7 @@ static int hts_acceptlink_(httrackp * opt, int ptr, int lien_tot,
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'
+ if (!heap(ptr)->link_import) { // ne résulte pas d'un 'moved'
forbidden_url = 0;
hts_log_print(opt, LOG_DEBUG, "upper link authorized: %s%s",
adr, fil);
@@ -303,7 +299,7 @@ static int hts_acceptlink_(httrackp * opt, int ptr, int lien_tot,
}
} 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'
+ if (!heap(ptr)->link_import) { // ne résulte pas d'un 'moved'
forbidden_url = 0;
hts_log_print(opt, LOG_DEBUG, "upper link authorized: %s%s",
adr, fil);
@@ -314,11 +310,11 @@ static int hts_acceptlink_(httrackp * opt, int ptr, int lien_tot,
} else {
hts_log_print(opt, LOG_ERROR,
"Error building relative link %s and %s", fil,
- liens[ptr]->fil);
+ heap(ptr)->fil);
}
} else {
hts_log_print(opt, LOG_ERROR, "Error building relative link %s and %s",
- fil, liens[liens[ptr]->premier]->fil);
+ fil, heap(heap(ptr)->premier)->fil);
}
} // tester interdiction de descendre?
@@ -327,16 +323,16 @@ static int hts_acceptlink_(httrackp * opt, int ptr, int lien_tot,
char BIGSTK tempo[HTS_URLMAXSIZE * 2];
char BIGSTK tempo2[HTS_URLMAXSIZE * 2];
- if (lienrelatif(tempo, fil, liens[liens[ptr]->premier]->fil) == 0) {
- if (lienrelatif(tempo2, fil, liens[ptr]->fil) == 0) {
+ if (lienrelatif(tempo, fil, heap(heap(ptr)->premier)->fil) == 0) {
+ if (lienrelatif(tempo2, fil, heap(ptr)->fil) == 0) {
} else {
hts_log_print(opt, LOG_ERROR,
"Error building relative link %s and %s", fil,
- liens[ptr]->fil);
+ heap(ptr)->fil);
}
} else {
hts_log_print(opt, LOG_ERROR, "Error building relative link %s and %s",
- fil, liens[liens[ptr]->premier]->fil);
+ fil, heap(heap(ptr)->premier)->fil);
}
} // fin tester interdiction de monter
@@ -352,24 +348,24 @@ static int hts_acceptlink_(httrackp * opt, int ptr, int lien_tot,
break; // interdicton de sortir au dela de l'adresse
case 1:{ // sortie sur le même dom.xxx
size_t i = strlen(adr) - 1;
- size_t j = strlen(urladr) - 1;
+ size_t j = strlen(urladr()) - 1;
if ((i > 0) && (j > 0)) {
while((i > 0) && (adr[i] != '.'))
i--;
- while((j > 0) && (urladr[j] != '.'))
+ while((j > 0) && (urladr()[j] != '.'))
j--;
if ((i > 0) && (j > 0)) {
i--;
j--;
while((i > 0) && (adr[i] != '.'))
i--;
- while((j > 0) && (urladr[j] != '.'))
+ while((j > 0) && (urladr()[j] != '.'))
j--;
}
}
if ((i > 0) && (j > 0)) {
- if (!strfield2(adr + i, urladr + j)) { // !=
+ if (!strfield2(adr + i, urladr() + j)) { // !=
if (!opt->wizard) { // mode non wizard
//printf("refused: %s\n",adr);
forbidden_url = 1; // pas même domaine
@@ -391,14 +387,14 @@ static int hts_acceptlink_(httrackp * opt, int ptr, int lien_tot,
break;
case 2:{ // sortie sur le même .xxx
size_t i = strlen(adr) - 1;
- size_t j = strlen(urladr) - 1;
+ size_t j = strlen(urladr()) - 1;
while((i > 0) && (adr[i] != '.'))
i--;
- while((j > 0) && (urladr[j] != '.'))
+ while((j > 0) && (urladr()[j] != '.'))
j--;
if ((i > 0) && (j > 0)) {
- if (!strfield2(adr + i, urladr + j)) { // !-
+ if (!strfield2(adr + i, urladr() + j)) { // !-
if (!opt->wizard) { // mode non wizard
//printf("refused: %s\n",adr);
forbidden_url = 1; // pas même .xx
@@ -497,7 +493,7 @@ static int hts_acceptlink_(httrackp * opt, int ptr, int lien_tot,
// there is no way yet to tag "external" links, and therefore links that are
// "weak" (authorized depth < external depth) are just not considered for external
// hack
- if (liens[ptr]->depth > opt->extdepth) {
+ if (heap(ptr)->depth > opt->extdepth) {
// *set_prio_to = opt->extdepth + 1;
*set_prio_to = 1 + (opt->extdepth);
may_set_prio_to = 0; // clear may-set flag
@@ -506,11 +502,11 @@ static int hts_acceptlink_(httrackp * opt, int ptr, int lien_tot,
if (question) {
hts_log_print(opt, LOG_DEBUG,
"(wizard) ambiguous link accepted (external depth): link %s at %s%s",
- l, urladr, urlfil);
+ 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);
+ l, urladr(), urlfil());
}
}
@@ -554,14 +550,14 @@ static int hts_acceptlink_(httrackp * opt, int ptr, int lien_tot,
may_set_prio_to = 0; // clear may-set flag
hts_log_print(opt, LOG_DEBUG,
"(wizard) explicit authorized (%s) link: link %s at %s%s",
- mdepth, l, urladr, urlfil);
+ 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
hts_log_print(opt, LOG_DEBUG,
"(wizard) explicit forbidden (%s) link: link %s at %s%s",
- mdepth, l, urladr, urlfil);
+ mdepth, l, urladr(), urlfil());
} // sinon on touche à rien
}
}
@@ -569,14 +565,14 @@ static int hts_acceptlink_(httrackp * opt, int ptr, int lien_tot,
// vérifier mode mirror links
if (question) {
if (opt->mirror_first_page) { // mode mirror links
- if (liens[ptr]->precedent == 0) { // parent=primary!
+ if (heap(ptr)->precedent == 0) { // parent=primary!
forbidden_url = 0; // autorisé
may_set_prio_to = 0; // clear may-set flag
question = 1; // résolution auto
force_mirror = 5; // mirror (5)
hts_log_print(opt, LOG_DEBUG,
"(wizard) explicit mirror link: link %s at %s%s", l,
- urladr, urlfil);
+ urladr(), urlfil());
}
}
}
@@ -588,7 +584,7 @@ static int hts_acceptlink_(httrackp * opt, int ptr, int lien_tot,
forbidden_url = 1;
hts_log_print(opt, LOG_DEBUG,
"(wizard) ambiguous forbidden link: link %s at %s%s", l,
- urladr, urlfil);
+ urladr(), urlfil());
}
}
// vérifier robots.txt
@@ -623,14 +619,14 @@ static int hts_acceptlink_(httrackp * opt, int ptr, int lien_tot,
if (!forbidden_url) {
hts_log_print(opt, LOG_DEBUG,
"(wizard) shared foreign domain link: link %s at %s%s", l,
- urladr, urlfil);
+ urladr(), urlfil());
} else {
hts_log_print(opt, LOG_DEBUG,
"(wizard) cancelled foreign domain link: link %s at %s%s",
- l, urladr, urlfil);
+ l, urladr(), urlfil());
}
#if BDEBUG==3
- printf("at %s in %s, wizard says: url %s ", urladr, urlfil, l);
+ printf("at %s in %s, wizard says: url %s ", urladr(), urlfil(), l);
if (forbidden_url)
printf("cancelled");
else
@@ -988,7 +984,4 @@ int hts_testlinksize(httrackp * opt, const char *adr, const char *fil, LLint siz
return jok;
}
-#undef urladr
-#undef urlfil
-
#undef HT_INSERT_FILTERS0
diff --git a/src/httrack.c b/src/httrack.c
index 7c1ea5e..452ba2c 100644
--- a/src/httrack.c
+++ b/src/httrack.c
@@ -224,6 +224,7 @@ int main(int argc, char **argv) {
signal_handlers();
hts_init();
opt = global_opt = hts_create_opt();
+ assert(opt->size_httrackp == sizeof(httrackp));
CHAIN_FUNCTION(opt, init, htsshow_init, NULL);
CHAIN_FUNCTION(opt, uninit, htsshow_uninit, NULL);