1
1

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
Этот коммит содержится в:
Daniel Stenberg 2009-03-13 22:15:27 +00:00
родитель d89782d99f
Коммит a52f5d3b7e
10 изменённых файлов: 377 добавлений и 397 удалений

20
NEWS
Просмотреть файл

@ -1,3 +1,23 @@
- (Mar 13 2009) Daniel Stenberg: 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
- (Mar 7 2009) Olivier Hervieu pointed out a flaw in the
libssh2_channel_x11_req_ex() function that made it produce a crappy random

Просмотреть файл

@ -224,12 +224,12 @@ libssh2_channel_open_ex(LIBSSH2_SESSION * session, const char *channel_type,
}
if (session->open_state == libssh2_NB_state_sent) {
rc = libssh2_packet_requirev_ex(session, reply_codes,
&session->open_data,
&session->open_data_len, 1,
session->open_packet + 5 +
channel_type_len, 4,
&session->open_packet_requirev_state);
rc = libssh2_packet_requirev(session, reply_codes,
&session->open_data,
&session->open_data_len, 1,
session->open_packet + 5 +
channel_type_len, 4,
&session->open_packet_requirev_state);
if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block", 0);
return NULL;
@ -299,13 +299,15 @@ libssh2_channel_open_ex(LIBSSH2_SESSION * session, const char *channel_type,
/* Clear out packets meant for this channel */
libssh2_htonu32(channel_id, session->open_channel->local.id);
while ((libssh2_packet_ask_ex
(session, SSH_MSG_CHANNEL_DATA, &session->open_data,
&session->open_data_len, 1, channel_id, 4, 0) >= 0)
while ((libssh2_packet_ask(session, SSH_MSG_CHANNEL_DATA,
&session->open_data,
&session->open_data_len, 1,
channel_id, 4, 0) >= 0)
||
(libssh2_packet_ask_ex
(session, SSH_MSG_CHANNEL_EXTENDED_DATA, &session->open_data,
&session->open_data_len, 1, channel_id, 4, 0) >= 0)) {
(libssh2_packet_ask(session, SSH_MSG_CHANNEL_EXTENDED_DATA,
&session->open_data,
&session->open_data_len, 1,
channel_id, 4, 0) >= 0)) {
LIBSSH2_FREE(session, session->open_data);
session->open_data = NULL;
}
@ -483,10 +485,9 @@ libssh2_channel_forward_listen_ex(LIBSSH2_SESSION * session, const char *host,
}
if (session->fwdLstn_state == libssh2_NB_state_sent) {
rc = libssh2_packet_requirev_ex(session, reply_codes, &data, &data_len,
0, NULL, 0,
&session->
fwdLstn_packet_requirev_state);
rc = libssh2_packet_requirev(session, reply_codes, &data, &data_len,
0, NULL, 0,
&session->fwdLstn_packet_requirev_state);
if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block", 0);
return NULL;
@ -796,10 +797,10 @@ libssh2_channel_setenv_ex(LIBSSH2_CHANNEL * channel, const char *varname,
}
if (channel->setenv_state == libssh2_NB_state_sent) {
rc = libssh2_packet_requirev_ex(session, reply_codes, &data, &data_len,
1, channel->setenv_local_channel, 4,
&channel->
setenv_packet_requirev_state);
rc = libssh2_packet_requirev(session, reply_codes, &data, &data_len,
1, channel->setenv_local_channel, 4,
&channel->
setenv_packet_requirev_state);
if (rc == PACKET_EAGAIN) {
return PACKET_EAGAIN;
}
@ -921,10 +922,9 @@ libssh2_channel_request_pty_ex(LIBSSH2_CHANNEL * channel, const char *term,
}
if (channel->reqPTY_state == libssh2_NB_state_sent) {
rc = libssh2_packet_requirev_ex(session, reply_codes, &data, &data_len,
1, channel->reqPTY_local_channel, 4,
&channel->
reqPTY_packet_requirev_state);
rc = libssh2_packet_requirev(session, reply_codes, &data, &data_len,
1, channel->reqPTY_local_channel, 4,
&channel->reqPTY_packet_requirev_state);
if (rc == PACKET_EAGAIN) {
return PACKET_EAGAIN;
} else if (rc) {
@ -1135,10 +1135,9 @@ libssh2_channel_x11_req_ex(LIBSSH2_CHANNEL * channel, int single_connection,
}
if (channel->reqX11_state == libssh2_NB_state_sent) {
rc = libssh2_packet_requirev_ex(session, reply_codes, &data, &data_len,
1, channel->reqX11_local_channel, 4,
&channel->
reqX11_packet_requirev_state);
rc = libssh2_packet_requirev(session, reply_codes, &data, &data_len,
1, channel->reqX11_local_channel, 4,
&channel->reqX11_packet_requirev_state);
if (rc == PACKET_EAGAIN) {
return PACKET_EAGAIN;
} else if (rc) {
@ -1243,10 +1242,9 @@ libssh2_channel_process_startup(LIBSSH2_CHANNEL * channel, const char *request,
}
if (channel->process_state == libssh2_NB_state_sent) {
rc = libssh2_packet_requirev_ex(session, reply_codes, &data, &data_len,
1, channel->process_local_channel, 4,
&channel->
process_packet_requirev_state);
rc = libssh2_packet_requirev(session, reply_codes, &data, &data_len,
1, channel->process_local_channel, 4,
&channel->process_packet_requirev_state);
if (rc == PACKET_EAGAIN) {
return PACKET_EAGAIN;
} else if (rc) {
@ -1374,10 +1372,12 @@ libssh2_channel_get_exit_status(LIBSSH2_CHANNEL * channel)
/* }}} */
/* {{{ libssh2_channel_receive_window_adjust
* Adjust the receive window for a channel by adjustment bytes
* If the amount to be adjusted is less than LIBSSH2_CHANNEL_MINADJUST and
* force is 0 the adjustment amount will be queued for a later packet
/*
* libssh2_channel_receive_window_adjust
*
* Adjust the receive window for a channel by adjustment bytes. If the amount
* to be adjusted is less than LIBSSH2_CHANNEL_MINADJUST and force is 0 the
* adjustment amount will be queued for a later packet.
*
* Returns the new size of the receive window (as understood by remote end)
*/
@ -1407,11 +1407,10 @@ libssh2_channel_receive_window_adjust(LIBSSH2_CHANNEL * channel,
adjustment += channel->adjust_queue;
channel->adjust_queue = 0;
/* Adjust the window based on the block we just freed */
channel->adjust_adjust[0] = SSH_MSG_CHANNEL_WINDOW_ADJUST;
libssh2_htonu32(channel->adjust_adjust + 1, channel->remote.id);
libssh2_htonu32(channel->adjust_adjust + 5, adjustment);
libssh2_htonu32(&channel->adjust_adjust[1], channel->remote.id);
libssh2_htonu32(&channel->adjust_adjust[5], adjustment);
_libssh2_debug(channel->session, LIBSSH2_DBG_CONN,
"Adjusting window %lu bytes for data flushed from "
"channel %lu/%lu",
@ -1423,18 +1422,19 @@ libssh2_channel_receive_window_adjust(LIBSSH2_CHANNEL * channel,
rc = libssh2_packet_write(channel->session, channel->adjust_adjust, 9);
if (rc == PACKET_EAGAIN) {
return PACKET_EAGAIN;
} else if (rc) {
}
else if (rc) {
libssh2_error(channel->session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send transfer-window adjustment packet, "
"deferring",
0);
"deferring", 0);
channel->adjust_queue = adjustment;
channel->adjust_state = libssh2_NB_state_idle;
} else {
channel->adjust_state = libssh2_NB_state_idle;
}
else {
channel->remote.window_size += adjustment;
}
channel->adjust_state = libssh2_NB_state_idle;
return channel->remote.window_size;
}
@ -1482,11 +1482,10 @@ libssh2_channel_handle_extended_data2(LIBSSH2_CHANNEL * channel,
return 0;
}
/* }}} */
/*
* {{{ libssh2_channel_read_ex
* Read data from a channel blocking or non-blocking depending on set state
* libssh2_channel_read_ex
*
* Read data from a channel (blocking or non-blocking depending on set state)
*
* When this is done non-blocking, it is important to not return 0 until the
* currently read channel is complete. If we read stuff from the wire but it
@ -1498,27 +1497,24 @@ libssh2_channel_read_ex(LIBSSH2_CHANNEL * channel, int stream_id, char *buf,
size_t buflen)
{
LIBSSH2_SESSION *session = channel->session;
libssh2pack_t rc = 0;
libssh2pack_t rc;
if (channel->read_state == libssh2_NB_state_idle) {
_libssh2_debug(session, LIBSSH2_DBG_CONN,
"Attempting to read %d bytes from channel %lu/%lu stream #%d",
"Requested to read %d bytes from channel %lu/%lu "
"stream #%d",
(int) buflen, channel->local.id, channel->remote.id,
stream_id);
/* process all incoming packets */
do {
if (libssh2_waitsocket(session, 0) > 0) {
rc = libssh2_packet_read(session);
} else {
/* Set for PACKET_EAGAIN so we continue */
rc = PACKET_EAGAIN;
}
} while (rc > 0);
rc = 1; /* set to >0 to let the while loop start */
/* process all pending incoming packets */
while (rc > 0)
rc = libssh2_packet_read(session);
if ((rc < 0) && (rc != PACKET_EAGAIN))
return -1;
if ((rc < 0) && (rc != PACKET_EAGAIN)) {
return rc;
}
channel->read_bytes_read = 0;
channel->read_packet = session->packets.head;
@ -1537,126 +1533,90 @@ libssh2_channel_read_ex(LIBSSH2_CHANNEL * channel, int stream_id, char *buf,
rc = 0;
channel->read_block = 0;
do {
if (channel->read_block) {
/* in the second lap and onwards, do this...
* If we haven't yet filled our buffer, try to read more
* data. */
if ( channel->read_bytes_read < (int) buflen) {
rc = libssh2_packet_read(session);
while (channel->read_packet &&
!channel->remote.close &&
(channel->read_bytes_read < (int) buflen)) {
LIBSSH2_PACKET *readpkt = channel->read_packet;
/* If we didn't find any more data to read */
if (rc < 0) {
if ( channel->read_bytes_read > 0){
break; /* finish processing and return */
}
/* In case packet gets destroyed during this iteration */
channel->read_next = readpkt->next;
/* no packets available, no data read. */
channel->read_state = libssh2_NB_state_idle;
return rc;
}
/* We read more data, restart our processing at the beginning
* of our packet list. */
channel->read_packet = session->packets.head;
channel->read_local_id =
libssh2_ntohu32(readpkt->data + 1);
/*
* Either we asked for a specific extended data stream
* (and data was available),
* or the standard stream (and data was available),
* or the standard stream with extended_data_merge
* enabled and data was available
*/
if ((stream_id
&& (readpkt->data[0] == SSH_MSG_CHANNEL_EXTENDED_DATA)
&& (channel->local.id == channel->read_local_id)
&& (stream_id == (int) libssh2_ntohu32(readpkt->data + 5)))
|| (!stream_id && (readpkt->data[0] == SSH_MSG_CHANNEL_DATA)
&& (channel->local.id == channel->read_local_id))
|| (!stream_id
&& (readpkt->data[0] == SSH_MSG_CHANNEL_EXTENDED_DATA)
&& (channel->local.id == channel->read_local_id)
&& (channel->remote.extended_data_ignore_mode ==
LIBSSH2_CHANNEL_EXTENDED_DATA_MERGE))) {
channel->read_want = buflen - channel->read_bytes_read;
channel->read_unlink_packet = 0;
if (channel->read_want >=
(int) (readpkt->data_len - readpkt->data_head)) {
channel->read_want = readpkt->data_len - readpkt->data_head;
channel->read_unlink_packet = 1;
}
else { /* The read buffer is full, finish processing and return */
break;
}
}
while (channel->read_packet
&& (channel->read_bytes_read < (int) buflen)) {
/* In case packet gets destroyed during this iteration */
channel->read_next = channel->read_packet->next;
_libssh2_debug(session, LIBSSH2_DBG_CONN,
"Reading %d of buffered data from %lu/%lu/%d",
channel->read_want, channel->local.id,
channel->remote.id, stream_id);
memcpy(buf + channel->read_bytes_read,
readpkt->data + readpkt->data_head, channel->read_want);
readpkt->data_head += channel->read_want;
channel->read_bytes_read += channel->read_want;
channel->read_local_id =
libssh2_ntohu32(channel->read_packet->data + 1);
/*
* Either we asked for a specific extended data stream
* (and data was available),
* or the standard stream (and data was available),
* or the standard stream with extended_data_merge
* enabled and data was available
*/
if ((stream_id
&& (channel->read_packet->data[0] ==
SSH_MSG_CHANNEL_EXTENDED_DATA)
&& (channel->local.id == channel->read_local_id)
&& (stream_id ==
(int) libssh2_ntohu32(channel->read_packet->data + 5)))
|| (!stream_id
&& (channel->read_packet->data[0] == SSH_MSG_CHANNEL_DATA)
&& (channel->local.id == channel->read_local_id))
|| (!stream_id
&& (channel->read_packet->data[0] ==
SSH_MSG_CHANNEL_EXTENDED_DATA)
&& (channel->local.id == channel->read_local_id)
&& (channel->remote.extended_data_ignore_mode ==
LIBSSH2_CHANNEL_EXTENDED_DATA_MERGE))) {
channel->read_want = buflen - channel->read_bytes_read;
channel->read_unlink_packet = 0;
if (channel->read_want >=
(int) (channel->read_packet->data_len -
channel->read_packet->data_head)) {
channel->read_want =
channel->read_packet->data_len -
channel->read_packet->data_head;
channel->read_unlink_packet = 1;
if (channel->read_unlink_packet) {
if (readpkt->prev) {
readpkt->prev->next = readpkt->next;
} else {
session->packets.head = readpkt->next;
}
if (readpkt->next) {
readpkt->next->prev = readpkt->prev;
} else {
session->packets.tail = readpkt->prev;
}
LIBSSH2_FREE(session, readpkt->data);
_libssh2_debug(session, LIBSSH2_DBG_CONN,
"Reading %d of buffered data from %lu/%lu/%d",
channel->read_want, channel->local.id,
channel->remote.id, stream_id);
memcpy(buf + channel->read_bytes_read,
channel->read_packet->data +
channel->read_packet->data_head, channel->read_want);
channel->read_packet->data_head += channel->read_want;
channel->read_bytes_read += channel->read_want;
if (channel->read_unlink_packet) {
if (channel->read_packet->prev) {
channel->read_packet->prev->next =
channel->read_packet->next;
} else {
session->packets.head = channel->read_packet->next;
}
if (channel->read_packet->next) {
channel->read_packet->next->prev =
channel->read_packet->prev;
} else {
session->packets.tail = channel->read_packet->prev;
}
LIBSSH2_FREE(session, channel->read_packet->data);
_libssh2_debug(session, LIBSSH2_DBG_CONN,
"Unlinking empty packet buffer from "
"channel %lu/%lu",
channel->local.id, channel->remote.id);
channel_read_ex_point1:
channel->read_state = libssh2_NB_state_jump1;
rc = libssh2_channel_receive_window_adjust(channel,
channel->
read_packet->
data_len -
(stream_id ? 13
: 9), 0);
if (rc == PACKET_EAGAIN) {
return PACKET_EAGAIN;
}
channel->read_state = libssh2_NB_state_created;
LIBSSH2_FREE(session, channel->read_packet);
channel->read_packet = NULL;
"Unlink packet buffer from "
"channel %lu/%lu",
channel->local.id, channel->remote.id);
channel_read_ex_point1:
/* Since there's a goto to this place without assigning
'readpkt' we must be careful here to not use it */
channel->read_state = libssh2_NB_state_jump1;
rc = libssh2_channel_receive_window_adjust(channel,
channel->
read_packet->
data_len -
(stream_id ? 13
: 9), 0);
if (rc == PACKET_EAGAIN) {
return PACKET_EAGAIN;
}
channel->read_state = libssh2_NB_state_created;
LIBSSH2_FREE(session, channel->read_packet);
}
channel->read_packet = channel->read_next;
}
channel->read_block = 1;
} while ((channel->read_bytes_read == 0) && !channel->remote.close);
channel->read_packet = channel->read_next;
}
channel->read_state = libssh2_NB_state_idle;
if (channel->read_bytes_read == 0) {
@ -1678,10 +1638,9 @@ libssh2_channel_read_ex(LIBSSH2_CHANNEL * channel, int stream_id, char *buf,
return channel->read_bytes_read;
}
/* }}} */
/*
* {{{ libssh2_channel_packet_data_len
* libssh2_channel_packet_data_len
*
* Return the size of the data block of the current packet, or 0 if there
* isn't a packet.
*/
@ -1733,9 +1692,9 @@ libssh2_channel_packet_data_len(LIBSSH2_CHANNEL * channel, int stream_id)
return 0;
}
/* }}} */
/* {{{ libssh2_channel_write_ex
/*
* libssh2_channel_write_ex
*
* Send data to a channel
*/
LIBSSH2_API ssize_t
@ -2157,13 +2116,11 @@ libssh2_channel_free(LIBSSH2_CHANNEL * channel)
/* Clear out packets meant for this channel */
libssh2_htonu32(channel_id, channel->local.id);
while ((libssh2_packet_ask_ex
(session, SSH_MSG_CHANNEL_DATA, &data, &data_len, 1, channel_id, 4,
0) >= 0)
while ((libssh2_packet_ask(session, SSH_MSG_CHANNEL_DATA, &data,
&data_len, 1, channel_id, 4, 0) >= 0)
||
(libssh2_packet_ask_ex
(session, SSH_MSG_CHANNEL_EXTENDED_DATA, &data, &data_len, 1,
channel_id, 4, 0) >= 0)) {
(libssh2_packet_ask(session, SSH_MSG_CHANNEL_EXTENDED_DATA, &data,
&data_len, 1, channel_id, 4, 0) >= 0)) {
LIBSSH2_FREE(session, data);
}

Просмотреть файл

@ -182,10 +182,10 @@ kex_method_diffie_hellman_groupGP_sha1_key_exchange(LIBSSH2_SESSION *session,
if (exchange_state->state == libssh2_NB_state_sent1) {
/* Wait for KEX reply */
rc = libssh2_packet_require_ex(session, packet_type_reply,
&exchange_state->s_packet,
&exchange_state->s_packet_len, 0, NULL,
0, &exchange_state->req_state);
rc = libssh2_packet_require(session, packet_type_reply,
&exchange_state->s_packet,
&exchange_state->s_packet_len, 0, NULL,
0, &exchange_state->req_state);
if (rc == PACKET_EAGAIN) {
return PACKET_EAGAIN;
}
@ -429,10 +429,10 @@ kex_method_diffie_hellman_groupGP_sha1_key_exchange(LIBSSH2_SESSION *session,
}
if (exchange_state->state == libssh2_NB_state_sent3) {
rc = libssh2_packet_require_ex(session, SSH_MSG_NEWKEYS,
&exchange_state->tmp,
&exchange_state->tmp_len, 0, NULL, 0,
&exchange_state->req_state);
rc = libssh2_packet_require(session, SSH_MSG_NEWKEYS,
&exchange_state->tmp,
&exchange_state->tmp_len, 0, NULL, 0,
&exchange_state->req_state);
if (rc == PACKET_EAGAIN) {
return PACKET_EAGAIN;
} else if (rc) {
@ -852,9 +852,9 @@ kex_method_diffie_hellman_group_exchange_sha1_key_exchange
}
if (key_state->state == libssh2_NB_state_sent) {
rc = libssh2_packet_require_ex(session, SSH_MSG_KEX_DH_GEX_GROUP,
&key_state->data, &key_state->data_len,
0, NULL, 0, &key_state->req_state);
rc = libssh2_packet_require(session, SSH_MSG_KEX_DH_GEX_GROUP,
&key_state->data, &key_state->data_len,
0, NULL, 0, &key_state->req_state);
if (rc == PACKET_EAGAIN) {
return PACKET_EAGAIN;
} else if (rc) {
@ -1720,10 +1720,10 @@ libssh2_kex_exchange(LIBSSH2_SESSION * session, int reexchange,
if (key_state->state == libssh2_NB_state_sent1) {
retcode =
libssh2_packet_require_ex(session, SSH_MSG_KEXINIT,
&key_state->data,
&key_state->data_len, 0, NULL, 0,
&key_state->req_state);
libssh2_packet_require(session, SSH_MSG_KEXINIT,
&key_state->data,
&key_state->data_len, 0, NULL, 0,
&key_state->req_state);
if (retcode == PACKET_EAGAIN) {
session->state &= ~LIBSSH2_STATE_KEX_ACTIVE;
return PACKET_EAGAIN;

Просмотреть файл

@ -1148,31 +1148,31 @@ int libssh2_waitsocket(LIBSSH2_SESSION * session, long seconds);
libssh2pack_t libssh2_packet_read(LIBSSH2_SESSION * session);
int libssh2_packet_ask_ex(LIBSSH2_SESSION * session, unsigned char packet_type,
unsigned char **data, unsigned long *data_len,
unsigned long match_ofs,
const unsigned char *match_buf,
unsigned long match_len, int poll_socket);
int libssh2_packet_ask(LIBSSH2_SESSION * session, unsigned char packet_type,
unsigned char **data, unsigned long *data_len,
unsigned long match_ofs,
const unsigned char *match_buf,
unsigned long match_len, int poll_socket);
int libssh2_packet_askv_ex(LIBSSH2_SESSION * session,
const unsigned char *packet_types,
unsigned char **data, unsigned long *data_len,
unsigned long match_ofs,
int libssh2_packet_askv(LIBSSH2_SESSION * session,
const unsigned char *packet_types,
unsigned char **data, unsigned long *data_len,
unsigned long match_ofs,
const unsigned char *match_buf,
unsigned long match_len, int poll_socket);
int libssh2_packet_require(LIBSSH2_SESSION * session,
unsigned char packet_type, unsigned char **data,
unsigned long *data_len, unsigned long match_ofs,
const unsigned char *match_buf,
unsigned long match_len, int poll_socket);
int libssh2_packet_require_ex(LIBSSH2_SESSION * session,
unsigned char packet_type, unsigned char **data,
unsigned long *data_len, unsigned long match_ofs,
const unsigned char *match_buf,
unsigned long match_len,
packet_require_state_t * state);
int libssh2_packet_requirev_ex(LIBSSH2_SESSION * session,
const unsigned char *packet_types,
unsigned char **data, unsigned long *data_len,
unsigned long match_ofs,
const unsigned char *match_buf,
unsigned long match_len,
packet_requirev_state_t * state);
unsigned long match_len,
packet_require_state_t * state);
int libssh2_packet_requirev(LIBSSH2_SESSION * session,
const unsigned char *packet_types,
unsigned char **data, unsigned long *data_len,
unsigned long match_ofs,
const unsigned char *match_buf,
unsigned long match_len,
packet_requirev_state_t * state);
int libssh2_packet_burn(LIBSSH2_SESSION * session,
libssh2_nonblocking_states * state);
int libssh2_packet_write(LIBSSH2_SESSION * session, unsigned char *data,

Просмотреть файл

@ -202,13 +202,13 @@ _libssh2_debug(LIBSSH2_SESSION * session, int context, const char *format, ...)
static const char *const contexts[9] = {
"Unknown",
"Transport",
"Key Exchange",
"Key Ex",
"Userauth",
"Connection",
"scp",
"SFTP Subsystem",
"Conn",
"SCP",
"SFTP",
"Failure Event",
"Publickey Subsystem",
"Publickey",
};
if (context < 1 || context > 8) {

Просмотреть файл

@ -432,10 +432,11 @@ libssh2_packet_x11_open(LIBSSH2_SESSION * session, unsigned char *data,
return 0;
}
/* }}} */
/* {{{ libssh2_packet_new
* Create a new packet and attach it to the brigade
/*
* libssh2_packet_add
*
* Create a new packet and attach it to the brigade. Called from the transport
* layer when it as received a packet.
*/
int
libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data,
@ -954,17 +955,17 @@ libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data,
return 0;
}
/* }}} */
/* {{{ libssh2_packet_ask
/*
* libssh2_packet_ask
*
* Scan the brigade for a matching packet type, optionally poll the socket for
* a packet first
*/
int
libssh2_packet_ask_ex(LIBSSH2_SESSION * session, unsigned char packet_type,
unsigned char **data, unsigned long *data_len,
unsigned long match_ofs, const unsigned char *match_buf,
unsigned long match_len, int poll_socket)
libssh2_packet_ask(LIBSSH2_SESSION * session, unsigned char packet_type,
unsigned char **data, unsigned long *data_len,
unsigned long match_ofs, const unsigned char *match_buf,
unsigned long match_len, int poll_socket)
{
LIBSSH2_PACKET *packet = session->packets.head;
@ -1018,19 +1019,19 @@ libssh2_packet_ask_ex(LIBSSH2_SESSION * session, unsigned char packet_type,
return -1;
}
/* }}} */
/* {{{ libssh2_packet_askv
/*
* libssh2_packet_askv
*
* Scan for any of a list of packet types in the brigade, optionally poll the
* socket for a packet first
*/
int
libssh2_packet_askv_ex(LIBSSH2_SESSION * session,
const unsigned char *packet_types,
unsigned char **data, unsigned long *data_len,
unsigned long match_ofs,
const unsigned char *match_buf,
unsigned long match_len, int poll_socket)
libssh2_packet_askv(LIBSSH2_SESSION * session,
const unsigned char *packet_types,
unsigned char **data, unsigned long *data_len,
unsigned long match_ofs,
const unsigned char *match_buf,
unsigned long match_len, int poll_socket)
{
int i, packet_types_len = strlen((char *) packet_types);
@ -1041,9 +1042,9 @@ libssh2_packet_askv_ex(LIBSSH2_SESSION * session,
* return PACKET_EAGAIN. Not sure the correct action, I
* think it is right as is.
*/
if (0 == libssh2_packet_ask_ex(session, packet_types[i], data,
data_len, match_ofs, match_buf,
match_len, i ? 0 : poll_socket)) {
if (0 == libssh2_packet_ask(session, packet_types[i], data,
data_len, match_ofs, match_buf,
match_len, i ? 0 : poll_socket)) {
return 0;
}
}
@ -1051,9 +1052,9 @@ libssh2_packet_askv_ex(LIBSSH2_SESSION * session,
return -1;
}
/* }}} */
/* {{{ waitsocket
/*
* libssh2_waitsocket
*
* Returns
* negative on error
* >0 on incoming data
@ -1080,7 +1081,9 @@ libssh2_waitsocket(LIBSSH2_SESSION * session, long seconds)
return rc;
}
/* {{{ libssh2_packet_require
/*
* libssh2_packet_require
*
* Loops libssh2_packet_read() until the packet requested is available
* SSH_DISCONNECT or a SOCKET_DISCONNECTED will cause a bailout
*
@ -1088,17 +1091,17 @@ libssh2_waitsocket(LIBSSH2_SESSION * session, long seconds)
* Returns 0 when it has taken care of the requested packet.
*/
int
libssh2_packet_require_ex(LIBSSH2_SESSION * session, unsigned char packet_type,
unsigned char **data, unsigned long *data_len,
unsigned long match_ofs,
const unsigned char *match_buf,
unsigned long match_len,
packet_require_state_t * state)
libssh2_packet_require(LIBSSH2_SESSION * session, unsigned char packet_type,
unsigned char **data, unsigned long *data_len,
unsigned long match_ofs,
const unsigned char *match_buf,
unsigned long match_len,
packet_require_state_t * state)
{
if (state->start == 0) {
if (libssh2_packet_ask_ex
(session, packet_type, data, data_len, match_ofs, match_buf,
match_len, 0) == 0) {
if (libssh2_packet_ask(session, packet_type, data, data_len,
match_ofs, match_buf,
match_len, 0) == 0) {
/* A packet was available in the packet brigade */
return 0;
}
@ -1123,9 +1126,8 @@ libssh2_packet_require_ex(LIBSSH2_SESSION * session, unsigned char packet_type,
return ret;
} else if (ret == packet_type) {
/* Be lazy, let packet_ask pull it out of the brigade */
ret =
libssh2_packet_ask_ex(session, packet_type, data, data_len,
match_ofs, match_buf, match_len, 0);
ret = libssh2_packet_ask(session, packet_type, data, data_len,
match_ofs, match_buf, match_len, 0);
state->start = 0;
return ret;
} else if (ret == 0) {
@ -1165,8 +1167,8 @@ libssh2_packet_burn(LIBSSH2_SESSION * session,
all_packets[i - 1] = i;
}
if (libssh2_packet_askv_ex
(session, all_packets, &data, &data_len, 0, NULL, 0, 0) == 0) {
if (libssh2_packet_askv(session, all_packets, &data, &data_len, 0,
NULL, 0, 0) == 0) {
i = data[0];
/* A packet was available in the packet brigade, burn it */
LIBSSH2_FREE(session, data);
@ -1191,8 +1193,7 @@ libssh2_packet_burn(LIBSSH2_SESSION * session,
/* Be lazy, let packet_ask pull it out of the brigade */
if (0 ==
libssh2_packet_ask_ex(session, ret, &data, &data_len, 0, NULL, 0,
0)) {
libssh2_packet_ask(session, ret, &data, &data_len, 0, NULL, 0, 0)) {
/* Smoke 'em if you got 'em */
LIBSSH2_FREE(session, data);
*state = libssh2_NB_state_idle;
@ -1204,10 +1205,8 @@ libssh2_packet_burn(LIBSSH2_SESSION * session,
return -1;
}
/* }}} */
/*
* {{{ libssh2_packet_requirev
* libssh2_packet_requirev
*
* Loops libssh2_packet_read() until one of a list of packet types requested is
* available
@ -1216,17 +1215,16 @@ libssh2_packet_burn(LIBSSH2_SESSION * session,
*/
int
libssh2_packet_requirev_ex(LIBSSH2_SESSION * session,
const unsigned char *packet_types,
unsigned char **data, unsigned long *data_len,
unsigned long match_ofs,
const unsigned char *match_buf,
unsigned long match_len,
packet_requirev_state_t * state)
libssh2_packet_requirev(LIBSSH2_SESSION * session,
const unsigned char *packet_types,
unsigned char **data, unsigned long *data_len,
unsigned long match_ofs,
const unsigned char *match_buf,
unsigned long match_len,
packet_requirev_state_t * state)
{
if (libssh2_packet_askv_ex
(session, packet_types, data, data_len, match_ofs, match_buf,
match_len, 0) == 0) {
if (libssh2_packet_askv(session, packet_types, data, data_len, match_ofs,
match_buf, match_len, 0) == 0) {
/* One of the packets listed was available in the packet
brigade */
state->start = 0;
@ -1256,9 +1254,9 @@ libssh2_packet_requirev_ex(LIBSSH2_SESSION * session,
if (strchr((char *) packet_types, ret)) {
/* Be lazy, let packet_ask pull it out of the brigade */
return libssh2_packet_askv_ex(session, packet_types, data,
data_len, match_ofs, match_buf,
match_len, 0);
return libssh2_packet_askv(session, packet_types, data,
data_len, match_ofs, match_buf,
match_len, 0);
}
}
@ -1267,4 +1265,3 @@ libssh2_packet_requirev_ex(LIBSSH2_SESSION * session,
return -1;
}
/* }}} */

Просмотреть файл

@ -630,10 +630,10 @@ libssh2_session_startup(LIBSSH2_SESSION * session, int sock)
}
if (session->startup_state == libssh2_NB_state_sent4) {
rc = libssh2_packet_require_ex(session, SSH_MSG_SERVICE_ACCEPT,
&session->startup_data,
&session->startup_data_len, 0, NULL, 0,
&session->startup_req_state);
rc = libssh2_packet_require(session, SSH_MSG_SERVICE_ACCEPT,
&session->startup_data,
&session->startup_data_len, 0, NULL, 0,
&session->startup_req_state);
if (rc == PACKET_EAGAIN) {
return LIBSSH2_ERROR_EAGAIN;
} else if (rc) {

Просмотреть файл

@ -1,4 +1,5 @@
/* Copyright (c) 2004-2008, Sara Golemon <sarag@libssh2.org>
* Copyright (c) 2009 by Daniel Stenberg
* All rights reserved.
*
* Redistribution and use in source and binary forms,
@ -82,7 +83,9 @@
/* S_IFDIR */
#define LIBSSH2_SFTP_ATTR_PFILETYPE_DIR 0040000
/* {{{ sftp_packet_add
/*
* sftp_packet_add
*
* Add a packet to the SFTP packet brigade
*/
static int
@ -118,9 +121,9 @@ sftp_packet_add(LIBSSH2_SFTP * sftp, unsigned char *data,
return 0;
}
/* }}} */
/* {{{ sftp_packet_read
/*
* sftp_packet_read
*
* Frame an SFTP packet off the channel
*/
static int
@ -134,8 +137,7 @@ sftp_packet_read(LIBSSH2_SFTP * sftp)
ssize_t bytes_received;
int rc;
_libssh2_debug(session, LIBSSH2_DBG_SFTP, "Waiting for packet");
_libssh2_debug(session, LIBSSH2_DBG_SFTP, "recv packet");
/* If there was a previous partial, start using it */
if (sftp->partial_packet) {
@ -217,45 +219,41 @@ sftp_packet_read(LIBSSH2_SFTP * sftp)
return packet[0];
}
/* }}} */
/* {{{ sftp_packet_ask
* A la libssh2_packet_ask()
/*
* sftp_packet_ask()
*
* Checks if there's a matching SFTP packet available.
*/
static int
sftp_packet_ask(LIBSSH2_SFTP * sftp, unsigned char packet_type,
unsigned long request_id, unsigned char **data,
unsigned long *data_len, int poll_channel)
unsigned long *data_len)
{
LIBSSH2_SESSION *session = sftp->channel->session;
LIBSSH2_PACKET *packet = sftp->packets.head;
unsigned char match_buf[5];
int match_len = 5;
int match_len;
_libssh2_debug(session, LIBSSH2_DBG_SFTP, "Asking for %d packet",
(int) packet_type);
if (poll_channel) {
int ret = sftp_packet_read(sftp);
if (ret == PACKET_EAGAIN) {
return PACKET_EAGAIN;
} else if (ret < 0) {
return -1;
}
}
match_buf[0] = packet_type;
if (packet_type == SSH_FXP_VERSION) {
/* Special consideration when matching VERSION packet */
match_len = 1;
} else {
match_len = 5;
libssh2_htonu32(match_buf + 1, request_id);
}
while (packet) {
if (strncmp((char *) packet->data, (char *) match_buf, match_len) == 0) {
if (!memcmp((char *) packet->data, (char *) match_buf, match_len)) {
/* Match! Fetch the data */
*data = packet->data;
*data_len = packet->data_len;
/* unlink and free this struct */
if (packet->prev) {
packet->prev->next = packet->next;
} else {
@ -272,6 +270,7 @@ sftp_packet_ask(LIBSSH2_SFTP * sftp, unsigned char packet_type,
return 0;
}
/* check next struct in the list */
packet = packet->next;
}
return -1;
@ -290,12 +289,13 @@ sftp_packet_require(LIBSSH2_SFTP * sftp, unsigned char packet_type,
LIBSSH2_SESSION *session = sftp->channel->session;
int ret;
_libssh2_debug(session, LIBSSH2_DBG_SFTP, "Requiring %d packet",
(int) packet_type);
_libssh2_debug(session, LIBSSH2_DBG_SFTP, "Requiring packet %d id %ld",
(int) packet_type, request_id);
if (sftp_packet_ask(sftp, packet_type, request_id, data,
data_len, 0) == 0) {
if (sftp_packet_ask(sftp, packet_type, request_id, data, data_len) == 0) {
/* The right packet was available in the packet brigade */
_libssh2_debug(session, LIBSSH2_DBG_SFTP, "Got %d",
(int) packet_type);
return 0;
}
@ -307,10 +307,12 @@ sftp_packet_require(LIBSSH2_SFTP * sftp, unsigned char packet_type,
return -1;
}
if (packet_type == ret) {
/* Be lazy, let packet_ask pull it out of the brigade */
return sftp_packet_ask(sftp, packet_type, request_id, data,
data_len, 0);
/* data was read, check the queue again */
if (!sftp_packet_ask(sftp, packet_type, request_id, data, data_len)) {
/* The right packet was available in the packet brigade */
_libssh2_debug(session, LIBSSH2_DBG_SFTP, "Got %d",
(int) packet_type);
return 0;
}
}
@ -318,7 +320,6 @@ sftp_packet_require(LIBSSH2_SFTP * sftp, unsigned char packet_type,
return -1;
}
/* }}} */
/* {{{ sftp_packet_requirev
* Require one of N possible reponses
@ -340,7 +341,7 @@ sftp_packet_requirev(LIBSSH2_SFTP * sftp, int num_valid_responses,
while (sftp->channel->session->socket_state == LIBSSH2_SOCKET_CONNECTED) {
for(i = 0; i < num_valid_responses; i++) {
if (sftp_packet_ask(sftp, valid_responses[i], request_id,
data, data_len, 0) == 0) {
data, data_len) == 0) {
/*
* Set to zero before all returns to say
* the timeout is not active
@ -529,9 +530,9 @@ LIBSSH2_CHANNEL_CLOSE_FUNC(libssh2_sftp_dtor)
LIBSSH2_FREE(session, sftp);
}
/* }}} */
/* {{{ libssh2_sftp_init
/*
* libssh2_sftp_init
*
* Startup an SFTP session
*
* NOTE: Will block in a busy loop on error. This has to be done,
@ -1082,6 +1083,9 @@ libssh2_sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer,
sftp->read_state = libssh2_NB_state_sent1;
}
else
/* internal error, 'data' is not assigned */
return -1;
switch (data[0]) {
case SSH_FXP_STATUS:
@ -1234,12 +1238,15 @@ libssh2_sftp_readdir_ex(LIBSSH2_SFTP_HANDLE * handle, char *buffer,
if (sftp->readdir_state == libssh2_NB_state_created) {
_libssh2_debug(session, LIBSSH2_DBG_SFTP,
"Reading entries from directory handle");
if ((retcode =
libssh2_channel_write_ex(channel, 0,
(char *) sftp->readdir_packet,
packet_len)) == PACKET_EAGAIN) {
retcode =
libssh2_channel_write_ex(channel, 0,
(char *) sftp->readdir_packet,
packet_len);
if (retcode == PACKET_EAGAIN) {
return PACKET_EAGAIN;
} else if (packet_len != retcode) {
}
else if (packet_len != retcode) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send FXP_READ command", 0);
LIBSSH2_FREE(session, sftp->readdir_packet);
@ -1379,9 +1386,10 @@ libssh2_sftp_write(LIBSSH2_SFTP_HANDLE * handle, const char *buffer,
}
if (sftp->write_state == libssh2_NB_state_created) {
if ((rc =
libssh2_channel_write_ex(channel, 0, (char *) sftp->write_packet,
packet_len)) == PACKET_EAGAIN) {
rc =
libssh2_channel_write_ex(channel, 0, (char *) sftp->write_packet,
packet_len);
if (rc == PACKET_EAGAIN) {
return PACKET_EAGAIN;
}
if (packet_len != rc) {
@ -1913,7 +1921,7 @@ libssh2_sftp_mkdir_ex(LIBSSH2_SFTP * sftp, const char *path,
LIBSSH2_SFTP_ATTRIBUTES attrs = {
LIBSSH2_SFTP_ATTR_PERMISSIONS, 0, 0, 0, 0, 0, 0
};
unsigned long data_len, retcode, request_id;
unsigned long data_len, retcode;
/* 13 = packet_len(4) + packet_type(1) + request_id(4) + path_len(4) */
ssize_t packet_len = path_len + 13 + libssh2_sftp_attrsize(&attrs);
unsigned char *packet, *s, *data;
@ -1934,8 +1942,8 @@ libssh2_sftp_mkdir_ex(LIBSSH2_SFTP * sftp, const char *path,
libssh2_htonu32(s, packet_len - 4);
s += 4;
*(s++) = SSH_FXP_MKDIR;
request_id = sftp->request_id++;
libssh2_htonu32(s, request_id);
sftp->mkdir_request_id = sftp->request_id++;
libssh2_htonu32(s, sftp->mkdir_request_id);
s += 4;
libssh2_htonu32(s, path_len);
s += 4;
@ -1946,14 +1954,12 @@ libssh2_sftp_mkdir_ex(LIBSSH2_SFTP * sftp, const char *path,
sftp->mkdir_state = libssh2_NB_state_created;
} else {
packet = sftp->mkdir_packet;
request_id = sftp->mkdir_request_id;
}
if (sftp->mkdir_state == libssh2_NB_state_created) {
rc = libssh2_channel_write_ex(channel, 0, (char *) packet, packet_len);
if (rc == PACKET_EAGAIN) {
sftp->mkdir_packet = packet;
sftp->mkdir_request_id = request_id;
return PACKET_EAGAIN;
}
if (packet_len != rc) {
@ -1968,8 +1974,8 @@ libssh2_sftp_mkdir_ex(LIBSSH2_SFTP * sftp, const char *path,
sftp->mkdir_packet = NULL;
}
rc = sftp_packet_require(sftp, SSH_FXP_STATUS, request_id, &data,
&data_len);
rc = sftp_packet_require(sftp, SSH_FXP_STATUS, sftp->mkdir_request_id,
&data, &data_len);
if (rc == PACKET_EAGAIN) {
return PACKET_EAGAIN;
} else if (rc) {
@ -1985,6 +1991,7 @@ libssh2_sftp_mkdir_ex(LIBSSH2_SFTP * sftp, const char *path,
LIBSSH2_FREE(session, data);
if (retcode == LIBSSH2_FX_OK) {
_libssh2_debug(session, LIBSSH2_DBG_SFTP, "OK!");
return 0;
} else {
libssh2_error(session, LIBSSH2_ERROR_SFTP_PROTOCOL,
@ -2018,7 +2025,7 @@ libssh2_sftp_rmdir_ex(LIBSSH2_SFTP * sftp, const char *path,
s = sftp->rmdir_packet = LIBSSH2_ALLOC(session, packet_len);
if (!sftp->rmdir_packet) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for FXP_MKDIR packet", 0);
"Unable to allocate memory for FXP_RMDIR packet", 0);
return -1;
}
@ -2043,7 +2050,7 @@ libssh2_sftp_rmdir_ex(LIBSSH2_SFTP * sftp, const char *path,
return PACKET_EAGAIN;
} else if (packet_len != rc) {
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send FXP_MKDIR command", 0);
"Unable to send FXP_RMDIR command", 0);
LIBSSH2_FREE(session, sftp->rmdir_packet);
sftp->rmdir_packet = NULL;
sftp->rmdir_state = libssh2_NB_state_idle;
@ -2113,7 +2120,7 @@ libssh2_sftp_stat_ex(LIBSSH2_SFTP * sftp, const char *path,
s = sftp->stat_packet = LIBSSH2_ALLOC(session, packet_len);
if (!sftp->stat_packet) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for FXP_MKDIR packet", 0);
"Unable to allocate memory for FXP_*STAT packet", 0);
return -1;
}

Просмотреть файл

@ -1,4 +1,5 @@
/* Copyright (C) 2007 The Written Word, Inc. All rights reserved.
* Copyright (C) 2009 by Daniel Stenberg
* Author: Daniel Stenberg <daniel@haxx.se>
*
* Redistribution and use in source and binary forms,
@ -43,8 +44,8 @@
#include <assert.h>
#define MAX_BLOCKSIZE 32 /* MUST fit biggest crypto block size we use/get */
#define MAX_MACSIZE 20 /* MUST fit biggest MAC length we support */
#define MAX_BLOCKSIZE 32 /* MUST fit biggest crypto block size we use/get */
#define MAX_MACSIZE 20 /* MUST fit biggest MAC length we support */
#ifdef LIBSSH2DEBUG
#define UNPRINTABLE_CHAR '.'
@ -169,7 +170,8 @@ fullpacket(LIBSSH2_SESSION * session, int encrypted /* 1 or 0 */ )
session->fullpacket_payload_len -= p->padding_length;
/* Check for and deal with decompression */
if (session->remote.comp && strcmp(session->remote.comp->name, "none")) {
if (session->remote.comp &&
strcmp(session->remote.comp->name, "none")) {
unsigned char *data;
unsigned long data_len;
int free_payload = 1;
@ -207,8 +209,7 @@ fullpacket(LIBSSH2_SESSION * session, int encrypted /* 1 or 0 */ )
p->payload = LIBSSH2_ALLOC(session, data_len);
if (!p->payload) {
libssh2_error(session, LIBSSH2_ERROR_ALLOC, (char *)
"Unable to allocate memory for copy of uncompressed data",
0);
"Unable to allocate memory", 0);
return PACKET_ENOMEM;
}
memcpy(p->payload, data, data_len);
@ -242,10 +243,11 @@ fullpacket(LIBSSH2_SESSION * session, int encrypted /* 1 or 0 */ )
}
/* {{{ libssh2_packet_read
* Collect a packet into the input brigade
* block only controls whether or not to wait for a packet to start,
* Once a packet starts, libssh2 will block until it is complete
/*
* libssh2_packet_read
*
* Collect a packet into the input brigade block only controls whether or not
* to wait for a packet to start.
*
* Returns packet type added to input brigade (PACKET_NONE if nothing added),
* or PACKET_FAIL on failure and PACKET_EAGAIN if it couldn't process a full
@ -274,12 +276,12 @@ libssh2_packet_read(LIBSSH2_SESSION * session)
/*
* All channels, systems, subsystems, etc eventually make it down here
* when looking for more incoming data. If a key exchange is going on
* (LIBSSH2_STATE_EXCHANGING_KEYS bit is set) then the remote end
* will ONLY send key exchange related traffic. In non-blocking mode,
* there is a chance to break out of the kex_exchange function with an
* EAGAIN status, and never come back to it. If LIBSSH2_STATE_EXCHANGING_KEYS
* is active, then we must redirect to the key exchange. However,
* if kex_exchange is active (as in it is the one that calls this execution
* (LIBSSH2_STATE_EXCHANGING_KEYS bit is set) then the remote end will
* ONLY send key exchange related traffic. In non-blocking mode, there is
* a chance to break out of the kex_exchange function with an EAGAIN
* status, and never come back to it. If LIBSSH2_STATE_EXCHANGING_KEYS is
* active, then we must redirect to the key exchange. However, if
* kex_exchange is active (as in it is the one that calls this execution
* of packet_read, then don't redirect, as that would be an infinite loop!
*/
@ -590,8 +592,6 @@ libssh2_packet_read(LIBSSH2_SESSION * session)
return PACKET_FAIL; /* we never reach this point */
}
/* }}} */
static libssh2pack_t
send_existing(LIBSSH2_SESSION * session, unsigned char *data,
unsigned long data_len, ssize_t * ret)
@ -645,7 +645,9 @@ send_existing(LIBSSH2_SESSION * session, unsigned char *data,
return PACKET_NONE;
}
/* {{{ libssh2_packet_write
/*
* libssh2_packet_write
*
* Send a packet, encrypting it and adding a MAC code if necessary
* Returns 0 on success, non-zero on failure.
*
@ -811,5 +813,5 @@ libssh2_packet_write(LIBSSH2_SESSION * session, unsigned char *data,
return PACKET_NONE; /* all is good */
}
/* }}} */

Просмотреть файл

@ -122,12 +122,11 @@ libssh2_userauth_list(LIBSSH2_SESSION * session, const char *username,
}
if (session->userauth_list_state == libssh2_NB_state_sent) {
rc = libssh2_packet_requirev_ex(session, reply_codes,
&session->userauth_list_data,
&session->userauth_list_data_len, 0,
NULL, 0,
&session->
userauth_list_packet_requirev_state);
rc = libssh2_packet_requirev(session, reply_codes,
&session->userauth_list_data,
&session->userauth_list_data_len, 0,
NULL, 0,
&session->userauth_list_packet_requirev_state);
if (rc == PACKET_EAGAIN) {
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block requesting userauth list", 0);
@ -269,12 +268,12 @@ libssh2_userauth_password_ex(LIBSSH2_SESSION * session, const char *username,
|| (session->userauth_pswd_state == libssh2_NB_state_sent1)
|| (session->userauth_pswd_state == libssh2_NB_state_sent2)) {
if (session->userauth_pswd_state == libssh2_NB_state_sent) {
rc = libssh2_packet_requirev_ex(session, reply_codes,
&session->userauth_pswd_data,
&session->userauth_pswd_data_len,
0, NULL, 0,
&session->
userauth_pswd_packet_requirev_state);
rc = libssh2_packet_requirev(session, reply_codes,
&session->userauth_pswd_data,
&session->userauth_pswd_data_len,
0, NULL, 0,
&session->
userauth_pswd_packet_requirev_state);
if (rc == PACKET_EAGAIN) {
return PACKET_EAGAIN;
} else if (rc) {
@ -780,11 +779,11 @@ libssh2_userauth_hostbased_fromfile_ex(LIBSSH2_SESSION * session,
if (session->userauth_host_state == libssh2_NB_state_sent) {
unsigned long data_len;
rc = libssh2_packet_requirev_ex(session, reply_codes,
&session->userauth_host_data,
&data_len, 0, NULL, 0,
&session->
userauth_host_packet_requirev_state);
rc = libssh2_packet_requirev(session, reply_codes,
&session->userauth_host_data,
&data_len, 0, NULL, 0,
&session->
userauth_host_packet_requirev_state);
if (rc == PACKET_EAGAIN) {
return PACKET_EAGAIN;
} else if (rc) {
@ -942,12 +941,12 @@ libssh2_userauth_publickey_fromfile_ex(LIBSSH2_SESSION * session,
unsigned char *sig;
unsigned long sig_len;
rc = libssh2_packet_requirev_ex(session, reply_codes,
&session->userauth_pblc_data,
&session->userauth_pblc_data_len, 0,
NULL, 0,
&session->
userauth_pblc_packet_requirev_state);
rc = libssh2_packet_requirev(session, reply_codes,
&session->userauth_pblc_data,
&session->userauth_pblc_data_len, 0,
NULL, 0,
&session->
userauth_pblc_packet_requirev_state);
if (rc == PACKET_EAGAIN) {
return PACKET_EAGAIN;
} else if (rc) {
@ -1107,12 +1106,10 @@ libssh2_userauth_publickey_fromfile_ex(LIBSSH2_SESSION * session,
/* PK_OK is no longer valid */
reply_codes[2] = 0;
rc = libssh2_packet_requirev_ex(session, reply_codes,
&session->userauth_pblc_data,
&session->userauth_pblc_data_len, 0, NULL,
0,
&session->
userauth_pblc_packet_requirev_state);
rc = libssh2_packet_requirev(session, reply_codes,
&session->userauth_pblc_data,
&session->userauth_pblc_data_len, 0, NULL, 0,
&session->userauth_pblc_packet_requirev_state);
if (rc == PACKET_EAGAIN) {
return PACKET_EAGAIN;
} else if (rc) {
@ -1245,12 +1242,12 @@ libssh2_userauth_keyboard_interactive_ex(LIBSSH2_SESSION * session,
for(;;) {
if (session->userauth_kybd_state == libssh2_NB_state_sent) {
rc = libssh2_packet_requirev_ex(session, reply_codes,
&session->userauth_kybd_data,
&session->userauth_kybd_data_len,
0, NULL, 0,
&session->
userauth_kybd_packet_requirev_state);
rc = libssh2_packet_requirev(session, reply_codes,
&session->userauth_kybd_data,
&session->userauth_kybd_data_len,
0, NULL, 0,
&session->
userauth_kybd_packet_requirev_state);
if (rc == PACKET_EAGAIN) {
return PACKET_EAGAIN;
} else if (rc) {