home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 71 / CDROM71.ISO / internet / navoff / data1.cab / Sources / src / htswizard.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-04-01  |  28.0 KB  |  808 lines

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