Annotation of Amaya/amaya/AHTURLTools.c, revision 1.21

1.7       cvs         1: /*
                      2:  *
                      3:  *  (c) COPYRIGHT MIT and INRIA, 1996.
                      4:  *  Please first read the full copyright statement in file COPYRIGHT.
                      5:  *
                      6:  */
1.9       cvs         7: 
1.10      cvs         8: /*
                      9:  * AHTURLTools.c: contains all the functions for testing, manipulating,
                     10:  * and normalizing URLs.
                     11:  *
                     12:  * Authors: J. Kahan, I. Vatton
                     13:  *
                     14:  */
1.7       cvs        15:  
1.8       cvs        16: /* Amaya includes  */
1.15      cvs        17: #define THOT_EXPORT extern
1.3       cvs        18: #include "amaya.h"
                     19: 
1.8       cvs        20: 
                     21: #include "init_f.h"
                     22: #include "AHTURLTools_f.h"
                     23: 
                     24: /*----------------------------------------------------------------------
1.11      cvs        25:   ExplodeURL 
1.8       cvs        26:   ----------------------------------------------------------------------*/
                     27: 
                     28: #ifdef __STDC__
                     29: void                ExplodeURL (char *url, char **proto, char **host, char **dir, char **file)
                     30: #else
                     31: void                ExplodeURL (url, proto, host, dir, file)
                     32: char               *url;
                     33: char              **proto;
                     34: char              **host;
                     35: char              **dir;
                     36: char              **file;
                     37: 
                     38: #endif
                     39: {
1.9       cvs        40:    char               *curr, *temp;
1.8       cvs        41: 
                     42:    if ((url == NULL) || (proto == NULL) || (host == NULL) ||
                     43:        (dir == NULL) || (file == NULL))
                     44:       return;
                     45: 
                     46:    /* initialize every pointer */
                     47:    *proto = *host = *dir = *file = NULL;
                     48: 
                     49:    /* skip any leading space */
                     50:    while ((*url == SPACE) || (*url == TAB))
                     51:       url++;
1.9       cvs        52:    curr = url;
                     53:    if (*curr == 0)
1.8       cvs        54:       goto finished;
                     55: 
                     56:    /* go to the end of the URL */
1.9       cvs        57:    while ((*curr != 0) && (*curr != SPACE) && (*curr != '\b') &&
                     58:          (*curr != '\r') && (*curr != EOL))
                     59:       curr++;
1.8       cvs        60: 
                     61:    /* mark the end of the chain */
1.9       cvs        62:    *curr = EOS;
                     63:    curr--;
                     64:    if (curr <= url)
1.8       cvs        65:       goto finished;
                     66: 
                     67:    /* search the next DIR_SEP indicating the beginning of the file name */
                     68:    do
1.11      cvs        69:      curr--;
1.9       cvs        70:    while ((curr >= url) && (*curr != DIR_SEP));
1.11      cvs        71: 
1.9       cvs        72:    if (curr < url)
1.8       cvs        73:       goto finished;
1.9       cvs        74:    *file = curr + 1;
1.8       cvs        75: 
                     76:    /* mark the end of the dir */
1.9       cvs        77:    *curr = EOS;
                     78:    curr--;
                     79:    if (curr < url)
1.8       cvs        80:       goto finished;
                     81: 
                     82:    /* search for the "/" indicating the host name start */
1.9       cvs        83:    while ((curr > url) && ((*curr != DIR_SEP) || (*(curr + 1) != DIR_SEP)))
                     84:       curr--;
1.8       cvs        85: 
                     86:    /* if we found it, separate the host name from the directory */
1.9       cvs        87:    if ((*curr == DIR_SEP) && (*(curr + 1) == DIR_SEP))
1.8       cvs        88:      {
1.9       cvs        89:        *host = temp = curr + 2;
1.8       cvs        90:        while ((*temp != 0) && (*temp != DIR_SEP))
                     91:           temp++;
                     92:        if (*temp == DIR_SEP)
                     93:          {
                     94:             *temp = EOS;
                     95:             *dir = temp + 1;
                     96:          }
                     97:      }
                     98:    else
1.11      cvs        99:      *dir = curr;
                    100: 
1.9       cvs       101:    if (curr <= url)
1.8       cvs       102:       goto finished;
                    103: 
                    104:    /* mark the end of the proto */
1.9       cvs       105:    *curr = EOS;
                    106:    curr--;
                    107:    if (curr < url)
1.8       cvs       108:       goto finished;
                    109: 
1.9       cvs       110:    if (*curr == ':')
1.8       cvs       111:      {
1.9       cvs       112:        *curr = EOS;
                    113:        curr--;
1.8       cvs       114:      }
                    115:    else
                    116:       goto finished;
1.11      cvs       117: 
1.9       cvs       118:    if (curr < url)
1.8       cvs       119:       goto finished;
1.9       cvs       120:    while ((curr > url) && (isalpha (*curr)))
                    121:       curr--;
                    122:    *proto = curr;
1.8       cvs       123: 
                    124:  finished:;
                    125: 
                    126: #ifdef AMAYA_DEBUG
                    127:    fprintf (stderr, "ExplodeURL(%s)\n\t", url);
                    128:    if (*proto)
                    129:       fprintf (stderr, "proto : %s, ", *proto);
                    130:    if (*host)
                    131:       fprintf (stderr, "host : %s, ", *host);
                    132:    if (*dir)
                    133:       fprintf (stderr, "dir : %s, ", *dir);
                    134:    if (*file)
                    135:       fprintf (stderr, "file : %s ", *file);
                    136:    fprintf (stderr, "\n");
                    137: #endif
                    138: 
                    139: }
