1
1

131 Коммитов

Автор SHA1 Сообщение Дата
Daniel Stenberg
c1683ae92c sftp_close_handle: packet list is generic
Fix comment, simplify the loop logic
2010-12-14 09:33:58 +01:00
Daniel Stenberg
1b65c6ae26 sftp_read: pipeline reads
The SFTP read function now does transfers the same way the SFTP write
function was made to recently: it creates a list of many outgoing
FXP_READ packets that each asks for a small data chunk. The code then
tries to keep sending read request while collecting the acks for the
previous requests and returns the received data.
2010-12-14 09:30:25 +01:00
Daniel Stenberg
92ea3bda60 sftp_write: removed unused variable 2010-12-13 19:02:19 +01:00
Daniel Stenberg
0cc14be09d sftp_seek: fix
The new SFTP write code caused a regression as the seek function no
longer worked as it didn't set the write position properly.

It should be noted that seeking is STRONGLY PROHIBITED during upload, as
the upload magic uses two different offset positions and the multiple
outstanding packets etc make them sensitive to change in the midst of
operations.

This functionality was just verified with the new example code
sftp_append. This bug was filed as bug #202:

Bug: http://trac.libssh2.org/ticket/202
2010-12-10 23:51:20 +01:00
Daniel Stenberg
7899d28ecb sftp_write: handle "left over" acked data
The SFTP handle struct now buffers number of acked bytes that haven't
yet been returned. The way this is used is as following:

1. sftp_write() gets called with a buffer of let say size 32000. We
split 32000 into 8 smaller packets and send them off one by one. One of
them gets acked before the function returns so 4000 is returned.

2. sftp_write() gets called again a short while after the previous one,
now with a much smaller size passed in to the function. Lets say 8000.
In the mean-time, all of the remaining packets from the previous call
have been acked (7*4000 = 28000). This function then returns 8000 as all
data passed in are already sent and it can't return any more than what
it got passed in. But we have 28000 bytes acked. We now store the
remaining 20000 in the handle->u.file.acked struct field to add up in
the next call.

3. sftp_write() gets called again, and now there's a backlogged 20000
bytes to return as fine and that will get skipped from the beginning
of the buffer that is passed in.
2010-11-11 11:57:35 +01:00
Daniel Stenberg
2f5a2ff8e6 sftp_write: polished and simplified
Removed unnecessary struct fields and state changes within the function.

Made the loop that checks for ACKs only check chunks that were fully
sent.
2010-11-10 23:29:16 +01:00
Daniel Stenberg
1964ccb557 sftp_readdir: avoid shadowing 2010-11-10 13:05:08 +01:00
Daniel Stenberg
2dfa5d38cb sftp_write: don't return EAGAIN if no EAGAIN was received
This function now only returns EAGAIN if a lower layer actually returned
EAGAIN to it. If nothing was acked and no EAGAIN was received, it will
now instead return 0.
2010-11-09 13:09:08 +01:00
Daniel Stenberg
6395a738fd sftp_packet_read: handle partial reads of the length field
SFTP packets come as [32 bit length][payload] and the code didn't
previously handle that the initial 32 bit field was read only partially
when it was read.
2010-11-02 19:14:33 +01:00
Daniel Stenberg
57af0da9f7 sftp_write: removed superfluous assignment 2010-11-01 22:58:47 +01:00
Daniel Stenberg
a0dd0c5992 sftp_packet_require: propagate error codes better
There were some chances that they would cause -1 to get returned by
public functions and as we're hunting down all such occurances and since
the underlying functions do return valuable information the code now
passes back proper return codes better.
2010-11-01 09:33:36 +01:00
Daniel Stenberg
95db6cc62c sftp_close_handle: free any trailing write chunks 2010-10-25 16:30:09 +02:00
Daniel Stenberg
5b4ed2717b SFTP: bufgix, move more sftp stuff to sftp.h
The sftp_write function shouldn't assume that the buffer pointer will be
the same in subsequent calls, even if it assumes that the data already
passed in before haven't changed.

