diff options
author | Andreas Schneider <mail@cynapses.org> | 2009-04-22 15:53:29 +0000 |
---|---|---|
committer | Andreas Schneider <mail@cynapses.org> | 2009-04-22 15:53:29 +0000 |
commit | 5be3a3c0663382cac06d47534068be48c21515e2 (patch) | |
tree | 30c06c16e611893503dd37ce69f224607fb79dbe | |
parent | 75eddb1ebbae7795daa54bc849fd66092511aa16 (diff) | |
download | libssh-5be3a3c0663382cac06d47534068be48c21515e2.tar.gz libssh-5be3a3c0663382cac06d47534068be48c21515e2.tar.xz libssh-5be3a3c0663382cac06d47534068be48c21515e2.zip |
Improve sftp_enqueue().
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@582 7dcaeef0-15fb-0310-b436-a5af3365683c
-rw-r--r-- | libssh/sftp.c | 45 |
1 files changed, 29 insertions, 16 deletions
diff --git a/libssh/sftp.c b/libssh/sftp.c index f4ae481..2251c13 100644 --- a/libssh/sftp.c +++ b/libssh/sftp.c @@ -39,7 +39,7 @@ #define sftp_leave_function() _leave_function(sftp->channel->session) /* functions */ -void sftp_enqueue(SFTP_SESSION *session, SFTP_MESSAGE *msg); +static int sftp_enqueue(SFTP_SESSION *session, SFTP_MESSAGE *msg); static void sftp_message_free(SFTP_MESSAGE *msg); static void sftp_set_error(SFTP_SESSION *sftp, int errnum); @@ -389,7 +389,11 @@ static int sftp_read_and_dispatch(SFTP_SESSION *sftp) { return -1; } - sftp_enqueue(sftp, msg); + if (sftp_enqueue(sftp, msg) < 0) { + sftp_message_free(msg); + sftp_leave_function(); + return -1; + } sftp_leave_function(); return 0; @@ -503,21 +507,30 @@ static void request_queue_free(REQUEST_QUEUE *queue) { SAFE_FREE(queue); } -void sftp_enqueue(SFTP_SESSION *sftp, SFTP_MESSAGE *msg){ - REQUEST_QUEUE *queue=request_queue_new(msg); - REQUEST_QUEUE *ptr; - ssh_log(sftp->session, SSH_LOG_PACKET, - "queued msg type %d id %d", - msg->id, msg->packet_type); - if(!sftp->queue) - sftp->queue=queue; - else { - ptr=sftp->queue; - while(ptr->next){ - ptr=ptr->next; /* find end of linked list */ - } - ptr->next=queue; /* add it on bottom */ +static int sftp_enqueue(SFTP_SESSION *sftp, SFTP_MESSAGE *msg) { + REQUEST_QUEUE *queue = NULL; + REQUEST_QUEUE *ptr; + + queue = request_queue_new(msg); + if (queue == NULL) { + return -1; + } + + ssh_log(sftp->session, SSH_LOG_PACKET, + "Queued msg type %d id %d", + msg->id, msg->packet_type); + + if(sftp->queue == NULL) { + sftp->queue = queue; + } else { + ptr = sftp->queue; + while(ptr->next) { + ptr=ptr->next; /* find end of linked list */ } + ptr->next = queue; /* add it on bottom */ + } + + return 0; } /* pulls of a message from the queue based on the ID. returns null if no message has been found */ |