|
Packit |
8f70b4 |
/*
|
|
Packit |
8f70b4 |
* lftp - file transfer program
|
|
Packit |
8f70b4 |
*
|
|
Packit |
8f70b4 |
* Copyright (c) 1996-2015 by Alexander V. Lukyanov (lav@yars.free.net)
|
|
Packit |
8f70b4 |
*
|
|
Packit |
8f70b4 |
* This program is free software; you can redistribute it and/or modify
|
|
Packit |
8f70b4 |
* it under the terms of the GNU General Public License as published by
|
|
Packit |
8f70b4 |
* the Free Software Foundation; either version 3 of the License, or
|
|
Packit |
8f70b4 |
* (at your option) any later version.
|
|
Packit |
8f70b4 |
*
|
|
Packit |
8f70b4 |
* This program is distributed in the hope that it will be useful,
|
|
Packit |
8f70b4 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
8f70b4 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit |
8f70b4 |
* GNU General Public License for more details.
|
|
Packit |
8f70b4 |
*
|
|
Packit |
8f70b4 |
* You should have received a copy of the GNU General Public License
|
|
Packit |
8f70b4 |
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
Packit |
8f70b4 |
*/
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
#ifndef FILTER_H
|
|
Packit |
8f70b4 |
#define FILTER_H
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
#include "ProcWait.h"
|
|
Packit |
8f70b4 |
#include "ArgV.h"
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
struct FileTimestamp;
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
class FDStream
|
|
Packit |
8f70b4 |
{
|
|
Packit |
8f70b4 |
bool close_when_done;
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
protected:
|
|
Packit |
8f70b4 |
bool closed;
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
void DoCloseFD();
|
|
Packit |
8f70b4 |
void SetFD(int new_fd,bool c);
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
public:
|
|
Packit |
8f70b4 |
int fd;
|
|
Packit |
8f70b4 |
xstring_c name;
|
|
Packit |
8f70b4 |
xstring_c full_name;
|
|
Packit |
8f70b4 |
xstring_c cwd;
|
|
Packit |
8f70b4 |
xstring error_text;
|
|
Packit |
8f70b4 |
const char *status;
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
bool error() { return error_text!=0; }
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
virtual int getfd() { return fd; }
|
|
Packit |
8f70b4 |
bool is_closed() const { return closed; }
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
FDStream();
|
|
Packit |
8f70b4 |
FDStream(int new_fd,const char *new_name);
|
|
Packit |
8f70b4 |
virtual ~FDStream();
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
void MakeErrorText(int e=0);
|
|
Packit |
8f70b4 |
bool NonFatalError(int err);
|
|
Packit |
8f70b4 |
void set_status(const char *str) { status=str; }
|
|
Packit |
8f70b4 |
void clear_status() { status=0; }
|
|
Packit |
8f70b4 |
void CloseWhenDone() { close_when_done=true; }
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
void SetCwd(const char *);
|
|
Packit |
8f70b4 |
const char *GetCwd() const { return cwd; }
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
virtual off_t get_size() { return -1; }
|
|
Packit |
8f70b4 |
virtual void setmtime(const FileTimestamp &) {}
|
|
Packit |
8f70b4 |
virtual bool can_setmtime() { return false; }
|
|
Packit |
8f70b4 |
virtual void remove_if_empty() {}
|
|
Packit |
8f70b4 |
virtual void remove() {}
|
|
Packit |
8f70b4 |
virtual bool Done();
|
|
Packit |
8f70b4 |
virtual bool usesfd(int n_fd) { return fd==n_fd; }
|
|
Packit |
8f70b4 |
virtual void Kill(int=SIGTERM) {}
|
|
Packit |
8f70b4 |
virtual pid_t GetProcGroup() const { return 0; }
|
|
Packit |
8f70b4 |
virtual bool broken() { return false; }
|
|
Packit |
8f70b4 |
virtual bool can_seek() { return false; }
|
|
Packit |
8f70b4 |
virtual void revert_backup() {}
|
|
Packit |
8f70b4 |
virtual void remove_backup() {}
|
|
Packit |
8f70b4 |
};
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
class OutputFilter : public FDStream
|
|
Packit |
8f70b4 |
{
|
|
Packit |
8f70b4 |
Ref<ArgV> a;
|
|
Packit |
8f70b4 |
ProcWait *w;
|
|
Packit |
8f70b4 |
pid_t pg;
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
Ref<FDStream> my_second;
|
|
Packit |
8f70b4 |
const Ref<FDStream>& second;
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
bool stderr_to_stdout;
|
|
Packit |
8f70b4 |
bool stdout_to_null;
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
void Init();
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
virtual void Parent(int *p); // what to do with pipe if parent
|
|
Packit |
8f70b4 |
virtual void Child (int *p); // same for child
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
protected:
|
|
Packit |
8f70b4 |
int second_fd;
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
public:
|
|
Packit |
8f70b4 |
OutputFilter(const char *filter,int second_fd=-1);
|
|
Packit |
8f70b4 |
OutputFilter(const char *filter,FDStream *second);
|
|
Packit |
8f70b4 |
OutputFilter(const char *filter,const Ref<FDStream>& second);
|
|
Packit |
8f70b4 |
OutputFilter(ArgV *a,int second_fd=-1);
|
|
Packit |
8f70b4 |
OutputFilter(ArgV *a,FDStream *second);
|
|
Packit |
8f70b4 |
OutputFilter(ArgV *a,const Ref<FDStream>& second);
|
|
Packit |
8f70b4 |
virtual ~OutputFilter();
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
void StderrToStdout() { stderr_to_stdout=true; }
|
|
Packit |
8f70b4 |
void StdoutToNull() { stdout_to_null=true; }
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
int getfd();
|
|
Packit |
8f70b4 |
bool Done();
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
bool usesfd(int n_fd);
|
|
Packit |
8f70b4 |
void Kill(int sig=SIGTERM);
|
|
Packit |
8f70b4 |
pid_t GetProcGroup() const { return pg; }
|
|
Packit |
8f70b4 |
void SetProcGroup(pid_t new_pg) { pg=new_pg; }
|
|
Packit |
8f70b4 |
ProcWait::State GetProcState() { return w->GetState(); }
|
|
Packit |
8f70b4 |
int GetProcExitCode() { return w->GetInfo()>>8; }
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
bool broken();
|
|
Packit |
8f70b4 |
};
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
class InputFilter : public OutputFilter
|
|
Packit |
8f70b4 |
{
|
|
Packit |
8f70b4 |
virtual void Parent(int *p);
|
|
Packit |
8f70b4 |
virtual void Child (int *p);
|
|
Packit |
8f70b4 |
public:
|
|
Packit |
8f70b4 |
InputFilter(const char *filter,int second_fd=-1)
|
|
Packit |
8f70b4 |
: OutputFilter(filter,second_fd) {}
|
|
Packit |
8f70b4 |
InputFilter(const char *filter,FDStream *second)
|
|
Packit |
8f70b4 |
: OutputFilter(filter,second) {}
|
|
Packit |
8f70b4 |
InputFilter(ArgV *a,int second_fd=-1)
|
|
Packit |
8f70b4 |
: OutputFilter(a,second_fd) {}
|
|
Packit |
8f70b4 |
InputFilter(ArgV *a,FDStream *second)
|
|
Packit |
8f70b4 |
: OutputFilter(a,second) {}
|
|
Packit |
8f70b4 |
};
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
class FileStream : public FDStream
|
|
Packit |
8f70b4 |
{
|
|
Packit |
8f70b4 |
int mode;
|
|
Packit |
8f70b4 |
mode_t create_mode;
|
|
Packit |
8f70b4 |
bool do_lock;
|
|
Packit |
8f70b4 |
bool no_keep_backup;
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
xstring_c backup_file;
|
|
Packit |
8f70b4 |
mode_t old_file_mode;
|
|
Packit |
8f70b4 |
public:
|
|
Packit |
8f70b4 |
FileStream(const char *fname,int open_mode);
|
|
Packit |
8f70b4 |
~FileStream();
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
void setmtime(const FileTimestamp &);
|
|
Packit |
8f70b4 |
bool can_setmtime() { return true; }
|
|
Packit |
8f70b4 |
void remove_if_empty();
|
|
Packit |
8f70b4 |
void remove();
|
|
Packit |
8f70b4 |
int getfd();
|
|
Packit |
8f70b4 |
bool can_seek();
|
|
Packit |
8f70b4 |
off_t get_size();
|
|
Packit |
8f70b4 |
void set_lock(bool flag=true) { do_lock=flag; }
|
|
Packit |
8f70b4 |
void set_create_mode(mode_t m) { create_mode=m; }
|
|
Packit |
8f70b4 |
void revert_backup();
|
|
Packit |
8f70b4 |
void remove_backup();
|
|
Packit |
8f70b4 |
void dont_keep_backup() { no_keep_backup=true; }
|
|
Packit |
8f70b4 |
};
|
|
Packit |
8f70b4 |
|
|
Packit |
8f70b4 |
#endif /* FILTER_H */
|