The sftp structs are now moved to sftp.h (which I forgot to add before)
2010-10-25 16:05:53 +02:00
Daniel Stenberg
59f74de157 SFTP: use multiple outgoing packets when writing
sftp_write was rewritten to split up outgoing data into multiple packets
and deal with the acks in a more asynchronous manner. This is meant to
help overcome latency and round-trip problems with the SFTP protocol.
2010-10-25 01:43:54 +02:00
Daniel Stenberg
a94886f157 _libssh2_channel_write: removed 32500 size limit
Neither _libssh2_channel_write nor sftp_write now have the 32500 size
limit anymore and instead the channel writing function now has its own
logic to send data in multiple calls until everything is sent.
2010-10-23 01:16:12 +02:00
Daniel Stenberg
c48840ba88 _libssh2_transport_send: replaces _libssh2_transport_write
The new function takes two data areas, combines them and sends them as a
single SSH packet. This allows several functions to allocate and copy
less data.

I also found and fixed a mixed up use of the compression function
arguments that I introduced in my rewrite in a recent commit.
2010-10-23 00:11:59 +02:00
Daniel Stenberg
518d25eba1 SFTP: limit write() to not produce overly large packets
sftp_write() now limits how much data it gets at a time even more
than before. Since this function creates a complete outgoing
packet based on what gets passed to it, it is crucial that it
doesn't create too large packets.

