aboutsummaryrefslogtreecommitdiff
path: root/libssh/sftpserver.c
diff options
context:
space:
mode:
authorAndreas Schneider <mail@cynapses.org>2009-04-27 11:59:14 +0000
committerAndreas Schneider <mail@cynapses.org>2009-04-27 11:59:14 +0000
commit315e5aca84bc8d2269b70a9dfe8c61ca94f5fa8f (patch)
tree4625052aa2fbf072136f3f113519dbbb17ee2fe8 /libssh/sftpserver.c
parentbf312c50a9c7f80d38ca394e6cb5ab37e6ff4b88 (diff)
downloadlibssh-315e5aca84bc8d2269b70a9dfe8c61ca94f5fa8f.tar.gz
libssh-315e5aca84bc8d2269b70a9dfe8c61ca94f5fa8f.tar.xz
libssh-315e5aca84bc8d2269b70a9dfe8c61ca94f5fa8f.zip
Improve sftp_handle_alloc.
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@628 7dcaeef0-15fb-0310-b436-a5af3365683c
Diffstat (limited to 'libssh/sftpserver.c')
-rw-r--r--libssh/sftpserver.c55
1 files changed, 34 insertions, 21 deletions
diff --git a/libssh/sftpserver.c b/libssh/sftpserver.c
index 21f2d0c..9384ce2 100644
--- a/libssh/sftpserver.c
+++ b/libssh/sftpserver.c
@@ -412,32 +412,45 @@ int sftp_reply_data(SFTP_CLIENT_MESSAGE *msg, const void *data, int len) {
return 0;
}
-/* this function will return you a new handle to give the client.
+/*
+ * This function will return you a new handle to give the client.
* the function accepts an info that can be retrieved later with
* the handle. Care is given that a corrupted handle won't give a
- * valid info (or worse). */
-STRING *sftp_handle_alloc(SFTP_SESSION *sftp, void *info){
- int i;
- u32 val;
- STRING *ret;
+ * valid info (or worse).
+ */
+STRING *sftp_handle_alloc(SFTP_SESSION *sftp, void *info) {
+ STRING *ret;
+ u32 val;
+ int i;
+ if (sftp->handles == NULL) {
+ sftp->handles = malloc(sizeof(void *) * SFTP_HANDLES);
if (sftp->handles == NULL) {
- sftp->handles = malloc(sizeof(void *) * SFTP_HANDLES);
- if (sftp->handles == NULL) {
- return NULL;
- }
- memset(sftp->handles,0,sizeof(void *)*SFTP_HANDLES);
+ return NULL;
}
- for(i=0; i<SFTP_HANDLES;++i)
- if(!sftp->handles[i])
- break;
- if(i==SFTP_HANDLES)
- return NULL; // no handle available
- val=i;
- ret=string_new(4);
- memcpy(ret->string,&val,sizeof(u32));
- sftp->handles[i]=info;
- return ret;
+ memset(sftp->handles, 0, sizeof(void *) * SFTP_HANDLES);
+ }
+
+ for (i = 0; i < SFTP_HANDLES; i++) {
+ if (sftp->handles[i] == NULL) {
+ break;
+ }
+ }
+
+ if (i == SFTP_HANDLES) {
+ return NULL; /* no handle available */
+ }
+
+ val = i;
+ ret = string_new(4);
+ if (ret == NULL) {
+ return NULL;
+ }
+
+ memcpy(ret->string, &val, sizeof(u32));
+ sftp->handles[i] = info;
+
+ return ret;
}
void *sftp_handle(SFTP_SESSION *sftp, STRING *handle){