1
0
mirror of https://git.libssh.org/projects/libssh.git synced 2025-11-27 13:21:11 +03:00

packet: Reformat ssh_packet_process()

Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
Anderson Toshiyuki Sasaki
2019-06-24 18:50:01 +02:00
committed by Andreas Schneider
parent 1d54a3880d
commit a1ee22eb64

View File

@@ -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 * @brief dispatch the call of packet handlers callbacks for a received packet
* @param type type of packet * @param type type of packet
*/ */
void ssh_packet_process(ssh_session session, uint8_t type){ void ssh_packet_process(ssh_session session, uint8_t type)
struct ssh_iterator *i; {
int r=SSH_PACKET_NOT_USED; struct ssh_iterator *i = NULL;
ssh_packet_callbacks cb; int rc = SSH_PACKET_NOT_USED;
ssh_packet_callbacks cb;
SSH_LOG(SSH_LOG_PACKET, "Dispatching handler for packet type %d",type); SSH_LOG(SSH_LOG_PACKET, "Dispatching handler for packet type %d", type);
if(session->packet_callbacks == NULL){ if (session->packet_callbacks == NULL) {
SSH_LOG(SSH_LOG_RARE,"Packet callback is not initialized !"); SSH_LOG(SSH_LOG_RARE, "Packet callback is not initialized !");
return;
}
return; i = ssh_list_get_iterator(session->packet_callbacks);
} while (i != NULL) {
i=ssh_list_get_iterator(session->packet_callbacks); cb = ssh_iterator_value(ssh_packet_callbacks, i);
while(i != NULL){ i = i->next;
cb=ssh_iterator_value(ssh_packet_callbacks,i);
i=i->next; if (!cb) {
if(!cb) continue;
continue; }
if(cb->start > type)
continue; if (cb->start > type) {
if(cb->start + cb->n_callbacks <= type) continue;
continue; }
if(cb->callbacks[type - cb->start]==NULL)
continue; if (cb->start + cb->n_callbacks <= type) {
r=cb->callbacks[type - cb->start](session,type,session->in_buffer,cb->user); continue;
if(r==SSH_PACKET_USED) }
break;
} if (cb->callbacks[type - cb->start] == NULL) {
if(r==SSH_PACKET_NOT_USED){ continue;
SSH_LOG(SSH_LOG_RARE,"Couldn't do anything with packet type %d",type); }
ssh_packet_send_unimplemented(session, session->recv_seq-1);
} 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 /** @internal