Re: lftp 3.1 : problem with webdav MOVE

2005-03-09 Thread nodens
Alexander V. Lukyanov wrote:

 For testing if the destination is a directory, it is necessary to modify

mvJob class, not Http. You could use GetFileInfo class and LsCache::IsDirectory
for quick cache lookup.

  

I wouldn't have found this myself, thanks :)

2) when moving a file, lftp wait forever after receiving the response
  

from server (unless it is an error). The command must be interrupted


with ctrl+c :
[snip]
  

attached is a patch that fixes this issue. Hope I didn't messed up, I'm a
beginner both with lftp and C++ ;)



Thanks for the patch. I have fixed it differently, though.
  

Everything works well now (as far as I have tested).

I liked my method, because we never entered the RECEIVING_BODY state
that way, but yours works perfectly, and you make decisions after all :)

Best regards and thanks again.


-- 
Clément Hermann


Re: lftp 3.1 : problem with webdav MOVE

2005-03-06 Thread Clement Hermann
Hi again,
Alexander V. Lukyanov wrote:
Does this patch fix the problem?
 

Sort of. This particular problem is fixed, but two other problems show up :
1) The Destination: header must be the complete path to new destination. 
Giving a collection (directory) as argument will overwrite the collection.

so, if I want to move testfile in directory /test, Destination: must 
be as follow :

Destination: http://[EMAIL PROTECTED]/test/testfile
So we must first test if the destination is a directory, and appending 
the filename to the directory URI eventually. At least, this must be 
done to provide a consistent interface accross protocols. This is a 
webdav limitation but the clients I have tested do it that way. We could 
imagine a rename command wich do overwrite the destination if it's a 
directory, but I don't see it as a must-have.
Concerning this, I might be able to provide a patch, but I need some advice: 
how should we test that the destination is a directory, for maximum 
consistency ? By creating a boolean function (say, IsDirectory) and 
modifying the RENAME case in Http::Send ?

2) when moving a file, lftp wait forever after receiving the response 
from server (unless it is an error). The command must be interrupted 
with ctrl+c :
[snip]
attached is a patch that fixes this issue. Hope I didn't messed up, I'm a 
beginner both with lftp and C++ ;)

Best regards,
--
Clément 'nodens' Hermann
- L'air pur ? c'est pas en RL, ça ? c'est pas hors charte ?
Jean in L'Histoire des Pingouins, http://tnemeth.free.fr/fmbl/linuxsf/
--- ../lftp-3.1.0.patched/src/Http.cc	2005-03-07 00:33:42.0 +0100
+++ src/Http.cc	2005-03-07 00:30:21.0 +0100
@@ -60,6 +60,7 @@
 #define H_PARTIAL(x)((x) == 206)
 #define H_REDIRECTED(x) (((x) == 301) || ((x) == 302))
 #define H_EMPTY(x)	(((x) == 204) || ((x) == 205))
+#define H_CREATED(x)	((x) == 201)
 #define H_CONTINUE(x)	((x) == 100 || (x) == 102)
 #define H_REQUESTED_RANGE_NOT_SATISFIABLE(x) ((x) == 416)
 
@@ -1365,6 +1366,13 @@
   if(H_EMPTY(status_code)  body_size0)
 	 body_size=0;
 
