File lftp-compat-mode.patch of Package lftp

--- src/CmdExec.cc
+++ src/CmdExec.cc
@@ -1165,6 +1165,47 @@
    dyn_cmd_table.append(new_entry);
 }
 
+void CmdExec::RegisterCompatCommand(const char *name,cmd_creator_t creator,const char *short_desc,const char *long_desc)
+{
+   if(dyn_cmd_table==0)
+   {
+      int count=0;
+      for(const cmd_rec *c=static_cmd_table; c->name; c++)
+        count++;
+      dyn_cmd_table.nset(static_cmd_table,count);
+   }
+
+   for(int i=0; i<dyn_cmd_table.count(); i++)
+   {
+      cmd_rec *const c=&dyn_cmd_table[i];
+      if(!strcmp(c->name,name))
+      {
+         char *lftp_name=(char*)malloc(5+strlen(name)+1);
+         char *short_d = NULL;
+         const char *old_short_desc = c->short_desc;
+         const char *old_long_desc = c->long_desc;
+
+         if (c->short_desc) {
+             short_d = (char*)malloc(5+strlen(c->short_desc)+1);
+             sprintf(short_d, "lftp-%s", c->short_desc);
+             c->short_desc = short_d;
+         }
+
+         sprintf(lftp_name, "lftp-%s", name);
+         c->name = lftp_name;
+
+         cmd_rec new_entry={name,
+                            creator, 
+                            ( short_desc ? short_desc : old_short_desc ), 
+                            ( long_desc ? long_desc : old_long_desc ) };
+         dyn_cmd_table.append(new_entry);
+         return;
+      }
+   }
+   cmd_rec new_entry={name,creator,short_desc,long_desc};
+   dyn_cmd_table.append(new_entry);
+}
+
 void CmdExec::ChangeSession(FileAccess *new_session)
 {
    session=new_session;
--- src/CmdExec.h
+++ src/CmdExec.h
@@ -219,6 +219,9 @@
    static void RegisterCommand(const char *name,cmd_creator_t creator,
       const char *short_name=0,const char *long_name=0);
 
+   static void RegisterCompatCommand(const char *name,cmd_creator_t creator,
+      const char *short_name=0,const char *long_name=0);
+
    Job *builtin_lcd();
    Job *builtin_cd();
    Job *builtin_open();
--- src/CompatMode.cc
+++ src/CompatMode.cc
@@ -0,0 +1,232 @@
+/*
+ * compat mode for lftp
+ *
+ * Copyright (c) 2005 by Petr Ostadal (postadal@suse.cz)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+
+#include <config.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <unistd.h>
+#include <assert.h>
+#include <pwd.h>
+#include "MirrorJob.h"
+#include "CmdExec.h"
+#include "rmJob.h"
+#include "mkdirJob.h"
+#include "ChmodJob.h"
+#include "misc.h"
+#include "plural.h"
+#include "getopt.h"
+#include "FindJob.h"
+#include "url.h"
+#include "CopyJob.h"
+#include "pgetJob.h"
+
+#include "modconfig.h"
+
+#include <fcntl.h>
+#include <termios.h>
+
+#include "xmalloc.h"
+#include "GetPass.h"
+#include "CharReader.h"
+#include "SignalHook.h"
+#include "Job.h"
+
+
+int ascii_mode;
+
+char* GetText(const char *prompt) {
+   static char *oldtext=0;
+   static int tty_fd=-2;
+   static FILE *f=0;
+
+   xfree(oldtext);
+   oldtext=0;
+
+   if(tty_fd==-2)
+   {
+      if(isatty(0))
+	 tty_fd=0;
+      else
+      {
+	 tty_fd=open("/dev/tty",O_RDONLY);
+   	 if(tty_fd!=-1)
+	    fcntl(tty_fd,F_SETFD,FD_CLOEXEC);
+      }
+   }
+   if(tty_fd==-1)
+      return 0;
+
+   write(tty_fd,prompt,strlen(prompt));
+   oldtext=readline_from_file(tty_fd);
+   return oldtext;
+}
+
+CMD(ascii)
+{
+    ascii_mode = 1;
+    return NULL;
+}
+
+CMD(bin)
+{
+    ascii_mode = 0;
+    return NULL;
+}
+
+CMD(type) 
+{
+    if (parent->args->count() == 2) {
+        if (strcmp(parent->args->getarg(1), "binary") == 0)
+            ascii_mode = 0;
+        else if (strcmp(parent->args->getarg(1), "ascii") == 0)
+            ascii_mode = 1;
+        else
+            parent->eprintf(_("Try `help %s' for more information.\n"), parent->args->a0());
+    } else if (parent->args->count() == 1) {
+        if (ascii_mode)
+            parent->printf("Using ascii mode to transfer files.\n");
+        else
+            parent->printf("Using binary mode to transfer files.\n");
+    }
+    else
+        parent->eprintf(_("Try `help %s' for more information.\n"), parent->args->a0());
+    return NULL;
+}
+
+CMD(user);
+
+CMD(compat_user)
+{
+    char *user;
+
+    if(parent->args->count() == 1) {
+        user = GetText("(username) ");
+        
+        if (!user || strlen(user) == 0) {
+            parent->eprintf(_("Try `help %s' for more information.\n"), parent->args->a0());
+            return NULL;
+        }
+        user = strdup(user);
+        parent->args->Add(user);
+    }
+    
+    return cmd_user(parent);
+}
+
+CMD(compat_open)
+{
+    const char *myname = getlogin();
+    struct passwd *pw;
+    char *name = NULL;
+    char *prompt = NULL;
+    char *cmd;
+    int len = 0;
+    ascii_mode = 1;
+    Job *job;
+    int n;
+    
+    if (parent->args->count() == 3)
+        parent->args->insarg(2, "-p");
+    else if (parent->args->count() != 2) {
+        parent->eprintf(_("Try `help %s' for more information.\n"), parent->args->a0());
+        return NULL;
+    }
+    
+    if (myname == NULL && (pw = getpwuid(getuid())) != NULL)
+        myname = pw->pw_name;
+    if (myname) {
+        len = strlen(myname) + 10;
+        prompt = (char*)malloc(len);
+        if (len <= snprintf(prompt, len, "Name (%s): ", myname))
+            prompt[len - 1] = '\0';
+        name = GetText(prompt);
+        name = strdup(name && strlen(name) > 0 ? name : myname);
+        free(prompt);
+    }
+    else {
+        name = GetText("Name: ");
+        if (name) strdup (name);
+    }
+    
+            
+    if (name != NULL && strlen(name) == 0) {
+        free(name);
+        name = NULL;
+    }
+
+    if (name) {
+        len = strlen(name) + 11;
+        cmd = (char*)malloc(len);
+
+        if (len <= snprintf(cmd, len, "lftp-user %s", name))
+            cmd[len - 1] = '\0';
+
+        parent->PrependCmd(cmd);
+
+        free(name);
+        free(cmd);
+    }
+    job = parent->builtin_open();
+    n = job->Do();
+    
+    return job;
+}
+
+CMD(get);
+
+CMD(compat_get)
+{
+    if (ascii_mode && parent->args->count() > 1)
+        parent->args->insarg(1, "-a");
+    
+    return cmd_get(parent);
+}
+
+CMD(get1);
+
+CMD(compat_get1)
+{
+    if (ascii_mode && parent->args->count() > 1)
+        parent->args->insarg(1, "-a");
+    
+    return cmd_get1(parent);
+}
+
+void module_init()
+{
+    ascii_mode = 0;
+
+    CmdExec::RegisterCompatCommand("user", cmd_compat_user, "user <username> [<pass>]", "send new user information (only for backward compatibility, use lftp-user instead)\n");
+    CmdExec::RegisterCompatCommand("open", cmd_compat_open, "open <site> [<port]", "connect to remote ftp server (only for backward compatibility, use lftp-open instead)\n");
+    
+    CmdExec::RegisterCompatCommand("get", cmd_compat_get);
+    CmdExec::RegisterCompatCommand("mget", cmd_compat_get);
+    CmdExec::RegisterCompatCommand("put", cmd_compat_get);
+    CmdExec::RegisterCompatCommand("mput", cmd_compat_get);
+    CmdExec::RegisterCompatCommand("get1", cmd_compat_get1);
+    
+    
+    CmdExec::RegisterCommand("ascii", cmd_ascii, "ascii", "set ascii transfer type\n");
+    CmdExec::RegisterCommand("binary", cmd_bin, "binary", "set binary transfer type\n");
+    CmdExec::RegisterCommand("type", cmd_type, "type [ascii|binary]", "set file transfer type\n");
+}
--- src/CompatMode.h
+++ src/CompatMode.h
@@ -0,0 +1,28 @@
+/*
+ * lftp and utils
+ *
+ * Copyright (c) 2005 by Petr Ostadal (postadal@suse.cz)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef COMPATMODE_H
+#define COMPATMODE_H
+
+#include "Job.h"
+extern int ascii_mode;
+
+
+#endif //COMPATMODE_H
--- src/Makefile.am
+++ src/Makefile.am
@@ -20,7 +20,7 @@
 example_module1_la_LDFLAGS  = -module -avoid-version -rpath $(pkgverlibdir)
 
 TASK_MODULES = liblftp-pty.la liblftp-network.la proto-ftp.la proto-http.la proto-file.la proto-fish.la proto-sftp.la
-JOB_MODULES = liblftp-getdate.la cmd-mirror.la cmd-sleep.la
+JOB_MODULES = liblftp-getdate.la cmd-mirror.la cmd-sleep.la compat-mode.la
 if WITH_MODULES
   pkgverlib_LTLIBRARIES = $(TASK_MODULES) $(JOB_MODULES)
 else
@@ -41,6 +41,7 @@
 liblftp_network_la_SOURCES = NetAccess.cc NetAccess.h Resolver.cc Resolver.h\
  lftp_ssl.cc lftp_ssl.h buffer_ssl.cc buffer_ssl.h RateLimit.cc RateLimit.h
 liblftp_getdate_la_SOURCES = getdate.y getdate.h
+compat_mode_la_SOURCES = CompatMode.cc CompatMode.h
 
 proto_ftp_la_LDFLAGS  = -module -avoid-version -rpath $(pkgverlibdir)
 proto_http_la_LDFLAGS = -module -avoid-version -rpath $(pkgverlibdir)
@@ -54,6 +55,8 @@
 liblftp_network_la_LIBADD  = $(SOCKSLIBS) $(OPENSSL_LIBS) $(LIBGNUTLS_LIBS)
 liblftp_getdate_la_LDFLAGS = -avoid-version -rpath $(pkgverlibdir)
 
+compat_mode_la_LDFLAGS = -module -avoid-version -rpath $(pkgverlibdir)
+
 proto_ftp_la_LIBADD  = -L$(DESTDIR)$(pkgverlibdir) liblftp-network.la
 proto_http_la_LIBADD = -L$(DESTDIR)$(pkgverlibdir) liblftp-network.la $(EXPAT_LIBS)
 proto_fish_la_LIBADD = -L$(DESTDIR)$(pkgverlibdir) liblftp-network.la liblftp-pty.la
--- src/lftp_wrapper.c
+++ src/lftp_wrapper.c
@@ -507,17 +507,6 @@
 	    char *buf_url = NULL;
 	    int is = haveFile(buf2);
 
-/**	    if (ftp_port == NULL)
-		snprintf(open, 100,
-			 (anonymous
-			  || isWithUsername(buf2) ? LFTP_OPEN :
-			  LFTP_COMPAT_MODE_OPEN));
-	    else
-		snprintf(open, 100, "%s -p %s",
-			 (anonymous
-			  || isWithUsername(buf2) ? LFTP_OPEN :
-			  LFTP_COMPAT_MODE_OPEN), ftp_port);**/
-
 	    int ishtml,isftp,isfile,ishost,isuser; //flags for url
 	    int tmp_port;
 	    ishtml=isHTML(buf2);
@@ -569,8 +558,7 @@
 			buf_url = get_url(buf2);
 			tmp_port= isPortInUrl(buf2);/* no need to test error message, it is done in get_url() */
 			if(tmp_port)ftp_port_i=tmp_port;
-			snprintf(open, 100,(anonymous || isuser || (isftp && !ishost) ? LFTP_OPEN :
-			  LFTP_COMPAT_MODE_OPEN)); 
+			snprintf(open, 100,LFTP_OPEN); 
 			snprintf(buf, BUFSIZE, "%s %s:%d; %s %s",
 					 open, buf_url, ftp_port_i, get,
 					 buf_file);
@@ -591,9 +579,6 @@
 		    }
 		}
 		
-		/*if (!strncmp
-		    (buf2, ANONYMOUS_PREFIX, strlen(ANONYMOUS_PREFIX)))
-		    anonymous_offset = strlen(ANONYMOUS_PREFIX);*/
 		snprintf(open, 100,(anonymous || isuser) ? LFTP_OPEN :
 			  LFTP_COMPAT_MODE_OPEN);     
 		buf_file = get_file(buf2); /* directory */ 
openSUSE Build Service is sponsored by