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