Diff for /libwww/Library/src/HTFile.c between versions 1.73.2.3 and 1.74

version 1.73.2.3, 1995/03/09 18:20:52 version 1.74, 1994/12/06 14:27:46
Line 24 Line 24
 **      target machine runs VMS?  **      target machine runs VMS?
 */  */
   
   /* System dependent stuff */
   #include "sysdep.h"
   
 /* Library Includes */  /* Library Includes */
 #include "tcp.h"  
 #include "HTUtils.h"  #include "HTUtils.h"
 #include "HTString.h"  
 #include "HTParse.h"  #include "HTParse.h"
 #include "HTTCP.h"  #include "HTTCP.h"
   #include "HTFTP.h"
 #include "HTAnchor.h"  #include "HTAnchor.h"
 #include "HTAtom.h"  #include "HTAtom.h"
 #include "HTWriter.h"  #include "HTWriter.h"
 #include "HTFWrite.h"  #include "HTFWriter.h"
 #include "HTInit.h"  #include "HTInit.h"
 #include "HTBTree.h"  #include "HTBTree.h"
 #include "HTFormat.h"  #include "HTFormat.h"
Line 42 Line 44
 #include "HTFile.h"             /* Implemented here */  #include "HTFile.h"             /* Implemented here */
   
 #ifdef VMS  #ifdef VMS
 #include "HTVMSUtils.h"  
 PRIVATE char * suffix_separators = "._";  PRIVATE char * suffix_separators = "._";
 #else  #else
 PRIVATE char * suffix_separators = ".,_";  PRIVATE char * suffix_separators = ".,_";
