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.
This commit is contained in:
Daniel Stenberg 2010-04-17 13:18:15 +02:00
parent 81e63b3657
commit c3bcdd88a4
21 changed files with 599 additions and 862 deletions

View File

@ -4,4 +4,4 @@ CSOURCES = channel.c comp.c crypt.c hostkey.c kex.c mac.c misc.c \
global.c
HHEADERS = libssh2_priv.h openssl.h libgcrypt.h transport.h channel.h \
comp.h mac.h misc.h
comp.h mac.h misc.h packet.h

View File

@ -284,8 +284,8 @@ agent_transact_pageant(LIBSSH2_AGENT *agent, agent_transaction_ctx_t transctx)
return -1;
}
p = MapViewOfFile(filemap, FILE_MAP_WRITE, 0, 0, 0);
_libssh2_htonu32(p, transctx->request_len);
memcpy(p + 4, transctx->request, transctx->request_len);
_libssh2_store_str(p, transctx->request, transctx->request_len);
cds.dwData = PAGEANT_COPYDATA_ID;
cds.cbData = 1 + strlen(mapname);
cds.lpData = mapname;
@ -361,18 +361,14 @@ agent_sign(LIBSSH2_SESSION *session, unsigned char **sig, size_t *sig_len,
*s++ = SSH2_AGENTC_SIGN_REQUEST;
/* key blob */
_libssh2_htonu32(s, identity->external.blob_len);
s += 4;
memcpy(s, identity->external.blob, identity->external.blob_len);
s += identity->external.blob_len;
_libssh2_store_str(&s, (const char *)identity->external.blob,
identity->external.blob_len);
/* data */
_libssh2_htonu32(s, data_len);
s += 4;
memcpy(s, data, data_len);
s += data_len;
_libssh2_store_str(&s, (const char *)data, data_len);
/* flags */
_libssh2_htonu32(s, 0);
s += 4;
_libssh2_store_u32(&s, 0);
transctx->request_len = s - transctx->request;
transctx->state = agent_NB_state_request_created;
}

View File