With this method, there's also no longer any problem to use very
large buffers in your application and feed that to libssh2. I've
done numerous tests now with uploading data over SFTP using 100K
buffers and I've had no problems with that.
2010-06-11 16:07:30 +02:00
Daniel Stenberg
4cf935abab inputchecks: make lots of API functions check for NULL pointers
If an application accidentally provides a NULL handle pointer to
the channel or sftp public functions, they now return an error
instead of segfaulting.
2010-06-11 13:05:55 +02:00
Daniel Stenberg
eeeebd02e7 SFTP: fail init SFTP if session isn't authenticated
Alexander Lamaison filed bug #172
(http://trac.libssh2.org/ticket/172), and pointed out that SFTP
init would do bad if the session isn't yet authenticated at the
time of the call, so we now check for this situation and returns
an error if detected. Calling sftp_init() at this point is bad
usage to start with.
2010-06-07 13:10:51 +02:00
Daniel Stenberg
d15663477b statvfs: use libssh2_sftp_statvfs only, no "_ex"
As the long-term goal is to get rid of the extensive set of
macros from the API we can just as well start small by not adding
new macros when we add new functions. Therefore we let the
function be libssh2_sftp_statvfs() plainly without using an _ex
suffix.

I also made it use size_t instead of unsigned int for the string
length as that too is a long-term goal for the API.
2010-05-28 17:25:42 +02:00
Joey Degges
ed526a0e24 Add libssh2_sftp_statvfs() and libssh2_sftp_fstatvfs()
These can be used to get file system statistics from servers that
support the statvfs@openssh.com and fstatvfs@openssh.com extensions.
2010-05-24 07:05:23 +02:00
Mikhail Gusarov
b3ed8e064a Restoring copyright statements from pre-git era
Eli Fant has contributed fragmenting SFTP requests
2010-05-05 15:44:15 +07:00
Alexander Lamaison
6c3f2ec815 Removed unecessary brackets. 2010-04-28 17:41:17 +01:00
Alexander Lamaison
f1df0b7fbc Changed sftp_attrsize macro to a static function. 2010-04-28 17:38:00 +01:00
Daniel Stenberg
45210d8376 sftp_attrsize: protect the macro argument with proper parentheses 2010-04-28 10:23:40 +02:00
Daniel Stenberg
d811478071 sftp_read: move a read_responses array to where its used
I find that this increases readability since the array is used
only in the function call just immediately below and nowhere
else.
2010-04-28 00:39:23 +02:00
Daniel Stenberg
b979af1eee sftp_readdir: turn a small array static const and move it 2010-04-28 00:38:22 +02:00
Daniel Stenberg
37624b61e3 sftp_attrsize: converted function to a macro
This way, the macro can evaluate a static number at compile time
for two out of four uses, and it probably runs faster for the
other two cases too.
2010-04-28 00:23:09 +02:00
Daniel Stenberg
4c26a46362 sftp_open: deal with short channel_write calls
This was an old TODO that just wasn't done before. If
channel_write returns short, that is not an error.
2010-04-28 00:12:47 +02:00
Daniel Stenberg
77efca961d sftp_open: clean up, better check of input data
The clang-analyzer report made it look into this function and
I've went through it to remove a potential use of an
uninitialized variable and I also added some validation of input
data received from the server.

In general, lots of more code in this file need to validate the
input before assuming it is correct: there are servers out there
that have bugs or just have another idea of how to do the SFTP
protocol.
2010-04-27 23:59:55 +02:00
Daniel Stenberg
000b0f73d0 libssh2_publickey_init: fixed to work better non-blocking
This was triggered by a clang-analyzer complaint that turned out
to be valid, and it made me dig deeper and fix some generic non-
blocking problems I disovered in the code.

While cleaning this up, I moved session-specific stuff over to a
new session.h header from the libssh2_priv.h header.
2010-04-25 19:35:43 +02:00
Daniel Stenberg
88ac2dd43c sftp_close_handle: add precation to not access NULL pointer
clang-analyzer pointed this out as a "Pass-by-value argument in
function call is undefined" but while I can't see exactly how
this can ever happen in reality I think a little check for safety
isn't such a bad thing here.
2010-04-24 13:03:27 +02:00
Daniel Stenberg
9209309bc3 sftp_init: remove unused variables and assignments 2010-04-17 19:05:53 +02:00
Daniel Stenberg
100059989f data types: convert more to use size_t and uint32_t 2010-04-17 13:34:44 +02:00
Daniel Stenberg
c3bcdd88a4 cleanups: better binary packet gen, size_t fixes and PACKET_* removal
I'll introduce a new internal function set named

 _libssh2_store_u32
 _libssh2_store_u64
 _libssh2_store_str

That can be used all through the library to build binary outgoing
packets.  Using these instead of the current approach removes
hundreds of lines from the library while at the same time greatly
enhances readability. I've not yet fully converted everything to
use these functions.

I've converted LOTS of 'unsigned long' to 'size_t' where
data/string lengths are dealt with internally. This is The Right
Thing and it will help us make the transition to our
size_t-polished API later on as well.

I'm removing the PACKET_* error codes. They were originally
introduced as a set of separate error codes from the transport
layer, but having its own set of errors turned out to be very
awkward and they were then converted into a set of #defines that
simply maps them to the global libssh2 error codes instead. Now,
I'l take the next logical step and simply replace the PACKET_*
defines with the actual LIBSSH2_ERROR_* defines. It will increase
readability and decrease confusion.

I also separated packet stuff into its own packet.h header file.
2010-04-17 13:18:15 +02:00
Daniel Stenberg
1adcb5234f rename libssh2_error to the correct _libssh2_error
We reserve ^libssh2_ for public symbols and we use _libssh2 as
prefix for internal ones. I fixed the intendation of all these
edits with emacs afterwards, which then changed it slightly more
than just _libssh2_error() expressions but I didn't see any
obvious problems.
2010-04-16 00:18:51 +02:00
Daniel Stenberg
9cc824e27b data type cleanup: made lots of code use size_t etc
A lot of code used 'unsigned long' and the likes when it should
rather just use plain 'int' or use size_t for data lengths.
2010-04-15 20:37:46 +02:00
Daniel Stenberg
e22cdcea77 sftp_readdir: simplified and bugfixed
This function no longer has any special purpose code for the
single entry case, as it was pointless.

The previous code would overflow the buffers with an off-by-one
in case the file name or longentry data fields received from the
server were exactly as long as the buffer provided to
libssh2_sftp_readdir_ex.

We now make sure that libssh2_sftp_readdir_ex() ALWAYS zero
terminate the buffers it fills in.

The function no longer calls the libssh2_* function again, but
properly uses the internal sftp_* instead.
2010-04-15 01:15:35 +02:00
Daniel Stenberg
8b7e22cb33 sftp_init() deal with _libssh2_channel_write() returns short
When _libssh2_channel_write() is asked to send off 9 bytes, the
code needs to deal with the situation where less than 9 bytes
were sent off and prepare to send the remaining piece at a later
time.
2010-04-01 20:25:49 +02:00
Daniel Stenberg
d4a768af4e removed libssh2_error()'s forth argument
libssh2_error() no longer allocates a string and only accepts a const
error string. I also made a lot of functions use the construct of
return libssh2_error(...) instead of having one call to
libssh2_error() and then a separate return call. In several of those
cases I then also changed the former -1 return code to a more
detailed one - something that I think will not change behaviors
anywhere but it's worth keeping an eye open for any such.
2010-03-03 23:04:05 +01:00
Peter Stuge
d142f385da Use LIBSSH2_TRACE_* internally and remove redundant LIBSSH2_DBG_* 2009-12-08 08:52:03 +01:00
Alexander Lamaison
e642e2c202 Detabify. 2009-11-24 14:54:10 +00:00
Daniel Stenberg
f07cf3afd3 Fixed memory leak in sftp_fstat(). 2009-11-24 14:45:46 +00:00
Daniel Stenberg
0357befa42 remove debug leftovers 2009-08-30 17:06:57 +02:00
Daniel Stenberg
85198c1cdb channel_read() was changed to _libssh2_channel_read() as lots of
internal code was changed to use that instead of wrongly using
libssh2_channel_read_ex(). Some files now need to include
channel.h to get this proto.

channel_read() calls libssh2_error() properly on transport_read()
failures

channel_read() was adjusted to not "invent" EAGAIN return code in
case the transport_read() didn't return it

channel_close() now returns 0 or error code, as
documented. Previously it would return number of bytes read in
the last read, which was confusing (and useless).
2009-08-30 17:00:49 +02:00
Daniel Stenberg
face4750ca changed all return EAGAIN to return the variable instead
I made this change just to easier grep for "return .*EAGAIN" cases
as they should be very rare or done wrongly. Already worked to find
a flaw, marked with "TODO FIXME THIS IS WRONG" in channel.c. I also
fixed a few cases to become more general returns now when we have
more unified return codes internally.
2009-08-25 00:54:47 +02:00
Daniel Stenberg
f64a84a909 error code cleanup 2009-08-25 00:23:34 +02:00
Daniel Stenberg
13e920d4ef fix several return -1 to return a proper error code
On many places in the code there have been laziness return -1
statements lying around that should be fixed to return sensible
error codes. Here's a take at fixing a few offenders.
2009-08-24 22:28:27 +02:00
Daniel Stenberg
d8b6f3c7b8 move over lots of code to the _libssh2_list_* functions
and I fixed a few minor bugs at the same time
2009-08-20 00:56:54 +02:00
Daniel Stenberg
08cad8e14c moved the handling of SFTP handles to new linked list code
Each SFTP file handle is now handled by the "mother-struct"
using the generic linked list functions. The goal is to move
all custom linked list code to use this set of functions.

I also moved the list declarations to the misc.h where they
belong and made misc.h no longer include libssh2_priv.h itself
since now libssh2_priv.h needs misc.h...

In misc.c I added a #if 0'ed _libssh2_list_insert() function
because I ended up writing one, and I believe we may need it here
too once we move over more stuff to use the _libssh2_list* family.
2009-08-20 00:56:54 +02:00