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