1.3       cvs       140: 
1.4       cvs       141: /*----------------------------------------------------------------------
1.9       cvs       142:   IsHTMLName                                                         
                    143:   returns TRUE if path points to an HTML resource.
1.4       cvs       144:   ----------------------------------------------------------------------*/
1.3       cvs       145: #ifdef __STDC__
                    146: boolean             IsHTMLName (char *path)
                    147: #else  /* __STDC__ */
                    148: boolean             IsHTMLName (path)
                    149: char               *path;
                    150: #endif /* __STDC__ */
                    151: {
1.5       cvs       152:    char                temppath[MAX_LENGTH];
                    153:    char                suffix[MAX_LENGTH];
                    154:    char                nsuffix[MAX_LENGTH];
                    155:    int                 i;
                    156: 
                    157:    if (!path)
1.13      cvs       158:      return (FALSE);
1.5       cvs       159: 
                    160:    strcpy (temppath, path);
                    161:    ExtractSuffix (temppath, suffix);
                    162: 
                    163:    /* Normalize the suffix */
                    164:    i = 0;
                    165:    while (suffix[i] != EOS)
1.13      cvs       166:      {
                    167:        nsuffix[i] = TOLOWER (suffix[i]);
                    168:        i++;
                    169:      }
1.5       cvs       170:    nsuffix[i] = EOS;
                    171:    if ((strcmp (nsuffix, "html")) &&
                    172:        (strcmp (nsuffix, "htm")) &&
                    173:        (strcmp (nsuffix, "shtml")))
1.13      cvs       174:      return (FALSE);
                    175:    else if ((!strcmp (nsuffix, "gz")) ||
1.16      cvs       176:            (!strcmp (nsuffix, "z")))
1.13      cvs       177:      {
                    178:        /* take in account compressed files */
                    179:        ExtractSuffix (temppath, suffix);       
                    180:        /* Normalize the suffix */
                    181:        i = 0;
                    182:        while (suffix[i] != EOS)
                    183:         {
                    184:           nsuffix[i] = TOLOWER (suffix[i]);
                    185:           i++;
                    186:         }
                    187:        nsuffix[i] = EOS;
                    188:        if ((strcmp (nsuffix, "html")) &&
                    189:           (strcmp (nsuffix, "htm")) &&
                    190:           (strcmp (nsuffix, "shtml")))
                    191:         return (FALSE);
                    192:        else
                    193:         return (TRUE);
                    194:      }
                    195:    else
                    196:      return (TRUE);
1.3       cvs       197: }
                    198: 
