FreeRDP/winpr/libwinpr
ilammy 092e870d2a wClipboard/posix: implement file range retrieval
This is another bunch of callbacks which provide the file contents to
the clients. We jump through some extra hoops in order to have more
pleasant user experience.

Simple stuff goes first. The file offset (or position) is split into the
low and high parts because this is the format in which the clients
receive the request from the server. They can simply copy the values as
is into the struct without repackaging them (which we do instead in the
end to get a 64-bit off_t).

Another thing is that we try to minimize the number of lseek() calls and
to keep as few file descriptors open as possible. We cannot open all the
files at once as there could be thousands of them and we'll run out of
the allowed number of the fds. However, the server can (in theory)
request the file ranges randomly so we need to be prepared for that. One
way to do that would be to always open the file before reading and close
it immediately afterwards. A dead simple solution with an acceptable
performance, but... some file systems do not support seeking, such as
FTP directories mounted over FUSE. However, they handle sequential
reading just fine *and* the server requests the data sequentially most
of the time so we can exploit this.

Thus open the file only once, during the first range request and keep
it open until the server reads all the data. In order to know how much
data is left we keep an accurate account of all reads and maintain the
file offset ourselves. This also allows us to avoid calling lseek() when
the file offset will not be effectively changed. However, if the server
requests some weird offset then we have no choice and will attempt
seeking. Unfortunately, we cannot tell whether it is a genuine failure
or the file system just does not support seeking, so we do not handle
the error further. (One workaround would be to reopen the file and keep
reading it until we're at the correct offset.) In this way we can
support sequential-only file systems if the server requests the contents
sequentially (and it does).

Also note that we do an fstat() right after opening the file in order to
have an accurate value of file size, for this exact file descriptor we
will be using. We should have it filled it by now, but just in case...

There is one more thing to explain. The cbRequested field specifies the
maximum number of bytes the server can handle, not the required number.
Usually this is some power-of-two number like 64 KB, based on the size
of the files on the clipboard. This is why posix_file_read_perform()
does not attempt to fill the whole buffer by repeatedly calling read()
if it has read less data than requested. The server can handle underruns
just fine (and this spares us from special-casing the EOF condition).
2017-04-09 03:15:49 +03:00
..
asn1 First shot on fixing over linking 2016-03-29 18:14:34 +02:00
bcrypt First shot on fixing over linking 2016-03-29 18:14:34 +02:00
clipboard wClipboard/posix: implement file range retrieval 2017-04-09 03:15:49 +03:00
com First shot on fixing over linking 2016-03-29 18:14:34 +02:00
comm Added fallback for CMSPAR. (See debian #854689) 2017-02-09 19:58:26 +01:00
credentials Removed windows module.def files. 2016-02-29 15:18:47 +01:00
credui fix string format specifiers 2016-12-16 13:48:43 +01:00
crt Merge pull request #3864 from DavBfr/rewrite-disk-redirection 2017-04-06 17:32:21 +02:00
crypto Fixed memory leak and return value check issue. 2017-03-28 17:56:44 +02:00
dsparse fix string format specifiers 2016-12-16 13:48:43 +01:00
environment Fixed tests and dead store warnings. 2017-03-28 16:49:56 +02:00
error fix string format specifiers 2016-12-16 13:48:43 +01:00
file Fix indentation 2017-04-05 15:35:03 -07:00
handle Merge pull request #3163 from akallabeth/set_file_time 2016-03-02 09:43:46 +01:00
heap Removed windows module.def files. 2016-02-29 15:18:47 +01:00
input Several fixes for keyboard type 7 (japanese) 2016-02-11 21:40:50 +01:00
interlocked Fixed tests and dead store warnings. 2017-03-28 16:49:56 +02:00
io winpr: fix UWP portability 2016-12-02 13:18:55 -05:00
library ifdef's for Cygwin compilation 2017-02-10 18:06:20 +03:00
locale First shot on fixing over linking 2016-03-29 18:14:34 +02:00
memory First shot on fixing over linking 2016-03-29 18:14:34 +02:00
nt fix string format specifiers 2016-12-16 13:48:43 +01:00
path Misc Fixes 2017-03-17 14:07:33 -07:00
pipe Fixed tests and dead store warnings. 2017-03-28 16:49:56 +02:00
pool fix string format specifiers 2016-12-16 13:48:43 +01:00
registry fix string format specifiers 2016-12-16 13:48:43 +01:00
rpc fix string format specifiers 2016-12-16 13:48:43 +01:00
security First shot on fixing over linking 2016-03-29 18:14:34 +02:00
shell Fixed android build issues. 2016-02-01 15:21:07 +01:00
smartcard smartcard: implement ListReaderGroups 2017-02-16 16:59:03 +01:00
sspi Fixed GetEnvironmentVariable. 2017-03-03 12:43:00 +01:00
sspicli winpr/synch: remove the dependency on winsock.h 2015-07-14 11:39:41 +02:00
synch Fixed RPATH settings for OS X 2017-04-06 08:08:07 +02:00
sysinfo Added test for GetComputerName/GetComputerNameEx 2017-02-28 11:03:10 +01:00
thread Fixed tests and dead store warnings. 2017-03-28 16:49:56 +02:00
timezone Update timezone data to Dec 2016 2017-01-11 16:56:34 -05:00
utils Fixed tests and dead store warnings. 2017-03-28 16:49:56 +02:00
winhttp winpr: always build "monolitic" 2014-07-10 11:10:58 +02:00
winsock ifdef's for Cygwin compilation 2017-02-10 18:06:20 +03:00
wnd fix string format specifiers 2016-12-16 13:48:43 +01:00
wtsapi Fixed tests and dead store warnings. 2017-03-28 16:49:56 +02:00
CMakeLists.txt Build: Use correct pdb names when installing with symbols 2017-01-31 13:32:51 +01:00
dummy.c freerdp: various missing link dependencies and symbol exports 2013-09-03 21:48:26 -04:00
log.h Moved logging defines to main logger. 2014-09-09 16:32:04 +02:00