version 1.147, 2002/09/11 15:23:46
|
version 1.148, 2002/09/12 17:07:14
|
Line 934 char *GetBaseURL (Document doc)
|
Line 934 char *GetBaseURL (Document doc)
|
|
|
if (doc == 0 || !DocumentURLs[doc]) |
if (doc == 0 || !DocumentURLs[doc]) |
return NULL; |
return NULL; |
|
/* the other functions expect basename to have no more than MAX_LENGTH chars */ |
basename = TtaGetMemory (MAX_LENGTH); |
basename = TtaGetMemory (MAX_LENGTH); |
strncpy (basename, DocumentURLs[doc], MAX_LENGTH-1); |
basename[0] = EOS; |
basename[MAX_LENGTH-1] = EOS; |
|
length = MAX_LENGTH -1; |
length = MAX_LENGTH -1; |
/* is it a HTML document ? */ |
|
elType.ElSSchema = TtaGetDocumentSSchema (doc); |
/* do we have a location header? */ |
if (!strcmp (TtaGetSSchemaName (elType.ElSSchema), "HTML")) |
if (DocumentMeta[doc] && DocumentMeta[doc]->full_content_location |
/* it's a HTML document */ |
&& DocumentMeta[doc]->full_content_location[0] != EOS) |
{ |
{ |
/* get the document element */ |
strncpy (basename, DocumentMeta[doc]->full_content_location, MAX_LENGTH-1); |
el = TtaGetMainRoot (doc); |
basename[MAX_LENGTH-1] = EOS; |
/* search the BASE element */ |
length = strlen (basename); |
elType.ElTypeNum = HTML_EL_HEAD; |
} |
el = TtaSearchTypedElement (elType, SearchForward, el); |
else |
if (el) |
{ |
/* there is a HEAD element */ |
/* is it a HTML document ? */ |
{ |
elType.ElSSchema = TtaGetDocumentSSchema (doc); |
/* look for a BASE element within the HEAD */ |
if (!strcmp (TtaGetSSchemaName (elType.ElSSchema), "HTML")) |
elType.ElTypeNum = HTML_EL_BASE; |
/* it's a HTML document */ |
el = TtaSearchTypedElement (elType, SearchInTree, el); |
|
} |
|
if (el) |
|
{ |
{ |
/* The document has a BASE element. Get the HREF attribute of the |
/* get the document element */ |
BASE element */ |
el = TtaGetMainRoot (doc); |
attrType.AttrSSchema = elType.ElSSchema; |
/* search the BASE element */ |
attrType.AttrTypeNum = HTML_ATTR_HREF_; |
elType.ElTypeNum = HTML_EL_HEAD; |
attr = TtaGetAttribute (el, attrType); |
el = TtaSearchTypedElement (elType, SearchForward, el); |
if (attr) |
if (el) |
|
/* there is a HEAD element */ |
{ |
{ |
/* Use the base path of the document */ |
/* look for a BASE element within the HEAD */ |
TtaGiveTextAttributeValue (attr, basename, &length); |
elType.ElTypeNum = HTML_EL_BASE; |
/* base and orgName have to be separated by a DIR_SEP */ |
el = TtaSearchTypedElement (elType, SearchInTree, el); |
length--; |
} |
if (basename[0] != EOS && basename[length] != URL_SEP && |
if (el) |
basename[length] != DIR_SEP) |
{ |
/* verify if the base has the form "protocol://server:port" */ |
/* The document has a BASE element. Get the HREF attribute of the |
|
BASE element */ |
|
attrType.AttrSSchema = elType.ElSSchema; |
|
attrType.AttrTypeNum = HTML_ATTR_HREF_; |
|
attr = TtaGetAttribute (el, attrType); |
|
if (attr) |
{ |
{ |
ptr = AmayaParseUrl (basename, "", AMAYA_PARSE_ACCESS | |
/* Use the base path of the document */ |
AMAYA_PARSE_HOST | |
TtaGiveTextAttributeValue (attr, basename, &length); |
AMAYA_PARSE_PUNCTUATION); |
|
if (ptr && !strcmp (ptr, basename)) |
|
{ |
|
/* it has this form, complete it by adding a URL_STR */ |
|
if (strchr (basename, DIR_SEP)) |
|
strcat (basename, DIR_STR); |
|
else |
|
strcat (basename, URL_STR); |
|
length++; |
|
} |
|
if (ptr) |
|
TtaFreeMemory (ptr); |
|
} |
} |
} |
} |
} |
} |
} |
} |
|
|
|
if (basename[0] != EOS) |
|
{ |
|
/* base and orgName have to be separated by a DIR_SEP */ |
|
length--; |
|
if (basename[0] != EOS && basename[length] != URL_SEP && |
|
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, complete it by adding a URL_STR */ |
|
if (strchr (basename, DIR_SEP)) |
|
strcat (basename, DIR_STR); |
|
else |
|
strcat (basename, URL_STR); |
|
length++; |
|
} |
|
if (ptr) |
|
TtaFreeMemory (ptr); |
|
} |
|
} |
|
|
|
/* there was no base element and no location header, we use the DocumentURL */ |
|
if (basename[0] == EOS) |
|
{ |
|
strncpy (basename, DocumentURLs[doc], MAX_LENGTH-1); |
|
basename[MAX_LENGTH-1] = EOS; |
|
} |
|
|
/* Remove anything after the last DIR_SEP char. If no such char is found, |
/* 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 |
* 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, |
* protocol. If found, end the string there. If neither char is found, |