1.4       cvs       199: /*----------------------------------------------------------------------
1.9       cvs       200:   IsImageName                                
                    201:   returns TRUE if path points to an image resource.
1.4       cvs       202:   ----------------------------------------------------------------------*/
1.3       cvs       203: #ifdef __STDC__
                    204: boolean             IsImageName (char *path)
                    205: #else  /* __STDC__ */
                    206: boolean             IsImageName (path)
                    207: char               *path;
                    208: #endif /* __STDC__ */
                    209: {
1.5       cvs       210:    char                temppath[MAX_LENGTH];
                    211:    char                suffix[MAX_LENGTH];
                    212:    char                nsuffix[MAX_LENGTH];
                    213:    int                 i;
                    214: 
                    215:    if (!path)
1.13      cvs       216:       return (FALSE);
1.5       cvs       217: 
                    218:    strcpy (temppath, path);
                    219:    ExtractSuffix (temppath, suffix);
                    220: 
                    221:    /* Normalize the suffix */
                    222:    i = 0;
                    223:    while (suffix[i] != EOS)
1.13      cvs       224:      {
                    225:        nsuffix[i] = TOLOWER (suffix[i]);
                    226:        i++;
                    227:      }
1.5       cvs       228:    nsuffix[i] = EOS;
                    229:    if ((strcmp (nsuffix, "gif")) && (strcmp (nsuffix, "xbm")) &&
                    230:        (strcmp (nsuffix, "xpm")) && (strcmp (nsuffix, "jpg")) &&
                    231:        (strcmp (nsuffix, "png")) && (strcmp (nsuffix, "au")))
1.13      cvs       232:       return (FALSE);
                    233:    return (TRUE);
1.3       cvs       234: }
                    235: 
1.4       cvs       236: /*----------------------------------------------------------------------
1.9       cvs       237:   IsTextName                                                         
1.4       cvs       238:   ----------------------------------------------------------------------*/
1.3       cvs       239: #ifdef __STDC__
                    240: boolean             IsTextName (char *path)
                    241: #else  /* __STDC__ */
                    242: boolean             IsTextName (path)
                    243: char               *path;
                    244: 
                    245: #endif /* __STDC__ */
                    246: {
1.5       cvs       247:    char                temppath[MAX_LENGTH];
                    248:    char                suffix[MAX_LENGTH];
                    249:    char                nsuffix[MAX_LENGTH];
                    250:    int                 i;
                    251: 
                    252:    if (!path)
1.13      cvs       253:      return (FALSE);
1.5       cvs       254: 
                    255:    strcpy (temppath, path);
                    256:    ExtractSuffix (temppath, suffix);
                    257: 
                    258:    /* Normalize the suffix */
                    259:    i = 0;
                    260:    while (suffix[i] != EOS)
                    261:      {
                    262:        nsuffix[i] = TOLOWER (suffix[i]);
                    263:        i++;
                    264:      }
                    265:    nsuffix[i] = EOS;
                    266: 
                    267:    if ((strcmp (nsuffix, "gif")) && (strcmp (nsuffix, "xbm")) &&
                    268:        (strcmp (nsuffix, "xpm")) && (strcmp (nsuffix, "jpg")) &&
                    269:        (strcmp (nsuffix, "pdf")) && (strcmp (nsuffix, "png")) &&
                    270:        (strcmp (nsuffix, "tgz")) && (strcmp (nsuffix, "xpg")) &&
                    271:        (strcmp (nsuffix, "xpd")) && (strcmp (nsuffix, "ps")) &&
                    272:        (strcmp (nsuffix, "au")))
1.13      cvs       273:       return (TRUE);
1.16      cvs       274:    else if ((!strcmp (nsuffix, "gz")) || (!strcmp (nsuffix, "z")))
1.13      cvs       275:      {
                    276:        /* take in account compressed files */
                    277:        ExtractSuffix (temppath, suffix);       
                    278:        /* Normalize the suffix */
                    279:        i = 0;
                    280:        while (suffix[i] != EOS)
                    281:         {
                    282:           nsuffix[i] = TOLOWER (suffix[i]);
                    283:           i++;
                    284:         }
                    285:        nsuffix[i] = EOS;
                    286:        if ((!strcmp (nsuffix, "html")) ||
                    287:           (!strcmp (nsuffix, "htm")) ||
                    288:           (!strcmp (nsuffix, "shtml")))
                    289:         return (TRUE);
                    290:        else
                    291:         return (FALSE);
                    292:      }
                    293:    else
                    294:      return (FALSE);
1.3       cvs       295: }
                    296: 
