Reformatted the code, updated line endings to match original file,
fixed the build problem, removed tabs and replaced with spaces and removed C89 unfriendly comments.
This commit is contained in:
parent
b2334b227d
commit
8896b675f8
141
src/channel.c
141
src/channel.c
@ -934,79 +934,75 @@ LIBSSH2_API int
|
||||
libssh2_channel_request_pty_size_ex(LIBSSH2_CHANNEL * channel, int width,
|
||||
int height, int width_px, int height_px)
|
||||
{
|
||||
LIBSSH2_SESSION *session = channel->session;
|
||||
unsigned char *s, *data;
|
||||
static const unsigned char reply_codes[3] =
|
||||
{ SSH_MSG_CHANNEL_SUCCESS, SSH_MSG_CHANNEL_FAILURE, 0 };
|
||||
unsigned long data_len;
|
||||
int rc;
|
||||
LIBSSH2_SESSION *session = channel->session;
|
||||
unsigned char *s;
|
||||
int rc;
|
||||
|
||||
if (channel->reqPTY_state == libssh2_NB_state_idle) {
|
||||
channel->reqPTY_packet_len = 39;
|
||||
if (channel->reqPTY_state == libssh2_NB_state_idle) {
|
||||
channel->reqPTY_packet_len = 39;
|
||||
|
||||
/* Zero the whole thing out */
|
||||
memset(&channel->reqPTY_packet_requirev_state, 0,
|
||||
sizeof(channel->reqPTY_packet_requirev_state));
|
||||
/* Zero the whole thing out */
|
||||
memset(&channel->reqPTY_packet_requirev_state, 0,
|
||||
sizeof(channel->reqPTY_packet_requirev_state));
|
||||
|
||||
_libssh2_debug(session, LIBSSH2_DBG_CONN,
|
||||
"changing tty size on channel %lu/%lu",
|
||||
channel->local.id,
|
||||
channel->remote.id);
|
||||
_libssh2_debug(session, LIBSSH2_DBG_CONN,
|
||||
"changing tty size on channel %lu/%lu",
|
||||
channel->local.id,
|
||||
channel->remote.id);
|
||||
|
||||
s = channel->reqPTY_packet =
|
||||
LIBSSH2_ALLOC(session, channel->reqPTY_packet_len);
|
||||
if (!channel->reqPTY_packet) {
|
||||
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
|
||||
"Unable to allocate memory for pty-request", 0);
|
||||
return -1;
|
||||
}
|
||||
s = channel->reqPTY_packet =
|
||||
LIBSSH2_ALLOC(session, channel->reqPTY_packet_len);
|
||||
|
||||
if (!channel->reqPTY_packet) {
|
||||
libssh2_error(session, LIBSSH2_ERROR_ALLOC,
|
||||
"Unable to allocate memory for pty-request", 0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
*(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;
|
||||
*(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;
|
||||
|
||||
*(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;
|
||||
*(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;
|
||||
|
||||
channel->reqPTY_state = libssh2_NB_state_created;
|
||||
}
|
||||
channel->reqPTY_state = libssh2_NB_state_created;
|
||||
}
|
||||
|
||||
if (channel->reqPTY_state == libssh2_NB_state_created) {
|
||||
rc = libssh2_packet_write(session, channel->reqPTY_packet,
|
||||
channel->reqPTY_packet_len);
|
||||
if (rc == PACKET_EAGAIN) {
|
||||
return PACKET_EAGAIN;
|
||||
} else if (rc) {
|
||||
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
|
||||
"Unable to send window-change packet", 0);
|
||||
LIBSSH2_FREE(session, channel->reqPTY_packet);
|
||||
channel->reqPTY_packet = NULL;
|
||||
channel->reqPTY_state = libssh2_NB_state_idle;
|
||||
return -1;
|
||||
}
|
||||
LIBSSH2_FREE(session, channel->reqPTY_packet);
|
||||
channel->reqPTY_packet = NULL;
|
||||
if (channel->reqPTY_state == libssh2_NB_state_created) {
|
||||
rc = libssh2_packet_write(session, channel->reqPTY_packet,
|
||||
channel->reqPTY_packet_len);
|
||||
if (rc == PACKET_EAGAIN) {
|
||||
return PACKET_EAGAIN;
|
||||
} else if (rc) {
|
||||
libssh2_error(session, LIBSSH2_ERROR_SOCKET_SEND,
|
||||
"Unable to send window-change packet", 0);
|
||||
LIBSSH2_FREE(session, channel->reqPTY_packet);
|
||||
channel->reqPTY_packet = NULL;
|
||||
channel->reqPTY_state = libssh2_NB_state_idle;
|
||||
return -1;
|
||||
}
|
||||
LIBSSH2_FREE(session, channel->reqPTY_packet);
|
||||
channel->reqPTY_packet = NULL;
|
||||
libssh2_htonu32(channel->reqPTY_local_channel, channel->local.id);
|
||||
channel->reqPTY_state = libssh2_NB_state_sent;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
libssh2_htonu32(channel->reqPTY_local_channel, channel->local.id);
|
||||
|
||||
channel->reqPTY_state = libssh2_NB_state_sent;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
channel->reqPTY_state = libssh2_NB_state_idle;
|
||||
return -1;
|
||||
channel->reqPTY_state = libssh2_NB_state_idle;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Keep this an even number */
|
||||
@ -1521,14 +1517,15 @@ libssh2_channel_read_ex(LIBSSH2_CHANNEL * channel, int stream_id, char *buf,
|
||||
channel->read_packet = session->packets.head;
|
||||
}
|
||||
|
||||
//We didn't read any data from the socket and no packets are waiting to be read
|
||||
if (rc < 0) && (! channel->read_packet)) {
|
||||
if (rc != PACKET_EAGAIN) {
|
||||
channel->read_state = libssh2_NB_state_idle;
|
||||
}
|
||||
/* no packets available */
|
||||
return rc;
|
||||
}
|
||||
/* We didn't read any data from the socket and
|
||||
* no packets are waiting to be read */
|
||||
if ((rc < 0) && (! channel->read_packet)) {
|
||||
if (rc != PACKET_EAGAIN) {
|
||||
channel->read_state = libssh2_NB_state_idle;
|
||||
}
|
||||
/* no packets available */
|
||||
return rc;
|
||||
}
|
||||
|
||||
while (channel->read_packet
|
||||
&& (channel->read_bytes_read < (int) buflen)) {
|
||||
|
@ -1193,10 +1193,13 @@ libssh2_poll_channel_read(LIBSSH2_CHANNEL * channel, int extended)
|
||||
{
|
||||
if ( channel->local.id == libssh2_ntohu32(packet->data + 1)) {
|
||||
if ( extended == 1 &&
|
||||
(packet->data[0] == SSH_MSG_CHANNEL_EXTENDED_DATA || packet->data[0] == SSH_MSG_CHANNEL_DATA ))
|
||||
(packet->data[0] == SSH_MSG_CHANNEL_EXTENDED_DATA
|
||||
|| packet->data[0] == SSH_MSG_CHANNEL_DATA )) {
|
||||
return 1;
|
||||
else if ( extended == 0 && packet->data[0] == SSH_MSG_CHANNEL_DATA)
|
||||
} else if ( extended == 0 &&
|
||||
packet->data[0] == SSH_MSG_CHANNEL_DATA) {
|
||||
return 1;
|
||||
}
|
||||
//else - no data of any type is ready to be read
|
||||
}
|
||||
packet = packet->next;
|
||||
|
Loading…
Reference in New Issue
Block a user