Commit Graph

1314 Commits

Author SHA1 Message Date
Daniel Stenberg
7015488150 libssh2_sftp_stat_ex.3: cleaned up, extended
Removed the macros from it as they have their own man pages.

Added the LIBSSH2_SFTP_ATTRIBUTES struct in here for easier reference.
2011-01-06 00:30:32 +01:00
Daniel Stenberg
164838c7dd sftp_readdir: return error if buffer is too small
If asked to read data into a buffer and the buffer is too small to hold
the data, this function now returns an error instead of as previously
just copy as much as fits.
2011-01-04 14:30:04 +01:00
Daniel Stenberg
f9b1b95059 sftp_symlink: return error if receive buffer too small
and clean up some variable type mismatches

Discussion: http://www.libssh2.org/mail/libssh2-devel-archive-2011-01/0001.shtml
2011-01-04 14:15:57 +01:00
Daniel Stenberg
59207291fc docs: clarify what happens with a too small buffer
This flaw is subject to change, but I figured it might be valuable to
users of existing code to know how it works.
2011-01-03 00:07:44 +01:00
Daniel Stenberg
0da37e0924 channel_request_pty_size: fix reqPTY_state
The state variable isn't properly set so every other call to the
function fails!

Bug: http://libssh2.org/mail/libssh2-devel-archive-2010-12/0096.shtml
Reported by: Steve Legg
2011-01-01 16:16:32 +01:00
Daniel Stenberg
4552c73cd5 data size: cleanup
Fix 64bit warnings by using (s)size_t and dedicated uint32_t types more.
2010-12-30 00:09:53 +01:00
Pierre Joye
306929ee80 ssize_t: proper typedef with MSVC compilers
As discussed on the mailing list, it was wrong for win64 and using the
VC-provided type is the safest approach instead of second- guessing
which one it should be.
2010-12-29 23:22:00 +01:00
Guenter Knauf
326f741a52 Updated OpenSSL version. 2010-12-22 14:39:59 +01:00
Guenter Knauf
aa4f861643 Expanded tabs to spaces. 2010-12-22 14:27:55 +01:00
Joey Degges
fd691deb17 _libssh2_ntohu64: fix conversion from network bytes to uint64
Cast individual bytes to uint64 to avoid overflow in arithmetic.
2010-12-21 13:15:42 +01:00
Daniel Stenberg
20da09932e libssh2_userauth_list: language fix
"faily" is not a good English word, and I also cleaned up some other minor
mistakes
2010-12-20 14:22:07 +01:00
Daniel Stenberg
3ab7af095a crypto: unify the generic functions
Added crypto.h that is the unified header to include when using crypto
functionality. It should be the only header that needs to adapt to the
underlying crypto library in use. It provides the set of prototypes that
are library agnostic.
2010-12-19 00:00:50 +01:00
Mark Smith
5b1a7ec2f1 userauth: derive publickey from private
Pass a NULL pointer for the publickey parameter of
libssh2_userauth_publickey_fromfile and
libssh2_userauth_hostbased_fromfile functions.  In this case, the
functions recompute the public key from the private key file data.

This is work done by Jean-Louis CHARTON
<Jean-Louis.CHARTON@oikialog.com>, then adapted by Mark Smith and
slightly edited further by me Daniel.

WARNING: this does leave the feature NOT WORKING when libssh2 is built
to use libgcrypt instead of OpenSSL simply due to lack of
implementation.
2010-12-18 23:38:08 +01:00
Daniel Stenberg
5ee38702a0 ssh2_echo: Value stored to 'exitcode' is never read 2010-12-15 21:58:43 +01:00
Daniel Stenberg
2165ceacd3 _libssh2_packet_add: fix SSH_MSG_DEBUG weirdness
I believe I may have caused this weird typo style error when I cleaned
up this function a while ago. Corrected now.
2010-12-15 21:57:06 +01:00
Daniel Stenberg
121237ce2f uint32: more longs converted to proper types
I also moved the MAC struct over to the mac.h header file and made sure
that the users of that struct include that file.
2010-12-15 09:52:18 +01:00
Daniel Stenberg
b3e832172b SFTP: more types to uint32_t
The 'num_names' field in the SSH_FXP_NAME response is an unsigned 32bit
value so we make sure to treat it like that.
2010-12-15 09:31:37 +01:00
Daniel Stenberg
3faa8bc940 SFTP: request_ids are uint32_t
I went over the code and made sure we use uint32_t all over for the
request_id data. It is an unsigned 32bit value on the wire.
2010-12-15 09:27:00 +01:00
Daniel Stenberg
2f0c0cef76 SFTP: store request_id separately in packets
By using a new separate struct for incoming SFTP packets and not sharing
the generic packet struct, we can get rid of an unused field and add a
new one dedicated for holding the request_id for the incoming
package. As sftp_packet_ask() is called fairly often, a "mere" integer
comparison is MUCH faster than the previous memcmp() of (typically) 5
bytes.
2010-12-14 23:49:51 +01:00
Daniel Stenberg
75909e05a9 libssh2_sftp_open_ex: man page extended and cleaned up
I added the missing documentation for the 'flags' argument.
2010-12-14 15:06:04 +01:00
Daniel Stenberg
47b4e62780 SFTP: unify the READ/WRITE chunk structs 2010-12-14 13:29:41 +01:00
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