Here is an updated patch for my new smp method.  This one detects
if the remote side has mimencode and uses that if it is
available.  Otherwise, it uses perl to do the mimencode stuff.

Some possible improvements:

o Don't always send the tramp_mime* shell functions.
o Use MIME::Base64 if installed (because it has compiled C
  routines on many platforms).
o Uh... Others.

This method is a good default method since perl is pretty widely
deployed and it will use the faster (for large files) mimencode
if it is installed.

Mark.

-- 
                      ommnes exeunt in mysterium
                     All Things Lead into Mystery
cd /usr/home/mah/.elisp/
diff -c /usr/home/mah/work/debian/tramp/lisp/tramp.el /usr/home/mah/.elisp/tramp.el
*** /usr/home/mah/work/debian/tramp/lisp/tramp.el	Wed Mar 28 15:44:30 2001
--- /usr/home/mah/.elisp/tramp.el	Mon May 21 11:39:07 2001
***************
*** 309,314 ****
--- 309,328 ----
                (tramp-encoding-function    base64-encode-region)
                (tramp-decoding-function    base64-decode-region)
                (tramp-telnet-program       nil))
+      ("smp"   (tramp-connection-function  tramp-open-connection-rsh)
+               (tramp-rsh-program          "ssh")
+               (tramp-rcp-program          nil)
+               (tramp-remote-sh            "/bin/sh")
+               (tramp-rsh-args             ("-e" "none"))
+               (tramp-rcp-args             nil)
+               (tramp-rcp-keep-date-arg    nil)
+               (tramp-su-program           nil)
+               (tramp-su-args              nil)
+               (tramp-encoding-command     "tramp_mimencode")
+               (tramp-decoding-command     "tramp_mimedecode")
+               (tramp-encoding-function    base64-encode-region)
+               (tramp-decoding-function    base64-decode-region)
+               (tramp-telnet-program       nil))
       ("sm1"   (tramp-connection-function  tramp-open-connection-rsh)
                (tramp-rsh-program          "ssh1")
                (tramp-rcp-program          nil)
***************
*** 991,996 ****
--- 1005,1056 ----
    "Perl script to produce output suitable for use with `file-attributes'
  on the remote file system.")
  
+ ;; Perl script to implement `mime-encode'
+ (defvar tramp-perl-mime-encode (concat
+  "sub encode_base64 ($);
+   my $buf;
+   while(read(STDIN, $buf, 60*57)) { print encode_base64($buf) }
+   sub encode_base64 ($) {
+     my $res = \"\";
+     my $eol = \"\n\";
+     pos($_[0]) = 0;                          # ensure start at the beginning
+     while ($_[0] =~ /(.{1,45})/gs) {
+ 	$res .= substr(pack(\"u\", $1), 1);
+ 	chop($res);
+     }
+     $res =~ tr|` -_|AA-Za-z0-9+/|;               # `# help emacs
+     # fix padding at the end
+     my $padding = (3 - length($_[0]) % 3) % 3;
+     $res =~ s/.{$padding}$/\"=\" x $padding/e if $padding;
+     # break encoded string into lines of no more than 76 characters each
+     if (length $eol) {
+ 	$res =~ s/(.{1,76})/$1$eol/g;
+     }
+     $res;}"))
+ 
+ ;; Perl script to implement `mime-decode'
+ (defvar tramp-perl-mime-decode (concat
+  "sub decode_base64 ($);
+   my $buf;
+   while(read(STDIN, $buf, 60*57)) { print decode_base64($buf) }
+   sub decode_base64 ($) {
+     local($^W) = 0; # unpack(\"u\",...) gives bogus warning in 5.00[123]
+ 
+     my $str = shift;
+     my $res = \"\";
+ 
+     $str =~ tr|A-Za-z0-9+=/||cd;            # remove non-base64 chars
+     if (length($str) % 4) {
+ 	warn(\"Length of base64 data not a multiple of 4\")
+     }
+     $str =~ s/=+$//;                        # remove padding
+     $str =~ tr|A-Za-z0-9+/| -_|;            # convert to uuencoded format
+     while ($str =~ /(.{1,60})/gs) {
+ 	my $len = chr(32 + length($1)*3/4); # compute length byte
+ 	$res .= unpack(\"u\", $len . $1 );    # uudecode
+     }
+     $res;}"))
+ 
  ; These values conform to `file-attributes' from XEmacs 21.2.
  ; GNU Emacs and other tools not checked.
  (defconst tramp-file-mode-type-map '((0  . "-")  ; Normal file (SVID-v2 and XPG2)
***************
*** 1492,1498 ****
  
  ;; Other file name ops.
  
! ;; Matthias Köppe <[EMAIL PROTECTED]>
  (defun tramp-handle-directory-file-name (directory)
    "Like `directory-file-name' for tramp files."
    (if (and (eq (aref directory (- (length directory) 1)) ?/)
--- 1552,1558 ----
  
  ;; Other file name ops.
  
! ;; Matthias Köppe <[EMAIL PROTECTED]>
  (defun tramp-handle-directory-file-name (directory)
    "Like `directory-file-name' for tramp files."
    (if (and (eq (aref directory (- (length directory) 1)) ?/)
***************
*** 3607,3612 ****
--- 3667,3696 ----
  		 " -e '" tramp-perl-file-attributes "' $1 2>/dev/null"
                   tramp-rsh-end-of-line
  		 "}"))
+ 	(tramp-wait-for-output)
+ 	(tramp-message 5 "Sending the Perl `mime-encode' implementation.")
+ 	(tramp-send-command
+ 	 multi-method method user host
+ 	 (concat "tramp_mimencode () {" tramp-rsh-end-of-line
+ 		 (if (tramp-find-executable multi-method method user host
+                                      "mimencode"  tramp-remote-path t)
+ 		     "mimencode -b $1" 
+ 		   (concat tramp-remote-perl
+ 			   " -e '" tramp-perl-mime-encode "' $1 2>/dev/null"))
+ 		 tramp-rsh-end-of-line
+ 		 "}"))
+ 	(tramp-wait-for-output)
+ 	(tramp-message 5 "Sending the Perl `mime-decode' implementation.")
+ 	(tramp-send-command
+ 	 multi-method method user host
+ 	 (concat "tramp_mimedecode () {" tramp-rsh-end-of-line
+ 		 (if (tramp-find-executable multi-method method user host
+                                      "mimencode"  tramp-remote-path t)
+ 		     "mimencode -u -b $1" 
+ 		   (concat tramp-remote-perl
+ 			   " -e '" tramp-perl-mime-decode "' $1 2>/dev/null"))
+ 		 tramp-rsh-end-of-line
+ 		 "}"))
  	(tramp-wait-for-output))))
    ;; Find ln(1)
    (erase-buffer)
***************
*** 4478,4484 ****
  ;;   transfer method to use.  (Greg Stark)
  ;; * Remove unneeded parameters from methods.
  ;; * Invoke rsync once for copying a whole directory hierarchy.
! ;;   (Francesco Potortì)
  ;; * Should we set PATH ourselves or should we rely on the remote end
  ;;   to do it?
  ;; * Do the autoconf thing.
--- 4562,4568 ----
  ;;   transfer method to use.  (Greg Stark)
  ;; * Remove unneeded parameters from methods.
  ;; * Invoke rsync once for copying a whole directory hierarchy.
! ;;   (Francesco Potortì)
  ;; * Should we set PATH ourselves or should we rely on the remote end
  ;;   to do it?
  ;; * Do the autoconf thing.

Diff finished at Mon May 21 11:39:30

Reply via email to