1.4       cvs       297: /*----------------------------------------------------------------------
1.9       cvs       298:   IsHTTPPath                                     
                    299:   returns TRUE if path is in fact an http URL.
1.4       cvs       300:   ----------------------------------------------------------------------*/
1.3       cvs       301: #ifdef __STDC__
                    302: boolean             IsHTTPPath (char *path)
                    303: #else  /* __STDC__ */
                    304: boolean             IsHTTPPath (path)
                    305: char               *path;
                    306: #endif /* __STDC__ */
                    307: {
1.5       cvs       308:    if (!path)
                    309:       return FALSE;
1.3       cvs       310: 
1.5       cvs       311:    if (strncmp (path, "http:", 5) != 0)
                    312:       return FALSE;
                    313:    return TRUE;
1.3       cvs       314: }
                    315: 
1.4       cvs       316: /*----------------------------------------------------------------------
1.9       cvs       317:   IsWithParameters                           
                    318:   returns TRUE if url has a concatenated query string.
1.4       cvs       319:   ----------------------------------------------------------------------*/
1.3       cvs       320: #ifdef __STDC__
1.9       cvs       321: boolean             IsWithParameters (char *url)
1.3       cvs       322: #else  /* __STDC__ */
1.9       cvs       323: boolean             IsWithParameters (url)
                    324: char               *url;
1.3       cvs       325: #endif /* __STDC__ */
                    326: {
1.5       cvs       327:    int                 i;
1.3       cvs       328: 
1.9       cvs       329:    if ((!url) || (url[0] == EOS))
1.5       cvs       330:       return FALSE;
1.3       cvs       331: 
1.9       cvs       332:    i = strlen (url) - 1;
                    333:    while (i > 0 && url[i--] != '?')
1.5       cvs       334:       if (i < 0)
                    335:         return FALSE;
1.3       cvs       336: 
1.5       cvs       337:    /* There is a parameter */
                    338:    return TRUE;
1.3       cvs       339: }
                    340: 
1.4       cvs       341: /*----------------------------------------------------------------------
1.9       cvs       342:   IsW3Path                                           
                    343:   returns TRUE if path is in fact a URL.
1.4       cvs       344:   ----------------------------------------------------------------------*/
1.3       cvs       345: #ifdef __STDC__
                    346: boolean             IsW3Path (char *path)
                    347: #else  /* __STDC__ */
                    348: boolean             IsW3Path (path)
                    349: char               *path;
                    350: #endif /* __STDC__ */
                    351: {
1.5       cvs       352:    if ((strncmp (path, "http:", 5)) && (strncmp (path, "ftp:", 4)) &&
                    353:        (strncmp (path, "telnet:", 7)) && (strncmp (path, "wais:", 5)) &&
                    354:        (strncmp (path, "news:", 5)) && (strncmp (path, "gopher:", 7)) &&
                    355:        (strncmp (path, "mailto:", 7)) && (strncmp (path, "archie:", 7)))
                    356:       return FALSE;
                    357:    return TRUE;
1.3       cvs       358: }
                    359: 
