1
1

sftp: added useful server APIs

Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
Этот коммит содержится в:
Aris Adamantiadis 2013-05-30 10:38:47 +02:00 коммит произвёл Andreas Schneider
родитель 55ddc3932e
Коммит 7e7910a1ca
2 изменённых файлов: 41 добавлений и 3 удалений

Просмотреть файл

@ -132,6 +132,7 @@ struct sftp_client_message_struct {
int attr_num;
ssh_buffer attrbuf; /* used by sftp_reply_attrs */
ssh_string data; /* can be newpath of rename() */
ssh_buffer complete_message; /* complete message in case of retransmission*/
};
struct sftp_request_queue_struct {
@ -824,8 +825,14 @@ int buffer_add_attributes(ssh_buffer buffer, sftp_attributes attr);
sftp_attributes sftp_parse_attr(sftp_session session, ssh_buffer buf,int expectname);
/* sftpserver.c */
sftp_client_message sftp_get_client_message(sftp_session sftp);
void sftp_client_message_free(sftp_client_message msg);
LIBSSH_API sftp_client_message sftp_get_client_message(sftp_session sftp);
LIBSSH_API void sftp_client_message_free(sftp_client_message msg);
LIBSSH_API uint8_t sftp_client_message_get_type(sftp_client_message msg);
LIBSSH_API const char *sftp_client_message_get_filename(sftp_client_message msg);
LIBSSH_API void sftp_client_message_set_filename(sftp_client_message msg, const char *newname);
LIBSSH_API char *sftp_client_message_get_data(sftp_client_message msg);
LIBSSH_API uint32_t sftp_client_message_get_flags(sftp_client_message msg);
LIBSSH_API int sftp_send_client_message(sftp_session sftp, sftp_client_message msg);
int sftp_reply_name(sftp_client_message msg, const char *name,
sftp_attributes attr);
int sftp_reply_handle(sftp_client_message msg, ssh_string handle);

Просмотреть файл

@ -62,6 +62,10 @@ sftp_client_message sftp_get_client_message(sftp_session sftp) {
msg->type = packet->type;
msg->sftp = sftp;
/* take a copy of the whole packet */
msg->complete_message = ssh_buffer_new();
buffer_add_data(msg->complete_message, buffer_get_rest(payload), buffer_get_rest_len(payload));
buffer_get_u32(payload, &msg->id);
switch(msg->type) {
@ -241,6 +245,33 @@ sftp_client_message sftp_get_client_message(sftp_session sftp) {
return msg;
}
/* Send an sftp client message. Can be used in cas of proxying */
int sftp_send_client_message(sftp_session sftp, sftp_client_message msg){
return sftp_packet_write(sftp, msg->type, msg->complete_message);
}
uint8_t sftp_client_message_get_type(sftp_client_message msg){
return msg->type;
}
const char *sftp_client_message_get_filename(sftp_client_message msg){
return msg->filename;
}
void sftp_client_message_set_filename(sftp_client_message msg, const char *newname){
free(msg->filename);
msg->filename = strdup(newname);
}
char *sftp_client_message_get_data(sftp_client_message msg){
char *str = ssh_string_to_char(msg->data);
return str;
}
uint32_t sftp_client_message_get_flags(sftp_client_message msg){
return msg->flags;
}
void sftp_client_message_free(sftp_client_message msg) {
if (msg == NULL) {
return;
@ -250,7 +281,7 @@ void sftp_client_message_free(sftp_client_message msg) {
ssh_string_free(msg->data);
ssh_string_free(msg->handle);
sftp_attributes_free(msg->attr);
ssh_buffer_free(msg->complete_message);
ZERO_STRUCTP(msg);
SAFE_FREE(msg);
}