88 Commits

Author SHA1 Message Date
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
Daniel Stenberg
0751067c2f Fix compiler warnings appearing with VS2008. Based on Steven Van Ingelgem's
patch in #2787839 with a bunch of additional edits by yours truly.
2009-07-07 13:44:17 +02:00
Daniel Stenberg
6b7c19ec26 remove #if 0'ed code 2009-05-25 11:23:06 +02:00
Daniel Stenberg
42e9f02025 spell fix a comment 2009-05-25 10:58:13 +02:00
Daniel Stenberg
5a162ad9f8 Added some clarifying comments on how the 'sftpInit_sftp' and
'sftpInit_channel' struct fields within the session struct are used. And made
sure to clear them both correctly when sftp_init() returns instead of at
shutdown time, as it must not touch them at shutdown time. This should make it
possible to properly make more than one SFTP handle.
2009-05-25 10:50:49 +02:00
Daniel Stenberg
0357ce6c48 clear session->sftpInit_sftp unconditionally 2009-05-24 23:51:59 +02:00
Daniel Stenberg
c5f335ad4f Fix my recent session->sftpInit_sftp fix which wasn't correct. The memory area
does not need to be freed (it already gets freed) but clearing the pointer is
a good idea. And it should be done _after_ the channel_free() call.
2009-05-24 23:44:52 +02:00
Daniel Stenberg
f1f49c3cce - Anonymous bug report #2795816 revealed that libssh2_sftp_shutdown() did not
properly free/cleanup the SFTP handle so libssh2 leaked memory and caused
   an assert() on subsequent libssh2_sftp_init() calls on the same session.
2009-05-23 22:30:43 +02:00
Daniel Stenberg
b755f3eb10 First, only try to send max packet size *4 to channel write, as trying to send
much larger packages only cause internal problems and much larger allocations.

Also fix sftp_write() when _libssh2_channel_write() returns that a packet was
only partially sent as that is not an error.

Fixed a few error messages to more accurately point out the problem
2009-05-20 14:31:46 +02:00
Daniel Stenberg
e63cbd907f Jussi Mononen pointed out we used an unsigned variable to store negative
values in, when a plain int is much better anyway since it matches the return
type.
2009-04-06 14:50:29 +00:00
Daniel Stenberg
117b95e6e3 made sure the SFTP code makes more use of internal non-blocking functions
instead of the external API entries
2009-03-29 22:09:29 +00:00
Daniel Stenberg
75d5830490 Additional non-blocking fixes. 2009-03-27 22:24:09 +00:00
Daniel Stenberg
103a6e9e0b Me and my long fingers couldn't resist "merging" these statements in a previous
commit but of course that broke functionality and this is a revert of that
change.
2009-03-27 21:52:49 +00:00
Daniel Stenberg
4353711127 fixed sftp_shutdown() for the blockiness and fixed libssh2_channel_close()
to work properly non-blocking
2009-03-27 20:20:48 +00:00
Daniel Stenberg
f390c8e02d fix comments, moved to htonu64 function to sftp.c and made it static 2009-03-27 07:03:00 +00:00
Daniel Stenberg
eabe072496 * Renamed the functions in src/transport.c to be _libssh2_transport_ prefixed
and introduced a transport.h header.

* Fixed the blocking mode to only change behavior not the actual underlying
  socket mode so we now always work with non-blocking sockets. This also
  introduces a new rule of thumb in libssh2 code: we don't call the
  external function calls internally. We use the internal (non-blocking)
  ones!

* libssh2_channel_receive_window_adjust2 was added and
  libssh2_channel_receive_window_adjust is now deprecated

* Introduced "local" header files with prototypes etc for different parts
  instead of cramming everything into libssh2_priv.h. channel.h is the
  first.