@ -49,6 +49,7 @@
#include "channel.h"
#include "transport.h"
#include "packet.h"
/*
* _libssh2_channel_nextid
@ -192,20 +193,10 @@ _libssh2_channel_open(LIBSSH2_SESSION * session, const char *channel_type,
goto channel_error;
}
*(s++) = SSH_MSG_CHANNEL_OPEN;
_libssh2_htonu32(s, channel_type_len);
s += 4;
memcpy(s, channel_type, channel_type_len);
s += channel_type_len;
_libssh2_htonu32(s, session->open_local_channel);
s += 4;
_libssh2_htonu32(s, window_size);
s += 4;
_libssh2_htonu32(s, packet_size);
s += 4;
_libssh2_store_str(&s, channel_type, channel_type_len);
_libssh2_store_u32(&s, session->open_local_channel);
_libssh2_store_u32(&s, window_size);
_libssh2_store_u32(&s, packet_size);
if (message && message_len) {
memcpy(s, message, message_len);
@ -218,7 +209,7 @@ _libssh2_channel_open(LIBSSH2_SESSION * session, const char *channel_type,
if (session->open_state == libssh2_NB_state_created) {
rc = _libssh2_transport_write(session, session->open_packet,
session->open_packet_len);
if (rc == PACKET_EAGAIN) {
if (rc == LIBSSH2_ERROR_EAGAIN) {
_libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block sending channel-open request");
return NULL;
@ -238,7 +229,7 @@ _libssh2_channel_open(LIBSSH2_SESSION * session, const char *channel_type,
session->open_packet + 5 +
channel_type_len, 4,
&session->open_packet_requirev_state);
if (rc == PACKET_EAGAIN) {
if (rc == LIBSSH2_ERROR_EAGAIN) {
_libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block");
return NULL;
} else if (rc) {
@ -372,19 +363,10 @@ channel_direct_tcpip(LIBSSH2_SESSION * session, const char *host,
"Unable to allocate memory for direct-tcpip connection");
return NULL;
}
_libssh2_htonu32(s, session->direct_host_len);
s += 4;
memcpy(s, host, session->direct_host_len);
s += session->direct_host_len;
_libssh2_htonu32(s, port);
s += 4;
_libssh2_htonu32(s, session->direct_shost_len);
s += 4;
memcpy(s, shost, session->direct_shost_len);
s += session->direct_shost_len;
_libssh2_htonu32(s, sport);
s += 4;
_libssh2_store_str(&s, host, session->direct_host_len);
_libssh2_store_u32(&s, port);
_libssh2_store_str(&s, shost, session->direct_shost_len);
_libssh2_store_u32(&s, sport);
}
channel =
@ -439,7 +421,7 @@ channel_forward_listen(LIBSSH2_SESSION * session, const char *host,
unsigned char *s, *data;
static const unsigned char reply_codes[3] =
{ SSH_MSG_REQUEST_SUCCESS, SSH_MSG_REQUEST_FAILURE, 0 };
unsigned long data_len;
size_t data_len;
int rc;
if (session->fwdLstn_state == libssh2_NB_state_idle) {
@ -467,18 +449,12 @@ channel_forward_listen(LIBSSH2_SESSION * session, const char *host,
}
*(s++) = SSH_MSG_GLOBAL_REQUEST;
_libssh2_htonu32(s, sizeof("tcpip-forward") - 1);
s += 4;
memcpy(s, "tcpip-forward", sizeof("tcpip-forward") - 1);
s += sizeof("tcpip-forward") - 1;
_libssh2_store_str(&s, "tcpip-forward", sizeof("tcpip-forward") - 1);
*(s++) = 0x01; /* want_reply */
_libssh2_htonu32(s, session->fwdLstn_host_len);
s += 4;
memcpy(s, host ? host : "0.0.0.0", session->fwdLstn_host_len);
s += session->fwdLstn_host_len;
_libssh2_htonu32(s, port);
s += 4;
_libssh2_store_str(&s, host ? host : "0.0.0.0",
session->fwdLstn_host_len);
_libssh2_store_u32(&s, port);
session->fwdLstn_state = libssh2_NB_state_created;
}
@ -486,7 +462,7 @@ channel_forward_listen(LIBSSH2_SESSION * session, const char *host,
if (session->fwdLstn_state == libssh2_NB_state_created) {
rc = _libssh2_transport_write(session, session->fwdLstn_packet,
session->fwdLstn_packet_len);
if (rc == PACKET_EAGAIN) {
if (rc == LIBSSH2_ERROR_EAGAIN) {
_libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
"Would block sending global-request packet for "
"forward listen request");
@ -510,7 +486,7 @@ channel_forward_listen(LIBSSH2_SESSION * session, const char *host,
rc = _libssh2_packet_requirev(session, reply_codes, &data, &data_len,
0, NULL, 0,
&session->fwdLstn_packet_requirev_state);
if (rc == PACKET_EAGAIN) {
if (rc == LIBSSH2_ERROR_EAGAIN) {
_libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block");
return NULL;
} else if (rc) {
@ -605,17 +581,17 @@ libssh2_channel_forward_listen_ex(LIBSSH2_SESSION *session, const char *host,
* Stop listening on a remote port and free the listener
* Toss out any pending (un-accept()ed) connections
*
* Return 0 on success, PACKET_EAGAIN if would block, -1 on error
* Return 0 on success, LIBSSH2_ERROR_EAGAIN if would block, -1 on error
*/
static int channel_forward_cancel(LIBSSH2_LISTENER *listener)
{
LIBSSH2_SESSION *session = listener->session;
LIBSSH2_CHANNEL *queued;
unsigned char *packet, *s;
unsigned long host_len = strlen(listener->host);
size_t host_len = strlen(listener->host);
/* 14 = packet_type(1) + request_len(4) + want_replay(1) + host_len(4) +
port(4) */
unsigned long packet_len =
size_t packet_len =
host_len + 14 + sizeof("cancel-tcpip-forward") - 1;
int rc;
@ -632,18 +608,12 @@ static int channel_forward_cancel(LIBSSH2_LISTENER *listener)
}
*(s++) = SSH_MSG_GLOBAL_REQUEST;
_libssh2_htonu32(s, sizeof("cancel-tcpip-forward") - 1);
s += 4;
memcpy(s, "cancel-tcpip-forward", sizeof("cancel-tcpip-forward") - 1);
s += sizeof("cancel-tcpip-forward") - 1;
_libssh2_store_str(&s, "cancel-tcpip-forward",
sizeof("cancel-tcpip-forward") - 1);
*(s++) = 0x00; /* want_reply */
_libssh2_htonu32(s, host_len);
s += 4;
memcpy(s, listener->host, host_len);
s += host_len;
_libssh2_htonu32(s, listener->port);
s += 4;
_libssh2_store_str(&s, listener->host, host_len);
_libssh2_store_u32(&s, listener->port);
listener->chanFwdCncl_state = libssh2_NB_state_created;
} else {
@ -652,7 +622,7 @@ static int channel_forward_cancel(LIBSSH2_LISTENER *listener)
if (listener->chanFwdCncl_state == libssh2_NB_state_created) {
rc = _libssh2_transport_write(session, packet, packet_len);
if (rc == PACKET_EAGAIN) {
if (rc == LIBSSH2_ERROR_EAGAIN) {
listener->chanFwdCncl_data = packet;
return rc;
}
@ -674,7 +644,7 @@ static int channel_forward_cancel(LIBSSH2_LISTENER *listener)
LIBSSH2_CHANNEL *next = _libssh2_list_next(&queued->node);
rc = libssh2_channel_free(queued);
if (rc == PACKET_EAGAIN) {
if (rc == LIBSSH2_ERROR_EAGAIN) {
return rc;
}
queued = next;
@ -697,7 +667,7 @@ static int channel_forward_cancel(LIBSSH2_LISTENER *listener)
* Stop listening on a remote port and free the listener
* Toss out any pending (un-accept()ed) connections
*
* Return 0 on success, PACKET_EAGAIN if would block, -1 on error
* Return 0 on success, LIBSSH2_ERROR_EAGAIN if would block, -1 on error
*/
LIBSSH2_API int
libssh2_channel_forward_cancel(LIBSSH2_LISTENER *listener)
@ -735,7 +705,7 @@ channel_forward_accept(LIBSSH2_LISTENER *listener)
return channel;
}
if (rc == PACKET_EAGAIN) {
if (rc == LIBSSH2_ERROR_EAGAIN) {
_libssh2_error(listener->session, LIBSSH2_ERROR_EAGAIN,
"Would block waiting for packet");
}
@ -773,7 +743,7 @@ static int channel_setenv(LIBSSH2_CHANNEL *channel,
unsigned char *s, *data;
static const unsigned char reply_codes[3] =
{ SSH_MSG_CHANNEL_SUCCESS, SSH_MSG_CHANNEL_FAILURE, 0 };
unsigned long data_len;
size_t data_len;
int rc;
if (channel->setenv_state == libssh2_NB_state_idle) {
@ -799,24 +769,11 @@ static int channel_setenv(LIBSSH2_CHANNEL *channel,
}
*(s++) = SSH_MSG_CHANNEL_REQUEST;
_libssh2_htonu32(s, channel->remote.id);
s += 4;
_libssh2_htonu32(s, sizeof("env") - 1);
s += 4;
memcpy(s, "env", sizeof("env") - 1);
s += sizeof("env") - 1;
_libssh2_store_u32(&s, channel->remote.id);
_libssh2_store_str(&s, "env", sizeof("env") - 1);
*(s++) = 0x01;
_libssh2_htonu32(s, varname_len);
s += 4;
memcpy(s, varname, varname_len);
s += varname_len;
_libssh2_htonu32(s, value_len);
s += 4;
memcpy(s, value, value_len);
s += value_len;
_libssh2_store_str(&s, varname, varname_len);
_libssh2_store_str(&s, value, value_len);
channel->setenv_state = libssh2_NB_state_created;
}
@ -824,7 +781,7 @@ static int channel_setenv(LIBSSH2_CHANNEL *channel,
if (channel->setenv_state == libssh2_NB_state_created) {
rc = _libssh2_transport_write(session, channel->setenv_packet,
channel->setenv_packet_len);
if (rc == PACKET_EAGAIN) {
if (rc == LIBSSH2_ERROR_EAGAIN) {
return rc;
} else if (rc) {
LIBSSH2_FREE(session, channel->setenv_packet);
@ -847,7 +804,7 @@ static int channel_setenv(LIBSSH2_CHANNEL *channel,
1, channel->setenv_local_channel, 4,
&channel->
setenv_packet_requirev_state);
if (rc == PACKET_EAGAIN) {
if (rc == LIBSSH2_ERROR_EAGAIN) {
return rc;
}
if (rc) {
@ -900,7 +857,7 @@ static int channel_request_pty(LIBSSH2_CHANNEL *channel,
unsigned char *s, *data;
static const unsigned char reply_codes[3] =
{ SSH_MSG_CHANNEL_SUCCESS, SSH_MSG_CHANNEL_FAILURE, 0 };
unsigned long data_len;
size_t data_len;
int rc;
if (channel->reqPTY_state == libssh2_NB_state_idle) {
@ -925,37 +882,17 @@ static int channel_request_pty(LIBSSH2_CHANNEL *channel,
}
*(s++) = SSH_MSG_CHANNEL_REQUEST;
_libssh2_htonu32(s, channel->remote.id);
s += 4;
_libssh2_htonu32(s, sizeof("pty-req") - 1);
s += 4;
memcpy(s, "pty-req", sizeof("pty-req") - 1);
s += sizeof("pty-req") - 1;
_libssh2_store_u32(&s, channel->remote.id);
_libssh2_store_str(&s, (char *)"pty-req", sizeof("pty-req") - 1);
*(s++) = 0x01;
_libssh2_htonu32(s, term_len);
s += 4;
if (term) {
memcpy(s, term, term_len);
s += term_len;
}
_libssh2_htonu32(s, width);
s += 4;
_libssh2_htonu32(s, height);
s += 4;
_libssh2_htonu32(s, width_px);
s += 4;
_libssh2_htonu32(s, height_px);
s += 4;
_libssh2_htonu32(s, modes_len);
s += 4;
if (modes) {
memcpy(s, modes, modes_len);
s += modes_len;
}
_libssh2_store_str(&s, term, term_len);
_libssh2_store_u32(&s, width);
_libssh2_store_u32(&s, height);
_libssh2_store_u32(&s, width_px);
_libssh2_store_u32(&s, height_px);
_libssh2_store_str(&s, modes, modes_len);
channel->reqPTY_state = libssh2_NB_state_created;
}
@ -963,7 +900,7 @@ static int channel_request_pty(LIBSSH2_CHANNEL *channel,
if (channel->reqPTY_state == libssh2_NB_state_created) {
rc = _libssh2_transport_write(session, channel->reqPTY_packet,
channel->reqPTY_packet_len);
if (rc == PACKET_EAGAIN) {
if (rc == LIBSSH2_ERROR_EAGAIN) {
return rc;
} else if (rc) {
LIBSSH2_FREE(session, channel->reqPTY_packet);
@ -984,7 +921,7 @@ static int channel_request_pty(LIBSSH2_CHANNEL *channel,
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) {
if (rc == LIBSSH2_ERROR_EAGAIN) {
return rc;
} else if (rc) {
channel->reqPTY_state = libssh2_NB_state_idle;
@ -1045,28 +982,19 @@ channel_request_pty_size(LIBSSH2_CHANNEL * channel, int width,
s = channel->reqPTY_packet =
LIBSSH2_ALLOC(session, channel->reqPTY_packet_len);
if (!channel->reqPTY_packet) {
if (!channel->reqPTY_packet)
return _libssh2_error(session, LIBSSH2_ERROR_ALLOC,
"Unable to allocate memory for pty-request");
}
*(s++) = SSH_MSG_CHANNEL_REQUEST;
_libssh2_htonu32(s, channel->remote.id);
s += 4;
_libssh2_htonu32(s, sizeof("window-change") - 1);
s += 4;
memcpy(s, "window-change", sizeof("window-change") - 1);
s += sizeof("window-change") - 1;
_libssh2_store_u32(&s, channel->remote.id);
_libssh2_store_str(&s, (char *)"window-change",
sizeof("window-change") - 1);
*(s++) = 0x00; /* Don't reply */
_libssh2_htonu32(s, width);
s += 4;
_libssh2_htonu32(s, height);
s += 4;
_libssh2_htonu32(s, width_px);
s += 4;
_libssh2_htonu32(s, height_px);
s += 4;
_libssh2_store_u32(&s, width);
_libssh2_store_u32(&s, height);
_libssh2_store_u32(&s, width_px);
_libssh2_store_u32(&s, height_px);
channel->reqPTY_state = libssh2_NB_state_created;
}
@ -1074,7 +1002,7 @@ channel_request_pty_size(LIBSSH2_CHANNEL * channel, int width,
if (channel->reqPTY_state == libssh2_NB_state_created) {
rc = _libssh2_transport_write(session, channel->reqPTY_packet,
channel->reqPTY_packet_len);
if (rc == PACKET_EAGAIN) {
if (rc == LIBSSH2_ERROR_EAGAIN) {
return rc;
} else if (rc) {
LIBSSH2_FREE(session, channel->reqPTY_packet);
@ -1122,10 +1050,10 @@ channel_x11_req(LIBSSH2_CHANNEL *channel, int single_connection,
unsigned char *s, *data;
static const unsigned char reply_codes[3] =
{ SSH_MSG_CHANNEL_SUCCESS, SSH_MSG_CHANNEL_FAILURE, 0 };
unsigned long data_len;
unsigned long proto_len =
size_t data_len;
size_t proto_len =
auth_proto ? strlen(auth_proto) : (sizeof("MIT-MAGIC-COOKIE-1") - 1);
unsigned long cookie_len =
size_t cookie_len =
auth_cookie ? strlen(auth_cookie) : LIBSSH2_X11_RANDOM_COOKIE_LEN;
int rc;
@ -1155,23 +1083,16 @@ channel_x11_req(LIBSSH2_CHANNEL *channel, int single_connection,
}
*(s++) = SSH_MSG_CHANNEL_REQUEST;
_libssh2_htonu32(s, channel->remote.id);
s += 4;
_libssh2_htonu32(s, sizeof("x11-req") - 1);
s += 4;
memcpy(s, "x11-req", sizeof("x11-req") - 1);
s += sizeof("x11-req") - 1;
_libssh2_store_u32(&s, channel->remote.id);
_libssh2_store_str(&s, "x11-req", sizeof("x11-req") - 1);
*(s++) = 0x01; /* want_reply */
*(s++) = single_connection ? 0x01 : 0x00;
_libssh2_htonu32(s, proto_len);
s += 4;
memcpy(s, auth_proto ? auth_proto : "MIT-MAGIC-COOKIE-1", proto_len);
s += proto_len;
_libssh2_store_str(&s, auth_proto?auth_proto:"MIT-MAGIC-COOKIE-1",
proto_len);
_libssh2_htonu32(s, cookie_len);
s += 4;
_libssh2_store_u32(&s, cookie_len);
if (auth_cookie) {
memcpy(s, auth_cookie, cookie_len);
} else {
@ -1189,16 +1110,14 @@ channel_x11_req(LIBSSH2_CHANNEL *channel, int single_connection,
}
s += cookie_len;
_libssh2_htonu32(s, screen_number);
s += 4;
_libssh2_store_u32(&s, screen_number);
channel->reqX11_state = libssh2_NB_state_created;
}
if (channel->reqX11_state == libssh2_NB_state_created) {
rc = _libssh2_transport_write(session, channel->reqX11_packet,
channel->reqX11_packet_len);
if (rc == PACKET_EAGAIN) {
if (rc == LIBSSH2_ERROR_EAGAIN) {
return rc;
}
if (rc) {
@ -1220,7 +1139,7 @@ channel_x11_req(LIBSSH2_CHANNEL *channel, int single_connection,
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) {
if (rc == LIBSSH2_ERROR_EAGAIN) {
return rc;
} else if (rc) {
channel->reqX11_state = libssh2_NB_state_idle;
@ -1271,7 +1190,7 @@ _libssh2_channel_process_startup(LIBSSH2_CHANNEL *channel,
unsigned char *s, *data;
static const unsigned char reply_codes[3] =
{ SSH_MSG_CHANNEL_SUCCESS, SSH_MSG_CHANNEL_FAILURE, 0 };
unsigned long data_len;
size_t data_len;
int rc;
if (channel->process_state == libssh2_NB_state_idle) {
@ -1299,21 +1218,12 @@ _libssh2_channel_process_startup(LIBSSH2_CHANNEL *channel,
}
*(s++) = SSH_MSG_CHANNEL_REQUEST;
_libssh2_htonu32(s, channel->remote.id);
s += 4;
_libssh2_htonu32(s, request_len);
s += 4;
memcpy(s, request, request_len);
s += request_len;
_libssh2_store_u32(&s, channel->remote.id);
_libssh2_store_str(&s, request, request_len);
*(s++) = 0x01;
if (message) {
_libssh2_htonu32(s, message_len);
s += 4;
memcpy(s, message, message_len);
s += message_len;
}
if (message)
_libssh2_store_str(&s, message, message_len);
channel->process_state = libssh2_NB_state_created;
}
@ -1321,7 +1231,7 @@ _libssh2_channel_process_startup(LIBSSH2_CHANNEL *channel,
if (channel->process_state == libssh2_NB_state_created) {
rc = _libssh2_transport_write(session, channel->process_packet,
channel->process_packet_len);
if (rc == PACKET_EAGAIN) {
if (rc == LIBSSH2_ERROR_EAGAIN) {
return rc;
}
else if (rc) {
@ -1343,7 +1253,7 @@ _libssh2_channel_process_startup(LIBSSH2_CHANNEL *channel,
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) {
if (rc == LIBSSH2_ERROR_EAGAIN) {
return rc;
} else if (rc) {
channel->process_state = libssh2_NB_state_idle;
@ -1458,7 +1368,7 @@ _libssh2_channel_flush(LIBSSH2_CHANNEL *channel, int streamid)
rc = _libssh2_channel_receive_window_adjust(channel,
channel->flush_refund_bytes,
0, NULL);
if (rc == PACKET_EAGAIN)
if (rc == LIBSSH2_ERROR_EAGAIN)
return rc;
}
@ -1545,7 +1455,7 @@ _libssh2_channel_receive_window_adjust(LIBSSH2_CHANNEL * channel,
}
rc = _libssh2_transport_write(channel->session, channel->adjust_adjust, 9);
if (rc == PACKET_EAGAIN) {
if (rc == LIBSSH2_ERROR_EAGAIN) {
return rc;
}
else if (rc) {
@ -1636,7 +1546,7 @@ _libssh2_channel_extended_data(LIBSSH2_CHANNEL *channel, int ignore_mode)
int rc =
_libssh2_channel_flush(channel,
LIBSSH2_CHANNEL_FLUSH_EXTENDED_DATA);
if(PACKET_EAGAIN == rc)
if(LIBSSH2_ERROR_EAGAIN == rc)
return rc;
}
}
@ -1685,7 +1595,7 @@ libssh2_channel_handle_extended_data(LIBSSH2_CHANNEL *channel,
*
* It is important to not return 0 until the currently read channel is
* complete. If we read stuff from the wire but it was no payload data to fill
* in the buffer with, we MUST make sure to return PACKET_EAGAIN.
* in the buffer with, we MUST make sure to return LIBSSH2_ERROR_EAGAIN.
*/
ssize_t _libssh2_channel_read(LIBSSH2_CHANNEL *channel, int stream_id,
char *buf, size_t buflen)
@ -1714,7 +1624,7 @@ ssize_t _libssh2_channel_read(LIBSSH2_CHANNEL *channel, int stream_id,
while (rc > 0)
rc = _libssh2_transport_read(session);
if ((rc < 0) && (rc != PACKET_EAGAIN))
if ((rc < 0) && (rc != LIBSSH2_ERROR_EAGAIN))
return _libssh2_error(session, rc, "transport read");
/*
@ -1813,7 +1723,7 @@ ssize_t _libssh2_channel_read(LIBSSH2_CHANNEL *channel, int stream_id,
return 0;
else
/* if the transport layer said EAGAIN then we say so as well */
return (rc == PACKET_EAGAIN)?rc:0;
return (rc == LIBSSH2_ERROR_EAGAIN)?rc:0;
}
else
/* make sure we remain in the created state to focus on emptying the
@ -1830,7 +1740,7 @@ ssize_t _libssh2_channel_read(LIBSSH2_CHANNEL *channel, int stream_id,
this special state here */
rc = _libssh2_channel_receive_window_adjust(channel,
(LIBSSH2_CHANNEL_WINDOW_DEFAULT*60), 0, NULL);
if (rc == PACKET_EAGAIN)
if (rc == LIBSSH2_ERROR_EAGAIN)
return rc;
_libssh2_debug(session, LIBSSH2_TRACE_CONN,
@ -1852,7 +1762,7 @@ ssize_t _libssh2_channel_read(LIBSSH2_CHANNEL *channel, int stream_id,
* 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
* was no payload data to fill in the buffer with, we MUST make sure to return
* PACKET_EAGAIN.
* LIBSSH2_ERROR_EAGAIN.
*/
LIBSSH2_API ssize_t
libssh2_channel_read_ex(LIBSSH2_CHANNEL *channel, int stream_id, char *buf,
@ -1996,12 +1906,9 @@ _libssh2_channel_write(LIBSSH2_CHANNEL *channel, int stream_id,
*(channel->write_s++) =
stream_id ? SSH_MSG_CHANNEL_EXTENDED_DATA :
SSH_MSG_CHANNEL_DATA;
_libssh2_htonu32(channel->write_s, channel->remote.id);
channel->write_s += 4;
if (stream_id) {
_libssh2_htonu32(channel->write_s, stream_id);
channel->write_s += 4;
}
_libssh2_store_u32(&channel->write_s, channel->remote.id);
if (stream_id)
_libssh2_store_u32(&channel->write_s, stream_id);
/* Don't exceed the remote end's limits */
/* REMEMBER local means local as the SOURCE of the data */
@ -2021,10 +1928,7 @@ _libssh2_channel_write(LIBSSH2_CHANNEL *channel, int stream_id,
channel->remote.id, stream_id);
channel->write_bufwrite = channel->local.packet_size;
}
_libssh2_htonu32(channel->write_s, channel->write_bufwrite);
channel->write_s += 4;
memcpy(channel->write_s, buf, channel->write_bufwrite);
channel->write_s += channel->write_bufwrite;
_libssh2_store_str(&channel->write_s, buf, channel->write_bufwrite);
_libssh2_debug(session, LIBSSH2_TRACE_CONN,
"Sending %d bytes on channel %lu/%lu, stream_id=%d",
@ -2038,7 +1942,7 @@ _libssh2_channel_write(LIBSSH2_CHANNEL *channel, int stream_id,
rc = _libssh2_transport_write(session, channel->write_packet,
channel->write_s -
channel->write_packet);
if (rc == PACKET_EAGAIN) {
if (rc == LIBSSH2_ERROR_EAGAIN) {
if(wrote) {
/* some pieces of data was sent before the EAGAIN so we
return that amount! As we ignore EAGAIN, we must drain
@ -2110,7 +2014,7 @@ static int channel_send_eof(LIBSSH2_CHANNEL *channel)
packet[0] = SSH_MSG_CHANNEL_EOF;
_libssh2_htonu32(packet + 1, channel->remote.id);
rc = _libssh2_transport_write(session, packet, 5);
if (rc == PACKET_EAGAIN) {
if (rc == LIBSSH2_ERROR_EAGAIN) {
return rc;
}
else if (rc) {
@ -2186,7 +2090,7 @@ static int channel_wait_eof(LIBSSH2_CHANNEL *channel)
break;
}
rc = _libssh2_transport_read(session);
if (rc == PACKET_EAGAIN) {
if (rc == LIBSSH2_ERROR_EAGAIN) {
return rc;
}
else if (rc < 0) {
@ -2246,7 +2150,7 @@ channel_close(LIBSSH2_CHANNEL * channel)
if (channel->close_state == libssh2_NB_state_created) {
retcode = _libssh2_transport_write(session, channel->close_packet, 5);
if (retcode == PACKET_EAGAIN) {
if (retcode == LIBSSH2_ERROR_EAGAIN) {
return retcode;
} else if (retcode) {
channel->close_state = libssh2_NB_state_idle;
@ -2366,7 +2270,7 @@ int _libssh2_channel_free(LIBSSH2_CHANNEL *channel)
LIBSSH2_SESSION *session = channel->session;
unsigned char channel_id[4];
unsigned char *data;
unsigned long data_len;
size_t data_len;
int rc;
assert(session);
@ -2384,7 +2288,7 @@ int _libssh2_channel_free(LIBSSH2_CHANNEL *channel)
&& (session->socket_state == LIBSSH2_SOCKET_CONNECTED)) {
rc = channel_close(channel);
if(rc == PACKET_EAGAIN)
if(rc == LIBSSH2_ERROR_EAGAIN)
return rc;
else if (rc < 0) {
channel->free_state = libssh2_NB_state_idle;
@ -2476,7 +2380,7 @@ libssh2_channel_window_read_ex(LIBSSH2_CHANNEL * channel,
}
if (read_avail) {
unsigned long bytes_queued = 0;
size_t bytes_queued = 0;
LIBSSH2_PACKET *packet =
_libssh2_list_first(&channel->session->packets);

View File

@ -60,7 +60,7 @@ static int hostkey_method_ssh_rsa_dtor(LIBSSH2_SESSION * session,
static int
hostkey_method_ssh_rsa_init(LIBSSH2_SESSION * session,
const unsigned char *hostkey_data,
unsigned long hostkey_data_len,
size_t hostkey_data_len,
void **abstract)
{
libssh2_rsa_ctx *rsactx;
@ -139,9 +139,9 @@ hostkey_method_ssh_rsa_initPEM(LIBSSH2_SESSION * session,
static int
hostkey_method_ssh_rsa_sig_verify(LIBSSH2_SESSION * session,
const unsigned char *sig,
unsigned long sig_len,
size_t sig_len,
const unsigned char *m,
unsigned long m_len, void **abstract)
size_t m_len, void **abstract)
{
libssh2_rsa_ctx *rsactx = (libssh2_rsa_ctx *) (*abstract);
(void) session;
@ -160,8 +160,8 @@ hostkey_method_ssh_rsa_sig_verify(LIBSSH2_SESSION * session,
static int
hostkey_method_ssh_rsa_signv(LIBSSH2_SESSION * session,
unsigned char **signature,
unsigned long *signature_len,
unsigned long veccount,
size_t *signature_len,
int veccount,
const struct iovec datavec[],
void **abstract)
{
@ -232,7 +232,7 @@ static int hostkey_method_ssh_dss_dtor(LIBSSH2_SESSION * session,
static int
hostkey_method_ssh_dss_init(LIBSSH2_SESSION * session,
const unsigned char *hostkey_data,
unsigned long hostkey_data_len,
size_t hostkey_data_len,
void **abstract)
{
libssh2_dsa_ctx *dsactx;
@ -314,9 +314,9 @@ hostkey_method_ssh_dss_initPEM(LIBSSH2_SESSION * session,
static int
hostkey_method_ssh_dss_sig_verify(LIBSSH2_SESSION * session,
const unsigned char *sig,
unsigned long sig_len,
size_t sig_len,
const unsigned char *m,
unsigned long m_len, void **abstract)
size_t m_len, void **abstract)
{
libssh2_dsa_ctx *dsactx = (libssh2_dsa_ctx *) (*abstract);
@ -338,8 +338,8 @@ hostkey_method_ssh_dss_sig_verify(LIBSSH2_SESSION * session,
static int
hostkey_method_ssh_dss_signv(LIBSSH2_SESSION * session,
unsigned char **signature,
unsigned long *signature_len,
unsigned long veccount,
size_t *signature_len,
int veccount,
const struct iovec datavec[],
void **abstract)
{

View File

@ -79,7 +79,7 @@ libssh2_keepalive_send (LIBSSH2_SESSION *session,
rc = _libssh2_transport_write(session, keepalive_data, len);
/* Silently ignore PACKET_EAGAIN here: if the write buffer is
already full, sending another keepalive is not useful. */
if (rc && rc != PACKET_EAGAIN) {
if (rc && rc != LIBSSH2_ERROR_EAGAIN) {
_libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
"Unable to send keepalive message");
return rc;

View File

@ -142,7 +142,7 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session,
if (exchange_state->state == libssh2_NB_state_created) {
rc = _libssh2_transport_write(session, exchange_state->e_packet,
exchange_state->e_packet_len);
if (rc == PACKET_EAGAIN) {
if (rc == LIBSSH2_ERROR_EAGAIN) {
return rc;
} else if (rc) {
ret = _libssh2_error(session, rc,
@ -163,7 +163,7 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session,
"Waiting for badly guessed KEX packet (to be ignored)");
burn_type =
_libssh2_packet_burn(session, &exchange_state->burn_state);
if (burn_type == PACKET_EAGAIN) {
if (burn_type == LIBSSH2_ERROR_EAGAIN) {
return burn_type;
} else if (burn_type <= 0) {
/* Failed to receive a packet */
@ -186,7 +186,7 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session,
&exchange_state->s_packet,
&exchange_state->s_packet_len, 0, NULL,
0, &exchange_state->req_state);
if (rc == PACKET_EAGAIN) {
if (rc == LIBSSH2_ERROR_EAGAIN) {
return rc;
}
if (rc) {
@ -411,7 +411,7 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session,
if (exchange_state->state == libssh2_NB_state_sent2) {
rc = _libssh2_transport_write(session, &exchange_state->c, 1);
if (rc == PACKET_EAGAIN) {
if (rc == LIBSSH2_ERROR_EAGAIN) {
return rc;
} else if (rc) {
ret = _libssh2_error(session, rc, "Unable to send NEWKEYS message");
@ -426,7 +426,7 @@ static int diffie_hellman_sha1(LIBSSH2_SESSION *session,
&exchange_state->tmp,
&exchange_state->tmp_len, 0, NULL, 0,
&exchange_state->req_state);
if (rc == PACKET_EAGAIN) {
if (rc == LIBSSH2_ERROR_EAGAIN) {
return rc;
} else if (rc) {
ret = _libssh2_error(session, rc, "Timed out waiting for NEWKEYS");
@ -682,7 +682,7 @@ kex_method_diffie_hellman_group1_sha1_key_exchange(LIBSSH2_SESSION *session,
ret = diffie_hellman_sha1(session, key_state->g, key_state->p, 128,
SSH_MSG_KEXDH_INIT, SSH_MSG_KEXDH_REPLY,
NULL, 0, &key_state->exchange_state);
if (ret == PACKET_EAGAIN) {
if (ret == LIBSSH2_ERROR_EAGAIN) {
return ret;
}
@ -758,7 +758,7 @@ kex_method_diffie_hellman_group14_sha1_key_exchange(LIBSSH2_SESSION *session,
ret = diffie_hellman_sha1(session, key_state->g, key_state->p,
256, SSH_MSG_KEXDH_INIT, SSH_MSG_KEXDH_REPLY,
NULL, 0, &key_state->exchange_state);
if (ret == PACKET_EAGAIN) {
if (ret == LIBSSH2_ERROR_EAGAIN) {
return ret;
}
@ -812,7 +812,7 @@ kex_method_diffie_hellman_group_exchange_sha1_key_exchange
if (key_state->state == libssh2_NB_state_created) {
rc = _libssh2_transport_write(session, key_state->request,
key_state->request_len);
if (rc == PACKET_EAGAIN) {
if (rc == LIBSSH2_ERROR_EAGAIN) {
return rc;
} else if (rc) {
ret = _libssh2_error(session, rc,
@ -827,7 +827,7 @@ kex_method_diffie_hellman_group_exchange_sha1_key_exchange
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) {
if (rc == LIBSSH2_ERROR_EAGAIN) {
return rc;
} else if (rc) {
ret = _libssh2_error(session, rc,
@ -856,7 +856,7 @@ kex_method_diffie_hellman_group_exchange_sha1_key_exchange
key_state->data + 1,
key_state->data_len - 1,
&key_state->exchange_state);
if (ret == PACKET_EAGAIN) {
if (ret == LIBSSH2_ERROR_EAGAIN) {
return ret;
}
@ -1107,7 +1107,7 @@ static int kexinit(LIBSSH2_SESSION * session)
}
rc = _libssh2_transport_write(session, data, data_len);
if (rc == PACKET_EAGAIN) {
if (rc == LIBSSH2_ERROR_EAGAIN) {
session->kexinit_data = data;
session->kexinit_data_len = data_len;
return rc;
@ -1675,7 +1675,7 @@ libssh2_kex_exchange(LIBSSH2_SESSION * session, int reexchange,
if (key_state->state == libssh2_NB_state_sent) {
retcode = kexinit(session);
if (retcode == PACKET_EAGAIN) {
if (retcode == LIBSSH2_ERROR_EAGAIN) {
session->state &= ~LIBSSH2_STATE_KEX_ACTIVE;
return retcode;
} else if (retcode) {
@ -1696,7 +1696,7 @@ libssh2_kex_exchange(LIBSSH2_SESSION * session, int reexchange,
&key_state->data,
&key_state->data_len, 0, NULL, 0,
&key_state->req_state);
if (retcode == PACKET_EAGAIN) {
if (retcode == LIBSSH2_ERROR_EAGAIN) {
session->state &= ~LIBSSH2_STATE_KEX_ACTIVE;
return retcode;
}
@ -1732,7 +1732,7 @@ libssh2_kex_exchange(LIBSSH2_SESSION * session, int reexchange,
if (key_state->state == libssh2_NB_state_sent2) {
retcode = session->kex->exchange_keys(session,
&key_state->key_state_low);
if (retcode == PACKET_EAGAIN) {
if (retcode == LIBSSH2_ERROR_EAGAIN) {
session->state &= ~LIBSSH2_STATE_KEX_ACTIVE;
return retcode;
} else if (retcode) {

View File

@ -344,8 +344,8 @@ int
_libssh2_rsa_sha1_sign(LIBSSH2_SESSION * session,
libssh2_dsa_ctx * rsactx,
const unsigned char *hash,
unsigned long hash_len,
unsigned char **signature, unsigned long *signature_len)
size_t hash_len,
unsigned char **signature, size_t *signature_len)
{
gcry_sexp_t sig_sexp;
gcry_sexp_t data;

View File

@ -83,6 +83,21 @@
# endif
#endif
/* Needed for struct iovec on some platforms */
#ifdef HAVE_SYS_UIO_H
#include <sys/uio.h>
#endif
#ifdef HAVE_SYS_SOCKET_H
# include <sys/socket.h>
#endif
#ifdef HAVE_SYS_IOCTL_H
# include <sys/ioctl.h>
#endif
#ifdef HAVE_INTTYPES_H
#include <inttypes.h>
#endif
#include "libssh2.h"
#include "libssh2_publickey.h"
#include "libssh2_sftp.h"
@ -116,20 +131,6 @@ static inline int writev(int sock, struct iovec *iov, int nvecs)
#endif /* WIN32 */
/* Needed for struct iovec on some platforms */
#ifdef HAVE_SYS_UIO_H
#include <sys/uio.h>
#endif
#ifdef HAVE_SYS_SOCKET_H
# include <sys/socket.h>
#endif
#ifdef HAVE_SYS_IOCTL_H
# include <sys/ioctl.h>
#endif
#ifdef HAVE_INTTYPES_H
#include <inttypes.h>
#endif
#ifdef LIBSSH2_LIBGCRYPT
#include "libgcrypt.h"
@ -235,9 +236,9 @@ typedef struct kmdhgGPsha1kex_state_t
unsigned char *tmp;
unsigned char h_sig_comp[SHA_DIGEST_LENGTH];
unsigned char c;
unsigned long e_packet_len;
unsigned long s_packet_len;
unsigned long tmp_len;
size_t e_packet_len;
size_t s_packet_len;
size_t tmp_len;
_libssh2_bn_ctx *ctx;
_libssh2_bn *x;
_libssh2_bn *e;
@ -247,9 +248,9 @@ typedef struct kmdhgGPsha1kex_state_t
unsigned char *f_value;
unsigned char *k_value;
unsigned char *h_sig;
unsigned long f_value_len;
unsigned long k_value_len;
unsigned long h_sig_len;
size_t f_value_len;
size_t k_value_len;
size_t h_sig_len;
libssh2_sha1_ctx exchange_hash;
packet_require_state_t req_state;
libssh2_nonblocking_states burn_state;
@ -264,8 +265,8 @@ typedef struct key_exchange_state_low_t
_libssh2_bn *g; /* SSH2 defined value (2) */
unsigned char request[13];
unsigned char *data;
unsigned long request_len;
unsigned long data_len;
size_t request_len;
size_t data_len;
} key_exchange_state_low_t;
typedef struct key_exchange_state_t
@ -274,9 +275,9 @@ typedef struct key_exchange_state_t
packet_require_state_t req_state;
key_exchange_state_low_t key_state_low;
unsigned char *data;
unsigned long data_len;
size_t data_len;
unsigned char *oldlocal;
unsigned long oldlocal_len;
size_t oldlocal_len;
} key_exchange_state_t;
#define FwdNotReq "Forward not requested"
@ -320,7 +321,7 @@ struct _LIBSSH2_PACKET
/* Unencrypted Payload (no type byte, no padding, just the facts ma'am) */
unsigned char *data;
unsigned long data_len;
size_t data_len;
/* Where to start reading data from,
* used for channel data that's been partially consumed */
@ -536,7 +537,7 @@ struct _LIBSSH2_PUBLICKEY
unsigned char *listFetch_s;
unsigned char listFetch_buffer[12];
unsigned char *listFetch_data;
unsigned long listFetch_data_len;
size_t listFetch_data_len;
};
#define SFTP_HANDLE_MAXLEN 256 /* according to spec! */
@ -754,9 +755,9 @@ struct _LIBSSH2_SESSION
/* State variables used in libssh2_session_startup() */
libssh2_nonblocking_states startup_state;
unsigned char *startup_data;
unsigned long startup_data_len;
size_t startup_data_len;
unsigned char startup_service[sizeof("ssh-userauth") + 5 - 1];
unsigned long startup_service_length;
size_t startup_service_length;
packet_require_state_t startup_req_state;
key_exchange_state_t startup_key_state;
@ -766,7 +767,7 @@ struct _LIBSSH2_SESSION
/* State variables used in libssh2_session_disconnect_ex() */
libssh2_nonblocking_states disconnect_state;
unsigned char *disconnect_data;
unsigned long disconnect_data_len;
size_t disconnect_data_len;
/* State variables used in libssh2_packet_read() */
libssh2_nonblocking_states readPack_state;
@ -775,14 +776,14 @@ struct _LIBSSH2_SESSION
/* State variables used in libssh2_userauth_list() */
libssh2_nonblocking_states userauth_list_state;
unsigned char *userauth_list_data;
unsigned long userauth_list_data_len;
size_t userauth_list_data_len;
packet_requirev_state_t userauth_list_packet_requirev_state;
/* State variables used in libssh2_userauth_password_ex() */
libssh2_nonblocking_states userauth_pswd_state;
unsigned char *userauth_pswd_data;
unsigned char userauth_pswd_data0;
unsigned long userauth_pswd_data_len;
size_t userauth_pswd_data_len;
char *userauth_pswd_newpw;
int userauth_pswd_newpw_len;
packet_requirev_state_t userauth_pswd_packet_requirev_state;
@ -790,22 +791,22 @@ struct _LIBSSH2_SESSION
/* State variables used in libssh2_userauth_hostbased_fromfile_ex() */
libssh2_nonblocking_states userauth_host_state;
unsigned char *userauth_host_data;
unsigned long userauth_host_data_len;
size_t userauth_host_data_len;
unsigned char *userauth_host_packet;
unsigned long userauth_host_packet_len;
size_t userauth_host_packet_len;
unsigned char *userauth_host_method;
unsigned long userauth_host_method_len;
size_t userauth_host_method_len;
unsigned char *userauth_host_s;
packet_requirev_state_t userauth_host_packet_requirev_state;
/* State variables used in libssh2_userauth_publickey_fromfile_ex() */
libssh2_nonblocking_states userauth_pblc_state;
unsigned char *userauth_pblc_data;
unsigned long userauth_pblc_data_len;
size_t userauth_pblc_data_len;
unsigned char *userauth_pblc_packet;
unsigned long userauth_pblc_packet_len;
size_t userauth_pblc_packet_len;
unsigned char *userauth_pblc_method;
unsigned long userauth_pblc_method_len;
size_t userauth_pblc_method_len;
unsigned char *userauth_pblc_s;
unsigned char *userauth_pblc_b;
packet_requirev_state_t userauth_pblc_packet_requirev_state;
@ -813,9 +814,9 @@ struct _LIBSSH2_SESSION
/* State variables used in libssh2_userauth_keyboard_interactive_ex() */
libssh2_nonblocking_states userauth_kybd_state;
unsigned char *userauth_kybd_data;
unsigned long userauth_kybd_data_len;
size_t userauth_kybd_data_len;
unsigned char *userauth_kybd_packet;
unsigned long userauth_kybd_packet_len;
size_t userauth_kybd_packet_len;
unsigned int userauth_kybd_auth_name_len;
char *userauth_kybd_auth_name;
unsigned userauth_kybd_auth_instruction_len;
@ -831,17 +832,17 @@ struct _LIBSSH2_SESSION
packet_requirev_state_t open_packet_requirev_state;
LIBSSH2_CHANNEL *open_channel;
unsigned char *open_packet;
unsigned long open_packet_len;
size_t open_packet_len;
unsigned char *open_data;
unsigned long open_data_len;
unsigned long open_local_channel;
size_t open_data_len;
uint32_t open_local_channel;
/* State variables used in libssh2_channel_direct_tcpip_ex() */
libssh2_nonblocking_states direct_state;
unsigned char *direct_message;
unsigned long direct_host_len;
unsigned long direct_shost_len;
unsigned long direct_message_len;
size_t direct_host_len;
size_t direct_shost_len;
size_t direct_message_len;
/* State variables used in libssh2_channel_forward_listen_ex() */
libssh2_nonblocking_states fwdLstn_state;
@ -855,7 +856,7 @@ struct _LIBSSH2_SESSION
LIBSSH2_PUBLICKEY *pkeyInit_pkey;
LIBSSH2_CHANNEL *pkeyInit_channel;
unsigned char *pkeyInit_data;
unsigned long pkeyInit_data_len;
size_t pkeyInit_data_len;
/* State variables used in libssh2_packet_add() */
libssh2_nonblocking_states packAdd_state;
@ -955,18 +956,18 @@ struct _LIBSSH2_HOSTKEY_METHOD
unsigned long hash_len;
int (*init) (LIBSSH2_SESSION * session, const unsigned char *hostkey_data,
unsigned long hostkey_data_len, void **abstract);
size_t hostkey_data_len, void **abstract);
int (*initPEM) (LIBSSH2_SESSION * session, const char *privkeyfile,
unsigned const char *passphrase, void **abstract);
int (*sig_verify) (LIBSSH2_SESSION * session, const unsigned char *sig,
unsigned long sig_len, const unsigned char *m,
unsigned long m_len, void **abstract);
size_t sig_len, const unsigned char *m,
size_t m_len, void **abstract);
int (*signv) (LIBSSH2_SESSION * session, unsigned char **signature,
unsigned long *signature_len, unsigned long veccount,
size_t *signature_len, int veccount,
const struct iovec datavec[], void **abstract);
int (*encrypt) (LIBSSH2_SESSION * session, unsigned char **dst,
unsigned long *dst_len, const unsigned char *src,
unsigned long src_len, void **abstract);
size_t *dst_len, const unsigned char *src,
size_t src_len, void **abstract);
int (*dtor) (LIBSSH2_SESSION * session, void **abstract);
};
@ -1108,10 +1109,6 @@ _libssh2_debug(LIBSSH2_SESSION * session, int context, const char *format, ...)
void _libssh2_session_shutdown(LIBSSH2_SESSION * session);
unsigned int _libssh2_ntohu32(const unsigned char *buf);
libssh2_uint64_t _libssh2_ntohu64(const unsigned char *buf);
void _libssh2_htonu32(unsigned char *buf, unsigned int val);
#ifdef WIN32
ssize_t _libssh2_recv(libssh2_socket_t socket, void *buffer, size_t length, int flags);
ssize_t _libssh2_send(libssh2_socket_t socket, const void *buffer, size_t length, int flags);
@ -1126,53 +1123,6 @@ ssize_t _libssh2_send(libssh2_socket_t socket, const void *buffer, size_t length
int _libssh2_wait_socket(LIBSSH2_SESSION *session);
/* These started out as private return codes for the transport layer, but was
converted to using the library-wide return codes to easy propagation of the
error reasons all over etc without risking mixups. The PACKET_* names are
left only to reduce the impact of changing the code all over.*/
#define PACKET_TIMEOUT LIBSSH2_ERROR_TIMEOUT
#define PACKET_BADUSE LIBSSH2_ERROR_BAD_USE
#define PACKET_COMPRESS LIBSSH2_ERROR_COMPRESS
#define PACKET_TOOBIG LIBSSH2_ERROR_OUT_OF_BOUNDARY
#define PACKET_ENOMEM LIBSSH2_ERROR_ALLOC
#define PACKET_EAGAIN LIBSSH2_ERROR_EAGAIN
#define PACKET_FAIL LIBSSH2_ERROR_SOCKET_NONE
#define PACKET_NONE LIBSSH2_ERROR_NONE
int _libssh2_packet_read(LIBSSH2_SESSION * session);