ALEX support in libwww2 (Mosaic)
assar@nada.kth.se
Date: Mon, 13 Dec 93 07:40:12 +0100
From: assar@nada.kth.se
Message-id: <9312130640.AA03296@kai.nada.kth.se>
To: alex-servers@CS.CMU.EDU, www-talk@www0.cern.ch
Subject: ALEX support in libwww2 (Mosaic)
Cc: bg@nada.kth.se
Content-Length: 6523
> Has anyone hacked mosaic to use Alex?
>
> A couple users have pointed out that it would be very nice
> to have a flag to tell mosaic to use /alex for FTPable
> files.
>
> Mosaic does not cache files and does not seem to even
> cache open FTP connections.
>
> -- Vince
Here are patches to use Alex in libwww2 (which is used by Mosaic)
This patch is also ftp-able as
file://ftp.nada.kth.se/pub/Mosaic-2.1.alex.patch
After applying this patch all URLs with file: will go through Alex and
all ftp: will use normal FTP.
(Alex is a transparent way of doing anonymous FTP with caching. FTP to
alex.sp.cs.cmu.edu for more information and source.)
All comments, bugreports and fixes are welcome.
------------------------------ cut here ------------------------------
Index: Makefile
===================================================================
RCS file: /afs/nada.kth.se/misc/projects/mosaic/MASTER/Mosaic/Makefile,v
retrieving revision 1.1.1.1
diff -c -r1.1.1.1 Makefile
*** 1.1.1.1 1993/12/13 01:50:48
--- Makefile 1993/12/13 04:41:11
***************
*** 150,156 ****
#### . If you want to define the default Mosaic documentation directory
#### (should be a URL), set -DDOCS_DIRECTORY_DEFAULT=\\\"url\\\"
#### . Other things you can define are spelled out in src/mosaic.h.
! customflags =
--- 150,156 ----
#### . If you want to define the default Mosaic documentation directory
#### (should be a URL), set -DDOCS_DIRECTORY_DEFAULT=\\\"url\\\"
#### . Other things you can define are spelled out in src/mosaic.h.
! customflags = -DALEX
***************
*** 203,209 ****
libwww2::
@echo --- Building libwww2
! cd libwww2; make CC=$(CC) RANLIB=$(RANLIB) CFLAGS="$(CFLAGS) $(knrflag) $(waisflags)"
src::
@echo --- Building src
--- 203,209 ----
libwww2::
@echo --- Building libwww2
! cd libwww2; make CC=$(CC) RANLIB=$(RANLIB) CFLAGS="$(CFLAGS) $(knrflag) $(waisflags) $(customflags)"
src::
@echo --- Building src
Index: libwww2/HTFile.c
===================================================================
RCS file: /afs/nada.kth.se/misc/projects/mosaic/MASTER/Mosaic/libwww2/HTFile.c,v
retrieving revision 1.1.1.1
diff -c -r1.1.1.1 HTFile.c
*** 1.1.1.1 1993/12/13 01:51:41
--- HTFile.c 1993/12/13 04:44:24
***************
*** 833,839 ****
--- 833,899 ----
}
+ #ifdef ALEX
+ #define ALEX_PREFIX "/alex/"
+
+ /*
+ ** Return an alexified version of the nodename.
+ */
+
+ PRIVATE char * alexifynode ARGS1 (CONST char *, nodename)
+ {
+ char * result = malloc(strlen(nodename) + 1);
+ char * ournode;
+ char * dot;
+
+ StrAllocCopy(ournode, nodename);
+ result[0] = '\0';
+
+ while(dot = strrchr(ournode, '.')) {
+ strcat(result, dot+1);
+ strcat(result, "/");
+ *dot = '\0';
+ }
+ strcat(result, ournode);
+ free(ournode);
+ return result;
+ }
+
+ /* Convert an address to alex.
+ **
+ */
+
+ PRIVATE char * HTAlexName
+ ARGS1 (
+ char *, addr
+ )
+ {
+ char * newname;
+ char * filename;
+ char * nodename;
+ char * newaddr;
+ char * alexnode;
+
+ StrAllocCopy(newname, addr);
+ filename=HTParse(newname, "", PARSE_PATH|PARSE_PUNCTUATION);
+ nodename=HTParse(newname, "", PARSE_HOST);
+ free(newname);
+ alexnode = alexifynode(nodename);
+ free(nodename);
+ newaddr = malloc(strlen(ALEX_PREFIX)
+ + strlen(alexnode) + strlen(filename) + 1);
+ strcpy(newaddr, ALEX_PREFIX);
+ strcat(newaddr, alexnode);
+ strcat(newaddr, filename);
+ free(alexnode);
+ free(filename);
+ return newaddr;
+ }
+
+
+ #endif /* ALEX */
+
/* Load a document
** ---------------
**
***************
*** 860,865 ****
--- 920,926 ----
char * newname=0; /* Simplified name of file */
HTAtom * encoding; /* @@ not used yet */
int compressed;
+ int alexp;
extern char *HTgeticonname(HTFormat, char *);
/* Reduce the filename to a basic form (hopefully unique!)
***************
*** 895,901 ****
}
#else
- free(filename);
/* For unix, we try to translate the name into the name of a transparently
** mounted file.
--- 956,961 ----
***************
*** 907,916 ****
--- 967,988 ----
{ /* try local file system */
char * localname = HTLocalName(addr);
+ char * officialname = localname;
struct stat dir_info;
if (!localname)
+ #ifdef ALEX
+ {
+ alexp = 1;
+ free(localname);
+ localname = HTAlexName(addr);
+ officialname = filename;
+ }
+ #else
goto suicide;
+ #endif /* ALEX */
+ else
+ free(filename);
#ifdef GOT_READ_DIR
***************
*** 1106,1111 ****
--- 1178,1188 ----
HT = HText_new();
HText_beginAppend(HT);
+ #ifdef ALEX
+ if(alexp)
+ HText_appendText(HT, "<H1>Alex Directory ");
+ else
+ #endif /* ALEX */
HText_appendText(HT, "<H1>Local Directory ");
HText_appendText(HT, localname);
HText_appendText(HT, "</H1>\n");
***************
*** 1130,1138 ****
if(strcmp(dataptr,"..") == 0)
{
! if(strcmp(localname,"/") != 0)
{
! strcpy(buffer,localname);
ptr = strrchr(buffer, '/');
--- 1207,1215 ----
if(strcmp(dataptr,"..") == 0)
{
! if(strcmp(officialname,"/") != 0)
{
! strcpy(buffer,officialname);
ptr = strrchr(buffer, '/');
***************
*** 1163,1169 ****
if(stat(filepath, &statbuf) == -1) continue;
HText_appendText(HT,"<DD><A HREF=\"");
! HText_appendText (HT, localname);
if(localname[strlen(localname)-1] != '/')
{
--- 1240,1246 ----
if(stat(filepath, &statbuf) == -1) continue;
HText_appendText(HT,"<DD><A HREF=\"");
! HText_appendText (HT, officialname);
if(localname[strlen(localname)-1] != '/')
{
***************
*** 1265,1270 ****
--- 1342,1348 ----
/* Now, as transparently mounted access has failed, we try FTP.
*/
suicide:
+ free(filename);
return HTFTPLoad(addr, anchor, format_out, sink);
}