version 1.17, 1997/02/04 12:13:42
|
version 1.18, 1997/02/04 17:52:57
|
Line 396 char *docName;
|
Line 396 char *docName;
|
#endif /* __STDC__ */ |
#endif /* __STDC__ */ |
{ |
{ |
char basename[MAX_LENGTH]; |
char basename[MAX_LENGTH]; |
char tempname[MAX_LENGTH]; |
char tempOrgName[MAX_LENGTH]; |
int i; |
|
char *ptr; |
char *ptr; |
char *basename_ptr; |
|
int basename_flag; |
|
Element el; |
Element el; |
ElementType elType; |
ElementType elType; |
AttributeType attrType; |
AttributeType attrType; |
Attribute attrHREF; |
Attribute attrHREF = NULL; |
int length; |
int length; |
|
|
/* Fix up orgName, by erasing leading and trailing white space */ |
|
if (!newName || !docName) |
if (!newName || !docName) |
return; |
return; |
|
|
|
/* |
|
** First Step: Clean orgName |
|
** Make sure we have a complete orgName, without any leading or trailing |
|
** white spaces, or trailinbg new lines |
|
*/ |
|
|
ptr = orgName; |
ptr = orgName; |
while (*ptr == ' ' && *ptr++ != EOS) ; |
/* skip leading white space and new line characters */ |
strcpy (tempname, ptr); |
while ((*ptr == ' ' || *ptr == '\n') && *ptr++ != EOS); |
ptr = strchr (tempname, ' '); |
strcpy (tempOrgName, ptr); |
|
/* clean trailing white space */ |
|
ptr = strchr (tempOrgName, ' '); |
|
if (ptr) |
|
*ptr = EOS; |
|
/* clean trailing new lines */ |
|
ptr = strchr (tempOrgName, '\n'); |
if (ptr) |
if (ptr) |
*ptr = EOS; |
*ptr = EOS; |
|
|
if (IsW3Path (tempname)) |
/* |
/* the name is complete */ |
** Second Step: make orgName a complete URL |
strcpy (newName, tempname); |
** If the URL does not include a protocol, then |
|
** try to calculate one using the doc's base element |
|
** (if it exists), |
|
*/ |
|
|
|
if (tempOrgName[0] == EOS || IsW3Path (tempOrgName) || doc == 0) |
|
/* the name is complete, go to the Fifth Step */ |
|
strcpy (newName, tempOrgName); |
else |
else |
{ |
{ |
if (doc == 0) |
/* take into account the BASE element. */ |
{ |
length = MAX_LENGTH; |
basename_ptr = ""; |
/* get the root element */ |
basename_flag = FALSE; |
el = TtaGetMainRoot (doc); |
} |
|
else |
|
{ |
|
/* take into account the BASE element. */ |
|
length = MAX_LENGTH; |
|
/* get the root element */ |
|
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 |
|
** 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 */ |
** The document has a BASE element |
TtaGiveTextAttributeValue (attrHREF, basename, &length); |
** Get the HREF attribute of the BASE Element |
/* base and orgName have to be separated by a DIR_SEP */ |
*/ |
if (basename[0] != EOS && basename[length] != '/') |
attrType.AttrSSchema = elType.ElSSchema; |
/* verify if the base has the form "protocol://server:port" */ |
attrType.AttrTypeNum = HTML_ATTR_HREF_; |
|
attrHREF = TtaGetAttribute (el, attrType); |
|
if (attrHREF) |
|
{ |
{ |
/* Use the base path of the document */ |
ptr = HTParse (basename, "", PARSE_ACCESS | PARSE_HOST | |
TtaGiveTextAttributeValue (attrHREF, basename, &length); |
PARSE_PUNCTUATION); |
/* base and orgName have to be separated by a DIR_SEP */ |
if (ptr && !strcmp (ptr, basename)) |
if (basename[strlen (basename) - 1] != DIR_SEP) |
|
{ |
{ |
if (IsHTMLName (basename)) |
/* it has this form, we complete it by adding a "/" */ |
{ |
strcat (basename, "/"); |
/* remove the document name from basename */ |
length++; |
length = strlen (basename) - 1; |
|
while (basename[length] != DIR_SEP) |
|
basename[length--] = EOS; |
|
} |
|
else if (tempname[0] != DIR_SEP) |
|
strcat (basename, DIR_STR); |
|
} |
} |
|
if (ptr) |
|
HT_FREE (ptr); |
} |
} |
else |
/* search for the first DIR_SEP char */ |
basename[0] = EOS; |
while (length >= 0 && basename[length] != DIR_SEP) |
|
basename[length--] = EOS; |
} |
} |
else |
else |
basename[0] = EOS; |
basename[0] = EOS; |
|
} |
if (basename[0] == EOS) |
else |
|
basename[0] = EOS; |
|
|
|
/* |
|
** Third 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]) |
{ |
{ |
/* there is no BASE element in that document. */ |
strcpy (basename, DocumentURLs[(int) doc]); |
if (DocumentURLs[(int) doc]) |
/* base and orgName have to be separated by a DIR_SEP */ |
{ |
length = strlen (basename) - 1; |
basename_ptr = HTParse (DocumentURLs[(int) doc], "", PARSE_ALL); |
/* search for the first DIR_SEP char */ |
basename_flag = TRUE; |
while (length >= 0 && basename[length] != DIR_SEP) |
} |
basename[length--] = EOS; |
else |
|
{ |
|
basename_ptr = ""; |
|
basename_flag = FALSE; |
|
} |
|
} |
} |
else |
else |
{ |
{ |
basename_ptr = HTParse (basename, "", PARSE_ALL); |
basename [0] = EOS; |
basename_flag = TRUE; |
|
} |
} |
} |
} |
|
|
|
/* |
|
** Fourth Step, calculate the absolute URL, using the base |
|
*/ |
|
|
|
ptr = HTParse (tempOrgName, basename, PARSE_ALL); |
|
|
if (tempname[0] == '/' && doc) |
|
ptr = HTParse (tempname, basename_ptr, PARSE_ACCESS | PARSE_PUNCTUATION | PARSE_HOST); |
|
else |
|
ptr = HTParse (tempname, basename_ptr, PARSE_ALL); |
|
if (basename_flag) |
|
HT_FREE (basename_ptr); |
|
if (ptr) |
if (ptr) |
{ |
{ |
ptr = HTSimplify (&ptr); |
ptr = HTSimplify (&ptr); |
Line 505 char *docName;
|
Line 521 char *docName;
|
HT_FREE (ptr); |
HT_FREE (ptr); |
} |
} |
else |
else |
newName[0] = EOS; |
newName[0] = EOS; |
} |
} |
|
|
i = strlen (newName) - 1; |
/* |
if (i > 0) |
** Fifth step: |
|
** Prepare the docname that will refer to this ressource in the |
|
** .amaya directory. If the new URL finishes on "/", then use |
|
** noname.html as a default ressource name |
|
*/ |
|
length = strlen (newName) - 1; |
|
if (length > 0) |
{ |
{ |
/* search now the document name */ |
if (newName[length] == DIR_SEP) |
ptr = strrchr (newName, DIR_SEP); |
{ |
if (ptr) |
/* docname was not comprised inside the URL, so let's */ |
ptr++; |
/* assign the default ressource name */ |
if (ptr && *ptr != EOS) |
strcpy (docName, "noname.html"); |
strcpy (docName, ptr); |
/* remove DIR_SEP at the end of complete path */ |
|
newName[length] = EOS; |
|
} |
else |
else |
/* the docname was not comprised inside the URL, so let's */ |
{ |
/* assign a "noname.html" name :) */ |
/* docname is comprised inside the URL */ |
strcpy (docName, "noname.html"); |
while (length >= 0 && newName[length] != DIR_SEP) |
|
length--; |
/* remove DIR_SEP at the end of complete path */ |
if (length < 0) |
if (newName[i] == DIR_SEP) |
strcpy (docName, newName); |
newName[i] = EOS; |
else |
|
strcpy (docName, &newName[length+1]); |
|
} |
} |
} |
} |
else |
|
docName[0] = EOS; |
|
} |
|
|
/*---------------------------------------------------------------------- |
/*---------------------------------------------------------------------- |
IsSameHost |
IsSameHost |