Пример #1
0
/*	Convert file URLs into a local representation
**	---------------------------------------------
**	The URL has already been translated through the rules in get_physical
**	in HTAccess.c and all we need to do now is to map the path to a local
**	representation, for example if must translate '/' to the ones that
**	turn the wrong way ;-)
**	Returns:
**		OK:	local file (that must be freed by caller)
**		Error:	NULL
*/
PUBLIC char * HTWWWToLocal (const char * url, const char * base,
                            HTUserProfile * up)
{
    if (url) {
        char * access = HTParse(url, base, PARSE_ACCESS);
        char * host = HTParse(url, base, PARSE_HOST);
        char * path = HTParse(url, base, PARSE_PATH+PARSE_PUNCTUATION);
        const char * myhost = HTUserProfile_fqdn(up);

        /* Find out if this is a reference to the local file system */
        if ((*access && strcmp(access, "file") && strcmp(access, "cache")) ||
                (*host && strcasecomp(host, "localhost") &&
                 myhost && strcmp(host, myhost))) {
            HTTRACE(CORE_TRACE, "LocalName... Not on local file system\n");
            HT_FREE(access);
            HT_FREE(host);
            HT_FREE(path);
            return NULL;
        } else {
            char *ptr;
            if ((ptr = strchr(path, ';')) || (ptr = strchr(path, '?')))
                *ptr = '\0';

            /*
            ** Do whatever translation is required here in order to fit your
            ** platform _before_ the path is unescaped.
            */
#ifdef VMS
            HTVMS_checkDecnet(path);
#endif
#ifdef WWW_MSWINDOWS
            /* An absolute pathname with logical drive */
            if (*path == '/' && path[2] == ':') {
                char *orig=path, *dest=path+1;
                while((*orig++ = *dest++));

                /* A network host */
            } else if (*host && strcasecomp(host, "localhost")) {
                char * newpath = NULL;
                StrAllocMCopy(&newpath, "//", host, path, NULL);
                HT_FREE(path);
                path = newpath;
            }

            /* Convert '/' to '\' */
            {
                char *p = path;
                while (*p) {
                    if (*p=='/') *p='\\';
                    p++;
                }
            }
#endif

            HTUnEscape(path);		  /* Take out the escaped characters */
            HTTRACE(CORE_TRACE, "Node........ `%s' means path `%s'\n" _ url _ path);
            HT_FREE(access);
            HT_FREE(host);
            return path;
        }
    }
    return NULL;
}
Пример #2
0
PUBLIC int HTStat ARGS2(
	char *, filename, 
	stat_t *, info)
{
   /* 
      the following stuff does not work in VMS with a normal stat...
      -->   /disk$user/duns/www if www is a directory
		is statted like: 	/disk$user/duns/www.dir 
		after a normal stat has failed
      -->   /disk$user/duns	if duns is a toplevel directory
		is statted like:	/disk$user/000000/duns.dir
      -->   /disk$user since disk$user is a device
		is statted like:	/disk$user/000000/000000.dir
      -->   /			
		searches all devices, no solution yet...
      -->   /vxcern!/disk$cr/wwwteam/login.com
		is not statted but granted with fake information...
   */
int Result;
int Len;
char *Ptr, *Ptr2;
char Name[256];

   /* try normal stat... */
   Result = stat(filename,info);
   if (Result == 0)
      return(Result);

   /* make local copy */
   strcpy(Name,filename);

   /* if filename contains a node specification (! or ::), we will try to access
      the file via DECNET, but we do not stat it..., just return success 
      with some fake information... */
   if (HTVMS_checkDecnet(Name))
   {
      /* set up fake info, only the one we use... */
      info->st_dev = NULL;
      info->st_ino[0] = 0;
      info->st_ino[1] = 0;
      info->st_ino[2] = 0;
      info->st_mode = S_IFREG | S_IREAD;	/* assume it is a regular Readable file */
      info->st_nlink = NULL;
      info->st_uid = 0;
      info->st_gid = 0;
      info->st_rdev = 0;
      info->st_size = 0;
      info->st_atime = time(NULL);
      info->st_mtime = time(NULL);
      info->st_ctime = time(NULL);

      return(0);
   }

   /* failed,so do device search in case root is requested */
   if (!strcmp(Name,"/"))
   {  /* root requested */
      return(-1);
   }
   
   /* failed so this might be a directory, add '.dir' */
   Len = strlen(Name);
   if (Name[Len-1] == '/')
      Name[Len-1] = '\0';
   
   /* fail in case of device */
   Ptr = strchr(Name+1,'/');
   if ((Ptr == NULL) && (Name[0] == '/'))
   {  /* device only... */
      strcat(Name,"/000000/000000");
   }
   
   if (Ptr != NULL)
   {  /* correct filename in case of toplevel dir */
      Ptr2 = strchr(Ptr+1,'/');
      if ((Ptr2 == NULL) && (Name[0] == '/'))
      {
         char End[256];
         strcpy(End,Ptr);
         *(Ptr+1) = '\0';
         strcat(Name,"000000");
         strcat(Name,End);
      }
   }

   /* try in case a file on toplevel directory or .DIR was alreadyt specified */
   Result = stat(Name,info);
   if (Result == 0)
      return(Result);

   /* add .DIR and try again */
   strcat(Name,".dir");
   Result = stat(Name,info);
   return(Result);
}