diff options
author | Andreas Schneider <mail@cynapses.org> | 2009-04-14 08:55:33 +0000 |
---|---|---|
committer | Andreas Schneider <mail@cynapses.org> | 2009-04-14 08:55:33 +0000 |
commit | 22b3122c6c297f7329100543afc7e712b3dc91d5 (patch) | |
tree | 19baf76d5741cf36b5481d06320726b6d60ea422 /libssh/packet.c | |
parent | 640cf4cc93f92296fc6a8a4f64a7e2be0983f76e (diff) | |
download | libssh-22b3122c6c297f7329100543afc7e712b3dc91d5.tar.gz libssh-22b3122c6c297f7329100543afc7e712b3dc91d5.tar.xz libssh-22b3122c6c297f7329100543afc7e712b3dc91d5.zip |
Use consistent return values for packet_translate().
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@456 7dcaeef0-15fb-0310-b436-a5af3365683c
Diffstat (limited to 'libssh/packet.c')
-rw-r--r-- | libssh/packet.c | 44 |
1 files changed, 25 insertions, 19 deletions
diff --git a/libssh/packet.c b/libssh/packet.c index 1895578..cda8383 100644 --- a/libssh/packet.c +++ b/libssh/packet.c @@ -373,24 +373,29 @@ int packet_read(SSH_SESSION *session) { return packet_read2(session); } -int packet_translate(SSH_SESSION *session){ - enter_function(); - memset(&session->in_packet,0,sizeof(PACKET)); - if(!session->in_buffer){ - leave_function(); - return -1; - } - ssh_log(session, SSH_LOG_RARE, "Final size %d", - buffer_get_rest_len(session->in_buffer)); - if(!buffer_get_u8(session->in_buffer,&session->in_packet.type)){ - ssh_set_error(session,SSH_FATAL,"Packet too short to read type"); - leave_function(); - return -1; - } - ssh_log(session, SSH_LOG_RARE, "Type %hhd", session->in_packet.type); - session->in_packet.valid=1; +int packet_translate(SSH_SESSION *session) { + enter_function(); + + memset(&session->in_packet, 0, sizeof(PACKET)); + if(session->in_buffer == NULL) { leave_function(); - return 0; + return SSH_ERROR; + } + + ssh_log(session, SSH_LOG_RARE, "Final size %d", + buffer_get_rest_len(session->in_buffer)); + + if(buffer_get_u8(session->in_buffer, &session->in_packet.type) == 0) { + ssh_set_error(session, SSH_FATAL, "Packet too short to read type"); + leave_function(); + return SSH_ERROR; + } + + ssh_log(session, SSH_LOG_RARE, "Type %hhd", session->in_packet.type); + session->in_packet.valid = 1; + + leave_function(); + return SSH_OK; } /* Write the the bufferized output. If the session is blocking, or enforce_blocking @@ -585,7 +590,8 @@ 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) || packet_translate(session)){ + if ((packet_read1(session) != SSH_OK) || + (packet_translate(session) != SSH_OK)) { leave_function(); return -1; } @@ -637,7 +643,7 @@ static int packet_wait2(SSH_SESSION *session,int type,int blocking){ leave_function(); return ret; } - if(packet_translate(session)){ + if (packet_translate(session) != SSH_OK) { leave_function(); return SSH_ERROR; } |