aboutsummaryrefslogtreecommitdiff
path: root/libssh/sftp.c
diff options
context:
space:
mode:
Diffstat (limited to 'libssh/sftp.c')
-rw-r--r--libssh/sftp.c335
1 files changed, 166 insertions, 169 deletions
diff --git a/libssh/sftp.c b/libssh/sftp.c
index ec244a2..cdeb9e2 100644
--- a/libssh/sftp.c
+++ b/libssh/sftp.c
@@ -63,10 +63,10 @@ struct sftp_ext_struct {
};
/* functions */
-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);
-static void status_msg_free(STATUS_MESSAGE *status);
+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);
+static void status_msg_free(sftp_status_message status);
static sftp_ext sftp_ext_new(void) {
sftp_ext ext;
@@ -99,8 +99,8 @@ static void sftp_ext_free(sftp_ext ext) {
SAFE_FREE(ext);
}
-SFTP_SESSION *sftp_new(ssh_session session){
- SFTP_SESSION *sftp;
+sftp_session sftp_new(ssh_session session){
+ sftp_session sftp;
enter_function();
@@ -109,7 +109,7 @@ SFTP_SESSION *sftp_new(ssh_session session){
return NULL;
}
- sftp = malloc(sizeof(SFTP_SESSION));
+ sftp = malloc(sizeof(struct sftp_session_struct));
if (sftp == NULL) {
leave_function();
return NULL;
@@ -149,10 +149,10 @@ SFTP_SESSION *sftp_new(ssh_session session){
}
#ifdef WITH_SERVER
-SFTP_SESSION *sftp_server_new(ssh_session session, ssh_channel chan){
- SFTP_SESSION *sftp = NULL;
+sftp_session sftp_server_new(ssh_session session, ssh_channel chan){
+ sftp_session sftp = NULL;
- sftp = malloc(sizeof(SFTP_SESSION));
+ sftp = malloc(sizeof(struct sftp_session_struct));
if (sftp == NULL) {
return NULL;
}
@@ -164,9 +164,9 @@ SFTP_SESSION *sftp_server_new(ssh_session session, ssh_channel chan){
return sftp;
}
-int sftp_server_init(SFTP_SESSION *sftp){
+int sftp_server_init(sftp_session sftp){
ssh_session session = sftp->session;
- SFTP_PACKET *packet = NULL;
+ sftp_packet packet = NULL;
ssh_buffer reply = NULL;
uint32_t version;
@@ -229,8 +229,8 @@ int sftp_server_init(SFTP_SESSION *sftp){
}
#endif /* WITH_SERVER */
-void sftp_free(SFTP_SESSION *sftp){
- struct request_queue *ptr;
+void sftp_free(sftp_session sftp){
+ sftp_request_queue ptr;
if (sftp == NULL) {
return;
@@ -239,7 +239,7 @@ void sftp_free(SFTP_SESSION *sftp){
channel_send_eof(sftp->channel);
ptr = sftp->queue;
while(ptr) {
- struct request_queue *old;
+ sftp_request_queue old;
sftp_message_free(ptr->message);
old = ptr->next;
SAFE_FREE(ptr);
@@ -253,7 +253,7 @@ void sftp_free(SFTP_SESSION *sftp){
SAFE_FREE(sftp);
}
-int sftp_packet_write(SFTP_SESSION *sftp, uint8_t type, ssh_buffer payload){
+int sftp_packet_write(sftp_session sftp, uint8_t type, ssh_buffer payload){
int size;
if (buffer_prepend_data(payload, &type, sizeof(uint8_t)) < 0) {
@@ -279,13 +279,13 @@ int sftp_packet_write(SFTP_SESSION *sftp, uint8_t type, ssh_buffer payload){
return size;
}
-SFTP_PACKET *sftp_packet_read(SFTP_SESSION *sftp) {
- SFTP_PACKET *packet = NULL;
+sftp_packet sftp_packet_read(sftp_session sftp) {
+ sftp_packet packet = NULL;
uint32_t size;
sftp_enter_function();
- packet = malloc(sizeof(SFTP_PACKET));
+ packet = malloc(sizeof(struct sftp_packet_struct));
if (packet == NULL) {
return NULL;
}
@@ -332,14 +332,14 @@ SFTP_PACKET *sftp_packet_read(SFTP_SESSION *sftp) {
return packet;
}
-static void sftp_set_error(SFTP_SESSION *sftp, int errnum) {
+static void sftp_set_error(sftp_session sftp, int errnum) {
if (sftp != NULL) {
sftp->errnum = errnum;
}
}
/* Get the last sftp error */
-int sftp_get_error(SFTP_SESSION *sftp) {
+int sftp_get_error(sftp_session sftp) {
if (sftp == NULL) {
return -1;
}
@@ -347,12 +347,12 @@ int sftp_get_error(SFTP_SESSION *sftp) {
return sftp->errnum;
}
-static SFTP_MESSAGE *sftp_message_new(SFTP_SESSION *sftp){
- SFTP_MESSAGE *msg = NULL;
+static sftp_message sftp_message_new(sftp_session sftp){
+ sftp_message msg = NULL;
sftp_enter_function();
- msg = malloc(sizeof(SFTP_MESSAGE));
+ msg = malloc(sizeof(struct sftp_message_struct));
if (msg == NULL) {
return NULL;
}
@@ -369,8 +369,8 @@ static SFTP_MESSAGE *sftp_message_new(SFTP_SESSION *sftp){
return msg;
}
-static void sftp_message_free(SFTP_MESSAGE *msg) {
- SFTP_SESSION *sftp;
+static void sftp_message_free(sftp_message msg) {
+ sftp_session sftp;
if (msg == NULL) {
return;
@@ -385,9 +385,9 @@ static void sftp_message_free(SFTP_MESSAGE *msg) {
sftp_leave_function();
}
-static SFTP_MESSAGE *sftp_get_message(SFTP_PACKET *packet) {
- SFTP_SESSION *sftp = packet->sftp;
- SFTP_MESSAGE *msg = NULL;
+static sftp_message sftp_get_message(sftp_packet packet) {
+ sftp_session sftp = packet->sftp;
+ sftp_message msg = NULL;
sftp_enter_function();
@@ -434,9 +434,9 @@ static SFTP_MESSAGE *sftp_get_message(SFTP_PACKET *packet) {
return msg;
}
-static int sftp_read_and_dispatch(SFTP_SESSION *sftp) {
- SFTP_PACKET *packet = NULL;
- SFTP_MESSAGE *msg = NULL;
+static int sftp_read_and_dispatch(sftp_session sftp) {
+ sftp_packet packet = NULL;
+ sftp_message msg = NULL;
sftp_enter_function();
@@ -463,7 +463,7 @@ static int sftp_read_and_dispatch(SFTP_SESSION *sftp) {
return 0;
}
-void sftp_packet_free(SFTP_PACKET *packet) {
+void sftp_packet_free(sftp_packet packet) {
if (packet == NULL) {
return;
}
@@ -473,8 +473,8 @@ void sftp_packet_free(SFTP_PACKET *packet) {
}
/* Initialize the sftp session with the server. */
-int sftp_init(SFTP_SESSION *sftp) {
- SFTP_PACKET *packet = NULL;
+int sftp_init(sftp_session sftp) {
+ sftp_packet packet = NULL;
ssh_buffer buffer = NULL;
ssh_string ext_name_s = NULL;
ssh_string ext_data_s = NULL;
@@ -582,7 +582,7 @@ int sftp_init(SFTP_SESSION *sftp) {
return 0;
}
-unsigned int sftp_extensions_get_count(SFTP_SESSION *sftp) {
+unsigned int sftp_extensions_get_count(sftp_session sftp) {
if (sftp == NULL || sftp->ext == NULL) {
return 0;
}
@@ -590,7 +590,7 @@ unsigned int sftp_extensions_get_count(SFTP_SESSION *sftp) {
return sftp->ext->count;
}
-const char *sftp_extensions_get_name(SFTP_SESSION *sftp, unsigned int idx) {
+const char *sftp_extensions_get_name(sftp_session sftp, unsigned int idx) {
if (sftp == NULL || sftp->ext == NULL || sftp->ext->name == NULL) {
return NULL;
}
@@ -602,7 +602,7 @@ const char *sftp_extensions_get_name(SFTP_SESSION *sftp, unsigned int idx) {
return sftp->ext->name[idx];
}
-const char *sftp_extensions_get_data(SFTP_SESSION *sftp, unsigned int idx) {
+const char *sftp_extensions_get_data(sftp_session sftp, unsigned int idx) {
if (sftp == NULL || sftp->ext == NULL || sftp->ext->data == NULL) {
return NULL;
}
@@ -614,7 +614,7 @@ const char *sftp_extensions_get_data(SFTP_SESSION *sftp, unsigned int idx) {
return sftp->ext->data[idx];
}
-int sftp_extension_supported(SFTP_SESSION *sftp, const char *name,
+int sftp_extension_supported(sftp_session sftp, const char *name,
const char *data) {
int i, n;
@@ -629,10 +629,10 @@ int sftp_extension_supported(SFTP_SESSION *sftp, const char *name,
return 0;
}
-static REQUEST_QUEUE *request_queue_new(SFTP_MESSAGE *msg) {
- REQUEST_QUEUE *queue = NULL;
+static sftp_request_queue request_queue_new(sftp_message msg) {
+ sftp_request_queue queue = NULL;
- queue = malloc(sizeof(REQUEST_QUEUE));
+ queue = malloc(sizeof(struct sftp_request_queue_struct));
if (queue == NULL) {
return NULL;
}
@@ -643,7 +643,7 @@ static REQUEST_QUEUE *request_queue_new(SFTP_MESSAGE *msg) {
return queue;
}
-static void request_queue_free(REQUEST_QUEUE *queue) {
+static void request_queue_free(sftp_request_queue queue) {
if (queue == NULL) {
return;
}
@@ -652,9 +652,9 @@ static void request_queue_free(REQUEST_QUEUE *queue) {
SAFE_FREE(queue);
}
-static int sftp_enqueue(SFTP_SESSION *sftp, SFTP_MESSAGE *msg) {
- REQUEST_QUEUE *queue = NULL;
- REQUEST_QUEUE *ptr;
+static int sftp_enqueue(sftp_session sftp, sftp_message msg) {
+ sftp_request_queue queue = NULL;
+ sftp_request_queue ptr;
queue = request_queue_new(msg);
if (queue == NULL) {
@@ -682,10 +682,10 @@ static int sftp_enqueue(SFTP_SESSION *sftp, SFTP_MESSAGE *msg) {
* Pulls of a message from the queue based on the ID.
* Returns NULL if no message has been found.
*/
-static SFTP_MESSAGE *sftp_dequeue(SFTP_SESSION *sftp, uint32_t id){
- REQUEST_QUEUE *prev = NULL;
- REQUEST_QUEUE *queue;
- SFTP_MESSAGE *msg;
+static sftp_message sftp_dequeue(sftp_session sftp, uint32_t id){
+ sftp_request_queue prev = NULL;
+ sftp_request_queue queue;
+ sftp_message msg;
if(sftp->queue == NULL) {
return NULL;
@@ -720,12 +720,12 @@ static SFTP_MESSAGE *sftp_dequeue(SFTP_SESSION *sftp, uint32_t id){
* between them.
* Returns a new ID ready to use in a request
*/
-static inline uint32_t sftp_get_new_id(SFTP_SESSION *session) {
+static inline uint32_t sftp_get_new_id(sftp_session session) {
return ++session->id_counter;
}
-static STATUS_MESSAGE *parse_status_msg(SFTP_MESSAGE *msg){
- STATUS_MESSAGE *status;
+static sftp_status_message parse_status_msg(sftp_message msg){
+ sftp_status_message status;
if (msg->packet_type != SSH_FXP_STATUS) {
ssh_set_error(msg->sftp->session, SSH_FATAL,
@@ -733,7 +733,7 @@ static STATUS_MESSAGE *parse_status_msg(SFTP_MESSAGE *msg){
return NULL;
}
- status = malloc(sizeof(STATUS_MESSAGE));
+ status = malloc(sizeof(struct sftp_message_struct));
if (status == NULL) {
return NULL;
}
@@ -762,7 +762,7 @@ static STATUS_MESSAGE *parse_status_msg(SFTP_MESSAGE *msg){
return status;
}
-static void status_msg_free(STATUS_MESSAGE *status){
+static void status_msg_free(sftp_status_message status){
if (status == NULL) {
return;
}
@@ -774,8 +774,8 @@ static void status_msg_free(STATUS_MESSAGE *status){
SAFE_FREE(status);
}
-static SFTP_FILE *parse_handle_msg(SFTP_MESSAGE *msg){
- SFTP_FILE *file;
+static sftp_file parse_handle_msg(sftp_message msg){
+ sftp_file file;
if(msg->packet_type != SSH_FXP_HANDLE) {
ssh_set_error(msg->sftp->session, SSH_FATAL,
@@ -783,7 +783,7 @@ static SFTP_FILE *parse_handle_msg(SFTP_MESSAGE *msg){
return NULL;
}
- file = malloc(sizeof(SFTP_FILE));
+ file = malloc(sizeof(struct sftp_file_struct));
if (file == NULL) {
return NULL;
}
@@ -805,11 +805,11 @@ static SFTP_FILE *parse_handle_msg(SFTP_MESSAGE *msg){
}
/* Open a directory */
-SFTP_DIR *sftp_opendir(SFTP_SESSION *sftp, const char *path){
- SFTP_MESSAGE *msg = NULL;
- SFTP_FILE *file = NULL;
- SFTP_DIR *dir = NULL;
- STATUS_MESSAGE *status;
+sftp_dir sftp_opendir(sftp_session sftp, const char *path){
+ sftp_message msg = NULL;
+ sftp_file file = NULL;
+ sftp_dir dir = NULL;
+ sftp_status_message status;
ssh_string path_s;
ssh_buffer payload;
uint32_t id;
@@ -864,7 +864,7 @@ SFTP_DIR *sftp_opendir(SFTP_SESSION *sftp, const char *path){
file = parse_handle_msg(msg);
sftp_message_free(msg);
if (file != NULL) {
- dir = malloc(sizeof(SFTP_DIR));
+ dir = malloc(sizeof(struct sftp_dir_struct));
if (dir == NULL) {
return NULL;
}
@@ -895,9 +895,9 @@ SFTP_DIR *sftp_opendir(SFTP_SESSION *sftp, const char *path){
* baselines from the protocol version 4.
* This code is more or less dead but maybe we need it in future.
*/
-static SFTP_ATTRIBUTES *sftp_parse_attr_4(SFTP_SESSION *sftp, ssh_buffer buf,
+static sftp_attributes sftp_parse_attr_4(sftp_session sftp, ssh_buffer buf,
int expectnames) {
- SFTP_ATTRIBUTES *attr;
+ sftp_attributes attr;
ssh_string owner = NULL;
ssh_string group = NULL;
uint32_t flags = 0;
@@ -906,7 +906,7 @@ static SFTP_ATTRIBUTES *sftp_parse_attr_4(SFTP_SESSION *sftp, ssh_buffer buf,
/* unused member variable */
(void) expectnames;
- attr = malloc(sizeof(SFTP_ATTRIBUTES));
+ attr = malloc(sizeof(struct sftp_attributes_struct));
if (attr == NULL) {
return NULL;
}
@@ -1069,15 +1069,15 @@ static SFTP_ATTRIBUTES *sftp_parse_attr_4(SFTP_SESSION *sftp, ssh_buffer buf,
string extended_data
... more extended data (extended_type - extended_data pairs),
so that number of pairs equals extended_count */
-static SFTP_ATTRIBUTES *sftp_parse_attr_3(SFTP_SESSION *sftp, ssh_buffer buf,
+static sftp_attributes sftp_parse_attr_3(sftp_session sftp, ssh_buffer buf,
int expectname) {
ssh_string longname = NULL;
ssh_string name = NULL;
- SFTP_ATTRIBUTES *attr;
+ sftp_attributes attr;
uint32_t flags = 0;
int ok = 0;
- attr = malloc(sizeof(SFTP_ATTRIBUTES));
+ attr = malloc(sizeof(struct sftp_attributes_struct));
if (attr == NULL) {
return NULL;
}
@@ -1208,7 +1208,7 @@ static SFTP_ATTRIBUTES *sftp_parse_attr_3(SFTP_SESSION *sftp, ssh_buffer buf,
}
/* FIXME is this really needed as a public function? */
-int buffer_add_attributes(ssh_buffer buffer, SFTP_ATTRIBUTES *attr) {
+int buffer_add_attributes(ssh_buffer buffer, sftp_attributes attr) {
uint32_t flags = (attr ? attr->flags : 0);
flags &= (SSH_FILEXFER_ATTR_SIZE | SSH_FILEXFER_ATTR_UIDGID |
@@ -1250,7 +1250,7 @@ int buffer_add_attributes(ssh_buffer buffer, SFTP_ATTRIBUTES *attr) {
}
-SFTP_ATTRIBUTES *sftp_parse_attr(SFTP_SESSION *session, ssh_buffer buf,
+sftp_attributes sftp_parse_attr(sftp_session session, ssh_buffer buf,
int expectname) {
switch(session->version) {
case 4:
@@ -1267,15 +1267,15 @@ SFTP_ATTRIBUTES *sftp_parse_attr(SFTP_SESSION *session, ssh_buffer buf,
}
/* Get the version of the SFTP protocol supported by the server */
-int sftp_server_version(SFTP_SESSION *sftp) {
+int sftp_server_version(sftp_session sftp) {
return sftp->server_version;
}
/* Get a single file attributes structure of a directory. */
-SFTP_ATTRIBUTES *sftp_readdir(SFTP_SESSION *sftp, SFTP_DIR *dir) {
- SFTP_MESSAGE *msg = NULL;
- STATUS_MESSAGE *status;
- SFTP_ATTRIBUTES *attr;
+sftp_attributes sftp_readdir(sftp_session sftp, sftp_dir dir) {
+ sftp_message msg = NULL;
+ sftp_status_message status;
+ sftp_attributes attr;
ssh_buffer payload;
uint32_t id;
@@ -1374,12 +1374,12 @@ SFTP_ATTRIBUTES *sftp_readdir(SFTP_SESSION *sftp, SFTP_DIR *dir) {
}
/* Tell if the directory has reached EOF (End Of File). */
-int sftp_dir_eof(SFTP_DIR *dir) {
+int sftp_dir_eof(sftp_dir dir) {
return dir->eof;
}
/* Free a SFTP_ATTRIBUTE handle */
-void sftp_attributes_free(SFTP_ATTRIBUTES *file){
+void sftp_attributes_free(sftp_attributes file){
if (file == NULL) {
return;
}
@@ -1396,9 +1396,9 @@ void sftp_attributes_free(SFTP_ATTRIBUTES *file){
SAFE_FREE(file);
}
-static int sftp_handle_close(SFTP_SESSION *sftp, ssh_string handle) {
- STATUS_MESSAGE *status;
- SFTP_MESSAGE *msg = NULL;
+static int sftp_handle_close(sftp_session sftp, ssh_string handle) {
+ sftp_status_message status;
+ sftp_message msg = NULL;
ssh_buffer buffer = NULL;
uint32_t id;
@@ -1453,12 +1453,12 @@ static int sftp_handle_close(SFTP_SESSION *sftp, ssh_string handle) {
return -1;
}
-int sftp_file_close(SFTP_FILE *file) {
+int sftp_file_close(sftp_file file) {
return sftp_close(file);
}
/* Close an open file handle. */
-int sftp_close(SFTP_FILE *file){
+int sftp_close(sftp_file file){
int err = SSH_NO_ERROR;
SAFE_FREE(file->name);
@@ -1472,12 +1472,12 @@ int sftp_close(SFTP_FILE *file){
return err;
}
-int sftp_dir_close(SFTP_DIR *dir) {
+int sftp_dir_close(sftp_dir dir) {
return sftp_closedir(dir);
}
/* Close an open directory. */
-int sftp_closedir(SFTP_DIR *dir){
+int sftp_closedir(sftp_dir dir){
int err = SSH_NO_ERROR;
SAFE_FREE(dir->name);
@@ -1493,12 +1493,12 @@ int sftp_closedir(SFTP_DIR *dir){
}
/* Open a file on the server. */
-SFTP_FILE *sftp_open(SFTP_SESSION *sftp, const char *file, int flags,
+sftp_file sftp_open(sftp_session sftp, const char *file, int flags,
mode_t mode) {
- SFTP_MESSAGE *msg = NULL;
- STATUS_MESSAGE *status;
- SFTP_ATTRIBUTES attr;
- SFTP_FILE *handle;
+ sftp_message msg = NULL;
+ sftp_status_message status;
+ struct sftp_attributes_struct attr;
+ sftp_file handle;
ssh_string filename;
ssh_buffer buffer;
uint32_t sftp_flags = 0;
@@ -1584,18 +1584,18 @@ SFTP_FILE *sftp_open(SFTP_SESSION *sftp, const char *file, int flags,
return NULL;
}
-void sftp_file_set_nonblocking(SFTP_FILE *handle){
+void sftp_file_set_nonblocking(sftp_file handle){
handle->nonblocking=1;
}
-void sftp_file_set_blocking(SFTP_FILE *handle){
+void sftp_file_set_blocking(sftp_file handle){
handle->nonblocking=0;
}
/* Read from a file using an opened sftp file handle. */
-ssize_t sftp_read(SFTP_FILE *handle, void *buf, size_t count) {
- SFTP_SESSION *sftp = handle->sftp;
- SFTP_MESSAGE *msg = NULL;
- STATUS_MESSAGE *status;
+ssize_t sftp_read(sftp_file handle, void *buf, size_t count) {
+ sftp_session sftp = handle->sftp;
+ sftp_message msg = NULL;
+ sftp_status_message status;
ssh_string datastring;
ssh_buffer buffer;
int id;
@@ -1686,8 +1686,8 @@ ssize_t sftp_read(SFTP_FILE *handle, void *buf, size_t count) {
}
/* Start an asynchronous read from a file using an opened sftp file handle. */
-int sftp_async_read_begin(SFTP_FILE *file, uint32_t len){
- SFTP_SESSION *sftp = file->sftp;
+int sftp_async_read_begin(sftp_file file, uint32_t len){
+ sftp_session sftp = file->sftp;
ssh_buffer buffer;
uint32_t id;
@@ -1716,10 +1716,10 @@ int sftp_async_read_begin(SFTP_FILE *file, uint32_t len){
}
/* Wait for an asynchronous read to complete and save the data. */
-int sftp_async_read(SFTP_FILE *file, void *data, uint32_t size, uint32_t id){
- SFTP_SESSION *sftp = file->sftp;
- SFTP_MESSAGE *msg = NULL;
- STATUS_MESSAGE *status;
+int sftp_async_read(sftp_file file, void *data, uint32_t size, uint32_t id){
+ sftp_session sftp = file->sftp;
+ sftp_message msg = NULL;
+ sftp_status_message status;
ssh_string datastring;
int err = SSH_OK;
uint32_t len;
@@ -1806,10 +1806,10 @@ int sftp_async_read(SFTP_FILE *file, void *data, uint32_t size, uint32_t id){
return SSH_ERROR;
}
-ssize_t sftp_write(SFTP_FILE *file, const void *buf, size_t count) {
- SFTP_SESSION *sftp = file->sftp;
- SFTP_MESSAGE *msg = NULL;
- STATUS_MESSAGE *status;
+ssize_t sftp_write(sftp_file file, const void *buf, size_t count) {
+ sftp_session sftp = file->sftp;
+ sftp_message msg = NULL;
+ sftp_status_message status;
ssh_string datastring;
ssh_buffer buffer;
uint32_t id;
@@ -1888,7 +1888,7 @@ ssize_t sftp_write(SFTP_FILE *file, const void *buf, size_t count) {
}
/* Seek to a specific location in a file. */
-int sftp_seek(SFTP_FILE *file, uint32_t new_offset) {
+int sftp_seek(sftp_file file, uint32_t new_offset) {
if (file == NULL) {
return -1;
}
@@ -1898,7 +1898,7 @@ int sftp_seek(SFTP_FILE *file, uint32_t new_offset) {
return 0;
}
-int sftp_seek64(SFTP_FILE *file, uint64_t new_offset) {
+int sftp_seek64(sftp_file file, uint64_t new_offset) {
if (file == NULL) {
return -1;
}
@@ -1909,28 +1909,28 @@ int sftp_seek64(SFTP_FILE *file, uint64_t new_offset) {
}
/* Report current byte position in file. */
-unsigned long sftp_tell(SFTP_FILE *file) {
+unsigned long sftp_tell(sftp_file file) {
return (unsigned long)file->offset;
}
/* Report current byte position in file. */
-uint64_t sftp_tell64(SFTP_FILE *file) {
+uint64_t sftp_tell64(sftp_file file) {
return (uint64_t) file->offset;
}
/* Rewinds the position of the file pointer to the beginning of the file.*/
-void sftp_rewind(SFTP_FILE *file) {
+void sftp_rewind(sftp_file file) {
file->offset = 0;
}
/* deprecated */
-int sftp_rm(SFTP_SESSION *sftp, const char *file) {
+int sftp_rm(sftp_session sftp, const char *file) {
return sftp_unlink(sftp, file);
}
/* code written by Nick */
-int sftp_unlink(SFTP_SESSION *sftp, const char *file) {
- STATUS_MESSAGE *status = NULL;
- SFTP_MESSAGE *msg = NULL;
+int sftp_unlink(sftp_session sftp, const char *file) {
+ sftp_status_message status = NULL;
+ sftp_message msg = NULL;
ssh_string filename;
ssh_buffer buffer;
uint32_t id;
@@ -1997,9 +1997,9 @@ int sftp_unlink(SFTP_SESSION *sftp, const char *file) {
}
/* code written by Nick */
-int sftp_rmdir(SFTP_SESSION *sftp, const char *directory) {
- STATUS_MESSAGE *status = NULL;
- SFTP_MESSAGE *msg = NULL;
+int sftp_rmdir(sftp_session sftp, const char *directory) {
+ sftp_status_message status = NULL;
+ sftp_message msg = NULL;
ssh_string filename;
ssh_buffer buffer;
uint32_t id;
@@ -2064,11 +2064,11 @@ int sftp_rmdir(SFTP_SESSION *sftp, const char *directory) {
}
/* Code written by Nick */
-int sftp_mkdir(SFTP_SESSION *sftp, const char *directory, mode_t mode) {
- STATUS_MESSAGE *status = NULL;
- SFTP_MESSAGE *msg = NULL;
- SFTP_ATTRIBUTES *errno_attr = NULL;
- SFTP_ATTRIBUTES attr;
+int sftp_mkdir(sftp_session sftp, const char *directory, mode_t mode) {
+ sftp_status_message status = NULL;
+ sftp_message msg = NULL;
+ sftp_attributes errno_attr = NULL;
+ struct sftp_attributes_struct attr;
ssh_buffer buffer;
ssh_string path;
uint32_t id;
@@ -2153,9 +2153,9 @@ int sftp_mkdir(SFTP_SESSION *sftp, const char *directory, mode_t mode) {
}
/* code written by nick */
-int sftp_rename(SFTP_SESSION *sftp, const char *original, const char *newname) {
- STATUS_MESSAGE *status = NULL;
- SFTP_MESSAGE *msg = NULL;
+int sftp_rename(sftp_session sftp, const char *original, const char *newname) {
+ sftp_status_message status = NULL;
+ sftp_message msg = NULL;
ssh_buffer buffer;
ssh_string oldpath;
ssh_string newpath;
@@ -2237,12 +2237,12 @@ int sftp_rename(SFTP_SESSION *sftp, const char *original, const char *newname) {
/* Code written by Nick */
/* Set file attributes on a file, directory or symbolic link. */
-int sftp_setstat(SFTP_SESSION *sftp, const char *file, SFTP_ATTRIBUTES *attr) {
+int sftp_setstat(sftp_session sftp, const char *file, sftp_attributes attr) {
uint32_t id = sftp_get_new_id(sftp);
ssh_buffer buffer = buffer_new();
ssh_string path = string_from_char(file);
- SFTP_MESSAGE *msg = NULL;
- STATUS_MESSAGE *status = NULL;
+ sftp_message msg = NULL;
+ sftp_status_message status = NULL;
buffer = buffer_new();
if (buffer == NULL) {
@@ -2307,9 +2307,8 @@ int sftp_setstat(SFTP_SESSION *sftp, const char *file, SFTP_ATTRIBUTES *attr) {
}
/* Change the file owner and group */
-int sftp_chown(SFTP_SESSION *sftp, const char *file, uid_t owner, gid_t group) {
- SFTP_ATTRIBUTES attr;
-
+int sftp_chown(sftp_session sftp, const char *file, uid_t owner, gid_t group) {
+ struct sftp_attributes_struct attr;
ZERO_STRUCT(attr);
attr.uid = owner;
@@ -2320,9 +2319,8 @@ int sftp_chown(SFTP_SESSION *sftp, const char *file, uid_t owner, gid_t group) {
}
/* Change permissions of a file */
-int sftp_chmod(SFTP_SESSION *sftp, const char *file, mode_t mode) {
- SFTP_ATTRIBUTES attr;
-
+int sftp_chmod(sftp_session sftp, const char *file, mode_t mode) {
+ struct sftp_attributes_struct attr;
ZERO_STRUCT(attr);
attr.permissions = mode;
attr.flags = SSH_FILEXFER_ATTR_PERMISSIONS;
@@ -2331,10 +2329,9 @@ int sftp_chmod(SFTP_SESSION *sftp, const char *file, mode_t mode) {
}
/* Change the last modification and access time of a file. */
-int sftp_utimes(SFTP_SESSION *sftp, const char *file,
+int sftp_utimes(sftp_session sftp, const char *file,
const struct timeval *times) {
- SFTP_ATTRIBUTES attr;
-
+ struct sftp_attributes_struct attr;
ZERO_STRUCT(attr);
attr.atime = times[0].tv_sec;
@@ -2349,9 +2346,9 @@ int sftp_utimes(SFTP_SESSION *sftp, const char *file,
return sftp_setstat(sftp, file, &attr);
}
-int sftp_symlink(SFTP_SESSION *sftp, const char *target, const char *dest) {
- STATUS_MESSAGE *status = NULL;
- SFTP_MESSAGE *msg = NULL;
+int sftp_symlink(sftp_session sftp, const char *target, const char *dest) {
+ sftp_status_message status = NULL;
+ sftp_message msg = NULL;
ssh_string target_s;
ssh_string dest_s;
ssh_buffer buffer;
@@ -2454,9 +2451,9 @@ int sftp_symlink(SFTP_SESSION *sftp, const char *target, const char *dest) {
return -1;
}
-char *sftp_readlink(SFTP_SESSION *sftp, const char *path) {
- STATUS_MESSAGE *status = NULL;
- SFTP_MESSAGE *msg = NULL;
+char *sftp_readlink(sftp_session sftp, const char *path) {
+ sftp_status_message status = NULL;
+ sftp_message msg = NULL;
ssh_string path_s = NULL;
ssh_string link_s = NULL;
ssh_buffer buffer;
@@ -2528,12 +2525,12 @@ char *sftp_readlink(SFTP_SESSION *sftp, const char *path) {
return NULL;
}
-static SFTP_STATVFS *sftp_parse_statvfs(SFTP_SESSION *sftp, ssh_buffer buf) {
- SFTP_STATVFS *statvfs;
+static sftp_statvfs_t sftp_parse_statvfs(sftp_session sftp, ssh_buffer buf) {
+ sftp_statvfs_t statvfs;
uint64_t tmp;
int ok = 0;
- statvfs = malloc(sizeof(SFTP_STATVFS));
+ statvfs = malloc(sizeof(struct sftp_statvfs_struct));
if (statvfs == NULL) {
return NULL;
}
@@ -2619,9 +2616,9 @@ static SFTP_STATVFS *sftp_parse_statvfs(SFTP_SESSION *sftp, ssh_buffer buf) {
return statvfs;
}
-SFTP_STATVFS *sftp_statvfs(SFTP_SESSION *sftp, const char *path) {
- STATUS_MESSAGE *status = NULL;
- SFTP_MESSAGE *msg = NULL;
+sftp_statvfs_t sftp_statvfs(sftp_session sftp, const char *path) {
+ sftp_status_message status = NULL;
+ sftp_message msg = NULL;
ssh_string pathstr;
ssh_string ext;
ssh_buffer buffer;
@@ -2671,7 +2668,7 @@ SFTP_STATVFS *sftp_statvfs(SFTP_SESSION *sftp, const char *path) {
}
if (msg->packet_type == SSH_FXP_EXTENDED_REPLY) {
- SFTP_STATVFS *buf = sftp_parse_statvfs(sftp, msg->payload);
+ sftp_statvfs_t buf = sftp_parse_statvfs(sftp, msg->payload);
sftp_message_free(msg);
if (buf == NULL) {
return NULL;
@@ -2696,10 +2693,10 @@ SFTP_STATVFS *sftp_statvfs(SFTP_SESSION *sftp, const char *path) {
return NULL;
}
-SFTP_STATVFS *sftp_fstatvfs(SFTP_FILE *file) {
- STATUS_MESSAGE *status = NULL;
- SFTP_MESSAGE *msg = NULL;
- SFTP_SESSION *sftp;
+sftp_statvfs_t sftp_fstatvfs(sftp_file file) {
+ sftp_status_message status = NULL;
+ sftp_message msg = NULL;
+ sftp_session sftp;
ssh_string ext;
ssh_buffer buffer;
uint32_t id;
@@ -2740,7 +2737,7 @@ SFTP_STATVFS *sftp_fstatvfs(SFTP_FILE *file) {
}
if (msg->packet_type == SSH_FXP_EXTENDED_REPLY) {
- SFTP_STATVFS *buf = sftp_parse_statvfs(sftp, msg->payload);
+ sftp_statvfs_t buf = sftp_parse_statvfs(sftp, msg->payload);
sftp_message_free(msg);
if (buf == NULL) {
return NULL;
@@ -2765,7 +2762,7 @@ SFTP_STATVFS *sftp_fstatvfs(SFTP_FILE *file) {
return NULL;
}
-void sftp_statvfs_free(SFTP_STATVFS *statvfs) {
+void sftp_statvfs_free(sftp_statvfs_t statvfs) {
if (statvfs == NULL) {
return;
}
@@ -2774,9 +2771,9 @@ void sftp_statvfs_free(SFTP_STATVFS *statvfs) {
}
/* another code written by Nick */
-char *sftp_canonicalize_path(SFTP_SESSION *sftp, const char *path) {
- STATUS_MESSAGE *status = NULL;
- SFTP_MESSAGE *msg = NULL;
+char *sftp_canonicalize_path(sftp_session sftp, const char *path) {
+ sftp_status_message status = NULL;
+ sftp_message msg = NULL;
ssh_string name = NULL;
ssh_string pathstr;
ssh_buffer buffer;
@@ -2848,10 +2845,10 @@ char *sftp_canonicalize_path(SFTP_SESSION *sftp, const char *path) {
return NULL;
}
-static SFTP_ATTRIBUTES *sftp_xstat(SFTP_SESSION *sftp, const char *path,
+static sftp_attributes sftp_xstat(sftp_session sftp, const char *path,
int param) {
- STATUS_MESSAGE *status = NULL;
- SFTP_MESSAGE *msg = NULL;
+ sftp_status_message status = NULL;
+ sftp_message msg = NULL;
ssh_string pathstr;
ssh_buffer buffer;
uint32_t id;
@@ -2906,17 +2903,17 @@ static SFTP_ATTRIBUTES *sftp_xstat(SFTP_SESSION *sftp, const char *path,
return NULL;
}
-SFTP_ATTRIBUTES *sftp_stat(SFTP_SESSION *session, const char *path) {
+sftp_attributes sftp_stat(sftp_session session, const char *path) {
return sftp_xstat(session, path, SSH_FXP_STAT);
}
-SFTP_ATTRIBUTES *sftp_lstat(SFTP_SESSION *session, const char *path) {
+sftp_attributes sftp_lstat(sftp_session session, const char *path) {
return sftp_xstat(session, path, SSH_FXP_LSTAT);
}
-SFTP_ATTRIBUTES *sftp_fstat(SFTP_FILE *file) {
- STATUS_MESSAGE *status = NULL;
- SFTP_MESSAGE *msg = NULL;
+sftp_attributes sftp_fstat(sftp_file file) {
+ sftp_status_message status = NULL;
+ sftp_message msg = NULL;
ssh_buffer buffer;
uint32_t id;