mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-11-30 13:01:23 +03:00
Improve sftp_xstat().
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@615 7dcaeef0-15fb-0310-b436-a5af3365683c
This commit is contained in:
@@ -2273,42 +2273,62 @@ char *sftp_canonicalize_path(SFTP_SESSION *sftp, const char *path) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static SFTP_ATTRIBUTES *sftp_xstat(SFTP_SESSION *sftp, const char *path, int param){
|
||||
u32 id=sftp_get_new_id(sftp);
|
||||
BUFFER *buffer=buffer_new();
|
||||
STRING *pathstr= string_from_char(path);
|
||||
SFTP_MESSAGE *msg=NULL;
|
||||
STATUS_MESSAGE *status=NULL;
|
||||
SFTP_ATTRIBUTES *pattr=NULL;
|
||||
static SFTP_ATTRIBUTES *sftp_xstat(SFTP_SESSION *sftp, const char *path,
|
||||
int param) {
|
||||
STATUS_MESSAGE *status = NULL;
|
||||
SFTP_MESSAGE *msg = NULL;
|
||||
STRING *pathstr;
|
||||
BUFFER *buffer;
|
||||
u32 id;
|
||||
|
||||
buffer_add_u32(buffer,id);
|
||||
buffer_add_ssh_string(buffer,pathstr);
|
||||
free(pathstr);
|
||||
sftp_packet_write(sftp,param,buffer);
|
||||
buffer_free(buffer);
|
||||
while(!msg){
|
||||
if(sftp_read_and_dispatch(sftp))
|
||||
return NULL;
|
||||
msg=sftp_dequeue(sftp,id);
|
||||
}
|
||||
if(msg->packet_type==SSH_FXP_ATTRS){
|
||||
pattr=sftp_parse_attr(sftp,msg->payload,0);
|
||||
return pattr;
|
||||
}
|
||||
if(msg->packet_type== SSH_FXP_STATUS){
|
||||
status=parse_status_msg(msg);
|
||||
sftp_message_free(msg);
|
||||
if(!status)
|
||||
return NULL;
|
||||
sftp_set_error(sftp, status->status);
|
||||
ssh_set_error(sftp->session,SSH_REQUEST_DENIED,"sftp server: %s",status->errormsg);
|
||||
status_msg_free(status);
|
||||
return NULL;
|
||||
}
|
||||
ssh_set_error(sftp->session, SSH_FATAL,
|
||||
"Received mesg %d during stat()", msg->packet_type);
|
||||
sftp_message_free(msg);
|
||||
buffer = buffer_new();
|
||||
if (buffer == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pathstr = string_from_char(path);
|
||||
if (pathstr == NULL) {
|
||||
buffer_free(buffer);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
id = sftp_get_new_id(sftp);
|
||||
if (buffer_add_u32(buffer, id) < 0 ||
|
||||
buffer_add_ssh_string(buffer, pathstr) < 0 ||
|
||||
sftp_packet_write(sftp, param, buffer) < 0) {
|
||||
buffer_free(buffer);
|
||||
string_free(pathstr);
|
||||
return NULL;
|
||||
}
|
||||
buffer_free(buffer);
|
||||
string_free(pathstr);
|
||||
|
||||
while (msg == NULL) {
|
||||
if (sftp_read_and_dispatch(sftp) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
msg = sftp_dequeue(sftp, id);
|
||||
}
|
||||
|
||||
if (msg->packet_type == SSH_FXP_ATTRS) {
|
||||
return sftp_parse_attr(sftp, msg->payload, 0);
|
||||
} else if (msg->packet_type == SSH_FXP_STATUS) {
|
||||
status = parse_status_msg(msg);
|
||||
sftp_message_free(msg);
|
||||
if (status == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
sftp_set_error(sftp, status->status);
|
||||
ssh_set_error(sftp->session, SSH_REQUEST_DENIED,
|
||||
"SFTP server: %s", status->errormsg);
|
||||
status_msg_free(status);
|
||||
return NULL;
|
||||
}
|
||||
ssh_set_error(sftp->session, SSH_FATAL,
|
||||
"Received mesg %d during stat()", msg->packet_type);
|
||||
sftp_message_free(msg);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SFTP_ATTRIBUTES *sftp_stat(SFTP_SESSION *session, const char *path){
|
||||
|
||||
Reference in New Issue
Block a user