1
/****************************************************************************
2
** filetrans.h - classes for handling file transfers
3
** Copyright (C) 2001, 2002 Justin Karneges
5
** This program is free software; you can redistribute it and/or
6
** modify it under the terms of the GNU General Public License
7
** as published by the Free Software Foundation; either version 2
8
** of the License, or (at your option) any later version.
10
** This program is distributed in the hope that it will be useful,
11
** but WITHOUT ANY WARRANTY; without even the implied warranty of
12
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
** GNU General Public License for more details.
15
** You should have received a copy of the GNU General Public License
16
** along with this program; if not, write to the Free Software
17
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
19
****************************************************************************/
26
#include<qserversocket.h>
28
#include<qguardedptr.h>
31
#include<qsignalmapper.h>
38
/****************************************************************************
41
The FileServer class implements a simple httpd which serves files based
42
on keys (for security). Use 'addFile' to offer a file. 'addFile'
43
will generate a unique key for the file and return a pointer to a
47
ftserv.setServer("127.0.0.1", 12345);
48
FileServerItem *item = ftserv.addFile("/home/justin/myfile.txt");
50
The resulting URL (item->url) would be something like:
52
http://127.0.0.1:12345/e1f13de17df17c5a/myfile.txt
54
The local path to the file is kept hidden from the recipient.
56
****************************************************************************/
59
struct FileServerItem;
62
class FileServer : public QObject
69
void setServer(const QString &, int);
70
FileServerItem *addFile(const QString &fname, const QString &desc, const QString &who);
71
QPtrList<FileServerItem> items() const;
74
void newDownload(QGuardedPtr<FileTransfer>);
77
void connectionReady(int sock);
78
void transferDiscarded(int id);
81
FileServerItem *getFSI(const QString &key);
85
FileTransfer *findByID(int);
87
QSignalMapper *sigmap[2];
88
QPtrList<FileTransfer> ftlist;
89
QPtrList<FileServerItem> filelist;
95
void (*old_sigpipe)(int);
97
friend class FileTransfer;
101
class ServSock : public QServerSocket
108
void connectionReady(int);
112
void newConnection(int);
116
struct FileServerItem
122
QString url, who, desc;
126
class FileTransfer : public QObject
130
FileTransfer(FileServer *par);
134
bool isValid() { return v_isValid; }
142
QByteArray stringData;
150
void sock_readyRead();
151
void sock_connectionClosed();
152
void sock_bytesWritten(int);
156
bool getGETInfo(const QString &getReq, QString *resource, QString *http_ver);
157
bool extractResourceInfo(const QString &resource, QString *fname, QString *key);