home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 71 / CDROM71.ISO / internet / navoff / data1.cab / Sources / src / htsrobots.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-04-01  |  3.6 KB  |  122 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. /*       robots.txt (website robot file)                        */
  39. /* Author: Xavier Roche                                         */
  40. /* ------------------------------------------------------------ */
  41.  
  42.  
  43. #include "htsrobots.h"
  44.  
  45. /* specific definitions */
  46. #include "htsbase.h"
  47. #include "htslib.h"
  48. #include <stdio.h>
  49. #include <stdlib.h>
  50. /* END specific definitions */
  51.  
  52.  
  53. // -- robots --
  54.  
  55. // fil="" : vΘrifier si rΦgle dΘja enregistrΘe
  56. int checkrobots(robots_wizard* robots,char* adr,char* fil) {
  57.   while(robots) {
  58.     if (strfield2(robots->adr,adr)) {
  59.       if (fil[0]) {
  60.         int ptr=0;
  61.         char line[250];
  62.         if (strnotempty(robots->token)) {
  63.           do {
  64.             ptr+=binput(robots->token+ptr,line,200);
  65.             if (line[0]=='/') {    // absolu
  66.               if (strfield(fil,line)) {                 // commence avec ligne
  67.                 return -1;        // interdit
  68.               }
  69.             } else {    // relatif
  70.               if (strstrcase(fil,line)) {
  71.                 return -1;
  72.               }
  73.             }
  74.           } while( (strnotempty(line)) && (ptr<(int) strlen(robots->token)) );
  75.         }
  76.       } else {
  77.         return -1;
  78.       }
  79.     }
  80.     robots=robots->next;
  81.   }
  82.   return 0;
  83. }
  84. int checkrobots_set(robots_wizard* robots,char* adr,char* data) {
  85.   if (((int) strlen(data)) > 999) return 0;
  86.   while(robots) {
  87.     if (strfield2(robots->adr,adr)) {    // entrΘe existe
  88.       strcpy(robots->token,data);
  89. #if DEBUG_ROBOTS
  90.         printf("robots.txt: set %s to %s\n",adr,data);
  91. #endif
  92.       return -1;
  93.     }
  94.     else if (!robots->next) {
  95.       robots->next=(robots_wizard*) calloc(1,sizeof(robots_wizard));
  96.       if (robots->next) {
  97.         robots->next->next=NULL;
  98.         strcpy(robots->next->adr,adr);
  99.         strcpy(robots->next->token,data);
  100. #if DEBUG_ROBOTS
  101.         printf("robots.txt: new set %s to %s\n",adr,data);
  102. #endif
  103.       }
  104. #if DEBUG_ROBOTS
  105.       else
  106.         printf("malloc error!!\n");
  107. #endif
  108.     }
  109.     robots=robots->next;
  110.   }
  111.   return 0;
  112. }
  113. void checkrobots_free(robots_wizard* robots) {
  114.   if (robots->next) {
  115.     checkrobots_free(robots->next);
  116.     freet(robots->next);
  117.     robots->next=NULL;
  118.   }
  119. }
  120.  
  121. // -- robots --
  122.