Diff for /Amaya/amaya/AHTURLTools.c between versions 1.4 and 1.5

version 1.4, 1996/12/07 15:10:40 version 1.5, 1996/12/11 14:48:53
Line 12 Line 12
 #include "conststr.h"  #include "conststr.h"
 #include "AHTMemConv.h"  #include "AHTMemConv.h"
 #include "init.h"  #include "init.h"
 #include "AHTURLTools.h" /** defined here **/  #include "AHTURLTools.h"        /* defined here */
   
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
    IsHTMLName                                                              IsHTMLName                                                         
Line 26  char               *path; Line 26  char               *path;
   
 #endif /* __STDC__ */  #endif /* __STDC__ */
 {  {
   char                temppath[MAX_LENGTH];     char                temppath[MAX_LENGTH];
   char                suffix[MAX_LENGTH];     char                suffix[MAX_LENGTH];
   char                nsuffix[MAX_LENGTH];     char                nsuffix[MAX_LENGTH];
   int                 i;     int                 i;
   
   if (!path)     if (!path)
     return FALSE;        return FALSE;
   
   strcpy (temppath, path);     strcpy (temppath, path);
   ExtractSuffix (temppath, suffix);     ExtractSuffix (temppath, suffix);
   
   /* Normalize the suffix */     /* Normalize the suffix */
   i = 0;     i = 0;
   while (suffix[i] != EOS)     while (suffix[i] != EOS)
     nsuffix[i] = TOLOWER (suffix[i++]);        nsuffix[i] = TOLOWER (suffix[i++]);
   nsuffix[i] = EOS;     nsuffix[i] = EOS;
   if ((strcmp (nsuffix, "html")) &&     if ((strcmp (nsuffix, "html")) &&
       (strcmp (nsuffix, "htm")) &&         (strcmp (nsuffix, "htm")) &&
       (strcmp (nsuffix, "shtml")))         (strcmp (nsuffix, "shtml")))
     return FALSE;        return FALSE;
   return TRUE;     return TRUE;
 }  }
   
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
Line 61  char               *path; Line 61  char               *path;
   
 #endif /* __STDC__ */  #endif /* __STDC__ */
 {  {
   char                temppath[MAX_LENGTH];     char                temppath[MAX_LENGTH];
   char                suffix[MAX_LENGTH];     char                suffix[MAX_LENGTH];
   char                nsuffix[MAX_LENGTH];     char                nsuffix[MAX_LENGTH];
   int                 i;     int                 i;
   
   if (!path)     if (!path)
     return FALSE;        return FALSE;
   
   strcpy (temppath, path);     strcpy (temppath, path);
   ExtractSuffix (temppath, suffix);     ExtractSuffix (temppath, suffix);
   
   /* Normalize the suffix */     /* Normalize the suffix */
   i = 0;     i = 0;
   while (suffix[i] != EOS)     while (suffix[i] != EOS)
     nsuffix[i] = TOLOWER (suffix[i++]);        nsuffix[i] = TOLOWER (suffix[i++]);
   nsuffix[i] = EOS;     nsuffix[i] = EOS;
   if ((strcmp (nsuffix, "gif")) && (strcmp (nsuffix, "xbm")) &&     if ((strcmp (nsuffix, "gif")) && (strcmp (nsuffix, "xbm")) &&
       (strcmp (nsuffix, "xpm")) && (strcmp (nsuffix, "jpg")) &&         (strcmp (nsuffix, "xpm")) && (strcmp (nsuffix, "jpg")) &&
       (strcmp (nsuffix, "png")) && (strcmp (nsuffix, "au")))         (strcmp (nsuffix, "png")) && (strcmp (nsuffix, "au")))
     return FALSE;        return FALSE;
   return TRUE;     return TRUE;
 }  }
   
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
Line 96  char               *path; Line 96  char               *path;
   
 #endif /* __STDC__ */  #endif /* __STDC__ */
 {  {
   char                temppath[MAX_LENGTH];     char                temppath[MAX_LENGTH];
   char                suffix[MAX_LENGTH];     char                suffix[MAX_LENGTH];
   char                nsuffix[MAX_LENGTH];     char                nsuffix[MAX_LENGTH];
   int                 i;     int                 i;
   
   if (!path)     if (!path)
     return FALSE;        return FALSE;
   
   strcpy (temppath, path);     strcpy (temppath, path);
   ExtractSuffix (temppath, suffix);     ExtractSuffix (temppath, suffix);
   
   /* Normalize the suffix */     /* Normalize the suffix */
   i = 0;     i = 0;
   while (suffix[i] != EOS)     while (suffix[i] != EOS)
     {       {
       nsuffix[i] = TOLOWER (suffix[i]);          nsuffix[i] = TOLOWER (suffix[i]);
       i++;          i++;
     }       }
   nsuffix[i] = EOS;     nsuffix[i] = EOS;
   
   if ((strcmp (nsuffix, "gif")) && (strcmp (nsuffix, "xbm")) &&     if ((strcmp (nsuffix, "gif")) && (strcmp (nsuffix, "xbm")) &&
       (strcmp (nsuffix, "xpm")) && (strcmp (nsuffix, "jpg")) &&         (strcmp (nsuffix, "xpm")) && (strcmp (nsuffix, "jpg")) &&
       (strcmp (nsuffix, "pdf")) && (strcmp (nsuffix, "png")) &&         (strcmp (nsuffix, "pdf")) && (strcmp (nsuffix, "png")) &&
       (strcmp (nsuffix, "Z")) && (strcmp (nsuffix, "gz")) &&         (strcmp (nsuffix, "Z")) && (strcmp (nsuffix, "gz")) &&
       (strcmp (nsuffix, "tgz")) && (strcmp (nsuffix, "xpg")) &&         (strcmp (nsuffix, "tgz")) && (strcmp (nsuffix, "xpg")) &&
       (strcmp (nsuffix, "xpd")) && (strcmp (nsuffix, "ps")) &&         (strcmp (nsuffix, "xpd")) && (strcmp (nsuffix, "ps")) &&
       (strcmp (nsuffix, "au")))         (strcmp (nsuffix, "au")))
     return TRUE;        return TRUE;
   return FALSE;     return FALSE;
 }  }
   
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
Line 139  char               *path; Line 139  char               *path;
   
 #endif /* __STDC__ */  #endif /* __STDC__ */
 {  {
   if (!path)     if (!path)
     return FALSE;        return FALSE;
   
   if (strncmp (path, "http:", 5) != 0)     if (strncmp (path, "http:", 5) != 0)
     return FALSE;        return FALSE;
   return TRUE;     return TRUE;
 }  }
   
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
Line 159  char               *path; Line 159  char               *path;
   
 #endif /* __STDC__ */  #endif /* __STDC__ */
 {  {
   int                 i;     int                 i;
   
   if ((!path) || (path[0] == EOS))  
     return FALSE;  
   
   i = strlen (path) - 1;     if ((!path) || (path[0] == EOS))
   while (i > 0 && path[i--] != '?')  
     if (i < 0)  
       return FALSE;        return FALSE;
   
   /* There is a parameter */     i = strlen (path) - 1;
   return TRUE;     while (i > 0 && path[i--] != '?')
         if (i < 0)
            return FALSE;
   
      /* There is a parameter */
      return TRUE;
 }  }
   
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
Line 185  char               *path; Line 185  char               *path;
   
 #endif /* __STDC__ */  #endif /* __STDC__ */
 {  {
   if ((strncmp (path, "http:", 5)) && (strncmp (path, "ftp:", 4)) &&     if ((strncmp (path, "http:", 5)) && (strncmp (path, "ftp:", 4)) &&
       (strncmp (path, "telnet:", 7)) && (strncmp (path, "wais:", 5)) &&         (strncmp (path, "telnet:", 7)) && (strncmp (path, "wais:", 5)) &&
       (strncmp (path, "news:", 5)) && (strncmp (path, "gopher:", 7)) &&         (strncmp (path, "news:", 5)) && (strncmp (path, "gopher:", 7)) &&
       (strncmp (path, "mailto:", 7)) && (strncmp (path, "archie:", 7)))         (strncmp (path, "mailto:", 7)) && (strncmp (path, "archie:", 7)))
     return FALSE;        return FALSE;
   return TRUE;     return TRUE;
 }  }
   
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
Line 205  char               *path; Line 205  char               *path;
   
 #endif /* __STDC__ */  #endif /* __STDC__ */
 {  {
   if (!strncmp (path, "http:", 5)     if (!strncmp (path, "http:", 5)
       /***|| !strncmp (path, "ftp:", 4)        /***|| !strncmp (path, "ftp:", 4)
       || !strncmp (path, "news:", 5)***/)        || !strncmp (path, "news:", 5)***/ )
     return (YES);        return (YES);
   else     else
     return (NO);        return (NO);
 }  }
   
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
Line 225  char               *path; Line 225  char               *path;
   
 #endif /* __STDC__ */  #endif /* __STDC__ */
 {  {
  if (strchr(path,':') && !strncmp (path, "http:", 5))     if (strchr (path, ':') && !strncmp (path, "http:", 5))
    return (YES);        return (YES);
  else     else
    return (NO);        return (NO);
 }  }
   
   
