summaryrefslogtreecommitdiffstats
path: root/src/ftpthread.h
blob: 4372e824ca2a7076fc27cabaaff620f3138be7a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/***************************************************************************
 *   Copyright (C) 2004 by Magnus Kulke                                    *
 *   mkulke@magnusmachine                                                  *
 *                                                                         *
 *   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.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#ifndef FTPTHREAD_H
#define FTPTHREAD_H

#define KB_THREAD_TIMEOUT 1000

#include <list>
#include <qthread.h>
#include <qstringlist.h>
#include <qvaluelist.h>
#include <qvaluevector.h>
#include "eventhandler.h"
#include "kbfileinfo.h"

using namespace std;

class ftplib;
class QObject;
class KbDirInfo;

typedef list<KbFileInfo*> filist;
typedef pair<off64_t, bool> xferpair;
typedef pair<filist, filist> dirpair;

/**
@author Magnus Kulke
*/
class FtpThread : public QThread 
{
public:
   FtpThread();
   ~FtpThread();
	static void CallbackLog(char *log, void *arg, bool out);
	static int CallbackXfer(off64_t xfered, void *arg);
	void SetEventReceiver(QObject* eventreceiver);
	void ClearQueue();
	bool Connect(QString host);
	bool Login(QString user, QString pass);
	bool Quit();
	bool Pwd();
	bool Chdir(QString path);
	bool Cdup();
	bool Dir(bool force = false);
	bool Scandir(KbDirInfo* dir);
	bool Rm(QString name);
	bool Rmdir(QString name);
	bool Authtls();
	bool Pasv(bool flag);
	bool EncryptData(bool flag, bool force = false);
	bool Transfer_Fxp(QString src, QString dst, FtpThread* dstftp, int srctls, int dsttls, off64_t resume = 0, int alt = 0);
	bool Mkdir(QString path);
	bool Rename(QString src, QString dst);
	bool Raw(QString cmd);
	bool Transfer_Get(QString src, QString dst, int tls, off64_t resume = 0);
	bool Transfer_Put(QString src, QString dst, int tls, off64_t resume = 0);
	bool Transfer_Changedir(QString dir, int tls);
	bool Transfer_Mkdir(QString dir);
	void Event(EventHandler::EventType type, void *data = NULL);
	ftplib* Ftp() { return mp_ftp; };
	void FxpReportResult(bool result);
	bool FxpDisableTls();
private:
	enum task
	{
		connect = 0,
		negotiateencryption,
		login,
		quit,
		pwd,
		chdir,
		cdup,
		dir,
		scandir,
		rm,
		rmdir,
		authtls,
		dataencryption,
		mkdir,
		rename,
		raw,
		transfer_changedir,
		transfer_get,
		transfer_mkdir,
		transfer_put,
		transfer_fxp
	};	
	void run();
	bool FormatFilelist(const char *filename,
		QString current,
		filist *filetable,
		filist *dirtable
	);
	void InitInternals();
	void Connect_thread(); 
	void Login_thread(); 
	void Pwd_thread();
	void Quit_thread();
	void Chdir_thread();
	void Cdup_thread();
	void Dir_thread();
	void Scandir_thread();
	void Delete_thread();
	void Rm_thread();
	void Rmdir_thread();
	void Authtls_thread();
	void Dataencryption_thread();
	void Mkdir_thread();
	void Rename_thread();
	void Raw_thread();
	void Transfer_Changedir_thread();
	void Transfer_Get_thread();
	void Transfer_Put_thread();
	void Transfer_Fxp_thread();
	void Transfer_Mkdir_thread();
	bool Scandir_recurse(KbDirInfo *dir, QString path);
	bool Delete_recurse(QString name);
	bool ConnectionLost();
private:
	QMutex* mp_mutex;
	QObject* mp_eventreceiver;
	ftplib* mp_ftp;
	QString m_pwd;
	bool m_dataencrypted;
	KbDirInfo* mp_scandir;
	filist m_dirlist, m_filelist;
	dirpair m_dircontent;
	QValueList<task> m_tasklist;
	QStringList m_stringlist;
	QValueList<int> m_intlist;
	QValueList<off64_t> m_ulonglist;
	QValueList<FtpThread*> m_ftplist;
	QValueVector<dirpair> m_cache_vector;
	QStringList m_cache_list;
public:
	QString m_linebuffer;
};

#endif