1.4       cvs       360: /*----------------------------------------------------------------------
1.9       cvs       361:   IsValidProtocol                                                    
                    362:   returns true if the url protocol is supported by Amaya.
1.4       cvs       363:   ----------------------------------------------------------------------*/
1.3       cvs       364: #ifdef __STDC__
1.9       cvs       365: boolean             IsValidProtocol (char *url)
1.3       cvs       366: #else  /* __STDC__ */
1.9       cvs       367: boolean             IsValidProtocol (url)
                    368: char               *url;
1.3       cvs       369: #endif /* __STDC__ */
                    370: {
1.9       cvs       371:    if (!strncmp (url, "http:", 5)
1.3       cvs       372:       /***|| !strncmp (path, "ftp:", 4)
1.5       cvs       373:       || !strncmp (path, "news:", 5)***/ )
1.8       cvs       374:       return (TRUE);
1.5       cvs       375:    else
1.8       cvs       376:       return (FALSE);
1.3       cvs       377: }
                    378: 
1.4       cvs       379: /*----------------------------------------------------------------------
1.9       cvs       380:    NormalizeURL
                    381:    normalizes orgName according to a base associated with doc, and
                    382:    following the standard URL format rules.
                    383:    The function returns the new complete and normalized URL 
1.12      cvs       384:    or file name path (newName) and the name of the document (docName).        
1.9       cvs       385:    N.B. If the function can't find out what's the docName, it assigns
                    386:    the name "noname.html".
1.4       cvs       387:   ----------------------------------------------------------------------*/
1.3       cvs       388: #ifdef __STDC__
                    389: void                NormalizeURL (char *orgName, Document doc, char *newName, char *docName)
                    390: #else  /* __STDC__ */
                    391: void                NormalizeURL (orgName, doc, newName, docName)
                    392: char               *orgName;
                    393: Document            doc;
                    394: char               *newName;
                    395: char               *docName;
                    396: #endif /* __STDC__ */
                    397: {
1.5       cvs       398:    char                basename[MAX_LENGTH];
1.18      cvs       399:    char                tempOrgName[MAX_LENGTH];
1.5       cvs       400:    char               *ptr;
                    401:    Element             el;
                    402:    ElementType         elType;
                    403:    AttributeType       attrType;
1.18      cvs       404:    Attribute           attrHREF = NULL;
1.5       cvs       405:    int                 length;
                    406: 
                    407:    if (!newName || !docName)
                    408:       return;
1.18      cvs       409: 
                    410:    /*
                    411:    ** First Step: Clean orgName
                    412:    ** Make sure we have a complete orgName, without any leading or trailing
                    413:    ** white spaces, or trailinbg new lines
                    414:    */
                    415: 
1.5       cvs       416:    ptr = orgName;
1.18      cvs       417:    /* skip leading white space and new line characters */
1.19      cvs       418:    while ((*ptr == ' ' || *ptr == EOL) && *ptr++ != EOS);
1.18      cvs       419:    strcpy (tempOrgName, ptr);
                    420:    /* clean trailing white space */
                    421:    ptr = strchr (tempOrgName, ' ');
                    422:    if (ptr)
                    423:       *ptr = EOS;
                    424:    /* clean trailing new lines */
1.19      cvs       425:    ptr = strchr (tempOrgName, EOL);
1.5       cvs       426:    if (ptr)
                    427:       *ptr = EOS;
                    428: 
1.18      cvs       429:    /*
                    430:    ** Second Step: make orgName a complete URL
                    431:    ** If the URL does not include a protocol, then
                    432:    ** try to calculate one using the doc's base element 
                    433:    ** (if it exists),
                    434:    */
1.21    ! cvs       435:    if (tempOrgName[0] == EOS)
        !           436:      {
        !           437:        newName[0] = EOS;
        !           438:        return;
        !           439:      }
        !           440:    else if (IsW3Path (tempOrgName))
        !           441:      {
        !           442:        /* the name is complete, go to the Sixth Step */
        !           443:        strcpy (newName, tempOrgName);
        !           444:        /* verify if the URL has the form "protocol://server:port" */
        !           445:        ptr = HTParse (newName, "", PARSE_ACCESS | PARSE_HOST |
        !           446:                      PARSE_PUNCTUATION);
        !           447:        if (ptr && !strcmp (ptr, newName))
        !           448:         {
        !           449:           /* it has this form, we complete it by adding a "/"  */
        !           450:           strcat (newName, "/");
        !           451:           length++;
        !           452:         }
        !           453:        if (ptr)
        !           454:         HT_FREE (ptr);
        !           455:      }
        !           456:    else if ( doc == 0)
1.19      cvs       457:      /* the name is complete, go to the Sixth Step */
1.18      cvs       458:      strcpy (newName, tempOrgName);
1.5       cvs       459:    else
                    460:      {
1.18      cvs       461:        /* take into account the BASE element. */
                    462:        length = MAX_LENGTH;
                    463:        /* get the root element    */
                    464:        el = TtaGetMainRoot (doc);
                    465:           
                    466:        /* search the BASE element */
                    467:        elType.ElSSchema = TtaGetDocumentSSchema (doc);
                    468:        elType.ElTypeNum = HTML_EL_BASE;
                    469:        el = TtaSearchTypedElement (elType, SearchInTree, el);
                    470:        if (el)
1.17      cvs       471:         {
1.18      cvs       472:           /* 
                    473:           ** The document has a BASE element 
                    474:           ** Get the HREF attribute of the BASE Element 
                    475:           */
                    476:           attrType.AttrSSchema = elType.ElSSchema;
                    477:           attrType.AttrTypeNum = HTML_ATTR_HREF_;
                    478:           attrHREF = TtaGetAttribute (el, attrType);
                    479:           if (attrHREF)
1.14      cvs       480:             {
1.18      cvs       481:               /* Use the base path of the document */
                    482:               TtaGiveTextAttributeValue (attrHREF, basename, &length);
                    483:               /* base and orgName have to be separated by a DIR_SEP */
1.20      cvs       484:               length--;
1.18      cvs       485:               if (basename[0] != EOS && basename[length] != '/') 
                    486:                 /* verify if the base has the form "protocol://server:port" */
1.14      cvs       487:                 {
1.18      cvs       488:                   ptr = HTParse (basename, "", PARSE_ACCESS | PARSE_HOST |
                    489:                                                PARSE_PUNCTUATION);
                    490:                   if (ptr && !strcmp (ptr, basename))
1.14      cvs       491:                     {
1.18      cvs       492:                     /* it has this form, we complete it by adding a "/"  */
                    493:                     strcat (basename, "/");
                    494:                     length++;
1.14      cvs       495:                     }
1.18      cvs       496:                   if (ptr)
                    497:                     HT_FREE (ptr);
1.14      cvs       498:                 }
1.19      cvs       499:               /* Third Step: prepare the base
                    500:               ** Removing anything after the
                    501:               ** last DIR_SEP char. If no such char is found, then search for
                    502:               ** the first ":" char, hoping that what's before that is a
                    503:               ** protocol. If found, end the string there. If neither
                    504:               ** char is found, then discard the whole base element.
                    505:               */
                    506: 
                    507:               /* search for the last DIR_SEP char */
1.18      cvs       508:               while (length >= 0  && basename[length] != DIR_SEP)
1.19      cvs       509:                 length--;
                    510:               if (length >= 0)
                    511:                 /* found the last DIR_SEP char, end the string there */
                    512:                 basename[length + 1] = EOS;               
                    513:               else
                    514:                 /* search for the first ":" char */
                    515:                 {
                    516:                   for (length = 0; basename[length] != ':' && 
1.20      cvs       517:                          basename[length] != EOS; length++);
1.19      cvs       518:                   if (basename[length] == ':')
                    519:                     /* found, so end the string there */
                    520:                     basename[length + 1] = EOS;
                    521:                   else
                    522:                     /* not found, discard the base */
                    523:                     basename[0] = EOS;
                    524:                 }
1.14      cvs       525:             }
                    526:           else
                    527:             basename[0] = EOS;
1.18      cvs       528:         }
                    529: 
                    530:        /*
1.19      cvs       531:        ** Fourth Step: 
1.18      cvs       532:        ** If there's no base element, and if we're following
1.19      cvs       533:        ** a link, use the URL of the current document as a base.
1.18      cvs       534:        */
                    535: 
                    536:        if (!attrHREF)
                    537:         {
                    538:           if (DocumentURLs[(int) doc])
1.14      cvs       539:             {
1.18      cvs       540:               strcpy (basename, DocumentURLs[(int) doc]);
                    541:               /* base and orgName have to be separated by a DIR_SEP */
                    542:               length = strlen (basename) - 1;
1.19      cvs       543:               /* search for the last DIR_SEP char */
1.18      cvs       544:               while (length >= 0  && basename[length] != DIR_SEP)
1.19      cvs       545:                 length--;
                    546:               if (length >= 0)
                    547:                 /* found the last DIR_SEP char, end the string there */
                    548:                 basename[length + 1] = EOS;               
                    549:               else
                    550:                 /* search for the first ":" char */
                    551:                 {
                    552:                   for (length = 0; basename[length] != ':' && 
                    553:                          basename[length] != EOS; length ++);
                    554:                   if (basename[length] == ':')
                    555:                     /* found, so end the string there */
                    556:                     basename[length + 1] = EOS;
                    557:                   else
                    558:                     /* not found, discard the base */
                    559:                     basename[0] = EOS;
                    560:                 }
1.14      cvs       561:             }
                    562:           else
1.19      cvs       563:               basename[0] = EOS;
1.14      cvs       564:         }
1.18      cvs       565:   
                    566:        /*
1.19      cvs       567:        ** Fifth Step, calculate the absolute URL, using the base
1.18      cvs       568:        */
                    569: 
                    570:        ptr = HTParse (tempOrgName, basename, PARSE_ALL);
1.16      cvs       571: 
1.14      cvs       572:        if (ptr)
                    573:         {
                    574:           ptr = HTSimplify (&ptr);
                    575:           strcpy (newName, ptr);
                    576:           HT_FREE (ptr);
                    577:         }
                    578:        else
1.18      cvs       579:           newName[0] = EOS;
1.5       cvs       580:      }
                    581: 
1.18      cvs       582:    /*
1.19      cvs       583:    ** Sixth and last Step:
1.18      cvs       584:    ** Prepare the docname that will refer to this ressource in the
1.19      cvs       585:    ** .amaya directory. If the new URL finishes on DIR_SEP, then use
1.18      cvs       586:    ** noname.html as a default ressource name
                    587:    */
1.19      cvs       588: 
                    589:    if (newName[0] != EOS)
1.5       cvs       590:      {
1.19      cvs       591:        length = strlen (newName) - 1;
1.18      cvs       592:        if (newName[length] == DIR_SEP)
                    593:         {
                    594:           /* docname was not comprised inside the URL, so let's */
                    595:           /* assign the default ressource name */
                    596:           strcpy (docName, "noname.html");
                    597:           /* remove DIR_SEP at the end of complete path */
                    598:           newName[length] = EOS;
                    599:         }
1.14      cvs       600:        else
1.18      cvs       601:         {
                    602:           /* docname is comprised inside the URL */
                    603:           while (length >= 0  && newName[length] != DIR_SEP)
                    604:             length--;
                    605:           if (length < 0)
                    606:             strcpy (docName, newName);
                    607:           else
                    608:             strcpy (docName, &newName[length+1]);
                    609:         }
1.19      cvs       610: 
1.5       cvs       611:      }
1.18      cvs       612:    else
                    613:      docName[0] = EOS;
                    614: } 
