home *** CD-ROM | disk | FTP | other *** search
/ PC Open 48 / pcopen48.iso / Internet / HtTrack / DATA1.CAB / Sources / src / htswizard.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-21  |  27.5 KB  |  795 lines

  1. /* ------------------------------------------------------------ */
  2. /*
  3. HTTrack Website Copier, Offline Browser for Windows and Unix
  4. Copyright (C) Xavier Roche, Yann Philippot
  5.  
  6. This program is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU General Public License
  8. as published by the Free Software Foundation; either version 2
  9. of the License, or any later version.
  10.  
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  19.  
  20.  
  21. Important notes:
  22.  
  23. - We hereby ask people using this source NOT to use it in purpose of grabbing
  24. emails addresses, or collecting any other private information on persons.
  25. This would disgrace our work, and spoil the many hours we spent on it.
  26.  
  27.  
  28. This project has been developed by Xavier Roche and Yann Philippot,
  29. from the company Serianet at Caen, France (http://www.serianet.com)
  30.  
  31. Please visit our Website: http://www.httrack.com
  32. */
  33.  
  34.  
  35. /* ------------------------------------------------------------ */
  36. /* File: httrack.c subroutines:                                 */
  37. /*       wizard system (accept/refuse links)                    */
  38. /* Author: Xavier Roche                                         */
  39. /* ------------------------------------------------------------ */
  40.  
  41. #include "htswizard.h"
  42. #include "htsdefines.h"
  43.  
  44. /* specific definitions */
  45. #include "htsbase.h"
  46. #include <stdio.h>
  47. #include <stdlib.h>
  48. #include <string.h>
  49. #include <ctype.h>
  50. /* END specific definitions */
  51.  
  52. // version 1 pour httpmirror
  53. // flusher si on doit lire peu α peu le fichier
  54. #define test_flush if (opt->flush) { fflush(opt->log); fflush(opt->errlog); }
  55.  
  56. // pour allΘger la syntaxe, des raccourcis sont crΘΘs
  57. #define urladr   (liens[ptr]->adr)
  58. #define urlfil   (liens[ptr]->fil)
  59. #define level    (liens[ptr]->prio)
  60. #define new_stat_bytes HTS_TOTAL_RECV
  61.  
  62. // libΘrer filters[0] pour insΘrer un ΘlΘment dans filters[0]
  63. #define HT_INSERT_FILTERS0 {\
  64.   int i;\
  65.   if (*filptr > 0) {\
  66.     for(i = (*filptr)-1 ; i>=0 ; i--) {\
  67.       strcpy(filters[i+1],filters[i]);\
  68.     }\
  69.   }\
  70.   strcpy(filters[0],"");\
  71.   (*filptr)++;\
  72.   (*filptr)=minimum((*filptr),filter_max);\
  73. }
  74.  
  75.  
  76.  
  77. /*
  78. httrackp opt     bloc d'options
  79. int ptr,int lien_tot,lien_url** liens
  80.                              relatif aux liens
  81. char* adr,char* fil
  82.                              adresse/fichier α tester
  83. char** filters,int filptr,int filter_max
  84.                              relatif aux filtres
  85. robots_wizard* robots
  86.                              relatif aux robots
  87. int* set_prio_to_0
  88.                              callback obligatoire "ne capturer QUE ce lien et pas les suivants"
  89. int* just_test_it
  90.                              callback optionnel "ne faire que tester ce lien Θventuellement"
  91. retour:
  92.                0 acceptΘ
  93.                1 refusΘ
  94.               -1 pas d'avis
  95. */
  96. int hts_acceptlink(httrackp* opt,
  97.                    int ptr,int lien_tot,lien_url** liens,
  98.                    char* adr,char* fil,
  99.                    char** filters,int* filptr,int filter_max,
  100.                    robots_wizard* robots,
  101.                    int* set_prio_to_0,
  102.                    int* just_test_it) {
  103.  
  104.   int forbidden_url=-1;
  105.   int meme_adresse;
  106.  
  107.   // -------------------- PHASE 1 --------------------
  108.  
  109.   /* Infos */
  110.   if ((opt->debug>1) && (opt->log!=NULL)) {
  111.     fspc(opt->log,"debug"); fprintf(opt->log,"wizard test begins: %s%s"LF,adr,fil);
  112.     test_flush;
  113.   }
  114.   
  115.   /* Doit-on traiter les non html? */
  116.   if ((opt->getmode & 2)==0) {    // non on ne doit pas
  117.     if (!ishtml(fil)) {  // non il ne faut pas
  118.       //adr[0]='\0';    // ne pas traiter ce lien, pas traiter
  119.       forbidden_url=1;    // interdire rΘcupΘration du lien
  120.       if ((opt->debug>1) && (opt->log!=NULL)) {
  121.         fspc(opt->log,"debug"); fprintf(opt->log,"non-html file ignored at %s : %s"LF,adr,fil);
  122.         test_flush;
  123.       }
  124.       
  125.     }
  126.   }
  127.   
  128.   /* Niveau 1: ne pas parser suivant! */
  129.   if (ptr>0) {
  130.     if (level<=1) {
  131.       forbidden_url=1;    // interdire rΘcupΘration du lien
  132.       if ((opt->debug>1) && (opt->log!=NULL)) {
  133.         fspc(opt->log,"debug"); fprintf(opt->log,"file from too far level ignored at %s : %s"LF,adr,fil);
  134.         test_flush;
  135.       }
  136.     }
  137.   }
  138.  
  139.   /* en cas d'Θchec en phase 1, retour immΘdiat! */
  140.   if (forbidden_url==1) {
  141.     return forbidden_url;
  142.   }
  143.   
  144.   // -------------------- PHASE 2 --------------------
  145.  
  146.   // ------------------------------------------------------
  147.   // doit-on traiter ce lien?.. vΘrifier droits de dΘplacement
  148.   meme_adresse=strfield2(adr,urladr);
  149.   if ((opt->debug>1) && (opt->log!=NULL)) {
  150.     fspc(opt->log,"debug"); 
  151.     if (meme_adresse) 
  152.       fprintf(opt->log,"Compare addresses: %s=%s"LF,adr,urladr);
  153.     else
  154.       fprintf(opt->log,"Compare addresses: %s!=%s"LF,adr,urladr);
  155.     test_flush;
  156.   }
  157.   if (meme_adresse) {  // mΩme adresse 
  158.     {  // tester interdiction de descendre
  159.       // MODIFIE : en cas de remontΘe puis de redescente, il se pouvait qu'on ne puisse pas atteindre certains fichiers
  160.       // problΦme: si un fichier est virtuellement accessible via une page mais dont le lien est sur une autre *uniquement*..
  161.       char tempo[HTS_URLMAXSIZE*2];
  162.       char tempo2[HTS_URLMAXSIZE*2];
  163.       
  164.       // note (up/down): on calcule α partir du lien primaire, ET du lien prΘcΘdent.
  165.       // ex: si on descend 2 fois on peut remonter 1 fois
  166.       
  167.       if (lienrelatif(tempo,fil,liens[liens[ptr]->premier]->fil)==0) {
  168.         if (lienrelatif(tempo2,fil,liens[ptr]->fil)==0) {
  169.           if ((opt->debug>1) && (opt->log!=NULL)) {
  170.             fspc(opt->log,"debug"); fprintf(opt->log,"build relative links to test: %s %s (with %s and %s)"LF,tempo,tempo2,liens[liens[ptr]->premier]->fil,liens[ptr]->fil);
  171.             test_flush;
  172.           }
  173.           
  174.           // si vient de primary, ne pas tester lienrelatif avec (car host "diffΘrent")
  175.           /*if (liens[liens[ptr]->premier] == 0) {   // vient de primary
  176.           }
  177.           */
  178.           
  179.           // NEW: finalement OK, sauf pour les moved repΘrΘs par link_import
  180.           // PROBLEME : annulΘ a cause d'un lien Θventuel isolΘ acceptΘ..qui entrainerait un miroir
  181.           
  182.           // (test mΩme niveau (NOUVEAU α cause de certains problΦmes de filtres non intΘgrΘs))
  183.           // NEW
  184.           if ( (!strchr(tempo+1,'/')) || (!strchr(tempo2+1,'/')) ) {
  185.             if (!liens[ptr]->link_import) {   // ne rΘsulte pas d'un 'moved'
  186.               forbidden_url=0;
  187.               if ((opt->debug>1) && (opt->log!=NULL)) {
  188.                 fspc(opt->log,"debug"); fprintf(opt->log,"same level link authorized: %s%s"LF,adr,fil);
  189.                 test_flush;
  190.               }
  191.             }
  192.           }
  193.           
  194.           // down
  195.           if ( (strncmp(tempo,"../",3)) || (strncmp(tempo2,"../",3)))  {   // pas montΘe sinon ne nbous concerne pas
  196.             int test1,test2;
  197.             if (!strncmp(tempo,"../",3))
  198.               test1=0;
  199.             else
  200.               test1 = (strchr(tempo +((*tempo =='/')?1:0),'/')!=NULL);
  201.             if (!strncmp(tempo2,"../",3))
  202.               test2=0;
  203.             else
  204.               test2 = (strchr(tempo2+((*tempo2=='/')?1:0),'/')!=NULL);
  205.             if ( (test1) && (test2) ) {   // on ne peut que descendre
  206.               if ((opt->seeker & 1)==0) {  // interdiction de descendre
  207.                 forbidden_url=1;
  208.                 if ((opt->debug>1) && (opt->log!=NULL)) {
  209.                   fspc(opt->log,"debug"); fprintf(opt->log,"lower link canceled: %s%s"LF,adr,fil);
  210.                   test_flush;
  211.                 }
  212.               } else {    // autorisΘ α priori - NEW
  213.                 if (!liens[ptr]->link_import) {   // ne rΘsulte pas d'un 'moved'
  214.                   forbidden_url=0;
  215.                   if ((opt->debug>1) && (opt->log!=NULL)) {
  216.                     fspc(opt->log,"debug"); fprintf(opt->log,"lower link authorized: %s%s"LF,adr,fil);
  217.                     test_flush;
  218.                   }
  219.                 }
  220.               }
  221.             } else if ( (test1) || (test2) ) {   // on peut descendre pour accΘder au lien
  222.               if ((opt->seeker & 1)!=0) {  // on peut descendre - NEW
  223.                 if (!liens[ptr]->link_import) {   // ne rΘsulte pas d'un 'moved'
  224.                   forbidden_url=0;
  225.                   if ((opt->debug>1) && (opt->log!=NULL)) {
  226.                     fspc(opt->log,"debug"); fprintf(opt->log,"lower link authorized: %s%s"LF,adr,fil);
  227.                     test_flush;
  228.                   }
  229.                 }
  230.               }
  231.             }
  232.           }
  233.           
  234.           
  235.           // up
  236.           if ( (!strncmp(tempo,"../",3)) && (!strncmp(tempo2,"../",3)) ) {    // impossible sans monter
  237.             if ((opt->seeker & 2)==0) {  // interdiction de monter
  238.               forbidden_url=1;
  239.               if ((opt->debug>1) && (opt->log!=NULL)) {
  240.                 fspc(opt->log,"debug"); fprintf(opt->log,"upper link canceled: %s%s"LF,adr,fil);
  241.                 test_flush;
  242.               }
  243.             } else {       // autorisΘ α monter - NEW
  244.               if (!liens[ptr]->link_import) {   // ne rΘsulte pas d'un 'moved'
  245.                 forbidden_url=0;
  246.                 if ((opt->debug>1) && (opt->log!=NULL)) {
  247.                   fspc(opt->log,"debug"); fprintf(opt->log,"upper link authorized: %s%s"LF,adr,fil);
  248.                   test_flush;
  249.                 }
  250.               }
  251.             }
  252.           } else if ( (!strncmp(tempo,"../",3)) || (!strncmp(tempo2,"../",3)) ) {    // Possible en montant
  253.             if ((opt->seeker & 2)!=0) {  // autorisΘ α monter - NEW
  254.               if (!liens[ptr]->link_import) {   // ne rΘsulte pas d'un 'moved'
  255.                 forbidden_url=0;
  256.                 if ((opt->debug>1) && (opt->log!=NULL)) {
  257.                   fspc(opt->log,"debug"); fprintf(opt->log,"upper link authorized: %s%s"LF,adr,fil);
  258.                   test_flush;
  259.                 }
  260.               }
  261.             }  // sinon autorisΘ en descente
  262.           }
  263.           
  264.           
  265.         } else {
  266.           if (opt->errlog) {
  267.             fprintf(opt->errlog,"Error building relative link %s and %s"LF,fil,liens[ptr]->fil);
  268.             test_flush;
  269.           }
  270.         }
  271.       } else {
  272.         if (opt->errlog) {
  273.           fprintf(opt->errlog,"Error building relative link %s and %s"LF,fil,liens[liens[ptr]->premier]->fil);
  274.           test_flush;
  275.         }
  276.       }
  277.       
  278.     }  // tester interdiction de descendre?
  279.     
  280.     {  // tester interdiction de monter
  281.       char tempo[HTS_URLMAXSIZE*2];
  282.       char tempo2[HTS_URLMAXSIZE*2];
  283.       if (lienrelatif(tempo,fil,liens[liens[ptr]->premier]->fil)==0) {
  284.         if (lienrelatif(tempo2,fil,liens[ptr]->fil)==0) {
  285.         } else {
  286.           if (opt->errlog) { 
  287.             fprintf(opt->errlog,"Error building relative link %s and %s"LF,fil,liens[ptr]->fil);
  288.             test_flush;
  289.           }
  290.           
  291.         }
  292.       } else {
  293.         if (opt->errlog) { 
  294.           fprintf(opt->errlog,"Error building relative link %s and %s"LF,fil,liens[liens[ptr]->premier]->fil);
  295.           test_flush;
  296.         }
  297.         
  298.       }
  299.     }   // fin tester interdiction de monter
  300.     
  301.   } else {    // adresse diffΘrente, sortir?
  302.     
  303.     //if (!opt->wizard) {    // mode non wizard
  304.     // doit-on traiter ce lien?.. vΘrifier droits de sortie
  305.     switch((opt->travel & 255)) {
  306.     case 0: 
  307.       if (!opt->wizard)    // mode non wizard
  308.         forbidden_url=1; break;    // interdicton de sortir au dela de l'adresse
  309.     case 1: {              // sortie sur le mΩme dom.xxx
  310.       int i=strlen(adr)-1;
  311.       int j=strlen(urladr)-1;
  312.       while( (i>0) && (adr[i]!='.')) i--;
  313.       while( (j>0) && (urladr[j]!='.')) j--;
  314.       i--; j--;
  315.       while( (i>0) && (adr[i]!='.')) i--;
  316.       while( (j>0) && (urladr[j]!='.')) j--;
  317.       if ((i>0) && (j>0)) {
  318.         if (!strfield2(adr+i,urladr+j)) {   // !=
  319.           if (!opt->wizard) {   // mode non wizard
  320.             //printf("refused: %s\n",adr);
  321.             forbidden_url=1;  // pas mΩme domaine  
  322.             if ((opt->debug>1) && (opt->log!=NULL)) {
  323.               fspc(opt->log,"debug"); fprintf(opt->log,"foreign domain link canceled: %s%s"LF,adr,fil);
  324.               test_flush;
  325.             }
  326.           }
  327.           
  328.         } else {
  329.           if (opt->wizard) {   // mode wizard
  330.             forbidden_url=0;  // mΩme domaine  
  331.             if ((opt->debug>1) && (opt->log!=NULL)) {
  332.               fspc(opt->log,"debug"); fprintf(opt->log,"same domain link authorized: %s%s"LF,adr,fil);
  333.               test_flush;
  334.             }
  335.           }
  336.         }
  337.         
  338.       } else
  339.         forbidden_url=1;
  340.             } 
  341.       break;  
  342.     case 2: {                      // sortie sur le mΩme .xxx
  343.       int i=strlen(adr)-1;
  344.       int j=strlen(urladr)-1;
  345.       while( (i>0) && (adr[i]!='.')) i--;
  346.       while( (j>0) && (urladr[j]!='.')) j--;
  347.       if ((i>0) && (j>0)) {
  348.         if (!strfield2(adr+i,urladr+j)) {   // !-
  349.           if (!opt->wizard) {   // mode non wizard
  350.             //printf("refused: %s\n",adr);
  351.             forbidden_url=1;  // pas mΩme .xx  
  352.             if ((opt->debug>1) && (opt->log!=NULL)) {
  353.               fspc(opt->log,"debug"); fprintf(opt->log,"foreign location link canceled: %s%s"LF,adr,fil);
  354.               test_flush;
  355.             }
  356.           }
  357.         } else {
  358.           if (opt->wizard) {   // mode wizard
  359.             forbidden_url=0;  // mΩme domaine  
  360.             if ((opt->debug>1) && (opt->log!=NULL)) {
  361.               fspc(opt->log,"debug"); fprintf(opt->log,"same location link authorized: %s%s"LF,adr,fil);
  362.               test_flush;
  363.             }
  364.           }
  365.         }
  366.       } else forbidden_url=1;     
  367.             } 
  368.       break;
  369.     case 7:                 // everywhere!!
  370.       if (opt->wizard) {   // mode wizard
  371.         forbidden_url=0;
  372.         break;
  373.       }
  374.     }  // switch
  375.     
  376.     // ANCIENNE POS -- rΘcupΘrer les liens α c⌠tΘs d'un lien (nearlink)
  377.     
  378.   }  // fin test adresse identique/diffΘrente
  379.  
  380.   // -------------------- PHASE 3 --------------------
  381.  
  382.   // rΘcupΘrer les liens α c⌠tΘs d'un lien (nearlink) (nvelle pos)
  383.   if (opt->nearlink) {
  384.     if (!ishtml(fil)) {  // non html
  385.       //printf("ok %s%s\n",ad,fil);
  386.       forbidden_url=0;    // autoriser
  387.       if ((opt->debug>1) && (opt->log!=NULL)) {
  388.         fspc(opt->log,"debug"); fprintf(opt->log,"near link authorized: %s%s"LF,adr,fil);
  389.         test_flush;
  390.       }
  391.     }
  392.   }
  393.   
  394.   // -------------------- PHASE 4 --------------------
  395.   
  396.   // ------------------------------------------------------
  397.   // Si wizard, il se peut qu'on autorise ou qu'on interdise 
  398.   // un lien spΘcial avant mΩme de tester sa position, sa hiΘrarchie etc.
  399.   // peut court-circuiter le forbidden_url prΘcΘdent
  400.   if (opt->wizard) { // le wizard entre en action..
  401.     //
  402.     int jok;
  403.     int question=1;         // poser une question                            
  404.     int force_mirror=0;     // pour mirror links
  405.     int filters_answer=0;   // dΘcision prise par les filtres
  406.     char l[HTS_URLMAXSIZE*2];
  407.     
  408.     if (forbidden_url!=-1) question=0;  // pas de question, rΘsolu
  409.     
  410.     // former URL complΦte du lien actuel
  411.     strcpy(l,jump_identification(adr));
  412.     if (*fil!='/') strcat(l,"/");
  413.     strcat(l,fil);
  414.     
  415.     // tester filters (URLs autorisΘes ou interdites explicitement)
  416.     
  417.     // si lien primaire on saute le joker, on est pas lΘmur
  418.     if (ptr==0) {  // lien primaire, autoriser
  419.       question=1;    // la question sera rΘsolue automatiquement
  420.       forbidden_url=0;
  421.     } else {
  422.       // filters, 0=sait pas 1=ok -1=interdit
  423.       jok = fa_strjoker(filters,*filptr,l,NULL,NULL);
  424.       if (jok == 1) {   // autorisΘ
  425.         filters_answer=1;  // dΘcision prise par les filtres
  426.         question=0;    // ne pas poser de question, autorisΘ
  427.         forbidden_url=0;  // URL autorisΘe
  428.         if ((opt->debug>1) && (opt->log!=NULL)) {
  429.           fspc(opt->log,"debug"); fprintf(opt->log,"(wizard) explicit authorized link: link %s at %s%s"LF,l,urladr,urlfil);
  430.           test_flush;
  431.         }
  432.       } else if (jok == -1) {
  433.         filters_answer=1;  // dΘcision prise par les filtres
  434.         question=0;    // ne pas poser de question:
  435.         forbidden_url=1;   // URL interdite
  436.         if ((opt->debug>1) && (opt->log!=NULL)) {
  437.           fspc(opt->log,"debug"); fprintf(opt->log,"(wizard) explicit forbidden link: link %s at %s%s"LF,l,urladr,urlfil);
  438.           test_flush;
  439.         }
  440.       }  // sinon on touche α rien
  441.     }
  442.     
  443.     // vΘrifier mode mirror links
  444.     if (question) {
  445.       if (opt->mirror_first_page) {    // mode mirror links
  446.         if (liens[ptr]->precedent==0) {  // parent=primary!
  447.           forbidden_url=0;    // autorisΘ
  448.           question=1;         // rΘsolution auto
  449.           force_mirror=5;     // mirror (5)
  450.           if ((opt->debug>1) && (opt->log!=NULL)) {
  451.             fspc(opt->log,"debug"); fprintf(opt->log,"(wizard) explicit mirror link: link %s at %s%s"LF,l,urladr,urlfil);
  452.             test_flush;
  453.           }
  454.         }
  455.       }
  456.     }
  457.     
  458.     // on doit poser la question.. peut on la poser?
  459.     // (oui je sais quel preuve de dΘlicatesse, merci merci)      
  460.     if ((question) && (ptr>0) && (!force_mirror)) {
  461.       if (opt->wizard==2) {    // Θliminer tous les liens non rΘpertoriΘs comme autorisΘs (ou inconnus)
  462.         question=0;
  463.         forbidden_url=1;
  464.         if ((opt->debug>1) && (opt->log!=NULL)) {
  465.           fspc(opt->log,"debug"); fprintf(opt->log,"(wizard) ambiguous forbidden link: link %s at %s%s"LF,l,urladr,urlfil);
  466.           test_flush;
  467.         }
  468.       }
  469.     }
  470.     
  471.     // vΘrifier robots.txt
  472.     if (opt->robots) {
  473.       int r = checkrobots(robots,adr,fil);
  474.       if (r == -1) {    // interdiction
  475. #if DEBUG_ROBOTS
  476.         printf("robots.txt forbidden: %s%s\n",adr,fil);
  477. #endif
  478.         // question rΘsolue, par les filtres, et mode robot non strict
  479.         if ((!question) && (filters_answer) && (opt->robots == 1) && (forbidden_url!=1)) {
  480.           r=0;    // annuler interdiction des robots
  481.           if (!forbidden_url) {
  482.             if ((opt->debug>1) && (opt->log!=NULL)) {
  483.               fspc(opt->log,"debug"); fprintf(opt->log,"Warning link followed against robots.txt: link %s at %s%s"LF,l,adr,fil);
  484.               test_flush;
  485.             }
  486.           }
  487.         }
  488.         if (r == -1) {    // interdire
  489.           forbidden_url=1;
  490.           question=0;
  491.           if ((opt->debug>1) && (opt->log!=NULL)) {
  492.             fspc(opt->log,"debug"); fprintf(opt->log,"(robots.txt) forbidden link: link %s at %s%s"LF,l,adr,fil);
  493.             test_flush;
  494.           }
  495.         }
  496.       }
  497.     }
  498.     
  499.     if (!question) {
  500.       if ((opt->debug>1) && (opt->log!=NULL)) {
  501.         if (!forbidden_url) {
  502.           fspc(opt->log,"debug"); fprintf(opt->log,"(wizard) shared foreign domain link: link %s at %s%s"LF,l,urladr,urlfil);
  503.         } else {
  504.           fspc(opt->log,"debug"); fprintf(opt->log,"(wizard) cancelled foreign domain link: link %s at %s%s"LF,l,urladr,urlfil);
  505.         }
  506.         test_flush;
  507.       }
  508. #if BDEBUG==3
  509.       printf("at %s in %s, wizard says: url %s ",urladr,urlfil,l);
  510.       if (forbidden_url) printf("cancelled"); else printf(">SHARED<");
  511.       printf("\n");
  512. #endif 
  513.     }
  514.  
  515.     /* en cas de question, ou lien primaire (enregistrer autorisations) */
  516.     if (question || (ptr==0)) {
  517. #if HTS_ANALYSTE!=2
  518.       char s[4];
  519. #else
  520.       char* s;
  521. #endif
  522.       int n=0;
  523.       
  524.       // si primaire (plus bas) alors ...
  525.       if ((ptr!=0) && (force_mirror==0)) {
  526.         HTS_REQUEST_START;
  527.         HT_PRINT("\n");
  528.         HT_PRINT("At "); HT_PRINT(urladr); HT_PRINT(", there is a link ("); HT_PRINT(adr); HT_PRINT("/"); HT_PRINT(fil); HT_PRINT(") which goes outside the address."LF);
  529.         HT_PRINT("What should I do? (press a key + enter)"LF LF);
  530.         HT_PRINT("* Ignore all further links" LF);
  531.         HT_PRINT("0 Ignore this link (default if empty entry)"LF);
  532.         HT_PRINT("1 Ignore directory and lower structures"LF);
  533.         HT_PRINT("2 Ignore all domain"LF);
  534.         //HT_PRINT("3 (Ignore location, not implemented)\n");
  535.         HT_PRINT(LF);
  536.         HT_PRINT("4 Get only this page/link"LF);
  537.         HT_PRINT("5 Mirror this link (useful)"LF);
  538.         HT_PRINT("6 Mirror links located in the same domain"LF);
  539.         HT_PRINT(LF);
  540. #if HTS_ANALYSTE!=2
  541.         //HT_PRINT("! View extract of html code where the link is located"LF);
  542. #endif
  543.         HTS_REQUEST_END;
  544. #if HTS_ANALYSTE!=2
  545.         do {
  546.           io_flush; linput(stdin,s,2);
  547. #else
  548.           {
  549.             char tempo[HTS_URLMAXSIZE*2];
  550.             tempo[0]='\0';
  551.             strcat(tempo,adr);
  552.             strcat(tempo,"/");
  553.             strcat(tempo,fil);
  554.             s=hts_htmlcheck_query3(tempo);
  555.           }
  556. #endif
  557.           if (strnotempty(s)==0)  // entrΘe
  558.             n=0;
  559.           else if (isdigit((unsigned char)*s))
  560.             sscanf(s,"%d",&n);
  561.           else {
  562.             switch(*s) {
  563.             case '*': n=-1; break;
  564.             case '!': n=-999; {
  565.               /*char *a;
  566.               int i;                                    
  567.               a=copie_de_adr-128;
  568.               if (a<r.adr) a=r.adr;
  569.               for(i=0;i<256;i++) {
  570.                 if (a==copie_de_adr) printf("\nHERE:\n");
  571.                 printf("%c",*a++);
  572.               }
  573.               printf("\n\n");
  574.               */
  575.                       }
  576.               break;
  577.             default: n=-999; printf("What did you say?\n"); break;
  578.               
  579.             } 
  580.           }
  581. #if HTS_ANALYSTE!=2                                                              
  582.         } while(n==-999);
  583. #endif
  584.         io_flush;
  585.       } else {   // lien primaire: autoriser rΘpertoire entier
  586.         if (!force_mirror) {
  587.           if ((opt->seeker & 1)==0) {  // interdiction de descendre
  588.             n=7;
  589.           } else {
  590.             n=5;   // autoriser miroir rΘpertoires descendants (lien primaire)
  591.           }
  592.         } else   // forcer valeur (sub-wizard)
  593.           n=force_mirror;
  594.       }
  595.       
  596.       switch(n) {
  597.       case -1: // sauter tout le reste
  598.         forbidden_url=1;
  599.         opt->wizard=2;    // sauter tout le reste
  600.         break;
  601.       case 0:    // interdire les mΩmes liens: adr/fil
  602.         forbidden_url=1; 
  603.         HT_INSERT_FILTERS0;    // insΘrer en 0
  604.         strcpy(filters[0],"-");
  605.         strcat(filters[0],jump_identification(adr));
  606.         if (*fil!='/') strcat(filters[0],"/");
  607.         strcat(filters[0],fil);
  608.         break;
  609.         
  610.       case 1: // Θliminer rΘpertoire entier et sous rΘp: adr/path/ *
  611.         forbidden_url=1;
  612.         {
  613.           int i=strlen(fil)-1;
  614.           while((fil[i]!='/') && (i>0)) i--;
  615.           if (fil[i]=='/') {
  616.             HT_INSERT_FILTERS0;    // insΘrer en 0
  617.             strcpy(filters[0],"-");
  618.             strcat(filters[0],jump_identification(adr));
  619.             if (*fil!='/') strcat(filters[0],"/");
  620.             strncat(filters[0],fil,i);
  621.             if (filters[0][strlen(filters[0])-1]!='/') strcat(filters[0],"/");
  622.             strcat(filters[0],"*");
  623.           }
  624.         }            
  625.         
  626.         // ** ...
  627.         break;
  628.         
  629.       case 2:    // adresse adr*
  630.         forbidden_url=1;
  631.         HT_INSERT_FILTERS0;    // insΘrer en 0                                
  632.         strcpy(filters[0],"-");
  633.         strcat(filters[0],jump_identification(adr));
  634.         strcat(filters[0],"*");
  635.         break;
  636.         
  637.       case 3: // ** A FAIRE
  638.         forbidden_url=1;
  639.         /*
  640.         {
  641.         int i=strlen(adr)-1;
  642.         while((adr[i]!='/') && (i>0)) i--;
  643.         if (i>0) {
  644.         
  645.           }
  646.           
  647.       }*/
  648.         
  649.         break;
  650.         //
  651.       case 4:    // same link
  652.         // PAS BESOIN!!
  653.         /*HT_INSERT_FILTERS0;    // insΘrer en 0                                
  654.         strcpy(filters[0],"+");
  655.         strcat(filters[0],adr);
  656.         if (*fil!='/') strcat(filters[0],"/");
  657.         strcat(filters[0],fil);*/
  658.         
  659.         
  660.         // Θtant donnΘ le renversement wizard/primary filter (les primary autorisent up/down ET interdisent)
  661.         // il faut Θviter d'un lien isolΘ effectue un miroir total..
  662.         
  663.         *set_prio_to_0 = 1;    // niveau de rΘcursion=0 (pas de miroir)
  664.         
  665.         break;
  666.         
  667.       case 5:    // autoriser rΘpertoire entier et fils
  668.         if ((opt->seeker & 2)==0) {  // interdiction de monter
  669.           int i=strlen(fil)-1;
  670.           while((fil[i]!='/') && (i>0)) i--;
  671.           if (fil[i]=='/') {
  672.             HT_INSERT_FILTERS0;    // insΘrer en 0                                
  673.             strcpy(filters[0],"+");
  674.             strcat(filters[0],jump_identification(adr));
  675.             if (*fil!='/') strcat(filters[0],"/");
  676.             strncat(filters[0],fil,i+1);
  677.             strcat(filters[0],"*");
  678.           }
  679.         } else {    // autoriser domaine alors!!
  680.           HT_INSERT_FILTERS0;    // insΘrer en 0                                strcpy(filters[filptr],"+");
  681.           strcpy(filters[0],"+");
  682.           strcat(filters[0],jump_identification(adr));
  683.           strcat(filters[0],"*");
  684.         }
  685.         break;
  686.         
  687.       case 6:    // same domain
  688.         HT_INSERT_FILTERS0;    // insΘrer en 0                                strcpy(filters[filptr],"+");
  689.         strcpy(filters[0],"+");
  690.         strcat(filters[0],jump_identification(adr));
  691.         strcat(filters[0],"*");
  692.         break;
  693.         //
  694.       case 7:    // autoriser ce rΘpertoire
  695.         {
  696.           int i=strlen(fil)-1;
  697.           while((fil[i]!='/') && (i>0)) i--;
  698.           if (fil[i]=='/') {
  699.             HT_INSERT_FILTERS0;    // insΘrer en 0                                
  700.             strcpy(filters[0],"+");
  701.             strcat(filters[0],jump_identification(adr));
  702.             if (*fil!='/') strcat(filters[0],"/");
  703.             strncat(filters[0],fil,i+1);
  704.             strcat(filters[0],"*[file]");
  705.           }
  706.         }
  707.         
  708.         break;
  709.         
  710.       case 50:    // on fait rien
  711.         break;
  712.       }  // switch 
  713.                               
  714.     }  // test du wizard sur l'url
  715.   }  // fin du test wizard..
  716.  
  717.   // -------------------- PHASE 5 --------------------
  718.  
  719.   // lien non autorisΘ, peut-on juste le tester?
  720.   if (just_test_it) {
  721.     if (forbidden_url==1) {
  722.       if (opt->travel&256) {    // tester tout de mΩme
  723.         
  724.         if (strfield(adr,"ftp://")==0) {    // PAS ftp!
  725.           forbidden_url=1;    // oui oui toujours interdit (note: sert α rien car ==1 mais c pour comprendre)
  726.           *just_test_it=1;     // mais on teste
  727.           if ((opt->debug>1) && (opt->log!=NULL)) {
  728.             fspc(opt->log,"debug"); fprintf(opt->log,"Testing link %s%s"LF,adr,fil);
  729.           }
  730.         }
  731.       }
  732.     }
  733.     //adr[0]='\0';  // cancel
  734.   }
  735.   
  736.   // -------------------- PHASE 6 --------------------
  737. #if HTS_ANALYSTE==2
  738.   {
  739.     int test_url=hts_htmlcheck_check(adr,fil,forbidden_url);
  740.     if (test_url!=-1)
  741.       forbidden_url=test_url;
  742.   }
  743. #endif  
  744.   return forbidden_url;
  745. }
  746.  
  747. // tester taille
  748. int hts_testlinksize(httrackp* opt,
  749.                      char* adr,char* fil,
  750.                      LLint size) {
  751.   int jok=0;
  752.   if (size>=0) {
  753.     char l[HTS_URLMAXSIZE*2];
  754.     if (size>=0) {
  755.       LLint sz=size;
  756.       int size_flag=0;
  757.       
  758.       // former URL complΦte du lien actuel
  759.       strcpy(l,jump_identification(adr));
  760.       if (*fil!='/') strcat(l,"/");
  761.       strcat(l,fil);
  762.       
  763.       // tester filtres (taille)
  764.       jok = fa_strjoker(opt->filters.filters,*opt->filters.filptr,l,&sz,&size_flag);
  765.       
  766.       // log
  767.       if (jok==1) {
  768.         if ((opt->debug>1) && (opt->log!=NULL)) {
  769.           fspc(opt->log,"debug"); fprintf(opt->log,"File confirmed (size test): %s%s ("LLintP")"LF,adr,fil,(LLint)(size));
  770.         }
  771.       } else if (jok==-1) {
  772.         if (size_flag) {        /* interdit α cause de la taille */
  773.           if ((opt->debug>1) && (opt->log!=NULL)) {
  774.             fspc(opt->log,"debug"); fprintf(opt->log,"File cancelled due to its size: %s%s ("LLintP", limit: "LLintP")"LF,adr,fil,(LLint)(size),(LLint)(sz));
  775.           }
  776.         } else {
  777.           jok=1;
  778.         }
  779.       }
  780.     }
  781.   }
  782.   return jok;
  783. }
  784.  
  785.  
  786.  
  787. #undef test_flush
  788. #undef urladr
  789. #undef urlfil
  790. #undef level
  791. #undef new_stat_bytes
  792.  
  793. #undef HT_INSERT_FILTERS0
  794.  
  795.