On Wed, May 03, 2000 at 09:31:08PM +0200, Nils Lohner wrote:
> Hello Alexander...
>   I'm using lftp with hftp://address and the file listings are still strange
> sometimes.  I know you once sent me an email on how to get the raw results
> of the ls command, but I don't remember- something with cat I think... can
> you give that to me again?  Otherwise, if you tell me where to look, I may
> take a look at the code...
>
> lftp [EMAIL PROTECTED]:~> ls
> drwxr-xr-x  --  /
> -rw-rw-r--   1 ftpuser  ftp        8510079 Mar 10 11:03 ~/FASTCA2BA_W5.pdf
>
> Also: put doesn't work in hftp:
> lftp [EMAIL PROTECTED]:~> put ~/.cshrc -o test
> put: Access failed: 501 Method Not Implemented (.cshrc)

I recommend to use squid instead of apache as your proxy server, from
the raw html you sent in other letter I could notice at least two bugs
in it, and as you mentioned above, apache does not support PUT to ftp.

Anyway, I could make a workaround. Patch for testing is attached.

--
   Alexander.                       (never mind that noise you heard)
Index: HttpDir.cc
===================================================================
RCS file: /home/lav/cvsroot/lftp/src/HttpDir.cc,v
retrieving revision 1.44
diff -u -r1.44 HttpDir.cc
--- HttpDir.cc  2000/03/20 16:34:59     1.44
+++ HttpDir.cc  2000/05/04 14:38:50
@@ -287,6 +287,8 @@
    if(tag_scan->tag==0)
       return tag_len;  // not interesting
 
+   bool hftp=(prefix && !xstrcmp(prefix->proto,"hftp"));
+
    // ok, found the target.
 
    decode_amps(link_target);  // decode all & and similar
@@ -296,7 +298,20 @@
       if(base_href)
       {
         xfree(*base_href);
-        *base_href=xstrdup(link_target);
+        *base_href=xstrdup(link_target,+2);
+        if(hftp)
+        {
+           // workaround apache proxy bugs.
+           char *t=strstr(*base_href,";type=");
+           if(t && t[6] && t[7]=='/' && t[8]==0)
+              *t=0;
+           char *p=*base_href+url::path_index(*base_href);
+           if(p[0]=='/' && p[1]=='/')
+           {
+              memmove(p+4,p+2,strlen(p+2)+1);
+              memcpy(p+1,"%2F",3);
+           }
+        }
       }
       return tag_len;
    }
@@ -358,11 +373,7 @@
       if(!prefix)
         return tag_len;        // no way
 
-      const char *pproto=prefix->proto;
-      if(!xstrcmp(pproto,"hftp"))
-        pproto++;
-
-      if(xstrcmp(link_url.proto,pproto)
+      if(xstrcmp(link_url.proto,prefix->proto+hftp)
       || xstrcmp(link_url.host,prefix->host)
       || xstrcmp(link_url.user,prefix->user)
       || xstrcmp(link_url.port,prefix->port))
@@ -399,16 +410,23 @@
    else
       strcpy(link_target,link_url.path);
 
+   if(link_target[0]=='/' && link_target[1]=='/' && hftp)
+   {
+      // workaround for apache proxy.
+      link_target++;
+   }
+
    int link_len=strlen(link_target);
    bool is_directory=(link_len>0 && link_target[link_len-1]=='/');
    if(is_directory && link_len>1)
       link_target[--link_len]=0;
 
-   if(prefix && prefix->path)
+   if(prefix)
    {
       const char *p_path=prefix->path;
+      if(p_path==0)
+        p_path="~";
       int p_len=strlen(p_path);
-
       if(p_len==1 && p_path[0]=='/' && link_target[0]=='/')
       {
         if(link_len>1)
Index: xmalloc.h
===================================================================
RCS file: /home/lav/cvsroot/lftp/src/xmalloc.h,v
retrieving revision 1.7
diff -u -r1.7 xmalloc.h
--- xmalloc.h   2000/02/12 17:45:41     1.7
+++ xmalloc.h   2000/05/04 13:25:02
@@ -34,7 +34,7 @@
 
 void *xmalloc(size_t);
 void *xrealloc(void *,size_t);
-char *xstrdup(const char *s);
+char *xstrdup(const char *s,int spare=0);
 #define alloca_strdup(s) ((s)?strcpy((char*)alloca(strlen((s))+1),(s)):0)
 
 static inline void *xmemdup(const void *m,int len)
Index: xmalloc.cc
===================================================================
RCS file: /home/lav/cvsroot/lftp/src/xmalloc.cc,v
retrieving revision 1.7
diff -u -r1.7 xmalloc.cc
--- xmalloc.cc  2000/02/12 19:56:19     1.7
+++ xmalloc.cc  2000/05/04 13:24:53
@@ -86,7 +86,7 @@
    free(p);
 }
 
-char *xstrdup(const char *s)
+char *xstrdup(const char *s,int spare)
 {
    if(!s)
       return 0;
@@ -94,7 +94,7 @@
    printf("xstrdup \"%s\"\n",s);
 #endif
    int len=strlen(s)+1;
-   char *mem=(char*)xmalloc(len);
+   char *mem=(char*)xmalloc(len+spare);
    memcpy(mem,s,len);
    return mem;
 }

Reply via email to