fixed some wrong comments and did a minor code edit and some further
whitespace changes
This commit is contained in:
parent
a678dbac06
commit
ce9d44a3ff
100
src/scp.c
100
src/scp.c
@ -39,12 +39,11 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
/* {{{ libssh2_scp_recv
|
/*
|
||||||
|
* libssh2_scp_recv
|
||||||
|
*
|
||||||
* Open a channel and request a remote file via SCP
|
* Open a channel and request a remote file via SCP
|
||||||
*
|
*
|
||||||
* NOTE: Will block in a busy loop on error. This has to be done,
|
|
||||||
* otherwise the blocking error code would erase the true
|
|
||||||
* cause of the error.
|
|
||||||
*/
|
*/
|
||||||
LIBSSH2_API LIBSSH2_CHANNEL *
|
LIBSSH2_API LIBSSH2_CHANNEL *
|
||||||
libssh2_scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
|
libssh2_scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
|
||||||
@ -81,28 +80,25 @@ libssh2_scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
|
|||||||
|
|
||||||
if (session->scpRecv_state == libssh2_NB_state_created) {
|
if (session->scpRecv_state == libssh2_NB_state_created) {
|
||||||
/* Allocate a channel */
|
/* Allocate a channel */
|
||||||
do {
|
session->scpRecv_channel =
|
||||||
session->scpRecv_channel =
|
libssh2_channel_open_ex(session, "session",
|
||||||
libssh2_channel_open_ex(session, "session",
|
sizeof("session") - 1,
|
||||||
sizeof("session") - 1,
|
LIBSSH2_CHANNEL_WINDOW_DEFAULT,
|
||||||
LIBSSH2_CHANNEL_WINDOW_DEFAULT,
|
LIBSSH2_CHANNEL_PACKET_DEFAULT, NULL,
|
||||||
LIBSSH2_CHANNEL_PACKET_DEFAULT, NULL,
|
0);
|
||||||
0);
|
if (!session->scpRecv_channel) {
|
||||||
if (!session->scpRecv_channel) {
|
if (libssh2_session_last_errno(session) !=
|
||||||
if (libssh2_session_last_errno(session) !=
|
LIBSSH2_ERROR_EAGAIN) {
|
||||||
LIBSSH2_ERROR_EAGAIN) {
|
LIBSSH2_FREE(session, session->scpRecv_command);
|
||||||
LIBSSH2_FREE(session, session->scpRecv_command);
|
session->scpRecv_command = NULL;
|
||||||
session->scpRecv_command = NULL;
|
session->scpRecv_state = libssh2_NB_state_idle;
|
||||||
session->scpRecv_state = libssh2_NB_state_idle;
|
|
||||||
return NULL;
|
|
||||||
} else if (libssh2_session_last_errno(session) ==
|
|
||||||
LIBSSH2_ERROR_EAGAIN) {
|
|
||||||
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
|
|
||||||
"Would block starting up channel", 0);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} while (!session->scpRecv_channel);
|
else {
|
||||||
|
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
|
||||||
|
"Would block starting up channel", 0);
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
session->scpRecv_state = libssh2_NB_state_sent;
|
session->scpRecv_state = libssh2_NB_state_sent;
|
||||||
}
|
}
|
||||||
@ -151,9 +147,8 @@ libssh2_scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
|
|||||||
|
|
||||||
if ((session->scpRecv_state == libssh2_NB_state_sent2)
|
if ((session->scpRecv_state == libssh2_NB_state_sent2)
|
||||||
|| (session->scpRecv_state == libssh2_NB_state_sent3)) {
|
|| (session->scpRecv_state == libssh2_NB_state_sent3)) {
|
||||||
while (sb
|
while (sb && (session->scpRecv_response_len <
|
||||||
&& (session->scpRecv_response_len <
|
LIBSSH2_SCP_RESPONSE_BUFLEN)) {
|
||||||
LIBSSH2_SCP_RESPONSE_BUFLEN)) {
|
|
||||||
unsigned char *s, *p;
|
unsigned char *s, *p;
|
||||||
|
|
||||||
if (session->scpRecv_state == libssh2_NB_state_sent2) {
|
if (session->scpRecv_state == libssh2_NB_state_sent2) {
|
||||||
@ -199,8 +194,9 @@ libssh2_scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
|
|||||||
session->scpRecv_err_len);
|
session->scpRecv_err_len);
|
||||||
if (rc <= 0) {
|
if (rc <= 0) {
|
||||||
/*
|
/*
|
||||||
* Since we have alread started reading this packet, it is
|
* Since we have alread started reading this packet,
|
||||||
* already in the systems so it can't return PACKET_EAGAIN
|
* it is already in the systems so it can't return
|
||||||
|
* PACKET_EAGAIN
|
||||||
*/
|
*/
|
||||||
LIBSSH2_FREE(session, session->scpRecv_err_msg);
|
LIBSSH2_FREE(session, session->scpRecv_err_msg);
|
||||||
session->scpRecv_err_msg = NULL;
|
session->scpRecv_err_msg = NULL;
|
||||||
@ -249,11 +245,13 @@ libssh2_scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
|
|||||||
0);
|
0);
|
||||||
goto scp_recv_error;
|
goto scp_recv_error;
|
||||||
}
|
}
|
||||||
/* Way too short to be an SCP response, or not done yet, short circuit */
|
/* Way too short to be an SCP response, or not done yet,
|
||||||
|
short circuit */
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We're guaranteed not to go under response_len == 0 by the logic above */
|
/* We're guaranteed not to go under response_len == 0 by the
|
||||||
|
logic above */
|
||||||
while ((session->
|
while ((session->
|
||||||
scpRecv_response[session->scpRecv_response_len - 1] ==
|
scpRecv_response[session->scpRecv_response_len - 1] ==
|
||||||
'\r')
|
'\r')
|
||||||
@ -346,7 +344,8 @@ libssh2_scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
|
|||||||
"mtime = %ld, atime = %ld",
|
"mtime = %ld, atime = %ld",
|
||||||
session->scpRecv_mtime, session->scpRecv_atime);
|
session->scpRecv_mtime, session->scpRecv_atime);
|
||||||
|
|
||||||
/* We *should* check that atime.usec is valid, but why let that stop use? */
|
/* We *should* check that atime.usec is valid, but why let
|
||||||
|
that stop use? */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -418,11 +417,13 @@ libssh2_scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
|
|||||||
0);
|
0);
|
||||||
goto scp_recv_error;
|
goto scp_recv_error;
|
||||||
}
|
}
|
||||||
/* Way too short to be an SCP response, or not done yet, short circuit */
|
/* Way too short to be an SCP response, or not done yet,
|
||||||
|
short circuit */
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We're guaranteed not to go under response_len == 0 by the logic above */
|
/* We're guaranteed not to go under response_len == 0 by the
|
||||||
|
logic above */
|
||||||
while ((session->
|
while ((session->
|
||||||
scpRecv_response[session->scpRecv_response_len - 1] ==
|
scpRecv_response[session->scpRecv_response_len - 1] ==
|
||||||
'\r')
|
'\r')
|
||||||
@ -505,7 +506,8 @@ libssh2_scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
|
|||||||
"mode = 0%lo size = %ld", session->scpRecv_mode,
|
"mode = 0%lo size = %ld", session->scpRecv_mode,
|
||||||
session->scpRecv_size);
|
session->scpRecv_size);
|
||||||
|
|
||||||
/* We *should* check that basename is valid, but why let that stop us? */
|
/* We *should* check that basename is valid, but why let that
|
||||||
|
stop us? */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -532,14 +534,11 @@ libssh2_scp_recv(LIBSSH2_SESSION * session, const char *path, struct stat * sb)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
/*
|
||||||
|
* libssh2_scp_send_ex
|
||||||
/* {{{ libssh2_scp_send_ex
|
*
|
||||||
* Send a file using SCP
|
* Send a file using SCP
|
||||||
*
|
*
|
||||||
* NOTE: Will block in a busy loop on error. This has to be done,
|
|
||||||
* otherwise the blocking error code would erase the true
|
|
||||||
* cause of the error.
|
|
||||||
*/
|
*/
|
||||||
LIBSSH2_API LIBSSH2_CHANNEL *
|
LIBSSH2_API LIBSSH2_CHANNEL *
|
||||||
libssh2_scp_send_ex(LIBSSH2_SESSION * session, const char *path, int mode,
|
libssh2_scp_send_ex(LIBSSH2_SESSION * session, const char *path, int mode,
|
||||||
@ -591,17 +590,17 @@ libssh2_scp_send_ex(LIBSSH2_SESSION * session, const char *path, int mode,
|
|||||||
LIBSSH2_CHANNEL_PACKET_DEFAULT, NULL, 0);
|
LIBSSH2_CHANNEL_PACKET_DEFAULT, NULL, 0);
|
||||||
if (!session->scpSend_channel) {
|
if (!session->scpSend_channel) {
|
||||||
if (libssh2_session_last_errno(session) != LIBSSH2_ERROR_EAGAIN) {
|
if (libssh2_session_last_errno(session) != LIBSSH2_ERROR_EAGAIN) {
|
||||||
/* previous call set libssh2_session_last_error(), pass it through */
|
/* previous call set libssh2_session_last_error(), pass it
|
||||||
|
through */
|
||||||
LIBSSH2_FREE(session, session->scpSend_command);
|
LIBSSH2_FREE(session, session->scpSend_command);
|
||||||
session->scpSend_command = NULL;
|
session->scpSend_command = NULL;
|
||||||
session->scpSend_state = libssh2_NB_state_idle;
|
session->scpSend_state = libssh2_NB_state_idle;
|
||||||
return NULL;
|
}
|
||||||
} else if (libssh2_session_last_errno(session) ==
|
else {
|
||||||
LIBSSH2_ERROR_EAGAIN) {
|
|
||||||
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
|
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
|
||||||
"Would block starting up channel", 0);
|
"Would block starting up channel", 0);
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
session->scpSend_state = libssh2_NB_state_sent;
|
session->scpSend_state = libssh2_NB_state_sent;
|
||||||
@ -617,8 +616,10 @@ libssh2_scp_send_ex(LIBSSH2_SESSION * session, const char *path, int mode,
|
|||||||
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
|
libssh2_error(session, LIBSSH2_ERROR_EAGAIN,
|
||||||
"Would block requesting SCP startup", 0);
|
"Would block requesting SCP startup", 0);
|
||||||
return NULL;
|
return NULL;
|
||||||
} else if (rc) {
|
}
|
||||||
/* previous call set libssh2_session_last_error(), pass it through */
|
else if (rc) {
|
||||||
|
/* previous call set libssh2_session_last_error(), pass it
|
||||||
|
through */
|
||||||
LIBSSH2_FREE(session, session->scpSend_command);
|
LIBSSH2_FREE(session, session->scpSend_command);
|
||||||
session->scpSend_command = NULL;
|
session->scpSend_command = NULL;
|
||||||
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
libssh2_error(session, LIBSSH2_ERROR_SCP_PROTOCOL,
|
||||||
@ -797,4 +798,3 @@ libssh2_scp_send_ex(LIBSSH2_SESSION * session, const char *path, int mode,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* }}} */
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user