mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-12-02 01:17:52 +03:00
Improve sftp_handle_alloc.
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@628 7dcaeef0-15fb-0310-b436-a5af3365683c
This commit is contained in:
@@ -412,31 +412,44 @@ int sftp_reply_data(SFTP_CLIENT_MESSAGE *msg, const void *data, int len) {
|
|||||||
return 0;
|
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 function accepts an info that can be retrieved later with
|
||||||
* the handle. Care is given that a corrupted handle won't give a
|
* the handle. Care is given that a corrupted handle won't give a
|
||||||
* valid info (or worse). */
|
* valid info (or worse).
|
||||||
STRING *sftp_handle_alloc(SFTP_SESSION *sftp, void *info){
|
*/
|
||||||
int i;
|
STRING *sftp_handle_alloc(SFTP_SESSION *sftp, void *info) {
|
||||||
u32 val;
|
|
||||||
STRING *ret;
|
STRING *ret;
|
||||||
|
u32 val;
|
||||||
|
int i;
|
||||||
|
|
||||||
if (sftp->handles == NULL) {
|
if (sftp->handles == NULL) {
|
||||||
sftp->handles = malloc(sizeof(void *) * SFTP_HANDLES);
|
sftp->handles = malloc(sizeof(void *) * SFTP_HANDLES);
|
||||||
if (sftp->handles == NULL) {
|
if (sftp->handles == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
memset(sftp->handles,0,sizeof(void *)*SFTP_HANDLES);
|
memset(sftp->handles, 0, sizeof(void *) * SFTP_HANDLES);
|
||||||
}
|
}
|
||||||
for(i=0; i<SFTP_HANDLES;++i)
|
|
||||||
if(!sftp->handles[i])
|
for (i = 0; i < SFTP_HANDLES; i++) {
|
||||||
|
if (sftp->handles[i] == NULL) {
|
||||||
break;
|
break;
|
||||||
if(i==SFTP_HANDLES)
|
}
|
||||||
return NULL; // no handle available
|
}
|
||||||
val=i;
|
|
||||||
ret=string_new(4);
|
if (i == SFTP_HANDLES) {
|
||||||
memcpy(ret->string,&val,sizeof(u32));
|
return NULL; /* no handle available */
|
||||||
sftp->handles[i]=info;
|
}
|
||||||
|
|
||||||
|
val = i;
|
||||||
|
ret = string_new(4);
|
||||||
|
if (ret == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(ret->string, &val, sizeof(u32));
|
||||||
|
sftp->handles[i] = info;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user