+  // 201 Created
+  if(H_CREATED(status_code))
+  {
+	 state=DONE;
+ return MOVED;
+  }
+
   if(H_REDIRECTED(status_code))
   {
 	 // check if it is redirection to the same server


Re: lftp 3.1 : problem with webdav MOVE

2005-03-06 Thread Clement Hermann
forgot to paste the result :
lftp [EMAIL PROTECTED]:/extended/upload/test mv dir/testfile testfile
--- MOVE /extended/upload/test/dir/testfile HTTP/1.1
--- Host: webdav.example.com
--- User-Agent: lftp/3.1.0
--- Accept: */*
--- Destination: 
https://[EMAIL PROTECTED]/extended/upload/test/testfile
--- Authorization: Basic bGludXhtb3ZpZXotZXh0ZW5kZWQ6ZS1qYWhzdXh4IQ==
--- Connection: keep-alive
---
--- HTTP/1.1 201 Created
--- Date: Sun, 06 Mar 2005 23:54:36 GMT
--- Server: Apache/1.3.33 (Debian GNU/Linux) PHP/4.3.10-7 mod_ssl/2.8.22 
OpenSSL/0.9.7d mod_perl/1.29 DAV/1.0.3
--- Keep-Alive: timeout=15, max=96
--- Connection: Keep-Alive
--- Transfer-Encoding: chunked
--- Content-Type: text/html; charset=iso-8859-1
---
file renamed
lftp [EMAIL PROTECTED]:/extended/upload/test


Clement Hermann wrote:
Hi again,
Alexander V. Lukyanov wrote:
Does this patch fix the problem?
 

Sort of. This particular problem is fixed, but two other problems show 
up :

1) The Destination: header must be the complete path to new 
destination. Giving a collection (directory) as argument will 
overwrite the collection.

so, if I want to move testfile in directory /test, Destination: must 
be as follow :

Destination: http://[EMAIL PROTECTED]/test/testfile
So we must first test if the destination is a directory, and appending 
the filename to the directory URI eventually. At least, this must be 
done to provide a consistent interface accross protocols. This is a 
webdav limitation but the clients I have tested do it that way. We 
could imagine a rename command wich do overwrite the destination if 
it's a directory, but I don't see it as a must-have.

Concerning this, I might be able to provide a patch, but I need some 
advice: how should we test that the destination is a directory, for 
maximum consistency ? By creating a boolean function (say, IsDirectory) 
and modifying the RENAME case in Http::Send ?

2) when moving a file, lftp wait forever after receiving the response 
from server (unless it is an error). The command must be interrupted 
with ctrl+c :
[snip]

attached is a patch that fixes this issue. Hope I didn't messed up, I'm 
a beginner both with lftp and C++ ;)

Best regards,

--- ../lftp-3.1.0.patched/src/Http.cc	2005-03-07 00:33:42.0 +0100
+++ src/Http.cc	2005-03-07 00:30:21.0 +0100
@@ -60,6 +60,7 @@
 #define H_PARTIAL(x)((x) == 206)
 #define H_REDIRECTED(x) (((x) == 301) || ((x) == 302))
 #define H_EMPTY(x)	(((x) == 204) || ((x) == 205))
+#define H_CREATED(x)	((x) == 201)
 #define H_CONTINUE(x)	((x) == 100 || (x) == 102)
 #define H_REQUESTED_RANGE_NOT_SATISFIABLE(x) ((x) == 416)
 
@@ -1365,6 +1366,13 @@
   if(H_EMPTY(status_code)  body_size0)
 	 body_size=0;
 
+  // 201 Created
+  if(H_CREATED(status_code))
+  {
+	 state=DONE;
+ return MOVED;
+  }
+
   if(H_REDIRECTED(status_code))
   {
 	 // check if it is redirection to the same server

--
Clément 'nodens' Hermann
- L'air pur ? c'est pas en RL, ça ? c'est pas hors charte ?
Jean in L'Histoire des Pingouins, http://tnemeth.free.fr/fmbl/linuxsf/



Re: lftp 3.1 : problem with webdav MOVE

2005-03-02 Thread Alexander V. Lukyanov
On Tue, Mar 01, 2005 at 10:10:39PM +0100, Clement Hermann wrote:
 However, I've got a small problem with MOVE requests, it complains about
 it beeing bad formated :

Does this patch fix the problem?

 the Destination could even be another server. This is not handled by

It could only be done as quote command extension. Same for COPY request.

--
   Alexander.
Index: FileAccess.cc
===
RCS file: /home/lav/cvsroot/lftp/src/FileAccess.cc,v
retrieving revision 1.117
diff -u -p -r1.117 FileAccess.cc
--- FileAccess.cc   10 Feb 2005 13:37:16 -  1.117
+++ FileAccess.cc   2 Mar 2005 11:01:13 -
@@ -402,7 +402,8 @@ const char *FileAccess::GetFileURL(const
{
   if(!f || (f[0]!='/'  f[0]!='~'))
 f=dir_file(cwd?cwd:~,f);
-  u.path=(char*)f;
+  u.path=alloca_strdup(f);
+  OptimizePath(u.path,/*strip_trailing_slash*/false);
}
 
xfree(url);
@@ -571,7 +572,7 @@ int FileAccess::device_prefix_len(const 
return 0;
 }
 
-void FileAccess::OptimizePath(char *path)
+void FileAccess::OptimizePath(char *path,bool strip_trailing_slash)
 {
int  prefix_size=0;
 
@@ -614,7 +615,7 @@ void FileAccess::OptimizePath(char *path
   if(in[0]=='/')
   {
 // double slash or a slash on the end
-if(in[1]=='/' || in[1]=='\0')
+if(in[1]=='/' || (strip_trailing_slash  in[1]=='\0'))
 {
in++;
continue;
Index: FileAccess.h
===
RCS file: /home/lav/cvsroot/lftp/src/FileAccess.h,v
retrieving revision 1.82
diff -u -p -r1.82 FileAccess.h
--- FileAccess.h4 Feb 2005 15:25:51 -   1.82
+++ FileAccess.h2 Mar 2005 11:00:15 -
@@ -221,7 +221,7 @@ public:
virtual voidRename(const char *rfile,const char *to);
virtual void Mkdir(const char *rfile,bool allpath=false);
virtual void Chdir(const char *dir,bool verify=true);
-   void OptimizePath(char *path);
+   void OptimizePath(char *path,bool strip_trailing_slash=true);
void SetCwd(const char *dir) { xfree(cwd); cwd=xstrdup(dir); }
void Remove(const char *rfile){ Open(rfile,REMOVE); }
void RemoveDir(const char *dir)  { Open(dir,REMOVE_DIR); }
Index: Http.cc
===
RCS file: /home/lav/cvsroot/lftp/src/Http.cc,v
retrieving revision 1.187
diff -u -p -r1.187 Http.cc
--- Http.cc 25 Feb 2005 12:47:41 -  1.187
+++ Http.cc 2 Mar 2005 06:54:40 -
@@ -609,11 +609,7 @@ void Http::SendRequest(const char *conne
case RENAME:
   {
 SendMethod(MOVE,efile);
-char *efile1=string_alloca(strlen(file1)*3+1);
-url::encode_string(file1,efile1,URL_PATH_UNSAFE);
-char *pfile1=string_alloca(strlen(ecwd)+1+strlen(efile1)+1+6+1);
-DirFile(pfile1,ecwd,efile1);
-Send(Destination: %s\r\n,pfile1);
+Send(Destination: %s\r\n,GetFileURL(file1));
   }
}
SendAuth();