Commit Graph

1543 Commits

Author SHA1 Message Date
Daniel Stenberg
1b1ff333e4 SFTP: fix memory leaks
Make sure that we cleanup remainders when the handle is closed and when
the subsystem is shutdown.

Existing flaw: if a single handle sends packets that haven't been
replied to yet at the time when the handle is closed, those packets will
arrive later and end up in the generic packet brigade queue and they
will remain in there until flushed. They will use unnecessary memory,
make things slower and they will ruin the SFTP handling if the
request_id counter ever wraps (highly unlikely to every happen).
2010-12-14 11:46:53 +01:00
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
811cce09b5 _libssh2_channel_close: don't call transport read if disconnected
The loop that waits for remote.close to get set may end up looping
forever since session->socket_state gets set to
LIBSSH2_SOCKET_DISCONNECTED by the packet_add() function called from the
transport_read() function and after having been set to
LIBSSH2_SOCKET_DISCONNECTED, the transport_read() function will only
return 0.

Bug: http://trac.libssh2.org/ticket/198
2010-12-11 22:43:22 +01:00
Daniel Stenberg
6875285b71 libssh2_sftp_seek64: new man page
Split off libssh2_sftp_seek64 from the libssh2_sftp_seek man page, and
mentioned that we consider the latter deprecated. Also added a mention
about the dangers of doing seek during writing or reading.
2010-12-11 00:03:42 +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
499b989d46 sftp_append: new example doing SFTP append 2010-12-10 23:49:16 +01:00
Daniel Stenberg
fa07d9fefc MAX_SFTP_OUTGOING_SIZE: 30000
I ran SFTP upload tests against localhost. It showed that to make the
app reach really good speeds, I needed to do a little code tweak and
change MAX_SFTP_OUTGOING_SIZE from 4000 to 30000. The tests I did before
with the high latency tests didn't show any real difference whatever I
had that size set to.

This number is the size in bytes that libssh2 cuts off the large input
buffer and sends off as an individual sftp packet.
2010-12-06 21:10:10 +01:00
Daniel Stenberg
b0c32a85fc sftp_write_sliding.c: new example
This is an example that is very similar to sftp_write_nonblock.c, with
the exception that this uses

1 - a larger upload buffer

2 - a sliding buffer mechnism to allow the app to keep sending lots of
data to libssh2 without having to first drain the buffer.

These are two key issues to make libssh2 SFTP uploads really perform
well at this point in time.
2010-12-05 00:06:39 +01:00
Daniel Stenberg
7ed7dad3b4 cpp: s/#elsif/#elif
This looks like a typo as #elsif is not really C...
2010-12-02 12:40:59 +01:00
Daniel Stenberg
b215ec0af5 _libssh2_channel_write: revert channel_write() use
The attempts made to have _libssh2_channel_write() accept larger pieces
of data and split up the data by itself into 32700 byte chunks and pass
them on to channel_write() in a loop as a way to do faster operations on
larger data blocks was a failed attempt.

The reason why it is difficult:

The API only allows EAGAIN or a length to be returned. When looping over
multiple blocks to get sent, one block can get sent and the next might
not. And yet: when transport_send() has returned EAGAIN we must not call
it again with new data until it has returned OK on the existing data it
is still working on. This makes it a mess and we do get a much easier
job by simply returning the bytes or EAGAIN at once, as in the EAGAIN
case we can assume that we will be called with the same arguments again
and transport_send() will be happy.

Unfortunately, I think we take a small performance hit by not being able
to do this.
2010-11-13 23:13:21 +01:00
Daniel Stenberg
ac6d0fb706 ssh2_echo: new example
This is a new example snippet. The code is largely based on ssh2_exec,
and is written by Tommy Lindgren. I edited it into C90 compliance and to
conform to libssh2 indent style and some more.
2010-11-13 23:11:39 +01:00
Daniel Stenberg
e87293d480 send_existing: return after send_existing
When a piece of data is sent from the send_existing() function we must
make the parent function return afterwards. Otherwise we risk that the
parent function tries to send more data and ends up getting an EGAIN for
that more data and since it can only return one return code it doesn't
return info for the successfully sent data.

As this change is a regression I now added a larger comment explaining
why it has to work like this.
2010-11-13 12:25:06 +01:00
Daniel Stenberg
a3ce1073c4 _libssh2_channel_write: count resent data as written
In the logic that resends data that was kept for that purpose due to a
previous EAGAIN, the data was not counted as sent causing badness.
2010-11-13 12:23:23 +01:00
Peter Stuge
97a1881749 Use fprintf(stderr, ) instead of write(2, ) for debugging 2010-11-13 02:06:41 +01:00
Peter Stuge
80f7508d55 session/transport: Correctly handle when _libssh2_send() returns -EAGAIN 2010-11-13 01:53:39 +01:00
Peter Stuge
e8c44e789f src/agent.c: Simplify _libssh2_send() error checking ever so slightly 2010-11-13 01:50:24 +01:00
Daniel Stenberg
ca2e81eb1f send/recv: use _libssh2_recv and _libssh2_send now
Starting now, we unconditionally use the internal replacement functions
for send() and recv() - creatively named _libssh2_recv() and
_libssh2_send().

