diff options
author | Anderson Toshiyuki Sasaki <ansasaki@redhat.com> | 2019-06-24 18:50:01 +0200 |
---|---|---|
committer | Andreas Schneider <asn@cryptomilk.org> | 2019-06-27 10:37:41 +0200 |
commit | 3f2375e948092aad0e6e35ac3ff78018ab866d2b (patch) | |
tree | 64dea0baa30bcecbc752bc92bbec84127577ea31 | |
parent | 4d06c2f283eae3f80b73c8565f96eb73a4a755be (diff) | |
download | libssh-3f2375e948092aad0e6e35ac3ff78018ab866d2b.tar.gz libssh-3f2375e948092aad0e6e35ac3ff78018ab866d2b.tar.xz libssh-3f2375e948092aad0e6e35ac3ff78018ab866d2b.zip |
packet: Reformat ssh_packet_process()
Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit a1ee22eb6414bca7b3532fcef669d65a53929b2f)
-rw-r--r-- | src/packet.c | 75 |
1 files changed, 44 insertions, 31 deletions
diff --git a/src/packet.c b/src/packet.c index 9ae26289..903e0288 100644 --- a/src/packet.c +++ b/src/packet.c @@ -1438,37 +1438,50 @@ void ssh_packet_set_default_callbacks(ssh_session session){ * @brief dispatch the call of packet handlers callbacks for a received packet * @param type type of packet */ -void ssh_packet_process(ssh_session session, uint8_t type){ - struct ssh_iterator *i; - int r=SSH_PACKET_NOT_USED; - ssh_packet_callbacks cb; - - SSH_LOG(SSH_LOG_PACKET, "Dispatching handler for packet type %d",type); - if(session->packet_callbacks == NULL){ - SSH_LOG(SSH_LOG_RARE,"Packet callback is not initialized !"); - - return; - } - i=ssh_list_get_iterator(session->packet_callbacks); - while(i != NULL){ - cb=ssh_iterator_value(ssh_packet_callbacks,i); - i=i->next; - if(!cb) - continue; - if(cb->start > type) - continue; - if(cb->start + cb->n_callbacks <= type) - continue; - if(cb->callbacks[type - cb->start]==NULL) - continue; - r=cb->callbacks[type - cb->start](session,type,session->in_buffer,cb->user); - if(r==SSH_PACKET_USED) - break; - } - if(r==SSH_PACKET_NOT_USED){ - SSH_LOG(SSH_LOG_RARE,"Couldn't do anything with packet type %d",type); - ssh_packet_send_unimplemented(session, session->recv_seq-1); - } +void ssh_packet_process(ssh_session session, uint8_t type) +{ + struct ssh_iterator *i = NULL; + int rc = SSH_PACKET_NOT_USED; + ssh_packet_callbacks cb; + + SSH_LOG(SSH_LOG_PACKET, "Dispatching handler for packet type %d", type); + if (session->packet_callbacks == NULL) { + SSH_LOG(SSH_LOG_RARE, "Packet callback is not initialized !"); + return; + } + + i = ssh_list_get_iterator(session->packet_callbacks); + while (i != NULL) { + cb = ssh_iterator_value(ssh_packet_callbacks, i); + i = i->next; + + if (!cb) { + continue; + } + + if (cb->start > type) { + continue; + } + + if (cb->start + cb->n_callbacks <= type) { + continue; + } + + if (cb->callbacks[type - cb->start] == NULL) { + continue; + } + + rc = cb->callbacks[type - cb->start](session, type, session->in_buffer, + cb->user); + if (rc == SSH_PACKET_USED) { + break; + } + } + + if (rc == SSH_PACKET_NOT_USED) { + SSH_LOG(SSH_LOG_RARE, "Couldn't do anything with packet type %d", type); + ssh_packet_send_unimplemented(session, session->recv_seq - 1); + } } /** @internal |