-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilezillaserverdesc.cpp
More file actions
45 lines (42 loc) · 1.15 KB
/
filezillaserverdesc.cpp
File metadata and controls
45 lines (42 loc) · 1.15 KB
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
#include "filezillaserverdesc.h"
#include <cstdint>
FilezillaServerDesc::FilezillaServerDesc():
isValid(false), serverVersion(0), protocolVersion(0)
{
}
/**
* @brief Parses a server description from filezilla.
* @param The bytes first received from the filezilla server when connecting.
* @return -1 if parsing failed, otherwise the number of bytes that was parsed, always more than 0.
*/
int FilezillaServerDesc::Parse(const QByteArray &bytes)
{
isValid = false; // Assume incorrect until proven otherwise.
if(bytes.length() < 15)
{
return -1;
}
if(bytes[0] == 'F' && bytes[1] == 'Z' && bytes[2] == 'S')
{
unsigned int uiTemp = bytes[3]*256 + bytes[4];
if(uiTemp != 4)
{
return -1;
}
uiTemp = *reinterpret_cast<const uint32_t*>(&bytes.data()[5]);
serverVersion = uiTemp;
uiTemp = bytes[9]*256 + bytes[10];
if(uiTemp != 4)
{
return -1;
}
uiTemp = *reinterpret_cast<const uint32_t*>(&bytes.data()[11]);
protocolVersion = uiTemp;
isValid = true;
}
else
{
return -1;
}
return 15;
}