On errors, these functions return the negative 'errno' value instead of
the traditional -1. This design allows systems that have no "natural"
errno support to not have to invent it. It also means that no code
outside of these two transfer functions should use the errno variable.
2010-11-12 21:53:35 +01:00
Daniel Stenberg
aff9c825c8 channel_write: move some logic to _libssh2_channel_write
Some checks are better done in _libssh2_channel_write just once per
write instead of in channel_write() since the looping will call the
latter function multiple times per _libssh2_channel_write() invoke.
2010-11-12 15:15:46 +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
160453cee4 SCP: on failure, show the numerical error reason
By calling libssh2_session_last_errno()
2010-11-10 17:26:38 +01:00
Daniel Stenberg
82fa5d2167 SFTP: provide the numerical error reason on failure 2010-11-10 17:26:02 +01:00
Daniel Stenberg
1c3e1c4d25 SCP: clean up failure treatment
When SCP send or recv fails, it gets a special message from the server
with a warning or error message included. We have no current API to
expose that message but the foundation is there. Removed unnecessary use
of session struct fields.
2010-11-10 17:17:32 +01:00
Daniel Stenberg
1d2a5b8456 sftp_write: enlarge buffer to perform better 2010-11-10 15:00:55 +01:00
Daniel Stenberg
1d11d02aa9 packets: code cleanup
I added size checks in several places. I fixed the code flow to be easier
to read in some places.

I removed unnecessary zeroing of structs. I removed unused struct fields.
2010-11-10 14:56:14 +01:00
Daniel Stenberg
f4ad3e0120 LIBSSH2_CALLBACK_MACERROR: clarify return code use 2010-11-10 14:41:56 +01:00
Daniel Stenberg
772564650d _libssh2_userauth_publickey: avoid shadowing 2010-11-10 13:28:33 +01:00
Daniel Stenberg
05ba8db8aa packet: avoid shadowing global symbols 2010-11-10 13:06:39 +01:00
Daniel Stenberg
1964ccb557 sftp_readdir: avoid shadowing 2010-11-10 13:05:08 +01:00
Daniel Stenberg
bef0ce5392 shadowing: don't shadow the global compress 2010-11-10 13:04:30 +01:00
Daniel Stenberg
fb6afd01a1 _libssh2_packet_add: turn ifs into a single switch 2010-11-10 12:21:48 +01:00
Daniel Stenberg
a302428335 _libssh2_packet_add: check SSH_MSG_GLOBAL_REQUEST packet 2010-11-09 19:59:18 +01:00
Daniel Stenberg
7ad152a6b2 _libssh2_packet_add: SSH_MSG_DEBUG length checks
Verify lengths before using them. Read always_display from the correct
index. Don't copy stuff around just to provide zero-termination of the
strings.
2010-11-09 15:07:32 +01:00
Daniel Stenberg
075ff19574 _libssh2_packet_add: SSH_MSG_IGNORE skip memmove
There's no promise of a zero termination of the data in the callback so
no longer perform ugly operation in order to provide it.
2010-11-09 14:57:36 +01:00
Daniel Stenberg
16f46c1cfc _libssh2_packet_add: SSH_MSG_DISCONNECT length checks
Verify lengths before trying to read data.
2010-11-09 14:53:44 +01:00
Daniel Stenberg
aa2fdb3e7e indent: break lines at 80 columns 2010-11-09 14:32:02 +01:00
Daniel Stenberg
8f10da89c5 SSH_MSG_CHANNEL_OPEN_FAILURE: used defined values
We don't like magic numbers in the code. Now the acceptable failure
codes sent in the SSH_MSG_CHANNEL_OPEN_FAILURE message are added as
defined values in the private header file.
2010-11-09 14:28:29 +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
095e9e7b3e _libssh2_wait_socket: detect nothing-to-wait-for
If _libssh2_wait_socket() gets called but there's no direction set to
wait for, this causes a "hang". This code now detects this situation,
set a 1 second timeout instead and outputs a debug output about it.
2010-11-09 13:07:15 +01:00
Daniel Stenberg
588c8946fc decomp: remove the free_dest argument
Since the decompress function ALWAYS returns allocated memory we get a
lot simpler code by removing the ability to return data unallocated.
2010-11-03 15:03:57 +01:00
Daniel Stenberg
a6fc9aeec9 decomp: cleaned off old compression stuff
I cleared off legacy code from when the compression and decompression
functions were a single unified function. Makes the code easier to read
too.
2010-11-03 14:52:42 +01:00
TJ Saunders
7603c0f854 decomp: increase decompression buffer sizes 2010-11-03 14:45:52 +01:00
TJ Saunders
8974dc05ae zlib: Add debug tracing of zlib errors 2010-11-03 14:42:44 +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
Jasmeet Bagga
73be9fab04 kex_agree_hostkey: fix NULL pointer derefence
While setting up the session, ssh tries to determine the type of
encryption method it can use for the session. This requires looking at
the keys offered by the remote host and comparing these with the methods
supported by libssh2 (rsa & dss). To do this there is an iteration over
the array containing the methods supported by libssh2.

If there is no agreement on the type of encryption we come to the 3rd
entry of the hostkeyp array. Here hostkeyp is valid but *hostkep is
NULL. Thus when we dereference that in (*hostkeyp)->name there is a
crash
2010-11-02 00:02:25 +01:00
Daniel Stenberg
753e55ef23 _libssh2_transport_send: remove dead assignment
'data' isn't accessed beyond this point so there's no need to assign it.
2010-11-01 23:00:07 +01:00
Daniel Stenberg
4760e4d051 scp_recv: remove dead assignment
Instead of assigning a variable we won't read, we now use the more
explicit (void) prefix.
2010-11-01 22:59:15 +01:00
Daniel Stenberg
57af0da9f7 sftp_write: removed superfluous assignment 2010-11-01 22:58:47 +01:00