diff --git a/src/channel.c b/src/channel.c index 9f4e926..d9a54d6 100644 --- a/src/channel.c +++ b/src/channel.c @@ -116,15 +116,15 @@ _libssh2_channel_locate(LIBSSH2_SESSION * session, unsigned long channel_id) } /* - * channel_open + * _libssh2_channel_open * * Establish a generic session channel */ -static LIBSSH2_CHANNEL * -channel_open(LIBSSH2_SESSION * session, const char *channel_type, - unsigned int channel_type_len, - unsigned int window_size, unsigned int packet_size, - const char *message, unsigned int message_len) +LIBSSH2_CHANNEL * +_libssh2_channel_open(LIBSSH2_SESSION * session, const char *channel_type, + unsigned int channel_type_len, + unsigned int window_size, unsigned int packet_size, + const char *message, unsigned int message_len) { static const unsigned char reply_codes[3] = { SSH_MSG_CHANNEL_OPEN_CONFIRMATION, @@ -342,9 +342,10 @@ libssh2_channel_open_ex(LIBSSH2_SESSION *session, const char *type, const char *msg, unsigned int msg_len) { LIBSSH2_CHANNEL *ptr; - BLOCK_ADJUST_ERRNO(ptr, session, channel_open(session, type, type_len, - window_size, packet_size, - msg, msg_len)); + BLOCK_ADJUST_ERRNO(ptr, session, + _libssh2_channel_open(session, type, type_len, + window_size, packet_size, + msg, msg_len)); return ptr; } @@ -1304,14 +1305,14 @@ libssh2_channel_x11_req_ex(LIBSSH2_CHANNEL *channel, int single_connection, /* - * libssh2_channel_process_startup + * _libssh2_channel_process_startup * * Primitive for libssh2_channel_(shell|exec|subsystem) */ -static int -channel_process_startup(LIBSSH2_CHANNEL *channel, - const char *request, unsigned int request_len, - const char *message, unsigned int message_len) +int +_libssh2_channel_process_startup(LIBSSH2_CHANNEL *channel, + const char *request, unsigned int request_len, + const char *message, unsigned int message_len) { LIBSSH2_SESSION *session = channel->session; unsigned char *s, *data; @@ -1424,7 +1425,8 @@ libssh2_channel_process_startup(LIBSSH2_CHANNEL *channel, { int rc; BLOCK_ADJUST(rc, channel->session, - channel_process_startup(channel, req, req_len, msg, msg_len)); + _libssh2_channel_process_startup(channel, req, req_len, + msg, msg_len)); return rc; } @@ -1985,13 +1987,13 @@ _libssh2_channel_packet_data_len(LIBSSH2_CHANNEL * channel, int stream_id) } /* - * channel_write + * _libssh2_channel_write * * Send data to a channel */ -static ssize_t -channel_write(LIBSSH2_CHANNEL *channel, int stream_id, - const char *buf, size_t buflen) +ssize_t +_libssh2_channel_write(LIBSSH2_CHANNEL *channel, int stream_id, + const char *buf, size_t buflen) { LIBSSH2_SESSION *session = channel->session; libssh2pack_t rc; @@ -2161,7 +2163,7 @@ libssh2_channel_write_ex(LIBSSH2_CHANNEL *channel, int stream_id, { ssize_t rc; BLOCK_ADJUST(rc, channel->session, - channel_write(channel, stream_id, buf, buflen)); + _libssh2_channel_write(channel, stream_id, buf, buflen)); return rc; } diff --git a/src/channel.h b/src/channel.h index e9fc293..5141153 100644 --- a/src/channel.h +++ b/src/channel.h @@ -73,5 +73,36 @@ int _libssh2_channel_free(LIBSSH2_CHANNEL *channel); int _libssh2_channel_extended_data(LIBSSH2_CHANNEL *channel, int ignore_mode); +/* + * _libssh2_channel_write + * + * Send data to a channel + */ +ssize_t +_libssh2_channel_write(LIBSSH2_CHANNEL *channel, int stream_id, + const char *buf, size_t buflen); + +/* + * _libssh2_channel_open + * + * Establish a generic session channel + */ +LIBSSH2_CHANNEL * +_libssh2_channel_open(LIBSSH2_SESSION * session, const char *channel_type, + unsigned int channel_type_len, + unsigned int window_size, unsigned int packet_size, + const char *message, unsigned int message_len); + + +/* + * _libssh2_channel_process_startup + * + * Primitive for libssh2_channel_(shell|exec|subsystem) + */ +int +_libssh2_channel_process_startup(LIBSSH2_CHANNEL *channel, + const char *request, unsigned int request_len, + const char *message, unsigned int message_len); + #endif /* __LIBSSH2_CHANNEL_H */ diff --git a/src/sftp.c b/src/sftp.c index 7703b48..ee3a9cb 100644 --- a/src/sftp.c +++ b/src/sftp.c @@ -572,9 +572,9 @@ static LIBSSH2_SFTP *sftp_init(LIBSSH2_SESSION *session) if (session->sftpInit_state == libssh2_NB_state_created) { session->sftpInit_channel = - libssh2_channel_open_ex(session, "session", sizeof("session") - 1, - LIBSSH2_CHANNEL_WINDOW_DEFAULT, - LIBSSH2_CHANNEL_PACKET_DEFAULT, NULL, 0); + _libssh2_channel_open(session, "session", sizeof("session") - 1, + LIBSSH2_CHANNEL_WINDOW_DEFAULT, + LIBSSH2_CHANNEL_PACKET_DEFAULT, NULL, 0); if (!session->sftpInit_channel) { if (libssh2_session_last_errno(session) == LIBSSH2_ERROR_EAGAIN) { libssh2_error(session, LIBSSH2_ERROR_EAGAIN, @@ -592,10 +592,10 @@ static LIBSSH2_SFTP *sftp_init(LIBSSH2_SESSION *session) } if (session->sftpInit_state == libssh2_NB_state_sent) { - rc = libssh2_channel_process_startup(session->sftpInit_channel, - "subsystem", - sizeof("subsystem") - 1, "sftp", - strlen("sftp")); + rc = _libssh2_channel_process_startup(session->sftpInit_channel, + "subsystem", + sizeof("subsystem") - 1, "sftp", + strlen("sftp")); if (rc == PACKET_EAGAIN) { libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block to request SFTP subsystem", 0); @@ -640,8 +640,8 @@ static LIBSSH2_SFTP *sftp_init(LIBSSH2_SESSION *session) } if (session->sftpInit_state == libssh2_NB_state_sent2) { - rc = libssh2_channel_write_ex(session->sftpInit_channel, 0, - (char *) session->sftpInit_buffer, 9); + rc = _libssh2_channel_write(session->sftpInit_channel, 0, + (char *) session->sftpInit_buffer, 9); if (rc == PACKET_EAGAIN) { libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block sending SSH_FXP_INIT", 0); @@ -879,8 +879,8 @@ sftp_open(LIBSSH2_SFTP *sftp, const char *filename, } if (sftp->open_state == libssh2_NB_state_created) { - rc = libssh2_channel_write_ex(channel, 0, (char *) sftp->open_packet, - sftp->open_packet_len); + rc = _libssh2_channel_write(channel, 0, (char *) sftp->open_packet, + sftp->open_packet_len); if (rc == PACKET_EAGAIN) { libssh2_error(session, LIBSSH2_ERROR_EAGAIN, "Would block sending FXP_OPEN or FXP_OPENDIR command", @@ -1094,9 +1094,8 @@ static ssize_t sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer, } if (sftp->read_state == libssh2_NB_state_created) { - retcode = - libssh2_channel_write_ex(channel, 0, (char *) packet, - packet_len); + retcode = _libssh2_channel_write(channel, 0, (char *) packet, + packet_len); if (retcode == PACKET_EAGAIN) { sftp->read_packet = packet; sftp->read_request_id = request_id; @@ -1298,11 +1297,9 @@ static int sftp_readdir(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"); - retcode = - libssh2_channel_write_ex(channel, 0, - (char *) sftp->readdir_packet, - packet_len); - + retcode = _libssh2_channel_write(channel, 0, + (char *) sftp->readdir_packet, + packet_len); if (retcode == PACKET_EAGAIN) { return PACKET_EAGAIN; } @@ -1459,9 +1456,8 @@ static ssize_t sftp_write(LIBSSH2_SFTP_HANDLE * handle, const char *buffer, } if (sftp->write_state == libssh2_NB_state_created) { - rc = - libssh2_channel_write_ex(channel, 0, (char *) sftp->write_packet, - packet_len); + rc = _libssh2_channel_write(channel, 0, (char *) sftp->write_packet, + packet_len); if (rc == PACKET_EAGAIN) { return PACKET_EAGAIN; } @@ -1568,8 +1564,8 @@ static int sftp_fstat(LIBSSH2_SFTP_HANDLE *handle, } if (sftp->fstat_state == libssh2_NB_state_created) { - rc = libssh2_channel_write_ex(channel, 0, (char *) sftp->fstat_packet, - packet_len); + rc = _libssh2_channel_write(channel, 0, (char *) sftp->fstat_packet, + packet_len); if (rc == PACKET_EAGAIN) { return PACKET_EAGAIN; } else if (packet_len != rc) { @@ -1711,9 +1707,8 @@ sftp_close_handle(LIBSSH2_SFTP_HANDLE *handle) } if (handle->close_state == libssh2_NB_state_created) { - rc = libssh2_channel_write_ex(channel, 0, - (char *) handle->close_packet, - packet_len); + rc = _libssh2_channel_write(channel, 0, (char *) handle->close_packet, + packet_len); if (rc == PACKET_EAGAIN) { return PACKET_EAGAIN; } else if (packet_len != rc) { @@ -1828,8 +1823,8 @@ static int sftp_unlink(LIBSSH2_SFTP *sftp, const char *filename, } if (sftp->unlink_state == libssh2_NB_state_created) { - rc = libssh2_channel_write_ex(channel, 0, (char *) sftp->unlink_packet, - packet_len); + rc = _libssh2_channel_write(channel, 0, (char *) sftp->unlink_packet, + packet_len); if (rc == PACKET_EAGAIN) { return PACKET_EAGAIN; } else if (packet_len != rc) { @@ -1950,8 +1945,8 @@ static int sftp_rename(LIBSSH2_SFTP *sftp, const char *source_filename, } if (sftp->rename_state == libssh2_NB_state_created) { - rc = libssh2_channel_write_ex(channel, 0, (char *) sftp->rename_packet, - sftp->rename_s - sftp->rename_packet); + rc = _libssh2_channel_write(channel, 0, (char *) sftp->rename_packet, + sftp->rename_s - sftp->rename_packet); if (rc == PACKET_EAGAIN) { return PACKET_EAGAIN; } else if (packet_len != rc) { @@ -2081,7 +2076,7 @@ static int sftp_mkdir(LIBSSH2_SFTP *sftp, const char *path, } if (sftp->mkdir_state == libssh2_NB_state_created) { - rc = libssh2_channel_write_ex(channel, 0, (char *) packet, packet_len); + rc = _libssh2_channel_write(channel, 0, (char *) packet, packet_len); if (rc == PACKET_EAGAIN) { sftp->mkdir_packet = packet; return PACKET_EAGAIN; @@ -2179,8 +2174,8 @@ static int sftp_rmdir(LIBSSH2_SFTP *sftp, const char *path, } if (sftp->rmdir_state == libssh2_NB_state_created) { - rc = libssh2_channel_write_ex(channel, 0, (char *) sftp->rmdir_packet, - packet_len); + rc = _libssh2_channel_write(channel, 0, (char *) sftp->rmdir_packet, + packet_len); if (rc == PACKET_EAGAIN) { return PACKET_EAGAIN; } else if (packet_len != rc) { @@ -2298,8 +2293,8 @@ static int sftp_stat(LIBSSH2_SFTP *sftp, const char *path, } if (sftp->stat_state == libssh2_NB_state_created) { - rc = libssh2_channel_write_ex(channel, 0, (char *) sftp->stat_packet, - packet_len); + rc = _libssh2_channel_write(channel, 0, (char *) sftp->stat_packet, + packet_len); if (rc == PACKET_EAGAIN) { return PACKET_EAGAIN; } else if (packet_len != rc) { @@ -2438,9 +2433,8 @@ static int sftp_symlink(LIBSSH2_SFTP *sftp, const char *path, } if (sftp->symlink_state == libssh2_NB_state_created) { - rc = libssh2_channel_write_ex(channel, 0, - (char *) sftp->symlink_packet, - packet_len); + rc = _libssh2_channel_write(channel, 0, (char *) sftp->symlink_packet, + packet_len); if (rc == PACKET_EAGAIN) { return PACKET_EAGAIN; } else if (packet_len != rc) {