-
Notifications
You must be signed in to change notification settings - Fork 5
/
tftptransfer.h
96 lines (77 loc) · 2.19 KB
/
tftptransfer.h
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
/*
* This file is part of PXEDHCP.
* Copyright 2013 A. Douglas Gale
*
* PXEDHCP 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 3 of the License, or
* (at your option) any later version.
*
* PXEDHCP 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.
*/
#ifndef TFTPTRANSFER_H
#define TFTPTRANSFER_H
#include <QObject>
#include <QHostAddress>
#include <QUdpSocket>
#include <QFile>
#include <QTimer>
#include "tftpserver.h"
class TFTPTransfer : public QObject
{
Q_OBJECT
enum Opcodes
{
RRQ = 1,
WRQ = 2,
DATA = 3,
ACK = 4,
ERROR = 5,
OACK = 6
};
enum ErrorCode
{
NOTDEFINED,
FILENOTFOUND,
ACCESSVIOLATION,
DISKFULL,
ILLEGALOPERATION,
UNKNOWNTRANSFERID,
FILEEXISTS,
NOSUCHUSER
};
QByteArray recvBuffer;
QFile *file;
QUdpSocket *sock;
QByteArray sendBuffer;
quint16 sendSize;
quint16 block;
quint16 blockSize;
QHostAddress clientAddr;
quint16 clientPort;
QTimer *retransmitTimer;
int retransmitInterval;
public:
explicit TFTPTransfer(QObject *parent = 0);
void SendErrorPacket(QUdpSocket *target,
const QHostAddress &address, quint16 port,
quint16 errorCode, const QString &errorMessage);
void SendErrorFileNotFound(QUdpSocket *target,
const QHostAddress &addr, quint16 port);
bool StartTransfer(
QUdpSocket *listener, const QHostAddress &addr, quint16 port,
quint16 opcode, const QString &serverRoot,
const TFTPServer::OptionList &options);
static QString TranslateFilename(
const QString &serverRoot, const char *filename);
signals:
void verboseEvent(const QString &msg);
void ErrorEvent(const QString &msg);
public slots:
void OnPacketReceived();
void OnRetransmitTimer();
};
#endif // TFTPTRANSFER_H