Line 238  PUBLIC HTContentDescription * HTGetConte Line 239  PUBLIC HTContentDescription * HTGetConte
         HTSuffix * suff;          HTSuffix * suff;
         BOOL found = NO;          BOOL found = NO;
   
         if (PROT_TRACE)          CTRACE(stderr, "Searching... for suffix %d: \"%s\"\n", i, actual[i]);
             fprintf(TDEST, "Searching... for suffix %d: \"%s\"\n",i,actual[i]);  
   
         while ((suff = (HTSuffix*)HTList_nextObject(cur))) {          while ((suff = (HTSuffix*)HTList_nextObject(cur))) {
             if ((HTSuffixCaseSense && !strcmp(suff->suffix, actual[i])) ||              if ((HTSuffixCaseSense && !strcmp(suff->suffix, actual[i])) ||
Line 346  PUBLIC char * HTLocalName ARGS1(CONST ch Line 346  PUBLIC char * HTLocalName ARGS1(CONST ch
         HTVMS_checkDecnet(path);          HTVMS_checkDecnet(path);
 #endif /* VMS */  #endif /* VMS */
   
         if (PROT_TRACE)          CTRACE(stderr, "Local filename is \"%s\"\n", path);
             fprintf(TDEST, "Local filename is \"%s\"\n", path);  
         return(path);          return(path);
     }      }
   
Line 361  PUBLIC char * HTLocalName ARGS1(CONST ch Line 360  PUBLIC char * HTLocalName ARGS1(CONST ch
         HTVMS_checkDecnet(path);          HTVMS_checkDecnet(path);
 #endif /* VMS */  #endif /* VMS */
   
             if (TRACE)              if (TRACE) fprintf(stderr, "Node........ `%s' means path `%s'\n", name, path);
                 fprintf(TDEST, "Node........ `%s' means path `%s'\n",name,path);  
             return(path);              return(path);
         } else {          } else {
             char * result = (char *)malloc(              char * result = (char *)malloc(
Line 371  PUBLIC char * HTLocalName ARGS1(CONST ch Line 369  PUBLIC char * HTLocalName ARGS1(CONST ch
             sprintf(result, "%s%s%s", "/Net/", host, path);              sprintf(result, "%s%s%s", "/Net/", host, path);
             free(host);              free(host);
             free(path);              free(path);
             if (TRACE) fprintf(TDEST, "Node........ `%s' means file `%s'\n", name, result);              if (TRACE) fprintf(stderr, "Node........ `%s' means file `%s'\n", name, result);
             return result;              return result;
         }          }
     } else {  /* other access */      } else {  /* other access */
Line 424  PUBLIC char * WWW_nameOfFile ARGS1 (CONS Line 422  PUBLIC char * WWW_nameOfFile ARGS1 (CONS
         if (result == NULL) outofmem(__FILE__, "WWW_nameOfFile");          if (result == NULL) outofmem(__FILE__, "WWW_nameOfFile");
         sprintf(result, "file://%s%s", HTGetHostName(), name);          sprintf(result, "file://%s%s", HTGetHostName(), name);
     }      }
     if (TRACE) fprintf(TDEST, "File `%s'\n\tmeans node `%s'\n", name, result);      if (TRACE) fprintf(stderr, "File `%s'\n\tmeans node `%s'\n", name, result);
     return result;      return result;
 }  }
   
Line 527  PUBLIC float HTFileValue ARGS1 (CONST ch Line 525  PUBLIC float HTFileValue ARGS1 (CONST ch
     while ((suff = (HTSuffix*)HTList_nextObject(cur))) {      while ((suff = (HTSuffix*)HTList_nextObject(cur))) {
         int ls = strlen(suff->suffix);          int ls = strlen(suff->suffix);
         if ((ls <= lf) && 0==strcmp(suff->suffix, filename + lf - ls)) {          if ((ls <= lf) && 0==strcmp(suff->suffix, filename + lf - ls)) {
             if (TRACE) fprintf(TDEST, "File Value.. Value of %s is %.3f\n",              if (TRACE) fprintf(stderr, "File Value.. Value of %s is %.3f\n",
                                filename, suff->quality);                                 filename, suff->quality);
             return suff->quality;               /* OK -- found */              return suff->quality;               /* OK -- found */
         }          }
Line 546  PUBLIC float HTFileValue ARGS1 (CONST ch Line 544  PUBLIC float HTFileValue ARGS1 (CONST ch
 **      1.      No code for non-unix systems.  **      1.      No code for non-unix systems.
 **      2.      Isn't there a quicker way?  **      2.      Isn't there a quicker way?
 */  */
 #ifndef NO_UNIX_IO  
 PUBLIC BOOL HTEditable ARGS1 (CONST char *,filename)  PUBLIC BOOL HTEditable ARGS1 (CONST char *,filename)
 {  {
 #ifdef NO_GROUPS  #ifndef HAVE_GRP_H
     return NO;          /* Safe answer till we find the correct algorithm */      return NO;          /* Safe answer till we find the correct algorithm */
 #else  #else
 #ifdef NeXT      GETGROUPS_T groups[NGROUPS];
     int         groups[NGROUPS];  
 #else  
     gid_t       groups[NGROUPS];  
 #endif    
     uid_t       myUid;      uid_t       myUid;
     int         ngroups;                        /* The number of groups  */      int         ngroups;                        /* The number of groups  */
     struct stat fileStatus;      struct stat fileStatus;
Line 570  PUBLIC BOOL HTEditable ARGS1 (CONST char Line 563  PUBLIC BOOL HTEditable ARGS1 (CONST char
   
     if (TRACE) {      if (TRACE) {
         int i;          int i;
         fprintf(TDEST,           fprintf(stderr, 
             "File mode is 0%o, uid=%d, gid=%d. My uid=%d, %d groups (",              "File mode is 0%o, uid=%d, gid=%d. My uid=%d, %d groups (",
             (unsigned int) fileStatus.st_mode, (int) fileStatus.st_uid,              (unsigned int) fileStatus.st_mode, (int) fileStatus.st_uid,
             (int) fileStatus.st_gid, (int) myUid, ngroups);              (int) fileStatus.st_gid, (int) myUid, ngroups);
         for (i=0; i<ngroups; i++) fprintf(TDEST, " %d", (int) groups[i]);          for (i=0; i<ngroups; i++) fprintf(stderr, " %d", (int) groups[i]);
         fprintf(TDEST, ")\n");          fprintf(stderr, ")\n");
     }      }
           
     if (fileStatus.st_mode & 0002)              /* I can write anyway? */      if (fileStatus.st_mode & 0002)              /* I can write anyway? */
Line 592  PUBLIC BOOL HTEditable ARGS1 (CONST char Line 585  PUBLIC BOOL HTEditable ARGS1 (CONST char
                 return YES;                  return YES;
         }          }
     }      }
     if (TRACE) fprintf(TDEST, "\tFile is not editable.\n");      if (TRACE) fprintf(stderr, "\tFile is not editable.\n");
     return NO;                                  /* If no excuse, can't do */      return NO;                                  /* If no excuse, can't do */
 #endif  #endif
 }  }
 #endif /* NO_UNIX_IO */  
   
 /*      Make a save stream  /*      Make a save stream
 **      ------------------  **      ------------------
Line 635  PUBLIC HTStream * HTFileSaveStream ARGS1 Line 627  PUBLIC HTStream * HTFileSaveStream ARGS1
         if ((fp=fopen(filename, "r"))) {                /* File exists */          if ((fp=fopen(filename, "r"))) {                /* File exists */
 #endif /* not VMS */  #endif /* not VMS */
             fclose(fp);              fclose(fp);
             if (TRACE) fprintf(TDEST, "File `%s' exists\n", filename);              if (TRACE) fprintf(stderr, "File `%s' exists\n", filename);
             if (remove(backup_filename)) {              if (remove(backup_filename)) {
                 if (TRACE) fprintf(TDEST, "Backup file `%s' removed\n",                  if (TRACE) fprintf(stderr, "Backup file `%s' removed\n",
                                    backup_filename);                                     backup_filename);
             }              }
             if (rename(filename, backup_filename)) {    /* != 0 => Failure */              if (rename(filename, backup_filename)) {    /* != 0 => Failure */
                 if (TRACE) fprintf(TDEST, "Rename `%s' to `%s' FAILED!\n",                  if (TRACE) fprintf(stderr, "Rename `%s' to `%s' FAILED!\n",
                                    filename, backup_filename);                                     filename, backup_filename);
             } else {                                    /* Success */              } else {                                    /* Success */
                 if (TRACE) fprintf(TDEST, "Renamed `%s' to `%s'\n", filename,                  if (TRACE) fprintf(stderr, "Renamed `%s' to `%s'\n", filename,
                                    backup_filename);                                     backup_filename);
             }              }
         }          }
Line 652  PUBLIC HTStream * HTFileSaveStream ARGS1 Line 644  PUBLIC HTStream * HTFileSaveStream ARGS1
     } /* if take backup */          } /* if take backup */    
           
     if ((fp = fopen(filename, "w")) == NULL) {      if ((fp = fopen(filename, "w")) == NULL) {
         HTErrorSysAdd(request, ERR_FATAL, errno, NO, "fopen");          HTErrorSysAdd(request, ERR_FATAL, NO, "fopen");
         return NULL;          return NULL;
     } else      } else
         return HTFWriter_new(fp, NO);          return HTFWriter_new(fp, NO);
Line 677  PUBLIC int HTLoadFile ARGS1 (HTRequest * Line 669  PUBLIC int HTLoadFile ARGS1 (HTRequest *
     char *url;      char *url;
   
     if (!request || !request->anchor) {      if (!request || !request->anchor) {
         if (TRACE) fprintf(TDEST, "HTLoadFile.. Called with bad argument\n");          if (TRACE) fprintf(stderr, "HTLoadFile.. Called with bad argument\n");
         return HT_INTERNAL;          return HT_INTERNAL;
     }      }
     url = HTAnchor_physical(request->anchor);      url = HTAnchor_physical(request->anchor);
     if (TRACE) fprintf(TDEST, "LoadFile.... Looking for `%s\'\n", url);      if (TRACE) fprintf(stderr, "LoadFile.... Looking for `%s\'\n", url);
   
   
 /*      For unix, we try to translate the name into the name of a transparently  /*      For unix, we try to translate the name into the name of a transparently
Line 689  PUBLIC int HTLoadFile ARGS1 (HTRequest * Line 681  PUBLIC int HTLoadFile ARGS1 (HTRequest *
 **  **
 **      Not allowed in secure (HTClientHost) situations TBL 921019  **      Not allowed in secure (HTClientHost) situations TBL 921019
 */  */
 #ifndef NO_UNIX_IO  
     /*  Need protection here for telnet server but not httpd server */      /*  Need protection here for telnet server but not httpd server */
                     
     if (!HTSecure) {      if (!HTSecure) {
         char * localname = HTLocalName(url);               /* Does unescape! */          char * localname = HTLocalName(url);               /* Does unescape! */
         struct stat stat_info;          struct stat stat_info;
         char * multi;          char * multi;
         request->content_type = HTFileFormat(localname,          HTFormat format = HTFileFormat(localname, &request->content_encoding,
                                              &request->content_encoding,                                         &request->content_language);
                                              &request->content_language);          if (TRACE) fprintf(stderr, "HTLoadFile.. Accessing local file system.\n");
         if (TRACE) fprintf(TDEST, "HTLoadFile.. Accessing local file system.\n");  
   
 #ifdef GOT_READ_DIR  #ifdef HAVE_OPENDIR
   
 /*      Multiformat handling. If suffix matches MULTI_SUFFIX then scan  /*      Multiformat handling. If suffix matches MULTI_SUFFIX then scan
 **      directory to find a good file.  **      directory to find a good file.
Line 730  PUBLIC int HTLoadFile ARGS1 (HTRequest * Line 720  PUBLIC int HTLoadFile ARGS1 (HTRequest *
 */  */
         if (HTStat(localname, &stat_info) == -1) {          if (HTStat(localname, &stat_info) == -1) {
             if (TRACE)              if (TRACE)
                 fprintf(TDEST, "HTLoadFile.. Can't stat %s\n", localname);                  fprintf(stderr, "HTLoadFile.. Can't stat %s\n", localname);
         } else {          } else {
             if (((stat_info.st_mode) & S_IFMT) == S_IFDIR) {              if (((stat_info.st_mode) & S_IFMT) == S_IFDIR) {
                 status = HTBrowseDirectory(request, localname);                  status = HTBrowseDirectory(request, localname);
Line 739  PUBLIC int HTLoadFile ARGS1 (HTRequest * Line 729  PUBLIC int HTLoadFile ARGS1 (HTRequest *
             }              }
         }          }
   
 #endif /* GOT_READ_DIR */  #endif /* HAVE_OPENDIR */
   
 open_file:  open_file:
         {          {
Line 750  open_file: Line 740  open_file:
 #endif /* not VMS */  #endif /* not VMS */
   
             if (fp) {              if (fp) {
                 if(TRACE) fprintf(TDEST, "HTLoadFile.. Opened `%s' on local file system\n", localname);                  if(TRACE) fprintf (stderr, "HTLoadFile.. Opened `%s' on local file system\n", localname);
                 if (HTEditable(localname)) {                  if (HTEditable(localname)) {
                     HTAtom * put = HTAtom_for("PUT");                      HTAtom * put = HTAtom_for("PUT");
                     HTList * methods = HTAnchor_methods(request->anchor);                      HTList * methods = HTAnchor_methods(request->anchor);
Line 758  open_file: Line 748  open_file:
                         HTList_addObject(methods, put);                          HTList_addObject(methods, put);
                     }                      }
                 }                  }
                 status = HTParseFile(request->content_type, fp, request);                  status = HTParseFile(format, fp, request);
                 fclose(fp);                  fclose(fp);
   
                 FREE(localname);                  FREE(localname);
                 goto cleanup;                  goto cleanup;
             } else              } else
                 HTErrorSysAdd(request, ERR_FATAL, errno, NO, "fopen");                  HTErrorSysAdd(request, ERR_FATAL, NO, "fopen");
         }          }
         FREE(localname);          FREE(localname);
     } /* End of local file system */      } /* End of local file system */
 #endif /* NO_UNIX_IO */  
   
 #ifndef DECNET  #ifndef DECNET
     /* Now, as transparently mounted access has failed, we try FTP. */      /* Now, as transparently mounted access has failed, we try FTP. */
     {      {
         char *nodename = HTParse(url, "", PARSE_HOST);          char *nodename = HTParse(url, "", PARSE_HOST);
         CONST char *hostname = HTGetHostName();          if (nodename && *nodename && strcmp(nodename, HTGetHostName())!=0) {
         if (nodename && *nodename && hostname &&              char * newname = NULL;
             strcmp(nodename, hostname) && strcmp(nodename, "localhost")) {  
             HTAnchor *anchor;  
             char *newname = NULL;  
             char *unescaped = NULL;              char *unescaped = NULL;
             StrAllocCopy(unescaped, url);              StrAllocCopy(unescaped, url);
             HTUnEscape(unescaped);              HTUnEscape(unescaped);
             HTErrorAdd(request, ERR_WARN, NO, HTERR_FILE_TO_FTP,              HTErrorAdd(request, ERR_FATAL, NO, HTERR_FILE_TO_FTP,
                        (void *) unescaped,                         (void *) unescaped,
                        (int) strlen(unescaped), "HTLoadFile");                         (int) strlen(unescaped), "HTLoadFile");
             StrAllocCopy(newname, "ftp:");              StrAllocCopy(newname, "ftp:");
Line 790  open_file: Line 776  open_file:
                 StrAllocCat(newname, url+5);                  StrAllocCat(newname, url+5);
             else              else
                 StrAllocCat(newname, url);                  StrAllocCat(newname, url);
             anchor = HTAnchor_findAddress(newname);              HTAnchor_setPhysical(request->anchor, newname);
             free(newname);              free(newname);
             free(nodename);              free(nodename);
             free(unescaped);              free(unescaped);
             return HTLoadAnchorRecursive(anchor, request);              return HTLoad(request, YES);      /* Jump directly to FTP module */
         }          }
         free(nodename);          free(nodename);
     }      }
 #endif  #endif
   
   cleanup:    cleanup:
   #if 0
       if (status < 0 && status != HT_INTERRUPTED) {
           char *unescaped = NULL;
           StrAllocCopy(unescaped, url);
           HTUnEscape(unescaped);
           HTErrorAdd(request, ERR_FATAL, NO, HTERR_NOT_FOUND, (void *) unescaped,
                      (int) strlen(unescaped), "HTLoadFile");
           free(unescaped);
       }
   #endif
     return status;      return status;
 }  }
   
 /* Protocol descriptors */  /*              Protocol descriptors
   */
 GLOBALDEF PUBLIC HTProtocol HTFile = {  GLOBALDEF PUBLIC HTProtocol HTFile = {
     "file", SOC_BLOCK, HTLoadFile, HTFileSaveStream, NULL      "file", SOC_BLOCK, HTLoadFile, HTFileSaveStream, NULL
 };  };

Removed from v.1.73.2.3  
changed lines
  Added in v.1.74


Webmaster