aboutsummaryrefslogtreecommitdiff
path: root/libssh/packet.c
diff options
context:
space:
mode:
authorAndreas Schneider <mail@cynapses.org>2009-04-14 09:37:22 +0000
committerAndreas Schneider <mail@cynapses.org>2009-04-14 09:37:22 +0000
commit4174577db3e4c6ae3dce7bf78f0f96462463cf85 (patch)
treeee9e23583e1d91c65dcec7ab7a94c644d1a88c5a /libssh/packet.c
parent6ec84bfc2eb9922e83876a4352859dfcc4850efa (diff)
downloadlibssh-4174577db3e4c6ae3dce7bf78f0f96462463cf85.tar.gz
libssh-4174577db3e4c6ae3dce7bf78f0f96462463cf85.tar.xz
libssh-4174577db3e4c6ae3dce7bf78f0f96462463cf85.zip
Use consistend return values for packet_wait() functions.
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@462 7dcaeef0-15fb-0310-b436-a5af3365683c
Diffstat (limited to 'libssh/packet.c')
-rw-r--r--libssh/packet.c197
1 files changed, 106 insertions, 91 deletions
diff --git a/libssh/packet.c b/libssh/packet.c
index 816dc3f..4ee3aaa 100644
--- a/libssh/packet.c
+++ b/libssh/packet.c
@@ -662,105 +662,120 @@ void packet_parse(SSH_SESSION *session) {
}
#ifdef HAVE_SSH1
-static int packet_wait1(SSH_SESSION *session,int type,int blocking){
- enter_function();
- ssh_log(session,SSH_LOG_PROTOCOL,"packet_wait1 waiting for %d",type);
- while(1){
- if ((packet_read1(session) != SSH_OK) ||
- (packet_translate(session) != SSH_OK)) {
- leave_function();
- return -1;
+static int packet_wait1(SSH_SESSION *session, int type, int blocking) {
+
+ enter_function();
+
+ ssh_log(session, SSH_LOG_PROTOCOL, "packet_wait1 waiting for %d", type);
+
+ do {
+ if ((packet_read1(session) != SSH_OK) ||
+ (packet_translate(session) != SSH_OK)) {
+ leave_function();
+ return SSH_ERROR;
+ }
+ ssh_log(session, SSH_LOG_PACKET, "packet_wait1() received a type %d packet",
+ session->in_packet.type);
+ switch (session->in_packet.type) {
+ case SSH_MSG_DISCONNECT:
+ packet_parse(session);
+ leave_function();
+ return SSH_ERROR;
+ case SSH_SMSG_STDOUT_DATA:
+ case SSH_SMSG_STDERR_DATA:
+ case SSH_SMSG_EXITSTATUS:
+ if (channel_handle1(session,type) < 0) {
+ leave_function();
+ return SSH_ERROR;
}
- ssh_log(session,SSH_LOG_PACKET,"packet_wait 1 received a type %d packet",session->in_packet.type);
- switch(session->in_packet.type){
- case SSH_MSG_DISCONNECT:
- packet_parse(session);
- leave_function();
- return -1;
- case SSH_SMSG_STDOUT_DATA:
- case SSH_SMSG_STDERR_DATA:
- case SSH_SMSG_EXITSTATUS:
- if (channel_handle1(session,type) < 0) {
- leave_function();
- return -1;
- }
- break;
- case SSH_MSG_DEBUG:
- case SSH_MSG_IGNORE:
- break;
-/* case SSH2_MSG_CHANNEL_CLOSE:
- packet_parse(session);
- break;;
-*/
- default:
- if(type && (type != session->in_packet.type)){
- ssh_set_error(session,SSH_FATAL,"waitpacket(): Received a %d type packet, was waiting for a %d\n",session->in_packet.type,type);
- leave_function();
- return -1;
- }
- leave_function();
- return 0;
- }
- if(blocking==0){
- leave_function();
- return 0;
+ break;
+ case SSH_MSG_DEBUG:
+ case SSH_MSG_IGNORE:
+ break;
+ /* case SSH2_MSG_CHANNEL_CLOSE:
+ packet_parse(session);
+ break;;
+ */
+ default:
+ if (type && (type != session->in_packet.type)) {
+ ssh_set_error(session, SSH_FATAL,
+ "packet_wait1(): Received a %d type packet, but expected %d\n",
+ session->in_packet.type, type);
+ leave_function();
+ return SSH_ERROR;
}
+ leave_function();
+ return SSH_OK;
}
- leave_function();
- return 0;
+
+ if (blocking == 0) {
+ leave_function();
+ return SSH_OK;
+ }
+ } while(1);
+
+ leave_function();
+ return SSH_OK;
}
#endif /* HAVE_SSH1 */
-static int packet_wait2(SSH_SESSION *session,int type,int blocking){
- int ret;
- enter_function();
- while(1){
- ret=packet_read2(session);
- if(ret != SSH_OK){
- leave_function();
- return ret;
- }
- if (packet_translate(session) != SSH_OK) {
- leave_function();
- return SSH_ERROR;
- }
- switch(session->in_packet.type){
- case SSH2_MSG_DISCONNECT:
- packet_parse(session);
- ssh_log(session, SSH_LOG_PACKET, "received disconnect packet");
- leave_function();
- return SSH_ERROR;
- case SSH2_MSG_CHANNEL_WINDOW_ADJUST:
- case SSH2_MSG_CHANNEL_DATA:
- case SSH2_MSG_CHANNEL_EXTENDED_DATA:
- case SSH2_MSG_CHANNEL_REQUEST:
- case SSH2_MSG_CHANNEL_EOF:
- case SSH2_MSG_CHANNEL_CLOSE:
- packet_parse(session);
- break;
- case SSH2_MSG_IGNORE:
- break;
- default:
- if(type && (type != session->in_packet.type)){
- ssh_set_error(session,SSH_FATAL,"waitpacket(): Received a %d type packet, was waiting for a %d\n",session->in_packet.type,type);
- leave_function();
- return SSH_ERROR;
- }
- leave_function();
- return SSH_OK;
- }
- if(blocking==0){
- leave_function();
- return SSH_OK; //shouldn't it return SSH_AGAIN here ?
+
+static int packet_wait2(SSH_SESSION *session, int type, int blocking) {
+ int rc = SSH_ERROR;
+
+ enter_function();
+ do {
+ rc = packet_read2(session);
+ if (rc != SSH_OK) {
+ leave_function();
+ return rc;
+ }
+ if (packet_translate(session) != SSH_OK) {
+ leave_function();
+ return SSH_ERROR;
+ }
+ switch (session->in_packet.type) {
+ case SSH2_MSG_DISCONNECT:
+ packet_parse(session);
+ ssh_log(session, SSH_LOG_PACKET, "received disconnect packet");
+ leave_function();
+ return SSH_ERROR;
+ case SSH2_MSG_CHANNEL_WINDOW_ADJUST:
+ case SSH2_MSG_CHANNEL_DATA:
+ case SSH2_MSG_CHANNEL_EXTENDED_DATA:
+ case SSH2_MSG_CHANNEL_REQUEST:
+ case SSH2_MSG_CHANNEL_EOF:
+ case SSH2_MSG_CHANNEL_CLOSE:
+ packet_parse(session);
+ break;
+ case SSH2_MSG_IGNORE:
+ break;
+ default:
+ if (type && (type != session->in_packet.type)) {
+ ssh_set_error(session, SSH_FATAL,
+ "packet_wait2(): Received a %d type packet, but expected a %d\n",
+ session->in_packet.type, type);
+ leave_function();
+ return SSH_ERROR;
}
+ leave_function();
+ return SSH_OK;
}
- leave_function();
- return SSH_OK;
+ if (blocking == 0) {
+ leave_function();
+ return SSH_OK; //shouldn't it return SSH_AGAIN here ?
+ }
+ } while(1);
+
+ leave_function();
+ return SSH_OK;
}
-int packet_wait(SSH_SESSION *session, int type, int block){
+
+int packet_wait(SSH_SESSION *session, int type, int block) {
#ifdef HAVE_SSH1
- if(session->version==1)
- return packet_wait1(session,type,block);
- else
+ if (session->version == 1) {
+ return packet_wait1(session, type, block);
+ }
#endif
- return packet_wait2(session,type,block);
+ return packet_wait2(session, type, block);
}
+