// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: rsh.cc,v 1.3 2001/03/06 07:15:29 jgg Exp $
+// $Id: rsh.cc,v 1.6.2.1 2004/01/16 18:58:50 mdz Exp $
/* ######################################################################
RSH method - Transfer files via rsh compatible program
##################################################################### */
/*}}}*/
-// Iclude Files /*{{{*/
+// Include Files /*{{{*/
#include "rsh.h"
#include <apt-pkg/error.h>
#include <stdio.h>
#include <errno.h>
#include <stdarg.h>
+#include <apti18n.h>
/*}}}*/
const char *Prog;
unsigned long TimeOut = 120;
+Configuration::Item const *RshOptions = 0;
time_t RSHMethod::FailTime = 0;
string RSHMethod::FailFile;
int RSHMethod::FailFd = -1;
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;
// 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);
// 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";
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. /*{{{*/
{
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;
}
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;
}
/*}}}*/
return false;
// Parse it
- StrToTime(Msg,Time);
- return true;
+ return FTPMDTMStrToTime(Msg.c_str(), Time);
}
/*}}}*/
// RSHConn::Get - Get a file /*{{{*/
if (Resume != 0) {
if (Hash.AddFD(To.Fd(),Resume) == false) {
- _error->Errno("read","Problem hashing file");
+ _error->Errno("read",_("Problem hashing file"));
return false;
}
}
if (WaitFd(ReadFd,false,TimeOut) == false)
{
Close();
- return _error->Error("Data socket timed out");
+ return _error->Error(_("Data socket timed out"));
}
// Read the data..
if (Res == 0)
{
Close();
- return _error->Error("Connection closed prematurely");
+ return _error->Error(_("Connection closed prematurely"));
}
if (Res < 0)
// RSHMethod::RSHMethod - Constructor /*{{{*/
// ---------------------------------------------------------------------
/* */
-RSHMethod::RSHMethod() : pkgAcqMethod("1.0")
+RSHMethod::RSHMethod() : pkgAcqMethod("1.0",SendConfig)
{
signal(SIGTERM,SigTerm);
signal(SIGINT,SigTerm);
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 /*{{{*/
// ---------------------------------------------------------------------
/* */
// 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;
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;
}
Res.LastModified = FailTime;
- Res.MD5Sum = Hash.MD5.Result();
+ Res.TakeHashes(Hash);
// Timestamp
struct utimbuf UBuf;
int main(int argc, const char *argv[])
{
+ setlocale(LC_ALL, "");
+
RSHMethod Mth;
Prog = strrchr(argv[0],'/');
Prog++;