Diff for /Amaya/amaya/AHTURLTools.c between versions 1.30 and 1.31

version 1.30, 1997/05/29 14:02:36 version 1.31, 1997/06/05 06:40:32
Line 405  char               *url; Line 405  char               *url;
       return (FALSE);        return (FALSE);
 }  }
   
   
   /*----------------------------------------------------------------------
      GetBaseURL
      normalizes orgName according to a base associated with doc, and
      following the standard URL format rules.
      The function returns the base used to solve relative URL and SRC:
         - the base of the document,
         - or the document path (without document name).
     ----------------------------------------------------------------------*/
   #ifdef __STDC__
   char               *GetBaseURL (Document doc)
   #else  /* __STDC__ */
   char               *GetBaseURL (doc)
   Document            doc;
   #endif /* __STDC__ */
   {
     Element             el;
     ElementType         elType;
     AttributeType       attrType;
     Attribute           attr;
     char               *ptr, *basename;
     int                 length;
   
     basename = TtaGetMemory (MAX_LENGTH);
     strcpy (basename, DocumentURLs[doc]);
     length = MAX_LENGTH -1;
     /* get the root element    */
     el = TtaGetMainRoot (doc);
     /* search the BASE element */
     elType.ElSSchema = TtaGetDocumentSSchema (doc);
     elType.ElTypeNum = HTML_EL_BASE;
     el = TtaSearchTypedElement (elType, SearchInTree, el);
     if (el)
       {
         /*  The document has a BASE element -> Get the HREF attribute */
         attrType.AttrSSchema = elType.ElSSchema;
         attrType.AttrTypeNum = HTML_ATTR_HREF_;
         attr = TtaGetAttribute (el, attrType);
         if (attr)
           {
             /* Use the base path of the document */
             TtaGiveTextAttributeValue (attr, basename, &length);
             /* base and orgName have to be separated by a DIR_SEP */
             length--;
             if (basename[0] != EOS && basename[length] != DIR_SEP) 
               /* verify if the base has the form "protocol://server:port" */
               {
                 ptr = AmayaParseUrl (basename, "", AMAYA_PARSE_ACCESS | AMAYA_PARSE_HOST |
                                      AMAYA_PARSE_PUNCTUATION);
                 if (ptr && !strcmp (ptr, basename))
                   {
                     /* it has this form, we complete it by adding a DIR_STR  */
                     strcat (basename, DIR_STR);
                     length++;
                   }
                 if (ptr)
                   TtaFreeMemory (ptr);
               }
           }
       }
   
     /* Remove anything after the last DIR_SEP char. If no such char is found,
      * then search for the first ":" char, hoping that what's before that is a
      * protocol. If found, end the string there. If neither char is found,
      * then discard the whole base element.
      */
     length = strlen (basename) - 1;
     /* search for the last DIR_SEP char */
     while (length >= 0  && basename[length] != DIR_SEP)
       length--;
     if (length >= 0)
       /* found the last DIR_SEP char, end the string there */
       basename[length + 1] = EOS;            
     else
       /* search for the first PATH_STR char */
       {
         for (length = 0; basename[length] != PATH_SEP && 
                basename[length] != EOS; length ++);
         if (basename[length] == PATH_SEP)
           /* found, so end the string there */
           basename[length + 1] = EOS;
         else
           /* not found, discard the base */
           basename[0] = EOS;
       }
     return (basename);
   }
   
   
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
    NormalizeURL     NormalizeURL
    normalizes orgName according to a base associated with doc, and     normalizes orgName according to a base associated with doc, and