2009-03-26 15:41:14 +00:00
Daniel Stenberg
2e548c1ca0 Updated comments and removed "libssh2_" prefixes from static functions 2009-03-23 13:35:20 +00:00
Daniel Stenberg
cc5e952fa0 A cleanup effort: libssh2_ prefixes only on external APIs. Use _libssh2_ prefix
for library-wide internal functions. Don't use any of those on static functions.
I also did some comments and whitespace changes.
2009-03-17 13:48:35 +00:00
Daniel Stenberg
a52f5d3b7e Cleanups, that do seem to have boosted SFTP download performance up to 300% in
some tests:

  * cut off "_ex" from several internal function names

  * corrected some log outputs

  * simplified libssh2_channel_read_ex() and made it much faster in the process

  * cut out {{{ and }}} comments that were incorrect anyway

  * fixed sftp_packet_ask() to return the correct packet by using memcmp() and
    not strncmp()

  * fixed mkdir()'s wait for packet to use the correct request_id - it
    semi-worked previously because strncmp() in sftp_packet_ask() made it
    match far too easily.

  * took away the polling functionality from sftp_packet_ask() since it wasn't
    used
2009-03-13 22:15:27 +00:00
Daniel Stenberg
62769b438f libssh2_sftp_seek64() it is now for the 64bit seek function too as the seek2
name has never been used in a release and it makes the naming consistent
2008-12-22 13:18:36 +00:00
Daniel Stenberg
8eba2961ac Based on Alexander Lamaison's patch, there's now a new
function called libssh2_sftp_tell64() that returns the 64 bit file offset,
as the existing libssh2_sftp_tell() only returns a size_t.
2008-12-22 12:46:45 +00:00
Daniel Stenberg
962a41e4ec first conversion of a malloc => buffer in the sftp handle struct 2008-12-22 12:38:41 +00:00
Daniel Stenberg
70f844e57c - Markus Moeller fixed the issue also reported by Alexander Lamaison which
caused SFTP reads with large buffers to fail.
2008-12-19 22:21:36 +00:00
Daniel Stenberg
e26956be72 Avoid one malloc by putting the entire handle buffer in the handle struct
at once, use a define for the maximum size length of the handle instead of
'256' in the code.
2008-12-17 10:45:20 +00:00
Daniel Stenberg
2535c5c2ee removed some more libssh2_ prefixes from private functions
Made the libssh2_sftp_open_ex() deal with servers that first responds with
STATUS OK and then sends the actual HANDLE. It seems openssh does this at
times and it screwed things up. To me it seems like a spec violation...
2008-12-16 15:35:33 +00:00
Daniel Stenberg
f1dae83d5e Nothing used libssh2_sftp_packet_read's flush argument anymore so I removed
it and simplified the code somewhat thanks to that. I then renamed the function
to sftp_packet_read() only since it is private in this file anyway.
2008-12-16 12:31:58 +00:00
Daniel Stenberg
bcad67636b renamed libssh2_sftp_packet_requirev to plain sftp_packet_requirev since it
is private in this file only and a shorter name is nicer

Removed a "flush" of the data in sftp_packet_requirev() that now seems to have
made SFTP operations a lot more reliable. It didn't make much sense to have it
there but if someone can present a reason for one I figure we should carefully
investigate one and only do it conditionally where/when needed.
2008-12-15 22:58:07 +00:00
Daniel Stenberg
61fda23340 - Based on bug #1815692, we introduce libssh2_sftp_seek2() that allows seeking
beyond the 2GB margin even on 32bit machines.
2008-09-29 14:11:29 +00:00
Daniel Stenberg
9b31ca67ac Gah, I broke Sebastian's patch when I left out the parentheses his patch
did contain. Added properly now.
2008-06-24 22:33:25 +00:00
Daniel Stenberg
3f0d30d1d6 |sftp.c:1470: warning: cast to pointer from integer of different size Another
reason why macros are evil: The string (which is allready char *) should be
cast into char * not the integer.