1.3       cvs       615: 
1.4       cvs       616: /*----------------------------------------------------------------------
1.9       cvs       617:   IsSameHost                                                         
1.4       cvs       618:   ----------------------------------------------------------------------*/
1.3       cvs       619: #ifdef __STDC__
                    620: boolean             IsSameHost (char *url1, char *url2)
                    621: #else  /* __STDC__ */
                    622: boolean             IsSameHost (url1, url2)
                    623: char               *path;
                    624: #endif /* __STDC__ */
                    625: {
1.5       cvs       626:    char               *basename_ptr1, *basename_ptr2;
                    627:    boolean             result;
1.3       cvs       628: 
1.5       cvs       629:    basename_ptr1 = HTParse (url1, "", PARSE_ACCESS | PARSE_HOST | PARSE_PUNCTUATION);
                    630:    basename_ptr2 = HTParse (url2, "", PARSE_ACCESS | PARSE_HOST | PARSE_PUNCTUATION);
1.3       cvs       631: 
1.5       cvs       632:    if (strcmp (basename_ptr1, basename_ptr2))
1.8       cvs       633:       result = FALSE;
1.5       cvs       634:    else
1.8       cvs       635:       result = TRUE;
1.3       cvs       636: 
1.5       cvs       637:    HT_FREE (basename_ptr1);
                    638:    HT_FREE (basename_ptr2);
1.3       cvs       639: 
1.5       cvs       640:    return (result);
1.3       cvs       641: }
                    642: 
                    643: 