Line 424  char               *newName; Line 513  char               *newName;
 char               *docName;  char               *docName;
 #endif /* __STDC__ */  #endif /* __STDC__ */
 {  {
    char                basename[MAX_LENGTH];     char               *basename;
    char                tempOrgName[MAX_LENGTH];     char                tempOrgName[MAX_LENGTH];
    char               *ptr;     char               *ptr;
    Element             el;  
    ElementType         elType;  
    AttributeType       attrType;  
    Attribute           attrHREF = NULL;  
    int                 length;     int                 length;
   
    if (!newName || !docName)     if (!newName || !docName)
       return;        return;
   
    /*     /*
    ** First Step: Clean orgName      * Clean orgName
    ** Make sure we have a complete orgName, without any leading or trailing      * Make sure we have a complete orgName, without any leading or trailing
    ** white spaces, or trailinbg new lines      * white spaces, or trailinbg new lines
    */      */
   
    ptr = orgName;     ptr = orgName;
    /* skip leading white space and new line characters */     /* skip leading white space and new line characters */
Line 456  char               *docName; Line 541  char               *docName;
       *ptr = EOS;        *ptr = EOS;
   
    /*     /*
    ** Second Step: make orgName a complete URL      * Make orgName a complete URL
    ** If the URL does not include a protocol, then      * If the URL does not include a protocol, then try to calculate
    ** try to calculate one using the doc's base element       * one using the doc's base element (if it exists),
    ** (if it exists),      */
    */  
    if (tempOrgName[0] == EOS)     if (tempOrgName[0] == EOS)
      {       {
        newName[0] = EOS;         newName[0] = EOS;
Line 486  char               *docName; Line 570  char               *docName;
      strcpy (newName, tempOrgName);       strcpy (newName, tempOrgName);
    else     else
      {       {
        /* take into account the BASE element. */  
        length = MAX_LENGTH -1;  
        /* get the root element    */  
        el = TtaGetMainRoot (doc);  
              
        /* search the BASE element */  
        elType.ElSSchema = TtaGetDocumentSSchema (doc);  
        elType.ElTypeNum = HTML_EL_BASE;  
        el = TtaSearchTypedElement (elType, SearchInTree, el);  
        if (el)  
          {  
            /*   
            ** The document has a 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 */  
                TtaGiveTextAttributeValue (attrHREF, basename, &length);  
                /* base and orgName have to be separated by a DIR_SEP */  
                length--;  
                if (basename[0] != EOS && basename[length] != DIR_SEP)   
                  /* verify if the base has the form "protocol://server:port" */  
                  {  
                    ptr = AmayaParseUrl (basename, "", AMAYA_PARSE_ACCESS | AMAYA_PARSE_HOST |  
                                                 AMAYA_PARSE_PUNCTUATION);  
                    if (ptr && !strcmp (ptr, basename))  
                      {  
                      /* it has this form, we complete it by adding a DIR_STR  */  
                      strcat (basename, DIR_STR);  
                      length++;  
                      }  
                    if (ptr)  
                      TtaFreeMemory (ptr);  
                  }  
                /* Third Step: prepare the base  
                ** Removing anything after the  
                ** last DIR_SEP char. If no such char is found, then search for  
                ** the first ":" char, hoping that what's before that is a  
                ** protocol. If found, end the string there. If neither  
                ** char is found, then discard the whole base element.  
                */  
   
                /* search for the last DIR_SEP char */  
                while (length >= 0  && basename[length] != DIR_SEP)  
                  length--;  
                if (length >= 0)  
                  /* found the last DIR_SEP char, end the string there */  
                  basename[length + 1] = EOS;                 
                else  
                  /* search for the first PATH_STR char */  
                  {  
                    for (length = 0; basename[length] != PATH_SEP &&   
                           basename[length] != EOS; length++);  
                    if (basename[length] == PATH_SEP)  
                      /* found, so end the string there */  
                      basename[length + 1] = EOS;  
                    else  
                      /* not found, discard the base */  
                      basename[0] = EOS;  
                  }  
              }  
            else  
              basename[0] = EOS;  
          }  
        
        /*  
        ** Fourth Step:   
        ** If there's no base element, and if we're following  
        ** a link, use the URL of the current document as a base.  
        */  
   
        if (!attrHREF)  
          {  
            if (DocumentURLs[(int) doc])  
              {  
                strcpy (basename, DocumentURLs[(int) doc]);  
                /* base and orgName have to be separated by a DIR_SEP */  
                length = strlen (basename) - 1;  
                /* search for the last DIR_SEP char */  
                while (length >= 0  && basename[length] != DIR_SEP)  
                  length--;  
                if (length >= 0)  
                  /* found the last DIR_SEP char, end the string there */  
                  basename[length + 1] = EOS;                 
                else  
                  /* search for the first PATH_STR char */  
                  {  
                    for (length = 0; basename[length] != PATH_SEP &&   
                           basename[length] != EOS; length ++);  
                    if (basename[length] == PATH_SEP)  
                      /* found, so end the string there */  
                      basename[length + 1] = EOS;  
                    else  
                      /* not found, discard the base */  
                      basename[0] = EOS;  
                  }  
              }  
            else  
                basename[0] = EOS;  
          }  
             
        /*         /* Calculate the absolute URL, using the base or document URL */
        ** Fifth Step, calculate the absolute URL, using the base         basename = GetBaseURL (doc);
        */  
   
        ptr = AmayaParseUrl (tempOrgName, basename, AMAYA_PARSE_ALL);         ptr = AmayaParseUrl (tempOrgName, basename, AMAYA_PARSE_ALL);
          TtaFreeMemory (basename);
        if (ptr)         if (ptr)
          {           {
            SimplifyUrl (&ptr);             SimplifyUrl (&ptr);
Line 608  char               *docName; Line 586  char               *docName;
      }       }
   
    /*     /*
    ** Sixth and last Step:      * Prepare the docname that will refer to this ressource in the
    ** Prepare the docname that will refer to this ressource in the      * .amaya directory. If the new URL finishes on DIR_SEP, then use
    ** .amaya directory. If the new URL finishes on DIR_SEP, then use      * noname.html as a default ressource name
    ** noname.html as a default ressource name  
    */     */
   
    if (newName[0] != EOS)     if (newName[0] != EOS)
      {       {
        length = strlen (newName) - 1;         length = strlen (newName) - 1;
Line 1263  char               *target; Line 1239  char               *target;
   
   
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
   MakeRelativeUrl: make relative name    MakeRelativeURL: make relative name
       
   This function creates and returns a string which gives an expression of    This function creates and returns a string which gives an expression of
   one address as related to another. Where there is no relation, an absolute    one address as related to another. Where there is no relation, an absolute
Line 1279  char               *target; Line 1255  char               *target;
         The caller is responsible for freeing the resulting name later.          The caller is responsible for freeing the resulting name later.
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
 #ifdef __STDC__  #ifdef __STDC__
 char            *MakeRelativeUrl (char *aName, char *relatedName)  char            *MakeRelativeURL (char *aName, char *relatedName)
 #else  /* __STDC__ */  #else  /* __STDC__ */
 char            *MakeRelativeUrl (aName, relatedName)  char            *MakeRelativeURL (aName, relatedName)
 char            *aName;  char            *aName;
 char            *relatedName;  char            *relatedName;
 #endif  /* __STDC__ */  #endif  /* __STDC__ */
Line 1314  char            *relatedName; Line 1290  char            *relatedName;
         }          }
     }      }
           
     /* q, p point to the first non-matching character or zero */    /* q, p point to the first non-matching character or zero */
     if ((slashes < 2 && after_access == NULL)    if (*q == EOS)
         || (slashes < 3 && after_access != NULL))      {
       {        /* New name is a subset of the related name */
         /* Local files or remote files whitout common path */        /* exactly the right length */
         /* exactly the right length */        len = strlen (p);
         len = strlen (aName);        if ((return_value = (char *) TtaGetMemory (len + 1)) != NULL)
         if ((return_value = (char *) TtaGetMemory (len + 1)) != NULL)          strcpy (return_value, p);
           strcpy (return_value, aName);      }
       }    else if ((slashes < 2 && after_access == NULL)
     else        || (slashes < 3 && after_access != NULL))
       {      {
         /* Some path in common */        /* Two names whitout common path */
         if (slashes == 3 && strncmp (aName, "http:", 5) == 0)        /* exactly the right length */
           /* just the same server */        len = strlen (aName);
           strcpy (result, last_slash);        if ((return_value = (char *) TtaGetMemory (len + 1)) != NULL)
         else          strcpy (return_value, aName);
           {      }
             levels= 0;     else
             for (; *q && (*q != '#'); q++)      {
               if (*q == DIR_SEP)        /* Some path in common */
                 levels++;        if (slashes == 3 && strncmp (aName, "http:", 5) == 0)
                       /* just the same server */
             result[0] = 0;          strcpy (result, last_slash);
             for (;levels; levels--)        else
               strcat (result, "../");          {
             strcat (result, last_slash+1);            levels= 0; 
           }             for (; *q && (*q != '#'); q++)
               if (*q == DIR_SEP)
         /* exactly the right length */                levels++;
         len = strlen (result);            
         if ((return_value = (char *) TtaGetMemory (len + 1)) != NULL)            result[0] = 0;
           strcpy (return_value, result);            for (;levels; levels--)
               strcat (result, "../");
             strcat (result, last_slash+1);
           } 
         
         /* exactly the right length */
         len = strlen (result);
         if ((return_value = (char *) TtaGetMemory (len + 1)) != NULL)
           strcpy (return_value, result);
     }      }
   return (return_value);    return (return_value);
 }  }

Removed from v.1.30  
changed lines
  Added in v.1.31


Webmaster