-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRemoteDir.cpp
142 lines (115 loc) · 3.93 KB
/
RemoteDir.cpp
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
#include "StdFuncs.h"
#include "RemoteFactory.h"
#include "Yggdrasil/Commands.h"
#include <memory>
#include <string.h>
/**
* Sends a directory listing to the remote client.
* This command is not required for the remote directory implementation, but must be present.
*
* @date Sunday 22-Jan-2023 11:08 am, Code HQ Tokyo Tsukuda
*/
void CDir::execute()
{
}
/**
* Requests a directory listing on the remote server.
* Requests the remote server list the contents of the specified directory. The name of the directory
* to be listed is passed in as the payload. If "" or "." is passed in, the contents of the current
* directory will be listed.
*
* @date Sunday 22-Jan-2023 11:07 am, Code HQ Tokyo Tsukuda
*/
TResult CDir::sendRequest()
{
int32_t payloadSize = static_cast<int32_t>(strlen(m_directoryName) + 1);
m_command.m_size = payloadSize;
sendCommand();
m_socket->write(m_directoryName, payloadSize);
readResponse();
return TResult{};
}
/**
* Opens a remote object for scanning.
* This function prepares to scan a file or directory. The a_pattern parameter can refer to either a
* directory name, a single filename, a wildcard pattern or a combination thereof.
*
* @date Sunday 22-Jan-2023 10:41 am, Code HQ Tokyo Tsukuda
* @param a_pattern OS specific path and wildcard to scan
* @return KErrNone if successful, otherwise one of the system errors
*/
int RRemoteDir::open(const char *a_pattern)
{
(void) a_pattern;
int retVal = KErrNone;
if (m_socket->isOpen())
{
CDir *handler = nullptr;
try
{
handler = new CDir(m_socket, a_pattern);
handler->sendRequest();
if (handler->getResponse()->m_result == KErrNone)
{
const char *name;
TInt64 size;
TEntry *Entry;
TTime Now;
const unsigned char *payload = handler->getResponsePayload();
const unsigned char *payloadEnd = payload + handler->getResponse()->m_size;
Now.HomeTime();
/* Iterate through the file information in the payload and extract its contents. Provided the payload */
/* is structured correctly, we could just check for it being ended by NULL terminator, but in the */
/* interest of safety, we'll also check that we haven't overrun the end */
while (payload < payloadEnd && *payload != '\0')
{
name = reinterpret_cast<const char *>(payload);
payload += strlen(name) + 1;
READ_INT_64(size, payload);
payload += sizeof(size);
if ((Entry = m_entries.Append(name)) != NULL)
{
Entry->Set(EFalse, EFalse, size, 0, Now.DateTime());
}
ASSERTM((payload < payloadEnd), "RRemoteDir::open => Payload contents do not match its size");
}
}
else
{
Utils::info("RRemoteDir::open() => Received invalid response %d", handler->getResponse()->m_result);
retVal = handler->getResponse()->m_result;
}
}
catch (RSocket::Error &a_exception)
{
Utils::info("RRemoteDir::open() => Unable to perform I/O on socket (Error = %d)", a_exception.m_result);
retVal = KErrNotFound;
}
delete handler;
}
else
{
Utils::info("RRemoteDir::open() => Connection to server \"%s:%d\" is not open", m_remoteFactory->getServer().c_str(),
m_remoteFactory->getPort());
retVal = KErrNotOpen;
}
return retVal;
}
/**
* Scans a remote directory for file and directory entries.
* Scans a directory that has been prepared with RRemoteDir::open() and populates a list with all of
* the entries found. This list is then returned to the calling client code.
*
* @date Sunday 22-Jan-2023 10:42 am, Code HQ Tokyo Tsukuda
* @param a_entries Reference to a ptr into which to place a ptr to the array of entries read
* by this function
* @param a_sortOrder Enumeration specifying the order in which to sort the files. EDirSortNone
* is used by default
* @return KErrNone is always returned, as this method cannot fail
*/
int RRemoteDir::read(TEntryArray *&a_entries, enum TDirSortOrder a_sortOrder)
{
(void) a_sortOrder;
a_entries = &m_entries;
return KErrNone;
}