From 2fc4c7e3359f6e046faab7cf0089a9375f4b5350 Mon Sep 17 00:00:00 2001 From: Aris Adamantiadis Date: Fri, 8 Jan 2010 22:25:26 +0100 Subject: [PATCH] Dequeue the processed messages --- include/libssh/messages.h | 1 + libssh/messages.c | 20 +++++++++++++++++++- libssh/server.c | 10 ++++++++-- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/include/libssh/messages.h b/include/libssh/messages.h index b53fda9f..933cd70c 100644 --- a/include/libssh/messages.h +++ b/include/libssh/messages.h @@ -85,5 +85,6 @@ int message_handle_channel_request(ssh_session session, ssh_channel channel, ssh const char *request, uint8_t want_reply); int ssh_execute_message_callbacks(ssh_session session); void ssh_message_queue(ssh_session session, ssh_message message); +ssh_message ssh_message_pop_head(ssh_session session); #endif /* MESSAGES_H_ */ diff --git a/libssh/messages.c b/libssh/messages.c index 8dfe482e..e5d6c3a7 100644 --- a/libssh/messages.c +++ b/libssh/messages.c @@ -711,7 +711,7 @@ ssh_message ssh_message_get(ssh_session session) { } msg=ssh_list_get_head(ssh_message, session->ssh_message_list); } while(msg==NULL); - + msg=ssh_message_pop_head(session); leave_function(); return msg; } @@ -790,6 +790,24 @@ void ssh_message_queue(ssh_session session, ssh_message message){ } } +/** @internal + * @brief Pops one message from the message list and dequeue it. + * @param session SSH session. + * @returns The head message, or NULL if it doesn't exist + */ +ssh_message ssh_message_pop_head(ssh_session session){ + ssh_message msg=NULL; + struct ssh_iterator *i; + if(session->ssh_message_list == NULL) + return NULL; + i=ssh_list_get_iterator(session->ssh_message_list); + if(i != NULL){ + msg=ssh_iterator_value(ssh_message,i); + ssh_list_remove(session->ssh_message_list,i); + } + return msg; +} + /** * @} */ diff --git a/libssh/server.c b/libssh/server.c index efb3220c..87bb3ab7 100644 --- a/libssh/server.c +++ b/libssh/server.c @@ -908,17 +908,23 @@ int ssh_execute_message_callbacks(ssh_session session){ if(!session->ssh_message_list) return SSH_OK; if(session->ssh_message_callback){ - while((msg=ssh_list_get_head(ssh_message , session->ssh_message_list)) != NULL){ + while(ssh_list_get_head(ssh_message , session->ssh_message_list) != NULL){ + msg=ssh_message_pop_head(session); ret=session->ssh_message_callback(session,msg); if(ret==1){ ret = ssh_message_reply_default(msg); + ssh_message_free(msg); if(ret != SSH_OK) return ret; + } else { + ssh_message_free(msg); } } } else { - while((msg=ssh_list_get_head(ssh_message , session->ssh_message_list)) != NULL){ + while(ssh_list_get_head(ssh_message , session->ssh_message_list) != NULL){ + msg=ssh_message_pop_head(session); ret = ssh_message_reply_default(msg); + ssh_message_free(msg); if(ret != SSH_OK) return ret; }