1.4       cvs       644: /*----------------------------------------------------------------------
1.9       cvs       645:   AHTMakeRelativeURL                                                
                    646:   converts url into a relative url to base_url.
                    647:   If succesful, returns the new URL, otherwise, it returns NULL.
                    648:   The caller has to free the new URL.
1.4       cvs       649:   ----------------------------------------------------------------------*/
1.3       cvs       650: #ifdef __STDC__
1.5       cvs       651: char               *AHTMakeRelativeName (char *url, char *base_url)
1.3       cvs       652: #else  /* __STDC__ */
1.5       cvs       653: char               *AHTMakeRelativeName (url, base_url)
                    654: char                url;
                    655: char                base_url;
                    656: 
1.3       cvs       657: #endif /* __STDC__ */
                    658: {
1.5       cvs       659:    char               *base_ptr, *url_ptr;
                    660:    char               *result;
                    661: 
                    662:    /* verify if we are in the same host */
1.3       cvs       663: 
1.5       cvs       664:    base_ptr = HTParse (base_url, "", PARSE_ACCESS | PARSE_HOST | PARSE_PUNCTUATION);
                    665:    url_ptr = HTParse (url, "", PARSE_ACCESS | PARSE_HOST | PARSE_PUNCTUATION);
1.3       cvs       666: 
1.5       cvs       667:    if (!strcmp (base_ptr, url_ptr))
                    668:      {
                    669:        HT_FREE (base_ptr);
                    670:        HT_FREE (url_ptr);
1.3       cvs       671: 
1.5       cvs       672:        /* Normalize the URLs */
1.3       cvs       673: 
1.5       cvs       674:        base_ptr = HTParse (base_url, "", PARSE_ALL);
                    675:        url_ptr = HTParse (url, "", PARSE_ALL);
1.3       cvs       676: 
1.5       cvs       677:        /* Use libwww to make relative name */
1.3       cvs       678: 
1.5       cvs       679:        result = HTRelative (url_ptr, base_ptr);
                    680:        HT_FREE (base_ptr);
                    681:        HT_FREE (url_ptr);
                    682:      }
                    683:    else
                    684:       result = (char *) NULL;
1.3       cvs       685: 
1.5       cvs       686:    return (result);
1.3       cvs       687: }
1.9       cvs       688: 
                    689: 
                    690: 

Webmaster