version 1.31, 1997/06/05 06:40:32
|
version 1.32, 1997/06/18 12:42:45
|
Line 67 char **file;
|
Line 67 char **file;
|
#endif |
#endif |
{ |
{ |
char *curr, *temp; |
char *curr, *temp; |
|
char my_dir_sep; |
|
|
|
if (url && strchr (url, '/')) |
|
{ |
|
my_dir_sep = '/'; |
|
} else { |
|
my_dir_sep = DIR_SEP; |
|
} |
|
|
|
|
if ((url == NULL) || (proto == NULL) || (host == NULL) || |
if ((url == NULL) || (proto == NULL) || (host == NULL) || |
(dir == NULL) || (file == NULL)) |
(dir == NULL) || (file == NULL)) |
Line 96 char **file;
|
Line 105 char **file;
|
/* search the next DIR_SEP indicating the beginning of the file name */ |
/* search the next DIR_SEP indicating the beginning of the file name */ |
do |
do |
curr--; |
curr--; |
while ((curr >= url) && (*curr != DIR_SEP)); |
while ((curr >= url) && (*curr != my_dir_sep)); |
|
|
if (curr < url) |
if (curr < url) |
goto finished; |
goto finished; |
Line 109 char **file;
|
Line 118 char **file;
|
goto finished; |
goto finished; |
|
|
/* search for the DIR_STR indicating the host name start */ |
/* search for the DIR_STR indicating the host name start */ |
while ((curr > url) && ((*curr != DIR_SEP) || (*(curr + 1) != DIR_SEP))) |
while ((curr > url) && ((*curr != my_dir_sep) || (*(curr + 1) != my_dir_sep))) |
curr--; |
curr--; |
|
|
/* if we found it, separate the host name from the directory */ |
/* if we found it, separate the host name from the directory */ |
if ((*curr == DIR_SEP) && (*(curr + 1) == DIR_SEP)) |
if ((*curr == DIR_SEP) && (*(curr + 1) == my_dir_sep)) |
{ |
{ |
*host = temp = curr + 2; |
*host = temp = curr + 2; |
while ((*temp != 0) && (*temp != DIR_SEP)) |
while ((*temp != 0) && (*temp != my_dir_sep)) |
temp++; |
temp++; |
if (*temp == DIR_SEP) |
if (*temp == my_dir_sep) |
{ |
{ |
*temp = EOS; |
*temp = EOS; |
*dir = temp + 1; |
*dir = temp + 1; |
Line 136 char **file;
|
Line 145 char **file;
|
if (curr < url) |
if (curr < url) |
goto finished; |
goto finished; |
|
|
if (*curr == PATH_SEP) |
if (*curr == ':') |
{ |
{ |
*curr = EOS; |
*curr = EOS; |
curr--; |
curr--; |
Line 425 Document doc;
|
Line 434 Document doc;
|
ElementType elType; |
ElementType elType; |
AttributeType attrType; |
AttributeType attrType; |
Attribute attr; |
Attribute attr; |
|
char my_dir_sep; |
|
char *my_dir_str; |
char *ptr, *basename; |
char *ptr, *basename; |
int length; |
int length; |
|
|
Line 449 Document doc;
|
Line 460 Document doc;
|
TtaGiveTextAttributeValue (attr, basename, &length); |
TtaGiveTextAttributeValue (attr, basename, &length); |
/* base and orgName have to be separated by a DIR_SEP */ |
/* base and orgName have to be separated by a DIR_SEP */ |
length--; |
length--; |
if (basename[0] != EOS && basename[length] != DIR_SEP) |
|
|
if (basename [0] != EOS && strchr (basename, '/')) |
|
{ |
|
my_dir_str = "/"; |
|
my_dir_sep = '/'; |
|
} |
|
else |
|
{ |
|
my_dir_str = DIR_STR; |
|
my_dir_sep = DIR_SEP; |
|
} |
|
|
|
|
|
if (basename[0] != EOS && basename[length] != my_dir_sep) |
/* verify if the base has the form "protocol://server:port" */ |
/* verify if the base has the form "protocol://server:port" */ |
{ |
{ |
ptr = AmayaParseUrl (basename, "", AMAYA_PARSE_ACCESS | AMAYA_PARSE_HOST | |
ptr = AmayaParseUrl (basename, "", AMAYA_PARSE_ACCESS | AMAYA_PARSE_HOST | |
Line 457 Document doc;
|
Line 481 Document doc;
|
if (ptr && !strcmp (ptr, basename)) |
if (ptr && !strcmp (ptr, basename)) |
{ |
{ |
/* it has this form, we complete it by adding a DIR_STR */ |
/* it has this form, we complete it by adding a DIR_STR */ |
strcat (basename, DIR_STR); |
strcat (basename, my_dir_str); |
length++; |
length++; |
} |
} |
if (ptr) |
if (ptr) |
TtaFreeMemory (ptr); |
TtaFreeMemory (ptr); |
} |
} |
} |
} |
} |
} |
|
else |
|
{ |
|
if (basename [0] != EOS && strchr (basename, '/')) |
|
{ |
|
my_dir_str = "/"; |
|
my_dir_sep = '/'; |
|
} |
|
else |
|
{ |
|
my_dir_str = DIR_STR; |
|
my_dir_sep = DIR_SEP; |
|
} |
|
|
|
} |
|
|
/* 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 |
Line 473 Document doc;
|
Line 511 Document doc;
|
*/ |
*/ |
length = strlen (basename) - 1; |
length = strlen (basename) - 1; |
/* search for the last DIR_SEP char */ |
/* search for the last DIR_SEP char */ |
while (length >= 0 && basename[length] != DIR_SEP) |
while (length >= 0 && basename[length] != my_dir_sep) |
length--; |
length--; |
if (length >= 0) |
if (length >= 0) |
/* found the last DIR_SEP char, end the string there */ |
/* found the last DIR_SEP char, end the string there */ |
Line 481 Document doc;
|
Line 519 Document doc;
|
else |
else |
/* search for the first PATH_STR char */ |
/* search for the first PATH_STR char */ |
{ |
{ |
for (length = 0; basename[length] != PATH_SEP && |
for (length = 0; basename[length] != ':' && |
basename[length] != EOS; length ++); |
basename[length] != EOS; length ++); |
if (basename[length] == PATH_SEP) |
if (basename[length] == ':') |
/* found, so end the string there */ |
/* found, so end the string there */ |
basename[length + 1] = EOS; |
basename[length + 1] = EOS; |
else |
else |
Line 517 char *docName;
|
Line 555 char *docName;
|
char tempOrgName[MAX_LENGTH]; |
char tempOrgName[MAX_LENGTH]; |
char *ptr; |
char *ptr; |
int length; |
int length; |
|
char my_dir_sep; |
|
char *my_dir_str; |
|
|
if (!newName || !docName) |
if (!newName || !docName) |
return; |
return; |
|
|
|
if (doc != 0) |
|
basename = GetBaseURL (doc); |
|
else |
|
basename = (char *) NULL; |
|
|
|
if (strchr (orgName, '/') || (basename && strchr (basename, '/'))) |
|
{ |
|
my_dir_str = "/"; |
|
my_dir_sep = '/'; |
|
} else { |
|
my_dir_str = DIR_STR; |
|
my_dir_sep = DIR_SEP; |
|
} |
|
|
|
|
/* |
/* |
* 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 |
Line 560 char *docName;
|
Line 615 char *docName;
|
if (ptr && !strcmp (ptr, newName)) |
if (ptr && !strcmp (ptr, newName)) |
{ |
{ |
/* it has this form, we complete it by adding a DIR_STR */ |
/* it has this form, we complete it by adding a DIR_STR */ |
strcat (newName, DIR_STR); |
strcat (newName, my_dir_str); |
} |
} |
if (ptr) |
if (ptr) |
TtaFreeMemory (ptr); |
TtaFreeMemory (ptr); |
Line 572 char *docName;
|
Line 627 char *docName;
|
{ |
{ |
|
|
/* Calculate the absolute URL, using the base or document URL */ |
/* Calculate the absolute URL, using the base or document URL */ |
basename = GetBaseURL (doc); |
|
ptr = AmayaParseUrl (tempOrgName, basename, AMAYA_PARSE_ALL); |
ptr = AmayaParseUrl (tempOrgName, basename, AMAYA_PARSE_ALL); |
TtaFreeMemory (basename); |
TtaFreeMemory (basename); |
if (ptr) |
if (ptr) |
Line 593 char *docName;
|
Line 648 char *docName;
|
if (newName[0] != EOS) |
if (newName[0] != EOS) |
{ |
{ |
length = strlen (newName) - 1; |
length = strlen (newName) - 1; |
if (newName[length] == DIR_SEP) |
if (newName[length] == my_dir_sep) |
{ |
{ |
/* docname was not comprised inside the URL, so let's */ |
/* docname was not comprised inside the URL, so let's */ |
/* assign the default ressource name */ |
/* assign the default ressource name */ |
Line 604 char *docName;
|
Line 659 char *docName;
|
else |
else |
{ |
{ |
/* docname is comprised inside the URL */ |
/* docname is comprised inside the URL */ |
while (length >= 0 && newName[length] != DIR_SEP) |
while (length >= 0 && newName[length] != my_dir_sep) |
length--; |
length--; |
if (length < 0) |
if (length < 0) |
strcpy (docName, newName); |
strcpy (docName, newName); |
Line 767 HTURI *parts;
|
Line 822 HTURI *parts;
|
char * p; |
char * p; |
char * after_access = name; |
char * after_access = name; |
|
|
|
char my_dir_sep; |
|
char my_path_sep; |
|
|
|
if (name && strchr (name, '/')) { |
|
my_dir_sep = '/'; |
|
my_path_sep = ':'; |
|
} else { |
|
my_dir_sep = DIR_SEP; |
|
my_path_sep = ':'; |
|
} |
|
|
|
|
memset(parts, '\0', sizeof(HTURI)); |
memset(parts, '\0', sizeof(HTURI)); |
/* Look for fragment identifier */ |
/* Look for fragment identifier */ |
if ((p = strrchr(name, '#')) != NULL) |
if ((p = strrchr(name, '#')) != NULL) |
Line 777 HTURI *parts;
|
Line 844 HTURI *parts;
|
|
|
for (p=name; *p; p++) |
for (p=name; *p; p++) |
{ |
{ |
if (*p==DIR_SEP || *p=='#' || *p=='?') |
if (*p==my_dir_sep || *p=='#' || *p=='?') |
break; |
break; |
if (*p==PATH_SEP) |
if (*p==':') |
{ |
{ |
*p = 0; |
*p = 0; |
parts->access = after_access; /* Scheme has been specified */ |
parts->access = after_access; /* Scheme has been specified */ |
Line 801 HTURI *parts;
|
Line 868 HTURI *parts;
|
} |
} |
|
|
p = after_access; |
p = after_access; |
if (*p==DIR_SEP) |
if (*p==my_dir_sep) |
{ |
{ |
if (p[1]==DIR_SEP) |
if (p[1]==my_dir_sep) |
{ |
{ |
parts->host = p+2; /* host has been specified */ |
parts->host = p+2; /* host has been specified */ |
*p = 0; /* Terminate access */ |
*p = 0; /* Terminate access */ |
/* look for end of host name if any */ |
/* look for end of host name if any */ |
p = strchr(parts->host,DIR_SEP); |
p = strchr(parts->host,my_dir_sep); |
if (p) |
if (p) |
{ |
{ |
*p=0; /* Terminate host */ |
*p=0; /* Terminate host */ |
Line 858 int wanted;
|
Line 925 int wanted;
|
char *p, *access; |
char *p, *access; |
HTURI given, related; |
HTURI given, related; |
int len; |
int len; |
|
char my_dir_sep; |
|
char *my_dir_str; |
|
|
|
if (strchr (aName, '/') || strchr (relatedName, '/') ) |
|
{ |
|
my_dir_str = "/"; |
|
my_dir_sep = '/'; |
|
} |
|
else |
|
{ |
|
my_dir_str = DIR_STR; |
|
my_dir_sep = DIR_SEP; |
|
} |
|
|
|
|
/* Make working copies of input strings to cut up: */ |
/* Make working copies of input strings to cut up: */ |
return_value = NULL; |
return_value = NULL; |
result[0] = 0; /* Clear string */ |
result[0] = 0; /* Clear string */ |
Line 876 int wanted;
|
Line 957 int wanted;
|
{ |
{ |
strcat (result, access); |
strcat (result, access); |
if(wanted & AMAYA_PARSE_PUNCTUATION) |
if(wanted & AMAYA_PARSE_PUNCTUATION) |
strcat (result, PATH_STR); |
strcat (result, ":"); |
} |
} |
|
|
if (given.access && related.access) |
if (given.access && related.access) |
Line 912 int wanted;
|
Line 993 int wanted;
|
{ |
{ |
/* All is given */ |
/* All is given */ |
if (wanted & AMAYA_PARSE_PUNCTUATION) |
if (wanted & AMAYA_PARSE_PUNCTUATION) |
strcat (result, DIR_STR); |
strcat (result, my_dir_str); |
strcat (result, given.absolute); |
strcat (result, given.absolute); |
} |
} |
else if (related.absolute) |
else if (related.absolute) |
{ |
{ |
/* Adopt path not name */ |
/* Adopt path not name */ |
strcat (result, DIR_STR); |
strcat (result, my_dir_str); |
strcat (result, related.absolute); |
strcat (result, related.absolute); |
if (given.relative) |
if (given.relative) |
{ |
{ |
Line 926 int wanted;
|
Line 1007 int wanted;
|
p = strchr (result, '?'); |
p = strchr (result, '?'); |
if (!p) |
if (!p) |
p=result+strlen(result)-1; |
p=result+strlen(result)-1; |
for (; *p!=DIR_SEP; p--); /* last / */ |
for (; *p!=my_dir_sep; p--); /* last / */ |
/* Remove filename */ |
/* Remove filename */ |
p[1]=0; |
p[1]=0; |
/* Add given one */ |
/* Add given one */ |
Line 941 int wanted;
|
Line 1022 int wanted;
|
strcat (result, related.relative); |
strcat (result, related.relative); |
else |
else |
/* No inheritance */ |
/* No inheritance */ |
strcat (result, DIR_STR); |
strcat (result, my_dir_str); |
} |
} |
|
|
if (wanted & AMAYA_PARSE_ANCHOR) |
if (wanted & AMAYA_PARSE_ANCHOR) |
Line 995 char *host;
|
Line 1076 char *host;
|
char *path; |
char *path; |
char *access = host-3; |
char *access = host-3; |
|
|
while (access>*filename && *(access-1)!=DIR_SEP) /* Find access method */ |
char my_dir_sep; |
|
char *my_dir_str; |
|
|
|
|
|
if (*filename && strchr (*filename, '/')) { |
|
my_dir_str = "/"; |
|
my_dir_sep = '/'; |
|
} |
|
else { |
|
my_dir_str = DIR_STR; |
|
my_dir_sep = DIR_SEP; |
|
} |
|
|
|
while (access>*filename && *(access-1)!= my_dir_sep) /* Find access method */ |
access--; |
access--; |
if ((path = strchr(host, DIR_SEP)) == NULL) /* Find path */ |
if ((path = strchr(host, my_dir_sep)) == NULL) /* Find path */ |
path = host + strlen(host); |
path = host + strlen(host); |
if ((strptr = strchr(host, '@')) != NULL && strptr<path) /* UserId */ |
if ((strptr = strchr(host, '@')) != NULL && strptr<path) /* UserId */ |
host = strptr; |
host = strptr; |
if ((port = strchr(host, PATH_SEP)) != NULL && port>path) /* Port number */ |
if ((port = strchr(host, ':')) != NULL && port>path) /* Port number */ |
port = NULL; |
port = NULL; |
|
|
strptr = host; /* Convert to lower-case */ |
strptr = host; /* Convert to lower-case */ |
Line 1024 char *host;
|
Line 1118 char *host;
|
} |
} |
/* Chop off port if `:', `:80' (http), `:70' (gopher), or `:21' (ftp) */ |
/* Chop off port if `:', `:80' (http), `:70' (gopher), or `:21' (ftp) */ |
if (port) { |
if (port) { |
if (!*(port+1) || *(port+1)==DIR_SEP) { |
if (!*(port+1) || *(port+1)==my_dir_sep) { |
if (!newname) { |
if (!newname) { |
char *orig=port, *dest=port+1; |
char *orig=port, *dest=port+1; |
while((*orig++ = *dest++)); |
while((*orig++ = *dest++)); |
} |
} |
} else if ((!strncmp(access, "http", 4) && |
} else if ((!strncmp(access, "http", 4) && |
(*(port+1)=='8'&&*(port+2)=='0'&&(*(port+3)==DIR_SEP||!*(port+3)))) || |
(*(port+1)=='8'&&*(port+2)=='0'&&(*(port+3)==my_dir_sep||!*(port+3)))) || |
(!strncmp(access, "gopher", 6) && |
(!strncmp(access, "gopher", 6) && |
(*(port+1)=='7'&&*(port+2)=='0'&&(*(port+3)==DIR_SEP||!*(port+3)))) || |
(*(port+1)=='7'&&*(port+2)=='0'&&(*(port+3)==my_dir_sep||!*(port+3)))) || |
(!strncmp(access, "ftp", 3) && |
(!strncmp(access, "ftp", 3) && |
(*(port+1)=='2'&&*(port+2)=='1'&&(*(port+3)==DIR_SEP||!*(port+3))))) { |
(*(port+1)=='2'&&*(port+2)=='1'&&(*(port+3)==my_dir_sep||!*(port+3))))) { |
if (!newname) { |
if (!newname) { |
char *orig=port, *dest=port+3; |
char *orig=port, *dest=port+3; |
while((*orig++ = *dest++)); |
while((*orig++ = *dest++)); |
Line 1059 char *host;
|
Line 1153 char *host;
|
|
|
/*---------------------------------------------------------------------- |
/*---------------------------------------------------------------------- |
SimplifyUrl: simplify a URI |
SimplifyUrl: simplify a URI |
A URI is allowed to contain the seqeunce xxx/../ which may be |
A URI is allowed to contain the sequence xxx/../ which may be |
replaced by "" , and the seqeunce "/./" which may be replaced by DIR_STR. |
replaced by "" , and the sequence "/./" which may be replaced by DIR_STR. |
Simplification helps us recognize duplicate URIs. |
Simplification helps us recognize duplicate URIs. |
|
|
Thus, /etc/junk/../fred becomes /etc/fred |
Thus, /etc/junk/../fred becomes /etc/fred |
Line 1093 char **url;
|
Line 1187 char **url;
|
char *newptr, *access; |
char *newptr, *access; |
char *orig, *dest, *end; |
char *orig, *dest, *end; |
|
|
|
char my_dir_sep; |
|
char *my_dir_str; |
|
|
|
|
if (!url || !*url) |
if (!url || !*url) |
return; |
return; |
|
|
|
if (strchr (*url, '/')) |
|
{ |
|
my_dir_str = "/"; |
|
my_dir_sep = '/'; |
|
} |
|
else |
|
{ |
|
my_dir_str = DIR_STR; |
|
my_dir_sep = DIR_SEP; |
|
} |
|
|
|
|
/* Find any scheme name */ |
/* Find any scheme name */ |
if ((path = strstr(*url, "://")) != NULL) |
if ((path = strstr(*url, "://")) != NULL) |
{ /* Find host name */ |
{ /* Find host name */ |
Line 1114 char **url;
|
Line 1224 char **url;
|
else |
else |
path = *url; |
path = *url; |
|
|
if (*path == DIR_SEP && *(path+1)==DIR_SEP) |
if (*path == my_dir_sep && *(path+1)==my_dir_sep) |
/* Some URLs start //<foo> */ |
/* Some URLs start //<foo> */ |
path += 1; |
path += 1; |
else if (!strncmp(path, "news:", 5)) |
else if (!strncmp(path, "news:", 5)) |
Line 1142 char **url;
|
Line 1252 char **url;
|
p = path; |
p = path; |
while (p < end) |
while (p < end) |
{ |
{ |
if (*p==DIR_SEP) |
if (*p==my_dir_sep) |
{ |
{ |
if (p > *url && *(p+1) == '.' && (*(p+2) == DIR_SEP || !*(p+2))) |
if (p > *url && *(p+1) == '.' && (*(p+2) == my_dir_sep || !*(p+2))) |
{ |
{ |
orig = p + 1; |
orig = p + 1; |
dest = (*(p+2)!=DIR_SEP) ? p+2 : p+3; |
dest = (*(p+2)!=my_dir_sep) ? p+2 : p+3; |
while ((*orig++ = *dest++)); /* Remove a slash and a dot */ |
while ((*orig++ = *dest++)); /* Remove a slash and a dot */ |
end = orig - 1; |
end = orig - 1; |
} |
} |
else if (*(p+1)=='.' && *(p+2)=='.' && (*(p+3)==DIR_SEP || !*(p+3))) |
else if (*(p+1)=='.' && *(p+2)=='.' && (*(p+3)==my_dir_sep || !*(p+3))) |
{ |
{ |
newptr = p; |
newptr = p; |
while (newptr>path && *--newptr!=DIR_SEP); /* prev slash */ |
while (newptr>path && *--newptr!=my_dir_sep); /* prev slash */ |
if (strncmp(newptr, "/../", 4)) |
if (strncmp(newptr, "/../", 4)) |
{ |
{ |
orig = newptr + 1; |
orig = newptr + 1; |
dest = (*(p+3)!=DIR_SEP) ? p+3 : p+4; |
dest = (*(p+3)!=my_dir_sep) ? p+3 : p+4; |
while ((*orig++ = *dest++)); /* Remove /xxx/.. */ |
while ((*orig++ = *dest++)); /* Remove /xxx/.. */ |
end = orig-1; |
end = orig-1; |
/* Start again with prev slash */ |
/* Start again with prev slash */ |
Line 1167 char **url;
|
Line 1277 char **url;
|
else |
else |
p++; |
p++; |
} |
} |
else if (*(p+1) == DIR_SEP) |
else if (*(p+1) == my_dir_sep) |
{ |
{ |
while (*(p+1) == DIR_SEP) |
while (*(p+1) == my_dir_sep) |
{ |
{ |
orig = p; |
orig = p; |
dest = p + 1; |
dest = p + 1; |
Line 1280 char *relatedName;
|
Line 1390 char *relatedName;
|
for (; *p && (*p == *q); p++, q++) |
for (; *p && (*p == *q); p++, q++) |
{ |
{ |
/* Find extent of match */ |
/* Find extent of match */ |
if (*p == PATH_SEP) |
if (*p == ':') |
after_access = p + 1; |
after_access = p + 1; |
if (*p == DIR_SEP) |
if (*p == DIR_SEP) |
{ |
{ |