Signed-off-by: Sebastian Siewior <sebastian@breakpoint.cc>
2008-06-23 22:20:00 +00:00
Guenter Knauf
4600d108ed fixed 'uninitialized' compiler warnings. 2007-11-18 20:57:13 +00:00
Daniel Stenberg
210459db4b re-indented the source code with this script:
indent \
--braces-on-if-line \
--braces-after-struct-decl-line \
--space-after-cast \
--line-length 79 \
--comment-line-length 79 \
--cuddle-else \
--no-tabs \
--tab-size 8 \
--indent-level 4 \
--no-space-after-for \
--space-after-if \
--space-after-while \
--no-space-after-function-call-names \
*.[ch]
2007-08-06 20:48:04 +00:00
James Housley
a87fdff9e9 The variable "packet" needs to be in LIBSSH2_SFTP_HANDLE for re-entry when
blocking in libssh2_sftp_close_handle()
2007-07-09 15:11:37 +00:00
James Housley
9dfd71121e Small fixes:
* libssh2_sftp_packet_read() - use the right variable for the
        number of bytes returned by libssh2_channel_read_ex()
* libssh2_sftp_packet_requirev - only call libssh2_waitsocket() when
        in blocking IO mode
2007-06-18 22:38:32 +00:00
James Housley
019cd1abc0 Clean up and standardization of code 2007-06-17 23:34:35 +00:00
James Housley
0742a972c1 Created libssh2_sftp_readdir_ex() and updated LIBSSH2_APINO to 200706151200 2007-06-15 17:22:49 +00:00
James Housley
8223acec0a Don't use memory after it has been freed, pointed out by Troy Gutjahr 2007-06-15 01:41:58 +00:00
James Housley
dde2b09496 libssh2_channel_free() actually can return PACKET_EAGAIN. Update all
calling functions to support that with the following API notes:

* libssh2_publickey_shutdown(), libssh2_session_free() changed
  to return an "int" to allow signaling of LIBSSH2_ERROR_EAGAIN.

* libssh2_scp_recv(), libssh2_scp_send_ex() and libssh2_sftp_init()
  will loop in on libssh2_channel_free() when there is an error.
  It is not possible to return LIBSSH2_ERROR_EAGAIN in this condition
  in these 3 functions and not lose the original error code.
2007-06-12 18:27:37 +00:00
James Housley
b2f3582a59 When shutting down sub-systems and closing the channel try our best
to free any memory still allocated in the state variables
2007-06-07 16:43:20 +00:00
James Housley
7d57222912 Finish making SFTP fully non-blocking capable.
Functions that return an "int", and friends, return LIBSSH2SFTP_EAGAIN.
Functions that return a structure return NULL and set the error to
LIBSSH2_ERROR_EAGAIN
2007-06-07 16:01:12 +00:00
James Housley
d141ba49f3 Make libssh2_sftp_write() be fully non-blocking. The state of the socket
is fully honored.  LIBSSH2SFTP_EAGAIN is returned when the call would
block.
2007-06-06 19:52:11 +00:00
James Housley
4b8db8c1ab Modify the code to truely support non-blocking. Propogate the EAGAIN error
all the way up to the user interface.  All code modules bug sftp.c have
been completed.

Functions that return an "int", or similar return LIBSSH2CHANNEL_EAGAIN to
indicate some part of the call would block, in non-blocking mode.

Functions that return a structure, like "LIBSSH2_CHANNEL *", return NULL
and set the libssh2 error.  The error can be obtained with either
libssh2_session_last_error() or libssh2_session_last_errno().  Either of
these will return the error code of LIBSSH2_ERROR_EAGAIN if the
call would block, in non-blocking mode.

The current state of a function and some variable are keep in the
structures so that on the next call the operation that would block can
be retried again with the same data.
2007-06-06 12:34:06 +00:00
James Housley
412b25d971 Initially the libssh2 code was indented with tabs of 4 spaces. Some of
the recent commits converted the tabs to 4 spaces, which matched the
initial indent size.  Other commits converted the tabs to 8 spaces, this
didn't match.

All the code has been converted to 4 space indents.  No changes to line
lengths or actual code was performed.  This is in preperation to my up
coming non-blocking work so my commits should only be code changes and
line lengths in the code I am working on.
2007-05-28 17:56:08 +00:00
James Housley
a66885c51c Make _libssh2_sftp_mkdir_ex() fully non-blocking safe. This makes
libssh2_sftp_mkdirnb_ex() non-blocking safe and libssh2_sftp_mkdir_ex()
blocking safe
2007-04-22 19:51:24 +00:00