aboutsummaryrefslogtreecommitdiff
path: root/src/messages.c
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2018-09-28 15:53:41 +0200
committerAndreas Schneider <asn@cryptomilk.org>2018-10-24 09:48:35 +0200
commit9fbbdcc154eb787ed4dde6e7cc36d3c1d973e0eb (patch)
tree1178a1863efca9a451fd24bbd2c46e99cf5e6179 /src/messages.c
parentb9ac61d5a3a0b3f052094bf2eba7a1ac7942ce99 (diff)
downloadlibssh-9fbbdcc154eb787ed4dde6e7cc36d3c1d973e0eb.tar.gz
libssh-9fbbdcc154eb787ed4dde6e7cc36d3c1d973e0eb.tar.xz
libssh-9fbbdcc154eb787ed4dde6e7cc36d3c1d973e0eb.zip
messages: Rework ssh_message_queue()
Return early and make it easier to understand. Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Diffstat (limited to 'src/messages.c')
-rw-r--r--src/messages.c73
1 files changed, 43 insertions, 30 deletions
diff --git a/src/messages.c b/src/messages.c
index 4b293751..ca8ad736 100644
--- a/src/messages.c
+++ b/src/messages.c
@@ -411,45 +411,58 @@ static int ssh_execute_message_callback(ssh_session session, ssh_message msg) {
*/
static void ssh_message_queue(ssh_session session, ssh_message message)
{
- if (message != NULL) {
#ifdef WITH_SERVER
- int ret;
- /* probably not the best place to execute server callbacks, but still better
- * than nothing.
- */
- ret = ssh_execute_server_callbacks(session, message);
- if (ret == SSH_OK){
- ssh_message_free(message);
- return;
- }
+ int ret;
+#endif
+
+ if (message == NULL) {
+ return;
+ }
+
+#ifdef WITH_SERVER
+ /* probably not the best place to execute server callbacks, but still better
+ * than nothing.
+ */
+ ret = ssh_execute_server_callbacks(session, message);
+ if (ret == SSH_OK) {
+ ssh_message_free(message);
+ return;
+ }
#endif /* WITH_SERVER */
- if(session->ssh_message_callback != NULL) {
- ssh_execute_message_callback(session, message);
- return;
- }
- if (session->server_callbacks != NULL){
- /* if we have server callbacks, but nothing was executed, it means we are
- * in non-synchronous mode, and we just don't care about the message we
- * received. Just send a default response. Do not queue it.
- */
- ssh_message_reply_default(message);
- ssh_message_free(message);
- return;
- }
- if(session->ssh_message_list == NULL) {
- session->ssh_message_list = ssh_list_new();
- }
+
+ if (session->ssh_message_callback != NULL) {
+ /* This will transfer the message, do not free. */
+ ssh_execute_message_callback(session, message);
+ return;
+ }
+
+ if (session->server_callbacks != NULL) {
+ /* if we have server callbacks, but nothing was executed, it means we are
+ * in non-synchronous mode, and we just don't care about the message we
+ * received. Just send a default response. Do not queue it.
+ */
+ ssh_message_reply_default(message);
+ ssh_message_free(message);
+ return;
+ }
+
+ if (session->ssh_message_list == NULL) {
+ session->ssh_message_list = ssh_list_new();
if (session->ssh_message_list != NULL) {
- ssh_list_append(session->ssh_message_list, message);
- } else {
- /* If the message list couldn't be allocated, the message can't be
- * enqueued */
+ /*
+ * If the message list couldn't be allocated, the message can't be
+ * enqueued
+ */
ssh_message_reply_default(message);
ssh_set_error_oom(session);
ssh_message_free(message);
return;
}
}
+
+ /* This will transfer the message, do not free. */
+ ssh_list_append(session->ssh_message_list, message);
+ return;
}
/**