Resync
[ntk/apt.git] / methods / rsh.cc
index 9e521ed..6cd6182 100644 (file)
@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description                                                         /*{{{*/
-// $Id: rsh.cc,v 1.2 2001/02/20 07:03:18 jgg Exp $
+// $Id: rsh.cc,v 1.6 2003/02/10 07:34:41 doogie Exp $
 /* ######################################################################
 
    RSH method - Transfer files via rsh compatible program
@@ -10,7 +10,8 @@
 
    ##################################################################### */
                                                                        /*}}}*/
-// Iclude Files                                                                /*{{{*/
+// Include Files                                                       /*{{{*/
+#include <apti18n.h>
 #include "rsh.h"
 #include <apt-pkg/error.h>
 
@@ -26,6 +27,7 @@
 
 const char *Prog;
 unsigned long TimeOut = 120;
+Configuration::Item const *RshOptions = 0;
 time_t RSHMethod::FailTime = 0;
 string RSHMethod::FailFile;
 int RSHMethod::FailFd = -1;
@@ -86,7 +88,7 @@ bool RSHConn::Connect(string Host, string User)
    int Pipes[4] = {-1,-1,-1,-1};
    if (pipe(Pipes) != 0 || pipe(Pipes+2) != 0)
    {
-      _error->Errno("pipe","Failed to create IPC pipe to subprocess");
+      _error->Errno("pipe",_("Failed to create IPC pipe to subprocess"));
       for (int I = 0; I != 4; I++)
         close(Pipes[I]);
       return false;
@@ -99,8 +101,8 @@ bool RSHConn::Connect(string Host, string User)
    // The child
    if (Process == 0)
    {
-      const char *Args[6];
-      int i = 0;
+      const char *Args[400];
+      unsigned int i = 0;
 
       dup2(Pipes[1],STDOUT_FILENO);
       dup2(Pipes[2],STDIN_FILENO);
@@ -108,6 +110,19 @@ bool RSHConn::Connect(string Host, string User)
       // Probably should do
       // dup2(open("/dev/null",O_RDONLY),STDERR_FILENO);
 
+      // Insert user-supplied command line options
+      Configuration::Item const *Opts = RshOptions;
+      if (Opts != 0)
+      {
+         Opts = Opts->Child;
+        for (; Opts != 0; Opts = Opts->Next)
+         {
+            if (Opts->Value.empty() == true)
+               continue;
+            Args[i++] = Opts->Value.c_str();
+         }
+      }
+
       Args[i++] = Prog;
       if (User.empty() == false) {
          Args[i++] = "-l";
@@ -165,21 +180,21 @@ bool RSHConn::ReadLine(string &Text)
       if (WaitFd(ReadFd,false,TimeOut) == false)
       {
          Close();
-         return _error->Error("Connection timeout");
+         return _error->Error(_("Connection timeout"));
       }
 
       // Suck it back
       int Res = read(ReadFd,Buffer + Len,sizeof(Buffer) - Len);
       if (Res <= 0)
       {
-         _error->Errno("read","Read error");
+         _error->Errno("read",_("Read error"));
          Close();
          return false;
       }
       Len += Res;
    }
 
-   return _error->Error("A response overflowed the buffer.");
+   return _error->Error(_("A response overflowed the buffer."));
 }
                                                                        /*}}}*/
 // RSHConn::WriteMsg - Send a message with optional remote sync.       /*{{{*/
@@ -208,13 +223,13 @@ bool RSHConn::WriteMsg(string &Text,bool Sync,const char *Fmt,...)
       {
         
         Close();
-        return _error->Error("Connection timeout");
+        return _error->Error(_("Connection timeout"));
       }      
       
       int Res = write(WriteFd,S + Start,Len);
       if (Res <= 0)
       {
-         _error->Errno("write","Write Error");
+         _error->Errno("write",_("Write Error"));
          Close();
          return false;
       }
@@ -246,7 +261,7 @@ bool RSHConn::Size(const char *Path,unsigned long &Size)
    char *End;
    Size = strtoul(Msg.c_str(),&End,10);
    if (End == Msg.c_str())
-      return _error->Error("File Not Found");
+      return _error->Error(_("File Not Found"));
    return true;
 }
                                                                        /*}}}*/
