home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 April / enter-2004-04.iso / files / httrack-3.30.exe / {app} / src / htsrobots.c < prev    next >
Encoding:
C/C++ Source or Header  |  2003-10-11  |  3.5 KB  |  120 lines

  1. /* ------------------------------------------------------------ */
  2. /*
  3. HTTrack Website Copier, Offline Browser for Windows and Unix
  4. Copyright (C) Xavier Roche 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. Please visit our Website: http://www.httrack.com
  29. */
  30.  
  31.  
  32. /* ------------------------------------------------------------ */
  33. /* File: httrack.c subroutines:                                 */
  34. /*       robots.txt (website robot file)                        */
  35. /* Author: Xavier Roche                                         */
  36. /* ------------------------------------------------------------ */
  37.  
  38.  
  39. #include "htsrobots.h"
  40.  
  41. /* specific definitions */
  42. #include "htsbase.h"
  43. #include "htslib.h"
  44. #include <stdio.h>
  45. #include <stdlib.h>
  46. #include <string.h>
  47. /* END specific definitions */
  48.  
  49.  
  50. // -- robots --
  51.  
  52. // fil="" : vΘrifier si rΦgle dΘja enregistrΘe
  53. int checkrobots(robots_wizard* robots,char* adr,char* fil) {
  54.   while(robots) {
  55.     if (strfield2(robots->adr,adr)) {
  56.       if (fil[0]) {
  57.         int ptr=0;
  58.         char line[250];
  59.         if (strnotempty(robots->token)) {
  60.           do {
  61.             ptr+=binput(robots->token+ptr,line,200);
  62.             if (line[0]=='/') {    // absolu
  63.               if (strfield(fil,line)) {                 // commence avec ligne
  64.                 return -1;        // interdit
  65.               }
  66.             } else {    // relatif
  67.               if (strstrcase(fil,line)) {
  68.                 return -1;
  69.               }
  70.             }
  71.           } while( (strnotempty(line)) && (ptr<(int) strlen(robots->token)) );
  72.         }
  73.       } else {
  74.         return -1;
  75.       }
  76.     }
  77.     robots=robots->next;
  78.   }
  79.   return 0;
  80. }
  81. int checkrobots_set(robots_wizard* robots,char* adr,char* data) {
  82.   if (((int) strlen(adr)) >= sizeof(robots->adr) - 2) return 0;
  83.   if (((int) strlen(data)) >= sizeof(robots->token) - 2) return 0;
  84.   while(robots) {
  85.     if (strfield2(robots->adr,adr)) {    // entrΘe existe
  86.       strcpybuff(robots->token,data);
  87. #if DEBUG_ROBOTS
  88.         printf("robots.txt: set %s to %s\n",adr,data);
  89. #endif
  90.       return -1;
  91.     }
  92.     else if (!robots->next) {
  93.       robots->next=(robots_wizard*) calloct(1,sizeof(robots_wizard));
  94.       if (robots->next) {
  95.         robots->next->next=NULL;
  96.         strcpybuff(robots->next->adr,adr);
  97.         strcpybuff(robots->next->token,data);
  98. #if DEBUG_ROBOTS
  99.         printf("robots.txt: new set %s to %s\n",adr,data);
  100. #endif
  101.       }
  102. #if DEBUG_ROBOTS
  103.       else
  104.         printf("malloc error!!\n");
  105. #endif
  106.     }
  107.     robots=robots->next;
  108.   }
  109.   return 0;
  110. }
  111. void checkrobots_free(robots_wizard* robots) {
  112.   if (robots->next) {
  113.     checkrobots_free(robots->next);
  114.     freet(robots->next);
  115.     robots->next=NULL;
  116.   }
  117. }
  118.  
  119. // -- robots --
  120.