Line 253  char               *docName; Line 253  char               *docName;
   
 #endif /* __STDC__ */  #endif /* __STDC__ */
 {  {
   char                basename[MAX_LENGTH];     char                basename[MAX_LENGTH];
   char                tempname[MAX_LENGTH];     char                tempname[MAX_LENGTH];
   int                 i;     int                 i;
   char               *ptr;     char               *ptr;
   char               *basename_ptr;     char               *basename_ptr;
   int                 basename_flag;     int                 basename_flag;
   Element             el;     Element             el;
   ElementType         elType;     ElementType         elType;
   AttributeType       attrType;     AttributeType       attrType;
   Attribute           attrHREF;     Attribute           attrHREF;
   int                 length;     int                 length;
   
   /* Fix up orgName, by erasing leading and trailing white space */     /* Fix up orgName, by erasing leading and trailing white space */
   if (!newName || !docName)     if (!newName || !docName)
     return;        return;
   ptr = orgName;     ptr = orgName;
   while (*ptr == ' ' && *ptr++ != EOS) ;     while (*ptr == ' ' && *ptr++ != EOS) ;
   strcpy (tempname, ptr);     strcpy (tempname, ptr);
   ptr = strchr (tempname, ' ');     ptr = strchr (tempname, ' ');
   if (ptr)     if (ptr)
     *ptr = EOS;        *ptr = EOS;
   
   /*      /* 
   ** the following block to take into account the BASE element.        ** the following block to take into account the BASE element.
   ** This is not very optimized, as this procedure is repeated for        ** This is not very optimized, as this procedure is repeated for
   ** each element which is retrieved. A better way would be to        ** each element which is retrieved. A better way would be to
   ** move this higher up in the function call hierarchy.        ** move this higher up in the function call hierarchy.
   */      */
   if (IsValidNormalizeURL (tempname) && doc)     if (IsValidNormalizeURL (tempname) && doc)
     {       {
       length = MAX_LENGTH;          length = MAX_LENGTH;
       /* get the root element    */          /* get the root element    */
       el = TtaGetMainRoot (doc);          el = TtaGetMainRoot (doc);
   
       /* search the BASE element */          /* search the BASE element */
       elType.ElSSchema = TtaGetDocumentSSchema (doc);          elType.ElSSchema = TtaGetDocumentSSchema (doc);
       elType.ElTypeNum = HTML_EL_BASE;          elType.ElTypeNum = HTML_EL_BASE;
       el = TtaSearchTypedElement (elType, SearchInTree, el);          el = TtaSearchTypedElement (elType, SearchInTree, el);
       if (el)          if (el)
         {            {
           /*                /* 
           ** The document has a BASE element                   ** The document has a BASE element 
           ** Get the HREF attribute of the BASE Element                   ** Get the HREF attribute of the BASE Element 
           */  
           attrType.AttrSSchema = elType.ElSSchema;  
           attrType.AttrTypeNum = HTML_ATTR_HREF_;  
           attrHREF = TtaGetAttribute (el, attrType);  
           if (attrHREF)  
             {  
               /*   
               ** Use the base path of the document   
               ** To do: verify length of the buffer  
               ** length > TtaGetTextAttributeLength (attrHREF) + strlen (orgName)   
               */                */
               TtaGiveTextAttributeValue (attrHREF, basename, &length);               attrType.AttrSSchema = elType.ElSSchema;
                attrType.AttrTypeNum = HTML_ATTR_HREF_;
               /*                attrHREF = TtaGetAttribute (el, attrType);
               ** base and orgName have to be separated by a DIR_SEP                if (attrHREF)
               */                 {
               if (basename[strlen (basename) - 1] != DIR_SEP && tempname[0] != DIR_SEP)                    /* 
                 strcat (basename, DIR_STR);                       ** Use the base path of the document 
             }                       ** To do: verify length of the buffer
         }                       ** length > TtaGetTextAttributeLength (attrHREF) + strlen (orgName) 
       else                     */
         basename[0] = EOS;                    TtaGiveTextAttributeValue (attrHREF, basename, &length);
     }  
   else                    /* 
     basename[0] = EOS;                       ** base and orgName have to be separated by a DIR_SEP 
                      */
   if (basename[0] == EOS)                    if (basename[strlen (basename) - 1] != DIR_SEP && tempname[0] != DIR_SEP)
     {                       strcat (basename, DIR_STR);
       /*                  }
       ** There is no BASE element in that document.            }
       ** A temporary fix as TtaExtractName does not tolerate a name          else
       ** ending in /. Here, we reinsert the slash, in order to             basename[0] = EOS;
       ** parse the name in the following two lines. A bit       }
       ** redundant and has to be reviewed.       else
       */        basename[0] = EOS;
       if (DocumentURLs[(int) doc])  
         {     if (basename[0] == EOS)
           basename_ptr = HTParse (DocumentURLs[(int) doc], "", PARSE_ALL);       {
           basename_flag = TRUE;          /* 
         }             ** There is no BASE element in that document.
       else             ** A temporary fix as TtaExtractName does not tolerate a name
         {             ** ending in /. Here, we reinsert the slash, in order to
           basename_ptr = "";             ** parse the name in the following two lines. A bit
           basename_flag = FALSE;             ** redundant and has to be reviewed.  
         }           */
     }          if (DocumentURLs[(int) doc])
   else            {
     {               basename_ptr = HTParse (DocumentURLs[(int) doc], "", PARSE_ALL);
       basename_ptr = HTParse (basename, "", PARSE_ALL);               basename_flag = TRUE;
       basename_flag = TRUE;            }
     }                           /* if-else tempname */          else
             {
   ptr = HTParse (tempname, basename_ptr, PARSE_ALL);               basename_ptr = "";
   if (basename_flag)               basename_flag = FALSE;
     HT_FREE (basename_ptr);            }
   if (ptr)       }
     {     else
       ptr = HTSimplify (&ptr);       {
       strcpy (newName, ptr);          basename_ptr = HTParse (basename, "", PARSE_ALL);
       HT_FREE (ptr);          basename_flag = TRUE;
     }       }                          /* if-else tempname */
   else  
     newName[0] = EOS;     ptr = HTParse (tempname, basename_ptr, PARSE_ALL);
      if (basename_flag)
   i = strlen (newName) - 1;        HT_FREE (basename_ptr);
   if (i > 0)     if (ptr)
     {       {
       /*           ptr = HTSimplify (&ptr);
       ** A temporary fix for an interfacing problem:          strcpy (newName, ptr);
       ** TtaExtractName does not tolerate url's finished on DIR_SEP          HT_FREE (ptr);
       */       }
       ptr = strrchr (newName, DIR_SEP);     else
       if (ptr)        newName[0] = EOS;
         ptr++;  
       if (ptr && *ptr != EOS)     i = strlen (newName) - 1;
         strcpy (docName, ptr);     if (i > 0)
       else                             {
         /*          /* 
         ** The docname was not comprised inside the URL, so let's              ** A temporary fix for an interfacing problem:
         ** assign a "noname.html" name :)             ** TtaExtractName does not tolerate url's finished on DIR_SEP
         */           */
         strcpy (docName, "noname.html");          ptr = strrchr (newName, DIR_SEP);
           if (ptr)
       /*              ptr++;
       ** A temporary fix for an interfacing problem:          if (ptr && *ptr != EOS)
       ** TtaExtractName does not tolerate url's finished on DIR_SEP             strcpy (docName, ptr);
       */          else
       if (newName[i] == DIR_SEP)             /*
         newName[i] = EOS;                ** The docname was not comprised inside the URL, so let's 
     }                ** assign a "noname.html" name :)
               */
              strcpy (docName, "noname.html");
   
           /* 
              ** A temporary fix for an interfacing problem:
              ** TtaExtractName does not tolerate url's finished on DIR_SEP
            */
           if (newName[i] == DIR_SEP)
              newName[i] = EOS;
        }
 }  }
   
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
Line 400  char               *path; Line 400  char               *path;
   
 #endif /* __STDC__ */  #endif /* __STDC__ */
 {  {
  char *basename_ptr1, *basename_ptr2;     char               *basename_ptr1, *basename_ptr2;
  boolean result;     boolean             result;
   
  basename_ptr1 = HTParse(url1, "", PARSE_ACCESS | PARSE_HOST | PARSE_PUNCTUATION);     basename_ptr1 = HTParse (url1, "", PARSE_ACCESS | PARSE_HOST | PARSE_PUNCTUATION);
  basename_ptr2 = HTParse(url2, "", PARSE_ACCESS | PARSE_HOST | PARSE_PUNCTUATION);     basename_ptr2 = HTParse (url2, "", PARSE_ACCESS | PARSE_HOST | PARSE_PUNCTUATION);
   
  if (strcmp (basename_ptr1, basename_ptr2))     if (strcmp (basename_ptr1, basename_ptr2))
    result = NO;        result = NO;
  else     else
    result = YES;        result = YES;
   
  HT_FREE(basename_ptr1);     HT_FREE (basename_ptr1);
  HT_FREE(basename_ptr2);     HT_FREE (basename_ptr2);
   
  return(result);     return (result);
 }  }
   
   
Line 423  char               *path; Line 423  char               *path;
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
   
 #ifdef __STDC__  #ifdef __STDC__
 char *AHTMakeRelativeName(char *url, char *base_url)  char               *AHTMakeRelativeName (char *url, char *base_url)
 #else  /* __STDC__ */  #else  /* __STDC__ */
 char *AHTMakeRelativeName(url, base_url)  char               *AHTMakeRelativeName (url, base_url)
 char url;  char                url;
 char base_url;  char                base_url;
   
 #endif /* __STDC__ */  #endif /* __STDC__ */
 {  {
  char *base_ptr, *url_ptr;     char               *base_ptr, *url_ptr;
  char *result;     char               *result;
   
  /* verify if we are in the same host */     /* verify if we are in the same host */
   
  base_ptr = HTParse(base_url, "", PARSE_ACCESS | PARSE_HOST | PARSE_PUNCTUATION);  
  url_ptr = HTParse(url, "", PARSE_ACCESS | PARSE_HOST | PARSE_PUNCTUATION);  
    
  if (!strcmp (base_ptr, url_ptr)) {  
    HT_FREE(base_ptr);  
    HT_FREE(url_ptr);  
   
    /* Normalize the URLs */  
   
    base_ptr = HTParse(base_url, "", PARSE_ALL);  
    url_ptr = HTParse(url, "", PARSE_ALL);  
   
    /* Use libwww to make relative name */  
   
    result = HTRelative(url_ptr, base_ptr);  
    HT_FREE(base_ptr);  
    HT_FREE(url_ptr);  
  }  
  else  
    result = (char *) NULL;  
   
  return(result);  
 }  
   
      base_ptr = HTParse (base_url, "", PARSE_ACCESS | PARSE_HOST | PARSE_PUNCTUATION);
      url_ptr = HTParse (url, "", PARSE_ACCESS | PARSE_HOST | PARSE_PUNCTUATION);
   
      if (!strcmp (base_ptr, url_ptr))
        {
           HT_FREE (base_ptr);
           HT_FREE (url_ptr);
   
           /* Normalize the URLs */
   
           base_ptr = HTParse (base_url, "", PARSE_ALL);
           url_ptr = HTParse (url, "", PARSE_ALL);
   
           /* Use libwww to make relative name */
   
           result = HTRelative (url_ptr, base_ptr);
           HT_FREE (base_ptr);
           HT_FREE (url_ptr);
        }
      else
         result = (char *) NULL;
   
      return (result);
   }

Removed from v.1.4  
changed lines
  Added in v.1.5


Webmaster