@@ -271,7 +286,7 @@ bool RSHConn::ModTime(const char *Path, time_t &Time)
 // ---------------------------------------------------------------------
 /* */
 bool RSHConn::Get(const char *Path,FileFd &To,unsigned long Resume,
-                  MD5Summation &MD5,bool &Missing, unsigned long Size)
+                  Hashes &Hash,bool &Missing, unsigned long Size)
 {
    Missing = false;
 
@@ -284,8 +299,8 @@ bool RSHConn::Get(const char *Path,FileFd &To,unsigned long Resume,
       return false;
 
    if (Resume != 0) {
-      if (MD5.AddFD(To.Fd(),Resume) == false) {
-        _error->Errno("read","Problem hashing file");
+      if (Hash.AddFD(To.Fd(),Resume) == false) {
+        _error->Errno("read",_("Problem hashing file"));
         return false;
       }
    }
@@ -304,7 +319,7 @@ bool RSHConn::Get(const char *Path,FileFd &To,unsigned long Resume,
       if (WaitFd(ReadFd,false,TimeOut) == false)
       {
          Close();
-         return _error->Error("Data socket timed out");
+         return _error->Error(_("Data socket timed out"));
       }
 
       // Read the data..
@@ -312,7 +327,7 @@ bool RSHConn::Get(const char *Path,FileFd &To,unsigned long Resume,
       if (Res == 0)
       {
         Close();
-        return _error->Error("Connection closed prematurely");
+        return _error->Error(_("Connection closed prematurely"));
       }
       
       if (Res < 0)
@@ -323,7 +338,7 @@ bool RSHConn::Get(const char *Path,FileFd &To,unsigned long Resume,
       }
       MyLen += Res;
 
-      MD5.Add(Buffer,Res);
+      Hash.Add(Buffer,Res);
       if (To.Write(Buffer,Res) == false)
       {
          Close();
@@ -338,7 +353,7 @@ bool RSHConn::Get(const char *Path,FileFd &To,unsigned long Resume,
 // RSHMethod::RSHMethod - Constructor                                  /*{{{*/
 // ---------------------------------------------------------------------
 /* */
-RSHMethod::RSHMethod() : pkgAcqMethod("1.0")
+RSHMethod::RSHMethod() : pkgAcqMethod("1.0",SendConfig)
 {
    signal(SIGTERM,SigTerm);
    signal(SIGINT,SigTerm);
@@ -346,6 +361,23 @@ RSHMethod::RSHMethod() : pkgAcqMethod("1.0")
    FailFd = -1;
 };
                                                                        /*}}}*/
+// RSHMethod::Configuration - Handle a configuration message           /*{{{*/
+// ---------------------------------------------------------------------
+bool RSHMethod::Configuration(string Message)
+{
+   char ProgStr[100];
+  
+   if (pkgAcqMethod::Configuration(Message) == false)
+      return false;
+
+   snprintf(ProgStr, sizeof ProgStr, "Acquire::%s::Timeout", Prog);
+   TimeOut = _config->FindI(ProgStr,TimeOut);
+   snprintf(ProgStr, sizeof ProgStr, "Acquire::%s::Options", Prog);
+   RshOptions = _config->Tree(ProgStr);
+
+   return true;
+}
+                                                                       /*}}}*/
 // RSHMethod::SigTerm - Clean up and timestamp the files on exit       /*{{{*/
 // ---------------------------------------------------------------------
 /* */
@@ -390,7 +422,7 @@ bool RSHMethod::Fetch(FetchItem *Itm)
 
    // We say this mainly because the pause here is for the
    // ssh connection that is still going
-   Status("Connecting to %s", Get.Host.c_str());
+   Status(_("Connecting to %s"), Get.Host.c_str());
 
    // Get the files information
    unsigned long Size;
@@ -398,7 +430,7 @@ bool RSHMethod::Fetch(FetchItem *Itm)
        Server->ModTime(File,FailTime) == false)
    {
       //Fail(true);
-      //_error->Error("File Not Found"); // Will be handled by Size
+      //_error->Error(_("File Not Found")); // Will be handled by Size
       return false;
    }
    Res.Size = Size;
@@ -428,7 +460,7 @@ bool RSHMethod::Fetch(FetchItem *Itm)
    }
 
    // Open the file
-   MD5Summation MD5;
+   Hashes Hash;
    {
       FileFd Fd(Itm->DestFile,FileFd::WriteAny);
       if (_error->PendingError() == true)
@@ -441,7 +473,7 @@ bool RSHMethod::Fetch(FetchItem *Itm)
       FailFd = Fd.Fd();
 
       bool Missing;
-      if (Server->Get(File,Fd,Res.ResumePoint,MD5,Missing,Res.Size) == false)
+      if (Server->Get(File,Fd,Res.ResumePoint,Hash,Missing,Res.Size) == false)
       {
         Fd.Close();
 
@@ -462,7 +494,7 @@ bool RSHMethod::Fetch(FetchItem *Itm)
    }
 
    Res.LastModified = FailTime;
-   Res.MD5Sum = MD5.Result();
+   Res.TakeHashes(Hash);
 
    // Timestamp
    struct utimbuf UBuf;